From gitlab at gitlab.haskell.org Sat Aug 1 01:02:22 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 31 Jul 2020 21:02:22 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 6 commits: Fix minimal imports dump for boot files (fix #18497) Message-ID: <5f24bf1ee9023_80b3f849420ad98604923f@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e4197667 by Vladislav Zavialov at 2020-07-31T21:02:20-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 30 changed files: - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/Dwarf/Types.hs - compiler/GHC/CmmToAsm/PIC.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/Ppr/TyThing.hs - compiler/GHC/HsToCore.hs - compiler/GHC/HsToCore/Coverage.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/Rename/Names.hs - compiler/GHC/StgToCmm.hs - compiler/GHC/StgToCmm/Bind.hs - compiler/GHC/StgToCmm/Closure.hs - compiler/GHC/StgToCmm/Heap.hs - compiler/GHC/StgToCmm/Layout.hs - compiler/GHC/Tc/Module.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Tc/Types/Origin.hs - libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs - rts/Hpc.c - + testsuite/tests/haddock/should_compile_flag_haddock/T17652.hs - + testsuite/tests/haddock/should_compile_flag_haddock/T17652.stderr - testsuite/tests/haddock/should_compile_flag_haddock/all.T - testsuite/tests/lib/integer/all.T - testsuite/tests/lib/integer/integerPowMod.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6a1853aff6f8b74cead5ed67262458c5c74b0ff2...e419766777b5fea9628314b082f8a411ca9727da -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6a1853aff6f8b74cead5ed67262458c5c74b0ff2...e419766777b5fea9628314b082f8a411ca9727da You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 1 08:22:37 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sat, 01 Aug 2020 04:22:37 -0400 Subject: [Git][ghc/ghc][master] 2 commits: Refactor CLabel pretty-printing Message-ID: <5f25264deb744_80b3f848c1e06f460647fa@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - 17 changed files: - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/Dwarf/Types.hs - compiler/GHC/CmmToAsm/PIC.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/HsToCore.hs - compiler/GHC/HsToCore/Coverage.hs - compiler/GHC/StgToCmm.hs - compiler/GHC/StgToCmm/Bind.hs - compiler/GHC/StgToCmm/Closure.hs - compiler/GHC/StgToCmm/Heap.hs - compiler/GHC/StgToCmm/Layout.hs - rts/Hpc.c Changes: ===================================== compiler/GHC/Cmm/CLabel.hs ===================================== @@ -108,7 +108,7 @@ module GHC.Cmm.CLabel ( -- * Conversions toClosureLbl, toSlowEntryLbl, toEntryLbl, toInfoLbl, hasHaskellName, - pprCLabel, + pprCLabel, pprCLabel_LLVM, pprCLabel_NCG, isInfoTableLabel, isConInfoTableLabel, isIdLabel, isTickyLabel @@ -242,7 +242,7 @@ data CLabel -- | These labels are generated and used inside the NCG only. -- They are special variants of a label used for dynamic linking - -- see module PositionIndependentCode for details. + -- see module "GHC.CmmToAsm.PIC" for details. | DynamicLinkerLabel DynamicLinkerLabelInfo CLabel -- | This label is generated and used inside the NCG only. @@ -398,23 +398,24 @@ data ForeignLabelSource -- We can't make a Show instance for CLabel because lots of its components don't have instances. -- The regular Outputable instance only shows the label name, and not its other info. -- -pprDebugCLabel :: CLabel -> SDoc -pprDebugCLabel lbl +pprDebugCLabel :: Platform -> CLabel -> SDoc +pprDebugCLabel platform lbl = case lbl of - IdLabel _ _ info-> ppr lbl <> (parens $ text "IdLabel" - <> whenPprDebug (text ":" <> text (show info))) + IdLabel _ _ info-> pprCLabel_other platform lbl + <> (parens $ text "IdLabel" + <> whenPprDebug (text ":" <> text (show info))) CmmLabel pkg _ext _name _info - -> ppr lbl <> (parens $ text "CmmLabel" <+> ppr pkg) + -> pprCLabel_other platform lbl <> (parens $ text "CmmLabel" <+> ppr pkg) - RtsLabel{} -> ppr lbl <> (parens $ text "RtsLabel") + RtsLabel{} -> pprCLabel_other platform lbl <> (parens $ text "RtsLabel") ForeignLabel _name mSuffix src funOrData - -> ppr lbl <> (parens $ text "ForeignLabel" - <+> ppr mSuffix - <+> ppr src - <+> ppr funOrData) + -> pprCLabel_other platform lbl <> (parens $ text "ForeignLabel" + <+> ppr mSuffix + <+> ppr src + <+> ppr funOrData) - _ -> ppr lbl <> (parens $ text "other CLabel") + _ -> pprCLabel_other platform lbl <> (parens $ text "other CLabel") data IdLabelInfo @@ -753,34 +754,37 @@ mkAsmTempDieLabel l = mkAsmTempDerivedLabel l (fsLit "_die") -- ----------------------------------------------------------------------------- -- Convert between different kinds of label -toClosureLbl :: CLabel -> CLabel -toClosureLbl (IdLabel n c _) = IdLabel n c Closure -toClosureLbl (CmmLabel m ext str _) = CmmLabel m ext str CmmClosure -toClosureLbl l = pprPanic "toClosureLbl" (ppr l) - -toSlowEntryLbl :: CLabel -> CLabel -toSlowEntryLbl (IdLabel n _ BlockInfoTable) - = pprPanic "toSlowEntryLbl" (ppr n) -toSlowEntryLbl (IdLabel n c _) = IdLabel n c Slow -toSlowEntryLbl l = pprPanic "toSlowEntryLbl" (ppr l) - -toEntryLbl :: CLabel -> CLabel -toEntryLbl (IdLabel n c LocalInfoTable) = IdLabel n c LocalEntry -toEntryLbl (IdLabel n c ConInfoTable) = IdLabel n c ConEntry -toEntryLbl (IdLabel n _ BlockInfoTable) = mkLocalBlockLabel (nameUnique n) - -- See Note [Proc-point local block entry-point]. -toEntryLbl (IdLabel n c _) = IdLabel n c Entry -toEntryLbl (CmmLabel m ext str CmmInfo) = CmmLabel m ext str CmmEntry -toEntryLbl (CmmLabel m ext str CmmRetInfo) = CmmLabel m ext str CmmRet -toEntryLbl l = pprPanic "toEntryLbl" (ppr l) - -toInfoLbl :: CLabel -> CLabel -toInfoLbl (IdLabel n c LocalEntry) = IdLabel n c LocalInfoTable -toInfoLbl (IdLabel n c ConEntry) = IdLabel n c ConInfoTable -toInfoLbl (IdLabel n c _) = IdLabel n c InfoTable -toInfoLbl (CmmLabel m ext str CmmEntry)= CmmLabel m ext str CmmInfo -toInfoLbl (CmmLabel m ext str CmmRet) = CmmLabel m ext str CmmRetInfo -toInfoLbl l = pprPanic "CLabel.toInfoLbl" (ppr l) +toClosureLbl :: Platform -> CLabel -> CLabel +toClosureLbl platform lbl = case lbl of + IdLabel n c _ -> IdLabel n c Closure + CmmLabel m ext str _ -> CmmLabel m ext str CmmClosure + _ -> pprPanic "toClosureLbl" (pprCLabel_other platform lbl) + +toSlowEntryLbl :: Platform -> CLabel -> CLabel +toSlowEntryLbl platform lbl = case lbl of + IdLabel n _ BlockInfoTable -> pprPanic "toSlowEntryLbl" (ppr n) + IdLabel n c _ -> IdLabel n c Slow + _ -> pprPanic "toSlowEntryLbl" (pprCLabel_other platform lbl) + +toEntryLbl :: Platform -> CLabel -> CLabel +toEntryLbl platform lbl = case lbl of + IdLabel n c LocalInfoTable -> IdLabel n c LocalEntry + IdLabel n c ConInfoTable -> IdLabel n c ConEntry + IdLabel n _ BlockInfoTable -> mkLocalBlockLabel (nameUnique n) + -- See Note [Proc-point local block entry-point]. + IdLabel n c _ -> IdLabel n c Entry + CmmLabel m ext str CmmInfo -> CmmLabel m ext str CmmEntry + CmmLabel m ext str CmmRetInfo -> CmmLabel m ext str CmmRet + _ -> pprPanic "toEntryLbl" (pprCLabel_other platform lbl) + +toInfoLbl :: Platform -> CLabel -> CLabel +toInfoLbl platform lbl = case lbl of + IdLabel n c LocalEntry -> IdLabel n c LocalInfoTable + IdLabel n c ConEntry -> IdLabel n c ConInfoTable + IdLabel n c _ -> IdLabel n c InfoTable + CmmLabel m ext str CmmEntry -> CmmLabel m ext str CmmInfo + CmmLabel m ext str CmmRet -> CmmLabel m ext str CmmRetInfo + _ -> pprPanic "CLabel.toInfoLbl" (pprCLabel_other platform lbl) hasHaskellName :: CLabel -> Maybe Name hasHaskellName (IdLabel n _ _) = Just n @@ -1208,34 +1212,50 @@ and are not externally visible. -} instance Outputable CLabel where - ppr c = sdocWithDynFlags $ \dynFlags -> pprCLabel dynFlags c + ppr lbl = sdocWithDynFlags (\dflags -> pprCLabel (backend dflags) (targetPlatform dflags) lbl) + +pprCLabel :: Backend -> Platform -> CLabel -> SDoc +pprCLabel bcknd platform lbl = + case bcknd of + NCG -> pprCLabel_NCG platform lbl + LLVM -> pprCLabel_LLVM platform lbl + _ -> pprCLabel_other platform lbl + +pprCLabel_LLVM :: Platform -> CLabel -> SDoc +pprCLabel_LLVM = pprCLabel_NCG + +pprCLabel_NCG :: Platform -> CLabel -> SDoc +pprCLabel_NCG platform lbl = getPprStyle $ \sty -> + let + -- some platform (e.g. Darwin) require a leading "_" for exported asm + -- symbols + maybe_underscore :: SDoc -> SDoc + maybe_underscore doc = + if platformLeadingUnderscore platform + then pp_cSEP <> doc + else doc -pprCLabel :: DynFlags -> CLabel -> SDoc -pprCLabel dflags = \case - (LocalBlockLabel u) -> tempLabelPrefixOrUnderscore platform <> pprUniqueAlways u + in case lbl of + LocalBlockLabel u + -> tempLabelPrefixOrUnderscore platform <> pprUniqueAlways u - (AsmTempLabel u) - | not (platformUnregisterised platform) + AsmTempLabel u -> tempLabelPrefixOrUnderscore platform <> pprUniqueAlways u - (AsmTempDerivedLabel l suf) - | useNCG + AsmTempDerivedLabel l suf -> ptext (asmTempLabelPrefix platform) <> case l of AsmTempLabel u -> pprUniqueAlways u LocalBlockLabel u -> pprUniqueAlways u - _other -> pprCLabel dflags l + _other -> pprCLabel_NCG platform l <> ftext suf - (DynamicLinkerLabel info lbl) - | useNCG + DynamicLinkerLabel info lbl -> pprDynamicLinkerAsmLabel platform info lbl PicBaseLabel - | useNCG -> text "1b" - (DeadStripPreventer lbl) - | useNCG + DeadStripPreventer lbl -> {- `lbl` can be temp one but we need to ensure that dsp label will stay @@ -1243,36 +1263,36 @@ pprCLabel dflags = \case optional `_` (underscore) because this is how you mark non-temp symbols on some platforms (Darwin) -} - maybe_underscore $ text "dsp_" <> pprCLabel dflags lbl <> text "_dsp" + maybe_underscore $ text "dsp_" <> pprCLabel_NCG platform lbl <> text "_dsp" - (StringLitLabel u) - | useNCG + StringLitLabel u -> pprUniqueAlways u <> ptext (sLit "_str") - lbl -> getPprStyle $ \sty -> - if useNCG && asmStyle sty - then maybe_underscore $ pprAsmCLbl lbl - else pprCLbl platform lbl + ForeignLabel fs (Just sz) _ _ + | asmStyle sty + , OSMinGW32 <- platformOS platform + -> -- In asm mode, we need to put the suffix on a stdcall ForeignLabel. + -- (The C compiler does this itself). + maybe_underscore $ ftext fs <> char '@' <> int sz - where - platform = targetPlatform dflags - useNCG = backend dflags == NCG + _ | asmStyle sty -> maybe_underscore $ pprCLabel_common platform lbl + | otherwise -> pprCLabel_common platform lbl - maybe_underscore :: SDoc -> SDoc - maybe_underscore doc = - if platformLeadingUnderscore platform - then pp_cSEP <> doc - else doc +pprCLabel_other :: Platform -> CLabel -> SDoc +pprCLabel_other platform lbl = + case lbl of + LocalBlockLabel u + -> tempLabelPrefixOrUnderscore platform <> pprUniqueAlways u + + AsmTempLabel u + | not (platformUnregisterised platform) + -> tempLabelPrefixOrUnderscore platform <> pprUniqueAlways u + + lbl -> pprCLabel_common platform lbl - pprAsmCLbl (ForeignLabel fs (Just sz) _ _) - | platformOS platform == OSMinGW32 - -- In asm mode, we need to put the suffix on a stdcall ForeignLabel. - -- (The C compiler does this itself). - = ftext fs <> char '@' <> int sz - pprAsmCLbl lbl = pprCLbl platform lbl -pprCLbl :: Platform -> CLabel -> SDoc -pprCLbl platform = \case +pprCLabel_common :: Platform -> CLabel -> SDoc +pprCLabel_common platform = \case (StringLitLabel u) -> pprUniqueAlways u <> text "_str" (SRTLabel u) -> tempLabelPrefixOrUnderscore platform <> pprUniqueAlways u <> pp_cSEP <> text "srt" (LargeBitmapLabel u) -> tempLabelPrefixOrUnderscore platform @@ -1335,11 +1355,11 @@ pprCLbl platform = \case (CCS_Label ccs) -> ppr ccs (HpcTicksLabel mod) -> text "_hpc_tickboxes_" <> ppr mod <> ptext (sLit "_hpc") - (AsmTempLabel {}) -> panic "pprCLbl AsmTempLabel" - (AsmTempDerivedLabel {}) -> panic "pprCLbl AsmTempDerivedLabel" - (DynamicLinkerLabel {}) -> panic "pprCLbl DynamicLinkerLabel" - (PicBaseLabel {}) -> panic "pprCLbl PicBaseLabel" - (DeadStripPreventer {}) -> panic "pprCLbl DeadStripPreventer" + (AsmTempLabel {}) -> panic "pprCLabel_common AsmTempLabel" + (AsmTempDerivedLabel {}) -> panic "pprCLabel_common AsmTempDerivedLabel" + (DynamicLinkerLabel {}) -> panic "pprCLabel_common DynamicLinkerLabel" + (PicBaseLabel {}) -> panic "pprCLabel_common PicBaseLabel" + (DeadStripPreventer {}) -> panic "pprCLabel_common DeadStripPreventer" ppIdFlavor :: IdLabelInfo -> SDoc ppIdFlavor x = pp_cSEP <> text @@ -1402,60 +1422,60 @@ pprDynamicLinkerAsmLabel platform dllInfo lbl = OSDarwin | platformArch platform == ArchX86_64 -> case dllInfo of - CodeStub -> char 'L' <> ppr lbl <> text "$stub" - SymbolPtr -> char 'L' <> ppr lbl <> text "$non_lazy_ptr" - GotSymbolPtr -> ppr lbl <> text "@GOTPCREL" - GotSymbolOffset -> ppr lbl + CodeStub -> char 'L' <> ppLbl <> text "$stub" + SymbolPtr -> char 'L' <> ppLbl <> text "$non_lazy_ptr" + GotSymbolPtr -> ppLbl <> text "@GOTPCREL" + GotSymbolOffset -> ppLbl | otherwise -> case dllInfo of - CodeStub -> char 'L' <> ppr lbl <> text "$stub" - SymbolPtr -> char 'L' <> ppr lbl <> text "$non_lazy_ptr" + CodeStub -> char 'L' <> ppLbl <> text "$stub" + SymbolPtr -> char 'L' <> ppLbl <> text "$non_lazy_ptr" _ -> panic "pprDynamicLinkerAsmLabel" OSAIX -> case dllInfo of - SymbolPtr -> text "LC.." <> ppr lbl -- GCC's naming convention + SymbolPtr -> text "LC.." <> ppLbl -- GCC's naming convention _ -> panic "pprDynamicLinkerAsmLabel" _ | osElfTarget (platformOS platform) -> elfLabel OSMinGW32 -> case dllInfo of - SymbolPtr -> text "__imp_" <> ppr lbl + SymbolPtr -> text "__imp_" <> ppLbl _ -> panic "pprDynamicLinkerAsmLabel" _ -> panic "pprDynamicLinkerAsmLabel" where + ppLbl = pprCLabel_NCG platform lbl elfLabel | platformArch platform == ArchPPC = case dllInfo of CodeStub -> -- See Note [.LCTOC1 in PPC PIC code] - ppr lbl <> text "+32768 at plt" - SymbolPtr -> text ".LC_" <> ppr lbl + ppLbl <> text "+32768 at plt" + SymbolPtr -> text ".LC_" <> ppLbl _ -> panic "pprDynamicLinkerAsmLabel" | platformArch platform == ArchX86_64 = case dllInfo of - CodeStub -> ppr lbl <> text "@plt" - GotSymbolPtr -> ppr lbl <> text "@gotpcrel" - GotSymbolOffset -> ppr lbl - SymbolPtr -> text ".LC_" <> ppr lbl + CodeStub -> ppLbl <> text "@plt" + GotSymbolPtr -> ppLbl <> text "@gotpcrel" + GotSymbolOffset -> ppLbl + SymbolPtr -> text ".LC_" <> ppLbl | platformArch platform == ArchPPC_64 ELF_V1 || platformArch platform == ArchPPC_64 ELF_V2 = case dllInfo of - GotSymbolPtr -> text ".LC_" <> ppr lbl - <> text "@toc" - GotSymbolOffset -> ppr lbl - SymbolPtr -> text ".LC_" <> ppr lbl + GotSymbolPtr -> text ".LC_" <> ppLbl <> text "@toc" + GotSymbolOffset -> ppLbl + SymbolPtr -> text ".LC_" <> ppLbl _ -> panic "pprDynamicLinkerAsmLabel" | otherwise = case dllInfo of - CodeStub -> ppr lbl <> text "@plt" - SymbolPtr -> text ".LC_" <> ppr lbl - GotSymbolPtr -> ppr lbl <> text "@got" - GotSymbolOffset -> ppr lbl <> text "@gotoff" + CodeStub -> ppLbl <> text "@plt" + SymbolPtr -> text ".LC_" <> ppLbl + GotSymbolPtr -> ppLbl <> text "@got" + GotSymbolOffset -> ppLbl <> text "@gotoff" -- Figure out whether `symbol` may serve as an alias -- to `target` within one compilation unit. ===================================== compiler/GHC/Cmm/Info.hs ===================================== @@ -253,7 +253,7 @@ mkInfoTableContents dflags ++ [ liveness_lit, slow_entry ] ; return (Nothing, Nothing, extra_bits, liveness_data) } where - slow_entry = CmmLabel (toSlowEntryLbl info_lbl) + slow_entry = CmmLabel (toSlowEntryLbl platform info_lbl) srt_lit = case srt_label of [] -> mkIntCLit platform 0 (lit:_rest) -> ASSERT( null _rest ) lit ===================================== compiler/GHC/Cmm/Info/Build.hs ===================================== @@ -459,8 +459,8 @@ newtype CAFLabel = CAFLabel CLabel type CAFSet = Set CAFLabel type CAFEnv = LabelMap CAFSet -mkCAFLabel :: CLabel -> CAFLabel -mkCAFLabel lbl = CAFLabel (toClosureLbl lbl) +mkCAFLabel :: Platform -> CLabel -> CAFLabel +mkCAFLabel platform lbl = CAFLabel (toClosureLbl platform lbl) -- This is a label that we can put in an SRT. It *must* be a closure label, -- pointing to either a FUN_STATIC, THUNK_STATIC, or CONSTR. @@ -470,10 +470,10 @@ newtype SRTEntry = SRTEntry CLabel -- --------------------------------------------------------------------- -- CAF analysis -addCafLabel :: CLabel -> CAFSet -> CAFSet -addCafLabel l s +addCafLabel :: Platform -> CLabel -> CAFSet -> CAFSet +addCafLabel platform l s | Just _ <- hasHaskellName l - , let caf_label = mkCAFLabel l + , let caf_label = mkCAFLabel platform l -- For imported Ids hasCAF will have accurate CafInfo -- Locals are initialized as CAFFY. We turn labels with empty SRTs into -- non-CAFFYs in doSRTs @@ -483,21 +483,20 @@ addCafLabel l s = s cafAnalData - :: CmmStatics + :: Platform + -> CmmStatics -> CAFSet - -cafAnalData (CmmStaticsRaw _lbl _data) = - Set.empty - -cafAnalData (CmmStatics _lbl _itbl _ccs payload) = - foldl' analyzeStatic Set.empty payload - where - analyzeStatic s lit = - case lit of - CmmLabel c -> addCafLabel c s - CmmLabelOff c _ -> addCafLabel c s - CmmLabelDiffOff c1 c2 _ _ -> addCafLabel c1 $! addCafLabel c2 s - _ -> s +cafAnalData platform st = case st of + CmmStaticsRaw _lbl _data -> Set.empty + CmmStatics _lbl _itbl _ccs payload -> + foldl' analyzeStatic Set.empty payload + where + analyzeStatic s lit = + case lit of + CmmLabel c -> addCafLabel platform c s + CmmLabelOff c _ -> addCafLabel platform c s + CmmLabelDiffOff c1 c2 _ _ -> addCafLabel platform c1 $! addCafLabel platform c2 s + _ -> s -- | -- For each code block: @@ -507,16 +506,17 @@ cafAnalData (CmmStatics _lbl _itbl _ccs payload) = -- This gives us a `CAFEnv`: a mapping from code block to sets of labels -- cafAnal - :: LabelSet -- The blocks representing continuations, ie. those + :: Platform + -> LabelSet -- The blocks representing continuations, ie. those -- that will get RET info tables. These labels will -- get their own SRTs, so we don't aggregate CAFs from -- references to these labels, we just use the label. -> CLabel -- The top label of the proc -> CmmGraph -> CAFEnv -cafAnal contLbls topLbl cmmGraph = +cafAnal platform contLbls topLbl cmmGraph = analyzeCmmBwd cafLattice - (cafTransfers contLbls (g_entry cmmGraph) topLbl) cmmGraph mapEmpty + (cafTransfers platform contLbls (g_entry cmmGraph) topLbl) cmmGraph mapEmpty cafLattice :: DataflowLattice CAFSet @@ -527,8 +527,8 @@ cafLattice = DataflowLattice Set.empty add in changedIf (Set.size new' > Set.size old) new' -cafTransfers :: LabelSet -> Label -> CLabel -> TransferFun CAFSet -cafTransfers contLbls entry topLbl +cafTransfers :: Platform -> LabelSet -> Label -> CLabel -> TransferFun CAFSet +cafTransfers platform contLbls entry topLbl block@(BlockCC eNode middle xNode) fBase = let joined :: CAFSet joined = cafsInNode xNode $! live' @@ -546,11 +546,11 @@ cafTransfers contLbls entry topLbl successorFact s -- If this is a loop back to the entry, we can refer to the -- entry label. - | s == entry = Just (addCafLabel topLbl Set.empty) + | s == entry = Just (addCafLabel platform topLbl Set.empty) -- If this is a continuation, we want to refer to the -- SRT for the continuation's info table | s `setMember` contLbls - = Just (Set.singleton (mkCAFLabel (infoTblLbl s))) + = Just (Set.singleton (mkCAFLabel platform (infoTblLbl s))) -- Otherwise, takes the CAF references from the destination | otherwise = lookupFact s fBase @@ -562,11 +562,11 @@ cafTransfers contLbls entry topLbl addCafExpr expr !set = case expr of CmmLit (CmmLabel c) -> - addCafLabel c set + addCafLabel platform c set CmmLit (CmmLabelOff c _) -> - addCafLabel c set + addCafLabel platform c set CmmLit (CmmLabelDiffOff c1 c2 _ _) -> - addCafLabel c1 $! addCafLabel c2 set + addCafLabel platform c1 $! addCafLabel platform c2 set _ -> set in @@ -649,35 +649,34 @@ getBlockLabels = mapMaybe getBlockLabel -- where the label is -- - the info label for a continuation or dynamic closure -- - the closure label for a top-level function (not a CAF) -getLabelledBlocks :: CmmDecl -> [(SomeLabel, CAFLabel)] -getLabelledBlocks (CmmData _ (CmmStaticsRaw _ _)) = - [] -getLabelledBlocks (CmmData _ (CmmStatics lbl _ _ _)) = - [ (DeclLabel lbl, mkCAFLabel lbl) ] -getLabelledBlocks (CmmProc top_info _ _ _) = - [ (BlockLabel blockId, caf_lbl) - | (blockId, info) <- mapToList (info_tbls top_info) - , let rep = cit_rep info - , not (isStaticRep rep) || not (isThunkRep rep) - , let !caf_lbl = mkCAFLabel (cit_lbl info) - ] +getLabelledBlocks :: Platform -> CmmDecl -> [(SomeLabel, CAFLabel)] +getLabelledBlocks platform decl = case decl of + CmmData _ (CmmStaticsRaw _ _) -> [] + CmmData _ (CmmStatics lbl _ _ _) -> [ (DeclLabel lbl, mkCAFLabel platform lbl) ] + CmmProc top_info _ _ _ -> [ (BlockLabel blockId, caf_lbl) + | (blockId, info) <- mapToList (info_tbls top_info) + , let rep = cit_rep info + , not (isStaticRep rep) || not (isThunkRep rep) + , let !caf_lbl = mkCAFLabel platform (cit_lbl info) + ] -- | Put the labelled blocks that we will be annotating with SRTs into -- dependency order. This is so that we can process them one at a -- time, resolving references to earlier blocks to point to their -- SRTs. CAFs themselves are not included here; see getCAFs below. depAnalSRTs - :: CAFEnv + :: Platform + -> CAFEnv -> Map CLabel CAFSet -- CAFEnv for statics -> [CmmDecl] -> [SCC (SomeLabel, CAFLabel, Set CAFLabel)] -depAnalSRTs cafEnv cafEnv_static decls = +depAnalSRTs platform cafEnv cafEnv_static decls = srtTrace "depAnalSRTs" (text "decls:" <+> ppr decls $$ text "nodes:" <+> ppr (map node_payload nodes) $$ text "graph:" <+> ppr graph) graph where labelledBlocks :: [(SomeLabel, CAFLabel)] - labelledBlocks = concatMap getLabelledBlocks decls + labelledBlocks = concatMap (getLabelledBlocks platform) decls labelToBlock :: Map CAFLabel SomeLabel labelToBlock = foldl' (\m (v,k) -> Map.insert k v m) Map.empty labelledBlocks @@ -701,9 +700,9 @@ depAnalSRTs cafEnv cafEnv_static decls = -- SRT, since the point of SRTs is to keep CAFs alive. -- - CAFs therefore don't take part in the dependency analysis in depAnalSRTs. -- instead we generate their SRTs after everything else. -getCAFs :: CAFEnv -> [CmmDecl] -> [(Label, CAFLabel, Set CAFLabel)] -getCAFs cafEnv decls = - [ (g_entry g, mkCAFLabel topLbl, cafs) +getCAFs :: Platform -> CAFEnv -> [CmmDecl] -> [(Label, CAFLabel, Set CAFLabel)] +getCAFs platform cafEnv decls = + [ (g_entry g, mkCAFLabel platform topLbl, cafs) | CmmProc top_info topLbl _ g <- decls , Just info <- [mapLookup (g_entry g) (info_tbls top_info)] , let rep = cit_rep info @@ -747,11 +746,11 @@ srtMapNonCAFs srtMap = get_name (_l, Just _srt_entry) = Nothing -- | resolve a CAFLabel to its SRTEntry using the SRTMap -resolveCAF :: SRTMap -> CAFLabel -> Maybe SRTEntry -resolveCAF srtMap lbl@(CAFLabel l) = +resolveCAF :: Platform -> SRTMap -> CAFLabel -> Maybe SRTEntry +resolveCAF platform srtMap lbl@(CAFLabel l) = srtTrace "resolveCAF" ("l:" <+> ppr l <+> "resolved:" <+> ppr ret) ret where - ret = Map.findWithDefault (Just (SRTEntry (toClosureLbl l))) lbl srtMap + ret = Map.findWithDefault (Just (SRTEntry (toClosureLbl platform l))) lbl srtMap -- | Attach SRTs to all info tables in the CmmDecls, and add SRT -- declarations to the ModuleSRTInfo. @@ -791,6 +790,8 @@ doSRTs dflags moduleSRTInfo procs data_ = do decls = map snd data_ ++ concat procss staticFuns = mapFromList (getStaticFuns decls) + platform = targetPlatform dflags + -- Put the decls in dependency order. Why? So that we can implement -- [Inline] and [Filter]. If we need to refer to an SRT that has -- a single entry, we use the entry itself, which means that we @@ -799,10 +800,10 @@ doSRTs dflags moduleSRTInfo procs data_ = do -- them. let sccs :: [SCC (SomeLabel, CAFLabel, Set CAFLabel)] - sccs = {-# SCC depAnalSRTs #-} depAnalSRTs cafEnv static_data_env decls + sccs = {-# SCC depAnalSRTs #-} depAnalSRTs platform cafEnv static_data_env decls cafsWithSRTs :: [(Label, CAFLabel, Set CAFLabel)] - cafsWithSRTs = getCAFs cafEnv decls + cafsWithSRTs = getCAFs platform cafEnv decls srtTraceM "doSRTs" (text "data:" <+> ppr data_ $$ text "procs:" <+> ppr procs $$ @@ -853,7 +854,7 @@ doSRTs dflags moduleSRTInfo procs data_ = do -- be CAFFY. -- See Note [Ticky labels in SRT analysis] above for -- why we exclude ticky labels here. - Map.insert (mkCAFLabel lbl) Nothing srtMap + Map.insert (mkCAFLabel platform lbl) Nothing srtMap | otherwise -> -- Not an IdLabel, ignore srtMap @@ -933,6 +934,7 @@ oneSRT dflags staticFuns lbls caf_lbls isCAF cafs static_data = do let config = initConfig dflags profile = targetProfile dflags + platform = profilePlatform profile srtMap = moduleSRTMap topSRT blockids = getBlockLabels lbls @@ -951,7 +953,7 @@ oneSRT dflags staticFuns lbls caf_lbls isCAF cafs static_data = do -- Resolve references to their SRT entries resolved :: [SRTEntry] - resolved = mapMaybe (resolveCAF srtMap) (Set.toList nonRec) + resolved = mapMaybe (resolveCAF platform srtMap) (Set.toList nonRec) -- The set of all SRTEntries in SRTs that we refer to from here. allBelow = @@ -1016,7 +1018,7 @@ oneSRT dflags staticFuns lbls caf_lbls isCAF cafs static_data = do -- We're going to build an SRT for this group, which should include function -- references in the group. See Note [recursive SRTs]. let allBelow_funs = - Set.fromList (map (SRTEntry . toClosureLbl) otherFunLabels) + Set.fromList (map (SRTEntry . toClosureLbl platform) otherFunLabels) let filtered = filtered0 `Set.union` allBelow_funs srtTraceM "oneSRT" (text "filtered:" <+> ppr filtered $$ text "allBelow_funs:" <+> ppr allBelow_funs) ===================================== compiler/GHC/Cmm/Pipeline.hs ===================================== @@ -46,7 +46,7 @@ cmmPipeline cmmPipeline hsc_env srtInfo prog = withTimingSilent dflags (text "Cmm pipeline") forceRes $ do let dflags = hsc_dflags hsc_env - tops <- {-# SCC "tops" #-} mapM (cpsTop hsc_env) prog + tops <- {-# SCC "tops" #-} mapM (cpsTop dflags) prog let (procs, data_) = partitionEithers tops (srtInfo, cmms) <- {-# SCC "doSRTs" #-} doSRTs dflags srtInfo procs data_ @@ -59,9 +59,9 @@ cmmPipeline hsc_env srtInfo prog = withTimingSilent dflags (text "Cmm pipeline") dflags = hsc_dflags hsc_env -cpsTop :: HscEnv -> CmmDecl -> IO (Either (CAFEnv, [CmmDecl]) (CAFSet, CmmDecl)) -cpsTop _ p@(CmmData _ statics) = return (Right (cafAnalData statics, p)) -cpsTop hsc_env proc = +cpsTop :: DynFlags -> CmmDecl -> IO (Either (CAFEnv, [CmmDecl]) (CAFSet, CmmDecl)) +cpsTop dflags p@(CmmData _ statics) = return (Right (cafAnalData (targetPlatform dflags) statics, p)) +cpsTop dflags proc = do ----------- Control-flow optimisations ---------------------------------- @@ -118,7 +118,7 @@ cpsTop hsc_env proc = Opt_D_dump_cmm_sink "Sink assignments" ------------- CAF analysis ---------------------------------------------- - let cafEnv = {-# SCC "cafAnal" #-} cafAnal call_pps l g + let cafEnv = {-# SCC "cafAnal" #-} cafAnal platform call_pps l g dumpWith dflags Opt_D_dump_cmm_caf "CAFEnv" FormatText (ppr cafEnv) g <- if splitting_proc_points @@ -153,8 +153,7 @@ cpsTop hsc_env proc = return (Left (cafEnv, g)) - where dflags = hsc_dflags hsc_env - platform = targetPlatform dflags + where platform = targetPlatform dflags dump = dumpGraph dflags dumps flag name ===================================== compiler/GHC/Cmm/ProcPoint.hs ===================================== @@ -319,7 +319,7 @@ splitAtProcPoints dflags entry_label callPPs procPoints procMap tablesNextToCode = platformTablesNextToCode platform jump_label (Just info_lbl) _ | tablesNextToCode = info_lbl - | otherwise = toEntryLbl info_lbl + | otherwise = toEntryLbl platform info_lbl jump_label Nothing block_lbl = block_lbl add_if_pp id rst = case mapLookup id procLabels of ===================================== compiler/GHC/CmmToAsm.hs ===================================== @@ -891,7 +891,7 @@ makeImportsDoc dflags imports | needImportedSymbols config = vcat $ (pprGotDeclaration config :) $ - map ( pprImportedSymbol dflags config . fst . head) $ + map ( pprImportedSymbol config . fst . head) $ groupBy (\(_,a) (_,b) -> a == b) $ sortBy (\(_,a) (_,b) -> compare a b) $ map doPpr $ @@ -901,7 +901,7 @@ makeImportsDoc dflags imports doPpr lbl = (lbl, renderWithStyle (initSDocContext dflags astyle) - (pprCLabel dflags lbl)) + (pprCLabel_NCG platform lbl)) astyle = mkCodeStyle AsmStyle -- ----------------------------------------------------------------------------- ===================================== compiler/GHC/CmmToAsm/Dwarf/Types.hs ===================================== @@ -156,6 +156,13 @@ pprDwarfInfo platform haveSrc d pprDwarfInfoClose noChildren = pprDwarfInfoOpen platform haveSrc d +-- | Print a CLabel name in a ".stringz \"LABEL\"" +pprLabelString :: Platform -> CLabel -> SDoc +pprLabelString platform label = + pprString' -- we don't need to escape the string as labels don't contain exotic characters + $ withPprStyle (mkCodeStyle CStyle) -- force CStyle (foreign labels may be printed differently in AsmStyle) + $ pprCLabel_NCG platform label + -- | Prints assembler data corresponding to DWARF info records. Note -- that the binary format of this is parameterized in @abbrevDecls@ and -- has to be kept in synch. @@ -172,12 +179,11 @@ pprDwarfInfoOpen platform haveSrc (DwarfCompileUnit _ name producer compDir lowL $$ if haveSrc then sectionOffset platform (ptext lineLbl) (ptext dwarfLineLabel) else empty -pprDwarfInfoOpen platform _ (DwarfSubprogram _ name label - parent) = sdocWithDynFlags $ \df -> +pprDwarfInfoOpen platform _ (DwarfSubprogram _ name label parent) = ppr (mkAsmTempDieLabel label) <> colon $$ pprAbbrev abbrev $$ pprString name - $$ pprString (renderWithStyle (initSDocContext df (mkCodeStyle CStyle)) (ppr label)) + $$ pprLabelString platform label $$ pprFlag (externallyVisibleCLabel label) $$ pprWord platform (ppr label) $$ pprWord platform (ppr $ mkAsmTempEndLabel label) @@ -189,14 +195,14 @@ pprDwarfInfoOpen platform _ (DwarfSubprogram _ name label Just _ -> DwAbbrSubprogramWithParent parentValue = maybe empty pprParentDie parent pprParentDie sym = sectionOffset platform (ppr sym) (ptext dwarfInfoLabel) -pprDwarfInfoOpen _ _ (DwarfBlock _ label Nothing) = sdocWithDynFlags $ \df -> +pprDwarfInfoOpen platform _ (DwarfBlock _ label Nothing) = ppr (mkAsmTempDieLabel label) <> colon $$ pprAbbrev DwAbbrBlockWithoutCode - $$ pprString (renderWithStyle (initSDocContext df (mkCodeStyle CStyle)) (ppr label)) -pprDwarfInfoOpen platform _ (DwarfBlock _ label (Just marker)) = sdocWithDynFlags $ \df -> + $$ pprLabelString platform label +pprDwarfInfoOpen platform _ (DwarfBlock _ label (Just marker)) = ppr (mkAsmTempDieLabel label) <> colon $$ pprAbbrev DwAbbrBlock - $$ pprString (renderWithStyle (initSDocContext df (mkCodeStyle CStyle)) (ppr label)) + $$ pprLabelString platform label $$ pprWord platform (ppr marker) $$ pprWord platform (ppr $ mkAsmTempEndLabel marker) pprDwarfInfoOpen _ _ (DwarfSrcNote ss) = ===================================== compiler/GHC/CmmToAsm/PIC.hs ===================================== @@ -2,7 +2,7 @@ This module handles generation of position independent code and dynamic-linking related issues for the native code generator. - This depends both the architecture and OS, so we define it here + This depends on both the architecture and OS, so we define it here instead of in one of the architecture specific modules. Things outside this module which are related to this: @@ -62,20 +62,13 @@ import GHC.CmmToAsm.Config import GHC.Cmm.Dataflow.Collections import GHC.Cmm -import GHC.Cmm.CLabel ( CLabel, ForeignLabelSource(..), pprCLabel, - mkDynamicLinkerLabel, DynamicLinkerLabelInfo(..), - dynamicLinkerLabelInfo, mkPicBaseLabel, - labelDynamic, externallyVisibleCLabel ) - -import GHC.Cmm.CLabel ( mkForeignLabel ) - +import GHC.Cmm.CLabel import GHC.Types.Basic import GHC.Unit.Module import GHC.Utils.Outputable -import GHC.Driver.Session import GHC.Data.FastString @@ -573,21 +566,21 @@ pprGotDeclaration config = case (arch,os) of -- and one for non-PIC. -- -pprImportedSymbol :: DynFlags -> NCGConfig -> CLabel -> SDoc -pprImportedSymbol dflags config importedLbl = case (arch,os) of +pprImportedSymbol :: NCGConfig -> CLabel -> SDoc +pprImportedSymbol config importedLbl = case (arch,os) of (ArchX86, OSDarwin) | Just (CodeStub, lbl) <- dynamicLinkerLabelInfo importedLbl -> if not pic then vcat [ text ".symbol_stub", - text "L" <> pprCLabel dflags lbl <> ptext (sLit "$stub:"), - text "\t.indirect_symbol" <+> pprCLabel dflags lbl, - text "\tjmp *L" <> pprCLabel dflags lbl + text "L" <> ppr_lbl lbl <> ptext (sLit "$stub:"), + text "\t.indirect_symbol" <+> ppr_lbl lbl, + text "\tjmp *L" <> ppr_lbl lbl <> text "$lazy_ptr", - text "L" <> pprCLabel dflags lbl + text "L" <> ppr_lbl lbl <> text "$stub_binder:", - text "\tpushl $L" <> pprCLabel dflags lbl + text "\tpushl $L" <> ppr_lbl lbl <> text "$lazy_ptr", text "\tjmp dyld_stub_binding_helper" ] @@ -595,16 +588,16 @@ pprImportedSymbol dflags config importedLbl = case (arch,os) of vcat [ text ".section __TEXT,__picsymbolstub2," <> text "symbol_stubs,pure_instructions,25", - text "L" <> pprCLabel dflags lbl <> ptext (sLit "$stub:"), - text "\t.indirect_symbol" <+> pprCLabel dflags lbl, + text "L" <> ppr_lbl lbl <> ptext (sLit "$stub:"), + text "\t.indirect_symbol" <+> ppr_lbl lbl, text "\tcall ___i686.get_pc_thunk.ax", text "1:", - text "\tmovl L" <> pprCLabel dflags lbl + text "\tmovl L" <> ppr_lbl lbl <> text "$lazy_ptr-1b(%eax),%edx", text "\tjmp *%edx", - text "L" <> pprCLabel dflags lbl + text "L" <> ppr_lbl lbl <> text "$stub_binder:", - text "\tlea L" <> pprCLabel dflags lbl + text "\tlea L" <> ppr_lbl lbl <> text "$lazy_ptr-1b(%eax),%eax", text "\tpushl %eax", text "\tjmp dyld_stub_binding_helper" @@ -612,16 +605,16 @@ pprImportedSymbol dflags config importedLbl = case (arch,os) of $+$ vcat [ text ".section __DATA, __la_sym_ptr" <> (if pic then int 2 else int 3) <> text ",lazy_symbol_pointers", - text "L" <> pprCLabel dflags lbl <> ptext (sLit "$lazy_ptr:"), - text "\t.indirect_symbol" <+> pprCLabel dflags lbl, - text "\t.long L" <> pprCLabel dflags lbl + text "L" <> ppr_lbl lbl <> ptext (sLit "$lazy_ptr:"), + text "\t.indirect_symbol" <+> ppr_lbl lbl, + text "\t.long L" <> ppr_lbl lbl <> text "$stub_binder"] | Just (SymbolPtr, lbl) <- dynamicLinkerLabelInfo importedLbl -> vcat [ text ".non_lazy_symbol_pointer", - char 'L' <> pprCLabel dflags lbl <> text "$non_lazy_ptr:", - text "\t.indirect_symbol" <+> pprCLabel dflags lbl, + char 'L' <> ppr_lbl lbl <> text "$non_lazy_ptr:", + text "\t.indirect_symbol" <+> ppr_lbl lbl, text "\t.long\t0"] | otherwise @@ -644,8 +637,8 @@ pprImportedSymbol dflags config importedLbl = case (arch,os) of (_, OSAIX) -> case dynamicLinkerLabelInfo importedLbl of Just (SymbolPtr, lbl) -> vcat [ - text "LC.." <> pprCLabel dflags lbl <> char ':', - text "\t.long" <+> pprCLabel dflags lbl ] + text "LC.." <> ppr_lbl lbl <> char ':', + text "\t.long" <+> ppr_lbl lbl ] _ -> empty -- ELF / Linux @@ -682,8 +675,8 @@ pprImportedSymbol dflags config importedLbl = case (arch,os) of -> case dynamicLinkerLabelInfo importedLbl of Just (SymbolPtr, lbl) -> vcat [ - text ".LC_" <> pprCLabel dflags lbl <> char ':', - text "\t.quad" <+> pprCLabel dflags lbl ] + text ".LC_" <> ppr_lbl lbl <> char ':', + text "\t.quad" <+> ppr_lbl lbl ] _ -> empty _ | osElfTarget os @@ -696,8 +689,8 @@ pprImportedSymbol dflags config importedLbl = case (arch,os) of in vcat [ text ".section \".got2\", \"aw\"", - text ".LC_" <> pprCLabel dflags lbl <> char ':', - ptext symbolSize <+> pprCLabel dflags lbl ] + text ".LC_" <> ppr_lbl lbl <> char ':', + ptext symbolSize <+> ppr_lbl lbl ] -- PLT code stubs are generated automatically by the dynamic linker. _ -> empty @@ -705,8 +698,9 @@ pprImportedSymbol dflags config importedLbl = case (arch,os) of _ -> panic "PIC.pprImportedSymbol: no match" where platform = ncgPlatform config - arch = platformArch platform - os = platformOS platform + ppr_lbl = pprCLabel_NCG platform + arch = platformArch platform + os = platformOS platform pic = ncgPIC config -------------------------------------------------------------------------------- ===================================== compiler/GHC/CmmToLlvm/Base.hs ===================================== @@ -496,7 +496,8 @@ ghcInternalFunctions = do strCLabel_llvm :: CLabel -> LlvmM LMString strCLabel_llvm lbl = do dflags <- getDynFlags - let sdoc = pprCLabel dflags lbl + platform <- getPlatform + let sdoc = pprCLabel_LLVM platform lbl str = Outp.renderWithStyle (initSDocContext dflags (Outp.mkCodeStyle Outp.CStyle)) sdoc ===================================== compiler/GHC/HsToCore.hs ===================================== @@ -140,7 +140,7 @@ deSugar hsc_env ; (ds_fords, foreign_prs) <- dsForeigns fords ; ds_rules <- mapMaybeM dsRule rules ; let hpc_init - | gopt Opt_Hpc dflags = hpcInitCode mod ds_hpc_info + | gopt Opt_Hpc dflags = hpcInitCode (hsc_dflags hsc_env) mod ds_hpc_info | otherwise = empty ; return ( ds_ev_binds , foreign_prs `appOL` core_prs `appOL` spec_prs ===================================== compiler/GHC/HsToCore/Coverage.hs ===================================== @@ -1315,9 +1315,9 @@ static void hpc_init_Main(void) hs_hpc_module("Main",8,1150288664,_hpc_tickboxes_Main_hpc);} -} -hpcInitCode :: Module -> HpcInfo -> SDoc -hpcInitCode _ (NoHpcInfo {}) = Outputable.empty -hpcInitCode this_mod (HpcInfo tickCount hashNo) +hpcInitCode :: DynFlags -> Module -> HpcInfo -> SDoc +hpcInitCode _ _ (NoHpcInfo {}) = Outputable.empty +hpcInitCode dflags this_mod (HpcInfo tickCount hashNo) = vcat [ text "static void hpc_init_" <> ppr this_mod <> text "(void) __attribute__((constructor));" @@ -1335,7 +1335,9 @@ hpcInitCode this_mod (HpcInfo tickCount hashNo) ]) ] where - tickboxes = ppr (mkHpcTicksLabel $ this_mod) + platform = targetPlatform dflags + bcknd = backend dflags + tickboxes = pprCLabel bcknd platform (mkHpcTicksLabel $ this_mod) module_name = hcat (map (text.charToC) $ BS.unpack $ bytesFS (moduleNameFS (moduleName this_mod))) ===================================== compiler/GHC/StgToCmm.hs ===================================== @@ -247,7 +247,7 @@ cgDataCon data_con , rep_ty <- typePrimRep (scaledThing ty) , not (isVoidRep rep_ty) ] - ; emitClosureAndInfoTable dyn_info_tbl NativeDirectCall [] $ + ; emitClosureAndInfoTable platform dyn_info_tbl NativeDirectCall [] $ -- NB: the closure pointer is assumed *untagged* on -- entry to a constructor. If the pointer is tagged, -- then we should not be entering it. This assumption ===================================== compiler/GHC/StgToCmm/Bind.hs ===================================== @@ -558,7 +558,7 @@ mkSlowEntryCode bndr cl_info arg_regs -- function closure is already in `Node' = do profile <- getProfile platform <- getPlatform let node = idToReg platform (NonVoid bndr) - slow_lbl = closureSlowEntryLabel cl_info + slow_lbl = closureSlowEntryLabel platform cl_info fast_lbl = closureLocalEntryLabel platform cl_info -- mkDirectJump does not clobber `Node' containing function closure jump = mkJump profile NativeNodeCall ===================================== compiler/GHC/StgToCmm/Closure.hs ===================================== @@ -785,16 +785,16 @@ isToplevClosure (ClosureInfo { closureLFInfo = lf_info }) -- Label generation -------------------------------------- -staticClosureLabel :: ClosureInfo -> CLabel -staticClosureLabel = toClosureLbl . closureInfoLabel +staticClosureLabel :: Platform -> ClosureInfo -> CLabel +staticClosureLabel platform = toClosureLbl platform . closureInfoLabel -closureSlowEntryLabel :: ClosureInfo -> CLabel -closureSlowEntryLabel = toSlowEntryLbl . closureInfoLabel +closureSlowEntryLabel :: Platform -> ClosureInfo -> CLabel +closureSlowEntryLabel platform = toSlowEntryLbl platform . closureInfoLabel closureLocalEntryLabel :: Platform -> ClosureInfo -> CLabel closureLocalEntryLabel platform - | platformTablesNextToCode platform = toInfoLbl . closureInfoLabel - | otherwise = toEntryLbl . closureInfoLabel + | platformTablesNextToCode platform = toInfoLbl platform . closureInfoLabel + | otherwise = toEntryLbl platform . closureInfoLabel mkClosureInfoTableLabel :: Platform -> Id -> LambdaFormInfo -> CLabel mkClosureInfoTableLabel platform id lf_info ===================================== compiler/GHC/StgToCmm/Heap.hs ===================================== @@ -333,17 +333,19 @@ entryHeapCheck :: ClosureInfo -> FCode () -> FCode () -entryHeapCheck cl_info nodeSet arity args code - = entryHeapCheck' is_fastf node arity args code - where +entryHeapCheck cl_info nodeSet arity args code = do + platform <- getPlatform + let node = case nodeSet of Just r -> CmmReg (CmmLocal r) - Nothing -> CmmLit (CmmLabel $ staticClosureLabel cl_info) + Nothing -> CmmLit (CmmLabel $ staticClosureLabel platform cl_info) is_fastf = case closureFunInfo cl_info of Just (_, ArgGen _) -> False _otherwise -> True + entryHeapCheck' is_fastf node arity args code + -- | lower-level version for "GHC.Cmm.Parser" entryHeapCheck' :: Bool -- is a known function pattern -> CmmExpr -- expression for the closure pointer ===================================== compiler/GHC/StgToCmm/Layout.hs ===================================== @@ -617,15 +617,15 @@ emitClosureProcAndInfoTable top_lvl bndr lf_info info_tbl args body conv = if nodeMustPointToIt profile lf_info then NativeNodeCall else NativeDirectCall (offset, _, _) = mkCallEntry profile conv args' [] - ; emitClosureAndInfoTable info_tbl conv args' $ body (offset, node, arg_regs) + ; emitClosureAndInfoTable (profilePlatform profile) info_tbl conv args' $ body (offset, node, arg_regs) } -- Data constructors need closures, but not with all the argument handling -- needed for functions. The shared part goes here. -emitClosureAndInfoTable :: - CmmInfoTable -> Convention -> [LocalReg] -> FCode () -> FCode () -emitClosureAndInfoTable info_tbl conv args body +emitClosureAndInfoTable + :: Platform -> CmmInfoTable -> Convention -> [LocalReg] -> FCode () -> FCode () +emitClosureAndInfoTable platform info_tbl conv args body = do { (_, blks) <- getCodeScoped body - ; let entry_lbl = toEntryLbl (cit_lbl info_tbl) + ; let entry_lbl = toEntryLbl platform (cit_lbl info_tbl) ; emitProcWithConvention conv (Just info_tbl) entry_lbl args blks } ===================================== rts/Hpc.c ===================================== @@ -241,8 +241,8 @@ startupHpc(void) /* * Called on a per-module basis, by a constructor function compiled - * with each module (see Coverage.hpcInitCode), declaring where the - * tix boxes are stored in memory. This memory can be uninitized, + * with each module (see GHC.HsToCore.Coverage.hpcInitCode), declaring + * where the tix boxes are stored in memory. This memory can be uninitized, * because we will initialize it with either the contents of the tix * file, or all zeros. * View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/380638a33691ba43fdcd2e18bca636750e5f66f1...3b15dc3cfb1a33e3d4d952af62d4d0b841a731f5 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/380638a33691ba43fdcd2e18bca636750e5f66f1...3b15dc3cfb1a33e3d4d952af62d4d0b841a731f5 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 1 08:23:10 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sat, 01 Aug 2020 04:23:10 -0400 Subject: [Git][ghc/ghc][master] Test case for #17652 Message-ID: <5f25266ef50d_80b3f849420ad9860658c4@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 3 changed files: - + testsuite/tests/haddock/should_compile_flag_haddock/T17652.hs - + testsuite/tests/haddock/should_compile_flag_haddock/T17652.stderr - testsuite/tests/haddock/should_compile_flag_haddock/all.T Changes: ===================================== testsuite/tests/haddock/should_compile_flag_haddock/T17652.hs ===================================== @@ -0,0 +1,8 @@ +module T17652 where + +data X + = B + -- | x + !Int + -- | y + String ===================================== testsuite/tests/haddock/should_compile_flag_haddock/T17652.stderr ===================================== @@ -0,0 +1,6 @@ + +==================== Parser ==================== +module T17652 where +data X = B !Int " x" String " y" + + ===================================== testsuite/tests/haddock/should_compile_flag_haddock/all.T ===================================== @@ -62,3 +62,4 @@ test('T17544_kw', normal, compile, ['-haddock -Winvalid-haddock -ddump-parsed-as test('haddockExtraDocs', normal, compile, ['-haddock -Winvalid-haddock']) test('haddockTySyn', normal, compile, ['-haddock -Winvalid-haddock -ddump-parsed']) test('T8944', normal, compile, ['-haddock -Winvalid-haddock -ddump-parsed']) +test('T17652', normal, compile, ['-haddock -Winvalid-haddock -ddump-parsed']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e30fed6c6de1f881ce313900274294a793e42677 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e30fed6c6de1f881ce313900274294a793e42677 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 1 15:41:08 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sat, 01 Aug 2020 11:41:08 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T17962b Message-ID: <5f258d1417a49_80b104e15b46081360@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T17962b at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T17962b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 1 16:11:06 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sat, 01 Aug 2020 12:11:06 -0400 Subject: [Git][ghc/ghc][wip/T17962b] 19 commits: Fix typo in haddock Message-ID: <5f25941abcadd_80b3f849420ad9860833c7@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - abd5ef48 by Ben Gamari at 2020-08-01T12:10:53-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - d2c2468a by Ben Gamari at 2020-08-01T12:10:53-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 30 changed files: - aclocal.m4 - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Utils.hs - compiler/GHC/Driver/Make.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Rename/Bind.hs - compiler/GHC/Rename/Expr.hs - compiler/GHC/Rename/HsType.hs - compiler/GHC/Rename/Module.hs - compiler/GHC/Rename/Pat.hs - compiler/GHC/Rename/Utils.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - compiler/GHC/Tc/Deriv.hs - compiler/GHC/Tc/Deriv/Functor.hs - compiler/GHC/Tc/Deriv/Generate.hs - compiler/GHC/Tc/Deriv/Infer.hs - compiler/GHC/Tc/Deriv/Utils.hs - compiler/GHC/Tc/Instance/Class.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Types/Name/Reader.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - ghc.mk - hadrian/cfg/system.config.in The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b101ec2bccc70ae611383d4b3b6bd3c5d28a0692...d2c2468ab3b03d5d4f411b71bda1a8ae22b5da2d -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b101ec2bccc70ae611383d4b3b6bd3c5d28a0692...d2c2468ab3b03d5d4f411b71bda1a8ae22b5da2d You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 1 17:01:36 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sat, 01 Aug 2020 13:01:36 -0400 Subject: [Git][ghc/ghc][wip/T17962b] 2 commits: Refactor handling of object merging Message-ID: <5f259ff0a81e7_80b3f849c1caa1060855c7@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: f340dece by Ben Gamari at 2020-08-01T13:01:30-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - b6f6ae2f by Ben Gamari at 2020-08-01T13:01:30-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 23 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Cabal.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk - utils/iserv/ghc.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + else + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + AC_MSG_RESULT(affected, using $SettingsMergeObjectsCommand to merge objects) + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + fi + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -2140,29 +2140,7 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = GHC.SysTools.runLink dflags ([ - GHC.SysTools.Option "-nostdlib", - GHC.SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in GHC.Driver.Session - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [GHC.SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [GHC.SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [GHC.SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [GHC.SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args cc = GHC.SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] ++ [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" | OSMinGW32 == osInfo @@ -2176,7 +2154,7 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] ccInfo <- getCompilerInfo dflags ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -102,6 +102,7 @@ module GHC.Driver.Session ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -120,6 +121,7 @@ module GHC.Driver.Session ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -142,10 +144,10 @@ module GHC.Driver.Session ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -940,6 +942,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -986,6 +990,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/GHC/Settings.hs ===================================== @@ -28,6 +28,7 @@ module GHC.Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -46,6 +47,7 @@ module GHC.Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -99,6 +101,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -124,6 +127,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] @@ -200,6 +204,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -236,6 +242,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -137,6 +137,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -183,6 +185,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -201,6 +204,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -299,6 +299,13 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== configure.ac ===================================== @@ -602,13 +602,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -96,6 +96,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -115,6 +115,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -138,6 +144,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -99,6 +99,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -127,9 +127,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -311,6 +312,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -91,6 +91,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -109,6 +110,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -176,6 +179,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -191,6 +195,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -294,6 +294,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -101,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Cabal.hs ===================================== @@ -148,7 +148,7 @@ cppArgs = do withBuilderKey :: Builder -> String withBuilderKey b = case b of Ar _ _ -> "--with-ar=" - Ld _ -> "--with-ld=" + MergeObjects _ -> "--with-ld=" Cc _ _ -> "--with-gcc=" Ghc _ _ -> "--with-ghc=" Alex -> "--with-alex=" ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -37,6 +37,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -244,6 +245,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -223,6 +223,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -500,6 +500,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -733,7 +735,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" ===================================== utils/iserv/ghc.mk ===================================== @@ -30,9 +30,8 @@ endif # refer to the RTS. This is harmless if you don't use it (adds a bit # of overhead to startup and increases the binary sizes) but if you # need it there's no alternative. -# Don't do this on FreeBSD to work around #17962. ifeq "$(TargetElf)" "YES" -ifeq "$(findstring $(TargetOS_CPP), solaris2 freebsd)" "" +ifneq "$(TargetOS_CPP)" "solaris2" # The Solaris linker does not support --export-dynamic option. It also # does not need it since it exports all dynamic symbols by default utils/iserv_stage2_MORE_HC_OPTS += -optl-Wl,--export-dynamic View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d2c2468ab3b03d5d4f411b71bda1a8ae22b5da2d...b6f6ae2ff6c650540a7978e01b42f38ace4d3890 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d2c2468ab3b03d5d4f411b71bda1a8ae22b5da2d...b6f6ae2ff6c650540a7978e01b42f38ace4d3890 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 1 17:26:21 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sat, 01 Aug 2020 13:26:21 -0400 Subject: [Git][ghc/ghc][wip/T17962b] 2 commits: Refactor handling of object merging Message-ID: <5f25a5bd8cbfb_80b104e15b460864f6@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: 2f4e7e22 by Ben Gamari at 2020-08-01T13:26:14-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 0032f0e3 by Ben Gamari at 2020-08-01T13:26:14-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 23 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Cabal.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk - utils/iserv/ghc.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + else + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + AC_MSG_RESULT(affected, using $SettingsMergeObjectsCommand to merge objects) + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + fi + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -2140,31 +2140,9 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = GHC.SysTools.runLink dflags ([ - GHC.SysTools.Option "-nostdlib", - GHC.SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in GHC.Driver.Session - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [GHC.SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [GHC.SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [GHC.SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [GHC.SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args cc = GHC.SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" + [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" | OSMinGW32 == osInfo , not $ target32Bit (targetPlatform dflags) ] @@ -2176,7 +2154,7 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] ccInfo <- getCompilerInfo dflags ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -102,6 +102,7 @@ module GHC.Driver.Session ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -120,6 +121,7 @@ module GHC.Driver.Session ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -142,10 +144,10 @@ module GHC.Driver.Session ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -940,6 +942,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -986,6 +990,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/GHC/Settings.hs ===================================== @@ -28,6 +28,7 @@ module GHC.Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -46,6 +47,7 @@ module GHC.Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -99,6 +101,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -124,6 +127,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] @@ -200,6 +204,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -236,6 +242,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -137,6 +137,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -183,6 +185,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -201,6 +204,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -299,6 +299,13 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== configure.ac ===================================== @@ -602,13 +602,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -96,6 +96,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -115,6 +115,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -138,6 +144,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -99,6 +99,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -127,9 +127,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -311,6 +312,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -91,6 +91,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -109,6 +110,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -176,6 +179,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -191,6 +195,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -294,6 +294,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -101,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Cabal.hs ===================================== @@ -148,7 +148,7 @@ cppArgs = do withBuilderKey :: Builder -> String withBuilderKey b = case b of Ar _ _ -> "--with-ar=" - Ld _ -> "--with-ld=" + MergeObjects _ -> "--with-ld=" Cc _ _ -> "--with-gcc=" Ghc _ _ -> "--with-ghc=" Alex -> "--with-alex=" ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -37,6 +37,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -244,6 +245,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -223,6 +223,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -500,6 +500,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -733,7 +735,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" ===================================== utils/iserv/ghc.mk ===================================== @@ -30,9 +30,8 @@ endif # refer to the RTS. This is harmless if you don't use it (adds a bit # of overhead to startup and increases the binary sizes) but if you # need it there's no alternative. -# Don't do this on FreeBSD to work around #17962. ifeq "$(TargetElf)" "YES" -ifeq "$(findstring $(TargetOS_CPP), solaris2 freebsd)" "" +ifneq "$(TargetOS_CPP)" "solaris2" # The Solaris linker does not support --export-dynamic option. It also # does not need it since it exports all dynamic symbols by default utils/iserv_stage2_MORE_HC_OPTS += -optl-Wl,--export-dynamic View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b6f6ae2ff6c650540a7978e01b42f38ace4d3890...0032f0e3ca13716b80a829134beec8128b5b7bf3 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b6f6ae2ff6c650540a7978e01b42f38ace4d3890...0032f0e3ca13716b80a829134beec8128b5b7bf3 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 1 17:35:21 2020 From: gitlab at gitlab.haskell.org (Ryan Scott) Date: Sat, 01 Aug 2020 13:35:21 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18521 Message-ID: <5f25a7d9abb0e_80b3f8496224a70608967f@gitlab.haskell.org.mail> Ryan Scott pushed new branch wip/T18521 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18521 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 1 17:41:15 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sat, 01 Aug 2020 13:41:15 -0400 Subject: [Git][ghc/ghc][wip/T17962b] 2 commits: Refactor handling of object merging Message-ID: <5f25a93bf593_80b3f849c1caa1060935e7@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: 9c8bcba3 by Ben Gamari at 2020-08-01T13:41:08-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - aef73e79 by Ben Gamari at 2020-08-01T13:41:08-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 23 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Cabal.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk - utils/iserv/ghc.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + else + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + AC_MSG_RESULT(affected, using $SettingsMergeObjectsCommand to merge objects) + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + fi + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -2140,31 +2140,9 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = GHC.SysTools.runLink dflags ([ - GHC.SysTools.Option "-nostdlib", - GHC.SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in GHC.Driver.Session - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [GHC.SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [GHC.SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [GHC.SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [GHC.SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args = GHC.SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" + [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" | OSMinGW32 == osInfo , not $ target32Bit (targetPlatform dflags) ] @@ -2176,25 +2154,24 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] - ccInfo <- getCompilerInfo dflags if ldIsGnuLd then do script <- newTempName dflags TFL_CurrentModule "ldscript" cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [GHC.SysTools.FileOption "" script] ccInfo + ld_r [GHC.SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files ld_r [GHC.SysTools.Option "-Wl,-filelist", - GHC.SysTools.FileOption "-Wl," filelist] ccInfo + GHC.SysTools.FileOption "-Wl," filelist] else do - ld_r (map (GHC.SysTools.FileOption "") o_files) ccInfo + ld_r (map (GHC.SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -102,6 +102,7 @@ module GHC.Driver.Session ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -120,6 +121,7 @@ module GHC.Driver.Session ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -142,10 +144,10 @@ module GHC.Driver.Session ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -940,6 +942,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -986,6 +990,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/GHC/Settings.hs ===================================== @@ -28,6 +28,7 @@ module GHC.Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -46,6 +47,7 @@ module GHC.Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -99,6 +101,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -124,6 +127,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] @@ -200,6 +204,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -236,6 +242,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -137,6 +137,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -183,6 +185,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -201,6 +204,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -299,6 +299,13 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== configure.ac ===================================== @@ -602,13 +602,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -96,6 +96,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -115,6 +115,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -138,6 +144,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -99,6 +99,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -127,9 +127,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -311,6 +312,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -91,6 +91,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -109,6 +110,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -176,6 +179,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -191,6 +195,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -294,6 +294,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -101,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Cabal.hs ===================================== @@ -148,7 +148,7 @@ cppArgs = do withBuilderKey :: Builder -> String withBuilderKey b = case b of Ar _ _ -> "--with-ar=" - Ld _ -> "--with-ld=" + MergeObjects _ -> "--with-ld=" Cc _ _ -> "--with-gcc=" Ghc _ _ -> "--with-ghc=" Alex -> "--with-alex=" ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -37,6 +37,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -244,6 +245,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -223,6 +223,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -500,6 +500,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -733,7 +735,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" ===================================== utils/iserv/ghc.mk ===================================== @@ -30,9 +30,8 @@ endif # refer to the RTS. This is harmless if you don't use it (adds a bit # of overhead to startup and increases the binary sizes) but if you # need it there's no alternative. -# Don't do this on FreeBSD to work around #17962. ifeq "$(TargetElf)" "YES" -ifeq "$(findstring $(TargetOS_CPP), solaris2 freebsd)" "" +ifneq "$(TargetOS_CPP)" "solaris2" # The Solaris linker does not support --export-dynamic option. It also # does not need it since it exports all dynamic symbols by default utils/iserv_stage2_MORE_HC_OPTS += -optl-Wl,--export-dynamic View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0032f0e3ca13716b80a829134beec8128b5b7bf3...aef73e79c4d4d47c81a144a1fa6e8e84ed7d0193 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0032f0e3ca13716b80a829134beec8128b5b7bf3...aef73e79c4d4d47c81a144a1fa6e8e84ed7d0193 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 1 18:19:23 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sat, 01 Aug 2020 14:19:23 -0400 Subject: [Git][ghc/ghc][wip/T17962b] 2 commits: Refactor handling of object merging Message-ID: <5f25b22b15d2e_80b3f849a265454610289e@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: 437ecd54 by Ben Gamari at 2020-08-01T14:19:14-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 626d13e8 by Ben Gamari at 2020-08-01T14:19:14-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 22 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk - utils/iserv/ghc.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + else + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + AC_MSG_RESULT(affected, using $SettingsMergeObjectsCommand to merge objects) + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + fi + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -2140,31 +2140,9 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = GHC.SysTools.runLink dflags ([ - GHC.SysTools.Option "-nostdlib", - GHC.SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in GHC.Driver.Session - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [GHC.SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [GHC.SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [GHC.SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [GHC.SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args = GHC.SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" + [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" | OSMinGW32 == osInfo , not $ target32Bit (targetPlatform dflags) ] @@ -2176,25 +2154,24 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] - ccInfo <- getCompilerInfo dflags if ldIsGnuLd then do script <- newTempName dflags TFL_CurrentModule "ldscript" cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [GHC.SysTools.FileOption "" script] ccInfo + ld_r [GHC.SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files ld_r [GHC.SysTools.Option "-Wl,-filelist", - GHC.SysTools.FileOption "-Wl," filelist] ccInfo + GHC.SysTools.FileOption "-Wl," filelist] else do - ld_r (map (GHC.SysTools.FileOption "") o_files) ccInfo + ld_r (map (GHC.SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -102,6 +102,7 @@ module GHC.Driver.Session ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -120,6 +121,7 @@ module GHC.Driver.Session ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -142,10 +144,10 @@ module GHC.Driver.Session ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -940,6 +942,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -986,6 +990,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/GHC/Settings.hs ===================================== @@ -28,6 +28,7 @@ module GHC.Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -46,6 +47,7 @@ module GHC.Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -99,6 +101,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -124,6 +127,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] @@ -200,6 +204,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -236,6 +242,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -137,6 +137,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -183,6 +185,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -201,6 +204,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -299,6 +299,13 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== configure.ac ===================================== @@ -602,13 +602,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -96,6 +96,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -115,6 +115,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -138,6 +144,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -99,6 +99,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -127,9 +127,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -311,6 +312,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -91,6 +91,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -109,6 +110,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -176,6 +179,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -191,6 +195,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -294,6 +294,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -101,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -37,6 +37,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -244,6 +245,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -223,6 +223,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -500,6 +500,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -733,7 +735,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" ===================================== utils/iserv/ghc.mk ===================================== @@ -30,9 +30,8 @@ endif # refer to the RTS. This is harmless if you don't use it (adds a bit # of overhead to startup and increases the binary sizes) but if you # need it there's no alternative. -# Don't do this on FreeBSD to work around #17962. ifeq "$(TargetElf)" "YES" -ifeq "$(findstring $(TargetOS_CPP), solaris2 freebsd)" "" +ifneq "$(TargetOS_CPP)" "solaris2" # The Solaris linker does not support --export-dynamic option. It also # does not need it since it exports all dynamic symbols by default utils/iserv_stage2_MORE_HC_OPTS += -optl-Wl,--export-dynamic View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/aef73e79c4d4d47c81a144a1fa6e8e84ed7d0193...626d13e8e7a538aba176aeceeed06dc8d6538fc7 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/aef73e79c4d4d47c81a144a1fa6e8e84ed7d0193...626d13e8e7a538aba176aeceeed06dc8d6538fc7 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 1 18:52:19 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sat, 01 Aug 2020 14:52:19 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18070 Message-ID: <5f25b9e3d90aa_80b3f848a2ebd5c61054d@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T18070 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18070 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 2 14:34:11 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sun, 02 Aug 2020 10:34:11 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 3 commits: Test case for #17652 Message-ID: <5f26cee32537c_80b3f8468e02b5461349bd@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 1a23a7dd by Ryan Scott at 2020-08-02T10:34:03-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - 94bfcb1c by Leon Schoorl at 2020-08-02T10:34:03-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 16 changed files: - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Parser/PostProcess/Haddock.hs - compiler/GHC/Rename/Module.hs - compiler/GHC/ThToHs.hs - includes/ghc.mk - testsuite/tests/haddock/should_compile_flag_haddock/T17544.stderr - testsuite/tests/haddock/should_compile_flag_haddock/T17544_kw.stderr - + testsuite/tests/haddock/should_compile_flag_haddock/T17652.hs - + testsuite/tests/haddock/should_compile_flag_haddock/T17652.stderr - testsuite/tests/haddock/should_compile_flag_haddock/all.T - testsuite/tests/parser/should_compile/T15323.stderr Changes: ===================================== compiler/GHC/Hs/Decls.hs ===================================== @@ -71,7 +71,7 @@ module GHC.Hs.Decls ( ForeignDecl(..), LForeignDecl, ForeignImport(..), ForeignExport(..), CImportSpec(..), -- ** Data-constructor declarations - ConDecl(..), LConDecl, ConDeclGADTPrefixPs(..), + ConDecl(..), LConDecl, HsConDeclDetails, hsConDeclArgTys, hsConDeclTheta, getConNames, getConArgs, -- ** Document comments @@ -111,7 +111,6 @@ import GHC.Core.Coercion import GHC.Types.ForeignCall import GHC.Hs.Extension import GHC.Types.Name -import GHC.Types.Name.Reader import GHC.Types.Name.Set -- others: @@ -1437,12 +1436,13 @@ data ConDecl pass { con_g_ext :: XConDeclGADT pass , con_names :: [XRec pass (IdP pass)] - -- The next four fields describe the type after the '::' + -- The following fields describe the type after the '::' -- See Note [GADT abstract syntax] - -- The following field is Located to anchor API Annotations, - -- AnnForall and AnnDot. , con_forall :: XRec pass Bool -- ^ True <=> explicit forall -- False => hsq_explicit is empty + -- + -- The 'XRec' is used to anchor API + -- annotations, AnnForall and AnnDot. , con_qvars :: [LHsTyVarBndr Specificity pass] -- Whether or not there is an /explicit/ forall, we still -- need to capture the implicitly-bound type/kind variables @@ -1479,25 +1479,18 @@ type instance XConDeclGADT GhcTc = NoExtField type instance XConDeclH98 (GhcPass _) = NoExtField -type instance XXConDecl GhcPs = ConDeclGADTPrefixPs -type instance XXConDecl GhcRn = NoExtCon -type instance XXConDecl GhcTc = NoExtCon - --- | Stores the types of prefix GADT constructors in the parser. This is used --- in lieu of ConDeclGADT, which requires knowing the specific argument and --- result types, as this is difficult to determine in general in the parser. --- See @Note [GADT abstract syntax]@. -data ConDeclGADTPrefixPs = ConDeclGADTPrefixPs - { con_gp_names :: [Located RdrName] - -- ^ The GADT constructor declaration's names. - , con_gp_ty :: LHsSigType GhcPs - -- ^ The type after the @::@. - , con_gp_doc :: Maybe LHsDocString - -- ^ A possible Haddock comment. - } +type instance XXConDecl (GhcPass _) = NoExtCon {- Note [GADT abstract syntax] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The types of both forms of GADT constructors are very structured, as they +must consist of the quantified type variables (if provided), followed by the +context (if provided), followed by the argument types (if provided), followed +by the result type. (See "Wrinkle: No nested foralls or contexts" below for +more discussion on the restrictions imposed here.) As a result, instead of +storing the type of a GADT constructor as a single LHsType, we split it up +into its constituent components for easier access. + There are two broad ways to classify GADT constructors: * Record-syntax constructors. For example: @@ -1510,48 +1503,45 @@ There are two broad ways to classify GADT constructors: data T a where K :: forall a. Ord a => [a] -> ... -> T a -Initially, both forms of GADT constructors are initially parsed as a single -LHsType. However, GADTs have a certain structure, requiring distinct argument -and result types, as well as imposing restrictions on where `forall`s and -contexts can be (see "Wrinkle: No nested foralls or contexts" below). As a -result, it is convenient to split up the LHsType into its individual -components, which are stored in the ConDeclGADT constructor of ConDecl. - -Where should this splitting occur? For GADT constructors with record syntax, -we split in the parser (in GHC.Parser.PostProcess.mkGadtDecl). We must do this -splitting before the renamer, as we need the record field names for use in -GHC.Hs.Utils.hsConDeclsBinders. +This distinction is recorded in the `con_args :: HsConDetails pass`, which +tracks if we're dealing with a RecCon or PrefixCon. It is easy to distinguish +the two in the AST since record GADT constructors use HsRecTy. This distinction +is made in GHC.Parser.PostProcess.mkGadtDecl. -For prefix GADT constructors, however, the situation is more complicated. It -can be difficult to split a prefix GADT type until we know type operator -fixities. Consider this, for example: +It is worth elaborating a bit more on the process of splitting the argument +types of a GADT constructor, since there are some non-obvious details involved. +While splitting the argument types of a record GADT constructor is easy (they +are stored in an HsRecTy), splitting the arguments of a prefix GADT constructor +is trickier. The basic idea is that we must split along the outermost function +arrows ((->) and (#->)) in the type, which GHC.Hs.Type.splitHsFunType +accomplishes. But what about type operators? Consider: C :: a :*: b -> a :*: b -> a :+: b -Initially, the type of C will parse as: +This could parse in many different ways depending on the precedences of each +type operator. In particular, if (:*:) were to have lower precedence than (->), +then it could very well parse like this: - a :*: (b -> (a :*: (b -> (a :+: b)))) + a :*: ((b -> a) :*: ((b -> a) :+: b))) -So it's hard to split up the arguments until we've done the precedence -resolution (in the renamer). (Unlike prefix GADT types, record GADT types -do not have this problem because of their uniform syntax.) +This would give the false impression that the whole type is part of one large +return type, with no arguments. Note that we do not fully resolve the exact +precedences of each user-defined type operator until the renamer, so this a +more difficult task for the parser. -As a result, we deliberately avoid splitting prefix GADT types in the parser. -Instead, we store the entire LHsType in ConDeclGADTPrefixPs, a GHC-specific -extension constructor to ConDecl. Later, in the renamer -(in GHC.Rename.Module.rnConDecl), we resolve the fixities of all type operators -in the LHsType, which facilitates splitting it into argument and result types -accurately. We finish renaming a ConDeclGADTPrefixPs by putting the split -components into a ConDeclGADT. This is why ConDeclGADTPrefixPs has the suffix --Ps, as it is only used by the parser. +Fortunately, there is no risk of the above happening. GHC's parser gives +special treatment to function arrows, and as a result, they are always parsed +with a lower precedence than any other type operator. As a result, the type +above is actually parsed like this: -Note that the existence of ConDeclGADTPrefixPs does not imply that ConDeclGADT -goes completely unused by the parser. Other consumers of GHC's abstract syntax -are still free to use ConDeclGADT. Indeed, both Haddock and Template Haskell -construct values of type `ConDecl GhcPs` by way of ConDeclGADT, as neither of -them have the same difficulties with operator precedence that GHC's parser -does. As an example, see GHC.ThToHs.cvtConstr, which converts Template Haskell -syntax into GHC syntax. + (a :*: b) -> ((a :*: b) -> (a :+: b)) + +While we won't know the exact precedences of (:*:) and (:+:) until the renamer, +all we are concerned about in the parser is identifying the overall shape of +the argument and result types, which we can accomplish by piggybacking on the +special treatment given to function arrows. In a future where function arrows +aren't given special status in the parser, we will likely have to modify +GHC.Parser.PostProcess.mergeOps to preserve this trick. ----- -- Wrinkle: No nested foralls or contexts @@ -1681,14 +1671,6 @@ pp_condecls cs [] -> False (L _ ConDeclH98{} : _) -> False (L _ ConDeclGADT{} : _) -> True - (L _ (XConDecl x) : _) -> - case ghcPass @p of - GhcPs | ConDeclGADTPrefixPs{} <- x - -> True -#if __GLASGOW_HASKELL__ < 811 - GhcRn -> noExtCon x - GhcTc -> noExtCon x -#endif instance (OutputableBndrId p) => Outputable (ConDecl (GhcPass p)) where ppr = pprConDecl @@ -1730,16 +1712,6 @@ pprConDecl (ConDeclGADT { con_names = cons, con_qvars = qvars ppr_arrow_chain (a:as) = sep (a : map (arrow <+>) as) ppr_arrow_chain [] = empty -pprConDecl (XConDecl x) = - case ghcPass @p of - GhcPs | ConDeclGADTPrefixPs { con_gp_names = cons, con_gp_ty = ty - , con_gp_doc = doc } <- x - -> ppr_mbDoc doc <+> ppr_con_names cons <+> dcolon <+> ppr ty -#if __GLASGOW_HASKELL__ < 811 - GhcRn -> noExtCon x - GhcTc -> noExtCon x -#endif - ppr_con_names :: (OutputableBndr a) => [Located a] -> SDoc ppr_con_names = pprWithCommas (pprPrefixOcc . unLoc) ===================================== compiler/GHC/Hs/Instances.hs ===================================== @@ -168,8 +168,6 @@ deriving instance Data (ConDecl GhcPs) deriving instance Data (ConDecl GhcRn) deriving instance Data (ConDecl GhcTc) -deriving instance Data ConDeclGADTPrefixPs - -- deriving instance DataIdLR p p => Data (TyFamInstDecl p) deriving instance Data (TyFamInstDecl GhcPs) deriving instance Data (TyFamInstDecl GhcRn) ===================================== compiler/GHC/Hs/Type.hs ===================================== @@ -68,7 +68,7 @@ module GHC.Hs.Type ( splitLHsInstDeclTy, getLHsInstDeclHead, getLHsInstDeclClass_maybe, splitLHsPatSynTy, splitLHsForAllTyInvis, splitLHsForAllTyInvis_KP, splitLHsQualTy, - splitLHsSigmaTyInvis, splitLHsGADTPrefixTy, + splitLHsSigmaTyInvis, splitLHsGadtTy, splitHsFunType, hsTyGetAppHead_maybe, mkHsOpTy, mkHsAppTy, mkHsAppTys, mkHsAppKindTy, ignoreParens, hsSigType, hsSigWcType, hsPatSigType, @@ -1331,7 +1331,9 @@ mkHsAppKindTy ext ty k -- splitHsFunType decomposes a type (t1 -> t2 ... -> tn) -- Breaks up any parens in the result type: -- splitHsFunType (a -> (b -> c)) = ([a,b], c) -splitHsFunType :: LHsType GhcRn -> ([HsScaled GhcRn (LHsType GhcRn)], LHsType GhcRn) +splitHsFunType :: + LHsType (GhcPass p) + -> ([HsScaled (GhcPass p) (LHsType (GhcPass p))], LHsType (GhcPass p)) splitHsFunType (L _ (HsParTy _ ty)) = splitHsFunType ty @@ -1460,7 +1462,7 @@ splitLHsSigmaTyInvis_KP ty , (mb_ctxt, ty2) <- splitLHsQualTy_KP ty1 = (mb_tvbs, mb_ctxt, ty2) --- | Decompose a prefix GADT type into its constituent parts. +-- | Decompose a GADT type into its constituent parts. -- Returns @(mb_tvbs, mb_ctxt, body)@, where: -- -- * @mb_tvbs@ are @Just@ the leading @forall at s, if they are provided. @@ -1474,10 +1476,10 @@ splitLHsSigmaTyInvis_KP ty -- This function is careful not to look through parentheses. -- See @Note [GADT abstract syntax] (Wrinkle: No nested foralls or contexts)@ -- "GHC.Hs.Decls" for why this is important. -splitLHsGADTPrefixTy :: +splitLHsGadtTy :: LHsType (GhcPass pass) -> (Maybe [LHsTyVarBndr Specificity (GhcPass pass)], Maybe (LHsContext (GhcPass pass)), LHsType (GhcPass pass)) -splitLHsGADTPrefixTy = splitLHsSigmaTyInvis_KP +splitLHsGadtTy = splitLHsSigmaTyInvis_KP -- | Decompose a type of the form @forall . body@ into its constituent -- parts. Only splits type variable binders that ===================================== compiler/GHC/Hs/Utils.hs ===================================== @@ -1265,16 +1265,6 @@ hsConDeclsBinders cons (remSeen', flds) = get_flds remSeen args (ns, fs) = go remSeen' rs - XConDecl x -> case ghcPass @p of - GhcPs | ConDeclGADTPrefixPs { con_gp_names = names } <- x - -> (map (L loc . unLoc) names ++ ns, fs) -#if __GLASGOW_HASKELL__ < 811 - GhcRn -> noExtCon x - GhcTc -> noExtCon x -#endif - where - (ns, fs) = go remSeen rs - get_flds :: Seen p -> HsConDeclDetails (GhcPass p) -> (Seen p, [LFieldOcc (GhcPass p)]) get_flds remSeen (RecCon flds) ===================================== compiler/GHC/Parser.y ===================================== @@ -2176,8 +2176,9 @@ gadt_constr :: { LConDecl GhcPs } -- see Note [Difference in parsing GADT and data constructors] -- Returns a list because of: C,D :: ty : optSemi con_list '::' sigtype - {% ams (sLL $2 $> (mkGadtDecl (unLoc $2) $4)) - [mu AnnDcolon $3] } + {% do { decl <- mkGadtDecl (unLoc $2) $4 + ; ams (sLL $2 $> decl) + [mu AnnDcolon $3] } } {- Note [Difference in parsing GADT and data constructors] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -670,34 +670,41 @@ mkConDeclH98 name mb_forall mb_cxt args , con_doc = Nothing } -- | Construct a GADT-style data constructor from the constructor names and --- their type. This will return different AST forms for record syntax --- constructors and prefix constructors, as the latter must be handled --- specially in the renamer. See @Note [GADT abstract syntax]@ in --- "GHC.Hs.Decls" for the full story. +-- their type. Some interesting aspects of this function: +-- +-- * This splits up the constructor type into its quantified type variables (if +-- provided), context (if provided), argument types, and result type, and +-- records whether this is a prefix or record GADT constructor. See +-- Note [GADT abstract syntax] in "GHC.Hs.Decls" for more details. +-- +-- * If -XLinearTypes is not enabled, the function arrows in a prefix GADT +-- constructor are always interpreted as linear. If -XLinearTypes is enabled, +-- we faithfully record whether -> or #-> was used. mkGadtDecl :: [Located RdrName] -> LHsType GhcPs - -> ConDecl GhcPs -mkGadtDecl names ty - | Just (mtvs, mcxt, args, res_ty) <- mb_record_gadt ty - = ConDeclGADT { con_g_ext = noExtField - , con_names = names - , con_forall = L (getLoc ty) $ isJust mtvs - , con_qvars = fromMaybe [] mtvs - , con_mb_cxt = mcxt - , con_args = args - , con_res_ty = res_ty - , con_doc = Nothing } - | otherwise - = XConDecl $ ConDeclGADTPrefixPs { con_gp_names = names - , con_gp_ty = mkLHsSigType ty - , con_gp_doc = Nothing } + -> P (ConDecl GhcPs) +mkGadtDecl names ty = do + linearEnabled <- getBit LinearTypesBit + + let (args, res_ty) + | L _ (HsFunTy _ _w (L loc (HsRecTy _ rf)) res_ty) <- body_ty + = (RecCon (L loc rf), res_ty) + | otherwise + = let (arg_types, res_type) = splitHsFunType body_ty + arg_types' | linearEnabled = arg_types + | otherwise = map (hsLinear . hsScaledThing) arg_types + in (PrefixCon arg_types', res_type) + + pure $ ConDeclGADT { con_g_ext = noExtField + , con_names = names + , con_forall = L (getLoc ty) $ isJust mtvs + , con_qvars = fromMaybe [] mtvs + , con_mb_cxt = mcxt + , con_args = args + , con_res_ty = res_ty + , con_doc = Nothing } where - mb_record_gadt ty - | (mtvs, mcxt, body_ty) <- splitLHsGADTPrefixTy ty - , L _ (HsFunTy _ _w (L loc (HsRecTy _ rf)) res_ty) <- body_ty - = Just (mtvs, mcxt, RecCon (L loc rf), res_ty) - | otherwise - = Nothing + (mtvs, mcxt, body_ty) = splitLHsGadtTy ty setRdrNameSpace :: RdrName -> NameSpace -> RdrName -- ^ This rather gruesome function is used mainly by the parser. ===================================== compiler/GHC/Parser/PostProcess/Haddock.hs ===================================== @@ -716,15 +716,6 @@ instance HasHaddock (Located (ConDecl GhcPs)) where ConDeclH98 { con_ext, con_name, con_forall, con_ex_tvs, con_mb_cxt, con_doc = con_doc', con_args = RecCon (L l_rec flds') } - XConDecl (ConDeclGADTPrefixPs { con_gp_names, con_gp_ty }) -> do - -- discardHasInnerDocs is ok because we don't need this info for GADTs. - con_gp_doc' <- discardHasInnerDocs $ getConDoc (getLoc (head con_gp_names)) - con_gp_ty' <- addHaddock con_gp_ty - pure $ L l_con_decl $ - XConDecl (ConDeclGADTPrefixPs - { con_gp_names, - con_gp_ty = con_gp_ty', - con_gp_doc = con_gp_doc' }) -- Keep track of documentation comments on the data constructor or any of its -- fields. ===================================== compiler/GHC/Rename/Module.hs ===================================== @@ -1856,7 +1856,6 @@ rnDataDefn doc (HsDataDefn { dd_ND = new_or_data, dd_cType = cType where h98_style = case condecls of -- Note [Stupid theta] (L _ (ConDeclGADT {})) : _ -> False - (L _ (XConDecl (ConDeclGADTPrefixPs {}))) : _ -> False _ -> True rn_derivs (L loc ds) @@ -2246,6 +2245,12 @@ rnConDecl decl@(ConDeclGADT { con_names = names ; (new_args, fvs2) <- rnConDeclDetails (unLoc (head new_names)) ctxt args ; (new_res_ty, fvs3) <- rnLHsType ctxt res_ty + -- Ensure that there are no nested `forall`s or contexts, per + -- Note [GADT abstract syntax] (Wrinkle: No nested foralls or contexts) + -- in GHC.Hs.Type. + ; addNoNestedForallsContextsErr ctxt + (text "GADT constructor type signature") new_res_ty + ; let all_fvs = fvs1 `plusFV` fvs2 `plusFV` fvs3 ; traceRn "rnConDecl (ConDeclGADT)" @@ -2257,47 +2262,6 @@ rnConDecl decl@(ConDeclGADT { con_names = names , con_forall = forall }, -- Remove when #18311 is fixed all_fvs) } } --- This case is only used for prefix GADT constructors generated by GHC's --- parser, where we do not know the argument types until type operator --- precedence has been resolved. See Note [GADT abstract syntax] in --- GHC.Hs.Decls for the full story. -rnConDecl (XConDecl (ConDeclGADTPrefixPs { con_gp_names = names, con_gp_ty = ty - , con_gp_doc = mb_doc })) - = do { mapM_ (addLocM checkConName) names - ; new_names <- mapM lookupLocatedTopBndrRn names - ; mb_doc' <- rnMbLHsDoc mb_doc - - ; let ctxt = ConDeclCtx new_names - ; (ty', fvs) <- rnHsSigType ctxt TypeLevel ty - ; linearTypes <- xopt LangExt.LinearTypes <$> getDynFlags - - -- Now that operator precedence has been resolved, we can split the - -- GADT type into its individual components below. - ; let HsIB { hsib_ext = implicit_tkvs, hsib_body = body } = ty' - (mb_explicit_tkvs, mb_cxt, tau) = splitLHsGADTPrefixTy body - lhas_forall = L (getLoc body) $ isJust mb_explicit_tkvs - explicit_tkvs = fromMaybe [] mb_explicit_tkvs - (arg_tys, res_ty) = splitHsFunType tau - arg_details | linearTypes = PrefixCon arg_tys - | otherwise = PrefixCon $ map (hsLinear . hsScaledThing) arg_tys - - -- NB: The only possibility here is PrefixCon. RecCon is handled - -- separately, through ConDeclGADT, from the parser onwards. - - -- Ensure that there are no nested `forall`s or contexts, per - -- Note [GADT abstract syntax] (Wrinkle: No nested foralls or contexts) - -- in GHC.Hs.Type. - ; addNoNestedForallsContextsErr ctxt - (text "GADT constructor type signature") res_ty - - ; traceRn "rnConDecl (ConDeclGADTPrefixPs)" - (ppr names $$ ppr implicit_tkvs $$ ppr explicit_tkvs) - ; pure (ConDeclGADT { con_g_ext = implicit_tkvs, con_names = new_names - , con_forall = lhas_forall, con_qvars = explicit_tkvs - , con_mb_cxt = mb_cxt, con_args = arg_details - , con_res_ty = res_ty, con_doc = mb_doc' }, - fvs) } - rnMbContext :: HsDocContext -> Maybe (LHsContext GhcPs) -> RnM (Maybe (LHsContext GhcRn), FreeVars) rnMbContext _ Nothing = return (Nothing, emptyFVs) ===================================== compiler/GHC/ThToHs.hs ===================================== @@ -611,14 +611,6 @@ cvtConstr (ForallC tvs ctxt con) where all_tvs = tvs' ++ ex_tvs - -- The GadtC and RecGadtC cases of cvtConstr will always return a - -- ConDeclGADT, not a ConDeclGADTPrefixPs, so this case is unreachable. - -- See Note [GADT abstract syntax] in GHC.Hs.Decls for more on the - -- distinction between ConDeclGADT and ConDeclGADTPrefixPs. - add_forall _ _ con@(XConDecl (ConDeclGADTPrefixPs {})) = - pprPanic "cvtConstr.add_forall: Unexpected ConDeclGADTPrefixPs" - (Outputable.ppr con) - cvtConstr (GadtC [] _strtys _ty) = failWith (text "GadtC must have at least one constructor name") ===================================== includes/ghc.mk ===================================== @@ -163,7 +163,7 @@ $$(includes_$1_H_PLATFORM) : includes/ghc.mk includes/Makefile | $$$$(dir $$$$@) @echo "#if !defined(__GHCPLATFORM_H__)" > $$@ @echo "#define __GHCPLATFORM_H__" >> $$@ @echo >> $$@ - @echo "#define GHC_STAGE $1" >> $$@ + @echo "#define GHC_STAGE ($1 + 1)" >> $$@ @echo >> $$@ @echo "#define BuildPlatform_TYPE $(BuildPlatform_$1_CPP)" >> $$@ @echo "#define HostPlatform_TYPE $(HostPlatform_$1_CPP)" >> $$@ ===================================== testsuite/tests/haddock/should_compile_flag_haddock/T17544.stderr ===================================== @@ -372,31 +372,35 @@ (Nothing) (Nothing) [({ T17544.hs:25:5-18 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544.hs:25:5-8 } - (Unqual - {OccName: MkD5}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544.hs:25:5-8 } + (Unqual + {OccName: MkD5}))] + ({ T17544.hs:25:13-18 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544.hs:25:13-18 } + (HsAppTy (NoExtField) - ({ T17544.hs:25:13-18 } - (HsAppTy + ({ T17544.hs:25:13-14 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544.hs:25:13-14 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:25:13-14 } - (Unqual - {OccName: D5})))) + (Unqual + {OccName: D5})))) + ({ T17544.hs:25:16-18 } + (HsTyVar + (NoExtField) + (NotPromoted) ({ T17544.hs:25:16-18 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:25:16-18 } - (Unqual - {OccName: Int}))))))) - (Nothing))))] + (Unqual + {OccName: Int})))))) + (Nothing)))] ({ } []))))))] (Nothing))))) @@ -504,31 +508,35 @@ (Nothing) (Nothing) [({ T17544.hs:31:5-18 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544.hs:31:5-8 } - (Unqual - {OccName: MkD6}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544.hs:31:5-8 } + (Unqual + {OccName: MkD6}))] + ({ T17544.hs:31:13-18 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544.hs:31:13-18 } + (HsAppTy (NoExtField) - ({ T17544.hs:31:13-18 } - (HsAppTy + ({ T17544.hs:31:13-14 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544.hs:31:13-14 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:31:13-14 } - (Unqual - {OccName: D6})))) + (Unqual + {OccName: D6})))) + ({ T17544.hs:31:16-18 } + (HsTyVar + (NoExtField) + (NotPromoted) ({ T17544.hs:31:16-18 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:31:16-18 } - (Unqual - {OccName: Int}))))))) - (Nothing))))] + (Unqual + {OccName: Int})))))) + (Nothing)))] ({ } []))))))] (Nothing))))) @@ -636,31 +644,35 @@ (Nothing) (Nothing) [({ T17544.hs:37:5-18 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544.hs:37:5-8 } - (Unqual - {OccName: MkD7}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544.hs:37:5-8 } + (Unqual + {OccName: MkD7}))] + ({ T17544.hs:37:13-18 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544.hs:37:13-18 } + (HsAppTy (NoExtField) - ({ T17544.hs:37:13-18 } - (HsAppTy + ({ T17544.hs:37:13-14 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544.hs:37:13-14 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:37:13-14 } - (Unqual - {OccName: D7})))) + (Unqual + {OccName: D7})))) + ({ T17544.hs:37:16-18 } + (HsTyVar + (NoExtField) + (NotPromoted) ({ T17544.hs:37:16-18 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:37:16-18 } - (Unqual - {OccName: Int}))))))) - (Nothing))))] + (Unqual + {OccName: Int})))))) + (Nothing)))] ({ } []))))))] (Nothing))))) @@ -768,31 +780,35 @@ (Nothing) (Nothing) [({ T17544.hs:43:5-18 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544.hs:43:5-8 } - (Unqual - {OccName: MkD8}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544.hs:43:5-8 } + (Unqual + {OccName: MkD8}))] + ({ T17544.hs:43:13-18 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544.hs:43:13-18 } + (HsAppTy (NoExtField) - ({ T17544.hs:43:13-18 } - (HsAppTy + ({ T17544.hs:43:13-14 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544.hs:43:13-14 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:43:13-14 } - (Unqual - {OccName: D8})))) + (Unqual + {OccName: D8})))) + ({ T17544.hs:43:16-18 } + (HsTyVar + (NoExtField) + (NotPromoted) ({ T17544.hs:43:16-18 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:43:16-18 } - (Unqual - {OccName: Int}))))))) - (Nothing))))] + (Unqual + {OccName: Int})))))) + (Nothing)))] ({ } []))))))] (Nothing))))) @@ -900,31 +916,35 @@ (Nothing) (Nothing) [({ T17544.hs:49:5-18 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544.hs:49:5-8 } - (Unqual - {OccName: MkD9}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544.hs:49:5-8 } + (Unqual + {OccName: MkD9}))] + ({ T17544.hs:49:13-18 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544.hs:49:13-18 } + (HsAppTy (NoExtField) - ({ T17544.hs:49:13-18 } - (HsAppTy + ({ T17544.hs:49:13-14 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544.hs:49:13-14 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:49:13-14 } - (Unqual - {OccName: D9})))) + (Unqual + {OccName: D9})))) + ({ T17544.hs:49:16-18 } + (HsTyVar + (NoExtField) + (NotPromoted) ({ T17544.hs:49:16-18 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:49:16-18 } - (Unqual - {OccName: Int}))))))) - (Nothing))))] + (Unqual + {OccName: Int})))))) + (Nothing)))] ({ } []))))))] (Nothing))))) @@ -1032,31 +1052,35 @@ (Nothing) (Nothing) [({ T17544.hs:55:5-20 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544.hs:55:5-9 } - (Unqual - {OccName: MkD10}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544.hs:55:5-9 } + (Unqual + {OccName: MkD10}))] + ({ T17544.hs:55:14-20 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544.hs:55:14-20 } + (HsAppTy (NoExtField) - ({ T17544.hs:55:14-20 } - (HsAppTy + ({ T17544.hs:55:14-16 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544.hs:55:14-16 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:55:14-16 } - (Unqual - {OccName: D10})))) + (Unqual + {OccName: D10})))) + ({ T17544.hs:55:18-20 } + (HsTyVar + (NoExtField) + (NotPromoted) ({ T17544.hs:55:18-20 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:55:18-20 } - (Unqual - {OccName: Int}))))))) - (Nothing))))] + (Unqual + {OccName: Int})))))) + (Nothing)))] ({ } []))))))] (Nothing))))) ===================================== testsuite/tests/haddock/should_compile_flag_haddock/T17544_kw.stderr ===================================== @@ -30,24 +30,28 @@ (Nothing) (Nothing) [({ T17544_kw.hs:16:9-20 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544_kw.hs:16:9-13 } - (Unqual - {OccName: MkFoo}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544_kw.hs:16:9-13 } + (Unqual + {OccName: MkFoo}))] + ({ T17544_kw.hs:16:18-20 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544_kw.hs:16:18-20 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544_kw.hs:16:18-20 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544_kw.hs:16:18-20 } - (Unqual - {OccName: Foo}))))) - (Just - ({ T17544_kw.hs:15:10-35 } - (HsDocString - " Bad comment for MkFoo"))))))] + (Unqual + {OccName: Foo})))) + (Just + ({ T17544_kw.hs:15:10-35 } + (HsDocString + " Bad comment for MkFoo")))))] ({ } []))))) ,({ T17544_kw.hs:(18,1)-(19,26) } @@ -70,33 +74,34 @@ (Nothing) (Nothing) [({ T17544_kw.hs:19:9-26 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544_kw.hs:19:9-13 } - (Unqual - {OccName: MkBar}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544_kw.hs:19:9-13 } + (Unqual + {OccName: MkBar}))] + ({ T17544_kw.hs:19:18-26 } + (False)) + [] + (Nothing) + (PrefixCon + [(HsScaled + (HsLinearArrow) + ({ T17544_kw.hs:19:18-19 } + (HsTupleTy + (NoExtField) + (HsBoxedOrConstraintTuple) + [])))]) + ({ T17544_kw.hs:19:24-26 } + (HsTyVar (NoExtField) - ({ T17544_kw.hs:19:18-26 } - (HsFunTy - (NoExtField) - (HsUnrestrictedArrow) - ({ T17544_kw.hs:19:18-19 } - (HsTupleTy - (NoExtField) - (HsBoxedOrConstraintTuple) - [])) - ({ T17544_kw.hs:19:24-26 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544_kw.hs:19:24-26 } - (Unqual - {OccName: Bar}))))))) - (Just - ({ T17544_kw.hs:18:13-38 } - (HsDocString - " Bad comment for MkBar"))))))] + (NotPromoted) + ({ T17544_kw.hs:19:24-26 } + (Unqual + {OccName: Bar})))) + (Just + ({ T17544_kw.hs:18:13-38 } + (HsDocString + " Bad comment for MkBar")))))] ({ } []))))) ,({ T17544_kw.hs:(21,1)-(24,18) } ===================================== testsuite/tests/haddock/should_compile_flag_haddock/T17652.hs ===================================== @@ -0,0 +1,8 @@ +module T17652 where + +data X + = B + -- | x + !Int + -- | y + String ===================================== testsuite/tests/haddock/should_compile_flag_haddock/T17652.stderr ===================================== @@ -0,0 +1,6 @@ + +==================== Parser ==================== +module T17652 where +data X = B !Int " x" String " y" + + ===================================== testsuite/tests/haddock/should_compile_flag_haddock/all.T ===================================== @@ -62,3 +62,4 @@ test('T17544_kw', normal, compile, ['-haddock -Winvalid-haddock -ddump-parsed-as test('haddockExtraDocs', normal, compile, ['-haddock -Winvalid-haddock']) test('haddockTySyn', normal, compile, ['-haddock -Winvalid-haddock -ddump-parsed']) test('T8944', normal, compile, ['-haddock -Winvalid-haddock -ddump-parsed']) +test('T17652', normal, compile, ['-haddock -Winvalid-haddock -ddump-parsed']) ===================================== testsuite/tests/parser/should_compile/T15323.stderr ===================================== @@ -36,67 +36,62 @@ (Nothing) (Nothing) [({ T15323.hs:6:5-54 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T15323.hs:6:5-14 } - (Unqual - {OccName: TestParens}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T15323.hs:6:5-14 } + (Unqual + {OccName: TestParens}))] + ({ T15323.hs:6:20-54 } + (True)) + [({ T15323.hs:6:27 } + (UserTyVar + (NoExtField) + (SpecifiedSpec) + ({ T15323.hs:6:27 } + (Unqual + {OccName: v}))))] + (Just + ({ T15323.hs:6:31-36 } + [({ T15323.hs:6:31-36 } + (HsParTy + (NoExtField) + ({ T15323.hs:6:32-35 } + (HsAppTy + (NoExtField) + ({ T15323.hs:6:32-33 } + (HsTyVar + (NoExtField) + (NotPromoted) + ({ T15323.hs:6:32-33 } + (Unqual + {OccName: Eq})))) + ({ T15323.hs:6:35 } + (HsTyVar + (NoExtField) + (NotPromoted) + ({ T15323.hs:6:35 } + (Unqual + {OccName: v}))))))))])) + (PrefixCon + []) + ({ T15323.hs:6:41-54 } + (HsAppTy (NoExtField) - ({ T15323.hs:6:20-54 } - (HsForAllTy + ({ T15323.hs:6:41-52 } + (HsTyVar (NoExtField) - (HsForAllInvis - (NoExtField) - [({ T15323.hs:6:27 } - (UserTyVar - (NoExtField) - (SpecifiedSpec) - ({ T15323.hs:6:27 } - (Unqual - {OccName: v}))))]) - ({ T15323.hs:6:31-54 } - (HsQualTy - (NoExtField) - ({ T15323.hs:6:31-36 } - [({ T15323.hs:6:31-36 } - (HsParTy - (NoExtField) - ({ T15323.hs:6:32-35 } - (HsAppTy - (NoExtField) - ({ T15323.hs:6:32-33 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T15323.hs:6:32-33 } - (Unqual - {OccName: Eq})))) - ({ T15323.hs:6:35 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T15323.hs:6:35 } - (Unqual - {OccName: v}))))))))]) - ({ T15323.hs:6:41-54 } - (HsAppTy - (NoExtField) - ({ T15323.hs:6:41-52 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T15323.hs:6:41-52 } - (Unqual - {OccName: MaybeDefault})))) - ({ T15323.hs:6:54 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T15323.hs:6:54 } - (Unqual - {OccName: v}))))))))))) - (Nothing))))] + (NotPromoted) + ({ T15323.hs:6:41-52 } + (Unqual + {OccName: MaybeDefault})))) + ({ T15323.hs:6:54 } + (HsTyVar + (NoExtField) + (NotPromoted) + ({ T15323.hs:6:54 } + (Unqual + {OccName: v})))))) + (Nothing)))] ({ } [])))))] (Nothing) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e419766777b5fea9628314b082f8a411ca9727da...94bfcb1c7e77d0624990c7330ff019d84c2d87c5 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e419766777b5fea9628314b082f8a411ca9727da...94bfcb1c7e77d0624990c7330ff019d84c2d87c5 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 2 14:35:48 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 02 Aug 2020 10:35:48 -0400 Subject: [Git][ghc/ghc][wip/T17962b] 2 commits: Revert "iserv: Don't pass --export-dynamic on FreeBSD" Message-ID: <5f26cf44162b3_80b3f8496224a7061380b1@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: f9b7497d by Ben Gamari at 2020-08-02T10:33:49-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 946c650c by Ben Gamari at 2020-08-02T10:33:49-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 22 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk - utils/iserv/ghc.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + res=0 + else + AC_MSG_RESULT([affected]) + res=1 + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + return $res + fi + } + + if test -z "$SettingsMergeObjectsCommand"; then + SettingsMergeObjectsCommand="$LD" + fi + if test -z "$SettingsMergeObjectsFlags"; then + SettingsMergeObjectsFlags="-r" + fi + + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + AC_MSG_CHECKING([Looking for using $SettingsMergeObjectsCommand to merge objects) + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_MSG_ERROR([Linker (LD=$LD) is affected by binuntils #22266 but couldn't find another unaffected linker. Please set SettingsMergeObjectsCommand to a functional linker.]) + fi + fi + + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -2140,31 +2140,9 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = GHC.SysTools.runLink dflags ([ - GHC.SysTools.Option "-nostdlib", - GHC.SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in GHC.Driver.Session - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [GHC.SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [GHC.SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [GHC.SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [GHC.SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args = GHC.SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" + [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" | OSMinGW32 == osInfo , not $ target32Bit (targetPlatform dflags) ] @@ -2176,25 +2154,24 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] - ccInfo <- getCompilerInfo dflags if ldIsGnuLd then do script <- newTempName dflags TFL_CurrentModule "ldscript" cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [GHC.SysTools.FileOption "" script] ccInfo + ld_r [GHC.SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files ld_r [GHC.SysTools.Option "-Wl,-filelist", - GHC.SysTools.FileOption "-Wl," filelist] ccInfo + GHC.SysTools.FileOption "-Wl," filelist] else do - ld_r (map (GHC.SysTools.FileOption "") o_files) ccInfo + ld_r (map (GHC.SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -102,6 +102,7 @@ module GHC.Driver.Session ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -120,6 +121,7 @@ module GHC.Driver.Session ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -142,10 +144,10 @@ module GHC.Driver.Session ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -940,6 +942,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -986,6 +990,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/GHC/Settings.hs ===================================== @@ -28,6 +28,7 @@ module GHC.Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -46,6 +47,7 @@ module GHC.Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -99,6 +101,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -124,6 +127,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] @@ -200,6 +204,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -236,6 +242,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -137,6 +137,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -183,6 +185,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -201,6 +204,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -299,6 +299,13 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== configure.ac ===================================== @@ -602,13 +602,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -96,6 +96,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -115,6 +115,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -138,6 +144,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -99,6 +99,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -127,9 +127,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -311,6 +312,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -91,6 +91,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -109,6 +110,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -176,6 +179,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -191,6 +195,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -294,6 +294,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -101,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -37,6 +37,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -244,6 +245,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -223,6 +223,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -500,6 +500,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -733,7 +735,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" ===================================== utils/iserv/ghc.mk ===================================== @@ -30,9 +30,8 @@ endif # refer to the RTS. This is harmless if you don't use it (adds a bit # of overhead to startup and increases the binary sizes) but if you # need it there's no alternative. -# Don't do this on FreeBSD to work around #17962. ifeq "$(TargetElf)" "YES" -ifeq "$(findstring $(TargetOS_CPP), solaris2 freebsd)" "" +ifneq "$(TargetOS_CPP)" "solaris2" # The Solaris linker does not support --export-dynamic option. It also # does not need it since it exports all dynamic symbols by default utils/iserv_stage2_MORE_HC_OPTS += -optl-Wl,--export-dynamic View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/626d13e8e7a538aba176aeceeed06dc8d6538fc7...946c650c46603f2442242ae2aceb216b7e8fff5e -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/626d13e8e7a538aba176aeceeed06dc8d6538fc7...946c650c46603f2442242ae2aceb216b7e8fff5e You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 2 14:47:55 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 02 Aug 2020 10:47:55 -0400 Subject: [Git][ghc/ghc][wip/T17962b] Refactor handling of object merging Message-ID: <5f26d21be716f_80b3f849a25e6906138853@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: dca90ba9 by Ben Gamari at 2020-08-02T10:47:47-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 21 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + res=0 + else + AC_MSG_RESULT([affected]) + res=1 + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + return $res + fi + } + + if test -z "$SettingsMergeObjectsCommand"; then + SettingsMergeObjectsCommand="$LD" + fi + if test -z "$SettingsMergeObjectsFlags"; then + SettingsMergeObjectsFlags="-r" + fi + + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + AC_MSG_CHECKING([Looking for using $SettingsMergeObjectsCommand to merge objects]) + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_MSG_ERROR([Linker (LD=$LD) is affected by binuntils #22266 but couldn't find another unaffected linker. Please set SettingsMergeObjectsCommand to a functional linker.]) + fi + fi + + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -2140,31 +2140,9 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = GHC.SysTools.runLink dflags ([ - GHC.SysTools.Option "-nostdlib", - GHC.SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in GHC.Driver.Session - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [GHC.SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [GHC.SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [GHC.SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [GHC.SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args = GHC.SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" + [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" | OSMinGW32 == osInfo , not $ target32Bit (targetPlatform dflags) ] @@ -2176,25 +2154,24 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] - ccInfo <- getCompilerInfo dflags if ldIsGnuLd then do script <- newTempName dflags TFL_CurrentModule "ldscript" cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [GHC.SysTools.FileOption "" script] ccInfo + ld_r [GHC.SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files ld_r [GHC.SysTools.Option "-Wl,-filelist", - GHC.SysTools.FileOption "-Wl," filelist] ccInfo + GHC.SysTools.FileOption "-Wl," filelist] else do - ld_r (map (GHC.SysTools.FileOption "") o_files) ccInfo + ld_r (map (GHC.SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -102,6 +102,7 @@ module GHC.Driver.Session ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -120,6 +121,7 @@ module GHC.Driver.Session ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -142,10 +144,10 @@ module GHC.Driver.Session ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -940,6 +942,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -986,6 +990,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/GHC/Settings.hs ===================================== @@ -28,6 +28,7 @@ module GHC.Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -46,6 +47,7 @@ module GHC.Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -99,6 +101,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -124,6 +127,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] @@ -200,6 +204,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -236,6 +242,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -137,6 +137,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -183,6 +185,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -201,6 +204,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -299,6 +299,13 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== configure.ac ===================================== @@ -602,13 +602,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -96,6 +96,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -115,6 +115,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -138,6 +144,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -99,6 +99,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -127,9 +127,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -311,6 +312,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -91,6 +91,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -109,6 +110,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -176,6 +179,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -191,6 +195,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -294,6 +294,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -101,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -37,6 +37,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -244,6 +245,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -223,6 +223,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -500,6 +500,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -733,7 +735,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dca90ba9e7007aabed487aecc902470abbe9eeee -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dca90ba9e7007aabed487aecc902470abbe9eeee You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 2 15:44:04 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 02 Aug 2020 11:44:04 -0400 Subject: [Git][ghc/ghc][wip/T17962b] Refactor handling of object merging Message-ID: <5f26df448404f_80b3f849a25e69061394ba@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: 26d37c83 by Ben Gamari at 2020-08-02T11:43:56-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 21 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + res=0 + else + AC_MSG_RESULT([affected]) + res=1 + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + return $res + fi + } + + if test -z "$SettingsMergeObjectsCommand"; then + SettingsMergeObjectsCommand="$LD" + fi + if test -z "$SettingsMergeObjectsFlags"; then + SettingsMergeObjectsFlags="-r" + fi + + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_MSG_NOTICE([$SettingsMergeObjectsCommand is broken due to binutils #22266, looking for another linker...]) + SettingsMergeObjectsCommand="" + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the SettingsMergeObjectsCommand variable to a functional linker.]) + fi + fi + + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -2140,31 +2140,9 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = GHC.SysTools.runLink dflags ([ - GHC.SysTools.Option "-nostdlib", - GHC.SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in GHC.Driver.Session - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [GHC.SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [GHC.SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [GHC.SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [GHC.SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args = GHC.SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" + [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" | OSMinGW32 == osInfo , not $ target32Bit (targetPlatform dflags) ] @@ -2176,25 +2154,24 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] - ccInfo <- getCompilerInfo dflags if ldIsGnuLd then do script <- newTempName dflags TFL_CurrentModule "ldscript" cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [GHC.SysTools.FileOption "" script] ccInfo + ld_r [GHC.SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files ld_r [GHC.SysTools.Option "-Wl,-filelist", - GHC.SysTools.FileOption "-Wl," filelist] ccInfo + GHC.SysTools.FileOption "-Wl," filelist] else do - ld_r (map (GHC.SysTools.FileOption "") o_files) ccInfo + ld_r (map (GHC.SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -102,6 +102,7 @@ module GHC.Driver.Session ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -120,6 +121,7 @@ module GHC.Driver.Session ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -142,10 +144,10 @@ module GHC.Driver.Session ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -940,6 +942,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -986,6 +990,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/GHC/Settings.hs ===================================== @@ -28,6 +28,7 @@ module GHC.Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -46,6 +47,7 @@ module GHC.Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -99,6 +101,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -124,6 +127,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] @@ -200,6 +204,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -236,6 +242,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -137,6 +137,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -183,6 +185,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -201,6 +204,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -299,6 +299,13 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== configure.ac ===================================== @@ -602,13 +602,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -96,6 +96,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -115,6 +115,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -138,6 +144,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -99,6 +99,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -127,9 +127,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -311,6 +312,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -91,6 +91,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -109,6 +110,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -176,6 +179,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -191,6 +195,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -294,6 +294,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -101,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -37,6 +37,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -244,6 +245,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -223,6 +223,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -500,6 +500,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -733,7 +735,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/26d37c83a5b6e83f82532d87874890f22ae94b62 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/26d37c83a5b6e83f82532d87874890f22ae94b62 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 2 15:46:46 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 02 Aug 2020 11:46:46 -0400 Subject: [Git][ghc/ghc][wip/T17962b] Refactor handling of object merging Message-ID: <5f26dfe6c174d_80bf4344646139897@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: 1696a5b7 by Ben Gamari at 2020-08-02T11:46:37-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 21 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + res=0 + else + AC_MSG_RESULT([affected]) + res=1 + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + return $res + fi + } + + if test -z "$SettingsMergeObjectsCommand"; then + SettingsMergeObjectsCommand="$LD" + fi + if test -z "$SettingsMergeObjectsFlags"; then + SettingsMergeObjectsFlags="-r" + fi + + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_MSG_NOTICE([$SettingsMergeObjectsCommand is broken due to binutils 22266, looking for another linker...]) + SettingsMergeObjectsCommand="" + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the SettingsMergeObjectsCommand variable to a functional linker.]) + fi + fi + + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -2140,31 +2140,9 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = GHC.SysTools.runLink dflags ([ - GHC.SysTools.Option "-nostdlib", - GHC.SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in GHC.Driver.Session - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [GHC.SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [GHC.SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [GHC.SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [GHC.SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args = GHC.SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" + [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" | OSMinGW32 == osInfo , not $ target32Bit (targetPlatform dflags) ] @@ -2176,25 +2154,24 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] - ccInfo <- getCompilerInfo dflags if ldIsGnuLd then do script <- newTempName dflags TFL_CurrentModule "ldscript" cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [GHC.SysTools.FileOption "" script] ccInfo + ld_r [GHC.SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files ld_r [GHC.SysTools.Option "-Wl,-filelist", - GHC.SysTools.FileOption "-Wl," filelist] ccInfo + GHC.SysTools.FileOption "-Wl," filelist] else do - ld_r (map (GHC.SysTools.FileOption "") o_files) ccInfo + ld_r (map (GHC.SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -102,6 +102,7 @@ module GHC.Driver.Session ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -120,6 +121,7 @@ module GHC.Driver.Session ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -142,10 +144,10 @@ module GHC.Driver.Session ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -940,6 +942,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -986,6 +990,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/GHC/Settings.hs ===================================== @@ -28,6 +28,7 @@ module GHC.Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -46,6 +47,7 @@ module GHC.Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -99,6 +101,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -124,6 +127,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] @@ -200,6 +204,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -236,6 +242,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -137,6 +137,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -183,6 +185,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -201,6 +204,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -299,6 +299,13 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== configure.ac ===================================== @@ -602,13 +602,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -96,6 +96,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -115,6 +115,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -138,6 +144,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -99,6 +99,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -127,9 +127,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -311,6 +312,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -91,6 +91,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -109,6 +110,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -176,6 +179,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -191,6 +195,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -294,6 +294,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -101,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -37,6 +37,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -244,6 +245,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -223,6 +223,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -500,6 +500,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -733,7 +735,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1696a5b7453e9d505ab7367ecf4d8c627be5000d -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1696a5b7453e9d505ab7367ecf4d8c627be5000d You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 2 16:36:26 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 02 Aug 2020 12:36:26 -0400 Subject: [Git][ghc/ghc][wip/T17962b] Refactor handling of object merging Message-ID: <5f26eb8a7a8f2_80bf43446461444f1@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: 69c03c65 by Ben Gamari at 2020-08-02T12:36:15-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 21 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + res=0 + else + AC_MSG_RESULT([affected]) + res=1 + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + return $res + fi + } + + if test -z "$SettingsMergeObjectsCommand"; then + SettingsMergeObjectsCommand="$LD" + fi + if test -z "$SettingsMergeObjectsFlags"; then + SettingsMergeObjectsFlags="-r" + fi + + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_MSG_NOTICE([$SettingsMergeObjectsCommand is broken due to binutils 22266, looking for another linker...]) + SettingsMergeObjectsCommand="" + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the SettingsMergeObjectsCommand variable to a functional linker.]) + fi + fi + + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -2140,31 +2140,9 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = GHC.SysTools.runLink dflags ([ - GHC.SysTools.Option "-nostdlib", - GHC.SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in GHC.Driver.Session - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [GHC.SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [GHC.SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [GHC.SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [GHC.SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args = GHC.SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" + [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" | OSMinGW32 == osInfo , not $ target32Bit (targetPlatform dflags) ] @@ -2176,25 +2154,24 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] - ccInfo <- getCompilerInfo dflags if ldIsGnuLd then do script <- newTempName dflags TFL_CurrentModule "ldscript" cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [GHC.SysTools.FileOption "" script] ccInfo + ld_r [GHC.SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files ld_r [GHC.SysTools.Option "-Wl,-filelist", - GHC.SysTools.FileOption "-Wl," filelist] ccInfo + GHC.SysTools.FileOption "-Wl," filelist] else do - ld_r (map (GHC.SysTools.FileOption "") o_files) ccInfo + ld_r (map (GHC.SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -102,6 +102,7 @@ module GHC.Driver.Session ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -120,6 +121,7 @@ module GHC.Driver.Session ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -142,10 +144,10 @@ module GHC.Driver.Session ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -940,6 +942,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -986,6 +990,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/GHC/Settings.hs ===================================== @@ -28,6 +28,7 @@ module GHC.Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -46,6 +47,7 @@ module GHC.Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -99,6 +101,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -124,6 +127,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] @@ -200,6 +204,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -236,6 +242,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -137,6 +137,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -183,6 +185,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -201,6 +204,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -299,6 +299,13 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== configure.ac ===================================== @@ -602,13 +602,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -96,6 +96,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -115,6 +115,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -138,6 +144,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -99,6 +99,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -127,9 +127,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -311,6 +312,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -91,6 +91,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -109,6 +110,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -176,6 +179,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -191,6 +195,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -294,6 +294,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -101,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -37,6 +37,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -244,6 +245,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -223,6 +223,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -500,6 +500,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -733,7 +735,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/69c03c6598499aa3fcd915ffd41cfe097b234e0f -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/69c03c6598499aa3fcd915ffd41cfe097b234e0f You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 2 17:13:16 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Sun, 02 Aug 2020 13:13:16 -0400 Subject: [Git][ghc/ghc][wip/az/exactprint] 178 commits: ghc-prim: Turn some comments into haddocks Message-ID: <5f26f42ce3fc6_80b10e6f9b461448ab@gitlab.haskell.org.mail> Alan Zimmerman pushed to branch wip/az/exactprint at Glasgow Haskell Compiler / GHC Commits: e61d5395 by Chaitanya Koparkar at 2020-07-07T13:55:59-04:00 ghc-prim: Turn some comments into haddocks [ci skip] - - - - - 37743f91 by John Ericson at 2020-07-07T13:56:00-04:00 Support `timesInt2#` in LLVM backend - - - - - 46397e53 by John Ericson at 2020-07-07T13:56:00-04:00 `genericIntMul2Op`: Call `genericWordMul2Op` directly This unblocks a refactor, and removes partiality. It might be a PowerPC regression but that should be fixable. - - - - - 8a1c0584 by John Ericson at 2020-07-07T13:56:00-04:00 Simplify `PrimopCmmEmit` Follow @simonpj's suggestion of pushing the "into regs" logic into `emitPrimOp`. With the previous commit getting rid of the recursion in `genericIntMul2Op`, this is now an easy refactor. - - - - - 6607f203 by John Ericson at 2020-07-07T13:56:00-04:00 `opAllDone` -> `opIntoRegs` The old name was and terrible and became worse after the previous commit's refactor moved non-trivial funcationlity into its body. - - - - - fdcc53ba by Sylvain Henry at 2020-07-07T13:56:00-04:00 Optimise genericIntMul2Op We shouldn't directly call 'genericWordMul2Op' in genericIntMul2Op because a target may provide a faster primop for 'WordMul2Op': we'd better use it! - - - - - 686e7225 by Moritz Angermann at 2020-07-07T13:56:01-04:00 [linker/rtsSymbols] More linker symbols Mostly symbols needed for aarch64/armv7l and in combination with musl, where we have to rely on loading *all* objects/archives - __stack_chk_* only when not DYNAMIC - - - - - 3f60b94d by Moritz Angermann at 2020-07-07T13:56:01-04:00 better if guards. - - - - - 7abffced by Moritz Angermann at 2020-07-07T13:56:01-04:00 Fix (1) - - - - - cdfeb3f2 by Moritz Angermann at 2020-07-07T13:56:01-04:00 AArch32 symbols only on aarch32. - - - - - f496c955 by Adam Sandberg Ericsson at 2020-07-07T13:56:02-04:00 add -flink-rts flag to link the rts when linking a shared or static library #18072 By default we don't link the RTS when linking shared libraries because in the most usual mode a shared library is an intermediary product, for example a Haskell library, that will be linked into some executable in the end. So we wish to defer the RTS flavour to link to the final link. However sometimes the final product is the shared library, for example when writing a plugin for some other system, so we do wish the shared library to link the RTS. For consistency we also make -staticlib honor this flag and its inversion. -staticlib currently implies -flink-shared. - - - - - c59faf67 by Stefan Schulze Frielinghaus at 2020-07-07T13:56:04-04:00 hadrian: link check-ppr against debugging RTS if ghcDebugged - - - - - 0effc57d by Adam Sandberg Ericsson at 2020-07-07T13:56:05-04:00 rts linker: teach the linker about GLIBC's special handling of *stat, mknod and atexit functions #7072 - - - - - 96153433 by Adam Sandberg Ericsson at 2020-07-07T13:56:06-04:00 hadrian: make hadrian/ghci use the bootstrap compiler from configure #18190 - - - - - 4d24f886 by Adam Sandberg Ericsson at 2020-07-07T13:56:07-04:00 hadrian: ignore cabal configure verbosity related flags #18131 - - - - - 7332bbff by Ben Gamari at 2020-07-07T13:56:08-04:00 testsuite: Widen T12234 acceptance window to 2% Previously it wasn't uncommon to see +/-1% fluctuations in compiler allocations on this test. - - - - - 180b6313 by Gabor Greif at 2020-07-07T13:56:08-04:00 When running libtool, report it as such - - - - - d3bd6897 by Sylvain Henry at 2020-07-07T13:56:11-04:00 BigNum: rename BigNat types Before this patch BigNat names were confusing because we had: * GHC.Num.BigNat.BigNat: unlifted type used everywhere else * GHC.Num.BigNat.BigNatW: lifted type only used to share static constants * GHC.Natural.BigNat: lifted type only used for backward compatibility After this patch we have: * GHC.Num.BigNat.BigNat#: unlifted type * GHC.Num.BigNat.BigNat: lifted type (reexported from GHC.Natural) Thanks to @RyanGlScott for spotting this. - - - - - 929d26db by Sylvain Henry at 2020-07-07T13:56:12-04:00 Bignum: don't build ghc-bignum with stage0 Noticed by @Ericson2314 - - - - - d25b6851 by Sylvain Henry at 2020-07-07T13:56:12-04:00 Hadrian: ghc-gmp.h shouldn't be a compiler dependency - - - - - 0ddae2ba by Sylvain Henry at 2020-07-07T13:56:14-04:00 DynFlags: factor out pprUnitId from "Outputable UnitId" instance - - - - - 204f3f5d by Krzysztof Gogolewski at 2020-07-07T13:56:18-04:00 Remove unused function pprHsForAllExtra (#18423) The function `pprHsForAllExtra` was called only on `Nothing` since 2015 (1e041b7382b6aa). - - - - - 3033e0e4 by Adam Sandberg Ericsson at 2020-07-08T20:36:49-04:00 hadrian: add flag to skip rebuilding dependency information #17636 - - - - - b7de4b96 by Stefan Schulze Frielinghaus at 2020-07-09T09:49:22-04:00 Fix GHCi :print on big-endian platforms On big-endian platforms executing import GHC.Exts data Foo = Foo Float# deriving Show foo = Foo 42.0# foo :print foo results in an arithmetic overflow exception which is caused by function index where moveBytes equals word_size - (r + item_size_b) * 8 Here we have a mixture of units. Both, word_size and item_size_b have unit bytes whereas r has unit bits. On 64-bit platforms moveBytes equals then 8 - (0 + 4) * 8 which results in a negative and therefore invalid second parameter for a shiftL operation. In order to make things more clear the expression (word .&. (mask `shiftL` moveBytes)) `shiftR` moveBytes is equivalent to (word `shiftR` moveBytes) .&. mask On big-endian platforms the shift must be a left shift instead of a right shift. For symmetry reasons not a mask is used but two shifts in order to zero out bits. Thus the fixed version equals case endian of BigEndian -> (word `shiftL` moveBits) `shiftR` zeroOutBits `shiftL` zeroOutBits LittleEndian -> (word `shiftR` moveBits) `shiftL` zeroOutBits `shiftR` zeroOutBits Fixes #16548 and #14455 - - - - - 3656dff8 by Sylvain Henry at 2020-07-09T09:50:01-04:00 LLVM: fix MO_S_Mul2 support (#18434) The value indicating if the carry is useful wasn't taken into account. - - - - - d9f09506 by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Define multiShotIO and use it in mkSplitUniqueSupply This patch is part of the ongoing eta-expansion saga; see #18238. It implements a neat trick (suggested by Sebastian Graf) that allows the programmer to disable the default one-shot behaviour of IO (the "state hack"). The trick is to use a new multiShotIO function; see Note [multiShotIO]. For now, multiShotIO is defined here in Unique.Supply; but it should ultimately be moved to the IO library. The change is necessary to get good code for GHC's unique supply; see Note [Optimising the unique supply]. However it makes no difference to GHC as-is. Rather, it makes a difference when a subsequent commit Improve eta-expansion using ArityType lands. - - - - - bce695cc by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Make arityType deal with join points As Note [Eta-expansion and join points] describes, this patch makes arityType deal correctly with join points. What was there before was not wrong, but yielded lower arities than it could. Fixes #18328 In base GHC this makes no difference to nofib. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- n-body -0.1% -0.1% -1.2% -1.1% 0.0% -------------------------------------------------------------------------------- Min -0.1% -0.1% -55.0% -56.5% 0.0% Max -0.0% 0.0% +16.1% +13.4% 0.0% Geometric Mean -0.0% -0.0% -30.1% -31.0% -0.0% But it starts to make real difference when we land the change to the way mkDupableAlts handles StrictArg, in fixing #13253 and friends. I think this is because we then get more non-inlined join points. - - - - - 2b7c71cb by Simon Peyton Jones at 2020-07-11T12:17:02-04:00 Improve eta-expansion using ArityType As #18355 shows, we were failing to preserve one-shot info when eta-expanding. It's rather easy to fix, by using ArityType more, rather than just Arity. This patch is important to suport the one-shot monad trick; see #18202. But the extra tracking of one-shot-ness requires the patch Define multiShotIO and use it in mkSplitUniqueSupply If that patch is missing, ths patch makes things worse in GHC.Types.Uniq.Supply. With it, however, we see these improvements T3064 compiler bytes allocated -2.2% T3294 compiler bytes allocated -1.3% T12707 compiler bytes allocated -1.3% T13056 compiler bytes allocated -2.2% Metric Decrease: T3064 T3294 T12707 T13056 - - - - - de139cc4 by Artem Pelenitsyn at 2020-07-12T02:53:20-04:00 add reproducer for #15630 - - - - - c4de6a7a by Andreas Klebinger at 2020-07-12T02:53:55-04:00 Give Uniq[D]FM a phantom type for its key. This fixes #17667 and should help to avoid such issues going forward. The changes are mostly mechanical in nature. With two notable exceptions. * The register allocator. The register allocator references registers by distinct uniques. However they come from the types of VirtualReg, Reg or Unique in various places. As a result we sometimes cast the key type of the map and use functions which operate on the now typed map but take a raw Unique as actual key. The logic itself has not changed it just becomes obvious where we do so now. * <Type>Env Modules. As an example a ClassEnv is currently queried using the types `Class`, `Name`, and `TyCon`. This is safe since for a distinct class value all these expressions give the same unique. getUnique cls getUnique (classTyCon cls) getUnique (className cls) getUnique (tcName $ classTyCon cls) This is for the most part contained within the modules defining the interface. However it requires us to play dirty when we are given a `Name` to lookup in a `UniqFM Class a` map. But again the logic did not change and it's for the most part hidden behind the Env Module. Some of these cases could be avoided by refactoring but this is left for future work. We also bump the haddock submodule as it uses UniqFM. - - - - - c2cfdfde by Aaron Allen at 2020-07-13T09:00:33-04:00 Warn about empty Char enumerations (#18402) Currently the "Enumeration is empty" warning (-Wempty-enumerations) only fires for numeric literals. This patch adds support for `Char` literals so that enumerating an empty list of `Char`s will also trigger the warning. - - - - - c3ac87ec by Stefan Schulze Frielinghaus at 2020-07-13T09:01:10-04:00 hadrian: build check-ppr dynamic if GHC is build dynamic Fixes #18361 - - - - - 9ad072b4 by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Use dumpStyle when printing inlinings This just makes debug-printing consistent, and more informative. - - - - - e78c4efb by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Comments only - - - - - 7ccb760b by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Reduce result discount in conSize Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c - - - - - 7f0b671e by Ben Gamari at 2020-07-13T14:52:49-04:00 testsuite: Widen acceptance threshold on T5837 This test is positively tiny and consequently the bytes allocated measurement will be relatively noisy. Consequently I have seen this fail spuriously quite often. - - - - - 118e1c3d by Alp Mestanogullari at 2020-07-14T21:30:52-04:00 compiler: re-engineer the treatment of rebindable if Executing on the plan described in #17582, this patch changes the way if expressions are handled in the compiler in the presence of rebindable syntax. We get rid of the SyntaxExpr field of HsIf and instead, when rebindable syntax is on, we rewrite the HsIf node to the appropriate sequence of applications of the local `ifThenElse` function. In order to be able to report good error messages, with expressions as they were written by the user (and not as desugared by the renamer), we make use of TTG extensions to extend GhcRn expression ASTs with an `HsExpansion` construct, which keeps track of a source (GhcPs) expression and the desugared (GhcRn) expression that it gives rise to. This way, we can typecheck the latter while reporting the former in error messages. In order to discard the error context lines that arise from typechecking the desugared expressions (because they talk about expressions that the user has not written), we carefully give a special treatment to the nodes fabricated by this new renaming-time transformation when typechecking them. See Note [Rebindable syntax and HsExpansion] for more details. The note also includes a recipe to apply the same treatment to other rebindable constructs. Tests 'rebindable11' and 'rebindable12' have been added to make sure we report identical error messages as before this patch under various circumstances. We also now disable rebindable syntax when processing untyped TH quotes, as per the discussion in #18102 and document the interaction of rebindable syntax and Template Haskell, both in Note [Template Haskell quotes and Rebindable Syntax] and in the user guide, adding a test to make sure that we do not regress in that regard. - - - - - 64c774b0 by Andreas Klebinger at 2020-07-14T21:31:27-04:00 Explain why keeping DynFlags in AnalEnv saves allocation. - - - - - 254245d0 by Ben Gamari at 2020-07-14T21:32:03-04:00 docs/users-guide: Update default -funfolding-use-threshold value This was changed in 3d2991f8 but I neglected to update the documentation. Fixes #18419. - - - - - 4c259f86 by Andreas Klebinger at 2020-07-14T21:32:41-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. - - - - - 23797224 by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 .gitlab: re-enable integer-simple substitute (BIGNUM_BACKEND) Recently build system migrated from INTEGER_LIBRARY to BIGNUM_BACKEND. But gitlab CI was never updated. Let's enable BIGNUM_BACKEND=native. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - e0db878a by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 ghc-bignum: bring in sync .hs-boot files with module declarations Before this change `BIGNUM_BACKEND=native` build was failing as: ``` libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs:708:16: error: * Variable not in scope: naturalFromBigNat# :: WordArray# -> t * Perhaps you meant one of these: `naturalFromBigNat' (imported from GHC.Num.Natural), `naturalToBigNat' (imported from GHC.Num.Natural) | 708 | m' = naturalFromBigNat# m | ``` This happens because `.hs-boot` files are slightly out of date. This change brings in data and function types in sync. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - c9f65c36 by Stefan Schulze Frielinghaus at 2020-07-14T21:33:57-04:00 rts/Disassembler.c: Use FMT_HexWord for printing values in hex format - - - - - 58ae62eb by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 macOS: Load frameworks without stating them first. macOS Big Sur makes the following change to how frameworks are shipped with the OS: > New in macOS Big Sur 11 beta, the system ships with a built-in > dynamic linker cache of all system-provided libraries. As part of > this change, copies of dynamic libraries are no longer present on > the filesystem. Code that attempts to check for dynamic library > presence by looking for a file at a path or enumerating a directory > will fail. Instead, check for library presence by attempting to > dlopen() the path, which will correctly check for the library in the > cache. (62986286) https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/ Therefore, the previous method of checking whether a library exists before attempting to load it makes GHC.Runtime.Linker.loadFramework fail to find frameworks installed at /System/Library/Frameworks. GHC.Runtime.Linker.loadFramework now opportunistically loads the framework libraries without checking for their existence first, failing only if all attempts to load a given framework from any of the various possible locations fail. - - - - - cdc4a6b0 by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 loadFramework: Output the errors collected in all loading attempts. With the recent change away from first finding and then loading a framework, loadFramework had no way of communicating the real reason why loadDLL failed if it was any reason other than the framework missing from the file system. It now collects all loading attempt errors into a list and concatenates them into a string to return to the caller. - - - - - 51dbfa52 by Ben Gamari at 2020-07-15T04:05:34-04:00 StgToCmm: Use CmmRegOff smart constructor Previously we would generate expressions of the form `CmmRegOff BaseReg 0`. This should do no harm (and really should be handled by the NCG anyways) but it's better to just generate a plain `CmmReg`. - - - - - ae11bdfd by Ben Gamari at 2020-07-15T04:06:08-04:00 testsuite: Add regression test for #17744 Test due to @monoidal. - - - - - 0e3c277a by Ben Gamari at 2020-07-15T16:41:01-04:00 Bump Cabal submodule Updates a variety of tests as Cabal is now more strict about Cabal file form. - - - - - ceed994a by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Drop Windows Vista support, require Windows 7 - - - - - 00a23bfd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Update Windows FileSystem wrapper utilities. - - - - - 459e1c5f by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Use SlimReaderLocks and ConditonalVariables provided by the OS instead of emulated ones - - - - - 763088fc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Small linker comment and ifdef cleanups - - - - - 1a228ff9 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Flush event logs eagerly. - - - - - e9e04dda by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Refactor Buffer structures to be able to track async operations - - - - - 356dc3fe by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Implement new Console API - - - - - 90e69f77 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add IOPort synchronization primitive - - - - - 71245fcc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add new io-manager cmdline options - - - - - d548a3b3 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Init Windows console Codepage to UTF-8. - - - - - 58ef6366 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add unsafeSplat to GHC.Event.Array - - - - - d660725e by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add size and iterate to GHC.Event.IntTable. - - - - - 050da6dd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Switch Testsuite to test winio by default - - - - - 4bf542bf by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Multiple refactorings and support changes. - - - - - 4489af6b by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core threaded I/O manager - - - - - 64d8f2fe by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core non-threaded I/O manager - - - - - 8da15a09 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix a scheduler bug with the threaded-runtime. - - - - - 84ea3d14 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Relaxing some constraints in io-manager. - - - - - ccf0d107 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix issues with non-threaded I/O manager after split. - - - - - b492fe6e by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Remove some barf statements that are a bit strict. - - - - - 01423fd2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Expand comments describing non-threaded loop - - - - - 4b69004f by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: fix FileSize unstat-able handles - - - - - 9b384270 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Implement new tempfile routines for winio - - - - - f1e0be82 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix input truncation when reading from handle. This was caused by not upholding the read buffer invariant that bufR == bufL == 0 for empty read buffers. - - - - - e176b625 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix output truncation for writes larger than buffer size - - - - - a831ce0e by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Rewrite bufWrite. I think it's far easier to follow the code now. It's also correct now as I had still missed a spot where we didn't update the offset. - - - - - 6aefdf62 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix offset set by bufReadEmpty. bufReadEmpty returns the bytes read *including* content that was already buffered, But for calculating the offset we only care about the number of bytes read into the new buffer. - - - - - 750ebaee by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Clean up code surrounding IOPort primitives. According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc. - - - - - ffd31db9 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix multi threaded threadDelay and a few other small changes. Multithreaded threadDelay suffered from a race condition based on the ioManagerStatus. Since the status isn't needed for WIO I removed it completely. This resulted in a light refactoring, as consequence we will always wake up the IO manager using interruptSystemManager, which uses `postQueuedCompletionStatus` internally. I also added a few comments which hopefully makes the code easier to dive into for the next person diving in. - - - - - 6ec26df2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 wionio: Make IO subsystem check a no-op on non-windows platforms. - - - - - 29bcd936 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Set handle offset when opening files in Append mode. Otherwise we would truncate the file. - - - - - 55c29700 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Remove debug event log trace - - - - - 9acb9f40 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix sqrt and openFile009 test cases - - - - - 57017cb7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Allow hp2ps to build with -DDEBUG - - - - - b8cd9995 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update output of T9681 since we now actually run it. - - - - - 10af5b14 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: A few more improvements to the IOPort primitives. - - - - - 39afc4a7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix expected tempfiles output. Tempfiles now works properly on windows, as such we can delete the win32 specific output. - - - - - 99db46e0 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Assign thread labels to IOManager threads. - - - - - be6af732 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Properly check for the tso of an incall to be zero. - - - - - e2c6dac7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark FD instances as unsupported under WINIO. - - - - - fd02ceed by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix threadDelay maxBound invocations. Instead of letting the ns timer overflow now clamp it at (maxBound :: Word64) ns. That still gives a few hundred years. - - - - - bc79f9f1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comments/cleanup an import in base - - - - - 1d197f4b by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark outstanding_service_requests volatile. As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration. - - - - - dc438186 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Make last_event a local variable - - - - - 2fc957c5 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comment about thread safety of processCompletion. - - - - - 4c026b6c by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: nonthreaded: Create io processing threads in main thread. We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread. - - - - - f47c7208 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add an exported isHeapAlloced function to the RTS - - - - - cc5d7bb1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Queue IO processing threads at the front of the queue. This will unblock the IO thread sooner hopefully leading to higher throughput in some situations. - - - - - e7630115 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: ThreadDelay001: Use higher resolution timer. - - - - - 451b5f96 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update T9681 output, disable T4808 on windows. T4808 tests functionality of the FD interface which won't be supported under WINIO. T9681 just has it's expected output tweaked. - - - - - dd06f930 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Wake io manager once per registerTimeout. Which is implicitly done in editTimeouts, so need to wake it up twice. - - - - - e87d0bf9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update placeholder comment with actual function name. - - - - - fc9025db by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Always lock win32 event queue - - - - - c24c9a1f by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Display thread labels when tracing scheduler events. - - - - - 06542b03 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Refactor non-threaded runner thread and scheduler interface. Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event. - - - - - 256299b1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove outstanding_requests from runner. We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port. - - - - - 3ebd8ad9 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Various fixes related to rebase and testdriver - - - - - 6be6bcba by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Fix rebase artifacts - - - - - 2c649dc3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename unsafeSplat to unsafeCopyFromBuffer - - - - - a18b73f3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove unused size/iterate operations from IntTable - - - - - 16bab48e by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Detect running IO Backend via peeking at RtsConfig - - - - - 8b8405a0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update temp path so GCC etc can handle it. Also fix PIPE support, clean up error casting, fix memory leaks - - - - - 2092bc54 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Minor comments/renamings - - - - - a5b5b6c0 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Checking if an error code indicates completion is now a function. - - - - - 362176fd by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Small refactor in withOverlappedEx - - - - - 32e20597 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: A few comments and commented out dbxIO - - - - - a4bfc1d9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't drop buffer offset in byteView/cwcharView - - - - - b3ad2a54 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: revert BHandle changes. - - - - - 3dcd87e2 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Fix imports - - - - - 5a371890 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update ghc-cabal to handle new Cabal submodule bump - - - - - d07ebe0d by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Only compile sources on Windows - - - - - dcb42393 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Actually return Nothing on EOF for non-blocking read - - - - - 895a3beb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate logic in encodeMultiByte[Raw]IO. - - - - - e06e6734 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate openFile logic - - - - - b59430c0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: fix -werror issue in encoding file - - - - - f8d39a51 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't mention windows specific functions when building on Linux. - - - - - 6a533d2a by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add a note about file locking in the RTS. - - - - - cf37ce34 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Add version to @since annotation - - - - - 0fafa2eb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename GHC.Conc.IOCP -> GHC.Conc.WinIO - - - - - 1854fc23 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Expand GHC.Conc.POSIX description It now explains users may not use these functions when using the old IO manager. - - - - - fcc7ba41 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Fix potential spaceleak in __createUUIDTempFileErrNo - - - - - 6b3fd9fa by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant -Wno-missing-signatures pragmas - - - - - 916fc861 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Make it explicit that we only create one IO manager - - - - - f260a721 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Note why we don't use blocking waits. - - - - - aa0a4bbf by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove commented out pragma - - - - - d679b544 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant buffer write in Handle/Text.hs:bufReadEmpty - - - - - d3f94368 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename SmartHandles to StdHandles - - - - - bd6b8ec1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add comment stating failure behaviour for getUniqueFileInfo. - - - - - 12846b85 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update IOPort haddocks. - - - - - 9f39fb14 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Add a note cross reference - - - - - 62dd5a73 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Name Haskell/OS I/O Manager explicitly in Note - - - - - fa807828 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Expand BlockedOnIOCompletion description. - - - - - f0880a1d by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove historical todos - - - - - 8e58e714 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Update note, remove debugging pragma. - - - - - aa4d84d5 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: flushCharReadBuffer shouldn't need to adjust offsets. - - - - - e580893a by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove obsolete comment about cond. variables - - - - - d54e9d79 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix initial linux validate build - - - - - 3cd4de46 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix ThreadDelay001 CPP - - - - - c88b1b9f by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix openFile009 merge conflict leftover - - - - - 849e8889 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept T9681 output. GHC now reports String instead of [Char]. - - - - - e7701818 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix cabal006 after upgrading cabal submodule Demand cabal 2.0 syntax instead of >= 1.20 as required by newer cabal versions. - - - - - a44f0373 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix stderr output for ghci/linking/dyn tests. We used to filter rtsopts, i opted to instead just accept the warning of it having no effect. This works both for -rtsopts, as well as -with-rtsopts which winio adds. - - - - - 515d9896 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T15261b stdout for --io-manager flag. - - - - - 949aaacc by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T5435_dyn_asm stderr The warning about rtsopts having no consequences is expected. So accept new stderr. - - - - - 7d424e1e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Also accept T7037 stderr - - - - - 1f009768 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal04 by filtering rts args - - - - - 981a9f2e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal01 by accepting expected stderr - - - - - b7b0464e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix safePkg01 by accepting expected stderr - - - - - 32734b29 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix T5435_dyn_gcc by accepting expected stderr - - - - - acc5cebf by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix tempfiles test on linux - - - - - c577b789 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for T3807 - - - - - c108c527 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload - - - - - 2b0b9a08 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload_multiple_objs - - - - - 67afb03c by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify wording on conditional variables. - - - - - 3bd41572 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify comment on cooked mode. - - - - - ded58a03 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: update lockfile signature and remove mistaken symbol in rts. - - - - - 2143c492 by Ben Gamari at 2020-07-15T16:41:04-04:00 testsuite: Add winio and winio_threaded ways Reverts many of the testsuite changes - - - - - c0979cc5 by Ben Gamari at 2020-07-16T10:56:54-04:00 Merge remote-tracking branch 'origin/wip/winio' - - - - - 750a1595 by Ben Gamari at 2020-07-18T07:26:41-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. - - - - - 6ba6a881 by Hécate at 2020-07-18T07:26:42-04:00 Implement `fullCompilerVersion` Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403 This MR adds `fullCompilerVersion`, a function that shares the same backend as the `--numeric-version` GHC flag, exposing a full, three-digit version datatype. - - - - - e6cf27df by Hécate at 2020-07-18T07:26:43-04:00 Add a Lint hadrian rule and an .hlint.yaml file in base/ - - - - - bcb177dd by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Allow multiple case branches to have a higher rank type As #18412 points out, it should be OK for multiple case alternatives to have a higher rank type, provided they are all the same. This patch implements that change. It sweeps away GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it with an enhanced version of fillInferResult. The basic change to fillInferResult is to permit the case in which another case alternative has already filled in the result; and in that case simply unify. It's very simple actually. See the new Note [fillInferResult] in TcMType Other refactoring: - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType (previously some of it was in Unify) - Move tcInstType and friends from TcMType to Instantiate, where it more properly belongs. (TCMType was getting very long.) - - - - - e5525a51 by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Improve typechecking of NPlusK patterns This patch (due to Richard Eisenberg) improves documentation of the wrapper returned by tcSubMult (see Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify). And, more substantially, it cleans up the multiplicity handling in the typechecking of NPlusKPat - - - - - 12f90352 by Krzysztof Gogolewski at 2020-07-18T07:26:45-04:00 Remove {-# CORE #-} pragma (part of #18048) This pragma has no effect since 2011. It was introduced for External Core, which no longer exists. Updates haddock submodule. - - - - - e504c913 by Simon Peyton Jones at 2020-07-18T07:26:45-04:00 Refactor the simplification of join binders This MR (for #18449) refactors the Simplifier's treatment of join-point binders. Specifically, it puts together, into GHC.Core.Opt.Simplify.Env.adjustJoinPointType two currently-separate ways in which we adjust the type of a join point. As the comment says: -- (adjustJoinPointType mult new_res_ty join_id) does two things: -- -- 1. Set the return type of the join_id to new_res_ty -- See Note [Return type for join points] -- -- 2. Adjust the multiplicity of arrows in join_id's type, as -- directed by 'mult'. See Note [Scaling join point arguments] I think this actually fixes a latent bug, by ensuring that the seIdSubst and seInScope have the right multiplicity on the type of join points. I did some tidying up while I was at it. No more setJoinResTy, or modifyJoinResTy: instead it's done locally in Simplify.Env.adjustJoinPointType - - - - - 49b265f0 by Chaitanya Koparkar at 2020-07-18T07:26:46-04:00 Fix minor typos in a Core.hs note - - - - - 8d59aed6 by Stefan Schulze Frielinghaus at 2020-07-18T07:26:47-04:00 GHCi: Fix isLittleEndian - - - - - c26e81d1 by Ben Gamari at 2020-07-18T07:26:47-04:00 testsuite: Mark ghci tests as fragile under unreg compiler In particular I have seen T16012 fail repeatedly under the unregisterised compiler. - - - - - efef19cf by Alan Zimmerman at 2020-07-20T18:49:23+01:00 Proof of Concept implementation of in-tree API Annotations This MR introduces a possible machinery to introduce API Annotations into the TTG extension points. It is intended to be a concrete example for discussion. It still needs to process comments. ---- Work in progress, adding more TTG extensions for annotations. And fixing ppr round-trip tests by being able to blank out in-tree annotations, as done with SrcSpans. This is needed for the case of class Foo a where for which current ppr does not print the "where". Rename AA to AddApiAnn and AA to AddAnn Add XConPatIn and XConPatOut Rebase ---- First pass at bringing in LocatedA for API anns in locations Treatment of ECP in parsing is provisional at this stage, leads to some horribly stuff in Parser.y and RdrHsSyn. It is an extensive but not invasive change. I think (AZ). Locally it reports some parsing tests using less memory. Add ApiAnns to the HsExpr data structure. rebase. Change HsMatchContext and HsStmtContext to use an id, not a GhcPass parameter. Add ApiAnns to Hs/Types Rebase Rebased 2020-03-25 WIP on in-tree annotations Includes updating HsModule Imports LocateA ImportDecl so we can hang AnnSemi off it A whole bunch of stuff more InjectivityAnn and FamEqn now have annotations in them Add annotations to context srcspan ---- In-tree annotations: LHsDecl and LHsBind LocatedA ---- WIP on in-tree annotations ---- in-tree annotations: LHsType is now LocatedA ---- FunDeps is now also a HS data type ---- WIP. Added LocatedA to Pat, Expr, Decl And worked some more through Parser.y ---- LStmt now Located ---- Finished working through Parser.y, tests seem ok failures relate to annotations. Adding test infrastructure for check-exact Like check-ppr, but checking for an exact reproduction of the parsed source file. Starting to work on actual exact printer Bring in ApiAnnName As an alternative for LocatedA, to be used for names only. Carrying extra name adornments, such as locations of backticks, parens, etc. Working on changing ApiAnnName to accurately reflect actual usage Get rid of AnnApiName in favour of LocatedN Working on check-exact. Making progress Working on the ghc-exact bit Progress, can reproduce the first Test.hs file. Move API Annotations out of the extensions to annotations - - - - - e676cc0e by Alan Zimmerman at 2020-08-02T18:12:51+01:00 Remove LHsLocalBinds - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitmodules - Makefile - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/PrimOps.hs - + compiler/GHC/Builtin/RebindableNames.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Sink.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/Reg/Graph.hs - compiler/GHC/CmmToAsm/Reg/Graph/Coalesce.hs - compiler/GHC/CmmToAsm/Reg/Graph/Spill.hs - compiler/GHC/CmmToAsm/Reg/Graph/SpillClean.hs - compiler/GHC/CmmToAsm/Reg/Graph/SpillCost.hs - compiler/GHC/CmmToAsm/Reg/Graph/Stats.hs - compiler/GHC/CmmToAsm/Reg/Linear.hs - compiler/GHC/CmmToAsm/Reg/Linear/Base.hs - compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs - compiler/GHC/CmmToAsm/Reg/Linear/StackMap.hs - compiler/GHC/CmmToAsm/Reg/Linear/Stats.hs - compiler/GHC/CmmToAsm/Reg/Liveness.hs - + compiler/GHC/CmmToAsm/Reg/Utils.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fdc5119622740ad6eff59bc0dd6df4c51981f294...e676cc0e16137042103b83a5440726d1eb9ebb6e -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fdc5119622740ad6eff59bc0dd6df4c51981f294...e676cc0e16137042103b83a5440726d1eb9ebb6e You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 2 18:40:17 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 02 Aug 2020 14:40:17 -0400 Subject: [Git][ghc/ghc][wip/T17962b] Refactor handling of object merging Message-ID: <5f270891f2a33_80b3f8496224a706145620@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: 0136ded3 by Ben Gamari at 2020-08-02T14:40:09-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 21 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + res=0 + else + AC_MSG_RESULT([affected]) + res=1 + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + return $res + fi + } + + if test -z "$SettingsMergeObjectsCommand"; then + SettingsMergeObjectsCommand="$LD" + fi + if test -z "$SettingsMergeObjectsFlags"; then + SettingsMergeObjectsFlags="-r" + fi + + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_MSG_NOTICE([$SettingsMergeObjectsCommand is broken due to binutils 22266, looking for another linker...]) + SettingsMergeObjectsCommand="" + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the SettingsMergeObjectsCommand variable to a functional linker.]) + fi + fi + + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -2140,31 +2140,9 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = GHC.SysTools.runLink dflags ([ - GHC.SysTools.Option "-nostdlib", - GHC.SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in GHC.Driver.Session - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [GHC.SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [GHC.SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [GHC.SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [GHC.SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args = GHC.SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" + [ GHC.SysTools.Option "--oformat,pe-bigobj-x86-64" | OSMinGW32 == osInfo , not $ target32Bit (targetPlatform dflags) ] @@ -2176,25 +2154,24 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] - ccInfo <- getCompilerInfo dflags if ldIsGnuLd then do script <- newTempName dflags TFL_CurrentModule "ldscript" cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [GHC.SysTools.FileOption "" script] ccInfo + ld_r [GHC.SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files - ld_r [GHC.SysTools.Option "-Wl,-filelist", - GHC.SysTools.FileOption "-Wl," filelist] ccInfo + ld_r [GHC.SysTools.Option "-filelist", + GHC.SysTools.FileOption "" filelist] else do - ld_r (map (GHC.SysTools.FileOption "") o_files) ccInfo + ld_r (map (GHC.SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -102,6 +102,7 @@ module GHC.Driver.Session ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -120,6 +121,7 @@ module GHC.Driver.Session ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -142,10 +144,10 @@ module GHC.Driver.Session ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -940,6 +942,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -986,6 +990,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/GHC/Settings.hs ===================================== @@ -28,6 +28,7 @@ module GHC.Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -46,6 +47,7 @@ module GHC.Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -99,6 +101,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -124,6 +127,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] @@ -200,6 +204,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -236,6 +242,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -137,6 +137,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -183,6 +185,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -201,6 +204,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -1,4 +1,5 @@ {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- -- Tasks running external programs for SysTools @@ -299,6 +300,19 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + -- N.B. Darwin's ld64 doesn't support response files. Consequently we only + -- use them on Windows where they are truly necessary. +#if defined(mingw32_HOST_OS) + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env +#else + runSomething dflags "Merge objects" p args2 +#endif runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== configure.ac ===================================== @@ -602,13 +602,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -96,6 +96,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -115,6 +115,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -138,6 +144,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -99,6 +99,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -127,9 +127,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -311,6 +312,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -91,6 +91,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -109,6 +110,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -176,6 +179,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -191,6 +195,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -294,6 +294,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -101,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -37,6 +37,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -244,6 +245,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -223,6 +223,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -500,6 +500,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -733,7 +735,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0136ded3433543e061f26fb2224262da69f9301b -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0136ded3433543e061f26fb2224262da69f9301b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 2 20:44:21 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sun, 02 Aug 2020 16:44:21 -0400 Subject: [Git][ghc/ghc][master] Remove ConDeclGADTPrefixPs Message-ID: <5f2725a57ff32_80bf43446461550d@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - 12 changed files: - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Parser/PostProcess/Haddock.hs - compiler/GHC/Rename/Module.hs - compiler/GHC/ThToHs.hs - testsuite/tests/haddock/should_compile_flag_haddock/T17544.stderr - testsuite/tests/haddock/should_compile_flag_haddock/T17544_kw.stderr - testsuite/tests/parser/should_compile/T15323.stderr Changes: ===================================== compiler/GHC/Hs/Decls.hs ===================================== @@ -71,7 +71,7 @@ module GHC.Hs.Decls ( ForeignDecl(..), LForeignDecl, ForeignImport(..), ForeignExport(..), CImportSpec(..), -- ** Data-constructor declarations - ConDecl(..), LConDecl, ConDeclGADTPrefixPs(..), + ConDecl(..), LConDecl, HsConDeclDetails, hsConDeclArgTys, hsConDeclTheta, getConNames, getConArgs, -- ** Document comments @@ -111,7 +111,6 @@ import GHC.Core.Coercion import GHC.Types.ForeignCall import GHC.Hs.Extension import GHC.Types.Name -import GHC.Types.Name.Reader import GHC.Types.Name.Set -- others: @@ -1437,12 +1436,13 @@ data ConDecl pass { con_g_ext :: XConDeclGADT pass , con_names :: [XRec pass (IdP pass)] - -- The next four fields describe the type after the '::' + -- The following fields describe the type after the '::' -- See Note [GADT abstract syntax] - -- The following field is Located to anchor API Annotations, - -- AnnForall and AnnDot. , con_forall :: XRec pass Bool -- ^ True <=> explicit forall -- False => hsq_explicit is empty + -- + -- The 'XRec' is used to anchor API + -- annotations, AnnForall and AnnDot. , con_qvars :: [LHsTyVarBndr Specificity pass] -- Whether or not there is an /explicit/ forall, we still -- need to capture the implicitly-bound type/kind variables @@ -1479,25 +1479,18 @@ type instance XConDeclGADT GhcTc = NoExtField type instance XConDeclH98 (GhcPass _) = NoExtField -type instance XXConDecl GhcPs = ConDeclGADTPrefixPs -type instance XXConDecl GhcRn = NoExtCon -type instance XXConDecl GhcTc = NoExtCon - --- | Stores the types of prefix GADT constructors in the parser. This is used --- in lieu of ConDeclGADT, which requires knowing the specific argument and --- result types, as this is difficult to determine in general in the parser. --- See @Note [GADT abstract syntax]@. -data ConDeclGADTPrefixPs = ConDeclGADTPrefixPs - { con_gp_names :: [Located RdrName] - -- ^ The GADT constructor declaration's names. - , con_gp_ty :: LHsSigType GhcPs - -- ^ The type after the @::@. - , con_gp_doc :: Maybe LHsDocString - -- ^ A possible Haddock comment. - } +type instance XXConDecl (GhcPass _) = NoExtCon {- Note [GADT abstract syntax] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The types of both forms of GADT constructors are very structured, as they +must consist of the quantified type variables (if provided), followed by the +context (if provided), followed by the argument types (if provided), followed +by the result type. (See "Wrinkle: No nested foralls or contexts" below for +more discussion on the restrictions imposed here.) As a result, instead of +storing the type of a GADT constructor as a single LHsType, we split it up +into its constituent components for easier access. + There are two broad ways to classify GADT constructors: * Record-syntax constructors. For example: @@ -1510,48 +1503,45 @@ There are two broad ways to classify GADT constructors: data T a where K :: forall a. Ord a => [a] -> ... -> T a -Initially, both forms of GADT constructors are initially parsed as a single -LHsType. However, GADTs have a certain structure, requiring distinct argument -and result types, as well as imposing restrictions on where `forall`s and -contexts can be (see "Wrinkle: No nested foralls or contexts" below). As a -result, it is convenient to split up the LHsType into its individual -components, which are stored in the ConDeclGADT constructor of ConDecl. - -Where should this splitting occur? For GADT constructors with record syntax, -we split in the parser (in GHC.Parser.PostProcess.mkGadtDecl). We must do this -splitting before the renamer, as we need the record field names for use in -GHC.Hs.Utils.hsConDeclsBinders. +This distinction is recorded in the `con_args :: HsConDetails pass`, which +tracks if we're dealing with a RecCon or PrefixCon. It is easy to distinguish +the two in the AST since record GADT constructors use HsRecTy. This distinction +is made in GHC.Parser.PostProcess.mkGadtDecl. -For prefix GADT constructors, however, the situation is more complicated. It -can be difficult to split a prefix GADT type until we know type operator -fixities. Consider this, for example: +It is worth elaborating a bit more on the process of splitting the argument +types of a GADT constructor, since there are some non-obvious details involved. +While splitting the argument types of a record GADT constructor is easy (they +are stored in an HsRecTy), splitting the arguments of a prefix GADT constructor +is trickier. The basic idea is that we must split along the outermost function +arrows ((->) and (#->)) in the type, which GHC.Hs.Type.splitHsFunType +accomplishes. But what about type operators? Consider: C :: a :*: b -> a :*: b -> a :+: b -Initially, the type of C will parse as: +This could parse in many different ways depending on the precedences of each +type operator. In particular, if (:*:) were to have lower precedence than (->), +then it could very well parse like this: - a :*: (b -> (a :*: (b -> (a :+: b)))) + a :*: ((b -> a) :*: ((b -> a) :+: b))) -So it's hard to split up the arguments until we've done the precedence -resolution (in the renamer). (Unlike prefix GADT types, record GADT types -do not have this problem because of their uniform syntax.) +This would give the false impression that the whole type is part of one large +return type, with no arguments. Note that we do not fully resolve the exact +precedences of each user-defined type operator until the renamer, so this a +more difficult task for the parser. -As a result, we deliberately avoid splitting prefix GADT types in the parser. -Instead, we store the entire LHsType in ConDeclGADTPrefixPs, a GHC-specific -extension constructor to ConDecl. Later, in the renamer -(in GHC.Rename.Module.rnConDecl), we resolve the fixities of all type operators -in the LHsType, which facilitates splitting it into argument and result types -accurately. We finish renaming a ConDeclGADTPrefixPs by putting the split -components into a ConDeclGADT. This is why ConDeclGADTPrefixPs has the suffix --Ps, as it is only used by the parser. +Fortunately, there is no risk of the above happening. GHC's parser gives +special treatment to function arrows, and as a result, they are always parsed +with a lower precedence than any other type operator. As a result, the type +above is actually parsed like this: -Note that the existence of ConDeclGADTPrefixPs does not imply that ConDeclGADT -goes completely unused by the parser. Other consumers of GHC's abstract syntax -are still free to use ConDeclGADT. Indeed, both Haddock and Template Haskell -construct values of type `ConDecl GhcPs` by way of ConDeclGADT, as neither of -them have the same difficulties with operator precedence that GHC's parser -does. As an example, see GHC.ThToHs.cvtConstr, which converts Template Haskell -syntax into GHC syntax. + (a :*: b) -> ((a :*: b) -> (a :+: b)) + +While we won't know the exact precedences of (:*:) and (:+:) until the renamer, +all we are concerned about in the parser is identifying the overall shape of +the argument and result types, which we can accomplish by piggybacking on the +special treatment given to function arrows. In a future where function arrows +aren't given special status in the parser, we will likely have to modify +GHC.Parser.PostProcess.mergeOps to preserve this trick. ----- -- Wrinkle: No nested foralls or contexts @@ -1681,14 +1671,6 @@ pp_condecls cs [] -> False (L _ ConDeclH98{} : _) -> False (L _ ConDeclGADT{} : _) -> True - (L _ (XConDecl x) : _) -> - case ghcPass @p of - GhcPs | ConDeclGADTPrefixPs{} <- x - -> True -#if __GLASGOW_HASKELL__ < 811 - GhcRn -> noExtCon x - GhcTc -> noExtCon x -#endif instance (OutputableBndrId p) => Outputable (ConDecl (GhcPass p)) where ppr = pprConDecl @@ -1730,16 +1712,6 @@ pprConDecl (ConDeclGADT { con_names = cons, con_qvars = qvars ppr_arrow_chain (a:as) = sep (a : map (arrow <+>) as) ppr_arrow_chain [] = empty -pprConDecl (XConDecl x) = - case ghcPass @p of - GhcPs | ConDeclGADTPrefixPs { con_gp_names = cons, con_gp_ty = ty - , con_gp_doc = doc } <- x - -> ppr_mbDoc doc <+> ppr_con_names cons <+> dcolon <+> ppr ty -#if __GLASGOW_HASKELL__ < 811 - GhcRn -> noExtCon x - GhcTc -> noExtCon x -#endif - ppr_con_names :: (OutputableBndr a) => [Located a] -> SDoc ppr_con_names = pprWithCommas (pprPrefixOcc . unLoc) ===================================== compiler/GHC/Hs/Instances.hs ===================================== @@ -168,8 +168,6 @@ deriving instance Data (ConDecl GhcPs) deriving instance Data (ConDecl GhcRn) deriving instance Data (ConDecl GhcTc) -deriving instance Data ConDeclGADTPrefixPs - -- deriving instance DataIdLR p p => Data (TyFamInstDecl p) deriving instance Data (TyFamInstDecl GhcPs) deriving instance Data (TyFamInstDecl GhcRn) ===================================== compiler/GHC/Hs/Type.hs ===================================== @@ -68,7 +68,7 @@ module GHC.Hs.Type ( splitLHsInstDeclTy, getLHsInstDeclHead, getLHsInstDeclClass_maybe, splitLHsPatSynTy, splitLHsForAllTyInvis, splitLHsForAllTyInvis_KP, splitLHsQualTy, - splitLHsSigmaTyInvis, splitLHsGADTPrefixTy, + splitLHsSigmaTyInvis, splitLHsGadtTy, splitHsFunType, hsTyGetAppHead_maybe, mkHsOpTy, mkHsAppTy, mkHsAppTys, mkHsAppKindTy, ignoreParens, hsSigType, hsSigWcType, hsPatSigType, @@ -1331,7 +1331,9 @@ mkHsAppKindTy ext ty k -- splitHsFunType decomposes a type (t1 -> t2 ... -> tn) -- Breaks up any parens in the result type: -- splitHsFunType (a -> (b -> c)) = ([a,b], c) -splitHsFunType :: LHsType GhcRn -> ([HsScaled GhcRn (LHsType GhcRn)], LHsType GhcRn) +splitHsFunType :: + LHsType (GhcPass p) + -> ([HsScaled (GhcPass p) (LHsType (GhcPass p))], LHsType (GhcPass p)) splitHsFunType (L _ (HsParTy _ ty)) = splitHsFunType ty @@ -1460,7 +1462,7 @@ splitLHsSigmaTyInvis_KP ty , (mb_ctxt, ty2) <- splitLHsQualTy_KP ty1 = (mb_tvbs, mb_ctxt, ty2) --- | Decompose a prefix GADT type into its constituent parts. +-- | Decompose a GADT type into its constituent parts. -- Returns @(mb_tvbs, mb_ctxt, body)@, where: -- -- * @mb_tvbs@ are @Just@ the leading @forall at s, if they are provided. @@ -1474,10 +1476,10 @@ splitLHsSigmaTyInvis_KP ty -- This function is careful not to look through parentheses. -- See @Note [GADT abstract syntax] (Wrinkle: No nested foralls or contexts)@ -- "GHC.Hs.Decls" for why this is important. -splitLHsGADTPrefixTy :: +splitLHsGadtTy :: LHsType (GhcPass pass) -> (Maybe [LHsTyVarBndr Specificity (GhcPass pass)], Maybe (LHsContext (GhcPass pass)), LHsType (GhcPass pass)) -splitLHsGADTPrefixTy = splitLHsSigmaTyInvis_KP +splitLHsGadtTy = splitLHsSigmaTyInvis_KP -- | Decompose a type of the form @forall . body@ into its constituent -- parts. Only splits type variable binders that ===================================== compiler/GHC/Hs/Utils.hs ===================================== @@ -1265,16 +1265,6 @@ hsConDeclsBinders cons (remSeen', flds) = get_flds remSeen args (ns, fs) = go remSeen' rs - XConDecl x -> case ghcPass @p of - GhcPs | ConDeclGADTPrefixPs { con_gp_names = names } <- x - -> (map (L loc . unLoc) names ++ ns, fs) -#if __GLASGOW_HASKELL__ < 811 - GhcRn -> noExtCon x - GhcTc -> noExtCon x -#endif - where - (ns, fs) = go remSeen rs - get_flds :: Seen p -> HsConDeclDetails (GhcPass p) -> (Seen p, [LFieldOcc (GhcPass p)]) get_flds remSeen (RecCon flds) ===================================== compiler/GHC/Parser.y ===================================== @@ -2176,8 +2176,9 @@ gadt_constr :: { LConDecl GhcPs } -- see Note [Difference in parsing GADT and data constructors] -- Returns a list because of: C,D :: ty : optSemi con_list '::' sigtype - {% ams (sLL $2 $> (mkGadtDecl (unLoc $2) $4)) - [mu AnnDcolon $3] } + {% do { decl <- mkGadtDecl (unLoc $2) $4 + ; ams (sLL $2 $> decl) + [mu AnnDcolon $3] } } {- Note [Difference in parsing GADT and data constructors] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -670,34 +670,41 @@ mkConDeclH98 name mb_forall mb_cxt args , con_doc = Nothing } -- | Construct a GADT-style data constructor from the constructor names and --- their type. This will return different AST forms for record syntax --- constructors and prefix constructors, as the latter must be handled --- specially in the renamer. See @Note [GADT abstract syntax]@ in --- "GHC.Hs.Decls" for the full story. +-- their type. Some interesting aspects of this function: +-- +-- * This splits up the constructor type into its quantified type variables (if +-- provided), context (if provided), argument types, and result type, and +-- records whether this is a prefix or record GADT constructor. See +-- Note [GADT abstract syntax] in "GHC.Hs.Decls" for more details. +-- +-- * If -XLinearTypes is not enabled, the function arrows in a prefix GADT +-- constructor are always interpreted as linear. If -XLinearTypes is enabled, +-- we faithfully record whether -> or #-> was used. mkGadtDecl :: [Located RdrName] -> LHsType GhcPs - -> ConDecl GhcPs -mkGadtDecl names ty - | Just (mtvs, mcxt, args, res_ty) <- mb_record_gadt ty - = ConDeclGADT { con_g_ext = noExtField - , con_names = names - , con_forall = L (getLoc ty) $ isJust mtvs - , con_qvars = fromMaybe [] mtvs - , con_mb_cxt = mcxt - , con_args = args - , con_res_ty = res_ty - , con_doc = Nothing } - | otherwise - = XConDecl $ ConDeclGADTPrefixPs { con_gp_names = names - , con_gp_ty = mkLHsSigType ty - , con_gp_doc = Nothing } + -> P (ConDecl GhcPs) +mkGadtDecl names ty = do + linearEnabled <- getBit LinearTypesBit + + let (args, res_ty) + | L _ (HsFunTy _ _w (L loc (HsRecTy _ rf)) res_ty) <- body_ty + = (RecCon (L loc rf), res_ty) + | otherwise + = let (arg_types, res_type) = splitHsFunType body_ty + arg_types' | linearEnabled = arg_types + | otherwise = map (hsLinear . hsScaledThing) arg_types + in (PrefixCon arg_types', res_type) + + pure $ ConDeclGADT { con_g_ext = noExtField + , con_names = names + , con_forall = L (getLoc ty) $ isJust mtvs + , con_qvars = fromMaybe [] mtvs + , con_mb_cxt = mcxt + , con_args = args + , con_res_ty = res_ty + , con_doc = Nothing } where - mb_record_gadt ty - | (mtvs, mcxt, body_ty) <- splitLHsGADTPrefixTy ty - , L _ (HsFunTy _ _w (L loc (HsRecTy _ rf)) res_ty) <- body_ty - = Just (mtvs, mcxt, RecCon (L loc rf), res_ty) - | otherwise - = Nothing + (mtvs, mcxt, body_ty) = splitLHsGadtTy ty setRdrNameSpace :: RdrName -> NameSpace -> RdrName -- ^ This rather gruesome function is used mainly by the parser. ===================================== compiler/GHC/Parser/PostProcess/Haddock.hs ===================================== @@ -716,15 +716,6 @@ instance HasHaddock (Located (ConDecl GhcPs)) where ConDeclH98 { con_ext, con_name, con_forall, con_ex_tvs, con_mb_cxt, con_doc = con_doc', con_args = RecCon (L l_rec flds') } - XConDecl (ConDeclGADTPrefixPs { con_gp_names, con_gp_ty }) -> do - -- discardHasInnerDocs is ok because we don't need this info for GADTs. - con_gp_doc' <- discardHasInnerDocs $ getConDoc (getLoc (head con_gp_names)) - con_gp_ty' <- addHaddock con_gp_ty - pure $ L l_con_decl $ - XConDecl (ConDeclGADTPrefixPs - { con_gp_names, - con_gp_ty = con_gp_ty', - con_gp_doc = con_gp_doc' }) -- Keep track of documentation comments on the data constructor or any of its -- fields. ===================================== compiler/GHC/Rename/Module.hs ===================================== @@ -1856,7 +1856,6 @@ rnDataDefn doc (HsDataDefn { dd_ND = new_or_data, dd_cType = cType where h98_style = case condecls of -- Note [Stupid theta] (L _ (ConDeclGADT {})) : _ -> False - (L _ (XConDecl (ConDeclGADTPrefixPs {}))) : _ -> False _ -> True rn_derivs (L loc ds) @@ -2246,6 +2245,12 @@ rnConDecl decl@(ConDeclGADT { con_names = names ; (new_args, fvs2) <- rnConDeclDetails (unLoc (head new_names)) ctxt args ; (new_res_ty, fvs3) <- rnLHsType ctxt res_ty + -- Ensure that there are no nested `forall`s or contexts, per + -- Note [GADT abstract syntax] (Wrinkle: No nested foralls or contexts) + -- in GHC.Hs.Type. + ; addNoNestedForallsContextsErr ctxt + (text "GADT constructor type signature") new_res_ty + ; let all_fvs = fvs1 `plusFV` fvs2 `plusFV` fvs3 ; traceRn "rnConDecl (ConDeclGADT)" @@ -2257,47 +2262,6 @@ rnConDecl decl@(ConDeclGADT { con_names = names , con_forall = forall }, -- Remove when #18311 is fixed all_fvs) } } --- This case is only used for prefix GADT constructors generated by GHC's --- parser, where we do not know the argument types until type operator --- precedence has been resolved. See Note [GADT abstract syntax] in --- GHC.Hs.Decls for the full story. -rnConDecl (XConDecl (ConDeclGADTPrefixPs { con_gp_names = names, con_gp_ty = ty - , con_gp_doc = mb_doc })) - = do { mapM_ (addLocM checkConName) names - ; new_names <- mapM lookupLocatedTopBndrRn names - ; mb_doc' <- rnMbLHsDoc mb_doc - - ; let ctxt = ConDeclCtx new_names - ; (ty', fvs) <- rnHsSigType ctxt TypeLevel ty - ; linearTypes <- xopt LangExt.LinearTypes <$> getDynFlags - - -- Now that operator precedence has been resolved, we can split the - -- GADT type into its individual components below. - ; let HsIB { hsib_ext = implicit_tkvs, hsib_body = body } = ty' - (mb_explicit_tkvs, mb_cxt, tau) = splitLHsGADTPrefixTy body - lhas_forall = L (getLoc body) $ isJust mb_explicit_tkvs - explicit_tkvs = fromMaybe [] mb_explicit_tkvs - (arg_tys, res_ty) = splitHsFunType tau - arg_details | linearTypes = PrefixCon arg_tys - | otherwise = PrefixCon $ map (hsLinear . hsScaledThing) arg_tys - - -- NB: The only possibility here is PrefixCon. RecCon is handled - -- separately, through ConDeclGADT, from the parser onwards. - - -- Ensure that there are no nested `forall`s or contexts, per - -- Note [GADT abstract syntax] (Wrinkle: No nested foralls or contexts) - -- in GHC.Hs.Type. - ; addNoNestedForallsContextsErr ctxt - (text "GADT constructor type signature") res_ty - - ; traceRn "rnConDecl (ConDeclGADTPrefixPs)" - (ppr names $$ ppr implicit_tkvs $$ ppr explicit_tkvs) - ; pure (ConDeclGADT { con_g_ext = implicit_tkvs, con_names = new_names - , con_forall = lhas_forall, con_qvars = explicit_tkvs - , con_mb_cxt = mb_cxt, con_args = arg_details - , con_res_ty = res_ty, con_doc = mb_doc' }, - fvs) } - rnMbContext :: HsDocContext -> Maybe (LHsContext GhcPs) -> RnM (Maybe (LHsContext GhcRn), FreeVars) rnMbContext _ Nothing = return (Nothing, emptyFVs) ===================================== compiler/GHC/ThToHs.hs ===================================== @@ -611,14 +611,6 @@ cvtConstr (ForallC tvs ctxt con) where all_tvs = tvs' ++ ex_tvs - -- The GadtC and RecGadtC cases of cvtConstr will always return a - -- ConDeclGADT, not a ConDeclGADTPrefixPs, so this case is unreachable. - -- See Note [GADT abstract syntax] in GHC.Hs.Decls for more on the - -- distinction between ConDeclGADT and ConDeclGADTPrefixPs. - add_forall _ _ con@(XConDecl (ConDeclGADTPrefixPs {})) = - pprPanic "cvtConstr.add_forall: Unexpected ConDeclGADTPrefixPs" - (Outputable.ppr con) - cvtConstr (GadtC [] _strtys _ty) = failWith (text "GadtC must have at least one constructor name") ===================================== testsuite/tests/haddock/should_compile_flag_haddock/T17544.stderr ===================================== @@ -372,31 +372,35 @@ (Nothing) (Nothing) [({ T17544.hs:25:5-18 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544.hs:25:5-8 } - (Unqual - {OccName: MkD5}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544.hs:25:5-8 } + (Unqual + {OccName: MkD5}))] + ({ T17544.hs:25:13-18 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544.hs:25:13-18 } + (HsAppTy (NoExtField) - ({ T17544.hs:25:13-18 } - (HsAppTy + ({ T17544.hs:25:13-14 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544.hs:25:13-14 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:25:13-14 } - (Unqual - {OccName: D5})))) + (Unqual + {OccName: D5})))) + ({ T17544.hs:25:16-18 } + (HsTyVar + (NoExtField) + (NotPromoted) ({ T17544.hs:25:16-18 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:25:16-18 } - (Unqual - {OccName: Int}))))))) - (Nothing))))] + (Unqual + {OccName: Int})))))) + (Nothing)))] ({ } []))))))] (Nothing))))) @@ -504,31 +508,35 @@ (Nothing) (Nothing) [({ T17544.hs:31:5-18 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544.hs:31:5-8 } - (Unqual - {OccName: MkD6}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544.hs:31:5-8 } + (Unqual + {OccName: MkD6}))] + ({ T17544.hs:31:13-18 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544.hs:31:13-18 } + (HsAppTy (NoExtField) - ({ T17544.hs:31:13-18 } - (HsAppTy + ({ T17544.hs:31:13-14 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544.hs:31:13-14 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:31:13-14 } - (Unqual - {OccName: D6})))) + (Unqual + {OccName: D6})))) + ({ T17544.hs:31:16-18 } + (HsTyVar + (NoExtField) + (NotPromoted) ({ T17544.hs:31:16-18 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:31:16-18 } - (Unqual - {OccName: Int}))))))) - (Nothing))))] + (Unqual + {OccName: Int})))))) + (Nothing)))] ({ } []))))))] (Nothing))))) @@ -636,31 +644,35 @@ (Nothing) (Nothing) [({ T17544.hs:37:5-18 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544.hs:37:5-8 } - (Unqual - {OccName: MkD7}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544.hs:37:5-8 } + (Unqual + {OccName: MkD7}))] + ({ T17544.hs:37:13-18 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544.hs:37:13-18 } + (HsAppTy (NoExtField) - ({ T17544.hs:37:13-18 } - (HsAppTy + ({ T17544.hs:37:13-14 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544.hs:37:13-14 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:37:13-14 } - (Unqual - {OccName: D7})))) + (Unqual + {OccName: D7})))) + ({ T17544.hs:37:16-18 } + (HsTyVar + (NoExtField) + (NotPromoted) ({ T17544.hs:37:16-18 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:37:16-18 } - (Unqual - {OccName: Int}))))))) - (Nothing))))] + (Unqual + {OccName: Int})))))) + (Nothing)))] ({ } []))))))] (Nothing))))) @@ -768,31 +780,35 @@ (Nothing) (Nothing) [({ T17544.hs:43:5-18 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544.hs:43:5-8 } - (Unqual - {OccName: MkD8}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544.hs:43:5-8 } + (Unqual + {OccName: MkD8}))] + ({ T17544.hs:43:13-18 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544.hs:43:13-18 } + (HsAppTy (NoExtField) - ({ T17544.hs:43:13-18 } - (HsAppTy + ({ T17544.hs:43:13-14 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544.hs:43:13-14 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:43:13-14 } - (Unqual - {OccName: D8})))) + (Unqual + {OccName: D8})))) + ({ T17544.hs:43:16-18 } + (HsTyVar + (NoExtField) + (NotPromoted) ({ T17544.hs:43:16-18 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:43:16-18 } - (Unqual - {OccName: Int}))))))) - (Nothing))))] + (Unqual + {OccName: Int})))))) + (Nothing)))] ({ } []))))))] (Nothing))))) @@ -900,31 +916,35 @@ (Nothing) (Nothing) [({ T17544.hs:49:5-18 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544.hs:49:5-8 } - (Unqual - {OccName: MkD9}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544.hs:49:5-8 } + (Unqual + {OccName: MkD9}))] + ({ T17544.hs:49:13-18 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544.hs:49:13-18 } + (HsAppTy (NoExtField) - ({ T17544.hs:49:13-18 } - (HsAppTy + ({ T17544.hs:49:13-14 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544.hs:49:13-14 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:49:13-14 } - (Unqual - {OccName: D9})))) + (Unqual + {OccName: D9})))) + ({ T17544.hs:49:16-18 } + (HsTyVar + (NoExtField) + (NotPromoted) ({ T17544.hs:49:16-18 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:49:16-18 } - (Unqual - {OccName: Int}))))))) - (Nothing))))] + (Unqual + {OccName: Int})))))) + (Nothing)))] ({ } []))))))] (Nothing))))) @@ -1032,31 +1052,35 @@ (Nothing) (Nothing) [({ T17544.hs:55:5-20 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544.hs:55:5-9 } - (Unqual - {OccName: MkD10}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544.hs:55:5-9 } + (Unqual + {OccName: MkD10}))] + ({ T17544.hs:55:14-20 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544.hs:55:14-20 } + (HsAppTy (NoExtField) - ({ T17544.hs:55:14-20 } - (HsAppTy + ({ T17544.hs:55:14-16 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544.hs:55:14-16 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:55:14-16 } - (Unqual - {OccName: D10})))) + (Unqual + {OccName: D10})))) + ({ T17544.hs:55:18-20 } + (HsTyVar + (NoExtField) + (NotPromoted) ({ T17544.hs:55:18-20 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544.hs:55:18-20 } - (Unqual - {OccName: Int}))))))) - (Nothing))))] + (Unqual + {OccName: Int})))))) + (Nothing)))] ({ } []))))))] (Nothing))))) ===================================== testsuite/tests/haddock/should_compile_flag_haddock/T17544_kw.stderr ===================================== @@ -30,24 +30,28 @@ (Nothing) (Nothing) [({ T17544_kw.hs:16:9-20 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544_kw.hs:16:9-13 } - (Unqual - {OccName: MkFoo}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544_kw.hs:16:9-13 } + (Unqual + {OccName: MkFoo}))] + ({ T17544_kw.hs:16:18-20 } + (False)) + [] + (Nothing) + (PrefixCon + []) + ({ T17544_kw.hs:16:18-20 } + (HsTyVar (NoExtField) + (NotPromoted) ({ T17544_kw.hs:16:18-20 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544_kw.hs:16:18-20 } - (Unqual - {OccName: Foo}))))) - (Just - ({ T17544_kw.hs:15:10-35 } - (HsDocString - " Bad comment for MkFoo"))))))] + (Unqual + {OccName: Foo})))) + (Just + ({ T17544_kw.hs:15:10-35 } + (HsDocString + " Bad comment for MkFoo")))))] ({ } []))))) ,({ T17544_kw.hs:(18,1)-(19,26) } @@ -70,33 +74,34 @@ (Nothing) (Nothing) [({ T17544_kw.hs:19:9-26 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T17544_kw.hs:19:9-13 } - (Unqual - {OccName: MkBar}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T17544_kw.hs:19:9-13 } + (Unqual + {OccName: MkBar}))] + ({ T17544_kw.hs:19:18-26 } + (False)) + [] + (Nothing) + (PrefixCon + [(HsScaled + (HsLinearArrow) + ({ T17544_kw.hs:19:18-19 } + (HsTupleTy + (NoExtField) + (HsBoxedOrConstraintTuple) + [])))]) + ({ T17544_kw.hs:19:24-26 } + (HsTyVar (NoExtField) - ({ T17544_kw.hs:19:18-26 } - (HsFunTy - (NoExtField) - (HsUnrestrictedArrow) - ({ T17544_kw.hs:19:18-19 } - (HsTupleTy - (NoExtField) - (HsBoxedOrConstraintTuple) - [])) - ({ T17544_kw.hs:19:24-26 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T17544_kw.hs:19:24-26 } - (Unqual - {OccName: Bar}))))))) - (Just - ({ T17544_kw.hs:18:13-38 } - (HsDocString - " Bad comment for MkBar"))))))] + (NotPromoted) + ({ T17544_kw.hs:19:24-26 } + (Unqual + {OccName: Bar})))) + (Just + ({ T17544_kw.hs:18:13-38 } + (HsDocString + " Bad comment for MkBar")))))] ({ } []))))) ,({ T17544_kw.hs:(21,1)-(24,18) } ===================================== testsuite/tests/parser/should_compile/T15323.stderr ===================================== @@ -36,67 +36,62 @@ (Nothing) (Nothing) [({ T15323.hs:6:5-54 } - (XConDecl - (ConDeclGADTPrefixPs - [({ T15323.hs:6:5-14 } - (Unqual - {OccName: TestParens}))] - (HsIB + (ConDeclGADT + (NoExtField) + [({ T15323.hs:6:5-14 } + (Unqual + {OccName: TestParens}))] + ({ T15323.hs:6:20-54 } + (True)) + [({ T15323.hs:6:27 } + (UserTyVar + (NoExtField) + (SpecifiedSpec) + ({ T15323.hs:6:27 } + (Unqual + {OccName: v}))))] + (Just + ({ T15323.hs:6:31-36 } + [({ T15323.hs:6:31-36 } + (HsParTy + (NoExtField) + ({ T15323.hs:6:32-35 } + (HsAppTy + (NoExtField) + ({ T15323.hs:6:32-33 } + (HsTyVar + (NoExtField) + (NotPromoted) + ({ T15323.hs:6:32-33 } + (Unqual + {OccName: Eq})))) + ({ T15323.hs:6:35 } + (HsTyVar + (NoExtField) + (NotPromoted) + ({ T15323.hs:6:35 } + (Unqual + {OccName: v}))))))))])) + (PrefixCon + []) + ({ T15323.hs:6:41-54 } + (HsAppTy (NoExtField) - ({ T15323.hs:6:20-54 } - (HsForAllTy + ({ T15323.hs:6:41-52 } + (HsTyVar (NoExtField) - (HsForAllInvis - (NoExtField) - [({ T15323.hs:6:27 } - (UserTyVar - (NoExtField) - (SpecifiedSpec) - ({ T15323.hs:6:27 } - (Unqual - {OccName: v}))))]) - ({ T15323.hs:6:31-54 } - (HsQualTy - (NoExtField) - ({ T15323.hs:6:31-36 } - [({ T15323.hs:6:31-36 } - (HsParTy - (NoExtField) - ({ T15323.hs:6:32-35 } - (HsAppTy - (NoExtField) - ({ T15323.hs:6:32-33 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T15323.hs:6:32-33 } - (Unqual - {OccName: Eq})))) - ({ T15323.hs:6:35 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T15323.hs:6:35 } - (Unqual - {OccName: v}))))))))]) - ({ T15323.hs:6:41-54 } - (HsAppTy - (NoExtField) - ({ T15323.hs:6:41-52 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T15323.hs:6:41-52 } - (Unqual - {OccName: MaybeDefault})))) - ({ T15323.hs:6:54 } - (HsTyVar - (NoExtField) - (NotPromoted) - ({ T15323.hs:6:54 } - (Unqual - {OccName: v}))))))))))) - (Nothing))))] + (NotPromoted) + ({ T15323.hs:6:41-52 } + (Unqual + {OccName: MaybeDefault})))) + ({ T15323.hs:6:54 } + (HsTyVar + (NoExtField) + (NotPromoted) + ({ T15323.hs:6:54 } + (Unqual + {OccName: v})))))) + (Nothing)))] ({ } [])))))] (Nothing) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/226417424b2b578fd3c5424588367cb24e7720eb -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/226417424b2b578fd3c5424588367cb24e7720eb You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 2 20:44:54 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sun, 02 Aug 2020 16:44:54 -0400 Subject: [Git][ghc/ghc][master] Fix GHC_STAGE definition generated by make Message-ID: <5f2725c66656b_80b10e6f9b4615887d@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 1 changed file: - includes/ghc.mk Changes: ===================================== includes/ghc.mk ===================================== @@ -163,7 +163,7 @@ $$(includes_$1_H_PLATFORM) : includes/ghc.mk includes/Makefile | $$$$(dir $$$$@) @echo "#if !defined(__GHCPLATFORM_H__)" > $$@ @echo "#define __GHCPLATFORM_H__" >> $$@ @echo >> $$@ - @echo "#define GHC_STAGE $1" >> $$@ + @echo "#define GHC_STAGE ($1 + 1)" >> $$@ @echo >> $$@ @echo "#define BuildPlatform_TYPE $(BuildPlatform_$1_CPP)" >> $$@ @echo "#define HostPlatform_TYPE $(HostPlatform_$1_CPP)" >> $$@ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f2d1accf67cb6e1dab6b2c78fef4b64526c31a4a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f2d1accf67cb6e1dab6b2c78fef4b64526c31a4a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 2 21:24:19 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 02 Aug 2020 17:24:19 -0400 Subject: [Git][ghc/ghc][wip/T17962b] Refactor handling of object merging Message-ID: <5f272f035307_80b3f848c1e06f46172751@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: ee482622 by Ben Gamari at 2020-08-02T17:24:10-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 21 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + res=0 + else + AC_MSG_RESULT([affected]) + res=1 + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + return $res + fi + } + + if test -z "$SettingsMergeObjectsCommand"; then + SettingsMergeObjectsCommand="$LD" + fi + if test -z "$SettingsMergeObjectsFlags"; then + SettingsMergeObjectsFlags="-r" + fi + + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_MSG_NOTICE([$SettingsMergeObjectsCommand is broken due to binutils 22266, looking for another linker...]) + SettingsMergeObjectsCommand="" + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the SettingsMergeObjectsCommand variable to a functional linker.]) + fi + fi + + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -2140,34 +2140,13 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = GHC.SysTools.runLink dflags ([ - GHC.SysTools.Option "-nostdlib", - GHC.SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in GHC.Driver.Session - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [GHC.SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [GHC.SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [GHC.SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [GHC.SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args = GHC.SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" - | OSMinGW32 == osInfo - , not $ target32Bit (targetPlatform dflags) - ] + concat + [ [GHC.SysTools.Option "--oformat", GHC.SysTools.Option "pe-bigobj-x86-64"] + | OSMinGW32 == osInfo + , not $ target32Bit (targetPlatform dflags) + ] ++ map GHC.SysTools.Option ld_build_id ++ [ GHC.SysTools.Option "-o", GHC.SysTools.FileOption "" output_fn ] @@ -2176,25 +2155,24 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] - ccInfo <- getCompilerInfo dflags if ldIsGnuLd then do script <- newTempName dflags TFL_CurrentModule "ldscript" cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [GHC.SysTools.FileOption "" script] ccInfo + ld_r [GHC.SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files - ld_r [GHC.SysTools.Option "-Wl,-filelist", - GHC.SysTools.FileOption "-Wl," filelist] ccInfo + ld_r [GHC.SysTools.Option "-filelist", + GHC.SysTools.FileOption "" filelist] else do - ld_r (map (GHC.SysTools.FileOption "") o_files) ccInfo + ld_r (map (GHC.SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -102,6 +102,7 @@ module GHC.Driver.Session ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -120,6 +121,7 @@ module GHC.Driver.Session ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -142,10 +144,10 @@ module GHC.Driver.Session ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -940,6 +942,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -986,6 +990,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/GHC/Settings.hs ===================================== @@ -28,6 +28,7 @@ module GHC.Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -46,6 +47,7 @@ module GHC.Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -99,6 +101,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -124,6 +127,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] @@ -200,6 +204,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -236,6 +242,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -137,6 +137,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -183,6 +185,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -201,6 +204,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -1,4 +1,5 @@ {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- -- Tasks running external programs for SysTools @@ -299,6 +300,19 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + -- N.B. Darwin's ld64 doesn't support response files. Consequently we only + -- use them on Windows where they are truly necessary. +#if defined(mingw32_HOST_OS) + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env +#else + runSomething dflags "Merge objects" p args2 +#endif runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== configure.ac ===================================== @@ -602,13 +602,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -96,6 +96,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -115,6 +115,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -138,6 +144,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -99,6 +99,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -127,9 +127,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -311,6 +312,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -91,6 +91,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -109,6 +110,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -176,6 +179,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -191,6 +195,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -294,6 +294,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -101,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -37,6 +37,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -244,6 +245,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -223,6 +223,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -500,6 +500,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -733,7 +735,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ee482622ef4247700abeede5c5f200284a493719 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ee482622ef4247700abeede5c5f200284a493719 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 3 08:49:19 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Mon, 03 Aug 2020 04:49:19 -0400 Subject: [Git][ghc/ghc][wip/T8095-spj] CI adjustments Message-ID: <5f27cf8f39a3d_80b8ca3ed06214110@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T8095-spj at Glasgow Haskell Compiler / GHC Commits: 5d6395d1 by Simon Peyton Jones at 2020-08-03T09:47:21+01:00 CI adjustments This patch temporarily * Marks -ddump-coercions as undocumented (so that CI doesn't stumble) * Adds -ddump-coercions to TEST_HC so that all tests run with it on - - - - - 2 changed files: - docs/users_guide/expected-undocumented-flags.txt - testsuite/mk/test.mk Changes: ===================================== docs/users_guide/expected-undocumented-flags.txt ===================================== @@ -169,3 +169,4 @@ -ticky-LNE -ticky-allocd -ticky-dyn-thunk +-ddrop-coercions ===================================== testsuite/mk/test.mk ===================================== @@ -37,7 +37,7 @@ endif # TEST_HC_OPTS is passed to every invocation of TEST_HC # in nested Makefiles TEST_HC_OPTS = -dcore-lint -dstg-lint -dcmm-lint \ - -no-user-$(GhcPackageDbFlag) -rtsopts $(EXTRA_HC_OPTS) + -no-user-$(GhcPackageDbFlag) -rtsopts $(EXTRA_HC_OPTS) -ddrop-coercions ifeq "$(MinGhcVersion711)" "YES" # Don't warn about missing specialisations. They can only occur with `-O`, but View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5d6395d10e6edebade963477fc7f703161d5d837 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5d6395d10e6edebade963477fc7f703161d5d837 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 3 09:20:03 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Mon, 03 Aug 2020 05:20:03 -0400 Subject: [Git][ghc/ghc][wip/T18126] 92 commits: DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) Message-ID: <5f27d6c351ff1_80b3f849a265454621890@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18126 at Glasgow Haskell Compiler / GHC Commits: 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - db113646 by Simon Peyton Jones at 2020-08-03T10:18:50+01:00 Implement Quick Look impredicativity This patch implements Quick Look impredicativity (#18126), sticking very closely to the design in A quick look at impredicativity, Serrano et al, ICFP 2020 The main change is that a big chunk of GHC.Tc.Gen.Expr has been extracted to two new modules GHC.Tc.Gen.App GHC.Tc.Gen.Head which deal with typechecking n-ary applications, and the head of such applications, respectively. Both contain a good deal of documentation. Three other loosely-related changes are in this patch: * I implemented (partly by accident) point (2) of the accepted GHC proposal "Clean up printing of foralls", namely https://github.com/ghc-proposals/ghc-proposals/blob/ master/proposals/0179-printing-foralls.rst In particular, see Note [TcRnExprMode] in GHC.Tc.Module - :type instantiates /inferred/, but not /specified/, quantifiers - :type +d instantiates /all/ quantifiers - :type +v is killed off * HsRecFld (which the renamer introduces for record field selectors), is now preserved by the typechecker, rather than being rewritten back to HsVar. This is more uniform, and turned out to be more convenient in the new scheme of things. * The GHCi debugger uses a non-standard unification that allows the unification variables to unify with polytypes. We used to hack this by using ImpredicativeTypes, but that doesn't work anymore so I introduces RuntimeUnkTv. See Note [RuntimeUnkTv] in GHC.Runtime.Heap.Inspect WARNING: this patch won't validate on its own. It was too hard to fully disentangle it from the following patch, on type errors and kind generalisation. Changes to tests * Fixes #9730 (test added) * Fixes #7026 (test added) * Fixes most of #8808, except function `g2'` which uses a section (which doesn't play with QL yet -- see #18126) Test added * Fixes #1330. NB Church1.hs subsumes Church2.hs, which is now deleted * Fixes #17332 (test added) * Fixes #4295 * This patch makes typecheck/should_run/T7861 fail. But that turns out to be a pre-existing bug: #18467. So I have just made T7861 into expect_broken(18467) - - - - - 24089329 by Simon Peyton Jones at 2020-08-03T10:19:26+01:00 Improve kind generalisation, error messages This patch does two things: * It refactors GHC.Tc.Errors a bit. In debugging Quick Look I was forced to look in detail at error messages, and ended up doing a bit of refactoring, esp in mkTyVarEqErr'. It's still quite a mess, but a bit better, I think. * It makes a significant improvement to the kind checking of type and class declarations. Specifically, we now ensure that if kind checking fails with an unsolved constraint, all the skolems are in scope. That wasn't the case before, which led to some obscure error messages; and occasional failures with "no skolem info" (eg #16245). Both of these, and the main Quick Look patch itself, affect a /lot/ of error messages, as you can see from the number of files changed. I've checked them all; I think they are as good or better than before. Smaller things * I documented the various instances of VarBndr better. See Note [The VarBndr tyep and its uses] in GHC.Types.Var * Renamed GHC.Tc.Solver.simpl_top to simplifyTopWanteds * A bit of refactoring in bindExplicitTKTele, to avoid the footwork with Either. Simpler now. * Move promoteTyVar from GHC.Tc.Solver to GHC.Tc.Utils.TcMType Fixes #16245 (comment 211369), memorialised as typeecheck/polykinds/T16245a - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/test-metrics.sh - CODEOWNERS - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/Graph.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Monad.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Switch/Implement.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/Config.hs - compiler/GHC/CmmToAsm/Dwarf/Types.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/29962b14c720698dba888b6d62ad3d80d65eeb29...24089329113711303742306177fa5be64ca85879 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/29962b14c720698dba888b6d62ad3d80d65eeb29...24089329113711303742306177fa5be64ca85879 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 3 09:22:01 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Mon, 03 Aug 2020 05:22:01 -0400 Subject: [Git][ghc/ghc][wip/T18323] 6 commits: Refactor CLabel pretty-printing Message-ID: <5f27d739538df_80b3f849c1caa10622001d@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18323 at Glasgow Haskell Compiler / GHC Commits: 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 997c5ab9 by Simon Peyton Jones at 2020-08-03T10:21:24+01:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 30 changed files: - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/Dwarf/Types.hs - compiler/GHC/CmmToAsm/PIC.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Coverage.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Parser/PostProcess/Haddock.hs - compiler/GHC/Rename/Module.hs - compiler/GHC/StgToCmm.hs - compiler/GHC/StgToCmm/Bind.hs - compiler/GHC/StgToCmm/Closure.hs - compiler/GHC/StgToCmm/Heap.hs - compiler/GHC/StgToCmm/Layout.hs - compiler/GHC/Tc/Gen/Bind.hs - compiler/GHC/Tc/Gen/Match.hs - compiler/GHC/Tc/Gen/Match.hs-boot The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7f19e539c0a4c775478a26e172f681084781e017...997c5ab975254481d30a9c46ab7c011bd857c2c9 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7f19e539c0a4c775478a26e172f681084781e017...997c5ab975254481d30a9c46ab7c011bd857c2c9 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 3 11:50:00 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Mon, 03 Aug 2020 07:50:00 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: Remove ConDeclGADTPrefixPs Message-ID: <5f27f9e8443_80b3f849c1caa10624764c@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 991b7bc9 by Hécate at 2020-08-03T07:49:57-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - 9681b392 by Ryan Scott at 2020-08-03T07:49:57-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 30 changed files: - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Parser/PostProcess/Haddock.hs - compiler/GHC/Rename/Module.hs - compiler/GHC/ThToHs.hs - includes/ghc.mk - libraries/base/.hlint.yaml - libraries/base/Control/Concurrent/QSemN.hs - libraries/base/Control/Exception/Base.hs - libraries/base/Data/Coerce.hs - libraries/base/Data/Complex.hs - libraries/base/Data/Data.hs - libraries/base/Data/Dynamic.hs - libraries/base/Data/Either.hs - libraries/base/Data/Functor/Compose.hs - libraries/base/Data/Functor/Contravariant.hs - libraries/base/Data/Functor/Identity.hs - libraries/base/Data/IORef.hs - libraries/base/Data/List/NonEmpty.hs - libraries/base/Data/Semigroup.hs - libraries/base/Data/Type/Bool.hs - libraries/base/Data/Type/Coercion.hs - libraries/base/Data/Type/Equality.hs - libraries/base/Data/Typeable.hs - libraries/base/Data/Unique.hs - libraries/base/Data/Void.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/94bfcb1c7e77d0624990c7330ff019d84c2d87c5...9681b3928e8a938b606bfbcdcc4d57f7c653ff17 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/94bfcb1c7e77d0624990c7330ff019d84c2d87c5...9681b3928e8a938b606bfbcdcc4d57f7c653ff17 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 3 13:05:15 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 03 Aug 2020 09:05:15 -0400 Subject: [Git][ghc/ghc][wip/T17962b] hi Message-ID: <5f280b8b5773d_80bf43446462926c7@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: 8f897318 by Ben Gamari at 2020-08-03T09:05:05-04:00 hi - - - - - 1 changed file: - aclocal.m4 Changes: ===================================== aclocal.m4 ===================================== @@ -2531,102 +2531,102 @@ AC_DEFUN([FIND_LD],[ ]) -# FIND_MERGE_OBJECTS -# ------------------ -# Find which linker to use to merge object files. +# CHECK_FOR_GOLD_T22266 +# ---------------------- # -AC_DEFUN([FIND_MERGE_OBJECTS],[ - AC_REQUIRE([FIND_LD]) +# Test for binutils #22266. This bug manifested as GHC bug #14328 (see also: +# #14675, #14291). +# Uses test from +# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=033bfb739b525703bfe23f151d09e9beee3a2afe +# +# $1 = linker to test +# Sets $result to 0 if not affected, 1 otherwise +AC_DEFUN([CHECK_FOR_GOLD_T22266],[ + AC_MSG_CHECKING([for ld.gold object merging bug (binutils 22266)]) + if ! $1 --version | grep -v -q "GNU gold"; then + # Not gold + result=0 + elif test "$cross_compiling" = "yes"; then + AC_MSG_RESULT([cross-compiling, assuming LD can merge objects correctly.]) + result=0 + else + FPTOOLS_WRITE_FILE([conftest.a.c], [ + __attribute__((section(".data.a"))) + static int int_from_a_1 = 0x11223344; - # check_for_T22266 - # ------------------ - # - # Test for binutils #22266. This bug manifested as GHC bug #14328 (see also: #14675, #14291). - # Uses test from - # https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=033bfb739b525703bfe23f151d09e9beee3a2afe - # - # $1 = linker to test - # Returns 0 if not affected, 1 otherwise - check_for_T22266() { - AC_MSG_CHECKING([for ld.gold object merging bug (binutils 22266)]) - if ! $1 --version | grep -v -q "GNU gold"; then - # Not gold - return 0 - elif test "$cross_compiling" = "yes"; then - AC_MSG_RESULT([cross-compiling, assuming LD can merge objects correctly.]) - return 0 - else - FPTOOLS_WRITE_FILE([conftest.a.c], [ - __attribute__((section(".data.a"))) - static int int_from_a_1 = 0x11223344; + __attribute__((section(".data.rel.ro.a"))) + int *p_int_from_a_2 = &int_from_a_1; - __attribute__((section(".data.rel.ro.a"))) - int *p_int_from_a_2 = &int_from_a_1; + const char *hello (void); - const char *hello (void); + const char * + hello (void) + { + return "XXXHello, world!" + 3; + } + ]) - const char * - hello (void) - { - return "XXXHello, world!" + 3; - } - ]) + FPTOOLS_WRITE_FILE([conftest.main.c], [ + #include + #include - FPTOOLS_WRITE_FILE([conftest.main.c], [ - #include - #include + extern int *p_int_from_a_2; + extern const char *hello (void); - extern int *p_int_from_a_2; - extern const char *hello (void); + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) - int main (void) { - if (*p_int_from_a_2 != 0x11223344) - abort (); - if (strcmp(hello(), "Hello, world!") != 0) - abort (); - return 0; + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) } - ]) - - FPTOOLS_WRITE_FILE([conftest.t], [ - SECTIONS + .rodata : { - .text : { - *(.text*) - } - .rodata : - { - *(.rodata .rodata.* .gnu.linkonce.r.*) - } - .data.rel.ro : { - *(.data.rel.ro*) - } - .data : { - *(.data*) - } - .bss : { - *(.bss*) - } + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) } - ]) + .bss : { + *(.bss*) + } + } + ]) - $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) - $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) - $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) - $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) - if ./conftest; then - AC_MSG_RESULT([not affected]) - res=0 - else - AC_MSG_RESULT([affected]) - res=1 - fi - rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest - return $res + if ./conftest; then + AC_MSG_RESULT([not affected]) + result=0 + else + AC_MSG_RESULT([affected]) + result=1 fi - } + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + fi +]) + +# FIND_MERGE_OBJECTS +# ------------------ +# Find which linker to use to merge object files. +# +AC_DEFUN([FIND_MERGE_OBJECTS],[ + AC_REQUIRE([FIND_LD]) if test -z "$SettingsMergeObjectsCommand"; then SettingsMergeObjectsCommand="$LD" @@ -2635,16 +2635,17 @@ AC_DEFUN([FIND_MERGE_OBJECTS],[ SettingsMergeObjectsFlags="-r" fi - if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + CHECK_FOR_GOLD_T22266($SettingsMergeObjectsCommand) + if test "$result" = "1"; then AC_MSG_NOTICE([$SettingsMergeObjectsCommand is broken due to binutils 22266, looking for another linker...]) SettingsMergeObjectsCommand="" AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) - if ! check_for_T22266 "$SettingsMergeObjectsCommand"; then + CHECK_FOR_GOLD_T22266($SettingsMergeObjectsCommand) + if test "$result" = "1"; then AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the SettingsMergeObjectsCommand variable to a functional linker.]) fi fi - if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" fi View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8f89731825347ad4efe366ccf652fce3f7090605 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8f89731825347ad4efe366ccf652fce3f7090605 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 3 13:16:00 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 03 Aug 2020 09:16:00 -0400 Subject: [Git][ghc/ghc][wip/T17962b] Refactor handling of object merging Message-ID: <5f280e106c1b4_80b3f849a265454629388e@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17962b at Glasgow Haskell Compiler / GHC Commits: cf656aba by Ben Gamari at 2020-08-03T09:15:53-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 21 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + result=0 + else + AC_MSG_RESULT([affected]) + result=1 + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + fi +]) + +# FIND_MERGE_OBJECTS +# ------------------ +# Find which linker to use to merge object files. +# +AC_DEFUN([FIND_MERGE_OBJECTS],[ + AC_REQUIRE([FIND_LD]) + + if test -z "$SettingsMergeObjectsCommand"; then + SettingsMergeObjectsCommand="$LD" + fi + if test -z "$SettingsMergeObjectsFlags"; then + SettingsMergeObjectsFlags="-r" + fi + + CHECK_FOR_GOLD_T22266($SettingsMergeObjectsCommand) + if test "$result" = "1"; then + AC_MSG_NOTICE([$SettingsMergeObjectsCommand is broken due to binutils 22266, looking for another linker...]) + SettingsMergeObjectsCommand="" + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + CHECK_FOR_GOLD_T22266($SettingsMergeObjectsCommand) + if test "$result" = "1"; then + AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the SettingsMergeObjectsCommand variable to a functional linker.]) + fi + fi + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -2133,6 +2133,23 @@ We must enable bigobj output in a few places: Unfortunately the big object format is not supported on 32-bit targets so none of this can be used in that case. + + +Note [Merging object files for GHCi] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +GHCi can usually loads standard linkable object files using GHC's linker +implementation. However, most users build their projects with -split-sections, +meaning that such object files can have an extremely high number of sections. +As the linker must map each of these sections individually, loading such object +files is very inefficient. + +To avoid this inefficiency, we use the linker's `-r` flag and a linker script +to produce a merged relocatable object file. This file will contain a singe +text section section and can consequently be mapped far more efficiently. As +gcc tends to do unpredictable things to our linker command line, we opt to +invoke ld directly in this case, in contrast to our usual strategy of linking +via gcc. + -} joinObjectFiles :: DynFlags -> [FilePath] -> FilePath -> IO () @@ -2140,34 +2157,13 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = GHC.SysTools.runLink dflags ([ - GHC.SysTools.Option "-nostdlib", - GHC.SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in GHC.Driver.Session - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [GHC.SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [GHC.SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [GHC.SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [GHC.SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args = GHC.SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" - | OSMinGW32 == osInfo - , not $ target32Bit (targetPlatform dflags) - ] + concat + [ [GHC.SysTools.Option "--oformat", GHC.SysTools.Option "pe-bigobj-x86-64"] + | OSMinGW32 == osInfo + , not $ target32Bit (targetPlatform dflags) + ] ++ map GHC.SysTools.Option ld_build_id ++ [ GHC.SysTools.Option "-o", GHC.SysTools.FileOption "" output_fn ] @@ -2176,25 +2172,24 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] - ccInfo <- getCompilerInfo dflags if ldIsGnuLd then do script <- newTempName dflags TFL_CurrentModule "ldscript" cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [GHC.SysTools.FileOption "" script] ccInfo + ld_r [GHC.SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files - ld_r [GHC.SysTools.Option "-Wl,-filelist", - GHC.SysTools.FileOption "-Wl," filelist] ccInfo + ld_r [GHC.SysTools.Option "-filelist", + GHC.SysTools.FileOption "" filelist] else do - ld_r (map (GHC.SysTools.FileOption "") o_files) ccInfo + ld_r (map (GHC.SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -102,6 +102,7 @@ module GHC.Driver.Session ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -120,6 +121,7 @@ module GHC.Driver.Session ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -142,10 +144,10 @@ module GHC.Driver.Session ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -940,6 +942,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -986,6 +990,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/GHC/Settings.hs ===================================== @@ -28,6 +28,7 @@ module GHC.Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -46,6 +47,7 @@ module GHC.Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -99,6 +101,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -124,6 +127,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] @@ -200,6 +204,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -236,6 +242,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -137,6 +137,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -183,6 +185,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -201,6 +204,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -1,4 +1,5 @@ {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- -- Tasks running external programs for SysTools @@ -299,6 +300,20 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +-- See Note [Merging object files for GHCi] in GHC.Driver.Pipeline. +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + -- N.B. Darwin's ld64 doesn't support response files. Consequently we only + -- use them on Windows where they are truly necessary. +#if defined(mingw32_HOST_OS) + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env +#else + runSomething dflags "Merge objects" p args2 +#endif runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== configure.ac ===================================== @@ -602,13 +602,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -96,6 +96,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -115,6 +115,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -138,6 +144,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -99,6 +99,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -127,9 +127,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -311,6 +312,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -91,6 +91,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -109,6 +110,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -176,6 +179,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -191,6 +195,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -294,6 +294,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -92,6 +92,7 @@ buildDynamicLibUnix root suffix dynlibpath = do -- | Build a "GHCi library" ('LibGhci') under the given build root, with the -- complete path of the file to build is given as the second argument. +-- See Note [Merging object files for GHCi] in GHC.Driver.Pipeline. buildGhciLibO :: FilePath -> FilePath -> Action () buildGhciLibO root ghcilibPath = do l@(BuildPath _ stage _ (LibGhci _ _ _)) @@ -101,7 +102,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -37,6 +37,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -244,6 +245,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -223,6 +223,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -500,6 +500,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -733,7 +735,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cf656aba070c8d2da91cadf3cbfbb9d91005e717 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cf656aba070c8d2da91cadf3cbfbb9d91005e717 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 3 15:23:11 2020 From: gitlab at gitlab.haskell.org (Richard Eisenberg) Date: Mon, 03 Aug 2020 11:23:11 -0400 Subject: [Git][ghc/ghc][wip/derived-refactor] Checkpoint to share with SPJ Message-ID: <5f282bdf4ffb_80b8ca3ed063312e3@gitlab.haskell.org.mail> Richard Eisenberg pushed to branch wip/derived-refactor at Glasgow Haskell Compiler / GHC Commits: 49b2b653 by Richard Eisenberg at 2020-08-03T11:22:57-04:00 Checkpoint to share with SPJ - - - - - 7 changed files: - compiler/GHC/Tc/Instance/FunDeps.hs - compiler/GHC/Tc/Solver.hs - compiler/GHC/Tc/TyCl/PatSyn.hs - compiler/GHC/Tc/Types/Evidence.hs - compiler/GHC/Tc/Utils/TcType.hs - compiler/GHC/Tc/Validity.hs - testsuite/tests/typecheck/should_compile/tc231.hs Changes: ===================================== compiler/GHC/Tc/Instance/FunDeps.hs ===================================== @@ -19,7 +19,7 @@ module GHC.Tc.Instance.FunDeps , checkInstCoverage , checkFunDeps , pprFundeps - , oclose + , instFD, oclose ) where @@ -555,7 +555,7 @@ oclose preds fixed_tvs -- implicit params don't really determine a type variable, and -- skipping this causes implicit params to monomorphise too many -- variables; see Note [Inheriting implicit parameters] in - -- GHC.Tc.Utils.TcType. Skipping causes typecheck/should_compile/tc219 + -- GHC.Tc.Solver. Skipping causes typecheck/should_compile/tc219 -- to fail. extend fixed_tvs = foldl' add fixed_tvs tv_fds ===================================== compiler/GHC/Tc/Solver.hs ===================================== @@ -29,7 +29,7 @@ module GHC.Tc.Solver( import GHC.Prelude import GHC.Data.Bag -import GHC.Core.Class ( Class, classKey, classTyCon, classHasFds ) +import GHC.Core.Class ( Class, classKey, classTyCon, classHasFds, classTvsFds ) import GHC.Driver.Session import GHC.Types.Id ( idType ) import GHC.Tc.Utils.Instantiate @@ -47,8 +47,9 @@ import GHC.Tc.Utils.TcMType as TcM import GHC.Tc.Utils.Monad as TcM import GHC.Tc.Solver.Monad as TcS import GHC.Tc.Types.Constraint -import GHC.Tc.Instance.FunDeps ( oclose ) +import GHC.Tc.Instance.FunDeps ( oclose, instFD ) import GHC.Core.Predicate +import GHC.Core.TyCon import GHC.Tc.Types.Origin import GHC.Tc.Utils.TcType import GHC.Core.Type @@ -67,7 +68,7 @@ import Control.Monad import Data.Foldable ( toList ) import Data.List ( partition ) import Data.List.NonEmpty ( NonEmpty(..) ) -import GHC.Data.Maybe ( isJust ) +import GHC.Data.Maybe ( isJust, mapMaybe ) {- ********************************************************************************* @@ -987,6 +988,58 @@ If the monomorphism restriction does not apply, then we quantify as follows: qtvs. We have to zonk the constraints first, so they "see" the freshly created skolems. +Note [Lift equality constraints when quantifying] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +We can't quantify over a constraint (t1 ~# t2) because that isn't a +predicate type; see Note [Types for coercions, predicates, and evidence] +in GHC.Core.TyCo.Rep. + +So we have to 'lift' it to (t1 ~ t2). Similarly (~R#) must be lifted +to Coercible. + +This tiresome lifting is the reason that pick_me (in +pickQuantifiablePreds) returns a Maybe rather than a Bool. + +Note [Inheriting implicit parameters] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider this: + + f x = (x::Int) + ?y + +where f is *not* a top-level binding. +From the RHS of f we'll get the constraint (?y::Int). +There are two types we might infer for f: + + f :: Int -> Int + +(so we get ?y from the context of f's definition), or + + f :: (?y::Int) => Int -> Int + +At first you might think the first was better, because then +?y behaves like a free variable of the definition, rather than +having to be passed at each call site. But of course, the WHOLE +IDEA is that ?y should be passed at each call site (that's what +dynamic binding means) so we'd better infer the second. + +BOTTOM LINE: when *inferring types* you must quantify over implicit +parameters, *even if* they don't mention the bound type variables. +Reason: because implicit parameters, uniquely, have local instance +declarations. See pickQuantifiablePreds. + +Note [Quantifying over equality constraints] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Should we quantify over an equality constraint (s ~ t)? In general, we don't. +Doing so may simply postpone a type error from the function definition site to +its call site. (At worst, imagine (Int ~ Bool)). + +However, consider this + forall a. (F [a] ~ Int) => blah +Should we quantify over the (F [a] ~ Int). Perhaps yes, because at the call +site we will know 'a', and perhaps we have instance F [Bool] = Int. +So we *do* quantify over a type-family equality where the arguments mention +the quantified variables. + -} decideQuantification @@ -1162,6 +1215,21 @@ decideMonoTyVars infer_mode name_taus psigs candidates , text (if isSingleton name_taus then "it" else "them") , text "a type signature"]) +{- "RAE" +------------------- +growMonoTyVars :: [PredType] -- candidates + -> TyVarSet -- original mono vars + -> TyVarSet -- all mono vars +-- given the candidates and a seed set of mono tyvars, grows the +-- set of mono tyvars. The expanded set includes all tyvars that are +-- determined by the seeds, or transitively by other tyvars determined +-- by the seeds. However, there is a catch: we must use only predicates +-- that we will not, in the end, want to quantify over. Because we +-- don't quantify over equalities, this set initially includes just +-- equalities, but we also include any non-equalities whose free variables +-- are all mono (as these will not be quantified over). +-} + ------------------- defaultTyVarsAndSimplify :: TcLevel -> TyCoVarSet @@ -1260,6 +1328,81 @@ decideQuantifiedTyVars name_taus psigs candidates ; quantifyTyVars dvs_plus } +------------------ +-- | When inferring types, should we quantify over a given predicate? +-- Generally true of classes; generally false of equality constraints. +-- Equality constraints that mention quantified type variables and +-- implicit variables complicate the story. See Notes +-- [Inheriting implicit parameters] and [Quantifying over equality constraints] +pickQuantifiablePreds + :: TyVarSet -- Quantifying over these + -> TcThetaType -- Proposed constraints to quantify + -> TcThetaType -- A subset that we can actually quantify +-- This function decides whether a particular constraint should be +-- quantified over, given the type variables that are being quantified +pickQuantifiablePreds qtvs theta + = let flex_ctxt = True in -- Quantify over non-tyvar constraints, even without + -- -XFlexibleContexts: see #10608, #10351 + -- flex_ctxt <- xoptM Opt_FlexibleContexts + mapMaybe (pick_me flex_ctxt) theta + where + pick_me flex_ctxt pred + = case classifyPredType pred of + + ClassPred cls tys + | Just {} <- isCallStackPred cls tys + -- NEVER infer a CallStack constraint. Otherwise we let + -- the constraints bubble up to be solved from the outer + -- context, or be defaulted when we reach the top-level. + -- See Note [Overview of implicit CallStacks] in GHC.Tc.Types.Evidence + -> Nothing + + | isIPClass cls + -> Just pred -- See note [Inheriting implicit parameters] + + | pick_cls_pred flex_ctxt cls tys + -> Just pred + + EqPred eq_rel ty1 ty2 + | quantify_equality eq_rel ty1 ty2 + , Just (cls, tys) <- boxEqPred eq_rel ty1 ty2 + -- boxEqPred: See Note [Lift equality constraints when quantifying] + , pick_cls_pred flex_ctxt cls tys + -> Just (mkClassPred cls tys) + + IrredPred ty + | tyCoVarsOfType ty `intersectsVarSet` qtvs + -> Just pred + + _ -> Nothing + + + pick_cls_pred flex_ctxt cls tys + = tyCoVarsOfTypes tys `intersectsVarSet` qtvs + && (checkValidClsArgs flex_ctxt cls tys) + -- Only quantify over predicates that checkValidType + -- will pass! See #10351. + && (no_fixed_dependencies cls tys) + + no_fixed_dependencies cls tys + = and [ qtvs `intersectsVarSet` tyCoVarsOfTypes fd_lhs_tys + | fd <- cls_fds + , let (fd_lhs_tys, _) = instFD fd cls_tvs tys ] + where + (cls_tvs, cls_fds) = classTvsFds cls + + + -- See Note [Quantifying over equality constraints] + quantify_equality NomEq ty1 ty2 = quant_fun ty1 || quant_fun ty2 + quantify_equality ReprEq _ _ = True + + quant_fun ty + = case tcSplitTyConApp_maybe ty of + Just (tc, tys) | isTypeFamilyTyCon tc + -> tyCoVarsOfTypes tys `intersectsVarSet` qtvs + _ -> False + + ------------------ growThetaTyVars :: ThetaType -> TyCoVarSet -> TyCoVarSet -- See Note [Growing the tau-tvs using constraints] @@ -1269,7 +1412,7 @@ growThetaTyVars theta tcvs where seed_tcvs = tcvs `unionVarSet` tyCoVarsOfTypes ips (ips, non_ips) = partition isIPPred theta - -- See Note [Inheriting implicit parameters] in GHC.Tc.Utils.TcType + -- See Note [Inheriting implicit parameters] mk_next :: VarSet -> VarSet -- Maps current set to newly-grown ones mk_next so_far = foldr (grow_one so_far) emptyVarSet non_ips ===================================== compiler/GHC/Tc/TyCl/PatSyn.hs ===================================== @@ -309,7 +309,7 @@ and is not implicitly instantiated. So in mkProvEvidence we lift (a ~# b) to (a ~ b). Tiresome, and marginally less efficient, if the builder/martcher are not inlined. -See also Note [Lift equality constraints when quantifying] in GHC.Tc.Utils.TcType +See also Note [Lift equality constraints when quantifying] in GHC.Tc.Solver Note [Coercions that escape] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/Tc/Types/Evidence.hs ===================================== @@ -754,7 +754,7 @@ Important Details: - GHC should NEVER report an insoluble CallStack constraint. - GHC should NEVER infer a CallStack constraint unless one was requested - with a partial type signature (See TcType.pickQuantifiablePreds). + with a partial type signature (See GHC.Tc.Solver..pickQuantifiablePreds). - A CallStack (defined in GHC.Stack.Types) is a [(String, SrcLoc)], where the String is the name of the binder that is used at the ===================================== compiler/GHC/Tc/Utils/TcType.hs ===================================== @@ -93,7 +93,7 @@ module GHC.Tc.Utils.TcType ( --------------------------------- -- Predicate types mkMinimalBySCs, transSuperClasses, - pickQuantifiablePreds, pickCapturedPreds, + pickCapturedPreds, immSuperClasses, boxEqPred, isImprovementPred, @@ -1653,71 +1653,7 @@ evVarPred var = varType var -- partial signatures, (isEvVarType kappa) will return False. But -- nothing is wrong. So I just removed the ASSERT. ------------------- --- | When inferring types, should we quantify over a given predicate? --- Generally true of classes; generally false of equality constraints. --- Equality constraints that mention quantified type variables and --- implicit variables complicate the story. See Notes --- [Inheriting implicit parameters] and [Quantifying over equality constraints] -pickQuantifiablePreds - :: TyVarSet -- Quantifying over these - -> TcThetaType -- Proposed constraints to quantify - -> TcThetaType -- A subset that we can actually quantify --- This function decides whether a particular constraint should be --- quantified over, given the type variables that are being quantified -pickQuantifiablePreds qtvs theta - = let flex_ctxt = True in -- Quantify over non-tyvar constraints, even without - -- -XFlexibleContexts: see #10608, #10351 - -- flex_ctxt <- xoptM Opt_FlexibleContexts - mapMaybe (pick_me flex_ctxt) theta - where - pick_me flex_ctxt pred - = case classifyPredType pred of - - ClassPred cls tys - | Just {} <- isCallStackPred cls tys - -- NEVER infer a CallStack constraint. Otherwise we let - -- the constraints bubble up to be solved from the outer - -- context, or be defaulted when we reach the top-level. - -- See Note [Overview of implicit CallStacks] - -> Nothing - - | isIPClass cls - -> Just pred -- See note [Inheriting implicit parameters] - - | pick_cls_pred flex_ctxt cls tys - -> Just pred - - EqPred eq_rel ty1 ty2 - | quantify_equality eq_rel ty1 ty2 - , Just (cls, tys) <- boxEqPred eq_rel ty1 ty2 - -- boxEqPred: See Note [Lift equality constraints when quantifying] - , pick_cls_pred flex_ctxt cls tys - -> Just (mkClassPred cls tys) - - IrredPred ty - | tyCoVarsOfType ty `intersectsVarSet` qtvs - -> Just pred - - _ -> Nothing - - - pick_cls_pred flex_ctxt cls tys - = tyCoVarsOfTypes tys `intersectsVarSet` qtvs - && (checkValidClsArgs flex_ctxt cls tys) - -- Only quantify over predicates that checkValidType - -- will pass! See #10351. - - -- See Note [Quantifying over equality constraints] - quantify_equality NomEq ty1 ty2 = quant_fun ty1 || quant_fun ty2 - quantify_equality ReprEq _ _ = True - - quant_fun ty - = case tcSplitTyConApp_maybe ty of - Just (tc, tys) | isTypeFamilyTyCon tc - -> tyCoVarsOfTypes tys `intersectsVarSet` qtvs - _ -> False - +--------------------------- boxEqPred :: EqRel -> Type -> Type -> Maybe (Class, [Type]) -- Given (t1 ~# t2) or (t1 ~R# t2) return the boxed version -- (t1 ~ t2) or (t1 `Coercible` t2) @@ -1909,71 +1845,6 @@ Notice that See also GHC.Tc.TyCl.Utils.checkClassCycles. -Note [Lift equality constraints when quantifying] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -We can't quantify over a constraint (t1 ~# t2) because that isn't a -predicate type; see Note [Types for coercions, predicates, and evidence] -in GHC.Core.TyCo.Rep. - -So we have to 'lift' it to (t1 ~ t2). Similarly (~R#) must be lifted -to Coercible. - -This tiresome lifting is the reason that pick_me (in -pickQuantifiablePreds) returns a Maybe rather than a Bool. - -Note [Quantifying over equality constraints] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Should we quantify over an equality constraint (s ~ t)? In general, we don't. -Doing so may simply postpone a type error from the function definition site to -its call site. (At worst, imagine (Int ~ Bool)). - -However, consider this - forall a. (F [a] ~ Int) => blah -Should we quantify over the (F [a] ~ Int)? Perhaps yes, because at the call -site we will know 'a', and perhaps we have instance F [Bool] = Int. -So we *do* quantify over a type-family equality where the arguments mention -the quantified variables. - -Note [Inheriting implicit parameters] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider this: - - f x = (x::Int) + ?y - -where f is *not* a top-level binding. -From the RHS of f we'll get the constraint (?y::Int). -There are two types we might infer for f: - - f :: Int -> Int - -(so we get ?y from the context of f's definition), or - - f :: (?y::Int) => Int -> Int - -At first you might think the first was better, because then -?y behaves like a free variable of the definition, rather than -having to be passed at each call site. But of course, the WHOLE -IDEA is that ?y should be passed at each call site (that's what -dynamic binding means) so we'd better infer the second. - -BOTTOM LINE: when *inferring types* you must quantify over implicit -parameters, *even if* they don't mention the bound type variables. -Reason: because implicit parameters, uniquely, have local instance -declarations. See pickQuantifiablePreds. - -Note [Quantifying over equality constraints] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Should we quantify over an equality constraint (s ~ t)? In general, we don't. -Doing so may simply postpone a type error from the function definition site to -its call site. (At worst, imagine (Int ~ Bool)). - -However, consider this - forall a. (F [a] ~ Int) => blah -Should we quantify over the (F [a] ~ Int). Perhaps yes, because at the call -site we will know 'a', and perhaps we have instance F [Bool] = Int. -So we *do* quantify over a type-family equality where the arguments mention -the quantified variables. - ************************************************************************ * * Classifying types ===================================== compiler/GHC/Tc/Validity.hs ===================================== @@ -1126,7 +1126,7 @@ check_pred_help under_syn env dflags ctxt pred -- is wrong. For user written signatures, it'll be rejected by kind-checking -- well before we get to validity checking. For inferred types we are careful -- to box such constraints in GHC.Tc.Utils.TcType.pickQuantifiablePreds, as described - -- in Note [Lift equality constraints when quantifying] in GHC.Tc.Utils.TcType + -- in Note [Lift equality constraints when quantifying] in GHC.Tc.Solver ForAllPred _ theta head -> check_quant_pred env dflags ctxt pred theta head IrredPred {} -> check_irred_pred under_syn env dflags ctxt pred ===================================== testsuite/tests/typecheck/should_compile/tc231.hs ===================================== @@ -9,6 +9,8 @@ -- Note the quantification over 'b', which was previously -- omitted; see Note [Important subtlety in oclose] in GHC.Tc.Instance.FunDeps +-- (Note removed in ecddaca17dccbe1d0b56220d838fce8bc4b97884, but you can +-- find it in the history) module ShouldCompile where @@ -26,4 +28,3 @@ class Zork s a b | a -> b where huh :: Q s a chain -> ST s () foo b = huh (s b) - View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/49b2b653040754fe20dbd52248433264ee3daeb1 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/49b2b653040754fe20dbd52248433264ee3daeb1 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 3 17:16:39 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Mon, 03 Aug 2020 13:16:39 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/t18522 Message-ID: <5f284677e91a8_80b3f8468e02b54634131c@gitlab.haskell.org.mail> Vladislav Zavialov pushed new branch wip/t18522 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/t18522 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 3 20:36:49 2020 From: gitlab at gitlab.haskell.org (Ryan Scott) Date: Mon, 03 Aug 2020 16:36:49 -0400 Subject: [Git][ghc/ghc][wip/T18521] Make CodeQ and TExpQ levity polymorphic Message-ID: <5f2875617c836_80b3f848c1e06f463552e7@gitlab.haskell.org.mail> Ryan Scott pushed to branch wip/T18521 at Glasgow Haskell Compiler / GHC Commits: 5a419632 by Ryan Scott at 2020-08-03T16:36:33-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 5 changed files: - libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs - libraries/template-haskell/Language/Haskell/TH/Syntax.hs - libraries/template-haskell/changelog.md - + testsuite/tests/quotes/T18521.hs - testsuite/tests/quotes/all.T Changes: ===================================== libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs ===================================== @@ -1,4 +1,5 @@ -{-# LANGUAGE Safe #-} +{-# LANGUAGE PolyKinds #-} +{-# LANGUAGE Trustworthy #-} -- | -- Language.Haskell.TH.Lib.Internal exposes some additional functionality that @@ -19,19 +20,31 @@ module Language.Haskell.TH.Lib.Internal where import Language.Haskell.TH.Syntax hiding (Role, InjectivityAnn) import qualified Language.Haskell.TH.Syntax as TH import Control.Applicative(liftA, liftA2) +import qualified Data.Kind as Kind (Type) import Data.Word( Word8 ) +import GHC.Exts (TYPE) import Prelude ---------------------------------------------------------- -- * Type synonyms ---------------------------------------------------------- +-- Since GHC 8.8 is currently the minimum boot compiler version that we must +-- support, we must use inline kind signatures to make TExpQ and CodeQ +-- levity polymorphic. When we drop support for GHC 8.8, we can instead use +-- standalone kind signatures, which are provided as comments. + +-- | Levity-polymorphic since /template-haskell-2.17.0.0/. +-- type TExpQ :: TYPE r -> Kind.Type +type TExpQ (a :: TYPE r) = Q (TExp a) + +-- type CodeQ :: TYPE r -> Kind.Type +type CodeQ = Code Q :: (TYPE r -> Kind.Type) + type InfoQ = Q Info type PatQ = Q Pat type FieldPatQ = Q FieldPat type ExpQ = Q Exp -type TExpQ a = Q (TExp a) -type CodeQ = Code Q type DecQ = Q Dec type DecsQ = Q [Dec] type Decs = [Dec] -- Defined as it is more convenient to wire-in ===================================== libraries/template-haskell/Language/Haskell/TH/Syntax.hs ===================================== @@ -341,6 +341,8 @@ newtype TExp (a :: TYPE (r :: RuntimeRep)) = TExp -- • In the Template Haskell quotation [|| "foo" ||] -- In the expression: [|| "foo" ||] -- In the Template Haskell splice $$([|| "foo" ||]) +-- +-- Levity-polymorphic since /template-haskell-2.16.0.0/. -- | Discard the type annotation and produce a plain Template Haskell -- expression ===================================== libraries/template-haskell/changelog.md ===================================== @@ -32,6 +32,8 @@ * Add support for QualifiedDo. The data constructors `DoE` and `MDoE` got a new `Maybe ModName` argument to describe the qualifier of do blocks. + * The argument to `TExpQ` can now be levity polymorphic. + ## 2.16.0.0 *TBA* * Add support for tuple sections. (#15843) The type signatures of `TupE` and ===================================== testsuite/tests/quotes/T18521.hs ===================================== @@ -0,0 +1,15 @@ +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE TemplateHaskellQuotes #-} +module T18521 where + +import GHC.Exts (Int#) +import Language.Haskell.TH + +a :: Code Q Int# +a = [|| 42# ||] + +b :: CodeQ Int# +b = a + +c :: TExpQ Int# +c = examineCode a ===================================== testsuite/tests/quotes/all.T ===================================== @@ -19,6 +19,7 @@ test('T16384', req_th, compile, ['']) test('T17857', normal, compile, ['']) test('T18103', normal, compile, ['']) test('T18263', normal, compile_fail, ['']) +test('T18521', normal, compile, ['']) test('TH_tf2', normal, compile, ['-v0']) test('TH_ppr1', normal, compile_and_run, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5a41963271906e776f99a866aa134fb99812e999 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5a41963271906e776f99a866aa134fb99812e999 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 12:38:55 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Tue, 04 Aug 2020 08:38:55 -0400 Subject: [Git][ghc/ghc][wip/T8095-spj] Free-var fixes Message-ID: <5f2956df29afe_80b10e6f9b4640855f@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T8095-spj at Glasgow Haskell Compiler / GHC Commits: ce39b22b by Simon Peyton Jones at 2020-08-04T13:38:05+01:00 Free-var fixes This should stop the perf regressions - - - - - 3 changed files: - compiler/GHC/Core/TyCo/FVs.hs - compiler/GHC/Core/TyCo/Rep.hs - compiler/GHC/Tc/Instance/Family.hs Changes: ===================================== compiler/GHC/Core/TyCo/FVs.hs ===================================== @@ -25,7 +25,7 @@ module GHC.Core.TyCo.FVs -- Injective free vars injectiveVarsOfType, injectiveVarsOfTypes, - invisibleVarsOfType, invisibleVarsOfTypes, + invisibleVarsOfTypes, -- No Free vars noFreeVarsOfType, noFreeVarsOfTypes, noFreeVarsOfCo, @@ -221,7 +221,7 @@ kind are free. * * ********************************************************************* -} -{- Note [Acumulating parameter free variables] +{- Note [Accumulating parameter free variables] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We can use foldType to build an accumulating-parameter version of a free-var finder, thus: @@ -271,7 +271,16 @@ emptyInScope = emptyVarSet runTyCoVars :: TyCoFvFun a TyCoVarSet -> a -> TyCoVarSet {-# INLINE runTyCoVars #-} -runTyCoVars f x = appEndo (f emptyInScope x) emptyVarSet +runTyCoVars f = \x -> appEndo (f emptyInScope x) emptyVarSet + -- It's very important that the \x is to the right of the '=', so + -- runTyCoVars has arity 1. It is often applied to just one arg e.g. + -- tyCoVarsOfType = runTyCoVars deep_ty + -- We want runTyCoVars to inline, so that deep_ty is applied to two args, + -- which in turn makes deep_ty eta-expand. Without that eta-expansion, + -- deep_ty is dreadfully inefficient. + -- + -- If we put the \x to the left of the '=', runTyCoVars would only + -- inline when applied to /two/ arguments. {- ********************************************************************* @@ -281,22 +290,20 @@ runTyCoVars f x = appEndo (f emptyInScope x) emptyVarSet * * ********************************************************************* -} -tyCoVarsOfType :: Type -> TyCoVarSet -tyCoVarsOfType ty = runTyCoVars deep_ty ty --- Alternative: --- tyCoVarsOfType ty = closeOverKinds (shallowTyCoVarsOfType ty) +-- See Note [Free variables of Coercions] +tyCoVarsOfType :: Type -> TyCoVarSet tyCoVarsOfTypes :: [Type] -> TyCoVarSet -tyCoVarsOfTypes tys = runTyCoVars deep_tys tys --- Alternative: --- tyCoVarsOfTypes tys = closeOverKinds (shallowTyCoVarsOfTypes tys) +tyCoVarsOfCo :: Coercion -> TyCoVarSet +tyCoVarsOfCos :: [Coercion] -> TyCoVarSet -tyCoVarsOfCo :: Coercion -> TyCoVarSet --- See Note [Free variables of Coercions] -tyCoVarsOfCo co = runTyCoVars deep_co co +tyCoVarsOfType = runTyCoVars deep_ty +tyCoVarsOfTypes = runTyCoVars deep_tys +tyCoVarsOfCo = runTyCoVars deep_co +tyCoVarsOfCos = runTyCoVars deep_cos -tyCoVarsOfCos :: [Coercion] -> TyCoVarSet -tyCoVarsOfCos cos = runTyCoVars deep_cos cos +-- Alternative for tyCoVarsOfType +-- tyCoVarsOfType ty = closeOverKinds (shallowTyCoVarsOfType ty) deep_ty :: TyCoFvFun Type TyCoVarSet deep_tys :: TyCoFvFun [Type] TyCoVarSet @@ -866,26 +873,32 @@ injectiveVarsOfTypes look_under_tfs = mapUnionFV (injectiveVarsOfType look_under -- * In a coercion -- * In a Specified or Inferred argument to a function -- See Note [VarBndrs, TyCoVarBinders, TyConBinders, and visibility] in "GHC.Core.TyCo.Rep" -invisibleVarsOfType :: Type -> FV -invisibleVarsOfType = go - where - go ty | Just ty' <- coreView ty - = go ty' - go (TyVarTy v) = go (tyVarKind v) - go (AppTy f a) = go f `unionFV` go a - go (FunTy _ w ty1 ty2) = go w `unionFV` go ty1 `unionFV` go ty2 - go (TyConApp tc tys) = tyCoFVsOfTypes invisibles `unionFV` - invisibleVarsOfTypes visibles - where (invisibles, visibles) = partitionInvisibleTypes tc tys - go (ForAllTy tvb ty) = tyCoFVsBndr tvb $ go ty - go LitTy{} = emptyFV - go (CastTy ty co) = tyCoFVsOfCo co `unionFV` go ty - go (CoercionTy co) = tyCoFVsOfCo co - --- | Like 'invisibleVarsOfType', but for many types. -invisibleVarsOfTypes :: [Type] -> FV -invisibleVarsOfTypes = mapUnionFV invisibleVarsOfType - +invisibleVarsOfTypes :: [Type] -> VarSet +invisibleVarsOfTypes = runTyCoVars invis_tys + +invis_tys :: TyCoFvFun [Type] TyCoVarSet +invis_tys _ [] = mempty +invis_tys is (ty:tys) = invis_ty is ty `mappend` invis_tys is tys + +invis_ty :: TyCoFvFun Type TyCoVarSet +invis_ty is ty | Just ty' <- coreView ty + = invis_ty is ty' + +invis_ty is (TyVarTy v) + | v `elemVarSet` is = mempty + | otherwise = deep_ty emptyVarSet (tyVarKind v) +invis_ty is (AppTy f a) = invis_ty is f `mappend` invis_ty is a +invis_ty is (FunTy _ w ty1 ty2) = invis_ty is w `mappend` invis_ty is ty1 `mappend` invis_ty is ty2 +invis_ty is (TyConApp tc tys) = deep_tys is invisibles `mappend` + invis_tys is visibles + where (invisibles, visibles) = partitionInvisibleTypes tc tys +invis_ty is (ForAllTy tvb ty) = invis_ty is (tyVarKind tv) `mappend` + invis_ty (is `extendVarSet` tv) ty + where + tv = binderVar tvb +invis_ty _ LitTy{} = mempty +invis_ty is (CastTy ty co) = deep_co is co `mappend` invis_ty is ty +invis_ty is (CoercionTy co) = deep_co is co {- ********************************************************************* * * ===================================== compiler/GHC/Core/TyCo/Rep.hs ===================================== @@ -1962,12 +1962,14 @@ foldTyCo (TyCoFolder { tcf_view = view where env' = tycobinder env tv Inferred - go_prov env (ZapCoProv cvs) = strictFoldDVarSet (mappend . covar env) - mempty cvs + go_prov env (ZapCoProv cvs) = go_cvs env (dVarSetElems cvs) go_prov env (PhantomProv co) = go_co env co go_prov env (ProofIrrelProv co) = go_co env co go_prov _ (PluginProv _) = mempty + go_cvs _ [] = mempty + go_cvs env (cv:cvs) = covar env cv `mappend` go_cvs env cvs + {- ********************************************************************* * * typeSize, coercionSize ===================================== compiler/GHC/Tc/Instance/Family.hs ===================================== @@ -918,7 +918,7 @@ unusedInjTvsInRHS dflags tycon@(tyConInjectivityInfo -> Injective inj_list) lhs any_bad = not $ isEmptyVarSet bad_vars - invis_vars = fvVarSet $ invisibleVarsOfTypes [mkTyConApp tycon lhs, rhs] + invis_vars = invisibleVarsOfTypes [mkTyConApp tycon lhs, rhs] any_invisible = any_bad && (bad_vars `intersectsVarSet` invis_vars) suggest_undec = any_bad && View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ce39b22bdfeee800aa09394110213ad0487e6168 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ce39b22bdfeee800aa09394110213ad0487e6168 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 17:00:56 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 04 Aug 2020 13:00:56 -0400 Subject: [Git][ghc/ghc][wip/backports] 8 commits: Restore haskeline submodule to v0.8.0.0 Message-ID: <5f299448b5f8f_80b3f849c1caa106431460@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: f34695e9 by Ben Gamari at 2020-07-30T10:48:10-04:00 Restore haskeline submodule to v0.8.0.0 It appears that this was incorrectly reverted in 4186c713e65dc5041d0b7a0e1d77f48edc763c3a. - - - - - 274989ff by Ben Gamari at 2020-07-30T10:48:10-04:00 users-guide: Mention LLVM version requirement - - - - - 484c4d89 by Ben Gamari at 2020-07-30T10:48:10-04:00 Use ld.gold to link on deb10 Otherwise we use ld.lld, which fails with ld.lld: error: -r and --export-dynamic may not be used together - - - - - bb0dae83 by Ben Gamari at 2020-07-30T10:48:10-04:00 Release GHC 8.10.2 - - - - - 81134748 by Ben Gamari at 2020-07-31T16:47:01-04:00 gitlab-ci: Build ARMv7 and AArch64 on Debian 10, not Debian 9 - - - - - fec2abb8 by Leon Schoorl at 2020-08-01T14:43:48-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 (cherry picked from commit a481afef354ca0383477fd20891c2e8eb9ef4449) - - - - - 428320a9 by Ben Gamari at 2020-08-03T17:51:43-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. (cherry picked from commit f9b7497d30d98a054d4ec5a8df2dfaf4a2b0bb30) - - - - - cdeb8887 by Ben Gamari at 2020-08-03T21:19:45-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 26 changed files: - .gitlab-ci.yml - aclocal.m4 - compiler/main/DriverPipeline.hs - compiler/main/DynFlags.hs - compiler/main/Settings.hs - compiler/main/SysTools/Settings.hs - compiler/main/SysTools/Tasks.hs - compiler/main/ToolSettings.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/8.10.2-notes.rst - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - libraries/haskeline - mk/config.mk.in - rules/build-package-way.mk - utils/iserv/ghc.mk Changes: ===================================== .gitlab-ci.yml ===================================== @@ -467,61 +467,61 @@ validate-x86_64-darwin: - toolchain ################################# -# aarch64-linux-deb9 +# aarch64-linux-deb10 ################################# -.build-aarch64-linux-deb9: +.build-aarch64-linux-deb10: extends: .validate-linux stage: full-build - image: "registry.gitlab.haskell.org/ghc/ci-images/aarch64-linux-deb9:$DOCKER_REV" + image: "registry.gitlab.haskell.org/ghc/ci-images/aarch64-linux-deb10:$DOCKER_REV" allow_failure: true variables: - TEST_ENV: "aarch64-linux-deb9" - BIN_DIST_PREP_TAR_COMP: "ghc-aarch64-linux-deb9.tar.xz" + TEST_ENV: "aarch64-linux-deb10" + BIN_DIST_PREP_TAR_COMP: "ghc-aarch64-linux-deb10.tar.xz" cache: - key: linux-aarch64-deb9 + key: linux-aarch64-deb10 tags: - aarch64-linux -validate-aarch64-linux-deb9: - extends: .build-aarch64-linux-deb9 +validate-aarch64-linux-deb10: + extends: .build-aarch64-linux-deb10 artifacts: when: always expire_in: 2 week -nightly-aarch64-linux-deb9: +nightly-aarch64-linux-deb10: <<: *nightly - extends: .build-aarch64-linux-deb9 + extends: .build-aarch64-linux-deb10 variables: TEST_TYPE: slowtest ################################# -# armv7-linux-deb9 +# armv7-linux-deb10 ################################# -.build-armv7-linux-deb9: +.build-armv7-linux-deb10: extends: .validate-linux stage: full-build - image: "registry.gitlab.haskell.org/ghc/ci-images/armv7-linux-deb9:$DOCKER_REV" + image: "registry.gitlab.haskell.org/ghc/ci-images/armv7-linux-deb10:$DOCKER_REV" variables: - TEST_ENV: "armv7-linux-deb9" - BIN_DIST_PREP_TAR_COMP: "ghc-armv7-linux-deb9.tar.xz" + TEST_ENV: "armv7-linux-deb10" + BIN_DIST_PREP_TAR_COMP: "ghc-armv7-linux-deb10.tar.xz" CONFIGURE_ARGS: "--host=armv7-linux-gnueabihf --build=armv7-linux-gnueabihf --target=armv7-linux-gnueabihf" cache: - key: linux-armv7-deb9 + key: linux-armv7-deb10 tags: - armv7-linux -validate-armv7-linux-deb9: - extends: .build-armv7-linux-deb9 +validate-armv7-linux-deb10: + extends: .build-armv7-linux-deb10 allow_failure: true artifacts: when: always expire_in: 2 week -nightly-armv7-linux-deb9: +nightly-armv7-linux-deb10: <<: *nightly - extends: .build-armv7-linux-deb9 + extends: .build-armv7-linux-deb10 variables: TEST_TYPE: slowtest @@ -655,6 +655,7 @@ validate-x86_64-linux-deb9-dwarf: variables: TEST_ENV: "x86_64-linux-deb10" BIN_DIST_PREP_TAR_COMP: "./ghc-x86_64-deb10-linux.tar.xz" + LD: "ld.gold" cache: key: linux-x86_64-deb10 ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + result=0 + else + AC_MSG_RESULT([affected]) + result=1 + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + fi +]) + +# FIND_MERGE_OBJECTS +# ------------------ +# Find which linker to use to merge object files. +# +AC_DEFUN([FIND_MERGE_OBJECTS],[ + AC_REQUIRE([FIND_LD]) + + if test -z "$SettingsMergeObjectsCommand"; then + SettingsMergeObjectsCommand="$LD" + fi + if test -z "$SettingsMergeObjectsFlags"; then + SettingsMergeObjectsFlags="-r" + fi + + CHECK_FOR_GOLD_T22266($SettingsMergeObjectsCommand) + if test "$result" = "1"; then + AC_MSG_NOTICE([$SettingsMergeObjectsCommand is broken due to binutils 22266, looking for another linker...]) + SettingsMergeObjectsCommand="" + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + CHECK_FOR_GOLD_T22266($SettingsMergeObjectsCommand) + if test "$result" = "1"; then + AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the SettingsMergeObjectsCommand variable to a functional linker.]) + fi + fi + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/main/DriverPipeline.hs ===================================== @@ -2119,6 +2119,23 @@ We must enable bigobj output in a few places: Unfortunately the big object format is not supported on 32-bit targets so none of this can be used in that case. + + +Note [Merging object files for GHCi] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +GHCi can usually loads standard linkable object files using GHC's linker +implementation. However, most users build their projects with -split-sections, +meaning that such object files can have an extremely high number of sections. +As the linker must map each of these sections individually, loading such object +files is very inefficient. + +To avoid this inefficiency, we use the linker's `-r` flag and a linker script +to produce a merged relocatable object file. This file will contain a singe +text section section and can consequently be mapped far more efficiently. As +gcc tends to do unpredictable things to our linker command line, we opt to +invoke ld directly in this case, in contrast to our usual strategy of linking +via gcc. + -} joinObjectFiles :: DynFlags -> [FilePath] -> FilePath -> IO () @@ -2126,43 +2143,22 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = SysTools.runLink dflags ([ - SysTools.Option "-nostdlib", - SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in DynFlags - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args cc = SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" - | OSMinGW32 == osInfo - , not $ target32Bit (targetPlatform dflags) - ] - ++ map SysTools.Option ld_build_id - ++ [ SysTools.Option "-o", - SysTools.FileOption "" output_fn ] + concat + [ [GHC.SysTools.Option "--oformat", GHC.SysTools.Option "pe-bigobj-x86-64"] + | OSMinGW32 == osInfo + , not $ target32Bit (targetPlatform dflags) + ] + ++ map GHC.SysTools.Option ld_build_id + ++ [ GHC.SysTools.Option "-o", + GHC.SysTools.FileOption "" output_fn ] ++ args) -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] ccInfo <- getCompilerInfo dflags @@ -2172,15 +2168,15 @@ joinObjectFiles dflags o_files output_fn = do cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [SysTools.FileOption "" script] ccInfo + ld_r [SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files - ld_r [SysTools.Option "-Wl,-filelist", - SysTools.FileOption "-Wl," filelist] ccInfo + ld_r [GHC.SysTools.Option "-filelist", + GHC.SysTools.FileOption "" filelist] else do - ld_r (map (SysTools.FileOption "") o_files) ccInfo + ld_r (map (GHC.SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/main/DynFlags.hs ===================================== @@ -106,6 +106,7 @@ module DynFlags ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -124,6 +125,7 @@ module DynFlags ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -152,10 +154,10 @@ module DynFlags ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, systemPackageConfig, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, tablesNextToCode, @@ -1447,6 +1449,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -1493,6 +1497,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/main/Settings.hs ===================================== @@ -19,6 +19,7 @@ module Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -37,6 +38,7 @@ module Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -125,6 +127,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -161,6 +165,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/main/SysTools/Settings.hs ===================================== @@ -141,6 +141,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -202,6 +204,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -220,6 +223,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/main/SysTools/Tasks.hs ===================================== @@ -1,4 +1,5 @@ {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- -- Tasks running external programs for SysTools @@ -299,6 +300,20 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +-- See Note [Merging object files for GHCi] in GHC.Driver.Pipeline. +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + -- N.B. Darwin's ld64 doesn't support response files. Consequently we only + -- use them on Windows where they are truly necessary. +#if defined(mingw32_HOST_OS) + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env +#else + runSomething dflags "Merge objects" p args2 +#endif runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== compiler/main/ToolSettings.hs ===================================== @@ -25,6 +25,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -50,6 +51,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] ===================================== configure.ac ===================================== @@ -13,10 +13,10 @@ dnl # see what flags are available. (Better yet, read the documentation!) # -AC_INIT([The Glorious Glasgow Haskell Compilation System], [8.10.1], [glasgow-haskell-bugs at haskell.org], [ghc-AC_PACKAGE_VERSION]) +AC_INIT([The Glorious Glasgow Haskell Compilation System], [8.10.2], [glasgow-haskell-bugs at haskell.org], [ghc-AC_PACKAGE_VERSION]) # Set this to YES for a released version, otherwise NO -: ${RELEASE=NO} +: ${RELEASE=YES} # The primary version (e.g. 7.5, 7.4.1) is set in the AC_INIT line # above. If this is not a released version, then we will append the @@ -577,13 +577,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -102,6 +102,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/8.10.2-notes.rst ===================================== @@ -6,6 +6,8 @@ Release notes for version 8.10.2 The significant changes to the various parts of the compiler are listed in the following sections. +Like previous releases in the 8.10 series, the :ghc-flag:`LLVM backend <-fllvm>` +of this release is to be used with LLVM 9. Highlights ---------- ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -114,6 +114,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -137,6 +143,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -97,6 +97,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -125,9 +125,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -312,6 +313,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -90,6 +90,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -108,6 +109,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -175,6 +178,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -190,6 +194,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -288,6 +288,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -91,6 +91,7 @@ buildDynamicLibUnix root suffix dynlibpath = do -- | Build a "GHCi library" ('LibGhci') under the given build root, with the -- complete path of the file to build is given as the second argument. +-- See Note [Merging object files for GHCi] in GHC.Driver.Pipeline. buildGhciLibO :: FilePath -> FilePath -> Action () buildGhciLibO root ghcilibPath = do l@(BuildPath _ stage _ (LibGhci _ _ _)) @@ -100,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -38,6 +38,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -246,6 +247,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -162,7 +162,7 @@ $$(includes_$1_H_PLATFORM) : includes/ghc.mk includes/Makefile | $$$$(dir $$$$@) @echo "#if !defined(__GHCPLATFORM_H__)" > $$@ @echo "#define __GHCPLATFORM_H__" >> $$@ @echo >> $$@ - @echo "#define GHC_STAGE $1" >> $$@ + @echo "#define GHC_STAGE ($1 + 1)" >> $$@ @echo >> $$@ @echo "#define BuildPlatform_TYPE $(BuildPlatform_$1_CPP)" >> $$@ @echo "#define HostPlatform_TYPE $(HostPlatform_$1_CPP)" >> $$@ @@ -222,6 +222,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== libraries/haskeline ===================================== @@ -1 +1 @@ -Subproject commit 98d69248d08389f349e12981da43797b8860ae67 +Subproject commit 463fc49d17bfab846cceba48bccc02ef285e6cba ===================================== mk/config.mk.in ===================================== @@ -512,6 +512,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -745,7 +747,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" ===================================== utils/iserv/ghc.mk ===================================== @@ -30,9 +30,8 @@ endif # refer to the RTS. This is harmless if you don't use it (adds a bit # of overhead to startup and increases the binary sizes) but if you # need it there's no alternative. -# Don't do this on FreeBSD to work around #17962. ifeq "$(TargetElf)" "YES" -ifeq "$(findstring $(TargetOS_CPP), solaris2 freebsd)" "" +ifneq "$(TargetOS_CPP)" "solaris2" # The Solaris linker does not support --export-dynamic option. It also # does not need it since it exports all dynamic symbols by default utils/iserv_stage2_MORE_HC_OPTS += -optl-Wl,--export-dynamic View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/dbe09a235cc1cd94215bbf7a43bcad01b253396f...cdeb88870c0d78fc47fbe610ca2a0a0f46b14beb -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/dbe09a235cc1cd94215bbf7a43bcad01b253396f...cdeb88870c0d78fc47fbe610ca2a0a0f46b14beb You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 17:28:12 2020 From: gitlab at gitlab.haskell.org (Josh Meredith) Date: Tue, 04 Aug 2020 13:28:12 -0400 Subject: [Git][ghc/ghc][wip/pluginExtFields] 25 commits: Fix typo Message-ID: <5f299aac297dc_80b3f848c1e06f464345c8@gitlab.haskell.org.mail> Josh Meredith pushed to branch wip/pluginExtFields at Glasgow Haskell Compiler / GHC Commits: b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - f21e6c53 by Josh Meredith at 2020-08-04T13:28:09-04:00 Add machinery for plugins to write data to extensible interface fields - - - - - 0b051156 by Josh Meredith at 2020-08-04T13:28:09-04:00 Add function to remove plugin interface fields - - - - - 30 changed files: - aclocal.m4 - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/Dwarf/Types.hs - compiler/GHC/CmmToAsm/PIC.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Utils.hs - compiler/GHC/Core/Ppr/TyThing.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Make.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore.hs - compiler/GHC/HsToCore/Coverage.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/IfaceToCore.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Parser/PostProcess/Haddock.hs - compiler/GHC/Rename/Bind.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9622de46a83374456a24c5e67957e4ce69de9e87...0b051156b11c2440b81b6c933541d199b5b3d591 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9622de46a83374456a24c5e67957e4ce69de9e87...0b051156b11c2440b81b6c933541d199b5b3d591 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 17:32:09 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Tue, 04 Aug 2020 13:32:09 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/t18522-b Message-ID: <5f299b99b1a41_80b3f848705b144643495c@gitlab.haskell.org.mail> Vladislav Zavialov pushed new branch wip/t18522-b at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/t18522-b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 18:08:20 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 04 Aug 2020 14:08:20 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 9 commits: hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. Message-ID: <5f29a414d20af_80b3f8468e02b546457993@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d240e2f3 by Sylvain Henry at 2020-08-04T14:08:10-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - dfd106b5 by Sylvain Henry at 2020-08-04T14:08:10-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 8be9ec6b by Krzysztof Gogolewski at 2020-08-04T14:08:15-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 5f4cde87 by Ben Gamari at 2020-08-04T14:08:15-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - c54a5e88 by Ben Gamari at 2020-08-04T14:08:15-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 52baf8c3 by Hécate at 2020-08-04T14:08:17-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - d0f579ad by Ryan Scott at 2020-08-04T14:08:18-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 30 changed files: - aclocal.m4 - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Driver/CodeOutput.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - compiler/ghc.cabal.in - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Cabal.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - libraries/base/.hlint.yaml - libraries/base/Control/Concurrent/QSemN.hs - libraries/base/Control/Exception/Base.hs - libraries/base/Data/Coerce.hs - libraries/base/Data/Complex.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9681b3928e8a938b606bfbcdcc4d57f7c653ff17...d0f579adc7ecace9300d07d52a7c5e934ef1b68c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9681b3928e8a938b606bfbcdcc4d57f7c653ff17...d0f579adc7ecace9300d07d52a7c5e934ef1b68c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 18:26:46 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Tue, 04 Aug 2020 14:26:46 -0400 Subject: [Git][ghc/ghc][wip/t18522] Fix debug_ppr_ty ForAllTy (#18522) Message-ID: <5f29a866c6b8b_80b3f8496224a7064719a5@gitlab.haskell.org.mail> Vladislav Zavialov pushed to branch wip/t18522 at Glasgow Haskell Compiler / GHC Commits: b61598c7 by Vladislav Zavialov at 2020-08-04T21:26:20+03:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 4 changed files: - compiler/GHC/Core/TyCo/Ppr.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.stdout - testsuite/tests/ghc-api/all.T Changes: ===================================== compiler/GHC/Core/TyCo/Ppr.hs ===================================== @@ -36,7 +36,8 @@ import {-# SOURCE #-} GHC.CoreToIface import {-# SOURCE #-} GHC.Core.DataCon ( dataConFullSig , dataConUserTyVarBinders, DataCon ) -import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many ) +import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many, + splitForAllTysReq, splitForAllTysInvis ) import GHC.Core.TyCon import GHC.Core.TyCo.Rep @@ -268,19 +269,32 @@ debug_ppr_ty prec (CastTy ty co) debug_ppr_ty _ (CoercionTy co) = parens (text "CO" <+> ppr co) -debug_ppr_ty prec ty@(ForAllTy {}) - | (tvs, body) <- split ty +-- Invisible forall: forall {k} (a :: k). t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysInvis t + , not (null bndrs) = maybeParen prec funPrec $ - hang (text "forall" <+> fsep (map ppr tvs) <> dot) - -- The (map ppr tvs) will print kind-annotated - -- tvs, because we are (usually) in debug-style - 2 (ppr body) + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <> dot, + ppr body ] where - split ty | ForAllTy tv ty' <- ty - , (tvs, body) <- split ty' - = (tv:tvs, body) - | otherwise - = ([], ty) + -- (ppr tv) will print the kind-annotated in debug-style + ppr_bndr (Bndr tv InferredSpec) = braces (ppr tv) + ppr_bndr (Bndr tv SpecifiedSpec) = ppr tv + +-- Visible forall: forall x y -> t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysReq t + , not (null bndrs) + = maybeParen prec funPrec $ + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <+> arrow, + ppr body ] + where + -- (ppr tv) will print the kind-annotated in debug-style + ppr_bndr (Bndr tv ()) = ppr tv + +-- Impossible case: neither visible nor invisible forall. +debug_ppr_ty _ ForAllTy{} + = panic "debug_ppr_ty: neither splitForAllTysInvis nor splitForAllTysReq returned any binders" {- Note [Infix type variables] ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.hs ===================================== @@ -0,0 +1,50 @@ +{-# LANGUAGE TemplateHaskell, ExplicitForAll, PolyKinds #-} + +module Main where + +import Language.Haskell.TH (runQ) +import GHC.Types.Basic +import GHC.ThToHs +import GHC.Driver.Session +import GHC.Core.TyCo.Ppr +import GHC.Utils.Outputable +import GHC.Tc.Module +import GHC.Tc.Utils.Zonk +import GHC.Utils.Error +import GHC.Driver.Types +import GHC +import qualified GHC.LanguageExtensions as LangExt + +import Data.Either (fromRight) +import Control.Monad.IO.Class (liftIO) +import System.Environment (getArgs) + +main :: IO () +main = do + [libdir] <- getArgs + runGhc (Just libdir) $ do + initial_dflags <- getSessionDynFlags + setSessionDynFlags $ initial_dflags + `dopt_set` Opt_D_ppr_debug + `gopt_set` Opt_SuppressUniques + `gopt_set` Opt_SuppressModulePrefixes + `gopt_set` Opt_SuppressVarKinds + `xopt_set` LangExt.KindSignatures + `xopt_set` LangExt.PolyKinds + `xopt_set` LangExt.RankNTypes + hsc_env <- getSession + let dflags = hsc_dflags hsc_env + liftIO $ do + th_t <- runQ [t| forall k {j}. + forall (a :: k) (b :: j) -> + () |] + let hs_t = fromRight (error "convertToHsType") $ + convertToHsType Generated noSrcSpan th_t + ((warnings, errors), mres) <- + tcRnType hsc_env SkolemiseFlexi True hs_t + case mres of + Nothing -> do + printBagOfErrors dflags warnings + printBagOfErrors dflags errors + Just (t, _) -> do + putStrLn $ showSDoc dflags (debugPprType t) ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.stdout ===================================== @@ -0,0 +1,2 @@ +forall k{tv}[tv] {j{tv}[tv]}. +forall a{tv}[tv] b{tv}[tv] -> (){(w) tc} ===================================== testsuite/tests/ghc-api/all.T ===================================== @@ -20,3 +20,7 @@ test('T9015', extra_run_opts('"' + config.libdir + '"'), test('T11579', extra_run_opts('"' + config.libdir + '"'), compile_and_run, ['-package ghc']) test('T12099', normal, compile_and_run, ['-package ghc']) +test('T18522-dbg-ppr', + extra_run_opts('"' + config.libdir + '"'), + compile_and_run, + ['-package ghc']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b61598c750b9ab5d719dd6df5119c9007cb8e5bd -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b61598c750b9ab5d719dd6df5119c9007cb8e5bd You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 18:28:53 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Tue, 04 Aug 2020 14:28:53 -0400 Subject: [Git][ghc/ghc][wip/t18522] Fix debug_ppr_ty ForAllTy (#18522) Message-ID: <5f29a8e5ab3c4_80b3f848a386fc8647478e@gitlab.haskell.org.mail> Vladislav Zavialov pushed to branch wip/t18522 at Glasgow Haskell Compiler / GHC Commits: 6248d953 by Vladislav Zavialov at 2020-08-04T21:28:15+03:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 4 changed files: - compiler/GHC/Core/TyCo/Ppr.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.stdout - testsuite/tests/ghc-api/all.T Changes: ===================================== compiler/GHC/Core/TyCo/Ppr.hs ===================================== @@ -36,7 +36,8 @@ import {-# SOURCE #-} GHC.CoreToIface import {-# SOURCE #-} GHC.Core.DataCon ( dataConFullSig , dataConUserTyVarBinders, DataCon ) -import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many ) +import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many, + splitForAllTysReq, splitForAllTysInvis ) import GHC.Core.TyCon import GHC.Core.TyCo.Rep @@ -268,19 +269,34 @@ debug_ppr_ty prec (CastTy ty co) debug_ppr_ty _ (CoercionTy co) = parens (text "CO" <+> ppr co) -debug_ppr_ty prec ty@(ForAllTy {}) - | (tvs, body) <- split ty +-- Invisible forall: forall {k} (a :: k). t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysInvis t + , not (null bndrs) = maybeParen prec funPrec $ - hang (text "forall" <+> fsep (map ppr tvs) <> dot) - -- The (map ppr tvs) will print kind-annotated - -- tvs, because we are (usually) in debug-style - 2 (ppr body) + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <> dot, + ppr body ] where - split ty | ForAllTy tv ty' <- ty - , (tvs, body) <- split ty' - = (tv:tvs, body) - | otherwise - = ([], ty) + -- (ppr tv) will print the binder kind-annotated + -- when in debug-style + ppr_bndr (Bndr tv InferredSpec) = braces (ppr tv) + ppr_bndr (Bndr tv SpecifiedSpec) = ppr tv + +-- Visible forall: forall x y -> t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysReq t + , not (null bndrs) + = maybeParen prec funPrec $ + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <+> arrow, + ppr body ] + where + -- (ppr tv) will print the binder kind-annotated + -- when in debug-style + ppr_bndr (Bndr tv ()) = ppr tv + +-- Impossible case: neither visible nor invisible forall. +debug_ppr_ty _ ForAllTy{} + = panic "debug_ppr_ty: neither splitForAllTysInvis nor splitForAllTysReq returned any binders" {- Note [Infix type variables] ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.hs ===================================== @@ -0,0 +1,50 @@ +{-# LANGUAGE TemplateHaskell, ExplicitForAll, PolyKinds #-} + +module Main where + +import Language.Haskell.TH (runQ) +import GHC.Types.Basic +import GHC.ThToHs +import GHC.Driver.Session +import GHC.Core.TyCo.Ppr +import GHC.Utils.Outputable +import GHC.Tc.Module +import GHC.Tc.Utils.Zonk +import GHC.Utils.Error +import GHC.Driver.Types +import GHC +import qualified GHC.LanguageExtensions as LangExt + +import Data.Either (fromRight) +import Control.Monad.IO.Class (liftIO) +import System.Environment (getArgs) + +main :: IO () +main = do + [libdir] <- getArgs + runGhc (Just libdir) $ do + initial_dflags <- getSessionDynFlags + setSessionDynFlags $ initial_dflags + `dopt_set` Opt_D_ppr_debug + `gopt_set` Opt_SuppressUniques + `gopt_set` Opt_SuppressModulePrefixes + `gopt_set` Opt_SuppressVarKinds + `xopt_set` LangExt.KindSignatures + `xopt_set` LangExt.PolyKinds + `xopt_set` LangExt.RankNTypes + hsc_env <- getSession + let dflags = hsc_dflags hsc_env + liftIO $ do + th_t <- runQ [t| forall k {j}. + forall (a :: k) (b :: j) -> + () |] + let hs_t = fromRight (error "convertToHsType") $ + convertToHsType Generated noSrcSpan th_t + ((warnings, errors), mres) <- + tcRnType hsc_env SkolemiseFlexi True hs_t + case mres of + Nothing -> do + printBagOfErrors dflags warnings + printBagOfErrors dflags errors + Just (t, _) -> do + putStrLn $ showSDoc dflags (debugPprType t) ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.stdout ===================================== @@ -0,0 +1,2 @@ +forall k{tv}[tv] {j{tv}[tv]}. +forall a{tv}[tv] b{tv}[tv] -> (){(w) tc} ===================================== testsuite/tests/ghc-api/all.T ===================================== @@ -20,3 +20,7 @@ test('T9015', extra_run_opts('"' + config.libdir + '"'), test('T11579', extra_run_opts('"' + config.libdir + '"'), compile_and_run, ['-package ghc']) test('T12099', normal, compile_and_run, ['-package ghc']) +test('T18522-dbg-ppr', + extra_run_opts('"' + config.libdir + '"'), + compile_and_run, + ['-package ghc']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6248d95388b778c94c194ce56e809f77378f5a7e -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6248d95388b778c94c194ce56e809f77378f5a7e You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 18:40:42 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Tue, 04 Aug 2020 14:40:42 -0400 Subject: [Git][ghc/ghc][wip/t18522-b] Fix visible forall in ppr_ty (#18522) Message-ID: <5f29abaae91d1_80b8ca3ed064754e3@gitlab.haskell.org.mail> Vladislav Zavialov pushed to branch wip/t18522-b at Glasgow Haskell Compiler / GHC Commits: 9f0367b1 by Vladislav Zavialov at 2020-08-04T21:39:37+03:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - 4 changed files: - compiler/GHC/Iface/Type.hs - + testsuite/tests/polykinds/T18522-ppr.script - + testsuite/tests/polykinds/T18522-ppr.stdout - testsuite/tests/polykinds/all.T Changes: ===================================== compiler/GHC/Iface/Type.hs ===================================== @@ -441,6 +441,7 @@ splitIfaceSigmaTy ty (theta, tau) = split_rho rho split_foralls (IfaceForAllTy bndr ty) + | isInvisibleArgFlag (binderArgFlag bndr) = case split_foralls ty of { (bndrs, rho) -> (bndr:bndrs, rho) } split_foralls rho = ([], rho) @@ -448,6 +449,12 @@ splitIfaceSigmaTy ty = case split_rho ty2 of { (ps, tau) -> (ty1:ps, tau) } split_rho tau = ([], tau) +splitIfaceReqForallTy :: IfaceType -> ([IfaceForAllBndr], IfaceType) +splitIfaceReqForallTy (IfaceForAllTy bndr ty) + | isVisibleArgFlag (binderArgFlag bndr) + = case splitIfaceReqForallTy ty of { (bndrs, rho) -> (bndr:bndrs, rho) } +splitIfaceReqForallTy rho = ([], rho) + suppressIfaceInvisibles :: PrintExplicitKinds -> [IfaceTyConBinder] -> [a] -> [a] suppressIfaceInvisibles (PrintExplicitKinds True) _tys xs = xs suppressIfaceInvisibles (PrintExplicitKinds False) tys xs = suppress tys xs @@ -1184,8 +1191,10 @@ pprIfaceSigmaType show_forall ty = hideNonStandardTypes ppr_fn ty where ppr_fn iface_ty = - let (tvs, theta, tau) = splitIfaceSigmaTy iface_ty - in ppr_iface_forall_part show_forall tvs theta (ppr tau) + let (invis_tvs, theta, tau) = splitIfaceSigmaTy iface_ty + (req_tvs, tau') = splitIfaceReqForallTy tau + in ppr_iface_forall_part show_forall invis_tvs theta $ + sep [pprIfaceForAll req_tvs, ppr tau'] pprUserIfaceForAll :: [IfaceForAllBndr] -> SDoc pprUserIfaceForAll tvs ===================================== testsuite/tests/polykinds/T18522-ppr.script ===================================== @@ -0,0 +1,4 @@ +:set -XPolyKinds -XDataKinds -XRankNTypes -XTypeFamilies +import Data.Kind (Type) +type family T :: forall k -> (k ~ k) => forall j -> k -> j -> Type +:k T ===================================== testsuite/tests/polykinds/T18522-ppr.stdout ===================================== @@ -0,0 +1 @@ +T :: forall k -> (k ~ k) => forall j -> k -> j -> * ===================================== testsuite/tests/polykinds/all.T ===================================== @@ -223,3 +223,4 @@ test('T18300', normal, compile_fail, ['']) test('T18451', normal, compile_fail, ['']) test('T18451a', normal, compile_fail, ['']) test('T18451b', normal, compile_fail, ['']) +test('T18522-ppr', normal, ghci_script, ['T18522-ppr.script']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9f0367b1aacd98e4861c06c0ebdae46c632185dd -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9f0367b1aacd98e4861c06c0ebdae46c632185dd You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 19:07:57 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Tue, 04 Aug 2020 15:07:57 -0400 Subject: [Git][ghc/ghc][wip/T8095-spj] Simplify TyCoFolder Message-ID: <5f29b20d51088_80b3f849c1caa106485641@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T8095-spj at Glasgow Haskell Compiler / GHC Commits: 16ef62d4 by Simon Peyton Jones at 2020-08-04T20:06:59+01:00 Simplify TyCoFolder This commit removes the 'env' part of TyCoFolder. A nice simplification! - - - - - 6 changed files: - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/TyCo/FVs.hs - compiler/GHC/Core/TyCo/Rep.hs - compiler/GHC/Core/Unify.hs - compiler/GHC/Tc/Utils/TcType.hs - compiler/GHC/Tc/Utils/Zonk.hs Changes: ===================================== compiler/GHC/Core/Coercion.hs ===================================== @@ -2940,22 +2940,19 @@ simplifyArgsWorker orig_ki_binders orig_inner_ki orig_fvs %************************************************************************ -} -bad_co_hole_ty :: () -> Type -> Monoid.Any -bad_co_hole_co :: () -> Coercion -> Monoid.Any +bad_co_hole_ty :: Type -> Monoid.Any +bad_co_hole_co :: Coercion -> Monoid.Any (bad_co_hole_ty, _, bad_co_hole_co, _) = foldTyCo folder where - folder :: TyCoFolder () Monoid.Any + folder :: TyCoFolder Monoid.Any folder = TyCoFolder { tcf_view = const Nothing - , tcf_tyvar = const2 (Monoid.Any False) - , tcf_covar = const2 (Monoid.Any False) - , tcf_hole = const hole - , tcf_tycobinder = const2 + , tcf_tyvar = const (Monoid.Any False) + , tcf_covar = const (Monoid.Any False) + , tcf_hole = hole + , tcf_tycobinder = \_ _ acc -> acc } - const2 :: a -> b -> c -> a - const2 x _ _ = x - hole :: CoercionHole -> Monoid.Any hole (CoercionHole { ch_blocker = YesBlockSubst }) = Monoid.Any True hole _ = Monoid.Any False @@ -2963,9 +2960,9 @@ bad_co_hole_co :: () -> Coercion -> Monoid.Any -- | Is there a blocking coercion hole in this type? See -- "GHC.Tc.Solver.Canonical" Note [Equalities with incompatible kinds] badCoercionHole :: Type -> Bool -badCoercionHole = Monoid.getAny . bad_co_hole_ty () +badCoercionHole = Monoid.getAny . bad_co_hole_ty -- | Is there a blocking coercion hole in this coercion? See -- GHC.Tc.Solver.Canonical Note [Equalities with incompatible kinds] badCoercionHoleCo :: Coercion -> Bool -badCoercionHoleCo = Monoid.getAny . bad_co_hole_co () +badCoercionHoleCo = Monoid.getAny . bad_co_hole_co ===================================== compiler/GHC/Core/TyCo/FVs.hs ===================================== @@ -1,4 +1,4 @@ -{-# LANGUAGE CPP #-} +{-# LANGUAGE CPP, PatternSynonyms #-} module GHC.Core.TyCo.FVs ( shallowTyCoVarsOfType, shallowTyCoVarsOfTypes, @@ -39,7 +39,7 @@ module GHC.Core.TyCo.FVs closeOverKinds, -- * Raw materials - Endo(..), TyCoFvFun, InScopeBndrs, emptyInScope, runTyCoVars + TyCoAcc(..), InScopeBndrs, emptyInScope, extendInScope, runTyCoVars ) where #include "HsVersions.h" @@ -48,7 +48,6 @@ import GHC.Prelude import {-# SOURCE #-} GHC.Core.Type (coreView, partitionInvisibleTypes) -import Data.Monoid as DM ( Endo(..), All(..) ) import GHC.Core.TyCo.Rep import GHC.Core.TyCon import GHC.Types.Var @@ -59,7 +58,8 @@ import GHC.Types.Var.Set import GHC.Types.Var.Env import GHC.Utils.Misc import GHC.Utils.Panic - +import Data.Semigroup as Semigroup +import GHC.Exts( oneShot ) {- %************************************************************************ %* * @@ -264,14 +264,54 @@ TL;DR: check this regularly! -} type InScopeBndrs = TyCoVarSet -type TyCoFvFun a s = InScopeBndrs -> a -> Endo s +newtype TyCoAcc acc = TCA' { runTCA :: InScopeBndrs -> acc -> acc } + +pattern TCA :: forall acc. (InScopeBndrs -> acc -> acc) -> TyCoAcc acc +{-# COMPLETE TCA #-} +pattern TCA f <- TCA' f + where + TCA f = TCA' (oneShot f) + +instance Semigroup (TyCoAcc acc) where + (TCA f1) <> (TCA f2) = TCA (\is acc -> f2 is (f1 is acc)) + {-# INLINE (<>) #-} + +instance Monoid (TyCoAcc acc) where + mempty = TCA (\_ acc -> acc) + {-# INLINE mempty #-} + mappend = (Semigroup.<>) + {-# INLINE mappend #-} emptyInScope :: InScopeBndrs emptyInScope = emptyVarSet -runTyCoVars :: TyCoFvFun a TyCoVarSet -> a -> TyCoVarSet +addTyCoVar :: TyCoVar -> TyCoAcc TyCoVarSet -> TyCoAcc TyCoVarSet +-- Add a variable tcv, and the extras, to the free vars unless +-- tcv is in the in-scope +-- or is already in the in-scope set- +-- The 'extras' start from an empty in-scope set; +-- see Note [Closing over free variable kinds] +addTyCoVar tcv (TCA add_extras) = TCA add_it + where + add_it is acc + | tcv `elemVarSet` is = acc + | tcv `elemVarSet` acc = acc + | otherwise = add_extras emptyVarSet (acc `extendVarSet` tcv) + +extendInScope :: TyCoVar -> TyCoAcc acc -> TyCoAcc acc +-- Gather the argument free vars in an empty in-scope set +extendInScope tcv (TCA f) = TCA (\is acc -> f (is `extendVarSet` tcv) acc) + +whenNotInScope :: TyCoVar -> TyCoAcc acc -> TyCoAcc acc +-- If tcv is not in the in-scope set, compute +-- the 'extras' in an empty in-scope set +whenNotInScope tcv (TCA f) = TCA (\is acc -> if tcv `elemVarSet` is + then acc + else f emptyInScope acc) + +runTyCoVars :: (a -> TyCoAcc TyCoVarSet) -> a -> TyCoVarSet {-# INLINE runTyCoVars #-} -runTyCoVars f = \x -> appEndo (f emptyInScope x) emptyVarSet +runTyCoVars f = \x -> runTCA (f x) emptyInScope emptyVarSet -- It's very important that the \x is to the right of the '=', so -- runTyCoVars has arity 1. It is often applied to just one arg e.g. -- tyCoVarsOfType = runTyCoVars deep_ty @@ -292,9 +332,9 @@ runTyCoVars f = \x -> appEndo (f emptyInScope x) emptyVarSet -- See Note [Free variables of Coercions] -tyCoVarsOfType :: Type -> TyCoVarSet -tyCoVarsOfTypes :: [Type] -> TyCoVarSet -tyCoVarsOfCo :: Coercion -> TyCoVarSet +tyCoVarsOfType :: Type -> TyCoVarSet +tyCoVarsOfTypes :: [Type] -> TyCoVarSet +tyCoVarsOfCo :: Coercion -> TyCoVarSet tyCoVarsOfCos :: [Coercion] -> TyCoVarSet tyCoVarsOfType = runTyCoVars deep_ty @@ -305,27 +345,21 @@ tyCoVarsOfCos = runTyCoVars deep_cos -- Alternative for tyCoVarsOfType -- tyCoVarsOfType ty = closeOverKinds (shallowTyCoVarsOfType ty) -deep_ty :: TyCoFvFun Type TyCoVarSet -deep_tys :: TyCoFvFun [Type] TyCoVarSet -deep_co :: TyCoFvFun Coercion TyCoVarSet -deep_cos :: TyCoFvFun [Coercion] TyCoVarSet +deep_ty :: Type -> TyCoAcc TyCoVarSet +deep_tys :: [Type] -> TyCoAcc TyCoVarSet +deep_co :: Coercion -> TyCoAcc TyCoVarSet +deep_cos :: [Coercion] -> TyCoAcc TyCoVarSet (deep_ty, deep_tys, deep_co, deep_cos) = foldTyCo deepTcvFolder -deepTcvFolder :: TyCoFolder InScopeBndrs (Endo TyCoVarSet) +deepTcvFolder :: TyCoFolder (TyCoAcc TyCoVarSet) deepTcvFolder = TyCoFolder { tcf_view = noView , tcf_tyvar = do_tcv, tcf_covar = do_tcv , tcf_hole = do_hole, tcf_tycobinder = do_bndr } where - do_tcv is v = Endo do_it - where - do_it acc | v `elemVarSet` is = acc - | v `elemVarSet` acc = acc - | otherwise = appEndo (deep_ty emptyInScope (varType v)) $ - acc `extendVarSet` v - -- emptyInScope: see Note [Closing over free variable kinds] - - do_bndr is tcv _ = extendVarSet is tcv - do_hole is hole = do_tcv is (coHoleCoVar hole) + do_tcv v = addTyCoVar v (deep_ty (varType v)) + + do_bndr tcv _vis fvs = extendInScope tcv fvs + do_hole hole = do_tcv (coHoleCoVar hole) -- See Note [CoercionHoles and coercion free variables] -- in GHC.Core.TyCo.Rep @@ -337,18 +371,16 @@ deepTcvFolder = TyCoFolder { tcf_view = noView ********************************************************************* -} -shallowTyCoVarsOfType :: Type -> TyCoVarSet -- See Note [Free variables of types] -shallowTyCoVarsOfType = runTyCoVars shallow_ty +shallowTyCoVarsOfType :: Type -> TyCoVarSet +shallowTyCoVarsOfTypes :: [Type] -> TyCoVarSet +shallowTyCoVarsOfCo :: Coercion -> TyCoVarSet +shallowTyCoVarsOfCos :: [Coercion] -> TyCoVarSet -shallowTyCoVarsOfTypes :: [Type] -> TyCoVarSet +shallowTyCoVarsOfType = runTyCoVars shallow_ty shallowTyCoVarsOfTypes = runTyCoVars shallow_tys - -shallowTyCoVarsOfCo :: Coercion -> TyCoVarSet -shallowTyCoVarsOfCo = runTyCoVars shallow_co - -shallowTyCoVarsOfCos :: [Coercion] -> TyCoVarSet -shallowTyCoVarsOfCos = runTyCoVars shallow_cos +shallowTyCoVarsOfCo = runTyCoVars shallow_co +shallowTyCoVarsOfCos = runTyCoVars shallow_cos -- | Returns free variables of types, including kind variables as -- a non-deterministic set. For type synonyms it does /not/ expand the @@ -364,25 +396,21 @@ shallowTyCoVarsOfCoVarEnv cos = shallowTyCoVarsOfCos (nonDetEltsUFM cos) -- It's OK to use nonDetEltsUFM here because we immediately -- forget the ordering by returning a set -shallow_ty :: TyCoFvFun Type TyCoVarSet -shallow_tys :: TyCoFvFun [Type] TyCoVarSet -shallow_co :: TyCoFvFun Coercion TyCoVarSet -shallow_cos :: TyCoFvFun [Coercion] TyCoVarSet +shallow_ty :: Type -> TyCoAcc TyCoVarSet +shallow_tys :: [Type] -> TyCoAcc TyCoVarSet +shallow_co :: Coercion -> TyCoAcc TyCoVarSet +shallow_cos :: [Coercion] -> TyCoAcc TyCoVarSet + (shallow_ty, shallow_tys, shallow_co, shallow_cos) = foldTyCo shallowTcvFolder -shallowTcvFolder :: TyCoFolder InScopeBndrs (Endo TyCoVarSet) +shallowTcvFolder :: TyCoFolder (TyCoAcc TyCoVarSet) shallowTcvFolder = TyCoFolder { tcf_view = noView , tcf_tyvar = do_tcv, tcf_covar = do_tcv , tcf_hole = do_hole, tcf_tycobinder = do_bndr } where - do_tcv is v = Endo do_it - where - do_it acc | v `elemVarSet` is = acc - | v `elemVarSet` acc = acc - | otherwise = acc `extendVarSet` v - - do_bndr is tcv _ = extendVarSet is tcv - do_hole _ _ = mempty -- Ignore coercion holes + do_hole _ = mempty -- Ignore coercion holes + do_tcv v = addTyCoVar v mempty + do_bndr tcv _vis fvs = extendInScope tcv fvs {- ********************************************************************* @@ -412,61 +440,63 @@ coVarsOfTypes = runTyCoVars deep_cv_tys coVarsOfCo = runTyCoVars deep_cv_co coVarsOfCos = runTyCoVars deep_cv_cos -deep_cv_ty :: TyCoFvFun Type TyCoVarSet -deep_cv_tys :: TyCoFvFun [Type] TyCoVarSet -deep_cv_co :: TyCoFvFun Coercion TyCoVarSet -deep_cv_cos :: TyCoFvFun [Coercion] TyCoVarSet +deep_cv_ty :: Type -> TyCoAcc TyCoVarSet +deep_cv_tys :: [Type] -> TyCoAcc TyCoVarSet +deep_cv_co :: Coercion -> TyCoAcc TyCoVarSet +deep_cv_cos :: [Coercion] -> TyCoAcc TyCoVarSet (deep_cv_ty, deep_cv_tys, deep_cv_co, deep_cv_cos) = foldTyCo deepCoVarFolder -deepCoVarFolder :: TyCoFolder InScopeBndrs (Endo CoVarSet) +deepCoVarFolder :: TyCoFolder (TyCoAcc TyCoVarSet) deepCoVarFolder = TyCoFolder { tcf_view = noView , tcf_tyvar = do_tyvar, tcf_covar = do_covar , tcf_hole = do_hole, tcf_tycobinder = do_bndr } where - do_tyvar _ _ = mempty + do_tyvar _ = mempty -- This do_tyvar means we won't see any CoVars in this -- TyVar's kind. This may be wrong; but it's the way it's -- always been. And its awkward to change, because -- the tyvar won't end up in the accumulator, so -- we'd look repeatedly. Blargh. - do_covar is v = Endo do_it - where - do_it acc | v `elemVarSet` is = acc - | v `elemVarSet` acc = acc - | otherwise = appEndo (deep_cv_ty emptyInScope (varType v)) $ - acc `extendVarSet` v - -- emptyInScope: see Note [Closing over free variable kinds] - - do_bndr is tcv _ = extendVarSet is tcv - do_hole is hole = do_covar is (coHoleCoVar hole) + do_covar cv = addTyCoVar cv (deep_ty (varType cv)) + + do_bndr tcv _vis fvs = extendInScope tcv fvs + do_hole hole = do_covar (coHoleCoVar hole) -- See Note [CoercionHoles and coercion free variables] -- in GHC.Core.TyCo.Rep ------- Same again, but for DCoVarSet ---------- coVarsOfCoDSet :: Coercion -> DCoVarSet -coVarsOfCoDSet co = appEndo (deep_dcv_co emptyInScope co) emptyDVarSet +coVarsOfCoDSet co = runTCA (deep_dcv_co co) emptyVarSet emptyDVarSet -deep_dcv_ty :: TyCoFvFun Type DCoVarSet -deep_dcv_co :: TyCoFvFun Coercion DCoVarSet +deep_dcv_ty :: Type -> TyCoAcc DCoVarSet +deep_dcv_co :: Coercion -> TyCoAcc DCoVarSet (deep_dcv_ty, _, deep_dcv_co, _) = foldTyCo deepCoVarDSetFolder -deepCoVarDSetFolder :: TyCoFolder InScopeBndrs (Endo DCoVarSet) +deepCoVarDSetFolder :: TyCoFolder (TyCoAcc DCoVarSet) deepCoVarDSetFolder = TyCoFolder { tcf_view = noView , tcf_tyvar = do_tyvar, tcf_covar = do_covar , tcf_hole = do_hole, tcf_tycobinder = do_bndr } where - do_tyvar _ _ = mempty - do_covar is v = Endo do_it - where - do_it :: DCoVarSet -> DCoVarSet - do_it acc | v `elemVarSet` is = acc - | v `elemDVarSet` acc = acc - | otherwise = appEndo (deep_dcv_ty emptyInScope (varType v)) $ - acc `extendDVarSet` v - do_bndr is tcv _ = extendVarSet is tcv - do_hole is hole = do_covar is (coHoleCoVar hole) + do_tyvar _ = mempty + do_covar cv = addCoVarDSet cv (deep_dcv_ty (varType cv)) + + + do_bndr tcv _vis fvs = extendInScope tcv fvs + do_hole hole = do_covar (coHoleCoVar hole) + +addCoVarDSet :: CoVar -> TyCoAcc DCoVarSet -> TyCoAcc DCoVarSet +-- Add a variable to the free vars unless it is in the in-scope +-- or is already in the in-scope set- +addCoVarDSet cv (TCA add_extras) = TCA add_it + where + add_it is acc | cv `elemVarSet` is = acc + | cv `elemDVarSet` acc = acc + | otherwise = add_extras emptyInScope $ + acc `extendDVarSet` cv + -- emptyInScopeSet: see Note [Closing over free variable kinds] + {- ********************************************************************* * * @@ -481,7 +511,7 @@ closeOverKinds :: TyCoVarSet -> TyCoVarSet -- add the deep free variables of its kind closeOverKinds vs = nonDetStrictFoldVarSet do_one vs vs where - do_one v acc = appEndo (deep_ty emptyVarSet (varType v)) acc + do_one v acc = runTCA (deep_ty (varType v)) emptyInScope acc {- --------------- Alternative version 1 (using FV) ------------ closeOverKinds = fvVarSet . closeOverKindsFV . nonDetEltsUniqSet @@ -876,29 +906,27 @@ injectiveVarsOfTypes look_under_tfs = mapUnionFV (injectiveVarsOfType look_under invisibleVarsOfTypes :: [Type] -> VarSet invisibleVarsOfTypes = runTyCoVars invis_tys -invis_tys :: TyCoFvFun [Type] TyCoVarSet -invis_tys _ [] = mempty -invis_tys is (ty:tys) = invis_ty is ty `mappend` invis_tys is tys - -invis_ty :: TyCoFvFun Type TyCoVarSet -invis_ty is ty | Just ty' <- coreView ty - = invis_ty is ty' - -invis_ty is (TyVarTy v) - | v `elemVarSet` is = mempty - | otherwise = deep_ty emptyVarSet (tyVarKind v) -invis_ty is (AppTy f a) = invis_ty is f `mappend` invis_ty is a -invis_ty is (FunTy _ w ty1 ty2) = invis_ty is w `mappend` invis_ty is ty1 `mappend` invis_ty is ty2 -invis_ty is (TyConApp tc tys) = deep_tys is invisibles `mappend` - invis_tys is visibles +invis_tys :: [Type] -> TyCoAcc TyCoVarSet +invis_tys [] = mempty +invis_tys (ty:tys) = invis_ty ty `mappend` invis_tys tys + +invis_ty :: Type -> TyCoAcc TyCoVarSet +invis_ty ty | Just ty' <- coreView ty + = invis_ty ty' + +invis_ty (TyVarTy v) = whenNotInScope v $ + deep_ty (tyVarKind v) +invis_ty (AppTy f a) = invis_ty f `mappend` invis_ty a +invis_ty (FunTy _ w ty1 ty2) = invis_ty w `mappend` invis_ty ty1 `mappend` invis_ty ty2 +invis_ty (TyConApp tc tys) = deep_tys invisibles `mappend` + invis_tys visibles where (invisibles, visibles) = partitionInvisibleTypes tc tys -invis_ty is (ForAllTy tvb ty) = invis_ty is (tyVarKind tv) `mappend` - invis_ty (is `extendVarSet` tv) ty - where - tv = binderVar tvb -invis_ty _ LitTy{} = mempty -invis_ty is (CastTy ty co) = deep_co is co `mappend` invis_ty is ty -invis_ty is (CoercionTy co) = deep_co is co +invis_ty (ForAllTy (Bndr tv _) ty) = invis_ty (tyVarKind tv) `mappend` + extendInScope tv (invis_ty ty) +invis_ty (LitTy {}) = mempty +invis_ty (CastTy ty co) = deep_co co `mappend` invis_ty ty +invis_ty (CoercionTy co) = deep_co co + {- ********************************************************************* * * @@ -906,28 +934,31 @@ invis_ty is (CoercionTy co) = deep_co is co * * ********************************************************************* -} -nfvFolder :: TyCoFolder InScopeBndrs DM.All +nfvFolder :: TyCoFolder (TyCoAcc Bool) nfvFolder = TyCoFolder { tcf_view = noView , tcf_tyvar = do_tcv, tcf_covar = do_tcv , tcf_hole = do_hole, tcf_tycobinder = do_bndr } where - do_tcv is tv = All (tv `elemVarSet` is) - do_hole _ _ = All True -- I'm unsure; probably never happens - do_bndr is tv _ = is `extendVarSet` tv + do_tcv tv = TCA (\is acc -> acc && tv `elemVarSet` is) + do_hole _ = mempty -- I'm unsure; probably never happens + do_bndr tv _vis fvs = extendInScope tv fvs -nfv_ty :: InScopeBndrs -> Type -> DM.All -nfv_tys :: InScopeBndrs -> [Type] -> DM.All -nfv_co :: InScopeBndrs -> Coercion -> DM.All +nfv_ty :: Type -> TyCoAcc Bool +nfv_tys :: [Type] -> TyCoAcc Bool +nfv_co :: Coercion -> TyCoAcc Bool (nfv_ty, nfv_tys, nfv_co, _) = foldTyCo nfvFolder -noFreeVarsOfType :: Type -> Bool -noFreeVarsOfType ty = DM.getAll (nfv_ty emptyInScope ty) +runAll :: TyCoAcc Bool -> Bool +runAll (TCA f) = f emptyInScope True +noFreeVarsOfType :: Type -> Bool noFreeVarsOfTypes :: [Type] -> Bool -noFreeVarsOfTypes tys = DM.getAll (nfv_tys emptyInScope tys) +noFreeVarsOfCo :: Coercion -> Bool + +noFreeVarsOfType ty = runAll (nfv_ty ty) +noFreeVarsOfTypes tys = runAll (nfv_tys tys) +noFreeVarsOfCo co = runAll (nfv_co co) -noFreeVarsOfCo :: Coercion -> Bool -noFreeVarsOfCo co = DM.getAll (nfv_co emptyInScope co) {- ********************************************************************* ===================================== compiler/GHC/Core/TyCo/Rep.hs ===================================== @@ -1883,18 +1883,17 @@ TyCoFolder data constructor for deep_tcf as a loop breaker, so the record selections still cancel. And eta expansion still happens too. -} -data TyCoFolder env a +data TyCoFolder a = TyCoFolder { tcf_view :: Type -> Maybe Type -- Optional "view" function -- E.g. expand synonyms - , tcf_tyvar :: env -> TyVar -> a - , tcf_covar :: env -> CoVar -> a - , tcf_hole :: env -> CoercionHole -> a + , tcf_tyvar :: TyVar -> a + , tcf_covar :: CoVar -> a + , tcf_hole :: CoercionHole -> a -- ^ What to do with coercion holes. -- See Note [Coercion holes] in "GHC.Core.TyCo.Rep". - , tcf_tycobinder :: env -> TyCoVar -> ArgFlag -> env - -- ^ The returned env is used in the extended scope + , tcf_tycobinder :: TyCoVar -> ArgFlag -> a -> a } noView :: Type -> Maybe Type -- Simplest form of tcf_view @@ -1902,11 +1901,11 @@ noView :: Type -> Maybe Type -- Simplest form of tcf_view noView _ = Nothing {-# INLINE foldTyCo #-} -- See Note [Specialising foldType] -foldTyCo :: Monoid a => TyCoFolder env a - -> ( env -> Type -> a - , env -> [Type] -> a - , env -> Coercion -> a - , env -> [Coercion] -> a ) +foldTyCo :: Monoid a => TyCoFolder a + -> ( Type -> a + , [Type] -> a + , Coercion -> a + , [Coercion] -> a ) foldTyCo (TyCoFolder { tcf_view = view , tcf_tyvar = tyvar , tcf_tycobinder = tycobinder @@ -1914,61 +1913,58 @@ foldTyCo (TyCoFolder { tcf_view = view , tcf_hole = cohole }) = (go_ty, go_tys, go_co, go_cos) where - go_ty env ty | Just ty' <- view ty = go_ty env ty' - go_ty env (TyVarTy tv) = tyvar env tv - go_ty env (AppTy t1 t2) = go_ty env t1 `mappend` go_ty env t2 - go_ty _ (LitTy {}) = mempty - go_ty env (CastTy ty co) = go_ty env ty `mappend` go_co env co - go_ty env (CoercionTy co) = go_co env co - go_ty env (FunTy _ w arg res) = go_ty env w `mappend` go_ty env arg `mappend` go_ty env res - go_ty env (TyConApp _ tys) = go_tys env tys - go_ty env (ForAllTy (Bndr tv vis) inner) - = let !env' = tycobinder env tv vis -- Avoid building a thunk here - in go_ty env (varType tv) `mappend` go_ty env' inner + go_ty ty | Just ty' <- view ty = go_ty ty' + go_ty (TyVarTy tv) = tyvar tv + go_ty (AppTy t1 t2) = go_ty t1 `mappend` go_ty t2 + go_ty (LitTy {}) = mempty + go_ty (CastTy ty co) = go_ty ty `mappend` go_co co + go_ty (CoercionTy co) = go_co co + go_ty (FunTy _ w arg res) = go_ty w `mappend` go_ty arg `mappend` go_ty res + go_ty (TyConApp _ tys) = go_tys tys + go_ty (ForAllTy (Bndr tv vis) inner) + = go_ty (varType tv) `mappend` tycobinder tv vis (go_ty inner) -- Explicit recursion becuase using foldr builds a local - -- loop (with env free) and I'm not confident it'll be + -- loop (with free) and I'm not confident it'll be -- lambda lifted in the end - go_tys _ [] = mempty - go_tys env (t:ts) = go_ty env t `mappend` go_tys env ts - - go_cos _ [] = mempty - go_cos env (c:cs) = go_co env c `mappend` go_cos env cs - - go_co env (Refl ty) = go_ty env ty - go_co env (GRefl _ ty MRefl) = go_ty env ty - go_co env (GRefl _ ty (MCo co)) = go_ty env ty `mappend` go_co env co - go_co env (TyConAppCo _ _ args) = go_cos env args - go_co env (AppCo c1 c2) = go_co env c1 `mappend` go_co env c2 - go_co env (FunCo _ cw c1 c2) = go_co env cw `mappend` - go_co env c1 `mappend` - go_co env c2 - go_co env (CoVarCo cv) = covar env cv - go_co env (AxiomInstCo _ _ args) = go_cos env args - go_co env (HoleCo hole) = cohole env hole - go_co env (UnivCo p _ t1 t2) = go_prov env p `mappend` go_ty env t1 - `mappend` go_ty env t2 - go_co env (SymCo co) = go_co env co - go_co env (TransCo c1 c2) = go_co env c1 `mappend` go_co env c2 - go_co env (AxiomRuleCo _ cos) = go_cos env cos - go_co env (NthCo _ _ co) = go_co env co - go_co env (LRCo _ co) = go_co env co - go_co env (InstCo co arg) = go_co env co `mappend` go_co env arg - go_co env (KindCo co) = go_co env co - go_co env (SubCo co) = go_co env co - go_co env (ForAllCo tv kind_co co) - = go_co env kind_co `mappend` go_ty env (varType tv) - `mappend` go_co env' co - where - env' = tycobinder env tv Inferred - - go_prov env (ZapCoProv cvs) = go_cvs env (dVarSetElems cvs) - go_prov env (PhantomProv co) = go_co env co - go_prov env (ProofIrrelProv co) = go_co env co - go_prov _ (PluginProv _) = mempty - - go_cvs _ [] = mempty - go_cvs env (cv:cvs) = covar env cv `mappend` go_cvs env cvs + go_tys [] = mempty + go_tys (t:ts) = go_ty t `mappend` go_tys ts + + go_cos [] = mempty + go_cos (c:cs) = go_co c `mappend` go_cos cs + + go_co (Refl ty) = go_ty ty + go_co (GRefl _ ty MRefl) = go_ty ty + go_co (GRefl _ ty (MCo co)) = go_ty ty `mappend` go_co co + go_co (TyConAppCo _ _ args) = go_cos args + go_co (AppCo c1 c2) = go_co c1 `mappend` go_co c2 + go_co (FunCo _ cw c1 c2) = go_co cw `mappend` + go_co c1 `mappend` + go_co c2 + go_co (CoVarCo cv) = covar cv + go_co (AxiomInstCo _ _ args) = go_cos args + go_co (HoleCo hole) = cohole hole + go_co (UnivCo p _ t1 t2) = go_prov p `mappend` go_ty t1 + `mappend` go_ty t2 + go_co (SymCo co) = go_co co + go_co (TransCo c1 c2) = go_co c1 `mappend` go_co c2 + go_co (AxiomRuleCo _ cos) = go_cos cos + go_co (NthCo _ _ co) = go_co co + go_co (LRCo _ co) = go_co co + go_co (InstCo co arg) = go_co co `mappend` go_co arg + go_co (KindCo co) = go_co co + go_co (SubCo co) = go_co co + go_co (ForAllCo tv kind_co co) + = go_co kind_co `mappend` go_ty (varType tv) + `mappend` tycobinder tv Inferred (go_co co) + + go_prov (ZapCoProv cvs) = go_cvs (dVarSetElems cvs) + go_prov (PhantomProv co) = go_co co + go_prov (ProofIrrelProv co) = go_co co + go_prov (PluginProv _) = mempty + + go_cvs [] = mempty + go_cvs (cv:cvs) = covar cv `mappend` go_cvs cvs {- ********************************************************************* * * ===================================== compiler/GHC/Core/Unify.hs ===================================== @@ -1316,6 +1316,7 @@ newtype UM a pattern UM :: (UMState -> UnifyResultM (UMState, a)) -> UM a -- See Note [The one-shot state monad trick] +{-# COMPLETE UM #-} pattern UM m <- UM' m where UM m = UM' (oneShot m) ===================================== compiler/GHC/Tc/Utils/TcType.hs ===================================== @@ -937,11 +937,11 @@ exactTyCoVarsOfTypes :: [Type] -> TyCoVarSet exactTyCoVarsOfType = runTyCoVars exact_ty exactTyCoVarsOfTypes = runTyCoVars exact_tys -exact_ty :: TyCoFvFun Type TyCoVarSet -exact_tys :: TyCoFvFun [Type] TyCoVarSet +exact_ty :: Type -> TyCoAcc TyCoVarSet +exact_tys :: [Type] -> TyCoAcc TyCoVarSet (exact_ty, exact_tys, _, _) = foldTyCo exactTcvFolder -exactTcvFolder :: TyCoFolder TyCoVarSet (Endo TyCoVarSet) +exactTcvFolder :: TyCoFolder (TyCoAcc TyCoVarSet) exactTcvFolder = deepTcvFolder { tcf_view = tcView } -- This is the key line ===================================== compiler/GHC/Tc/Utils/Zonk.hs ===================================== @@ -4,7 +4,7 @@ -} -{-# LANGUAGE CPP, TupleSections #-} +{-# LANGUAGE CPP, TupleSections, PatternSynonyms #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ViewPatterns #-} @@ -94,6 +94,7 @@ import Control.Monad import Data.Semigroup as Semigroup import Data.List ( partition ) import Control.Arrow ( second ) +import GHC.Exts ( oneShot ) {- ************************************************************************ @@ -1920,54 +1921,63 @@ zapCoercion ze co = do { t1 <- zonkTcTypeToTypeX ze t1 coVarsOfCoM :: TcCoercion -> TcM DCoVarSet -- Find the free CoVars of an un-zonked TcCoercion -- but without -- zonking it and returning a perhaps large new coercion -coVarsOfCoM co = runEndoM (co_vars_of_co FVs.emptyInScope co) emptyDVarSet +coVarsOfCoM co = runTCAM (co_vars_of_co co) FVs.emptyInScope emptyDVarSet -co_vars_of_co :: FVs.InScopeBndrs -> TcCoercion -> EndoM TcM DCoVarSet -co_vars_of_ty :: FVs.InScopeBndrs -> TcType -> EndoM TcM DCoVarSet +co_vars_of_co :: TcCoercion -> TyCoAccM TcM DCoVarSet +co_vars_of_ty :: TcType -> TyCoAccM TcM DCoVarSet (co_vars_of_ty, _, co_vars_of_co, _) = foldTyCo co_vars_folder -co_vars_folder :: TyCoFolder FVs.InScopeBndrs (EndoM TcM DCoVarSet) +co_vars_folder :: TyCoFolder (TyCoAccM TcM DCoVarSet) co_vars_folder = TyCoFolder { tcf_view = noView , tcf_tyvar = do_tyvar, tcf_covar = do_covar , tcf_hole = do_hole, tcf_tycobinder = do_bndr } where - do_tyvar _ _ = mempty - do_covar is v = EndoM do_it + do_tyvar _ = mempty + do_covar v = TCAM do_it where - do_it :: DCoVarSet -> TcM DCoVarSet - do_it acc | v `elemVarSet` is = return acc - | v `elemDVarSet` acc = return acc - | otherwise = runEndoM (co_vars_of_ty is (varType v)) $ - acc `extendDVarSet` v - do_bndr is tcv _ = extendVarSet is tcv - - do_hole :: FVs.InScopeBndrs -> CoercionHole -> EndoM TcM DCoVarSet - do_hole is hole@(CoercionHole { ch_ref = ref }) - = EndoM $ \ acc -> + do_it :: InScopeBndrs -> DCoVarSet -> TcM DCoVarSet + do_it is acc | v `elemVarSet` is = return acc + | v `elemDVarSet` acc = return acc + | otherwise = runTCAM (co_vars_of_ty (varType v)) emptyInScope $ + acc `extendDVarSet` v + do_bndr tcv _vis fvs = extendInScopeM tcv fvs + + do_hole :: CoercionHole -> TyCoAccM TcM DCoVarSet + do_hole hole@(CoercionHole { ch_ref = ref }) + = TCAM $ \ is acc -> do { contents <- readTcRef ref ; case contents of - Just co -> runEndoM (co_vars_of_co is co) acc + Just co -> runTCAM (co_vars_of_co co) is acc Nothing -> do { traceTc "Zonking unfilled coercion hole (zap)" (ppr hole) ; return acc } } -------------------------------------- --- EndoM is copied from package 'foldl', but I don't want --- to add a new dependency to GHC for 6 lines of code -newtype EndoM m a = EndoM { runEndoM :: a -> m a } +-- Based on EndoM in package 'foldl', but with added InScopeBndrs +-- c.f. TyCoAcc in GHC.Core.TyCo.FVs +newtype TyCoAccM m acc = TCAM' { runTCAM :: FVs.InScopeBndrs -> acc -> m acc } -instance Monad m => Semigroup (EndoM m a) where - (EndoM f) <> (EndoM g) = EndoM (f <=< g) +pattern TCAM :: forall m acc. (InScopeBndrs -> acc -> m acc) -> TyCoAccM m acc +{-# COMPLETE TCAM #-} +pattern TCAM f <- TCAM' f + where + TCAM f = TCAM' (oneShot f) + +extendInScopeM :: TyCoVar -> TyCoAccM m acc -> TyCoAccM m acc +-- Gather the argument free vars in an empty in-scope set +extendInScopeM tcv (TCAM f) = TCAM (\is acc -> f (is `extendVarSet` tcv) acc) + +instance Monad m => Semigroup (TyCoAccM m a) where + (TCAM f) <> (TCAM g) = TCAM (\is acc -> do { acc <- f is acc + ; g is acc }) {-# INLINE (<>) #-} -instance Monad m => Monoid (EndoM m a) where - mempty = EndoM return +instance Monad m => Monoid (TyCoAccM m a) where + mempty = TCAM (\_ acc -> return acc) {-# INLINE mempty #-} mappend = (Semigroup.<>) {-# INLINE mappend #-} --- End of copy --------------------------------------- - +-------------------------------------- zonkTcTypeToTypeX :: ZonkEnv -> TcType -> TcM Type zonkTcTypesToTypesX :: ZonkEnv -> [TcType] -> TcM [Type] zonkCoToCo :: ZonkEnv -> Coercion -> TcM Coercion View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/16ef62d4e72205a79fcdf33726f920e27ed490e2 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/16ef62d4e72205a79fcdf33726f920e27ed490e2 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 19:17:34 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 04 Aug 2020 15:17:34 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18527 Message-ID: <5f29b44e644e_80b3f8468e02b54648641b@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T18527 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18527 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 19:35:05 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Tue, 04 Aug 2020 15:35:05 -0400 Subject: [Git][ghc/ghc][wip/t18522-b] Fix visible forall in ppr_ty (#18522) Message-ID: <5f29b869d3ed7_80b3f848705b1446489394@gitlab.haskell.org.mail> Vladislav Zavialov pushed to branch wip/t18522-b at Glasgow Haskell Compiler / GHC Commits: fdd1d02b by Vladislav Zavialov at 2020-08-04T22:34:42+03:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - 4 changed files: - compiler/GHC/Iface/Type.hs - + testsuite/tests/polykinds/T18522-ppr.script - + testsuite/tests/polykinds/T18522-ppr.stdout - testsuite/tests/polykinds/all.T Changes: ===================================== compiler/GHC/Iface/Type.hs ===================================== @@ -441,6 +441,7 @@ splitIfaceSigmaTy ty (theta, tau) = split_rho rho split_foralls (IfaceForAllTy bndr ty) + | isInvisibleArgFlag (binderArgFlag bndr) = case split_foralls ty of { (bndrs, rho) -> (bndr:bndrs, rho) } split_foralls rho = ([], rho) @@ -448,6 +449,12 @@ splitIfaceSigmaTy ty = case split_rho ty2 of { (ps, tau) -> (ty1:ps, tau) } split_rho tau = ([], tau) +splitIfaceReqForallTy :: IfaceType -> ([IfaceForAllBndr], IfaceType) +splitIfaceReqForallTy (IfaceForAllTy bndr ty) + | isVisibleArgFlag (binderArgFlag bndr) + = case splitIfaceReqForallTy ty of { (bndrs, rho) -> (bndr:bndrs, rho) } +splitIfaceReqForallTy rho = ([], rho) + suppressIfaceInvisibles :: PrintExplicitKinds -> [IfaceTyConBinder] -> [a] -> [a] suppressIfaceInvisibles (PrintExplicitKinds True) _tys xs = xs suppressIfaceInvisibles (PrintExplicitKinds False) tys xs = suppress tys xs @@ -1184,8 +1191,23 @@ pprIfaceSigmaType show_forall ty = hideNonStandardTypes ppr_fn ty where ppr_fn iface_ty = - let (tvs, theta, tau) = splitIfaceSigmaTy iface_ty - in ppr_iface_forall_part show_forall tvs theta (ppr tau) + let (invis_tvs, theta, tau) = splitIfaceSigmaTy iface_ty + (req_tvs, tau') = splitIfaceReqForallTy tau + -- splitIfaceSigmaTy is recursive, so it will gather the binders after + -- the theta, i.e. forall a. theta => forall b. tau + -- will give you ([a,b], theta, tau). + -- + -- This isn't right when it comes to visible forall (see + -- testsuite/tests/polykinds/T18522-ppr), + -- so we split off required binders separately, + -- using splitIfaceReqForallTy. + -- + -- An alternative solution would be to make splitIfaceSigmaTy + -- non-recursive (see #18458). + -- Then it could handle both invisible and required binders, and + -- splitIfaceReqForallTy wouldn't be necessary here. + in ppr_iface_forall_part show_forall invis_tvs theta $ + sep [pprIfaceForAll req_tvs, ppr tau'] pprUserIfaceForAll :: [IfaceForAllBndr] -> SDoc pprUserIfaceForAll tvs ===================================== testsuite/tests/polykinds/T18522-ppr.script ===================================== @@ -0,0 +1,4 @@ +:set -XPolyKinds -XDataKinds -XRankNTypes -XTypeFamilies +import Data.Kind (Type) +type family T :: forall k -> (k ~ k) => forall j -> k -> j -> Type +:k T ===================================== testsuite/tests/polykinds/T18522-ppr.stdout ===================================== @@ -0,0 +1 @@ +T :: forall k -> (k ~ k) => forall j -> k -> j -> * ===================================== testsuite/tests/polykinds/all.T ===================================== @@ -223,3 +223,4 @@ test('T18300', normal, compile_fail, ['']) test('T18451', normal, compile_fail, ['']) test('T18451a', normal, compile_fail, ['']) test('T18451b', normal, compile_fail, ['']) +test('T18522-ppr', normal, ghci_script, ['T18522-ppr.script']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fdd1d02bf3a5a2a2e80b9717957883d561a5bdd9 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fdd1d02bf3a5a2a2e80b9717957883d561a5bdd9 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 19:35:17 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 04 Aug 2020 15:35:17 -0400 Subject: [Git][ghc/ghc][wip/T18527] CmmLint: Check foreign call argument register invariant Message-ID: <5f29b87577d29_80b3f848c1e06f4648976e@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18527 at Glasgow Haskell Compiler / GHC Commits: d04d0eaf by Ben Gamari at 2020-08-04T15:35:12-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 1 changed file: - compiler/GHC/Cmm/Lint.hs Changes: ===================================== compiler/GHC/Cmm/Lint.hs ===================================== @@ -6,6 +6,7 @@ -- ----------------------------------------------------------------------------- {-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} module GHC.Cmm.Lint ( cmmLint, cmmLintGraph @@ -14,6 +15,7 @@ module GHC.Cmm.Lint ( import GHC.Prelude import GHC.Platform +import GHC.Platform.Regs (callerSaves) import GHC.Cmm.Dataflow.Block import GHC.Cmm.Dataflow.Collections import GHC.Cmm.Dataflow.Graph @@ -26,7 +28,7 @@ import GHC.Cmm.Ppr () -- For Outputable instances import GHC.Utils.Outputable import GHC.Driver.Session -import Control.Monad (ap) +import Control.Monad (ap, unless) -- Things to check: -- - invariant on CmmBlock in GHC.Cmm.Expr (see comment there) @@ -160,7 +162,14 @@ lintCmmMiddle node = case node of CmmUnsafeForeignCall target _formals actuals -> do lintTarget target - mapM_ lintCmmExpr actuals + let lintArg expr = do + -- Arguments can't mention caller-saved + -- registers. See See Note [Register + -- parameter passing]. + mayNotMentionCallerSavedRegs (text "foreign call argument") expr + lintCmmExpr expr + + mapM_ lintArg actuals lintCmmLast :: LabelSet -> CmmNode O C -> CmmLint () @@ -188,18 +197,37 @@ lintCmmLast labels node = case node of CmmForeignCall tgt _ args succ _ _ _ -> do lintTarget tgt - mapM_ lintCmmExpr args + let lintArg expr = do + -- Arguments can't mention caller-saved + -- registers. See See Note [Register + -- parameter passing]. + mayNotMentionCallerSavedRegs (text "foreign call argument") expr + lintCmmExpr expr + mapM_ lintArg args checkTarget succ where checkTarget id | setMember id labels = return () | otherwise = cmmLintErr (text "Branch to nonexistent id" <+> ppr id) - lintTarget :: ForeignTarget -> CmmLint () -lintTarget (ForeignTarget e _) = lintCmmExpr e >> return () +lintTarget (ForeignTarget e _) = do + mayNotMentionCallerSavedRegs (text "foreign target") e + _ <- lintCmmExpr e + return () lintTarget (PrimTarget {}) = return () +-- | As noted in Note [Register parameter passing], the arguments and +-- 'ForeignTarget' of a foreign call mustn't mention +-- caller-saved registers. +mayNotMentionCallerSavedRegs :: (UserOfRegs GlobalReg a, Outputable a) + => SDoc -> a -> CmmLint () +mayNotMentionCallerSavedRegs what thing = do + dflags <- getDynFlags + let badRegs = filter (callerSaves (targetPlatform dflags)) + $ foldRegsUsed dflags (flip (:)) [] thing + unless (null badRegs) + $ cmmLintErr (what <+> text "mentions caller-saved registers: " <> ppr badRegs $$ ppr thing) checkCond :: Platform -> CmmExpr -> CmmLint () checkCond _ (CmmMachOp mop _) | isComparisonMachOp mop = return () View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d04d0eafefa6ace6d5addd20a344cb731eec0903 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d04d0eafefa6ace6d5addd20a344cb731eec0903 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 21:24:41 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Tue, 04 Aug 2020 17:24:41 -0400 Subject: [Git][ghc/ghc][wip/disamb-td] 7 commits: Refactor CLabel pretty-printing Message-ID: <5f29d2199a044_80b3f848a372f8c650135a@gitlab.haskell.org.mail> Vladislav Zavialov pushed to branch wip/disamb-td at Glasgow Haskell Compiler / GHC Commits: 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - c2159000 by Vladislav Zavialov at 2020-08-04T23:10:59+03:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - f5ab0e11 by Vladislav Zavialov at 2020-08-05T00:22:36+03:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, we have a bit of refactoring in addition to documentation update. - - - - - 30 changed files: - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/Dwarf/Types.hs - compiler/GHC/CmmToAsm/PIC.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore.hs - compiler/GHC/HsToCore/Coverage.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Parser/PostProcess/Haddock.hs - compiler/GHC/Rename/Module.hs - compiler/GHC/StgToCmm.hs - compiler/GHC/StgToCmm/Bind.hs - compiler/GHC/StgToCmm/Closure.hs - compiler/GHC/StgToCmm/Heap.hs - compiler/GHC/StgToCmm/Layout.hs - compiler/GHC/ThToHs.hs - includes/ghc.mk - rts/Hpc.c - testsuite/tests/haddock/should_compile_flag_haddock/T17544.stderr - testsuite/tests/haddock/should_compile_flag_haddock/T17544_kw.stderr - + testsuite/tests/haddock/should_compile_flag_haddock/T17652.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/734bd8cd1328825ff0c67b1272d0062177eb8583...f5ab0e11eab91fa9262aa377fb09ed004f9a1f26 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/734bd8cd1328825ff0c67b1272d0062177eb8583...f5ab0e11eab91fa9262aa377fb09ed004f9a1f26 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 21:41:21 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Tue, 04 Aug 2020 17:41:21 -0400 Subject: [Git][ghc/ghc][wip/disamb-td] Clean up the story around runPV/runECP_P/runECP_PV Message-ID: <5f29d601b1c1d_80b3f848a372f8c65133d9@gitlab.haskell.org.mail> Vladislav Zavialov pushed to branch wip/disamb-td at Glasgow Haskell Compiler / GHC Commits: 9514e73b by Vladislav Zavialov at 2020-08-05T00:41:03+03:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 2 changed files: - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs Changes: ===================================== compiler/GHC/Parser.y ===================================== @@ -1080,7 +1080,7 @@ topdecl :: { LHsDecl GhcPs } -- The $(..) form is one possible form of infixexp -- but we treat an arbitrary expression just as if -- it had a $(..) wrapped around it - | infixexp {% runECP_P $1 >>= \ $1 -> + | infixexp {% runPV (unECP $1) >>= \ $1 -> return $ sLL $1 $> $ mkSpliceDecl $1 } -- Type classes @@ -1528,7 +1528,7 @@ decl_cls : at_decl_cls { $1 } -- A 'default' signature used with the generic-programming extension | 'default' infixexp '::' sigtype - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> do { v <- checkValSigLhs $2 ; let err = text "in default signature" <> colon <+> quotes (ppr $2) @@ -1671,8 +1671,8 @@ rules :: { OrdList (LRuleDecl GhcPs) } rule :: { LRuleDecl GhcPs } : STRING rule_activation rule_foralls infixexp '=' exp - {%runECP_P $4 >>= \ $4 -> - runECP_P $6 >>= \ $6 -> + {%runPV (unECP $4) >>= \ $4 -> + runPV (unECP $6) >>= \ $6 -> ams (sLL $1 $> $ HsRule { rd_ext = noExtField , rd_name = L (gl $1) (getSTRINGs $1, getSTRING $1) , rd_act = (snd $2) `orElse` AlwaysActive @@ -1800,19 +1800,19 @@ stringlist :: { Located (OrdList (Located StringLiteral)) } ----------------------------------------------------------------------------- -- Annotations annotation :: { LHsDecl GhcPs } - : '{-# ANN' name_var aexp '#-}' {% runECP_P $3 >>= \ $3 -> + : '{-# ANN' name_var aexp '#-}' {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) (ValueAnnProvenance $2) $3)) [mo $1,mc $4] } - | '{-# ANN' 'type' tycon aexp '#-}' {% runECP_P $4 >>= \ $4 -> + | '{-# ANN' 'type' tycon aexp '#-}' {% runPV (unECP $4) >>= \ $4 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) (TypeAnnProvenance $3) $4)) [mo $1,mj AnnType $2,mc $5] } - | '{-# ANN' 'module' aexp '#-}' {% runECP_P $3 >>= \ $3 -> + | '{-# ANN' 'module' aexp '#-}' {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) ModuleAnnProvenance $3)) @@ -2315,7 +2315,7 @@ There's an awkward overlap with a type signature. Consider decl_no_th :: { LHsDecl GhcPs } : sigdecl { $1 } - | infixexp opt_sig rhs {% runECP_P $1 >>= \ $1 -> + | infixexp opt_sig rhs {% runPV (unECP $1) >>= \ $1 -> do { (ann,r) <- checkValDef $1 (snd $2) $3; let { l = comb2 $1 $> }; -- Depending upon what the pattern looks like we might get either @@ -2339,7 +2339,7 @@ decl :: { LHsDecl GhcPs } | splice_exp { sLL $1 $> $ mkSpliceDecl $1 } rhs :: { Located ([AddAnn],GRHSs GhcPs (LHsExpr GhcPs)) } - : '=' exp wherebinds {% runECP_P $2 >>= \ $2 -> return $ + : '=' exp wherebinds {% runPV (unECP $2) >>= \ $2 -> return $ sL (comb3 $1 $2 $3) ((mj AnnEqual $1 : (fst $ unLoc $3)) ,GRHSs noExtField (unguardedRHS (comb3 $1 $2 $3) $2) @@ -2353,7 +2353,7 @@ gdrhs :: { Located [LGRHS GhcPs (LHsExpr GhcPs)] } | gdrh { sL1 $1 [$1] } gdrh :: { LGRHS GhcPs (LHsExpr GhcPs) } - : '|' guardquals '=' exp {% runECP_P $4 >>= \ $4 -> + : '|' guardquals '=' exp {% runPV (unECP $4) >>= \ $4 -> ams (sL (comb2 $1 $>) $ GRHS noExtField (unLoc $2) $4) [mj AnnVbar $1,mj AnnEqual $3] } @@ -2361,7 +2361,7 @@ sigdecl :: { LHsDecl GhcPs } : -- See Note [Declaration/signature overlap] for why we need infixexp here infixexp '::' sigtype - {% do { $1 <- runECP_P $1 + {% do { $1 <- runPV (unECP $1) ; v <- checkValSigLhs $1 ; _ <- amsL (comb2 $1 $>) [mu AnnDcolon $2] ; return (sLL $1 $> $ SigD noExtField $ @@ -2457,30 +2457,30 @@ quasiquote :: { Located (HsSplice GhcPs) } exp :: { ECP } : infixexp '::' sigtype { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> rejectPragmaPV $1 >> amms (mkHsTySigPV (comb2 $1 $>) $1 $3) [mu AnnDcolon $2] } - | infixexp '-<' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '-<' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $1 $3 HsFirstOrderApp True) [mu Annlarrowtail $2] } - | infixexp '>-' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '>-' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $3 $1 HsFirstOrderApp False) [mu Annrarrowtail $2] } - | infixexp '-<<' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '-<<' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $1 $3 HsHigherOrderApp True) [mu AnnLarrowtail $2] } - | infixexp '>>-' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '>>-' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $3 $1 HsHigherOrderApp False) @@ -2494,8 +2494,8 @@ infixexp :: { ECP } { ECP $ superInfixOp $ $2 >>= \ $2 -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> rejectPragmaPV $1 >> amms (mkHsOpAppPV (comb2 $1 $>) $1 $2 $3) [mj AnnVal $2] } @@ -2507,14 +2507,14 @@ exp10p :: { ECP } exp_prag(e) :: { ECP } : prag_e e -- See Note [Pragmas and operator fixity] - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsPragE noExtField (snd $ unLoc $1) $2) (fst $ unLoc $1) } exp10 :: { ECP } : '-' fexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsNegAppPV (comb2 $1 $>) $2) [mj AnnMinus $1] } | fexp { $1 } @@ -2597,16 +2597,16 @@ prag_e :: { Located ([AddAnn], HsPragE GhcPs) } fexp :: { ECP } : fexp aexp { ECP $ superFunArg $ - runECP_PV $1 >>= \ $1 -> - runECP_PV $2 >>= \ $2 -> + unECP $1 >>= \ $1 -> + unECP $2 >>= \ $2 -> mkHsAppPV (comb2 $1 $>) $1 $2 } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer | fexp PREFIX_AT atype { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> amms (mkHsAppTypePV (comb2 $1 $>) $1 $3) [mj AnnAt $2] } - | 'static' aexp {% runECP_P $2 >>= \ $2 -> + | 'static' aexp {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsStatic noExtField $2) [mj AnnStatic $1] } @@ -2616,23 +2616,23 @@ aexp :: { ECP } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer : qvar TIGHT_INFIX_AT aexp { ECP $ - runECP_PV $3 >>= \ $3 -> + unECP $3 >>= \ $3 -> amms (mkHsAsPatPV (comb2 $1 $>) $1 $3) [mj AnnAt $2] } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer | PREFIX_TILDE aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsLazyPatPV (comb2 $1 $>) $2) [mj AnnTilde $1] } | PREFIX_BANG aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsBangPatPV (comb2 $1 $>) $2) [mj AnnBang $1] } | PREFIX_MINUS aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsNegAppPV (comb2 $1 $>) $2) [mj AnnMinus $1] } | '\\' apat apats '->' exp { ECP $ - runECP_PV $5 >>= \ $5 -> + unECP $5 >>= \ $5 -> amms (mkHsLamPV (comb2 $1 $>) (mkMatchGroup FromSource [sLL $1 $> $ Match { m_ext = noExtField , m_ctxt = LambdaExpr @@ -2640,7 +2640,7 @@ aexp :: { ECP } , m_grhss = unguardedGRHSs $5 }])) [mj AnnLam $1, mu AnnRarrow $4] } | 'let' binds 'in' exp { ECP $ - runECP_PV $4 >>= \ $4 -> + unECP $4 >>= \ $4 -> amms (mkHsLetPV (comb2 $1 $>) (snd (unLoc $2)) $4) (mj AnnLet $1:mj AnnIn $3 :(fst $ unLoc $2)) } @@ -2650,10 +2650,10 @@ aexp :: { ECP } (mkMatchGroup FromSource (snd $ unLoc $3))) (mj AnnLam $1:mj AnnCase $2:(fst $ unLoc $3)) } | 'if' exp optSemi 'then' exp optSemi 'else' exp - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> return $ ECP $ - runECP_PV $5 >>= \ $5 -> - runECP_PV $8 >>= \ $8 -> + unECP $5 >>= \ $5 -> + unECP $8 >>= \ $8 -> amms (mkHsIfPV (comb2 $1 $>) $2 (snd $3) $5 (snd $6) $8) (mj AnnIf $1:mj AnnThen $4 :mj AnnElse $7 @@ -2664,7 +2664,7 @@ aexp :: { ECP } ams (sLL $1 $> $ HsMultiIf noExtField (reverse $ snd $ unLoc $2)) (mj AnnIf $1:(fst $ unLoc $2)) } - | 'case' exp 'of' altslist {% runECP_P $2 >>= \ $2 -> + | 'case' exp 'of' altslist {% runPV (unECP $2) >>= \ $2 -> return $ ECP $ $4 >>= \ $4 -> amms (mkHsCasePV (comb3 $1 $3 $4) $2 (mkMatchGroup @@ -2688,8 +2688,8 @@ aexp :: { ECP } (snd $ unLoc $2))) (mj AnnMdo $1:(fst $ unLoc $2)) } | 'proc' aexp '->' exp - {% (checkPattern <=< runECP_P) $2 >>= \ p -> - runECP_P $4 >>= \ $4 at cmd -> + {% (checkPattern <=< runPV) (unECP $2) >>= \ p -> + runPV (unECP $4) >>= \ $4 at cmd -> fmap ecpFromExp $ ams (sLL $1 $> $ HsProc noExtField p (sLL $1 $> $ HsCmdTop noExtField cmd)) -- TODO: is LL right here? @@ -2699,7 +2699,7 @@ aexp :: { ECP } aexp1 :: { ECP } : aexp1 '{' fbinds '}' { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> $3 >>= \ $3 -> amms (mkHsRecordPV (comb2 $1 $>) (comb2 $2 $4) $1 (snd $3)) (moc $2:mcc $4:(fst $3)) } @@ -2723,7 +2723,7 @@ aexp2 :: { ECP } -- correct Haskell (you'd have to write '((+ 3), (4 -))') -- but the less cluttered version fell out of having texps. | '(' texp ')' { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsParPV (comb2 $1 $>) $2) [mop $1,mcp $3] } | '(' tup_exprs ')' { ECP $ $2 >>= \ $2 -> @@ -2731,7 +2731,7 @@ aexp2 :: { ECP } ((mop $1:fst $2) ++ [mcp $3]) } | '(#' texp '#)' { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkSumOrTuplePV (comb2 $1 $>) Unboxed (Tuple [L (gl $2) (Just $2)])) [mo $1,mc $3] } | '(#' tup_exprs '#)' { ECP $ @@ -2751,18 +2751,18 @@ aexp2 :: { ECP } | TH_TY_QUOTE tyvar {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } | TH_TY_QUOTE gtycon {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } | TH_TY_QUOTE {- nothing -} {% reportEmptyDoubleQuotes (getLoc $1) } - | '[|' exp '|]' {% runECP_P $2 >>= \ $2 -> + | '[|' exp '|]' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (ExpBr noExtField $2)) (if (hasE $1) then [mj AnnOpenE $1, mu AnnCloseQ $3] else [mu AnnOpenEQ $1,mu AnnCloseQ $3]) } - | '[||' exp '||]' {% runECP_P $2 >>= \ $2 -> + | '[||' exp '||]' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (TExpBr noExtField $2)) (if (hasE $1) then [mj AnnOpenE $1,mc $3] else [mo $1,mc $3]) } | '[t|' ktype '|]' {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (TypBr noExtField $2)) [mo $1,mu AnnCloseQ $3] } - | '[p|' infixexp '|]' {% (checkPattern <=< runECP_P) $2 >>= \p -> + | '[p|' infixexp '|]' {% (checkPattern <=< runPV) (unECP $2) >>= \p -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (PatBr noExtField p)) [mo $1,mu AnnCloseQ $3] } @@ -2772,7 +2772,7 @@ aexp2 :: { ECP } | quasiquote { ECP $ mkHsSplicePV $1 } -- arrow notation extension - | '(|' aexp cmdargs '|)' {% runECP_P $2 >>= \ $2 -> + | '(|' aexp cmdargs '|)' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrForm noExtField $2 Prefix Nothing (reverse $3)) @@ -2784,14 +2784,14 @@ splice_exp :: { LHsExpr GhcPs } splice_untyped :: { Located (HsSplice GhcPs) } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer - : PREFIX_DOLLAR aexp2 {% runECP_P $2 >>= \ $2 -> + : PREFIX_DOLLAR aexp2 {% runPV (unECP $2) >>= \ $2 -> ams (sLL $1 $> $ mkUntypedSplice DollarSplice $2) [mj AnnDollar $1] } splice_typed :: { Located (HsSplice GhcPs) } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer : PREFIX_DOLLAR_DOLLAR aexp2 - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> ams (sLL $1 $> $ mkTypedSplice DollarSplice $2) [mj AnnDollarDollar $1] } @@ -2800,7 +2800,7 @@ cmdargs :: { [LHsCmdTop GhcPs] } | {- empty -} { [] } acmd :: { LHsCmdTop GhcPs } - : aexp {% runECP_P $1 >>= \ cmd -> + : aexp {% runPV (unECP $1) >>= \ cmd -> runPV (checkCmdBlockArguments cmd) >>= \ _ -> return (sL1 cmd $ HsCmdTop noExtField cmd) } @@ -2834,21 +2834,21 @@ texp :: { ECP } -- Meanwhile, the renamer checks that real sections appear -- inside parens. | infixexp qop - {% runECP_P $1 >>= \ $1 -> + {% runPV (unECP $1) >>= \ $1 -> runPV (rejectPragmaPV $1) >> runPV $2 >>= \ $2 -> return $ ecpFromExp $ sLL $1 $> $ SectionL noExtField $1 $2 } | qopm infixexp { ECP $ superInfixOp $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> $1 >>= \ $1 -> mkHsSectionR_PV (comb2 $1 $>) $1 $2 } -- View patterns get parenthesized above | exp '->' texp { ECP $ - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> amms (mkHsViewPatPV (comb2 $1 $>) $1 $3) [mu AnnRarrow $2] } -- Always at least one comma or bar. @@ -2857,12 +2857,12 @@ texp :: { ECP } -- in GHC.Hs.Expr. tup_exprs :: { forall b. DisambECP b => PV ([AddAnn],SumOrTuple b) } : texp commas_tup_tail - { runECP_PV $1 >>= \ $1 -> + { unECP $1 >>= \ $1 -> $2 >>= \ $2 -> do { addAnnotation (gl $1) AnnComma (fst $2) ; return ([],Tuple ((sL1 $1 (Just $1)) : snd $2)) } } - | texp bars { runECP_PV $1 >>= \ $1 -> return $ + | texp bars { unECP $1 >>= \ $1 -> return $ (mvbars (fst $2), Sum 1 (snd $2 + 1) $1) } | commas tup_tail @@ -2872,7 +2872,7 @@ tup_exprs :: { forall b. DisambECP b => PV ([AddAnn],SumOrTuple b) } ([],Tuple (map (\l -> L l Nothing) (fst $1) ++ $2)) } } | bars texp bars0 - { runECP_PV $2 >>= \ $2 -> return $ + { unECP $2 >>= \ $2 -> return $ (mvbars (fst $1) ++ mvbars (fst $3), Sum (snd $1 + 1) (snd $1 + snd $3 + 1) $2) } -- Always starts with commas; always follows an expr @@ -2886,11 +2886,11 @@ commas_tup_tail : commas tup_tail -- Always follows a comma tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] } - : texp commas_tup_tail { runECP_PV $1 >>= \ $1 -> + : texp commas_tup_tail { unECP $1 >>= \ $1 -> $2 >>= \ $2 -> addAnnotation (gl $1) AnnComma (fst $2) >> return ((L (gl $1) (Just $1)) : snd $2) } - | texp { runECP_PV $1 >>= \ $1 -> + | texp { unECP $1 >>= \ $1 -> return [L (gl $1) (Just $1)] } | {- empty -} { return [noLoc Nothing] } @@ -2901,48 +2901,48 @@ tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] } -- avoiding another shift/reduce-conflict. -- Never empty. list :: { forall b. DisambECP b => SrcSpan -> PV (Located b) } - : texp { \loc -> runECP_PV $1 >>= \ $1 -> + : texp { \loc -> unECP $1 >>= \ $1 -> mkHsExplicitListPV loc [$1] } | lexps { \loc -> $1 >>= \ $1 -> mkHsExplicitListPV loc (reverse $1) } - | texp '..' { \loc -> runECP_PV $1 >>= \ $1 -> + | texp '..' { \loc -> unECP $1 >>= \ $1 -> ams (L loc $ ArithSeq noExtField Nothing (From $1)) [mj AnnDotdot $2] >>= ecpFromExp' } | texp ',' exp '..' { \loc -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> ams (L loc $ ArithSeq noExtField Nothing (FromThen $1 $3)) [mj AnnComma $2,mj AnnDotdot $4] >>= ecpFromExp' } - | texp '..' exp { \loc -> runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + | texp '..' exp { \loc -> unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> ams (L loc $ ArithSeq noExtField Nothing (FromTo $1 $3)) [mj AnnDotdot $2] >>= ecpFromExp' } | texp ',' exp '..' exp { \loc -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> - runECP_PV $5 >>= \ $5 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> + unECP $5 >>= \ $5 -> ams (L loc $ ArithSeq noExtField Nothing (FromThenTo $1 $3 $5)) [mj AnnComma $2,mj AnnDotdot $4] >>= ecpFromExp' } | texp '|' flattenedpquals { \loc -> checkMonadComp >>= \ ctxt -> - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> ams (L loc $ mkHsComp ctxt (unLoc $3) $1) [mj AnnVbar $2] >>= ecpFromExp' } lexps :: { forall b. DisambECP b => PV [Located b] } : lexps ',' texp { $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $3 >>= \ $3 -> addAnnotation (gl $ head $ $1) AnnComma (gl $2) >> return (((:) $! $3) $! $1) } - | texp ',' texp { runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + | texp ',' texp { unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> addAnnotation (gl $1) AnnComma (gl $2) >> return [$3,$1] } @@ -2992,20 +2992,20 @@ squals :: { Located [LStmt GhcPs (LHsExpr GhcPs)] } -- In reverse order, becau transformqual :: { Located ([AddAnn],[LStmt GhcPs (LHsExpr GhcPs)] -> Stmt GhcPs (LHsExpr GhcPs)) } -- Function is applied to a list of stmts *in order* - : 'then' exp {% runECP_P $2 >>= \ $2 -> return $ + : 'then' exp {% runPV (unECP $2) >>= \ $2 -> return $ sLL $1 $> ([mj AnnThen $1], \ss -> (mkTransformStmt ss $2)) } - | 'then' exp 'by' exp {% runECP_P $2 >>= \ $2 -> - runECP_P $4 >>= \ $4 -> + | 'then' exp 'by' exp {% runPV (unECP $2) >>= \ $2 -> + runPV (unECP $4) >>= \ $4 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnBy $3], \ss -> (mkTransformByStmt ss $2 $4)) } | 'then' 'group' 'using' exp - {% runECP_P $4 >>= \ $4 -> + {% runPV (unECP $4) >>= \ $4 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnUsing $3], \ss -> (mkGroupUsingStmt ss $4)) } | 'then' 'group' 'by' exp 'using' exp - {% runECP_P $4 >>= \ $4 -> - runECP_P $6 >>= \ $6 -> + {% runPV (unECP $4) >>= \ $4 -> + runPV (unECP $6) >>= \ $6 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnBy $3,mj AnnUsing $5], \ss -> (mkGroupByUsingStmt ss $4 $6)) } @@ -3079,7 +3079,7 @@ alt_rhs :: { forall b. DisambECP b => PV (Located ([AddAnn],GRHSs GhcPs (Located return $ sLL alt $> (fst $ unLoc $2, GRHSs noExtField (unLoc alt) (snd $ unLoc $2)) } ralt :: { forall b. DisambECP b => PV (Located [LGRHS GhcPs (Located b)]) } - : '->' exp { runECP_PV $2 >>= \ $2 -> + : '->' exp { unECP $2 >>= \ $2 -> ams (sLL $1 $> (unguardedRHS (comb2 $1 $2) $2)) [mu AnnRarrow $1] } | gdpats { $1 >>= \gdpats -> @@ -3102,7 +3102,7 @@ ifgdpats :: { Located ([AddAnn],[LGRHS GhcPs (LHsExpr GhcPs)]) } gdpat :: { forall b. DisambECP b => PV (LGRHS GhcPs (Located b)) } : '|' guardquals '->' exp - { runECP_PV $4 >>= \ $4 -> + { unECP $4 >>= \ $4 -> ams (sL (comb2 $1 $>) $ GRHS noExtField (unLoc $2) $4) [mj AnnVbar $1,mu AnnRarrow $3] } @@ -3111,15 +3111,15 @@ gdpat :: { forall b. DisambECP b => PV (LGRHS GhcPs (Located b)) } -- Bangs inside are parsed as infix operator applications, so that -- we parse them right when bang-patterns are off pat :: { LPat GhcPs } -pat : exp {% (checkPattern <=< runECP_P) $1 } +pat : exp {% (checkPattern <=< runPV) (unECP $1) } bindpat :: { LPat GhcPs } -bindpat : exp {% -- See Note [Parser-Validator ReaderT SDoc] in GHC.Parser.PostProcess +bindpat : exp {% -- See Note [Parser-Validator Hint] in GHC.Parser.PostProcess checkPattern_msg (text "Possibly caused by a missing 'do'?") - (runECP_PV $1) } + (unECP $1) } apat :: { LPat GhcPs } -apat : aexp {% (checkPattern <=< runECP_P) $1 } +apat : aexp {% (checkPattern <=< runPV) (unECP $1) } apats :: { [LPat GhcPs] } : apat apats { $1 : $2 } @@ -3182,10 +3182,10 @@ stmt :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } (mj AnnRec $1:(fst $ unLoc $2)) } qual :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } - : bindpat '<-' exp { runECP_PV $3 >>= \ $3 -> + : bindpat '<-' exp { unECP $3 >>= \ $3 -> ams (sLL $1 $> $ mkPsBindStmt $1 $3) [mu AnnLarrow $2] } - | exp { runECP_PV $1 >>= \ $1 -> + | exp { unECP $1 >>= \ $1 -> return $ sL1 $1 $ mkBodyStmt $1 } | 'let' binds { ams (sLL $1 $> $ LetStmt noExtField (snd $ unLoc $2)) (mj AnnLet $1:(fst $ unLoc $2)) } @@ -3208,7 +3208,7 @@ fbinds1 :: { forall b. DisambECP b => PV ([AddAnn],([LHsRecField GhcPs (Located | '..' { return ([mj AnnDotdot $1],([], Just (getLoc $1))) } fbind :: { forall b. DisambECP b => PV (LHsRecField GhcPs (Located b)) } - : qvar '=' texp { runECP_PV $3 >>= \ $3 -> + : qvar '=' texp { unECP $3 >>= \ $3 -> ams (sLL $1 $> $ HsRecField (sL1 $1 $ mkFieldOcc $1) $3 False) [mj AnnEqual $2] } -- RHS is a 'texp', allowing view patterns (#6038) @@ -3234,7 +3234,7 @@ dbinds :: { Located [LIPBind GhcPs] } -- | {- empty -} { [] } dbind :: { LIPBind GhcPs } -dbind : ipvar '=' exp {% runECP_P $3 >>= \ $3 -> +dbind : ipvar '=' exp {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (IPBind noExtField (Left $1) $3)) [mj AnnEqual $2] } ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -95,8 +95,7 @@ module GHC.Parser.PostProcess ( -- Expression/command/pattern ambiguity resolution PV, runPV, - ECP(ECP, runECP_PV), - runECP_P, + ECP(ECP, unECP), DisambInfixOp(..), DisambECP(..), ecpFromExp, @@ -1335,7 +1334,6 @@ checkMonadComp = do -- See Note [Ambiguous syntactic categories] -- --- See Note [Parser-Validator] -- See Note [Ambiguous syntactic categories] -- -- This newtype is required to avoid impredicative types in monadic @@ -1349,10 +1347,7 @@ checkMonadComp = do -- P (forall b. DisambECP b => PV (Located b)) -- newtype ECP = - ECP { runECP_PV :: forall b. DisambECP b => PV (Located b) } - -runECP_P :: DisambECP b => ECP -> P (Located b) -runECP_P p = runPV (runECP_PV p) + ECP { unECP :: forall b. DisambECP b => PV (Located b) } ecpFromExp :: LHsExpr GhcPs -> ECP ecpFromExp a = ECP (ecpFromExp' a) @@ -1882,7 +1877,6 @@ tyToDataConBuilder t = {- Note [Ambiguous syntactic categories] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - There are places in the grammar where we do not know whether we are parsing an expression or a pattern without unlimited lookahead (which we do not have in 'happy'): @@ -1977,6 +1971,21 @@ position and shadows the previous $1. We can do this because internally is to be able to write (sLL $1 $>) later on. The alternative would be to write this as ($1 >>= \ fresh_name -> ...), but then we couldn't refer to the last fresh name as $>. + +Finally, we instantiate the polymorphic type to a concrete one, and run the +parser-validator, for example: + + stmt :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } + e_stmt :: { LStmt GhcPs (LHsExpr GhcPs) } + : stmt {% runPV $1 } + +In e_stmt, three things happen: + + 1. we instantiate: b ~ HsExpr GhcPs + 2. we embed the PV computation into P by using runPV + 3. we run validation by using a monadic production, {% ... } + +At this point the ambiguity is resolved. -} @@ -2133,7 +2142,6 @@ Alternative VII, a product type We could avoid the intermediate representation of Alternative VI by parsing into a product of interpretations directly: - -- See Note [Parser-Validator] type ExpCmdPat = ( PV (LHsExpr GhcPs) , PV (LHsCmd GhcPs) , PV (LHsPat GhcPs) ) @@ -2153,7 +2161,6 @@ We can easily define ambiguities between arbitrary subsets of interpretations. For example, when we know ahead of type that only an expression or a command is possible, but not a pattern, we can use a smaller type: - -- See Note [Parser-Validator] type ExpCmd = (PV (LHsExpr GhcPs), PV (LHsCmd GhcPs)) checkExpOf2 (e, _) = e -- interpret as an expression @@ -2663,7 +2670,25 @@ data PV_Accum = data PV_Result a = PV_Ok PV_Accum a | PV_Failed PV_Accum --- See Note [Parser-Validator] +-- During parsing, we make use of several monadic effects: reporting parse errors, +-- accumulating warnings, adding API annotations, and checking for extensions. These +-- effects are captured by the 'MonadP' type class. +-- +-- Sometimes we need to postpone some of these effects to a later stage due to +-- ambiguities described in Note [Ambiguous syntactic categories]. +-- We could use two layers of the P monad, one for each stage: +-- +-- abParser :: forall x. DisambAB x => P (P x) +-- +-- The outer layer of P consumes the input and builds the inner layer, which +-- validates the input. But this type is not particularly helpful, as it obscures +-- the fact that the inner layer of P never consumes any input. +-- +-- For clarity, we introduce the notion of a parser-validator: a parser that does +-- not consume any input, but may fail or use other effects. Thus we have: +-- +-- abParser :: forall x. DisambAB x => P (PV x) +-- newtype PV a = PV { unPV :: PV_Context -> PV_Accum -> PV_Result a } instance Functor PV where @@ -2737,36 +2762,6 @@ instance MonadP PV where PV_Ok acc' () addAnnotation _ _ _ = return () -{- Note [Parser-Validator] -~~~~~~~~~~~~~~~~~~~~~~~~~~ - -When resolving ambiguities, we need to postpone failure to make a choice later. -For example, if we have ambiguity between some A and B, our parser could be - - abParser :: P (Maybe A, Maybe B) - -This way we can represent four possible outcomes of parsing: - - (Just a, Nothing) -- definitely A - (Nothing, Just b) -- definitely B - (Just a, Just b) -- either A or B - (Nothing, Nothing) -- neither A nor B - -However, if we want to report informative parse errors, accumulate warnings, -and add API annotations, we are better off using 'P' instead of 'Maybe': - - abParser :: P (P A, P B) - -So we have an outer layer of P that consumes the input and builds the inner -layer, which validates the input. - -For clarity, we introduce the notion of a parser-validator: a parser that does -not consume any input, but may fail or use other effects. Thus we have: - - abParser :: P (PV A, PV B) - --} - {- Note [Parser-Validator Hint] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A PV computation is parametrized by a hint for error messages, which can be set View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9514e73bff4cc77e5a8505826b09cfa46f168b46 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9514e73bff4cc77e5a8505826b09cfa46f168b46 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 22:08:04 2020 From: gitlab at gitlab.haskell.org (Richard Eisenberg) Date: Tue, 04 Aug 2020 18:08:04 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18534 Message-ID: <5f29dc44e7366_80b3f8496224a70651444b@gitlab.haskell.org.mail> Richard Eisenberg pushed new branch wip/T18534 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18534 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 22:35:52 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Tue, 04 Aug 2020 18:35:52 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/az/ghc-9.0-anns Message-ID: <5f29e2c87ed35_80b3f848a386fc86521589@gitlab.haskell.org.mail> Alan Zimmerman pushed new branch wip/az/ghc-9.0-anns at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/az/ghc-9.0-anns You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 4 23:43:49 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Tue, 04 Aug 2020 19:43:49 -0400 Subject: [Git][ghc/ghc][wip/T8095-spj] 28 commits: Fix typo Message-ID: <5f29f2b54daff_80b3f849c1caa106524419@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T8095-spj at Glasgow Haskell Compiler / GHC Commits: b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 2d6d21ef by Simon Peyton Jones at 2020-08-05T00:15:27+01:00 Zap coercions (take 2) This is Simon's take on coercion zapping. The basic approach remains the same: add a UnivProv for a zapped coercion, controlled by -ddrop-coercions. Particular features: * A zapped coercion is born in one place only: in GHC.Tc.Utils.Zonk, when zonking a coercion. By that time all coercion holes are filled in, so there is no issue about looking for free holes. * Flattening and solving are unaffected. They'll allocate coercions -- but my plan (not yet brought to fruition) is that they are never traversed when we have -ddrop-coercions * There will, therefore, be no perf gain in the type checker; but the entire rest of the compiler will benefit. - - - - - b5cc9c60 by Simon Peyton Jones at 2020-08-05T00:15:27+01:00 CI adjustments This patch temporarily * Marks -ddump-coercions as undocumented (so that CI doesn't stumble) * Adds -ddump-coercions to TEST_HC so that all tests run with it on - - - - - 98365e7d by Simon Peyton Jones at 2020-08-05T00:15:27+01:00 Free-var fixes This should stop the perf regressions - - - - - 60cc37ad by Simon Peyton Jones at 2020-08-05T00:15:28+01:00 Simplify TyCoFolder This commit removes the 'env' part of TyCoFolder. A nice simplification! - - - - - c5deeade by Simon Peyton Jones at 2020-08-05T00:15:28+01:00 Tidy up and documentation Notes - - - - - 30 changed files: - aclocal.m4 - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/Dwarf/Types.hs - compiler/GHC/CmmToAsm/PIC.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/Coercion/Opt.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/FVs.hs - compiler/GHC/Core/Lint.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Utils.hs - compiler/GHC/Core/Ppr/TyThing.hs - compiler/GHC/Core/TyCo/FVs.hs - compiler/GHC/Core/TyCo/Rep.hs - compiler/GHC/Core/TyCo/Subst.hs - compiler/GHC/Core/TyCo/Tidy.hs - compiler/GHC/Core/Type.hs - compiler/GHC/Core/Unify.hs - compiler/GHC/CoreToIface.hs - compiler/GHC/Driver/Flags.hs - compiler/GHC/Driver/Make.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Instances.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/16ef62d4e72205a79fcdf33726f920e27ed490e2...c5deeadeb1f90b47beab9d91dcb5095b22581efd -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/16ef62d4e72205a79fcdf33726f920e27ed490e2...c5deeadeb1f90b47beab9d91dcb5095b22581efd You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 01:38:44 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 04 Aug 2020 21:38:44 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 7 commits: Bignum: add backward compat integer-gmp functions Message-ID: <5f2a0da4d8177_80b3f848c1e06f46547457@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: dbcdced9 by Sylvain Henry at 2020-08-04T21:38:34-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 9a183993 by Sylvain Henry at 2020-08-04T21:38:34-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 959fa60d by Krzysztof Gogolewski at 2020-08-04T21:38:40-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 4c273c1c by Ben Gamari at 2020-08-04T21:38:40-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 0c5cd878 by Ben Gamari at 2020-08-04T21:38:40-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 133c044a by Hécate at 2020-08-04T21:38:41-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - 8a4a5637 by Ryan Scott at 2020-08-04T21:38:41-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 30 changed files: - aclocal.m4 - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - compiler/ghc.cabal.in - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - libraries/base/.hlint.yaml - libraries/base/Control/Concurrent/QSemN.hs - libraries/base/Control/Exception/Base.hs - libraries/base/Data/Coerce.hs - libraries/base/Data/Complex.hs - libraries/base/Data/Data.hs - libraries/base/Data/Dynamic.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d0f579adc7ecace9300d07d52a7c5e934ef1b68c...8a4a5637ec6143494f40013c183c723c0dea3cd9 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d0f579adc7ecace9300d07d52a7c5e934ef1b68c...8a4a5637ec6143494f40013c183c723c0dea3cd9 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 02:02:19 2020 From: gitlab at gitlab.haskell.org (Richard Eisenberg) Date: Tue, 04 Aug 2020 22:02:19 -0400 Subject: [Git][ghc/ghc][wip/T18534] Fail eagerly on a lev-poly datacon arg Message-ID: <5f2a132b6d77d_80b3f849c1caa106559414@gitlab.haskell.org.mail> Richard Eisenberg pushed to branch wip/T18534 at Glasgow Haskell Compiler / GHC Commits: d9081080 by Richard Eisenberg at 2020-08-04T22:02:09-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 4 changed files: - compiler/GHC/Tc/TyCl.hs - + testsuite/tests/typecheck/should_fail/T18534.hs - + testsuite/tests/typecheck/should_fail/T18534.stderr - testsuite/tests/typecheck/should_fail/all.T Changes: ===================================== compiler/GHC/Tc/TyCl.hs ===================================== @@ -74,7 +74,6 @@ import GHC.Types.SrcLoc import GHC.Data.List.SetOps import GHC.Driver.Session import GHC.Types.Unique -import GHC.Core.ConLike( ConLike(..) ) import GHC.Types.Basic import qualified GHC.LanguageExtensions as LangExt @@ -3819,15 +3818,14 @@ checkValidTyCl tc where recovery_code -- See Note [Recover from validity error] = do { traceTc "Aborted validity for tycon" (ppr tc) - ; return (concatMap mk_fake_tc $ - ATyCon tc : implicitTyConThings tc) } + ; return (map mk_fake_tc $ + tc : child_tycons tc) } - mk_fake_tc (ATyCon tc) - | isClassTyCon tc = [tc] -- Ugh! Note [Recover from validity error] - | otherwise = [makeRecoveryTyCon tc] - mk_fake_tc (AConLike (RealDataCon dc)) - = [makeRecoveryTyCon (promoteDataCon dc)] - mk_fake_tc _ = [] + mk_fake_tc tc + | isClassTyCon tc = tc -- Ugh! Note [Recover from validity error] + | otherwise = makeRecoveryTyCon tc + + child_tycons tc = tyConATs tc ++ map promoteDataCon (tyConDataCons tc) {- Note [Recover from validity error] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -3852,6 +3850,8 @@ Some notes: and so there was an internal error when we met 'MkT' in the body of 'S'. + Similarly for associated types. + * Painfully, we *don't* want to do this for classes. Consider tcfail041: class (?x::Int) => C a where ... @@ -3864,6 +3864,14 @@ Some notes: This is really bogus; now we have in scope a Class that is invalid in some way, with unknown downstream consequences. A better alternative might be to make a fake class TyCon. A job for another day. + +* Previously, we used implicitTyConThings to snaffle out the parts + to add to the context. The problem is that this also grabs data con + wrapper Ids. These could be filtered out. But, painfully, getting + the wrapper Ids checks the DataConRep, and forcing the DataConRep + can panic if there is a levity-polymorphic argument. This is #18534. + We don't need the wrapper Ids here anyway. So the code just takes what + it needs, via child_tycons. -} ------------------------- @@ -4050,8 +4058,13 @@ checkValidDataCon dflags existential_ok tc con -- regardless of whether or not UnliftedNewtypes is enabled. A -- later check in checkNewDataCon handles this, producing a -- better error message than checkForLevPoly would. - ; unless (isNewTyCon tc) - (mapM_ (checkForLevPoly empty) (map scaledThing $ dataConOrigArgTys con)) + ; unless (isNewTyCon tc) $ + checkNoErrs $ + mapM_ (checkForLevPoly empty) (map scaledThing $ dataConOrigArgTys con) + -- the checkNoErrs is to prevent a panic in isVanillaDataCon + -- (called a a few lines down), which can fall over if there is a + -- bang on a levity-polymorphic argument. This is #18534, + -- typecheck/should_fail/T18534 -- Extra checks for newtype data constructors. Importantly, these -- checks /must/ come before the call to checkValidType below. This ===================================== testsuite/tests/typecheck/should_fail/T18534.hs ===================================== @@ -0,0 +1,7 @@ +{-# LANGUAGE PolyKinds #-} + +module Test where + +import GHC.Exts + +data Test (a :: TYPE r) = Test !a ===================================== testsuite/tests/typecheck/should_fail/T18534.stderr ===================================== @@ -0,0 +1,7 @@ + +T18534.hs:7:27: error: + • A levity-polymorphic type is not allowed here: + Type: a + Kind: TYPE r + • In the definition of data constructor ‘Test’ + In the data type declaration for ‘Test’ ===================================== testsuite/tests/typecheck/should_fail/all.T ===================================== @@ -578,3 +578,4 @@ test('T18357', normal, compile_fail, ['']) test('T18357a', normal, compile_fail, ['']) test('T18357b', normal, compile_fail, ['']) test('T18455', normal, compile_fail, ['']) +test('T18534', normal, compile_fail, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d9081080bdd4617828f46a9a789ecc637056210b -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d9081080bdd4617828f46a9a789ecc637056210b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 02:21:50 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 04 Aug 2020 22:21:50 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/unloading Message-ID: <5f2a17be22688_80b3f848a386fc865613e6@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/unloading at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/unloading You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 03:38:01 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 04 Aug 2020 23:38:01 -0400 Subject: [Git][ghc/ghc][wip/backports] Refactor handling of object merging Message-ID: <5f2a29993a9c_80b3f8468e02b5465619e3@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: e69b0d42 by Ben Gamari at 2020-08-04T23:37:46-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 22 changed files: - aclocal.m4 - compiler/main/DriverPipeline.hs - compiler/main/DynFlags.hs - compiler/main/Settings.hs - compiler/main/SysTools/Settings.hs - compiler/main/SysTools/Tasks.hs - compiler/main/ToolSettings.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + result=0 + else + AC_MSG_RESULT([affected]) + result=1 + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + fi +]) + +# FIND_MERGE_OBJECTS +# ------------------ +# Find which linker to use to merge object files. +# +AC_DEFUN([FIND_MERGE_OBJECTS],[ + AC_REQUIRE([FIND_LD]) + + if test -z "$SettingsMergeObjectsCommand"; then + SettingsMergeObjectsCommand="$LD" + fi + if test -z "$SettingsMergeObjectsFlags"; then + SettingsMergeObjectsFlags="-r" + fi + + CHECK_FOR_GOLD_T22266($SettingsMergeObjectsCommand) + if test "$result" = "1"; then + AC_MSG_NOTICE([$SettingsMergeObjectsCommand is broken due to binutils 22266, looking for another linker...]) + SettingsMergeObjectsCommand="" + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + CHECK_FOR_GOLD_T22266($SettingsMergeObjectsCommand) + if test "$result" = "1"; then + AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the SettingsMergeObjectsCommand variable to a functional linker.]) + fi + fi + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/main/DriverPipeline.hs ===================================== @@ -2119,6 +2119,23 @@ We must enable bigobj output in a few places: Unfortunately the big object format is not supported on 32-bit targets so none of this can be used in that case. + + +Note [Merging object files for GHCi] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +GHCi can usually loads standard linkable object files using GHC's linker +implementation. However, most users build their projects with -split-sections, +meaning that such object files can have an extremely high number of sections. +As the linker must map each of these sections individually, loading such object +files is very inefficient. + +To avoid this inefficiency, we use the linker's `-r` flag and a linker script +to produce a merged relocatable object file. This file will contain a singe +text section section and can consequently be mapped far more efficiently. As +gcc tends to do unpredictable things to our linker command line, we opt to +invoke ld directly in this case, in contrast to our usual strategy of linking +via gcc. + -} joinObjectFiles :: DynFlags -> [FilePath] -> FilePath -> IO () @@ -2126,34 +2143,13 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = SysTools.runLink dflags ([ - SysTools.Option "-nostdlib", - SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in DynFlags - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args = SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" - | OSMinGW32 == osInfo - , not $ target32Bit (targetPlatform dflags) - ] + concat + [ [SysTools.Option "--oformat", SysTools.Option "pe-bigobj-x86-64"] + | OSMinGW32 == osInfo + , not $ target32Bit (targetPlatform dflags) + ] ++ map SysTools.Option ld_build_id ++ [ SysTools.Option "-o", SysTools.FileOption "" output_fn ] @@ -2162,25 +2158,24 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] - ccInfo <- getCompilerInfo dflags if ldIsGnuLd then do script <- newTempName dflags TFL_CurrentModule "ldscript" cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [SysTools.FileOption "" script] ccInfo + ld_r [SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files - ld_r [SysTools.Option "-Wl,-filelist", - SysTools.FileOption "-Wl," filelist] ccInfo + ld_r [SysTools.Option "-filelist", + SysTools.FileOption "" filelist] else do - ld_r (map (SysTools.FileOption "") o_files) ccInfo + ld_r (map (SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/main/DynFlags.hs ===================================== @@ -106,6 +106,7 @@ module DynFlags ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -124,6 +125,7 @@ module DynFlags ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -152,10 +154,10 @@ module DynFlags ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, systemPackageConfig, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, tablesNextToCode, @@ -1447,6 +1449,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -1493,6 +1497,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/main/Settings.hs ===================================== @@ -19,6 +19,7 @@ module Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -37,6 +38,7 @@ module Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -125,6 +127,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -161,6 +165,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/main/SysTools/Settings.hs ===================================== @@ -141,6 +141,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -202,6 +204,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -220,6 +223,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/main/SysTools/Tasks.hs ===================================== @@ -1,4 +1,5 @@ {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- -- Tasks running external programs for SysTools @@ -299,6 +300,20 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +-- See Note [Merging object files for GHCi] in GHC.Driver.Pipeline. +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + -- N.B. Darwin's ld64 doesn't support response files. Consequently we only + -- use them on Windows where they are truly necessary. +#if defined(mingw32_HOST_OS) + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env +#else + runSomething dflags "Merge objects" p args2 +#endif runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== compiler/main/ToolSettings.hs ===================================== @@ -25,6 +25,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -50,6 +51,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] ===================================== configure.ac ===================================== @@ -577,13 +577,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -102,6 +102,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -114,6 +114,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -137,6 +143,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -97,6 +97,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -125,9 +125,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -312,6 +313,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -90,6 +90,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -108,6 +109,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -175,6 +178,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -190,6 +194,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -288,6 +288,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -91,6 +91,7 @@ buildDynamicLibUnix root suffix dynlibpath = do -- | Build a "GHCi library" ('LibGhci') under the given build root, with the -- complete path of the file to build is given as the second argument. +-- See Note [Merging object files for GHCi] in GHC.Driver.Pipeline. buildGhciLibO :: FilePath -> FilePath -> Action () buildGhciLibO root ghcilibPath = do l@(BuildPath _ stage _ (LibGhci _ _ _)) @@ -100,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -38,6 +38,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -246,6 +247,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -222,6 +222,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -512,6 +512,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -745,7 +747,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e69b0d42d88794837694429d33667c2f20931820 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e69b0d42d88794837694429d33667c2f20931820 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 07:58:56 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 05 Aug 2020 03:58:56 -0400 Subject: [Git][ghc/ghc][master] 2 commits: hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. Message-ID: <5f2a66c06f6d4_80b3f8496224a706580395@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - 3 changed files: - compiler/GHC/Driver/CodeOutput.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Settings/Builders/Cabal.hs Changes: ===================================== compiler/GHC/Driver/CodeOutput.hs ===================================== @@ -125,27 +125,10 @@ outputC :: DynFlags outputC dflags filenm cmm_stream packages = do withTiming dflags (text "C codegen") (\a -> seq a () {- FIXME -}) $ do - - -- figure out which header files to #include in the generated .hc file: - -- - -- * extra_includes from packages - -- * -#include options from the cmdline and OPTIONS pragmas - -- * the _stub.h file, if there is one. - -- - let rts = unsafeLookupUnitId (unitState dflags) rtsUnitId - - let cc_injects = unlines (map mk_include (unitIncludes rts)) - mk_include h_file = - case h_file of - '"':_{-"-} -> "#include "++h_file - '<':_ -> "#include "++h_file - _ -> "#include \""++h_file++"\"" - let pkg_names = map unitIdString packages - doOutput filenm $ \ h -> do hPutStr h ("/* GHC_PACKAGES " ++ unwords pkg_names ++ "\n*/\n") - hPutStr h cc_injects + hPutStr h "#include \"Stg.h\"\n" let platform = targetPlatform dflags writeC = printForC dflags h . cmmToC platform Stream.consume cmm_stream writeC ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -218,7 +218,11 @@ ghcWrapper stage = do ghcPath <- expr $ () <$> topDirectory <*> programPath (vanillaContext (pred stage) ghc) return $ unwords $ map show $ [ ghcPath ] - ++ [ "-package-db " ++ dbPath | stage == Stage1 ] + ++ (if stage == Stage1 + then ["-no-global-package-db" + , "-package-db " ++ dbPath + ] + else []) ++ [ "$@" ] -- | Given a 'String' replace characters '.' and '-' by underscores ('_') so that ===================================== hadrian/src/Settings/Builders/Cabal.hs ===================================== @@ -49,6 +49,7 @@ cabalBuilderArgs = builder (Cabal Setup) ? do , arg $ "${pkgroot}/../../docs/html/libraries/" ++ pkgName pkg , withStaged $ Ghc CompileHs + , withBuilderArgs (Ghc CompileHs stage) , withStaged (GhcPkg Update) , withBuilderArgs (GhcPkg Update stage) , bootPackageDatabaseArgs @@ -159,6 +160,14 @@ withBuilderKey b = case b of -- | Add arguments to builders if needed. withBuilderArgs :: Builder -> Args withBuilderArgs b = case b of + Ghc _ stage -> do + top <- expr topDirectory + pkgDb <- expr $ packageDbPath stage + -- GHC starts with a nonempty package DB stack, so we need to tell it + -- to empty the stack first for it to truly consider only the package + -- DB we explicitly provide. See #17468. + notStage0 ? arg ("--ghc-option=-no-global-package-db") <> + arg ("--ghc-option=-package-db=" ++ top -/- pkgDb) GhcPkg _ stage -> do top <- expr topDirectory pkgDb <- expr $ packageDbPath stage View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f2d1accf67cb6e1dab6b2c78fef4b64526c31a4a...ef2ae81a394df573510b12b7e11bba0c931249d8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f2d1accf67cb6e1dab6b2c78fef4b64526c31a4a...ef2ae81a394df573510b12b7e11bba0c931249d8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 07:59:32 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 05 Aug 2020 03:59:32 -0400 Subject: [Git][ghc/ghc][master] 2 commits: Bignum: add backward compat integer-gmp functions Message-ID: <5f2a66e46077b_80b3f849c1caa10658124a@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5 changed files: - libraries/base/tests/isValidNatural.hs - libraries/base/tests/isValidNatural.stdout - libraries/ghc-bignum/src/GHC/Num/BigNat.hs - libraries/integer-gmp/integer-gmp.cabal - libraries/integer-gmp/src/GHC/Integer/GMP/Internals.hs Changes: ===================================== libraries/base/tests/isValidNatural.hs ===================================== @@ -3,8 +3,16 @@ import GHC.Num.Natural import GHC.Num.BigNat import GHC.Exts +import GHC.IO -main = print $ map naturalCheck [0, 1, maxWord, maxWord + 1, invalid] - where - maxWord = fromIntegral (maxBound :: Word) - invalid = NB (bigNatOne# (# #)) -- 1 would fit into the NS constructor. +main = do + let + maxWord = fromIntegral (maxBound :: Word) + invalid = NB (bigNatOne# (# #)) -- 1 would fit into the NS constructor. + + -- byteArray whose size is not a multiple of Word size + invalid2 <- IO $ \s -> case newByteArray# 27# s of + (# s', mba #) -> case unsafeFreezeByteArray# mba s' of + (# s'', ba #) -> (# s'', NB ba #) + + print $ map naturalCheck [0, 1, maxWord, maxWord + 1, invalid, invalid2] ===================================== libraries/base/tests/isValidNatural.stdout ===================================== @@ -1 +1 @@ -[True,True,True,True,False] +[True,True,True,True,False,False] ===================================== libraries/ghc-bignum/src/GHC/Num/BigNat.hs ===================================== @@ -80,6 +80,10 @@ data BigNat = BN# { unBigNat :: BigNat# } bigNatCheck# :: BigNat# -> Bool# bigNatCheck# bn | 0# <- bigNatSize# bn = 1# + -- check that size is a multiple of Word size + | r <- remInt# (sizeofByteArray# bn) WORD_SIZE_IN_BYTES# + , isTrue# (r /=# 0#) = 0# + -- check that most-significant limb isn't zero | 0## <- bigNatIndex# bn (bigNatSize# bn -# 1#) = 0# | True = 1# ===================================== libraries/integer-gmp/integer-gmp.cabal ===================================== @@ -26,6 +26,7 @@ library build-depends: base >= 4.11 && < 5 , ghc-prim + , ghc-bignum exposed-modules: GHC.Integer.GMP.Internals ===================================== libraries/integer-gmp/src/GHC/Integer/GMP/Internals.hs ===================================== @@ -5,6 +5,7 @@ {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE BlockArguments #-} #include "MachDeps.h" @@ -42,12 +43,73 @@ module GHC.Integer.GMP.Internals , GmpLimb, GmpLimb# , GmpSize, GmpSize# + -- ** + + , isValidBigNat# + , sizeofBigNat# + , zeroBigNat + , oneBigNat + + -- ** 'BigNat' arithmetic operations + , plusBigNat + , plusBigNatWord + , timesBigNat + , timesBigNatWord + , sqrBigNat + + , quotRemBigNat + , quotRemBigNatWord + , quotBigNatWord + , quotBigNat + , remBigNat + , remBigNatWord + + , gcdBigNat + , gcdBigNatWord + + -- ** 'BigNat' logic operations + , shiftRBigNat + , shiftLBigNat + , testBitBigNat + , clearBitBigNat + , complementBitBigNat + , setBitBigNat + , andBigNat + , xorBigNat + , popCountBigNat + , orBigNat + , bitBigNat + + -- ** 'BigNat' comparison predicates + , isZeroBigNat + + , compareBigNatWord + , compareBigNat + , eqBigNatWord + , eqBigNatWord# + , eqBigNat + , eqBigNat# + , gtBigNatWord# + + -- * Import/export functions + -- ** Compute size of serialisation + , sizeInBaseBigNat + , sizeInBaseInteger + , sizeInBaseWord# + + -- ** Export + , exportBigNatToAddr + + -- ** Import + , importBigNatFromAddr ) where import GHC.Integer import GHC.Natural import GHC.Num.Integer (Integer(..)) import qualified GHC.Num.Integer as I +import qualified GHC.Num.BigNat as B +import qualified GHC.Num.Primitives as P import GHC.Types import GHC.Prim @@ -112,3 +174,173 @@ type GmpLimb = Word type GmpLimb# = Word# type GmpSize = Int type GmpSize# = Int# + +{-# DEPRECATED sizeofBigNat# "Use bigNatSize# instead" #-} +sizeofBigNat# :: BigNat -> GmpSize# +sizeofBigNat# (BN# i) = B.bigNatSize# i + +{-# DEPRECATED isValidBigNat# "Use bigNatCheck# instead" #-} +isValidBigNat# :: BigNat -> Int# +isValidBigNat# (BN# i) = B.bigNatCheck# i + +{-# DEPRECATED zeroBigNat "Use bigNatZero instead" #-} +zeroBigNat :: BigNat +zeroBigNat = B.bigNatZero + +{-# DEPRECATED oneBigNat "Use bigNatOne instead" #-} +oneBigNat :: BigNat +oneBigNat = B.bigNatOne + +{-# DEPRECATED plusBigNat "Use bigNatAdd instead" #-} +plusBigNat :: BigNat -> BigNat -> BigNat +plusBigNat (BN# a) (BN# b) = BN# (B.bigNatAdd a b) + +{-# DEPRECATED plusBigNatWord "Use bigNatAddWord# instead" #-} +plusBigNatWord :: BigNat -> GmpLimb# -> BigNat +plusBigNatWord (BN# a) w = BN# (B.bigNatAddWord# a w) + +{-# DEPRECATED timesBigNat "Use bigNatMul instead" #-} +timesBigNat :: BigNat -> BigNat -> BigNat +timesBigNat (BN# a) (BN# b) = BN# (B.bigNatMul a b) + +{-# DEPRECATED timesBigNatWord "Use bigNatMulWord# instead" #-} +timesBigNatWord :: BigNat -> GmpLimb# -> BigNat +timesBigNatWord (BN# a) w = BN# (B.bigNatMulWord# a w) + +{-# DEPRECATED sqrBigNat "Use bigNatSqr instead" #-} +sqrBigNat :: BigNat -> BigNat +sqrBigNat (BN# a) = BN# (B.bigNatSqr a) + +{-# DEPRECATED quotRemBigNat "Use bigNatQuotRem# instead" #-} +quotRemBigNat :: BigNat -> BigNat -> (# BigNat,BigNat #) +quotRemBigNat (BN# a) (BN# b) = case B.bigNatQuotRem# a b of + (# q, r #) -> (# BN# q, BN# r #) + +{-# DEPRECATED quotRemBigNatWord "Use bigNatQuotRemWord# instead" #-} +quotRemBigNatWord :: BigNat -> GmpLimb# -> (# BigNat, GmpLimb# #) +quotRemBigNatWord (BN# a) b = case B.bigNatQuotRemWord# a b of + (# q, r #) -> (# BN# q, r #) + +{-# DEPRECATED quotBigNat "Use bigNatQuot instead" #-} +quotBigNat :: BigNat -> BigNat -> BigNat +quotBigNat (BN# a) (BN# b) = BN# (B.bigNatQuot a b) + +{-# DEPRECATED quotBigNatWord "Use bigNatQuotWord# instead" #-} +quotBigNatWord :: BigNat -> GmpLimb# -> BigNat +quotBigNatWord (BN# a) b = BN# (B.bigNatQuotWord# a b) + +{-# DEPRECATED remBigNat "Use bigNatRem instead" #-} +remBigNat :: BigNat -> BigNat -> BigNat +remBigNat (BN# a) (BN# b) = BN# (B.bigNatRem a b) + +{-# DEPRECATED remBigNatWord "Use bigNatRemWord# instead" #-} +remBigNatWord :: BigNat -> GmpLimb# -> Word# +remBigNatWord (BN# a) b = B.bigNatRemWord# a b + +{-# DEPRECATED gcdBigNatWord "Use bigNatGcdWord# instead" #-} +gcdBigNatWord :: BigNat -> Word# -> Word# +gcdBigNatWord (BN# a) b = B.bigNatGcdWord# a b + +{-# DEPRECATED gcdBigNat "Use bigNatGcd instead" #-} +gcdBigNat:: BigNat -> BigNat -> BigNat +gcdBigNat (BN# a) (BN# b) = BN# (B.bigNatGcd a b) + +{-# DEPRECATED shiftRBigNat "Use bigNatShiftR# instead" #-} +shiftRBigNat :: BigNat -> Int# -> BigNat +shiftRBigNat (BN# a) i = BN# (B.bigNatShiftR# a (int2Word# i)) + +{-# DEPRECATED shiftLBigNat "Use bigNatShiftL# instead" #-} +shiftLBigNat :: BigNat -> Int# -> BigNat +shiftLBigNat (BN# a) i = BN# (B.bigNatShiftL# a (int2Word# i)) + +{-# DEPRECATED testBitBigNat "Use bigNatTestBit# instead" #-} +testBitBigNat :: BigNat -> Int# -> Bool +testBitBigNat (BN# a) i = isTrue# (B.bigNatTestBit# a (int2Word# i)) + +{-# DEPRECATED clearBitBigNat "Use bigNatClearBit# instead" #-} +clearBitBigNat :: BigNat -> Int# -> BigNat +clearBitBigNat (BN# a) i = BN# (B.bigNatClearBit# a (int2Word# i)) + +{-# DEPRECATED complementBitBigNat "Use bigNatComplementBit# instead" #-} +complementBitBigNat :: BigNat -> Int# -> BigNat +complementBitBigNat (BN# a) i = BN# (B.bigNatComplementBit# a (int2Word# i)) + +{-# DEPRECATED setBitBigNat "Use bigNatSetBit# instead" #-} +setBitBigNat :: BigNat -> Int# -> BigNat +setBitBigNat (BN# a) i = BN# (B.bigNatSetBit# a (int2Word# i)) + +{-# DEPRECATED andBigNat "Use bigNatAnd instead" #-} +andBigNat :: BigNat -> BigNat -> BigNat +andBigNat (BN# a) (BN# b) = BN# (B.bigNatAnd a b) + +{-# DEPRECATED orBigNat "Use bigNatOr instead" #-} +orBigNat :: BigNat -> BigNat -> BigNat +orBigNat (BN# a) (BN# b) = BN# (B.bigNatOr a b) + +{-# DEPRECATED xorBigNat "Use bigNatXor instead" #-} +xorBigNat :: BigNat -> BigNat -> BigNat +xorBigNat (BN# a) (BN# b) = BN# (B.bigNatXor a b) + +{-# DEPRECATED popCountBigNat "Use bigNatPopCount# instead" #-} +popCountBigNat :: BigNat -> Int# +popCountBigNat (BN# a) = word2Int# (B.bigNatPopCount# a) + +{-# DEPRECATED bitBigNat "Use bigNatBit# instead" #-} +bitBigNat :: Int# -> BigNat +bitBigNat i = BN# (B.bigNatBit# (int2Word# i)) + +{-# DEPRECATED isZeroBigNat "Use bigNatIsZero instead" #-} +isZeroBigNat :: BigNat -> Bool +isZeroBigNat (BN# a) = B.bigNatIsZero a + +{-# DEPRECATED compareBigNat "Use bigNatCompare instead" #-} +compareBigNat :: BigNat -> BigNat -> Ordering +compareBigNat (BN# a) (BN# b) = B.bigNatCompare a b + +{-# DEPRECATED compareBigNatWord "Use bigNatCompareWord# instead" #-} +compareBigNatWord :: BigNat -> GmpLimb# -> Ordering +compareBigNatWord (BN# a) w = B.bigNatCompareWord# a w + +{-# DEPRECATED eqBigNatWord "Use bigNatEqWord# instead" #-} +eqBigNatWord :: BigNat -> GmpLimb# -> Bool +eqBigNatWord (BN# a) w = isTrue# (B.bigNatEqWord# a w) + +{-# DEPRECATED eqBigNatWord# "Use bigNatEqWord# instead" #-} +eqBigNatWord# :: BigNat -> GmpLimb# -> Int# +eqBigNatWord# (BN# a) w = B.bigNatEqWord# a w + +{-# DEPRECATED eqBigNat# "Use bigNatEq# instead" #-} +eqBigNat# :: BigNat -> BigNat -> Int# +eqBigNat# (BN# a) (BN# b) = B.bigNatEq# a b + +{-# DEPRECATED eqBigNat "Use bigNatEq instead" #-} +eqBigNat :: BigNat -> BigNat -> Bool +eqBigNat (BN# a) (BN# b) = B.bigNatEq a b + +{-# DEPRECATED gtBigNatWord# "Use bigNatGtWord# instead" #-} +gtBigNatWord# :: BigNat -> GmpLimb# -> Int# +gtBigNatWord# (BN# a) w = B.bigNatGtWord# a w + +{-# DEPRECATED sizeInBaseBigNat "Use bigNatSizeInBase# instead" #-} +sizeInBaseBigNat :: BigNat -> Int# -> Word# +sizeInBaseBigNat (BN# a) b = B.bigNatSizeInBase# (int2Word# b) a + +{-# DEPRECATED sizeInBaseInteger "Use integerSizeInBase# instead" #-} +sizeInBaseInteger :: Integer -> Int# -> Word# +sizeInBaseInteger i b = I.integerSizeInBase# (int2Word# b) i + +{-# DEPRECATED sizeInBaseWord# "Use wordSizeInBase# instead" #-} +sizeInBaseWord# :: Word# -> Int# -> Word# +sizeInBaseWord# a b = P.wordSizeInBase# (int2Word# b) a + +{-# DEPRECATED importBigNatFromAddr "Use bigNatFromAddr# instead" #-} +importBigNatFromAddr :: Addr# -> Word# -> Int# -> IO BigNat +importBigNatFromAddr addr sz endian = IO \s -> + case B.bigNatFromAddr# sz addr endian s of + (# s', b #) -> (# s', BN# b #) + +{-# DEPRECATED exportBigNatToAddr "Use bigNatToAddr# instead" #-} +exportBigNatToAddr :: BigNat -> Addr# -> Int# -> IO Word +exportBigNatToAddr (BN# b) addr endian = IO \s -> + case B.bigNatToAddr# b addr endian s of + (# s', w #) -> (# s', W# w #) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ef2ae81a394df573510b12b7e11bba0c931249d8...3f2f771869c65125ba013a5dd2b213061efe0fc2 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ef2ae81a394df573510b12b7e11bba0c931249d8...3f2f771869c65125ba013a5dd2b213061efe0fc2 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 08:00:10 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 05 Aug 2020 04:00:10 -0400 Subject: [Git][ghc/ghc][master] Rename Core.Opt.Driver -> Core.Opt.Pipeline Message-ID: <5f2a670ac08bf_80b3f848a386fc865872a1@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 4 changed files: - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Driver/Main.hs - compiler/ghc.cabal.in Changes: ===================================== compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs ===================================== @@ -6,7 +6,7 @@ {-# LANGUAGE CPP #-} -module GHC.Core.Opt.Driver ( core2core, simplifyExpr ) where +module GHC.Core.Opt.Pipeline ( core2core, simplifyExpr ) where #include "HsVersions.h" ===================================== compiler/GHC/Core/Opt/Simplify.hs ===================================== @@ -68,7 +68,7 @@ import GHC.Builtin.PrimOps ( PrimOp (SeqOp) ) {- The guts of the simplifier is in this module, but the driver loop for -the simplifier is in GHC.Core.Opt.Driver +the simplifier is in GHC.Core.Opt.Pipeline Note [The big picture] ~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/Driver/Main.hs ===================================== @@ -117,7 +117,7 @@ import GHC.Tc.Utils.Monad import GHC.Tc.Utils.Zonk ( ZonkFlexi (DefaultFlexi) ) import GHC.Types.Name.Cache ( initNameCache ) import GHC.Builtin.Utils -import GHC.Core.Opt.Driver +import GHC.Core.Opt.Pipeline import GHC.HsToCore import GHC.Iface.Load ( ifaceStats, initExternalPackageState, writeIface ) import GHC.Iface.Make ===================================== compiler/ghc.cabal.in ===================================== @@ -427,7 +427,7 @@ Library GHC.Core.Opt.OccurAnal GHC.Core.Opt.StaticArgs GHC.Core.Opt.SetLevels - GHC.Core.Opt.Driver + GHC.Core.Opt.Pipeline GHC.Core.Opt.Simplify.Env GHC.Core.Opt.Simplify.Monad GHC.Core.Opt.Simplify.Utils View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5e12cd1733b581f48a5873b12971b6974778eabb -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5e12cd1733b581f48a5873b12971b6974778eabb You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 08:00:46 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 05 Aug 2020 04:00:46 -0400 Subject: [Git][ghc/ghc][master] 2 commits: Revert "iserv: Don't pass --export-dynamic on FreeBSD" Message-ID: <5f2a672ea0ae9_80b3f849c1caa106589972@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 22 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk - utils/iserv/ghc.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + result=0 + else + AC_MSG_RESULT([affected]) + result=1 + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + fi +]) + +# FIND_MERGE_OBJECTS +# ------------------ +# Find which linker to use to merge object files. +# +AC_DEFUN([FIND_MERGE_OBJECTS],[ + AC_REQUIRE([FIND_LD]) + + if test -z "$SettingsMergeObjectsCommand"; then + SettingsMergeObjectsCommand="$LD" + fi + if test -z "$SettingsMergeObjectsFlags"; then + SettingsMergeObjectsFlags="-r" + fi + + CHECK_FOR_GOLD_T22266($SettingsMergeObjectsCommand) + if test "$result" = "1"; then + AC_MSG_NOTICE([$SettingsMergeObjectsCommand is broken due to binutils 22266, looking for another linker...]) + SettingsMergeObjectsCommand="" + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + CHECK_FOR_GOLD_T22266($SettingsMergeObjectsCommand) + if test "$result" = "1"; then + AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the SettingsMergeObjectsCommand variable to a functional linker.]) + fi + fi + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -2133,6 +2133,23 @@ We must enable bigobj output in a few places: Unfortunately the big object format is not supported on 32-bit targets so none of this can be used in that case. + + +Note [Merging object files for GHCi] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +GHCi can usually loads standard linkable object files using GHC's linker +implementation. However, most users build their projects with -split-sections, +meaning that such object files can have an extremely high number of sections. +As the linker must map each of these sections individually, loading such object +files is very inefficient. + +To avoid this inefficiency, we use the linker's `-r` flag and a linker script +to produce a merged relocatable object file. This file will contain a singe +text section section and can consequently be mapped far more efficiently. As +gcc tends to do unpredictable things to our linker command line, we opt to +invoke ld directly in this case, in contrast to our usual strategy of linking +via gcc. + -} joinObjectFiles :: DynFlags -> [FilePath] -> FilePath -> IO () @@ -2140,34 +2157,13 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = GHC.SysTools.runLink dflags ([ - GHC.SysTools.Option "-nostdlib", - GHC.SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in GHC.Driver.Session - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [GHC.SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [GHC.SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [GHC.SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [GHC.SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args = GHC.SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ GHC.SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" - | OSMinGW32 == osInfo - , not $ target32Bit (targetPlatform dflags) - ] + concat + [ [GHC.SysTools.Option "--oformat", GHC.SysTools.Option "pe-bigobj-x86-64"] + | OSMinGW32 == osInfo + , not $ target32Bit (targetPlatform dflags) + ] ++ map GHC.SysTools.Option ld_build_id ++ [ GHC.SysTools.Option "-o", GHC.SysTools.FileOption "" output_fn ] @@ -2176,25 +2172,24 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] - ccInfo <- getCompilerInfo dflags if ldIsGnuLd then do script <- newTempName dflags TFL_CurrentModule "ldscript" cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [GHC.SysTools.FileOption "" script] ccInfo + ld_r [GHC.SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files - ld_r [GHC.SysTools.Option "-Wl,-filelist", - GHC.SysTools.FileOption "-Wl," filelist] ccInfo + ld_r [GHC.SysTools.Option "-filelist", + GHC.SysTools.FileOption "" filelist] else do - ld_r (map (GHC.SysTools.FileOption "") o_files) ccInfo + ld_r (map (GHC.SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -102,6 +102,7 @@ module GHC.Driver.Session ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -120,6 +121,7 @@ module GHC.Driver.Session ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -142,10 +144,10 @@ module GHC.Driver.Session ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -940,6 +942,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -986,6 +990,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/GHC/Settings.hs ===================================== @@ -28,6 +28,7 @@ module GHC.Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -46,6 +47,7 @@ module GHC.Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -99,6 +101,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -124,6 +127,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] @@ -200,6 +204,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -236,6 +242,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -137,6 +137,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -183,6 +185,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -201,6 +204,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -1,4 +1,5 @@ {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- -- Tasks running external programs for SysTools @@ -299,6 +300,20 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +-- See Note [Merging object files for GHCi] in GHC.Driver.Pipeline. +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + -- N.B. Darwin's ld64 doesn't support response files. Consequently we only + -- use them on Windows where they are truly necessary. +#if defined(mingw32_HOST_OS) + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env +#else + runSomething dflags "Merge objects" p args2 +#endif runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== configure.ac ===================================== @@ -602,13 +602,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -96,6 +96,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -115,6 +115,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -138,6 +144,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -99,6 +99,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -127,9 +127,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -311,6 +312,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -91,6 +91,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -109,6 +110,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -176,6 +179,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -191,6 +195,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -298,6 +298,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -92,6 +92,7 @@ buildDynamicLibUnix root suffix dynlibpath = do -- | Build a "GHCi library" ('LibGhci') under the given build root, with the -- complete path of the file to build is given as the second argument. +-- See Note [Merging object files for GHCi] in GHC.Driver.Pipeline. buildGhciLibO :: FilePath -> FilePath -> Action () buildGhciLibO root ghcilibPath = do l@(BuildPath _ stage _ (LibGhci _ _ _)) @@ -101,7 +102,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -37,6 +37,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -244,6 +245,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -223,6 +223,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -500,6 +500,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -733,7 +735,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" ===================================== utils/iserv/ghc.mk ===================================== @@ -30,9 +30,8 @@ endif # refer to the RTS. This is harmless if you don't use it (adds a bit # of overhead to startup and increases the binary sizes) but if you # need it there's no alternative. -# Don't do this on FreeBSD to work around #17962. ifeq "$(TargetElf)" "YES" -ifeq "$(findstring $(TargetOS_CPP), solaris2 freebsd)" "" +ifneq "$(TargetOS_CPP)" "solaris2" # The Solaris linker does not support --export-dynamic option. It also # does not need it since it exports all dynamic symbols by default utils/iserv_stage2_MORE_HC_OPTS += -optl-Wl,--export-dynamic View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5e12cd1733b581f48a5873b12971b6974778eabb...53ce0db5a06598c88c6b8cb32043b878e7083dd4 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5e12cd1733b581f48a5873b12971b6974778eabb...53ce0db5a06598c88c6b8cb32043b878e7083dd4 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 08:01:21 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 05 Aug 2020 04:01:21 -0400 Subject: [Git][ghc/ghc][master] Remove all the unnecessary LANGUAGE pragmas Message-ID: <5f2a6751f0a58_80b3f848a386fc865911ef@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - 30 changed files: - libraries/base/.hlint.yaml - libraries/base/Control/Concurrent/QSemN.hs - libraries/base/Control/Exception/Base.hs - libraries/base/Data/Coerce.hs - libraries/base/Data/Complex.hs - libraries/base/Data/Data.hs - libraries/base/Data/Dynamic.hs - libraries/base/Data/Either.hs - libraries/base/Data/Functor/Compose.hs - libraries/base/Data/Functor/Contravariant.hs - libraries/base/Data/Functor/Identity.hs - libraries/base/Data/IORef.hs - libraries/base/Data/List/NonEmpty.hs - libraries/base/Data/Semigroup.hs - libraries/base/Data/Type/Bool.hs - libraries/base/Data/Type/Coercion.hs - libraries/base/Data/Type/Equality.hs - libraries/base/Data/Typeable.hs - libraries/base/Data/Unique.hs - libraries/base/Data/Void.hs - libraries/base/Foreign/C/Types.hs - libraries/base/Foreign/Ptr.hs - libraries/base/GHC/Base.hs - libraries/base/GHC/Conc/Sync.hs - libraries/base/GHC/Conc/WinIO.hs - libraries/base/GHC/Event/Manager.hs - libraries/base/GHC/Event/PSQ.hs - libraries/base/GHC/Event/TimerManager.hs - libraries/base/GHC/Event/Windows/ManagedThreadPool.hs - libraries/base/GHC/Exception/Type.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/eb7013c3037538aa9c947a21dbbfd7c297929ac8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/eb7013c3037538aa9c947a21dbbfd7c297929ac8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 08:01:58 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 05 Aug 2020 04:01:58 -0400 Subject: [Git][ghc/ghc][master] Make CodeQ and TExpQ levity polymorphic Message-ID: <5f2a67767075_80b3f849a25e69065995bc@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 5 changed files: - libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs - libraries/template-haskell/Language/Haskell/TH/Syntax.hs - libraries/template-haskell/changelog.md - + testsuite/tests/quotes/T18521.hs - testsuite/tests/quotes/all.T Changes: ===================================== libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs ===================================== @@ -1,4 +1,5 @@ -{-# LANGUAGE Safe #-} +{-# LANGUAGE PolyKinds #-} +{-# LANGUAGE Trustworthy #-} -- | -- Language.Haskell.TH.Lib.Internal exposes some additional functionality that @@ -19,19 +20,31 @@ module Language.Haskell.TH.Lib.Internal where import Language.Haskell.TH.Syntax hiding (Role, InjectivityAnn) import qualified Language.Haskell.TH.Syntax as TH import Control.Applicative(liftA, liftA2) +import qualified Data.Kind as Kind (Type) import Data.Word( Word8 ) +import GHC.Exts (TYPE) import Prelude ---------------------------------------------------------- -- * Type synonyms ---------------------------------------------------------- +-- Since GHC 8.8 is currently the minimum boot compiler version that we must +-- support, we must use inline kind signatures to make TExpQ and CodeQ +-- levity polymorphic. When we drop support for GHC 8.8, we can instead use +-- standalone kind signatures, which are provided as comments. + +-- | Levity-polymorphic since /template-haskell-2.17.0.0/. +-- type TExpQ :: TYPE r -> Kind.Type +type TExpQ (a :: TYPE r) = Q (TExp a) + +-- type CodeQ :: TYPE r -> Kind.Type +type CodeQ = Code Q :: (TYPE r -> Kind.Type) + type InfoQ = Q Info type PatQ = Q Pat type FieldPatQ = Q FieldPat type ExpQ = Q Exp -type TExpQ a = Q (TExp a) -type CodeQ = Code Q type DecQ = Q Dec type DecsQ = Q [Dec] type Decs = [Dec] -- Defined as it is more convenient to wire-in ===================================== libraries/template-haskell/Language/Haskell/TH/Syntax.hs ===================================== @@ -341,6 +341,8 @@ newtype TExp (a :: TYPE (r :: RuntimeRep)) = TExp -- • In the Template Haskell quotation [|| "foo" ||] -- In the expression: [|| "foo" ||] -- In the Template Haskell splice $$([|| "foo" ||]) +-- +-- Levity-polymorphic since /template-haskell-2.16.0.0/. -- | Discard the type annotation and produce a plain Template Haskell -- expression ===================================== libraries/template-haskell/changelog.md ===================================== @@ -32,6 +32,8 @@ * Add support for QualifiedDo. The data constructors `DoE` and `MDoE` got a new `Maybe ModName` argument to describe the qualifier of do blocks. + * The argument to `TExpQ` can now be levity polymorphic. + ## 2.16.0.0 *TBA* * Add support for tuple sections. (#15843) The type signatures of `TupE` and ===================================== testsuite/tests/quotes/T18521.hs ===================================== @@ -0,0 +1,15 @@ +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE TemplateHaskellQuotes #-} +module T18521 where + +import GHC.Exts (Int#) +import Language.Haskell.TH + +a :: Code Q Int# +a = [|| 42# ||] + +b :: CodeQ Int# +b = a + +c :: TExpQ Int# +c = examineCode a ===================================== testsuite/tests/quotes/all.T ===================================== @@ -19,6 +19,7 @@ test('T16384', req_th, compile, ['']) test('T17857', normal, compile, ['']) test('T18103', normal, compile, ['']) test('T18263', normal, compile_fail, ['']) +test('T18521', normal, compile, ['']) test('TH_tf2', normal, compile, ['-v0']) test('TH_ppr1', normal, compile_and_run, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fbcb886d503dd7aaebc4c40e59615068b3fd0bd7 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fbcb886d503dd7aaebc4c40e59615068b3fd0bd7 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 08:32:41 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 05 Aug 2020 04:32:41 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 12 commits: Bignum: add backward compat integer-gmp functions Message-ID: <5f2a6ea91889a_80b3f848705b1446601447@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 663c342b by Vladislav Zavialov at 2020-08-05T04:32:36-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - b5d3042b by Vladislav Zavialov at 2020-08-05T04:32:36-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 5c4f047f by Vladislav Zavialov at 2020-08-05T04:32:37-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 4eacd06b by Vladislav Zavialov at 2020-08-05T04:32:37-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - a63823a8 by Richard Eisenberg at 2020-08-05T04:32:37-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 30 changed files: - aclocal.m4 - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - compiler/GHC/Tc/TyCl.hs - compiler/ghc.cabal.in - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - libraries/base/.hlint.yaml - libraries/base/Control/Concurrent/QSemN.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/8a4a5637ec6143494f40013c183c723c0dea3cd9...a63823a8d3aa335efa643f2a2826dde539083167 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/8a4a5637ec6143494f40013c183c723c0dea3cd9...a63823a8d3aa335efa643f2a2826dde539083167 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 11:58:22 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Wed, 05 Aug 2020 07:58:22 -0400 Subject: [Git][ghc/ghc][wip/T8095-spj] 2 commits: Two perf wibbles Message-ID: <5f2a9eded00ef_80b3f848c1e06f4662829a@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T8095-spj at Glasgow Haskell Compiler / GHC Commits: 72570fae by Simon Peyton Jones at 2020-08-05T11:53:56+01:00 Two perf wibbles - - - - - d35f1fef by Simon Peyton Jones at 2020-08-05T12:57:42+01:00 Further wibbles - - - - - 3 changed files: - compiler/GHC/Core/TyCo/FVs.hs - compiler/GHC/Core/TyCo/Rep.hs - compiler/GHC/Core/Unify.hs Changes: ===================================== compiler/GHC/Core/TyCo/FVs.hs ===================================== @@ -268,13 +268,17 @@ type InScopeBndrs = TyCoVarSet newtype TyCoAcc acc = TCA' { runTCA :: InScopeBndrs -> acc -> acc } pattern TCA :: forall acc. (InScopeBndrs -> acc -> acc) -> TyCoAcc acc +-- See GHC.Core.Unify Note [The one-shot state monad trick] {-# COMPLETE TCA #-} pattern TCA f <- TCA' f where TCA f = TCA' (oneShot f) instance Semigroup (TyCoAcc acc) where - (TCA f1) <> (TCA f2) = TCA (\is acc -> f2 is (f1 is acc)) + (TCA f1) <> (TCA f2) = TCA (\is acc -> f1 is (f2 is acc)) + -- It makes a perf difference going f1 (f2 acc), rather + -- than f2 (f1 acc). In a short-cutting situation (e.g. + -- a boolean accumulator, people put the short-cut first. {-# INLINE (<>) #-} instance Monoid (TyCoAcc acc) where @@ -287,21 +291,25 @@ emptyInScope :: InScopeBndrs emptyInScope = emptyVarSet addTyCoVar :: TyCoVar -> TyCoAcc TyCoVarSet -> TyCoAcc TyCoVarSet --- Add a variable tcv, and the extras, to the free vars unless --- tcv is in the in-scope --- or is already in the in-scope set- --- The 'extras' start from an empty in-scope set; --- see Note [Closing over free variable kinds] -addTyCoVar tcv (TCA add_extras) = TCA add_it +-- If 'tcv' is (a) in scope or (b) in the accumulator, then do nothing +-- Otherwise: +-- - Add 'tcv' to the accumulator, and +-- - Run 'add_kind_fvs' starting from an empty in-scope set; +-- see Note [Closing over free variable kinds] +addTyCoVar tcv (TCA add_kind_fvs) = TCA add_it where add_it is acc | tcv `elemVarSet` is = acc | tcv `elemVarSet` acc = acc - | otherwise = add_extras emptyVarSet (acc `extendVarSet` tcv) + | otherwise = add_kind_fvs emptyVarSet (acc `extendVarSet` tcv) extendInScope :: TyCoVar -> TyCoAcc acc -> TyCoAcc acc -- Gather the argument free vars in an empty in-scope set -extendInScope tcv (TCA f) = TCA (\is acc -> f (is `extendVarSet` tcv) acc) +extendInScope tcv (TCA f) = TCA (\is acc -> let !is' = is `extendVarSet` tcv + in f is' acc) + -- Making this strict removes a thunk, which reduces + -- allocation slightly; and the in-scope set is consulted + -- at every variable occurrence anyway whenNotInScope :: TyCoVar -> TyCoAcc acc -> TyCoAcc acc -- If tcv is not in the in-scope set, compute ===================================== compiler/GHC/Core/TyCo/Rep.hs ===================================== @@ -1819,11 +1819,15 @@ coercion witnessing the reduction. The reduction will proceed as follows: ~> S (S (S (Z + S Z))) |> CoAx2 (CoAx2 (CoAx2 Refl)) ~> S (S (S (S (S Z)))) |> CoAx1 (CoAx2 (CoAx2 (CoAx2 Refl))) -Moreover, coercions are really only useful when validating core transformations -(i.e. by the Core Linter). To avoid burdening users who aren't linting with the -cost of maintaining these structures, we replace coercions with placeholders -("zap" them) them unless -dcore-lint is enabled. These placeholders are -represented by UnivCo with ZappedProv provenance. Concretely, a coercion +This looks linear, but the type arguments to CoAx2 are of size N, N-1 +etc; hence quadratic. + +Moreover, coercions are really only useful when validating core +transformations (i.e. by the Core Linter). To avoid burdening users +who aren't linting with the cost of maintaining these structures, we +replace coercions with placeholders ("zap" them) them unless +-dcore-lint is enabled. These placeholders are represented by UnivCo +with ZappedProv provenance. Concretely, a coercion co :: t1 ~r t2 @@ -1974,6 +1978,8 @@ keyword): to avoid unsound floating. This means that the free variable lists of zapped coercions loaded from interface files will lack top-level things (e.g. type constructors) that appear only in the unzapped proof. + +* coercionSize gives a smaller size, of course. -} @@ -2077,6 +2083,7 @@ data TyCoFolder a -- See Note [Coercion holes] in "GHC.Core.TyCo.Rep". , tcf_tycobinder :: TyCoVar -> ArgFlag -> a -> a + -- ^ Modify the result of folding over the body of the forall } noView :: Type -> Maybe Type -- Simplest form of tcf_view @@ -2107,7 +2114,7 @@ foldTyCo (TyCoFolder { tcf_view = view go_ty (ForAllTy (Bndr tv vis) inner) = go_ty (varType tv) `mappend` tycobinder tv vis (go_ty inner) - -- Explicit recursion becuase using foldr builds a local + -- Explicit recursion because using foldr builds a local -- loop (with free) and I'm not confident it'll be -- lambda lifted in the end go_tys [] = mempty @@ -2147,8 +2154,9 @@ foldTyCo (TyCoFolder { tcf_view = view go_prov (ZapCoProv cvs) = go_cvs (dVarSetElems cvs) -- This use of dVarSetElems does a sort, which seems very -- inefficient. But it seems required for determinism, alas. - -- Unless the 'a' is instantiated with a non-deterministic kind - -- of thing...could we exploit that somehow? ToDo. + -- Unless the 'a' is instantiated with a commutative monoid, + -- such as (VarSet -> VarSet) ...could we exploit that somehow? + -- ToDo. go_cvs [] = mempty go_cvs (cv:cvs) = covar cv `mappend` go_cvs cvs ===================================== compiler/GHC/Core/Unify.hs ===================================== @@ -1278,7 +1278,7 @@ and voila! In summary: described here is applicable on a monad-by-monad basis under programmer control. -* Beware: itt changes the behaviour of +* Beware: it changes the behaviour of map (foo 3) xs ToDo: explain what to do if you want to do this -} View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c5deeadeb1f90b47beab9d91dcb5095b22581efd...d35f1fefd24846dee79a6572c6b957309814d3fd -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c5deeadeb1f90b47beab9d91dcb5095b22581efd...d35f1fefd24846dee79a6572c6b957309814d3fd You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 12:47:00 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Wed, 05 Aug 2020 08:47:00 -0400 Subject: [Git][ghc/ghc] Deleted branch wip/backports Message-ID: <5f2aaa44366d0_80b3f849a25e690663447f@gitlab.haskell.org.mail> Ben Gamari deleted branch wip/backports at Glasgow Haskell Compiler / GHC -- You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 12:47:03 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Wed, 05 Aug 2020 08:47:03 -0400 Subject: [Git][ghc/ghc][ghc-8.10] 3 commits: Fix GHC_STAGE definition generated by make Message-ID: <5f2aaa47729ce_80b3f848a372f8c6634643@gitlab.haskell.org.mail> Ben Gamari pushed to branch ghc-8.10 at Glasgow Haskell Compiler / GHC Commits: fec2abb8 by Leon Schoorl at 2020-08-01T14:43:48-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 (cherry picked from commit a481afef354ca0383477fd20891c2e8eb9ef4449) - - - - - 428320a9 by Ben Gamari at 2020-08-03T17:51:43-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. (cherry picked from commit f9b7497d30d98a054d4ec5a8df2dfaf4a2b0bb30) - - - - - e69b0d42 by Ben Gamari at 2020-08-04T23:37:46-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - 23 changed files: - aclocal.m4 - compiler/main/DriverPipeline.hs - compiler/main/DynFlags.hs - compiler/main/Settings.hs - compiler/main/SysTools/Settings.hs - compiler/main/SysTools/Tasks.hs - compiler/main/ToolSettings.hs - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - mk/config.mk.in - rules/build-package-way.mk - utils/iserv/ghc.mk Changes: ===================================== aclocal.m4 ===================================== @@ -3,6 +3,15 @@ # To be a good autoconf citizen, names of local macros have prefixed with FP_ to # ensure we don't clash with any pre-supplied autoconf ones. +# FPTOOLS_WRITE_FILE +# ------------------ +# Write $2 to the file named $1. +AC_DEFUN([FPTOOLS_WRITE_FILE], +[ +cat >$1 < + #include + + extern int *p_int_from_a_2; + extern const char *hello (void); + + int main (void) { + if (*p_int_from_a_2 != 0x11223344) + abort (); + if (strcmp(hello(), "Hello, world!") != 0) + abort (); + return 0; + } + ]) + + FPTOOLS_WRITE_FILE([conftest.t], [ + SECTIONS + { + .text : { + *(.text*) + } + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .data.rel.ro : { + *(.data.rel.ro*) + } + .data : { + *(.data*) + } + .bss : { + *(.bss*) + } + } + ]) + + $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) + $SettingsMergeObjectsCommand $SettingsMergeObjectsFlags -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) + + $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) + $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) + + if ./conftest; then + AC_MSG_RESULT([not affected]) + result=0 + else + AC_MSG_RESULT([affected]) + result=1 + fi + rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest + fi +]) + +# FIND_MERGE_OBJECTS +# ------------------ +# Find which linker to use to merge object files. +# +AC_DEFUN([FIND_MERGE_OBJECTS],[ + AC_REQUIRE([FIND_LD]) + + if test -z "$SettingsMergeObjectsCommand"; then + SettingsMergeObjectsCommand="$LD" + fi + if test -z "$SettingsMergeObjectsFlags"; then + SettingsMergeObjectsFlags="-r" + fi + + CHECK_FOR_GOLD_T22266($SettingsMergeObjectsCommand) + if test "$result" = "1"; then + AC_MSG_NOTICE([$SettingsMergeObjectsCommand is broken due to binutils 22266, looking for another linker...]) + SettingsMergeObjectsCommand="" + AC_CHECK_TARGET_TOOL([SettingsMergeObjectsCommand], [ld]) + CHECK_FOR_GOLD_T22266($SettingsMergeObjectsCommand) + if test "$result" = "1"; then + AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the SettingsMergeObjectsCommand variable to a functional linker.]) + fi + fi + + if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" -a "$WORD_SIZE" = 64; then + SettingsMergeObjectsFlags="$SettingsMergeObjectsFlags --oformat=pe-bigobj-x86-64" + fi + + AC_SUBST(SettingsMergeObjectsCommand) + AC_SUBST(SettingsMergeObjectsFlags) +]) + # FIND_PYTHON # ----------- # Find the version of `python` to use (for the testsuite driver) ===================================== compiler/main/DriverPipeline.hs ===================================== @@ -2119,6 +2119,23 @@ We must enable bigobj output in a few places: Unfortunately the big object format is not supported on 32-bit targets so none of this can be used in that case. + + +Note [Merging object files for GHCi] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +GHCi can usually loads standard linkable object files using GHC's linker +implementation. However, most users build their projects with -split-sections, +meaning that such object files can have an extremely high number of sections. +As the linker must map each of these sections individually, loading such object +files is very inefficient. + +To avoid this inefficiency, we use the linker's `-r` flag and a linker script +to produce a merged relocatable object file. This file will contain a singe +text section section and can consequently be mapped far more efficiently. As +gcc tends to do unpredictable things to our linker command line, we opt to +invoke ld directly in this case, in contrast to our usual strategy of linking +via gcc. + -} joinObjectFiles :: DynFlags -> [FilePath] -> FilePath -> IO () @@ -2126,34 +2143,13 @@ joinObjectFiles dflags o_files output_fn = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' osInfo = platformOS (targetPlatform dflags) - ld_r args cc = SysTools.runLink dflags ([ - SysTools.Option "-nostdlib", - SysTools.Option "-Wl,-r" - ] - -- See Note [No PIE while linking] in DynFlags - ++ (if toolSettings_ccSupportsNoPie toolSettings' - then [SysTools.Option "-no-pie"] - else []) - - ++ (if any (cc ==) [Clang, AppleClang, AppleClang51] - then [] - else [SysTools.Option "-nodefaultlibs"]) - ++ (if osInfo == OSFreeBSD - then [SysTools.Option "-L/usr/lib"] - else []) - -- gcc on sparc sets -Wl,--relax implicitly, but - -- -r and --relax are incompatible for ld, so - -- disable --relax explicitly. - ++ (if platformArch (targetPlatform dflags) - `elem` [ArchSPARC, ArchSPARC64] - && ldIsGnuLd - then [SysTools.Option "-Wl,-no-relax"] - else []) + ld_r args = SysTools.runMergeObjects dflags ( -- See Note [Produce big objects on Windows] - ++ [ SysTools.Option "-Wl,--oformat,pe-bigobj-x86-64" - | OSMinGW32 == osInfo - , not $ target32Bit (targetPlatform dflags) - ] + concat + [ [SysTools.Option "--oformat", SysTools.Option "pe-bigobj-x86-64"] + | OSMinGW32 == osInfo + , not $ target32Bit (targetPlatform dflags) + ] ++ map SysTools.Option ld_build_id ++ [ SysTools.Option "-o", SysTools.FileOption "" output_fn ] @@ -2162,25 +2158,24 @@ joinObjectFiles dflags o_files output_fn = do -- suppress the generation of the .note.gnu.build-id section, -- which we don't need and sometimes causes ld to emit a -- warning: - ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["-Wl,--build-id=none"] + ld_build_id | toolSettings_ldSupportsBuildId toolSettings' = ["--build-id=none"] | otherwise = [] - ccInfo <- getCompilerInfo dflags if ldIsGnuLd then do script <- newTempName dflags TFL_CurrentModule "ldscript" cwd <- getCurrentDirectory let o_files_abs = map (\x -> "\"" ++ (cwd x) ++ "\"") o_files writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")" - ld_r [SysTools.FileOption "" script] ccInfo + ld_r [SysTools.FileOption "" script] else if toolSettings_ldSupportsFilelist toolSettings' then do filelist <- newTempName dflags TFL_CurrentModule "filelist" writeFile filelist $ unlines o_files - ld_r [SysTools.Option "-Wl,-filelist", - SysTools.FileOption "-Wl," filelist] ccInfo + ld_r [SysTools.Option "-filelist", + SysTools.FileOption "" filelist] else do - ld_r (map (SysTools.FileOption "") o_files) ccInfo + ld_r (map (SysTools.FileOption "") o_files) -- ----------------------------------------------------------------------------- -- Misc. ===================================== compiler/main/DynFlags.hs ===================================== @@ -106,6 +106,7 @@ module DynFlags ( sPgm_c, sPgm_a, sPgm_l, + sPgm_lm, sPgm_dll, sPgm_T, sPgm_windres, @@ -124,6 +125,7 @@ module DynFlags ( sOpt_cxx, sOpt_a, sOpt_l, + sOpt_lm, sOpt_windres, sOpt_lo, sOpt_lc, @@ -152,10 +154,10 @@ module DynFlags ( ghcUsagePath, ghciUsagePath, topDir, tmpDir, versionedAppDir, versionedFilePath, extraGccViaCFlags, systemPackageConfig, - pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_dll, pgm_T, + pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, - opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_i, + opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, tablesNextToCode, @@ -1447,6 +1449,8 @@ pgm_a :: DynFlags -> (String,[Option]) pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags pgm_l :: DynFlags -> (String,[Option]) pgm_l dflags = toolSettings_pgm_l $ toolSettings dflags +pgm_lm :: DynFlags -> (String,[Option]) +pgm_lm dflags = toolSettings_pgm_lm $ toolSettings dflags pgm_dll :: DynFlags -> (String,[Option]) pgm_dll dflags = toolSettings_pgm_dll $ toolSettings dflags pgm_T :: DynFlags -> String @@ -1493,6 +1497,8 @@ opt_a dflags= toolSettings_opt_a $ toolSettings dflags opt_l :: DynFlags -> [String] opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ++ toolSettings_opt_l (toolSettings dflags) +opt_lm :: DynFlags -> [String] +opt_lm dflags= toolSettings_opt_lm $ toolSettings dflags opt_windres :: DynFlags -> [String] opt_windres dflags= toolSettings_opt_windres $ toolSettings dflags opt_lcc :: DynFlags -> [String] ===================================== compiler/main/Settings.hs ===================================== @@ -19,6 +19,7 @@ module Settings , sPgm_c , sPgm_a , sPgm_l + , sPgm_lm , sPgm_dll , sPgm_T , sPgm_windres @@ -37,6 +38,7 @@ module Settings , sOpt_cxx , sOpt_a , sOpt_l + , sOpt_lm , sOpt_windres , sOpt_lo , sOpt_lc @@ -125,6 +127,8 @@ sPgm_a :: Settings -> (String, [Option]) sPgm_a = toolSettings_pgm_a . sToolSettings sPgm_l :: Settings -> (String, [Option]) sPgm_l = toolSettings_pgm_l . sToolSettings +sPgm_lm :: Settings -> (String, [Option]) +sPgm_lm = toolSettings_pgm_lm . sToolSettings sPgm_dll :: Settings -> (String, [Option]) sPgm_dll = toolSettings_pgm_dll . sToolSettings sPgm_T :: Settings -> String @@ -161,6 +165,8 @@ sOpt_a :: Settings -> [String] sOpt_a = toolSettings_opt_a . sToolSettings sOpt_l :: Settings -> [String] sOpt_l = toolSettings_opt_l . sToolSettings +sOpt_lm :: Settings -> [String] +sOpt_lm = toolSettings_opt_lm . sToolSettings sOpt_windres :: Settings -> [String] sOpt_windres = toolSettings_opt_windres . sToolSettings sOpt_lo :: Settings -> [String] ===================================== compiler/main/SysTools/Settings.hs ===================================== @@ -141,6 +141,8 @@ initSettings top_dir = do as_args = map Option cc_args ld_prog = cc_prog ld_args = map Option (cc_args ++ words cc_link_args_str) + ld_r_prog <- getSetting "Merge objects command" + ld_r_args <- getSetting "Merge objects flags" llvmTarget <- getSetting "LLVM target" @@ -202,6 +204,7 @@ initSettings top_dir = do , toolSettings_pgm_c = cc_prog , toolSettings_pgm_a = (as_prog, as_args) , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_lm = (ld_r_prog, map Option $ words ld_r_args) , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) , toolSettings_pgm_T = touch_path , toolSettings_pgm_windres = windres_path @@ -220,6 +223,7 @@ initSettings top_dir = do , toolSettings_opt_cxx = cxx_args , toolSettings_opt_a = [] , toolSettings_opt_l = [] + , toolSettings_opt_lm = [] , toolSettings_opt_windres = [] , toolSettings_opt_lcc = [] , toolSettings_opt_lo = [] ===================================== compiler/main/SysTools/Tasks.hs ===================================== @@ -1,4 +1,5 @@ {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- -- Tasks running external programs for SysTools @@ -299,6 +300,20 @@ ld: warning: symbol referencing errors ld_postfix = tail . snd . ld_warn_break ld_warning_found = not . null . snd . ld_warn_break +-- See Note [Merging object files for GHCi] in GHC.Driver.Pipeline. +runMergeObjects :: DynFlags -> [Option] -> IO () +runMergeObjects dflags args = traceToolCommand dflags "merge-objects" $ do + let (p,args0) = pgm_lm dflags + optl_args = map Option (getOpts dflags opt_lm) + args2 = args0 ++ args ++ optl_args + -- N.B. Darwin's ld64 doesn't support response files. Consequently we only + -- use them on Windows where they are truly necessary. +#if defined(mingw32_HOST_OS) + mb_env <- getGccEnv args2 + runSomethingResponseFile dflags id "Merge objects" p args2 mb_env +#else + runSomething dflags "Merge objects" p args2 +#endif runLibtool :: DynFlags -> [Option] -> IO () runLibtool dflags args = traceToolCommand dflags "libtool" $ do ===================================== compiler/main/ToolSettings.hs ===================================== @@ -25,6 +25,7 @@ data ToolSettings = ToolSettings , toolSettings_pgm_c :: String , toolSettings_pgm_a :: (String, [Option]) , toolSettings_pgm_l :: (String, [Option]) + , toolSettings_pgm_lm :: (String, [Option]) , toolSettings_pgm_dll :: (String, [Option]) , toolSettings_pgm_T :: String , toolSettings_pgm_windres :: String @@ -50,6 +51,7 @@ data ToolSettings = ToolSettings , toolSettings_opt_cxx :: [String] , toolSettings_opt_a :: [String] , toolSettings_opt_l :: [String] + , toolSettings_opt_lm :: [String] , toolSettings_opt_windres :: [String] , -- | LLVM: llvm optimiser toolSettings_opt_lo :: [String] ===================================== configure.ac ===================================== @@ -577,13 +577,12 @@ dnl ** Which ld to use dnl -------------------------------------------------------------- AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.]) FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" -LdNoGoldCmd="$LD_NO_GOLD" CFLAGS="$CFLAGS $GccUseLdOpt" AC_SUBST([LdCmd]) -AC_SUBST([LdNoGoldCmd]) FP_PROG_LD_IS_GNU FP_PROG_LD_BUILD_ID ===================================== distrib/configure.ac.in ===================================== @@ -102,6 +102,7 @@ FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) dnl ** Which ld to use? dnl -------------------------------------------------------------- FIND_LD([$target],[GccUseLdOpt]) +FIND_MERGE_OBJECTS() CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt" CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt" LdCmd="$LD" ===================================== docs/users_guide/phases.rst ===================================== @@ -73,6 +73,14 @@ given compilation phase: Use ⟨cmd⟩ as the linker. +.. ghc-flag:: -pgmlm ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the linker when merging object files + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the linker when merging object files (e.g. when generating + joined objects for loading into GHCi). + .. ghc-flag:: -pgmdll ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the DLL generator :type: dynamic @@ -189,6 +197,14 @@ the following flags: Pass ⟨option⟩ to the linker. +.. ghc-flag:: -optlm ⟨option⟩ + :shortdesc: pass ⟨option⟩ to the linker when merging object files. + :type: dynamic + :category: phase-options + + Pass ⟨option⟩ to the linker when merging object files. In the case of a + standard ``ld``-style linker this should generally include the ``-r`` flag. + .. ghc-flag:: -optdll ⟨option⟩ :shortdesc: pass ⟨option⟩ to the DLL generator :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -114,6 +114,12 @@ conf-ld-linker-args-stage1 = @CONF_LD_LINKER_OPTS_STAGE1@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@ conf-ld-linker-args-stage3 = @CONF_LD_LINKER_OPTS_STAGE3@ +conf-merge-objects-args-stage0 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage1 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage2 = @SettingsMergeObjectsFlags@ +conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ + + # Settings: #========== @@ -137,6 +143,8 @@ settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@ settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@ settings-ld-command = @SettingsLdCommand@ settings-ld-flags = @SettingsLdFlags@ +settings-merge-objects-command = @SettingsMergeObjectsCommand@ +settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ ===================================== hadrian/hadrian.cabal ===================================== @@ -97,6 +97,7 @@ executable hadrian , Settings.Builders.HsCpp , Settings.Builders.Ld , Settings.Builders.Make + , Settings.Builders.MergeObjects , Settings.Builders.RunTest , Settings.Builders.Xelatex , Settings.Default ===================================== hadrian/src/Builder.hs ===================================== @@ -125,9 +125,10 @@ data Builder = Alex | Hpc | HsCpp | Hsc2Hs Stage - | Ld Stage + | Ld Stage --- ^ linker | Make FilePath | Makeinfo + | MergeObjects Stage -- ^ linker to be used to merge object files. | Nm | Objdump | Patch @@ -312,6 +313,7 @@ systemBuilderPath builder = case builder of Happy -> fromKey "happy" HsCpp -> fromKey "hs-cpp" Ld _ -> fromKey "ld" + MergeObjects _ -> fromKey "settings-merge-objects-command" Make _ -> fromKey "make" Makeinfo -> fromKey "makeinfo" Nm -> fromKey "nm" ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -90,6 +90,7 @@ data SettingList = ConfCcArgs Stage | ConfCppArgs Stage | ConfGccLinkerArgs Stage | ConfLdLinkerArgs Stage + | ConfMergeObjectsArgs Stage | HsCppArgs -- TODO compute solely in Hadrian, removing these variables' definitions @@ -108,6 +109,8 @@ data SettingsFileSetting | SettingsFileSetting_CCompilerSupportsNoPie | SettingsFileSetting_LdCommand | SettingsFileSetting_LdFlags + | SettingsFileSetting_MergeObjectsCommand + | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand | SettingsFileSetting_DllWrapCommand @@ -175,6 +178,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of ConfCppArgs stage -> "conf-cpp-args-" ++ stageString stage ConfGccLinkerArgs stage -> "conf-gcc-linker-args-" ++ stageString stage ConfLdLinkerArgs stage -> "conf-ld-linker-args-" ++ stageString stage + ConfMergeObjectsArgs stage -> "conf-merge-objects-args-" ++ stageString stage HsCppArgs -> "hs-cpp-args" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the @@ -190,6 +194,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerSupportsNoPie -> "settings-c-compiler-supports-no-pie" SettingsFileSetting_LdCommand -> "settings-ld-command" SettingsFileSetting_LdFlags -> "settings-ld-flags" + SettingsFileSetting_MergeObjectsCommand -> "settings-merge-objects-command" + SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -288,6 +288,8 @@ generateSettings = do , ("ld supports build-id", expr $ lookupValueOrError configFile "ld-has-build-id") , ("ld supports filelist", expr $ lookupValueOrError configFile "ld-has-filelist") , ("ld is GNU ld", expr $ lookupValueOrError configFile "ld-is-gnu-ld") + , ("Merge objects command", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsCommand) + , ("Merge objects flags", expr $ settingsFileSetting SettingsFileSetting_MergeObjectsFlags) , ("ar command", expr $ settingsFileSetting SettingsFileSetting_ArCommand) , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) ===================================== hadrian/src/Rules/Library.hs ===================================== @@ -91,6 +91,7 @@ buildDynamicLibUnix root suffix dynlibpath = do -- | Build a "GHCi library" ('LibGhci') under the given build root, with the -- complete path of the file to build is given as the second argument. +-- See Note [Merging object files for GHCi] in GHC.Driver.Pipeline. buildGhciLibO :: FilePath -> FilePath -> Action () buildGhciLibO root ghcilibPath = do l@(BuildPath _ stage _ (LibGhci _ _ _)) @@ -100,7 +101,7 @@ buildGhciLibO root ghcilibPath = do let context = libGhciContext l objs <- allObjects context need objs - build $ target context (Ld stage) objs [ghcilibPath] + build $ target context (MergeObjects stage) objs [ghcilibPath] -- * Helpers ===================================== hadrian/src/Settings/Builders/Ld.hs ===================================== @@ -4,6 +4,5 @@ import Settings.Builders.Common ldBuilderArgs :: Args ldBuilderArgs = builder Ld ? mconcat [ getStagedSettingList ConfLdLinkerArgs - , arg "-r" , arg "-o", arg =<< getOutput , getInputs ] ===================================== hadrian/src/Settings/Builders/MergeObjects.hs ===================================== @@ -0,0 +1,9 @@ +module Settings.Builders.MergeObjects (mergeObjectsBuilderArgs) where + +import Settings.Builders.Common + +mergeObjectsBuilderArgs :: Args +mergeObjectsBuilderArgs = builder MergeObjects ? mconcat + [ getStagedSettingList ConfMergeObjectsArgs + , arg "-o", arg =<< getOutput + , getInputs ] ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -38,6 +38,7 @@ import Settings.Builders.Hsc2Hs import Settings.Builders.HsCpp import Settings.Builders.Ld import Settings.Builders.Make +import Settings.Builders.MergeObjects import Settings.Builders.RunTest import Settings.Builders.Xelatex import Settings.Packages @@ -246,6 +247,7 @@ defaultBuilderArgs = mconcat , hsCppBuilderArgs , ldBuilderArgs , makeBuilderArgs + , mergeObjectsBuilderArgs , runTestBuilderArgs , validateBuilderArgs , xelatexBuilderArgs ===================================== includes/ghc.mk ===================================== @@ -162,7 +162,7 @@ $$(includes_$1_H_PLATFORM) : includes/ghc.mk includes/Makefile | $$$$(dir $$$$@) @echo "#if !defined(__GHCPLATFORM_H__)" > $$@ @echo "#define __GHCPLATFORM_H__" >> $$@ @echo >> $$@ - @echo "#define GHC_STAGE $1" >> $$@ + @echo "#define GHC_STAGE ($1 + 1)" >> $$@ @echo >> $$@ @echo "#define BuildPlatform_TYPE $(BuildPlatform_$1_CPP)" >> $$@ @echo "#define HostPlatform_TYPE $(HostPlatform_$1_CPP)" >> $$@ @@ -222,6 +222,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@ @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@ @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@ + @echo ',("Merge objects command", "$(SettingsMergeObjectsCommand)")' >> $@ + @echo ',("Merge objects flags", "$(SettingsMergeObjectsFlags)")' >> $@ @echo ',("ar command", "$(SettingsArCommand)")' >> $@ @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -512,6 +512,8 @@ SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@ SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@ SettingsLdCommand = @SettingsLdCommand@ SettingsLdFlags = @SettingsLdFlags@ +SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ +SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ @@ -745,7 +747,6 @@ HaveDtrace = @HaveDtrace@ USE_DTRACE = $(HaveDtrace) DTRACE = @DtraceCmd@ -LD_NO_GOLD = @LdNoGoldCmd@ LD = @LdCmd@ NM = @NmCmd@ AR = @ArCmd@ ===================================== rules/build-package-way.mk ===================================== @@ -116,11 +116,7 @@ BINDIST_LIBS += $$($1_$2_$3_GHCI_LIB) endif endif $$($1_$2_$3_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) $$($1_$2_LD_SCRIPT) - $$(call cmd,LD_NO_GOLD) $$(CONF_LD_LINKER_OPTS_STAGE$4) -r $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) -# NB. LD_NO_GOLD above: see #14328 (symptoms: #14675,#14291). At least -# some versions of ld.gold appear to have a bug that causes the -# generated GHCi library to have some bogus relocations. Performance -# isn't critical here, so we fall back to the ordinary ld. + $$(call cmd,SettingsMergeObjectsCommand) $(SettingsMergeObjectsFlags) $$(if $$($1_$2_LD_SCRIPT),$$($1_$2_LD_SCRIPT_CMD) $$($1_$2_LD_SCRIPT)) -o $$@ $$(EXTRA_LD_LINKER_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS) ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES" # Don't bother making ghci libs for bootstrapping packages ifneq "$4" "0" ===================================== utils/iserv/ghc.mk ===================================== @@ -30,9 +30,8 @@ endif # refer to the RTS. This is harmless if you don't use it (adds a bit # of overhead to startup and increases the binary sizes) but if you # need it there's no alternative. -# Don't do this on FreeBSD to work around #17962. ifeq "$(TargetElf)" "YES" -ifeq "$(findstring $(TargetOS_CPP), solaris2 freebsd)" "" +ifneq "$(TargetOS_CPP)" "solaris2" # The Solaris linker does not support --export-dynamic option. It also # does not need it since it exports all dynamic symbols by default utils/iserv_stage2_MORE_HC_OPTS += -optl-Wl,--export-dynamic View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/81134748910b940eff5701c733ae2daaaa88ad58...e69b0d42d88794837694429d33667c2f20931820 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/81134748910b940eff5701c733ae2daaaa88ad58...e69b0d42d88794837694429d33667c2f20931820 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 14:12:59 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 05 Aug 2020 10:12:59 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 5 commits: Grammar for types and data/newtype constructors Message-ID: <5f2abe6b43d6d_80b3f848a372f8c6645829@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: cc620773 by Vladislav Zavialov at 2020-08-05T10:12:50-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 7125c171 by Vladislav Zavialov at 2020-08-05T10:12:50-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 3dff6731 by Vladislav Zavialov at 2020-08-05T10:12:50-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - a623263e by Vladislav Zavialov at 2020-08-05T10:12:50-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - e935b566 by Richard Eisenberg at 2020-08-05T10:12:51-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 20 changed files: - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Tc/TyCl.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.stdout - testsuite/tests/ghc-api/all.T - testsuite/tests/parser/should_fail/T12045d.stderr - testsuite/tests/parser/should_fail/strictnessDataCon_B.stderr - testsuite/tests/parser/should_fail/typeops_A.stderr - testsuite/tests/parser/should_fail/typeops_C.stderr - testsuite/tests/parser/should_fail/unpack_empty_type.stderr - testsuite/tests/parser/should_fail/unpack_inside_type.stderr - + testsuite/tests/polykinds/T18522-ppr.script - + testsuite/tests/polykinds/T18522-ppr.stdout - testsuite/tests/polykinds/all.T - + testsuite/tests/typecheck/should_fail/T18534.hs - + testsuite/tests/typecheck/should_fail/T18534.stderr - testsuite/tests/typecheck/should_fail/all.T Changes: ===================================== compiler/GHC/Core/TyCo/Ppr.hs ===================================== @@ -36,7 +36,8 @@ import {-# SOURCE #-} GHC.CoreToIface import {-# SOURCE #-} GHC.Core.DataCon ( dataConFullSig , dataConUserTyVarBinders, DataCon ) -import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many ) +import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many, + splitForAllTysReq, splitForAllTysInvis ) import GHC.Core.TyCon import GHC.Core.TyCo.Rep @@ -268,19 +269,34 @@ debug_ppr_ty prec (CastTy ty co) debug_ppr_ty _ (CoercionTy co) = parens (text "CO" <+> ppr co) -debug_ppr_ty prec ty@(ForAllTy {}) - | (tvs, body) <- split ty +-- Invisible forall: forall {k} (a :: k). t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysInvis t + , not (null bndrs) = maybeParen prec funPrec $ - hang (text "forall" <+> fsep (map ppr tvs) <> dot) - -- The (map ppr tvs) will print kind-annotated - -- tvs, because we are (usually) in debug-style - 2 (ppr body) + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <> dot, + ppr body ] where - split ty | ForAllTy tv ty' <- ty - , (tvs, body) <- split ty' - = (tv:tvs, body) - | otherwise - = ([], ty) + -- (ppr tv) will print the binder kind-annotated + -- when in debug-style + ppr_bndr (Bndr tv InferredSpec) = braces (ppr tv) + ppr_bndr (Bndr tv SpecifiedSpec) = ppr tv + +-- Visible forall: forall x y -> t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysReq t + , not (null bndrs) + = maybeParen prec funPrec $ + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <+> arrow, + ppr body ] + where + -- (ppr tv) will print the binder kind-annotated + -- when in debug-style + ppr_bndr (Bndr tv ()) = ppr tv + +-- Impossible case: neither visible nor invisible forall. +debug_ppr_ty _ ForAllTy{} + = panic "debug_ppr_ty: neither splitForAllTysInvis nor splitForAllTysReq returned any binders" {- Note [Infix type variables] ===================================== compiler/GHC/Iface/Type.hs ===================================== @@ -441,6 +441,7 @@ splitIfaceSigmaTy ty (theta, tau) = split_rho rho split_foralls (IfaceForAllTy bndr ty) + | isInvisibleArgFlag (binderArgFlag bndr) = case split_foralls ty of { (bndrs, rho) -> (bndr:bndrs, rho) } split_foralls rho = ([], rho) @@ -448,6 +449,12 @@ splitIfaceSigmaTy ty = case split_rho ty2 of { (ps, tau) -> (ty1:ps, tau) } split_rho tau = ([], tau) +splitIfaceReqForallTy :: IfaceType -> ([IfaceForAllBndr], IfaceType) +splitIfaceReqForallTy (IfaceForAllTy bndr ty) + | isVisibleArgFlag (binderArgFlag bndr) + = case splitIfaceReqForallTy ty of { (bndrs, rho) -> (bndr:bndrs, rho) } +splitIfaceReqForallTy rho = ([], rho) + suppressIfaceInvisibles :: PrintExplicitKinds -> [IfaceTyConBinder] -> [a] -> [a] suppressIfaceInvisibles (PrintExplicitKinds True) _tys xs = xs suppressIfaceInvisibles (PrintExplicitKinds False) tys xs = suppress tys xs @@ -1184,8 +1191,23 @@ pprIfaceSigmaType show_forall ty = hideNonStandardTypes ppr_fn ty where ppr_fn iface_ty = - let (tvs, theta, tau) = splitIfaceSigmaTy iface_ty - in ppr_iface_forall_part show_forall tvs theta (ppr tau) + let (invis_tvs, theta, tau) = splitIfaceSigmaTy iface_ty + (req_tvs, tau') = splitIfaceReqForallTy tau + -- splitIfaceSigmaTy is recursive, so it will gather the binders after + -- the theta, i.e. forall a. theta => forall b. tau + -- will give you ([a,b], theta, tau). + -- + -- This isn't right when it comes to visible forall (see + -- testsuite/tests/polykinds/T18522-ppr), + -- so we split off required binders separately, + -- using splitIfaceReqForallTy. + -- + -- An alternative solution would be to make splitIfaceSigmaTy + -- non-recursive (see #18458). + -- Then it could handle both invisible and required binders, and + -- splitIfaceReqForallTy wouldn't be necessary here. + in ppr_iface_forall_part show_forall invis_tvs theta $ + sep [pprIfaceForAll req_tvs, ppr tau'] pprUserIfaceForAll :: [IfaceForAllBndr] -> SDoc pprUserIfaceForAll tvs ===================================== compiler/GHC/Parser.y ===================================== @@ -1080,7 +1080,7 @@ topdecl :: { LHsDecl GhcPs } -- The $(..) form is one possible form of infixexp -- but we treat an arbitrary expression just as if -- it had a $(..) wrapped around it - | infixexp {% runECP_P $1 >>= \ $1 -> + | infixexp {% runPV (unECP $1) >>= \ $1 -> return $ sLL $1 $> $ mkSpliceDecl $1 } -- Type classes @@ -1528,7 +1528,7 @@ decl_cls : at_decl_cls { $1 } -- A 'default' signature used with the generic-programming extension | 'default' infixexp '::' sigtype - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> do { v <- checkValSigLhs $2 ; let err = text "in default signature" <> colon <+> quotes (ppr $2) @@ -1671,8 +1671,8 @@ rules :: { OrdList (LRuleDecl GhcPs) } rule :: { LRuleDecl GhcPs } : STRING rule_activation rule_foralls infixexp '=' exp - {%runECP_P $4 >>= \ $4 -> - runECP_P $6 >>= \ $6 -> + {%runPV (unECP $4) >>= \ $4 -> + runPV (unECP $6) >>= \ $6 -> ams (sLL $1 $> $ HsRule { rd_ext = noExtField , rd_name = L (gl $1) (getSTRINGs $1, getSTRING $1) , rd_act = (snd $2) `orElse` AlwaysActive @@ -1800,19 +1800,19 @@ stringlist :: { Located (OrdList (Located StringLiteral)) } ----------------------------------------------------------------------------- -- Annotations annotation :: { LHsDecl GhcPs } - : '{-# ANN' name_var aexp '#-}' {% runECP_P $3 >>= \ $3 -> + : '{-# ANN' name_var aexp '#-}' {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) (ValueAnnProvenance $2) $3)) [mo $1,mc $4] } - | '{-# ANN' 'type' tycon aexp '#-}' {% runECP_P $4 >>= \ $4 -> + | '{-# ANN' 'type' tycon aexp '#-}' {% runPV (unECP $4) >>= \ $4 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) (TypeAnnProvenance $3) $4)) [mo $1,mj AnnType $2,mc $5] } - | '{-# ANN' 'module' aexp '#-}' {% runECP_P $3 >>= \ $3 -> + | '{-# ANN' 'module' aexp '#-}' {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) ModuleAnnProvenance $3)) @@ -1966,22 +1966,28 @@ type :: { LHsType GhcPs } mult :: { LHsType GhcPs } : btype { $1 } - btype :: { LHsType GhcPs } - : tyapps {% mergeOps (unLoc $1) } - -tyapps :: { Located [Located TyEl] } -- NB: This list is reversed - : tyapp { sL1 $1 [$1] } - | tyapps tyapp { sLL $1 $> $ $2 : unLoc $1 } - -tyapp :: { Located TyEl } - : atype { sL1 $1 $ TyElOpd (unLoc $1) } - - -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer - | PREFIX_AT atype { sLL $1 $> $ (TyElKindApp (comb2 $1 $2) $2) } - - | tyop { mapLoc TyElOpr $1 } - | unpackedness { sL1 $1 $ TyElUnpackedness (unLoc $1) } + : infixtype {% runPV $1 } + +infixtype :: { forall b. DisambTD b => PV (Located b) } + : ftype { $1 } + | ftype tyop infixtype { $1 >>= \ $1 -> + $3 >>= \ $3 -> + mkHsOpTyPV $1 $2 $3 } + | unpackedness infixtype { $2 >>= \ $2 -> + mkUnpackednessPV $1 $2 } + +ftype :: { forall b. DisambTD b => PV (Located b) } + : atype { mkHsAppTyHeadPV $1 } + | tyop { failOpFewArgs $1 } + | ftype tyarg { $1 >>= \ $1 -> + mkHsAppTyPV $1 $2 } + | ftype PREFIX_AT tyarg { $1 >>= \ $1 -> + mkHsAppKindTyPV $1 (getLoc $2) $3 } + +tyarg :: { LHsType GhcPs } + : atype { $1 } + | unpackedness atype {% addUnpackednessP $1 $2 } tyop :: { Located RdrName } : qtyconop { $1 } @@ -2222,8 +2228,9 @@ forall :: { Located ([AddAnn], Maybe [LHsTyVarBndr Specificity GhcPs]) } | {- empty -} { noLoc ([], Nothing) } constr_stuff :: { Located (Located RdrName, HsConDeclDetails GhcPs) } - : tyapps {% do { c <- mergeDataCon (unLoc $1) - ; return $ sL1 $1 c } } + : infixtype {% fmap (mapLoc (\b -> (dataConBuilderCon b, + dataConBuilderDetails b))) + (runPV $1) } fielddecls :: { [LConDeclField GhcPs] } : {- empty -} { [] } @@ -2308,7 +2315,7 @@ There's an awkward overlap with a type signature. Consider decl_no_th :: { LHsDecl GhcPs } : sigdecl { $1 } - | infixexp opt_sig rhs {% runECP_P $1 >>= \ $1 -> + | infixexp opt_sig rhs {% runPV (unECP $1) >>= \ $1 -> do { (ann,r) <- checkValDef $1 (snd $2) $3; let { l = comb2 $1 $> }; -- Depending upon what the pattern looks like we might get either @@ -2332,7 +2339,7 @@ decl :: { LHsDecl GhcPs } | splice_exp { sLL $1 $> $ mkSpliceDecl $1 } rhs :: { Located ([AddAnn],GRHSs GhcPs (LHsExpr GhcPs)) } - : '=' exp wherebinds {% runECP_P $2 >>= \ $2 -> return $ + : '=' exp wherebinds {% runPV (unECP $2) >>= \ $2 -> return $ sL (comb3 $1 $2 $3) ((mj AnnEqual $1 : (fst $ unLoc $3)) ,GRHSs noExtField (unguardedRHS (comb3 $1 $2 $3) $2) @@ -2346,7 +2353,7 @@ gdrhs :: { Located [LGRHS GhcPs (LHsExpr GhcPs)] } | gdrh { sL1 $1 [$1] } gdrh :: { LGRHS GhcPs (LHsExpr GhcPs) } - : '|' guardquals '=' exp {% runECP_P $4 >>= \ $4 -> + : '|' guardquals '=' exp {% runPV (unECP $4) >>= \ $4 -> ams (sL (comb2 $1 $>) $ GRHS noExtField (unLoc $2) $4) [mj AnnVbar $1,mj AnnEqual $3] } @@ -2354,7 +2361,7 @@ sigdecl :: { LHsDecl GhcPs } : -- See Note [Declaration/signature overlap] for why we need infixexp here infixexp '::' sigtype - {% do { $1 <- runECP_P $1 + {% do { $1 <- runPV (unECP $1) ; v <- checkValSigLhs $1 ; _ <- amsL (comb2 $1 $>) [mu AnnDcolon $2] ; return (sLL $1 $> $ SigD noExtField $ @@ -2450,30 +2457,30 @@ quasiquote :: { Located (HsSplice GhcPs) } exp :: { ECP } : infixexp '::' sigtype { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> rejectPragmaPV $1 >> amms (mkHsTySigPV (comb2 $1 $>) $1 $3) [mu AnnDcolon $2] } - | infixexp '-<' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '-<' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $1 $3 HsFirstOrderApp True) [mu Annlarrowtail $2] } - | infixexp '>-' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '>-' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $3 $1 HsFirstOrderApp False) [mu Annrarrowtail $2] } - | infixexp '-<<' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '-<<' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $1 $3 HsHigherOrderApp True) [mu AnnLarrowtail $2] } - | infixexp '>>-' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '>>-' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $3 $1 HsHigherOrderApp False) @@ -2487,8 +2494,8 @@ infixexp :: { ECP } { ECP $ superInfixOp $ $2 >>= \ $2 -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> rejectPragmaPV $1 >> amms (mkHsOpAppPV (comb2 $1 $>) $1 $2 $3) [mj AnnVal $2] } @@ -2500,14 +2507,14 @@ exp10p :: { ECP } exp_prag(e) :: { ECP } : prag_e e -- See Note [Pragmas and operator fixity] - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsPragE noExtField (snd $ unLoc $1) $2) (fst $ unLoc $1) } exp10 :: { ECP } : '-' fexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsNegAppPV (comb2 $1 $>) $2) [mj AnnMinus $1] } | fexp { $1 } @@ -2590,16 +2597,16 @@ prag_e :: { Located ([AddAnn], HsPragE GhcPs) } fexp :: { ECP } : fexp aexp { ECP $ superFunArg $ - runECP_PV $1 >>= \ $1 -> - runECP_PV $2 >>= \ $2 -> + unECP $1 >>= \ $1 -> + unECP $2 >>= \ $2 -> mkHsAppPV (comb2 $1 $>) $1 $2 } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer | fexp PREFIX_AT atype { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> amms (mkHsAppTypePV (comb2 $1 $>) $1 $3) [mj AnnAt $2] } - | 'static' aexp {% runECP_P $2 >>= \ $2 -> + | 'static' aexp {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsStatic noExtField $2) [mj AnnStatic $1] } @@ -2609,23 +2616,23 @@ aexp :: { ECP } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer : qvar TIGHT_INFIX_AT aexp { ECP $ - runECP_PV $3 >>= \ $3 -> + unECP $3 >>= \ $3 -> amms (mkHsAsPatPV (comb2 $1 $>) $1 $3) [mj AnnAt $2] } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer | PREFIX_TILDE aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsLazyPatPV (comb2 $1 $>) $2) [mj AnnTilde $1] } | PREFIX_BANG aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsBangPatPV (comb2 $1 $>) $2) [mj AnnBang $1] } | PREFIX_MINUS aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsNegAppPV (comb2 $1 $>) $2) [mj AnnMinus $1] } | '\\' apat apats '->' exp { ECP $ - runECP_PV $5 >>= \ $5 -> + unECP $5 >>= \ $5 -> amms (mkHsLamPV (comb2 $1 $>) (mkMatchGroup FromSource [sLL $1 $> $ Match { m_ext = noExtField , m_ctxt = LambdaExpr @@ -2633,7 +2640,7 @@ aexp :: { ECP } , m_grhss = unguardedGRHSs $5 }])) [mj AnnLam $1, mu AnnRarrow $4] } | 'let' binds 'in' exp { ECP $ - runECP_PV $4 >>= \ $4 -> + unECP $4 >>= \ $4 -> amms (mkHsLetPV (comb2 $1 $>) (snd (unLoc $2)) $4) (mj AnnLet $1:mj AnnIn $3 :(fst $ unLoc $2)) } @@ -2643,10 +2650,10 @@ aexp :: { ECP } (mkMatchGroup FromSource (snd $ unLoc $3))) (mj AnnLam $1:mj AnnCase $2:(fst $ unLoc $3)) } | 'if' exp optSemi 'then' exp optSemi 'else' exp - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> return $ ECP $ - runECP_PV $5 >>= \ $5 -> - runECP_PV $8 >>= \ $8 -> + unECP $5 >>= \ $5 -> + unECP $8 >>= \ $8 -> amms (mkHsIfPV (comb2 $1 $>) $2 (snd $3) $5 (snd $6) $8) (mj AnnIf $1:mj AnnThen $4 :mj AnnElse $7 @@ -2657,7 +2664,7 @@ aexp :: { ECP } ams (sLL $1 $> $ HsMultiIf noExtField (reverse $ snd $ unLoc $2)) (mj AnnIf $1:(fst $ unLoc $2)) } - | 'case' exp 'of' altslist {% runECP_P $2 >>= \ $2 -> + | 'case' exp 'of' altslist {% runPV (unECP $2) >>= \ $2 -> return $ ECP $ $4 >>= \ $4 -> amms (mkHsCasePV (comb3 $1 $3 $4) $2 (mkMatchGroup @@ -2681,8 +2688,8 @@ aexp :: { ECP } (snd $ unLoc $2))) (mj AnnMdo $1:(fst $ unLoc $2)) } | 'proc' aexp '->' exp - {% (checkPattern <=< runECP_P) $2 >>= \ p -> - runECP_P $4 >>= \ $4 at cmd -> + {% (checkPattern <=< runPV) (unECP $2) >>= \ p -> + runPV (unECP $4) >>= \ $4 at cmd -> fmap ecpFromExp $ ams (sLL $1 $> $ HsProc noExtField p (sLL $1 $> $ HsCmdTop noExtField cmd)) -- TODO: is LL right here? @@ -2692,7 +2699,7 @@ aexp :: { ECP } aexp1 :: { ECP } : aexp1 '{' fbinds '}' { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> $3 >>= \ $3 -> amms (mkHsRecordPV (comb2 $1 $>) (comb2 $2 $4) $1 (snd $3)) (moc $2:mcc $4:(fst $3)) } @@ -2716,7 +2723,7 @@ aexp2 :: { ECP } -- correct Haskell (you'd have to write '((+ 3), (4 -))') -- but the less cluttered version fell out of having texps. | '(' texp ')' { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsParPV (comb2 $1 $>) $2) [mop $1,mcp $3] } | '(' tup_exprs ')' { ECP $ $2 >>= \ $2 -> @@ -2724,7 +2731,7 @@ aexp2 :: { ECP } ((mop $1:fst $2) ++ [mcp $3]) } | '(#' texp '#)' { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkSumOrTuplePV (comb2 $1 $>) Unboxed (Tuple [L (gl $2) (Just $2)])) [mo $1,mc $3] } | '(#' tup_exprs '#)' { ECP $ @@ -2744,18 +2751,18 @@ aexp2 :: { ECP } | TH_TY_QUOTE tyvar {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } | TH_TY_QUOTE gtycon {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } | TH_TY_QUOTE {- nothing -} {% reportEmptyDoubleQuotes (getLoc $1) } - | '[|' exp '|]' {% runECP_P $2 >>= \ $2 -> + | '[|' exp '|]' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (ExpBr noExtField $2)) (if (hasE $1) then [mj AnnOpenE $1, mu AnnCloseQ $3] else [mu AnnOpenEQ $1,mu AnnCloseQ $3]) } - | '[||' exp '||]' {% runECP_P $2 >>= \ $2 -> + | '[||' exp '||]' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (TExpBr noExtField $2)) (if (hasE $1) then [mj AnnOpenE $1,mc $3] else [mo $1,mc $3]) } | '[t|' ktype '|]' {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (TypBr noExtField $2)) [mo $1,mu AnnCloseQ $3] } - | '[p|' infixexp '|]' {% (checkPattern <=< runECP_P) $2 >>= \p -> + | '[p|' infixexp '|]' {% (checkPattern <=< runPV) (unECP $2) >>= \p -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (PatBr noExtField p)) [mo $1,mu AnnCloseQ $3] } @@ -2765,7 +2772,7 @@ aexp2 :: { ECP } | quasiquote { ECP $ mkHsSplicePV $1 } -- arrow notation extension - | '(|' aexp cmdargs '|)' {% runECP_P $2 >>= \ $2 -> + | '(|' aexp cmdargs '|)' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrForm noExtField $2 Prefix Nothing (reverse $3)) @@ -2777,14 +2784,14 @@ splice_exp :: { LHsExpr GhcPs } splice_untyped :: { Located (HsSplice GhcPs) } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer - : PREFIX_DOLLAR aexp2 {% runECP_P $2 >>= \ $2 -> + : PREFIX_DOLLAR aexp2 {% runPV (unECP $2) >>= \ $2 -> ams (sLL $1 $> $ mkUntypedSplice DollarSplice $2) [mj AnnDollar $1] } splice_typed :: { Located (HsSplice GhcPs) } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer : PREFIX_DOLLAR_DOLLAR aexp2 - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> ams (sLL $1 $> $ mkTypedSplice DollarSplice $2) [mj AnnDollarDollar $1] } @@ -2793,7 +2800,7 @@ cmdargs :: { [LHsCmdTop GhcPs] } | {- empty -} { [] } acmd :: { LHsCmdTop GhcPs } - : aexp {% runECP_P $1 >>= \ cmd -> + : aexp {% runPV (unECP $1) >>= \ cmd -> runPV (checkCmdBlockArguments cmd) >>= \ _ -> return (sL1 cmd $ HsCmdTop noExtField cmd) } @@ -2827,21 +2834,21 @@ texp :: { ECP } -- Meanwhile, the renamer checks that real sections appear -- inside parens. | infixexp qop - {% runECP_P $1 >>= \ $1 -> + {% runPV (unECP $1) >>= \ $1 -> runPV (rejectPragmaPV $1) >> runPV $2 >>= \ $2 -> return $ ecpFromExp $ sLL $1 $> $ SectionL noExtField $1 $2 } | qopm infixexp { ECP $ superInfixOp $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> $1 >>= \ $1 -> mkHsSectionR_PV (comb2 $1 $>) $1 $2 } -- View patterns get parenthesized above | exp '->' texp { ECP $ - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> amms (mkHsViewPatPV (comb2 $1 $>) $1 $3) [mu AnnRarrow $2] } -- Always at least one comma or bar. @@ -2850,12 +2857,12 @@ texp :: { ECP } -- in GHC.Hs.Expr. tup_exprs :: { forall b. DisambECP b => PV ([AddAnn],SumOrTuple b) } : texp commas_tup_tail - { runECP_PV $1 >>= \ $1 -> + { unECP $1 >>= \ $1 -> $2 >>= \ $2 -> do { addAnnotation (gl $1) AnnComma (fst $2) ; return ([],Tuple ((sL1 $1 (Just $1)) : snd $2)) } } - | texp bars { runECP_PV $1 >>= \ $1 -> return $ + | texp bars { unECP $1 >>= \ $1 -> return $ (mvbars (fst $2), Sum 1 (snd $2 + 1) $1) } | commas tup_tail @@ -2865,7 +2872,7 @@ tup_exprs :: { forall b. DisambECP b => PV ([AddAnn],SumOrTuple b) } ([],Tuple (map (\l -> L l Nothing) (fst $1) ++ $2)) } } | bars texp bars0 - { runECP_PV $2 >>= \ $2 -> return $ + { unECP $2 >>= \ $2 -> return $ (mvbars (fst $1) ++ mvbars (fst $3), Sum (snd $1 + 1) (snd $1 + snd $3 + 1) $2) } -- Always starts with commas; always follows an expr @@ -2879,11 +2886,11 @@ commas_tup_tail : commas tup_tail -- Always follows a comma tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] } - : texp commas_tup_tail { runECP_PV $1 >>= \ $1 -> + : texp commas_tup_tail { unECP $1 >>= \ $1 -> $2 >>= \ $2 -> addAnnotation (gl $1) AnnComma (fst $2) >> return ((L (gl $1) (Just $1)) : snd $2) } - | texp { runECP_PV $1 >>= \ $1 -> + | texp { unECP $1 >>= \ $1 -> return [L (gl $1) (Just $1)] } | {- empty -} { return [noLoc Nothing] } @@ -2894,48 +2901,48 @@ tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] } -- avoiding another shift/reduce-conflict. -- Never empty. list :: { forall b. DisambECP b => SrcSpan -> PV (Located b) } - : texp { \loc -> runECP_PV $1 >>= \ $1 -> + : texp { \loc -> unECP $1 >>= \ $1 -> mkHsExplicitListPV loc [$1] } | lexps { \loc -> $1 >>= \ $1 -> mkHsExplicitListPV loc (reverse $1) } - | texp '..' { \loc -> runECP_PV $1 >>= \ $1 -> + | texp '..' { \loc -> unECP $1 >>= \ $1 -> ams (L loc $ ArithSeq noExtField Nothing (From $1)) [mj AnnDotdot $2] >>= ecpFromExp' } | texp ',' exp '..' { \loc -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> ams (L loc $ ArithSeq noExtField Nothing (FromThen $1 $3)) [mj AnnComma $2,mj AnnDotdot $4] >>= ecpFromExp' } - | texp '..' exp { \loc -> runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + | texp '..' exp { \loc -> unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> ams (L loc $ ArithSeq noExtField Nothing (FromTo $1 $3)) [mj AnnDotdot $2] >>= ecpFromExp' } | texp ',' exp '..' exp { \loc -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> - runECP_PV $5 >>= \ $5 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> + unECP $5 >>= \ $5 -> ams (L loc $ ArithSeq noExtField Nothing (FromThenTo $1 $3 $5)) [mj AnnComma $2,mj AnnDotdot $4] >>= ecpFromExp' } | texp '|' flattenedpquals { \loc -> checkMonadComp >>= \ ctxt -> - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> ams (L loc $ mkHsComp ctxt (unLoc $3) $1) [mj AnnVbar $2] >>= ecpFromExp' } lexps :: { forall b. DisambECP b => PV [Located b] } : lexps ',' texp { $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $3 >>= \ $3 -> addAnnotation (gl $ head $ $1) AnnComma (gl $2) >> return (((:) $! $3) $! $1) } - | texp ',' texp { runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + | texp ',' texp { unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> addAnnotation (gl $1) AnnComma (gl $2) >> return [$3,$1] } @@ -2985,20 +2992,20 @@ squals :: { Located [LStmt GhcPs (LHsExpr GhcPs)] } -- In reverse order, becau transformqual :: { Located ([AddAnn],[LStmt GhcPs (LHsExpr GhcPs)] -> Stmt GhcPs (LHsExpr GhcPs)) } -- Function is applied to a list of stmts *in order* - : 'then' exp {% runECP_P $2 >>= \ $2 -> return $ + : 'then' exp {% runPV (unECP $2) >>= \ $2 -> return $ sLL $1 $> ([mj AnnThen $1], \ss -> (mkTransformStmt ss $2)) } - | 'then' exp 'by' exp {% runECP_P $2 >>= \ $2 -> - runECP_P $4 >>= \ $4 -> + | 'then' exp 'by' exp {% runPV (unECP $2) >>= \ $2 -> + runPV (unECP $4) >>= \ $4 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnBy $3], \ss -> (mkTransformByStmt ss $2 $4)) } | 'then' 'group' 'using' exp - {% runECP_P $4 >>= \ $4 -> + {% runPV (unECP $4) >>= \ $4 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnUsing $3], \ss -> (mkGroupUsingStmt ss $4)) } | 'then' 'group' 'by' exp 'using' exp - {% runECP_P $4 >>= \ $4 -> - runECP_P $6 >>= \ $6 -> + {% runPV (unECP $4) >>= \ $4 -> + runPV (unECP $6) >>= \ $6 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnBy $3,mj AnnUsing $5], \ss -> (mkGroupByUsingStmt ss $4 $6)) } @@ -3072,7 +3079,7 @@ alt_rhs :: { forall b. DisambECP b => PV (Located ([AddAnn],GRHSs GhcPs (Located return $ sLL alt $> (fst $ unLoc $2, GRHSs noExtField (unLoc alt) (snd $ unLoc $2)) } ralt :: { forall b. DisambECP b => PV (Located [LGRHS GhcPs (Located b)]) } - : '->' exp { runECP_PV $2 >>= \ $2 -> + : '->' exp { unECP $2 >>= \ $2 -> ams (sLL $1 $> (unguardedRHS (comb2 $1 $2) $2)) [mu AnnRarrow $1] } | gdpats { $1 >>= \gdpats -> @@ -3095,7 +3102,7 @@ ifgdpats :: { Located ([AddAnn],[LGRHS GhcPs (LHsExpr GhcPs)]) } gdpat :: { forall b. DisambECP b => PV (LGRHS GhcPs (Located b)) } : '|' guardquals '->' exp - { runECP_PV $4 >>= \ $4 -> + { unECP $4 >>= \ $4 -> ams (sL (comb2 $1 $>) $ GRHS noExtField (unLoc $2) $4) [mj AnnVbar $1,mu AnnRarrow $3] } @@ -3104,15 +3111,15 @@ gdpat :: { forall b. DisambECP b => PV (LGRHS GhcPs (Located b)) } -- Bangs inside are parsed as infix operator applications, so that -- we parse them right when bang-patterns are off pat :: { LPat GhcPs } -pat : exp {% (checkPattern <=< runECP_P) $1 } +pat : exp {% (checkPattern <=< runPV) (unECP $1) } bindpat :: { LPat GhcPs } -bindpat : exp {% -- See Note [Parser-Validator ReaderT SDoc] in GHC.Parser.PostProcess +bindpat : exp {% -- See Note [Parser-Validator Hint] in GHC.Parser.PostProcess checkPattern_msg (text "Possibly caused by a missing 'do'?") - (runECP_PV $1) } + (unECP $1) } apat :: { LPat GhcPs } -apat : aexp {% (checkPattern <=< runECP_P) $1 } +apat : aexp {% (checkPattern <=< runPV) (unECP $1) } apats :: { [LPat GhcPs] } : apat apats { $1 : $2 } @@ -3175,10 +3182,10 @@ stmt :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } (mj AnnRec $1:(fst $ unLoc $2)) } qual :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } - : bindpat '<-' exp { runECP_PV $3 >>= \ $3 -> + : bindpat '<-' exp { unECP $3 >>= \ $3 -> ams (sLL $1 $> $ mkPsBindStmt $1 $3) [mu AnnLarrow $2] } - | exp { runECP_PV $1 >>= \ $1 -> + | exp { unECP $1 >>= \ $1 -> return $ sL1 $1 $ mkBodyStmt $1 } | 'let' binds { ams (sLL $1 $> $ LetStmt noExtField (snd $ unLoc $2)) (mj AnnLet $1:(fst $ unLoc $2)) } @@ -3201,7 +3208,7 @@ fbinds1 :: { forall b. DisambECP b => PV ([AddAnn],([LHsRecField GhcPs (Located | '..' { return ([mj AnnDotdot $1],([], Just (getLoc $1))) } fbind :: { forall b. DisambECP b => PV (LHsRecField GhcPs (Located b)) } - : qvar '=' texp { runECP_PV $3 >>= \ $3 -> + : qvar '=' texp { unECP $3 >>= \ $3 -> ams (sLL $1 $> $ HsRecField (sL1 $1 $ mkFieldOcc $1) $3 False) [mj AnnEqual $2] } -- RHS is a 'texp', allowing view patterns (#6038) @@ -3227,7 +3234,7 @@ dbinds :: { Located [LIPBind GhcPs] } -- | {- empty -} { [] } dbind :: { LIPBind GhcPs } -dbind : ipvar '=' exp {% runECP_P $3 >>= \ $3 -> +dbind : ipvar '=' exp {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (IPBind noExtField (Left $1) $3)) [mj AnnEqual $2] } ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -68,7 +68,6 @@ module GHC.Parser.PostProcess ( checkRecordSyntax, checkEmptyGADTs, addFatalError, hintBangPat, - TyEl(..), mergeOps, mergeDataCon, mkBangTy, UnpackednessPragma(..), @@ -96,13 +95,19 @@ module GHC.Parser.PostProcess ( -- Expression/command/pattern ambiguity resolution PV, runPV, - ECP(ECP, runECP_PV), - runECP_P, + ECP(ECP, unECP), DisambInfixOp(..), DisambECP(..), ecpFromExp, ecpFromCmd, - PatBuilder + PatBuilder, + + -- Type/datacon ambiguity resolution + DisambTD(..), + addUnpackednessP, + DataConBuilder(), + dataConBuilderCon, + dataConBuilderDetails, ) where import GHC.Prelude @@ -126,20 +131,20 @@ import GHC.Types.ForeignCall import GHC.Builtin.Names ( allNameStrings ) import GHC.Types.SrcLoc import GHC.Types.Unique ( hasKey ) -import GHC.Data.OrdList ( OrdList, fromOL ) +import GHC.Data.OrdList import GHC.Utils.Outputable as Outputable import GHC.Data.FastString import GHC.Data.Maybe import GHC.Utils.Misc import GHC.Parser.Annotation import Data.List +import Data.Foldable import GHC.Driver.Session ( WarningFlag(..), DynFlags ) import GHC.Utils.Error ( Messages ) import Control.Monad import Text.ParserCombinators.ReadP as ReadP import Data.Char -import qualified Data.Monoid as Monoid import Data.Data ( dataTypeOf, fromConstr, dataTypeConstrs ) import Data.Kind ( Type ) @@ -559,30 +564,6 @@ context, so (C t1 t2) is a constraint and 'C' is a type constructor. As the result, in order to determine whether (C t1 t2) declares a data constructor, a type, or a context, we would need unlimited lookahead which 'happy' is not so happy with. - -The solution that accounts for all of these issues is to initially parse data -declarations and types as a reversed list of TyEl: - - data TyEl = TyElOpr RdrName - | TyElOpd (HsType GhcPs) - | ... - -For example, both occurrences of (C ! D) in the following example are parsed -into equal lists of TyEl: - - data T = C ! D => C ! D results in [ TyElOpd (HsTyVar "D") - , TyElOpr "!" - , TyElOpd (HsTyVar "C") ] - -Note that elements are in reverse order. Also, 'C' is parsed as a type -constructor (HsTyVar) even when it is a data constructor. We fix this in -`tyConToDataCon`. - -By the time the list of TyEl is assembled, we have looked ahead enough to -decide whether to reduce using `mergeOps` (for types) or `mergeDataCon` (for -data constructors). These functions are where the actual job of parsing is -done. - -} -- | Reinterpret a type constructor, including type operators, as a data @@ -798,7 +779,7 @@ to make setRdrNameSpace partial, so we just make an Unqual name instead. It really doesn't matter! -} -eitherToP :: Either (SrcSpan, SDoc) a -> P a +eitherToP :: MonadP m => Either (SrcSpan, SDoc) a -> m a -- Adapts the Either monad to the P monad eitherToP (Left (loc, doc)) = addFatalError loc doc eitherToP (Right thing) = return thing @@ -1309,323 +1290,31 @@ isFunLhs e = go e [] [] _ -> return Nothing } go _ _ _ = return Nothing --- | Either an operator or an operand. -data TyEl = TyElOpr RdrName | TyElOpd (HsType GhcPs) - | TyElKindApp SrcSpan (LHsType GhcPs) - -- See Note [TyElKindApp SrcSpan interpretation] - | TyElUnpackedness UnpackednessPragma - - -{- Note [TyElKindApp SrcSpan interpretation] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -A TyElKindApp captures type application written in haskell as - - @ Foo - -where Foo is some type. - -The SrcSpan reflects both elements, and there are AnnAt and AnnVal API -Annotations attached to this SrcSpan for the specific locations of -each within it. --} - -instance Outputable TyEl where - ppr (TyElOpr name) = ppr name - ppr (TyElOpd ty) = ppr ty - ppr (TyElKindApp _ ki) = text "@" <> ppr ki - ppr (TyElUnpackedness (UnpackednessPragma _ _ unpk)) = ppr unpk - --- | Extract a strictness/unpackedness annotation from the front of a reversed --- 'TyEl' list. -pUnpackedness - :: [Located TyEl] -- reversed TyEl - -> Maybe (SrcSpan, UnpackednessPragma, - [Located TyEl] {- remaining TyEl -}) -pUnpackedness (L l x1 : xs) | TyElUnpackedness up <- x1 = Just (l, up, xs) -pUnpackedness _ = Nothing - -pBangTy - :: LHsType GhcPs -- a type to be wrapped inside HsBangTy - -> [Located TyEl] -- reversed TyEl - -> ( Bool {- has a strict mark been consumed? -} - , LHsType GhcPs {- the resulting BangTy -} - , P () {- add annotations -} - , [Located TyEl] {- remaining TyEl -}) -pBangTy lt@(L l1 _) xs = - case pUnpackedness xs of - Nothing -> (False, lt, pure (), xs) - Just (l2, UnpackednessPragma anns prag unpk, xs') -> - let bl = combineSrcSpans l1 l2 - bt = addUnpackedness (prag, unpk) lt - in (True, L bl bt, addAnnsAt bl anns, xs') - mkBangTy :: SrcStrictness -> LHsType GhcPs -> HsType GhcPs mkBangTy strictness = HsBangTy noExtField (HsSrcBang NoSourceText NoSrcUnpack strictness) --- Result of parsing {-# UNPACK #-} or {-# NOUNPACK #-} +-- | Result of parsing @{-\# UNPACK \#-}@ or @{-\# NOUNPACK \#-}@. data UnpackednessPragma = UnpackednessPragma [AddAnn] SourceText SrcUnpackedness -addUnpackedness :: (SourceText, SrcUnpackedness) -> LHsType GhcPs -> HsType GhcPs -addUnpackedness (prag, unpk) (L _ (HsBangTy x bang t)) - | HsSrcBang NoSourceText NoSrcUnpack strictness <- bang - = HsBangTy x (HsSrcBang prag unpk strictness) t -addUnpackedness (prag, unpk) t - = HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t - --- | Merge a /reversed/ and /non-empty/ soup of operators and operands --- into a type. --- --- User input: @F x y + G a b * X@ --- Input to 'mergeOps': [X, *, b, a, G, +, y, x, F] --- Output corresponds to what the user wrote assuming all operators are of the --- same fixity and right-associative. --- --- It's a bit silly that we're doing it at all, as the renamer will have to --- rearrange this, and it'd be easier to keep things separate. --- --- See Note [Parsing data constructors is hard] -mergeOps :: [Located TyEl] -> P (LHsType GhcPs) -mergeOps ((L l1 (TyElOpd t)) : xs) - | (_, t', addAnns, xs') <- pBangTy (L l1 t) xs - , null xs' -- We accept a BangTy only when there are no preceding TyEl. - = addAnns >> return t' -mergeOps all_xs = go (0 :: Int) [] id all_xs - where - -- NB. When modifying clauses in 'go', make sure that the reasoning in - -- Note [Non-empty 'acc' in mergeOps clause [end]] is still correct. - - -- clause [unpk]: - -- handle (NO)UNPACK pragmas - go k acc ops_acc ((L l (TyElUnpackedness (UnpackednessPragma anns unpkSrc unpk))):xs) = - if not (null acc) && null xs - then do { acc' <- eitherToP $ mergeOpsAcc acc - ; let a = ops_acc acc' - strictMark = HsSrcBang unpkSrc unpk NoSrcStrict - bl = combineSrcSpans l (getLoc a) - bt = HsBangTy noExtField strictMark a - ; addAnnsAt bl anns - ; return (L bl bt) } - else addFatalError l unpkError - where - unpkSDoc = case unpkSrc of - NoSourceText -> ppr unpk - SourceText str -> text str <> text " #-}" - unpkError - | not (null xs) = unpkSDoc <+> text "cannot appear inside a type." - | null acc && k == 0 = unpkSDoc <+> text "must be applied to a type." - | otherwise = - -- See Note [Impossible case in mergeOps clause [unpk]] - panic "mergeOps.UNPACK: impossible position" - - -- clause [opr]: - -- when we encounter an operator, we must have accumulated - -- something for its rhs, and there must be something left - -- to build its lhs. - go k acc ops_acc ((L l (TyElOpr op)):xs) = - if null acc || null (filter isTyElOpd xs) - then failOpFewArgs (L l op) - else do { acc' <- eitherToP (mergeOpsAcc acc) - ; go (k + 1) [] (\c -> mkLHsOpTy c (L l op) (ops_acc acc')) xs } - where - isTyElOpd (L _ (TyElOpd _)) = True - isTyElOpd _ = False - - -- clause [opd]: - -- whenever an operand is encountered, it is added to the accumulator - go k acc ops_acc ((L l (TyElOpd a)):xs) = go k (HsValArg (L l a):acc) ops_acc xs - - -- clause [tyapp]: - -- whenever a type application is encountered, it is added to the accumulator - go k acc ops_acc ((L _ (TyElKindApp l a)):xs) = go k (HsTypeArg l a:acc) ops_acc xs - - -- clause [end] - -- See Note [Non-empty 'acc' in mergeOps clause [end]] - go _ acc ops_acc [] = do { acc' <- eitherToP (mergeOpsAcc acc) - ; return (ops_acc acc') } - -mergeOpsAcc :: [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> Either (SrcSpan, SDoc) (LHsType GhcPs) -mergeOpsAcc [] = panic "mergeOpsAcc: empty input" -mergeOpsAcc (HsTypeArg _ (L loc ki):_) - = Left (loc, text "Unexpected type application:" <+> ppr ki) -mergeOpsAcc (HsValArg ty : xs) = go1 ty xs - where - go1 :: LHsType GhcPs - -> [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> Either (SrcSpan, SDoc) (LHsType GhcPs) - go1 lhs [] = Right lhs - go1 lhs (x:xs) = case x of - HsValArg ty -> go1 (mkHsAppTy lhs ty) xs - HsTypeArg loc ki -> let ty = mkHsAppKindTy loc lhs ki - in go1 ty xs - HsArgPar _ -> go1 lhs xs -mergeOpsAcc (HsArgPar _: xs) = mergeOpsAcc xs - -{- Note [Impossible case in mergeOps clause [unpk]] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -This case should never occur. Let us consider all possible -variations of 'acc', 'xs', and 'k': - - acc xs k -============================== - null | null 0 -- "must be applied to a type" - null | not null 0 -- "must be applied to a type" -not null | null 0 -- successful parse -not null | not null 0 -- "cannot appear inside a type" - null | null >0 -- handled in clause [opr] - null | not null >0 -- "cannot appear inside a type" -not null | null >0 -- successful parse -not null | not null >0 -- "cannot appear inside a type" - -The (null acc && null xs && k>0) case is handled in clause [opr] -by the following check: - - if ... || null (filter isTyElOpd xs) - then failOpFewArgs (L l op) - -We know that this check has been performed because k>0, and by -the time we reach the end of the list (null xs), the only way -for (null acc) to hold is that there was not a single TyElOpd -between the operator and the end of the list. But this case is -caught by the check and reported as 'failOpFewArgs'. --} - -{- Note [Non-empty 'acc' in mergeOps clause [end]] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In clause [end] we need to know that 'acc' is non-empty to call 'mergeAcc' -without a check. - -Running 'mergeOps' with an empty input list is forbidden, so we do not consider -this possibility. This means we'll hit at least one other clause before we -reach clause [end]. - -* Clauses [unpk] and [doc] do not call 'go' recursively, so we cannot hit - clause [end] from there. -* Clause [opd] makes 'acc' non-empty, so if we hit clause [end] after it, 'acc' - will be non-empty. -* Clause [opr] checks that (filter isTyElOpd xs) is not null - so we are going - to hit clause [opd] at least once before we reach clause [end], making 'acc' - non-empty. -* There are no other clauses. - -Therefore, it is safe to omit a check for non-emptiness of 'acc' in clause -[end]. - --} - -pInfixSide :: [Located TyEl] -> Maybe (LHsType GhcPs, P (), [Located TyEl]) -pInfixSide ((L l (TyElOpd t)):xs) - | (True, t', addAnns, xs') <- pBangTy (L l t) xs - = Just (t', addAnns, xs') -pInfixSide (el:xs1) - | Just t1 <- pLHsTypeArg el - = go [t1] xs1 - where - go :: [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> [Located TyEl] -> Maybe (LHsType GhcPs, P (), [Located TyEl]) - go acc (el:xs) - | Just t <- pLHsTypeArg el - = go (t:acc) xs - go acc xs = case mergeOpsAcc acc of - Left _ -> Nothing - Right acc' -> Just (acc', pure (), xs) -pInfixSide _ = Nothing - -pLHsTypeArg :: Located TyEl -> Maybe (HsArg (LHsType GhcPs) (LHsKind GhcPs)) -pLHsTypeArg (L l (TyElOpd a)) = Just (HsValArg (L l a)) -pLHsTypeArg (L _ (TyElKindApp l a)) = Just (HsTypeArg l a) -pLHsTypeArg _ = Nothing - -orErr :: Maybe a -> b -> Either b a -orErr (Just a) _ = Right a -orErr Nothing b = Left b - --- | Merge a /reversed/ and /non-empty/ soup of operators and operands --- into a data constructor. --- --- User input: @C !A B -- ^ doc@ --- Input to 'mergeDataCon': ["doc", B, !A, C] --- Output: (C, PrefixCon [!A, B], "doc") --- --- See Note [Parsing data constructors is hard] -mergeDataCon - :: [Located TyEl] - -> P ( Located RdrName -- constructor name - , HsConDeclDetails GhcPs -- constructor field information - ) -mergeDataCon all_xs = - do { (addAnns, a) <- eitherToP res - ; addAnns - ; return a } +-- | Annotate a type with either an @{-\# UNPACK \#-}@ or a @{-\# NOUNPACK \#-}@ pragma. +addUnpackednessP :: MonadP m => Located UnpackednessPragma -> LHsType GhcPs -> m (LHsType GhcPs) +addUnpackednessP (L lprag (UnpackednessPragma anns prag unpk)) ty = do + let l' = combineSrcSpans lprag (getLoc ty) + t' = addUnpackedness ty + addAnnsAt l' anns + return (L l' t') where - -- The result of merging the list of reversed TyEl into a - -- data constructor, along with [AddAnn]. - res = goFirst all_xs - - goFirst [ L l (TyElOpd (HsTyVar _ _ (L _ tc))) ] - = do { data_con <- tyConToDataCon l tc - ; return (pure (), (data_con, PrefixCon [])) } - goFirst ((L l (TyElOpd (HsRecTy _ fields))):xs) - | [ L l' (TyElOpd (HsTyVar _ _ (L _ tc))) ] <- xs - = do { data_con <- tyConToDataCon l' tc - ; return (pure (), (data_con, RecCon (L l fields))) } - goFirst [L l (TyElOpd (HsTupleTy _ HsBoxedOrConstraintTuple ts))] - = return ( pure () - , ( L l (getRdrName (tupleDataCon Boxed (length ts))) - , PrefixCon (map hsLinear ts) ) ) - goFirst ((L l (TyElOpd t)):xs) - | (_, t', addAnns, xs') <- pBangTy (L l t) xs - = go addAnns [t'] xs' - goFirst (L l (TyElKindApp _ _):_) - = goInfix Monoid.<> Left (l, kindAppErr) - goFirst xs - = go (pure ()) [] xs - - go addAnns ts [ L l (TyElOpd (HsTyVar _ _ (L _ tc))) ] - = do { data_con <- tyConToDataCon l tc - ; return (addAnns, (data_con, PrefixCon (map hsLinear ts))) } - go addAnns ts ((L l (TyElOpd t)):xs) - | (_, t', addAnns', xs') <- pBangTy (L l t) xs - = go (addAnns >> addAnns') (t':ts) xs' - go _ _ ((L _ (TyElOpr _)):_) = - -- Encountered an operator: backtrack to the beginning and attempt - -- to parse as an infix definition. - goInfix - go _ _ (L l (TyElKindApp _ _):_) = goInfix Monoid.<> Left (l, kindAppErr) - go _ _ _ = Left malformedErr - where - malformedErr = - ( foldr combineSrcSpans noSrcSpan (map getLoc all_xs) - , text "Cannot parse data constructor" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs)) - - goInfix = - do { let xs0 = all_xs - ; (rhs, rhs_addAnns, xs1) <- pInfixSide xs0 `orErr` malformedErr - ; (op, xs3) <- case xs1 of - (L l (TyElOpr op)) : xs3 -> - do { data_con <- tyConToDataCon l op - ; return (data_con, xs3) } - _ -> Left malformedErr - ; (lhs, lhs_addAnns, xs5) <- pInfixSide xs3 `orErr` malformedErr - ; unless (null xs5) (Left malformedErr) - ; let addAnns = lhs_addAnns >> rhs_addAnns - ; return (addAnns, (op, InfixCon (hsLinear lhs) (hsLinear rhs))) } - where - malformedErr = - ( foldr combineSrcSpans noSrcSpan (map getLoc all_xs) - , text "Cannot parse an infix data constructor" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs)) - - kindAppErr = - text "Unexpected kind application" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs) + -- If we have a HsBangTy that only has a strictness annotation, + -- such as ~T or !T, then add the pragma to the existing HsBangTy. + -- + -- Otherwise, wrap the type in a new HsBangTy constructor. + addUnpackedness (L _ (HsBangTy x bang t)) + | HsSrcBang NoSourceText NoSrcUnpack strictness <- bang + = HsBangTy x (HsSrcBang prag unpk strictness) t + addUnpackedness t + = HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t --------------------------------------------------------------------------- -- | Check for monad comprehensions @@ -1645,7 +1334,6 @@ checkMonadComp = do -- See Note [Ambiguous syntactic categories] -- --- See Note [Parser-Validator] -- See Note [Ambiguous syntactic categories] -- -- This newtype is required to avoid impredicative types in monadic @@ -1659,10 +1347,7 @@ checkMonadComp = do -- P (forall b. DisambECP b => PV (Located b)) -- newtype ECP = - ECP { runECP_PV :: forall b. DisambECP b => PV (Located b) } - -runECP_P :: DisambECP b => ECP -> P (Located b) -runECP_P p = runPV (runECP_PV p) + ECP { unECP :: forall b. DisambECP b => PV (Located b) } ecpFromExp :: LHsExpr GhcPs -> ECP ecpFromExp a = ECP (ecpFromExp' a) @@ -2053,9 +1738,145 @@ mkPatRec (unLoc -> PatBuilderVar c) (HsRecFields fs dd) mkPatRec p _ = addFatalError (getLoc p) $ text "Not a record constructor:" <+> ppr p +-- | Disambiguate constructs that may appear when we do not know +-- ahead of time whether we are parsing a type or a newtype/data constructor. +-- +-- See Note [Ambiguous syntactic categories] for the general idea. +-- +-- See Note [Parsing data constructors is hard] for the specific issue this +-- particular class is solving. +-- +class DisambTD b where + -- | Process the head of a type-level function/constructor application, + -- i.e. the @H@ in @H a b c at . + mkHsAppTyHeadPV :: LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f x@ (function application or prefix data constructor). + mkHsAppTyPV :: Located b -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f \@t@ (visible kind application) + mkHsAppKindTyPV :: Located b -> SrcSpan -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f \# x@ (infix operator) + mkHsOpTyPV :: LHsType GhcPs -> Located RdrName -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @{-\# UNPACK \#-} t@ (unpack/nounpack pragma) + mkUnpackednessPV :: Located UnpackednessPragma -> Located b -> PV (Located b) + +instance DisambTD (HsType GhcPs) where + mkHsAppTyHeadPV = return + mkHsAppTyPV t1 t2 = return (mkHsAppTy t1 t2) + mkHsAppKindTyPV t l_at ki = return (mkHsAppKindTy l' t ki) + where l' = combineSrcSpans l_at (getLoc ki) + mkHsOpTyPV t1 op t2 = return (mkLHsOpTy t1 op t2) + mkUnpackednessPV = addUnpackednessP + +-- | An accumulator to build a prefix data constructor, +-- e.g. when parsing @MkT A B C@, the accumulator will evolve as follows: +-- +-- @ +-- 1. PrefixDataConBuilder [] MkT +-- 2. PrefixDataConBuilder [A] MkT +-- 3. PrefixDataConBuilder [A, B] MkT +-- 4. PrefixDataConBuilder [A, B, C] MkT +-- @ +-- +-- There are two reasons we have a separate builder type instead of using +-- @HsConDeclDetails GhcPs@ directly: +-- +-- 1. It's faster, because 'OrdList' gives us constant-time snoc. +-- 2. Having a separate type helps ensure that we don't forget to finalize a +-- 'RecTy' into a 'RecCon' (we do that in 'dataConBuilderDetails'). +-- +-- See Note [PatBuilder] for another builder type used in the parser. +-- Here the technique is similar, but the motivation is different. +data DataConBuilder + = PrefixDataConBuilder + (OrdList (LHsType GhcPs)) -- Data constructor fields + (Located RdrName) -- Data constructor name + | InfixDataConBuilder + (LHsType GhcPs) -- LHS field + (Located RdrName) -- Data constructor name + (LHsType GhcPs) -- RHS field + +dataConBuilderCon :: DataConBuilder -> Located RdrName +dataConBuilderCon (PrefixDataConBuilder _ dc) = dc +dataConBuilderCon (InfixDataConBuilder _ dc _) = dc + +dataConBuilderDetails :: DataConBuilder -> HsConDeclDetails GhcPs + +-- Detect when the record syntax is used: +-- data T = MkT { ... } +dataConBuilderDetails (PrefixDataConBuilder flds _) + | [L l_t (HsRecTy _ fields)] <- toList flds + = RecCon (L l_t fields) + +-- Normal prefix constructor, e.g. data T = MkT A B C +dataConBuilderDetails (PrefixDataConBuilder flds _) + = PrefixCon (map hsLinear (toList flds)) + +-- Infix constructor, e.g. data T = Int :! Bool +dataConBuilderDetails (InfixDataConBuilder lhs _ rhs) + = InfixCon (hsLinear lhs) (hsLinear rhs) + +instance Outputable DataConBuilder where + ppr (PrefixDataConBuilder flds data_con) = + hang (ppr data_con) 2 (sep (map ppr (toList flds))) + ppr (InfixDataConBuilder lhs data_con rhs) = + ppr lhs <+> ppr data_con <+> ppr rhs + +instance DisambTD DataConBuilder where + mkHsAppTyHeadPV = tyToDataConBuilder + + mkHsAppTyPV (L l (PrefixDataConBuilder flds fn)) t = + return $ + L (combineSrcSpans l (getLoc t)) + (PrefixDataConBuilder (flds `snocOL` t) fn) + mkHsAppTyPV (L _ InfixDataConBuilder{}) _ = + -- This case is impossible because of the way + -- the grammar in Parser.y is written (see infixtype/ftype). + panic "mkHsAppTyPV: InfixDataConBuilder" + + mkHsAppKindTyPV lhs l_at ki = + addFatalError l_at $ + hang (text "Unexpected kind application in a data/newtype declaration:") 2 + (ppr lhs <+> text "@" <> ppr ki) + + mkHsOpTyPV lhs (L l_tc tc) rhs = do + check_no_ops (unLoc rhs) -- check the RHS because parsing type operators is right-associative + data_con <- eitherToP $ tyConToDataCon l_tc tc + return $ L l (InfixDataConBuilder lhs data_con rhs) + where + l = combineLocs lhs rhs + check_no_ops (HsBangTy _ _ t) = check_no_ops (unLoc t) + check_no_ops (HsOpTy{}) = + addError l $ + hang (text "Cannot parse an infix data constructor in a data/newtype declaration:") + 2 (ppr lhs <+> ppr tc <+> ppr rhs) + check_no_ops _ = return () + + mkUnpackednessPV unpk constr_stuff + | L _ (InfixDataConBuilder lhs data_con rhs) <- constr_stuff + = -- When the user writes data T = {-# UNPACK #-} Int :+ Bool + -- we apply {-# UNPACK #-} to the LHS + do lhs' <- addUnpackednessP unpk lhs + let l = combineLocs unpk constr_stuff + return $ L l (InfixDataConBuilder lhs' data_con rhs) + | otherwise = + do addError (getLoc unpk) $ + text "{-# UNPACK #-} cannot be applied to a data constructor." + return constr_stuff + +tyToDataConBuilder :: LHsType GhcPs -> PV (Located DataConBuilder) +tyToDataConBuilder (L l (HsTyVar _ NotPromoted (L _ v))) = do + data_con <- eitherToP $ tyConToDataCon l v + return $ L l (PrefixDataConBuilder nilOL data_con) +tyToDataConBuilder (L l (HsTupleTy _ HsBoxedOrConstraintTuple ts)) = do + let data_con = L l (getRdrName (tupleDataCon Boxed (length ts))) + return $ L l (PrefixDataConBuilder (toOL ts) data_con) +tyToDataConBuilder t = + addFatalError (getLoc t) $ + hang (text "Cannot parse data constructor in a data/newtype declaration:") + 2 (ppr t) + {- Note [Ambiguous syntactic categories] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - There are places in the grammar where we do not know whether we are parsing an expression or a pattern without unlimited lookahead (which we do not have in 'happy'): @@ -2150,6 +1971,21 @@ position and shadows the previous $1. We can do this because internally is to be able to write (sLL $1 $>) later on. The alternative would be to write this as ($1 >>= \ fresh_name -> ...), but then we couldn't refer to the last fresh name as $>. + +Finally, we instantiate the polymorphic type to a concrete one, and run the +parser-validator, for example: + + stmt :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } + e_stmt :: { LStmt GhcPs (LHsExpr GhcPs) } + : stmt {% runPV $1 } + +In e_stmt, three things happen: + + 1. we instantiate: b ~ HsExpr GhcPs + 2. we embed the PV computation into P by using runPV + 3. we run validation by using a monadic production, {% ... } + +At this point the ambiguity is resolved. -} @@ -2306,7 +2142,6 @@ Alternative VII, a product type We could avoid the intermediate representation of Alternative VI by parsing into a product of interpretations directly: - -- See Note [Parser-Validator] type ExpCmdPat = ( PV (LHsExpr GhcPs) , PV (LHsCmd GhcPs) , PV (LHsPat GhcPs) ) @@ -2326,7 +2161,6 @@ We can easily define ambiguities between arbitrary subsets of interpretations. For example, when we know ahead of type that only an expression or a command is possible, but not a pattern, we can use a smaller type: - -- See Note [Parser-Validator] type ExpCmd = (PV (LHsExpr GhcPs), PV (LHsCmd GhcPs)) checkExpOf2 (e, _) = e -- interpret as an expression @@ -2809,7 +2643,7 @@ warnStarBndr span = addWarning Opt_WarnStarBinder span msg <+> text "modules with StarIsType," $$ text " including the definition module, you must qualify it." -failOpFewArgs :: Located RdrName -> P a +failOpFewArgs :: MonadP m => Located RdrName -> m a failOpFewArgs (L loc op) = do { star_is_type <- getBit StarIsTypeBit ; let msg = too_few $$ starInfo star_is_type op @@ -2836,7 +2670,25 @@ data PV_Accum = data PV_Result a = PV_Ok PV_Accum a | PV_Failed PV_Accum --- See Note [Parser-Validator] +-- During parsing, we make use of several monadic effects: reporting parse errors, +-- accumulating warnings, adding API annotations, and checking for extensions. These +-- effects are captured by the 'MonadP' type class. +-- +-- Sometimes we need to postpone some of these effects to a later stage due to +-- ambiguities described in Note [Ambiguous syntactic categories]. +-- We could use two layers of the P monad, one for each stage: +-- +-- abParser :: forall x. DisambAB x => P (P x) +-- +-- The outer layer of P consumes the input and builds the inner layer, which +-- validates the input. But this type is not particularly helpful, as it obscures +-- the fact that the inner layer of P never consumes any input. +-- +-- For clarity, we introduce the notion of a parser-validator: a parser that does +-- not consume any input, but may fail or use other effects. Thus we have: +-- +-- abParser :: forall x. DisambAB x => P (PV x) +-- newtype PV a = PV { unPV :: PV_Context -> PV_Accum -> PV_Result a } instance Functor PV where @@ -2910,36 +2762,6 @@ instance MonadP PV where PV_Ok acc' () addAnnotation _ _ _ = return () -{- Note [Parser-Validator] -~~~~~~~~~~~~~~~~~~~~~~~~~~ - -When resolving ambiguities, we need to postpone failure to make a choice later. -For example, if we have ambiguity between some A and B, our parser could be - - abParser :: P (Maybe A, Maybe B) - -This way we can represent four possible outcomes of parsing: - - (Just a, Nothing) -- definitely A - (Nothing, Just b) -- definitely B - (Just a, Just b) -- either A or B - (Nothing, Nothing) -- neither A nor B - -However, if we want to report informative parse errors, accumulate warnings, -and add API annotations, we are better off using 'P' instead of 'Maybe': - - abParser :: P (P A, P B) - -So we have an outer layer of P that consumes the input and builds the inner -layer, which validates the input. - -For clarity, we introduce the notion of a parser-validator: a parser that does -not consume any input, but may fail or use other effects. Thus we have: - - abParser :: P (PV A, PV B) - --} - {- Note [Parser-Validator Hint] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A PV computation is parametrized by a hint for error messages, which can be set ===================================== compiler/GHC/Tc/TyCl.hs ===================================== @@ -74,7 +74,6 @@ import GHC.Types.SrcLoc import GHC.Data.List.SetOps import GHC.Driver.Session import GHC.Types.Unique -import GHC.Core.ConLike( ConLike(..) ) import GHC.Types.Basic import qualified GHC.LanguageExtensions as LangExt @@ -3819,15 +3818,14 @@ checkValidTyCl tc where recovery_code -- See Note [Recover from validity error] = do { traceTc "Aborted validity for tycon" (ppr tc) - ; return (concatMap mk_fake_tc $ - ATyCon tc : implicitTyConThings tc) } + ; return (map mk_fake_tc $ + tc : child_tycons tc) } - mk_fake_tc (ATyCon tc) - | isClassTyCon tc = [tc] -- Ugh! Note [Recover from validity error] - | otherwise = [makeRecoveryTyCon tc] - mk_fake_tc (AConLike (RealDataCon dc)) - = [makeRecoveryTyCon (promoteDataCon dc)] - mk_fake_tc _ = [] + mk_fake_tc tc + | isClassTyCon tc = tc -- Ugh! Note [Recover from validity error] + | otherwise = makeRecoveryTyCon tc + + child_tycons tc = tyConATs tc ++ map promoteDataCon (tyConDataCons tc) {- Note [Recover from validity error] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -3852,6 +3850,8 @@ Some notes: and so there was an internal error when we met 'MkT' in the body of 'S'. + Similarly for associated types. + * Painfully, we *don't* want to do this for classes. Consider tcfail041: class (?x::Int) => C a where ... @@ -3864,6 +3864,14 @@ Some notes: This is really bogus; now we have in scope a Class that is invalid in some way, with unknown downstream consequences. A better alternative might be to make a fake class TyCon. A job for another day. + +* Previously, we used implicitTyConThings to snaffle out the parts + to add to the context. The problem is that this also grabs data con + wrapper Ids. These could be filtered out. But, painfully, getting + the wrapper Ids checks the DataConRep, and forcing the DataConRep + can panic if there is a levity-polymorphic argument. This is #18534. + We don't need the wrapper Ids here anyway. So the code just takes what + it needs, via child_tycons. -} ------------------------- @@ -4050,8 +4058,13 @@ checkValidDataCon dflags existential_ok tc con -- regardless of whether or not UnliftedNewtypes is enabled. A -- later check in checkNewDataCon handles this, producing a -- better error message than checkForLevPoly would. - ; unless (isNewTyCon tc) - (mapM_ (checkForLevPoly empty) (map scaledThing $ dataConOrigArgTys con)) + ; unless (isNewTyCon tc) $ + checkNoErrs $ + mapM_ (checkForLevPoly empty) (map scaledThing $ dataConOrigArgTys con) + -- the checkNoErrs is to prevent a panic in isVanillaDataCon + -- (called a a few lines down), which can fall over if there is a + -- bang on a levity-polymorphic argument. This is #18534, + -- typecheck/should_fail/T18534 -- Extra checks for newtype data constructors. Importantly, these -- checks /must/ come before the call to checkValidType below. This ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.hs ===================================== @@ -0,0 +1,50 @@ +{-# LANGUAGE TemplateHaskell, ExplicitForAll, PolyKinds #-} + +module Main where + +import Language.Haskell.TH (runQ) +import GHC.Types.Basic +import GHC.ThToHs +import GHC.Driver.Session +import GHC.Core.TyCo.Ppr +import GHC.Utils.Outputable +import GHC.Tc.Module +import GHC.Tc.Utils.Zonk +import GHC.Utils.Error +import GHC.Driver.Types +import GHC +import qualified GHC.LanguageExtensions as LangExt + +import Data.Either (fromRight) +import Control.Monad.IO.Class (liftIO) +import System.Environment (getArgs) + +main :: IO () +main = do + [libdir] <- getArgs + runGhc (Just libdir) $ do + initial_dflags <- getSessionDynFlags + setSessionDynFlags $ initial_dflags + `dopt_set` Opt_D_ppr_debug + `gopt_set` Opt_SuppressUniques + `gopt_set` Opt_SuppressModulePrefixes + `gopt_set` Opt_SuppressVarKinds + `xopt_set` LangExt.KindSignatures + `xopt_set` LangExt.PolyKinds + `xopt_set` LangExt.RankNTypes + hsc_env <- getSession + let dflags = hsc_dflags hsc_env + liftIO $ do + th_t <- runQ [t| forall k {j}. + forall (a :: k) (b :: j) -> + () |] + let hs_t = fromRight (error "convertToHsType") $ + convertToHsType Generated noSrcSpan th_t + ((warnings, errors), mres) <- + tcRnType hsc_env SkolemiseFlexi True hs_t + case mres of + Nothing -> do + printBagOfErrors dflags warnings + printBagOfErrors dflags errors + Just (t, _) -> do + putStrLn $ showSDoc dflags (debugPprType t) ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.stdout ===================================== @@ -0,0 +1,2 @@ +forall k{tv}[tv] {j{tv}[tv]}. +forall a{tv}[tv] b{tv}[tv] -> (){(w) tc} ===================================== testsuite/tests/ghc-api/all.T ===================================== @@ -20,3 +20,7 @@ test('T9015', extra_run_opts('"' + config.libdir + '"'), test('T11579', extra_run_opts('"' + config.libdir + '"'), compile_and_run, ['-package ghc']) test('T12099', normal, compile_and_run, ['-package ghc']) +test('T18522-dbg-ppr', + extra_run_opts('"' + config.libdir + '"'), + compile_and_run, + ['-package ghc']) ===================================== testsuite/tests/parser/should_fail/T12045d.stderr ===================================== @@ -1,4 +1,3 @@ T12045d.hs:11:16: error: - Unexpected kind application in a data/newtype declaration: - MkD @Nat Bool + Unexpected kind application in a data/newtype declaration: MkD @Nat ===================================== testsuite/tests/parser/should_fail/strictnessDataCon_B.stderr ===================================== @@ -1,3 +1,2 @@ -strictnessDataCon_B.hs:1:27: error: - {-# UNPACK #-} cannot appear inside a type. +strictnessDataCon_B.hs:1:42: error: parse error on input ‘}’ ===================================== testsuite/tests/parser/should_fail/typeops_A.stderr ===================================== @@ -1,2 +1,3 @@ -typeops_A.hs:1:12: error: Operator applied to too few arguments: + +typeops_A.hs:2:1: error: + parse error (possibly incorrect indentation or mismatched brackets) ===================================== testsuite/tests/parser/should_fail/typeops_C.stderr ===================================== @@ -1,2 +1,2 @@ -typeops_C.hs:1:12: error: Operator applied to too few arguments: + +typeops_C.hs:1:14: error: Operator applied to too few arguments: + ===================================== testsuite/tests/parser/should_fail/unpack_empty_type.stderr ===================================== @@ -1,3 +1,2 @@ -unpack_empty_type.hs:3:19: error: - {-# UNPACK #-} must be applied to a type. +unpack_empty_type.hs:3:34: error: parse error on input ‘}’ ===================================== testsuite/tests/parser/should_fail/unpack_inside_type.stderr ===================================== @@ -1,3 +1,7 @@ unpack_inside_type.hs:3:25: error: - {-# UNPACK #-} cannot appear inside a type. + • Unexpected UNPACK annotation: {-# UNPACK #-}Int + UNPACK annotation cannot appear nested inside a type + • In the first argument of ‘Maybe’, namely ‘({-# UNPACK #-}Int)’ + In the type ‘Maybe ({-# UNPACK #-}Int)’ + In the definition of data constructor ‘T’ ===================================== testsuite/tests/polykinds/T18522-ppr.script ===================================== @@ -0,0 +1,4 @@ +:set -XPolyKinds -XDataKinds -XRankNTypes -XTypeFamilies +import Data.Kind (Type) +type family T :: forall k -> (k ~ k) => forall j -> k -> j -> Type +:k T ===================================== testsuite/tests/polykinds/T18522-ppr.stdout ===================================== @@ -0,0 +1 @@ +T :: forall k -> (k ~ k) => forall j -> k -> j -> * ===================================== testsuite/tests/polykinds/all.T ===================================== @@ -223,3 +223,4 @@ test('T18300', normal, compile_fail, ['']) test('T18451', normal, compile_fail, ['']) test('T18451a', normal, compile_fail, ['']) test('T18451b', normal, compile_fail, ['']) +test('T18522-ppr', normal, ghci_script, ['T18522-ppr.script']) ===================================== testsuite/tests/typecheck/should_fail/T18534.hs ===================================== @@ -0,0 +1,7 @@ +{-# LANGUAGE PolyKinds #-} + +module Test where + +import GHC.Exts + +data Test (a :: TYPE r) = Test !a ===================================== testsuite/tests/typecheck/should_fail/T18534.stderr ===================================== @@ -0,0 +1,7 @@ + +T18534.hs:7:27: error: + • A levity-polymorphic type is not allowed here: + Type: a + Kind: TYPE r + • In the definition of data constructor ‘Test’ + In the data type declaration for ‘Test’ ===================================== testsuite/tests/typecheck/should_fail/all.T ===================================== @@ -578,3 +578,4 @@ test('T18357', normal, compile_fail, ['']) test('T18357a', normal, compile_fail, ['']) test('T18357b', normal, compile_fail, ['']) test('T18455', normal, compile_fail, ['']) +test('T18534', normal, compile_fail, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a63823a8d3aa335efa643f2a2826dde539083167...e935b566da341ae03c3612be21372a2afac2ed31 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a63823a8d3aa335efa643f2a2826dde539083167...e935b566da341ae03c3612be21372a2afac2ed31 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 16:19:08 2020 From: gitlab at gitlab.haskell.org (Richard Eisenberg) Date: Wed, 05 Aug 2020 12:19:08 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T11715-2020 Message-ID: <5f2adbfc9e2f6_80b8ca3ed0666947@gitlab.haskell.org.mail> Richard Eisenberg pushed new branch wip/T11715-2020 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T11715-2020 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 16:26:51 2020 From: gitlab at gitlab.haskell.org (Richard Eisenberg) Date: Wed, 05 Aug 2020 12:26:51 -0400 Subject: [Git][ghc/ghc][wip/T11715-2020] Use tcView, not coreView, in the pure unifier. Message-ID: <5f2addcbbbce6_80b3f8496224a7066696b0@gitlab.haskell.org.mail> Richard Eisenberg pushed to branch wip/T11715-2020 at Glasgow Haskell Compiler / GHC Commits: dfdf0fc3 by Richard Eisenberg at 2020-08-05T12:26:18-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - 2 changed files: - compiler/GHC/Core/Type.hs - compiler/GHC/Core/Unify.hs Changes: ===================================== compiler/GHC/Core/Type.hs ===================================== @@ -357,10 +357,28 @@ But in Core these two are treated as identical. We implement this by making 'coreView' convert 'Constraint' to 'TYPE LiftedRep' on the fly. The function tcView (used in the type checker) -does not do this. +does not do this. Accordingly, tcView is used in type-checker-oriented +functions (including the pure unifier, used in instance resolution), +while coreView is used during e.g. optimisation passes. See also #11715, which tracks removing this inconsistency. +The inconsistency actually leads to a potential soundness bug, in that +Constraint and Type are considered *apart* by the type family engine. +To wit, we can write + + type family F a + type instance F Type = Bool + type instance F Constraint = Int + +and (because Type ~# Constraint in Core), thus build a coercion between +Int and Bool. I (Richard E) conjecture that this never happens in practice, +but it's very uncomfortable. This, essentially, is the root problem +underneath #11715, which is quite resistant to an easy fix. The best +idea is to have roles in kind coercions, but that has yet to be implemented. +See also "A Role for Dependent Types in Haskell", ICFP 2019, which describes +how roles in kinds might work out. + -} -- | Gives the typechecker view of a type. This unwraps synonyms but ===================================== compiler/GHC/Core/Unify.hs ===================================== @@ -1121,7 +1121,7 @@ uUnrefined :: UMEnv -- We know that tv1 isn't refined uUnrefined env tv1' ty2 ty2' kco - | Just ty2'' <- coreView ty2' + | Just ty2'' <- tcView ty2' = uUnrefined env tv1' ty2 ty2'' kco -- Unwrap synonyms -- This is essential, in case we have -- type Foo a = a @@ -1483,6 +1483,8 @@ ty_co_match :: MatchEnv -- ^ ambient helpful info -> Maybe LiftCoEnv ty_co_match menv subst ty co lkco rkco | Just ty' <- coreView ty = ty_co_match menv subst ty' co lkco rkco + -- why coreView here, not tcView? Because we're firmly after type-checking. + -- This function is used only during coercion optimisation. -- handle Refl case: | tyCoVarsOfType ty `isNotInDomainOf` subst View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dfdf0fc3fffbdfe40f94b12740349666bcd8c4fc -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dfdf0fc3fffbdfe40f94b12740349666bcd8c4fc You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 17:10:06 2020 From: gitlab at gitlab.haskell.org (Richard Eisenberg) Date: Wed, 05 Aug 2020 13:10:06 -0400 Subject: [Git][ghc/ghc][wip/T11715-2020] Use tcView, not coreView, in the pure unifier. Message-ID: <5f2ae7eee7d7b_80b3f848a372f8c66915e3@gitlab.haskell.org.mail> Richard Eisenberg pushed to branch wip/T11715-2020 at Glasgow Haskell Compiler / GHC Commits: 171356f1 by Richard Eisenberg at 2020-08-05T13:09:58-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - 2 changed files: - compiler/GHC/Core/Type.hs - compiler/GHC/Core/Unify.hs Changes: ===================================== compiler/GHC/Core/Type.hs ===================================== @@ -357,10 +357,28 @@ But in Core these two are treated as identical. We implement this by making 'coreView' convert 'Constraint' to 'TYPE LiftedRep' on the fly. The function tcView (used in the type checker) -does not do this. +does not do this. Accordingly, tcView is used in type-checker-oriented +functions (including the pure unifier, used in instance resolution), +while coreView is used during e.g. optimisation passes. See also #11715, which tracks removing this inconsistency. +The inconsistency actually leads to a potential soundness bug, in that +Constraint and Type are considered *apart* by the type family engine. +To wit, we can write + + type family F a + type instance F Type = Bool + type instance F Constraint = Int + +and (because Type ~# Constraint in Core), thus build a coercion between +Int and Bool. I (Richard E) conjecture that this never happens in practice, +but it's very uncomfortable. This, essentially, is the root problem +underneath #11715, which is quite resistant to an easy fix. The best +idea is to have roles in kind coercions, but that has yet to be implemented. +See also "A Role for Dependent Types in Haskell", ICFP 2019, which describes +how roles in kinds might work out. + -} -- | Gives the typechecker view of a type. This unwraps synonyms but ===================================== compiler/GHC/Core/Unify.hs ===================================== @@ -957,7 +957,7 @@ unify_ty :: UMEnv -- Respects newtypes, PredTypes unify_ty env ty1 ty2 kco - -- TODO: More commentary needed here + -- Use tcView, not coreView. See Note [coreView vs tcView] in GHC.Core.Type. | Just ty1' <- tcView ty1 = unify_ty env ty1' ty2 kco | Just ty2' <- tcView ty2 = unify_ty env ty1 ty2' kco | CastTy ty1' co <- ty1 = if um_unif env @@ -1121,7 +1121,8 @@ uUnrefined :: UMEnv -- We know that tv1 isn't refined uUnrefined env tv1' ty2 ty2' kco - | Just ty2'' <- coreView ty2' + -- Use tcView, not coreView. See Note [coreView vs tcView] in GHC.Core.Type. + | Just ty2'' <- tcView ty2' = uUnrefined env tv1' ty2 ty2'' kco -- Unwrap synonyms -- This is essential, in case we have -- type Foo a = a @@ -1483,6 +1484,8 @@ ty_co_match :: MatchEnv -- ^ ambient helpful info -> Maybe LiftCoEnv ty_co_match menv subst ty co lkco rkco | Just ty' <- coreView ty = ty_co_match menv subst ty' co lkco rkco + -- why coreView here, not tcView? Because we're firmly after type-checking. + -- This function is used only during coercion optimisation. -- handle Refl case: | tyCoVarsOfType ty `isNotInDomainOf` subst View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/171356f1d63464ee7b55fe69c8884e843a5348d1 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/171356f1d63464ee7b55fe69c8884e843a5348d1 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 18:05:33 2020 From: gitlab at gitlab.haskell.org (Richard Eisenberg) Date: Wed, 05 Aug 2020 14:05:33 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18528 Message-ID: <5f2af4edd22bf_80b3f8496224a70669644@gitlab.haskell.org.mail> Richard Eisenberg pushed new branch wip/T18528 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18528 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 18:14:18 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Wed, 05 Aug 2020 14:14:18 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/az/anns-1 Message-ID: <5f2af6fac6f20_80b10e6f9b4670099f@gitlab.haskell.org.mail> Alan Zimmerman pushed new branch wip/az/anns-1 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/az/anns-1 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 5 23:24:45 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Wed, 05 Aug 2020 19:24:45 -0400 Subject: [Git][ghc/ghc][wip/T18527] 87 commits: Fix dead link to haskell prime discussion Message-ID: <5f2b3fbd6e4d5_80b3f848705b144672487d@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18527 at Glasgow Haskell Compiler / GHC Commits: 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 2bee3ba3 by Ben Gamari at 2020-08-04T17:41:51-04:00 cmm: Clean up Notes a bit - - - - - f63eadc9 by Ben Gamari at 2020-08-04T17:41:51-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 4fc61c9a by Ben Gamari at 2020-08-05T19:24:10-04:00 WIP: One approach to fix #18527 - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/test-metrics.sh - CODEOWNERS - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/Graph.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/Monad.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Switch/Implement.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/Config.hs - compiler/GHC/CmmToAsm/Dwarf/Types.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d04d0eafefa6ace6d5addd20a344cb731eec0903...4fc61c9a0574001f481e36db71ce792df1f99ff9 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d04d0eafefa6ace6d5addd20a344cb731eec0903...4fc61c9a0574001f481e36db71ce792df1f99ff9 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 00:53:22 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 05 Aug 2020 20:53:22 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 6 commits: Grammar for types and data/newtype constructors Message-ID: <5f2b5482c2970_80b3f8496224a7067358ee@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 750db644 by Vladislav Zavialov at 2020-08-05T20:53:08-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 2a372e7e by Vladislav Zavialov at 2020-08-05T20:53:08-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 8163bb18 by Vladislav Zavialov at 2020-08-05T20:53:08-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0f012645 by Vladislav Zavialov at 2020-08-05T20:53:08-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d0999fa6 by Richard Eisenberg at 2020-08-05T20:53:09-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 3021450b by Sylvain Henry at 2020-08-05T20:53:12-04:00 Use a type alias for Ways - - - - - 24 changed files: - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Platform/Profile.hs - compiler/GHC/Platform/Ways.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Unit/State.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.stdout - testsuite/tests/ghc-api/all.T - testsuite/tests/parser/should_fail/T12045d.stderr - testsuite/tests/parser/should_fail/strictnessDataCon_B.stderr - testsuite/tests/parser/should_fail/typeops_A.stderr - testsuite/tests/parser/should_fail/typeops_C.stderr - testsuite/tests/parser/should_fail/unpack_empty_type.stderr - testsuite/tests/parser/should_fail/unpack_inside_type.stderr - + testsuite/tests/polykinds/T18522-ppr.script - + testsuite/tests/polykinds/T18522-ppr.stdout - testsuite/tests/polykinds/all.T - + testsuite/tests/typecheck/should_fail/T18534.hs - + testsuite/tests/typecheck/should_fail/T18534.stderr - testsuite/tests/typecheck/should_fail/all.T Changes: ===================================== compiler/GHC/Core/TyCo/Ppr.hs ===================================== @@ -36,7 +36,8 @@ import {-# SOURCE #-} GHC.CoreToIface import {-# SOURCE #-} GHC.Core.DataCon ( dataConFullSig , dataConUserTyVarBinders, DataCon ) -import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many ) +import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many, + splitForAllTysReq, splitForAllTysInvis ) import GHC.Core.TyCon import GHC.Core.TyCo.Rep @@ -268,19 +269,34 @@ debug_ppr_ty prec (CastTy ty co) debug_ppr_ty _ (CoercionTy co) = parens (text "CO" <+> ppr co) -debug_ppr_ty prec ty@(ForAllTy {}) - | (tvs, body) <- split ty +-- Invisible forall: forall {k} (a :: k). t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysInvis t + , not (null bndrs) = maybeParen prec funPrec $ - hang (text "forall" <+> fsep (map ppr tvs) <> dot) - -- The (map ppr tvs) will print kind-annotated - -- tvs, because we are (usually) in debug-style - 2 (ppr body) + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <> dot, + ppr body ] where - split ty | ForAllTy tv ty' <- ty - , (tvs, body) <- split ty' - = (tv:tvs, body) - | otherwise - = ([], ty) + -- (ppr tv) will print the binder kind-annotated + -- when in debug-style + ppr_bndr (Bndr tv InferredSpec) = braces (ppr tv) + ppr_bndr (Bndr tv SpecifiedSpec) = ppr tv + +-- Visible forall: forall x y -> t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysReq t + , not (null bndrs) + = maybeParen prec funPrec $ + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <+> arrow, + ppr body ] + where + -- (ppr tv) will print the binder kind-annotated + -- when in debug-style + ppr_bndr (Bndr tv ()) = ppr tv + +-- Impossible case: neither visible nor invisible forall. +debug_ppr_ty _ ForAllTy{} + = panic "debug_ppr_ty: neither splitForAllTysInvis nor splitForAllTysReq returned any binders" {- Note [Infix type variables] ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -534,7 +534,7 @@ data DynFlags = DynFlags { homeUnitInstantiations:: [(ModuleName, Module)], -- ^ How to instantiate `homeUnitInstanceOfId` unit -- ways - ways :: Set Way, -- ^ Way flags from the command line + ways :: Ways, -- ^ Way flags from the command line -- For object splitting splitInfo :: Maybe (String,Int), @@ -1433,7 +1433,7 @@ defaultDynFlags mySettings llvmConfig = cfgWeightInfo = defaultCfgWeights } -defaultWays :: Settings -> Set Way +defaultWays :: Settings -> Ways defaultWays settings = if pc_DYNAMIC_BY_DEFAULT (sPlatformConstants settings) then Set.singleton WayDyn else Set.empty ===================================== compiler/GHC/Iface/Type.hs ===================================== @@ -441,6 +441,7 @@ splitIfaceSigmaTy ty (theta, tau) = split_rho rho split_foralls (IfaceForAllTy bndr ty) + | isInvisibleArgFlag (binderArgFlag bndr) = case split_foralls ty of { (bndrs, rho) -> (bndr:bndrs, rho) } split_foralls rho = ([], rho) @@ -448,6 +449,12 @@ splitIfaceSigmaTy ty = case split_rho ty2 of { (ps, tau) -> (ty1:ps, tau) } split_rho tau = ([], tau) +splitIfaceReqForallTy :: IfaceType -> ([IfaceForAllBndr], IfaceType) +splitIfaceReqForallTy (IfaceForAllTy bndr ty) + | isVisibleArgFlag (binderArgFlag bndr) + = case splitIfaceReqForallTy ty of { (bndrs, rho) -> (bndr:bndrs, rho) } +splitIfaceReqForallTy rho = ([], rho) + suppressIfaceInvisibles :: PrintExplicitKinds -> [IfaceTyConBinder] -> [a] -> [a] suppressIfaceInvisibles (PrintExplicitKinds True) _tys xs = xs suppressIfaceInvisibles (PrintExplicitKinds False) tys xs = suppress tys xs @@ -1184,8 +1191,23 @@ pprIfaceSigmaType show_forall ty = hideNonStandardTypes ppr_fn ty where ppr_fn iface_ty = - let (tvs, theta, tau) = splitIfaceSigmaTy iface_ty - in ppr_iface_forall_part show_forall tvs theta (ppr tau) + let (invis_tvs, theta, tau) = splitIfaceSigmaTy iface_ty + (req_tvs, tau') = splitIfaceReqForallTy tau + -- splitIfaceSigmaTy is recursive, so it will gather the binders after + -- the theta, i.e. forall a. theta => forall b. tau + -- will give you ([a,b], theta, tau). + -- + -- This isn't right when it comes to visible forall (see + -- testsuite/tests/polykinds/T18522-ppr), + -- so we split off required binders separately, + -- using splitIfaceReqForallTy. + -- + -- An alternative solution would be to make splitIfaceSigmaTy + -- non-recursive (see #18458). + -- Then it could handle both invisible and required binders, and + -- splitIfaceReqForallTy wouldn't be necessary here. + in ppr_iface_forall_part show_forall invis_tvs theta $ + sep [pprIfaceForAll req_tvs, ppr tau'] pprUserIfaceForAll :: [IfaceForAllBndr] -> SDoc pprUserIfaceForAll tvs ===================================== compiler/GHC/Parser.y ===================================== @@ -1080,7 +1080,7 @@ topdecl :: { LHsDecl GhcPs } -- The $(..) form is one possible form of infixexp -- but we treat an arbitrary expression just as if -- it had a $(..) wrapped around it - | infixexp {% runECP_P $1 >>= \ $1 -> + | infixexp {% runPV (unECP $1) >>= \ $1 -> return $ sLL $1 $> $ mkSpliceDecl $1 } -- Type classes @@ -1528,7 +1528,7 @@ decl_cls : at_decl_cls { $1 } -- A 'default' signature used with the generic-programming extension | 'default' infixexp '::' sigtype - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> do { v <- checkValSigLhs $2 ; let err = text "in default signature" <> colon <+> quotes (ppr $2) @@ -1671,8 +1671,8 @@ rules :: { OrdList (LRuleDecl GhcPs) } rule :: { LRuleDecl GhcPs } : STRING rule_activation rule_foralls infixexp '=' exp - {%runECP_P $4 >>= \ $4 -> - runECP_P $6 >>= \ $6 -> + {%runPV (unECP $4) >>= \ $4 -> + runPV (unECP $6) >>= \ $6 -> ams (sLL $1 $> $ HsRule { rd_ext = noExtField , rd_name = L (gl $1) (getSTRINGs $1, getSTRING $1) , rd_act = (snd $2) `orElse` AlwaysActive @@ -1800,19 +1800,19 @@ stringlist :: { Located (OrdList (Located StringLiteral)) } ----------------------------------------------------------------------------- -- Annotations annotation :: { LHsDecl GhcPs } - : '{-# ANN' name_var aexp '#-}' {% runECP_P $3 >>= \ $3 -> + : '{-# ANN' name_var aexp '#-}' {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) (ValueAnnProvenance $2) $3)) [mo $1,mc $4] } - | '{-# ANN' 'type' tycon aexp '#-}' {% runECP_P $4 >>= \ $4 -> + | '{-# ANN' 'type' tycon aexp '#-}' {% runPV (unECP $4) >>= \ $4 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) (TypeAnnProvenance $3) $4)) [mo $1,mj AnnType $2,mc $5] } - | '{-# ANN' 'module' aexp '#-}' {% runECP_P $3 >>= \ $3 -> + | '{-# ANN' 'module' aexp '#-}' {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) ModuleAnnProvenance $3)) @@ -1966,22 +1966,28 @@ type :: { LHsType GhcPs } mult :: { LHsType GhcPs } : btype { $1 } - btype :: { LHsType GhcPs } - : tyapps {% mergeOps (unLoc $1) } - -tyapps :: { Located [Located TyEl] } -- NB: This list is reversed - : tyapp { sL1 $1 [$1] } - | tyapps tyapp { sLL $1 $> $ $2 : unLoc $1 } - -tyapp :: { Located TyEl } - : atype { sL1 $1 $ TyElOpd (unLoc $1) } - - -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer - | PREFIX_AT atype { sLL $1 $> $ (TyElKindApp (comb2 $1 $2) $2) } - - | tyop { mapLoc TyElOpr $1 } - | unpackedness { sL1 $1 $ TyElUnpackedness (unLoc $1) } + : infixtype {% runPV $1 } + +infixtype :: { forall b. DisambTD b => PV (Located b) } + : ftype { $1 } + | ftype tyop infixtype { $1 >>= \ $1 -> + $3 >>= \ $3 -> + mkHsOpTyPV $1 $2 $3 } + | unpackedness infixtype { $2 >>= \ $2 -> + mkUnpackednessPV $1 $2 } + +ftype :: { forall b. DisambTD b => PV (Located b) } + : atype { mkHsAppTyHeadPV $1 } + | tyop { failOpFewArgs $1 } + | ftype tyarg { $1 >>= \ $1 -> + mkHsAppTyPV $1 $2 } + | ftype PREFIX_AT tyarg { $1 >>= \ $1 -> + mkHsAppKindTyPV $1 (getLoc $2) $3 } + +tyarg :: { LHsType GhcPs } + : atype { $1 } + | unpackedness atype {% addUnpackednessP $1 $2 } tyop :: { Located RdrName } : qtyconop { $1 } @@ -2222,8 +2228,9 @@ forall :: { Located ([AddAnn], Maybe [LHsTyVarBndr Specificity GhcPs]) } | {- empty -} { noLoc ([], Nothing) } constr_stuff :: { Located (Located RdrName, HsConDeclDetails GhcPs) } - : tyapps {% do { c <- mergeDataCon (unLoc $1) - ; return $ sL1 $1 c } } + : infixtype {% fmap (mapLoc (\b -> (dataConBuilderCon b, + dataConBuilderDetails b))) + (runPV $1) } fielddecls :: { [LConDeclField GhcPs] } : {- empty -} { [] } @@ -2308,7 +2315,7 @@ There's an awkward overlap with a type signature. Consider decl_no_th :: { LHsDecl GhcPs } : sigdecl { $1 } - | infixexp opt_sig rhs {% runECP_P $1 >>= \ $1 -> + | infixexp opt_sig rhs {% runPV (unECP $1) >>= \ $1 -> do { (ann,r) <- checkValDef $1 (snd $2) $3; let { l = comb2 $1 $> }; -- Depending upon what the pattern looks like we might get either @@ -2332,7 +2339,7 @@ decl :: { LHsDecl GhcPs } | splice_exp { sLL $1 $> $ mkSpliceDecl $1 } rhs :: { Located ([AddAnn],GRHSs GhcPs (LHsExpr GhcPs)) } - : '=' exp wherebinds {% runECP_P $2 >>= \ $2 -> return $ + : '=' exp wherebinds {% runPV (unECP $2) >>= \ $2 -> return $ sL (comb3 $1 $2 $3) ((mj AnnEqual $1 : (fst $ unLoc $3)) ,GRHSs noExtField (unguardedRHS (comb3 $1 $2 $3) $2) @@ -2346,7 +2353,7 @@ gdrhs :: { Located [LGRHS GhcPs (LHsExpr GhcPs)] } | gdrh { sL1 $1 [$1] } gdrh :: { LGRHS GhcPs (LHsExpr GhcPs) } - : '|' guardquals '=' exp {% runECP_P $4 >>= \ $4 -> + : '|' guardquals '=' exp {% runPV (unECP $4) >>= \ $4 -> ams (sL (comb2 $1 $>) $ GRHS noExtField (unLoc $2) $4) [mj AnnVbar $1,mj AnnEqual $3] } @@ -2354,7 +2361,7 @@ sigdecl :: { LHsDecl GhcPs } : -- See Note [Declaration/signature overlap] for why we need infixexp here infixexp '::' sigtype - {% do { $1 <- runECP_P $1 + {% do { $1 <- runPV (unECP $1) ; v <- checkValSigLhs $1 ; _ <- amsL (comb2 $1 $>) [mu AnnDcolon $2] ; return (sLL $1 $> $ SigD noExtField $ @@ -2450,30 +2457,30 @@ quasiquote :: { Located (HsSplice GhcPs) } exp :: { ECP } : infixexp '::' sigtype { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> rejectPragmaPV $1 >> amms (mkHsTySigPV (comb2 $1 $>) $1 $3) [mu AnnDcolon $2] } - | infixexp '-<' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '-<' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $1 $3 HsFirstOrderApp True) [mu Annlarrowtail $2] } - | infixexp '>-' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '>-' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $3 $1 HsFirstOrderApp False) [mu Annrarrowtail $2] } - | infixexp '-<<' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '-<<' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $1 $3 HsHigherOrderApp True) [mu AnnLarrowtail $2] } - | infixexp '>>-' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '>>-' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $3 $1 HsHigherOrderApp False) @@ -2487,8 +2494,8 @@ infixexp :: { ECP } { ECP $ superInfixOp $ $2 >>= \ $2 -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> rejectPragmaPV $1 >> amms (mkHsOpAppPV (comb2 $1 $>) $1 $2 $3) [mj AnnVal $2] } @@ -2500,14 +2507,14 @@ exp10p :: { ECP } exp_prag(e) :: { ECP } : prag_e e -- See Note [Pragmas and operator fixity] - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsPragE noExtField (snd $ unLoc $1) $2) (fst $ unLoc $1) } exp10 :: { ECP } : '-' fexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsNegAppPV (comb2 $1 $>) $2) [mj AnnMinus $1] } | fexp { $1 } @@ -2590,16 +2597,16 @@ prag_e :: { Located ([AddAnn], HsPragE GhcPs) } fexp :: { ECP } : fexp aexp { ECP $ superFunArg $ - runECP_PV $1 >>= \ $1 -> - runECP_PV $2 >>= \ $2 -> + unECP $1 >>= \ $1 -> + unECP $2 >>= \ $2 -> mkHsAppPV (comb2 $1 $>) $1 $2 } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer | fexp PREFIX_AT atype { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> amms (mkHsAppTypePV (comb2 $1 $>) $1 $3) [mj AnnAt $2] } - | 'static' aexp {% runECP_P $2 >>= \ $2 -> + | 'static' aexp {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsStatic noExtField $2) [mj AnnStatic $1] } @@ -2609,23 +2616,23 @@ aexp :: { ECP } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer : qvar TIGHT_INFIX_AT aexp { ECP $ - runECP_PV $3 >>= \ $3 -> + unECP $3 >>= \ $3 -> amms (mkHsAsPatPV (comb2 $1 $>) $1 $3) [mj AnnAt $2] } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer | PREFIX_TILDE aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsLazyPatPV (comb2 $1 $>) $2) [mj AnnTilde $1] } | PREFIX_BANG aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsBangPatPV (comb2 $1 $>) $2) [mj AnnBang $1] } | PREFIX_MINUS aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsNegAppPV (comb2 $1 $>) $2) [mj AnnMinus $1] } | '\\' apat apats '->' exp { ECP $ - runECP_PV $5 >>= \ $5 -> + unECP $5 >>= \ $5 -> amms (mkHsLamPV (comb2 $1 $>) (mkMatchGroup FromSource [sLL $1 $> $ Match { m_ext = noExtField , m_ctxt = LambdaExpr @@ -2633,7 +2640,7 @@ aexp :: { ECP } , m_grhss = unguardedGRHSs $5 }])) [mj AnnLam $1, mu AnnRarrow $4] } | 'let' binds 'in' exp { ECP $ - runECP_PV $4 >>= \ $4 -> + unECP $4 >>= \ $4 -> amms (mkHsLetPV (comb2 $1 $>) (snd (unLoc $2)) $4) (mj AnnLet $1:mj AnnIn $3 :(fst $ unLoc $2)) } @@ -2643,10 +2650,10 @@ aexp :: { ECP } (mkMatchGroup FromSource (snd $ unLoc $3))) (mj AnnLam $1:mj AnnCase $2:(fst $ unLoc $3)) } | 'if' exp optSemi 'then' exp optSemi 'else' exp - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> return $ ECP $ - runECP_PV $5 >>= \ $5 -> - runECP_PV $8 >>= \ $8 -> + unECP $5 >>= \ $5 -> + unECP $8 >>= \ $8 -> amms (mkHsIfPV (comb2 $1 $>) $2 (snd $3) $5 (snd $6) $8) (mj AnnIf $1:mj AnnThen $4 :mj AnnElse $7 @@ -2657,7 +2664,7 @@ aexp :: { ECP } ams (sLL $1 $> $ HsMultiIf noExtField (reverse $ snd $ unLoc $2)) (mj AnnIf $1:(fst $ unLoc $2)) } - | 'case' exp 'of' altslist {% runECP_P $2 >>= \ $2 -> + | 'case' exp 'of' altslist {% runPV (unECP $2) >>= \ $2 -> return $ ECP $ $4 >>= \ $4 -> amms (mkHsCasePV (comb3 $1 $3 $4) $2 (mkMatchGroup @@ -2681,8 +2688,8 @@ aexp :: { ECP } (snd $ unLoc $2))) (mj AnnMdo $1:(fst $ unLoc $2)) } | 'proc' aexp '->' exp - {% (checkPattern <=< runECP_P) $2 >>= \ p -> - runECP_P $4 >>= \ $4 at cmd -> + {% (checkPattern <=< runPV) (unECP $2) >>= \ p -> + runPV (unECP $4) >>= \ $4 at cmd -> fmap ecpFromExp $ ams (sLL $1 $> $ HsProc noExtField p (sLL $1 $> $ HsCmdTop noExtField cmd)) -- TODO: is LL right here? @@ -2692,7 +2699,7 @@ aexp :: { ECP } aexp1 :: { ECP } : aexp1 '{' fbinds '}' { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> $3 >>= \ $3 -> amms (mkHsRecordPV (comb2 $1 $>) (comb2 $2 $4) $1 (snd $3)) (moc $2:mcc $4:(fst $3)) } @@ -2716,7 +2723,7 @@ aexp2 :: { ECP } -- correct Haskell (you'd have to write '((+ 3), (4 -))') -- but the less cluttered version fell out of having texps. | '(' texp ')' { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsParPV (comb2 $1 $>) $2) [mop $1,mcp $3] } | '(' tup_exprs ')' { ECP $ $2 >>= \ $2 -> @@ -2724,7 +2731,7 @@ aexp2 :: { ECP } ((mop $1:fst $2) ++ [mcp $3]) } | '(#' texp '#)' { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkSumOrTuplePV (comb2 $1 $>) Unboxed (Tuple [L (gl $2) (Just $2)])) [mo $1,mc $3] } | '(#' tup_exprs '#)' { ECP $ @@ -2744,18 +2751,18 @@ aexp2 :: { ECP } | TH_TY_QUOTE tyvar {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } | TH_TY_QUOTE gtycon {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } | TH_TY_QUOTE {- nothing -} {% reportEmptyDoubleQuotes (getLoc $1) } - | '[|' exp '|]' {% runECP_P $2 >>= \ $2 -> + | '[|' exp '|]' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (ExpBr noExtField $2)) (if (hasE $1) then [mj AnnOpenE $1, mu AnnCloseQ $3] else [mu AnnOpenEQ $1,mu AnnCloseQ $3]) } - | '[||' exp '||]' {% runECP_P $2 >>= \ $2 -> + | '[||' exp '||]' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (TExpBr noExtField $2)) (if (hasE $1) then [mj AnnOpenE $1,mc $3] else [mo $1,mc $3]) } | '[t|' ktype '|]' {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (TypBr noExtField $2)) [mo $1,mu AnnCloseQ $3] } - | '[p|' infixexp '|]' {% (checkPattern <=< runECP_P) $2 >>= \p -> + | '[p|' infixexp '|]' {% (checkPattern <=< runPV) (unECP $2) >>= \p -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (PatBr noExtField p)) [mo $1,mu AnnCloseQ $3] } @@ -2765,7 +2772,7 @@ aexp2 :: { ECP } | quasiquote { ECP $ mkHsSplicePV $1 } -- arrow notation extension - | '(|' aexp cmdargs '|)' {% runECP_P $2 >>= \ $2 -> + | '(|' aexp cmdargs '|)' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrForm noExtField $2 Prefix Nothing (reverse $3)) @@ -2777,14 +2784,14 @@ splice_exp :: { LHsExpr GhcPs } splice_untyped :: { Located (HsSplice GhcPs) } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer - : PREFIX_DOLLAR aexp2 {% runECP_P $2 >>= \ $2 -> + : PREFIX_DOLLAR aexp2 {% runPV (unECP $2) >>= \ $2 -> ams (sLL $1 $> $ mkUntypedSplice DollarSplice $2) [mj AnnDollar $1] } splice_typed :: { Located (HsSplice GhcPs) } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer : PREFIX_DOLLAR_DOLLAR aexp2 - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> ams (sLL $1 $> $ mkTypedSplice DollarSplice $2) [mj AnnDollarDollar $1] } @@ -2793,7 +2800,7 @@ cmdargs :: { [LHsCmdTop GhcPs] } | {- empty -} { [] } acmd :: { LHsCmdTop GhcPs } - : aexp {% runECP_P $1 >>= \ cmd -> + : aexp {% runPV (unECP $1) >>= \ cmd -> runPV (checkCmdBlockArguments cmd) >>= \ _ -> return (sL1 cmd $ HsCmdTop noExtField cmd) } @@ -2827,21 +2834,21 @@ texp :: { ECP } -- Meanwhile, the renamer checks that real sections appear -- inside parens. | infixexp qop - {% runECP_P $1 >>= \ $1 -> + {% runPV (unECP $1) >>= \ $1 -> runPV (rejectPragmaPV $1) >> runPV $2 >>= \ $2 -> return $ ecpFromExp $ sLL $1 $> $ SectionL noExtField $1 $2 } | qopm infixexp { ECP $ superInfixOp $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> $1 >>= \ $1 -> mkHsSectionR_PV (comb2 $1 $>) $1 $2 } -- View patterns get parenthesized above | exp '->' texp { ECP $ - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> amms (mkHsViewPatPV (comb2 $1 $>) $1 $3) [mu AnnRarrow $2] } -- Always at least one comma or bar. @@ -2850,12 +2857,12 @@ texp :: { ECP } -- in GHC.Hs.Expr. tup_exprs :: { forall b. DisambECP b => PV ([AddAnn],SumOrTuple b) } : texp commas_tup_tail - { runECP_PV $1 >>= \ $1 -> + { unECP $1 >>= \ $1 -> $2 >>= \ $2 -> do { addAnnotation (gl $1) AnnComma (fst $2) ; return ([],Tuple ((sL1 $1 (Just $1)) : snd $2)) } } - | texp bars { runECP_PV $1 >>= \ $1 -> return $ + | texp bars { unECP $1 >>= \ $1 -> return $ (mvbars (fst $2), Sum 1 (snd $2 + 1) $1) } | commas tup_tail @@ -2865,7 +2872,7 @@ tup_exprs :: { forall b. DisambECP b => PV ([AddAnn],SumOrTuple b) } ([],Tuple (map (\l -> L l Nothing) (fst $1) ++ $2)) } } | bars texp bars0 - { runECP_PV $2 >>= \ $2 -> return $ + { unECP $2 >>= \ $2 -> return $ (mvbars (fst $1) ++ mvbars (fst $3), Sum (snd $1 + 1) (snd $1 + snd $3 + 1) $2) } -- Always starts with commas; always follows an expr @@ -2879,11 +2886,11 @@ commas_tup_tail : commas tup_tail -- Always follows a comma tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] } - : texp commas_tup_tail { runECP_PV $1 >>= \ $1 -> + : texp commas_tup_tail { unECP $1 >>= \ $1 -> $2 >>= \ $2 -> addAnnotation (gl $1) AnnComma (fst $2) >> return ((L (gl $1) (Just $1)) : snd $2) } - | texp { runECP_PV $1 >>= \ $1 -> + | texp { unECP $1 >>= \ $1 -> return [L (gl $1) (Just $1)] } | {- empty -} { return [noLoc Nothing] } @@ -2894,48 +2901,48 @@ tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] } -- avoiding another shift/reduce-conflict. -- Never empty. list :: { forall b. DisambECP b => SrcSpan -> PV (Located b) } - : texp { \loc -> runECP_PV $1 >>= \ $1 -> + : texp { \loc -> unECP $1 >>= \ $1 -> mkHsExplicitListPV loc [$1] } | lexps { \loc -> $1 >>= \ $1 -> mkHsExplicitListPV loc (reverse $1) } - | texp '..' { \loc -> runECP_PV $1 >>= \ $1 -> + | texp '..' { \loc -> unECP $1 >>= \ $1 -> ams (L loc $ ArithSeq noExtField Nothing (From $1)) [mj AnnDotdot $2] >>= ecpFromExp' } | texp ',' exp '..' { \loc -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> ams (L loc $ ArithSeq noExtField Nothing (FromThen $1 $3)) [mj AnnComma $2,mj AnnDotdot $4] >>= ecpFromExp' } - | texp '..' exp { \loc -> runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + | texp '..' exp { \loc -> unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> ams (L loc $ ArithSeq noExtField Nothing (FromTo $1 $3)) [mj AnnDotdot $2] >>= ecpFromExp' } | texp ',' exp '..' exp { \loc -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> - runECP_PV $5 >>= \ $5 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> + unECP $5 >>= \ $5 -> ams (L loc $ ArithSeq noExtField Nothing (FromThenTo $1 $3 $5)) [mj AnnComma $2,mj AnnDotdot $4] >>= ecpFromExp' } | texp '|' flattenedpquals { \loc -> checkMonadComp >>= \ ctxt -> - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> ams (L loc $ mkHsComp ctxt (unLoc $3) $1) [mj AnnVbar $2] >>= ecpFromExp' } lexps :: { forall b. DisambECP b => PV [Located b] } : lexps ',' texp { $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $3 >>= \ $3 -> addAnnotation (gl $ head $ $1) AnnComma (gl $2) >> return (((:) $! $3) $! $1) } - | texp ',' texp { runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + | texp ',' texp { unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> addAnnotation (gl $1) AnnComma (gl $2) >> return [$3,$1] } @@ -2985,20 +2992,20 @@ squals :: { Located [LStmt GhcPs (LHsExpr GhcPs)] } -- In reverse order, becau transformqual :: { Located ([AddAnn],[LStmt GhcPs (LHsExpr GhcPs)] -> Stmt GhcPs (LHsExpr GhcPs)) } -- Function is applied to a list of stmts *in order* - : 'then' exp {% runECP_P $2 >>= \ $2 -> return $ + : 'then' exp {% runPV (unECP $2) >>= \ $2 -> return $ sLL $1 $> ([mj AnnThen $1], \ss -> (mkTransformStmt ss $2)) } - | 'then' exp 'by' exp {% runECP_P $2 >>= \ $2 -> - runECP_P $4 >>= \ $4 -> + | 'then' exp 'by' exp {% runPV (unECP $2) >>= \ $2 -> + runPV (unECP $4) >>= \ $4 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnBy $3], \ss -> (mkTransformByStmt ss $2 $4)) } | 'then' 'group' 'using' exp - {% runECP_P $4 >>= \ $4 -> + {% runPV (unECP $4) >>= \ $4 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnUsing $3], \ss -> (mkGroupUsingStmt ss $4)) } | 'then' 'group' 'by' exp 'using' exp - {% runECP_P $4 >>= \ $4 -> - runECP_P $6 >>= \ $6 -> + {% runPV (unECP $4) >>= \ $4 -> + runPV (unECP $6) >>= \ $6 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnBy $3,mj AnnUsing $5], \ss -> (mkGroupByUsingStmt ss $4 $6)) } @@ -3072,7 +3079,7 @@ alt_rhs :: { forall b. DisambECP b => PV (Located ([AddAnn],GRHSs GhcPs (Located return $ sLL alt $> (fst $ unLoc $2, GRHSs noExtField (unLoc alt) (snd $ unLoc $2)) } ralt :: { forall b. DisambECP b => PV (Located [LGRHS GhcPs (Located b)]) } - : '->' exp { runECP_PV $2 >>= \ $2 -> + : '->' exp { unECP $2 >>= \ $2 -> ams (sLL $1 $> (unguardedRHS (comb2 $1 $2) $2)) [mu AnnRarrow $1] } | gdpats { $1 >>= \gdpats -> @@ -3095,7 +3102,7 @@ ifgdpats :: { Located ([AddAnn],[LGRHS GhcPs (LHsExpr GhcPs)]) } gdpat :: { forall b. DisambECP b => PV (LGRHS GhcPs (Located b)) } : '|' guardquals '->' exp - { runECP_PV $4 >>= \ $4 -> + { unECP $4 >>= \ $4 -> ams (sL (comb2 $1 $>) $ GRHS noExtField (unLoc $2) $4) [mj AnnVbar $1,mu AnnRarrow $3] } @@ -3104,15 +3111,15 @@ gdpat :: { forall b. DisambECP b => PV (LGRHS GhcPs (Located b)) } -- Bangs inside are parsed as infix operator applications, so that -- we parse them right when bang-patterns are off pat :: { LPat GhcPs } -pat : exp {% (checkPattern <=< runECP_P) $1 } +pat : exp {% (checkPattern <=< runPV) (unECP $1) } bindpat :: { LPat GhcPs } -bindpat : exp {% -- See Note [Parser-Validator ReaderT SDoc] in GHC.Parser.PostProcess +bindpat : exp {% -- See Note [Parser-Validator Hint] in GHC.Parser.PostProcess checkPattern_msg (text "Possibly caused by a missing 'do'?") - (runECP_PV $1) } + (unECP $1) } apat :: { LPat GhcPs } -apat : aexp {% (checkPattern <=< runECP_P) $1 } +apat : aexp {% (checkPattern <=< runPV) (unECP $1) } apats :: { [LPat GhcPs] } : apat apats { $1 : $2 } @@ -3175,10 +3182,10 @@ stmt :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } (mj AnnRec $1:(fst $ unLoc $2)) } qual :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } - : bindpat '<-' exp { runECP_PV $3 >>= \ $3 -> + : bindpat '<-' exp { unECP $3 >>= \ $3 -> ams (sLL $1 $> $ mkPsBindStmt $1 $3) [mu AnnLarrow $2] } - | exp { runECP_PV $1 >>= \ $1 -> + | exp { unECP $1 >>= \ $1 -> return $ sL1 $1 $ mkBodyStmt $1 } | 'let' binds { ams (sLL $1 $> $ LetStmt noExtField (snd $ unLoc $2)) (mj AnnLet $1:(fst $ unLoc $2)) } @@ -3201,7 +3208,7 @@ fbinds1 :: { forall b. DisambECP b => PV ([AddAnn],([LHsRecField GhcPs (Located | '..' { return ([mj AnnDotdot $1],([], Just (getLoc $1))) } fbind :: { forall b. DisambECP b => PV (LHsRecField GhcPs (Located b)) } - : qvar '=' texp { runECP_PV $3 >>= \ $3 -> + : qvar '=' texp { unECP $3 >>= \ $3 -> ams (sLL $1 $> $ HsRecField (sL1 $1 $ mkFieldOcc $1) $3 False) [mj AnnEqual $2] } -- RHS is a 'texp', allowing view patterns (#6038) @@ -3227,7 +3234,7 @@ dbinds :: { Located [LIPBind GhcPs] } -- | {- empty -} { [] } dbind :: { LIPBind GhcPs } -dbind : ipvar '=' exp {% runECP_P $3 >>= \ $3 -> +dbind : ipvar '=' exp {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (IPBind noExtField (Left $1) $3)) [mj AnnEqual $2] } ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -68,7 +68,6 @@ module GHC.Parser.PostProcess ( checkRecordSyntax, checkEmptyGADTs, addFatalError, hintBangPat, - TyEl(..), mergeOps, mergeDataCon, mkBangTy, UnpackednessPragma(..), @@ -96,13 +95,19 @@ module GHC.Parser.PostProcess ( -- Expression/command/pattern ambiguity resolution PV, runPV, - ECP(ECP, runECP_PV), - runECP_P, + ECP(ECP, unECP), DisambInfixOp(..), DisambECP(..), ecpFromExp, ecpFromCmd, - PatBuilder + PatBuilder, + + -- Type/datacon ambiguity resolution + DisambTD(..), + addUnpackednessP, + DataConBuilder(), + dataConBuilderCon, + dataConBuilderDetails, ) where import GHC.Prelude @@ -126,20 +131,20 @@ import GHC.Types.ForeignCall import GHC.Builtin.Names ( allNameStrings ) import GHC.Types.SrcLoc import GHC.Types.Unique ( hasKey ) -import GHC.Data.OrdList ( OrdList, fromOL ) +import GHC.Data.OrdList import GHC.Utils.Outputable as Outputable import GHC.Data.FastString import GHC.Data.Maybe import GHC.Utils.Misc import GHC.Parser.Annotation import Data.List +import Data.Foldable import GHC.Driver.Session ( WarningFlag(..), DynFlags ) import GHC.Utils.Error ( Messages ) import Control.Monad import Text.ParserCombinators.ReadP as ReadP import Data.Char -import qualified Data.Monoid as Monoid import Data.Data ( dataTypeOf, fromConstr, dataTypeConstrs ) import Data.Kind ( Type ) @@ -559,30 +564,6 @@ context, so (C t1 t2) is a constraint and 'C' is a type constructor. As the result, in order to determine whether (C t1 t2) declares a data constructor, a type, or a context, we would need unlimited lookahead which 'happy' is not so happy with. - -The solution that accounts for all of these issues is to initially parse data -declarations and types as a reversed list of TyEl: - - data TyEl = TyElOpr RdrName - | TyElOpd (HsType GhcPs) - | ... - -For example, both occurrences of (C ! D) in the following example are parsed -into equal lists of TyEl: - - data T = C ! D => C ! D results in [ TyElOpd (HsTyVar "D") - , TyElOpr "!" - , TyElOpd (HsTyVar "C") ] - -Note that elements are in reverse order. Also, 'C' is parsed as a type -constructor (HsTyVar) even when it is a data constructor. We fix this in -`tyConToDataCon`. - -By the time the list of TyEl is assembled, we have looked ahead enough to -decide whether to reduce using `mergeOps` (for types) or `mergeDataCon` (for -data constructors). These functions are where the actual job of parsing is -done. - -} -- | Reinterpret a type constructor, including type operators, as a data @@ -798,7 +779,7 @@ to make setRdrNameSpace partial, so we just make an Unqual name instead. It really doesn't matter! -} -eitherToP :: Either (SrcSpan, SDoc) a -> P a +eitherToP :: MonadP m => Either (SrcSpan, SDoc) a -> m a -- Adapts the Either monad to the P monad eitherToP (Left (loc, doc)) = addFatalError loc doc eitherToP (Right thing) = return thing @@ -1309,323 +1290,31 @@ isFunLhs e = go e [] [] _ -> return Nothing } go _ _ _ = return Nothing --- | Either an operator or an operand. -data TyEl = TyElOpr RdrName | TyElOpd (HsType GhcPs) - | TyElKindApp SrcSpan (LHsType GhcPs) - -- See Note [TyElKindApp SrcSpan interpretation] - | TyElUnpackedness UnpackednessPragma - - -{- Note [TyElKindApp SrcSpan interpretation] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -A TyElKindApp captures type application written in haskell as - - @ Foo - -where Foo is some type. - -The SrcSpan reflects both elements, and there are AnnAt and AnnVal API -Annotations attached to this SrcSpan for the specific locations of -each within it. --} - -instance Outputable TyEl where - ppr (TyElOpr name) = ppr name - ppr (TyElOpd ty) = ppr ty - ppr (TyElKindApp _ ki) = text "@" <> ppr ki - ppr (TyElUnpackedness (UnpackednessPragma _ _ unpk)) = ppr unpk - --- | Extract a strictness/unpackedness annotation from the front of a reversed --- 'TyEl' list. -pUnpackedness - :: [Located TyEl] -- reversed TyEl - -> Maybe (SrcSpan, UnpackednessPragma, - [Located TyEl] {- remaining TyEl -}) -pUnpackedness (L l x1 : xs) | TyElUnpackedness up <- x1 = Just (l, up, xs) -pUnpackedness _ = Nothing - -pBangTy - :: LHsType GhcPs -- a type to be wrapped inside HsBangTy - -> [Located TyEl] -- reversed TyEl - -> ( Bool {- has a strict mark been consumed? -} - , LHsType GhcPs {- the resulting BangTy -} - , P () {- add annotations -} - , [Located TyEl] {- remaining TyEl -}) -pBangTy lt@(L l1 _) xs = - case pUnpackedness xs of - Nothing -> (False, lt, pure (), xs) - Just (l2, UnpackednessPragma anns prag unpk, xs') -> - let bl = combineSrcSpans l1 l2 - bt = addUnpackedness (prag, unpk) lt - in (True, L bl bt, addAnnsAt bl anns, xs') - mkBangTy :: SrcStrictness -> LHsType GhcPs -> HsType GhcPs mkBangTy strictness = HsBangTy noExtField (HsSrcBang NoSourceText NoSrcUnpack strictness) --- Result of parsing {-# UNPACK #-} or {-# NOUNPACK #-} +-- | Result of parsing @{-\# UNPACK \#-}@ or @{-\# NOUNPACK \#-}@. data UnpackednessPragma = UnpackednessPragma [AddAnn] SourceText SrcUnpackedness -addUnpackedness :: (SourceText, SrcUnpackedness) -> LHsType GhcPs -> HsType GhcPs -addUnpackedness (prag, unpk) (L _ (HsBangTy x bang t)) - | HsSrcBang NoSourceText NoSrcUnpack strictness <- bang - = HsBangTy x (HsSrcBang prag unpk strictness) t -addUnpackedness (prag, unpk) t - = HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t - --- | Merge a /reversed/ and /non-empty/ soup of operators and operands --- into a type. --- --- User input: @F x y + G a b * X@ --- Input to 'mergeOps': [X, *, b, a, G, +, y, x, F] --- Output corresponds to what the user wrote assuming all operators are of the --- same fixity and right-associative. --- --- It's a bit silly that we're doing it at all, as the renamer will have to --- rearrange this, and it'd be easier to keep things separate. --- --- See Note [Parsing data constructors is hard] -mergeOps :: [Located TyEl] -> P (LHsType GhcPs) -mergeOps ((L l1 (TyElOpd t)) : xs) - | (_, t', addAnns, xs') <- pBangTy (L l1 t) xs - , null xs' -- We accept a BangTy only when there are no preceding TyEl. - = addAnns >> return t' -mergeOps all_xs = go (0 :: Int) [] id all_xs - where - -- NB. When modifying clauses in 'go', make sure that the reasoning in - -- Note [Non-empty 'acc' in mergeOps clause [end]] is still correct. - - -- clause [unpk]: - -- handle (NO)UNPACK pragmas - go k acc ops_acc ((L l (TyElUnpackedness (UnpackednessPragma anns unpkSrc unpk))):xs) = - if not (null acc) && null xs - then do { acc' <- eitherToP $ mergeOpsAcc acc - ; let a = ops_acc acc' - strictMark = HsSrcBang unpkSrc unpk NoSrcStrict - bl = combineSrcSpans l (getLoc a) - bt = HsBangTy noExtField strictMark a - ; addAnnsAt bl anns - ; return (L bl bt) } - else addFatalError l unpkError - where - unpkSDoc = case unpkSrc of - NoSourceText -> ppr unpk - SourceText str -> text str <> text " #-}" - unpkError - | not (null xs) = unpkSDoc <+> text "cannot appear inside a type." - | null acc && k == 0 = unpkSDoc <+> text "must be applied to a type." - | otherwise = - -- See Note [Impossible case in mergeOps clause [unpk]] - panic "mergeOps.UNPACK: impossible position" - - -- clause [opr]: - -- when we encounter an operator, we must have accumulated - -- something for its rhs, and there must be something left - -- to build its lhs. - go k acc ops_acc ((L l (TyElOpr op)):xs) = - if null acc || null (filter isTyElOpd xs) - then failOpFewArgs (L l op) - else do { acc' <- eitherToP (mergeOpsAcc acc) - ; go (k + 1) [] (\c -> mkLHsOpTy c (L l op) (ops_acc acc')) xs } - where - isTyElOpd (L _ (TyElOpd _)) = True - isTyElOpd _ = False - - -- clause [opd]: - -- whenever an operand is encountered, it is added to the accumulator - go k acc ops_acc ((L l (TyElOpd a)):xs) = go k (HsValArg (L l a):acc) ops_acc xs - - -- clause [tyapp]: - -- whenever a type application is encountered, it is added to the accumulator - go k acc ops_acc ((L _ (TyElKindApp l a)):xs) = go k (HsTypeArg l a:acc) ops_acc xs - - -- clause [end] - -- See Note [Non-empty 'acc' in mergeOps clause [end]] - go _ acc ops_acc [] = do { acc' <- eitherToP (mergeOpsAcc acc) - ; return (ops_acc acc') } - -mergeOpsAcc :: [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> Either (SrcSpan, SDoc) (LHsType GhcPs) -mergeOpsAcc [] = panic "mergeOpsAcc: empty input" -mergeOpsAcc (HsTypeArg _ (L loc ki):_) - = Left (loc, text "Unexpected type application:" <+> ppr ki) -mergeOpsAcc (HsValArg ty : xs) = go1 ty xs - where - go1 :: LHsType GhcPs - -> [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> Either (SrcSpan, SDoc) (LHsType GhcPs) - go1 lhs [] = Right lhs - go1 lhs (x:xs) = case x of - HsValArg ty -> go1 (mkHsAppTy lhs ty) xs - HsTypeArg loc ki -> let ty = mkHsAppKindTy loc lhs ki - in go1 ty xs - HsArgPar _ -> go1 lhs xs -mergeOpsAcc (HsArgPar _: xs) = mergeOpsAcc xs - -{- Note [Impossible case in mergeOps clause [unpk]] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -This case should never occur. Let us consider all possible -variations of 'acc', 'xs', and 'k': - - acc xs k -============================== - null | null 0 -- "must be applied to a type" - null | not null 0 -- "must be applied to a type" -not null | null 0 -- successful parse -not null | not null 0 -- "cannot appear inside a type" - null | null >0 -- handled in clause [opr] - null | not null >0 -- "cannot appear inside a type" -not null | null >0 -- successful parse -not null | not null >0 -- "cannot appear inside a type" - -The (null acc && null xs && k>0) case is handled in clause [opr] -by the following check: - - if ... || null (filter isTyElOpd xs) - then failOpFewArgs (L l op) - -We know that this check has been performed because k>0, and by -the time we reach the end of the list (null xs), the only way -for (null acc) to hold is that there was not a single TyElOpd -between the operator and the end of the list. But this case is -caught by the check and reported as 'failOpFewArgs'. --} - -{- Note [Non-empty 'acc' in mergeOps clause [end]] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In clause [end] we need to know that 'acc' is non-empty to call 'mergeAcc' -without a check. - -Running 'mergeOps' with an empty input list is forbidden, so we do not consider -this possibility. This means we'll hit at least one other clause before we -reach clause [end]. - -* Clauses [unpk] and [doc] do not call 'go' recursively, so we cannot hit - clause [end] from there. -* Clause [opd] makes 'acc' non-empty, so if we hit clause [end] after it, 'acc' - will be non-empty. -* Clause [opr] checks that (filter isTyElOpd xs) is not null - so we are going - to hit clause [opd] at least once before we reach clause [end], making 'acc' - non-empty. -* There are no other clauses. - -Therefore, it is safe to omit a check for non-emptiness of 'acc' in clause -[end]. - --} - -pInfixSide :: [Located TyEl] -> Maybe (LHsType GhcPs, P (), [Located TyEl]) -pInfixSide ((L l (TyElOpd t)):xs) - | (True, t', addAnns, xs') <- pBangTy (L l t) xs - = Just (t', addAnns, xs') -pInfixSide (el:xs1) - | Just t1 <- pLHsTypeArg el - = go [t1] xs1 - where - go :: [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> [Located TyEl] -> Maybe (LHsType GhcPs, P (), [Located TyEl]) - go acc (el:xs) - | Just t <- pLHsTypeArg el - = go (t:acc) xs - go acc xs = case mergeOpsAcc acc of - Left _ -> Nothing - Right acc' -> Just (acc', pure (), xs) -pInfixSide _ = Nothing - -pLHsTypeArg :: Located TyEl -> Maybe (HsArg (LHsType GhcPs) (LHsKind GhcPs)) -pLHsTypeArg (L l (TyElOpd a)) = Just (HsValArg (L l a)) -pLHsTypeArg (L _ (TyElKindApp l a)) = Just (HsTypeArg l a) -pLHsTypeArg _ = Nothing - -orErr :: Maybe a -> b -> Either b a -orErr (Just a) _ = Right a -orErr Nothing b = Left b - --- | Merge a /reversed/ and /non-empty/ soup of operators and operands --- into a data constructor. --- --- User input: @C !A B -- ^ doc@ --- Input to 'mergeDataCon': ["doc", B, !A, C] --- Output: (C, PrefixCon [!A, B], "doc") --- --- See Note [Parsing data constructors is hard] -mergeDataCon - :: [Located TyEl] - -> P ( Located RdrName -- constructor name - , HsConDeclDetails GhcPs -- constructor field information - ) -mergeDataCon all_xs = - do { (addAnns, a) <- eitherToP res - ; addAnns - ; return a } +-- | Annotate a type with either an @{-\# UNPACK \#-}@ or a @{-\# NOUNPACK \#-}@ pragma. +addUnpackednessP :: MonadP m => Located UnpackednessPragma -> LHsType GhcPs -> m (LHsType GhcPs) +addUnpackednessP (L lprag (UnpackednessPragma anns prag unpk)) ty = do + let l' = combineSrcSpans lprag (getLoc ty) + t' = addUnpackedness ty + addAnnsAt l' anns + return (L l' t') where - -- The result of merging the list of reversed TyEl into a - -- data constructor, along with [AddAnn]. - res = goFirst all_xs - - goFirst [ L l (TyElOpd (HsTyVar _ _ (L _ tc))) ] - = do { data_con <- tyConToDataCon l tc - ; return (pure (), (data_con, PrefixCon [])) } - goFirst ((L l (TyElOpd (HsRecTy _ fields))):xs) - | [ L l' (TyElOpd (HsTyVar _ _ (L _ tc))) ] <- xs - = do { data_con <- tyConToDataCon l' tc - ; return (pure (), (data_con, RecCon (L l fields))) } - goFirst [L l (TyElOpd (HsTupleTy _ HsBoxedOrConstraintTuple ts))] - = return ( pure () - , ( L l (getRdrName (tupleDataCon Boxed (length ts))) - , PrefixCon (map hsLinear ts) ) ) - goFirst ((L l (TyElOpd t)):xs) - | (_, t', addAnns, xs') <- pBangTy (L l t) xs - = go addAnns [t'] xs' - goFirst (L l (TyElKindApp _ _):_) - = goInfix Monoid.<> Left (l, kindAppErr) - goFirst xs - = go (pure ()) [] xs - - go addAnns ts [ L l (TyElOpd (HsTyVar _ _ (L _ tc))) ] - = do { data_con <- tyConToDataCon l tc - ; return (addAnns, (data_con, PrefixCon (map hsLinear ts))) } - go addAnns ts ((L l (TyElOpd t)):xs) - | (_, t', addAnns', xs') <- pBangTy (L l t) xs - = go (addAnns >> addAnns') (t':ts) xs' - go _ _ ((L _ (TyElOpr _)):_) = - -- Encountered an operator: backtrack to the beginning and attempt - -- to parse as an infix definition. - goInfix - go _ _ (L l (TyElKindApp _ _):_) = goInfix Monoid.<> Left (l, kindAppErr) - go _ _ _ = Left malformedErr - where - malformedErr = - ( foldr combineSrcSpans noSrcSpan (map getLoc all_xs) - , text "Cannot parse data constructor" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs)) - - goInfix = - do { let xs0 = all_xs - ; (rhs, rhs_addAnns, xs1) <- pInfixSide xs0 `orErr` malformedErr - ; (op, xs3) <- case xs1 of - (L l (TyElOpr op)) : xs3 -> - do { data_con <- tyConToDataCon l op - ; return (data_con, xs3) } - _ -> Left malformedErr - ; (lhs, lhs_addAnns, xs5) <- pInfixSide xs3 `orErr` malformedErr - ; unless (null xs5) (Left malformedErr) - ; let addAnns = lhs_addAnns >> rhs_addAnns - ; return (addAnns, (op, InfixCon (hsLinear lhs) (hsLinear rhs))) } - where - malformedErr = - ( foldr combineSrcSpans noSrcSpan (map getLoc all_xs) - , text "Cannot parse an infix data constructor" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs)) - - kindAppErr = - text "Unexpected kind application" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs) + -- If we have a HsBangTy that only has a strictness annotation, + -- such as ~T or !T, then add the pragma to the existing HsBangTy. + -- + -- Otherwise, wrap the type in a new HsBangTy constructor. + addUnpackedness (L _ (HsBangTy x bang t)) + | HsSrcBang NoSourceText NoSrcUnpack strictness <- bang + = HsBangTy x (HsSrcBang prag unpk strictness) t + addUnpackedness t + = HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t --------------------------------------------------------------------------- -- | Check for monad comprehensions @@ -1645,7 +1334,6 @@ checkMonadComp = do -- See Note [Ambiguous syntactic categories] -- --- See Note [Parser-Validator] -- See Note [Ambiguous syntactic categories] -- -- This newtype is required to avoid impredicative types in monadic @@ -1659,10 +1347,7 @@ checkMonadComp = do -- P (forall b. DisambECP b => PV (Located b)) -- newtype ECP = - ECP { runECP_PV :: forall b. DisambECP b => PV (Located b) } - -runECP_P :: DisambECP b => ECP -> P (Located b) -runECP_P p = runPV (runECP_PV p) + ECP { unECP :: forall b. DisambECP b => PV (Located b) } ecpFromExp :: LHsExpr GhcPs -> ECP ecpFromExp a = ECP (ecpFromExp' a) @@ -2053,9 +1738,145 @@ mkPatRec (unLoc -> PatBuilderVar c) (HsRecFields fs dd) mkPatRec p _ = addFatalError (getLoc p) $ text "Not a record constructor:" <+> ppr p +-- | Disambiguate constructs that may appear when we do not know +-- ahead of time whether we are parsing a type or a newtype/data constructor. +-- +-- See Note [Ambiguous syntactic categories] for the general idea. +-- +-- See Note [Parsing data constructors is hard] for the specific issue this +-- particular class is solving. +-- +class DisambTD b where + -- | Process the head of a type-level function/constructor application, + -- i.e. the @H@ in @H a b c at . + mkHsAppTyHeadPV :: LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f x@ (function application or prefix data constructor). + mkHsAppTyPV :: Located b -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f \@t@ (visible kind application) + mkHsAppKindTyPV :: Located b -> SrcSpan -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f \# x@ (infix operator) + mkHsOpTyPV :: LHsType GhcPs -> Located RdrName -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @{-\# UNPACK \#-} t@ (unpack/nounpack pragma) + mkUnpackednessPV :: Located UnpackednessPragma -> Located b -> PV (Located b) + +instance DisambTD (HsType GhcPs) where + mkHsAppTyHeadPV = return + mkHsAppTyPV t1 t2 = return (mkHsAppTy t1 t2) + mkHsAppKindTyPV t l_at ki = return (mkHsAppKindTy l' t ki) + where l' = combineSrcSpans l_at (getLoc ki) + mkHsOpTyPV t1 op t2 = return (mkLHsOpTy t1 op t2) + mkUnpackednessPV = addUnpackednessP + +-- | An accumulator to build a prefix data constructor, +-- e.g. when parsing @MkT A B C@, the accumulator will evolve as follows: +-- +-- @ +-- 1. PrefixDataConBuilder [] MkT +-- 2. PrefixDataConBuilder [A] MkT +-- 3. PrefixDataConBuilder [A, B] MkT +-- 4. PrefixDataConBuilder [A, B, C] MkT +-- @ +-- +-- There are two reasons we have a separate builder type instead of using +-- @HsConDeclDetails GhcPs@ directly: +-- +-- 1. It's faster, because 'OrdList' gives us constant-time snoc. +-- 2. Having a separate type helps ensure that we don't forget to finalize a +-- 'RecTy' into a 'RecCon' (we do that in 'dataConBuilderDetails'). +-- +-- See Note [PatBuilder] for another builder type used in the parser. +-- Here the technique is similar, but the motivation is different. +data DataConBuilder + = PrefixDataConBuilder + (OrdList (LHsType GhcPs)) -- Data constructor fields + (Located RdrName) -- Data constructor name + | InfixDataConBuilder + (LHsType GhcPs) -- LHS field + (Located RdrName) -- Data constructor name + (LHsType GhcPs) -- RHS field + +dataConBuilderCon :: DataConBuilder -> Located RdrName +dataConBuilderCon (PrefixDataConBuilder _ dc) = dc +dataConBuilderCon (InfixDataConBuilder _ dc _) = dc + +dataConBuilderDetails :: DataConBuilder -> HsConDeclDetails GhcPs + +-- Detect when the record syntax is used: +-- data T = MkT { ... } +dataConBuilderDetails (PrefixDataConBuilder flds _) + | [L l_t (HsRecTy _ fields)] <- toList flds + = RecCon (L l_t fields) + +-- Normal prefix constructor, e.g. data T = MkT A B C +dataConBuilderDetails (PrefixDataConBuilder flds _) + = PrefixCon (map hsLinear (toList flds)) + +-- Infix constructor, e.g. data T = Int :! Bool +dataConBuilderDetails (InfixDataConBuilder lhs _ rhs) + = InfixCon (hsLinear lhs) (hsLinear rhs) + +instance Outputable DataConBuilder where + ppr (PrefixDataConBuilder flds data_con) = + hang (ppr data_con) 2 (sep (map ppr (toList flds))) + ppr (InfixDataConBuilder lhs data_con rhs) = + ppr lhs <+> ppr data_con <+> ppr rhs + +instance DisambTD DataConBuilder where + mkHsAppTyHeadPV = tyToDataConBuilder + + mkHsAppTyPV (L l (PrefixDataConBuilder flds fn)) t = + return $ + L (combineSrcSpans l (getLoc t)) + (PrefixDataConBuilder (flds `snocOL` t) fn) + mkHsAppTyPV (L _ InfixDataConBuilder{}) _ = + -- This case is impossible because of the way + -- the grammar in Parser.y is written (see infixtype/ftype). + panic "mkHsAppTyPV: InfixDataConBuilder" + + mkHsAppKindTyPV lhs l_at ki = + addFatalError l_at $ + hang (text "Unexpected kind application in a data/newtype declaration:") 2 + (ppr lhs <+> text "@" <> ppr ki) + + mkHsOpTyPV lhs (L l_tc tc) rhs = do + check_no_ops (unLoc rhs) -- check the RHS because parsing type operators is right-associative + data_con <- eitherToP $ tyConToDataCon l_tc tc + return $ L l (InfixDataConBuilder lhs data_con rhs) + where + l = combineLocs lhs rhs + check_no_ops (HsBangTy _ _ t) = check_no_ops (unLoc t) + check_no_ops (HsOpTy{}) = + addError l $ + hang (text "Cannot parse an infix data constructor in a data/newtype declaration:") + 2 (ppr lhs <+> ppr tc <+> ppr rhs) + check_no_ops _ = return () + + mkUnpackednessPV unpk constr_stuff + | L _ (InfixDataConBuilder lhs data_con rhs) <- constr_stuff + = -- When the user writes data T = {-# UNPACK #-} Int :+ Bool + -- we apply {-# UNPACK #-} to the LHS + do lhs' <- addUnpackednessP unpk lhs + let l = combineLocs unpk constr_stuff + return $ L l (InfixDataConBuilder lhs' data_con rhs) + | otherwise = + do addError (getLoc unpk) $ + text "{-# UNPACK #-} cannot be applied to a data constructor." + return constr_stuff + +tyToDataConBuilder :: LHsType GhcPs -> PV (Located DataConBuilder) +tyToDataConBuilder (L l (HsTyVar _ NotPromoted (L _ v))) = do + data_con <- eitherToP $ tyConToDataCon l v + return $ L l (PrefixDataConBuilder nilOL data_con) +tyToDataConBuilder (L l (HsTupleTy _ HsBoxedOrConstraintTuple ts)) = do + let data_con = L l (getRdrName (tupleDataCon Boxed (length ts))) + return $ L l (PrefixDataConBuilder (toOL ts) data_con) +tyToDataConBuilder t = + addFatalError (getLoc t) $ + hang (text "Cannot parse data constructor in a data/newtype declaration:") + 2 (ppr t) + {- Note [Ambiguous syntactic categories] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - There are places in the grammar where we do not know whether we are parsing an expression or a pattern without unlimited lookahead (which we do not have in 'happy'): @@ -2150,6 +1971,21 @@ position and shadows the previous $1. We can do this because internally is to be able to write (sLL $1 $>) later on. The alternative would be to write this as ($1 >>= \ fresh_name -> ...), but then we couldn't refer to the last fresh name as $>. + +Finally, we instantiate the polymorphic type to a concrete one, and run the +parser-validator, for example: + + stmt :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } + e_stmt :: { LStmt GhcPs (LHsExpr GhcPs) } + : stmt {% runPV $1 } + +In e_stmt, three things happen: + + 1. we instantiate: b ~ HsExpr GhcPs + 2. we embed the PV computation into P by using runPV + 3. we run validation by using a monadic production, {% ... } + +At this point the ambiguity is resolved. -} @@ -2306,7 +2142,6 @@ Alternative VII, a product type We could avoid the intermediate representation of Alternative VI by parsing into a product of interpretations directly: - -- See Note [Parser-Validator] type ExpCmdPat = ( PV (LHsExpr GhcPs) , PV (LHsCmd GhcPs) , PV (LHsPat GhcPs) ) @@ -2326,7 +2161,6 @@ We can easily define ambiguities between arbitrary subsets of interpretations. For example, when we know ahead of type that only an expression or a command is possible, but not a pattern, we can use a smaller type: - -- See Note [Parser-Validator] type ExpCmd = (PV (LHsExpr GhcPs), PV (LHsCmd GhcPs)) checkExpOf2 (e, _) = e -- interpret as an expression @@ -2809,7 +2643,7 @@ warnStarBndr span = addWarning Opt_WarnStarBinder span msg <+> text "modules with StarIsType," $$ text " including the definition module, you must qualify it." -failOpFewArgs :: Located RdrName -> P a +failOpFewArgs :: MonadP m => Located RdrName -> m a failOpFewArgs (L loc op) = do { star_is_type <- getBit StarIsTypeBit ; let msg = too_few $$ starInfo star_is_type op @@ -2836,7 +2670,25 @@ data PV_Accum = data PV_Result a = PV_Ok PV_Accum a | PV_Failed PV_Accum --- See Note [Parser-Validator] +-- During parsing, we make use of several monadic effects: reporting parse errors, +-- accumulating warnings, adding API annotations, and checking for extensions. These +-- effects are captured by the 'MonadP' type class. +-- +-- Sometimes we need to postpone some of these effects to a later stage due to +-- ambiguities described in Note [Ambiguous syntactic categories]. +-- We could use two layers of the P monad, one for each stage: +-- +-- abParser :: forall x. DisambAB x => P (P x) +-- +-- The outer layer of P consumes the input and builds the inner layer, which +-- validates the input. But this type is not particularly helpful, as it obscures +-- the fact that the inner layer of P never consumes any input. +-- +-- For clarity, we introduce the notion of a parser-validator: a parser that does +-- not consume any input, but may fail or use other effects. Thus we have: +-- +-- abParser :: forall x. DisambAB x => P (PV x) +-- newtype PV a = PV { unPV :: PV_Context -> PV_Accum -> PV_Result a } instance Functor PV where @@ -2910,36 +2762,6 @@ instance MonadP PV where PV_Ok acc' () addAnnotation _ _ _ = return () -{- Note [Parser-Validator] -~~~~~~~~~~~~~~~~~~~~~~~~~~ - -When resolving ambiguities, we need to postpone failure to make a choice later. -For example, if we have ambiguity between some A and B, our parser could be - - abParser :: P (Maybe A, Maybe B) - -This way we can represent four possible outcomes of parsing: - - (Just a, Nothing) -- definitely A - (Nothing, Just b) -- definitely B - (Just a, Just b) -- either A or B - (Nothing, Nothing) -- neither A nor B - -However, if we want to report informative parse errors, accumulate warnings, -and add API annotations, we are better off using 'P' instead of 'Maybe': - - abParser :: P (P A, P B) - -So we have an outer layer of P that consumes the input and builds the inner -layer, which validates the input. - -For clarity, we introduce the notion of a parser-validator: a parser that does -not consume any input, but may fail or use other effects. Thus we have: - - abParser :: P (PV A, PV B) - --} - {- Note [Parser-Validator Hint] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A PV computation is parametrized by a hint for error messages, which can be set ===================================== compiler/GHC/Platform/Profile.hs ===================================== @@ -13,8 +13,6 @@ import GHC.Prelude import GHC.Platform import GHC.Platform.Ways -import Data.Set - -- | A platform profile fully describes the kind of objects that are generated -- for a platform. -- @@ -22,8 +20,8 @@ import Data.Set -- (profiling, debug, dynamic) also modify the ABI. -- data Profile = Profile - { profilePlatform :: !Platform -- ^ Platform - , profileWays :: !(Set Way) -- ^ Ways + { profilePlatform :: !Platform -- ^ Platform + , profileWays :: !Ways -- ^ Ways } -- | Get platform constants ===================================== compiler/GHC/Platform/Ways.hs ===================================== @@ -20,6 +20,7 @@ -- this compilation. module GHC.Platform.Ways ( Way(..) + , Ways , hasWay , allowed_combination , wayGeneralFlags @@ -61,12 +62,14 @@ data Way | WayDyn -- ^ Dynamic linking deriving (Eq, Ord, Show) +type Ways = Set Way + -- | Test if a ways is enabled -hasWay :: Set Way -> Way -> Bool +hasWay :: Ways -> Way -> Bool hasWay ws w = Set.member w ws -- | Check if a combination of ways is allowed -allowed_combination :: Set Way -> Bool +allowed_combination :: Ways -> Bool allowed_combination ways = not disallowed where disallowed = or [ hasWay ways x && hasWay ways y @@ -76,13 +79,13 @@ allowed_combination ways = not disallowed couples = [] -- we don't have any disallowed combination of ways nowadays -- | Unique tag associated to a list of ways -waysTag :: Set Way -> String +waysTag :: Ways -> String waysTag = concat . intersperse "_" . map wayTag . Set.toAscList -- | Unique build-tag associated to a list of ways -- -- RTS only ways are filtered out because they have no impact on the build. -waysBuildTag :: Set Way -> String +waysBuildTag :: Ways -> String waysBuildTag ws = waysTag (Set.filter (not . wayRTSOnly) ws) @@ -195,7 +198,7 @@ foreign import ccall unsafe "rts_isDynamic" rtsIsDynamicIO :: IO Int -- | Return host "full" ways (i.e. ways that have an impact on the compilation, -- not RTS only ways). These ways must be used when compiling codes targeting -- the internal interpreter. -hostFullWays :: Set Way +hostFullWays :: Ways hostFullWays = Set.unions [ if hostIsDynamic then Set.singleton WayDyn else Set.empty , if hostIsProfiled then Set.singleton WayProf else Set.empty ===================================== compiler/GHC/Tc/TyCl.hs ===================================== @@ -74,7 +74,6 @@ import GHC.Types.SrcLoc import GHC.Data.List.SetOps import GHC.Driver.Session import GHC.Types.Unique -import GHC.Core.ConLike( ConLike(..) ) import GHC.Types.Basic import qualified GHC.LanguageExtensions as LangExt @@ -3819,15 +3818,14 @@ checkValidTyCl tc where recovery_code -- See Note [Recover from validity error] = do { traceTc "Aborted validity for tycon" (ppr tc) - ; return (concatMap mk_fake_tc $ - ATyCon tc : implicitTyConThings tc) } + ; return (map mk_fake_tc $ + tc : child_tycons tc) } - mk_fake_tc (ATyCon tc) - | isClassTyCon tc = [tc] -- Ugh! Note [Recover from validity error] - | otherwise = [makeRecoveryTyCon tc] - mk_fake_tc (AConLike (RealDataCon dc)) - = [makeRecoveryTyCon (promoteDataCon dc)] - mk_fake_tc _ = [] + mk_fake_tc tc + | isClassTyCon tc = tc -- Ugh! Note [Recover from validity error] + | otherwise = makeRecoveryTyCon tc + + child_tycons tc = tyConATs tc ++ map promoteDataCon (tyConDataCons tc) {- Note [Recover from validity error] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -3852,6 +3850,8 @@ Some notes: and so there was an internal error when we met 'MkT' in the body of 'S'. + Similarly for associated types. + * Painfully, we *don't* want to do this for classes. Consider tcfail041: class (?x::Int) => C a where ... @@ -3864,6 +3864,14 @@ Some notes: This is really bogus; now we have in scope a Class that is invalid in some way, with unknown downstream consequences. A better alternative might be to make a fake class TyCon. A job for another day. + +* Previously, we used implicitTyConThings to snaffle out the parts + to add to the context. The problem is that this also grabs data con + wrapper Ids. These could be filtered out. But, painfully, getting + the wrapper Ids checks the DataConRep, and forcing the DataConRep + can panic if there is a levity-polymorphic argument. This is #18534. + We don't need the wrapper Ids here anyway. So the code just takes what + it needs, via child_tycons. -} ------------------------- @@ -4050,8 +4058,13 @@ checkValidDataCon dflags existential_ok tc con -- regardless of whether or not UnliftedNewtypes is enabled. A -- later check in checkNewDataCon handles this, producing a -- better error message than checkForLevPoly would. - ; unless (isNewTyCon tc) - (mapM_ (checkForLevPoly empty) (map scaledThing $ dataConOrigArgTys con)) + ; unless (isNewTyCon tc) $ + checkNoErrs $ + mapM_ (checkForLevPoly empty) (map scaledThing $ dataConOrigArgTys con) + -- the checkNoErrs is to prevent a panic in isVanillaDataCon + -- (called a a few lines down), which can fall over if there is a + -- bang on a levity-polymorphic argument. This is #18534, + -- typecheck/should_fail/T18534 -- Extra checks for newtype data constructors. Importantly, these -- checks /must/ come before the call to checkValidType below. This ===================================== compiler/GHC/Unit/State.hs ===================================== @@ -315,7 +315,7 @@ instance Monoid UnitVisibility where -- | Unit configuration data UnitConfig = UnitConfig { unitConfigPlatformArchOS :: !ArchOS -- ^ Platform arch and OS - , unitConfigWays :: !(Set Way) -- ^ Ways to use + , unitConfigWays :: !Ways -- ^ Ways to use , unitConfigProgramName :: !String -- ^ Name of the compiler (e.g. "GHC", "GHCJS"). Used to fetch environment -- variables such as "GHC[JS]_PACKAGE_PATH". ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.hs ===================================== @@ -0,0 +1,50 @@ +{-# LANGUAGE TemplateHaskell, ExplicitForAll, PolyKinds #-} + +module Main where + +import Language.Haskell.TH (runQ) +import GHC.Types.Basic +import GHC.ThToHs +import GHC.Driver.Session +import GHC.Core.TyCo.Ppr +import GHC.Utils.Outputable +import GHC.Tc.Module +import GHC.Tc.Utils.Zonk +import GHC.Utils.Error +import GHC.Driver.Types +import GHC +import qualified GHC.LanguageExtensions as LangExt + +import Data.Either (fromRight) +import Control.Monad.IO.Class (liftIO) +import System.Environment (getArgs) + +main :: IO () +main = do + [libdir] <- getArgs + runGhc (Just libdir) $ do + initial_dflags <- getSessionDynFlags + setSessionDynFlags $ initial_dflags + `dopt_set` Opt_D_ppr_debug + `gopt_set` Opt_SuppressUniques + `gopt_set` Opt_SuppressModulePrefixes + `gopt_set` Opt_SuppressVarKinds + `xopt_set` LangExt.KindSignatures + `xopt_set` LangExt.PolyKinds + `xopt_set` LangExt.RankNTypes + hsc_env <- getSession + let dflags = hsc_dflags hsc_env + liftIO $ do + th_t <- runQ [t| forall k {j}. + forall (a :: k) (b :: j) -> + () |] + let hs_t = fromRight (error "convertToHsType") $ + convertToHsType Generated noSrcSpan th_t + ((warnings, errors), mres) <- + tcRnType hsc_env SkolemiseFlexi True hs_t + case mres of + Nothing -> do + printBagOfErrors dflags warnings + printBagOfErrors dflags errors + Just (t, _) -> do + putStrLn $ showSDoc dflags (debugPprType t) ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.stdout ===================================== @@ -0,0 +1,2 @@ +forall k{tv}[tv] {j{tv}[tv]}. +forall a{tv}[tv] b{tv}[tv] -> (){(w) tc} ===================================== testsuite/tests/ghc-api/all.T ===================================== @@ -20,3 +20,7 @@ test('T9015', extra_run_opts('"' + config.libdir + '"'), test('T11579', extra_run_opts('"' + config.libdir + '"'), compile_and_run, ['-package ghc']) test('T12099', normal, compile_and_run, ['-package ghc']) +test('T18522-dbg-ppr', + extra_run_opts('"' + config.libdir + '"'), + compile_and_run, + ['-package ghc']) ===================================== testsuite/tests/parser/should_fail/T12045d.stderr ===================================== @@ -1,4 +1,3 @@ T12045d.hs:11:16: error: - Unexpected kind application in a data/newtype declaration: - MkD @Nat Bool + Unexpected kind application in a data/newtype declaration: MkD @Nat ===================================== testsuite/tests/parser/should_fail/strictnessDataCon_B.stderr ===================================== @@ -1,3 +1,2 @@ -strictnessDataCon_B.hs:1:27: error: - {-# UNPACK #-} cannot appear inside a type. +strictnessDataCon_B.hs:1:42: error: parse error on input ‘}’ ===================================== testsuite/tests/parser/should_fail/typeops_A.stderr ===================================== @@ -1,2 +1,3 @@ -typeops_A.hs:1:12: error: Operator applied to too few arguments: + +typeops_A.hs:2:1: error: + parse error (possibly incorrect indentation or mismatched brackets) ===================================== testsuite/tests/parser/should_fail/typeops_C.stderr ===================================== @@ -1,2 +1,2 @@ -typeops_C.hs:1:12: error: Operator applied to too few arguments: + +typeops_C.hs:1:14: error: Operator applied to too few arguments: + ===================================== testsuite/tests/parser/should_fail/unpack_empty_type.stderr ===================================== @@ -1,3 +1,2 @@ -unpack_empty_type.hs:3:19: error: - {-# UNPACK #-} must be applied to a type. +unpack_empty_type.hs:3:34: error: parse error on input ‘}’ ===================================== testsuite/tests/parser/should_fail/unpack_inside_type.stderr ===================================== @@ -1,3 +1,7 @@ unpack_inside_type.hs:3:25: error: - {-# UNPACK #-} cannot appear inside a type. + • Unexpected UNPACK annotation: {-# UNPACK #-}Int + UNPACK annotation cannot appear nested inside a type + • In the first argument of ‘Maybe’, namely ‘({-# UNPACK #-}Int)’ + In the type ‘Maybe ({-# UNPACK #-}Int)’ + In the definition of data constructor ‘T’ ===================================== testsuite/tests/polykinds/T18522-ppr.script ===================================== @@ -0,0 +1,4 @@ +:set -XPolyKinds -XDataKinds -XRankNTypes -XTypeFamilies +import Data.Kind (Type) +type family T :: forall k -> (k ~ k) => forall j -> k -> j -> Type +:k T ===================================== testsuite/tests/polykinds/T18522-ppr.stdout ===================================== @@ -0,0 +1 @@ +T :: forall k -> (k ~ k) => forall j -> k -> j -> * ===================================== testsuite/tests/polykinds/all.T ===================================== @@ -223,3 +223,4 @@ test('T18300', normal, compile_fail, ['']) test('T18451', normal, compile_fail, ['']) test('T18451a', normal, compile_fail, ['']) test('T18451b', normal, compile_fail, ['']) +test('T18522-ppr', normal, ghci_script, ['T18522-ppr.script']) ===================================== testsuite/tests/typecheck/should_fail/T18534.hs ===================================== @@ -0,0 +1,7 @@ +{-# LANGUAGE PolyKinds #-} + +module Test where + +import GHC.Exts + +data Test (a :: TYPE r) = Test !a ===================================== testsuite/tests/typecheck/should_fail/T18534.stderr ===================================== @@ -0,0 +1,7 @@ + +T18534.hs:7:27: error: + • A levity-polymorphic type is not allowed here: + Type: a + Kind: TYPE r + • In the definition of data constructor ‘Test’ + In the data type declaration for ‘Test’ ===================================== testsuite/tests/typecheck/should_fail/all.T ===================================== @@ -578,3 +578,4 @@ test('T18357', normal, compile_fail, ['']) test('T18357a', normal, compile_fail, ['']) test('T18357b', normal, compile_fail, ['']) test('T18455', normal, compile_fail, ['']) +test('T18534', normal, compile_fail, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e935b566da341ae03c3612be21372a2afac2ed31...3021450bd8227697257459cdba56b114a2ed83ff -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e935b566da341ae03c3612be21372a2afac2ed31...3021450bd8227697257459cdba56b114a2ed83ff You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 01:27:32 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Wed, 05 Aug 2020 21:27:32 -0400 Subject: [Git][ghc/ghc][wip/T18527] 2 commits: nativeGen: One approach to fix #18527 Message-ID: <5f2b5c842189c_80b3f8468e02b5467436f2@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18527 at Glasgow Haskell Compiler / GHC Commits: d1446316 by Ben Gamari at 2020-08-05T21:25:09-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - d71ed2cd by Ben Gamari at 2020-08-05T21:26:59-04:00 testsuite: Add test fo #18527 - - - - - 5 changed files: - compiler/GHC/CmmToAsm/X86/CodeGen.hs - + testsuite/tests/codeGen/should_run/T18527.hs - + testsuite/tests/codeGen/should_run/T18527.stdout - + testsuite/tests/codeGen/should_run/T18527FFI.c - testsuite/tests/codeGen/should_run/all.T Changes: ===================================== compiler/GHC/CmmToAsm/X86/CodeGen.hs ===================================== @@ -1028,6 +1028,9 @@ getRegister' _ is32Bit (CmmMachOp mop [x, y]) = do -- dyadic MachOps tmp. This is likely to be better, because the reg alloc can eliminate this reg->reg move here (it won't eliminate the other one, because the move is into the fixed %ecx). + * in the case of C calls the use of ecx here can interfere with arguments. + We avoid this with the hack described in Note [Evaluate C-call + arguments before placing in destination registers] -} shift_code width instr x y{-amount-} = do x_code <- getAnyReg x @@ -2022,6 +2025,7 @@ genCCall is32Bit (PrimTarget (MO_AtomicRMW width amop)) arg <- getNewRegNat format arg_code <- getAnyReg n platform <- ncgPlatform <$> getConfig + let dst_r = getRegisterReg platform (CmmLocal dst) (code, lbl) <- op_code dst_r arg amode return (addr_code `appOL` arg_code arg `appOL` code, Just lbl) @@ -2667,9 +2671,12 @@ genCCall' _ is32Bit target dest_regs args bid = do return code _ -> panic "genCCall: Wrong number of arguments/results for imul2" - _ -> if is32Bit - then genCCall32' target dest_regs args - else genCCall64' target dest_regs args + _ -> do + (instrs0, args') <- evalArgs bid args + instrs1 <- if is32Bit + then genCCall32' target dest_regs args' + else genCCall64' target dest_regs args' + return (instrs0 `appOL` instrs1) where divOp1 platform signed width results [arg_x, arg_y] = divOp platform signed width results Nothing arg_x arg_y @@ -2732,6 +2739,77 @@ genCCall' _ is32Bit target dest_regs args bid = do addSubIntC _ _ _ _ _ _ _ _ = panic "genCCall: Wrong number of arguments/results for addSubIntC" +{- +Note [Evaluate C-call arguments before placing in destination registers] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When producing code for C calls we must take care when placing arguments +in their final registers. Specifically, we must ensure that temporary register +usage due to evaluation of one argument does not clobber a register in which we +already placed a previous argument (e.g. as the code generation logic for +MO_Shl can clobber %rcx due to x86 instruction limitations). + +This is precisely what happened in #18527. Consider this C--: + + (result::I64) = call "ccall" doSomething(_s2hp::I64, 2244, _s2hq::I64, _s2hw::I64 | (1 << _s2hz::I64)); + +Here we are calling the C function `doSomething` with three arguments, the last +involving a non-trivial expression involving MO_Shl. In this case the NCG could +naively generate the following assembly (where $tmp denotes some temporary +register and $argN denotes the register for argument N, as dictated by the +platform's calling convention): + + mov _s2hp, $arg1 # place first argument + mov _s2hq, $arg2 # place second argument + + # Compute 1 << _s2hz + mov _s2hz, %rcx + shl %cl, $tmp + + # Compute (_s2hw | (1 << _s2hz)) + mov _s2hw, $arg3 + or $tmp, $arg3 + + # Perform the call + call func + +This code is outright broken on Windows which assigns $arg1 to %rcx. This means +that the evaluation of the last argument clobbers the first argument. + +To avoid this we use a rather awful hack: when producing code for a C call with +at least one non-trivial argument, we first evaluate all of the arguments into +local registers before moving them into their final calling-convention-defined +homes. This is performed by 'evalArgs'. Here we define "non-trivial" to be an +expression which might contain a MachOp since these are the only cases which +might clobber registers. Furthermore, we use a conservative approximation of +this condition (only looking at the top-level of CmmExprs) to avoid spending +too much effort trying to decide whether we want to take the fast path. +-} + +-- | See Note [Evaluate C-call arguments before placing in destination registers] +evalArgs :: BlockId -> [CmmActual] -> NatM (InstrBlock, [CmmActual]) +evalArgs bid actuals + | any mightContainMachOp actuals = do + regs_blks <- mapM evalArg actuals + return (concatOL $ map fst regs_blks, map snd regs_blks) + | otherwise = return (nilOL, actuals) + where + mightContainMachOp (CmmReg _) = False + mightContainMachOp (CmmRegOff _ _) = False + mightContainMachOp (CmmLit _) = False + mightContainMachOp _ = True + + evalArg :: CmmActual -> NatM (InstrBlock, CmmExpr) + evalArg actual = do + platform <- getPlatform + lreg <- newLocalReg $ cmmExprType platform actual + (instrs, bid') <- stmtToInstrs bid $ CmmAssign (CmmLocal lreg) actual + when (not $ isNothing bid') $ error "uh oh" + return (instrs, CmmReg $ CmmLocal lreg) + + newLocalReg :: CmmType -> NatM LocalReg + newLocalReg ty = LocalReg <$> getUniqueM <*> pure ty + -- Note [DIV/IDIV for bytes] -- -- IDIV reminder: ===================================== testsuite/tests/codeGen/should_run/T18527.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +module Main where + +import Data.Bits (setBit) +import Data.Word (Word32) +import Data.Int (Int64) + +main :: IO () +main = offending 100 0 1 + +offending :: Int64 -> Int64 -> Word32 -> IO () +offending h i id = do + oldMask <- sendMessage h (2245) i 0 + let newMask = setBit oldMask (fromIntegral id) + sendMessage h (2244) i newMask + return () + +foreign import ccall "func" + sendMessage :: Int64 -> Word32 -> Int64 -> Int64 -> IO Int64 ===================================== testsuite/tests/codeGen/should_run/T18527.stdout ===================================== @@ -0,0 +1,3 @@ +ffi call +ffi call + ===================================== testsuite/tests/codeGen/should_run/T18527FFI.c ===================================== @@ -0,0 +1,14 @@ +#include +#include + +int64_t func(int64_t a, uint32_t b, int64_t c, int64_t d) { + printf("ffi call"); + if (a == 1) { + printf(" with corrupted convention\n"); + } + else { + printf("\n"); + } + return 0; +} + ===================================== testsuite/tests/codeGen/should_run/all.T ===================================== @@ -207,3 +207,4 @@ test('T16449_2', exit_code(0), compile_and_run, ['']) test('T16846', [only_ways(['optasm']), exit_code(1)], compile_and_run, ['']) test('T17920', cmm_src, compile_and_run, ['']) +test('T18527', normal, compile_and_run, ['T18527FFI.c']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4fc61c9a0574001f481e36db71ce792df1f99ff9...d71ed2cd6334537d942632c94bdf8ff8613544bf -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4fc61c9a0574001f481e36db71ce792df1f99ff9...d71ed2cd6334537d942632c94bdf8ff8613544bf You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 06:33:39 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 06 Aug 2020 02:33:39 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 6 commits: Grammar for types and data/newtype constructors Message-ID: <5f2ba4439b670_80b3f8496224a70676142e@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: c5ad6bfe by Vladislav Zavialov at 2020-08-06T02:33:28-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 35ab4a85 by Vladislav Zavialov at 2020-08-06T02:33:28-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 4961394a by Vladislav Zavialov at 2020-08-06T02:33:28-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - b10961ea by Vladislav Zavialov at 2020-08-06T02:33:28-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - e6d51c9c by Richard Eisenberg at 2020-08-06T02:33:29-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 829f48c0 by Sylvain Henry at 2020-08-06T02:33:30-04:00 Use a type alias for Ways - - - - - 24 changed files: - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Platform/Profile.hs - compiler/GHC/Platform/Ways.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Unit/State.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.stdout - testsuite/tests/ghc-api/all.T - testsuite/tests/parser/should_fail/T12045d.stderr - testsuite/tests/parser/should_fail/strictnessDataCon_B.stderr - testsuite/tests/parser/should_fail/typeops_A.stderr - testsuite/tests/parser/should_fail/typeops_C.stderr - testsuite/tests/parser/should_fail/unpack_empty_type.stderr - testsuite/tests/parser/should_fail/unpack_inside_type.stderr - + testsuite/tests/polykinds/T18522-ppr.script - + testsuite/tests/polykinds/T18522-ppr.stdout - testsuite/tests/polykinds/all.T - + testsuite/tests/typecheck/should_fail/T18534.hs - + testsuite/tests/typecheck/should_fail/T18534.stderr - testsuite/tests/typecheck/should_fail/all.T Changes: ===================================== compiler/GHC/Core/TyCo/Ppr.hs ===================================== @@ -36,7 +36,8 @@ import {-# SOURCE #-} GHC.CoreToIface import {-# SOURCE #-} GHC.Core.DataCon ( dataConFullSig , dataConUserTyVarBinders, DataCon ) -import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many ) +import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many, + splitForAllTysReq, splitForAllTysInvis ) import GHC.Core.TyCon import GHC.Core.TyCo.Rep @@ -268,19 +269,34 @@ debug_ppr_ty prec (CastTy ty co) debug_ppr_ty _ (CoercionTy co) = parens (text "CO" <+> ppr co) -debug_ppr_ty prec ty@(ForAllTy {}) - | (tvs, body) <- split ty +-- Invisible forall: forall {k} (a :: k). t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysInvis t + , not (null bndrs) = maybeParen prec funPrec $ - hang (text "forall" <+> fsep (map ppr tvs) <> dot) - -- The (map ppr tvs) will print kind-annotated - -- tvs, because we are (usually) in debug-style - 2 (ppr body) + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <> dot, + ppr body ] where - split ty | ForAllTy tv ty' <- ty - , (tvs, body) <- split ty' - = (tv:tvs, body) - | otherwise - = ([], ty) + -- (ppr tv) will print the binder kind-annotated + -- when in debug-style + ppr_bndr (Bndr tv InferredSpec) = braces (ppr tv) + ppr_bndr (Bndr tv SpecifiedSpec) = ppr tv + +-- Visible forall: forall x y -> t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysReq t + , not (null bndrs) + = maybeParen prec funPrec $ + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <+> arrow, + ppr body ] + where + -- (ppr tv) will print the binder kind-annotated + -- when in debug-style + ppr_bndr (Bndr tv ()) = ppr tv + +-- Impossible case: neither visible nor invisible forall. +debug_ppr_ty _ ForAllTy{} + = panic "debug_ppr_ty: neither splitForAllTysInvis nor splitForAllTysReq returned any binders" {- Note [Infix type variables] ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -534,7 +534,7 @@ data DynFlags = DynFlags { homeUnitInstantiations:: [(ModuleName, Module)], -- ^ How to instantiate `homeUnitInstanceOfId` unit -- ways - ways :: Set Way, -- ^ Way flags from the command line + ways :: Ways, -- ^ Way flags from the command line -- For object splitting splitInfo :: Maybe (String,Int), @@ -1433,7 +1433,7 @@ defaultDynFlags mySettings llvmConfig = cfgWeightInfo = defaultCfgWeights } -defaultWays :: Settings -> Set Way +defaultWays :: Settings -> Ways defaultWays settings = if pc_DYNAMIC_BY_DEFAULT (sPlatformConstants settings) then Set.singleton WayDyn else Set.empty ===================================== compiler/GHC/Iface/Type.hs ===================================== @@ -441,6 +441,7 @@ splitIfaceSigmaTy ty (theta, tau) = split_rho rho split_foralls (IfaceForAllTy bndr ty) + | isInvisibleArgFlag (binderArgFlag bndr) = case split_foralls ty of { (bndrs, rho) -> (bndr:bndrs, rho) } split_foralls rho = ([], rho) @@ -448,6 +449,12 @@ splitIfaceSigmaTy ty = case split_rho ty2 of { (ps, tau) -> (ty1:ps, tau) } split_rho tau = ([], tau) +splitIfaceReqForallTy :: IfaceType -> ([IfaceForAllBndr], IfaceType) +splitIfaceReqForallTy (IfaceForAllTy bndr ty) + | isVisibleArgFlag (binderArgFlag bndr) + = case splitIfaceReqForallTy ty of { (bndrs, rho) -> (bndr:bndrs, rho) } +splitIfaceReqForallTy rho = ([], rho) + suppressIfaceInvisibles :: PrintExplicitKinds -> [IfaceTyConBinder] -> [a] -> [a] suppressIfaceInvisibles (PrintExplicitKinds True) _tys xs = xs suppressIfaceInvisibles (PrintExplicitKinds False) tys xs = suppress tys xs @@ -1184,8 +1191,23 @@ pprIfaceSigmaType show_forall ty = hideNonStandardTypes ppr_fn ty where ppr_fn iface_ty = - let (tvs, theta, tau) = splitIfaceSigmaTy iface_ty - in ppr_iface_forall_part show_forall tvs theta (ppr tau) + let (invis_tvs, theta, tau) = splitIfaceSigmaTy iface_ty + (req_tvs, tau') = splitIfaceReqForallTy tau + -- splitIfaceSigmaTy is recursive, so it will gather the binders after + -- the theta, i.e. forall a. theta => forall b. tau + -- will give you ([a,b], theta, tau). + -- + -- This isn't right when it comes to visible forall (see + -- testsuite/tests/polykinds/T18522-ppr), + -- so we split off required binders separately, + -- using splitIfaceReqForallTy. + -- + -- An alternative solution would be to make splitIfaceSigmaTy + -- non-recursive (see #18458). + -- Then it could handle both invisible and required binders, and + -- splitIfaceReqForallTy wouldn't be necessary here. + in ppr_iface_forall_part show_forall invis_tvs theta $ + sep [pprIfaceForAll req_tvs, ppr tau'] pprUserIfaceForAll :: [IfaceForAllBndr] -> SDoc pprUserIfaceForAll tvs ===================================== compiler/GHC/Parser.y ===================================== @@ -1080,7 +1080,7 @@ topdecl :: { LHsDecl GhcPs } -- The $(..) form is one possible form of infixexp -- but we treat an arbitrary expression just as if -- it had a $(..) wrapped around it - | infixexp {% runECP_P $1 >>= \ $1 -> + | infixexp {% runPV (unECP $1) >>= \ $1 -> return $ sLL $1 $> $ mkSpliceDecl $1 } -- Type classes @@ -1528,7 +1528,7 @@ decl_cls : at_decl_cls { $1 } -- A 'default' signature used with the generic-programming extension | 'default' infixexp '::' sigtype - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> do { v <- checkValSigLhs $2 ; let err = text "in default signature" <> colon <+> quotes (ppr $2) @@ -1671,8 +1671,8 @@ rules :: { OrdList (LRuleDecl GhcPs) } rule :: { LRuleDecl GhcPs } : STRING rule_activation rule_foralls infixexp '=' exp - {%runECP_P $4 >>= \ $4 -> - runECP_P $6 >>= \ $6 -> + {%runPV (unECP $4) >>= \ $4 -> + runPV (unECP $6) >>= \ $6 -> ams (sLL $1 $> $ HsRule { rd_ext = noExtField , rd_name = L (gl $1) (getSTRINGs $1, getSTRING $1) , rd_act = (snd $2) `orElse` AlwaysActive @@ -1800,19 +1800,19 @@ stringlist :: { Located (OrdList (Located StringLiteral)) } ----------------------------------------------------------------------------- -- Annotations annotation :: { LHsDecl GhcPs } - : '{-# ANN' name_var aexp '#-}' {% runECP_P $3 >>= \ $3 -> + : '{-# ANN' name_var aexp '#-}' {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) (ValueAnnProvenance $2) $3)) [mo $1,mc $4] } - | '{-# ANN' 'type' tycon aexp '#-}' {% runECP_P $4 >>= \ $4 -> + | '{-# ANN' 'type' tycon aexp '#-}' {% runPV (unECP $4) >>= \ $4 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) (TypeAnnProvenance $3) $4)) [mo $1,mj AnnType $2,mc $5] } - | '{-# ANN' 'module' aexp '#-}' {% runECP_P $3 >>= \ $3 -> + | '{-# ANN' 'module' aexp '#-}' {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) ModuleAnnProvenance $3)) @@ -1966,22 +1966,28 @@ type :: { LHsType GhcPs } mult :: { LHsType GhcPs } : btype { $1 } - btype :: { LHsType GhcPs } - : tyapps {% mergeOps (unLoc $1) } - -tyapps :: { Located [Located TyEl] } -- NB: This list is reversed - : tyapp { sL1 $1 [$1] } - | tyapps tyapp { sLL $1 $> $ $2 : unLoc $1 } - -tyapp :: { Located TyEl } - : atype { sL1 $1 $ TyElOpd (unLoc $1) } - - -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer - | PREFIX_AT atype { sLL $1 $> $ (TyElKindApp (comb2 $1 $2) $2) } - - | tyop { mapLoc TyElOpr $1 } - | unpackedness { sL1 $1 $ TyElUnpackedness (unLoc $1) } + : infixtype {% runPV $1 } + +infixtype :: { forall b. DisambTD b => PV (Located b) } + : ftype { $1 } + | ftype tyop infixtype { $1 >>= \ $1 -> + $3 >>= \ $3 -> + mkHsOpTyPV $1 $2 $3 } + | unpackedness infixtype { $2 >>= \ $2 -> + mkUnpackednessPV $1 $2 } + +ftype :: { forall b. DisambTD b => PV (Located b) } + : atype { mkHsAppTyHeadPV $1 } + | tyop { failOpFewArgs $1 } + | ftype tyarg { $1 >>= \ $1 -> + mkHsAppTyPV $1 $2 } + | ftype PREFIX_AT tyarg { $1 >>= \ $1 -> + mkHsAppKindTyPV $1 (getLoc $2) $3 } + +tyarg :: { LHsType GhcPs } + : atype { $1 } + | unpackedness atype {% addUnpackednessP $1 $2 } tyop :: { Located RdrName } : qtyconop { $1 } @@ -2222,8 +2228,9 @@ forall :: { Located ([AddAnn], Maybe [LHsTyVarBndr Specificity GhcPs]) } | {- empty -} { noLoc ([], Nothing) } constr_stuff :: { Located (Located RdrName, HsConDeclDetails GhcPs) } - : tyapps {% do { c <- mergeDataCon (unLoc $1) - ; return $ sL1 $1 c } } + : infixtype {% fmap (mapLoc (\b -> (dataConBuilderCon b, + dataConBuilderDetails b))) + (runPV $1) } fielddecls :: { [LConDeclField GhcPs] } : {- empty -} { [] } @@ -2308,7 +2315,7 @@ There's an awkward overlap with a type signature. Consider decl_no_th :: { LHsDecl GhcPs } : sigdecl { $1 } - | infixexp opt_sig rhs {% runECP_P $1 >>= \ $1 -> + | infixexp opt_sig rhs {% runPV (unECP $1) >>= \ $1 -> do { (ann,r) <- checkValDef $1 (snd $2) $3; let { l = comb2 $1 $> }; -- Depending upon what the pattern looks like we might get either @@ -2332,7 +2339,7 @@ decl :: { LHsDecl GhcPs } | splice_exp { sLL $1 $> $ mkSpliceDecl $1 } rhs :: { Located ([AddAnn],GRHSs GhcPs (LHsExpr GhcPs)) } - : '=' exp wherebinds {% runECP_P $2 >>= \ $2 -> return $ + : '=' exp wherebinds {% runPV (unECP $2) >>= \ $2 -> return $ sL (comb3 $1 $2 $3) ((mj AnnEqual $1 : (fst $ unLoc $3)) ,GRHSs noExtField (unguardedRHS (comb3 $1 $2 $3) $2) @@ -2346,7 +2353,7 @@ gdrhs :: { Located [LGRHS GhcPs (LHsExpr GhcPs)] } | gdrh { sL1 $1 [$1] } gdrh :: { LGRHS GhcPs (LHsExpr GhcPs) } - : '|' guardquals '=' exp {% runECP_P $4 >>= \ $4 -> + : '|' guardquals '=' exp {% runPV (unECP $4) >>= \ $4 -> ams (sL (comb2 $1 $>) $ GRHS noExtField (unLoc $2) $4) [mj AnnVbar $1,mj AnnEqual $3] } @@ -2354,7 +2361,7 @@ sigdecl :: { LHsDecl GhcPs } : -- See Note [Declaration/signature overlap] for why we need infixexp here infixexp '::' sigtype - {% do { $1 <- runECP_P $1 + {% do { $1 <- runPV (unECP $1) ; v <- checkValSigLhs $1 ; _ <- amsL (comb2 $1 $>) [mu AnnDcolon $2] ; return (sLL $1 $> $ SigD noExtField $ @@ -2450,30 +2457,30 @@ quasiquote :: { Located (HsSplice GhcPs) } exp :: { ECP } : infixexp '::' sigtype { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> rejectPragmaPV $1 >> amms (mkHsTySigPV (comb2 $1 $>) $1 $3) [mu AnnDcolon $2] } - | infixexp '-<' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '-<' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $1 $3 HsFirstOrderApp True) [mu Annlarrowtail $2] } - | infixexp '>-' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '>-' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $3 $1 HsFirstOrderApp False) [mu Annrarrowtail $2] } - | infixexp '-<<' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '-<<' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $1 $3 HsHigherOrderApp True) [mu AnnLarrowtail $2] } - | infixexp '>>-' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '>>-' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $3 $1 HsHigherOrderApp False) @@ -2487,8 +2494,8 @@ infixexp :: { ECP } { ECP $ superInfixOp $ $2 >>= \ $2 -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> rejectPragmaPV $1 >> amms (mkHsOpAppPV (comb2 $1 $>) $1 $2 $3) [mj AnnVal $2] } @@ -2500,14 +2507,14 @@ exp10p :: { ECP } exp_prag(e) :: { ECP } : prag_e e -- See Note [Pragmas and operator fixity] - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsPragE noExtField (snd $ unLoc $1) $2) (fst $ unLoc $1) } exp10 :: { ECP } : '-' fexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsNegAppPV (comb2 $1 $>) $2) [mj AnnMinus $1] } | fexp { $1 } @@ -2590,16 +2597,16 @@ prag_e :: { Located ([AddAnn], HsPragE GhcPs) } fexp :: { ECP } : fexp aexp { ECP $ superFunArg $ - runECP_PV $1 >>= \ $1 -> - runECP_PV $2 >>= \ $2 -> + unECP $1 >>= \ $1 -> + unECP $2 >>= \ $2 -> mkHsAppPV (comb2 $1 $>) $1 $2 } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer | fexp PREFIX_AT atype { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> amms (mkHsAppTypePV (comb2 $1 $>) $1 $3) [mj AnnAt $2] } - | 'static' aexp {% runECP_P $2 >>= \ $2 -> + | 'static' aexp {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsStatic noExtField $2) [mj AnnStatic $1] } @@ -2609,23 +2616,23 @@ aexp :: { ECP } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer : qvar TIGHT_INFIX_AT aexp { ECP $ - runECP_PV $3 >>= \ $3 -> + unECP $3 >>= \ $3 -> amms (mkHsAsPatPV (comb2 $1 $>) $1 $3) [mj AnnAt $2] } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer | PREFIX_TILDE aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsLazyPatPV (comb2 $1 $>) $2) [mj AnnTilde $1] } | PREFIX_BANG aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsBangPatPV (comb2 $1 $>) $2) [mj AnnBang $1] } | PREFIX_MINUS aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsNegAppPV (comb2 $1 $>) $2) [mj AnnMinus $1] } | '\\' apat apats '->' exp { ECP $ - runECP_PV $5 >>= \ $5 -> + unECP $5 >>= \ $5 -> amms (mkHsLamPV (comb2 $1 $>) (mkMatchGroup FromSource [sLL $1 $> $ Match { m_ext = noExtField , m_ctxt = LambdaExpr @@ -2633,7 +2640,7 @@ aexp :: { ECP } , m_grhss = unguardedGRHSs $5 }])) [mj AnnLam $1, mu AnnRarrow $4] } | 'let' binds 'in' exp { ECP $ - runECP_PV $4 >>= \ $4 -> + unECP $4 >>= \ $4 -> amms (mkHsLetPV (comb2 $1 $>) (snd (unLoc $2)) $4) (mj AnnLet $1:mj AnnIn $3 :(fst $ unLoc $2)) } @@ -2643,10 +2650,10 @@ aexp :: { ECP } (mkMatchGroup FromSource (snd $ unLoc $3))) (mj AnnLam $1:mj AnnCase $2:(fst $ unLoc $3)) } | 'if' exp optSemi 'then' exp optSemi 'else' exp - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> return $ ECP $ - runECP_PV $5 >>= \ $5 -> - runECP_PV $8 >>= \ $8 -> + unECP $5 >>= \ $5 -> + unECP $8 >>= \ $8 -> amms (mkHsIfPV (comb2 $1 $>) $2 (snd $3) $5 (snd $6) $8) (mj AnnIf $1:mj AnnThen $4 :mj AnnElse $7 @@ -2657,7 +2664,7 @@ aexp :: { ECP } ams (sLL $1 $> $ HsMultiIf noExtField (reverse $ snd $ unLoc $2)) (mj AnnIf $1:(fst $ unLoc $2)) } - | 'case' exp 'of' altslist {% runECP_P $2 >>= \ $2 -> + | 'case' exp 'of' altslist {% runPV (unECP $2) >>= \ $2 -> return $ ECP $ $4 >>= \ $4 -> amms (mkHsCasePV (comb3 $1 $3 $4) $2 (mkMatchGroup @@ -2681,8 +2688,8 @@ aexp :: { ECP } (snd $ unLoc $2))) (mj AnnMdo $1:(fst $ unLoc $2)) } | 'proc' aexp '->' exp - {% (checkPattern <=< runECP_P) $2 >>= \ p -> - runECP_P $4 >>= \ $4 at cmd -> + {% (checkPattern <=< runPV) (unECP $2) >>= \ p -> + runPV (unECP $4) >>= \ $4 at cmd -> fmap ecpFromExp $ ams (sLL $1 $> $ HsProc noExtField p (sLL $1 $> $ HsCmdTop noExtField cmd)) -- TODO: is LL right here? @@ -2692,7 +2699,7 @@ aexp :: { ECP } aexp1 :: { ECP } : aexp1 '{' fbinds '}' { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> $3 >>= \ $3 -> amms (mkHsRecordPV (comb2 $1 $>) (comb2 $2 $4) $1 (snd $3)) (moc $2:mcc $4:(fst $3)) } @@ -2716,7 +2723,7 @@ aexp2 :: { ECP } -- correct Haskell (you'd have to write '((+ 3), (4 -))') -- but the less cluttered version fell out of having texps. | '(' texp ')' { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsParPV (comb2 $1 $>) $2) [mop $1,mcp $3] } | '(' tup_exprs ')' { ECP $ $2 >>= \ $2 -> @@ -2724,7 +2731,7 @@ aexp2 :: { ECP } ((mop $1:fst $2) ++ [mcp $3]) } | '(#' texp '#)' { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkSumOrTuplePV (comb2 $1 $>) Unboxed (Tuple [L (gl $2) (Just $2)])) [mo $1,mc $3] } | '(#' tup_exprs '#)' { ECP $ @@ -2744,18 +2751,18 @@ aexp2 :: { ECP } | TH_TY_QUOTE tyvar {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } | TH_TY_QUOTE gtycon {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } | TH_TY_QUOTE {- nothing -} {% reportEmptyDoubleQuotes (getLoc $1) } - | '[|' exp '|]' {% runECP_P $2 >>= \ $2 -> + | '[|' exp '|]' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (ExpBr noExtField $2)) (if (hasE $1) then [mj AnnOpenE $1, mu AnnCloseQ $3] else [mu AnnOpenEQ $1,mu AnnCloseQ $3]) } - | '[||' exp '||]' {% runECP_P $2 >>= \ $2 -> + | '[||' exp '||]' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (TExpBr noExtField $2)) (if (hasE $1) then [mj AnnOpenE $1,mc $3] else [mo $1,mc $3]) } | '[t|' ktype '|]' {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (TypBr noExtField $2)) [mo $1,mu AnnCloseQ $3] } - | '[p|' infixexp '|]' {% (checkPattern <=< runECP_P) $2 >>= \p -> + | '[p|' infixexp '|]' {% (checkPattern <=< runPV) (unECP $2) >>= \p -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (PatBr noExtField p)) [mo $1,mu AnnCloseQ $3] } @@ -2765,7 +2772,7 @@ aexp2 :: { ECP } | quasiquote { ECP $ mkHsSplicePV $1 } -- arrow notation extension - | '(|' aexp cmdargs '|)' {% runECP_P $2 >>= \ $2 -> + | '(|' aexp cmdargs '|)' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrForm noExtField $2 Prefix Nothing (reverse $3)) @@ -2777,14 +2784,14 @@ splice_exp :: { LHsExpr GhcPs } splice_untyped :: { Located (HsSplice GhcPs) } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer - : PREFIX_DOLLAR aexp2 {% runECP_P $2 >>= \ $2 -> + : PREFIX_DOLLAR aexp2 {% runPV (unECP $2) >>= \ $2 -> ams (sLL $1 $> $ mkUntypedSplice DollarSplice $2) [mj AnnDollar $1] } splice_typed :: { Located (HsSplice GhcPs) } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer : PREFIX_DOLLAR_DOLLAR aexp2 - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> ams (sLL $1 $> $ mkTypedSplice DollarSplice $2) [mj AnnDollarDollar $1] } @@ -2793,7 +2800,7 @@ cmdargs :: { [LHsCmdTop GhcPs] } | {- empty -} { [] } acmd :: { LHsCmdTop GhcPs } - : aexp {% runECP_P $1 >>= \ cmd -> + : aexp {% runPV (unECP $1) >>= \ cmd -> runPV (checkCmdBlockArguments cmd) >>= \ _ -> return (sL1 cmd $ HsCmdTop noExtField cmd) } @@ -2827,21 +2834,21 @@ texp :: { ECP } -- Meanwhile, the renamer checks that real sections appear -- inside parens. | infixexp qop - {% runECP_P $1 >>= \ $1 -> + {% runPV (unECP $1) >>= \ $1 -> runPV (rejectPragmaPV $1) >> runPV $2 >>= \ $2 -> return $ ecpFromExp $ sLL $1 $> $ SectionL noExtField $1 $2 } | qopm infixexp { ECP $ superInfixOp $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> $1 >>= \ $1 -> mkHsSectionR_PV (comb2 $1 $>) $1 $2 } -- View patterns get parenthesized above | exp '->' texp { ECP $ - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> amms (mkHsViewPatPV (comb2 $1 $>) $1 $3) [mu AnnRarrow $2] } -- Always at least one comma or bar. @@ -2850,12 +2857,12 @@ texp :: { ECP } -- in GHC.Hs.Expr. tup_exprs :: { forall b. DisambECP b => PV ([AddAnn],SumOrTuple b) } : texp commas_tup_tail - { runECP_PV $1 >>= \ $1 -> + { unECP $1 >>= \ $1 -> $2 >>= \ $2 -> do { addAnnotation (gl $1) AnnComma (fst $2) ; return ([],Tuple ((sL1 $1 (Just $1)) : snd $2)) } } - | texp bars { runECP_PV $1 >>= \ $1 -> return $ + | texp bars { unECP $1 >>= \ $1 -> return $ (mvbars (fst $2), Sum 1 (snd $2 + 1) $1) } | commas tup_tail @@ -2865,7 +2872,7 @@ tup_exprs :: { forall b. DisambECP b => PV ([AddAnn],SumOrTuple b) } ([],Tuple (map (\l -> L l Nothing) (fst $1) ++ $2)) } } | bars texp bars0 - { runECP_PV $2 >>= \ $2 -> return $ + { unECP $2 >>= \ $2 -> return $ (mvbars (fst $1) ++ mvbars (fst $3), Sum (snd $1 + 1) (snd $1 + snd $3 + 1) $2) } -- Always starts with commas; always follows an expr @@ -2879,11 +2886,11 @@ commas_tup_tail : commas tup_tail -- Always follows a comma tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] } - : texp commas_tup_tail { runECP_PV $1 >>= \ $1 -> + : texp commas_tup_tail { unECP $1 >>= \ $1 -> $2 >>= \ $2 -> addAnnotation (gl $1) AnnComma (fst $2) >> return ((L (gl $1) (Just $1)) : snd $2) } - | texp { runECP_PV $1 >>= \ $1 -> + | texp { unECP $1 >>= \ $1 -> return [L (gl $1) (Just $1)] } | {- empty -} { return [noLoc Nothing] } @@ -2894,48 +2901,48 @@ tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] } -- avoiding another shift/reduce-conflict. -- Never empty. list :: { forall b. DisambECP b => SrcSpan -> PV (Located b) } - : texp { \loc -> runECP_PV $1 >>= \ $1 -> + : texp { \loc -> unECP $1 >>= \ $1 -> mkHsExplicitListPV loc [$1] } | lexps { \loc -> $1 >>= \ $1 -> mkHsExplicitListPV loc (reverse $1) } - | texp '..' { \loc -> runECP_PV $1 >>= \ $1 -> + | texp '..' { \loc -> unECP $1 >>= \ $1 -> ams (L loc $ ArithSeq noExtField Nothing (From $1)) [mj AnnDotdot $2] >>= ecpFromExp' } | texp ',' exp '..' { \loc -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> ams (L loc $ ArithSeq noExtField Nothing (FromThen $1 $3)) [mj AnnComma $2,mj AnnDotdot $4] >>= ecpFromExp' } - | texp '..' exp { \loc -> runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + | texp '..' exp { \loc -> unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> ams (L loc $ ArithSeq noExtField Nothing (FromTo $1 $3)) [mj AnnDotdot $2] >>= ecpFromExp' } | texp ',' exp '..' exp { \loc -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> - runECP_PV $5 >>= \ $5 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> + unECP $5 >>= \ $5 -> ams (L loc $ ArithSeq noExtField Nothing (FromThenTo $1 $3 $5)) [mj AnnComma $2,mj AnnDotdot $4] >>= ecpFromExp' } | texp '|' flattenedpquals { \loc -> checkMonadComp >>= \ ctxt -> - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> ams (L loc $ mkHsComp ctxt (unLoc $3) $1) [mj AnnVbar $2] >>= ecpFromExp' } lexps :: { forall b. DisambECP b => PV [Located b] } : lexps ',' texp { $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $3 >>= \ $3 -> addAnnotation (gl $ head $ $1) AnnComma (gl $2) >> return (((:) $! $3) $! $1) } - | texp ',' texp { runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + | texp ',' texp { unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> addAnnotation (gl $1) AnnComma (gl $2) >> return [$3,$1] } @@ -2985,20 +2992,20 @@ squals :: { Located [LStmt GhcPs (LHsExpr GhcPs)] } -- In reverse order, becau transformqual :: { Located ([AddAnn],[LStmt GhcPs (LHsExpr GhcPs)] -> Stmt GhcPs (LHsExpr GhcPs)) } -- Function is applied to a list of stmts *in order* - : 'then' exp {% runECP_P $2 >>= \ $2 -> return $ + : 'then' exp {% runPV (unECP $2) >>= \ $2 -> return $ sLL $1 $> ([mj AnnThen $1], \ss -> (mkTransformStmt ss $2)) } - | 'then' exp 'by' exp {% runECP_P $2 >>= \ $2 -> - runECP_P $4 >>= \ $4 -> + | 'then' exp 'by' exp {% runPV (unECP $2) >>= \ $2 -> + runPV (unECP $4) >>= \ $4 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnBy $3], \ss -> (mkTransformByStmt ss $2 $4)) } | 'then' 'group' 'using' exp - {% runECP_P $4 >>= \ $4 -> + {% runPV (unECP $4) >>= \ $4 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnUsing $3], \ss -> (mkGroupUsingStmt ss $4)) } | 'then' 'group' 'by' exp 'using' exp - {% runECP_P $4 >>= \ $4 -> - runECP_P $6 >>= \ $6 -> + {% runPV (unECP $4) >>= \ $4 -> + runPV (unECP $6) >>= \ $6 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnBy $3,mj AnnUsing $5], \ss -> (mkGroupByUsingStmt ss $4 $6)) } @@ -3072,7 +3079,7 @@ alt_rhs :: { forall b. DisambECP b => PV (Located ([AddAnn],GRHSs GhcPs (Located return $ sLL alt $> (fst $ unLoc $2, GRHSs noExtField (unLoc alt) (snd $ unLoc $2)) } ralt :: { forall b. DisambECP b => PV (Located [LGRHS GhcPs (Located b)]) } - : '->' exp { runECP_PV $2 >>= \ $2 -> + : '->' exp { unECP $2 >>= \ $2 -> ams (sLL $1 $> (unguardedRHS (comb2 $1 $2) $2)) [mu AnnRarrow $1] } | gdpats { $1 >>= \gdpats -> @@ -3095,7 +3102,7 @@ ifgdpats :: { Located ([AddAnn],[LGRHS GhcPs (LHsExpr GhcPs)]) } gdpat :: { forall b. DisambECP b => PV (LGRHS GhcPs (Located b)) } : '|' guardquals '->' exp - { runECP_PV $4 >>= \ $4 -> + { unECP $4 >>= \ $4 -> ams (sL (comb2 $1 $>) $ GRHS noExtField (unLoc $2) $4) [mj AnnVbar $1,mu AnnRarrow $3] } @@ -3104,15 +3111,15 @@ gdpat :: { forall b. DisambECP b => PV (LGRHS GhcPs (Located b)) } -- Bangs inside are parsed as infix operator applications, so that -- we parse them right when bang-patterns are off pat :: { LPat GhcPs } -pat : exp {% (checkPattern <=< runECP_P) $1 } +pat : exp {% (checkPattern <=< runPV) (unECP $1) } bindpat :: { LPat GhcPs } -bindpat : exp {% -- See Note [Parser-Validator ReaderT SDoc] in GHC.Parser.PostProcess +bindpat : exp {% -- See Note [Parser-Validator Hint] in GHC.Parser.PostProcess checkPattern_msg (text "Possibly caused by a missing 'do'?") - (runECP_PV $1) } + (unECP $1) } apat :: { LPat GhcPs } -apat : aexp {% (checkPattern <=< runECP_P) $1 } +apat : aexp {% (checkPattern <=< runPV) (unECP $1) } apats :: { [LPat GhcPs] } : apat apats { $1 : $2 } @@ -3175,10 +3182,10 @@ stmt :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } (mj AnnRec $1:(fst $ unLoc $2)) } qual :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } - : bindpat '<-' exp { runECP_PV $3 >>= \ $3 -> + : bindpat '<-' exp { unECP $3 >>= \ $3 -> ams (sLL $1 $> $ mkPsBindStmt $1 $3) [mu AnnLarrow $2] } - | exp { runECP_PV $1 >>= \ $1 -> + | exp { unECP $1 >>= \ $1 -> return $ sL1 $1 $ mkBodyStmt $1 } | 'let' binds { ams (sLL $1 $> $ LetStmt noExtField (snd $ unLoc $2)) (mj AnnLet $1:(fst $ unLoc $2)) } @@ -3201,7 +3208,7 @@ fbinds1 :: { forall b. DisambECP b => PV ([AddAnn],([LHsRecField GhcPs (Located | '..' { return ([mj AnnDotdot $1],([], Just (getLoc $1))) } fbind :: { forall b. DisambECP b => PV (LHsRecField GhcPs (Located b)) } - : qvar '=' texp { runECP_PV $3 >>= \ $3 -> + : qvar '=' texp { unECP $3 >>= \ $3 -> ams (sLL $1 $> $ HsRecField (sL1 $1 $ mkFieldOcc $1) $3 False) [mj AnnEqual $2] } -- RHS is a 'texp', allowing view patterns (#6038) @@ -3227,7 +3234,7 @@ dbinds :: { Located [LIPBind GhcPs] } -- | {- empty -} { [] } dbind :: { LIPBind GhcPs } -dbind : ipvar '=' exp {% runECP_P $3 >>= \ $3 -> +dbind : ipvar '=' exp {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (IPBind noExtField (Left $1) $3)) [mj AnnEqual $2] } ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -68,7 +68,6 @@ module GHC.Parser.PostProcess ( checkRecordSyntax, checkEmptyGADTs, addFatalError, hintBangPat, - TyEl(..), mergeOps, mergeDataCon, mkBangTy, UnpackednessPragma(..), @@ -96,13 +95,19 @@ module GHC.Parser.PostProcess ( -- Expression/command/pattern ambiguity resolution PV, runPV, - ECP(ECP, runECP_PV), - runECP_P, + ECP(ECP, unECP), DisambInfixOp(..), DisambECP(..), ecpFromExp, ecpFromCmd, - PatBuilder + PatBuilder, + + -- Type/datacon ambiguity resolution + DisambTD(..), + addUnpackednessP, + DataConBuilder(), + dataConBuilderCon, + dataConBuilderDetails, ) where import GHC.Prelude @@ -126,20 +131,20 @@ import GHC.Types.ForeignCall import GHC.Builtin.Names ( allNameStrings ) import GHC.Types.SrcLoc import GHC.Types.Unique ( hasKey ) -import GHC.Data.OrdList ( OrdList, fromOL ) +import GHC.Data.OrdList import GHC.Utils.Outputable as Outputable import GHC.Data.FastString import GHC.Data.Maybe import GHC.Utils.Misc import GHC.Parser.Annotation import Data.List +import Data.Foldable import GHC.Driver.Session ( WarningFlag(..), DynFlags ) import GHC.Utils.Error ( Messages ) import Control.Monad import Text.ParserCombinators.ReadP as ReadP import Data.Char -import qualified Data.Monoid as Monoid import Data.Data ( dataTypeOf, fromConstr, dataTypeConstrs ) import Data.Kind ( Type ) @@ -559,30 +564,6 @@ context, so (C t1 t2) is a constraint and 'C' is a type constructor. As the result, in order to determine whether (C t1 t2) declares a data constructor, a type, or a context, we would need unlimited lookahead which 'happy' is not so happy with. - -The solution that accounts for all of these issues is to initially parse data -declarations and types as a reversed list of TyEl: - - data TyEl = TyElOpr RdrName - | TyElOpd (HsType GhcPs) - | ... - -For example, both occurrences of (C ! D) in the following example are parsed -into equal lists of TyEl: - - data T = C ! D => C ! D results in [ TyElOpd (HsTyVar "D") - , TyElOpr "!" - , TyElOpd (HsTyVar "C") ] - -Note that elements are in reverse order. Also, 'C' is parsed as a type -constructor (HsTyVar) even when it is a data constructor. We fix this in -`tyConToDataCon`. - -By the time the list of TyEl is assembled, we have looked ahead enough to -decide whether to reduce using `mergeOps` (for types) or `mergeDataCon` (for -data constructors). These functions are where the actual job of parsing is -done. - -} -- | Reinterpret a type constructor, including type operators, as a data @@ -798,7 +779,7 @@ to make setRdrNameSpace partial, so we just make an Unqual name instead. It really doesn't matter! -} -eitherToP :: Either (SrcSpan, SDoc) a -> P a +eitherToP :: MonadP m => Either (SrcSpan, SDoc) a -> m a -- Adapts the Either monad to the P monad eitherToP (Left (loc, doc)) = addFatalError loc doc eitherToP (Right thing) = return thing @@ -1309,323 +1290,31 @@ isFunLhs e = go e [] [] _ -> return Nothing } go _ _ _ = return Nothing --- | Either an operator or an operand. -data TyEl = TyElOpr RdrName | TyElOpd (HsType GhcPs) - | TyElKindApp SrcSpan (LHsType GhcPs) - -- See Note [TyElKindApp SrcSpan interpretation] - | TyElUnpackedness UnpackednessPragma - - -{- Note [TyElKindApp SrcSpan interpretation] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -A TyElKindApp captures type application written in haskell as - - @ Foo - -where Foo is some type. - -The SrcSpan reflects both elements, and there are AnnAt and AnnVal API -Annotations attached to this SrcSpan for the specific locations of -each within it. --} - -instance Outputable TyEl where - ppr (TyElOpr name) = ppr name - ppr (TyElOpd ty) = ppr ty - ppr (TyElKindApp _ ki) = text "@" <> ppr ki - ppr (TyElUnpackedness (UnpackednessPragma _ _ unpk)) = ppr unpk - --- | Extract a strictness/unpackedness annotation from the front of a reversed --- 'TyEl' list. -pUnpackedness - :: [Located TyEl] -- reversed TyEl - -> Maybe (SrcSpan, UnpackednessPragma, - [Located TyEl] {- remaining TyEl -}) -pUnpackedness (L l x1 : xs) | TyElUnpackedness up <- x1 = Just (l, up, xs) -pUnpackedness _ = Nothing - -pBangTy - :: LHsType GhcPs -- a type to be wrapped inside HsBangTy - -> [Located TyEl] -- reversed TyEl - -> ( Bool {- has a strict mark been consumed? -} - , LHsType GhcPs {- the resulting BangTy -} - , P () {- add annotations -} - , [Located TyEl] {- remaining TyEl -}) -pBangTy lt@(L l1 _) xs = - case pUnpackedness xs of - Nothing -> (False, lt, pure (), xs) - Just (l2, UnpackednessPragma anns prag unpk, xs') -> - let bl = combineSrcSpans l1 l2 - bt = addUnpackedness (prag, unpk) lt - in (True, L bl bt, addAnnsAt bl anns, xs') - mkBangTy :: SrcStrictness -> LHsType GhcPs -> HsType GhcPs mkBangTy strictness = HsBangTy noExtField (HsSrcBang NoSourceText NoSrcUnpack strictness) --- Result of parsing {-# UNPACK #-} or {-# NOUNPACK #-} +-- | Result of parsing @{-\# UNPACK \#-}@ or @{-\# NOUNPACK \#-}@. data UnpackednessPragma = UnpackednessPragma [AddAnn] SourceText SrcUnpackedness -addUnpackedness :: (SourceText, SrcUnpackedness) -> LHsType GhcPs -> HsType GhcPs -addUnpackedness (prag, unpk) (L _ (HsBangTy x bang t)) - | HsSrcBang NoSourceText NoSrcUnpack strictness <- bang - = HsBangTy x (HsSrcBang prag unpk strictness) t -addUnpackedness (prag, unpk) t - = HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t - --- | Merge a /reversed/ and /non-empty/ soup of operators and operands --- into a type. --- --- User input: @F x y + G a b * X@ --- Input to 'mergeOps': [X, *, b, a, G, +, y, x, F] --- Output corresponds to what the user wrote assuming all operators are of the --- same fixity and right-associative. --- --- It's a bit silly that we're doing it at all, as the renamer will have to --- rearrange this, and it'd be easier to keep things separate. --- --- See Note [Parsing data constructors is hard] -mergeOps :: [Located TyEl] -> P (LHsType GhcPs) -mergeOps ((L l1 (TyElOpd t)) : xs) - | (_, t', addAnns, xs') <- pBangTy (L l1 t) xs - , null xs' -- We accept a BangTy only when there are no preceding TyEl. - = addAnns >> return t' -mergeOps all_xs = go (0 :: Int) [] id all_xs - where - -- NB. When modifying clauses in 'go', make sure that the reasoning in - -- Note [Non-empty 'acc' in mergeOps clause [end]] is still correct. - - -- clause [unpk]: - -- handle (NO)UNPACK pragmas - go k acc ops_acc ((L l (TyElUnpackedness (UnpackednessPragma anns unpkSrc unpk))):xs) = - if not (null acc) && null xs - then do { acc' <- eitherToP $ mergeOpsAcc acc - ; let a = ops_acc acc' - strictMark = HsSrcBang unpkSrc unpk NoSrcStrict - bl = combineSrcSpans l (getLoc a) - bt = HsBangTy noExtField strictMark a - ; addAnnsAt bl anns - ; return (L bl bt) } - else addFatalError l unpkError - where - unpkSDoc = case unpkSrc of - NoSourceText -> ppr unpk - SourceText str -> text str <> text " #-}" - unpkError - | not (null xs) = unpkSDoc <+> text "cannot appear inside a type." - | null acc && k == 0 = unpkSDoc <+> text "must be applied to a type." - | otherwise = - -- See Note [Impossible case in mergeOps clause [unpk]] - panic "mergeOps.UNPACK: impossible position" - - -- clause [opr]: - -- when we encounter an operator, we must have accumulated - -- something for its rhs, and there must be something left - -- to build its lhs. - go k acc ops_acc ((L l (TyElOpr op)):xs) = - if null acc || null (filter isTyElOpd xs) - then failOpFewArgs (L l op) - else do { acc' <- eitherToP (mergeOpsAcc acc) - ; go (k + 1) [] (\c -> mkLHsOpTy c (L l op) (ops_acc acc')) xs } - where - isTyElOpd (L _ (TyElOpd _)) = True - isTyElOpd _ = False - - -- clause [opd]: - -- whenever an operand is encountered, it is added to the accumulator - go k acc ops_acc ((L l (TyElOpd a)):xs) = go k (HsValArg (L l a):acc) ops_acc xs - - -- clause [tyapp]: - -- whenever a type application is encountered, it is added to the accumulator - go k acc ops_acc ((L _ (TyElKindApp l a)):xs) = go k (HsTypeArg l a:acc) ops_acc xs - - -- clause [end] - -- See Note [Non-empty 'acc' in mergeOps clause [end]] - go _ acc ops_acc [] = do { acc' <- eitherToP (mergeOpsAcc acc) - ; return (ops_acc acc') } - -mergeOpsAcc :: [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> Either (SrcSpan, SDoc) (LHsType GhcPs) -mergeOpsAcc [] = panic "mergeOpsAcc: empty input" -mergeOpsAcc (HsTypeArg _ (L loc ki):_) - = Left (loc, text "Unexpected type application:" <+> ppr ki) -mergeOpsAcc (HsValArg ty : xs) = go1 ty xs - where - go1 :: LHsType GhcPs - -> [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> Either (SrcSpan, SDoc) (LHsType GhcPs) - go1 lhs [] = Right lhs - go1 lhs (x:xs) = case x of - HsValArg ty -> go1 (mkHsAppTy lhs ty) xs - HsTypeArg loc ki -> let ty = mkHsAppKindTy loc lhs ki - in go1 ty xs - HsArgPar _ -> go1 lhs xs -mergeOpsAcc (HsArgPar _: xs) = mergeOpsAcc xs - -{- Note [Impossible case in mergeOps clause [unpk]] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -This case should never occur. Let us consider all possible -variations of 'acc', 'xs', and 'k': - - acc xs k -============================== - null | null 0 -- "must be applied to a type" - null | not null 0 -- "must be applied to a type" -not null | null 0 -- successful parse -not null | not null 0 -- "cannot appear inside a type" - null | null >0 -- handled in clause [opr] - null | not null >0 -- "cannot appear inside a type" -not null | null >0 -- successful parse -not null | not null >0 -- "cannot appear inside a type" - -The (null acc && null xs && k>0) case is handled in clause [opr] -by the following check: - - if ... || null (filter isTyElOpd xs) - then failOpFewArgs (L l op) - -We know that this check has been performed because k>0, and by -the time we reach the end of the list (null xs), the only way -for (null acc) to hold is that there was not a single TyElOpd -between the operator and the end of the list. But this case is -caught by the check and reported as 'failOpFewArgs'. --} - -{- Note [Non-empty 'acc' in mergeOps clause [end]] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In clause [end] we need to know that 'acc' is non-empty to call 'mergeAcc' -without a check. - -Running 'mergeOps' with an empty input list is forbidden, so we do not consider -this possibility. This means we'll hit at least one other clause before we -reach clause [end]. - -* Clauses [unpk] and [doc] do not call 'go' recursively, so we cannot hit - clause [end] from there. -* Clause [opd] makes 'acc' non-empty, so if we hit clause [end] after it, 'acc' - will be non-empty. -* Clause [opr] checks that (filter isTyElOpd xs) is not null - so we are going - to hit clause [opd] at least once before we reach clause [end], making 'acc' - non-empty. -* There are no other clauses. - -Therefore, it is safe to omit a check for non-emptiness of 'acc' in clause -[end]. - --} - -pInfixSide :: [Located TyEl] -> Maybe (LHsType GhcPs, P (), [Located TyEl]) -pInfixSide ((L l (TyElOpd t)):xs) - | (True, t', addAnns, xs') <- pBangTy (L l t) xs - = Just (t', addAnns, xs') -pInfixSide (el:xs1) - | Just t1 <- pLHsTypeArg el - = go [t1] xs1 - where - go :: [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> [Located TyEl] -> Maybe (LHsType GhcPs, P (), [Located TyEl]) - go acc (el:xs) - | Just t <- pLHsTypeArg el - = go (t:acc) xs - go acc xs = case mergeOpsAcc acc of - Left _ -> Nothing - Right acc' -> Just (acc', pure (), xs) -pInfixSide _ = Nothing - -pLHsTypeArg :: Located TyEl -> Maybe (HsArg (LHsType GhcPs) (LHsKind GhcPs)) -pLHsTypeArg (L l (TyElOpd a)) = Just (HsValArg (L l a)) -pLHsTypeArg (L _ (TyElKindApp l a)) = Just (HsTypeArg l a) -pLHsTypeArg _ = Nothing - -orErr :: Maybe a -> b -> Either b a -orErr (Just a) _ = Right a -orErr Nothing b = Left b - --- | Merge a /reversed/ and /non-empty/ soup of operators and operands --- into a data constructor. --- --- User input: @C !A B -- ^ doc@ --- Input to 'mergeDataCon': ["doc", B, !A, C] --- Output: (C, PrefixCon [!A, B], "doc") --- --- See Note [Parsing data constructors is hard] -mergeDataCon - :: [Located TyEl] - -> P ( Located RdrName -- constructor name - , HsConDeclDetails GhcPs -- constructor field information - ) -mergeDataCon all_xs = - do { (addAnns, a) <- eitherToP res - ; addAnns - ; return a } +-- | Annotate a type with either an @{-\# UNPACK \#-}@ or a @{-\# NOUNPACK \#-}@ pragma. +addUnpackednessP :: MonadP m => Located UnpackednessPragma -> LHsType GhcPs -> m (LHsType GhcPs) +addUnpackednessP (L lprag (UnpackednessPragma anns prag unpk)) ty = do + let l' = combineSrcSpans lprag (getLoc ty) + t' = addUnpackedness ty + addAnnsAt l' anns + return (L l' t') where - -- The result of merging the list of reversed TyEl into a - -- data constructor, along with [AddAnn]. - res = goFirst all_xs - - goFirst [ L l (TyElOpd (HsTyVar _ _ (L _ tc))) ] - = do { data_con <- tyConToDataCon l tc - ; return (pure (), (data_con, PrefixCon [])) } - goFirst ((L l (TyElOpd (HsRecTy _ fields))):xs) - | [ L l' (TyElOpd (HsTyVar _ _ (L _ tc))) ] <- xs - = do { data_con <- tyConToDataCon l' tc - ; return (pure (), (data_con, RecCon (L l fields))) } - goFirst [L l (TyElOpd (HsTupleTy _ HsBoxedOrConstraintTuple ts))] - = return ( pure () - , ( L l (getRdrName (tupleDataCon Boxed (length ts))) - , PrefixCon (map hsLinear ts) ) ) - goFirst ((L l (TyElOpd t)):xs) - | (_, t', addAnns, xs') <- pBangTy (L l t) xs - = go addAnns [t'] xs' - goFirst (L l (TyElKindApp _ _):_) - = goInfix Monoid.<> Left (l, kindAppErr) - goFirst xs - = go (pure ()) [] xs - - go addAnns ts [ L l (TyElOpd (HsTyVar _ _ (L _ tc))) ] - = do { data_con <- tyConToDataCon l tc - ; return (addAnns, (data_con, PrefixCon (map hsLinear ts))) } - go addAnns ts ((L l (TyElOpd t)):xs) - | (_, t', addAnns', xs') <- pBangTy (L l t) xs - = go (addAnns >> addAnns') (t':ts) xs' - go _ _ ((L _ (TyElOpr _)):_) = - -- Encountered an operator: backtrack to the beginning and attempt - -- to parse as an infix definition. - goInfix - go _ _ (L l (TyElKindApp _ _):_) = goInfix Monoid.<> Left (l, kindAppErr) - go _ _ _ = Left malformedErr - where - malformedErr = - ( foldr combineSrcSpans noSrcSpan (map getLoc all_xs) - , text "Cannot parse data constructor" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs)) - - goInfix = - do { let xs0 = all_xs - ; (rhs, rhs_addAnns, xs1) <- pInfixSide xs0 `orErr` malformedErr - ; (op, xs3) <- case xs1 of - (L l (TyElOpr op)) : xs3 -> - do { data_con <- tyConToDataCon l op - ; return (data_con, xs3) } - _ -> Left malformedErr - ; (lhs, lhs_addAnns, xs5) <- pInfixSide xs3 `orErr` malformedErr - ; unless (null xs5) (Left malformedErr) - ; let addAnns = lhs_addAnns >> rhs_addAnns - ; return (addAnns, (op, InfixCon (hsLinear lhs) (hsLinear rhs))) } - where - malformedErr = - ( foldr combineSrcSpans noSrcSpan (map getLoc all_xs) - , text "Cannot parse an infix data constructor" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs)) - - kindAppErr = - text "Unexpected kind application" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs) + -- If we have a HsBangTy that only has a strictness annotation, + -- such as ~T or !T, then add the pragma to the existing HsBangTy. + -- + -- Otherwise, wrap the type in a new HsBangTy constructor. + addUnpackedness (L _ (HsBangTy x bang t)) + | HsSrcBang NoSourceText NoSrcUnpack strictness <- bang + = HsBangTy x (HsSrcBang prag unpk strictness) t + addUnpackedness t + = HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t --------------------------------------------------------------------------- -- | Check for monad comprehensions @@ -1645,7 +1334,6 @@ checkMonadComp = do -- See Note [Ambiguous syntactic categories] -- --- See Note [Parser-Validator] -- See Note [Ambiguous syntactic categories] -- -- This newtype is required to avoid impredicative types in monadic @@ -1659,10 +1347,7 @@ checkMonadComp = do -- P (forall b. DisambECP b => PV (Located b)) -- newtype ECP = - ECP { runECP_PV :: forall b. DisambECP b => PV (Located b) } - -runECP_P :: DisambECP b => ECP -> P (Located b) -runECP_P p = runPV (runECP_PV p) + ECP { unECP :: forall b. DisambECP b => PV (Located b) } ecpFromExp :: LHsExpr GhcPs -> ECP ecpFromExp a = ECP (ecpFromExp' a) @@ -2053,9 +1738,145 @@ mkPatRec (unLoc -> PatBuilderVar c) (HsRecFields fs dd) mkPatRec p _ = addFatalError (getLoc p) $ text "Not a record constructor:" <+> ppr p +-- | Disambiguate constructs that may appear when we do not know +-- ahead of time whether we are parsing a type or a newtype/data constructor. +-- +-- See Note [Ambiguous syntactic categories] for the general idea. +-- +-- See Note [Parsing data constructors is hard] for the specific issue this +-- particular class is solving. +-- +class DisambTD b where + -- | Process the head of a type-level function/constructor application, + -- i.e. the @H@ in @H a b c at . + mkHsAppTyHeadPV :: LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f x@ (function application or prefix data constructor). + mkHsAppTyPV :: Located b -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f \@t@ (visible kind application) + mkHsAppKindTyPV :: Located b -> SrcSpan -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f \# x@ (infix operator) + mkHsOpTyPV :: LHsType GhcPs -> Located RdrName -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @{-\# UNPACK \#-} t@ (unpack/nounpack pragma) + mkUnpackednessPV :: Located UnpackednessPragma -> Located b -> PV (Located b) + +instance DisambTD (HsType GhcPs) where + mkHsAppTyHeadPV = return + mkHsAppTyPV t1 t2 = return (mkHsAppTy t1 t2) + mkHsAppKindTyPV t l_at ki = return (mkHsAppKindTy l' t ki) + where l' = combineSrcSpans l_at (getLoc ki) + mkHsOpTyPV t1 op t2 = return (mkLHsOpTy t1 op t2) + mkUnpackednessPV = addUnpackednessP + +-- | An accumulator to build a prefix data constructor, +-- e.g. when parsing @MkT A B C@, the accumulator will evolve as follows: +-- +-- @ +-- 1. PrefixDataConBuilder [] MkT +-- 2. PrefixDataConBuilder [A] MkT +-- 3. PrefixDataConBuilder [A, B] MkT +-- 4. PrefixDataConBuilder [A, B, C] MkT +-- @ +-- +-- There are two reasons we have a separate builder type instead of using +-- @HsConDeclDetails GhcPs@ directly: +-- +-- 1. It's faster, because 'OrdList' gives us constant-time snoc. +-- 2. Having a separate type helps ensure that we don't forget to finalize a +-- 'RecTy' into a 'RecCon' (we do that in 'dataConBuilderDetails'). +-- +-- See Note [PatBuilder] for another builder type used in the parser. +-- Here the technique is similar, but the motivation is different. +data DataConBuilder + = PrefixDataConBuilder + (OrdList (LHsType GhcPs)) -- Data constructor fields + (Located RdrName) -- Data constructor name + | InfixDataConBuilder + (LHsType GhcPs) -- LHS field + (Located RdrName) -- Data constructor name + (LHsType GhcPs) -- RHS field + +dataConBuilderCon :: DataConBuilder -> Located RdrName +dataConBuilderCon (PrefixDataConBuilder _ dc) = dc +dataConBuilderCon (InfixDataConBuilder _ dc _) = dc + +dataConBuilderDetails :: DataConBuilder -> HsConDeclDetails GhcPs + +-- Detect when the record syntax is used: +-- data T = MkT { ... } +dataConBuilderDetails (PrefixDataConBuilder flds _) + | [L l_t (HsRecTy _ fields)] <- toList flds + = RecCon (L l_t fields) + +-- Normal prefix constructor, e.g. data T = MkT A B C +dataConBuilderDetails (PrefixDataConBuilder flds _) + = PrefixCon (map hsLinear (toList flds)) + +-- Infix constructor, e.g. data T = Int :! Bool +dataConBuilderDetails (InfixDataConBuilder lhs _ rhs) + = InfixCon (hsLinear lhs) (hsLinear rhs) + +instance Outputable DataConBuilder where + ppr (PrefixDataConBuilder flds data_con) = + hang (ppr data_con) 2 (sep (map ppr (toList flds))) + ppr (InfixDataConBuilder lhs data_con rhs) = + ppr lhs <+> ppr data_con <+> ppr rhs + +instance DisambTD DataConBuilder where + mkHsAppTyHeadPV = tyToDataConBuilder + + mkHsAppTyPV (L l (PrefixDataConBuilder flds fn)) t = + return $ + L (combineSrcSpans l (getLoc t)) + (PrefixDataConBuilder (flds `snocOL` t) fn) + mkHsAppTyPV (L _ InfixDataConBuilder{}) _ = + -- This case is impossible because of the way + -- the grammar in Parser.y is written (see infixtype/ftype). + panic "mkHsAppTyPV: InfixDataConBuilder" + + mkHsAppKindTyPV lhs l_at ki = + addFatalError l_at $ + hang (text "Unexpected kind application in a data/newtype declaration:") 2 + (ppr lhs <+> text "@" <> ppr ki) + + mkHsOpTyPV lhs (L l_tc tc) rhs = do + check_no_ops (unLoc rhs) -- check the RHS because parsing type operators is right-associative + data_con <- eitherToP $ tyConToDataCon l_tc tc + return $ L l (InfixDataConBuilder lhs data_con rhs) + where + l = combineLocs lhs rhs + check_no_ops (HsBangTy _ _ t) = check_no_ops (unLoc t) + check_no_ops (HsOpTy{}) = + addError l $ + hang (text "Cannot parse an infix data constructor in a data/newtype declaration:") + 2 (ppr lhs <+> ppr tc <+> ppr rhs) + check_no_ops _ = return () + + mkUnpackednessPV unpk constr_stuff + | L _ (InfixDataConBuilder lhs data_con rhs) <- constr_stuff + = -- When the user writes data T = {-# UNPACK #-} Int :+ Bool + -- we apply {-# UNPACK #-} to the LHS + do lhs' <- addUnpackednessP unpk lhs + let l = combineLocs unpk constr_stuff + return $ L l (InfixDataConBuilder lhs' data_con rhs) + | otherwise = + do addError (getLoc unpk) $ + text "{-# UNPACK #-} cannot be applied to a data constructor." + return constr_stuff + +tyToDataConBuilder :: LHsType GhcPs -> PV (Located DataConBuilder) +tyToDataConBuilder (L l (HsTyVar _ NotPromoted (L _ v))) = do + data_con <- eitherToP $ tyConToDataCon l v + return $ L l (PrefixDataConBuilder nilOL data_con) +tyToDataConBuilder (L l (HsTupleTy _ HsBoxedOrConstraintTuple ts)) = do + let data_con = L l (getRdrName (tupleDataCon Boxed (length ts))) + return $ L l (PrefixDataConBuilder (toOL ts) data_con) +tyToDataConBuilder t = + addFatalError (getLoc t) $ + hang (text "Cannot parse data constructor in a data/newtype declaration:") + 2 (ppr t) + {- Note [Ambiguous syntactic categories] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - There are places in the grammar where we do not know whether we are parsing an expression or a pattern without unlimited lookahead (which we do not have in 'happy'): @@ -2150,6 +1971,21 @@ position and shadows the previous $1. We can do this because internally is to be able to write (sLL $1 $>) later on. The alternative would be to write this as ($1 >>= \ fresh_name -> ...), but then we couldn't refer to the last fresh name as $>. + +Finally, we instantiate the polymorphic type to a concrete one, and run the +parser-validator, for example: + + stmt :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } + e_stmt :: { LStmt GhcPs (LHsExpr GhcPs) } + : stmt {% runPV $1 } + +In e_stmt, three things happen: + + 1. we instantiate: b ~ HsExpr GhcPs + 2. we embed the PV computation into P by using runPV + 3. we run validation by using a monadic production, {% ... } + +At this point the ambiguity is resolved. -} @@ -2306,7 +2142,6 @@ Alternative VII, a product type We could avoid the intermediate representation of Alternative VI by parsing into a product of interpretations directly: - -- See Note [Parser-Validator] type ExpCmdPat = ( PV (LHsExpr GhcPs) , PV (LHsCmd GhcPs) , PV (LHsPat GhcPs) ) @@ -2326,7 +2161,6 @@ We can easily define ambiguities between arbitrary subsets of interpretations. For example, when we know ahead of type that only an expression or a command is possible, but not a pattern, we can use a smaller type: - -- See Note [Parser-Validator] type ExpCmd = (PV (LHsExpr GhcPs), PV (LHsCmd GhcPs)) checkExpOf2 (e, _) = e -- interpret as an expression @@ -2809,7 +2643,7 @@ warnStarBndr span = addWarning Opt_WarnStarBinder span msg <+> text "modules with StarIsType," $$ text " including the definition module, you must qualify it." -failOpFewArgs :: Located RdrName -> P a +failOpFewArgs :: MonadP m => Located RdrName -> m a failOpFewArgs (L loc op) = do { star_is_type <- getBit StarIsTypeBit ; let msg = too_few $$ starInfo star_is_type op @@ -2836,7 +2670,25 @@ data PV_Accum = data PV_Result a = PV_Ok PV_Accum a | PV_Failed PV_Accum --- See Note [Parser-Validator] +-- During parsing, we make use of several monadic effects: reporting parse errors, +-- accumulating warnings, adding API annotations, and checking for extensions. These +-- effects are captured by the 'MonadP' type class. +-- +-- Sometimes we need to postpone some of these effects to a later stage due to +-- ambiguities described in Note [Ambiguous syntactic categories]. +-- We could use two layers of the P monad, one for each stage: +-- +-- abParser :: forall x. DisambAB x => P (P x) +-- +-- The outer layer of P consumes the input and builds the inner layer, which +-- validates the input. But this type is not particularly helpful, as it obscures +-- the fact that the inner layer of P never consumes any input. +-- +-- For clarity, we introduce the notion of a parser-validator: a parser that does +-- not consume any input, but may fail or use other effects. Thus we have: +-- +-- abParser :: forall x. DisambAB x => P (PV x) +-- newtype PV a = PV { unPV :: PV_Context -> PV_Accum -> PV_Result a } instance Functor PV where @@ -2910,36 +2762,6 @@ instance MonadP PV where PV_Ok acc' () addAnnotation _ _ _ = return () -{- Note [Parser-Validator] -~~~~~~~~~~~~~~~~~~~~~~~~~~ - -When resolving ambiguities, we need to postpone failure to make a choice later. -For example, if we have ambiguity between some A and B, our parser could be - - abParser :: P (Maybe A, Maybe B) - -This way we can represent four possible outcomes of parsing: - - (Just a, Nothing) -- definitely A - (Nothing, Just b) -- definitely B - (Just a, Just b) -- either A or B - (Nothing, Nothing) -- neither A nor B - -However, if we want to report informative parse errors, accumulate warnings, -and add API annotations, we are better off using 'P' instead of 'Maybe': - - abParser :: P (P A, P B) - -So we have an outer layer of P that consumes the input and builds the inner -layer, which validates the input. - -For clarity, we introduce the notion of a parser-validator: a parser that does -not consume any input, but may fail or use other effects. Thus we have: - - abParser :: P (PV A, PV B) - --} - {- Note [Parser-Validator Hint] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A PV computation is parametrized by a hint for error messages, which can be set ===================================== compiler/GHC/Platform/Profile.hs ===================================== @@ -13,8 +13,6 @@ import GHC.Prelude import GHC.Platform import GHC.Platform.Ways -import Data.Set - -- | A platform profile fully describes the kind of objects that are generated -- for a platform. -- @@ -22,8 +20,8 @@ import Data.Set -- (profiling, debug, dynamic) also modify the ABI. -- data Profile = Profile - { profilePlatform :: !Platform -- ^ Platform - , profileWays :: !(Set Way) -- ^ Ways + { profilePlatform :: !Platform -- ^ Platform + , profileWays :: !Ways -- ^ Ways } -- | Get platform constants ===================================== compiler/GHC/Platform/Ways.hs ===================================== @@ -20,6 +20,7 @@ -- this compilation. module GHC.Platform.Ways ( Way(..) + , Ways , hasWay , allowed_combination , wayGeneralFlags @@ -61,12 +62,14 @@ data Way | WayDyn -- ^ Dynamic linking deriving (Eq, Ord, Show) +type Ways = Set Way + -- | Test if a ways is enabled -hasWay :: Set Way -> Way -> Bool +hasWay :: Ways -> Way -> Bool hasWay ws w = Set.member w ws -- | Check if a combination of ways is allowed -allowed_combination :: Set Way -> Bool +allowed_combination :: Ways -> Bool allowed_combination ways = not disallowed where disallowed = or [ hasWay ways x && hasWay ways y @@ -76,13 +79,13 @@ allowed_combination ways = not disallowed couples = [] -- we don't have any disallowed combination of ways nowadays -- | Unique tag associated to a list of ways -waysTag :: Set Way -> String +waysTag :: Ways -> String waysTag = concat . intersperse "_" . map wayTag . Set.toAscList -- | Unique build-tag associated to a list of ways -- -- RTS only ways are filtered out because they have no impact on the build. -waysBuildTag :: Set Way -> String +waysBuildTag :: Ways -> String waysBuildTag ws = waysTag (Set.filter (not . wayRTSOnly) ws) @@ -195,7 +198,7 @@ foreign import ccall unsafe "rts_isDynamic" rtsIsDynamicIO :: IO Int -- | Return host "full" ways (i.e. ways that have an impact on the compilation, -- not RTS only ways). These ways must be used when compiling codes targeting -- the internal interpreter. -hostFullWays :: Set Way +hostFullWays :: Ways hostFullWays = Set.unions [ if hostIsDynamic then Set.singleton WayDyn else Set.empty , if hostIsProfiled then Set.singleton WayProf else Set.empty ===================================== compiler/GHC/Tc/TyCl.hs ===================================== @@ -74,7 +74,6 @@ import GHC.Types.SrcLoc import GHC.Data.List.SetOps import GHC.Driver.Session import GHC.Types.Unique -import GHC.Core.ConLike( ConLike(..) ) import GHC.Types.Basic import qualified GHC.LanguageExtensions as LangExt @@ -3819,15 +3818,14 @@ checkValidTyCl tc where recovery_code -- See Note [Recover from validity error] = do { traceTc "Aborted validity for tycon" (ppr tc) - ; return (concatMap mk_fake_tc $ - ATyCon tc : implicitTyConThings tc) } + ; return (map mk_fake_tc $ + tc : child_tycons tc) } - mk_fake_tc (ATyCon tc) - | isClassTyCon tc = [tc] -- Ugh! Note [Recover from validity error] - | otherwise = [makeRecoveryTyCon tc] - mk_fake_tc (AConLike (RealDataCon dc)) - = [makeRecoveryTyCon (promoteDataCon dc)] - mk_fake_tc _ = [] + mk_fake_tc tc + | isClassTyCon tc = tc -- Ugh! Note [Recover from validity error] + | otherwise = makeRecoveryTyCon tc + + child_tycons tc = tyConATs tc ++ map promoteDataCon (tyConDataCons tc) {- Note [Recover from validity error] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -3852,6 +3850,8 @@ Some notes: and so there was an internal error when we met 'MkT' in the body of 'S'. + Similarly for associated types. + * Painfully, we *don't* want to do this for classes. Consider tcfail041: class (?x::Int) => C a where ... @@ -3864,6 +3864,14 @@ Some notes: This is really bogus; now we have in scope a Class that is invalid in some way, with unknown downstream consequences. A better alternative might be to make a fake class TyCon. A job for another day. + +* Previously, we used implicitTyConThings to snaffle out the parts + to add to the context. The problem is that this also grabs data con + wrapper Ids. These could be filtered out. But, painfully, getting + the wrapper Ids checks the DataConRep, and forcing the DataConRep + can panic if there is a levity-polymorphic argument. This is #18534. + We don't need the wrapper Ids here anyway. So the code just takes what + it needs, via child_tycons. -} ------------------------- @@ -4050,8 +4058,13 @@ checkValidDataCon dflags existential_ok tc con -- regardless of whether or not UnliftedNewtypes is enabled. A -- later check in checkNewDataCon handles this, producing a -- better error message than checkForLevPoly would. - ; unless (isNewTyCon tc) - (mapM_ (checkForLevPoly empty) (map scaledThing $ dataConOrigArgTys con)) + ; unless (isNewTyCon tc) $ + checkNoErrs $ + mapM_ (checkForLevPoly empty) (map scaledThing $ dataConOrigArgTys con) + -- the checkNoErrs is to prevent a panic in isVanillaDataCon + -- (called a a few lines down), which can fall over if there is a + -- bang on a levity-polymorphic argument. This is #18534, + -- typecheck/should_fail/T18534 -- Extra checks for newtype data constructors. Importantly, these -- checks /must/ come before the call to checkValidType below. This ===================================== compiler/GHC/Unit/State.hs ===================================== @@ -315,7 +315,7 @@ instance Monoid UnitVisibility where -- | Unit configuration data UnitConfig = UnitConfig { unitConfigPlatformArchOS :: !ArchOS -- ^ Platform arch and OS - , unitConfigWays :: !(Set Way) -- ^ Ways to use + , unitConfigWays :: !Ways -- ^ Ways to use , unitConfigProgramName :: !String -- ^ Name of the compiler (e.g. "GHC", "GHCJS"). Used to fetch environment -- variables such as "GHC[JS]_PACKAGE_PATH". ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.hs ===================================== @@ -0,0 +1,50 @@ +{-# LANGUAGE TemplateHaskell, ExplicitForAll, PolyKinds #-} + +module Main where + +import Language.Haskell.TH (runQ) +import GHC.Types.Basic +import GHC.ThToHs +import GHC.Driver.Session +import GHC.Core.TyCo.Ppr +import GHC.Utils.Outputable +import GHC.Tc.Module +import GHC.Tc.Utils.Zonk +import GHC.Utils.Error +import GHC.Driver.Types +import GHC +import qualified GHC.LanguageExtensions as LangExt + +import Data.Either (fromRight) +import Control.Monad.IO.Class (liftIO) +import System.Environment (getArgs) + +main :: IO () +main = do + [libdir] <- getArgs + runGhc (Just libdir) $ do + initial_dflags <- getSessionDynFlags + setSessionDynFlags $ initial_dflags + `dopt_set` Opt_D_ppr_debug + `gopt_set` Opt_SuppressUniques + `gopt_set` Opt_SuppressModulePrefixes + `gopt_set` Opt_SuppressVarKinds + `xopt_set` LangExt.KindSignatures + `xopt_set` LangExt.PolyKinds + `xopt_set` LangExt.RankNTypes + hsc_env <- getSession + let dflags = hsc_dflags hsc_env + liftIO $ do + th_t <- runQ [t| forall k {j}. + forall (a :: k) (b :: j) -> + () |] + let hs_t = fromRight (error "convertToHsType") $ + convertToHsType Generated noSrcSpan th_t + ((warnings, errors), mres) <- + tcRnType hsc_env SkolemiseFlexi True hs_t + case mres of + Nothing -> do + printBagOfErrors dflags warnings + printBagOfErrors dflags errors + Just (t, _) -> do + putStrLn $ showSDoc dflags (debugPprType t) ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.stdout ===================================== @@ -0,0 +1,2 @@ +forall k{tv}[tv] {j{tv}[tv]}. +forall a{tv}[tv] b{tv}[tv] -> (){(w) tc} ===================================== testsuite/tests/ghc-api/all.T ===================================== @@ -20,3 +20,7 @@ test('T9015', extra_run_opts('"' + config.libdir + '"'), test('T11579', extra_run_opts('"' + config.libdir + '"'), compile_and_run, ['-package ghc']) test('T12099', normal, compile_and_run, ['-package ghc']) +test('T18522-dbg-ppr', + extra_run_opts('"' + config.libdir + '"'), + compile_and_run, + ['-package ghc']) ===================================== testsuite/tests/parser/should_fail/T12045d.stderr ===================================== @@ -1,4 +1,3 @@ T12045d.hs:11:16: error: - Unexpected kind application in a data/newtype declaration: - MkD @Nat Bool + Unexpected kind application in a data/newtype declaration: MkD @Nat ===================================== testsuite/tests/parser/should_fail/strictnessDataCon_B.stderr ===================================== @@ -1,3 +1,2 @@ -strictnessDataCon_B.hs:1:27: error: - {-# UNPACK #-} cannot appear inside a type. +strictnessDataCon_B.hs:1:42: error: parse error on input ‘}’ ===================================== testsuite/tests/parser/should_fail/typeops_A.stderr ===================================== @@ -1,2 +1,3 @@ -typeops_A.hs:1:12: error: Operator applied to too few arguments: + +typeops_A.hs:2:1: error: + parse error (possibly incorrect indentation or mismatched brackets) ===================================== testsuite/tests/parser/should_fail/typeops_C.stderr ===================================== @@ -1,2 +1,2 @@ -typeops_C.hs:1:12: error: Operator applied to too few arguments: + +typeops_C.hs:1:14: error: Operator applied to too few arguments: + ===================================== testsuite/tests/parser/should_fail/unpack_empty_type.stderr ===================================== @@ -1,3 +1,2 @@ -unpack_empty_type.hs:3:19: error: - {-# UNPACK #-} must be applied to a type. +unpack_empty_type.hs:3:34: error: parse error on input ‘}’ ===================================== testsuite/tests/parser/should_fail/unpack_inside_type.stderr ===================================== @@ -1,3 +1,7 @@ unpack_inside_type.hs:3:25: error: - {-# UNPACK #-} cannot appear inside a type. + • Unexpected UNPACK annotation: {-# UNPACK #-}Int + UNPACK annotation cannot appear nested inside a type + • In the first argument of ‘Maybe’, namely ‘({-# UNPACK #-}Int)’ + In the type ‘Maybe ({-# UNPACK #-}Int)’ + In the definition of data constructor ‘T’ ===================================== testsuite/tests/polykinds/T18522-ppr.script ===================================== @@ -0,0 +1,4 @@ +:set -XPolyKinds -XDataKinds -XRankNTypes -XTypeFamilies +import Data.Kind (Type) +type family T :: forall k -> (k ~ k) => forall j -> k -> j -> Type +:k T ===================================== testsuite/tests/polykinds/T18522-ppr.stdout ===================================== @@ -0,0 +1 @@ +T :: forall k -> (k ~ k) => forall j -> k -> j -> * ===================================== testsuite/tests/polykinds/all.T ===================================== @@ -223,3 +223,4 @@ test('T18300', normal, compile_fail, ['']) test('T18451', normal, compile_fail, ['']) test('T18451a', normal, compile_fail, ['']) test('T18451b', normal, compile_fail, ['']) +test('T18522-ppr', normal, ghci_script, ['T18522-ppr.script']) ===================================== testsuite/tests/typecheck/should_fail/T18534.hs ===================================== @@ -0,0 +1,7 @@ +{-# LANGUAGE PolyKinds #-} + +module Test where + +import GHC.Exts + +data Test (a :: TYPE r) = Test !a ===================================== testsuite/tests/typecheck/should_fail/T18534.stderr ===================================== @@ -0,0 +1,7 @@ + +T18534.hs:7:27: error: + • A levity-polymorphic type is not allowed here: + Type: a + Kind: TYPE r + • In the definition of data constructor ‘Test’ + In the data type declaration for ‘Test’ ===================================== testsuite/tests/typecheck/should_fail/all.T ===================================== @@ -578,3 +578,4 @@ test('T18357', normal, compile_fail, ['']) test('T18357a', normal, compile_fail, ['']) test('T18357b', normal, compile_fail, ['']) test('T18455', normal, compile_fail, ['']) +test('T18534', normal, compile_fail, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/3021450bd8227697257459cdba56b114a2ed83ff...829f48c0181168c8012eb976135746a473878ec6 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/3021450bd8227697257459cdba56b114a2ed83ff...829f48c0181168c8012eb976135746a473878ec6 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 09:25:13 2020 From: gitlab at gitlab.haskell.org (Moritz Angermann) Date: Thu, 06 Aug 2020 05:25:13 -0400 Subject: [Git][ghc/ghc][wip/angerman/cross-test-suite] 71 commits: [linker] Fix out of range relocations. Message-ID: <5f2bcc79e5f35_80b3f849a25e6906774234@gitlab.haskell.org.mail> Moritz Angermann pushed to branch wip/angerman/cross-test-suite at Glasgow Haskell Compiler / GHC Commits: dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - c168a269 by Moritz Angermann at 2020-08-06T17:23:29+08:00 Cross Test Suite This introduces the ability to test cross compilers agains the testsuite as well. This is achieved by disabling some tests that make no sense in a cross compilation setting, or simply can not be made to cross compile proplery. The fundamental idea is that we can run produced binaries through a TEST_WRAPPER, if provided. This could be qemu in user mode, or wine, or nodejs, or anything that could transparrently run the executable build product on the build machine. - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/test-metrics.sh - CODEOWNERS - aclocal.m4 - compiler/GHC.hs - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/Graph.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Monad.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/Config.hs - compiler/GHC/CmmToAsm/Dwarf/Types.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs - compiler/GHC/CmmToC.hs - compiler/GHC/CmmToLlvm.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/Opt/OccurAnal.hs - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ff0f3737d334f845e64c1cd89b2cbcdbf6935fb9...c168a2692af42e77d3a7dc9d76d86e50c68da7f9 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ff0f3737d334f845e64c1cd89b2cbcdbf6935fb9...c168a2692af42e77d3a7dc9d76d86e50c68da7f9 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 12:03:57 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 06 Aug 2020 08:03:57 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 6 commits: Grammar for types and data/newtype constructors Message-ID: <5f2bf1ad50160_80b3f848c1e06f4680755d@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 2c812b7b by Vladislav Zavialov at 2020-08-06T08:03:45-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 9f702f5e by Vladislav Zavialov at 2020-08-06T08:03:45-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 68504fdf by Vladislav Zavialov at 2020-08-06T08:03:46-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - de222b0e by Vladislav Zavialov at 2020-08-06T08:03:46-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - 27aad4ab by Richard Eisenberg at 2020-08-06T08:03:46-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 54d6387a by Sylvain Henry at 2020-08-06T08:03:48-04:00 Use a type alias for Ways - - - - - 24 changed files: - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Platform/Profile.hs - compiler/GHC/Platform/Ways.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Unit/State.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.stdout - testsuite/tests/ghc-api/all.T - testsuite/tests/parser/should_fail/T12045d.stderr - testsuite/tests/parser/should_fail/strictnessDataCon_B.stderr - testsuite/tests/parser/should_fail/typeops_A.stderr - testsuite/tests/parser/should_fail/typeops_C.stderr - testsuite/tests/parser/should_fail/unpack_empty_type.stderr - testsuite/tests/parser/should_fail/unpack_inside_type.stderr - + testsuite/tests/polykinds/T18522-ppr.script - + testsuite/tests/polykinds/T18522-ppr.stdout - testsuite/tests/polykinds/all.T - + testsuite/tests/typecheck/should_fail/T18534.hs - + testsuite/tests/typecheck/should_fail/T18534.stderr - testsuite/tests/typecheck/should_fail/all.T Changes: ===================================== compiler/GHC/Core/TyCo/Ppr.hs ===================================== @@ -36,7 +36,8 @@ import {-# SOURCE #-} GHC.CoreToIface import {-# SOURCE #-} GHC.Core.DataCon ( dataConFullSig , dataConUserTyVarBinders, DataCon ) -import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many ) +import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many, + splitForAllTysReq, splitForAllTysInvis ) import GHC.Core.TyCon import GHC.Core.TyCo.Rep @@ -268,19 +269,34 @@ debug_ppr_ty prec (CastTy ty co) debug_ppr_ty _ (CoercionTy co) = parens (text "CO" <+> ppr co) -debug_ppr_ty prec ty@(ForAllTy {}) - | (tvs, body) <- split ty +-- Invisible forall: forall {k} (a :: k). t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysInvis t + , not (null bndrs) = maybeParen prec funPrec $ - hang (text "forall" <+> fsep (map ppr tvs) <> dot) - -- The (map ppr tvs) will print kind-annotated - -- tvs, because we are (usually) in debug-style - 2 (ppr body) + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <> dot, + ppr body ] where - split ty | ForAllTy tv ty' <- ty - , (tvs, body) <- split ty' - = (tv:tvs, body) - | otherwise - = ([], ty) + -- (ppr tv) will print the binder kind-annotated + -- when in debug-style + ppr_bndr (Bndr tv InferredSpec) = braces (ppr tv) + ppr_bndr (Bndr tv SpecifiedSpec) = ppr tv + +-- Visible forall: forall x y -> t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysReq t + , not (null bndrs) + = maybeParen prec funPrec $ + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <+> arrow, + ppr body ] + where + -- (ppr tv) will print the binder kind-annotated + -- when in debug-style + ppr_bndr (Bndr tv ()) = ppr tv + +-- Impossible case: neither visible nor invisible forall. +debug_ppr_ty _ ForAllTy{} + = panic "debug_ppr_ty: neither splitForAllTysInvis nor splitForAllTysReq returned any binders" {- Note [Infix type variables] ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -534,7 +534,7 @@ data DynFlags = DynFlags { homeUnitInstantiations:: [(ModuleName, Module)], -- ^ How to instantiate `homeUnitInstanceOfId` unit -- ways - ways :: Set Way, -- ^ Way flags from the command line + ways :: Ways, -- ^ Way flags from the command line -- For object splitting splitInfo :: Maybe (String,Int), @@ -1433,7 +1433,7 @@ defaultDynFlags mySettings llvmConfig = cfgWeightInfo = defaultCfgWeights } -defaultWays :: Settings -> Set Way +defaultWays :: Settings -> Ways defaultWays settings = if pc_DYNAMIC_BY_DEFAULT (sPlatformConstants settings) then Set.singleton WayDyn else Set.empty ===================================== compiler/GHC/Iface/Type.hs ===================================== @@ -441,6 +441,7 @@ splitIfaceSigmaTy ty (theta, tau) = split_rho rho split_foralls (IfaceForAllTy bndr ty) + | isInvisibleArgFlag (binderArgFlag bndr) = case split_foralls ty of { (bndrs, rho) -> (bndr:bndrs, rho) } split_foralls rho = ([], rho) @@ -448,6 +449,12 @@ splitIfaceSigmaTy ty = case split_rho ty2 of { (ps, tau) -> (ty1:ps, tau) } split_rho tau = ([], tau) +splitIfaceReqForallTy :: IfaceType -> ([IfaceForAllBndr], IfaceType) +splitIfaceReqForallTy (IfaceForAllTy bndr ty) + | isVisibleArgFlag (binderArgFlag bndr) + = case splitIfaceReqForallTy ty of { (bndrs, rho) -> (bndr:bndrs, rho) } +splitIfaceReqForallTy rho = ([], rho) + suppressIfaceInvisibles :: PrintExplicitKinds -> [IfaceTyConBinder] -> [a] -> [a] suppressIfaceInvisibles (PrintExplicitKinds True) _tys xs = xs suppressIfaceInvisibles (PrintExplicitKinds False) tys xs = suppress tys xs @@ -1184,8 +1191,23 @@ pprIfaceSigmaType show_forall ty = hideNonStandardTypes ppr_fn ty where ppr_fn iface_ty = - let (tvs, theta, tau) = splitIfaceSigmaTy iface_ty - in ppr_iface_forall_part show_forall tvs theta (ppr tau) + let (invis_tvs, theta, tau) = splitIfaceSigmaTy iface_ty + (req_tvs, tau') = splitIfaceReqForallTy tau + -- splitIfaceSigmaTy is recursive, so it will gather the binders after + -- the theta, i.e. forall a. theta => forall b. tau + -- will give you ([a,b], theta, tau). + -- + -- This isn't right when it comes to visible forall (see + -- testsuite/tests/polykinds/T18522-ppr), + -- so we split off required binders separately, + -- using splitIfaceReqForallTy. + -- + -- An alternative solution would be to make splitIfaceSigmaTy + -- non-recursive (see #18458). + -- Then it could handle both invisible and required binders, and + -- splitIfaceReqForallTy wouldn't be necessary here. + in ppr_iface_forall_part show_forall invis_tvs theta $ + sep [pprIfaceForAll req_tvs, ppr tau'] pprUserIfaceForAll :: [IfaceForAllBndr] -> SDoc pprUserIfaceForAll tvs ===================================== compiler/GHC/Parser.y ===================================== @@ -1080,7 +1080,7 @@ topdecl :: { LHsDecl GhcPs } -- The $(..) form is one possible form of infixexp -- but we treat an arbitrary expression just as if -- it had a $(..) wrapped around it - | infixexp {% runECP_P $1 >>= \ $1 -> + | infixexp {% runPV (unECP $1) >>= \ $1 -> return $ sLL $1 $> $ mkSpliceDecl $1 } -- Type classes @@ -1528,7 +1528,7 @@ decl_cls : at_decl_cls { $1 } -- A 'default' signature used with the generic-programming extension | 'default' infixexp '::' sigtype - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> do { v <- checkValSigLhs $2 ; let err = text "in default signature" <> colon <+> quotes (ppr $2) @@ -1671,8 +1671,8 @@ rules :: { OrdList (LRuleDecl GhcPs) } rule :: { LRuleDecl GhcPs } : STRING rule_activation rule_foralls infixexp '=' exp - {%runECP_P $4 >>= \ $4 -> - runECP_P $6 >>= \ $6 -> + {%runPV (unECP $4) >>= \ $4 -> + runPV (unECP $6) >>= \ $6 -> ams (sLL $1 $> $ HsRule { rd_ext = noExtField , rd_name = L (gl $1) (getSTRINGs $1, getSTRING $1) , rd_act = (snd $2) `orElse` AlwaysActive @@ -1800,19 +1800,19 @@ stringlist :: { Located (OrdList (Located StringLiteral)) } ----------------------------------------------------------------------------- -- Annotations annotation :: { LHsDecl GhcPs } - : '{-# ANN' name_var aexp '#-}' {% runECP_P $3 >>= \ $3 -> + : '{-# ANN' name_var aexp '#-}' {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) (ValueAnnProvenance $2) $3)) [mo $1,mc $4] } - | '{-# ANN' 'type' tycon aexp '#-}' {% runECP_P $4 >>= \ $4 -> + | '{-# ANN' 'type' tycon aexp '#-}' {% runPV (unECP $4) >>= \ $4 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) (TypeAnnProvenance $3) $4)) [mo $1,mj AnnType $2,mc $5] } - | '{-# ANN' 'module' aexp '#-}' {% runECP_P $3 >>= \ $3 -> + | '{-# ANN' 'module' aexp '#-}' {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) ModuleAnnProvenance $3)) @@ -1966,22 +1966,28 @@ type :: { LHsType GhcPs } mult :: { LHsType GhcPs } : btype { $1 } - btype :: { LHsType GhcPs } - : tyapps {% mergeOps (unLoc $1) } - -tyapps :: { Located [Located TyEl] } -- NB: This list is reversed - : tyapp { sL1 $1 [$1] } - | tyapps tyapp { sLL $1 $> $ $2 : unLoc $1 } - -tyapp :: { Located TyEl } - : atype { sL1 $1 $ TyElOpd (unLoc $1) } - - -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer - | PREFIX_AT atype { sLL $1 $> $ (TyElKindApp (comb2 $1 $2) $2) } - - | tyop { mapLoc TyElOpr $1 } - | unpackedness { sL1 $1 $ TyElUnpackedness (unLoc $1) } + : infixtype {% runPV $1 } + +infixtype :: { forall b. DisambTD b => PV (Located b) } + : ftype { $1 } + | ftype tyop infixtype { $1 >>= \ $1 -> + $3 >>= \ $3 -> + mkHsOpTyPV $1 $2 $3 } + | unpackedness infixtype { $2 >>= \ $2 -> + mkUnpackednessPV $1 $2 } + +ftype :: { forall b. DisambTD b => PV (Located b) } + : atype { mkHsAppTyHeadPV $1 } + | tyop { failOpFewArgs $1 } + | ftype tyarg { $1 >>= \ $1 -> + mkHsAppTyPV $1 $2 } + | ftype PREFIX_AT tyarg { $1 >>= \ $1 -> + mkHsAppKindTyPV $1 (getLoc $2) $3 } + +tyarg :: { LHsType GhcPs } + : atype { $1 } + | unpackedness atype {% addUnpackednessP $1 $2 } tyop :: { Located RdrName } : qtyconop { $1 } @@ -2222,8 +2228,9 @@ forall :: { Located ([AddAnn], Maybe [LHsTyVarBndr Specificity GhcPs]) } | {- empty -} { noLoc ([], Nothing) } constr_stuff :: { Located (Located RdrName, HsConDeclDetails GhcPs) } - : tyapps {% do { c <- mergeDataCon (unLoc $1) - ; return $ sL1 $1 c } } + : infixtype {% fmap (mapLoc (\b -> (dataConBuilderCon b, + dataConBuilderDetails b))) + (runPV $1) } fielddecls :: { [LConDeclField GhcPs] } : {- empty -} { [] } @@ -2308,7 +2315,7 @@ There's an awkward overlap with a type signature. Consider decl_no_th :: { LHsDecl GhcPs } : sigdecl { $1 } - | infixexp opt_sig rhs {% runECP_P $1 >>= \ $1 -> + | infixexp opt_sig rhs {% runPV (unECP $1) >>= \ $1 -> do { (ann,r) <- checkValDef $1 (snd $2) $3; let { l = comb2 $1 $> }; -- Depending upon what the pattern looks like we might get either @@ -2332,7 +2339,7 @@ decl :: { LHsDecl GhcPs } | splice_exp { sLL $1 $> $ mkSpliceDecl $1 } rhs :: { Located ([AddAnn],GRHSs GhcPs (LHsExpr GhcPs)) } - : '=' exp wherebinds {% runECP_P $2 >>= \ $2 -> return $ + : '=' exp wherebinds {% runPV (unECP $2) >>= \ $2 -> return $ sL (comb3 $1 $2 $3) ((mj AnnEqual $1 : (fst $ unLoc $3)) ,GRHSs noExtField (unguardedRHS (comb3 $1 $2 $3) $2) @@ -2346,7 +2353,7 @@ gdrhs :: { Located [LGRHS GhcPs (LHsExpr GhcPs)] } | gdrh { sL1 $1 [$1] } gdrh :: { LGRHS GhcPs (LHsExpr GhcPs) } - : '|' guardquals '=' exp {% runECP_P $4 >>= \ $4 -> + : '|' guardquals '=' exp {% runPV (unECP $4) >>= \ $4 -> ams (sL (comb2 $1 $>) $ GRHS noExtField (unLoc $2) $4) [mj AnnVbar $1,mj AnnEqual $3] } @@ -2354,7 +2361,7 @@ sigdecl :: { LHsDecl GhcPs } : -- See Note [Declaration/signature overlap] for why we need infixexp here infixexp '::' sigtype - {% do { $1 <- runECP_P $1 + {% do { $1 <- runPV (unECP $1) ; v <- checkValSigLhs $1 ; _ <- amsL (comb2 $1 $>) [mu AnnDcolon $2] ; return (sLL $1 $> $ SigD noExtField $ @@ -2450,30 +2457,30 @@ quasiquote :: { Located (HsSplice GhcPs) } exp :: { ECP } : infixexp '::' sigtype { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> rejectPragmaPV $1 >> amms (mkHsTySigPV (comb2 $1 $>) $1 $3) [mu AnnDcolon $2] } - | infixexp '-<' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '-<' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $1 $3 HsFirstOrderApp True) [mu Annlarrowtail $2] } - | infixexp '>-' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '>-' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $3 $1 HsFirstOrderApp False) [mu Annrarrowtail $2] } - | infixexp '-<<' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '-<<' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $1 $3 HsHigherOrderApp True) [mu AnnLarrowtail $2] } - | infixexp '>>-' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '>>-' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $3 $1 HsHigherOrderApp False) @@ -2487,8 +2494,8 @@ infixexp :: { ECP } { ECP $ superInfixOp $ $2 >>= \ $2 -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> rejectPragmaPV $1 >> amms (mkHsOpAppPV (comb2 $1 $>) $1 $2 $3) [mj AnnVal $2] } @@ -2500,14 +2507,14 @@ exp10p :: { ECP } exp_prag(e) :: { ECP } : prag_e e -- See Note [Pragmas and operator fixity] - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsPragE noExtField (snd $ unLoc $1) $2) (fst $ unLoc $1) } exp10 :: { ECP } : '-' fexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsNegAppPV (comb2 $1 $>) $2) [mj AnnMinus $1] } | fexp { $1 } @@ -2590,16 +2597,16 @@ prag_e :: { Located ([AddAnn], HsPragE GhcPs) } fexp :: { ECP } : fexp aexp { ECP $ superFunArg $ - runECP_PV $1 >>= \ $1 -> - runECP_PV $2 >>= \ $2 -> + unECP $1 >>= \ $1 -> + unECP $2 >>= \ $2 -> mkHsAppPV (comb2 $1 $>) $1 $2 } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer | fexp PREFIX_AT atype { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> amms (mkHsAppTypePV (comb2 $1 $>) $1 $3) [mj AnnAt $2] } - | 'static' aexp {% runECP_P $2 >>= \ $2 -> + | 'static' aexp {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsStatic noExtField $2) [mj AnnStatic $1] } @@ -2609,23 +2616,23 @@ aexp :: { ECP } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer : qvar TIGHT_INFIX_AT aexp { ECP $ - runECP_PV $3 >>= \ $3 -> + unECP $3 >>= \ $3 -> amms (mkHsAsPatPV (comb2 $1 $>) $1 $3) [mj AnnAt $2] } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer | PREFIX_TILDE aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsLazyPatPV (comb2 $1 $>) $2) [mj AnnTilde $1] } | PREFIX_BANG aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsBangPatPV (comb2 $1 $>) $2) [mj AnnBang $1] } | PREFIX_MINUS aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsNegAppPV (comb2 $1 $>) $2) [mj AnnMinus $1] } | '\\' apat apats '->' exp { ECP $ - runECP_PV $5 >>= \ $5 -> + unECP $5 >>= \ $5 -> amms (mkHsLamPV (comb2 $1 $>) (mkMatchGroup FromSource [sLL $1 $> $ Match { m_ext = noExtField , m_ctxt = LambdaExpr @@ -2633,7 +2640,7 @@ aexp :: { ECP } , m_grhss = unguardedGRHSs $5 }])) [mj AnnLam $1, mu AnnRarrow $4] } | 'let' binds 'in' exp { ECP $ - runECP_PV $4 >>= \ $4 -> + unECP $4 >>= \ $4 -> amms (mkHsLetPV (comb2 $1 $>) (snd (unLoc $2)) $4) (mj AnnLet $1:mj AnnIn $3 :(fst $ unLoc $2)) } @@ -2643,10 +2650,10 @@ aexp :: { ECP } (mkMatchGroup FromSource (snd $ unLoc $3))) (mj AnnLam $1:mj AnnCase $2:(fst $ unLoc $3)) } | 'if' exp optSemi 'then' exp optSemi 'else' exp - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> return $ ECP $ - runECP_PV $5 >>= \ $5 -> - runECP_PV $8 >>= \ $8 -> + unECP $5 >>= \ $5 -> + unECP $8 >>= \ $8 -> amms (mkHsIfPV (comb2 $1 $>) $2 (snd $3) $5 (snd $6) $8) (mj AnnIf $1:mj AnnThen $4 :mj AnnElse $7 @@ -2657,7 +2664,7 @@ aexp :: { ECP } ams (sLL $1 $> $ HsMultiIf noExtField (reverse $ snd $ unLoc $2)) (mj AnnIf $1:(fst $ unLoc $2)) } - | 'case' exp 'of' altslist {% runECP_P $2 >>= \ $2 -> + | 'case' exp 'of' altslist {% runPV (unECP $2) >>= \ $2 -> return $ ECP $ $4 >>= \ $4 -> amms (mkHsCasePV (comb3 $1 $3 $4) $2 (mkMatchGroup @@ -2681,8 +2688,8 @@ aexp :: { ECP } (snd $ unLoc $2))) (mj AnnMdo $1:(fst $ unLoc $2)) } | 'proc' aexp '->' exp - {% (checkPattern <=< runECP_P) $2 >>= \ p -> - runECP_P $4 >>= \ $4 at cmd -> + {% (checkPattern <=< runPV) (unECP $2) >>= \ p -> + runPV (unECP $4) >>= \ $4 at cmd -> fmap ecpFromExp $ ams (sLL $1 $> $ HsProc noExtField p (sLL $1 $> $ HsCmdTop noExtField cmd)) -- TODO: is LL right here? @@ -2692,7 +2699,7 @@ aexp :: { ECP } aexp1 :: { ECP } : aexp1 '{' fbinds '}' { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> $3 >>= \ $3 -> amms (mkHsRecordPV (comb2 $1 $>) (comb2 $2 $4) $1 (snd $3)) (moc $2:mcc $4:(fst $3)) } @@ -2716,7 +2723,7 @@ aexp2 :: { ECP } -- correct Haskell (you'd have to write '((+ 3), (4 -))') -- but the less cluttered version fell out of having texps. | '(' texp ')' { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsParPV (comb2 $1 $>) $2) [mop $1,mcp $3] } | '(' tup_exprs ')' { ECP $ $2 >>= \ $2 -> @@ -2724,7 +2731,7 @@ aexp2 :: { ECP } ((mop $1:fst $2) ++ [mcp $3]) } | '(#' texp '#)' { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkSumOrTuplePV (comb2 $1 $>) Unboxed (Tuple [L (gl $2) (Just $2)])) [mo $1,mc $3] } | '(#' tup_exprs '#)' { ECP $ @@ -2744,18 +2751,18 @@ aexp2 :: { ECP } | TH_TY_QUOTE tyvar {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } | TH_TY_QUOTE gtycon {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } | TH_TY_QUOTE {- nothing -} {% reportEmptyDoubleQuotes (getLoc $1) } - | '[|' exp '|]' {% runECP_P $2 >>= \ $2 -> + | '[|' exp '|]' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (ExpBr noExtField $2)) (if (hasE $1) then [mj AnnOpenE $1, mu AnnCloseQ $3] else [mu AnnOpenEQ $1,mu AnnCloseQ $3]) } - | '[||' exp '||]' {% runECP_P $2 >>= \ $2 -> + | '[||' exp '||]' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (TExpBr noExtField $2)) (if (hasE $1) then [mj AnnOpenE $1,mc $3] else [mo $1,mc $3]) } | '[t|' ktype '|]' {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (TypBr noExtField $2)) [mo $1,mu AnnCloseQ $3] } - | '[p|' infixexp '|]' {% (checkPattern <=< runECP_P) $2 >>= \p -> + | '[p|' infixexp '|]' {% (checkPattern <=< runPV) (unECP $2) >>= \p -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (PatBr noExtField p)) [mo $1,mu AnnCloseQ $3] } @@ -2765,7 +2772,7 @@ aexp2 :: { ECP } | quasiquote { ECP $ mkHsSplicePV $1 } -- arrow notation extension - | '(|' aexp cmdargs '|)' {% runECP_P $2 >>= \ $2 -> + | '(|' aexp cmdargs '|)' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrForm noExtField $2 Prefix Nothing (reverse $3)) @@ -2777,14 +2784,14 @@ splice_exp :: { LHsExpr GhcPs } splice_untyped :: { Located (HsSplice GhcPs) } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer - : PREFIX_DOLLAR aexp2 {% runECP_P $2 >>= \ $2 -> + : PREFIX_DOLLAR aexp2 {% runPV (unECP $2) >>= \ $2 -> ams (sLL $1 $> $ mkUntypedSplice DollarSplice $2) [mj AnnDollar $1] } splice_typed :: { Located (HsSplice GhcPs) } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer : PREFIX_DOLLAR_DOLLAR aexp2 - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> ams (sLL $1 $> $ mkTypedSplice DollarSplice $2) [mj AnnDollarDollar $1] } @@ -2793,7 +2800,7 @@ cmdargs :: { [LHsCmdTop GhcPs] } | {- empty -} { [] } acmd :: { LHsCmdTop GhcPs } - : aexp {% runECP_P $1 >>= \ cmd -> + : aexp {% runPV (unECP $1) >>= \ cmd -> runPV (checkCmdBlockArguments cmd) >>= \ _ -> return (sL1 cmd $ HsCmdTop noExtField cmd) } @@ -2827,21 +2834,21 @@ texp :: { ECP } -- Meanwhile, the renamer checks that real sections appear -- inside parens. | infixexp qop - {% runECP_P $1 >>= \ $1 -> + {% runPV (unECP $1) >>= \ $1 -> runPV (rejectPragmaPV $1) >> runPV $2 >>= \ $2 -> return $ ecpFromExp $ sLL $1 $> $ SectionL noExtField $1 $2 } | qopm infixexp { ECP $ superInfixOp $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> $1 >>= \ $1 -> mkHsSectionR_PV (comb2 $1 $>) $1 $2 } -- View patterns get parenthesized above | exp '->' texp { ECP $ - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> amms (mkHsViewPatPV (comb2 $1 $>) $1 $3) [mu AnnRarrow $2] } -- Always at least one comma or bar. @@ -2850,12 +2857,12 @@ texp :: { ECP } -- in GHC.Hs.Expr. tup_exprs :: { forall b. DisambECP b => PV ([AddAnn],SumOrTuple b) } : texp commas_tup_tail - { runECP_PV $1 >>= \ $1 -> + { unECP $1 >>= \ $1 -> $2 >>= \ $2 -> do { addAnnotation (gl $1) AnnComma (fst $2) ; return ([],Tuple ((sL1 $1 (Just $1)) : snd $2)) } } - | texp bars { runECP_PV $1 >>= \ $1 -> return $ + | texp bars { unECP $1 >>= \ $1 -> return $ (mvbars (fst $2), Sum 1 (snd $2 + 1) $1) } | commas tup_tail @@ -2865,7 +2872,7 @@ tup_exprs :: { forall b. DisambECP b => PV ([AddAnn],SumOrTuple b) } ([],Tuple (map (\l -> L l Nothing) (fst $1) ++ $2)) } } | bars texp bars0 - { runECP_PV $2 >>= \ $2 -> return $ + { unECP $2 >>= \ $2 -> return $ (mvbars (fst $1) ++ mvbars (fst $3), Sum (snd $1 + 1) (snd $1 + snd $3 + 1) $2) } -- Always starts with commas; always follows an expr @@ -2879,11 +2886,11 @@ commas_tup_tail : commas tup_tail -- Always follows a comma tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] } - : texp commas_tup_tail { runECP_PV $1 >>= \ $1 -> + : texp commas_tup_tail { unECP $1 >>= \ $1 -> $2 >>= \ $2 -> addAnnotation (gl $1) AnnComma (fst $2) >> return ((L (gl $1) (Just $1)) : snd $2) } - | texp { runECP_PV $1 >>= \ $1 -> + | texp { unECP $1 >>= \ $1 -> return [L (gl $1) (Just $1)] } | {- empty -} { return [noLoc Nothing] } @@ -2894,48 +2901,48 @@ tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] } -- avoiding another shift/reduce-conflict. -- Never empty. list :: { forall b. DisambECP b => SrcSpan -> PV (Located b) } - : texp { \loc -> runECP_PV $1 >>= \ $1 -> + : texp { \loc -> unECP $1 >>= \ $1 -> mkHsExplicitListPV loc [$1] } | lexps { \loc -> $1 >>= \ $1 -> mkHsExplicitListPV loc (reverse $1) } - | texp '..' { \loc -> runECP_PV $1 >>= \ $1 -> + | texp '..' { \loc -> unECP $1 >>= \ $1 -> ams (L loc $ ArithSeq noExtField Nothing (From $1)) [mj AnnDotdot $2] >>= ecpFromExp' } | texp ',' exp '..' { \loc -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> ams (L loc $ ArithSeq noExtField Nothing (FromThen $1 $3)) [mj AnnComma $2,mj AnnDotdot $4] >>= ecpFromExp' } - | texp '..' exp { \loc -> runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + | texp '..' exp { \loc -> unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> ams (L loc $ ArithSeq noExtField Nothing (FromTo $1 $3)) [mj AnnDotdot $2] >>= ecpFromExp' } | texp ',' exp '..' exp { \loc -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> - runECP_PV $5 >>= \ $5 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> + unECP $5 >>= \ $5 -> ams (L loc $ ArithSeq noExtField Nothing (FromThenTo $1 $3 $5)) [mj AnnComma $2,mj AnnDotdot $4] >>= ecpFromExp' } | texp '|' flattenedpquals { \loc -> checkMonadComp >>= \ ctxt -> - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> ams (L loc $ mkHsComp ctxt (unLoc $3) $1) [mj AnnVbar $2] >>= ecpFromExp' } lexps :: { forall b. DisambECP b => PV [Located b] } : lexps ',' texp { $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $3 >>= \ $3 -> addAnnotation (gl $ head $ $1) AnnComma (gl $2) >> return (((:) $! $3) $! $1) } - | texp ',' texp { runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + | texp ',' texp { unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> addAnnotation (gl $1) AnnComma (gl $2) >> return [$3,$1] } @@ -2985,20 +2992,20 @@ squals :: { Located [LStmt GhcPs (LHsExpr GhcPs)] } -- In reverse order, becau transformqual :: { Located ([AddAnn],[LStmt GhcPs (LHsExpr GhcPs)] -> Stmt GhcPs (LHsExpr GhcPs)) } -- Function is applied to a list of stmts *in order* - : 'then' exp {% runECP_P $2 >>= \ $2 -> return $ + : 'then' exp {% runPV (unECP $2) >>= \ $2 -> return $ sLL $1 $> ([mj AnnThen $1], \ss -> (mkTransformStmt ss $2)) } - | 'then' exp 'by' exp {% runECP_P $2 >>= \ $2 -> - runECP_P $4 >>= \ $4 -> + | 'then' exp 'by' exp {% runPV (unECP $2) >>= \ $2 -> + runPV (unECP $4) >>= \ $4 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnBy $3], \ss -> (mkTransformByStmt ss $2 $4)) } | 'then' 'group' 'using' exp - {% runECP_P $4 >>= \ $4 -> + {% runPV (unECP $4) >>= \ $4 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnUsing $3], \ss -> (mkGroupUsingStmt ss $4)) } | 'then' 'group' 'by' exp 'using' exp - {% runECP_P $4 >>= \ $4 -> - runECP_P $6 >>= \ $6 -> + {% runPV (unECP $4) >>= \ $4 -> + runPV (unECP $6) >>= \ $6 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnBy $3,mj AnnUsing $5], \ss -> (mkGroupByUsingStmt ss $4 $6)) } @@ -3072,7 +3079,7 @@ alt_rhs :: { forall b. DisambECP b => PV (Located ([AddAnn],GRHSs GhcPs (Located return $ sLL alt $> (fst $ unLoc $2, GRHSs noExtField (unLoc alt) (snd $ unLoc $2)) } ralt :: { forall b. DisambECP b => PV (Located [LGRHS GhcPs (Located b)]) } - : '->' exp { runECP_PV $2 >>= \ $2 -> + : '->' exp { unECP $2 >>= \ $2 -> ams (sLL $1 $> (unguardedRHS (comb2 $1 $2) $2)) [mu AnnRarrow $1] } | gdpats { $1 >>= \gdpats -> @@ -3095,7 +3102,7 @@ ifgdpats :: { Located ([AddAnn],[LGRHS GhcPs (LHsExpr GhcPs)]) } gdpat :: { forall b. DisambECP b => PV (LGRHS GhcPs (Located b)) } : '|' guardquals '->' exp - { runECP_PV $4 >>= \ $4 -> + { unECP $4 >>= \ $4 -> ams (sL (comb2 $1 $>) $ GRHS noExtField (unLoc $2) $4) [mj AnnVbar $1,mu AnnRarrow $3] } @@ -3104,15 +3111,15 @@ gdpat :: { forall b. DisambECP b => PV (LGRHS GhcPs (Located b)) } -- Bangs inside are parsed as infix operator applications, so that -- we parse them right when bang-patterns are off pat :: { LPat GhcPs } -pat : exp {% (checkPattern <=< runECP_P) $1 } +pat : exp {% (checkPattern <=< runPV) (unECP $1) } bindpat :: { LPat GhcPs } -bindpat : exp {% -- See Note [Parser-Validator ReaderT SDoc] in GHC.Parser.PostProcess +bindpat : exp {% -- See Note [Parser-Validator Hint] in GHC.Parser.PostProcess checkPattern_msg (text "Possibly caused by a missing 'do'?") - (runECP_PV $1) } + (unECP $1) } apat :: { LPat GhcPs } -apat : aexp {% (checkPattern <=< runECP_P) $1 } +apat : aexp {% (checkPattern <=< runPV) (unECP $1) } apats :: { [LPat GhcPs] } : apat apats { $1 : $2 } @@ -3175,10 +3182,10 @@ stmt :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } (mj AnnRec $1:(fst $ unLoc $2)) } qual :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } - : bindpat '<-' exp { runECP_PV $3 >>= \ $3 -> + : bindpat '<-' exp { unECP $3 >>= \ $3 -> ams (sLL $1 $> $ mkPsBindStmt $1 $3) [mu AnnLarrow $2] } - | exp { runECP_PV $1 >>= \ $1 -> + | exp { unECP $1 >>= \ $1 -> return $ sL1 $1 $ mkBodyStmt $1 } | 'let' binds { ams (sLL $1 $> $ LetStmt noExtField (snd $ unLoc $2)) (mj AnnLet $1:(fst $ unLoc $2)) } @@ -3201,7 +3208,7 @@ fbinds1 :: { forall b. DisambECP b => PV ([AddAnn],([LHsRecField GhcPs (Located | '..' { return ([mj AnnDotdot $1],([], Just (getLoc $1))) } fbind :: { forall b. DisambECP b => PV (LHsRecField GhcPs (Located b)) } - : qvar '=' texp { runECP_PV $3 >>= \ $3 -> + : qvar '=' texp { unECP $3 >>= \ $3 -> ams (sLL $1 $> $ HsRecField (sL1 $1 $ mkFieldOcc $1) $3 False) [mj AnnEqual $2] } -- RHS is a 'texp', allowing view patterns (#6038) @@ -3227,7 +3234,7 @@ dbinds :: { Located [LIPBind GhcPs] } -- | {- empty -} { [] } dbind :: { LIPBind GhcPs } -dbind : ipvar '=' exp {% runECP_P $3 >>= \ $3 -> +dbind : ipvar '=' exp {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (IPBind noExtField (Left $1) $3)) [mj AnnEqual $2] } ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -68,7 +68,6 @@ module GHC.Parser.PostProcess ( checkRecordSyntax, checkEmptyGADTs, addFatalError, hintBangPat, - TyEl(..), mergeOps, mergeDataCon, mkBangTy, UnpackednessPragma(..), @@ -96,13 +95,19 @@ module GHC.Parser.PostProcess ( -- Expression/command/pattern ambiguity resolution PV, runPV, - ECP(ECP, runECP_PV), - runECP_P, + ECP(ECP, unECP), DisambInfixOp(..), DisambECP(..), ecpFromExp, ecpFromCmd, - PatBuilder + PatBuilder, + + -- Type/datacon ambiguity resolution + DisambTD(..), + addUnpackednessP, + DataConBuilder(), + dataConBuilderCon, + dataConBuilderDetails, ) where import GHC.Prelude @@ -126,20 +131,20 @@ import GHC.Types.ForeignCall import GHC.Builtin.Names ( allNameStrings ) import GHC.Types.SrcLoc import GHC.Types.Unique ( hasKey ) -import GHC.Data.OrdList ( OrdList, fromOL ) +import GHC.Data.OrdList import GHC.Utils.Outputable as Outputable import GHC.Data.FastString import GHC.Data.Maybe import GHC.Utils.Misc import GHC.Parser.Annotation import Data.List +import Data.Foldable import GHC.Driver.Session ( WarningFlag(..), DynFlags ) import GHC.Utils.Error ( Messages ) import Control.Monad import Text.ParserCombinators.ReadP as ReadP import Data.Char -import qualified Data.Monoid as Monoid import Data.Data ( dataTypeOf, fromConstr, dataTypeConstrs ) import Data.Kind ( Type ) @@ -559,30 +564,6 @@ context, so (C t1 t2) is a constraint and 'C' is a type constructor. As the result, in order to determine whether (C t1 t2) declares a data constructor, a type, or a context, we would need unlimited lookahead which 'happy' is not so happy with. - -The solution that accounts for all of these issues is to initially parse data -declarations and types as a reversed list of TyEl: - - data TyEl = TyElOpr RdrName - | TyElOpd (HsType GhcPs) - | ... - -For example, both occurrences of (C ! D) in the following example are parsed -into equal lists of TyEl: - - data T = C ! D => C ! D results in [ TyElOpd (HsTyVar "D") - , TyElOpr "!" - , TyElOpd (HsTyVar "C") ] - -Note that elements are in reverse order. Also, 'C' is parsed as a type -constructor (HsTyVar) even when it is a data constructor. We fix this in -`tyConToDataCon`. - -By the time the list of TyEl is assembled, we have looked ahead enough to -decide whether to reduce using `mergeOps` (for types) or `mergeDataCon` (for -data constructors). These functions are where the actual job of parsing is -done. - -} -- | Reinterpret a type constructor, including type operators, as a data @@ -798,7 +779,7 @@ to make setRdrNameSpace partial, so we just make an Unqual name instead. It really doesn't matter! -} -eitherToP :: Either (SrcSpan, SDoc) a -> P a +eitherToP :: MonadP m => Either (SrcSpan, SDoc) a -> m a -- Adapts the Either monad to the P monad eitherToP (Left (loc, doc)) = addFatalError loc doc eitherToP (Right thing) = return thing @@ -1309,323 +1290,31 @@ isFunLhs e = go e [] [] _ -> return Nothing } go _ _ _ = return Nothing --- | Either an operator or an operand. -data TyEl = TyElOpr RdrName | TyElOpd (HsType GhcPs) - | TyElKindApp SrcSpan (LHsType GhcPs) - -- See Note [TyElKindApp SrcSpan interpretation] - | TyElUnpackedness UnpackednessPragma - - -{- Note [TyElKindApp SrcSpan interpretation] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -A TyElKindApp captures type application written in haskell as - - @ Foo - -where Foo is some type. - -The SrcSpan reflects both elements, and there are AnnAt and AnnVal API -Annotations attached to this SrcSpan for the specific locations of -each within it. --} - -instance Outputable TyEl where - ppr (TyElOpr name) = ppr name - ppr (TyElOpd ty) = ppr ty - ppr (TyElKindApp _ ki) = text "@" <> ppr ki - ppr (TyElUnpackedness (UnpackednessPragma _ _ unpk)) = ppr unpk - --- | Extract a strictness/unpackedness annotation from the front of a reversed --- 'TyEl' list. -pUnpackedness - :: [Located TyEl] -- reversed TyEl - -> Maybe (SrcSpan, UnpackednessPragma, - [Located TyEl] {- remaining TyEl -}) -pUnpackedness (L l x1 : xs) | TyElUnpackedness up <- x1 = Just (l, up, xs) -pUnpackedness _ = Nothing - -pBangTy - :: LHsType GhcPs -- a type to be wrapped inside HsBangTy - -> [Located TyEl] -- reversed TyEl - -> ( Bool {- has a strict mark been consumed? -} - , LHsType GhcPs {- the resulting BangTy -} - , P () {- add annotations -} - , [Located TyEl] {- remaining TyEl -}) -pBangTy lt@(L l1 _) xs = - case pUnpackedness xs of - Nothing -> (False, lt, pure (), xs) - Just (l2, UnpackednessPragma anns prag unpk, xs') -> - let bl = combineSrcSpans l1 l2 - bt = addUnpackedness (prag, unpk) lt - in (True, L bl bt, addAnnsAt bl anns, xs') - mkBangTy :: SrcStrictness -> LHsType GhcPs -> HsType GhcPs mkBangTy strictness = HsBangTy noExtField (HsSrcBang NoSourceText NoSrcUnpack strictness) --- Result of parsing {-# UNPACK #-} or {-# NOUNPACK #-} +-- | Result of parsing @{-\# UNPACK \#-}@ or @{-\# NOUNPACK \#-}@. data UnpackednessPragma = UnpackednessPragma [AddAnn] SourceText SrcUnpackedness -addUnpackedness :: (SourceText, SrcUnpackedness) -> LHsType GhcPs -> HsType GhcPs -addUnpackedness (prag, unpk) (L _ (HsBangTy x bang t)) - | HsSrcBang NoSourceText NoSrcUnpack strictness <- bang - = HsBangTy x (HsSrcBang prag unpk strictness) t -addUnpackedness (prag, unpk) t - = HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t - --- | Merge a /reversed/ and /non-empty/ soup of operators and operands --- into a type. --- --- User input: @F x y + G a b * X@ --- Input to 'mergeOps': [X, *, b, a, G, +, y, x, F] --- Output corresponds to what the user wrote assuming all operators are of the --- same fixity and right-associative. --- --- It's a bit silly that we're doing it at all, as the renamer will have to --- rearrange this, and it'd be easier to keep things separate. --- --- See Note [Parsing data constructors is hard] -mergeOps :: [Located TyEl] -> P (LHsType GhcPs) -mergeOps ((L l1 (TyElOpd t)) : xs) - | (_, t', addAnns, xs') <- pBangTy (L l1 t) xs - , null xs' -- We accept a BangTy only when there are no preceding TyEl. - = addAnns >> return t' -mergeOps all_xs = go (0 :: Int) [] id all_xs - where - -- NB. When modifying clauses in 'go', make sure that the reasoning in - -- Note [Non-empty 'acc' in mergeOps clause [end]] is still correct. - - -- clause [unpk]: - -- handle (NO)UNPACK pragmas - go k acc ops_acc ((L l (TyElUnpackedness (UnpackednessPragma anns unpkSrc unpk))):xs) = - if not (null acc) && null xs - then do { acc' <- eitherToP $ mergeOpsAcc acc - ; let a = ops_acc acc' - strictMark = HsSrcBang unpkSrc unpk NoSrcStrict - bl = combineSrcSpans l (getLoc a) - bt = HsBangTy noExtField strictMark a - ; addAnnsAt bl anns - ; return (L bl bt) } - else addFatalError l unpkError - where - unpkSDoc = case unpkSrc of - NoSourceText -> ppr unpk - SourceText str -> text str <> text " #-}" - unpkError - | not (null xs) = unpkSDoc <+> text "cannot appear inside a type." - | null acc && k == 0 = unpkSDoc <+> text "must be applied to a type." - | otherwise = - -- See Note [Impossible case in mergeOps clause [unpk]] - panic "mergeOps.UNPACK: impossible position" - - -- clause [opr]: - -- when we encounter an operator, we must have accumulated - -- something for its rhs, and there must be something left - -- to build its lhs. - go k acc ops_acc ((L l (TyElOpr op)):xs) = - if null acc || null (filter isTyElOpd xs) - then failOpFewArgs (L l op) - else do { acc' <- eitherToP (mergeOpsAcc acc) - ; go (k + 1) [] (\c -> mkLHsOpTy c (L l op) (ops_acc acc')) xs } - where - isTyElOpd (L _ (TyElOpd _)) = True - isTyElOpd _ = False - - -- clause [opd]: - -- whenever an operand is encountered, it is added to the accumulator - go k acc ops_acc ((L l (TyElOpd a)):xs) = go k (HsValArg (L l a):acc) ops_acc xs - - -- clause [tyapp]: - -- whenever a type application is encountered, it is added to the accumulator - go k acc ops_acc ((L _ (TyElKindApp l a)):xs) = go k (HsTypeArg l a:acc) ops_acc xs - - -- clause [end] - -- See Note [Non-empty 'acc' in mergeOps clause [end]] - go _ acc ops_acc [] = do { acc' <- eitherToP (mergeOpsAcc acc) - ; return (ops_acc acc') } - -mergeOpsAcc :: [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> Either (SrcSpan, SDoc) (LHsType GhcPs) -mergeOpsAcc [] = panic "mergeOpsAcc: empty input" -mergeOpsAcc (HsTypeArg _ (L loc ki):_) - = Left (loc, text "Unexpected type application:" <+> ppr ki) -mergeOpsAcc (HsValArg ty : xs) = go1 ty xs - where - go1 :: LHsType GhcPs - -> [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> Either (SrcSpan, SDoc) (LHsType GhcPs) - go1 lhs [] = Right lhs - go1 lhs (x:xs) = case x of - HsValArg ty -> go1 (mkHsAppTy lhs ty) xs - HsTypeArg loc ki -> let ty = mkHsAppKindTy loc lhs ki - in go1 ty xs - HsArgPar _ -> go1 lhs xs -mergeOpsAcc (HsArgPar _: xs) = mergeOpsAcc xs - -{- Note [Impossible case in mergeOps clause [unpk]] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -This case should never occur. Let us consider all possible -variations of 'acc', 'xs', and 'k': - - acc xs k -============================== - null | null 0 -- "must be applied to a type" - null | not null 0 -- "must be applied to a type" -not null | null 0 -- successful parse -not null | not null 0 -- "cannot appear inside a type" - null | null >0 -- handled in clause [opr] - null | not null >0 -- "cannot appear inside a type" -not null | null >0 -- successful parse -not null | not null >0 -- "cannot appear inside a type" - -The (null acc && null xs && k>0) case is handled in clause [opr] -by the following check: - - if ... || null (filter isTyElOpd xs) - then failOpFewArgs (L l op) - -We know that this check has been performed because k>0, and by -the time we reach the end of the list (null xs), the only way -for (null acc) to hold is that there was not a single TyElOpd -between the operator and the end of the list. But this case is -caught by the check and reported as 'failOpFewArgs'. --} - -{- Note [Non-empty 'acc' in mergeOps clause [end]] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In clause [end] we need to know that 'acc' is non-empty to call 'mergeAcc' -without a check. - -Running 'mergeOps' with an empty input list is forbidden, so we do not consider -this possibility. This means we'll hit at least one other clause before we -reach clause [end]. - -* Clauses [unpk] and [doc] do not call 'go' recursively, so we cannot hit - clause [end] from there. -* Clause [opd] makes 'acc' non-empty, so if we hit clause [end] after it, 'acc' - will be non-empty. -* Clause [opr] checks that (filter isTyElOpd xs) is not null - so we are going - to hit clause [opd] at least once before we reach clause [end], making 'acc' - non-empty. -* There are no other clauses. - -Therefore, it is safe to omit a check for non-emptiness of 'acc' in clause -[end]. - --} - -pInfixSide :: [Located TyEl] -> Maybe (LHsType GhcPs, P (), [Located TyEl]) -pInfixSide ((L l (TyElOpd t)):xs) - | (True, t', addAnns, xs') <- pBangTy (L l t) xs - = Just (t', addAnns, xs') -pInfixSide (el:xs1) - | Just t1 <- pLHsTypeArg el - = go [t1] xs1 - where - go :: [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> [Located TyEl] -> Maybe (LHsType GhcPs, P (), [Located TyEl]) - go acc (el:xs) - | Just t <- pLHsTypeArg el - = go (t:acc) xs - go acc xs = case mergeOpsAcc acc of - Left _ -> Nothing - Right acc' -> Just (acc', pure (), xs) -pInfixSide _ = Nothing - -pLHsTypeArg :: Located TyEl -> Maybe (HsArg (LHsType GhcPs) (LHsKind GhcPs)) -pLHsTypeArg (L l (TyElOpd a)) = Just (HsValArg (L l a)) -pLHsTypeArg (L _ (TyElKindApp l a)) = Just (HsTypeArg l a) -pLHsTypeArg _ = Nothing - -orErr :: Maybe a -> b -> Either b a -orErr (Just a) _ = Right a -orErr Nothing b = Left b - --- | Merge a /reversed/ and /non-empty/ soup of operators and operands --- into a data constructor. --- --- User input: @C !A B -- ^ doc@ --- Input to 'mergeDataCon': ["doc", B, !A, C] --- Output: (C, PrefixCon [!A, B], "doc") --- --- See Note [Parsing data constructors is hard] -mergeDataCon - :: [Located TyEl] - -> P ( Located RdrName -- constructor name - , HsConDeclDetails GhcPs -- constructor field information - ) -mergeDataCon all_xs = - do { (addAnns, a) <- eitherToP res - ; addAnns - ; return a } +-- | Annotate a type with either an @{-\# UNPACK \#-}@ or a @{-\# NOUNPACK \#-}@ pragma. +addUnpackednessP :: MonadP m => Located UnpackednessPragma -> LHsType GhcPs -> m (LHsType GhcPs) +addUnpackednessP (L lprag (UnpackednessPragma anns prag unpk)) ty = do + let l' = combineSrcSpans lprag (getLoc ty) + t' = addUnpackedness ty + addAnnsAt l' anns + return (L l' t') where - -- The result of merging the list of reversed TyEl into a - -- data constructor, along with [AddAnn]. - res = goFirst all_xs - - goFirst [ L l (TyElOpd (HsTyVar _ _ (L _ tc))) ] - = do { data_con <- tyConToDataCon l tc - ; return (pure (), (data_con, PrefixCon [])) } - goFirst ((L l (TyElOpd (HsRecTy _ fields))):xs) - | [ L l' (TyElOpd (HsTyVar _ _ (L _ tc))) ] <- xs - = do { data_con <- tyConToDataCon l' tc - ; return (pure (), (data_con, RecCon (L l fields))) } - goFirst [L l (TyElOpd (HsTupleTy _ HsBoxedOrConstraintTuple ts))] - = return ( pure () - , ( L l (getRdrName (tupleDataCon Boxed (length ts))) - , PrefixCon (map hsLinear ts) ) ) - goFirst ((L l (TyElOpd t)):xs) - | (_, t', addAnns, xs') <- pBangTy (L l t) xs - = go addAnns [t'] xs' - goFirst (L l (TyElKindApp _ _):_) - = goInfix Monoid.<> Left (l, kindAppErr) - goFirst xs - = go (pure ()) [] xs - - go addAnns ts [ L l (TyElOpd (HsTyVar _ _ (L _ tc))) ] - = do { data_con <- tyConToDataCon l tc - ; return (addAnns, (data_con, PrefixCon (map hsLinear ts))) } - go addAnns ts ((L l (TyElOpd t)):xs) - | (_, t', addAnns', xs') <- pBangTy (L l t) xs - = go (addAnns >> addAnns') (t':ts) xs' - go _ _ ((L _ (TyElOpr _)):_) = - -- Encountered an operator: backtrack to the beginning and attempt - -- to parse as an infix definition. - goInfix - go _ _ (L l (TyElKindApp _ _):_) = goInfix Monoid.<> Left (l, kindAppErr) - go _ _ _ = Left malformedErr - where - malformedErr = - ( foldr combineSrcSpans noSrcSpan (map getLoc all_xs) - , text "Cannot parse data constructor" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs)) - - goInfix = - do { let xs0 = all_xs - ; (rhs, rhs_addAnns, xs1) <- pInfixSide xs0 `orErr` malformedErr - ; (op, xs3) <- case xs1 of - (L l (TyElOpr op)) : xs3 -> - do { data_con <- tyConToDataCon l op - ; return (data_con, xs3) } - _ -> Left malformedErr - ; (lhs, lhs_addAnns, xs5) <- pInfixSide xs3 `orErr` malformedErr - ; unless (null xs5) (Left malformedErr) - ; let addAnns = lhs_addAnns >> rhs_addAnns - ; return (addAnns, (op, InfixCon (hsLinear lhs) (hsLinear rhs))) } - where - malformedErr = - ( foldr combineSrcSpans noSrcSpan (map getLoc all_xs) - , text "Cannot parse an infix data constructor" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs)) - - kindAppErr = - text "Unexpected kind application" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs) + -- If we have a HsBangTy that only has a strictness annotation, + -- such as ~T or !T, then add the pragma to the existing HsBangTy. + -- + -- Otherwise, wrap the type in a new HsBangTy constructor. + addUnpackedness (L _ (HsBangTy x bang t)) + | HsSrcBang NoSourceText NoSrcUnpack strictness <- bang + = HsBangTy x (HsSrcBang prag unpk strictness) t + addUnpackedness t + = HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t --------------------------------------------------------------------------- -- | Check for monad comprehensions @@ -1645,7 +1334,6 @@ checkMonadComp = do -- See Note [Ambiguous syntactic categories] -- --- See Note [Parser-Validator] -- See Note [Ambiguous syntactic categories] -- -- This newtype is required to avoid impredicative types in monadic @@ -1659,10 +1347,7 @@ checkMonadComp = do -- P (forall b. DisambECP b => PV (Located b)) -- newtype ECP = - ECP { runECP_PV :: forall b. DisambECP b => PV (Located b) } - -runECP_P :: DisambECP b => ECP -> P (Located b) -runECP_P p = runPV (runECP_PV p) + ECP { unECP :: forall b. DisambECP b => PV (Located b) } ecpFromExp :: LHsExpr GhcPs -> ECP ecpFromExp a = ECP (ecpFromExp' a) @@ -2053,9 +1738,145 @@ mkPatRec (unLoc -> PatBuilderVar c) (HsRecFields fs dd) mkPatRec p _ = addFatalError (getLoc p) $ text "Not a record constructor:" <+> ppr p +-- | Disambiguate constructs that may appear when we do not know +-- ahead of time whether we are parsing a type or a newtype/data constructor. +-- +-- See Note [Ambiguous syntactic categories] for the general idea. +-- +-- See Note [Parsing data constructors is hard] for the specific issue this +-- particular class is solving. +-- +class DisambTD b where + -- | Process the head of a type-level function/constructor application, + -- i.e. the @H@ in @H a b c at . + mkHsAppTyHeadPV :: LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f x@ (function application or prefix data constructor). + mkHsAppTyPV :: Located b -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f \@t@ (visible kind application) + mkHsAppKindTyPV :: Located b -> SrcSpan -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f \# x@ (infix operator) + mkHsOpTyPV :: LHsType GhcPs -> Located RdrName -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @{-\# UNPACK \#-} t@ (unpack/nounpack pragma) + mkUnpackednessPV :: Located UnpackednessPragma -> Located b -> PV (Located b) + +instance DisambTD (HsType GhcPs) where + mkHsAppTyHeadPV = return + mkHsAppTyPV t1 t2 = return (mkHsAppTy t1 t2) + mkHsAppKindTyPV t l_at ki = return (mkHsAppKindTy l' t ki) + where l' = combineSrcSpans l_at (getLoc ki) + mkHsOpTyPV t1 op t2 = return (mkLHsOpTy t1 op t2) + mkUnpackednessPV = addUnpackednessP + +-- | An accumulator to build a prefix data constructor, +-- e.g. when parsing @MkT A B C@, the accumulator will evolve as follows: +-- +-- @ +-- 1. PrefixDataConBuilder [] MkT +-- 2. PrefixDataConBuilder [A] MkT +-- 3. PrefixDataConBuilder [A, B] MkT +-- 4. PrefixDataConBuilder [A, B, C] MkT +-- @ +-- +-- There are two reasons we have a separate builder type instead of using +-- @HsConDeclDetails GhcPs@ directly: +-- +-- 1. It's faster, because 'OrdList' gives us constant-time snoc. +-- 2. Having a separate type helps ensure that we don't forget to finalize a +-- 'RecTy' into a 'RecCon' (we do that in 'dataConBuilderDetails'). +-- +-- See Note [PatBuilder] for another builder type used in the parser. +-- Here the technique is similar, but the motivation is different. +data DataConBuilder + = PrefixDataConBuilder + (OrdList (LHsType GhcPs)) -- Data constructor fields + (Located RdrName) -- Data constructor name + | InfixDataConBuilder + (LHsType GhcPs) -- LHS field + (Located RdrName) -- Data constructor name + (LHsType GhcPs) -- RHS field + +dataConBuilderCon :: DataConBuilder -> Located RdrName +dataConBuilderCon (PrefixDataConBuilder _ dc) = dc +dataConBuilderCon (InfixDataConBuilder _ dc _) = dc + +dataConBuilderDetails :: DataConBuilder -> HsConDeclDetails GhcPs + +-- Detect when the record syntax is used: +-- data T = MkT { ... } +dataConBuilderDetails (PrefixDataConBuilder flds _) + | [L l_t (HsRecTy _ fields)] <- toList flds + = RecCon (L l_t fields) + +-- Normal prefix constructor, e.g. data T = MkT A B C +dataConBuilderDetails (PrefixDataConBuilder flds _) + = PrefixCon (map hsLinear (toList flds)) + +-- Infix constructor, e.g. data T = Int :! Bool +dataConBuilderDetails (InfixDataConBuilder lhs _ rhs) + = InfixCon (hsLinear lhs) (hsLinear rhs) + +instance Outputable DataConBuilder where + ppr (PrefixDataConBuilder flds data_con) = + hang (ppr data_con) 2 (sep (map ppr (toList flds))) + ppr (InfixDataConBuilder lhs data_con rhs) = + ppr lhs <+> ppr data_con <+> ppr rhs + +instance DisambTD DataConBuilder where + mkHsAppTyHeadPV = tyToDataConBuilder + + mkHsAppTyPV (L l (PrefixDataConBuilder flds fn)) t = + return $ + L (combineSrcSpans l (getLoc t)) + (PrefixDataConBuilder (flds `snocOL` t) fn) + mkHsAppTyPV (L _ InfixDataConBuilder{}) _ = + -- This case is impossible because of the way + -- the grammar in Parser.y is written (see infixtype/ftype). + panic "mkHsAppTyPV: InfixDataConBuilder" + + mkHsAppKindTyPV lhs l_at ki = + addFatalError l_at $ + hang (text "Unexpected kind application in a data/newtype declaration:") 2 + (ppr lhs <+> text "@" <> ppr ki) + + mkHsOpTyPV lhs (L l_tc tc) rhs = do + check_no_ops (unLoc rhs) -- check the RHS because parsing type operators is right-associative + data_con <- eitherToP $ tyConToDataCon l_tc tc + return $ L l (InfixDataConBuilder lhs data_con rhs) + where + l = combineLocs lhs rhs + check_no_ops (HsBangTy _ _ t) = check_no_ops (unLoc t) + check_no_ops (HsOpTy{}) = + addError l $ + hang (text "Cannot parse an infix data constructor in a data/newtype declaration:") + 2 (ppr lhs <+> ppr tc <+> ppr rhs) + check_no_ops _ = return () + + mkUnpackednessPV unpk constr_stuff + | L _ (InfixDataConBuilder lhs data_con rhs) <- constr_stuff + = -- When the user writes data T = {-# UNPACK #-} Int :+ Bool + -- we apply {-# UNPACK #-} to the LHS + do lhs' <- addUnpackednessP unpk lhs + let l = combineLocs unpk constr_stuff + return $ L l (InfixDataConBuilder lhs' data_con rhs) + | otherwise = + do addError (getLoc unpk) $ + text "{-# UNPACK #-} cannot be applied to a data constructor." + return constr_stuff + +tyToDataConBuilder :: LHsType GhcPs -> PV (Located DataConBuilder) +tyToDataConBuilder (L l (HsTyVar _ NotPromoted (L _ v))) = do + data_con <- eitherToP $ tyConToDataCon l v + return $ L l (PrefixDataConBuilder nilOL data_con) +tyToDataConBuilder (L l (HsTupleTy _ HsBoxedOrConstraintTuple ts)) = do + let data_con = L l (getRdrName (tupleDataCon Boxed (length ts))) + return $ L l (PrefixDataConBuilder (toOL ts) data_con) +tyToDataConBuilder t = + addFatalError (getLoc t) $ + hang (text "Cannot parse data constructor in a data/newtype declaration:") + 2 (ppr t) + {- Note [Ambiguous syntactic categories] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - There are places in the grammar where we do not know whether we are parsing an expression or a pattern without unlimited lookahead (which we do not have in 'happy'): @@ -2150,6 +1971,21 @@ position and shadows the previous $1. We can do this because internally is to be able to write (sLL $1 $>) later on. The alternative would be to write this as ($1 >>= \ fresh_name -> ...), but then we couldn't refer to the last fresh name as $>. + +Finally, we instantiate the polymorphic type to a concrete one, and run the +parser-validator, for example: + + stmt :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } + e_stmt :: { LStmt GhcPs (LHsExpr GhcPs) } + : stmt {% runPV $1 } + +In e_stmt, three things happen: + + 1. we instantiate: b ~ HsExpr GhcPs + 2. we embed the PV computation into P by using runPV + 3. we run validation by using a monadic production, {% ... } + +At this point the ambiguity is resolved. -} @@ -2306,7 +2142,6 @@ Alternative VII, a product type We could avoid the intermediate representation of Alternative VI by parsing into a product of interpretations directly: - -- See Note [Parser-Validator] type ExpCmdPat = ( PV (LHsExpr GhcPs) , PV (LHsCmd GhcPs) , PV (LHsPat GhcPs) ) @@ -2326,7 +2161,6 @@ We can easily define ambiguities between arbitrary subsets of interpretations. For example, when we know ahead of type that only an expression or a command is possible, but not a pattern, we can use a smaller type: - -- See Note [Parser-Validator] type ExpCmd = (PV (LHsExpr GhcPs), PV (LHsCmd GhcPs)) checkExpOf2 (e, _) = e -- interpret as an expression @@ -2809,7 +2643,7 @@ warnStarBndr span = addWarning Opt_WarnStarBinder span msg <+> text "modules with StarIsType," $$ text " including the definition module, you must qualify it." -failOpFewArgs :: Located RdrName -> P a +failOpFewArgs :: MonadP m => Located RdrName -> m a failOpFewArgs (L loc op) = do { star_is_type <- getBit StarIsTypeBit ; let msg = too_few $$ starInfo star_is_type op @@ -2836,7 +2670,25 @@ data PV_Accum = data PV_Result a = PV_Ok PV_Accum a | PV_Failed PV_Accum --- See Note [Parser-Validator] +-- During parsing, we make use of several monadic effects: reporting parse errors, +-- accumulating warnings, adding API annotations, and checking for extensions. These +-- effects are captured by the 'MonadP' type class. +-- +-- Sometimes we need to postpone some of these effects to a later stage due to +-- ambiguities described in Note [Ambiguous syntactic categories]. +-- We could use two layers of the P monad, one for each stage: +-- +-- abParser :: forall x. DisambAB x => P (P x) +-- +-- The outer layer of P consumes the input and builds the inner layer, which +-- validates the input. But this type is not particularly helpful, as it obscures +-- the fact that the inner layer of P never consumes any input. +-- +-- For clarity, we introduce the notion of a parser-validator: a parser that does +-- not consume any input, but may fail or use other effects. Thus we have: +-- +-- abParser :: forall x. DisambAB x => P (PV x) +-- newtype PV a = PV { unPV :: PV_Context -> PV_Accum -> PV_Result a } instance Functor PV where @@ -2910,36 +2762,6 @@ instance MonadP PV where PV_Ok acc' () addAnnotation _ _ _ = return () -{- Note [Parser-Validator] -~~~~~~~~~~~~~~~~~~~~~~~~~~ - -When resolving ambiguities, we need to postpone failure to make a choice later. -For example, if we have ambiguity between some A and B, our parser could be - - abParser :: P (Maybe A, Maybe B) - -This way we can represent four possible outcomes of parsing: - - (Just a, Nothing) -- definitely A - (Nothing, Just b) -- definitely B - (Just a, Just b) -- either A or B - (Nothing, Nothing) -- neither A nor B - -However, if we want to report informative parse errors, accumulate warnings, -and add API annotations, we are better off using 'P' instead of 'Maybe': - - abParser :: P (P A, P B) - -So we have an outer layer of P that consumes the input and builds the inner -layer, which validates the input. - -For clarity, we introduce the notion of a parser-validator: a parser that does -not consume any input, but may fail or use other effects. Thus we have: - - abParser :: P (PV A, PV B) - --} - {- Note [Parser-Validator Hint] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A PV computation is parametrized by a hint for error messages, which can be set ===================================== compiler/GHC/Platform/Profile.hs ===================================== @@ -13,8 +13,6 @@ import GHC.Prelude import GHC.Platform import GHC.Platform.Ways -import Data.Set - -- | A platform profile fully describes the kind of objects that are generated -- for a platform. -- @@ -22,8 +20,8 @@ import Data.Set -- (profiling, debug, dynamic) also modify the ABI. -- data Profile = Profile - { profilePlatform :: !Platform -- ^ Platform - , profileWays :: !(Set Way) -- ^ Ways + { profilePlatform :: !Platform -- ^ Platform + , profileWays :: !Ways -- ^ Ways } -- | Get platform constants ===================================== compiler/GHC/Platform/Ways.hs ===================================== @@ -20,6 +20,7 @@ -- this compilation. module GHC.Platform.Ways ( Way(..) + , Ways , hasWay , allowed_combination , wayGeneralFlags @@ -61,12 +62,14 @@ data Way | WayDyn -- ^ Dynamic linking deriving (Eq, Ord, Show) +type Ways = Set Way + -- | Test if a ways is enabled -hasWay :: Set Way -> Way -> Bool +hasWay :: Ways -> Way -> Bool hasWay ws w = Set.member w ws -- | Check if a combination of ways is allowed -allowed_combination :: Set Way -> Bool +allowed_combination :: Ways -> Bool allowed_combination ways = not disallowed where disallowed = or [ hasWay ways x && hasWay ways y @@ -76,13 +79,13 @@ allowed_combination ways = not disallowed couples = [] -- we don't have any disallowed combination of ways nowadays -- | Unique tag associated to a list of ways -waysTag :: Set Way -> String +waysTag :: Ways -> String waysTag = concat . intersperse "_" . map wayTag . Set.toAscList -- | Unique build-tag associated to a list of ways -- -- RTS only ways are filtered out because they have no impact on the build. -waysBuildTag :: Set Way -> String +waysBuildTag :: Ways -> String waysBuildTag ws = waysTag (Set.filter (not . wayRTSOnly) ws) @@ -195,7 +198,7 @@ foreign import ccall unsafe "rts_isDynamic" rtsIsDynamicIO :: IO Int -- | Return host "full" ways (i.e. ways that have an impact on the compilation, -- not RTS only ways). These ways must be used when compiling codes targeting -- the internal interpreter. -hostFullWays :: Set Way +hostFullWays :: Ways hostFullWays = Set.unions [ if hostIsDynamic then Set.singleton WayDyn else Set.empty , if hostIsProfiled then Set.singleton WayProf else Set.empty ===================================== compiler/GHC/Tc/TyCl.hs ===================================== @@ -74,7 +74,6 @@ import GHC.Types.SrcLoc import GHC.Data.List.SetOps import GHC.Driver.Session import GHC.Types.Unique -import GHC.Core.ConLike( ConLike(..) ) import GHC.Types.Basic import qualified GHC.LanguageExtensions as LangExt @@ -3819,15 +3818,14 @@ checkValidTyCl tc where recovery_code -- See Note [Recover from validity error] = do { traceTc "Aborted validity for tycon" (ppr tc) - ; return (concatMap mk_fake_tc $ - ATyCon tc : implicitTyConThings tc) } + ; return (map mk_fake_tc $ + tc : child_tycons tc) } - mk_fake_tc (ATyCon tc) - | isClassTyCon tc = [tc] -- Ugh! Note [Recover from validity error] - | otherwise = [makeRecoveryTyCon tc] - mk_fake_tc (AConLike (RealDataCon dc)) - = [makeRecoveryTyCon (promoteDataCon dc)] - mk_fake_tc _ = [] + mk_fake_tc tc + | isClassTyCon tc = tc -- Ugh! Note [Recover from validity error] + | otherwise = makeRecoveryTyCon tc + + child_tycons tc = tyConATs tc ++ map promoteDataCon (tyConDataCons tc) {- Note [Recover from validity error] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -3852,6 +3850,8 @@ Some notes: and so there was an internal error when we met 'MkT' in the body of 'S'. + Similarly for associated types. + * Painfully, we *don't* want to do this for classes. Consider tcfail041: class (?x::Int) => C a where ... @@ -3864,6 +3864,14 @@ Some notes: This is really bogus; now we have in scope a Class that is invalid in some way, with unknown downstream consequences. A better alternative might be to make a fake class TyCon. A job for another day. + +* Previously, we used implicitTyConThings to snaffle out the parts + to add to the context. The problem is that this also grabs data con + wrapper Ids. These could be filtered out. But, painfully, getting + the wrapper Ids checks the DataConRep, and forcing the DataConRep + can panic if there is a levity-polymorphic argument. This is #18534. + We don't need the wrapper Ids here anyway. So the code just takes what + it needs, via child_tycons. -} ------------------------- @@ -4050,8 +4058,13 @@ checkValidDataCon dflags existential_ok tc con -- regardless of whether or not UnliftedNewtypes is enabled. A -- later check in checkNewDataCon handles this, producing a -- better error message than checkForLevPoly would. - ; unless (isNewTyCon tc) - (mapM_ (checkForLevPoly empty) (map scaledThing $ dataConOrigArgTys con)) + ; unless (isNewTyCon tc) $ + checkNoErrs $ + mapM_ (checkForLevPoly empty) (map scaledThing $ dataConOrigArgTys con) + -- the checkNoErrs is to prevent a panic in isVanillaDataCon + -- (called a a few lines down), which can fall over if there is a + -- bang on a levity-polymorphic argument. This is #18534, + -- typecheck/should_fail/T18534 -- Extra checks for newtype data constructors. Importantly, these -- checks /must/ come before the call to checkValidType below. This ===================================== compiler/GHC/Unit/State.hs ===================================== @@ -315,7 +315,7 @@ instance Monoid UnitVisibility where -- | Unit configuration data UnitConfig = UnitConfig { unitConfigPlatformArchOS :: !ArchOS -- ^ Platform arch and OS - , unitConfigWays :: !(Set Way) -- ^ Ways to use + , unitConfigWays :: !Ways -- ^ Ways to use , unitConfigProgramName :: !String -- ^ Name of the compiler (e.g. "GHC", "GHCJS"). Used to fetch environment -- variables such as "GHC[JS]_PACKAGE_PATH". ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.hs ===================================== @@ -0,0 +1,50 @@ +{-# LANGUAGE TemplateHaskell, ExplicitForAll, PolyKinds #-} + +module Main where + +import Language.Haskell.TH (runQ) +import GHC.Types.Basic +import GHC.ThToHs +import GHC.Driver.Session +import GHC.Core.TyCo.Ppr +import GHC.Utils.Outputable +import GHC.Tc.Module +import GHC.Tc.Utils.Zonk +import GHC.Utils.Error +import GHC.Driver.Types +import GHC +import qualified GHC.LanguageExtensions as LangExt + +import Data.Either (fromRight) +import Control.Monad.IO.Class (liftIO) +import System.Environment (getArgs) + +main :: IO () +main = do + [libdir] <- getArgs + runGhc (Just libdir) $ do + initial_dflags <- getSessionDynFlags + setSessionDynFlags $ initial_dflags + `dopt_set` Opt_D_ppr_debug + `gopt_set` Opt_SuppressUniques + `gopt_set` Opt_SuppressModulePrefixes + `gopt_set` Opt_SuppressVarKinds + `xopt_set` LangExt.KindSignatures + `xopt_set` LangExt.PolyKinds + `xopt_set` LangExt.RankNTypes + hsc_env <- getSession + let dflags = hsc_dflags hsc_env + liftIO $ do + th_t <- runQ [t| forall k {j}. + forall (a :: k) (b :: j) -> + () |] + let hs_t = fromRight (error "convertToHsType") $ + convertToHsType Generated noSrcSpan th_t + ((warnings, errors), mres) <- + tcRnType hsc_env SkolemiseFlexi True hs_t + case mres of + Nothing -> do + printBagOfErrors dflags warnings + printBagOfErrors dflags errors + Just (t, _) -> do + putStrLn $ showSDoc dflags (debugPprType t) ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.stdout ===================================== @@ -0,0 +1,2 @@ +forall k{tv}[tv] {j{tv}[tv]}. +forall a{tv}[tv] b{tv}[tv] -> (){(w) tc} ===================================== testsuite/tests/ghc-api/all.T ===================================== @@ -20,3 +20,7 @@ test('T9015', extra_run_opts('"' + config.libdir + '"'), test('T11579', extra_run_opts('"' + config.libdir + '"'), compile_and_run, ['-package ghc']) test('T12099', normal, compile_and_run, ['-package ghc']) +test('T18522-dbg-ppr', + extra_run_opts('"' + config.libdir + '"'), + compile_and_run, + ['-package ghc']) ===================================== testsuite/tests/parser/should_fail/T12045d.stderr ===================================== @@ -1,4 +1,3 @@ T12045d.hs:11:16: error: - Unexpected kind application in a data/newtype declaration: - MkD @Nat Bool + Unexpected kind application in a data/newtype declaration: MkD @Nat ===================================== testsuite/tests/parser/should_fail/strictnessDataCon_B.stderr ===================================== @@ -1,3 +1,2 @@ -strictnessDataCon_B.hs:1:27: error: - {-# UNPACK #-} cannot appear inside a type. +strictnessDataCon_B.hs:1:42: error: parse error on input ‘}’ ===================================== testsuite/tests/parser/should_fail/typeops_A.stderr ===================================== @@ -1,2 +1,3 @@ -typeops_A.hs:1:12: error: Operator applied to too few arguments: + +typeops_A.hs:2:1: error: + parse error (possibly incorrect indentation or mismatched brackets) ===================================== testsuite/tests/parser/should_fail/typeops_C.stderr ===================================== @@ -1,2 +1,2 @@ -typeops_C.hs:1:12: error: Operator applied to too few arguments: + +typeops_C.hs:1:14: error: Operator applied to too few arguments: + ===================================== testsuite/tests/parser/should_fail/unpack_empty_type.stderr ===================================== @@ -1,3 +1,2 @@ -unpack_empty_type.hs:3:19: error: - {-# UNPACK #-} must be applied to a type. +unpack_empty_type.hs:3:34: error: parse error on input ‘}’ ===================================== testsuite/tests/parser/should_fail/unpack_inside_type.stderr ===================================== @@ -1,3 +1,7 @@ unpack_inside_type.hs:3:25: error: - {-# UNPACK #-} cannot appear inside a type. + • Unexpected UNPACK annotation: {-# UNPACK #-}Int + UNPACK annotation cannot appear nested inside a type + • In the first argument of ‘Maybe’, namely ‘({-# UNPACK #-}Int)’ + In the type ‘Maybe ({-# UNPACK #-}Int)’ + In the definition of data constructor ‘T’ ===================================== testsuite/tests/polykinds/T18522-ppr.script ===================================== @@ -0,0 +1,4 @@ +:set -XPolyKinds -XDataKinds -XRankNTypes -XTypeFamilies +import Data.Kind (Type) +type family T :: forall k -> (k ~ k) => forall j -> k -> j -> Type +:k T ===================================== testsuite/tests/polykinds/T18522-ppr.stdout ===================================== @@ -0,0 +1 @@ +T :: forall k -> (k ~ k) => forall j -> k -> j -> * ===================================== testsuite/tests/polykinds/all.T ===================================== @@ -223,3 +223,4 @@ test('T18300', normal, compile_fail, ['']) test('T18451', normal, compile_fail, ['']) test('T18451a', normal, compile_fail, ['']) test('T18451b', normal, compile_fail, ['']) +test('T18522-ppr', normal, ghci_script, ['T18522-ppr.script']) ===================================== testsuite/tests/typecheck/should_fail/T18534.hs ===================================== @@ -0,0 +1,7 @@ +{-# LANGUAGE PolyKinds #-} + +module Test where + +import GHC.Exts + +data Test (a :: TYPE r) = Test !a ===================================== testsuite/tests/typecheck/should_fail/T18534.stderr ===================================== @@ -0,0 +1,7 @@ + +T18534.hs:7:27: error: + • A levity-polymorphic type is not allowed here: + Type: a + Kind: TYPE r + • In the definition of data constructor ‘Test’ + In the data type declaration for ‘Test’ ===================================== testsuite/tests/typecheck/should_fail/all.T ===================================== @@ -578,3 +578,4 @@ test('T18357', normal, compile_fail, ['']) test('T18357a', normal, compile_fail, ['']) test('T18357b', normal, compile_fail, ['']) test('T18455', normal, compile_fail, ['']) +test('T18534', normal, compile_fail, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/829f48c0181168c8012eb976135746a473878ec6...54d6387a65b6ca1b1d32891b697ec368fbb38eb3 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/829f48c0181168c8012eb976135746a473878ec6...54d6387a65b6ca1b1d32891b697ec368fbb38eb3 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 12:35:38 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Thu, 06 Aug 2020 08:35:38 -0400 Subject: [Git][ghc/ghc][wip/az/anns-1] ApiAnnotations; tweaks for ghc-exactprint update Message-ID: <5f2bf91a30f4d_80b3f8468e02b546816376@gitlab.haskell.org.mail> Alan Zimmerman pushed to branch wip/az/anns-1 at Glasgow Haskell Compiler / GHC Commits: 40d366d1 by Alan Zimmerman at 2020-08-06T13:34:01+01:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 4 changed files: - compiler/GHC.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Annotation.hs - utils/check-api-annotations/Main.hs Changes: ===================================== compiler/GHC.hs ===================================== @@ -248,7 +248,7 @@ module GHC ( srcSpanStartCol, srcSpanEndCol, -- ** Located - GenLocated(..), Located, + GenLocated(..), Located, RealLocated, -- *** Constructing Located noLoc, mkGeneralLocated, @@ -274,7 +274,7 @@ module GHC ( parser, -- * API Annotations - ApiAnns(..),AnnKeywordId(..),AnnotationComment(..), + ApiAnns(..),AnnKeywordId(..),AnnotationComment(..), ApiAnnKey, getAnnotation, getAndRemoveAnnotation, getAnnotationComments, getAndRemoveAnnotationComments, unicodeAnn, ===================================== compiler/GHC/Parser.y ===================================== @@ -863,17 +863,17 @@ header_top_importdecls :: { [LImportDecl GhcPs] } -- The Export List maybeexports :: { (Maybe (Located [LIE GhcPs])) } - : '(' exportlist ')' {% amsL (comb2 $1 $>) [mop $1,mcp $3] >> - return (Just (sLL $1 $> (fromOL $2))) } + : '(' exportlist ')' {% amsL (comb2 $1 $>) ([mop $1,mcp $3] ++ (fst $2)) >> + return (Just (sLL $1 $> (fromOL $ snd $2))) } | {- empty -} { Nothing } -exportlist :: { OrdList (LIE GhcPs) } - : exportlist1 { $1 } - | {- empty -} { nilOL } +exportlist :: { ([AddAnn], OrdList (LIE GhcPs)) } + : exportlist1 { ([], $1) } + | {- empty -} { ([], nilOL) } -- trailing comma: - | exportlist1 ',' { $1 } - | ',' { nilOL } + | exportlist1 ',' { ([mj AnnComma $2], $1) } + | ',' { ([mj AnnComma $1], nilOL) } exportlist1 :: { OrdList (LIE GhcPs) } : exportlist1 ',' export @@ -1019,11 +1019,11 @@ maybeimpspec :: { Located (Maybe (Bool, Located [LIE GhcPs])) } impspec :: { Located (Bool, Located [LIE GhcPs]) } : '(' exportlist ')' {% ams (sLL $1 $> (False, - sLL $1 $> $ fromOL $2)) - [mop $1,mcp $3] } + sLL $1 $> $ fromOL (snd $2))) + ([mop $1,mcp $3] ++ (fst $2)) } | 'hiding' '(' exportlist ')' {% ams (sLL $1 $> (True, - sLL $1 $> $ fromOL $3)) - [mj AnnHiding $1,mop $2,mcp $4] } + sLL $1 $> $ fromOL (snd $3))) + ([mj AnnHiding $1,mop $2,mcp $4] ++ (fst $3)) } ----------------------------------------------------------------------------- -- Fixity Declarations ===================================== compiler/GHC/Parser/Annotation.hs ===================================== @@ -259,6 +259,8 @@ data AnnKeywordId | AnnLarrow -- ^ '<-' | AnnLarrowU -- ^ '<-', unicode variant | AnnLet + | AnnLolly -- ^ '#->' + | AnnLollyU -- ^ '#->', unicode variant | AnnMdo | AnnMinus -- ^ '-' | AnnModule @@ -291,8 +293,6 @@ data AnnKeywordId | AnnStatic -- ^ 'static' | AnnStock | AnnThen - | AnnThIdSplice -- ^ '$' - | AnnThIdTySplice -- ^ '$$' | AnnThTyQuote -- ^ double ''' | AnnTilde -- ^ '~' | AnnType @@ -364,6 +364,7 @@ unicodeAnn AnnOpenB = AnnOpenBU unicodeAnn AnnCloseB = AnnCloseBU unicodeAnn AnnOpenEQ = AnnOpenEQU unicodeAnn AnnCloseQ = AnnCloseQU +unicodeAnn AnnLolly = AnnLollyU unicodeAnn ann = ann ===================================== utils/check-api-annotations/Main.hs ===================================== @@ -5,7 +5,6 @@ import Data.List import GHC import GHC.Driver.Session import GHC.Utils.Outputable -import GHC.Parser.Annotation import GHC.Types.SrcLoc import System.Environment( getArgs ) import System.Exit View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/40d366d17d358866e3900170ac9b2e7dcc3530be -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/40d366d17d358866e3900170ac9b2e7dcc3530be You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 12:54:58 2020 From: gitlab at gitlab.haskell.org (Ryan Scott) Date: Thu, 06 Aug 2020 08:54:58 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T16762 Message-ID: <5f2bfda2b950f_80b8ca3ed0681921d@gitlab.haskell.org.mail> Ryan Scott pushed new branch wip/T16762 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T16762 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 14:30:45 2020 From: gitlab at gitlab.haskell.org (Josh Meredith) Date: Thu, 06 Aug 2020 10:30:45 -0400 Subject: [Git][ghc/ghc][wip/pluginExtFields] 11 commits: hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. Message-ID: <5f2c141582836_80b10e6f9b468210c5@gitlab.haskell.org.mail> Josh Meredith pushed to branch wip/pluginExtFields at Glasgow Haskell Compiler / GHC Commits: 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 9e23e7db by Josh Meredith at 2020-08-06T10:30:42-04:00 Add machinery for plugins to write data to extensible interface fields - - - - - 189951d4 by Josh Meredith at 2020-08-06T10:30:42-04:00 Add function to remove plugin interface fields - - - - - 30 changed files: - aclocal.m4 - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Driver/CodeOutput.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/IfaceToCore.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/Tasks.hs - compiler/ghc.cabal.in - configure.ac - distrib/configure.ac.in - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Builder.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Rules/Library.hs - hadrian/src/Settings/Builders/Cabal.hs - hadrian/src/Settings/Builders/Ld.hs - + hadrian/src/Settings/Builders/MergeObjects.hs - hadrian/src/Settings/Default.hs - includes/ghc.mk - libraries/base/.hlint.yaml - libraries/base/Control/Concurrent/QSemN.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0b051156b11c2440b81b6c933541d199b5b3d591...189951d4f51d678a18443931a77ff1fce4be067d -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0b051156b11c2440b81b6c933541d199b5b3d591...189951d4f51d678a18443931a77ff1fce4be067d You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 15:30:14 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 11:30:14 -0400 Subject: [Git][ghc/ghc][wip/T18527] 4 commits: CmmLint: Check foreign call argument register invariant Message-ID: <5f2c220650538_80b3f849c1caa1068242bd@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18527 at Glasgow Haskell Compiler / GHC Commits: dc54647c by Ben Gamari at 2020-08-06T11:30:03-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 339a7909 by Ben Gamari at 2020-08-06T11:30:04-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - eb9ad8a1 by Ben Gamari at 2020-08-06T11:30:04-04:00 testsuite: Add test fo #18527 - - - - - 2e68f1bd by Ben Gamari at 2020-08-06T11:30:04-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - 7 changed files: - compiler/GHC/Cmm/Lint.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - + testsuite/tests/codeGen/should_run/T18527.hs - + testsuite/tests/codeGen/should_run/T18527.stdout - + testsuite/tests/codeGen/should_run/T18527FFI.c - testsuite/tests/codeGen/should_run/all.T - testsuite/tests/concurrent/prog001/all.T Changes: ===================================== compiler/GHC/Cmm/Lint.hs ===================================== @@ -6,6 +6,7 @@ -- ----------------------------------------------------------------------------- {-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} module GHC.Cmm.Lint ( cmmLint, cmmLintGraph @@ -14,6 +15,7 @@ module GHC.Cmm.Lint ( import GHC.Prelude import GHC.Platform +import GHC.Platform.Regs (callerSaves) import GHC.Cmm.Dataflow.Block import GHC.Cmm.Dataflow.Collections import GHC.Cmm.Dataflow.Graph @@ -26,7 +28,7 @@ import GHC.Cmm.Ppr () -- For Outputable instances import GHC.Utils.Outputable import GHC.Driver.Session -import Control.Monad (ap) +import Control.Monad (ap, unless) -- Things to check: -- - invariant on CmmBlock in GHC.Cmm.Expr (see comment there) @@ -160,7 +162,13 @@ lintCmmMiddle node = case node of CmmUnsafeForeignCall target _formals actuals -> do lintTarget target - mapM_ lintCmmExpr actuals + let lintArg expr = do + -- Arguments can't mention caller-saved + -- registers. See Note [Register parameter passing]. + mayNotMentionCallerSavedRegs (text "foreign call argument") expr + lintCmmExpr expr + + mapM_ lintArg actuals lintCmmLast :: LabelSet -> CmmNode O C -> CmmLint () @@ -188,18 +196,40 @@ lintCmmLast labels node = case node of CmmForeignCall tgt _ args succ _ _ _ -> do lintTarget tgt - mapM_ lintCmmExpr args + let lintArg expr = do + -- Arguments can't mention caller-saved + -- registers. See Note [Register + -- parameter passing]. + -- N.B. This won't catch local registers + -- which the NCG's register allocator later + -- places in caller-saved registers. + mayNotMentionCallerSavedRegs (text "foreign call argument") expr + lintCmmExpr expr + mapM_ lintArg args checkTarget succ where checkTarget id | setMember id labels = return () | otherwise = cmmLintErr (text "Branch to nonexistent id" <+> ppr id) - lintTarget :: ForeignTarget -> CmmLint () -lintTarget (ForeignTarget e _) = lintCmmExpr e >> return () +lintTarget (ForeignTarget e _) = do + mayNotMentionCallerSavedRegs (text "foreign target") e + _ <- lintCmmExpr e + return () lintTarget (PrimTarget {}) = return () +-- | As noted in Note [Register parameter passing], the arguments and +-- 'ForeignTarget' of a foreign call mustn't mention +-- caller-saved registers. +mayNotMentionCallerSavedRegs :: (UserOfRegs GlobalReg a, Outputable a) + => SDoc -> a -> CmmLint () +mayNotMentionCallerSavedRegs what thing = do + dflags <- getDynFlags + let badRegs = filter (callerSaves (targetPlatform dflags)) + $ foldRegsUsed dflags (flip (:)) [] thing + unless (null badRegs) + $ cmmLintErr (what <+> text "mentions caller-saved registers: " <> ppr badRegs $$ ppr thing) checkCond :: Platform -> CmmExpr -> CmmLint () checkCond _ (CmmMachOp mop _) | isComparisonMachOp mop = return () ===================================== compiler/GHC/CmmToAsm/X86/CodeGen.hs ===================================== @@ -1028,6 +1028,9 @@ getRegister' _ is32Bit (CmmMachOp mop [x, y]) = do -- dyadic MachOps tmp. This is likely to be better, because the reg alloc can eliminate this reg->reg move here (it won't eliminate the other one, because the move is into the fixed %ecx). + * in the case of C calls the use of ecx here can interfere with arguments. + We avoid this with the hack described in Note [Evaluate C-call + arguments before placing in destination registers] -} shift_code width instr x y{-amount-} = do x_code <- getAnyReg x @@ -2022,6 +2025,7 @@ genCCall is32Bit (PrimTarget (MO_AtomicRMW width amop)) arg <- getNewRegNat format arg_code <- getAnyReg n platform <- ncgPlatform <$> getConfig + let dst_r = getRegisterReg platform (CmmLocal dst) (code, lbl) <- op_code dst_r arg amode return (addr_code `appOL` arg_code arg `appOL` code, Just lbl) @@ -2667,9 +2671,12 @@ genCCall' _ is32Bit target dest_regs args bid = do return code _ -> panic "genCCall: Wrong number of arguments/results for imul2" - _ -> if is32Bit - then genCCall32' target dest_regs args - else genCCall64' target dest_regs args + _ -> do + (instrs0, args') <- evalArgs bid args + instrs1 <- if is32Bit + then genCCall32' target dest_regs args' + else genCCall64' target dest_regs args' + return (instrs0 `appOL` instrs1) where divOp1 platform signed width results [arg_x, arg_y] = divOp platform signed width results Nothing arg_x arg_y @@ -2732,6 +2739,83 @@ genCCall' _ is32Bit target dest_regs args bid = do addSubIntC _ _ _ _ _ _ _ _ = panic "genCCall: Wrong number of arguments/results for addSubIntC" +{- +Note [Evaluate C-call arguments before placing in destination registers] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When producing code for C calls we must take care when placing arguments +in their final registers. Specifically, we must ensure that temporary register +usage due to evaluation of one argument does not clobber a register in which we +already placed a previous argument (e.g. as the code generation logic for +MO_Shl can clobber %rcx due to x86 instruction limitations). + +This is precisely what happened in #18527. Consider this C--: + + (result::I64) = call "ccall" doSomething(_s2hp::I64, 2244, _s2hq::I64, _s2hw::I64 | (1 << _s2hz::I64)); + +Here we are calling the C function `doSomething` with three arguments, the last +involving a non-trivial expression involving MO_Shl. In this case the NCG could +naively generate the following assembly (where $tmp denotes some temporary +register and $argN denotes the register for argument N, as dictated by the +platform's calling convention): + + mov _s2hp, $arg1 # place first argument + mov _s2hq, $arg2 # place second argument + + # Compute 1 << _s2hz + mov _s2hz, %rcx + shl %cl, $tmp + + # Compute (_s2hw | (1 << _s2hz)) + mov _s2hw, $arg3 + or $tmp, $arg3 + + # Perform the call + call func + +This code is outright broken on Windows which assigns $arg1 to %rcx. This means +that the evaluation of the last argument clobbers the first argument. + +To avoid this we use a rather awful hack: when producing code for a C call with +at least one non-trivial argument, we first evaluate all of the arguments into +local registers before moving them into their final calling-convention-defined +homes. This is performed by 'evalArgs'. Here we define "non-trivial" to be an +expression which might contain a MachOp since these are the only cases which +might clobber registers. Furthermore, we use a conservative approximation of +this condition (only looking at the top-level of CmmExprs) to avoid spending +too much effort trying to decide whether we want to take the fast path. + +Note that this hack *also* applies to calls to out-of-line PrimTargets (which +are lowered via a C call) since outOfLineCmmOp produces the call via +(stmtToInstrs (CmmUnsafeForeignCall ...)), which will ultimately end up +back in genCCall{32,64}. +-} + +-- | See Note [Evaluate C-call arguments before placing in destination registers] +evalArgs :: BlockId -> [CmmActual] -> NatM (InstrBlock, [CmmActual]) +evalArgs bid actuals + | any mightContainMachOp actuals = do + regs_blks <- mapM evalArg actuals + return (concatOL $ map fst regs_blks, map snd regs_blks) + | otherwise = return (nilOL, actuals) + where + mightContainMachOp (CmmReg _) = False + mightContainMachOp (CmmRegOff _ _) = False + mightContainMachOp (CmmLit _) = False + mightContainMachOp _ = True + + evalArg :: CmmActual -> NatM (InstrBlock, CmmExpr) + evalArg actual = do + platform <- getPlatform + lreg <- newLocalReg $ cmmExprType platform actual + (instrs, bid') <- stmtToInstrs bid $ CmmAssign (CmmLocal lreg) actual + -- The above assignment shouldn't change the current block + MASSERT(isNothing bid') + return (instrs, CmmReg $ CmmLocal lreg) + + newLocalReg :: CmmType -> NatM LocalReg + newLocalReg ty = LocalReg <$> getUniqueM <*> pure ty + -- Note [DIV/IDIV for bytes] -- -- IDIV reminder: ===================================== testsuite/tests/codeGen/should_run/T18527.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +module Main where + +import Data.Bits (setBit) +import Data.Word (Word32) +import Data.Int (Int64) + +main :: IO () +main = offending 100 0 1 + +offending :: Int64 -> Int64 -> Word32 -> IO () +offending h i id = do + oldMask <- sendMessage h (2245) i 0 + let newMask = setBit oldMask (fromIntegral id) + sendMessage h (2244) i newMask + return () + +foreign import ccall "func" + sendMessage :: Int64 -> Word32 -> Int64 -> Int64 -> IO Int64 ===================================== testsuite/tests/codeGen/should_run/T18527.stdout ===================================== @@ -0,0 +1,3 @@ +ffi call +ffi call + ===================================== testsuite/tests/codeGen/should_run/T18527FFI.c ===================================== @@ -0,0 +1,14 @@ +#include +#include + +int64_t func(int64_t a, uint32_t b, int64_t c, int64_t d) { + printf("ffi call"); + if (a == 1) { + printf(" with corrupted convention\n"); + } + else { + printf("\n"); + } + return 0; +} + ===================================== testsuite/tests/codeGen/should_run/all.T ===================================== @@ -207,3 +207,4 @@ test('T16449_2', exit_code(0), compile_and_run, ['']) test('T16846', [only_ways(['optasm']), exit_code(1)], compile_and_run, ['']) test('T17920', cmm_src, compile_and_run, ['']) +test('T18527', normal, compile_and_run, ['T18527FFI.c']) ===================================== testsuite/tests/concurrent/prog001/all.T ===================================== @@ -16,4 +16,4 @@ test('concprog001', [extra_files(['Arithmetic.hs', 'Converter.hs', 'Mult.hs', 'S when(fast(), skip), only_ways(['threaded2']), fragile(16604), run_timeout_multiplier(2)], - multimod_compile_and_run, ['Mult', '']) + multimod_compile_and_run, ['Mult', '-package ghc']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d71ed2cd6334537d942632c94bdf8ff8613544bf...2e68f1bdd3f39522c8b27ab91e46c967fd805d1e -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d71ed2cd6334537d942632c94bdf8ff8613544bf...2e68f1bdd3f39522c8b27ab91e46c967fd805d1e You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 17:34:17 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 06 Aug 2020 13:34:17 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 6 commits: Grammar for types and data/newtype constructors Message-ID: <5f2c3f19b968f_80b3f849c1caa1068447d0@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 24 changed files: - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Platform/Profile.hs - compiler/GHC/Platform/Ways.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Unit/State.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.stdout - testsuite/tests/ghc-api/all.T - testsuite/tests/parser/should_fail/T12045d.stderr - testsuite/tests/parser/should_fail/strictnessDataCon_B.stderr - testsuite/tests/parser/should_fail/typeops_A.stderr - testsuite/tests/parser/should_fail/typeops_C.stderr - testsuite/tests/parser/should_fail/unpack_empty_type.stderr - testsuite/tests/parser/should_fail/unpack_inside_type.stderr - + testsuite/tests/polykinds/T18522-ppr.script - + testsuite/tests/polykinds/T18522-ppr.stdout - testsuite/tests/polykinds/all.T - + testsuite/tests/typecheck/should_fail/T18534.hs - + testsuite/tests/typecheck/should_fail/T18534.stderr - testsuite/tests/typecheck/should_fail/all.T Changes: ===================================== compiler/GHC/Core/TyCo/Ppr.hs ===================================== @@ -36,7 +36,8 @@ import {-# SOURCE #-} GHC.CoreToIface import {-# SOURCE #-} GHC.Core.DataCon ( dataConFullSig , dataConUserTyVarBinders, DataCon ) -import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many ) +import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many, + splitForAllTysReq, splitForAllTysInvis ) import GHC.Core.TyCon import GHC.Core.TyCo.Rep @@ -268,19 +269,34 @@ debug_ppr_ty prec (CastTy ty co) debug_ppr_ty _ (CoercionTy co) = parens (text "CO" <+> ppr co) -debug_ppr_ty prec ty@(ForAllTy {}) - | (tvs, body) <- split ty +-- Invisible forall: forall {k} (a :: k). t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysInvis t + , not (null bndrs) = maybeParen prec funPrec $ - hang (text "forall" <+> fsep (map ppr tvs) <> dot) - -- The (map ppr tvs) will print kind-annotated - -- tvs, because we are (usually) in debug-style - 2 (ppr body) + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <> dot, + ppr body ] where - split ty | ForAllTy tv ty' <- ty - , (tvs, body) <- split ty' - = (tv:tvs, body) - | otherwise - = ([], ty) + -- (ppr tv) will print the binder kind-annotated + -- when in debug-style + ppr_bndr (Bndr tv InferredSpec) = braces (ppr tv) + ppr_bndr (Bndr tv SpecifiedSpec) = ppr tv + +-- Visible forall: forall x y -> t +debug_ppr_ty prec t + | (bndrs, body) <- splitForAllTysReq t + , not (null bndrs) + = maybeParen prec funPrec $ + sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <+> arrow, + ppr body ] + where + -- (ppr tv) will print the binder kind-annotated + -- when in debug-style + ppr_bndr (Bndr tv ()) = ppr tv + +-- Impossible case: neither visible nor invisible forall. +debug_ppr_ty _ ForAllTy{} + = panic "debug_ppr_ty: neither splitForAllTysInvis nor splitForAllTysReq returned any binders" {- Note [Infix type variables] ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -534,7 +534,7 @@ data DynFlags = DynFlags { homeUnitInstantiations:: [(ModuleName, Module)], -- ^ How to instantiate `homeUnitInstanceOfId` unit -- ways - ways :: Set Way, -- ^ Way flags from the command line + ways :: Ways, -- ^ Way flags from the command line -- For object splitting splitInfo :: Maybe (String,Int), @@ -1433,7 +1433,7 @@ defaultDynFlags mySettings llvmConfig = cfgWeightInfo = defaultCfgWeights } -defaultWays :: Settings -> Set Way +defaultWays :: Settings -> Ways defaultWays settings = if pc_DYNAMIC_BY_DEFAULT (sPlatformConstants settings) then Set.singleton WayDyn else Set.empty ===================================== compiler/GHC/Iface/Type.hs ===================================== @@ -441,6 +441,7 @@ splitIfaceSigmaTy ty (theta, tau) = split_rho rho split_foralls (IfaceForAllTy bndr ty) + | isInvisibleArgFlag (binderArgFlag bndr) = case split_foralls ty of { (bndrs, rho) -> (bndr:bndrs, rho) } split_foralls rho = ([], rho) @@ -448,6 +449,12 @@ splitIfaceSigmaTy ty = case split_rho ty2 of { (ps, tau) -> (ty1:ps, tau) } split_rho tau = ([], tau) +splitIfaceReqForallTy :: IfaceType -> ([IfaceForAllBndr], IfaceType) +splitIfaceReqForallTy (IfaceForAllTy bndr ty) + | isVisibleArgFlag (binderArgFlag bndr) + = case splitIfaceReqForallTy ty of { (bndrs, rho) -> (bndr:bndrs, rho) } +splitIfaceReqForallTy rho = ([], rho) + suppressIfaceInvisibles :: PrintExplicitKinds -> [IfaceTyConBinder] -> [a] -> [a] suppressIfaceInvisibles (PrintExplicitKinds True) _tys xs = xs suppressIfaceInvisibles (PrintExplicitKinds False) tys xs = suppress tys xs @@ -1184,8 +1191,23 @@ pprIfaceSigmaType show_forall ty = hideNonStandardTypes ppr_fn ty where ppr_fn iface_ty = - let (tvs, theta, tau) = splitIfaceSigmaTy iface_ty - in ppr_iface_forall_part show_forall tvs theta (ppr tau) + let (invis_tvs, theta, tau) = splitIfaceSigmaTy iface_ty + (req_tvs, tau') = splitIfaceReqForallTy tau + -- splitIfaceSigmaTy is recursive, so it will gather the binders after + -- the theta, i.e. forall a. theta => forall b. tau + -- will give you ([a,b], theta, tau). + -- + -- This isn't right when it comes to visible forall (see + -- testsuite/tests/polykinds/T18522-ppr), + -- so we split off required binders separately, + -- using splitIfaceReqForallTy. + -- + -- An alternative solution would be to make splitIfaceSigmaTy + -- non-recursive (see #18458). + -- Then it could handle both invisible and required binders, and + -- splitIfaceReqForallTy wouldn't be necessary here. + in ppr_iface_forall_part show_forall invis_tvs theta $ + sep [pprIfaceForAll req_tvs, ppr tau'] pprUserIfaceForAll :: [IfaceForAllBndr] -> SDoc pprUserIfaceForAll tvs ===================================== compiler/GHC/Parser.y ===================================== @@ -1080,7 +1080,7 @@ topdecl :: { LHsDecl GhcPs } -- The $(..) form is one possible form of infixexp -- but we treat an arbitrary expression just as if -- it had a $(..) wrapped around it - | infixexp {% runECP_P $1 >>= \ $1 -> + | infixexp {% runPV (unECP $1) >>= \ $1 -> return $ sLL $1 $> $ mkSpliceDecl $1 } -- Type classes @@ -1528,7 +1528,7 @@ decl_cls : at_decl_cls { $1 } -- A 'default' signature used with the generic-programming extension | 'default' infixexp '::' sigtype - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> do { v <- checkValSigLhs $2 ; let err = text "in default signature" <> colon <+> quotes (ppr $2) @@ -1671,8 +1671,8 @@ rules :: { OrdList (LRuleDecl GhcPs) } rule :: { LRuleDecl GhcPs } : STRING rule_activation rule_foralls infixexp '=' exp - {%runECP_P $4 >>= \ $4 -> - runECP_P $6 >>= \ $6 -> + {%runPV (unECP $4) >>= \ $4 -> + runPV (unECP $6) >>= \ $6 -> ams (sLL $1 $> $ HsRule { rd_ext = noExtField , rd_name = L (gl $1) (getSTRINGs $1, getSTRING $1) , rd_act = (snd $2) `orElse` AlwaysActive @@ -1800,19 +1800,19 @@ stringlist :: { Located (OrdList (Located StringLiteral)) } ----------------------------------------------------------------------------- -- Annotations annotation :: { LHsDecl GhcPs } - : '{-# ANN' name_var aexp '#-}' {% runECP_P $3 >>= \ $3 -> + : '{-# ANN' name_var aexp '#-}' {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) (ValueAnnProvenance $2) $3)) [mo $1,mc $4] } - | '{-# ANN' 'type' tycon aexp '#-}' {% runECP_P $4 >>= \ $4 -> + | '{-# ANN' 'type' tycon aexp '#-}' {% runPV (unECP $4) >>= \ $4 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) (TypeAnnProvenance $3) $4)) [mo $1,mj AnnType $2,mc $5] } - | '{-# ANN' 'module' aexp '#-}' {% runECP_P $3 >>= \ $3 -> + | '{-# ANN' 'module' aexp '#-}' {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField (getANN_PRAGs $1) ModuleAnnProvenance $3)) @@ -1966,22 +1966,28 @@ type :: { LHsType GhcPs } mult :: { LHsType GhcPs } : btype { $1 } - btype :: { LHsType GhcPs } - : tyapps {% mergeOps (unLoc $1) } - -tyapps :: { Located [Located TyEl] } -- NB: This list is reversed - : tyapp { sL1 $1 [$1] } - | tyapps tyapp { sLL $1 $> $ $2 : unLoc $1 } - -tyapp :: { Located TyEl } - : atype { sL1 $1 $ TyElOpd (unLoc $1) } - - -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer - | PREFIX_AT atype { sLL $1 $> $ (TyElKindApp (comb2 $1 $2) $2) } - - | tyop { mapLoc TyElOpr $1 } - | unpackedness { sL1 $1 $ TyElUnpackedness (unLoc $1) } + : infixtype {% runPV $1 } + +infixtype :: { forall b. DisambTD b => PV (Located b) } + : ftype { $1 } + | ftype tyop infixtype { $1 >>= \ $1 -> + $3 >>= \ $3 -> + mkHsOpTyPV $1 $2 $3 } + | unpackedness infixtype { $2 >>= \ $2 -> + mkUnpackednessPV $1 $2 } + +ftype :: { forall b. DisambTD b => PV (Located b) } + : atype { mkHsAppTyHeadPV $1 } + | tyop { failOpFewArgs $1 } + | ftype tyarg { $1 >>= \ $1 -> + mkHsAppTyPV $1 $2 } + | ftype PREFIX_AT tyarg { $1 >>= \ $1 -> + mkHsAppKindTyPV $1 (getLoc $2) $3 } + +tyarg :: { LHsType GhcPs } + : atype { $1 } + | unpackedness atype {% addUnpackednessP $1 $2 } tyop :: { Located RdrName } : qtyconop { $1 } @@ -2222,8 +2228,9 @@ forall :: { Located ([AddAnn], Maybe [LHsTyVarBndr Specificity GhcPs]) } | {- empty -} { noLoc ([], Nothing) } constr_stuff :: { Located (Located RdrName, HsConDeclDetails GhcPs) } - : tyapps {% do { c <- mergeDataCon (unLoc $1) - ; return $ sL1 $1 c } } + : infixtype {% fmap (mapLoc (\b -> (dataConBuilderCon b, + dataConBuilderDetails b))) + (runPV $1) } fielddecls :: { [LConDeclField GhcPs] } : {- empty -} { [] } @@ -2308,7 +2315,7 @@ There's an awkward overlap with a type signature. Consider decl_no_th :: { LHsDecl GhcPs } : sigdecl { $1 } - | infixexp opt_sig rhs {% runECP_P $1 >>= \ $1 -> + | infixexp opt_sig rhs {% runPV (unECP $1) >>= \ $1 -> do { (ann,r) <- checkValDef $1 (snd $2) $3; let { l = comb2 $1 $> }; -- Depending upon what the pattern looks like we might get either @@ -2332,7 +2339,7 @@ decl :: { LHsDecl GhcPs } | splice_exp { sLL $1 $> $ mkSpliceDecl $1 } rhs :: { Located ([AddAnn],GRHSs GhcPs (LHsExpr GhcPs)) } - : '=' exp wherebinds {% runECP_P $2 >>= \ $2 -> return $ + : '=' exp wherebinds {% runPV (unECP $2) >>= \ $2 -> return $ sL (comb3 $1 $2 $3) ((mj AnnEqual $1 : (fst $ unLoc $3)) ,GRHSs noExtField (unguardedRHS (comb3 $1 $2 $3) $2) @@ -2346,7 +2353,7 @@ gdrhs :: { Located [LGRHS GhcPs (LHsExpr GhcPs)] } | gdrh { sL1 $1 [$1] } gdrh :: { LGRHS GhcPs (LHsExpr GhcPs) } - : '|' guardquals '=' exp {% runECP_P $4 >>= \ $4 -> + : '|' guardquals '=' exp {% runPV (unECP $4) >>= \ $4 -> ams (sL (comb2 $1 $>) $ GRHS noExtField (unLoc $2) $4) [mj AnnVbar $1,mj AnnEqual $3] } @@ -2354,7 +2361,7 @@ sigdecl :: { LHsDecl GhcPs } : -- See Note [Declaration/signature overlap] for why we need infixexp here infixexp '::' sigtype - {% do { $1 <- runECP_P $1 + {% do { $1 <- runPV (unECP $1) ; v <- checkValSigLhs $1 ; _ <- amsL (comb2 $1 $>) [mu AnnDcolon $2] ; return (sLL $1 $> $ SigD noExtField $ @@ -2450,30 +2457,30 @@ quasiquote :: { Located (HsSplice GhcPs) } exp :: { ECP } : infixexp '::' sigtype { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> rejectPragmaPV $1 >> amms (mkHsTySigPV (comb2 $1 $>) $1 $3) [mu AnnDcolon $2] } - | infixexp '-<' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '-<' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $1 $3 HsFirstOrderApp True) [mu Annlarrowtail $2] } - | infixexp '>-' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '>-' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $3 $1 HsFirstOrderApp False) [mu Annrarrowtail $2] } - | infixexp '-<<' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '-<<' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $1 $3 HsHigherOrderApp True) [mu AnnLarrowtail $2] } - | infixexp '>>-' exp {% runECP_P $1 >>= \ $1 -> - runECP_P $3 >>= \ $3 -> + | infixexp '>>-' exp {% runPV (unECP $1) >>= \ $1 -> + runPV (unECP $3) >>= \ $3 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrApp noExtField $3 $1 HsHigherOrderApp False) @@ -2487,8 +2494,8 @@ infixexp :: { ECP } { ECP $ superInfixOp $ $2 >>= \ $2 -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> rejectPragmaPV $1 >> amms (mkHsOpAppPV (comb2 $1 $>) $1 $2 $3) [mj AnnVal $2] } @@ -2500,14 +2507,14 @@ exp10p :: { ECP } exp_prag(e) :: { ECP } : prag_e e -- See Note [Pragmas and operator fixity] - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsPragE noExtField (snd $ unLoc $1) $2) (fst $ unLoc $1) } exp10 :: { ECP } : '-' fexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsNegAppPV (comb2 $1 $>) $2) [mj AnnMinus $1] } | fexp { $1 } @@ -2590,16 +2597,16 @@ prag_e :: { Located ([AddAnn], HsPragE GhcPs) } fexp :: { ECP } : fexp aexp { ECP $ superFunArg $ - runECP_PV $1 >>= \ $1 -> - runECP_PV $2 >>= \ $2 -> + unECP $1 >>= \ $1 -> + unECP $2 >>= \ $2 -> mkHsAppPV (comb2 $1 $>) $1 $2 } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer | fexp PREFIX_AT atype { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> amms (mkHsAppTypePV (comb2 $1 $>) $1 $3) [mj AnnAt $2] } - | 'static' aexp {% runECP_P $2 >>= \ $2 -> + | 'static' aexp {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsStatic noExtField $2) [mj AnnStatic $1] } @@ -2609,23 +2616,23 @@ aexp :: { ECP } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer : qvar TIGHT_INFIX_AT aexp { ECP $ - runECP_PV $3 >>= \ $3 -> + unECP $3 >>= \ $3 -> amms (mkHsAsPatPV (comb2 $1 $>) $1 $3) [mj AnnAt $2] } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer | PREFIX_TILDE aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsLazyPatPV (comb2 $1 $>) $2) [mj AnnTilde $1] } | PREFIX_BANG aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsBangPatPV (comb2 $1 $>) $2) [mj AnnBang $1] } | PREFIX_MINUS aexp { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsNegAppPV (comb2 $1 $>) $2) [mj AnnMinus $1] } | '\\' apat apats '->' exp { ECP $ - runECP_PV $5 >>= \ $5 -> + unECP $5 >>= \ $5 -> amms (mkHsLamPV (comb2 $1 $>) (mkMatchGroup FromSource [sLL $1 $> $ Match { m_ext = noExtField , m_ctxt = LambdaExpr @@ -2633,7 +2640,7 @@ aexp :: { ECP } , m_grhss = unguardedGRHSs $5 }])) [mj AnnLam $1, mu AnnRarrow $4] } | 'let' binds 'in' exp { ECP $ - runECP_PV $4 >>= \ $4 -> + unECP $4 >>= \ $4 -> amms (mkHsLetPV (comb2 $1 $>) (snd (unLoc $2)) $4) (mj AnnLet $1:mj AnnIn $3 :(fst $ unLoc $2)) } @@ -2643,10 +2650,10 @@ aexp :: { ECP } (mkMatchGroup FromSource (snd $ unLoc $3))) (mj AnnLam $1:mj AnnCase $2:(fst $ unLoc $3)) } | 'if' exp optSemi 'then' exp optSemi 'else' exp - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> return $ ECP $ - runECP_PV $5 >>= \ $5 -> - runECP_PV $8 >>= \ $8 -> + unECP $5 >>= \ $5 -> + unECP $8 >>= \ $8 -> amms (mkHsIfPV (comb2 $1 $>) $2 (snd $3) $5 (snd $6) $8) (mj AnnIf $1:mj AnnThen $4 :mj AnnElse $7 @@ -2657,7 +2664,7 @@ aexp :: { ECP } ams (sLL $1 $> $ HsMultiIf noExtField (reverse $ snd $ unLoc $2)) (mj AnnIf $1:(fst $ unLoc $2)) } - | 'case' exp 'of' altslist {% runECP_P $2 >>= \ $2 -> + | 'case' exp 'of' altslist {% runPV (unECP $2) >>= \ $2 -> return $ ECP $ $4 >>= \ $4 -> amms (mkHsCasePV (comb3 $1 $3 $4) $2 (mkMatchGroup @@ -2681,8 +2688,8 @@ aexp :: { ECP } (snd $ unLoc $2))) (mj AnnMdo $1:(fst $ unLoc $2)) } | 'proc' aexp '->' exp - {% (checkPattern <=< runECP_P) $2 >>= \ p -> - runECP_P $4 >>= \ $4 at cmd -> + {% (checkPattern <=< runPV) (unECP $2) >>= \ p -> + runPV (unECP $4) >>= \ $4 at cmd -> fmap ecpFromExp $ ams (sLL $1 $> $ HsProc noExtField p (sLL $1 $> $ HsCmdTop noExtField cmd)) -- TODO: is LL right here? @@ -2692,7 +2699,7 @@ aexp :: { ECP } aexp1 :: { ECP } : aexp1 '{' fbinds '}' { ECP $ - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> $3 >>= \ $3 -> amms (mkHsRecordPV (comb2 $1 $>) (comb2 $2 $4) $1 (snd $3)) (moc $2:mcc $4:(fst $3)) } @@ -2716,7 +2723,7 @@ aexp2 :: { ECP } -- correct Haskell (you'd have to write '((+ 3), (4 -))') -- but the less cluttered version fell out of having texps. | '(' texp ')' { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkHsParPV (comb2 $1 $>) $2) [mop $1,mcp $3] } | '(' tup_exprs ')' { ECP $ $2 >>= \ $2 -> @@ -2724,7 +2731,7 @@ aexp2 :: { ECP } ((mop $1:fst $2) ++ [mcp $3]) } | '(#' texp '#)' { ECP $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> amms (mkSumOrTuplePV (comb2 $1 $>) Unboxed (Tuple [L (gl $2) (Just $2)])) [mo $1,mc $3] } | '(#' tup_exprs '#)' { ECP $ @@ -2744,18 +2751,18 @@ aexp2 :: { ECP } | TH_TY_QUOTE tyvar {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } | TH_TY_QUOTE gtycon {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } | TH_TY_QUOTE {- nothing -} {% reportEmptyDoubleQuotes (getLoc $1) } - | '[|' exp '|]' {% runECP_P $2 >>= \ $2 -> + | '[|' exp '|]' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (ExpBr noExtField $2)) (if (hasE $1) then [mj AnnOpenE $1, mu AnnCloseQ $3] else [mu AnnOpenEQ $1,mu AnnCloseQ $3]) } - | '[||' exp '||]' {% runECP_P $2 >>= \ $2 -> + | '[||' exp '||]' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (TExpBr noExtField $2)) (if (hasE $1) then [mj AnnOpenE $1,mc $3] else [mo $1,mc $3]) } | '[t|' ktype '|]' {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (TypBr noExtField $2)) [mo $1,mu AnnCloseQ $3] } - | '[p|' infixexp '|]' {% (checkPattern <=< runECP_P) $2 >>= \p -> + | '[p|' infixexp '|]' {% (checkPattern <=< runPV) (unECP $2) >>= \p -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (PatBr noExtField p)) [mo $1,mu AnnCloseQ $3] } @@ -2765,7 +2772,7 @@ aexp2 :: { ECP } | quasiquote { ECP $ mkHsSplicePV $1 } -- arrow notation extension - | '(|' aexp cmdargs '|)' {% runECP_P $2 >>= \ $2 -> + | '(|' aexp cmdargs '|)' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromCmd $ ams (sLL $1 $> $ HsCmdArrForm noExtField $2 Prefix Nothing (reverse $3)) @@ -2777,14 +2784,14 @@ splice_exp :: { LHsExpr GhcPs } splice_untyped :: { Located (HsSplice GhcPs) } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer - : PREFIX_DOLLAR aexp2 {% runECP_P $2 >>= \ $2 -> + : PREFIX_DOLLAR aexp2 {% runPV (unECP $2) >>= \ $2 -> ams (sLL $1 $> $ mkUntypedSplice DollarSplice $2) [mj AnnDollar $1] } splice_typed :: { Located (HsSplice GhcPs) } -- See Note [Whitespace-sensitive operator parsing] in GHC.Parser.Lexer : PREFIX_DOLLAR_DOLLAR aexp2 - {% runECP_P $2 >>= \ $2 -> + {% runPV (unECP $2) >>= \ $2 -> ams (sLL $1 $> $ mkTypedSplice DollarSplice $2) [mj AnnDollarDollar $1] } @@ -2793,7 +2800,7 @@ cmdargs :: { [LHsCmdTop GhcPs] } | {- empty -} { [] } acmd :: { LHsCmdTop GhcPs } - : aexp {% runECP_P $1 >>= \ cmd -> + : aexp {% runPV (unECP $1) >>= \ cmd -> runPV (checkCmdBlockArguments cmd) >>= \ _ -> return (sL1 cmd $ HsCmdTop noExtField cmd) } @@ -2827,21 +2834,21 @@ texp :: { ECP } -- Meanwhile, the renamer checks that real sections appear -- inside parens. | infixexp qop - {% runECP_P $1 >>= \ $1 -> + {% runPV (unECP $1) >>= \ $1 -> runPV (rejectPragmaPV $1) >> runPV $2 >>= \ $2 -> return $ ecpFromExp $ sLL $1 $> $ SectionL noExtField $1 $2 } | qopm infixexp { ECP $ superInfixOp $ - runECP_PV $2 >>= \ $2 -> + unECP $2 >>= \ $2 -> $1 >>= \ $1 -> mkHsSectionR_PV (comb2 $1 $>) $1 $2 } -- View patterns get parenthesized above | exp '->' texp { ECP $ - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> amms (mkHsViewPatPV (comb2 $1 $>) $1 $3) [mu AnnRarrow $2] } -- Always at least one comma or bar. @@ -2850,12 +2857,12 @@ texp :: { ECP } -- in GHC.Hs.Expr. tup_exprs :: { forall b. DisambECP b => PV ([AddAnn],SumOrTuple b) } : texp commas_tup_tail - { runECP_PV $1 >>= \ $1 -> + { unECP $1 >>= \ $1 -> $2 >>= \ $2 -> do { addAnnotation (gl $1) AnnComma (fst $2) ; return ([],Tuple ((sL1 $1 (Just $1)) : snd $2)) } } - | texp bars { runECP_PV $1 >>= \ $1 -> return $ + | texp bars { unECP $1 >>= \ $1 -> return $ (mvbars (fst $2), Sum 1 (snd $2 + 1) $1) } | commas tup_tail @@ -2865,7 +2872,7 @@ tup_exprs :: { forall b. DisambECP b => PV ([AddAnn],SumOrTuple b) } ([],Tuple (map (\l -> L l Nothing) (fst $1) ++ $2)) } } | bars texp bars0 - { runECP_PV $2 >>= \ $2 -> return $ + { unECP $2 >>= \ $2 -> return $ (mvbars (fst $1) ++ mvbars (fst $3), Sum (snd $1 + 1) (snd $1 + snd $3 + 1) $2) } -- Always starts with commas; always follows an expr @@ -2879,11 +2886,11 @@ commas_tup_tail : commas tup_tail -- Always follows a comma tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] } - : texp commas_tup_tail { runECP_PV $1 >>= \ $1 -> + : texp commas_tup_tail { unECP $1 >>= \ $1 -> $2 >>= \ $2 -> addAnnotation (gl $1) AnnComma (fst $2) >> return ((L (gl $1) (Just $1)) : snd $2) } - | texp { runECP_PV $1 >>= \ $1 -> + | texp { unECP $1 >>= \ $1 -> return [L (gl $1) (Just $1)] } | {- empty -} { return [noLoc Nothing] } @@ -2894,48 +2901,48 @@ tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] } -- avoiding another shift/reduce-conflict. -- Never empty. list :: { forall b. DisambECP b => SrcSpan -> PV (Located b) } - : texp { \loc -> runECP_PV $1 >>= \ $1 -> + : texp { \loc -> unECP $1 >>= \ $1 -> mkHsExplicitListPV loc [$1] } | lexps { \loc -> $1 >>= \ $1 -> mkHsExplicitListPV loc (reverse $1) } - | texp '..' { \loc -> runECP_PV $1 >>= \ $1 -> + | texp '..' { \loc -> unECP $1 >>= \ $1 -> ams (L loc $ ArithSeq noExtField Nothing (From $1)) [mj AnnDotdot $2] >>= ecpFromExp' } | texp ',' exp '..' { \loc -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> ams (L loc $ ArithSeq noExtField Nothing (FromThen $1 $3)) [mj AnnComma $2,mj AnnDotdot $4] >>= ecpFromExp' } - | texp '..' exp { \loc -> runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + | texp '..' exp { \loc -> unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> ams (L loc $ ArithSeq noExtField Nothing (FromTo $1 $3)) [mj AnnDotdot $2] >>= ecpFromExp' } | texp ',' exp '..' exp { \loc -> - runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> - runECP_PV $5 >>= \ $5 -> + unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> + unECP $5 >>= \ $5 -> ams (L loc $ ArithSeq noExtField Nothing (FromThenTo $1 $3 $5)) [mj AnnComma $2,mj AnnDotdot $4] >>= ecpFromExp' } | texp '|' flattenedpquals { \loc -> checkMonadComp >>= \ ctxt -> - runECP_PV $1 >>= \ $1 -> + unECP $1 >>= \ $1 -> ams (L loc $ mkHsComp ctxt (unLoc $3) $1) [mj AnnVbar $2] >>= ecpFromExp' } lexps :: { forall b. DisambECP b => PV [Located b] } : lexps ',' texp { $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + unECP $3 >>= \ $3 -> addAnnotation (gl $ head $ $1) AnnComma (gl $2) >> return (((:) $! $3) $! $1) } - | texp ',' texp { runECP_PV $1 >>= \ $1 -> - runECP_PV $3 >>= \ $3 -> + | texp ',' texp { unECP $1 >>= \ $1 -> + unECP $3 >>= \ $3 -> addAnnotation (gl $1) AnnComma (gl $2) >> return [$3,$1] } @@ -2985,20 +2992,20 @@ squals :: { Located [LStmt GhcPs (LHsExpr GhcPs)] } -- In reverse order, becau transformqual :: { Located ([AddAnn],[LStmt GhcPs (LHsExpr GhcPs)] -> Stmt GhcPs (LHsExpr GhcPs)) } -- Function is applied to a list of stmts *in order* - : 'then' exp {% runECP_P $2 >>= \ $2 -> return $ + : 'then' exp {% runPV (unECP $2) >>= \ $2 -> return $ sLL $1 $> ([mj AnnThen $1], \ss -> (mkTransformStmt ss $2)) } - | 'then' exp 'by' exp {% runECP_P $2 >>= \ $2 -> - runECP_P $4 >>= \ $4 -> + | 'then' exp 'by' exp {% runPV (unECP $2) >>= \ $2 -> + runPV (unECP $4) >>= \ $4 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnBy $3], \ss -> (mkTransformByStmt ss $2 $4)) } | 'then' 'group' 'using' exp - {% runECP_P $4 >>= \ $4 -> + {% runPV (unECP $4) >>= \ $4 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnUsing $3], \ss -> (mkGroupUsingStmt ss $4)) } | 'then' 'group' 'by' exp 'using' exp - {% runECP_P $4 >>= \ $4 -> - runECP_P $6 >>= \ $6 -> + {% runPV (unECP $4) >>= \ $4 -> + runPV (unECP $6) >>= \ $6 -> return $ sLL $1 $> ([mj AnnThen $1,mj AnnGroup $2,mj AnnBy $3,mj AnnUsing $5], \ss -> (mkGroupByUsingStmt ss $4 $6)) } @@ -3072,7 +3079,7 @@ alt_rhs :: { forall b. DisambECP b => PV (Located ([AddAnn],GRHSs GhcPs (Located return $ sLL alt $> (fst $ unLoc $2, GRHSs noExtField (unLoc alt) (snd $ unLoc $2)) } ralt :: { forall b. DisambECP b => PV (Located [LGRHS GhcPs (Located b)]) } - : '->' exp { runECP_PV $2 >>= \ $2 -> + : '->' exp { unECP $2 >>= \ $2 -> ams (sLL $1 $> (unguardedRHS (comb2 $1 $2) $2)) [mu AnnRarrow $1] } | gdpats { $1 >>= \gdpats -> @@ -3095,7 +3102,7 @@ ifgdpats :: { Located ([AddAnn],[LGRHS GhcPs (LHsExpr GhcPs)]) } gdpat :: { forall b. DisambECP b => PV (LGRHS GhcPs (Located b)) } : '|' guardquals '->' exp - { runECP_PV $4 >>= \ $4 -> + { unECP $4 >>= \ $4 -> ams (sL (comb2 $1 $>) $ GRHS noExtField (unLoc $2) $4) [mj AnnVbar $1,mu AnnRarrow $3] } @@ -3104,15 +3111,15 @@ gdpat :: { forall b. DisambECP b => PV (LGRHS GhcPs (Located b)) } -- Bangs inside are parsed as infix operator applications, so that -- we parse them right when bang-patterns are off pat :: { LPat GhcPs } -pat : exp {% (checkPattern <=< runECP_P) $1 } +pat : exp {% (checkPattern <=< runPV) (unECP $1) } bindpat :: { LPat GhcPs } -bindpat : exp {% -- See Note [Parser-Validator ReaderT SDoc] in GHC.Parser.PostProcess +bindpat : exp {% -- See Note [Parser-Validator Hint] in GHC.Parser.PostProcess checkPattern_msg (text "Possibly caused by a missing 'do'?") - (runECP_PV $1) } + (unECP $1) } apat :: { LPat GhcPs } -apat : aexp {% (checkPattern <=< runECP_P) $1 } +apat : aexp {% (checkPattern <=< runPV) (unECP $1) } apats :: { [LPat GhcPs] } : apat apats { $1 : $2 } @@ -3175,10 +3182,10 @@ stmt :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } (mj AnnRec $1:(fst $ unLoc $2)) } qual :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } - : bindpat '<-' exp { runECP_PV $3 >>= \ $3 -> + : bindpat '<-' exp { unECP $3 >>= \ $3 -> ams (sLL $1 $> $ mkPsBindStmt $1 $3) [mu AnnLarrow $2] } - | exp { runECP_PV $1 >>= \ $1 -> + | exp { unECP $1 >>= \ $1 -> return $ sL1 $1 $ mkBodyStmt $1 } | 'let' binds { ams (sLL $1 $> $ LetStmt noExtField (snd $ unLoc $2)) (mj AnnLet $1:(fst $ unLoc $2)) } @@ -3201,7 +3208,7 @@ fbinds1 :: { forall b. DisambECP b => PV ([AddAnn],([LHsRecField GhcPs (Located | '..' { return ([mj AnnDotdot $1],([], Just (getLoc $1))) } fbind :: { forall b. DisambECP b => PV (LHsRecField GhcPs (Located b)) } - : qvar '=' texp { runECP_PV $3 >>= \ $3 -> + : qvar '=' texp { unECP $3 >>= \ $3 -> ams (sLL $1 $> $ HsRecField (sL1 $1 $ mkFieldOcc $1) $3 False) [mj AnnEqual $2] } -- RHS is a 'texp', allowing view patterns (#6038) @@ -3227,7 +3234,7 @@ dbinds :: { Located [LIPBind GhcPs] } -- | {- empty -} { [] } dbind :: { LIPBind GhcPs } -dbind : ipvar '=' exp {% runECP_P $3 >>= \ $3 -> +dbind : ipvar '=' exp {% runPV (unECP $3) >>= \ $3 -> ams (sLL $1 $> (IPBind noExtField (Left $1) $3)) [mj AnnEqual $2] } ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -68,7 +68,6 @@ module GHC.Parser.PostProcess ( checkRecordSyntax, checkEmptyGADTs, addFatalError, hintBangPat, - TyEl(..), mergeOps, mergeDataCon, mkBangTy, UnpackednessPragma(..), @@ -96,13 +95,19 @@ module GHC.Parser.PostProcess ( -- Expression/command/pattern ambiguity resolution PV, runPV, - ECP(ECP, runECP_PV), - runECP_P, + ECP(ECP, unECP), DisambInfixOp(..), DisambECP(..), ecpFromExp, ecpFromCmd, - PatBuilder + PatBuilder, + + -- Type/datacon ambiguity resolution + DisambTD(..), + addUnpackednessP, + DataConBuilder(), + dataConBuilderCon, + dataConBuilderDetails, ) where import GHC.Prelude @@ -126,20 +131,20 @@ import GHC.Types.ForeignCall import GHC.Builtin.Names ( allNameStrings ) import GHC.Types.SrcLoc import GHC.Types.Unique ( hasKey ) -import GHC.Data.OrdList ( OrdList, fromOL ) +import GHC.Data.OrdList import GHC.Utils.Outputable as Outputable import GHC.Data.FastString import GHC.Data.Maybe import GHC.Utils.Misc import GHC.Parser.Annotation import Data.List +import Data.Foldable import GHC.Driver.Session ( WarningFlag(..), DynFlags ) import GHC.Utils.Error ( Messages ) import Control.Monad import Text.ParserCombinators.ReadP as ReadP import Data.Char -import qualified Data.Monoid as Monoid import Data.Data ( dataTypeOf, fromConstr, dataTypeConstrs ) import Data.Kind ( Type ) @@ -559,30 +564,6 @@ context, so (C t1 t2) is a constraint and 'C' is a type constructor. As the result, in order to determine whether (C t1 t2) declares a data constructor, a type, or a context, we would need unlimited lookahead which 'happy' is not so happy with. - -The solution that accounts for all of these issues is to initially parse data -declarations and types as a reversed list of TyEl: - - data TyEl = TyElOpr RdrName - | TyElOpd (HsType GhcPs) - | ... - -For example, both occurrences of (C ! D) in the following example are parsed -into equal lists of TyEl: - - data T = C ! D => C ! D results in [ TyElOpd (HsTyVar "D") - , TyElOpr "!" - , TyElOpd (HsTyVar "C") ] - -Note that elements are in reverse order. Also, 'C' is parsed as a type -constructor (HsTyVar) even when it is a data constructor. We fix this in -`tyConToDataCon`. - -By the time the list of TyEl is assembled, we have looked ahead enough to -decide whether to reduce using `mergeOps` (for types) or `mergeDataCon` (for -data constructors). These functions are where the actual job of parsing is -done. - -} -- | Reinterpret a type constructor, including type operators, as a data @@ -798,7 +779,7 @@ to make setRdrNameSpace partial, so we just make an Unqual name instead. It really doesn't matter! -} -eitherToP :: Either (SrcSpan, SDoc) a -> P a +eitherToP :: MonadP m => Either (SrcSpan, SDoc) a -> m a -- Adapts the Either monad to the P monad eitherToP (Left (loc, doc)) = addFatalError loc doc eitherToP (Right thing) = return thing @@ -1309,323 +1290,31 @@ isFunLhs e = go e [] [] _ -> return Nothing } go _ _ _ = return Nothing --- | Either an operator or an operand. -data TyEl = TyElOpr RdrName | TyElOpd (HsType GhcPs) - | TyElKindApp SrcSpan (LHsType GhcPs) - -- See Note [TyElKindApp SrcSpan interpretation] - | TyElUnpackedness UnpackednessPragma - - -{- Note [TyElKindApp SrcSpan interpretation] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -A TyElKindApp captures type application written in haskell as - - @ Foo - -where Foo is some type. - -The SrcSpan reflects both elements, and there are AnnAt and AnnVal API -Annotations attached to this SrcSpan for the specific locations of -each within it. --} - -instance Outputable TyEl where - ppr (TyElOpr name) = ppr name - ppr (TyElOpd ty) = ppr ty - ppr (TyElKindApp _ ki) = text "@" <> ppr ki - ppr (TyElUnpackedness (UnpackednessPragma _ _ unpk)) = ppr unpk - --- | Extract a strictness/unpackedness annotation from the front of a reversed --- 'TyEl' list. -pUnpackedness - :: [Located TyEl] -- reversed TyEl - -> Maybe (SrcSpan, UnpackednessPragma, - [Located TyEl] {- remaining TyEl -}) -pUnpackedness (L l x1 : xs) | TyElUnpackedness up <- x1 = Just (l, up, xs) -pUnpackedness _ = Nothing - -pBangTy - :: LHsType GhcPs -- a type to be wrapped inside HsBangTy - -> [Located TyEl] -- reversed TyEl - -> ( Bool {- has a strict mark been consumed? -} - , LHsType GhcPs {- the resulting BangTy -} - , P () {- add annotations -} - , [Located TyEl] {- remaining TyEl -}) -pBangTy lt@(L l1 _) xs = - case pUnpackedness xs of - Nothing -> (False, lt, pure (), xs) - Just (l2, UnpackednessPragma anns prag unpk, xs') -> - let bl = combineSrcSpans l1 l2 - bt = addUnpackedness (prag, unpk) lt - in (True, L bl bt, addAnnsAt bl anns, xs') - mkBangTy :: SrcStrictness -> LHsType GhcPs -> HsType GhcPs mkBangTy strictness = HsBangTy noExtField (HsSrcBang NoSourceText NoSrcUnpack strictness) --- Result of parsing {-# UNPACK #-} or {-# NOUNPACK #-} +-- | Result of parsing @{-\# UNPACK \#-}@ or @{-\# NOUNPACK \#-}@. data UnpackednessPragma = UnpackednessPragma [AddAnn] SourceText SrcUnpackedness -addUnpackedness :: (SourceText, SrcUnpackedness) -> LHsType GhcPs -> HsType GhcPs -addUnpackedness (prag, unpk) (L _ (HsBangTy x bang t)) - | HsSrcBang NoSourceText NoSrcUnpack strictness <- bang - = HsBangTy x (HsSrcBang prag unpk strictness) t -addUnpackedness (prag, unpk) t - = HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t - --- | Merge a /reversed/ and /non-empty/ soup of operators and operands --- into a type. --- --- User input: @F x y + G a b * X@ --- Input to 'mergeOps': [X, *, b, a, G, +, y, x, F] --- Output corresponds to what the user wrote assuming all operators are of the --- same fixity and right-associative. --- --- It's a bit silly that we're doing it at all, as the renamer will have to --- rearrange this, and it'd be easier to keep things separate. --- --- See Note [Parsing data constructors is hard] -mergeOps :: [Located TyEl] -> P (LHsType GhcPs) -mergeOps ((L l1 (TyElOpd t)) : xs) - | (_, t', addAnns, xs') <- pBangTy (L l1 t) xs - , null xs' -- We accept a BangTy only when there are no preceding TyEl. - = addAnns >> return t' -mergeOps all_xs = go (0 :: Int) [] id all_xs - where - -- NB. When modifying clauses in 'go', make sure that the reasoning in - -- Note [Non-empty 'acc' in mergeOps clause [end]] is still correct. - - -- clause [unpk]: - -- handle (NO)UNPACK pragmas - go k acc ops_acc ((L l (TyElUnpackedness (UnpackednessPragma anns unpkSrc unpk))):xs) = - if not (null acc) && null xs - then do { acc' <- eitherToP $ mergeOpsAcc acc - ; let a = ops_acc acc' - strictMark = HsSrcBang unpkSrc unpk NoSrcStrict - bl = combineSrcSpans l (getLoc a) - bt = HsBangTy noExtField strictMark a - ; addAnnsAt bl anns - ; return (L bl bt) } - else addFatalError l unpkError - where - unpkSDoc = case unpkSrc of - NoSourceText -> ppr unpk - SourceText str -> text str <> text " #-}" - unpkError - | not (null xs) = unpkSDoc <+> text "cannot appear inside a type." - | null acc && k == 0 = unpkSDoc <+> text "must be applied to a type." - | otherwise = - -- See Note [Impossible case in mergeOps clause [unpk]] - panic "mergeOps.UNPACK: impossible position" - - -- clause [opr]: - -- when we encounter an operator, we must have accumulated - -- something for its rhs, and there must be something left - -- to build its lhs. - go k acc ops_acc ((L l (TyElOpr op)):xs) = - if null acc || null (filter isTyElOpd xs) - then failOpFewArgs (L l op) - else do { acc' <- eitherToP (mergeOpsAcc acc) - ; go (k + 1) [] (\c -> mkLHsOpTy c (L l op) (ops_acc acc')) xs } - where - isTyElOpd (L _ (TyElOpd _)) = True - isTyElOpd _ = False - - -- clause [opd]: - -- whenever an operand is encountered, it is added to the accumulator - go k acc ops_acc ((L l (TyElOpd a)):xs) = go k (HsValArg (L l a):acc) ops_acc xs - - -- clause [tyapp]: - -- whenever a type application is encountered, it is added to the accumulator - go k acc ops_acc ((L _ (TyElKindApp l a)):xs) = go k (HsTypeArg l a:acc) ops_acc xs - - -- clause [end] - -- See Note [Non-empty 'acc' in mergeOps clause [end]] - go _ acc ops_acc [] = do { acc' <- eitherToP (mergeOpsAcc acc) - ; return (ops_acc acc') } - -mergeOpsAcc :: [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> Either (SrcSpan, SDoc) (LHsType GhcPs) -mergeOpsAcc [] = panic "mergeOpsAcc: empty input" -mergeOpsAcc (HsTypeArg _ (L loc ki):_) - = Left (loc, text "Unexpected type application:" <+> ppr ki) -mergeOpsAcc (HsValArg ty : xs) = go1 ty xs - where - go1 :: LHsType GhcPs - -> [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> Either (SrcSpan, SDoc) (LHsType GhcPs) - go1 lhs [] = Right lhs - go1 lhs (x:xs) = case x of - HsValArg ty -> go1 (mkHsAppTy lhs ty) xs - HsTypeArg loc ki -> let ty = mkHsAppKindTy loc lhs ki - in go1 ty xs - HsArgPar _ -> go1 lhs xs -mergeOpsAcc (HsArgPar _: xs) = mergeOpsAcc xs - -{- Note [Impossible case in mergeOps clause [unpk]] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -This case should never occur. Let us consider all possible -variations of 'acc', 'xs', and 'k': - - acc xs k -============================== - null | null 0 -- "must be applied to a type" - null | not null 0 -- "must be applied to a type" -not null | null 0 -- successful parse -not null | not null 0 -- "cannot appear inside a type" - null | null >0 -- handled in clause [opr] - null | not null >0 -- "cannot appear inside a type" -not null | null >0 -- successful parse -not null | not null >0 -- "cannot appear inside a type" - -The (null acc && null xs && k>0) case is handled in clause [opr] -by the following check: - - if ... || null (filter isTyElOpd xs) - then failOpFewArgs (L l op) - -We know that this check has been performed because k>0, and by -the time we reach the end of the list (null xs), the only way -for (null acc) to hold is that there was not a single TyElOpd -between the operator and the end of the list. But this case is -caught by the check and reported as 'failOpFewArgs'. --} - -{- Note [Non-empty 'acc' in mergeOps clause [end]] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In clause [end] we need to know that 'acc' is non-empty to call 'mergeAcc' -without a check. - -Running 'mergeOps' with an empty input list is forbidden, so we do not consider -this possibility. This means we'll hit at least one other clause before we -reach clause [end]. - -* Clauses [unpk] and [doc] do not call 'go' recursively, so we cannot hit - clause [end] from there. -* Clause [opd] makes 'acc' non-empty, so if we hit clause [end] after it, 'acc' - will be non-empty. -* Clause [opr] checks that (filter isTyElOpd xs) is not null - so we are going - to hit clause [opd] at least once before we reach clause [end], making 'acc' - non-empty. -* There are no other clauses. - -Therefore, it is safe to omit a check for non-emptiness of 'acc' in clause -[end]. - --} - -pInfixSide :: [Located TyEl] -> Maybe (LHsType GhcPs, P (), [Located TyEl]) -pInfixSide ((L l (TyElOpd t)):xs) - | (True, t', addAnns, xs') <- pBangTy (L l t) xs - = Just (t', addAnns, xs') -pInfixSide (el:xs1) - | Just t1 <- pLHsTypeArg el - = go [t1] xs1 - where - go :: [HsArg (LHsType GhcPs) (LHsKind GhcPs)] - -> [Located TyEl] -> Maybe (LHsType GhcPs, P (), [Located TyEl]) - go acc (el:xs) - | Just t <- pLHsTypeArg el - = go (t:acc) xs - go acc xs = case mergeOpsAcc acc of - Left _ -> Nothing - Right acc' -> Just (acc', pure (), xs) -pInfixSide _ = Nothing - -pLHsTypeArg :: Located TyEl -> Maybe (HsArg (LHsType GhcPs) (LHsKind GhcPs)) -pLHsTypeArg (L l (TyElOpd a)) = Just (HsValArg (L l a)) -pLHsTypeArg (L _ (TyElKindApp l a)) = Just (HsTypeArg l a) -pLHsTypeArg _ = Nothing - -orErr :: Maybe a -> b -> Either b a -orErr (Just a) _ = Right a -orErr Nothing b = Left b - --- | Merge a /reversed/ and /non-empty/ soup of operators and operands --- into a data constructor. --- --- User input: @C !A B -- ^ doc@ --- Input to 'mergeDataCon': ["doc", B, !A, C] --- Output: (C, PrefixCon [!A, B], "doc") --- --- See Note [Parsing data constructors is hard] -mergeDataCon - :: [Located TyEl] - -> P ( Located RdrName -- constructor name - , HsConDeclDetails GhcPs -- constructor field information - ) -mergeDataCon all_xs = - do { (addAnns, a) <- eitherToP res - ; addAnns - ; return a } +-- | Annotate a type with either an @{-\# UNPACK \#-}@ or a @{-\# NOUNPACK \#-}@ pragma. +addUnpackednessP :: MonadP m => Located UnpackednessPragma -> LHsType GhcPs -> m (LHsType GhcPs) +addUnpackednessP (L lprag (UnpackednessPragma anns prag unpk)) ty = do + let l' = combineSrcSpans lprag (getLoc ty) + t' = addUnpackedness ty + addAnnsAt l' anns + return (L l' t') where - -- The result of merging the list of reversed TyEl into a - -- data constructor, along with [AddAnn]. - res = goFirst all_xs - - goFirst [ L l (TyElOpd (HsTyVar _ _ (L _ tc))) ] - = do { data_con <- tyConToDataCon l tc - ; return (pure (), (data_con, PrefixCon [])) } - goFirst ((L l (TyElOpd (HsRecTy _ fields))):xs) - | [ L l' (TyElOpd (HsTyVar _ _ (L _ tc))) ] <- xs - = do { data_con <- tyConToDataCon l' tc - ; return (pure (), (data_con, RecCon (L l fields))) } - goFirst [L l (TyElOpd (HsTupleTy _ HsBoxedOrConstraintTuple ts))] - = return ( pure () - , ( L l (getRdrName (tupleDataCon Boxed (length ts))) - , PrefixCon (map hsLinear ts) ) ) - goFirst ((L l (TyElOpd t)):xs) - | (_, t', addAnns, xs') <- pBangTy (L l t) xs - = go addAnns [t'] xs' - goFirst (L l (TyElKindApp _ _):_) - = goInfix Monoid.<> Left (l, kindAppErr) - goFirst xs - = go (pure ()) [] xs - - go addAnns ts [ L l (TyElOpd (HsTyVar _ _ (L _ tc))) ] - = do { data_con <- tyConToDataCon l tc - ; return (addAnns, (data_con, PrefixCon (map hsLinear ts))) } - go addAnns ts ((L l (TyElOpd t)):xs) - | (_, t', addAnns', xs') <- pBangTy (L l t) xs - = go (addAnns >> addAnns') (t':ts) xs' - go _ _ ((L _ (TyElOpr _)):_) = - -- Encountered an operator: backtrack to the beginning and attempt - -- to parse as an infix definition. - goInfix - go _ _ (L l (TyElKindApp _ _):_) = goInfix Monoid.<> Left (l, kindAppErr) - go _ _ _ = Left malformedErr - where - malformedErr = - ( foldr combineSrcSpans noSrcSpan (map getLoc all_xs) - , text "Cannot parse data constructor" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs)) - - goInfix = - do { let xs0 = all_xs - ; (rhs, rhs_addAnns, xs1) <- pInfixSide xs0 `orErr` malformedErr - ; (op, xs3) <- case xs1 of - (L l (TyElOpr op)) : xs3 -> - do { data_con <- tyConToDataCon l op - ; return (data_con, xs3) } - _ -> Left malformedErr - ; (lhs, lhs_addAnns, xs5) <- pInfixSide xs3 `orErr` malformedErr - ; unless (null xs5) (Left malformedErr) - ; let addAnns = lhs_addAnns >> rhs_addAnns - ; return (addAnns, (op, InfixCon (hsLinear lhs) (hsLinear rhs))) } - where - malformedErr = - ( foldr combineSrcSpans noSrcSpan (map getLoc all_xs) - , text "Cannot parse an infix data constructor" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs)) - - kindAppErr = - text "Unexpected kind application" <+> - text "in a data/newtype declaration:" $$ - nest 2 (hsep . reverse $ map ppr all_xs) + -- If we have a HsBangTy that only has a strictness annotation, + -- such as ~T or !T, then add the pragma to the existing HsBangTy. + -- + -- Otherwise, wrap the type in a new HsBangTy constructor. + addUnpackedness (L _ (HsBangTy x bang t)) + | HsSrcBang NoSourceText NoSrcUnpack strictness <- bang + = HsBangTy x (HsSrcBang prag unpk strictness) t + addUnpackedness t + = HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t --------------------------------------------------------------------------- -- | Check for monad comprehensions @@ -1645,7 +1334,6 @@ checkMonadComp = do -- See Note [Ambiguous syntactic categories] -- --- See Note [Parser-Validator] -- See Note [Ambiguous syntactic categories] -- -- This newtype is required to avoid impredicative types in monadic @@ -1659,10 +1347,7 @@ checkMonadComp = do -- P (forall b. DisambECP b => PV (Located b)) -- newtype ECP = - ECP { runECP_PV :: forall b. DisambECP b => PV (Located b) } - -runECP_P :: DisambECP b => ECP -> P (Located b) -runECP_P p = runPV (runECP_PV p) + ECP { unECP :: forall b. DisambECP b => PV (Located b) } ecpFromExp :: LHsExpr GhcPs -> ECP ecpFromExp a = ECP (ecpFromExp' a) @@ -2053,9 +1738,145 @@ mkPatRec (unLoc -> PatBuilderVar c) (HsRecFields fs dd) mkPatRec p _ = addFatalError (getLoc p) $ text "Not a record constructor:" <+> ppr p +-- | Disambiguate constructs that may appear when we do not know +-- ahead of time whether we are parsing a type or a newtype/data constructor. +-- +-- See Note [Ambiguous syntactic categories] for the general idea. +-- +-- See Note [Parsing data constructors is hard] for the specific issue this +-- particular class is solving. +-- +class DisambTD b where + -- | Process the head of a type-level function/constructor application, + -- i.e. the @H@ in @H a b c at . + mkHsAppTyHeadPV :: LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f x@ (function application or prefix data constructor). + mkHsAppTyPV :: Located b -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f \@t@ (visible kind application) + mkHsAppKindTyPV :: Located b -> SrcSpan -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @f \# x@ (infix operator) + mkHsOpTyPV :: LHsType GhcPs -> Located RdrName -> LHsType GhcPs -> PV (Located b) + -- | Disambiguate @{-\# UNPACK \#-} t@ (unpack/nounpack pragma) + mkUnpackednessPV :: Located UnpackednessPragma -> Located b -> PV (Located b) + +instance DisambTD (HsType GhcPs) where + mkHsAppTyHeadPV = return + mkHsAppTyPV t1 t2 = return (mkHsAppTy t1 t2) + mkHsAppKindTyPV t l_at ki = return (mkHsAppKindTy l' t ki) + where l' = combineSrcSpans l_at (getLoc ki) + mkHsOpTyPV t1 op t2 = return (mkLHsOpTy t1 op t2) + mkUnpackednessPV = addUnpackednessP + +-- | An accumulator to build a prefix data constructor, +-- e.g. when parsing @MkT A B C@, the accumulator will evolve as follows: +-- +-- @ +-- 1. PrefixDataConBuilder [] MkT +-- 2. PrefixDataConBuilder [A] MkT +-- 3. PrefixDataConBuilder [A, B] MkT +-- 4. PrefixDataConBuilder [A, B, C] MkT +-- @ +-- +-- There are two reasons we have a separate builder type instead of using +-- @HsConDeclDetails GhcPs@ directly: +-- +-- 1. It's faster, because 'OrdList' gives us constant-time snoc. +-- 2. Having a separate type helps ensure that we don't forget to finalize a +-- 'RecTy' into a 'RecCon' (we do that in 'dataConBuilderDetails'). +-- +-- See Note [PatBuilder] for another builder type used in the parser. +-- Here the technique is similar, but the motivation is different. +data DataConBuilder + = PrefixDataConBuilder + (OrdList (LHsType GhcPs)) -- Data constructor fields + (Located RdrName) -- Data constructor name + | InfixDataConBuilder + (LHsType GhcPs) -- LHS field + (Located RdrName) -- Data constructor name + (LHsType GhcPs) -- RHS field + +dataConBuilderCon :: DataConBuilder -> Located RdrName +dataConBuilderCon (PrefixDataConBuilder _ dc) = dc +dataConBuilderCon (InfixDataConBuilder _ dc _) = dc + +dataConBuilderDetails :: DataConBuilder -> HsConDeclDetails GhcPs + +-- Detect when the record syntax is used: +-- data T = MkT { ... } +dataConBuilderDetails (PrefixDataConBuilder flds _) + | [L l_t (HsRecTy _ fields)] <- toList flds + = RecCon (L l_t fields) + +-- Normal prefix constructor, e.g. data T = MkT A B C +dataConBuilderDetails (PrefixDataConBuilder flds _) + = PrefixCon (map hsLinear (toList flds)) + +-- Infix constructor, e.g. data T = Int :! Bool +dataConBuilderDetails (InfixDataConBuilder lhs _ rhs) + = InfixCon (hsLinear lhs) (hsLinear rhs) + +instance Outputable DataConBuilder where + ppr (PrefixDataConBuilder flds data_con) = + hang (ppr data_con) 2 (sep (map ppr (toList flds))) + ppr (InfixDataConBuilder lhs data_con rhs) = + ppr lhs <+> ppr data_con <+> ppr rhs + +instance DisambTD DataConBuilder where + mkHsAppTyHeadPV = tyToDataConBuilder + + mkHsAppTyPV (L l (PrefixDataConBuilder flds fn)) t = + return $ + L (combineSrcSpans l (getLoc t)) + (PrefixDataConBuilder (flds `snocOL` t) fn) + mkHsAppTyPV (L _ InfixDataConBuilder{}) _ = + -- This case is impossible because of the way + -- the grammar in Parser.y is written (see infixtype/ftype). + panic "mkHsAppTyPV: InfixDataConBuilder" + + mkHsAppKindTyPV lhs l_at ki = + addFatalError l_at $ + hang (text "Unexpected kind application in a data/newtype declaration:") 2 + (ppr lhs <+> text "@" <> ppr ki) + + mkHsOpTyPV lhs (L l_tc tc) rhs = do + check_no_ops (unLoc rhs) -- check the RHS because parsing type operators is right-associative + data_con <- eitherToP $ tyConToDataCon l_tc tc + return $ L l (InfixDataConBuilder lhs data_con rhs) + where + l = combineLocs lhs rhs + check_no_ops (HsBangTy _ _ t) = check_no_ops (unLoc t) + check_no_ops (HsOpTy{}) = + addError l $ + hang (text "Cannot parse an infix data constructor in a data/newtype declaration:") + 2 (ppr lhs <+> ppr tc <+> ppr rhs) + check_no_ops _ = return () + + mkUnpackednessPV unpk constr_stuff + | L _ (InfixDataConBuilder lhs data_con rhs) <- constr_stuff + = -- When the user writes data T = {-# UNPACK #-} Int :+ Bool + -- we apply {-# UNPACK #-} to the LHS + do lhs' <- addUnpackednessP unpk lhs + let l = combineLocs unpk constr_stuff + return $ L l (InfixDataConBuilder lhs' data_con rhs) + | otherwise = + do addError (getLoc unpk) $ + text "{-# UNPACK #-} cannot be applied to a data constructor." + return constr_stuff + +tyToDataConBuilder :: LHsType GhcPs -> PV (Located DataConBuilder) +tyToDataConBuilder (L l (HsTyVar _ NotPromoted (L _ v))) = do + data_con <- eitherToP $ tyConToDataCon l v + return $ L l (PrefixDataConBuilder nilOL data_con) +tyToDataConBuilder (L l (HsTupleTy _ HsBoxedOrConstraintTuple ts)) = do + let data_con = L l (getRdrName (tupleDataCon Boxed (length ts))) + return $ L l (PrefixDataConBuilder (toOL ts) data_con) +tyToDataConBuilder t = + addFatalError (getLoc t) $ + hang (text "Cannot parse data constructor in a data/newtype declaration:") + 2 (ppr t) + {- Note [Ambiguous syntactic categories] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - There are places in the grammar where we do not know whether we are parsing an expression or a pattern without unlimited lookahead (which we do not have in 'happy'): @@ -2150,6 +1971,21 @@ position and shadows the previous $1. We can do this because internally is to be able to write (sLL $1 $>) later on. The alternative would be to write this as ($1 >>= \ fresh_name -> ...), but then we couldn't refer to the last fresh name as $>. + +Finally, we instantiate the polymorphic type to a concrete one, and run the +parser-validator, for example: + + stmt :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } + e_stmt :: { LStmt GhcPs (LHsExpr GhcPs) } + : stmt {% runPV $1 } + +In e_stmt, three things happen: + + 1. we instantiate: b ~ HsExpr GhcPs + 2. we embed the PV computation into P by using runPV + 3. we run validation by using a monadic production, {% ... } + +At this point the ambiguity is resolved. -} @@ -2306,7 +2142,6 @@ Alternative VII, a product type We could avoid the intermediate representation of Alternative VI by parsing into a product of interpretations directly: - -- See Note [Parser-Validator] type ExpCmdPat = ( PV (LHsExpr GhcPs) , PV (LHsCmd GhcPs) , PV (LHsPat GhcPs) ) @@ -2326,7 +2161,6 @@ We can easily define ambiguities between arbitrary subsets of interpretations. For example, when we know ahead of type that only an expression or a command is possible, but not a pattern, we can use a smaller type: - -- See Note [Parser-Validator] type ExpCmd = (PV (LHsExpr GhcPs), PV (LHsCmd GhcPs)) checkExpOf2 (e, _) = e -- interpret as an expression @@ -2809,7 +2643,7 @@ warnStarBndr span = addWarning Opt_WarnStarBinder span msg <+> text "modules with StarIsType," $$ text " including the definition module, you must qualify it." -failOpFewArgs :: Located RdrName -> P a +failOpFewArgs :: MonadP m => Located RdrName -> m a failOpFewArgs (L loc op) = do { star_is_type <- getBit StarIsTypeBit ; let msg = too_few $$ starInfo star_is_type op @@ -2836,7 +2670,25 @@ data PV_Accum = data PV_Result a = PV_Ok PV_Accum a | PV_Failed PV_Accum --- See Note [Parser-Validator] +-- During parsing, we make use of several monadic effects: reporting parse errors, +-- accumulating warnings, adding API annotations, and checking for extensions. These +-- effects are captured by the 'MonadP' type class. +-- +-- Sometimes we need to postpone some of these effects to a later stage due to +-- ambiguities described in Note [Ambiguous syntactic categories]. +-- We could use two layers of the P monad, one for each stage: +-- +-- abParser :: forall x. DisambAB x => P (P x) +-- +-- The outer layer of P consumes the input and builds the inner layer, which +-- validates the input. But this type is not particularly helpful, as it obscures +-- the fact that the inner layer of P never consumes any input. +-- +-- For clarity, we introduce the notion of a parser-validator: a parser that does +-- not consume any input, but may fail or use other effects. Thus we have: +-- +-- abParser :: forall x. DisambAB x => P (PV x) +-- newtype PV a = PV { unPV :: PV_Context -> PV_Accum -> PV_Result a } instance Functor PV where @@ -2910,36 +2762,6 @@ instance MonadP PV where PV_Ok acc' () addAnnotation _ _ _ = return () -{- Note [Parser-Validator] -~~~~~~~~~~~~~~~~~~~~~~~~~~ - -When resolving ambiguities, we need to postpone failure to make a choice later. -For example, if we have ambiguity between some A and B, our parser could be - - abParser :: P (Maybe A, Maybe B) - -This way we can represent four possible outcomes of parsing: - - (Just a, Nothing) -- definitely A - (Nothing, Just b) -- definitely B - (Just a, Just b) -- either A or B - (Nothing, Nothing) -- neither A nor B - -However, if we want to report informative parse errors, accumulate warnings, -and add API annotations, we are better off using 'P' instead of 'Maybe': - - abParser :: P (P A, P B) - -So we have an outer layer of P that consumes the input and builds the inner -layer, which validates the input. - -For clarity, we introduce the notion of a parser-validator: a parser that does -not consume any input, but may fail or use other effects. Thus we have: - - abParser :: P (PV A, PV B) - --} - {- Note [Parser-Validator Hint] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A PV computation is parametrized by a hint for error messages, which can be set ===================================== compiler/GHC/Platform/Profile.hs ===================================== @@ -13,8 +13,6 @@ import GHC.Prelude import GHC.Platform import GHC.Platform.Ways -import Data.Set - -- | A platform profile fully describes the kind of objects that are generated -- for a platform. -- @@ -22,8 +20,8 @@ import Data.Set -- (profiling, debug, dynamic) also modify the ABI. -- data Profile = Profile - { profilePlatform :: !Platform -- ^ Platform - , profileWays :: !(Set Way) -- ^ Ways + { profilePlatform :: !Platform -- ^ Platform + , profileWays :: !Ways -- ^ Ways } -- | Get platform constants ===================================== compiler/GHC/Platform/Ways.hs ===================================== @@ -20,6 +20,7 @@ -- this compilation. module GHC.Platform.Ways ( Way(..) + , Ways , hasWay , allowed_combination , wayGeneralFlags @@ -61,12 +62,14 @@ data Way | WayDyn -- ^ Dynamic linking deriving (Eq, Ord, Show) +type Ways = Set Way + -- | Test if a ways is enabled -hasWay :: Set Way -> Way -> Bool +hasWay :: Ways -> Way -> Bool hasWay ws w = Set.member w ws -- | Check if a combination of ways is allowed -allowed_combination :: Set Way -> Bool +allowed_combination :: Ways -> Bool allowed_combination ways = not disallowed where disallowed = or [ hasWay ways x && hasWay ways y @@ -76,13 +79,13 @@ allowed_combination ways = not disallowed couples = [] -- we don't have any disallowed combination of ways nowadays -- | Unique tag associated to a list of ways -waysTag :: Set Way -> String +waysTag :: Ways -> String waysTag = concat . intersperse "_" . map wayTag . Set.toAscList -- | Unique build-tag associated to a list of ways -- -- RTS only ways are filtered out because they have no impact on the build. -waysBuildTag :: Set Way -> String +waysBuildTag :: Ways -> String waysBuildTag ws = waysTag (Set.filter (not . wayRTSOnly) ws) @@ -195,7 +198,7 @@ foreign import ccall unsafe "rts_isDynamic" rtsIsDynamicIO :: IO Int -- | Return host "full" ways (i.e. ways that have an impact on the compilation, -- not RTS only ways). These ways must be used when compiling codes targeting -- the internal interpreter. -hostFullWays :: Set Way +hostFullWays :: Ways hostFullWays = Set.unions [ if hostIsDynamic then Set.singleton WayDyn else Set.empty , if hostIsProfiled then Set.singleton WayProf else Set.empty ===================================== compiler/GHC/Tc/TyCl.hs ===================================== @@ -74,7 +74,6 @@ import GHC.Types.SrcLoc import GHC.Data.List.SetOps import GHC.Driver.Session import GHC.Types.Unique -import GHC.Core.ConLike( ConLike(..) ) import GHC.Types.Basic import qualified GHC.LanguageExtensions as LangExt @@ -3819,15 +3818,14 @@ checkValidTyCl tc where recovery_code -- See Note [Recover from validity error] = do { traceTc "Aborted validity for tycon" (ppr tc) - ; return (concatMap mk_fake_tc $ - ATyCon tc : implicitTyConThings tc) } + ; return (map mk_fake_tc $ + tc : child_tycons tc) } - mk_fake_tc (ATyCon tc) - | isClassTyCon tc = [tc] -- Ugh! Note [Recover from validity error] - | otherwise = [makeRecoveryTyCon tc] - mk_fake_tc (AConLike (RealDataCon dc)) - = [makeRecoveryTyCon (promoteDataCon dc)] - mk_fake_tc _ = [] + mk_fake_tc tc + | isClassTyCon tc = tc -- Ugh! Note [Recover from validity error] + | otherwise = makeRecoveryTyCon tc + + child_tycons tc = tyConATs tc ++ map promoteDataCon (tyConDataCons tc) {- Note [Recover from validity error] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -3852,6 +3850,8 @@ Some notes: and so there was an internal error when we met 'MkT' in the body of 'S'. + Similarly for associated types. + * Painfully, we *don't* want to do this for classes. Consider tcfail041: class (?x::Int) => C a where ... @@ -3864,6 +3864,14 @@ Some notes: This is really bogus; now we have in scope a Class that is invalid in some way, with unknown downstream consequences. A better alternative might be to make a fake class TyCon. A job for another day. + +* Previously, we used implicitTyConThings to snaffle out the parts + to add to the context. The problem is that this also grabs data con + wrapper Ids. These could be filtered out. But, painfully, getting + the wrapper Ids checks the DataConRep, and forcing the DataConRep + can panic if there is a levity-polymorphic argument. This is #18534. + We don't need the wrapper Ids here anyway. So the code just takes what + it needs, via child_tycons. -} ------------------------- @@ -4050,8 +4058,13 @@ checkValidDataCon dflags existential_ok tc con -- regardless of whether or not UnliftedNewtypes is enabled. A -- later check in checkNewDataCon handles this, producing a -- better error message than checkForLevPoly would. - ; unless (isNewTyCon tc) - (mapM_ (checkForLevPoly empty) (map scaledThing $ dataConOrigArgTys con)) + ; unless (isNewTyCon tc) $ + checkNoErrs $ + mapM_ (checkForLevPoly empty) (map scaledThing $ dataConOrigArgTys con) + -- the checkNoErrs is to prevent a panic in isVanillaDataCon + -- (called a a few lines down), which can fall over if there is a + -- bang on a levity-polymorphic argument. This is #18534, + -- typecheck/should_fail/T18534 -- Extra checks for newtype data constructors. Importantly, these -- checks /must/ come before the call to checkValidType below. This ===================================== compiler/GHC/Unit/State.hs ===================================== @@ -315,7 +315,7 @@ instance Monoid UnitVisibility where -- | Unit configuration data UnitConfig = UnitConfig { unitConfigPlatformArchOS :: !ArchOS -- ^ Platform arch and OS - , unitConfigWays :: !(Set Way) -- ^ Ways to use + , unitConfigWays :: !Ways -- ^ Ways to use , unitConfigProgramName :: !String -- ^ Name of the compiler (e.g. "GHC", "GHCJS"). Used to fetch environment -- variables such as "GHC[JS]_PACKAGE_PATH". ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.hs ===================================== @@ -0,0 +1,50 @@ +{-# LANGUAGE TemplateHaskell, ExplicitForAll, PolyKinds #-} + +module Main where + +import Language.Haskell.TH (runQ) +import GHC.Types.Basic +import GHC.ThToHs +import GHC.Driver.Session +import GHC.Core.TyCo.Ppr +import GHC.Utils.Outputable +import GHC.Tc.Module +import GHC.Tc.Utils.Zonk +import GHC.Utils.Error +import GHC.Driver.Types +import GHC +import qualified GHC.LanguageExtensions as LangExt + +import Data.Either (fromRight) +import Control.Monad.IO.Class (liftIO) +import System.Environment (getArgs) + +main :: IO () +main = do + [libdir] <- getArgs + runGhc (Just libdir) $ do + initial_dflags <- getSessionDynFlags + setSessionDynFlags $ initial_dflags + `dopt_set` Opt_D_ppr_debug + `gopt_set` Opt_SuppressUniques + `gopt_set` Opt_SuppressModulePrefixes + `gopt_set` Opt_SuppressVarKinds + `xopt_set` LangExt.KindSignatures + `xopt_set` LangExt.PolyKinds + `xopt_set` LangExt.RankNTypes + hsc_env <- getSession + let dflags = hsc_dflags hsc_env + liftIO $ do + th_t <- runQ [t| forall k {j}. + forall (a :: k) (b :: j) -> + () |] + let hs_t = fromRight (error "convertToHsType") $ + convertToHsType Generated noSrcSpan th_t + ((warnings, errors), mres) <- + tcRnType hsc_env SkolemiseFlexi True hs_t + case mres of + Nothing -> do + printBagOfErrors dflags warnings + printBagOfErrors dflags errors + Just (t, _) -> do + putStrLn $ showSDoc dflags (debugPprType t) ===================================== testsuite/tests/ghc-api/T18522-dbg-ppr.stdout ===================================== @@ -0,0 +1,2 @@ +forall k{tv}[tv] {j{tv}[tv]}. +forall a{tv}[tv] b{tv}[tv] -> (){(w) tc} ===================================== testsuite/tests/ghc-api/all.T ===================================== @@ -20,3 +20,7 @@ test('T9015', extra_run_opts('"' + config.libdir + '"'), test('T11579', extra_run_opts('"' + config.libdir + '"'), compile_and_run, ['-package ghc']) test('T12099', normal, compile_and_run, ['-package ghc']) +test('T18522-dbg-ppr', + extra_run_opts('"' + config.libdir + '"'), + compile_and_run, + ['-package ghc']) ===================================== testsuite/tests/parser/should_fail/T12045d.stderr ===================================== @@ -1,4 +1,3 @@ T12045d.hs:11:16: error: - Unexpected kind application in a data/newtype declaration: - MkD @Nat Bool + Unexpected kind application in a data/newtype declaration: MkD @Nat ===================================== testsuite/tests/parser/should_fail/strictnessDataCon_B.stderr ===================================== @@ -1,3 +1,2 @@ -strictnessDataCon_B.hs:1:27: error: - {-# UNPACK #-} cannot appear inside a type. +strictnessDataCon_B.hs:1:42: error: parse error on input ‘}’ ===================================== testsuite/tests/parser/should_fail/typeops_A.stderr ===================================== @@ -1,2 +1,3 @@ -typeops_A.hs:1:12: error: Operator applied to too few arguments: + +typeops_A.hs:2:1: error: + parse error (possibly incorrect indentation or mismatched brackets) ===================================== testsuite/tests/parser/should_fail/typeops_C.stderr ===================================== @@ -1,2 +1,2 @@ -typeops_C.hs:1:12: error: Operator applied to too few arguments: + +typeops_C.hs:1:14: error: Operator applied to too few arguments: + ===================================== testsuite/tests/parser/should_fail/unpack_empty_type.stderr ===================================== @@ -1,3 +1,2 @@ -unpack_empty_type.hs:3:19: error: - {-# UNPACK #-} must be applied to a type. +unpack_empty_type.hs:3:34: error: parse error on input ‘}’ ===================================== testsuite/tests/parser/should_fail/unpack_inside_type.stderr ===================================== @@ -1,3 +1,7 @@ unpack_inside_type.hs:3:25: error: - {-# UNPACK #-} cannot appear inside a type. + • Unexpected UNPACK annotation: {-# UNPACK #-}Int + UNPACK annotation cannot appear nested inside a type + • In the first argument of ‘Maybe’, namely ‘({-# UNPACK #-}Int)’ + In the type ‘Maybe ({-# UNPACK #-}Int)’ + In the definition of data constructor ‘T’ ===================================== testsuite/tests/polykinds/T18522-ppr.script ===================================== @@ -0,0 +1,4 @@ +:set -XPolyKinds -XDataKinds -XRankNTypes -XTypeFamilies +import Data.Kind (Type) +type family T :: forall k -> (k ~ k) => forall j -> k -> j -> Type +:k T ===================================== testsuite/tests/polykinds/T18522-ppr.stdout ===================================== @@ -0,0 +1 @@ +T :: forall k -> (k ~ k) => forall j -> k -> j -> * ===================================== testsuite/tests/polykinds/all.T ===================================== @@ -223,3 +223,4 @@ test('T18300', normal, compile_fail, ['']) test('T18451', normal, compile_fail, ['']) test('T18451a', normal, compile_fail, ['']) test('T18451b', normal, compile_fail, ['']) +test('T18522-ppr', normal, ghci_script, ['T18522-ppr.script']) ===================================== testsuite/tests/typecheck/should_fail/T18534.hs ===================================== @@ -0,0 +1,7 @@ +{-# LANGUAGE PolyKinds #-} + +module Test where + +import GHC.Exts + +data Test (a :: TYPE r) = Test !a ===================================== testsuite/tests/typecheck/should_fail/T18534.stderr ===================================== @@ -0,0 +1,7 @@ + +T18534.hs:7:27: error: + • A levity-polymorphic type is not allowed here: + Type: a + Kind: TYPE r + • In the definition of data constructor ‘Test’ + In the data type declaration for ‘Test’ ===================================== testsuite/tests/typecheck/should_fail/all.T ===================================== @@ -578,3 +578,4 @@ test('T18357', normal, compile_fail, ['']) test('T18357a', normal, compile_fail, ['']) test('T18357b', normal, compile_fail, ['']) test('T18455', normal, compile_fail, ['']) +test('T18534', normal, compile_fail, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/54d6387a65b6ca1b1d32891b697ec368fbb38eb3...63348155404c64334fa864454132630f9d2a4d7f -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/54d6387a65b6ca1b1d32891b697ec368fbb38eb3...63348155404c64334fa864454132630f9d2a4d7f You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 18:01:18 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 14:01:18 -0400 Subject: [Git][ghc/ghc][wip/T18527] 3 commits: nativeGen: One approach to fix #18527 Message-ID: <5f2c456e38d2b_80b3f848705b1446855787@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18527 at Glasgow Haskell Compiler / GHC Commits: a647bae8 by Ben Gamari at 2020-08-06T14:01:09-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - b4c85427 by Ben Gamari at 2020-08-06T14:01:09-04:00 testsuite: Add test fo #18527 - - - - - 78dd499b by Ben Gamari at 2020-08-06T14:01:09-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - 7 changed files: - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - + testsuite/tests/codeGen/should_run/T18527.hs - + testsuite/tests/codeGen/should_run/T18527.stdout - + testsuite/tests/codeGen/should_run/T18527FFI.c - testsuite/tests/codeGen/should_run/all.T - testsuite/tests/concurrent/prog001/all.T Changes: ===================================== compiler/GHC/Cmm/MachOp.hs ===================================== @@ -45,6 +45,9 @@ native code generators to handle. Most operations are parameterised by the 'Width' that they operate on. Some operations have separate signed and unsigned versions, and float and integer versions. + +Note that there are variety of places in the native code generator where we +assume that the code produced for a MachOp does not introduce new blocks. -} data MachOp ===================================== compiler/GHC/CmmToAsm/X86/CodeGen.hs ===================================== @@ -287,11 +287,11 @@ we construct as a separate data type and the actual control flow graph in the co Instead we now return the new basic block if a statement causes a change in the current block and use the block for all following statements. -For this reason genCCall is also split into two parts. -One for calls which *won't* change the basic blocks in -which successive instructions will be placed. -A different one for calls which *are* known to change the -basic block. +For this reason genCCall is also split into two parts. One for calls which +*won't* change the basic blocks in which successive instructions will be +placed (since they only evaluate CmmExpr, which can only contain MachOps, which +cannot introduce basic blocks in their lowerings). A different one for calls +which *are* known to change the basic block. -} @@ -1028,6 +1028,9 @@ getRegister' _ is32Bit (CmmMachOp mop [x, y]) = do -- dyadic MachOps tmp. This is likely to be better, because the reg alloc can eliminate this reg->reg move here (it won't eliminate the other one, because the move is into the fixed %ecx). + * in the case of C calls the use of ecx here can interfere with arguments. + We avoid this with the hack described in Note [Evaluate C-call + arguments before placing in destination registers] -} shift_code width instr x y{-amount-} = do x_code <- getAnyReg x @@ -2022,6 +2025,7 @@ genCCall is32Bit (PrimTarget (MO_AtomicRMW width amop)) arg <- getNewRegNat format arg_code <- getAnyReg n platform <- ncgPlatform <$> getConfig + let dst_r = getRegisterReg platform (CmmLocal dst) (code, lbl) <- op_code dst_r arg amode return (addr_code `appOL` arg_code arg `appOL` code, Just lbl) @@ -2667,9 +2671,12 @@ genCCall' _ is32Bit target dest_regs args bid = do return code _ -> panic "genCCall: Wrong number of arguments/results for imul2" - _ -> if is32Bit - then genCCall32' target dest_regs args - else genCCall64' target dest_regs args + _ -> do + (instrs0, args') <- evalArgs bid args + instrs1 <- if is32Bit + then genCCall32' target dest_regs args' + else genCCall64' target dest_regs args' + return (instrs0 `appOL` instrs1) where divOp1 platform signed width results [arg_x, arg_y] = divOp platform signed width results Nothing arg_x arg_y @@ -2732,6 +2739,83 @@ genCCall' _ is32Bit target dest_regs args bid = do addSubIntC _ _ _ _ _ _ _ _ = panic "genCCall: Wrong number of arguments/results for addSubIntC" +{- +Note [Evaluate C-call arguments before placing in destination registers] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When producing code for C calls we must take care when placing arguments +in their final registers. Specifically, we must ensure that temporary register +usage due to evaluation of one argument does not clobber a register in which we +already placed a previous argument (e.g. as the code generation logic for +MO_Shl can clobber %rcx due to x86 instruction limitations). + +This is precisely what happened in #18527. Consider this C--: + + (result::I64) = call "ccall" doSomething(_s2hp::I64, 2244, _s2hq::I64, _s2hw::I64 | (1 << _s2hz::I64)); + +Here we are calling the C function `doSomething` with three arguments, the last +involving a non-trivial expression involving MO_Shl. In this case the NCG could +naively generate the following assembly (where $tmp denotes some temporary +register and $argN denotes the register for argument N, as dictated by the +platform's calling convention): + + mov _s2hp, $arg1 # place first argument + mov _s2hq, $arg2 # place second argument + + # Compute 1 << _s2hz + mov _s2hz, %rcx + shl %cl, $tmp + + # Compute (_s2hw | (1 << _s2hz)) + mov _s2hw, $arg3 + or $tmp, $arg3 + + # Perform the call + call func + +This code is outright broken on Windows which assigns $arg1 to %rcx. This means +that the evaluation of the last argument clobbers the first argument. + +To avoid this we use a rather awful hack: when producing code for a C call with +at least one non-trivial argument, we first evaluate all of the arguments into +local registers before moving them into their final calling-convention-defined +homes. This is performed by 'evalArgs'. Here we define "non-trivial" to be an +expression which might contain a MachOp since these are the only cases which +might clobber registers. Furthermore, we use a conservative approximation of +this condition (only looking at the top-level of CmmExprs) to avoid spending +too much effort trying to decide whether we want to take the fast path. + +Note that this hack *also* applies to calls to out-of-line PrimTargets (which +are lowered via a C call) since outOfLineCmmOp produces the call via +(stmtToInstrs (CmmUnsafeForeignCall ...)), which will ultimately end up +back in genCCall{32,64}. +-} + +-- | See Note [Evaluate C-call arguments before placing in destination registers] +evalArgs :: BlockId -> [CmmActual] -> NatM (InstrBlock, [CmmActual]) +evalArgs bid actuals + | any mightContainMachOp actuals = do + regs_blks <- mapM evalArg actuals + return (concatOL $ map fst regs_blks, map snd regs_blks) + | otherwise = return (nilOL, actuals) + where + mightContainMachOp (CmmReg _) = False + mightContainMachOp (CmmRegOff _ _) = False + mightContainMachOp (CmmLit _) = False + mightContainMachOp _ = True + + evalArg :: CmmActual -> NatM (InstrBlock, CmmExpr) + evalArg actual = do + platform <- getPlatform + lreg <- newLocalReg $ cmmExprType platform actual + (instrs, bid') <- stmtToInstrs bid $ CmmAssign (CmmLocal lreg) actual + -- The above assignment shouldn't change the current block + MASSERT(isNothing bid') + return (instrs, CmmReg $ CmmLocal lreg) + + newLocalReg :: CmmType -> NatM LocalReg + newLocalReg ty = LocalReg <$> getUniqueM <*> pure ty + -- Note [DIV/IDIV for bytes] -- -- IDIV reminder: ===================================== testsuite/tests/codeGen/should_run/T18527.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +module Main where + +import Data.Bits (setBit) +import Data.Word (Word32) +import Data.Int (Int64) + +main :: IO () +main = offending 100 0 1 + +offending :: Int64 -> Int64 -> Word32 -> IO () +offending h i id = do + oldMask <- sendMessage h (2245) i 0 + let newMask = setBit oldMask (fromIntegral id) + sendMessage h (2244) i newMask + return () + +foreign import ccall "func" + sendMessage :: Int64 -> Word32 -> Int64 -> Int64 -> IO Int64 ===================================== testsuite/tests/codeGen/should_run/T18527.stdout ===================================== @@ -0,0 +1,3 @@ +ffi call +ffi call + ===================================== testsuite/tests/codeGen/should_run/T18527FFI.c ===================================== @@ -0,0 +1,14 @@ +#include +#include + +int64_t func(int64_t a, uint32_t b, int64_t c, int64_t d) { + printf("ffi call"); + if (a == 1) { + printf(" with corrupted convention\n"); + } + else { + printf("\n"); + } + return 0; +} + ===================================== testsuite/tests/codeGen/should_run/all.T ===================================== @@ -207,3 +207,4 @@ test('T16449_2', exit_code(0), compile_and_run, ['']) test('T16846', [only_ways(['optasm']), exit_code(1)], compile_and_run, ['']) test('T17920', cmm_src, compile_and_run, ['']) +test('T18527', normal, compile_and_run, ['T18527FFI.c']) ===================================== testsuite/tests/concurrent/prog001/all.T ===================================== @@ -16,4 +16,4 @@ test('concprog001', [extra_files(['Arithmetic.hs', 'Converter.hs', 'Mult.hs', 'S when(fast(), skip), only_ways(['threaded2']), fragile(16604), run_timeout_multiplier(2)], - multimod_compile_and_run, ['Mult', '']) + multimod_compile_and_run, ['Mult', '-package ghc']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2e68f1bdd3f39522c8b27ab91e46c967fd805d1e...78dd499beaafe7d85d70d52d1eafeb87c9fa3c30 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2e68f1bdd3f39522c8b27ab91e46c967fd805d1e...78dd499beaafe7d85d70d52d1eafeb87c9fa3c30 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 18:05:16 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 14:05:16 -0400 Subject: [Git][ghc/ghc][wip/T18527] 2 commits: testsuite: Add test for #18527 Message-ID: <5f2c465c57b05_80b3f849c1caa1068562d9@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18527 at Glasgow Haskell Compiler / GHC Commits: 187e2267 by Ben Gamari at 2020-08-06T14:05:06-04:00 testsuite: Add test for #18527 - - - - - b39b0afb by Ben Gamari at 2020-08-06T14:05:10-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - 5 changed files: - + testsuite/tests/codeGen/should_run/T18527.hs - + testsuite/tests/codeGen/should_run/T18527.stdout - + testsuite/tests/codeGen/should_run/T18527FFI.c - testsuite/tests/codeGen/should_run/all.T - testsuite/tests/concurrent/prog001/all.T Changes: ===================================== testsuite/tests/codeGen/should_run/T18527.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +module Main where + +import Data.Bits (setBit) +import Data.Word (Word32) +import Data.Int (Int64) + +main :: IO () +main = offending 100 0 1 + +offending :: Int64 -> Int64 -> Word32 -> IO () +offending h i id = do + oldMask <- sendMessage h (2245) i 0 + let newMask = setBit oldMask (fromIntegral id) + sendMessage h (2244) i newMask + return () + +foreign import ccall "func" + sendMessage :: Int64 -> Word32 -> Int64 -> Int64 -> IO Int64 ===================================== testsuite/tests/codeGen/should_run/T18527.stdout ===================================== @@ -0,0 +1,3 @@ +ffi call +ffi call + ===================================== testsuite/tests/codeGen/should_run/T18527FFI.c ===================================== @@ -0,0 +1,14 @@ +#include +#include + +int64_t func(int64_t a, uint32_t b, int64_t c, int64_t d) { + printf("ffi call"); + if (a == 1) { + printf(" with corrupted convention\n"); + } + else { + printf("\n"); + } + return 0; +} + ===================================== testsuite/tests/codeGen/should_run/all.T ===================================== @@ -207,3 +207,4 @@ test('T16449_2', exit_code(0), compile_and_run, ['']) test('T16846', [only_ways(['optasm']), exit_code(1)], compile_and_run, ['']) test('T17920', cmm_src, compile_and_run, ['']) +test('T18527', normal, compile_and_run, ['T18527FFI.c']) ===================================== testsuite/tests/concurrent/prog001/all.T ===================================== @@ -16,4 +16,4 @@ test('concprog001', [extra_files(['Arithmetic.hs', 'Converter.hs', 'Mult.hs', 'S when(fast(), skip), only_ways(['threaded2']), fragile(16604), run_timeout_multiplier(2)], - multimod_compile_and_run, ['Mult', '']) + multimod_compile_and_run, ['Mult', '-package ghc']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/78dd499beaafe7d85d70d52d1eafeb87c9fa3c30...b39b0afbe90ae48c34e326fd7cf85b651ff36e17 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/78dd499beaafe7d85d70d52d1eafeb87c9fa3c30...b39b0afbe90ae48c34e326fd7cf85b651ff36e17 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 18:05:32 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 14:05:32 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/backports Message-ID: <5f2c466cb2d4b_80b3f8496224a70685674e@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/backports at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/backports You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 21:09:40 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 17:09:40 -0400 Subject: [Git][ghc/ghc][wip/T18527] 3 commits: nativeGen: One approach to fix #18527 Message-ID: <5f2c7194a36_80b3f849c1caa1068988d3@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18527 at Glasgow Haskell Compiler / GHC Commits: 188575e0 by Ben Gamari at 2020-08-06T17:09:35-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 8248146b by Ben Gamari at 2020-08-06T17:09:35-04:00 testsuite: Add test for #18527 - - - - - 50202106 by Ben Gamari at 2020-08-06T17:09:35-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - 7 changed files: - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - + testsuite/tests/codeGen/should_run/T18527.hs - + testsuite/tests/codeGen/should_run/T18527.stdout - + testsuite/tests/codeGen/should_run/T18527FFI.c - testsuite/tests/codeGen/should_run/all.T - testsuite/tests/concurrent/prog001/all.T Changes: ===================================== compiler/GHC/Cmm/MachOp.hs ===================================== @@ -45,6 +45,9 @@ native code generators to handle. Most operations are parameterised by the 'Width' that they operate on. Some operations have separate signed and unsigned versions, and float and integer versions. + +Note that there are variety of places in the native code generator where we +assume that the code produced for a MachOp does not introduce new blocks. -} data MachOp ===================================== compiler/GHC/CmmToAsm/X86/CodeGen.hs ===================================== @@ -287,11 +287,11 @@ we construct as a separate data type and the actual control flow graph in the co Instead we now return the new basic block if a statement causes a change in the current block and use the block for all following statements. -For this reason genCCall is also split into two parts. -One for calls which *won't* change the basic blocks in -which successive instructions will be placed. -A different one for calls which *are* known to change the -basic block. +For this reason genCCall is also split into two parts. One for calls which +*won't* change the basic blocks in which successive instructions will be +placed (since they only evaluate CmmExpr, which can only contain MachOps, which +cannot introduce basic blocks in their lowerings). A different one for calls +which *are* known to change the basic block. -} @@ -1028,6 +1028,9 @@ getRegister' _ is32Bit (CmmMachOp mop [x, y]) = do -- dyadic MachOps tmp. This is likely to be better, because the reg alloc can eliminate this reg->reg move here (it won't eliminate the other one, because the move is into the fixed %ecx). + * in the case of C calls the use of ecx here can interfere with arguments. + We avoid this with the hack described in Note [Evaluate C-call + arguments before placing in destination registers] -} shift_code width instr x y{-amount-} = do x_code <- getAnyReg x @@ -2022,6 +2025,7 @@ genCCall is32Bit (PrimTarget (MO_AtomicRMW width amop)) arg <- getNewRegNat format arg_code <- getAnyReg n platform <- ncgPlatform <$> getConfig + let dst_r = getRegisterReg platform (CmmLocal dst) (code, lbl) <- op_code dst_r arg amode return (addr_code `appOL` arg_code arg `appOL` code, Just lbl) @@ -2667,9 +2671,12 @@ genCCall' _ is32Bit target dest_regs args bid = do return code _ -> panic "genCCall: Wrong number of arguments/results for imul2" - _ -> if is32Bit - then genCCall32' target dest_regs args - else genCCall64' target dest_regs args + _ -> do + (instrs0, args') <- evalArgs bid args + instrs1 <- if is32Bit + then genCCall32' target dest_regs args' + else genCCall64' target dest_regs args' + return (instrs0 `appOL` instrs1) where divOp1 platform signed width results [arg_x, arg_y] = divOp platform signed width results Nothing arg_x arg_y @@ -2732,6 +2739,83 @@ genCCall' _ is32Bit target dest_regs args bid = do addSubIntC _ _ _ _ _ _ _ _ = panic "genCCall: Wrong number of arguments/results for addSubIntC" +{- +Note [Evaluate C-call arguments before placing in destination registers] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When producing code for C calls we must take care when placing arguments +in their final registers. Specifically, we must ensure that temporary register +usage due to evaluation of one argument does not clobber a register in which we +already placed a previous argument (e.g. as the code generation logic for +MO_Shl can clobber %rcx due to x86 instruction limitations). + +This is precisely what happened in #18527. Consider this C--: + + (result::I64) = call "ccall" doSomething(_s2hp::I64, 2244, _s2hq::I64, _s2hw::I64 | (1 << _s2hz::I64)); + +Here we are calling the C function `doSomething` with three arguments, the last +involving a non-trivial expression involving MO_Shl. In this case the NCG could +naively generate the following assembly (where $tmp denotes some temporary +register and $argN denotes the register for argument N, as dictated by the +platform's calling convention): + + mov _s2hp, $arg1 # place first argument + mov _s2hq, $arg2 # place second argument + + # Compute 1 << _s2hz + mov _s2hz, %rcx + shl %cl, $tmp + + # Compute (_s2hw | (1 << _s2hz)) + mov _s2hw, $arg3 + or $tmp, $arg3 + + # Perform the call + call func + +This code is outright broken on Windows which assigns $arg1 to %rcx. This means +that the evaluation of the last argument clobbers the first argument. + +To avoid this we use a rather awful hack: when producing code for a C call with +at least one non-trivial argument, we first evaluate all of the arguments into +local registers before moving them into their final calling-convention-defined +homes. This is performed by 'evalArgs'. Here we define "non-trivial" to be an +expression which might contain a MachOp since these are the only cases which +might clobber registers. Furthermore, we use a conservative approximation of +this condition (only looking at the top-level of CmmExprs) to avoid spending +too much effort trying to decide whether we want to take the fast path. + +Note that this hack *also* applies to calls to out-of-line PrimTargets (which +are lowered via a C call) since outOfLineCmmOp produces the call via +(stmtToInstrs (CmmUnsafeForeignCall ...)), which will ultimately end up +back in genCCall{32,64}. +-} + +-- | See Note [Evaluate C-call arguments before placing in destination registers] +evalArgs :: BlockId -> [CmmActual] -> NatM (InstrBlock, [CmmActual]) +evalArgs bid actuals + | any mightContainMachOp actuals = do + regs_blks <- mapM evalArg actuals + return (concatOL $ map fst regs_blks, map snd regs_blks) + | otherwise = return (nilOL, actuals) + where + mightContainMachOp (CmmReg _) = False + mightContainMachOp (CmmRegOff _ _) = False + mightContainMachOp (CmmLit _) = False + mightContainMachOp _ = True + + evalArg :: CmmActual -> NatM (InstrBlock, CmmExpr) + evalArg actual = do + platform <- getPlatform + lreg <- newLocalReg $ cmmExprType platform actual + (instrs, bid1) <- stmtToInstrs bid $ CmmAssign (CmmLocal lreg) actual + -- The above assignment shouldn't change the current block + MASSERT(isNothing bid1) + return (instrs, CmmReg $ CmmLocal lreg) + + newLocalReg :: CmmType -> NatM LocalReg + newLocalReg ty = LocalReg <$> getUniqueM <*> pure ty + -- Note [DIV/IDIV for bytes] -- -- IDIV reminder: ===================================== testsuite/tests/codeGen/should_run/T18527.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +module Main where + +import Data.Bits (setBit) +import Data.Word (Word32) +import Data.Int (Int64) + +main :: IO () +main = offending 100 0 1 + +offending :: Int64 -> Int64 -> Word32 -> IO () +offending h i id = do + oldMask <- sendMessage h (2245) i 0 + let newMask = setBit oldMask (fromIntegral id) + sendMessage h (2244) i newMask + return () + +foreign import ccall "func" + sendMessage :: Int64 -> Word32 -> Int64 -> Int64 -> IO Int64 ===================================== testsuite/tests/codeGen/should_run/T18527.stdout ===================================== @@ -0,0 +1,3 @@ +ffi call +ffi call + ===================================== testsuite/tests/codeGen/should_run/T18527FFI.c ===================================== @@ -0,0 +1,14 @@ +#include +#include + +int64_t func(int64_t a, uint32_t b, int64_t c, int64_t d) { + printf("ffi call"); + if (a == 1) { + printf(" with corrupted convention\n"); + } + else { + printf("\n"); + } + return 0; +} + ===================================== testsuite/tests/codeGen/should_run/all.T ===================================== @@ -207,3 +207,4 @@ test('T16449_2', exit_code(0), compile_and_run, ['']) test('T16846', [only_ways(['optasm']), exit_code(1)], compile_and_run, ['']) test('T17920', cmm_src, compile_and_run, ['']) +test('T18527', normal, compile_and_run, ['T18527FFI.c']) ===================================== testsuite/tests/concurrent/prog001/all.T ===================================== @@ -16,4 +16,4 @@ test('concprog001', [extra_files(['Arithmetic.hs', 'Converter.hs', 'Mult.hs', 'S when(fast(), skip), only_ways(['threaded2']), fragile(16604), run_timeout_multiplier(2)], - multimod_compile_and_run, ['Mult', '']) + multimod_compile_and_run, ['Mult', '-package ghc']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b39b0afbe90ae48c34e326fd7cf85b651ff36e17...50202106a0e378d669ad53d476909b6bc7ac1618 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b39b0afbe90ae48c34e326fd7cf85b651ff36e17...50202106a0e378d669ad53d476909b6bc7ac1618 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 21:10:09 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 17:10:09 -0400 Subject: [Git][ghc/ghc][wip/backports] 2 commits: nativeGen: One approach to fix #18527 Message-ID: <5f2c71b1f3532_80b3f8496224a7068994da@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: b260f31f by Ben Gamari at 2020-08-06T17:10:00-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. (cherry picked from commit a647bae8518e96156eb7775c4cede52b69f711d7) - - - - - 44f958c8 by Ben Gamari at 2020-08-06T17:10:00-04:00 testsuite: Add test for #18527 - - - - - 6 changed files: - compiler/cmm/CmmMachOp.hs - compiler/nativeGen/X86/CodeGen.hs - + testsuite/tests/codeGen/should_run/T18527.hs - + testsuite/tests/codeGen/should_run/T18527.stdout - + testsuite/tests/codeGen/should_run/T18527FFI.c - testsuite/tests/codeGen/should_run/all.T Changes: ===================================== compiler/cmm/CmmMachOp.hs ===================================== @@ -43,6 +43,9 @@ native code generators to handle. Most operations are parameterised by the 'Width' that they operate on. Some operations have separate signed and unsigned versions, and float and integer versions. + +Note that there are variety of places in the native code generator where we +assume that the code produced for a MachOp does not introduce new blocks. -} data MachOp ===================================== compiler/nativeGen/X86/CodeGen.hs ===================================== @@ -292,11 +292,11 @@ we construct as a separate data type and the actual control flow graph in the co Instead we now return the new basic block if a statement causes a change in the current block and use the block for all following statements. -For this reason genCCall is also split into two parts. -One for calls which *won't* change the basic blocks in -which successive instructions will be placed. -A different one for calls which *are* known to change the -basic block. +For this reason genCCall is also split into two parts. One for calls which +*won't* change the basic blocks in which successive instructions will be +placed (since they only evaluate CmmExpr, which can only contain MachOps, which +cannot introduce basic blocks in their lowerings). A different one for calls +which *are* known to change the basic block. -} @@ -1037,6 +1037,9 @@ getRegister' _ is32Bit (CmmMachOp mop [x, y]) = do -- dyadic MachOps tmp. This is likely to be better, because the reg alloc can eliminate this reg->reg move here (it won't eliminate the other one, because the move is into the fixed %ecx). + * in the case of C calls the use of ecx here can interfere with arguments. + We avoid this with the hack described in Note [Evaluate C-call + arguments before placing in destination registers] -} shift_code width instr x y{-amount-} = do x_code <- getAnyReg x @@ -2614,9 +2617,12 @@ genCCall' _ is32Bit target dest_regs args bid = do return code _ -> panic "genCCall: Wrong number of arguments/results for mul2" - _ -> if is32Bit - then genCCall32' dflags target dest_regs args - else genCCall64' dflags target dest_regs args + _ -> do + (instrs0, args') <- evalArgs bid args + instrs1 <- if is32Bit + then genCCall32' dflags target dest_regs args' + else genCCall64' dflags target dest_regs args' + return (instrs0 `appOL` instrs1) where divOp1 platform signed width results [arg_x, arg_y] = divOp platform signed width results Nothing arg_x arg_y @@ -2679,6 +2685,83 @@ genCCall' _ is32Bit target dest_regs args bid = do addSubIntC _ _ _ _ _ _ _ _ = panic "genCCall: Wrong number of arguments/results for addSubIntC" +{- +Note [Evaluate C-call arguments before placing in destination registers] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When producing code for C calls we must take care when placing arguments +in their final registers. Specifically, we must ensure that temporary register +usage due to evaluation of one argument does not clobber a register in which we +already placed a previous argument (e.g. as the code generation logic for +MO_Shl can clobber %rcx due to x86 instruction limitations). + +This is precisely what happened in #18527. Consider this C--: + + (result::I64) = call "ccall" doSomething(_s2hp::I64, 2244, _s2hq::I64, _s2hw::I64 | (1 << _s2hz::I64)); + +Here we are calling the C function `doSomething` with three arguments, the last +involving a non-trivial expression involving MO_Shl. In this case the NCG could +naively generate the following assembly (where $tmp denotes some temporary +register and $argN denotes the register for argument N, as dictated by the +platform's calling convention): + + mov _s2hp, $arg1 # place first argument + mov _s2hq, $arg2 # place second argument + + # Compute 1 << _s2hz + mov _s2hz, %rcx + shl %cl, $tmp + + # Compute (_s2hw | (1 << _s2hz)) + mov _s2hw, $arg3 + or $tmp, $arg3 + + # Perform the call + call func + +This code is outright broken on Windows which assigns $arg1 to %rcx. This means +that the evaluation of the last argument clobbers the first argument. + +To avoid this we use a rather awful hack: when producing code for a C call with +at least one non-trivial argument, we first evaluate all of the arguments into +local registers before moving them into their final calling-convention-defined +homes. This is performed by 'evalArgs'. Here we define "non-trivial" to be an +expression which might contain a MachOp since these are the only cases which +might clobber registers. Furthermore, we use a conservative approximation of +this condition (only looking at the top-level of CmmExprs) to avoid spending +too much effort trying to decide whether we want to take the fast path. + +Note that this hack *also* applies to calls to out-of-line PrimTargets (which +are lowered via a C call) since outOfLineCmmOp produces the call via +(stmtToInstrs (CmmUnsafeForeignCall ...)), which will ultimately end up +back in genCCall{32,64}. +-} + +-- | See Note [Evaluate C-call arguments before placing in destination registers] +evalArgs :: BlockId -> [CmmActual] -> NatM (InstrBlock, [CmmActual]) +evalArgs bid actuals + | any mightContainMachOp actuals = do + regs_blks <- mapM evalArg actuals + return (concatOL $ map fst regs_blks, map snd regs_blks) + | otherwise = return (nilOL, actuals) + where + mightContainMachOp (CmmReg _) = False + mightContainMachOp (CmmRegOff _ _) = False + mightContainMachOp (CmmLit _) = False + mightContainMachOp _ = True + + evalArg :: CmmActual -> NatM (InstrBlock, CmmExpr) + evalArg actual = do + dflags <- getDynFlags + lreg <- newLocalReg $ cmmExprType dflags actual + (instrs, bid1) <- stmtToInstrs bid $ CmmAssign (CmmLocal lreg) actual + -- The above assignment shouldn't change the current block + MASSERT(isNothing bid1) + return (instrs, CmmReg $ CmmLocal lreg) + + newLocalReg :: CmmType -> NatM LocalReg + newLocalReg ty = LocalReg <$> getUniqueM <*> pure ty + -- Note [DIV/IDIV for bytes] -- -- IDIV reminder: ===================================== testsuite/tests/codeGen/should_run/T18527.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +module Main where + +import Data.Bits (setBit) +import Data.Word (Word32) +import Data.Int (Int64) + +main :: IO () +main = offending 100 0 1 + +offending :: Int64 -> Int64 -> Word32 -> IO () +offending h i id = do + oldMask <- sendMessage h (2245) i 0 + let newMask = setBit oldMask (fromIntegral id) + sendMessage h (2244) i newMask + return () + +foreign import ccall "func" + sendMessage :: Int64 -> Word32 -> Int64 -> Int64 -> IO Int64 ===================================== testsuite/tests/codeGen/should_run/T18527.stdout ===================================== @@ -0,0 +1,3 @@ +ffi call +ffi call + ===================================== testsuite/tests/codeGen/should_run/T18527FFI.c ===================================== @@ -0,0 +1,14 @@ +#include +#include + +int64_t func(int64_t a, uint32_t b, int64_t c, int64_t d) { + printf("ffi call"); + if (a == 1) { + printf(" with corrupted convention\n"); + } + else { + printf("\n"); + } + return 0; +} + ===================================== testsuite/tests/codeGen/should_run/all.T ===================================== @@ -205,3 +205,4 @@ test('T16449_2', exit_code(0), compile_and_run, ['']) test('T16846', [only_ways(['optasm']), exit_code(1)], compile_and_run, ['']) test('T17920', cmm_src, compile_and_run, ['']) +test('T18527', normal, compile_and_run, ['T18527FFI.c']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b19b690b10b0d39d8e412039425b8cfc2e6b78ca...44f958c869f88936db583a0e7edfa47a67cdf8f9 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b19b690b10b0d39d8e412039425b8cfc2e6b78ca...44f958c869f88936db583a0e7edfa47a67cdf8f9 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 21:51:02 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 17:51:02 -0400 Subject: [Git][ghc/ghc][wip/T18126] users guide: Fix various markup issues Message-ID: <5f2c7b46c4fb2_80b3f849a25e6906904599@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18126 at Glasgow Haskell Compiler / GHC Commits: 567c4d03 by GHC GitLab CI at 2020-08-06T21:50:36+00:00 users guide: Fix various markup issues - - - - - 4 changed files: - docs/users_guide/8.12.1-notes.rst - docs/users_guide/exts/explicit_forall.rst - docs/users_guide/exts/instances.rst - docs/users_guide/ghci.rst Changes: ===================================== docs/users_guide/8.12.1-notes.rst ===================================== @@ -49,9 +49,10 @@ Highlights - GHC now relies on a new "ghc-bignum" package to provide Integer/Natural implementations. This package supports the following backends: - - gmp: adapted from integer-gmp package that was used before - - native: new Haskell implementation, faster than integer-simple which is - not used anymore + + - gmp: adapted from integer-gmp package that was used before + - native: new Haskell implementation, faster than integer-simple which is + not used anymore - All backends now use the same representation for big numbers (the one that was previously used only by integer-gmp). It led to several compiler ===================================== docs/users_guide/exts/explicit_forall.rst ===================================== @@ -37,7 +37,7 @@ Notes: instance forall a. Eq a => Eq [a] where ... - Note that the use of ``forall``s in instance declarations is somewhat + Note that the use of ``forall``\ s in instance declarations is somewhat restricted in comparison to other types. For example, instance declarations are not allowed to contain nested ``forall``s. See :ref:`formal-instance-syntax` for more information. ===================================== docs/users_guide/exts/instances.rst ===================================== @@ -144,8 +144,8 @@ Where: ``forall a. a`` and ``Eq a => a`` are not legal ``btype``s, but ``(forall a. a)`` and ``(Eq a => a)`` are legal. - ``ctype`` is a ``btype`` that has no restrictions on an outermost - ``forall``/``=>``, so ``forall a. a`` and ``Eq a => a`` are legal ``ctype``s. -- ``arg_type`` is a type that is not allowed to have ``forall``s or ``=>``s + ``forall``/``=>``, so ``forall a. a`` and ``Eq a => a`` are legal ``ctype``\ s. +- ``arg_type`` is a type that is not allowed to have ``forall``s or ``=>``\ s - ``prefix_cls_tycon`` is a class type constructor written prefix (e.g., ``Show`` or ``(&&&)``), while ``infix_cls_tycon`` is a class type constructor written infix (e.g., ```Show``` or ``&&&``). @@ -155,7 +155,7 @@ implementation details of GHC's parser (such as the placement of Haddock comments), but it is sufficient to attain an understanding of what is syntactically allowed. Some further various observations about this grammar: -- Instance declarations are not allowed to be declared with nested ``forall``s +- Instance declarations are not allowed to be declared with nested ``forall``\ s or ``=>``s. For example, this would be rejected: :: instance forall a. forall b. C (Either a b) where ... ===================================== docs/users_guide/ghci.rst ===================================== @@ -2564,6 +2564,7 @@ commonly used commands. be used. .. code-block:: none + ghci>:set -XDataKinds -XUndecidableInstances ghci>import GHC.TypeLits ghci>class A a @@ -2974,6 +2975,11 @@ commonly used commands. *X> :type length length :: Foldable t => t a -> Int +.. ghci-cmd:: :type +v; ⟨expression⟩ + + Infers and prints the type of ⟨expression⟩, binding inferred type variables + with :ref:`*specified* visibility `. + .. ghci-cmd:: :type +d; ⟨expression⟩ Infers and prints the type of ⟨expression⟩, instantiating *all* the forall View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/567c4d0316c3b75403854b38afe730c9a640327a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/567c4d0316c3b75403854b38afe730c9a640327a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 23:01:40 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 19:01:40 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/drop-testsuite-io-manager Message-ID: <5f2c8bd485e3_80b3f846910c0c06924742@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/drop-testsuite-io-manager at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/drop-testsuite-io-manager You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 23:24:27 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 06 Aug 2020 19:24:27 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 7 commits: users-guide: Rename 8.12 to 9.0 Message-ID: <5f2c912bd7bbb_80b3f849a25e69069298ce@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: c456bab3 by Takenobu Tani at 2020-08-06T18:51:14+09:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 2aacccb9 by Vladislav Zavialov at 2020-08-06T19:24:23-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 183de579 by Vladislav Zavialov at 2020-08-06T19:24:23-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - b54e8a5a by Vladislav Zavialov at 2020-08-06T19:24:23-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - b221579f by Vladislav Zavialov at 2020-08-06T19:24:23-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - e855d06e by Richard Eisenberg at 2020-08-06T19:24:24-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 1aff3f96 by Sylvain Henry at 2020-08-06T19:24:25-04:00 Use a type alias for Ways - - - - - 30 changed files: - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Platform/Profile.hs - compiler/GHC/Platform/Ways.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Unit/State.hs - docs/users_guide/8.12.1-notes.rst → docs/users_guide/9.0.1-notes.rst - docs/users_guide/exts/lambda_case.rst - docs/users_guide/exts/lexical_negation.rst - docs/users_guide/exts/linear_types.rst - docs/users_guide/exts/negative_literals.rst - docs/users_guide/exts/qualified_do.rst - docs/users_guide/release-notes.rst - docs/users_guide/using-warnings.rst - + testsuite/tests/ghc-api/T18522-dbg-ppr.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.stdout - testsuite/tests/ghc-api/all.T - testsuite/tests/parser/should_fail/T12045d.stderr - testsuite/tests/parser/should_fail/strictnessDataCon_B.stderr - testsuite/tests/parser/should_fail/typeops_A.stderr - testsuite/tests/parser/should_fail/typeops_C.stderr - testsuite/tests/parser/should_fail/unpack_empty_type.stderr - testsuite/tests/parser/should_fail/unpack_inside_type.stderr - + testsuite/tests/polykinds/T18522-ppr.script - + testsuite/tests/polykinds/T18522-ppr.stdout - testsuite/tests/polykinds/all.T - + testsuite/tests/typecheck/should_fail/T18534.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/63348155404c64334fa864454132630f9d2a4d7f...1aff3f9692f4a0c7754ca00aa0ff07ba8659b1c3 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/63348155404c64334fa864454132630f9d2a4d7f...1aff3f9692f4a0c7754ca00aa0ff07ba8659b1c3 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 23:45:04 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 19:45:04 -0400 Subject: [Git][ghc/ghc][wip/T18291] 36 commits: Fix typo in haddock Message-ID: <5f2c96009c78b_80b3f848a372f8c69408c@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18291 at Glasgow Haskell Compiler / GHC Commits: 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 17b8468d by Ben Gamari at 2020-08-06T19:44:59-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 58c31aa7 by Ben Gamari at 2020-08-06T19:44:59-04:00 testsuite: Add test for #18291 - - - - - 30 changed files: - aclocal.m4 - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/Dwarf/Types.hs - compiler/GHC/CmmToAsm/PIC.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/Lint.hs - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Utils.hs - compiler/GHC/Core/Ppr/TyThing.hs - compiler/GHC/CoreToStg/Prep.hs - compiler/GHC/Driver/CodeOutput.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Make.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore.hs - compiler/GHC/HsToCore/Coverage.hs - compiler/GHC/Iface/Make.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/47d3683d752a340ff89a2097307e0042d30ba603...58c31aa741110776e9357077ab9d3d1f64472838 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/47d3683d752a340ff89a2097307e0042d30ba603...58c31aa741110776e9357077ab9d3d1f64472838 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 6 23:47:14 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 19:47:14 -0400 Subject: [Git][ghc/ghc][master] 7 commits: Grammar for types and data/newtype constructors Message-ID: <5f2c968263d62_80b3f848c1e06f469415c@gitlab.haskell.org.mail> Ben Gamari pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 30 changed files: - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Platform/Profile.hs - compiler/GHC/Platform/Ways.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Unit/State.hs - docs/users_guide/8.12.1-notes.rst → docs/users_guide/9.0.1-notes.rst - docs/users_guide/exts/lambda_case.rst - docs/users_guide/exts/lexical_negation.rst - docs/users_guide/exts/linear_types.rst - docs/users_guide/exts/negative_literals.rst - docs/users_guide/exts/qualified_do.rst - docs/users_guide/release-notes.rst - docs/users_guide/using-warnings.rst - + testsuite/tests/ghc-api/T18522-dbg-ppr.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.stdout - testsuite/tests/ghc-api/all.T - testsuite/tests/parser/should_fail/T12045d.stderr - testsuite/tests/parser/should_fail/strictnessDataCon_B.stderr - testsuite/tests/parser/should_fail/typeops_A.stderr - testsuite/tests/parser/should_fail/typeops_C.stderr - testsuite/tests/parser/should_fail/unpack_empty_type.stderr - testsuite/tests/parser/should_fail/unpack_inside_type.stderr - + testsuite/tests/polykinds/T18522-ppr.script - + testsuite/tests/polykinds/T18522-ppr.stdout - testsuite/tests/polykinds/all.T - + testsuite/tests/typecheck/should_fail/T18534.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fbcb886d503dd7aaebc4c40e59615068b3fd0bd7...9570c21295a2b4a1d1e40939869124f0b9b9bf91 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fbcb886d503dd7aaebc4c40e59615068b3fd0bd7...9570c21295a2b4a1d1e40939869124f0b9b9bf91 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 00:00:13 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 20:00:13 -0400 Subject: [Git][ghc/ghc][wip/bump-win32] 54 commits: Improve NegativeLiterals (#18022, GHC Proposal #344) Message-ID: <5f2c998d9f5ec_80b10e6f9b469638bf@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/bump-win32 at Glasgow Haskell Compiler / GHC Commits: aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - c403006c by Ben Gamari at 2020-08-06T19:59:05-04:00 Bump Win32 and process submodules - - - - - 30 changed files: - .gitlab-ci.yml - aclocal.m4 - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/Dwarf/Types.hs - compiler/GHC/CmmToAsm/PIC.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/Opt/OccurAnal.hs - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/SetLevels.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Monad.hs - compiler/GHC/Core/Opt/Simplify/Utils.hs - compiler/GHC/Core/Ppr/TyThing.hs - compiler/GHC/Core/SimpleOpt.hs - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/CodeOutput.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Make.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/Hs/Type.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f314afd7006118885ea7c7d1991f89812f67e3e3...c403006c13f161881e50ccbb9c6761fcbfc4ce03 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f314afd7006118885ea7c7d1991f89812f67e3e3...c403006c13f161881e50ccbb9c6761fcbfc4ce03 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 00:01:46 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 20:01:46 -0400 Subject: [Git][ghc/ghc][wip/explicit-perf-baseline] 52 commits: Drop 32-bit Windows support Message-ID: <5f2c99ea6ee0e_80b3f8486a507f46964439@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/explicit-perf-baseline at Glasgow Haskell Compiler / GHC Commits: aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - bbde6ea0 by Ben Gamari at 2020-08-06T20:00:52-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - 3c26eb6b by Ben Gamari at 2020-08-06T20:00:52-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 30 changed files: - .gitlab-ci.yml - aclocal.m4 - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/Dwarf/Types.hs - compiler/GHC/CmmToAsm/PIC.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/Opt/OccurAnal.hs - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/SetLevels.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Monad.hs - compiler/GHC/Core/Opt/Simplify/Utils.hs - compiler/GHC/Core/Ppr/TyThing.hs - compiler/GHC/Core/SimpleOpt.hs - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/CodeOutput.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Make.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/Hs/Type.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/df50f2f7cfffeff6d3be7e45151dc82013c0db66...3c26eb6b32b646f36751dc8bb9691b7802df7e94 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/df50f2f7cfffeff6d3be7e45151dc82013c0db66...3c26eb6b32b646f36751dc8bb9691b7802df7e94 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 00:08:55 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 20:08:55 -0400 Subject: [Git][ghc/ghc][wip/explicit-perf-baseline] gitlab-ci: Use MR base commit as performance baseline Message-ID: <5f2c9b975e3cd_80b3f8496224a7069674ba@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/explicit-perf-baseline at Glasgow Haskell Compiler / GHC Commits: 4b91e5ed by Ben Gamari at 2020-08-06T20:08:45-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 4 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - hadrian/src/Settings/Builders/RunTest.hs - testsuite/mk/test.mk Changes: ===================================== .gitlab-ci.yml ===================================== @@ -26,12 +26,28 @@ stages: - testing # head.hackage correctness and compiler performance testing - deploy # push documentation +# Note [The CI Story] +# ~~~~~~~~~~~~~~~~~~~ +# +# There are two different types of pipelines: +# +# - marge-bot merges to `master`. Here we perform an exhaustive validation +# across all of the platforms which we support. In addition, we push +# performance metric notes upstream, providing a persistent record of the +# performance characteristics of the compiler. +# +# - merge requests. Here we perform a slightly less exhaustive battery of +# testing. Namely we omit some configurations (e.g. the unregisterised job). +# These use the merge request's base commit for performance metric +# comparisons. +# + workflow: - # N.B.Don't run on wip/ branches, instead on run on merge requests. + # N.B. Don't run on wip/ branches, instead on run on merge requests. rules: - if: $CI_MERGE_REQUEST_ID - if: $CI_COMMIT_TAG - - if: '$CI_COMMIT_BRANCH == "master"' + - if: '$CI_COMMIT_BRANCH == "wip/marge_bot_batch_merge_job"' - if: '$CI_COMMIT_BRANCH =~ /ghc-[0.9]+\.[0-9]+/' - if: '$CI_PIPELINE_SOURCE == "web"' ===================================== .gitlab/ci.sh ===================================== @@ -363,6 +363,13 @@ function push_perf_notes() { "$TOP/.gitlab/test-metrics.sh" push } +# Figure out which commit should be used by the testsuite driver as a +# performance baseline. See Note [The CI Story]. +function determine_metric_baseline() { + export PERF_BASELINE_COMMIT="$(git merge-base $CI_MERGE_REQUEST_TARGET_BRANCH_NAME HEAD)" + info "Using $PERF_BASELINE_COMMIT for performance metric baseline..." +} + function test_make() { run "$MAKE" test_bindist TEST_PREP=YES run "$MAKE" V=0 test \ ===================================== hadrian/src/Settings/Builders/RunTest.hs ===================================== @@ -78,6 +78,7 @@ runTestBuilderArgs = builder RunTest ? do <*> (maybe False (=="YES") <$> lookupEnv "OS") (testEnv, testMetricsFile) <- expr . liftIO $ (,) <$> lookupEnv "TEST_ENV" <*> lookupEnv "METRICS_FILE" + perfBaseline <- expr . liftIO $ lookupEnv "PERF_BASELINE_COMMIT" threads <- shakeThreads <$> expr getShakeOptions os <- getTestSetting TestHostOS @@ -141,6 +142,9 @@ runTestBuilderArgs = builder RunTest ? do , arg "--config", arg $ "timeout_prog=" ++ show (top -/- timeoutProg) , arg "--config", arg $ "stats_files_dir=" ++ statsFilesDir , arg $ "--threads=" ++ show threads + , case perfBaseline of + Just commit | not (null commit) -> arg ("--perf-baseline=" ++ show commit) + _ -> mempty , emitWhenSet testEnv $ \env -> arg ("--test-env=" ++ show env) , emitWhenSet testMetricsFile $ \file -> arg ("--metrics-file=" ++ file) , getTestArgs -- User-provided arguments from command line. ===================================== testsuite/mk/test.mk ===================================== @@ -232,6 +232,10 @@ ifneq "$(VERBOSE)" "" RUNTEST_OPTS += --verbose=$(VERBOSE) endif +ifneq "$(PERF_TEST_BASELINE_COMMIT)" "" +RUNTEST_OPTS += --perf-baseline=$(PERF_TEST_BASELINE_COMMIT) +endif + ifeq "$(SKIP_PERF_TESTS)" "YES" RUNTEST_OPTS += --skip-perf-tests endif View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4b91e5edf64363eff7d087731c2806464033447c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4b91e5edf64363eff7d087731c2806464033447c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 00:33:51 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 20:33:51 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/perf-ci Message-ID: <5f2ca16f23556_80b8ca3ed069680db@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/perf-ci at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/perf-ci You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 01:10:13 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 06 Aug 2020 21:10:13 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18118 Message-ID: <5f2ca9f5c29fd_80b3f848a386fc86969837@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T18118 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18118 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 04:41:45 2020 From: gitlab at gitlab.haskell.org (Moritz Angermann) Date: Fri, 07 Aug 2020 00:41:45 -0400 Subject: [Git][ghc/ghc][wip/angerman/cross-test-suite] 10 commits: Grammar for types and data/newtype constructors Message-ID: <5f2cdb89ede9f_80b3f848a372f8c7002474@gitlab.haskell.org.mail> Moritz Angermann pushed to branch wip/angerman/cross-test-suite at Glasgow Haskell Compiler / GHC Commits: 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 9ebe8f64 by Moritz Angermann at 2020-08-07T12:25:33+08:00 Cross Test Suite This introduces the ability to test cross compilers agains the testsuite as well. This is achieved by disabling some tests that make no sense in a cross compilation setting, or simply can not be made to cross compile proplery. The fundamental idea is that we can run produced binaries through a TEST_WRAPPER, if provided. This could be qemu in user mode, or wine, or nodejs, or anything that could transparrently run the executable build product on the build machine. - - - - - 305f4d94 by Moritz Angermann at 2020-08-07T12:33:12+08:00 Clean up (1) - - - - - 8f57ef59 by Moritz Angermann at 2020-08-07T12:41:30+08:00 Try no-op _TEST_WRAPPER - - - - - 30 changed files: - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Platform/Profile.hs - compiler/GHC/Platform/Ways.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Unit/State.hs - docs/users_guide/8.12.1-notes.rst → docs/users_guide/9.0.1-notes.rst - docs/users_guide/exts/lambda_case.rst - docs/users_guide/exts/lexical_negation.rst - docs/users_guide/exts/linear_types.rst - docs/users_guide/exts/negative_literals.rst - docs/users_guide/exts/qualified_do.rst - docs/users_guide/release-notes.rst - docs/users_guide/using-warnings.rst - libraries/base/tests/IO/Makefile - libraries/base/tests/IO/T12010/Makefile - libraries/base/tests/Numeric/all.T - libraries/base/tests/all.T - testsuite/config/ghc - + testsuite/driver/id - testsuite/driver/testglobals.py - testsuite/driver/testlib.py - testsuite/mk/boilerplate.mk - testsuite/mk/ghc-config.hs - testsuite/mk/test.mk - testsuite/tests/annotations/should_fail/all.T - testsuite/tests/annotations/should_run/all.T The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c168a2692af42e77d3a7dc9d76d86e50c68da7f9...8f57ef5962d0d60b89d7a85e5aed7bbaedd715ff -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c168a2692af42e77d3a7dc9d76d86e50c68da7f9...8f57ef5962d0d60b89d7a85e5aed7bbaedd715ff You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 04:48:33 2020 From: gitlab at gitlab.haskell.org (Moritz Angermann) Date: Fri, 07 Aug 2020 00:48:33 -0400 Subject: [Git][ghc/ghc][wip/angerman/cross-test-suite] . Message-ID: <5f2cdd21a2f97_80b3f848a372f8c700456@gitlab.haskell.org.mail> Moritz Angermann pushed to branch wip/angerman/cross-test-suite at Glasgow Haskell Compiler / GHC Commits: 9e856205 by Moritz Angermann at 2020-08-07T12:48:11+08:00 . - - - - - 1 changed file: - testsuite/driver/testlib.py Changes: ===================================== testsuite/driver/testlib.py ===================================== @@ -1693,7 +1693,7 @@ def simple_run(name: TestName, way: WayName, prog: str, extra_run_opts: str) -> if config.test_wrapper is None: test_wrapper = "" else: - test_wrapper = "{config.test_wrapper} ".format(**locals) + test_wrapper = "{config.test_wrapper} ".format(**locals()) # if cmd looks like we want to execute something, run it through # the command wrapper. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9e856205588945585903eb26a9d970c350aa09a8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9e856205588945585903eb26a9d970c350aa09a8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 06:24:42 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 07 Aug 2020 02:24:42 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 14 commits: Grammar for types and data/newtype constructors Message-ID: <5f2cf3aabb287_80b3f8496224a7070185fc@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 786ca395 by Cale Gibbard at 2020-08-07T02:24:39-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - 758cb7a2 by Cale Gibbard at 2020-08-07T02:24:39-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 1e242fd8 by Ben Gamari at 2020-08-07T02:24:39-04:00 cmm: Clean up Notes a bit - - - - - c3ce0089 by Ben Gamari at 2020-08-07T02:24:39-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 8e48ae7b by Ben Gamari at 2020-08-07T02:24:39-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 2891a91d by Ben Gamari at 2020-08-07T02:24:39-04:00 testsuite: Add test for #18527 - - - - - 2edc326e by Ben Gamari at 2020-08-07T02:24:39-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - 30 changed files: - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Expr.hs-boot - compiler/GHC/HsToCore/ListComp.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Platform/Profile.hs - compiler/GHC/Platform/Ways.hs - compiler/GHC/StgToCmm/Foreign.hs - compiler/GHC/StgToCmm/Utils.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Unit/State.hs - docs/users_guide/8.12.1-notes.rst → docs/users_guide/9.0.1-notes.rst - docs/users_guide/exts/lambda_case.rst - docs/users_guide/exts/lexical_negation.rst - docs/users_guide/exts/linear_types.rst - docs/users_guide/exts/negative_literals.rst - docs/users_guide/exts/qualified_do.rst - docs/users_guide/release-notes.rst - docs/users_guide/using-warnings.rst - includes/stg/MachRegs.h - + testsuite/tests/codeGen/should_run/T18527.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1aff3f9692f4a0c7754ca00aa0ff07ba8659b1c3...2edc326efadb1d9cb9e412ecbee47cc9bf3d9b31 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1aff3f9692f4a0c7754ca00aa0ff07ba8659b1c3...2edc326efadb1d9cb9e412ecbee47cc9bf3d9b31 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 06:32:53 2020 From: gitlab at gitlab.haskell.org (Moritz Angermann) Date: Fri, 07 Aug 2020 02:32:53 -0400 Subject: [Git][ghc/ghc][wip/angerman/cross-test-suite] :fire: Message-ID: <5f2cf5957492c_80b3f848c1e06f4702236b@gitlab.haskell.org.mail> Moritz Angermann pushed to branch wip/angerman/cross-test-suite at Glasgow Haskell Compiler / GHC Commits: d14ac10b by Moritz Angermann at 2020-08-07T14:32:34+08:00 :fire: - - - - - 2 changed files: - testsuite/tests/rts/T1791/all.T - testsuite/tests/rts/T9579/all.T Changes: ===================================== testsuite/tests/rts/T1791/all.T ===================================== @@ -1,4 +1,4 @@ test('T1791', [ exit_code(0), extra_clean(['T1791.hi', 'T1791']) ], run_command, - ['''"$MAKE" -s --no-print-directory T1791 >/dev/null && "$TEST_WRAPPER" ./T1791 +RTS -M8M''']) + ['''"$MAKE" -s --no-print-directory T1791 >/dev/null && $_TEST_WRAPPER ./T1791 +RTS -M8M''']) ===================================== testsuite/tests/rts/T9579/all.T ===================================== @@ -10,7 +10,7 @@ def T9579_run_test(binName, expExitCode): # 4. replace actual number with NUM testCommandTemplate = """ $MAKE -s --no-print-directory T9579_{binName} \ - && ( ( "$TEST_WRAPPER" ./T9579_{binName} 2>&1; echo $?) \ + && ( ( $_TEST_WRAPPER ./T9579_{binName} 2>&1; echo $?) \ | sed -e 's/[0-9]* bytes/NUM bytes/g' ) \ """ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d14ac10bb3d5e09c1cae67a921ea0304bc08ff90 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d14ac10bb3d5e09c1cae67a921ea0304bc08ff90 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 12:31:42 2020 From: gitlab at gitlab.haskell.org (Josh Meredith) Date: Fri, 07 Aug 2020 08:31:42 -0400 Subject: [Git][ghc/ghc][wip/pluginExtFields] 9 commits: Grammar for types and data/newtype constructors Message-ID: <5f2d49ae17a8b_80b3f8496224a70705608a@gitlab.haskell.org.mail> Josh Meredith pushed to branch wip/pluginExtFields at Glasgow Haskell Compiler / GHC Commits: 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 8287a53f by Josh Meredith at 2020-08-07T08:31:40-04:00 Add machinery for plugins to write data to extensible interface fields - - - - - 22587e7f by Josh Meredith at 2020-08-07T08:31:40-04:00 Add function to remove plugin interface fields - - - - - 30 changed files: - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/IfaceToCore.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Platform/Profile.hs - compiler/GHC/Platform/Ways.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Unit/State.hs - docs/users_guide/8.12.1-notes.rst → docs/users_guide/9.0.1-notes.rst - docs/users_guide/exts/lambda_case.rst - docs/users_guide/exts/lexical_negation.rst - docs/users_guide/exts/linear_types.rst - docs/users_guide/exts/negative_literals.rst - docs/users_guide/exts/qualified_do.rst - docs/users_guide/release-notes.rst - docs/users_guide/using-warnings.rst - + testsuite/tests/ghc-api/T18522-dbg-ppr.hs - + testsuite/tests/ghc-api/T18522-dbg-ppr.stdout - testsuite/tests/ghc-api/all.T - testsuite/tests/parser/should_fail/T12045d.stderr - testsuite/tests/parser/should_fail/strictnessDataCon_B.stderr - testsuite/tests/parser/should_fail/typeops_A.stderr - testsuite/tests/parser/should_fail/typeops_C.stderr - testsuite/tests/parser/should_fail/unpack_empty_type.stderr - testsuite/tests/parser/should_fail/unpack_inside_type.stderr The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/189951d4f51d678a18443931a77ff1fce4be067d...22587e7f929d0457ed4a4bd91548cbe839432d47 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/189951d4f51d678a18443931a77ff1fce4be067d...22587e7f929d0457ed4a4bd91548cbe839432d47 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 12:34:51 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 07 Aug 2020 08:34:51 -0400 Subject: [Git][ghc/ghc][master] 2 commits: A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure Message-ID: <5f2d4a6b6c7d1_80b3f848c1e06f47056949@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 9 changed files: - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Expr.hs-boot - compiler/GHC/HsToCore/ListComp.hs - compiler/GHC/HsToCore/Utils.hs - + testsuite/tests/deSugar/should_run/DsDoExprFailMsg.hs - + testsuite/tests/deSugar/should_run/DsDoExprFailMsg.stderr - + testsuite/tests/deSugar/should_run/DsMonadCompFailMsg.hs - + testsuite/tests/deSugar/should_run/DsMonadCompFailMsg.stderr - testsuite/tests/deSugar/should_run/all.T Changes: ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -16,7 +16,6 @@ Desugaring expressions. module GHC.HsToCore.Expr ( dsExpr, dsLExpr, dsLExprNoLP, dsLocalBinds , dsValBinds, dsLit, dsSyntaxExpr - , dsHandleMonadicFailure ) where @@ -989,7 +988,7 @@ dsDo ctx stmts ; var <- selectSimpleMatchVarL (xbstc_boundResultMult xbs) pat ; match <- matchSinglePatVar var (StmtCtxt ctx) pat (xbstc_boundResultType xbs) (cantFailMatchResult body) - ; match_code <- dsHandleMonadicFailure pat match (xbstc_failOp xbs) + ; match_code <- dsHandleMonadicFailure ctx pat match (xbstc_failOp xbs) ; dsSyntaxExpr (xbstc_bindOp xbs) [rhs', Lam var match_code] } go _ (ApplicativeStmt body_ty args mb_join) stmts @@ -1010,7 +1009,7 @@ dsDo ctx stmts = do { var <- selectSimpleMatchVarL Many pat ; match <- matchSinglePatVar var (StmtCtxt ctx) pat body_ty (cantFailMatchResult body) - ; match_code <- dsHandleMonadicFailure pat match fail_op + ; match_code <- dsHandleMonadicFailure ctx pat match fail_op ; return (var:vs, match_code) } @@ -1065,31 +1064,6 @@ dsDo ctx stmts go _ (ParStmt {}) _ = panic "dsDo ParStmt" go _ (TransStmt {}) _ = panic "dsDo TransStmt" -dsHandleMonadicFailure :: LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr - -- In a do expression, pattern-match failure just calls - -- the monadic 'fail' rather than throwing an exception -dsHandleMonadicFailure pat match m_fail_op = - case shareFailureHandler match of - MR_Infallible body -> body - MR_Fallible body -> do - fail_op <- case m_fail_op of - -- Note that (non-monadic) list comprehension, pattern guards, etc could - -- have fallible bindings without an explicit failure op, but this is - -- handled elsewhere. See Note [Failing pattern matches in Stmts] the - -- breakdown of regular and special binds. - Nothing -> pprPanic "missing fail op" $ - text "Pattern match:" <+> ppr pat <+> - text "is failable, and fail_expr was left unset" - Just fail_op -> pure fail_op - dflags <- getDynFlags - fail_msg <- mkStringExpr (mk_fail_msg dflags pat) - fail_expr <- dsSyntaxExpr fail_op [fail_msg] - body fail_expr - -mk_fail_msg :: DynFlags -> Located e -> String -mk_fail_msg dflags pat = "Pattern match failure in do expression at " ++ - showPpr dflags (getLoc pat) - {- ************************************************************************ * * ===================================== compiler/GHC/HsToCore/Expr.hs-boot ===================================== @@ -1,6 +1,6 @@ module GHC.HsToCore.Expr where -import GHC.Hs ( HsExpr, LHsExpr, LHsLocalBinds, LPat, SyntaxExpr, FailOperator ) -import GHC.HsToCore.Monad ( DsM, MatchResult ) +import GHC.Hs ( HsExpr, LHsExpr, LHsLocalBinds, SyntaxExpr ) +import GHC.HsToCore.Monad ( DsM ) import GHC.Core ( CoreExpr ) import GHC.Hs.Extension ( GhcTc) @@ -8,5 +8,3 @@ dsExpr :: HsExpr GhcTc -> DsM CoreExpr dsLExpr, dsLExprNoLP :: LHsExpr GhcTc -> DsM CoreExpr dsSyntaxExpr :: SyntaxExpr GhcTc -> [CoreExpr] -> DsM CoreExpr dsLocalBinds :: LHsLocalBinds GhcTc -> CoreExpr -> DsM CoreExpr - -dsHandleMonadicFailure :: LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr ===================================== compiler/GHC/HsToCore/ListComp.hs ===================================== @@ -16,7 +16,7 @@ module GHC.HsToCore.ListComp ( dsListComp, dsMonadComp ) where import GHC.Prelude -import {-# SOURCE #-} GHC.HsToCore.Expr ( dsHandleMonadicFailure, dsExpr, dsLExpr, dsLExprNoLP, dsLocalBinds, dsSyntaxExpr ) +import {-# SOURCE #-} GHC.HsToCore.Expr ( dsExpr, dsLExpr, dsLExprNoLP, dsLocalBinds, dsSyntaxExpr ) import GHC.Hs import GHC.Tc.Utils.Zonk @@ -618,7 +618,7 @@ dsMcBindStmt pat rhs' bind_op fail_op res1_ty stmts ; var <- selectSimpleMatchVarL Many pat ; match <- matchSinglePatVar var (StmtCtxt (DoExpr Nothing)) pat res1_ty (cantFailMatchResult body) - ; match_code <- dsHandleMonadicFailure pat match fail_op + ; match_code <- dsHandleMonadicFailure (MonadComp :: HsStmtContext GhcRn) pat match fail_op ; dsSyntaxExpr bind_op [rhs', Lam var match_code] } -- Desugar nested monad comprehensions, for example in `then..` constructs ===================================== compiler/GHC/HsToCore/Utils.hs ===================================== @@ -24,6 +24,7 @@ module GHC.HsToCore.Utils ( extractMatchResult, combineMatchResults, adjustMatchResultDs, shareFailureHandler, + dsHandleMonadicFailure, mkCoLetMatchResult, mkViewMatchResult, mkGuardedMatchResult, matchCanFail, mkEvalMatchResult, mkCoPrimCaseMatchResult, mkCoAlgCaseMatchResult, mkCoSynCaseMatchResult, @@ -49,7 +50,7 @@ module GHC.HsToCore.Utils ( import GHC.Prelude import {-# SOURCE #-} GHC.HsToCore.Match ( matchSimply ) -import {-# SOURCE #-} GHC.HsToCore.Expr ( dsLExpr ) +import {-# SOURCE #-} GHC.HsToCore.Expr ( dsLExpr, dsSyntaxExpr ) import GHC.Hs import GHC.Tc.Utils.Zonk @@ -895,9 +896,33 @@ entered at most once. Adding a dummy 'realWorld' token argument makes it clear that sharing is not an issue. And that in turn makes it more CPR-friendly. This matters a lot: if you don't get it right, you lose the tail call property. For example, see #3403. +-} +dsHandleMonadicFailure :: Outputable (IdP p) => HsStmtContext p -> LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr + -- In a do expression, pattern-match failure just calls + -- the monadic 'fail' rather than throwing an exception +dsHandleMonadicFailure ctx pat match m_fail_op = + case shareFailureHandler match of + MR_Infallible body -> body + MR_Fallible body -> do + fail_op <- case m_fail_op of + -- Note that (non-monadic) list comprehension, pattern guards, etc could + -- have fallible bindings without an explicit failure op, but this is + -- handled elsewhere. See Note [Failing pattern matches in Stmts] the + -- breakdown of regular and special binds. + Nothing -> pprPanic "missing fail op" $ + text "Pattern match:" <+> ppr pat <+> + text "is failable, and fail_expr was left unset" + Just fail_op -> pure fail_op + dflags <- getDynFlags + fail_msg <- mkStringExpr (mk_fail_msg dflags ctx pat) + fail_expr <- dsSyntaxExpr fail_op [fail_msg] + body fail_expr + +mk_fail_msg :: Outputable (IdP p) => DynFlags -> HsStmtContext p -> Located e -> String +mk_fail_msg dflags ctx pat = showPpr dflags $ text "Pattern match failure in" <+> pprStmtContext ctx <+> text "at" <+> ppr (getLoc pat) -************************************************************************ +{- ********************************************************************* * * Ticks * * ===================================== testsuite/tests/deSugar/should_run/DsDoExprFailMsg.hs ===================================== @@ -0,0 +1,3 @@ +main = do + (x:xs) <- return [] + return () ===================================== testsuite/tests/deSugar/should_run/DsDoExprFailMsg.stderr ===================================== @@ -0,0 +1 @@ +DsDoExprFailMsg: user error (Pattern match failure in 'do' block at DsDoExprFailMsg.hs:2:3-8) ===================================== testsuite/tests/deSugar/should_run/DsMonadCompFailMsg.hs ===================================== @@ -0,0 +1,2 @@ +{-# LANGUAGE MonadComprehensions #-} +main = [() | (x:xs) <- return []] ===================================== testsuite/tests/deSugar/should_run/DsMonadCompFailMsg.stderr ===================================== @@ -0,0 +1 @@ +DsMonadCompFailMsg: user error (Pattern match failure in monad comprehension at DsMonadCompFailMsg.hs:2:14-19) ===================================== testsuite/tests/deSugar/should_run/all.T ===================================== @@ -66,3 +66,6 @@ test('T12595', normal, compile_and_run, ['']) test('T13285', normal, compile_and_run, ['']) test('T18151', normal, compile_and_run, ['']) test('T18172', [], ghci_script, ['T18172.script']) + +test('DsDoExprFailMsg', exit_code(1), compile_and_run, ['']) +test('DsMonadCompFailMsg', exit_code(1), compile_and_run, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9570c21295a2b4a1d1e40939869124f0b9b9bf91...fa9bb70a3fefef681cb0e80cc78977386c1dcf0a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9570c21295a2b4a1d1e40939869124f0b9b9bf91...fa9bb70a3fefef681cb0e80cc78977386c1dcf0a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 12:35:29 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 07 Aug 2020 08:35:29 -0400 Subject: [Git][ghc/ghc][master] 5 commits: cmm: Clean up Notes a bit Message-ID: <5f2d4a91abad7_80b3f8468e02b5470639b7@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - 13 changed files: - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/StgToCmm/Foreign.hs - compiler/GHC/StgToCmm/Utils.hs - includes/stg/MachRegs.h - + testsuite/tests/codeGen/should_run/T18527.hs - + testsuite/tests/codeGen/should_run/T18527.stdout - + testsuite/tests/codeGen/should_run/T18527FFI.c - testsuite/tests/codeGen/should_run/all.T - testsuite/tests/concurrent/prog001/all.T Changes: ===================================== compiler/GHC/Cmm/Lint.hs ===================================== @@ -6,6 +6,7 @@ -- ----------------------------------------------------------------------------- {-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} module GHC.Cmm.Lint ( cmmLint, cmmLintGraph @@ -14,6 +15,7 @@ module GHC.Cmm.Lint ( import GHC.Prelude import GHC.Platform +import GHC.Platform.Regs (callerSaves) import GHC.Cmm.Dataflow.Block import GHC.Cmm.Dataflow.Collections import GHC.Cmm.Dataflow.Graph @@ -26,7 +28,7 @@ import GHC.Cmm.Ppr () -- For Outputable instances import GHC.Utils.Outputable import GHC.Driver.Session -import Control.Monad (ap) +import Control.Monad (ap, unless) -- Things to check: -- - invariant on CmmBlock in GHC.Cmm.Expr (see comment there) @@ -160,7 +162,13 @@ lintCmmMiddle node = case node of CmmUnsafeForeignCall target _formals actuals -> do lintTarget target - mapM_ lintCmmExpr actuals + let lintArg expr = do + -- Arguments can't mention caller-saved + -- registers. See Note [Register parameter passing]. + mayNotMentionCallerSavedRegs (text "foreign call argument") expr + lintCmmExpr expr + + mapM_ lintArg actuals lintCmmLast :: LabelSet -> CmmNode O C -> CmmLint () @@ -188,18 +196,40 @@ lintCmmLast labels node = case node of CmmForeignCall tgt _ args succ _ _ _ -> do lintTarget tgt - mapM_ lintCmmExpr args + let lintArg expr = do + -- Arguments can't mention caller-saved + -- registers. See Note [Register + -- parameter passing]. + -- N.B. This won't catch local registers + -- which the NCG's register allocator later + -- places in caller-saved registers. + mayNotMentionCallerSavedRegs (text "foreign call argument") expr + lintCmmExpr expr + mapM_ lintArg args checkTarget succ where checkTarget id | setMember id labels = return () | otherwise = cmmLintErr (text "Branch to nonexistent id" <+> ppr id) - lintTarget :: ForeignTarget -> CmmLint () -lintTarget (ForeignTarget e _) = lintCmmExpr e >> return () +lintTarget (ForeignTarget e _) = do + mayNotMentionCallerSavedRegs (text "foreign target") e + _ <- lintCmmExpr e + return () lintTarget (PrimTarget {}) = return () +-- | As noted in Note [Register parameter passing], the arguments and +-- 'ForeignTarget' of a foreign call mustn't mention +-- caller-saved registers. +mayNotMentionCallerSavedRegs :: (UserOfRegs GlobalReg a, Outputable a) + => SDoc -> a -> CmmLint () +mayNotMentionCallerSavedRegs what thing = do + dflags <- getDynFlags + let badRegs = filter (callerSaves (targetPlatform dflags)) + $ foldRegsUsed dflags (flip (:)) [] thing + unless (null badRegs) + $ cmmLintErr (what <+> text "mentions caller-saved registers: " <> ppr badRegs $$ ppr thing) checkCond :: Platform -> CmmExpr -> CmmLint () checkCond _ (CmmMachOp mop _) | isComparisonMachOp mop = return () ===================================== compiler/GHC/Cmm/MachOp.hs ===================================== @@ -45,6 +45,9 @@ native code generators to handle. Most operations are parameterised by the 'Width' that they operate on. Some operations have separate signed and unsigned versions, and float and integer versions. + +Note that there are variety of places in the native code generator where we +assume that the code produced for a MachOp does not introduce new blocks. -} data MachOp ===================================== compiler/GHC/Cmm/Node.hs ===================================== @@ -93,7 +93,7 @@ data CmmNode e x where -- -- Invariant: the arguments and the ForeignTarget must not -- mention any registers for which GHC.Platform.callerSaves - -- is True. See Note [Register Parameter Passing]. + -- is True. See Note [Register parameter passing]. CmmBranch :: ULabel -> CmmNode O C -- Goto another block in the same procedure @@ -223,11 +223,12 @@ convention, rdi, rsi, rdx and rcx (as well as r8 and r9) may be used for argument passing. These are registers R3-R6, which our generated code may also be using; as a result, it's necessary to save these values before doing a foreign call. This is done during initial -code generation in callerSaveVolatileRegs in GHC.StgToCmm.Utils. However, -one result of doing this is that the contents of these registers -may mysteriously change if referenced inside the arguments. This -is dangerous, so you'll need to disable inlining much in the same -way is done in GHC.Cmm.Opt currently. We should fix this! +code generation in callerSaveVolatileRegs in GHC.StgToCmm.Utils. + +However, one result of doing this is that the contents of these registers may +mysteriously change if referenced inside the arguments. This is dangerous, so +you'll need to disable inlining much in the same way is done in GHC.Cmm.Sink +currently. We should fix this! -} --------------------------------------------- ===================================== compiler/GHC/Cmm/Sink.hs ===================================== @@ -772,6 +772,7 @@ regAddr _ _ _ _ = AnyMem {- Note [Inline GlobalRegs?] +~~~~~~~~~~~~~~~~~~~~~~~~~ Should we freely inline GlobalRegs? ===================================== compiler/GHC/CmmToAsm/X86/CodeGen.hs ===================================== @@ -287,11 +287,11 @@ we construct as a separate data type and the actual control flow graph in the co Instead we now return the new basic block if a statement causes a change in the current block and use the block for all following statements. -For this reason genCCall is also split into two parts. -One for calls which *won't* change the basic blocks in -which successive instructions will be placed. -A different one for calls which *are* known to change the -basic block. +For this reason genCCall is also split into two parts. One for calls which +*won't* change the basic blocks in which successive instructions will be +placed (since they only evaluate CmmExpr, which can only contain MachOps, which +cannot introduce basic blocks in their lowerings). A different one for calls +which *are* known to change the basic block. -} @@ -1028,6 +1028,9 @@ getRegister' _ is32Bit (CmmMachOp mop [x, y]) = do -- dyadic MachOps tmp. This is likely to be better, because the reg alloc can eliminate this reg->reg move here (it won't eliminate the other one, because the move is into the fixed %ecx). + * in the case of C calls the use of ecx here can interfere with arguments. + We avoid this with the hack described in Note [Evaluate C-call + arguments before placing in destination registers] -} shift_code width instr x y{-amount-} = do x_code <- getAnyReg x @@ -2022,6 +2025,7 @@ genCCall is32Bit (PrimTarget (MO_AtomicRMW width amop)) arg <- getNewRegNat format arg_code <- getAnyReg n platform <- ncgPlatform <$> getConfig + let dst_r = getRegisterReg platform (CmmLocal dst) (code, lbl) <- op_code dst_r arg amode return (addr_code `appOL` arg_code arg `appOL` code, Just lbl) @@ -2667,9 +2671,12 @@ genCCall' _ is32Bit target dest_regs args bid = do return code _ -> panic "genCCall: Wrong number of arguments/results for imul2" - _ -> if is32Bit - then genCCall32' target dest_regs args - else genCCall64' target dest_regs args + _ -> do + (instrs0, args') <- evalArgs bid args + instrs1 <- if is32Bit + then genCCall32' target dest_regs args' + else genCCall64' target dest_regs args' + return (instrs0 `appOL` instrs1) where divOp1 platform signed width results [arg_x, arg_y] = divOp platform signed width results Nothing arg_x arg_y @@ -2732,6 +2739,83 @@ genCCall' _ is32Bit target dest_regs args bid = do addSubIntC _ _ _ _ _ _ _ _ = panic "genCCall: Wrong number of arguments/results for addSubIntC" +{- +Note [Evaluate C-call arguments before placing in destination registers] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When producing code for C calls we must take care when placing arguments +in their final registers. Specifically, we must ensure that temporary register +usage due to evaluation of one argument does not clobber a register in which we +already placed a previous argument (e.g. as the code generation logic for +MO_Shl can clobber %rcx due to x86 instruction limitations). + +This is precisely what happened in #18527. Consider this C--: + + (result::I64) = call "ccall" doSomething(_s2hp::I64, 2244, _s2hq::I64, _s2hw::I64 | (1 << _s2hz::I64)); + +Here we are calling the C function `doSomething` with three arguments, the last +involving a non-trivial expression involving MO_Shl. In this case the NCG could +naively generate the following assembly (where $tmp denotes some temporary +register and $argN denotes the register for argument N, as dictated by the +platform's calling convention): + + mov _s2hp, $arg1 # place first argument + mov _s2hq, $arg2 # place second argument + + # Compute 1 << _s2hz + mov _s2hz, %rcx + shl %cl, $tmp + + # Compute (_s2hw | (1 << _s2hz)) + mov _s2hw, $arg3 + or $tmp, $arg3 + + # Perform the call + call func + +This code is outright broken on Windows which assigns $arg1 to %rcx. This means +that the evaluation of the last argument clobbers the first argument. + +To avoid this we use a rather awful hack: when producing code for a C call with +at least one non-trivial argument, we first evaluate all of the arguments into +local registers before moving them into their final calling-convention-defined +homes. This is performed by 'evalArgs'. Here we define "non-trivial" to be an +expression which might contain a MachOp since these are the only cases which +might clobber registers. Furthermore, we use a conservative approximation of +this condition (only looking at the top-level of CmmExprs) to avoid spending +too much effort trying to decide whether we want to take the fast path. + +Note that this hack *also* applies to calls to out-of-line PrimTargets (which +are lowered via a C call) since outOfLineCmmOp produces the call via +(stmtToInstrs (CmmUnsafeForeignCall ...)), which will ultimately end up +back in genCCall{32,64}. +-} + +-- | See Note [Evaluate C-call arguments before placing in destination registers] +evalArgs :: BlockId -> [CmmActual] -> NatM (InstrBlock, [CmmActual]) +evalArgs bid actuals + | any mightContainMachOp actuals = do + regs_blks <- mapM evalArg actuals + return (concatOL $ map fst regs_blks, map snd regs_blks) + | otherwise = return (nilOL, actuals) + where + mightContainMachOp (CmmReg _) = False + mightContainMachOp (CmmRegOff _ _) = False + mightContainMachOp (CmmLit _) = False + mightContainMachOp _ = True + + evalArg :: CmmActual -> NatM (InstrBlock, CmmExpr) + evalArg actual = do + platform <- getPlatform + lreg <- newLocalReg $ cmmExprType platform actual + (instrs, bid1) <- stmtToInstrs bid $ CmmAssign (CmmLocal lreg) actual + -- The above assignment shouldn't change the current block + MASSERT(isNothing bid1) + return (instrs, CmmReg $ CmmLocal lreg) + + newLocalReg :: CmmType -> NatM LocalReg + newLocalReg ty = LocalReg <$> getUniqueM <*> pure ty + -- Note [DIV/IDIV for bytes] -- -- IDIV reminder: ===================================== compiler/GHC/StgToCmm/Foreign.hs ===================================== @@ -261,7 +261,7 @@ load_target_into_temp other_target@(PrimTarget _) = -- What we want to do here is create a new temporary for the foreign -- call argument if it is not safe to use the expression directly, -- because the expression mentions caller-saves GlobalRegs (see --- Note [Register Parameter Passing]). +-- Note [Register parameter passing]). -- -- However, we can't pattern-match on the expression here, because -- this is used in a loop by GHC.Cmm.Parser, and testing the expression ===================================== compiler/GHC/StgToCmm/Utils.hs ===================================== @@ -243,7 +243,7 @@ emitRtsCallGen res lbl args safe -- shouldn't be doing the workaround at this point in the pipeline, see -- Note [Register parameter passing] and the ToDo on CmmCall in -- "GHC.Cmm.Node". Right now the workaround is to avoid inlining across --- unsafe foreign calls in rewriteAssignments, but this is strictly +-- unsafe foreign calls in GHC.Cmm.Sink, but this is strictly -- temporary. callerSaveVolatileRegs :: Platform -> (CmmAGraph, CmmAGraph) callerSaveVolatileRegs platform = (caller_save, caller_load) ===================================== includes/stg/MachRegs.h ===================================== @@ -61,6 +61,8 @@ are the RX, FX, DX and USER registers; as a result, if you decide to caller save a system register (e.g. SP, HP, etc), note that this code path is completely untested! -- EZY + + See Note [Register parameter passing] for details. -------------------------------------------------------------------------- */ /* ----------------------------------------------------------------------------- ===================================== testsuite/tests/codeGen/should_run/T18527.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +module Main where + +import Data.Bits (setBit) +import Data.Word (Word32) +import Data.Int (Int64) + +main :: IO () +main = offending 100 0 1 + +offending :: Int64 -> Int64 -> Word32 -> IO () +offending h i id = do + oldMask <- sendMessage h (2245) i 0 + let newMask = setBit oldMask (fromIntegral id) + sendMessage h (2244) i newMask + return () + +foreign import ccall "func" + sendMessage :: Int64 -> Word32 -> Int64 -> Int64 -> IO Int64 ===================================== testsuite/tests/codeGen/should_run/T18527.stdout ===================================== @@ -0,0 +1,3 @@ +ffi call +ffi call + ===================================== testsuite/tests/codeGen/should_run/T18527FFI.c ===================================== @@ -0,0 +1,14 @@ +#include +#include + +int64_t func(int64_t a, uint32_t b, int64_t c, int64_t d) { + printf("ffi call"); + if (a == 1) { + printf(" with corrupted convention\n"); + } + else { + printf("\n"); + } + return 0; +} + ===================================== testsuite/tests/codeGen/should_run/all.T ===================================== @@ -207,3 +207,4 @@ test('T16449_2', exit_code(0), compile_and_run, ['']) test('T16846', [only_ways(['optasm']), exit_code(1)], compile_and_run, ['']) test('T17920', cmm_src, compile_and_run, ['']) +test('T18527', normal, compile_and_run, ['T18527FFI.c']) ===================================== testsuite/tests/concurrent/prog001/all.T ===================================== @@ -16,4 +16,4 @@ test('concprog001', [extra_files(['Arithmetic.hs', 'Converter.hs', 'Mult.hs', 'S when(fast(), skip), only_ways(['threaded2']), fragile(16604), run_timeout_multiplier(2)], - multimod_compile_and_run, ['Mult', '']) + multimod_compile_and_run, ['Mult', '-package ghc']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fa9bb70a3fefef681cb0e80cc78977386c1dcf0a...dd51d53be42114c105b5ab15fcbdb387526b1c17 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fa9bb70a3fefef681cb0e80cc78977386c1dcf0a...dd51d53be42114c105b5ab15fcbdb387526b1c17 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 12:47:01 2020 From: gitlab at gitlab.haskell.org (Ryan Scott) Date: Fri, 07 Aug 2020 08:47:01 -0400 Subject: [Git][ghc/ghc][wip/T16762] WIP: T16762 Message-ID: <5f2d4d455a102_80b3f848a372f8c7064165@gitlab.haskell.org.mail> Ryan Scott pushed to branch wip/T16762 at Glasgow Haskell Compiler / GHC Commits: 3f4428b4 by Ryan Scott at 2020-08-07T08:46:41-04:00 WIP: T16762 [ci skip] - - - - - 23 changed files: - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Extension.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/Docs.hs - compiler/GHC/HsToCore/Quote.hs - compiler/GHC/Iface/Ext/Ast.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Parser/PostProcess/Haddock.hs - compiler/GHC/Rename/HsType.hs - compiler/GHC/Rename/Module.hs - compiler/GHC/Rename/Names.hs - compiler/GHC/Tc/Gen/Foreign.hs - compiler/GHC/Tc/Gen/HsType.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Tc/TyCl/Instance.hs - compiler/GHC/Tc/Utils/Env.hs - compiler/GHC/ThToHs.hs - compiler/GHC/Types/Var.hs - testsuite/tests/haddock/should_compile_flag_haddock/T17544.stderr - testsuite/tests/haddock/should_compile_flag_haddock/T17544_kw.stderr The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3f4428b42a5d61224aba5b7f74f5ecaf4b717094 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3f4428b42a5d61224aba5b7f74f5ecaf4b717094 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 14:51:39 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Fri, 07 Aug 2020 10:51:39 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T17962c Message-ID: <5f2d6a7b4b635_80b3f846910c0c07075479@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T17962c at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T17962c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 14:53:18 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Fri, 07 Aug 2020 10:53:18 -0400 Subject: [Git][ghc/ghc][wip/backports] configure: Fix double-negation in ld merge-objects check Message-ID: <5f2d6ade6f4c5_80b10e6f9b470792fa@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: 29204b1c by Ben Gamari at 2020-08-07T10:53:04-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. (cherry picked from commit d589ef25f54862968976bc279eb6748509794566) - - - - - 1 changed file: - aclocal.m4 Changes: ===================================== aclocal.m4 ===================================== @@ -2527,7 +2527,7 @@ AC_DEFUN([FIND_LD],[ # Sets $result to 0 if not affected, 1 otherwise AC_DEFUN([CHECK_FOR_GOLD_T22266],[ AC_MSG_CHECKING([for ld.gold object merging bug (binutils 22266)]) - if ! $1 --version | grep -v -q "GNU gold"; then + if ! $1 --version | grep -q "GNU gold"; then # Not gold result=0 elif test "$cross_compiling" = "yes"; then View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/29204b1c4f52ea34d84da33593052ee839293bf2 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/29204b1c4f52ea34d84da33593052ee839293bf2 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 16:59:51 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Fri, 07 Aug 2020 12:59:51 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/ghc-heap_hie.yaml Message-ID: <5f2d8887896e2_80b3f848a386fc870948ee@gitlab.haskell.org.mail> Sven Tennie pushed new branch wip/ghc-heap_hie.yaml at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/ghc-heap_hie.yaml You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 7 22:38:12 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 07 Aug 2020 18:38:12 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 9 commits: A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure Message-ID: <5f2dd7d499959_80b3f848c1e06f47110394@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - 649f9104 by Alan Zimmerman at 2020-08-07T18:38:06-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 15932b2a by Ben Gamari at 2020-08-07T18:38:06-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - 27 changed files: - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Expr.hs-boot - compiler/GHC/HsToCore/ListComp.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Annotation.hs - compiler/GHC/StgToCmm/Foreign.hs - compiler/GHC/StgToCmm/Utils.hs - includes/stg/MachRegs.h - + testsuite/tests/codeGen/should_run/T18527.hs - + testsuite/tests/codeGen/should_run/T18527.stdout - + testsuite/tests/codeGen/should_run/T18527FFI.c - testsuite/tests/codeGen/should_run/all.T - testsuite/tests/concurrent/prog001/all.T - + testsuite/tests/deSugar/should_run/DsDoExprFailMsg.hs - + testsuite/tests/deSugar/should_run/DsDoExprFailMsg.stderr - + testsuite/tests/deSugar/should_run/DsMonadCompFailMsg.hs - + testsuite/tests/deSugar/should_run/DsMonadCompFailMsg.stderr - testsuite/tests/deSugar/should_run/all.T - utils/check-api-annotations/Main.hs Changes: ===================================== aclocal.m4 ===================================== @@ -2543,7 +2543,7 @@ AC_DEFUN([FIND_LD],[ # Sets $result to 0 if not affected, 1 otherwise AC_DEFUN([CHECK_FOR_GOLD_T22266],[ AC_MSG_CHECKING([for ld.gold object merging bug (binutils 22266)]) - if ! $1 --version | grep -v -q "GNU gold"; then + if ! $1 --version | grep -q "GNU gold"; then # Not gold result=0 elif test "$cross_compiling" = "yes"; then ===================================== compiler/GHC.hs ===================================== @@ -248,7 +248,7 @@ module GHC ( srcSpanStartCol, srcSpanEndCol, -- ** Located - GenLocated(..), Located, + GenLocated(..), Located, RealLocated, -- *** Constructing Located noLoc, mkGeneralLocated, @@ -274,7 +274,7 @@ module GHC ( parser, -- * API Annotations - ApiAnns(..),AnnKeywordId(..),AnnotationComment(..), + ApiAnns(..),AnnKeywordId(..),AnnotationComment(..), ApiAnnKey, getAnnotation, getAndRemoveAnnotation, getAnnotationComments, getAndRemoveAnnotationComments, unicodeAnn, ===================================== compiler/GHC/Cmm/Lint.hs ===================================== @@ -6,6 +6,7 @@ -- ----------------------------------------------------------------------------- {-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} module GHC.Cmm.Lint ( cmmLint, cmmLintGraph @@ -14,6 +15,7 @@ module GHC.Cmm.Lint ( import GHC.Prelude import GHC.Platform +import GHC.Platform.Regs (callerSaves) import GHC.Cmm.Dataflow.Block import GHC.Cmm.Dataflow.Collections import GHC.Cmm.Dataflow.Graph @@ -26,7 +28,7 @@ import GHC.Cmm.Ppr () -- For Outputable instances import GHC.Utils.Outputable import GHC.Driver.Session -import Control.Monad (ap) +import Control.Monad (ap, unless) -- Things to check: -- - invariant on CmmBlock in GHC.Cmm.Expr (see comment there) @@ -160,7 +162,13 @@ lintCmmMiddle node = case node of CmmUnsafeForeignCall target _formals actuals -> do lintTarget target - mapM_ lintCmmExpr actuals + let lintArg expr = do + -- Arguments can't mention caller-saved + -- registers. See Note [Register parameter passing]. + mayNotMentionCallerSavedRegs (text "foreign call argument") expr + lintCmmExpr expr + + mapM_ lintArg actuals lintCmmLast :: LabelSet -> CmmNode O C -> CmmLint () @@ -188,18 +196,40 @@ lintCmmLast labels node = case node of CmmForeignCall tgt _ args succ _ _ _ -> do lintTarget tgt - mapM_ lintCmmExpr args + let lintArg expr = do + -- Arguments can't mention caller-saved + -- registers. See Note [Register + -- parameter passing]. + -- N.B. This won't catch local registers + -- which the NCG's register allocator later + -- places in caller-saved registers. + mayNotMentionCallerSavedRegs (text "foreign call argument") expr + lintCmmExpr expr + mapM_ lintArg args checkTarget succ where checkTarget id | setMember id labels = return () | otherwise = cmmLintErr (text "Branch to nonexistent id" <+> ppr id) - lintTarget :: ForeignTarget -> CmmLint () -lintTarget (ForeignTarget e _) = lintCmmExpr e >> return () +lintTarget (ForeignTarget e _) = do + mayNotMentionCallerSavedRegs (text "foreign target") e + _ <- lintCmmExpr e + return () lintTarget (PrimTarget {}) = return () +-- | As noted in Note [Register parameter passing], the arguments and +-- 'ForeignTarget' of a foreign call mustn't mention +-- caller-saved registers. +mayNotMentionCallerSavedRegs :: (UserOfRegs GlobalReg a, Outputable a) + => SDoc -> a -> CmmLint () +mayNotMentionCallerSavedRegs what thing = do + dflags <- getDynFlags + let badRegs = filter (callerSaves (targetPlatform dflags)) + $ foldRegsUsed dflags (flip (:)) [] thing + unless (null badRegs) + $ cmmLintErr (what <+> text "mentions caller-saved registers: " <> ppr badRegs $$ ppr thing) checkCond :: Platform -> CmmExpr -> CmmLint () checkCond _ (CmmMachOp mop _) | isComparisonMachOp mop = return () ===================================== compiler/GHC/Cmm/MachOp.hs ===================================== @@ -45,6 +45,9 @@ native code generators to handle. Most operations are parameterised by the 'Width' that they operate on. Some operations have separate signed and unsigned versions, and float and integer versions. + +Note that there are variety of places in the native code generator where we +assume that the code produced for a MachOp does not introduce new blocks. -} data MachOp ===================================== compiler/GHC/Cmm/Node.hs ===================================== @@ -93,7 +93,7 @@ data CmmNode e x where -- -- Invariant: the arguments and the ForeignTarget must not -- mention any registers for which GHC.Platform.callerSaves - -- is True. See Note [Register Parameter Passing]. + -- is True. See Note [Register parameter passing]. CmmBranch :: ULabel -> CmmNode O C -- Goto another block in the same procedure @@ -223,11 +223,12 @@ convention, rdi, rsi, rdx and rcx (as well as r8 and r9) may be used for argument passing. These are registers R3-R6, which our generated code may also be using; as a result, it's necessary to save these values before doing a foreign call. This is done during initial -code generation in callerSaveVolatileRegs in GHC.StgToCmm.Utils. However, -one result of doing this is that the contents of these registers -may mysteriously change if referenced inside the arguments. This -is dangerous, so you'll need to disable inlining much in the same -way is done in GHC.Cmm.Opt currently. We should fix this! +code generation in callerSaveVolatileRegs in GHC.StgToCmm.Utils. + +However, one result of doing this is that the contents of these registers may +mysteriously change if referenced inside the arguments. This is dangerous, so +you'll need to disable inlining much in the same way is done in GHC.Cmm.Sink +currently. We should fix this! -} --------------------------------------------- ===================================== compiler/GHC/Cmm/Sink.hs ===================================== @@ -772,6 +772,7 @@ regAddr _ _ _ _ = AnyMem {- Note [Inline GlobalRegs?] +~~~~~~~~~~~~~~~~~~~~~~~~~ Should we freely inline GlobalRegs? ===================================== compiler/GHC/CmmToAsm/X86/CodeGen.hs ===================================== @@ -287,11 +287,11 @@ we construct as a separate data type and the actual control flow graph in the co Instead we now return the new basic block if a statement causes a change in the current block and use the block for all following statements. -For this reason genCCall is also split into two parts. -One for calls which *won't* change the basic blocks in -which successive instructions will be placed. -A different one for calls which *are* known to change the -basic block. +For this reason genCCall is also split into two parts. One for calls which +*won't* change the basic blocks in which successive instructions will be +placed (since they only evaluate CmmExpr, which can only contain MachOps, which +cannot introduce basic blocks in their lowerings). A different one for calls +which *are* known to change the basic block. -} @@ -1028,6 +1028,9 @@ getRegister' _ is32Bit (CmmMachOp mop [x, y]) = do -- dyadic MachOps tmp. This is likely to be better, because the reg alloc can eliminate this reg->reg move here (it won't eliminate the other one, because the move is into the fixed %ecx). + * in the case of C calls the use of ecx here can interfere with arguments. + We avoid this with the hack described in Note [Evaluate C-call + arguments before placing in destination registers] -} shift_code width instr x y{-amount-} = do x_code <- getAnyReg x @@ -2022,6 +2025,7 @@ genCCall is32Bit (PrimTarget (MO_AtomicRMW width amop)) arg <- getNewRegNat format arg_code <- getAnyReg n platform <- ncgPlatform <$> getConfig + let dst_r = getRegisterReg platform (CmmLocal dst) (code, lbl) <- op_code dst_r arg amode return (addr_code `appOL` arg_code arg `appOL` code, Just lbl) @@ -2667,9 +2671,12 @@ genCCall' _ is32Bit target dest_regs args bid = do return code _ -> panic "genCCall: Wrong number of arguments/results for imul2" - _ -> if is32Bit - then genCCall32' target dest_regs args - else genCCall64' target dest_regs args + _ -> do + (instrs0, args') <- evalArgs bid args + instrs1 <- if is32Bit + then genCCall32' target dest_regs args' + else genCCall64' target dest_regs args' + return (instrs0 `appOL` instrs1) where divOp1 platform signed width results [arg_x, arg_y] = divOp platform signed width results Nothing arg_x arg_y @@ -2732,6 +2739,83 @@ genCCall' _ is32Bit target dest_regs args bid = do addSubIntC _ _ _ _ _ _ _ _ = panic "genCCall: Wrong number of arguments/results for addSubIntC" +{- +Note [Evaluate C-call arguments before placing in destination registers] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When producing code for C calls we must take care when placing arguments +in their final registers. Specifically, we must ensure that temporary register +usage due to evaluation of one argument does not clobber a register in which we +already placed a previous argument (e.g. as the code generation logic for +MO_Shl can clobber %rcx due to x86 instruction limitations). + +This is precisely what happened in #18527. Consider this C--: + + (result::I64) = call "ccall" doSomething(_s2hp::I64, 2244, _s2hq::I64, _s2hw::I64 | (1 << _s2hz::I64)); + +Here we are calling the C function `doSomething` with three arguments, the last +involving a non-trivial expression involving MO_Shl. In this case the NCG could +naively generate the following assembly (where $tmp denotes some temporary +register and $argN denotes the register for argument N, as dictated by the +platform's calling convention): + + mov _s2hp, $arg1 # place first argument + mov _s2hq, $arg2 # place second argument + + # Compute 1 << _s2hz + mov _s2hz, %rcx + shl %cl, $tmp + + # Compute (_s2hw | (1 << _s2hz)) + mov _s2hw, $arg3 + or $tmp, $arg3 + + # Perform the call + call func + +This code is outright broken on Windows which assigns $arg1 to %rcx. This means +that the evaluation of the last argument clobbers the first argument. + +To avoid this we use a rather awful hack: when producing code for a C call with +at least one non-trivial argument, we first evaluate all of the arguments into +local registers before moving them into their final calling-convention-defined +homes. This is performed by 'evalArgs'. Here we define "non-trivial" to be an +expression which might contain a MachOp since these are the only cases which +might clobber registers. Furthermore, we use a conservative approximation of +this condition (only looking at the top-level of CmmExprs) to avoid spending +too much effort trying to decide whether we want to take the fast path. + +Note that this hack *also* applies to calls to out-of-line PrimTargets (which +are lowered via a C call) since outOfLineCmmOp produces the call via +(stmtToInstrs (CmmUnsafeForeignCall ...)), which will ultimately end up +back in genCCall{32,64}. +-} + +-- | See Note [Evaluate C-call arguments before placing in destination registers] +evalArgs :: BlockId -> [CmmActual] -> NatM (InstrBlock, [CmmActual]) +evalArgs bid actuals + | any mightContainMachOp actuals = do + regs_blks <- mapM evalArg actuals + return (concatOL $ map fst regs_blks, map snd regs_blks) + | otherwise = return (nilOL, actuals) + where + mightContainMachOp (CmmReg _) = False + mightContainMachOp (CmmRegOff _ _) = False + mightContainMachOp (CmmLit _) = False + mightContainMachOp _ = True + + evalArg :: CmmActual -> NatM (InstrBlock, CmmExpr) + evalArg actual = do + platform <- getPlatform + lreg <- newLocalReg $ cmmExprType platform actual + (instrs, bid1) <- stmtToInstrs bid $ CmmAssign (CmmLocal lreg) actual + -- The above assignment shouldn't change the current block + MASSERT(isNothing bid1) + return (instrs, CmmReg $ CmmLocal lreg) + + newLocalReg :: CmmType -> NatM LocalReg + newLocalReg ty = LocalReg <$> getUniqueM <*> pure ty + -- Note [DIV/IDIV for bytes] -- -- IDIV reminder: ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -16,7 +16,6 @@ Desugaring expressions. module GHC.HsToCore.Expr ( dsExpr, dsLExpr, dsLExprNoLP, dsLocalBinds , dsValBinds, dsLit, dsSyntaxExpr - , dsHandleMonadicFailure ) where @@ -989,7 +988,7 @@ dsDo ctx stmts ; var <- selectSimpleMatchVarL (xbstc_boundResultMult xbs) pat ; match <- matchSinglePatVar var (StmtCtxt ctx) pat (xbstc_boundResultType xbs) (cantFailMatchResult body) - ; match_code <- dsHandleMonadicFailure pat match (xbstc_failOp xbs) + ; match_code <- dsHandleMonadicFailure ctx pat match (xbstc_failOp xbs) ; dsSyntaxExpr (xbstc_bindOp xbs) [rhs', Lam var match_code] } go _ (ApplicativeStmt body_ty args mb_join) stmts @@ -1010,7 +1009,7 @@ dsDo ctx stmts = do { var <- selectSimpleMatchVarL Many pat ; match <- matchSinglePatVar var (StmtCtxt ctx) pat body_ty (cantFailMatchResult body) - ; match_code <- dsHandleMonadicFailure pat match fail_op + ; match_code <- dsHandleMonadicFailure ctx pat match fail_op ; return (var:vs, match_code) } @@ -1065,31 +1064,6 @@ dsDo ctx stmts go _ (ParStmt {}) _ = panic "dsDo ParStmt" go _ (TransStmt {}) _ = panic "dsDo TransStmt" -dsHandleMonadicFailure :: LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr - -- In a do expression, pattern-match failure just calls - -- the monadic 'fail' rather than throwing an exception -dsHandleMonadicFailure pat match m_fail_op = - case shareFailureHandler match of - MR_Infallible body -> body - MR_Fallible body -> do - fail_op <- case m_fail_op of - -- Note that (non-monadic) list comprehension, pattern guards, etc could - -- have fallible bindings without an explicit failure op, but this is - -- handled elsewhere. See Note [Failing pattern matches in Stmts] the - -- breakdown of regular and special binds. - Nothing -> pprPanic "missing fail op" $ - text "Pattern match:" <+> ppr pat <+> - text "is failable, and fail_expr was left unset" - Just fail_op -> pure fail_op - dflags <- getDynFlags - fail_msg <- mkStringExpr (mk_fail_msg dflags pat) - fail_expr <- dsSyntaxExpr fail_op [fail_msg] - body fail_expr - -mk_fail_msg :: DynFlags -> Located e -> String -mk_fail_msg dflags pat = "Pattern match failure in do expression at " ++ - showPpr dflags (getLoc pat) - {- ************************************************************************ * * ===================================== compiler/GHC/HsToCore/Expr.hs-boot ===================================== @@ -1,6 +1,6 @@ module GHC.HsToCore.Expr where -import GHC.Hs ( HsExpr, LHsExpr, LHsLocalBinds, LPat, SyntaxExpr, FailOperator ) -import GHC.HsToCore.Monad ( DsM, MatchResult ) +import GHC.Hs ( HsExpr, LHsExpr, LHsLocalBinds, SyntaxExpr ) +import GHC.HsToCore.Monad ( DsM ) import GHC.Core ( CoreExpr ) import GHC.Hs.Extension ( GhcTc) @@ -8,5 +8,3 @@ dsExpr :: HsExpr GhcTc -> DsM CoreExpr dsLExpr, dsLExprNoLP :: LHsExpr GhcTc -> DsM CoreExpr dsSyntaxExpr :: SyntaxExpr GhcTc -> [CoreExpr] -> DsM CoreExpr dsLocalBinds :: LHsLocalBinds GhcTc -> CoreExpr -> DsM CoreExpr - -dsHandleMonadicFailure :: LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr ===================================== compiler/GHC/HsToCore/ListComp.hs ===================================== @@ -16,7 +16,7 @@ module GHC.HsToCore.ListComp ( dsListComp, dsMonadComp ) where import GHC.Prelude -import {-# SOURCE #-} GHC.HsToCore.Expr ( dsHandleMonadicFailure, dsExpr, dsLExpr, dsLExprNoLP, dsLocalBinds, dsSyntaxExpr ) +import {-# SOURCE #-} GHC.HsToCore.Expr ( dsExpr, dsLExpr, dsLExprNoLP, dsLocalBinds, dsSyntaxExpr ) import GHC.Hs import GHC.Tc.Utils.Zonk @@ -618,7 +618,7 @@ dsMcBindStmt pat rhs' bind_op fail_op res1_ty stmts ; var <- selectSimpleMatchVarL Many pat ; match <- matchSinglePatVar var (StmtCtxt (DoExpr Nothing)) pat res1_ty (cantFailMatchResult body) - ; match_code <- dsHandleMonadicFailure pat match fail_op + ; match_code <- dsHandleMonadicFailure (MonadComp :: HsStmtContext GhcRn) pat match fail_op ; dsSyntaxExpr bind_op [rhs', Lam var match_code] } -- Desugar nested monad comprehensions, for example in `then..` constructs ===================================== compiler/GHC/HsToCore/Utils.hs ===================================== @@ -24,6 +24,7 @@ module GHC.HsToCore.Utils ( extractMatchResult, combineMatchResults, adjustMatchResultDs, shareFailureHandler, + dsHandleMonadicFailure, mkCoLetMatchResult, mkViewMatchResult, mkGuardedMatchResult, matchCanFail, mkEvalMatchResult, mkCoPrimCaseMatchResult, mkCoAlgCaseMatchResult, mkCoSynCaseMatchResult, @@ -49,7 +50,7 @@ module GHC.HsToCore.Utils ( import GHC.Prelude import {-# SOURCE #-} GHC.HsToCore.Match ( matchSimply ) -import {-# SOURCE #-} GHC.HsToCore.Expr ( dsLExpr ) +import {-# SOURCE #-} GHC.HsToCore.Expr ( dsLExpr, dsSyntaxExpr ) import GHC.Hs import GHC.Tc.Utils.Zonk @@ -895,9 +896,33 @@ entered at most once. Adding a dummy 'realWorld' token argument makes it clear that sharing is not an issue. And that in turn makes it more CPR-friendly. This matters a lot: if you don't get it right, you lose the tail call property. For example, see #3403. +-} +dsHandleMonadicFailure :: Outputable (IdP p) => HsStmtContext p -> LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr + -- In a do expression, pattern-match failure just calls + -- the monadic 'fail' rather than throwing an exception +dsHandleMonadicFailure ctx pat match m_fail_op = + case shareFailureHandler match of + MR_Infallible body -> body + MR_Fallible body -> do + fail_op <- case m_fail_op of + -- Note that (non-monadic) list comprehension, pattern guards, etc could + -- have fallible bindings without an explicit failure op, but this is + -- handled elsewhere. See Note [Failing pattern matches in Stmts] the + -- breakdown of regular and special binds. + Nothing -> pprPanic "missing fail op" $ + text "Pattern match:" <+> ppr pat <+> + text "is failable, and fail_expr was left unset" + Just fail_op -> pure fail_op + dflags <- getDynFlags + fail_msg <- mkStringExpr (mk_fail_msg dflags ctx pat) + fail_expr <- dsSyntaxExpr fail_op [fail_msg] + body fail_expr + +mk_fail_msg :: Outputable (IdP p) => DynFlags -> HsStmtContext p -> Located e -> String +mk_fail_msg dflags ctx pat = showPpr dflags $ text "Pattern match failure in" <+> pprStmtContext ctx <+> text "at" <+> ppr (getLoc pat) -************************************************************************ +{- ********************************************************************* * * Ticks * * ===================================== compiler/GHC/Parser.y ===================================== @@ -863,17 +863,17 @@ header_top_importdecls :: { [LImportDecl GhcPs] } -- The Export List maybeexports :: { (Maybe (Located [LIE GhcPs])) } - : '(' exportlist ')' {% amsL (comb2 $1 $>) [mop $1,mcp $3] >> - return (Just (sLL $1 $> (fromOL $2))) } + : '(' exportlist ')' {% amsL (comb2 $1 $>) ([mop $1,mcp $3] ++ (fst $2)) >> + return (Just (sLL $1 $> (fromOL $ snd $2))) } | {- empty -} { Nothing } -exportlist :: { OrdList (LIE GhcPs) } - : exportlist1 { $1 } - | {- empty -} { nilOL } +exportlist :: { ([AddAnn], OrdList (LIE GhcPs)) } + : exportlist1 { ([], $1) } + | {- empty -} { ([], nilOL) } -- trailing comma: - | exportlist1 ',' { $1 } - | ',' { nilOL } + | exportlist1 ',' { ([mj AnnComma $2], $1) } + | ',' { ([mj AnnComma $1], nilOL) } exportlist1 :: { OrdList (LIE GhcPs) } : exportlist1 ',' export @@ -1019,11 +1019,11 @@ maybeimpspec :: { Located (Maybe (Bool, Located [LIE GhcPs])) } impspec :: { Located (Bool, Located [LIE GhcPs]) } : '(' exportlist ')' {% ams (sLL $1 $> (False, - sLL $1 $> $ fromOL $2)) - [mop $1,mcp $3] } + sLL $1 $> $ fromOL (snd $2))) + ([mop $1,mcp $3] ++ (fst $2)) } | 'hiding' '(' exportlist ')' {% ams (sLL $1 $> (True, - sLL $1 $> $ fromOL $3)) - [mj AnnHiding $1,mop $2,mcp $4] } + sLL $1 $> $ fromOL (snd $3))) + ([mj AnnHiding $1,mop $2,mcp $4] ++ (fst $3)) } ----------------------------------------------------------------------------- -- Fixity Declarations ===================================== compiler/GHC/Parser/Annotation.hs ===================================== @@ -259,6 +259,8 @@ data AnnKeywordId | AnnLarrow -- ^ '<-' | AnnLarrowU -- ^ '<-', unicode variant | AnnLet + | AnnLolly -- ^ '#->' + | AnnLollyU -- ^ '#->', unicode variant | AnnMdo | AnnMinus -- ^ '-' | AnnModule @@ -291,8 +293,6 @@ data AnnKeywordId | AnnStatic -- ^ 'static' | AnnStock | AnnThen - | AnnThIdSplice -- ^ '$' - | AnnThIdTySplice -- ^ '$$' | AnnThTyQuote -- ^ double ''' | AnnTilde -- ^ '~' | AnnType @@ -364,6 +364,7 @@ unicodeAnn AnnOpenB = AnnOpenBU unicodeAnn AnnCloseB = AnnCloseBU unicodeAnn AnnOpenEQ = AnnOpenEQU unicodeAnn AnnCloseQ = AnnCloseQU +unicodeAnn AnnLolly = AnnLollyU unicodeAnn ann = ann ===================================== compiler/GHC/StgToCmm/Foreign.hs ===================================== @@ -261,7 +261,7 @@ load_target_into_temp other_target@(PrimTarget _) = -- What we want to do here is create a new temporary for the foreign -- call argument if it is not safe to use the expression directly, -- because the expression mentions caller-saves GlobalRegs (see --- Note [Register Parameter Passing]). +-- Note [Register parameter passing]). -- -- However, we can't pattern-match on the expression here, because -- this is used in a loop by GHC.Cmm.Parser, and testing the expression ===================================== compiler/GHC/StgToCmm/Utils.hs ===================================== @@ -243,7 +243,7 @@ emitRtsCallGen res lbl args safe -- shouldn't be doing the workaround at this point in the pipeline, see -- Note [Register parameter passing] and the ToDo on CmmCall in -- "GHC.Cmm.Node". Right now the workaround is to avoid inlining across --- unsafe foreign calls in rewriteAssignments, but this is strictly +-- unsafe foreign calls in GHC.Cmm.Sink, but this is strictly -- temporary. callerSaveVolatileRegs :: Platform -> (CmmAGraph, CmmAGraph) callerSaveVolatileRegs platform = (caller_save, caller_load) ===================================== includes/stg/MachRegs.h ===================================== @@ -61,6 +61,8 @@ are the RX, FX, DX and USER registers; as a result, if you decide to caller save a system register (e.g. SP, HP, etc), note that this code path is completely untested! -- EZY + + See Note [Register parameter passing] for details. -------------------------------------------------------------------------- */ /* ----------------------------------------------------------------------------- ===================================== testsuite/tests/codeGen/should_run/T18527.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +module Main where + +import Data.Bits (setBit) +import Data.Word (Word32) +import Data.Int (Int64) + +main :: IO () +main = offending 100 0 1 + +offending :: Int64 -> Int64 -> Word32 -> IO () +offending h i id = do + oldMask <- sendMessage h (2245) i 0 + let newMask = setBit oldMask (fromIntegral id) + sendMessage h (2244) i newMask + return () + +foreign import ccall "func" + sendMessage :: Int64 -> Word32 -> Int64 -> Int64 -> IO Int64 ===================================== testsuite/tests/codeGen/should_run/T18527.stdout ===================================== @@ -0,0 +1,3 @@ +ffi call +ffi call + ===================================== testsuite/tests/codeGen/should_run/T18527FFI.c ===================================== @@ -0,0 +1,14 @@ +#include +#include + +int64_t func(int64_t a, uint32_t b, int64_t c, int64_t d) { + printf("ffi call"); + if (a == 1) { + printf(" with corrupted convention\n"); + } + else { + printf("\n"); + } + return 0; +} + ===================================== testsuite/tests/codeGen/should_run/all.T ===================================== @@ -207,3 +207,4 @@ test('T16449_2', exit_code(0), compile_and_run, ['']) test('T16846', [only_ways(['optasm']), exit_code(1)], compile_and_run, ['']) test('T17920', cmm_src, compile_and_run, ['']) +test('T18527', normal, compile_and_run, ['T18527FFI.c']) ===================================== testsuite/tests/concurrent/prog001/all.T ===================================== @@ -16,4 +16,4 @@ test('concprog001', [extra_files(['Arithmetic.hs', 'Converter.hs', 'Mult.hs', 'S when(fast(), skip), only_ways(['threaded2']), fragile(16604), run_timeout_multiplier(2)], - multimod_compile_and_run, ['Mult', '']) + multimod_compile_and_run, ['Mult', '-package ghc']) ===================================== testsuite/tests/deSugar/should_run/DsDoExprFailMsg.hs ===================================== @@ -0,0 +1,3 @@ +main = do + (x:xs) <- return [] + return () ===================================== testsuite/tests/deSugar/should_run/DsDoExprFailMsg.stderr ===================================== @@ -0,0 +1 @@ +DsDoExprFailMsg: user error (Pattern match failure in 'do' block at DsDoExprFailMsg.hs:2:3-8) ===================================== testsuite/tests/deSugar/should_run/DsMonadCompFailMsg.hs ===================================== @@ -0,0 +1,2 @@ +{-# LANGUAGE MonadComprehensions #-} +main = [() | (x:xs) <- return []] ===================================== testsuite/tests/deSugar/should_run/DsMonadCompFailMsg.stderr ===================================== @@ -0,0 +1 @@ +DsMonadCompFailMsg: user error (Pattern match failure in monad comprehension at DsMonadCompFailMsg.hs:2:14-19) ===================================== testsuite/tests/deSugar/should_run/all.T ===================================== @@ -66,3 +66,6 @@ test('T12595', normal, compile_and_run, ['']) test('T13285', normal, compile_and_run, ['']) test('T18151', normal, compile_and_run, ['']) test('T18172', [], ghci_script, ['T18172.script']) + +test('DsDoExprFailMsg', exit_code(1), compile_and_run, ['']) +test('DsMonadCompFailMsg', exit_code(1), compile_and_run, ['']) ===================================== utils/check-api-annotations/Main.hs ===================================== @@ -5,7 +5,6 @@ import Data.List import GHC import GHC.Driver.Session import GHC.Utils.Outputable -import GHC.Parser.Annotation import GHC.Types.SrcLoc import System.Environment( getArgs ) import System.Exit View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2edc326efadb1d9cb9e412ecbee47cc9bf3d9b31...15932b2a8d418a5e6b13acd4fc20e34fde9844df -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2edc326efadb1d9cb9e412ecbee47cc9bf3d9b31...15932b2a8d418a5e6b13acd4fc20e34fde9844df You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 8 03:22:05 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Fri, 07 Aug 2020 23:22:05 -0400 Subject: [Git][ghc/ghc][ghc-8.10] 3 commits: nativeGen: One approach to fix #18527 Message-ID: <5f2e1a5d3cfde_80b3f8468e02b547116219@gitlab.haskell.org.mail> Ben Gamari pushed to branch ghc-8.10 at Glasgow Haskell Compiler / GHC Commits: b260f31f by Ben Gamari at 2020-08-06T17:10:00-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. (cherry picked from commit a647bae8518e96156eb7775c4cede52b69f711d7) - - - - - 44f958c8 by Ben Gamari at 2020-08-06T17:10:00-04:00 testsuite: Add test for #18527 - - - - - 29204b1c by Ben Gamari at 2020-08-07T10:53:04-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. (cherry picked from commit d589ef25f54862968976bc279eb6748509794566) - - - - - 7 changed files: - aclocal.m4 - compiler/cmm/CmmMachOp.hs - compiler/nativeGen/X86/CodeGen.hs - + testsuite/tests/codeGen/should_run/T18527.hs - + testsuite/tests/codeGen/should_run/T18527.stdout - + testsuite/tests/codeGen/should_run/T18527FFI.c - testsuite/tests/codeGen/should_run/all.T Changes: ===================================== aclocal.m4 ===================================== @@ -2527,7 +2527,7 @@ AC_DEFUN([FIND_LD],[ # Sets $result to 0 if not affected, 1 otherwise AC_DEFUN([CHECK_FOR_GOLD_T22266],[ AC_MSG_CHECKING([for ld.gold object merging bug (binutils 22266)]) - if ! $1 --version | grep -v -q "GNU gold"; then + if ! $1 --version | grep -q "GNU gold"; then # Not gold result=0 elif test "$cross_compiling" = "yes"; then ===================================== compiler/cmm/CmmMachOp.hs ===================================== @@ -43,6 +43,9 @@ native code generators to handle. Most operations are parameterised by the 'Width' that they operate on. Some operations have separate signed and unsigned versions, and float and integer versions. + +Note that there are variety of places in the native code generator where we +assume that the code produced for a MachOp does not introduce new blocks. -} data MachOp ===================================== compiler/nativeGen/X86/CodeGen.hs ===================================== @@ -292,11 +292,11 @@ we construct as a separate data type and the actual control flow graph in the co Instead we now return the new basic block if a statement causes a change in the current block and use the block for all following statements. -For this reason genCCall is also split into two parts. -One for calls which *won't* change the basic blocks in -which successive instructions will be placed. -A different one for calls which *are* known to change the -basic block. +For this reason genCCall is also split into two parts. One for calls which +*won't* change the basic blocks in which successive instructions will be +placed (since they only evaluate CmmExpr, which can only contain MachOps, which +cannot introduce basic blocks in their lowerings). A different one for calls +which *are* known to change the basic block. -} @@ -1037,6 +1037,9 @@ getRegister' _ is32Bit (CmmMachOp mop [x, y]) = do -- dyadic MachOps tmp. This is likely to be better, because the reg alloc can eliminate this reg->reg move here (it won't eliminate the other one, because the move is into the fixed %ecx). + * in the case of C calls the use of ecx here can interfere with arguments. + We avoid this with the hack described in Note [Evaluate C-call + arguments before placing in destination registers] -} shift_code width instr x y{-amount-} = do x_code <- getAnyReg x @@ -2614,9 +2617,12 @@ genCCall' _ is32Bit target dest_regs args bid = do return code _ -> panic "genCCall: Wrong number of arguments/results for mul2" - _ -> if is32Bit - then genCCall32' dflags target dest_regs args - else genCCall64' dflags target dest_regs args + _ -> do + (instrs0, args') <- evalArgs bid args + instrs1 <- if is32Bit + then genCCall32' dflags target dest_regs args' + else genCCall64' dflags target dest_regs args' + return (instrs0 `appOL` instrs1) where divOp1 platform signed width results [arg_x, arg_y] = divOp platform signed width results Nothing arg_x arg_y @@ -2679,6 +2685,83 @@ genCCall' _ is32Bit target dest_regs args bid = do addSubIntC _ _ _ _ _ _ _ _ = panic "genCCall: Wrong number of arguments/results for addSubIntC" +{- +Note [Evaluate C-call arguments before placing in destination registers] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When producing code for C calls we must take care when placing arguments +in their final registers. Specifically, we must ensure that temporary register +usage due to evaluation of one argument does not clobber a register in which we +already placed a previous argument (e.g. as the code generation logic for +MO_Shl can clobber %rcx due to x86 instruction limitations). + +This is precisely what happened in #18527. Consider this C--: + + (result::I64) = call "ccall" doSomething(_s2hp::I64, 2244, _s2hq::I64, _s2hw::I64 | (1 << _s2hz::I64)); + +Here we are calling the C function `doSomething` with three arguments, the last +involving a non-trivial expression involving MO_Shl. In this case the NCG could +naively generate the following assembly (where $tmp denotes some temporary +register and $argN denotes the register for argument N, as dictated by the +platform's calling convention): + + mov _s2hp, $arg1 # place first argument + mov _s2hq, $arg2 # place second argument + + # Compute 1 << _s2hz + mov _s2hz, %rcx + shl %cl, $tmp + + # Compute (_s2hw | (1 << _s2hz)) + mov _s2hw, $arg3 + or $tmp, $arg3 + + # Perform the call + call func + +This code is outright broken on Windows which assigns $arg1 to %rcx. This means +that the evaluation of the last argument clobbers the first argument. + +To avoid this we use a rather awful hack: when producing code for a C call with +at least one non-trivial argument, we first evaluate all of the arguments into +local registers before moving them into their final calling-convention-defined +homes. This is performed by 'evalArgs'. Here we define "non-trivial" to be an +expression which might contain a MachOp since these are the only cases which +might clobber registers. Furthermore, we use a conservative approximation of +this condition (only looking at the top-level of CmmExprs) to avoid spending +too much effort trying to decide whether we want to take the fast path. + +Note that this hack *also* applies to calls to out-of-line PrimTargets (which +are lowered via a C call) since outOfLineCmmOp produces the call via +(stmtToInstrs (CmmUnsafeForeignCall ...)), which will ultimately end up +back in genCCall{32,64}. +-} + +-- | See Note [Evaluate C-call arguments before placing in destination registers] +evalArgs :: BlockId -> [CmmActual] -> NatM (InstrBlock, [CmmActual]) +evalArgs bid actuals + | any mightContainMachOp actuals = do + regs_blks <- mapM evalArg actuals + return (concatOL $ map fst regs_blks, map snd regs_blks) + | otherwise = return (nilOL, actuals) + where + mightContainMachOp (CmmReg _) = False + mightContainMachOp (CmmRegOff _ _) = False + mightContainMachOp (CmmLit _) = False + mightContainMachOp _ = True + + evalArg :: CmmActual -> NatM (InstrBlock, CmmExpr) + evalArg actual = do + dflags <- getDynFlags + lreg <- newLocalReg $ cmmExprType dflags actual + (instrs, bid1) <- stmtToInstrs bid $ CmmAssign (CmmLocal lreg) actual + -- The above assignment shouldn't change the current block + MASSERT(isNothing bid1) + return (instrs, CmmReg $ CmmLocal lreg) + + newLocalReg :: CmmType -> NatM LocalReg + newLocalReg ty = LocalReg <$> getUniqueM <*> pure ty + -- Note [DIV/IDIV for bytes] -- -- IDIV reminder: ===================================== testsuite/tests/codeGen/should_run/T18527.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +module Main where + +import Data.Bits (setBit) +import Data.Word (Word32) +import Data.Int (Int64) + +main :: IO () +main = offending 100 0 1 + +offending :: Int64 -> Int64 -> Word32 -> IO () +offending h i id = do + oldMask <- sendMessage h (2245) i 0 + let newMask = setBit oldMask (fromIntegral id) + sendMessage h (2244) i newMask + return () + +foreign import ccall "func" + sendMessage :: Int64 -> Word32 -> Int64 -> Int64 -> IO Int64 ===================================== testsuite/tests/codeGen/should_run/T18527.stdout ===================================== @@ -0,0 +1,3 @@ +ffi call +ffi call + ===================================== testsuite/tests/codeGen/should_run/T18527FFI.c ===================================== @@ -0,0 +1,14 @@ +#include +#include + +int64_t func(int64_t a, uint32_t b, int64_t c, int64_t d) { + printf("ffi call"); + if (a == 1) { + printf(" with corrupted convention\n"); + } + else { + printf("\n"); + } + return 0; +} + ===================================== testsuite/tests/codeGen/should_run/all.T ===================================== @@ -205,3 +205,4 @@ test('T16449_2', exit_code(0), compile_and_run, ['']) test('T16846', [only_ways(['optasm']), exit_code(1)], compile_and_run, ['']) test('T17920', cmm_src, compile_and_run, ['']) +test('T18527', normal, compile_and_run, ['T18527FFI.c']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e69b0d42d88794837694429d33667c2f20931820...29204b1c4f52ea34d84da33593052ee839293bf2 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e69b0d42d88794837694429d33667c2f20931820...29204b1c4f52ea34d84da33593052ee839293bf2 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 8 03:58:16 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 07 Aug 2020 23:58:16 -0400 Subject: [Git][ghc/ghc][master] ApiAnnotations; tweaks for ghc-exactprint update Message-ID: <5f2e22d8e77f8_80b3f848c1e06f4711672b@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 4 changed files: - compiler/GHC.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Annotation.hs - utils/check-api-annotations/Main.hs Changes: ===================================== compiler/GHC.hs ===================================== @@ -248,7 +248,7 @@ module GHC ( srcSpanStartCol, srcSpanEndCol, -- ** Located - GenLocated(..), Located, + GenLocated(..), Located, RealLocated, -- *** Constructing Located noLoc, mkGeneralLocated, @@ -274,7 +274,7 @@ module GHC ( parser, -- * API Annotations - ApiAnns(..),AnnKeywordId(..),AnnotationComment(..), + ApiAnns(..),AnnKeywordId(..),AnnotationComment(..), ApiAnnKey, getAnnotation, getAndRemoveAnnotation, getAnnotationComments, getAndRemoveAnnotationComments, unicodeAnn, ===================================== compiler/GHC/Parser.y ===================================== @@ -863,17 +863,17 @@ header_top_importdecls :: { [LImportDecl GhcPs] } -- The Export List maybeexports :: { (Maybe (Located [LIE GhcPs])) } - : '(' exportlist ')' {% amsL (comb2 $1 $>) [mop $1,mcp $3] >> - return (Just (sLL $1 $> (fromOL $2))) } + : '(' exportlist ')' {% amsL (comb2 $1 $>) ([mop $1,mcp $3] ++ (fst $2)) >> + return (Just (sLL $1 $> (fromOL $ snd $2))) } | {- empty -} { Nothing } -exportlist :: { OrdList (LIE GhcPs) } - : exportlist1 { $1 } - | {- empty -} { nilOL } +exportlist :: { ([AddAnn], OrdList (LIE GhcPs)) } + : exportlist1 { ([], $1) } + | {- empty -} { ([], nilOL) } -- trailing comma: - | exportlist1 ',' { $1 } - | ',' { nilOL } + | exportlist1 ',' { ([mj AnnComma $2], $1) } + | ',' { ([mj AnnComma $1], nilOL) } exportlist1 :: { OrdList (LIE GhcPs) } : exportlist1 ',' export @@ -1019,11 +1019,11 @@ maybeimpspec :: { Located (Maybe (Bool, Located [LIE GhcPs])) } impspec :: { Located (Bool, Located [LIE GhcPs]) } : '(' exportlist ')' {% ams (sLL $1 $> (False, - sLL $1 $> $ fromOL $2)) - [mop $1,mcp $3] } + sLL $1 $> $ fromOL (snd $2))) + ([mop $1,mcp $3] ++ (fst $2)) } | 'hiding' '(' exportlist ')' {% ams (sLL $1 $> (True, - sLL $1 $> $ fromOL $3)) - [mj AnnHiding $1,mop $2,mcp $4] } + sLL $1 $> $ fromOL (snd $3))) + ([mj AnnHiding $1,mop $2,mcp $4] ++ (fst $3)) } ----------------------------------------------------------------------------- -- Fixity Declarations ===================================== compiler/GHC/Parser/Annotation.hs ===================================== @@ -259,6 +259,8 @@ data AnnKeywordId | AnnLarrow -- ^ '<-' | AnnLarrowU -- ^ '<-', unicode variant | AnnLet + | AnnLolly -- ^ '#->' + | AnnLollyU -- ^ '#->', unicode variant | AnnMdo | AnnMinus -- ^ '-' | AnnModule @@ -291,8 +293,6 @@ data AnnKeywordId | AnnStatic -- ^ 'static' | AnnStock | AnnThen - | AnnThIdSplice -- ^ '$' - | AnnThIdTySplice -- ^ '$$' | AnnThTyQuote -- ^ double ''' | AnnTilde -- ^ '~' | AnnType @@ -364,6 +364,7 @@ unicodeAnn AnnOpenB = AnnOpenBU unicodeAnn AnnCloseB = AnnCloseBU unicodeAnn AnnOpenEQ = AnnOpenEQU unicodeAnn AnnCloseQ = AnnCloseQU +unicodeAnn AnnLolly = AnnLollyU unicodeAnn ann = ann ===================================== utils/check-api-annotations/Main.hs ===================================== @@ -5,7 +5,6 @@ import Data.List import GHC import GHC.Driver.Session import GHC.Utils.Outputable -import GHC.Parser.Annotation import GHC.Types.SrcLoc import System.Environment( getArgs ) import System.Exit View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e4f1b73ad9f292a6bbeb21fee44b0ba1a7f3c33b -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e4f1b73ad9f292a6bbeb21fee44b0ba1a7f3c33b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 8 03:58:50 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 07 Aug 2020 23:58:50 -0400 Subject: [Git][ghc/ghc][master] configure: Fix double-negation in ld merge-objects check Message-ID: <5f2e22fa3aa86_80b3f848c1e06f47119628@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - 1 changed file: - aclocal.m4 Changes: ===================================== aclocal.m4 ===================================== @@ -2543,7 +2543,7 @@ AC_DEFUN([FIND_LD],[ # Sets $result to 0 if not affected, 1 otherwise AC_DEFUN([CHECK_FOR_GOLD_T22266],[ AC_MSG_CHECKING([for ld.gold object merging bug (binutils 22266)]) - if ! $1 --version | grep -v -q "GNU gold"; then + if ! $1 --version | grep -q "GNU gold"; then # Not gold result=0 elif test "$cross_compiling" = "yes"; then View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8a665db6174eaedbbae925c0ccb4c22b3f29bcaf -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8a665db6174eaedbbae925c0ccb4c22b3f29bcaf You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 8 13:26:34 2020 From: gitlab at gitlab.haskell.org (Josh Meredith) Date: Sat, 08 Aug 2020 09:26:34 -0400 Subject: [Git][ghc/ghc][wip/pluginExtFields] 11 commits: A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure Message-ID: <5f2ea80a8ec7e_80b8ca3ed071346af@gitlab.haskell.org.mail> Josh Meredith pushed to branch wip/pluginExtFields at Glasgow Haskell Compiler / GHC Commits: 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - 87f739e4 by Josh Meredith at 2020-08-08T09:26:33-04:00 Add machinery for plugins to write data to extensible interface fields - - - - - 1a68c2a3 by Josh Meredith at 2020-08-08T09:26:33-04:00 Add function to remove plugin interface fields - - - - - 30 changed files: - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Expr.hs-boot - compiler/GHC/HsToCore/ListComp.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/IfaceToCore.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Annotation.hs - compiler/GHC/StgToCmm/Foreign.hs - compiler/GHC/StgToCmm/Utils.hs - includes/stg/MachRegs.h - + testsuite/tests/codeGen/should_run/T18527.hs - + testsuite/tests/codeGen/should_run/T18527.stdout - + testsuite/tests/codeGen/should_run/T18527FFI.c - testsuite/tests/codeGen/should_run/all.T - testsuite/tests/concurrent/prog001/all.T - + testsuite/tests/deSugar/should_run/DsDoExprFailMsg.hs - + testsuite/tests/deSugar/should_run/DsDoExprFailMsg.stderr - + testsuite/tests/deSugar/should_run/DsMonadCompFailMsg.hs - + testsuite/tests/deSugar/should_run/DsMonadCompFailMsg.stderr - testsuite/tests/deSugar/should_run/all.T The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/22587e7f929d0457ed4a4bd91548cbe839432d47...1a68c2a3db5dbd89431474a9ded0f47050eb5410 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/22587e7f929d0457ed4a4bd91548cbe839432d47...1a68c2a3db5dbd89431474a9ded0f47050eb5410 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 8 15:44:26 2020 From: gitlab at gitlab.haskell.org (Sylvain Henry) Date: Sat, 08 Aug 2020 11:44:26 -0400 Subject: [Git][ghc/ghc][wip/int64-everywhere] 125 commits: Revert "AArch32 symbols only on aarch32." Message-ID: <5f2ec85a6ffae_80b3f8468e02b5471422ac@gitlab.haskell.org.mail> Sylvain Henry pushed to branch wip/int64-everywhere at Glasgow Haskell Compiler / GHC Commits: 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - f9286516 by John Ericson at 2020-08-08T17:43:32+02:00 Make fixed-size `Int32#` and `Int64#` The boxed Int64 uses Int64#, but Int32# still uses Int#. The 32-bit case is less pressing to change because it is not a source of brittle CPP---it is the same thing on all platforms. We need Int64/Word64 constant folding to avoid the let/app restriction on Core, so that is implemented now. 32-bit constant unfolding and 32-bit literals are left as follow-up. This is the bulk of #11953 - - - - - f234e85a by John Ericson at 2020-08-08T17:43:32+02:00 Inline INT64 and WORD64 macros in primops.txt.pp The definition is now unconditional so there is no reason for that CPP. - - - - - e47884cd by Sylvain Henry at 2020-08-08T17:43:32+02:00 ghc-bignum: add support for Word64#/Int64# on 64-bit arch - - - - - 7d9873aa by Sylvain Henry at 2020-08-08T17:43:32+02:00 Fix fingerprint Core generation - - - - - bb7cc73d by Sylvain Henry at 2020-08-08T17:43:32+02:00 Fix some tests - - - - - e18f3949 by Sylvain Henry at 2020-08-08T17:43:32+02:00 Fix toArgRep - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/test-metrics.sh - CODEOWNERS - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/Graph.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Monad.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Switch/Implement.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7889c584da61dd9da81e7df24d54fd8855e8ee68...e18f3949396a63cb56477186f12e70f444fdcc84 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7889c584da61dd9da81e7df24d54fd8855e8ee68...e18f3949396a63cb56477186f12e70f444fdcc84 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 8 18:10:34 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Sat, 08 Aug 2020 14:10:34 -0400 Subject: [Git][ghc/ghc][wip/az/ghc-9.0-anns] 2 commits: Include API Annotations for trailing comma in export list Message-ID: <5f2eea9a4081e_80b3f848a372f8c7148317@gitlab.haskell.org.mail> Alan Zimmerman pushed to branch wip/az/ghc-9.0-anns at Glasgow Haskell Compiler / GHC Commits: 59984655 by Alan Zimmerman at 2020-08-06T08:35:44+01:00 Include API Annotations for trailing comma in export list - - - - - 8dbee2c5 by Alan Zimmerman at 2020-08-08T19:10:03+01:00 Api Annotations : Adjust SrsSpans for prefix bang (!). And prefix ~ - - - - - 4 changed files: - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - testsuite/tests/ghc-api/annotations/Makefile - testsuite/tests/ghc-api/annotations/T10358.stdout Changes: ===================================== compiler/GHC/Parser.y ===================================== @@ -863,17 +863,17 @@ header_top_importdecls :: { [LImportDecl GhcPs] } -- The Export List maybeexports :: { (Maybe (Located [LIE GhcPs])) } - : '(' exportlist ')' {% amsL (comb2 $1 $>) [mop $1,mcp $3] >> - return (Just (sLL $1 $> (fromOL $2))) } + : '(' exportlist ')' {% amsL (comb2 $1 $>) ([mop $1,mcp $3] ++ (fst $2)) >> + return (Just (sLL $1 $> (fromOL $ snd $2))) } | {- empty -} { Nothing } -exportlist :: { OrdList (LIE GhcPs) } - : exportlist1 { $1 } - | {- empty -} { nilOL } +exportlist :: { ([AddAnn], OrdList (LIE GhcPs)) } + : exportlist1 { ([], $1) } + | {- empty -} { ([], nilOL) } -- trailing comma: - | exportlist1 ',' { $1 } - | ',' { nilOL } + | exportlist1 ',' { ([mj AnnComma $2], $1) } + | ',' { ([mj AnnComma $1], nilOL) } exportlist1 :: { OrdList (LIE GhcPs) } : exportlist1 ',' export @@ -1019,11 +1019,11 @@ maybeimpspec :: { Located (Maybe (Bool, Located [LIE GhcPs])) } impspec :: { Located (Bool, Located [LIE GhcPs]) } : '(' exportlist ')' {% ams (sLL $1 $> (False, - sLL $1 $> $ fromOL $2)) - [mop $1,mcp $3] } + sLL $1 $> $ fromOL (snd $2))) + ([mop $1,mcp $3] ++ (fst $2)) } | 'hiding' '(' exportlist ')' {% ams (sLL $1 $> (True, - sLL $1 $> $ fromOL $3)) - [mj AnnHiding $1,mop $2,mcp $4] } + sLL $1 $> $ fromOL (snd $3))) + ([mj AnnHiding $1,mop $2,mcp $4] ++ (fst $3)) } ----------------------------------------------------------------------------- -- Fixity Declarations ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -1231,13 +1231,14 @@ makeFunBind fn ms checkPatBind :: LPat GhcPs -> Located (a,GRHSs GhcPs (LHsExpr GhcPs)) -> P ([AddAnn],HsBind GhcPs) -checkPatBind lhs (L match_span (_,grhss)) +checkPatBind lhs (L rhs_span (_,grhss)) | BangPat _ p <- unLoc lhs , VarPat _ v <- unLoc p = return ([], makeFunBind v [L match_span (m v)]) where + match_span = combineSrcSpans (getLoc lhs) rhs_span m v = Match { m_ext = noExtField - , m_ctxt = FunRhs { mc_fun = L (getLoc lhs) (unLoc v) + , m_ctxt = FunRhs { mc_fun = v , mc_fixity = Prefix , mc_strictness = SrcStrict } , m_pats = [] @@ -1373,19 +1374,24 @@ pBangTy lt@(L l1 _) xs = Nothing -> (False, lt, pure (), xs) Just (l2, anns, prag, unpk, xs') -> let bl = combineSrcSpans l1 l2 - bt = addUnpackedness (prag, unpk) lt - in (True, L bl bt, addAnnsAt bl anns, xs') + (anns2, bt) = addUnpackedness (prag, unpk) lt + in (True, L bl bt, addAnnsAt bl (anns ++ anns2), xs') mkBangTy :: SrcStrictness -> LHsType GhcPs -> HsType GhcPs mkBangTy strictness = HsBangTy noExtField (HsSrcBang NoSourceText NoSrcUnpack strictness) -addUnpackedness :: (SourceText, SrcUnpackedness) -> LHsType GhcPs -> HsType GhcPs -addUnpackedness (prag, unpk) (L _ (HsBangTy x bang t)) +addUnpackedness :: (SourceText, SrcUnpackedness) -> LHsType GhcPs -> ([AddAnn], HsType GhcPs) +addUnpackedness (prag, unpk) (L l (HsBangTy x bang t)) | HsSrcBang NoSourceText NoSrcUnpack strictness <- bang - = HsBangTy x (HsSrcBang prag unpk strictness) t + = let + anns = case strictness of + SrcLazy -> [AddAnn AnnTilde (srcSpanFirstCharacter l)] + SrcStrict -> [AddAnn AnnBang (srcSpanFirstCharacter l)] + NoSrcStrict -> [] + in (anns, HsBangTy x (HsSrcBang prag unpk strictness) t) addUnpackedness (prag, unpk) t - = HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t + = ([], HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t) -- | Merge a /reversed/ and /non-empty/ soup of operators and operands -- into a type. ===================================== testsuite/tests/ghc-api/annotations/Makefile ===================================== @@ -39,7 +39,8 @@ listcomps: .PHONY: T10358 T10358: - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358.hs + # Ignore result code, we have an unattached (superfluous) AnnBang + - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358.hs .PHONY: T10396 T10396: ===================================== testsuite/tests/ghc-api/annotations/T10358.stdout ===================================== @@ -1,5 +1,5 @@ ---Unattached Annotation Problems (should be empty list)--- -[] +[(AnnBang, Test10358.hs:5:19)] ---Ann before enclosing span problem (should be empty list)--- [ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f31cb332f644f3ff3b45aba35b3d8d252885c67a...8dbee2c578b1f642d45561be3f416119863e01eb -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f31cb332f644f3ff3b45aba35b3d8d252885c67a...8dbee2c578b1f642d45561be3f416119863e01eb You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 8 20:29:01 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Sat, 08 Aug 2020 16:29:01 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/az/anns-2 Message-ID: <5f2f0b0db385f_80b3f848c1e06f4714876a@gitlab.haskell.org.mail> Alan Zimmerman pushed new branch wip/az/anns-2 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/az/anns-2 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 8 21:43:55 2020 From: gitlab at gitlab.haskell.org (Sylvain Henry) Date: Sat, 08 Aug 2020 17:43:55 -0400 Subject: [Git][ghc/ghc][wip/int64-everywhere] Adapt rules from #16402 to Word64#/Int64# Message-ID: <5f2f1c9b1940f_80b3f848a372f8c7153715@gitlab.haskell.org.mail> Sylvain Henry pushed to branch wip/int64-everywhere at Glasgow Haskell Compiler / GHC Commits: d59df82c by Sylvain Henry at 2020-08-08T23:42:56+02:00 Adapt rules from #16402 to Word64#/Int64# - - - - - 2 changed files: - compiler/GHC/Core/Opt/ConstantFold.hs - testsuite/tests/numeric/should_compile/T16402.stderr Changes: ===================================== compiler/GHC/Core/Opt/ConstantFold.hs ===================================== @@ -781,16 +781,44 @@ subsumedByPrimOp primop = do -- e.g. narrow16 (x .&. 0xFFFF) -- ==> narrow16 x -- +-- Additionally, it detects casts from Word64/Int64 such as +-- +-- narrow16Word (word64ToWord (x .&. 0xFFFF)) +-- ==> narrow16 (word64ToWord x .&. 0xFFFF) +-- +-- narrow16Int (int64ToInt (word64ToInt64 (x .&. 0xFFFF))) +-- ==> narrow16 (int64ToInt (word64ToInt64 x) .&. 0xFFFF) +-- +-- These rules have been introduced to avoid breaking #16402 when Int64#/Word64# +-- primitives types and primops were added. They are quite ad-hoc but it is +-- expected that in the near future we will revisit them when we'll add support +-- for Int8#/Int16#/Int32# and Word8#/Word16#/Word32#. +-- narrowSubsumesAnd :: PrimOp -> PrimOp -> Int -> RuleM CoreExpr -narrowSubsumesAnd and_primop narrw n = do - [Var primop_id `App` x `App` y] <- getArgs - matchPrimOpId and_primop primop_id - let mask = bit n -1 +narrowSubsumesAnd and_primop narrw n = msum + [ do [Var primop_id `App` x `App` y] <- getArgs + matchPrimOpId and_primop primop_id + g x y <|> g y x + + , do [Var w64tow `App` (Var primop_id `App` x `App` y)] <- getArgs + matchPrimOpId Word64ToWord w64tow + matchPrimOpId Word64AndOp primop_id + let f k = Var w64tow `App` k + g (f x) y <|> g (f y) x + + , do [Var i64toi `App` (Var w64toi64 `App` (Var primop_id `App` x `App` y))] <- getArgs + matchPrimOpId Int64ToInt i64toi + matchPrimOpId Word64ToInt64Op w64toi64 + matchPrimOpId Word64AndOp primop_id + let f k = Var i64toi `App` (Var w64toi64 `App` k) + g (f x) y <|> g (f y) x + ] + where + mask = bit n - 1 g v (Lit (LitNumber _ m)) = do guard (m .&. mask == mask) return (Var (mkPrimOpId narrw) `App` v) g _ _ = mzero - g x y <|> g y x idempotent :: RuleM CoreExpr idempotent = do [e1, e2] <- getArgs ===================================== testsuite/tests/numeric/should_compile/T16402.stderr ===================================== @@ -1,7 +1,7 @@ ==================== Tidy Core ==================== Result size of Tidy Core - = {terms: 34, types: 19, coercions: 0, joins: 0/0} + = {terms: 38, types: 19, coercions: 0, joins: 0/0} -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} $trModule4 = "main"# @@ -18,16 +18,22 @@ $trModule1 = TrNameS $trModule2 -- RHS size: {terms: 3, types: 0, coercions: 0, joins: 0/0} $trModule = Module $trModule3 $trModule1 --- RHS size: {terms: 7, types: 3, coercions: 0, joins: 0/0} +-- RHS size: {terms: 9, types: 3, coercions: 0, joins: 0/0} smallWord_bar - = \ x -> case x of { W64# x# -> W64# (narrow16Word# x#) } + = \ x -> + case x of { W64# x# -> + W64# (wordToWord64# (narrow16Word# (word64ToWord# x#))) + } -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} smallWord_foo = smallWord_bar --- RHS size: {terms: 7, types: 3, coercions: 0, joins: 0/0} +-- RHS size: {terms: 9, types: 3, coercions: 0, joins: 0/0} smallInt_bar - = \ x -> case x of { I64# x# -> I64# (narrow16Int# x#) } + = \ x -> + case x of { I64# x# -> + I64# (intToInt64# (narrow16Int# (int64ToInt# x#))) + } -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} smallInt_foo = smallInt_bar View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d59df82c0e00045d6e72cc10acaf336d5a21c61e -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d59df82c0e00045d6e72cc10acaf336d5a21c61e You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 8 21:45:29 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sat, 08 Aug 2020 17:45:29 -0400 Subject: [Git][ghc/ghc] Pushed new tag ghc-8.10.2-release Message-ID: <5f2f1cf9e00df_80b10e6f9b471541bc@gitlab.haskell.org.mail> Ben Gamari pushed new tag ghc-8.10.2-release at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/ghc-8.10.2-release You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 8 21:46:16 2020 From: gitlab at gitlab.haskell.org (Sylvain Henry) Date: Sat, 08 Aug 2020 17:46:16 -0400 Subject: [Git][ghc/ghc][wip/int64-everywhere] Adapt rules from #16402 to Word64#/Int64# Message-ID: <5f2f1d284298d_80b10e6f9b4715439c@gitlab.haskell.org.mail> Sylvain Henry pushed to branch wip/int64-everywhere at Glasgow Haskell Compiler / GHC Commits: 0e934b9d by Sylvain Henry at 2020-08-08T23:45:39+02:00 Adapt rules from #16402 to Word64#/Int64# - - - - - 2 changed files: - compiler/GHC/Core/Opt/ConstantFold.hs - testsuite/tests/numeric/should_compile/T16402.stderr Changes: ===================================== compiler/GHC/Core/Opt/ConstantFold.hs ===================================== @@ -781,16 +781,44 @@ subsumedByPrimOp primop = do -- e.g. narrow16 (x .&. 0xFFFF) -- ==> narrow16 x -- +-- Additionally, it detects casts from Word64/Int64 such as +-- +-- narrow16Word (word64ToWord (x .&. 0xFFFF)) +-- ==> narrow16 (word64ToWord x) +-- +-- narrow16Int (int64ToInt (word64ToInt64 (x .&. 0xFFFF))) +-- ==> narrow16 (int64ToInt (word64ToInt64 x)) +-- +-- These rules have been introduced to avoid breaking #16402 when Int64#/Word64# +-- primitives types and primops were added. They are quite ad-hoc but it is +-- expected that in the near future we will revisit them when we'll add support +-- for Int8#/Int16#/Int32# and Word8#/Word16#/Word32#. +-- narrowSubsumesAnd :: PrimOp -> PrimOp -> Int -> RuleM CoreExpr -narrowSubsumesAnd and_primop narrw n = do - [Var primop_id `App` x `App` y] <- getArgs - matchPrimOpId and_primop primop_id - let mask = bit n -1 +narrowSubsumesAnd and_primop narrw n = msum + [ do [Var primop_id `App` x `App` y] <- getArgs + matchPrimOpId and_primop primop_id + g x y <|> g y x + + , do [Var w64tow `App` (Var primop_id `App` x `App` y)] <- getArgs + matchPrimOpId Word64ToWord w64tow + matchPrimOpId Word64AndOp primop_id + let f k = Var w64tow `App` k + g (f x) y <|> g (f y) x + + , do [Var i64toi `App` (Var w64toi64 `App` (Var primop_id `App` x `App` y))] <- getArgs + matchPrimOpId Int64ToInt i64toi + matchPrimOpId Word64ToInt64Op w64toi64 + matchPrimOpId Word64AndOp primop_id + let f k = Var i64toi `App` (Var w64toi64 `App` k) + g (f x) y <|> g (f y) x + ] + where + mask = bit n - 1 g v (Lit (LitNumber _ m)) = do guard (m .&. mask == mask) return (Var (mkPrimOpId narrw) `App` v) g _ _ = mzero - g x y <|> g y x idempotent :: RuleM CoreExpr idempotent = do [e1, e2] <- getArgs ===================================== testsuite/tests/numeric/should_compile/T16402.stderr ===================================== @@ -1,7 +1,7 @@ ==================== Tidy Core ==================== Result size of Tidy Core - = {terms: 34, types: 19, coercions: 0, joins: 0/0} + = {terms: 38, types: 19, coercions: 0, joins: 0/0} -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} $trModule4 = "main"# @@ -18,16 +18,22 @@ $trModule1 = TrNameS $trModule2 -- RHS size: {terms: 3, types: 0, coercions: 0, joins: 0/0} $trModule = Module $trModule3 $trModule1 --- RHS size: {terms: 7, types: 3, coercions: 0, joins: 0/0} +-- RHS size: {terms: 9, types: 3, coercions: 0, joins: 0/0} smallWord_bar - = \ x -> case x of { W64# x# -> W64# (narrow16Word# x#) } + = \ x -> + case x of { W64# x# -> + W64# (wordToWord64# (narrow16Word# (word64ToWord# x#))) + } -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} smallWord_foo = smallWord_bar --- RHS size: {terms: 7, types: 3, coercions: 0, joins: 0/0} +-- RHS size: {terms: 9, types: 3, coercions: 0, joins: 0/0} smallInt_bar - = \ x -> case x of { I64# x# -> I64# (narrow16Int# x#) } + = \ x -> + case x of { I64# x# -> + I64# (intToInt64# (narrow16Int# (int64ToInt# x#))) + } -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} smallInt_foo = smallInt_bar View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0e934b9da700172d5b70575a5df69549694a37c4 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0e934b9da700172d5b70575a5df69549694a37c4 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 8 21:51:14 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sat, 08 Aug 2020 17:51:14 -0400 Subject: [Git][ghc/ghc][wip/backports] 1344 commits: Changing Thread IDs from 32 bits to 64 bits. Message-ID: <5f2f1e52ce841_80b3f849c1caa107157755@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: e57b7cc6 by Roland Zumkeller at 2019-11-19T20:39:19-05:00 Changing Thread IDs from 32 bits to 64 bits. - - - - - d1f3c637 by Roland Zumkeller at 2019-11-19T20:39:19-05:00 Use pointer equality in Eq/Ord for ThreadId Changes (==) to use only pointer equality. This is safe because two threads are the same iff they have the same id. Changes `compare` to check pointer equality first and fall back on ids only in case of inequality. See discussion in #16761. - - - - - ef8a08e0 by Alexey Kuleshevich at 2019-11-19T20:39:20-05:00 hpc: Fix encoding issues. Add test for and fix #17073 * Make sure files are being read/written in UTF-8. Set encoding while writing HTML output. Also set encoding while writing and reading .tix files although we don't yet have a ticket complaining that this poses problems. * Set encoding in html header to utf8 * Upgrade to new version of 'hpc' library and reuse `readFileUtf8` and `writeFileUtf8` functions * Update git submodule for `hpc` * Bump up `hpc` executable version Co-authored-by: Ben Gamari <ben at smart-cactus.org> - - - - - b79e46d6 by Vladislav Zavialov at 2019-11-19T20:39:20-05:00 Strip parentheses in expressions contexts in error messages This makes error messages a tad less noisy. - - - - - 13bbde77 by Ben Gamari at 2019-11-21T13:56:56-05:00 Bump hsc2hs submodule Including Phyx's backport of the process changes fixing #17480. - - - - - d4d10501 by Ben Gamari at 2019-11-23T09:42:38-05:00 Bump hsc2hs submodule again This fixes the Darwin build. - - - - - 889d475b by nineonine at 2019-11-23T18:53:29-05:00 Fix typo in Note reference [skip ci] - - - - - 8a33abfc by Ryan Scott at 2019-11-23T18:54:05-05:00 Target the IsList instance for ZipList at base-4.14.0.0 (#17489) This moves the changelog entry about the instance from `base-4.15.0.0` to `base-4.14.0.0`. This accomplishes part (1) from #17489. [ci skip] - - - - - e43e6ece by Ben Gamari at 2019-11-23T18:54:41-05:00 rts: Expose interface for configuring EventLogWriters This exposes a set of interfaces from the GHC API for configuring EventLogWriters. These can be used by consumers like [ghc-eventlog-socket](https://github.com/bgamari/ghc-eventlog-socket). - - - - - de6bbdf2 by Matheus Magalhães de Alcantara at 2019-11-23T18:55:23-05:00 Take care to not eta-reduce jumps in CorePrep CorePrep already had a check to prevent it from eta-reducing Ids that respond true to hasNoBinding (foreign calls, constructors for unboxed sums and products, and Ids with compulsory unfoldings). It did not, however, consider join points as ids that 'must be saturated'. Checking whether the Id responds True to 'isJoinId' should prevent CorePrep from turning saturated jumps like the following (from #17429) into undersaturated ones: (\ eta_XP -> join { mapped_s1vo _ = lvl_s1vs } in jump mapped_s1vo eta_XP) - - - - - 4a1e7e47 by Matheus Magalhães de Alcantara at 2019-11-23T18:55:23-05:00 Make CorePrep.tryEtaReducePrep and CoreUtils.tryEtaReduce line up Simon PJ says he prefers this fix to #17429 over banning eta-reduction for jumps entirely. Sure enough, this also works. Test case: simplCore/should_compile/T17429.hs - - - - - 15f1dc33 by Ryan Scott at 2019-11-23T18:56:00-05:00 Prevent -optc arguments from being duplicated in reverse order (#17471) This reverts a part of commit 7bc5d6c6578ab9d60a83b81c7cc14819afef32ba that causes all arguments to `-optc` (and `-optcxx`) to be passed twice to the C/C++ compiler, once in reverse order and then again in the correct order. While passing duplicate arguments is usually harmless it can cause breakage in this pattern, which is employed by Hackage libraries in the wild: ``` ghc Foo.hs foo.c -optc-D -optcFOO ``` As `FOO -D -D FOO` will cause compilers to error. Fixes #17471. - - - - - e85c9b22 by Ben Gamari at 2019-11-23T18:56:36-05:00 Bump ghc version to 8.11 - - - - - 0e6c2045 by Ben Gamari at 2019-11-23T18:57:12-05:00 rts: Consolidate spinlock implementation Previously we had two distinct implementations: one with spinlock profiling and another without. This seems like needless duplication. - - - - - cb11fcb5 by Ben Gamari at 2019-11-23T18:57:49-05:00 Packages: Don't use expectJust Throw a slightly more informative error on failure. Motivated by the errors seen in !2160. - - - - - 5747ebe9 by Sebastian Graf at 2019-11-23T18:58:25-05:00 Stricten functions ins GHC.Natural This brings `Natural` on par with `Integer` and fixes #17499. Also does some manual CSE for 0 and 1 literals. - - - - - c14b723f by Ömer Sinan Ağacan at 2019-11-23T18:59:06-05:00 Bump exceptions submodule Adds a few files generated by GHC's configure script to .gitignore - - - - - 7b4c7b75 by Brian Wignall at 2019-11-23T19:04:52-05:00 Fix typos - - - - - 6008206a by Viktor Dukhovni at 2019-11-24T14:33:18-05:00 On FreeBSD 12 sys/sysctl.h requires sys/types.h Else build fails with: In file included from ExecutablePath.hsc:42: /usr/include/sys/sysctl.h:1062:25: error: unknown type name 'u_int'; did you mean 'int'? int sysctl(const int *, u_int, void *, size_t *, const void *, size_t); ^~~~~ int compiling libraries/base/dist-install/build/System/Environment/ExecutablePath_hsc_make.c failed (exit code 1) Perhaps also also other FreeBSD releases, but additional include will no harm even if not needed. - - - - - b694b566 by Ben Gamari at 2019-11-24T14:33:54-05:00 configure: Fix HAVE_C11_ATOMICS macro Previously we were using AC_DEFINE instead of AC_DEFINE_UNQUOTED, resulted in the variable not being interpolated. Fixes #17505. - - - - - 8b8dc366 by Krzysztof Gogolewski at 2019-11-25T14:37:38+01:00 Remove prefix arrow support for GADTs (#17211) This reverts the change in #9096. The specialcasing done for prefix (->) is brittle and does not support VTA, type families, type synonyms etc. - - - - - 5a08f7d4 by Sebastian Graf at 2019-11-27T00:14:59-05:00 Make warnings for TH splices opt-in In #17270 we have the pattern-match checker emit incorrect warnings. The reason for that behavior is ultimately an inconsistency in whether we treat TH splices as written by the user (`FromSource :: Origin`) or as generated code (`Generated`). This was first reported in #14838. The current solution is to TH splices as `Generated` by default and only treat them as `FromSource` when the user requests so (-fenable-th-splice-warnings). There are multiple reasons for opt-in rather than opt-out: * It's not clear that the user that compiles a splice is the author of the code that produces the warning. Think of the situation where she just splices in code from a third-party library that produces incomplete pattern matches. In this scenario, the user isn't even able to fix that warning. * Gathering information for producing the warnings (pattern-match check warnings in particular) is costly. There's no point in doing so if the user is not interested in those warnings. Fixes #17270, but not #14838, because the proper solution needs a GHC proposal extending the TH AST syntax. - - - - - 8168b42a by Vladislav Zavialov at 2019-11-27T11:32:18+03:00 Whitespace-sensitive bang patterns (#1087, #17162) This patch implements a part of GHC Proposal #229 that covers five operators: * the bang operator (!) * the tilde operator (~) * the at operator (@) * the dollar operator ($) * the double dollar operator ($$) Based on surrounding whitespace, these operators are disambiguated into bang patterns, lazy patterns, strictness annotations, type applications, splices, and typed splices. This patch doesn't cover the (-) operator or the -Woperator-whitespace warning, which are left as future work. - - - - - 9e5477c4 by Ryan Scott at 2019-11-27T20:01:50-05:00 Fix @since annotations for isResourceVanishedError and friends (#17488) - - - - - e122ba33 by Sergei Trofimovich at 2019-11-27T20:02:29-05:00 .gitmodules: tweak 'exception' URL to avoid redirection warnings Avoid initial close warning of form: ``` Cloning into 'exceptions'... warning: redirecting to https://gitlab.haskell.org/ghc/packages/exceptions.git/ ``` Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - 5f84b52a by Philipp Krüger at 2019-11-28T02:54:05-05:00 Reduce boolean blindness in OccInfo(OneOcc) #17482 * Transformed the type aliases `InterestingCxt`, `InsideLam` and `OneBranch` into data types. * Added Semigroup and Monoid instances for use in orOccInfo in OccurAnal.hs * Simplified some usage sites by using pattern matching instead of boolean algebra. Metric Increase: T12150 This increase was on a Mac-build of exactly 1%. This commit does *not* re-intruduce the asymptotic memory usage described in T12150. - - - - - 3748ba3a by Brian Wignall at 2019-11-28T02:54:52-05:00 Fix typos, using Wikipedia list of common typos - - - - - 6c59cc71 by Stefan Schulze Frielinghaus at 2019-11-28T02:55:33-05:00 Fix endian handling of LLVM backend Get rid of CPP macro WORDS_BIGENDIAN which is not defined anymore, and replace it by DynFlag. This fixes partially #17337. - - - - - 6985e0fc by Vladislav Zavialov at 2019-11-28T15:47:53+03:00 Factor out HsSCC/HsCoreAnn/HsTickPragma into HsPragE This is a refactoring with no user-visible changes (except for GHC API users). Consider the HsExpr constructors that correspond to user-written pragmas: HsSCC representing {-# SCC ... #-} HsCoreAnn representing {-# CORE ... #-} HsTickPragma representing {-# GENERATED ... #-} We can factor them out into a separate datatype, HsPragE. It makes the code a bit tidier, especially in the parser. Before this patch: hpc_annot :: { Located ( (([AddAnn],SourceText),(StringLiteral,(Int,Int),(Int,Int))), ((SourceText,SourceText),(SourceText,SourceText)) ) } After this patch: prag_hpc :: { Located ([AddAnn], HsPragE GhcPs) } - - - - - 7f695a20 by Ömer Sinan Ağacan at 2019-11-29T08:25:28-05:00 Pass ModDetails with (partial) ModIface in HscStatus (Partial) ModIface and ModDetails are generated at the same time, but they're passed differently: ModIface is passed in HscStatus consturctors while ModDetails is returned in a tuple. This refactors ModDetails passing so that it's passed around with ModIface in HscStatus constructors. This makes the code more consistent and hopefully easier to understand: ModIface and ModDetails are really very closely related. It makes sense to treat them the same way. - - - - - e921c90f by Ömer Sinan Ağacan at 2019-11-29T08:26:07-05:00 Improve few Foreign.Marshal.Utils docs In copyBytes and moveBytes mention which argument is source and which is destination. Also fixes some of the crazy indentation in the module and cleans trailing whitespace. - - - - - 316f2431 by Sebastian Graf at 2019-11-30T02:57:58-05:00 Hadrian docs: Rename the second "validate" entry to "slow-validate" [ci skip] That would be in line with the implementation. - - - - - 5aba5d32 by Vladislav Zavialov at 2019-11-30T02:58:34-05:00 Remove HasSrcSpan (#17494) Metric Decrease: haddock.compiler - - - - - d1de5c22 by Sylvain Henry at 2019-11-30T02:59:13-05:00 Use Hadrian by default in validate script (#17527) - - - - - 3a96a0b6 by Sebastian Graf at 2019-11-30T02:59:55-05:00 Simpler Semigroup instance for InsideLam and InterestingCtxt This mirrors the definition of `(&&)` and `(||)` now, relieving the Simplifier of a marginal amount of pressure. - - - - - f8cfe81a by Roland Senn at 2019-11-30T20:33:49+01:00 Improve tests for #17171 While backporting MR !1806 to 8.8.2 (!1885) I learnt the following: * Tests with `expect_fail` do not compare `*.stderr` output files. So a test using `expect_fail` will not detect future regressions on the `stderr` output. * To compare the `*.stderr` output files, I have to use the `exit_code(n)` function. * When a release is made, tests with `makefile_test` are converted to use `run_command`. * For the test `T17171a` the return code is `1` when running `makefile_test`, however it's `2` when running `run_command`. Therefore I decided: * To improve my tests for #17171 * To change test T17171a from `expect_fail` to `exit_code(2)` * To change both tests from `makefile_test` to `run_command` - - - - - 2b113fc9 by Vladislav Zavialov at 2019-12-01T08:17:05-05:00 Update DisambECP-related comments - - - - - beed7c3e by Ben Gamari at 2019-12-02T03:41:37-05:00 testsuite: Fix location of typing_stubs module This should fix the build on Debian 8. - - - - - 53251413 by Ben Gamari at 2019-12-02T03:42:14-05:00 testsuite: Don't override LD_LIBRARY_PATH, only prepend NixOS development environments often require that LD_LIBRARY_PATH be set in order to find system libraries. T1407 was overriding LD_LIBRARY_PATH, dropping these directories. Now it merely prepends, its directory. - - - - - 65400314 by Krzysztof Gogolewski at 2019-12-02T03:42:57-05:00 Convert warnings into assertions Since the invariants always hold in the testsuite, we can convert them to asserts. - - - - - 18baed64 by Alan Zimmerman at 2019-12-02T03:43:37-05:00 API Annotations: Unicode '->' on HsForallTy The code fragment type family Proxy2' ∷ ∀ k → k → Type where Proxy2' = Proxy' Generates AnnRarrow instead of AnnRarrowU for the first →. Fixes #17519 - - - - - 717f3236 by Brian Wignall at 2019-12-02T03:44:16-05:00 Fix more typos - - - - - bde48f8e by Ben Gamari at 2019-12-02T11:55:34-05:00 More Haddock syntax in GHC.Hs.Utils As suggested by RyanGlScott in !2163. - - - - - 038bedbc by Ben Gamari at 2019-12-02T11:56:18-05:00 Simplify: Fix pretty-printing of strictness A colleague recently hit the panic in Simplify.addEvals and I noticed that the message is quite unreadable due to incorrect pretty-printing. Fix this. - - - - - c500f652 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Fix changelog linting logic - - - - - 8ead967d by Ben Gamari at 2019-12-02T11:56:54-05:00 win32-init: Drop workaround for #17480 The `process` changes have now been merged into `hsc2hs`. (cherry picked from commit fa029f53132ad59f847ed012d3b835452cf16615) - - - - - d402209a by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Disable Sphinx build on Debian 8 The docutils version available appears to be too old to support the `table` directive's `:widths:` options. (cherry picked from commit 75764487a96a7a026948b5af5022781872d12baa) - - - - - f1f68824 by Ben Gamari at 2019-12-02T11:56:54-05:00 base: Fix <unistd.h> #include Previously we were including <sys/unistd.h> which is available on glibc but not musl. (cherry picked from commit e44b695ca7cb5f3f99eecfba05c9672c6a22205e) - - - - - 37eb94b3 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Bump Docker images Installs pxz on Centos7 (cherry picked from commit 86960e691f7a600be247c32a7cf795bf9abf7cc4) - - - - - aec98a79 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: pxz is unavailable on CentOS 7 Fall back to xz - - - - - 6708b8e5 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Set LANG on CentOS 7 It otherwise seems to default to ascii - - - - - 470ef0e7 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Consolidate release build configuration - - - - - 38338757 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Add Debian 10 builds - - - - - 012f13b5 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Fix Windows bindist collection Apparently variable interpolation in the `artifacts.paths` key of `gitlab-ci.yml` doesn't work on Windows as it does on WIndows. (cherry picked from commit 100cc756faa4468ed6950116bae30609c1c3468b) - - - - - a0f09e23 by Ben Gamari at 2019-12-02T11:56:54-05:00 testsuite: Simplify Python <3.5 fallback for TextIO (cherry picked from commit d092d8598694c23bc07cdcc504dff52fa5f33be1) - - - - - 2b2370ec by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Add release-x86_64-linux-deb9 job (cherry picked from commit cbedb3c4a90649f474cb716842ba53afc5a642ca) - - - - - b1c206fd by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Always build source tarball (cherry picked from commit 67b5de88ef923971f1980335137e3c7193213abd) - - - - - 4cbd5b47 by Sergei Trofimovich at 2019-12-02T11:57:33-05:00 configure.ac: make cross-compiler detection stricter Be more precise at detecting cross-compilation case. Before the change configuration $ ./configure --host=x86_64-pc-linux-gnu --target=x86_64-gentoo-linux-musl was not considered a cross-target. Even though libcs are different (`glibc` vs. `musl`). Without this patch build fails as: ``` "inplace/bin/ghc-cabal" check libraries/integer-gmp "inplace/bin/ghc-cabal" configure libraries/integer-gmp dist-install \ --with-ghc="/home/slyfox/dev/git/ghc/inplace/bin/ghc-stage1" \ --with-ghc-pkg="/home/slyfox/dev/git/ghc/inplace/bin/ghc-pkg" \ --disable-library-for-ghci --enable-library-vanilla --enable-library-for-ghci \ --enable-library-profiling --enable-shared --with-hscolour="/usr/bin/HsColour" \ --configure-option=CFLAGS="-Wall \ -Werror=unused-but-set-variable -Wno-error=inline \ -iquote /home/slyfox/dev/git/ghc/libraries/integer-gmp" \ --configure-option=LDFLAGS=" " --configure-option=CPPFLAGS=" \ " --gcc-options="-Wall -Werror=unused-but-set-variable -Wno-error=inline -iquote /home/slyfox/dev/git/ghc/libraries/integer-gmp \ " --with-gcc="x86_64-gentoo-linux-musl-gcc" --with-ld="x86_64-gentoo-linux-musl-ld.gold" --with-ar="x86_64-gentoo-linux-musl-ar" \ --with-alex="/usr/bin/alex" --with-happy="/usr/bin/happy" Configuring integer-gmp-1.0.2.0... configure: WARNING: unrecognized options: --with-compiler checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu checking for gcc... /usr/lib/ccache/bin/x86_64-gentoo-linux-musl-gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... configure: error: in `/home/slyfox/dev/git/ghc/libraries/integer-gmp/dist-install/build': configure: error: cannot run C compiled programs. If you meant to cross compile, use `--host'. See `config.log' for more details make[1]: *** [libraries/integer-gmp/ghc.mk:5: libraries/integer-gmp/dist-install/package-data.mk] Error 1 make: *** [Makefile:126: all] Error 2 ``` Note: here `ghc-stage1` is assumed to target `musl` target but is passed `glibc` toolchain. It happens because initial ./configure phase did not detect host/target as different. Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - 5f7cb423 by Sylvain Henry at 2019-12-02T23:59:29-05:00 Add `timesInt2#` primop - - - - - fbbe18a2 by Sylvain Henry at 2019-12-02T23:59:29-05:00 Use the new timesInt2# primop in integer-gmp (#9431) - - - - - 5a4b8d0c by Athas at 2019-12-03T00:00:09-05:00 Document RTS behaviour upon encountering '--'. - - - - - 705a16df by Ben Gamari at 2019-12-03T07:11:33-05:00 Make BCO# lifted In #17424 Simon PJ noted that there is a potentially unsafe occurrence of unsafeCoerce#, coercing from an unlifted to lifted type. However, nowhere in the compiler do we assume that a BCO# is not a thunk. Moreover, in the case of a CAF the result returned by `createBCO` *will* be a thunk (as noted in [Updatable CAF BCOs]). Consequently it seems better to rather make BCO# a lifted type and rename it to BCO. - - - - - 35afe4f3 by Sylvain Henry at 2019-12-03T07:12:13-05:00 Use Int# primops in `Bits Int{8,16,32,64}` instances - - - - - 7a51b587 by Sylvain Henry at 2019-12-03T07:12:13-05:00 Add constant folding rule (#16402) narrowN (x .&. m) m .&. (2^N-1) = 2^N-1 ==> narrowN x e.g. narrow16 (x .&. 0x12FFFF) ==> narrow16 x - - - - - 10caee7f by Ben Gamari at 2019-12-03T21:04:50-05:00 users-guide: Add 8.12.1 release notes - - - - - 25019d18 by Ben Gamari at 2019-12-03T21:04:50-05:00 Drop Uniquable constraint for AnnTarget This relied on deriveUnique, which was far too subtle to be safely applied. Thankfully the instance doesn't appear to be used so let's just drop it. - - - - - 78b67ad0 by Ben Gamari at 2019-12-03T21:04:50-05:00 Simplify uniqAway This does two things: * Eliminate all uses of Unique.deriveUnique, which was quite easy to mis-use and extremely subtle. * Rename the previous "derived unique" notion to "local unique". This is possible because the only places where `uniqAway` can be safely used are those where local uniqueness (with respect to some InScopeSet) is sufficient. * Rework the implementation of VarEnv.uniqAway, as discussed in #17462. This should make the operation significantly more efficient than its previous iterative implementation.. Metric Decrease: T9872c T12227 T9233 T14683 T5030 T12545 hie002 Metric Increase: T9961 - - - - - f03a41d4 by Ben Gamari at 2019-12-03T21:05:27-05:00 Elf: Fix link info note generation Previously we would use the `.int` assembler directive to generate 32-bit words in the note section. However, `.int` is note guaranteed to produce 4-bytes; in fact, on some platforms (e.g. AArch64) it produces 8-bytes. Use the `.4bytes` directive to avoid this. Moreover, we used the `.align` directive, which is quite platform dependent. On AArch64 it appears to not even be idempotent (despite what the documentation claims). `.balign` is consequentially preferred as it offers consistent behavior across platforms. - - - - - 84585e5e by Vladislav Zavialov at 2019-12-05T16:07:44-05:00 Meaning-preserving SCC annotations (#15730) This patch implements GHC Proposal #176: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0176-scc-parsing.rst Before the change: 1 / 2 / 2 = 0.25 1 / {-# SCC "name" #-} 2 / 2 = 1.0 After the change: 1 / 2 / 2 = 0.25 1 / {-# SCC "name" #-} 2 / 2 = parse error - - - - - e49e5470 by Vladislav Zavialov at 2019-12-05T16:07:44-05:00 Improve error messages for SCC pragmas - - - - - a2b535d9 by Ben Gamari at 2019-12-05T16:07:45-05:00 users guide: Try to silence underfull \hbox warnings We use two tricks, as suggested here [1]: * Use microtype to try to reduce the incidence of underfull boxes * Bump up \hbadness to eliminate the warnings - - - - - 4e47217f by Bodigrim at 2019-12-05T16:07:47-05:00 Make sameNat and sameSymbol proxy-polymorphic - - - - - 8324f0b7 by Bodigrim at 2019-12-05T16:07:47-05:00 Test proxy-polymorphic sameNat and sameSymbol - - - - - 69001f54 by Ben Gamari at 2019-12-05T16:07:48-05:00 nonmoving: Clear segment bitmaps during sweep Previously we would clear the bitmaps of segments which we are going to sweep during the preparatory pause. However, this is unnecessary: the existence of the mark epoch ensures that the sweep will correctly identify non-reachable objects, even if we do not clear the bitmap. We now defer clearing the bitmap to sweep, which happens concurrently with mutation. - - - - - 58a9c429 by Ben Gamari at 2019-12-05T16:07:48-05:00 testsuite: Disable divByZero on non-NCG targets The LLVM backend does not guarantee any particular semantics for division by zero, making this test unreliable across platforms. - - - - - 8280bd8a by Ben Gamari at 2019-12-05T16:07:49-05:00 testsuite: Factor out terminal coloring - - - - - 92a52aaa by Ben Gamari at 2019-12-05T16:07:49-05:00 testsuite: Make performance metric summary more readable Along with some refactoring. - - - - - c4ca29c7 by Ben Gamari at 2019-12-05T16:07:49-05:00 testsuite: Use colors more consistently - - - - - 3354c68e by Vladislav Zavialov at 2019-12-05T16:07:49-05:00 Pretty-printing of the * kind Before this patch, GHC always printed the * kind unparenthesized. This led to two issues: 1. Sometimes GHC printed invalid or incorrect code. For example, GHC would print: type F @* x = x when it meant to print: type F @(*) x = x In the former case, instead of a kind application we were getting a type operator (@*). 2. Sometimes GHC printed kinds that were correct but hard to read. Should Either * Int be read as Either (*) Int or as (*) Either Int ? This depends on whether -XStarIsType is enabled, but it would be easier if we didn't have to check for the flag when reading the code. We can solve both problems by assigning (*) a different precedence. Note that Haskell98 kinds are not affected: ((* -> *) -> *) -> * does NOT become (((*) -> (*)) -> (*)) -> (*) The parentheses are added when (*) is used in a function argument position: F * * * becomes F (*) (*) (*) F A * B becomes F A (*) B Proxy * becomes Proxy (*) a * -> * becomes a (*) -> * - - - - - 70dd0e4b by Vladislav Zavialov at 2019-12-05T16:07:49-05:00 Parenthesize the * kind in TH.Ppr - - - - - a7a4efbf by Ben Gamari at 2019-12-05T16:07:49-05:00 rts/NonMovingSweep: Fix locking of new mutable list allocation Previously we used allocBlockOnNode_sync in nonmovingSweepMutLists despite the fact that we aren't in the GC and therefore the allocation spinlock isn't in use. This meant that sweep would end up spinning until the next minor GC, when the SM lock was moved away from the SM_MUTEX to the spinlock. This isn't a correctness issue but it sure isn't good for performance. Found thanks for Ward. Fixes #17539. - - - - - f171b358 by Matthias Braun at 2019-12-05T16:07:51-05:00 Fix typo in documentation of Base.hs. - - - - - 9897e8c8 by Gabor Greif at 2019-12-06T21:20:38-05:00 Implement pointer tagging for big families (#14373) Formerly we punted on these and evaluated constructors always got a tag of 1. We now cascade switches because we have to check the tag first and when it is MAX_PTR_TAG then get the precise tag from the info table and switch on that. The only technically tricky part is that the default case needs (logical) duplication. To do this we emit an extra label for it and branch to that from the second switch. This avoids duplicated codegen. Here's a simple example of the new code gen: data D = D1 | D2 | D3 | D4 | D5 | D6 | D7 | D8 On a 64-bit system previously all constructors would be tagged 1. With the new code gen D7 and D8 are tagged 7: [Lib.D7_con_entry() { ... {offset c1eu: // global R1 = R1 + 7; call (P64[Sp])(R1) args: 8, res: 0, upd: 8; } }] [Lib.D8_con_entry() { ... {offset c1ez: // global R1 = R1 + 7; call (P64[Sp])(R1) args: 8, res: 0, upd: 8; } }] When switching we now look at the info table only when the tag is 7. For example, if we derive Enum for the type above, the Cmm looks like this: c2Le: _s2Js::P64 = R1; _c2Lq::P64 = _s2Js::P64 & 7; switch [1 .. 7] _c2Lq::P64 { case 1 : goto c2Lk; case 2 : goto c2Ll; case 3 : goto c2Lm; case 4 : goto c2Ln; case 5 : goto c2Lo; case 6 : goto c2Lp; case 7 : goto c2Lj; } // Read info table for tag c2Lj: _c2Lv::I64 = %MO_UU_Conv_W32_W64(I32[I64[_s2Js::P64 & (-8)] - 4]); if (_c2Lv::I64 != 6) goto c2Lu; else goto c2Lt; Generated Cmm sizes do not change too much, but binaries are very slightly larger, due to the fact that the new instructions are longer in encoded form. E.g. previously entry code for D8 above would be 00000000000001c0 <Lib_D8_con_info>: 1c0: 48 ff c3 inc %rbx 1c3: ff 65 00 jmpq *0x0(%rbp) With this patch 00000000000001d0 <Lib_D8_con_info>: 1d0: 48 83 c3 07 add $0x7,%rbx 1d4: ff 65 00 jmpq *0x0(%rbp) This is one byte longer. Secondly, reading info table directly and then switching is shorter _c1co: movq -1(%rbx),%rax movl -4(%rax),%eax // Switch on info table tag jmp *_n1d5(,%rax,8) than doing the same switch, and then for the tag 7 doing another switch: // When tag is 7 _c1ct: andq $-8,%rbx movq (%rbx),%rax movl -4(%rax),%eax // Switch on info table tag ... Some changes of binary sizes in actual programs: - In NoFib the worst case is 0.1% increase in benchmark "parser" (see NoFib results below). All programs get slightly larger. - Stage 2 compiler size does not change. - In "containers" (the library) size of all object files increases 0.0005%. Size of the test program "bitqueue-properties" increases 0.03%. nofib benchmarks kindly provided by Ömer (@osa1): NoFib Results ============= -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS +0.0% 0.0% -0.0% -0.0% -0.0% CSD +0.0% 0.0% 0.0% +0.0% +0.0% FS +0.0% 0.0% 0.0% +0.0% 0.0% S +0.0% 0.0% -0.0% 0.0% 0.0% VS +0.0% 0.0% -0.0% +0.0% +0.0% VSD +0.0% 0.0% -0.0% +0.0% -0.0% VSM +0.0% 0.0% 0.0% 0.0% 0.0% anna +0.0% 0.0% +0.1% -0.9% -0.0% ansi +0.0% 0.0% -0.0% +0.0% +0.0% atom +0.0% 0.0% 0.0% 0.0% 0.0% awards +0.0% 0.0% -0.0% +0.0% 0.0% banner +0.0% 0.0% -0.0% +0.0% 0.0% bernouilli +0.0% 0.0% +0.0% +0.0% +0.0% binary-trees +0.0% 0.0% -0.0% -0.0% -0.0% boyer +0.0% 0.0% +0.0% 0.0% -0.0% boyer2 +0.0% 0.0% +0.0% 0.0% -0.0% bspt +0.0% 0.0% +0.0% +0.0% 0.0% cacheprof +0.0% 0.0% +0.1% -0.8% 0.0% calendar +0.0% 0.0% -0.0% +0.0% -0.0% cichelli +0.0% 0.0% +0.0% 0.0% 0.0% circsim +0.0% 0.0% -0.0% -0.1% -0.0% clausify +0.0% 0.0% +0.0% +0.0% 0.0% comp_lab_zift +0.0% 0.0% +0.0% 0.0% -0.0% compress +0.0% 0.0% +0.0% +0.0% 0.0% compress2 +0.0% 0.0% 0.0% 0.0% 0.0% constraints +0.0% 0.0% -0.0% -0.0% -0.0% cryptarithm1 +0.0% 0.0% +0.0% 0.0% 0.0% cryptarithm2 +0.0% 0.0% +0.0% -0.0% 0.0% cse +0.0% 0.0% +0.0% +0.0% 0.0% digits-of-e1 +0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e2 +0.0% 0.0% +0.0% -0.0% -0.0% dom-lt +0.0% 0.0% +0.0% +0.0% 0.0% eliza +0.0% 0.0% -0.0% +0.0% 0.0% event +0.0% 0.0% -0.0% -0.0% -0.0% exact-reals +0.0% 0.0% +0.0% +0.0% +0.0% exp3_8 +0.0% 0.0% -0.0% -0.0% -0.0% expert +0.0% 0.0% +0.0% +0.0% +0.0% fannkuch-redux +0.0% 0.0% +0.0% 0.0% 0.0% fasta +0.0% 0.0% -0.0% -0.0% -0.0% fem +0.0% 0.0% +0.0% +0.0% +0.0% fft +0.0% 0.0% +0.0% -0.0% -0.0% fft2 +0.0% 0.0% +0.0% +0.0% +0.0% fibheaps +0.0% 0.0% +0.0% +0.0% 0.0% fish +0.0% 0.0% +0.0% +0.0% 0.0% fluid +0.0% 0.0% +0.0% +0.0% +0.0% fulsom +0.0% 0.0% +0.0% -0.0% +0.0% gamteb +0.0% 0.0% +0.0% -0.0% -0.0% gcd +0.0% 0.0% +0.0% +0.0% 0.0% gen_regexps +0.0% 0.0% +0.0% -0.0% -0.0% genfft +0.0% 0.0% -0.0% -0.0% -0.0% gg +0.0% 0.0% 0.0% -0.0% 0.0% grep +0.0% 0.0% +0.0% +0.0% +0.0% hidden +0.0% 0.0% +0.0% -0.0% -0.0% hpg +0.0% 0.0% +0.0% -0.1% -0.0% ida +0.0% 0.0% +0.0% -0.0% -0.0% infer +0.0% 0.0% -0.0% -0.0% -0.0% integer +0.0% 0.0% -0.0% -0.0% -0.0% integrate +0.0% 0.0% 0.0% +0.0% 0.0% k-nucleotide +0.0% 0.0% -0.0% -0.0% -0.0% kahan +0.0% 0.0% -0.0% -0.0% -0.0% knights +0.0% 0.0% +0.0% -0.0% -0.0% lambda +0.0% 0.0% +1.2% -6.1% -0.0% last-piece +0.0% 0.0% +0.0% -0.0% -0.0% lcss +0.0% 0.0% +0.0% -0.0% -0.0% life +0.0% 0.0% +0.0% -0.0% -0.0% lift +0.0% 0.0% +0.0% +0.0% 0.0% linear +0.0% 0.0% +0.0% +0.0% +0.0% listcompr +0.0% 0.0% -0.0% -0.0% -0.0% listcopy +0.0% 0.0% -0.0% -0.0% -0.0% maillist +0.0% 0.0% +0.0% -0.0% -0.0% mandel +0.0% 0.0% +0.0% +0.0% +0.0% mandel2 +0.0% 0.0% +0.0% +0.0% -0.0% mate +0.0% 0.0% +0.0% +0.0% +0.0% minimax +0.0% 0.0% -0.0% +0.0% -0.0% mkhprog +0.0% 0.0% +0.0% +0.0% +0.0% multiplier +0.0% 0.0% 0.0% +0.0% -0.0% n-body +0.0% 0.0% +0.0% -0.0% -0.0% nucleic2 +0.0% 0.0% +0.0% +0.0% -0.0% para +0.0% 0.0% +0.0% +0.0% +0.0% paraffins +0.0% 0.0% +0.0% +0.0% +0.0% parser +0.1% 0.0% +0.4% -1.7% -0.0% parstof +0.0% 0.0% -0.0% -0.0% -0.0% pic +0.0% 0.0% +0.0% 0.0% -0.0% pidigits +0.0% 0.0% -0.0% -0.0% -0.0% power +0.0% 0.0% +0.0% -0.0% -0.0% pretty +0.0% 0.0% +0.0% +0.0% +0.0% primes +0.0% 0.0% +0.0% 0.0% 0.0% primetest +0.0% 0.0% +0.0% +0.0% +0.0% prolog +0.0% 0.0% +0.0% +0.0% +0.0% puzzle +0.0% 0.0% +0.0% +0.0% +0.0% queens +0.0% 0.0% 0.0% +0.0% +0.0% reptile +0.0% 0.0% +0.0% +0.0% 0.0% reverse-complem +0.0% 0.0% -0.0% -0.0% -0.0% rewrite +0.0% 0.0% +0.0% 0.0% -0.0% rfib +0.0% 0.0% +0.0% +0.0% +0.0% rsa +0.0% 0.0% +0.0% +0.0% +0.0% scc +0.0% 0.0% +0.0% +0.0% +0.0% sched +0.0% 0.0% +0.0% +0.0% +0.0% scs +0.0% 0.0% +0.0% +0.0% 0.0% simple +0.0% 0.0% +0.0% +0.0% +0.0% solid +0.0% 0.0% +0.0% +0.0% 0.0% sorting +0.0% 0.0% +0.0% -0.0% 0.0% spectral-norm +0.0% 0.0% -0.0% -0.0% -0.0% sphere +0.0% 0.0% +0.0% -1.0% 0.0% symalg +0.0% 0.0% +0.0% +0.0% +0.0% tak +0.0% 0.0% +0.0% +0.0% +0.0% transform +0.0% 0.0% +0.4% -1.3% +0.0% treejoin +0.0% 0.0% +0.0% -0.0% 0.0% typecheck +0.0% 0.0% -0.0% +0.0% 0.0% veritas +0.0% 0.0% +0.0% -0.1% +0.0% wang +0.0% 0.0% +0.0% +0.0% +0.0% wave4main +0.0% 0.0% +0.0% 0.0% -0.0% wheel-sieve1 +0.0% 0.0% +0.0% +0.0% +0.0% wheel-sieve2 +0.0% 0.0% +0.0% +0.0% 0.0% x2n1 +0.0% 0.0% +0.0% +0.0% 0.0% -------------------------------------------------------------------------------- Min +0.0% 0.0% -0.0% -6.1% -0.0% Max +0.1% 0.0% +1.2% +0.0% +0.0% Geometric Mean +0.0% -0.0% +0.0% -0.1% -0.0% NoFib GC Results ================ -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- circsim +0.0% 0.0% -0.0% -0.0% -0.0% constraints +0.0% 0.0% -0.0% 0.0% -0.0% fibheaps +0.0% 0.0% 0.0% -0.0% -0.0% fulsom +0.0% 0.0% 0.0% -0.6% -0.0% gc_bench +0.0% 0.0% 0.0% 0.0% -0.0% hash +0.0% 0.0% -0.0% -0.0% -0.0% lcss +0.0% 0.0% 0.0% -0.0% 0.0% mutstore1 +0.0% 0.0% 0.0% -0.0% -0.0% mutstore2 +0.0% 0.0% +0.0% -0.0% -0.0% power +0.0% 0.0% -0.0% 0.0% -0.0% spellcheck +0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min +0.0% 0.0% -0.0% -0.6% -0.0% Max +0.0% 0.0% +0.0% 0.0% 0.0% Geometric Mean +0.0% +0.0% +0.0% -0.1% +0.0% Fixes #14373 These performance regressions appear to be a fluke in CI. See the discussion in !1742 for details. Metric Increase: T6048 T12234 T12425 Naperian T12150 T5837 T13035 - - - - - ee07421f by Simon Peyton Jones at 2019-12-06T21:21:14-05:00 Work in progress on coercionLKind, coercionRKind This is a preliminary patch for #17515 - - - - - 0a4ca9eb by Simon Peyton Jones at 2019-12-06T21:21:14-05:00 Split up coercionKind This patch implements the idea in #17515, splitting `coercionKind` into: * `coercion{Left,Right}Kind`, which computes the left/right side of the pair * `coercionKind`, which computes the pair of coercible types This is reduces allocation since we frequently only need only one side of the pair. Specifically, we see the following improvements on x86-64 Debian 9: | test | new | old | relative chg. | | :------- | ---------: | ------------: | ------------: | | T5030 | 695537752 | 747641152.0 | -6.97% | | T5321Fun | 449315744 | 474009040.0 | -5.21% | | T9872a | 2611071400 | 2645040952.0 | -1.28% | | T9872c | 2957097904 | 2994260264.0 | -1.24% | | T12227 | 773435072 | 812367768.0 | -4.79% | | T12545 | 3142687224 | 3215714752.0 | -2.27% | | T14683 | 9392407664 | 9824775000.0 | -4.40% | Metric Decrease: T12545 T9872a T14683 T5030 T12227 T9872c T5321Fun T9872b - - - - - d46a72e1 by Gabor Greif at 2019-12-09T12:05:15-05:00 Fix comment typos The below is only necessary to fix the CI perf fluke that happened in 9897e8c8ef0b19a9571ef97a1d9bb050c1ee9121: ------------------------- Metric Decrease: T5837 T6048 T9020 T12425 T12234 T13035 T12150 Naperian ------------------------- - - - - - e3bba7e4 by Micha Wiedenmann at 2019-12-10T19:52:44-05:00 users guide: Motivation of DefaultSignatures - - - - - 843ceb38 by Ben Gamari at 2019-12-10T19:53:54-05:00 rts: Add a long form flag to enable the non-moving GC The old flag, `-xn`, was quite cryptic. Here we add `--nonmoving-gc` in addition. - - - - - 921d3238 by Ryan Scott at 2019-12-10T19:54:34-05:00 Ignore unary constraint tuples during typechecking (#17511) We deliberately avoid defining a magical `Unit%` class, for reasons that I have expounded upon in the newly added `Note [Ignore unary constraint tuples]` in `TcHsType`. However, a sneaky user could try to insert `Unit%` into their program by way of Template Haskell, leading to the interface-file error observed in #17511. To avoid this, any time we encounter a unary constraint tuple during typechecking, we drop the surrounding constraint tuple application. This is safe to do since `Unit% a` and `a` would be semantically equivalent (unlike other forms of unary tuples). Fixes #17511. - - - - - 436ec9f3 by Ben Gamari at 2019-12-10T19:55:37-05:00 gitlab-ci: Move changelog linting logic to shell script Allowing it to be easily used locally. - - - - - 2f6b434f by Ben Gamari at 2019-12-10T19:55:37-05:00 gitlab-ci: Move changelog linting logic to shell script Allowing it to be easily used locally. - - - - - 7a5a6e07 by Ben Gamari at 2019-12-10T19:56:25-05:00 base: Fix incorrect @since in GHC.Natural Fixes #17547. - - - - - 2bbfaf8a by Ben Gamari at 2019-12-10T19:57:01-05:00 hadrian: AArch64 supports the GHCi interpreter and SMP I'm not sure how this was omitted from the list of supported architectures. - - - - - 8f1ceb67 by John Ericson at 2019-12-10T19:57:39-05:00 Move Int# section of primops.txt.pp This matches the organization of the fixed-sized ones, and keeps each Int* next to its corresponding Word*. - - - - - 7a823b0f by John Ericson at 2019-12-10T19:57:39-05:00 Move Int64# and Word64# sections of primops.txt.pp This way it is next to the other fixed-sized ones. - - - - - 8dd9929a by Ben Gamari at 2019-12-10T19:58:19-05:00 testsuite: Add (broken) test for #17510 - - - - - 6e47a76a by Ben Gamari at 2019-12-10T19:58:59-05:00 Re-layout validate script This script was previously a whitespace nightmare. - - - - - f80c4a66 by Crazycolorz5 at 2019-12-11T14:12:17-05:00 rts: Specialize hashing at call site rather than in struct. Separate word and string hash tables on the type level, and do not store the hashing function. Thus when a different hash function is desire it is provided upon accessing the table. This is worst case the same as before the change, and in the majority of cases is better. Also mark the functions for aggressive inlining to improve performance. {F1686506} Reviewers: bgamari, erikd, simonmar Subscribers: rwbarton, thomie, carter GHC Trac Issues: #13165 Differential Revision: https://phabricator.haskell.org/D4889 - - - - - 2d1b9619 by Richard Eisenberg at 2019-12-11T14:12:55-05:00 Warn on inferred polymorphic recursion Silly users sometimes try to use visible dependent quantification and polymorphic recursion without a CUSK or SAK. This causes unexpected errors. So we now adjust expectations with a bit of helpful messaging. Closes #17541 and closes #17131. test cases: dependent/should_fail/T{17541{,b},17131} - - - - - 4dde485e by Oleg Grenrus at 2019-12-12T02:24:46-05:00 Add --show-unit-ids flag to ghc-pkg I only added it into --simple-output and ghc-pkg check output; there are probably other places where it can be adopted. - - - - - e6e1ec08 by Ben Gamari at 2019-12-12T02:25:33-05:00 testsuite: Simplify and clarify performance test baseline search The previous implementation was extremely complicated, seemingly to allow the local and CI namespaces to be searched incrementally. However, it's quite unclear why this is needed and moreover the implementation seems to have had quadratic runtime cost in the search depth(!). - - - - - 29c4609c by Ben Gamari at 2019-12-12T02:26:19-05:00 testsuite: Add test for #17549 - - - - - 9f0ee253 by Ben Gamari at 2019-12-12T02:26:56-05:00 gitlab-ci: Move -dwarf and -debug jobs to full-build stage This sacrifices some precision in favor of improving parallelism. - - - - - 7179b968 by Ben Gamari at 2019-12-12T02:27:34-05:00 Revert "rts: Drop redundant flags for libffi" This seems to have regressed builds using `--with-system-libffi` (#17520). This reverts commit 3ce18700f80a12c48a029b49c6201ad2410071bb. - - - - - cc7d5650 by Oleg Grenrus at 2019-12-16T10:20:56+02:00 Having no shake upper bound is irresposible Given that shake is far from "done" API wise, and is central component to the build system. - - - - - 9431f905 by Oleg Grenrus at 2019-12-16T10:55:50+02:00 Add index-state to hadrian/cabal.project Then one is freer to omit upper bounds, as we won't pick any new entries on Hackage while building hadrian itself. - - - - - 3e17a866 by Krzysztof Gogolewski at 2019-12-16T19:31:44-05:00 Remove dataConSig As suggested in #17291 - - - - - 75355fde by Krzysztof Gogolewski at 2019-12-16T19:31:44-05:00 Use "OrCoVar" functions less As described in #17291, we'd like to separate coercions and expressions in a more robust fashion. This is a small step in this direction. - `mkLocalId` now panicks on a covar. Calls where this was not the case were changed to `mkLocalIdOrCoVar`. - Don't use "OrCoVar" functions in places where we know the type is not a coercion. - - - - - f9686e13 by Richard Eisenberg at 2019-12-16T19:32:21-05:00 Do more validity checks for quantified constraints Close #17583. Test case: typecheck/should_fail/T17563 - - - - - af763765 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Fix Windows artifact collection Variable interpolation in gitlab-ci.yml apparently doesn't work. Sigh. - - - - - e6d4b902 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Use xz --threads on Debian 10 - - - - - 8ba650e9 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Allow debian 8 build to fail The python release shipped with deb8 (3.3) is too old for our testsuite driver. - - - - - ac25a3f6 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Use xz --threads on Alpine - - - - - cc628088 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Another approach for xz detection - - - - - 37d788ab by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Re-add release-x86_64-deb9 job Also eliminate some redundancy. - - - - - f8279138 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Drop redundant release-x86_64-linux-deb9 job - - - - - 8148ff06 by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark cgrun057 as broken on ARMv7 Due to #17554. It's very surprising that this only occurs on ARMv7 but this is the only place I've seen this failure thusfar. - - - - - 85e5696d by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark prog001 as fragile on ARMv7 Due to #17555. - - - - - a5f0aab0 by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark T10272 as broken on ARMv7 Due to #17556. - - - - - 1e6827c6 by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark T13825-debugger as broken on ARMv7 Due to #17557. - - - - - 7cef0b7d by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark T14028 as broken on ARMv7 Due to #17558. - - - - - 6ea4eb4b by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Make ghc_built_by_llvm check more precise Previously it would hackily look at the flavour name to determine whether LLVM was used to build stage2 ghc. However, this didn't work at all with Hadrian and would miss cases like ARM where we use the LLVM backend by default. See #16087 for the motivation for why ghc_built_by_llvm is needed at all. This should catch one of the ARMv7 failures described in #17555. - - - - - c3e82bf7 by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark T5435_* tests as broken on ARM `T5435_v_asm_a`, `T5435_v_asm_b`, and `T5435_v_gcc` all fail on ARMv7. See #17559. - - - - - eb2aa851 by Ben Gamari at 2019-12-17T07:24:40-05:00 gitlab-ci: Don't allow armv7 jobs to fail - - - - - efc92216 by Ben Gamari at 2019-12-17T07:24:40-05:00 Revert "testsuite: Mark cgrun057 as broken on ARMv7" This reverts commit 6cfc47ec8a478e1751cb3e7338954da1853c3996. - - - - - 1d2bb9eb by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark print002 as fragile on ARM Due to #17557. Also accepting spurious performance change. Metric Decrease: T1969 - - - - - 41f4e4fb by Josh Meredith at 2019-12-17T07:25:17-05:00 Fix ambiguous occurence error when building Hadrian - - - - - 4374983a by Josh Meredith at 2019-12-17T07:25:17-05:00 Rename SphinxMode constructors - - - - - a8f7ecd5 by Josh Meredith at 2019-12-17T07:25:17-05:00 Use *Mode suffix instead of *M - - - - - 58655b9d by Sylvain Henry at 2019-12-18T13:43:37+01:00 Add GHC-API logging hooks * Add 'dumpAction' hook to DynFlags. It allows GHC API users to catch dumped intermediate codes and information. The format of the dump (Core, Stg, raw text, etc.) is now reported allowing easier automatic handling. * Add 'traceAction' hook to DynFlags. Some dumps go through the trace mechanism (for instance unfoldings that have been considered for inlining). This is problematic because: 1) dumps aren't written into files even with -ddump-to-file on 2) dumps are written on stdout even with GHC API 3) in this specific case, dumping depends on unsafe globally stored DynFlags which is bad for GHC API users We introduce 'traceAction' hook which allows GHC API to catch those traces and to avoid using globally stored DynFlags. * Avoid dumping empty logs via dumpAction/traceAction (but still write empty files to keep the existing behavior) - - - - - fad866e0 by Moritz Kiefer at 2019-12-19T11:15:39-05:00 Avoid race condition in hDuplicateTo In our codebase we have some code along the lines of ``` newStdout <- hDuplicate stdout stderr `hDuplicateTo` stdout ``` to avoid stray `putStrLn`s from corrupting a protocol (LSP) that is run over stdout. On CI we have seen a bunch of issues where `dup2` returned `EBUSY` so this fails with `ResourceExhausted` in Haskell. I’ve spent some time looking at the docs for `dup2` and the code in `base` and afaict the following race condition is being triggered here: 1. The user calls `hDuplicateTo stderr stdout`. 2. `hDuplicateTo` calls `hClose_help stdout_`, this closes the file handle for stdout. 3. The file handle for stdout is now free, so another thread allocating a file might get stdout. 4. If `dup2` is called while `stdout` (now pointing to something else) is half-open, it returns EBUSY. I think there might actually be an even worse case where `dup2` is run after FD 1 is fully open again. In that case, you will end up not just redirecting the original stdout to stderr but also the whatever resulted in that file handle being allocated. As far as I can tell, `dup2` takes care of closing the file handle itself so there is no reason to do this in `hDuplicateTo`. So this PR replaces the call to `hClose_help` by the only part of `hClose_help` that we actually care about, namely, `flushWriteBuffer`. I tested this on our codebase fairly extensively and haven’t been able to reproduce the issue with this patch. - - - - - 0c114c65 by Sylvain Henry at 2019-12-19T11:16:17-05:00 Handle large ARR_WORDS in heap census (fix #17572) We can do a heap census with a non-profiling RTS. With a non-profiling RTS we don't zero superfluous bytes of shrunk arrays hence a need to handle the case specifically to avoid a crash. Revert part of a586b33f8e8ad60b5c5ef3501c89e9b71794bbed - - - - - 1a0d1a65 by John Ericson at 2019-12-20T10:50:22-05:00 Deduplicate copied monad failure handler code - - - - - 70e56b27 by Ryan Scott at 2019-12-20T10:50:57-05:00 lookupBindGroupOcc: recommend names in the same namespace (#17593) Previously, `lookupBindGroupOcc`'s error message would recommend all similar names in scope, regardless of whether they were type constructors, data constructors, or functions, leading to the confusion witnessed in #17593. This is easily fixed by only recommending names in the same namespace, using the `nameSpacesRelated` function. Fixes #17593. - - - - - 3c12355e by Stefan Schulze Frielinghaus at 2019-12-24T01:03:44-05:00 Fix endian handling w.r.t. CPP macro WORDS_BIGENDIAN Include header file `ghcautoconf.h` where the CPP macro `WORDS_BIGENDIAN` is defined. This finally fixes #17337 (in conjunction with commit 6c59cc71dc). - - - - - 11f8eef5 by Stefan Schulze Frielinghaus at 2019-12-24T01:03:44-05:00 fixup! Fix endian handling w.r.t. CPP macro WORDS_BIGENDIAN - - - - - 40327b03 by Sylvain Henry at 2019-12-24T01:04:24-05:00 Remove outdated comment - - - - - aeea92ef by Sylvain Henry at 2019-12-25T19:23:54-05:00 Switch to ReadTheDocs theme for the user-guide - - - - - 26493eab by Gabor Greif at 2019-12-25T19:24:32-05:00 Fix copy-paste error in comment - - - - - 776df719 by Gabor Greif at 2019-12-25T19:24:32-05:00 Fix comment about minimal gcc version to be consistent what FP_GCC_VERSION requires - - - - - 3b17114d by Ömer Sinan Ağacan at 2019-12-26T14:09:11-05:00 Minor refactor in ghc.cabal.in: - Remove outdated comments - Move cutils.c from parser to cbits - Remove unused cutils.h - - - - - 334290b6 by Ryan Scott at 2019-12-26T14:09:48-05:00 Replace panic/notHandled with noExtCon in DsMeta There are many spots in `DsMeta` where `panic` or `notHandled` is used after pattern-matching on a TTG extension constructor. This is overkill, however, as using `noExtCon` would work just as well. This patch switches out these panics for `noExtCon`. - - - - - 68252aa3 by Ben Gamari at 2019-12-27T15:11:38-05:00 testsuite: Skip T17499 when built against integer-simple Since it routinely times out in CI. - - - - - 0c51aeeb by Gabor Greif at 2019-12-27T15:12:17-05:00 suppress popup dialog about missing Xcode at configure tested with `bash` and `zsh`. - - - - - 8d76bcc2 by Gabor Greif at 2019-12-27T15:12:17-05:00 while at it rename XCode to the official Xcode - - - - - 47a68205 by Ben Gamari at 2019-12-27T15:12:55-05:00 testsuite: Mark cgrun057 as fragile on ARM As reported in #17554. Only marking on ARM for now although there is evidence to suggest that the issue may occur on other platforms as well. - - - - - d03dec8f by Gabor Greif at 2019-12-27T15:13:32-05:00 use shell variable CcLlvmBackend for test Previously we used `AC_DEFINE`d variable `CC_LLVM_BACKEND` which has an empty shell expansion. - - - - - 2528e684 by Ben Gamari at 2019-12-30T06:51:32-05:00 driver: Include debug level in the recompilation check hash Fixes #17586. - - - - - f14bb50b by Ben Gamari at 2019-12-30T06:52:09-05:00 rts: Ensure that nonmoving gc isn't used with profiling - - - - - b426de37 by Ben Gamari at 2019-12-30T06:52:45-05:00 llvmGen: Ensure that entry labels don't have predecessors The LLVM IR forbids the entry label of a procedure from having any predecessors. In the case of a simple looping function the LLVM code generator broke this invariant, as noted in #17589. Fix this by moving the function prologue to its own basic block, as suggested by @kavon in #11649. Fixes #11649 and #17589. - - - - - 613f7265 by Ben Gamari at 2019-12-30T06:52:45-05:00 llvmGen: Drop old fix for #11649 This was a hack which is no longer necessary now since we introduce a dedicated entry block for each procedure. - - - - - fdeffa5e by Ben Gamari at 2019-12-30T06:53:23-05:00 rts: Error on invalid --numa flags Previously things like `+RTS --numa-debug` would enable NUMA support, despite being an invalid flag. - - - - - 9ce3ba68 by Ben Gamari at 2019-12-30T06:53:23-05:00 rts: Fix --debug-numa mode under Docker As noted in #17606, Docker disallows the get_mempolicy syscall by default. This caused numerous tests to fail under CI in the `debug_numa` way. Avoid this by disabling the NUMA probing logic when --debug-numa is in use, instead setting n_numa_nodes in RtsFlags.c. Fixes #17606. - - - - - 5baa2a43 by Ben Gamari at 2019-12-30T06:54:01-05:00 testsuite: Disable derefnull when built with LLVM LLVM does not guarantee any particular semantics when dereferencing null pointers. Consequently, this test actually passes when built with the LLVM backend. - - - - - bd544d3d by Ben Gamari at 2019-12-30T06:54:38-05:00 hadrian: Track hash of Cabal Setup builder arguments Lest we fail to rebuild when they change. Fixes #17611. - - - - - 6e2c495e by Ben Gamari at 2019-12-30T06:55:19-05:00 TcIface: Fix inverted logic in typechecking of source ticks Previously we would throw away source ticks when the debug level was non-zero. This is precisely the opposite of what was intended. Fixes #17616. Metric Decrease: T13056 T9020 T9961 T12425 - - - - - 7fad387d by Ben Gamari at 2019-12-30T06:55:55-05:00 perf_notes: Add --zero-y argument This makes it easier to see the true magnitude of fluctuations. Also do some house-keeping in the argument parsing department. - - - - - 0d42b287 by Ben Gamari at 2019-12-30T06:55:55-05:00 testsuite: Enlarge acceptance window for T1969 As noted in #17624, it's quite unstable, especially, for some reason, on i386 and armv7 (something about 32-bit platforms perhaps?). Metric Increase: T1969 - - - - - eb608235 by Sylvain Henry at 2019-12-31T14:22:32-05:00 Module hierarchy (#13009): Stg - - - - - d710fd66 by Vladislav Zavialov at 2019-12-31T14:23:10-05:00 Testsuite: update some Haddock tests Fixed tests: * haddockA039: added to all.T * haddockE004: replaced with T17561 (marked as expect_broken) New tests: * haddockA040: deriving clause for a data instance * haddockA041: haddock and CPP #include - - - - - 859ebdd4 by Kevin Buhr at 2019-12-31T23:44:39-05:00 Add "-Iw" RTS flag for minimum wait between idle GCs (#11134) - - - - - dd4b6551 by Kevin Buhr at 2019-12-31T23:44:39-05:00 Add additional Note explaining the -Iw flag - - - - - c4279ff1 by Kevin Buhr at 2019-12-31T23:44:39-05:00 Fix some sloppy indentation - - - - - b84c09d5 by Ömer Sinan Ağacan at 2019-12-31T23:45:19-05:00 Tweak Cmm dumps to avoid generating sections for empty groups When dumping Cmm groups check if the group is empty, to avoid generating empty sections in dump files like ==================== Output Cmm ==================== [] Also fixes a few bad indentation in the code around changes. - - - - - b2e0323f by Gabor Greif at 2020-01-03T21:22:36-05:00 Simplify mrStr - - - - - 3c9dc06b by Brian Wignall at 2020-01-04T15:55:06-05:00 Fix typos, via a Levenshtein-style corrector - - - - - d561c8f6 by Sylvain Henry at 2020-01-04T15:55:46-05:00 Add Cmm related hooks * stgToCmm hook * cmmToRawCmm hook These hooks are used by Asterius and could be useful to other clients of the GHC API. It increases the Parser dependencies (test CountParserDeps) to 184. It's still less than 200 which was the initial request (cf https://mail.haskell.org/pipermail/ghc-devs/2019-September/018122.html) so I think it's ok to merge this. - - - - - ae6b6276 by Oleg Grenrus at 2020-01-04T15:56:22-05:00 Update to Cabal submodule to v3.2.0.0-alpha3 Metric Increase: haddock.Cabal - - - - - 073f7cfd by Vladislav Zavialov at 2020-01-04T15:56:59-05:00 Add lexerDbg to dump the tokens fed to the parser This a small utility function that comes in handy when debugging the lexer and the parser. - - - - - 558d4d4a by Sylvain Henry at 2020-01-04T15:57:38-05:00 Split integerGmpInternals test in several parts This is to prepare for ghc-bignum which implements some but not all of gmp functions. - - - - - 4056b966 by Ben Gamari at 2020-01-04T15:58:15-05:00 testsuite: Mark cgrun057 as fragile on all platforms I have seen this fail both on x86-64/Debian 9 and armv7/Debian 9 See #17554. - - - - - 5ffea0c6 by Tamar Christina at 2020-01-06T18:38:37-05:00 Fix overflow. - - - - - 99a9f51b by Sylvain Henry at 2020-01-06T18:39:22-05:00 Module hierarchy: Iface (cf #13009) - - - - - 7aa4a061 by Ben Gamari at 2020-01-07T13:11:48-05:00 configure: Only check GCC version if CC is GCC Also refactor FP_GCC_EXTRA_FLAGS in a few ways: * We no longer support compilers which lack support for -fno-builtin and -fwrapv so remove the condition on GccVersion * These flags are only necessary when using the via-C backend so make them conditional on Unregisterised. Fixes #15742. - - - - - 0805ed7e by John Ericson at 2020-01-07T13:12:25-05:00 Use non-empty lists to remove partiality in matching code - - - - - 7844f3a8 by Ben Gamari at 2020-01-07T13:13:02-05:00 testsuite: Mark T17073 as broken on Windows Due to #17607. - - - - - acf40cae by Ben Gamari at 2020-01-07T13:13:02-05:00 gitlab-ci: Disallow Windows from failing - - - - - 34bc02c7 by Ben Gamari at 2020-01-07T13:13:02-05:00 configure: Find Python3 for testsuite In addition, we prefer the Mingw64 Python distribution on Windows due to #17483. - - - - - e35fe8d5 by Ben Gamari at 2020-01-07T13:13:02-05:00 testsuite: Fix Windows platform test Previously we used platform.system() and while this worked fine (e.g. returned `Windows`, as expected) locally under both msys and MingW64 Python distributions, it inexplicably returned `MINGW64_NT-10.0` under MingW64 Python on CI. It seems os.name is more reliable so we now use that instead.. - - - - - 48ef6217 by Ben Gamari at 2020-01-07T13:13:39-05:00 gitlab-ci: Rename push-test-metrics.sh to test-metrics.sh Refactoring to follow. - - - - - 2234fa92 by Ben Gamari at 2020-01-07T13:13:39-05:00 gitlab-ci: Pull test metrics before running testsuite Otherwise the testsuite driver may not have an up-to-date baseline. - - - - - 1ca9adbc by Sylvain Henry at 2020-01-07T13:14:18-05:00 Remove `parallel` check from configure.ac `parallel` is no longer a submodule since 3cb063c805ec841ca33b8371ef8aba9329221b6c - - - - - b69a3460 by Ryan Scott at 2020-01-07T13:14:57-05:00 Monomorphize HsModule to GhcPs (#17642) Analyzing the call sites for `HsModule` reveals that it is only ever used with parsed code (i.e., `GhcPs`). This simplifies `HsModule` by concretizing its `pass` parameter to always be `GhcPs`. Fixes #17642. - - - - - d491a679 by Sylvain Henry at 2020-01-08T06:16:31-05:00 Module hierarchy: Renamer (cf #13009) - - - - - d589410f by Ben Gamari at 2020-01-08T06:17:09-05:00 Bump haskeline submodule to 0.8.0.1 (cherry picked from commit feb3b955402d53c3875dd7a9a39f322827e5bd69) - - - - - 923a1272 by Ryan Scott at 2020-01-08T06:17:47-05:00 Print Core type applications with no whitespace after @ (#17643) This brings the pretty-printer for Core in line with how visible type applications are normally printed: namely, with no whitespace after the `@` character (i.e., `f @a` instead of `f @ a`). While I'm in town, I also give the same treatment to type abstractions (i.e., `\(@a)` instead of `\(@ a)`) and coercion applications (i.e., `f @~x` instead of `f @~ x`). Fixes #17643. - - - - - 49f83a0d by Adam Sandberg Eriksson at 2020-01-12T21:28:09-05:00 improve docs for HeaderInfo.getImports [skip ci] - - - - - 9129210f by Matthew Pickering at 2020-01-12T21:28:47-05:00 Overloaded Quotation Brackets (#246) This patch implements overloaded quotation brackets which generalise the desugaring of all quotation forms in terms of a new minimal interface. The main change is that a quotation, for example, [e| 5 |], will now have type `Quote m => m Exp` rather than `Q Exp`. The `Quote` typeclass contains a single method for generating new names which is used when desugaring binding structures. The return type of functions from the `Lift` type class, `lift` and `liftTyped` have been restricted to `forall m . Quote m => m Exp` rather than returning a result in a Q monad. More details about the feature can be read in the GHC proposal. https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0246-overloaded-bracket.rst - - - - - 350e2b78 by Richard Eisenberg at 2020-01-12T21:29:27-05:00 Don't zap to Any; error instead This changes GHC's treatment of so-called Naughty Quantification Candidates to issue errors, instead of zapping to Any. Close #16775. No new test cases, because existing ones cover this well. - - - - - 0b5ddc7f by Brian Wignall at 2020-01-12T21:30:08-05:00 Fix more typos, via an improved Levenshtein-style corrector - - - - - f732dbec by Ben Gamari at 2020-01-12T21:30:49-05:00 gitlab-ci: Retain bindists used by head.hackage for longer Previously we would keep them for two weeks. However, on the stable branches two weeks can easily elapse with no pushes. - - - - - c8636da5 by Sylvain Henry at 2020-01-12T21:31:30-05:00 Fix LANG=C for readelf invocation in T14999 The test fails when used with LANG=fr_FR.UTF-8 - - - - - 077a88de by Jean-Baptiste Mazon at 2020-01-12T21:32:08-05:00 users-guide/debug-info: typo “behivior” - - - - - 61916c5d by Simon Peyton Jones at 2020-01-12T21:32:44-05:00 Add comments about TH levels - - - - - 1fd766ca by Simon Peyton Jones at 2020-01-12T21:32:44-05:00 Comments about constraint floating - - - - - de01427e by Simon Peyton Jones at 2020-01-12T21:32:45-05:00 Minor refactor around quantified constraints This patch clarifies a dark corner of quantified constraints. * See Note [Yukky eq_sel for a HoleDest] in TcSMonad * Minor refactor, breaking out new function TcInteract.doTopReactEqPred - - - - - 30be3bf1 by Simon Peyton Jones at 2020-01-12T21:32:45-05:00 Comments in TcHsType - - - - - c5977d4d by Sebastian Graf at 2020-01-16T05:58:58-05:00 Better documentation for mkEtaWW [skip ci] So that hopefully I understand it faster next time. Also got rid of the confusing `orig_expr`, which makes the call site in `etaExpand` look out of sync with the passed `n` (which is not the original `n`). - - - - - 22c0bdc3 by John Ericson at 2020-01-16T05:59:37-05:00 Handle TagToEnum in the same big case as the other primops Before, it was a panic because it was handled above. But there must have been an error in my reasoning (another caller?) because #17442 reported the panic was hit. But, rather than figuring out what happened, I can just make it impossible by construction. By adding just a bit more bureaucracy in the return types, I can handle TagToEnum in the same case as all the others, so the big case is is now total, and the panic is removed. Fixes #17442 - - - - - ee5d63f4 by John Ericson at 2020-01-16T05:59:37-05:00 Get rid of OpDest `OpDest` was basically a defunctionalization. Just turn the code that cased on it into those functions, and call them directly. - - - - - 1ff55226 by John Ericson at 2020-01-16T06:00:16-05:00 Remove special case case of bool during STG -> C-- Allow removing the no longer needed cgPrimOp, getting rid of a small a small layer violation too. Change which made the special case no longer needed was #6135 / 6579a6c73082387f82b994305011f011d9d8382b, which dates back to 2013, making me feel better. - - - - - f416fe64 by Adam Wespiser at 2020-01-16T06:00:53-05:00 replace dead html link (fixes #17661) - - - - - f6bf2ce8 by Sebastian Graf at 2020-01-16T06:01:32-05:00 Revert "`exprOkForSpeculation` for Note [IO hack in the demand analyser]" This reverts commit ce64b397777408731c6dd3f5c55ea8415f9f565b on the grounds of the regression it would introduce in a couple of packages. Fixes #17653. Also undoes a slight metric increase in #13701 introduced by that commit that we didn't see prior to !1983. Metric Decrease: T13701 - - - - - a71323ff by Ben Gamari at 2020-01-17T08:43:16-05:00 gitlab-ci: Don't FORCE_SYMLINKS on Windows Not all runners have symlink permissions enabled. - - - - - 0499e3bc by Ömer Sinan Ağacan at 2020-01-20T15:31:33-05:00 Fix +RTS -Z flag documentation Stack squeezing is done on context switch, not on GC or stack overflow. Fix the documentation. Fixes #17685 [ci skip] - - - - - a661df91 by Ömer Sinan Ağacan at 2020-01-20T15:32:13-05:00 Document Stg.FVs module Fixes #17662 [ci skip] - - - - - db24e480 by Ben Gamari at 2020-01-20T15:32:52-05:00 llvmGen: Don't trash STG registers Fixes #13904. - - - - - f3d7fdb3 by Ben Gamari at 2020-01-20T15:32:52-05:00 llvmGen: Fix typo in readnone attribute - - - - - 442751c6 by Ben Gamari at 2020-01-20T15:32:52-05:00 llvmGen: Add lower-expect to the -O0 optimisation set @kavon says that this will improve block layout for stack checks. - - - - - e90ecc93 by Ben Gamari at 2020-01-20T15:32:52-05:00 llvmGen: Fix #14251 Fixes the calling convention for functions passing raw SSE-register values by adding padding as needed to get the values in the right registers. This problem cropped up when some args were unused an dropped from the live list. This folds together 2e23e1c7de01c92b038e55ce53d11bf9db993dd4 and 73273be476a8cc6c13368660b042b3b0614fd928 previously from @kavon. Metric Increase: T12707 ManyConstructors - - - - - 66e511a4 by Ben Gamari at 2020-01-20T15:33:28-05:00 testsuite: Preserve more information in framework failures Namely print the entire exception in hopes that this will help track down #17649. - - - - - b62b8cea by Ömer Sinan Ağacan at 2020-01-20T15:34:06-05:00 Remove deprecated -smp flag It was deprecated in 2012 with 46258b40 - - - - - 0c04a86a by Ben Gamari at 2020-01-20T15:34:43-05:00 gitlab-ci: Reenable submodule linter - - - - - 2bfabd22 by Ben Gamari at 2020-01-20T15:34:43-05:00 gitlab-ci: Allow submodule cleaning to fail on Windows Currently CI is inexplicably failing with ``` $ git submodule foreach git clean -xdf fatal: not a git repository: libffi-tarballs/../.git/modules/libffi-tarballs ``` I have no idea how this working tree got into such a state but we do need to fail more gracefully when it happens. Consequently, we allow the cleaning step to fail. - - - - - 14bced99 by Xavier Denis at 2020-01-20T15:35:21-05:00 Put the docs for :instances in alphabetical position - - - - - 7e0bb82b by Ben Gamari at 2020-01-20T15:35:57-05:00 Add missing Note [Improvement from Ground Wanteds] Closes #17659. - - - - - 17e43a7c by Ben Gamari at 2020-01-20T15:36:32-05:00 unregisterised: Fix declaration for stg_NO_FINALIZER Previously it had a redundant _entry suffix. We never noticed this previously presumably because we never generated references to it (however hard to believe this may be). However, it did start failing in !1304. - - - - - 3dae006f by PHO at 2020-01-20T15:37:08-05:00 Avoid ./configure failure on NetBSD - - - - - 738e2912 by Ben Gamari at 2020-01-24T13:42:56-05:00 testsuite: Widen acceptance window of T1969 I have seen >20% fluctuations in this number, leading to spurious failures. - - - - - ad4eb7a7 by Gabor Greif at 2020-01-25T05:19:07-05:00 Document the fact, that openFileBlocking can consume an OS thread indefinitely. Also state that a deadlock can happen with the non-threaded runtime. [ci skip] - - - - - be910728 by Sebastian Graf at 2020-01-25T05:19:46-05:00 `-ddump-str-signatures` dumps Text, not STG [skip ci] - - - - - 0e57d8a1 by Ömer Sinan Ağacan at 2020-01-25T05:20:27-05:00 Fix chaining tagged and untagged ptrs in compacting GC Currently compacting GC has the invariant that in a chain all fields are tagged the same. However this does not really hold: root pointers are not tagged, so when we thread a root we initialize a chain without a tag. When the pointed objects is evaluated and we have more pointers to it from the heap, we then add *tagged* fields to the chain (because pointers to it from the heap are tagged), ending up chaining fields with different tags (pointers from roots are NOT tagged, pointers from heap are). This breaks the invariant and as a result compacting GC turns tagged pointers into non-tagged. This later causes problem in the generated code where we do reads assuming that the pointer is aligned, e.g. 0x7(%rax) -- assumes that pointer is tagged 1 which causes misaligned reads. This caused #17088. We fix this using the "pointer tagging for large families" patch (#14373, !1742): - With the pointer tagging patch the GC can know what the tagged pointer to a CONSTR should be (previously we'd need to know the family size -- large families are always tagged 1, small families are tagged depending on the constructor). - Since we now know what the tags should be we no longer need to store the pointer tag in the info table pointers when forming chains in the compacting GC. As a result we no longer need to tag pointers in chains with 1/2 depending on whether the field points to an info table pointer, or to another field: an info table pointer is always tagged 0, everything else in the chain is tagged 1. The lost tags in pointers can be retrieved by looking at the info table. Finally, instead of using tag 1 for fields and tag 0 for info table pointers, we use two different tags for fields: - 1 for fields that have untagged pointers - 2 for fields that have tagged pointers When unchaining we then look at the pointer to a field, and depending on its tag we either leave a tagged pointer or an untagged pointer in the field. This allows chaining untagged and tagged fields together in compacting GC. Fixes #17088 Nofib results ------------- Binaries are smaller because of smaller `Compact.c` code. make mode=fast EXTRA_RUNTEST_OPTS="-cachegrind" EXTRA_HC_OPTS="-with-rtsopts=-c" NoFibRuns=1 -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS -0.3% 0.0% +0.0% +0.0% +0.0% CSD -0.3% 0.0% +0.0% +0.0% +0.0% FS -0.3% 0.0% +0.0% -0.0% -0.0% S -0.3% 0.0% +5.4% +0.8% +3.9% VS -0.3% 0.0% +0.0% -0.0% -0.0% VSD -0.3% 0.0% -0.0% -0.0% -0.2% VSM -0.3% 0.0% +0.0% +0.0% +0.0% anna -0.1% 0.0% +0.0% +0.0% +0.0% ansi -0.3% 0.0% +0.1% +0.0% +0.0% atom -0.2% 0.0% +0.0% +0.0% +0.0% awards -0.2% 0.0% +0.0% 0.0% -0.0% banner -0.3% 0.0% +0.0% +0.0% +0.0% bernouilli -0.3% 0.0% +0.1% +0.0% +0.0% binary-trees -0.2% 0.0% +0.0% 0.0% +0.0% boyer -0.3% 0.0% +0.2% +0.0% +0.0% boyer2 -0.2% 0.0% +0.2% +0.1% +0.0% bspt -0.2% 0.0% +0.0% +0.0% +0.0% cacheprof -0.2% 0.0% +0.0% +0.0% +0.0% calendar -0.3% 0.0% +0.0% +0.0% +0.0% cichelli -0.3% 0.0% +1.1% +0.2% +0.5% circsim -0.2% 0.0% +0.0% -0.0% -0.0% clausify -0.3% 0.0% +0.0% -0.0% -0.0% comp_lab_zift -0.2% 0.0% +0.0% +0.0% +0.0% compress -0.3% 0.0% +0.0% +0.0% +0.0% compress2 -0.3% 0.0% +0.0% -0.0% -0.0% constraints -0.3% 0.0% +0.2% +0.1% +0.1% cryptarithm1 -0.3% 0.0% +0.0% -0.0% 0.0% cryptarithm2 -0.3% 0.0% +0.0% +0.0% +0.0% cse -0.3% 0.0% +0.0% +0.0% +0.0% digits-of-e1 -0.3% 0.0% +0.0% +0.0% +0.0% digits-of-e2 -0.3% 0.0% +0.0% +0.0% -0.0% dom-lt -0.2% 0.0% +0.0% +0.0% +0.0% eliza -0.2% 0.0% +0.0% +0.0% +0.0% event -0.3% 0.0% +0.1% +0.0% -0.0% exact-reals -0.2% 0.0% +0.0% +0.0% +0.0% exp3_8 -0.3% 0.0% +0.0% +0.0% +0.0% expert -0.2% 0.0% +0.0% +0.0% +0.0% fannkuch-redux -0.3% 0.0% -0.0% -0.0% -0.0% fasta -0.3% 0.0% +0.0% +0.0% +0.0% fem -0.2% 0.0% +0.1% +0.0% +0.0% fft -0.2% 0.0% +0.0% -0.0% -0.0% fft2 -0.2% 0.0% +0.0% -0.0% +0.0% fibheaps -0.3% 0.0% +0.0% -0.0% -0.0% fish -0.3% 0.0% +0.0% +0.0% +0.0% fluid -0.2% 0.0% +0.4% +0.1% +0.1% fulsom -0.2% 0.0% +0.0% +0.0% +0.0% gamteb -0.2% 0.0% +0.1% +0.0% +0.0% gcd -0.3% 0.0% +0.0% +0.0% +0.0% gen_regexps -0.3% 0.0% +0.0% -0.0% -0.0% genfft -0.3% 0.0% +0.0% +0.0% +0.0% gg -0.2% 0.0% +0.7% +0.3% +0.2% grep -0.2% 0.0% +0.0% +0.0% +0.0% hidden -0.2% 0.0% +0.0% +0.0% +0.0% hpg -0.2% 0.0% +0.1% +0.0% +0.0% ida -0.3% 0.0% +0.0% +0.0% +0.0% infer -0.2% 0.0% +0.0% -0.0% -0.0% integer -0.3% 0.0% +0.0% +0.0% +0.0% integrate -0.2% 0.0% +0.0% +0.0% +0.0% k-nucleotide -0.2% 0.0% +0.0% +0.0% -0.0% kahan -0.3% 0.0% -0.0% -0.0% -0.0% knights -0.3% 0.0% +0.0% -0.0% -0.0% lambda -0.3% 0.0% +0.0% -0.0% -0.0% last-piece -0.3% 0.0% +0.0% +0.0% +0.0% lcss -0.3% 0.0% +0.0% +0.0% 0.0% life -0.3% 0.0% +0.0% -0.0% -0.0% lift -0.2% 0.0% +0.0% +0.0% +0.0% linear -0.2% 0.0% +0.0% +0.0% +0.0% listcompr -0.3% 0.0% +0.0% +0.0% +0.0% listcopy -0.3% 0.0% +0.0% +0.0% +0.0% maillist -0.3% 0.0% +0.0% -0.0% -0.0% mandel -0.2% 0.0% +0.0% +0.0% +0.0% mandel2 -0.3% 0.0% +0.0% +0.0% +0.0% mate -0.2% 0.0% +0.0% +0.0% +0.0% minimax -0.3% 0.0% +0.0% +0.0% +0.0% mkhprog -0.2% 0.0% +0.0% +0.0% +0.0% multiplier -0.3% 0.0% +0.0% -0.0% -0.0% n-body -0.2% 0.0% -0.0% -0.0% -0.0% nucleic2 -0.2% 0.0% +0.0% +0.0% +0.0% para -0.2% 0.0% +0.0% -0.0% -0.0% paraffins -0.3% 0.0% +0.0% -0.0% -0.0% parser -0.2% 0.0% +0.0% +0.0% +0.0% parstof -0.2% 0.0% +0.8% +0.2% +0.2% pic -0.2% 0.0% +0.1% -0.1% -0.1% pidigits -0.3% 0.0% +0.0% +0.0% +0.0% power -0.2% 0.0% +0.0% -0.0% -0.0% pretty -0.3% 0.0% -0.0% -0.0% -0.1% primes -0.3% 0.0% +0.0% +0.0% -0.0% primetest -0.2% 0.0% +0.0% -0.0% -0.0% prolog -0.3% 0.0% +0.0% -0.0% -0.0% puzzle -0.3% 0.0% +0.0% +0.0% +0.0% queens -0.3% 0.0% +0.0% +0.0% +0.0% reptile -0.2% 0.0% +0.2% +0.1% +0.0% reverse-complem -0.3% 0.0% +0.0% +0.0% +0.0% rewrite -0.3% 0.0% +0.0% -0.0% -0.0% rfib -0.2% 0.0% +0.0% +0.0% -0.0% rsa -0.2% 0.0% +0.0% +0.0% +0.0% scc -0.3% 0.0% -0.0% -0.0% -0.1% sched -0.3% 0.0% +0.0% +0.0% +0.0% scs -0.2% 0.0% +0.1% +0.0% +0.0% simple -0.2% 0.0% +3.4% +1.0% +1.8% solid -0.2% 0.0% +0.0% +0.0% +0.0% sorting -0.3% 0.0% +0.0% +0.0% +0.0% spectral-norm -0.2% 0.0% -0.0% -0.0% -0.0% sphere -0.2% 0.0% +0.0% +0.0% +0.0% symalg -0.2% 0.0% +0.0% +0.0% +0.0% tak -0.3% 0.0% +0.0% +0.0% -0.0% transform -0.2% 0.0% +0.2% +0.1% +0.1% treejoin -0.3% 0.0% +0.2% -0.0% -0.1% typecheck -0.3% 0.0% +0.0% +0.0% +0.0% veritas -0.1% 0.0% +0.0% +0.0% +0.0% wang -0.2% 0.0% +0.0% -0.0% -0.0% wave4main -0.3% 0.0% +0.0% -0.0% -0.0% wheel-sieve1 -0.3% 0.0% +0.0% -0.0% -0.0% wheel-sieve2 -0.3% 0.0% +0.0% -0.0% -0.0% x2n1 -0.3% 0.0% +0.0% +0.0% +0.0% -------------------------------------------------------------------------------- Min -0.3% 0.0% -0.0% -0.1% -0.2% Max -0.1% 0.0% +5.4% +1.0% +3.9% Geometric Mean -0.3% -0.0% +0.1% +0.0% +0.1% -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- circsim -0.2% 0.0% +1.6% +0.4% +0.7% constraints -0.3% 0.0% +4.3% +1.5% +2.3% fibheaps -0.3% 0.0% +3.5% +1.2% +1.3% fulsom -0.2% 0.0% +3.6% +1.2% +1.8% gc_bench -0.3% 0.0% +4.1% +1.3% +2.3% hash -0.3% 0.0% +6.6% +2.2% +3.6% lcss -0.3% 0.0% +0.7% +0.2% +0.7% mutstore1 -0.3% 0.0% +4.8% +1.4% +2.8% mutstore2 -0.3% 0.0% +3.4% +1.0% +1.7% power -0.2% 0.0% +2.7% +0.6% +1.9% spellcheck -0.3% 0.0% +1.1% +0.4% +0.4% -------------------------------------------------------------------------------- Min -0.3% 0.0% +0.7% +0.2% +0.4% Max -0.2% 0.0% +6.6% +2.2% +3.6% Geometric Mean -0.3% +0.0% +3.3% +1.0% +1.8% Metric changes -------------- While it sounds ridiculous, this change causes increased allocations in the following tests. We concluded that this change can't cause a difference in allocations and decided to land this patch. Fluctuations in "bytes allocated" metric is tracked in #17686. Metric Increase: Naperian T10547 T12150 T12234 T12425 T13035 T5837 T6048 - - - - - 8038cbd9 by Sebastian Graf at 2020-01-25T05:21:05-05:00 PmCheck: Formulate as translation between Clause Trees We used to check `GrdVec`s arising from multiple clauses and guards in isolation. That resulted in a split between `pmCheck` and `pmCheckGuards`, the implementations of which were similar, but subtly different in detail. Also the throttling mechanism described in `Note [Countering exponential blowup]` ultimately got quite complicated because it had to cater for both checking functions. This patch realises that pattern match checking doesn't just consider single guarded RHSs, but that it's always a whole set of clauses, each of which can have multiple guarded RHSs in turn. We do so by translating a list of `Match`es to a `GrdTree`: ```haskell data GrdTree = Rhs !RhsInfo | Guard !PmGrd !GrdTree -- captures lef-to-right match semantics | Sequence !GrdTree !GrdTree -- captures top-to-bottom match semantics | Empty -- For -XEmptyCase, neutral element of Sequence ``` Then we have a function `checkGrdTree` that matches a given `GrdTree` against an incoming set of values, represented by `Deltas`: ```haskell checkGrdTree :: GrdTree -> Deltas -> CheckResult ... ``` Throttling is isolated to the `Sequence` case and becomes as easy as one would expect: When the union of uncovered values becomes too big, just return the original incoming `Deltas` instead (which is always a superset of the union, thus a sound approximation). The returned `CheckResult` contains two things: 1. The set of values that were not covered by any of the clauses, for exhaustivity warnings. 2. The `AnnotatedTree` that enriches the syntactic structure of the input program with divergence and inaccessibility information. This is `AnnotatedTree`: ```haskell data AnnotatedTree = AccessibleRhs !RhsInfo | InaccessibleRhs !RhsInfo | MayDiverge !AnnotatedTree | SequenceAnn !AnnotatedTree !AnnotatedTree | EmptyAnn ``` Crucially, `MayDiverge` asserts that the tree may force diverging values, so not all of its wrapped clauses can be redundant. While the set of uncovered values can be used to generate the missing equations for warning messages, redundant and proper inaccessible equations can be extracted from `AnnotatedTree` by `redundantAndInaccessibleRhss`. For this to work properly, the interface to the Oracle had to change. There's only `addPmCts` now, which takes a bag of `PmCt`s. There's a whole bunch of `PmCt` variants to replace the different oracle functions from before. The new `AnnotatedTree` structure allows for more accurate warning reporting (as evidenced by a number of changes spread throughout GHC's code base), thus we fix #17465. Fixes #17646 on the go. Metric Decrease: T11822 T9233 PmSeriesS haddock.compiler - - - - - 86966d48 by Sebastian Graf at 2020-01-25T05:21:05-05:00 PmCheck: Properly handle constructor-bound type variables In https://gitlab.haskell.org/ghc/ghc/merge_requests/2192#note_246551 Simon convinced me that ignoring type variables existentially bound by data constructors have to be the same way as value binders. Sadly I couldn't think of a regression test, but I'm confident that this change strictly improves on the status quo. - - - - - c3fde723 by Ryan Scott at 2020-01-25T05:21:40-05:00 Handle local fixity declarations in DsMeta properly `DsMeta.rep_sig` used to skip over `FixSig` entirely, which had the effect of causing local fixity declarations to be dropped when quoted in Template Haskell. But there is no good reason for this state of affairs, as the code in `DsMeta.repFixD` (which handles top-level fixity declarations) handles local fixity declarations just fine. This patch factors out the necessary parts of `repFixD` so that they can be used in `rep_sig` as well. There was one minor complication: the fixity signatures for class methods in each `HsGroup` were stored both in `FixSig`s _and_ the list of `LFixitySig`s for top-level fixity signatures, so I needed to take action to prevent fixity signatures for class methods being converted to `Dec`s twice. I tweaked `RnSource.add` to avoid putting these fixity signatures in two places and added `Note [Top-level fixity signatures in an HsGroup]` in `GHC.Hs.Decls` to explain the new design. Fixes #17608. Bumps the Haddock submodule. - - - - - 6e2d9ee2 by Sylvain Henry at 2020-01-25T05:22:20-05:00 Module hierarchy: Cmm (cf #13009) - - - - - 8b726534 by PHO at 2020-01-25T05:23:01-05:00 Fix rts allocateExec() on NetBSD Similar to SELinux, NetBSD "PaX mprotect" prohibits marking a page mapping both writable and executable at the same time. Use libffi which knows how to work around it. - - - - - 6eb566a0 by Xavier Denis at 2020-01-25T05:23:39-05:00 Add ghc-in-ghci for stack based builds - - - - - b1a32170 by Xavier Denis at 2020-01-25T05:23:39-05:00 Create ghci.cabal.sh - - - - - 0a5e4f5f by Sylvain Henry at 2020-01-25T05:24:19-05:00 Split glasgow_exts into several files (#17316) - - - - - b3e5c678 by Ben Gamari at 2020-01-25T05:24:57-05:00 hadrian: Throw error on duplicate-named flavours Throw an error if the user requests a flavour for which there is more than one match. Fixes #17156. - - - - - 0940b59a by Ryan Scott at 2020-01-25T08:15:05-05:00 Do not bring visible foralls into scope in hsScopedTvs Previously, `hsScopedTvs` (and its cousin `hsWcScopedTvs`) pretended that visible dependent quantification could not possibly happen at the term level, and cemented that assumption with an `ASSERT`: ```hs hsScopedTvs (HsForAllTy { hst_fvf = vis_flag, ... }) = ASSERT( vis_flag == ForallInvis ) ... ``` It turns out that this assumption is wrong. You can end up tripping this `ASSERT` if you stick it to the man and write a type for a term that uses visible dependent quantification anyway, like in this example: ```hs {-# LANGUAGE ScopedTypeVariables #-} x :: forall a -> a -> a x = x ``` That won't typecheck, but that's not the point. Before the typechecker has a chance to reject this, the renamer will try to use `hsScopedTvs` to bring `a` into scope over the body of `x`, since `a` is quantified by a `forall`. This, in turn, causes the `ASSERT` to fail. Bummer. Instead of walking on this dangerous ground, this patch makes GHC adopt a more hardline stance by pattern-matching directly on `ForallInvis` in `hsScopedTvs`: ```hs hsScopedTvs (HsForAllTy { hst_fvf = ForallInvis, ... }) = ... ``` Now `a` will not be brought over the body of `x` at all (which is how it should be), there's no chance of the `ASSERT` failing anymore (as it's gone), and best of all, the behavior of `hsScopedTvs` does not change. Everyone wins! Fixes #17687. - - - - - 1132602f by Ryan Scott at 2020-01-27T10:03:42-05:00 Use splitLHs{ForAll,Sigma}TyInvis throughout the codebase Richard points out in #17688 that we use `splitLHsForAllTy` and `splitLHsSigmaTy` in places that we ought to be using the corresponding `-Invis` variants instead, identifying two bugs that are caused by this oversight: * Certain TH-quoted type signatures, such as those that appear in quoted `SPECIALISE` pragmas, silently turn visible `forall`s into invisible `forall`s. * When quoted, the type `forall a -> (a ~ a) => a` will turn into `forall a -> a` due to a bug in `DsMeta.repForall` that drops contexts that follow visible `forall`s. These are both ultimately caused by the fact that `splitLHsForAllTy` and `splitLHsSigmaTy` split apart visible `forall`s in addition to invisible ones. This patch cleans things up: * We now use `splitLHsForAllTyInvis` and `splitLHsSigmaTyInvis` throughout the codebase. Relatedly, the `splitLHsForAllTy` and `splitLHsSigmaTy` have been removed, as they are easy to misuse. * `DsMeta.repForall` now only handles invisible `forall`s to reduce the chance for confusion with visible `forall`s, which need to be handled differently. I also renamed it from `repForall` to `repForallT` to emphasize that its distinguishing characteristic is the fact that it desugars down to `L.H.TH.Syntax.ForallT`. Fixes #17688. - - - - - 97d0b0a3 by Matthew Pickering at 2020-01-27T10:04:19-05:00 Make Block.h compile with c++ compilers - - - - - 4bada77d by Tom Ellis at 2020-01-27T12:30:46-05:00 Disable two warnings for files that trigger them incomplete-uni-patterns and incomplete-record-updates will be in -Wall at a future date, so prepare for that by disabling those warnings on files that trigger them. - - - - - 0188404a by Tom Ellis at 2020-01-27T12:30:46-05:00 Add two warnings to stage 2 build - - - - - acae02c1 by Tom Ellis at 2020-01-27T12:30:46-05:00 Add two warnings to Hadrian - - - - - bf38a20e by Sylvain Henry at 2020-01-31T02:46:15-05:00 Call `interpretPackageEnv` from `setSessionDynFlags` interpretPackageEnv modifies the flags by reading the dreaded package environments. It is much less surprising to call it from `setSessionDynFlags` instead of reading package environments as a side-effect of `initPackages`. - - - - - 29c701c1 by Sylvain Henry at 2020-01-31T02:46:15-05:00 Refactor package related code The package terminology is a bit of a mess. Cabal packages contain components. Instances of these components when built with some flags/options/dependencies are called units. Units are registered into package databases and their metadata are called PackageConfig. GHC only knows about package databases containing units. It is a sad mismatch not fixed by this patch (we would have to rename parameters such as `package-id <unit-id>` which would affect users). This patch however fixes the following internal names: - Renames PackageConfig into UnitInfo. - Rename systemPackageConfig into globalPackageDatabase[Path] - Rename PkgConfXX into PkgDbXX - Rename pkgIdMap into unitIdMap - Rename ModuleToPkgDbAll into ModuleNameProvidersMap - Rename lookupPackage into lookupUnit - Add comments on DynFlags package related fields It also introduces a new `PackageDatabase` datatype instead of explicitly passing the following tuple: `(FilePath,[PackageConfig])`. The `pkgDatabase` field in `DynFlags` now contains the unit info for each unit of each package database exactly as they have been read from disk. Previously the command-line flag `-distrust-all-packages` would modify these unit info. Now this flag only affects the "dynamic" consolidated package state found in `pkgState` field. It makes sense because `initPackages` could be called first with this `distrust-all-packages` flag set and then again (using ghc-api) without and it should work (package databases are not read again from disk when `initPackages` is called the second time). Bump haddock submodule - - - - - 942c7148 by Ben Gamari at 2020-01-31T02:46:54-05:00 rename: Eliminate usage of mkVarOccUnique Replacing it with `newSysName`. Fixes #17061. - - - - - 41117d71 by Ben Gamari at 2020-01-31T02:47:31-05:00 base: Use one-shot kqueue on macOS The underlying reason requiring that one-shot usage be disabled (#13903) has been fixed. Closes #15768. - - - - - 01b15b83 by Ben Gamari at 2020-01-31T02:48:08-05:00 testsuite: Don't crash on encoding failure in print If the user doesn't use a Unicode locale then the testsuite driver would previously throw framework failures due to encoding failures. We now rather use the `replace` error-handling strategy. - - - - - c846618a by Ömer Sinan Ağacan at 2020-01-31T12:21:10+03:00 Do CafInfo/SRT analysis in Cmm This patch removes all CafInfo predictions and various hacks to preserve predicted CafInfos from the compiler and assigns final CafInfos to interface Ids after code generation. SRT analysis is extended to support static data, and Cmm generator is modified to allow generating static_link fields after SRT analysis. This also fixes `-fcatch-bottoms`, which introduces error calls in case expressions in CorePrep, which runs *after* CoreTidy (which is where we decide on CafInfos) and turns previously non-CAFFY things into CAFFY. Fixes #17648 Fixes #9718 Evaluation ========== NoFib ----- Boot with: `make boot mode=fast` Run: `make mode=fast EXTRA_RUNTEST_OPTS="-cachegrind" NoFibRuns=1` -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS -0.0% 0.0% -0.0% -0.0% -0.0% CSD -0.0% 0.0% -0.0% -0.0% -0.0% FS -0.0% 0.0% -0.0% -0.0% -0.0% S -0.0% 0.0% -0.0% -0.0% -0.0% VS -0.0% 0.0% -0.0% -0.0% -0.0% VSD -0.0% 0.0% -0.0% -0.0% -0.5% VSM -0.0% 0.0% -0.0% -0.0% -0.0% anna -0.1% 0.0% -0.0% -0.0% -0.0% ansi -0.0% 0.0% -0.0% -0.0% -0.0% atom -0.0% 0.0% -0.0% -0.0% -0.0% awards -0.0% 0.0% -0.0% -0.0% -0.0% banner -0.0% 0.0% -0.0% -0.0% -0.0% bernouilli -0.0% 0.0% -0.0% -0.0% -0.0% binary-trees -0.0% 0.0% -0.0% -0.0% -0.0% boyer -0.0% 0.0% -0.0% -0.0% -0.0% boyer2 -0.0% 0.0% -0.0% -0.0% -0.0% bspt -0.0% 0.0% -0.0% -0.0% -0.0% cacheprof -0.0% 0.0% -0.0% -0.0% -0.0% calendar -0.0% 0.0% -0.0% -0.0% -0.0% cichelli -0.0% 0.0% -0.0% -0.0% -0.0% circsim -0.0% 0.0% -0.0% -0.0% -0.0% clausify -0.0% 0.0% -0.0% -0.0% -0.0% comp_lab_zift -0.0% 0.0% -0.0% -0.0% -0.0% compress -0.0% 0.0% -0.0% -0.0% -0.0% compress2 -0.0% 0.0% -0.0% -0.0% -0.0% constraints -0.0% 0.0% -0.0% -0.0% -0.0% cryptarithm1 -0.0% 0.0% -0.0% -0.0% -0.0% cryptarithm2 -0.0% 0.0% -0.0% -0.0% -0.0% cse -0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e1 -0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e2 -0.0% 0.0% -0.0% -0.0% -0.0% dom-lt -0.0% 0.0% -0.0% -0.0% -0.0% eliza -0.0% 0.0% -0.0% -0.0% -0.0% event -0.0% 0.0% -0.0% -0.0% -0.0% exact-reals -0.0% 0.0% -0.0% -0.0% -0.0% exp3_8 -0.0% 0.0% -0.0% -0.0% -0.0% expert -0.0% 0.0% -0.0% -0.0% -0.0% fannkuch-redux -0.0% 0.0% -0.0% -0.0% -0.0% fasta -0.0% 0.0% -0.0% -0.0% -0.0% fem -0.0% 0.0% -0.0% -0.0% -0.0% fft -0.0% 0.0% -0.0% -0.0% -0.0% fft2 -0.0% 0.0% -0.0% -0.0% -0.0% fibheaps -0.0% 0.0% -0.0% -0.0% -0.0% fish -0.0% 0.0% -0.0% -0.0% -0.0% fluid -0.1% 0.0% -0.0% -0.0% -0.0% fulsom -0.0% 0.0% -0.0% -0.0% -0.0% gamteb -0.0% 0.0% -0.0% -0.0% -0.0% gcd -0.0% 0.0% -0.0% -0.0% -0.0% gen_regexps -0.0% 0.0% -0.0% -0.0% -0.0% genfft -0.0% 0.0% -0.0% -0.0% -0.0% gg -0.0% 0.0% -0.0% -0.0% -0.0% grep -0.0% 0.0% -0.0% -0.0% -0.0% hidden -0.0% 0.0% -0.0% -0.0% -0.0% hpg -0.1% 0.0% -0.0% -0.0% -0.0% ida -0.0% 0.0% -0.0% -0.0% -0.0% infer -0.0% 0.0% -0.0% -0.0% -0.0% integer -0.0% 0.0% -0.0% -0.0% -0.0% integrate -0.0% 0.0% -0.0% -0.0% -0.0% k-nucleotide -0.0% 0.0% -0.0% -0.0% -0.0% kahan -0.0% 0.0% -0.0% -0.0% -0.0% knights -0.0% 0.0% -0.0% -0.0% -0.0% lambda -0.0% 0.0% -0.0% -0.0% -0.0% last-piece -0.0% 0.0% -0.0% -0.0% -0.0% lcss -0.0% 0.0% -0.0% -0.0% -0.0% life -0.0% 0.0% -0.0% -0.0% -0.0% lift -0.0% 0.0% -0.0% -0.0% -0.0% linear -0.1% 0.0% -0.0% -0.0% -0.0% listcompr -0.0% 0.0% -0.0% -0.0% -0.0% listcopy -0.0% 0.0% -0.0% -0.0% -0.0% maillist -0.0% 0.0% -0.0% -0.0% -0.0% mandel -0.0% 0.0% -0.0% -0.0% -0.0% mandel2 -0.0% 0.0% -0.0% -0.0% -0.0% mate -0.0% 0.0% -0.0% -0.0% -0.0% minimax -0.0% 0.0% -0.0% -0.0% -0.0% mkhprog -0.0% 0.0% -0.0% -0.0% -0.0% multiplier -0.0% 0.0% -0.0% -0.0% -0.0% n-body -0.0% 0.0% -0.0% -0.0% -0.0% nucleic2 -0.0% 0.0% -0.0% -0.0% -0.0% para -0.0% 0.0% -0.0% -0.0% -0.0% paraffins -0.0% 0.0% -0.0% -0.0% -0.0% parser -0.1% 0.0% -0.0% -0.0% -0.0% parstof -0.1% 0.0% -0.0% -0.0% -0.0% pic -0.0% 0.0% -0.0% -0.0% -0.0% pidigits -0.0% 0.0% -0.0% -0.0% -0.0% power -0.0% 0.0% -0.0% -0.0% -0.0% pretty -0.0% 0.0% -0.3% -0.4% -0.4% primes -0.0% 0.0% -0.0% -0.0% -0.0% primetest -0.0% 0.0% -0.0% -0.0% -0.0% prolog -0.0% 0.0% -0.0% -0.0% -0.0% puzzle -0.0% 0.0% -0.0% -0.0% -0.0% queens -0.0% 0.0% -0.0% -0.0% -0.0% reptile -0.0% 0.0% -0.0% -0.0% -0.0% reverse-complem -0.0% 0.0% -0.0% -0.0% -0.0% rewrite -0.0% 0.0% -0.0% -0.0% -0.0% rfib -0.0% 0.0% -0.0% -0.0% -0.0% rsa -0.0% 0.0% -0.0% -0.0% -0.0% scc -0.0% 0.0% -0.3% -0.5% -0.4% sched -0.0% 0.0% -0.0% -0.0% -0.0% scs -0.0% 0.0% -0.0% -0.0% -0.0% simple -0.1% 0.0% -0.0% -0.0% -0.0% solid -0.0% 0.0% -0.0% -0.0% -0.0% sorting -0.0% 0.0% -0.0% -0.0% -0.0% spectral-norm -0.0% 0.0% -0.0% -0.0% -0.0% sphere -0.0% 0.0% -0.0% -0.0% -0.0% symalg -0.0% 0.0% -0.0% -0.0% -0.0% tak -0.0% 0.0% -0.0% -0.0% -0.0% transform -0.0% 0.0% -0.0% -0.0% -0.0% treejoin -0.0% 0.0% -0.0% -0.0% -0.0% typecheck -0.0% 0.0% -0.0% -0.0% -0.0% veritas -0.0% 0.0% -0.0% -0.0% -0.0% wang -0.0% 0.0% -0.0% -0.0% -0.0% wave4main -0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve1 -0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve2 -0.0% 0.0% -0.0% -0.0% -0.0% x2n1 -0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min -0.1% 0.0% -0.3% -0.5% -0.5% Max -0.0% 0.0% -0.0% -0.0% -0.0% Geometric Mean -0.0% -0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- circsim -0.1% 0.0% -0.0% -0.0% -0.0% constraints -0.0% 0.0% -0.0% -0.0% -0.0% fibheaps -0.0% 0.0% -0.0% -0.0% -0.0% gc_bench -0.0% 0.0% -0.0% -0.0% -0.0% hash -0.0% 0.0% -0.0% -0.0% -0.0% lcss -0.0% 0.0% -0.0% -0.0% -0.0% power -0.0% 0.0% -0.0% -0.0% -0.0% spellcheck -0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min -0.1% 0.0% -0.0% -0.0% -0.0% Max -0.0% 0.0% -0.0% -0.0% -0.0% Geometric Mean -0.0% +0.0% -0.0% -0.0% -0.0% Manual inspection of programs in testsuite/tests/programs --------------------------------------------------------- I built these programs with a bunch of dump flags and `-O` and compared STG, Cmm, and Asm dumps and file sizes. (Below the numbers in parenthesis show number of modules in the program) These programs have identical compiler (same .hi and .o sizes, STG, and Cmm and Asm dumps): - Queens (1), andre_monad (1), cholewo-eval (2), cvh_unboxing (3), andy_cherry (7), fun_insts (1), hs-boot (4), fast2haskell (2), jl_defaults (1), jq_readsPrec (1), jules_xref (1), jtod_circint (4), jules_xref2 (1), lennart_range (1), lex (1), life_space_leak (1), bargon-mangler-bug (7), record_upd (1), rittri (1), sanders_array (1), strict_anns (1), thurston-module-arith (2), okeefe_neural (1), joao-circular (6), 10queens (1) Programs with different compiler outputs: - jl_defaults (1): For some reason GHC HEAD marks a lot of top-level `[Int]` closures as CAFFY for no reason. With this patch we no longer make them CAFFY and generate less SRT entries. For some reason Main.o is slightly larger with this patch (1.3%) and the executable sizes are the same. (I'd expect both to be smaller) - launchbury (1): Same as jl_defaults: top-level `[Int]` closures marked as CAFFY for no reason. Similarly `Main.o` is 1.4% larger but the executable sizes are the same. - galois_raytrace (13): Differences are in the Parse module. There are a lot, but some of the changes are caused by the fact that for some reason (I think a bug) GHC HEAD marks the dictionary for `Functor Identity` as CAFFY. Parse.o is 0.4% larger, the executable size is the same. - north_array: We now generate less SRT entries because some of array primops used in this program like `NewArrayOp` get eliminated during Stg-to-Cmm and turn some CAFFY things into non-CAFFY. Main.o gets 24% larger (9224 bytes from 9000 bytes), executable sizes are the same. - seward-space-leak: Difference in this program is better shown by this smaller example: module Lib where data CDS = Case [CDS] [(Int, CDS)] | Call CDS CDS instance Eq CDS where Case sels1 rets1 == Case sels2 rets2 = sels1 == sels2 && rets1 == rets2 Call a1 b1 == Call a2 b2 = a1 == a2 && b1 == b2 _ == _ = False In this program GHC HEAD builds a new SRT for the recursive group of `(==)`, `(/=)` and the dictionary closure. Then `/=` points to `==` in its SRT field, and `==` uses the SRT object as its SRT. With this patch we use the closure for `/=` as the SRT and add `==` there. Then `/=` gets an empty SRT field and `==` points to `/=` in its SRT field. This change looks fine to me. Main.o gets 0.07% larger, executable sizes are identical. head.hackage ------------ head.hackage's CI script builds 428 packages from Hackage using this patch with no failures. Compiler performance -------------------- The compiler perf tests report that the compiler allocates slightly more (worst case observed so far is 4%). However most programs in the test suite are small, single file programs. To benchmark compiler performance on something more realistic I build Cabal (the library, 236 modules) with different optimisation levels. For the "max residency" row I run GHC with `+RTS -s -A100k -i0 -h` for more accurate numbers. Other rows are generated with just `-s`. (This is because `-i0` causes running GC much more frequently and as a result "bytes copied" gets inflated by more than 25x in some cases) * -O0 | | GHC HEAD | This MR | Diff | | --------------- | -------------- | -------------- | ------ | | Bytes allocated | 54,413,350,872 | 54,701,099,464 | +0.52% | | Bytes copied | 4,926,037,184 | 4,990,638,760 | +1.31% | | Max residency | 421,225,624 | 424,324,264 | +0.73% | * -O1 | | GHC HEAD | This MR | Diff | | --------------- | --------------- | --------------- | ------ | | Bytes allocated | 245,849,209,992 | 246,562,088,672 | +0.28% | | Bytes copied | 26,943,452,560 | 27,089,972,296 | +0.54% | | Max residency | 982,643,440 | 991,663,432 | +0.91% | * -O2 | | GHC HEAD | This MR | Diff | | --------------- | --------------- | --------------- | ------ | | Bytes allocated | 291,044,511,408 | 291,863,910,912 | +0.28% | | Bytes copied | 37,044,237,616 | 36,121,690,472 | -2.49% | | Max residency | 1,071,600,328 | 1,086,396,256 | +1.38% | Extra compiler allocations -------------------------- Runtime allocations of programs are as reported above (NoFib section). The compiler now allocates more than before. Main source of allocation in this patch compared to base commit is the new SRT algorithm (GHC.Cmm.Info.Build). Below is some of the extra work we do with this patch, numbers generated by profiled stage 2 compiler when building a pathological case (the test 'ManyConstructors') with '-O2': - We now sort the final STG for a module, which means traversing the entire program, generating free variable set for each top-level binding, doing SCC analysis, and re-ordering the program. In ManyConstructors this step allocates 97,889,952 bytes. - We now do SRT analysis on static data, which in a program like ManyConstructors causes analysing 10,000 bindings that we would previously just skip. This step allocates 70,898,352 bytes. - We now maintain an SRT map for the entire module as we compile Cmm groups: data ModuleSRTInfo = ModuleSRTInfo { ... , moduleSRTMap :: SRTMap } (SRTMap is just a strict Map from the 'containers' library) This map gets an entry for most bindings in a module (exceptions are THUNKs and CAFFY static functions). For ManyConstructors this map gets 50015 entries. - Once we're done with code generation we generate a NameSet from SRTMap for the non-CAFFY names in the current module. This set gets the same number of entries as the SRTMap. - Finally we update CafInfos in ModDetails for the non-CAFFY Ids, using the NameSet generated in the previous step. This usually does the least amount of allocation among the work listed here. Only place with this patch where we do less work in the CAF analysis in the tidying pass (CoreTidy). However that doesn't save us much, as the pass still needs to traverse the whole program and update IdInfos for other reasons. Only thing we don't here do is the `hasCafRefs` pass over the RHS of bindings, which is a stateless pass that returns a boolean value, so it doesn't allocate much. (Metric changes blow are all increased allocations) Metric changes -------------- Metric Increase: ManyAlternatives ManyConstructors T13035 T14683 T1969 T9961 - - - - - 2a87a565 by Andreas Klebinger at 2020-01-31T12:21:10+03:00 A few optimizations in STG and Cmm parts: (Guided by the profiler output) - Add a few bang patterns, INLINABLE annotations, and a seqList in a few places in Cmm and STG parts. - Do not add external variables as dependencies in STG dependency analysis (GHC.Stg.DepAnal). - - - - - bef704b6 by Simon Peyton Jones at 2020-02-01T02:28:45-05:00 Improve skolemisation This patch avoids skolemiseUnboundMetaTyVar making up a fresh Name when it doesn't need to. See Note [Skolemising and identity] Improves error messsages for partial type signatures. - - - - - cd110423 by Simon Peyton Jones at 2020-02-01T02:28:45-05:00 Improve pretty-printing for TyConBinders In particular, show their kinds. - - - - - 913287a0 by Simon Peyton Jones at 2020-02-01T02:28:45-05:00 Fix scoping of TyCon binders in TcTyClsDecls This patch fixes #17566 by refactoring the way we decide the final identity of the tyvars in the TyCons of a possibly-recursive nest of type and class decls, possibly with associated types. It's all laid out in Note [Swizzling the tyvars before generaliseTcTyCon] Main changes: * We have to generalise each decl (with its associated types) all at once: TcTyClsDecls.generaliseTyClDecl * The main new work is done in TcTyClsDecls.swizzleTcTyConBndrs * The mysterious TcHsSyn.zonkRecTyVarBndrs dies altogether Other smaller things: * A little refactoring, moving bindTyClTyVars from tcTyClDecl1 to tcDataDefn, tcSynRhs, etc. Clearer, reduces the number of parameters * Reduce the amount of swizzling required. Specifically, bindExplicitTKBndrs_Q_Tv doesn't need to clone a new Name for the TyVarTv, and not cloning means that in the vasly common case, swizzleTyConBndrs is a no-op In detail: Rename newTyVarTyVar --> cloneTyVarTyVar Add newTyVarTyTyVar that doesn't clone Use the non-cloning newTyVarTyVar in bindExplicitTKBndrs_Q_Tv Rename newFlexiKindedTyVarTyVar --> cloneFlexiKindedTyVarTyVar * Define new utility function and use it HsDecls.familyDeclName :: FamilyDecl (GhcPass p) -> IdP (GhcPass p) Updates haddock submodule. - - - - - 58ed6c4a by Ben Gamari at 2020-02-01T02:29:23-05:00 rts/M32Alloc: Don't attempt to unmap non-existent pages The m32 allocator's `pages` list may contain NULLs in the case that the page was flushed. Some `munmap` implementations (e.g. FreeBSD's) don't like it if we pass them NULL. Don't do that. - - - - - 859db7d6 by Ömer Sinan Ağacan at 2020-02-01T14:18:49+03:00 Improve/fix -fcatch-bottoms documentation Old documentation suggests that -fcatch-bottoms only adds a default alternative to bottoming case expression, but that's not true. We use a very simplistic "is exhaustive" check and add default alternatives to any case expression that does not cover all constructors of the type. In case of GADTs this simple check assumes all constructors should be covered, even the ones ruled out by the type of the scrutinee. Update the documentation to reflect this. (Originally noticed in #17648) [ci skip] - - - - - 54dfa94a by John Ericson at 2020-02-03T21:14:24-05:00 Fix docs for FrontendResult Other variant was removed in ac1a379363618a6f2f17fff65ce9129164b6ef30 but docs were no changed. - - - - - 5e63d9c0 by John Ericson at 2020-02-03T21:15:02-05:00 Refactor HscMain.finish I found the old control flow a bit hard to follow; I rewrote it to first decide whether to desugar, and then use that choice when computing whether to simplify / what sort of interface file to write. I hope eventually we will always write post-tc interface files, which will make the logic of this function even simpler, and continue the thrust of this refactor. - - - - - e580e5b8 by Stefan Schulze Frielinghaus at 2020-02-04T09:29:00-05:00 Do not build StgCRunAsm.S for unregisterised builds For unregisterised builds StgRun/StgReturn are implemented via a mini interpreter in StgCRun.c and therefore would collide with the implementations in StgCRunAsm.S. - - - - - e3b0bd97 by Stefan Schulze Frielinghaus at 2020-02-04T09:29:00-05:00 fixup! fixup! Do not build StgCRunAsm.S for unregisterised builds - - - - - eb629fab by John Ericson at 2020-02-04T09:29:38-05:00 Delete some superfluous helper functions in HscMain The driver code is some of the nastiest in GHC, and I am worried about being able to untangle all the tech debt. In `HscMain` we have a number of helpers which are either not-used or little used. I delete them so we can reduce cognative load, distilling the essential complexity away from the cruft. - - - - - c90eca55 by Sebastian Graf at 2020-02-05T09:21:29-05:00 PmCheck: Record type constraints arising from existentials in `PmCoreCt`s In #17703 (a follow-up of !2192), we established that contrary to my belief, type constraints arising from existentials in code like ```hs data Ex where Ex :: a -> Ex f _ | let x = Ex @Int 15 = case x of Ex -> ... ``` are in fact useful. This commit makes a number of refactorings and improvements to comments, but fundamentally changes `addCoreCt.core_expr` to record the type constraint `a ~ Int` in addition to `x ~ Ex @a y` and `y ~ 15`. Fixes #17703. - - - - - 6d3b5d57 by Ömer Sinan Ağacan at 2020-02-05T09:22:10-05:00 testlib: Extend existing *_opts in extra_*_opts Previously we'd override the existing {run,hc} opts in extra_{run,hc}_opts, which caused flakiness in T1969, see #17712. extra_{run,hc}_opts now extends {run,hc} opts, instead of overriding. Also we shrank the allocation area for T1969 in order to increase residency sampling frequency. Fixes #17712 - - - - - 9c89a48d by Ömer Sinan Ağacan at 2020-02-05T09:22:52-05:00 Remove CafInfo-related code from STG lambda lift pass After c846618ae0 we don't have accurate CafInfos for Ids in the current module and we're free to introduce new CAFFY or non-CAFFY bindings or change CafInfos of existing binders; so no we no longer need to maintain CafInfos in Core or STG passes. - - - - - 70ddb8bf by Ryan Scott at 2020-02-05T09:23:30-05:00 Add regression test for #17773 - - - - - e8004e5d by Ben Gamari at 2020-02-05T13:55:19-05:00 gitlab-ci: Allow Windows builds to fail again Due to T7702 and the process issues described in #17777. - - - - - 29b72c00 by Ben Gamari at 2020-02-06T11:55:41-05:00 VarSet: Introduce nonDetFoldVarSet - - - - - c4e6b35d by Ben Gamari at 2020-02-06T11:55:41-05:00 Move closeOverKinds and friends to TyCoFVs - - - - - ed2f0e5c by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Reform the free variable finders for types This patch delivers on (much of) #17509. * Introduces the shallow vs deep free variable distinction * Introduce TyCoRep.foldType, foldType :: Monoid a => TyCoFolder env a -> env -> Type -> a and use it in the free variable finders. * Substitution in TyCoSubst * ASSERTs are on for checkValidSubst * checkValidSubst uses shallowTyCoVarsOfTypes etc Quite a few things still to do * We could use foldType in lots of other places * We could use mapType for substitution. (Check that we get good code!) * Some (but not yet all) clients of substitution can now save time by using shallowTyCoVarsOfTypes * All calls to tyCoVarsOfTypes should be inspected; most of them should be shallow. Maybe. * Currently shallowTyCoVarsOfTypes still returns unification variables, but not CoVarHoles. Reason: we need to return unification variables in some of the calls in TcSimplify, eg when promoting. * We should do the same thing for tyCoFVsOfTypes, which is currently unchanged. * tyCoFVsOfTypes returns CoVarHoles, because of the use in TcSimplify.mkResidualConstraints. See Note [Emitting the residual implication in simplifyInfer] * #17509 talks about "relevant" variables too. - - - - - 01a1f4fb by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Use foldTyCo for noFreeVarsOfType - - - - - 0e59afd6 by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Simplify closeOverKinds - - - - - 9ca5c88e by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Use foldTyCo for coVarsOfType - - - - - 5541b87c by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Use foldTyCo for exactTyCoVarsOfType This entailed * Adding a tcf_view field to TyCoFolder * Moving exactTyCoVarsOtType to TcType. It properly belongs there, since only the typechecker calls this function. But it also means that we can "see" and inline tcView. Metric Decrease: T14683 - - - - - 7c122851 by Simon Peyton Jones at 2020-02-06T11:56:02-05:00 Comments only - - - - - 588acb99 by Adam Sandberg Eriksson at 2020-02-08T10:15:38-05:00 slightly better named cost-centres for simple pattern bindings #17006 ``` main = do print $ g [1..100] a where g xs x = map (`mod` x) xs a :: Int = 324 ``` The above program previously attributed the cost of computing 324 to a cost centre named `(...)`, with this change the cost is attributed to `a` instead. This change only affects simple pattern bindings (decorated variables: type signatures, parens, ~ annotations and ! annotations). - - - - - 309f8cfd by Richard Eisenberg at 2020-02-08T10:16:33-05:00 Remove unnecessary parentheses - - - - - 7755ffc2 by Richard Eisenberg at 2020-02-08T10:16:33-05:00 Introduce IsPass; refactor wrappers. There are two main payloads of this patch: 1. This introduces IsPass, which allows e.g. printing code to ask what pass it is running in (Renamed vs Typechecked) and thus print extension fields. See Note [IsPass] in Hs.Extension 2. This moves the HsWrap constructor into an extension field, where it rightly belongs. This is done for HsExpr and HsCmd, but not for HsPat, which is left as an exercise for the reader. There is also some refactoring around SyntaxExprs, but this is really just incidental. This patch subsumes !1721 (sorry @chreekat). Along the way, there is a bit of refactoring in GHC.Hs.Extension, including the removal of NameOrRdrName in favor of NoGhcTc. This meant that we had no real need for GHC.Hs.PlaceHolder, so I got rid of it. Updates haddock submodule. ------------------------- Metric Decrease: haddock.compiler ------------------------- - - - - - 7d452be4 by Dylan Yudaken at 2020-02-08T10:17:17-05:00 Fix hs_try_putmvar losing track of running cap If hs_try_putmvar was called through an unsafe import, it would lose track of the running cap causing a deadlock - - - - - c2e301ae by Ben Gamari at 2020-02-08T10:17:55-05:00 compiler: Qualify imports of Data.List - - - - - aede171a by Ben Gamari at 2020-02-08T10:17:55-05:00 testsuite: Fix -Wcompat-unqualified-imports issues - - - - - 4435a8e0 by Ben Gamari at 2020-02-08T10:17:55-05:00 Introduce -Wcompat-unqualified-imports This implements the warning proposed in option (B) of the Data.List.singleton CLC [discussion][]. This warning, which is included in `-Wcompat` is intended to help users identify imports of modules that will change incompatibly in future GHC releases. This currently only includes `Data.List` due to the expected specialisation and addition of `Data.List.singleton`. Fixes #17244. [discussion]: https://groups.google.com/d/msg/haskell-core-libraries/q3zHLmzBa5E/PmlAs_kYAQAJ - - - - - 28b5349a by Ben Gamari at 2020-02-08T10:17:55-05:00 Bump stm and process submodules - - - - - 7d04b9f2 by Ben Gamari at 2020-02-08T10:18:31-05:00 hadrian: Allow override of Cabal configuration in hadrian.settings Fixes #17612 by adding a `cabal.configure.opts` key for `hadrian.settings`. - - - - - 88bf81aa by Andreas Klebinger at 2020-02-08T10:19:10-05:00 Optimize unpackCString# to allocate less. unpackCString# is a recursive function which for each iteration returns a Cons cell containing the current Char, and a thunk for unpacking the rest of the string. In this patch we change from storing addr + offset inside this thunk to storing only the addr, simply incrementing the address on each iteration. This saves one word of allocation per unpacked character. For a program like "main = print "<largishString>" this amounts to 2-3% fewer % in bytes allocated. I also removed the now redundant local unpack definitions. This removes one call per unpack operation. - - - - - bec76733 by Ben Gamari at 2020-02-08T10:19:57-05:00 Fix GhcThreaded setting This adopts a patch from NetBSD's packaging fixing the `GhcThreaded` option of the make build system. In addition we introduce a `ghcThreaded` option in hadrian's `Flavour` type. Also fix Hadrian's treatment of the `Use Threaded` entry in `settings`. Previously it would incorrectly claim `Use Threaded = True` if we were building the `threaded` runtime way. However, this is inconsistent with the `make` build system, which defines it to be whether the `ghc` executable is linked against the threaded runtime. Fixes #17692. - - - - - 545cf1e1 by Ben Gamari at 2020-02-08T10:20:37-05:00 hadrian: Depend upon libray dependencies when configuring packages This will hopefully fix #17631. - - - - - 047d3d75 by Ben Gamari at 2020-02-08T10:21:16-05:00 testsuite: Add test for #15316 This is the full testcase for T15316. - - - - - 768e5866 by Julien Debon at 2020-02-08T10:22:07-05:00 doc(Data.List): Add some examples to Data.List - - - - - 3900cb83 by Julien Debon at 2020-02-08T10:22:07-05:00 Apply suggestion to libraries/base/GHC/List.hs - - - - - bd666766 by Ben Gamari at 2020-02-08T10:22:45-05:00 users-guide: Clarify that bundled patsyns were introduced in GHC 8.0 Closes #17094. - - - - - 95741ea1 by Pepe Iborra at 2020-02-08T10:23:23-05:00 Update to hie-bios 0.3.2 style program cradle - - - - - fb5c1912 by Sylvain Henry at 2020-02-08T10:24:07-05:00 Remove redundant case This alternative is redundant and triggers no warning when building with 8.6.5 - - - - - 5d83d948 by Matthew Pickering at 2020-02-08T10:24:43-05:00 Add mkHieFileWithSource which doesn't read the source file from disk cc/ @pepeiborra - - - - - dfdae56d by Andreas Klebinger at 2020-02-08T10:25:20-05:00 Rename ghcAssert to stgAssert in hp2ps/Main.h. This fixes #17763 - - - - - 658f7ac6 by Ben Gamari at 2020-02-08T10:26:00-05:00 includes: Avoid using single-line comments in HsFFI.h While single-line comments are supported by C99, dtrace on SmartOS apparently doesn't support them yet. - - - - - c95920a6 by Ömer Sinan Ağacan at 2020-02-08T10:26:42-05:00 Import qualified Prelude in parser This is in preparation of backwards-incompatible changes in happy. See https://github.com/simonmar/happy/issues/166 - - - - - b6dc319a by Ömer Sinan Ağacan at 2020-02-08T10:27:23-05:00 Add regression test for #12760 The bug seems to be fixed in the meantime, make sure it stays fixed. Closes #12760 - - - - - b3857b62 by Ben Gamari at 2020-02-08T10:28:03-05:00 base: Drop out-of-date comment The comment in GHC.Base claimed that ($) couldn't be used in that module as it was wired-in. However, this is no longer true; ($) is merely known key and is defined in Haskell (with a RuntimeRep-polymorphic type) in GHC.Base. The one piece of magic that ($) retains is that it a special typing rule to allow type inference with higher-rank types (e.g. `runST $ blah`; see Note [Typing rule for ($)] in TcExpr). - - - - - 1183ae94 by Daniel Gröber at 2020-02-08T10:29:00-05:00 rts: Fix Arena blocks accounting for MBlock sized allocations When requesting more than BLOCKS_PER_MBLOCK blocks allocGroup can return a different number of blocks than requested. Here we use the number of requested blocks, however arenaFree will subtract the actual number of blocks we got from arena_blocks (possibly) resulting in a negative value and triggering ASSERT(arena_blocks >= 0). - - - - - 97d59db5 by Daniel Gröber at 2020-02-08T10:29:48-05:00 rts: Fix need_prealloc being reset when retainer profiling is on - - - - - 1f630025 by Krzysztof Gogolewski at 2020-02-09T02:52:27-05:00 Add a test for #15712 - - - - - 2ac784ab by Ben Gamari at 2020-02-09T02:53:05-05:00 hadrian: Add --test-metrics argument Allowing the test metric output to be captured to a file, a la the METRIC_FILE environment variable of the make build system. - - - - - f432d8c6 by Ben Gamari at 2020-02-09T02:53:05-05:00 hadrian: Fix --test-summary argument This appears to be a cut-and-paste error. - - - - - a906595f by Arnaud Spiwack at 2020-02-09T02:53:50-05:00 Fix an outdated note link This link appears to have been forgotten in 0dad81ca5fd1f63bf8a3b6ad09787559e8bd05c0 . - - - - - 3ae83da1 by Alp Mestanogullari at 2020-02-09T02:54:28-05:00 hadrian: Windows fixes (bindists, CI) This commit implements a few Windows-specific fixes which get us from a CI job that can't even get as far as starting the testsuite driver, to a state where we can run the entire testssuite (but have test failures to fix). - Don't forget about a potential extension for the haddock program, when preparing the bindist. - Build the timeout program, used by the testsuite driver on Windows in place of the Python script used elsewhere, using the boot compiler. We could alternatively build it with the compiler that we're going to test but this would be a lot more tedious to write. - Implement a wrapper-script less installation procedure for Windows, in `hadrian/bindist/Makefile. - Make dependencies a bit more accurate in the aforementioned Makefile. - Update Windows/Hadrian CI job accordingly. This patch fixes #17486. - - - - - 82f9be8c by Roland Senn at 2020-02-09T02:55:06-05:00 Fix #14628: Panic (No skolem Info) in GHCi This patch implements the [sugggestion from Simon (PJ)](https://gitlab.haskell.org/ghc/ghc/issues/14628#note_146559): - Make `TcErrors.getSkolemInfo` return a `SkolemInfo` rather than an `Implication`. - If `getSkolemInfo` gets `RuntimeUnk`s, just return a new data constructor in `SkolemInfo`, called `RuntimeUnkSkol`. - In `TcErrors.pprSkols` print something sensible for a `RuntimeUnkSkol`. The `getSkolemInfo` function paniced while formating suggestions to add type annotations (subfunction `suggestAddSig`) to a *"Couldn't match type ‘x’ with ‘y’"* error message. The `getSkolemInfo` function didn't find any Implication value and paniced. With this patch the `getSkolemInfo` function does no longer panic, if it finds `RuntimeUnkSkol`s. As the panic occured while processing an error message, we don't need to implement any new error message! - - - - - b2e18e26 by Andreas Klebinger at 2020-02-09T02:55:46-05:00 Fix -ddump-stg-final. Once again make sure this dumps the STG used for codegen. - - - - - 414e2f62 by Sylvain Henry at 2020-02-09T02:56:26-05:00 Force -fPIC for intree GMP (fix #17799) Configure intree GMP with `--with-pic` instead of patching it. Moreover the correct patching was only done for x86_64/darwin (see #17799). - - - - - f0fd72ee by Sebastian Graf at 2020-02-09T17:22:38-05:00 8.10 Release notes for improvements to the pattern-match checker [skip ci] A little late to the game, but better late than never. - - - - - 00dc0f7e by Ömer Sinan Ağacan at 2020-02-09T17:23:17-05:00 Add regression test for #13142 Closes #13142 - - - - - f3e737bb by Sebastian Graf at 2020-02-10T20:04:09-05:00 Fix long distance info for record updates For record updates where the `record_expr` is a variable, as in #17783: ```hs data PartialRec = No | Yes { a :: Int, b :: Bool } update No = No update r@(Yes {}) = r { b = False } ``` We should make use of long distance info in `-Wincomplete-record-updates` checking. But the call to `matchWrapper` in the `RecUpd` case didn't specify a scrutinee expression, which would correspond to the `record_expr` `r` here. That is fixed now. Fixes #17783. - - - - - 5670881d by Tamar Christina at 2020-02-10T20:05:04-05:00 Fs: Fix UNC remapping code. - - - - - 375b3c45 by Oleg Grenrus at 2020-02-11T05:07:30-05:00 Add singleton to Data.OldList - - - - - de32beff by Richard Eisenberg at 2020-02-11T05:08:10-05:00 Do not create nested quantified constraints Previously, we would accidentally make constraints like forall a. C a => forall b. D b => E a b c as we traversed superclasses. No longer! This patch also expands Note [Eagerly expand given superclasses] to work over quantified constraints; necessary for T16502b. Close #17202 and #16502. test cases: typecheck/should_compile/T{17202,16502{,b}} - - - - - e319570e by Ben Gamari at 2020-02-11T05:08:47-05:00 rts: Use nanosleep instead of usleep usleep was removed in POSIX.1-2008. - - - - - b75e7486 by Ben Gamari at 2020-02-11T05:09:24-05:00 rts: Remove incorrect assertions around MSG_THROWTO messages Previously we would assert that threads which are sending a `MSG_THROWTO` message must have their blocking status be blocked on the message. In the usual case of a thread throwing to another thread this is guaranteed by `stg_killThreadzh`. However, `throwToSelf`, used by the GC to kill threads which ran out of heap, failed to guarantee this. Noted while debugging #17785. - - - - - aba51b65 by Sylvain Henry at 2020-02-11T05:10:04-05:00 Add arithmetic exception primops (#14664) - - - - - b157399f by Ben Gamari at 2020-02-11T05:10:40-05:00 configure: Don't assume Gnu linker on Solaris Compl Yue noticed that the linker was dumping the link map on SmartOS. This is because Smartos uses the Solaris linker, which uses the `-64` flag, not `-m64` like Gnu ld, to indicate that it should link for 64-bits. Fix the configure script to handle the Solaris linker correctly. - - - - - d8d73d77 by Simon Peyton Jones at 2020-02-11T05:11:18-05:00 Notes only: telescopes This documentation-only patch fixes #17793 - - - - - 58a4ddef by Alp Mestanogullari at 2020-02-11T05:12:17-05:00 hadrian: build (and ship) iserv on Windows - - - - - 82023524 by Matthew Pickering at 2020-02-11T18:04:17-05:00 TemplateHaskellQuotes: Allow nested splices There is no issue with nested splices as they do not require any compile time code execution. All execution is delayed until the top-level splice. - - - - - 50e24edd by Ömer Sinan Ağacan at 2020-02-11T18:04:57-05:00 Remove Hadrian's copy of (Data.Functor.<&>) The function was added to base with base-4.11 (GHC 8.4) - - - - - f82a2f90 by Sylvain Henry at 2020-02-12T01:56:46-05:00 Document GMP build [skip ci] - - - - - da7f7479 by Sylvain Henry at 2020-02-12T01:57:27-05:00 Module hierarchy: ByteCode and Runtime (cf #13009) Update haddock submodule - - - - - 04f51297 by Ömer Sinan Ağacan at 2020-02-12T01:58:11-05:00 Fix naming of tests for #12923 - - - - - 31fc3321 by Ömer Sinan Ağacan at 2020-02-12T01:58:11-05:00 Add regression test for #12926 Closes #12926 - - - - - f0c0ee7d by Krzysztof Gogolewski at 2020-02-12T01:58:51-05:00 Fix order of arguments in specializer (#17801) See https://gitlab.haskell.org/ghc/ghc/issues/17801#note_253330 No regression test, as it's hard to trigger. - - - - - 059c3c9d by Sebastian Graf at 2020-02-12T11:00:58+01:00 Separate CPR analysis from the Demand analyser The reasons for that can be found in the wiki: https://gitlab.haskell.org/ghc/ghc/wikis/nested-cpr/split-off-cpr We now run CPR after demand analysis (except for after the final demand analysis run just before code gen). CPR got its own dump flags (`-ddump-cpr-anal`, `-ddump-cpr-signatures`), but not its own flag to activate/deactivate. It will run with `-fstrictness`/`-fworker-wrapper`. As explained on the wiki page, this step is necessary for a sane Nested CPR analysis. And it has quite positive impact on compiler performance: Metric Decrease: T9233 T9675 T9961 T15263 - - - - - f5ffd8d9 by Ben Gamari at 2020-02-12T17:22:37-05:00 base: Expose GHC.Unicode.unicodeVersion This exposes a Data.Version.Version representing the version of the Unicode database used by `base`. This should clear up some confusion I have seen in tickets regarding with which Unicode versions a given GHC can be expected to work. While in town I also regenerated (but did not update) the Unicode database with database 12.0.0. Strangely, the file cited in the README no longer existed. Consequently, I used https://www.unicode.org/Public/12.0.0/ucd/UnicodeData.txt and was slightly surprised to find that there were a few changes. - - - - - 6c2585e0 by Ben Gamari at 2020-02-12T17:22:37-05:00 base: Update Unicode database to 12.1.0 Using `curl https://www.unicode.org/Public/12.1.0/ucd/UnicodeData.txt | libraries/base/cbits/ubconfc 12.1.0`. - - - - - df084681 by Krzysztof Gogolewski at 2020-02-12T23:58:52+01:00 Always display inferred variables using braces We now always show "forall {a}. T" for inferred variables, previously this was controlled by -fprint-explicit-foralls. This implements part 1 of https://github.com/ghc-proposals/ghc-proposals/pull/179. Part of GHC ticket #16320. Furthermore, when printing a levity restriction error, we now display the HsWrap of the expression. This lets users see the full elaboration with -fprint-typechecker-elaboration (see also #17670) - - - - - 16d643cf by Sylvain Henry at 2020-02-13T09:16:04-05:00 Remove -ddump-srts flag This flag is deemed not useful. - - - - - fa28ae95 by Sylvain Henry at 2020-02-13T09:16:04-05:00 Fix flag documentation (#17826) - - - - - 1bfd8259 by Sylvain Henry at 2020-02-13T09:16:43-05:00 Ensure that Hadrian is built correctly before using it When Hadrian failed to build, the script would pick a previously built Hadrian (if available) instead of failing. - - - - - cd6e786a by Ömer Sinan Ağacan at 2020-02-14T05:29:56-05:00 Add test for #17648 - - - - - 9f2c3677 by Sylvain Henry at 2020-02-14T05:30:39-05:00 GMP expects the Target platform as --host parameter - - - - - aa6086fd by Oleg Grenrus at 2020-02-14T05:31:16-05:00 Add explicit LANGUAGE Safe to template-haskell (cherry picked from commit a5e0f376821ca882880b03b07b451aa574e289ec) - - - - - af6a0c36 by Ben Gamari at 2020-02-14T05:31:53-05:00 hadrian: Add execution and target architecture to stage-compilation figure - - - - - cf739945 by Sylvain Henry at 2020-02-14T05:32:37-05:00 Module hierarchy: HsToCore (cf #13009) - - - - - 719db318 by Simon Peyton Jones at 2020-02-14T05:33:16-05:00 De-duplicate overlapping Notes Documentation only. Fixes #17827 - - - - - 7550417a by Sylvain Henry at 2020-02-14T05:33:56-05:00 Hadrian: drop Sphinx flag checking for PDF documentation (#17825) It seems that Sphinx produces the ghc-flags.txt in doc/users_guide/_build rather than pdfRoot. We could copy ghc-flags.txt into pdfRoot (like happens naturally in the HTML case) but the benefit is pretty small. Let's just only check the HTML case. - - - - - 813842f4 by Ben Gamari at 2020-02-14T10:16:36-05:00 make: Be more selective in building windows-extra-src tarball - - - - - 0725f4bb by Ben Gamari at 2020-02-14T10:16:36-05:00 Rework handling of win32 toolchain tarballs - - - - - 565ce7ae by Ben Gamari at 2020-02-14T10:16:36-05:00 gitlab-ci: Consolidate CI logic This moves nearly all of the CI logic to .gitlab/ci.sh. This improves things in a number of ways: * it's harder for inconsistencies to arise between architectures * it's easier to share logic between architectures * on Windows, it's easier to ensure that all CI steps are executed from within a properly initialized mingw session. While in town I also add a FreeBSD build job and update the Windows job to use the gitlab-runner PowerShell executor, since cmd.exe will be deprecated soon (fixing #17699). - - - - - 9cbace74 by Ben Gamari at 2020-02-14T10:16:36-05:00 gitlab-ci: Deduplicate nightly job configuration - - - - - 6e837144 by Ben Gamari at 2020-02-14T10:16:36-05:00 integer-gmp: Fix unused command-line argument -L is only needed during linking. - - - - - e5ee07ab by Ben Gamari at 2020-02-14T10:16:36-05:00 testsuite: Don't ask sed to operate in-place on symlinks Some sed implementations (e.g. FreeBSD) refuse to operate in-place on symlinks. - - - - - 71e5e68f by Ben Gamari at 2020-02-14T10:16:36-05:00 testsuite: Disable tests that assume name of libstdc++ on FreeBSD - - - - - 7b2da0f4 by Ben Gamari at 2020-02-14T10:16:36-05:00 testsuite: Mark T6132 as broken on FreeBSD - - - - - 8ef7a15a by Ben Gamari at 2020-02-14T10:16:36-05:00 testsuite/T16930: Don't rely on gnu grep specific --include In BSD grep this flag only affects directory recursion. - - - - - 6060003e by Ben Gamari at 2020-02-14T10:16:36-05:00 Pass -Wno-unused-command-line-arguments during link on FreeBSD FreeBSD cc throws a warning if we pass -pthread without actually using any pthread symbols. - - - - - 97497bae by Ben Gamari at 2020-02-14T10:16:36-05:00 base: Always clamp reads/writes to 2GB in length Previously we did this only on Darwin due to #17414. However, even on other platforms >2GB writes are on shaky ground. POSIX explicitly says that the result is implementation-specified and Linux will write at most 0x7ffff000, even on 64-bit platforms. Moreover, getting the sign of the syscall result correct is tricky, as demonstrated by the fact that T17414 currently fails on FreeBSD. For simplicity we now just uniformly clamp to 0x7ffff000 on all platforms. - - - - - 49be2a3f by Ben Gamari at 2020-02-14T10:16:36-05:00 configure: Fix sphinx version test The check for the "v" prefix is redundant. - - - - - f7f7a556 by Ben Gamari at 2020-02-14T10:16:37-05:00 users-guide: Fix unknown link targets - - - - - a204102c by Ben Gamari at 2020-02-14T10:16:37-05:00 docs/compare-flags: Don't use python f-strings - - - - - 92e15a37 by Ben Gamari at 2020-02-14T10:16:37-05:00 gitlab-ci: Fix various shellcheck warnings - - - - - 459f7c6e by Ben Gamari at 2020-02-14T10:16:37-05:00 hadrian: Drop empty arguments from target list Fixes #17748. - - - - - c06df28d by Ben Gamari at 2020-02-14T10:16:37-05:00 users-guide: Fix "invalid file" failure I have no idea how this worked previously. Different Python version? - - - - - 3fe8444f by Ben Gamari at 2020-02-14T10:16:59-05:00 testsuite: Mark T7702 as fragile on Windows Due to #16799. There was previously an attempt to mark it as broken but the `opsys` name was incorrect. - - - - - fe02f781 by Ben Gamari at 2020-02-14T10:16:59-05:00 testsuite: Assert the opsys names are known Previously opsys would take any string. This meant it was very easy for a typo to silently render the predicate ineffective. Fix this by checking the given operating system name against a list of known values. - - - - - 149e2a3a by Ben Gamari at 2020-02-14T10:16:59-05:00 compare-flags: Don't rely on encoding flag of subprocess.check_output Apparently it isn't supported by some slightly older Python versions. - - - - - 798d59f6 by Ben Gamari at 2020-02-14T10:16:59-05:00 rts: Add more debug output to failed path in onIOComplete This will help track down #17035. - - - - - e35f3f98 by Ben Gamari at 2020-02-14T10:16:59-05:00 gitlab-ci: Allow i386 Windows builds to fail again Due to the resistance of #17736 to resolution. - - - - - 261a3cf8 by Ben Gamari at 2020-02-14T10:17:00-05:00 gitlab-ci: Build integer-simple job in the validate flavour - - - - - b613a961 by Ben Gamari at 2020-02-14T10:17:00-05:00 gitlab-ci: Always use mingw64 python on Windows - - - - - 1bc8c8cd by Ben Gamari at 2020-02-14T10:17:00-05:00 gitlab-ci: Allow Windows build to fail due to #17777 The fact that `exec` isn't POSIX compliant means that things can break in arbitrarily bad ways. Sometimes things happen to work correctly but sadly this isn't always the case. - - - - - ac63020d by Ben Gamari at 2020-02-14T10:17:00-05:00 gitlab-ci: Drop unnecessary GHC_VERSION check - - - - - 6926f369 by Ben Gamari at 2020-02-14T10:17:00-05:00 Bump process submodule Folds in the second part of Phyx's Windows process exit fixes [1], hopefully finally resolving issue #17480. [1] https://github.com/haskell/process/pull/160 - - - - - 584eee71 by Tamar Christina at 2020-02-14T10:17:00-05:00 SysTools: Use "process job" when spawning processes on Windows GHC should make calls using process jobs when calling out to GCC and LD. The reason is these use the exec () family of posix functions. Window's process model doesn't allow replacement of processes so this is emulated by creating a new process and immediately exiting the old one. Because of this when using normal Windows wait functions you would return even without the child process having finished. In this case if you are depending on data from the child you will enter a race condition. The usual fix for this is to use process jobs and wait for the termination of all children that have ever been spawn by the process you called. But also waiting for the freeing of all resources. - - - - - ecabfa28 by Tamar Christina at 2020-02-14T10:17:00-05:00 Revert "compiler: Disable atomic renaming on Windows" The original reason this was disabled should be fixed by the previous commit. This reverts commit 1c1b63d63efe8b0f789aa7d5b87cfac3edd213eb. - - - - - 06d60c66 by Ben Gamari at 2020-02-14T10:17:00-05:00 Bump Cabal submodule - - - - - 8cabb384 by Ben Gamari at 2020-02-14T10:17:00-05:00 compare-flags: Fix output - - - - - 8cf646d3 by Ben Gamari at 2020-02-14T10:17:00-05:00 users-guide: Document -ddump-srts - - - - - 932307a5 by Ben Gamari at 2020-02-14T10:17:00-05:00 users-guide: Fix broken reference - - - - - e77818de by Ben Gamari at 2020-02-15T09:26:55-05:00 Accept performance changes These manifested in the integer-simple job. Metric Decrease: T12227 T5549 T14936 T4830 Conversions T5237 T8766 T4801 T10359 Metric Increase: T12234 T6048 T3294 T14683 T3064 T9872b T9872c T783 T5837 T10678 T14697 T5631 T9203 T13719 T12707 T13056 T9630 T10547 T9872d T1969 WWRec T10370 T5321FD haddock.Cabal T5642 T9872a T15263 T12425 MultiLayerModules T5205 T9233 T13379 haddock.base T9020 T13035 T12150 T9961 - - - - - 785008c1 by Ben Gamari at 2020-02-15T09:30:13-05:00 testsuite: Sort test names in expected change output - - - - - 9e851472 by Ömer Sinan Ağacan at 2020-02-16T10:38:41+03:00 Revert "users-guide: Document -ddump-srts" This reverts commit 8cf646d36b02b8ea1c289cb52781c9171853b514. The flag was removed by 16d643cf. [ci skip] - - - - - 9792c816 by Ben Gamari at 2020-02-16T09:47:08-05:00 testsuite: Probe whether symlinks are usable on Windows Closes #17706. - - - - - ee1e5342 by Vladislav Zavialov at 2020-02-16T09:47:44-05:00 Fix the "unused terminals: 2" warning in Parser.y - - - - - b4a8ce52 by Roland Senn at 2020-02-18T20:14:42-05:00 If a :reload finds syntax errors in the module graph, remove the loaded modules. (Fixes #17549) The processing in `compiler/main/GhcMake.hs` computes the ModuleGraph. If it finds errors in the module header or in the import specifications, then the new module graph is incomplete and should not be used. The code before #17549 just reported the errors and left the old ModuleGraph in place. The new code of this MR replaces the old ModuleGraph with an empty one. - - - - - d7029cc0 by Sylvain Henry at 2020-02-18T20:15:30-05:00 Hadrian: refactor GMP in-tree build support (#17756) * Hadrian doesn't use integer-gmp/config.mk file anymore to determine if building GMP in-tree is required. "config.mk" is created by Cabal when the integer-gmp package is configured and this file is still untracked by Hadrian. This led to a tricky configure "race" because "config.mk" is built by the "setup-config" rule, but this rule is also used to find dependencies, in particular the "ghc-gmp.h" header, but the creation of this file was depending (without being tracked) on "config.mk". Now Hadrian only builds in-tree GMP if `--with-intree-gmp` is passed to the top-level configure script. * in-tree GMP isn't built once for all in a fixed stage (Stage1) anymore. It is built per stage which is required if we build a cross-compiler * switching between in-tree and external GMP is now supported without having to clean the build directory first. * "wrappers.c" now includes "ghc-gmp.h" instead of "ghc.h". It helps ensuring that the build system generates "ghc-gmp.h". * build in-tree GMP in "<root>/stageN/gmp/gmpbuild" and produce useful artefacts (libgmp.a, gmp.h, objs/*.o) in "<root>/stageN/gmp" - - - - - 40d917fb by Vladislav Zavialov at 2020-02-18T20:16:07-05:00 Remove the MonadFail P instance There were two issues with this instance: * its existence meant that a pattern match failure in the P monad would produce a user-visible parse error, but the error message would not be helpful to the user * due to the MFP migration strategy, we had to use CPP in Lexer.x, and that created issues for #17750 Updates haddock submodule. - - - - - 5a1ce45d by Joshua Price at 2020-02-18T20:16:47-05:00 Fix unboxed tuple size limit (#17837) - - - - - 192caf58 by Vladislav Zavialov at 2020-02-18T20:17:24-05:00 Fix testsuite driver output (#17847) - - - - - 1500f089 by Sylvain Henry at 2020-02-18T20:18:12-05:00 Modules: Llvm (#13009) - - - - - d53e81c0 by Niklas Hambüchen at 2020-02-20T10:36:22-05:00 8.10 Release notes for atomic .o writes [skip ci] - - - - - 19680ee5 by Niklas Hambüchen at 2020-02-20T10:37:53-05:00 8.10 Release notes for --disable-delayed-os-memory-return [skip ci] - - - - - 74ad75e8 by Simon Peyton Jones at 2020-02-20T21:17:57-05:00 Re-implement unsafe coercions in terms of unsafe equality proofs (Commit message written by Omer, most of the code is written by Simon and Richard) See Note [Implementing unsafeCoerce] for how unsafe equality proofs and the new unsafeCoerce# are implemented. New notes added: - [Checking for levity polymorphism] in CoreLint.hs - [Implementing unsafeCoerce] in base/Unsafe/Coerce.hs - [Patching magic definitions] in Desugar.hs - [Wiring in unsafeCoerce#] in Desugar.hs Only breaking change in this patch is unsafeCoerce# is not exported from GHC.Exts, instead of GHC.Prim. Fixes #17443 Fixes #16893 NoFib ----- -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS -0.1% 0.0% -0.0% -0.0% -0.0% CSD -0.1% 0.0% -0.0% -0.0% -0.0% FS -0.1% 0.0% -0.0% -0.0% -0.0% S -0.1% 0.0% -0.0% -0.0% -0.0% VS -0.1% 0.0% -0.0% -0.0% -0.0% VSD -0.1% 0.0% -0.0% -0.0% -0.1% VSM -0.1% 0.0% -0.0% -0.0% -0.0% anna -0.0% 0.0% -0.0% -0.0% -0.0% ansi -0.1% 0.0% -0.0% -0.0% -0.0% atom -0.1% 0.0% -0.0% -0.0% -0.0% awards -0.1% 0.0% -0.0% -0.0% -0.0% banner -0.1% 0.0% -0.0% -0.0% -0.0% bernouilli -0.1% 0.0% -0.0% -0.0% -0.0% binary-trees -0.1% 0.0% -0.0% -0.0% -0.0% boyer -0.1% 0.0% -0.0% -0.0% -0.0% boyer2 -0.1% 0.0% -0.0% -0.0% -0.0% bspt -0.1% 0.0% -0.0% -0.0% -0.0% cacheprof -0.1% 0.0% -0.0% -0.0% -0.0% calendar -0.1% 0.0% -0.0% -0.0% -0.0% cichelli -0.1% 0.0% -0.0% -0.0% -0.0% circsim -0.1% 0.0% -0.0% -0.0% -0.0% clausify -0.1% 0.0% -0.0% -0.0% -0.0% comp_lab_zift -0.1% 0.0% -0.0% -0.0% -0.0% compress -0.1% 0.0% -0.0% -0.0% -0.0% compress2 -0.1% 0.0% -0.0% -0.0% -0.0% constraints -0.1% 0.0% -0.0% -0.0% -0.0% cryptarithm1 -0.1% 0.0% -0.0% -0.0% -0.0% cryptarithm2 -0.1% 0.0% -0.0% -0.0% -0.0% cse -0.1% 0.0% -0.0% -0.0% -0.0% digits-of-e1 -0.1% 0.0% -0.0% -0.0% -0.0% digits-of-e2 -0.1% 0.0% -0.0% -0.0% -0.0% dom-lt -0.1% 0.0% -0.0% -0.0% -0.0% eliza -0.1% 0.0% -0.0% -0.0% -0.0% event -0.1% 0.0% -0.0% -0.0% -0.0% exact-reals -0.1% 0.0% -0.0% -0.0% -0.0% exp3_8 -0.1% 0.0% -0.0% -0.0% -0.0% expert -0.1% 0.0% -0.0% -0.0% -0.0% fannkuch-redux -0.1% 0.0% -0.0% -0.0% -0.0% fasta -0.1% 0.0% -0.5% -0.3% -0.4% fem -0.1% 0.0% -0.0% -0.0% -0.0% fft -0.1% 0.0% -0.0% -0.0% -0.0% fft2 -0.1% 0.0% -0.0% -0.0% -0.0% fibheaps -0.1% 0.0% -0.0% -0.0% -0.0% fish -0.1% 0.0% -0.0% -0.0% -0.0% fluid -0.1% 0.0% -0.0% -0.0% -0.0% fulsom -0.1% 0.0% +0.0% +0.0% +0.0% gamteb -0.1% 0.0% -0.0% -0.0% -0.0% gcd -0.1% 0.0% -0.0% -0.0% -0.0% gen_regexps -0.1% 0.0% -0.0% -0.0% -0.0% genfft -0.1% 0.0% -0.0% -0.0% -0.0% gg -0.1% 0.0% -0.0% -0.0% -0.0% grep -0.1% 0.0% -0.0% -0.0% -0.0% hidden -0.1% 0.0% -0.0% -0.0% -0.0% hpg -0.1% 0.0% -0.0% -0.0% -0.0% ida -0.1% 0.0% -0.0% -0.0% -0.0% infer -0.1% 0.0% -0.0% -0.0% -0.0% integer -0.1% 0.0% -0.0% -0.0% -0.0% integrate -0.1% 0.0% -0.0% -0.0% -0.0% k-nucleotide -0.1% 0.0% -0.0% -0.0% -0.0% kahan -0.1% 0.0% -0.0% -0.0% -0.0% knights -0.1% 0.0% -0.0% -0.0% -0.0% lambda -0.1% 0.0% -0.0% -0.0% -0.0% last-piece -0.1% 0.0% -0.0% -0.0% -0.0% lcss -0.1% 0.0% -0.0% -0.0% -0.0% life -0.1% 0.0% -0.0% -0.0% -0.0% lift -0.1% 0.0% -0.0% -0.0% -0.0% linear -0.1% 0.0% -0.0% -0.0% -0.0% listcompr -0.1% 0.0% -0.0% -0.0% -0.0% listcopy -0.1% 0.0% -0.0% -0.0% -0.0% maillist -0.1% 0.0% -0.0% -0.0% -0.0% mandel -0.1% 0.0% -0.0% -0.0% -0.0% mandel2 -0.1% 0.0% -0.0% -0.0% -0.0% mate -0.1% 0.0% -0.0% -0.0% -0.0% minimax -0.1% 0.0% -0.0% -0.0% -0.0% mkhprog -0.1% 0.0% -0.0% -0.0% -0.0% multiplier -0.1% 0.0% -0.0% -0.0% -0.0% n-body -0.1% 0.0% -0.0% -0.0% -0.0% nucleic2 -0.1% 0.0% -0.0% -0.0% -0.0% para -0.1% 0.0% -0.0% -0.0% -0.0% paraffins -0.1% 0.0% -0.0% -0.0% -0.0% parser -0.1% 0.0% -0.0% -0.0% -0.0% parstof -0.1% 0.0% -0.0% -0.0% -0.0% pic -0.1% 0.0% -0.0% -0.0% -0.0% pidigits -0.1% 0.0% -0.0% -0.0% -0.0% power -0.1% 0.0% -0.0% -0.0% -0.0% pretty -0.1% 0.0% -0.1% -0.1% -0.1% primes -0.1% 0.0% -0.0% -0.0% -0.0% primetest -0.1% 0.0% -0.0% -0.0% -0.0% prolog -0.1% 0.0% -0.0% -0.0% -0.0% puzzle -0.1% 0.0% -0.0% -0.0% -0.0% queens -0.1% 0.0% -0.0% -0.0% -0.0% reptile -0.1% 0.0% -0.0% -0.0% -0.0% reverse-complem -0.1% 0.0% -0.0% -0.0% -0.0% rewrite -0.1% 0.0% -0.0% -0.0% -0.0% rfib -0.1% 0.0% -0.0% -0.0% -0.0% rsa -0.1% 0.0% -0.0% -0.0% -0.0% scc -0.1% 0.0% -0.1% -0.1% -0.1% sched -0.1% 0.0% -0.0% -0.0% -0.0% scs -0.1% 0.0% -0.0% -0.0% -0.0% simple -0.1% 0.0% -0.0% -0.0% -0.0% solid -0.1% 0.0% -0.0% -0.0% -0.0% sorting -0.1% 0.0% -0.0% -0.0% -0.0% spectral-norm -0.1% 0.0% -0.0% -0.0% -0.0% sphere -0.1% 0.0% -0.0% -0.0% -0.0% symalg -0.1% 0.0% -0.0% -0.0% -0.0% tak -0.1% 0.0% -0.0% -0.0% -0.0% transform -0.1% 0.0% -0.0% -0.0% -0.0% treejoin -0.1% 0.0% -0.0% -0.0% -0.0% typecheck -0.1% 0.0% -0.0% -0.0% -0.0% veritas -0.0% 0.0% -0.0% -0.0% -0.0% wang -0.1% 0.0% -0.0% -0.0% -0.0% wave4main -0.1% 0.0% -0.0% -0.0% -0.0% wheel-sieve1 -0.1% 0.0% -0.0% -0.0% -0.0% wheel-sieve2 -0.1% 0.0% -0.0% -0.0% -0.0% x2n1 -0.1% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min -0.1% 0.0% -0.5% -0.3% -0.4% Max -0.0% 0.0% +0.0% +0.0% +0.0% Geometric Mean -0.1% -0.0% -0.0% -0.0% -0.0% Test changes ------------ - break006 is marked as broken, see #17833 - The compiler allocates less when building T14683 (an unsafeCoerce#- heavy happy-generated code) on 64-platforms. Allocates more on 32-bit platforms. - Rest of the increases are tiny amounts (still enough to pass the threshold) in micro-benchmarks. I briefly looked at each one in a profiling build: most of the increased allocations seem to be because of random changes in the generated code. Metric Decrease: T14683 Metric Increase: T12150 T12234 T12425 T13035 T14683 T5837 T6048 Co-Authored-By: Richard Eisenberg <rae at cs.brynmawr.edu> Co-Authored-By: Ömer Sinan Ağacan <omeragacan at gmail.com> - - - - - 6880d6aa by Sylvain Henry at 2020-02-20T21:18:48-05:00 Disentangle DynFlags and SDoc Remove several uses of `sdocWithDynFlags`. The remaining ones are mostly CodeGen related (e.g. depend on target platform constants) and will be fixed separately. Metric Decrease: T12425 T9961 WWRec T1969 T14683 - - - - - 70a90110 by Julien Debon at 2020-02-20T21:19:27-05:00 doc(List): Add examples to GHC.List * Add examples * Cleanup documentation * Clarify merge process and Marge bot - - - - - c8439fc7 by Peter Trommler at 2020-02-20T21:20:05-05:00 Fix testsuite on powerpc64le Remove expect broken on recomp tests, #11260 was closed by !2264 and #11323 most likely by !2264 as well. GHCi scripts tests work on GHCi but not the external interpreter, adjust test configuration accordingly. Fixes unexpected passes. Mark test requiring DWARF expect fail on powerpc64[le] for #11261. - - - - - 65b7256a by Ömer Sinan Ağacan at 2020-02-20T21:20:45-05:00 Use concatMap(M) instead of `concat . map` and the monadic variant - - - - - 8b76d457 by Roland Senn at 2020-02-20T21:21:28-05:00 Fix #17832: Weird handling of exports named main in 8.10-rc1 Switching from `lookupGlobalOccRn_maybe` to `lookupInfoOccRn` to check whether a `main` function is in scope. Unfortunately `lookupGlobalOccRn_maybe` complains if there are multiple `main` functions in scope. - - - - - 466e1ad5 by Krzysztof Gogolewski at 2020-02-20T21:22:11-05:00 Use TTG for HsSplicedT constructor The constructor HsSplicedT occurs only in the GhcTc pass. This enforces this fact statically via TTG. - - - - - 4e622fca by Alexis King at 2020-02-20T21:22:49-05:00 Normalize types when dropping absent arguments from workers fixes #17852 - - - - - a533e547 by Adam Sandberg Eriksson at 2020-02-20T21:23:31-05:00 Mention users guide and release notes in merge request template - - - - - 05251b17 by Ben Gamari at 2020-02-20T21:24:08-05:00 gitlab-ci: Fix typo in BIN_DIST_PREP_TAR_COMP variable name - - - - - f44c7e67 by Ben Gamari at 2020-02-20T21:24:46-05:00 gitlab-ci: Avoid duplicating ~/.cabal contents with every build Previously our attempt to cache the cabal store would `cp cabal-cache ~/.cabal`. However, if the latter already existed this meant that we would end up with ~/.cabal/cabal-cache. Not only would this not help caching but it would exponentially grow the size of ~/.cabal. Not good! - - - - - c5ec9965 by Ben Gamari at 2020-02-20T21:56:13-05:00 GHC.Hs.Extension: Use Type instead of * - - - - - 89cb4cc4 by Ben Gamari at 2020-02-20T21:56:13-05:00 Use Type instead of * in GHC - - - - - 04eb0d6c by Ben Gamari at 2020-02-20T21:56:13-05:00 Enable -Wstar-is-type in -Wall As noted in [proposal 0143][proposal] this is supposed to happen in 8.12. Also fix an incorrect claim in the users guide that -Wstar-is-type is enabled by default. [proposal]: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0143-remove-star-kind.rst - - - - - 6de966f1 by Andreas Klebinger at 2020-02-20T21:56:15-05:00 Fix #17724 by having occAnal preserve used bindings. It sometimes happened that occAnal would remove bindings as dead code by relying on bindings to be in dependency order. The fix was contributed by SPJ. - - - - - abd7f962 by Ben Gamari at 2020-02-20T21:56:15-05:00 users-guide: Mention dependency on `exceptions` in release notes Fixes #17845. - - - - - 58175379 by Sylvain Henry at 2020-02-20T21:56:20-05:00 Hadrian: minor GMP refactoring Somehow I forgot to totally remove `gmpContext` in d7029cc09edc052c2f97effe33233c53340fcce0. This patch fixes it and adds some additional comments. - - - - - 33fa8d94 by Ryan Scott at 2020-02-20T21:56:21-05:00 Generalize liftData to work over any Quote (#17857) The Overloaded Quotations proposal generalized the type of `lift` to work over any `Quote`, but not the type of `liftData`, leading to #17857. Thankfully, generalizing `liftData` is extremely straightforward. Fixes #17857. - - - - - 3cea6795 by Sylvain Henry at 2020-02-20T21:56:23-05:00 Make: fix sdist target (#17848) - - - - - e2cce997 by Sylvain Henry at 2020-02-20T21:56:23-05:00 Hadrian: fix source-dist target (#17849) - - - - - 0a4c89b2 by Matthew Pickering at 2020-02-21T20:44:45-05:00 Special case `mkTyConApp liftedTypeKind []` We really need to make sure that these are shared because otherwise GHC will allocate thousands of identical `TyConApp` nodes. See #17292 ------------------------- Metric Decrease: haddock.Cabal T14683 ------------------------- - - - - - 0482f58a by Matthew Pickering at 2020-02-21T20:45:21-05:00 TH: wrapGenSyns, don't split the element type too much The invariant which allowed the pervious method of splitting the type of the body to find the type of the elements didn't work in the new overloaded quotation world as the type can be something like `WriterT () m a` rather than `Q a` like before. Fixes #17839 - - - - - be7068a6 by Vladislav Zavialov at 2020-02-21T20:45:59-05:00 Parser API annotations: RealSrcLoc During parsing, GHC collects lexical information about AST nodes and stores it in a map. It is needed to faithfully restore original source code, e.g. compare these expressions: a = b a = b The position of the equality sign is not recorded in the AST, so it must be stored elsewhere. This system is described in Note [Api annotations]. Before this patch, the mapping was represented by: Map (SrcSpan, AnnKeywordId) SrcSpan After this patch, the mapping is represented by: Map (RealSrcSpan, AnnKeywordId) RealSrcSpan The motivation behind this change is to avoid using the Ord SrcSpan instance (required by Map here), as it interferes with #17632 (see the discussion there). SrcSpan is isomorphic to Either String RealSrcSpan, but we shouldn't use those strings as Map keys. Those strings are intended as hints to the user, e.g. "<interactive>" or "<compiler-generated code>", so they are not a valid way to identify nodes in the source code. - - - - - 240f5bf6 by Sylvain Henry at 2020-02-21T20:46:40-05:00 Modules: Driver (#13009) submodule updates: nofib, haddock - - - - - 9d094111 by Sylvain Henry at 2020-02-21T20:47:19-05:00 Hadrian: `docs` rule needs `configure` (#17840) - - - - - 1674353a by Ben Gamari at 2020-02-23T17:31:19-05:00 fs: Port fixes from ghc-jailbreak repository * Override rename, unlink, and remove * Factor out wchar conversion - - - - - 853210f2 by Adam Sandberg Ericsson at 2020-02-23T17:32:03-05:00 show gcc linker options in configure summary - - - - - 2831544a by Adam Sandberg Ericsson at 2020-02-23T17:32:44-05:00 hadrian: docs depend on stage1 ghc - - - - - 1d9df9e0 by Adam Sandberg Ericsson at 2020-02-23T17:33:23-05:00 ci: after 5ce63d52fed the linux bindist for doc-tarball has changed name - - - - - 26e8fff3 by Vladislav Zavialov at 2020-02-24T02:05:30-05:00 Remove Ord SrcLoc, Ord SrcSpan Before this patch, GHC relied on Ord SrcSpan to identify source elements, by using SrcSpan as Map keys: blackList :: Map SrcSpan () -- compiler/GHC/HsToCore/Coverage.hs instanceMap :: Map SrcSpan Name -- compiler/GHC/HsToCore/Docs.hs Firstly, this design is not valid in presence of UnhelpfulSpan, as it distinguishes between UnhelpfulSpan "X" and UnhelpfulSpan "Y", but those strings are messages for the user, unfit to serve as identifiers for source elements. Secondly, this design made it hard to extend SrcSpan with additional data. Recall that the definition of SrcSpan is: data SrcSpan = RealSrcSpan !RealSrcSpan | UnhelpfulSpan !FastString Say we want to extend the RealSrcSpan constructor with additional information: data SrcSpan = RealSrcSpan !RealSrcSpan !AdditionalInformation | UnhelpfulSpan !FastString getAdditionalInformation :: SrcSpan -> AdditionalInformation getAdditionalInformation (RealSrcSpan _ a) = a Now, in order for Map SrcSpan to keep working correctly, we must *ignore* additional information when comparing SrcSpan values: instance Ord SrcSpan where compare (RealSrcSpan r1 _) (RealSrcSpan r2 _) = compare r1 r2 ... However, this would violate an important law: a == b therefore f a == f b Ignoring AdditionalInformation in comparisons would mean that with f=getAdditionalInformation, the law above does not hold. A more robust design is to avoid Ord SrcSpan altogether, which is what this patch implements. The mappings are changed to use RealSrcSpan instead: blackList :: Set RealSrcSpan -- compiler/GHC/HsToCore/Coverage.hs instanceMap :: Map RealSrcSpan Name -- compiler/GHC/HsToCore/Docs.hs All SrcSpan comparisons are now done with explicit comparison strategies: SrcLoc.leftmost_smallest SrcLoc.leftmost_largest SrcLoc.rightmost_smallest These strategies are not subject to the law mentioned above and can easily discard both the string stored in UnhelpfulSpan and AdditionalInformation. Updates haddock submodule. - - - - - 5aa6c188 by Ben Gamari at 2020-02-24T02:06:09-05:00 users-guide: Shuffle text - - - - - e3f17413 by Ben Gamari at 2020-02-24T02:06:09-05:00 users-guide: Drop old release notes - - - - - 84dd9610 by Ben Gamari at 2020-02-24T02:06:09-05:00 Bump directory submodule to 1.3.6.0 - - - - - e295a024 by Stefan Pavikevik at 2020-02-24T20:53:44-05:00 check for safe arguments, raising error when invalid (fix #17720) - - - - - 354e2787 by Krzysztof Gogolewski at 2020-02-24T20:54:35-05:00 Comments, small refactor * Remove outdated Note [HsForAllTy tyvar binders] and [Context quantification]. Since the wildcard refactor 1e041b7382, HsForAllTy no longer has an flag controlling explicity. The field `hsq_implicit` is gone too. The current situation is covered by Note [HsType binders] which is already linked from LHsQTyVars. * Small refactor in CoreLint, extracting common code to a function * Remove "not so sure about WpFun" in TcEvidence, per Richard's comment https://gitlab.haskell.org/ghc/ghc/merge_requests/852#note_223226 * Use mkIfThenElse in Foreign/Call, as it does exactly what we need. - - - - - 1b1067d1 by Sylvain Henry at 2020-02-24T20:55:25-05:00 Modules: CmmToAsm (#13009) - - - - - 621468f6 by Alexis King at 2020-02-26T15:08:09-05:00 Treat coercions as arguments for floating and inlining This reverts commit 8924224ecfa065ebc67b96a90d01cf9d2edd0e77 and fixes #17787. - - - - - def486c9 by Ben Gamari at 2020-02-26T15:08:47-05:00 hadrian: Allow libnuma library path to be specified - - - - - ed03d4e7 by Ben Gamari at 2020-02-26T15:08:47-05:00 hadrian: Refactor gmp arguments Move the gmp configuration to its own binding. - - - - - 09b88384 by Ben Gamari at 2020-02-26T15:08:47-05:00 hadrian: Tell Cabal about integer-gmp library location - - - - - 161e08c5 by Krzysztof Gogolewski at 2020-02-26T15:09:30-05:00 Remove dead code * FailablePattern can no longer be created since ab51bee40c82 Therefore, Opt_WarnMissingMonadFailInstances has no effect anymore. * XWrap is no longer used, it was moved to an extension field - - - - - e0d09db3 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Use 8.8.3 to bootstrap on Windows This should fix #17861. - - - - - 972bcf3a by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Fix symlink test Needs to `write` bytes, not str. - - - - - 273e60de by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Add shell subcommand for debugging within CI environment - - - - - 43b13ed3 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Fix colors on Darwin Darwin sh doesn't support \e. - - - - - 217546a7 by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Flush stdout buffers in InitEventLogging Otherwise we are sensitive to libc's buffering strategy. Similar to the issue fixed in 543dfaab166c81f46ac4af76918ce32190aaab22. - - - - - c7d4fa55 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Add run_hadrian subcommand I've ruined two trees already by failing to pass --flavour to hadrian. Let's factor this out so it can be reused during troubleshooting. - - - - - 7dc54873 by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Allow tests to be marked as broken on the command line This allows us to work-around distribution-specific breakage easily. - - - - - 25e2458e by Ben Gamari at 2020-02-26T15:10:09-05:00 hadrian: Add --broken-test flag This exposes the flag of the same name supported by the testsuite driver. - - - - - 55769996 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Mark some tests as broken on Alpine - - - - - 9ee7f87d by Ben Gamari at 2020-02-26T15:10:09-05:00 SysTools: Don't use process jobs if they are broken - - - - - bfaa3961 by Ben Gamari at 2020-02-26T15:10:09-05:00 Bump hsc2hs submodule Fixes name of C compiler. - - - - - b2b49a0a by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Make hasMetricsFile RHS more descriptive - - - - - 817f93ea by Sylvain Henry at 2020-02-26T15:10:58-05:00 Modules: Core (#13009) Update haddock submodule - - - - - 74311e10 by Sebastian Graf at 2020-02-27T16:22:45-05:00 PmCheck: Implement Long-distance information with Covered sets Consider ```hs data T = A | B | C f :: T -> Int f A = 1 f x = case x of A -> 2 B -> 3 C -> 4 ``` Clearly, the RHS returning 2 is redundant. But we don't currently see that, because our approximation to the covered set of the inner case expression just picks up the positive information from surrounding pattern matches. It lacks the context sensivity that `x` can't be `A` anymore! Therefore, we adopt the conceptually and practically superior approach of reusing the covered set of a particular GRHS from an outer pattern match. In this case, we begin checking the `case` expression with the covered set of `f`s second clause, which encodes the information that `x` can't be `A` anymore. After this MR, we will successfully warn about the RHS returning 2 being redundant. Perhaps surprisingly, this was a great simplification to the code of both the coverage checker and the desugarer. Found a redundant case alternative in `unix` submodule, so we have to bump it with a fix. Metric Decrease: T12227 - - - - - 59c023ba by Adam Sandberg Ericsson at 2020-02-27T16:23:25-05:00 configure: correctly generate LIBRARY_template_haskell_VERSION - - - - - 9be82389 by Krzysztof Gogolewski at 2020-02-28T02:35:35-05:00 boot: Remove remote origin check Previously, we used relative paths in submodules. When cloning from GitHub, they had to be manually tweaked. Since a76b233d we use absolute paths, so this workaround can be removed. - - - - - f4b6b594 by Ben Gamari at 2020-02-28T02:36:12-05:00 nonmoving: Fix marking in compact regions Previously we were tracing the object we were asked to mark, even if it lives in a compact region. However, there is no need to do this; we need only to mark the region itself as live. I have seen a segfault due to this due to the concurrent mark seeing a an object in the process of being compacted by the mutator. - - - - - f97d1fb6 by Alp Mestanogullari at 2020-02-28T02:36:59-05:00 base: use an explicit import list in System.Environment.ExecutablePath This was making -Werror builds fail on Windows (at least with Hadrian). - - - - - 66f5d6d6 by Simon Peyton Jones at 2020-02-28T22:03:23-05:00 Improve error handling for VTA + deferred type errors This fixes #17792 See Note [VTA for out-of-scope functions] in TcExpr - - - - - 37f12603 by Ilias Tsitsimpis at 2020-02-28T22:04:04-05:00 llvm-targets: Add arm-unknown-linux-gnueabi Add arm-unknown-linux-gnueabi, which is used by Debian's ARM EABI port (armel), as an LLVM target. - - - - - 327b29e1 by Vladislav Zavialov at 2020-02-29T05:06:31-05:00 Monotonic locations (#17632) When GHC is parsing a file generated by a tool, e.g. by the C preprocessor, the tool may insert #line pragmas to adjust the locations reported to the user. As the result, the locations recorded in RealSrcLoc are not monotonic. Elements that appear later in the StringBuffer are not guaranteed to have a higher line/column number. In fact, there are no guarantees whatsoever, as #line pragmas can arbitrarily modify locations. This lack of guarantees makes ideas such as #17544 infeasible. This patch adds an additional bit of information to every SrcLoc: newtype BufPos = BufPos { bufPos :: Int } A BufPos represents the location in the StringBuffer, unaffected by any pragmas. Updates haddock submodule. Metric Increase: haddock.Cabal haddock.base haddock.compiler MultiLayerModules Naperian parsing001 T12150 - - - - - 99d2de86 by Ben Gamari at 2020-02-29T05:07:10-05:00 plugins: Ensure that loadInterface plugins can see annotations loadInterface replaces the `mi_decls`, `mi_insts`, `mi_fam_insts`, `mi_rules`, `mi_anns` fields of ModIface with `undefined` before inserting the interface into the EPS. However, we still want to give loadInterface plugins access to these fields. Consequently, we want to pass the unmodified `ModIface` the plugin. - - - - - a999ee96 by Xavier Denis at 2020-02-29T05:07:50-05:00 Rename ghci.sh and build.sh to ghci and build respectively Convert hadrian buildscripts to unsuffixed, dashed form final cleanups - - - - - b5fb58fd by Ömer Sinan Ağacan at 2020-02-29T05:08:36-05:00 Document and refactor a few things around bitmap scavenging - Added a few comments in StgPAP - Added a few comments and assertions in scavenge_small_bitmap and walk_large_bitmap - Did tiny refactor in GHC.Data.Bitmap: added some comments, deleted dead code, used PlatformWordSize type. - - - - - 18757cab by Sylvain Henry at 2020-02-29T05:09:25-05:00 Refactor runtime interpreter code In #14335 we want to be able to use both the internal interpreter (for the plugins) and the external interpreter (for TH and GHCi) at the same time. This patch performs some preliminary refactoring: the `hsc_interp` field of HscEnv replaces `hsc_iserv` and is now used to indicate which interpreter (internal, external) to use to execute TH and GHCi. Opt_ExternalInterpreter flag and iserv options in DynFlags are now queried only when we set the session DynFlags. It should help making GHC multi-target in the future by selecting an interpreter according to the selected target. - - - - - b86a6395 by Adam Sandberg Ericsson at 2020-02-29T05:10:06-05:00 docs: correct relative links to haddocks from users guide (fixes #17866) - - - - - 0f55df7f by Adam Sandberg Ericsson at 2020-02-29T05:10:06-05:00 docs: correct link to th haddocks from users guide - - - - - 252e5117 by Jean-Baptiste Mazon at 2020-02-29T05:10:46-05:00 rts: enforce POSIX numeric locale for heap profiles - - - - - 34c7d230 by Sylvain Henry at 2020-02-29T05:11:27-05:00 Fix Hadrian's ``--configure`` (fix #17883) - - - - - 04d30137 by Ömer Sinan Ağacan at 2020-02-29T05:12:06-05:00 Simplify IfaceIdInfo type IfaceIdInfo type is confusing: there's practically no difference between `NoInfo` and `HasInfo []`. The comments say NoInfo is used when -fomit-interface-pragmas is enabled, but we don't need to distinguish `NoInfo` from `HasInfo []` in when reading the interface so the distinction is not important. This patch simplifies the type by removing NoInfo. When we have no info we use an empty list. With this change we no longer read the info list lazily when reading an IfaceInfoItem, but when reading an IfaceId the ifIdInfo field is read lazily, so I doubt this is going to be a problem. - - - - - 3979485b by Roland Senn at 2020-02-29T17:36:59+01:00 Show breakpoint locations of breakpoints which were ignored during :force (#2950) GHCi is split up into 2 major parts: The user-interface (UI) and the byte-code interpreter. With `-fexternal-interpreter` they even run in different processes. Communication between the UI and the Interpreter (called `iserv`) is done using messages over a pipe. This is called `Remote GHCI` and explained in the Note [Remote GHCi] in `compiler/ghci/GHCi.hs`. To process a `:force` command the UI sends a `Seq` message to the `iserv` process. Then `iserv` does the effective evaluation of the value. When during this process a breakpoint is hit, the `iserv` process has no additional information to enhance the `Ignoring breakpoint` output with the breakpoint location. To be able to print additional breakpoint information, there are 2 possible implementation choices: 1. Store the needed information in the `iserv` process. 2. Print the `Ignoring breakpoint` from the UI process. For option 1 we need to store the breakpoint info redundantely in 2 places and this is bad. Therfore option 2 was implemented in this MR: - The user enters a `force` command - The UI sends a `Seq` message to the `iserv` process. - If processing of the `Seq` message hits a breakpoint, the `iserv` process returns control to the UI process. - The UI looks up the source location of the breakpoint, and prints the enhanced `Ignoring breakpoint` output. - The UI sends a `ResumeSeq` message to the `iserv` process, to continue forcing. - - - - - 3cf7303b by Krzysztof Gogolewski at 2020-03-02T01:18:33-05:00 Remove dead code * The names in PrelName and THNames are no longer used since TH merged types and kinds, Typeable is kind-polymorphic, .net support was removed * unqualQuasiQuote no longer used since 6f8ff0bbad3b9fa3 - - - - - dbea7e9d by Ilias Tsitsimpis at 2020-03-02T01:19:12-05:00 Do not define hs_atomic{read,write}64() on non-64bit Do not define hs_atomicread64() and hs_atomicwrite64() on machines where WORD_SIZE_IN_BITS is less than 64, just like we do with the rest of the atomic functions which work on 64-bit values. Without this, compilation fails on MIPSel and PowerPC with the following error: /usr/bin/ld: /<<PKGBUILDDIR>>/libraries/ghc-prim/dist-install/build/libHSghc-prim-0.5.3_p.a(atomic.p_o): in function `hs_atomicread64': atomic.c:(.text.hs_atomicread64+0x8): undefined reference to `__sync_add_and_fetch_8' /usr/bin/ld: /<<PKGBUILDDIR>>/libraries/ghc-prim/dist-install/build/libHSghc-prim-0.5.3_p.a(atomic.p_o): in function `hs_atomicwrite64': atomic.c:(.text.hs_atomicwrite64+0x38): undefined reference to `__sync_bool_compare_and_swap_8' Fixes #17886. - - - - - 7c0c76fb by Roland Senn at 2020-03-02T17:13:55-05:00 Set `ImpredicativeTypes` during :print command. (#14828) If ImpredicativeTypes is not enabled, then `:print <term>` will fail if the type of <term> has nested `forall`s or `=>`s. This is because the GHCi debugger's internals will attempt to unify a metavariable with the type of <term> and then display the result, but if the type has nested `forall`s or `=>`s, then unification will fail. As a result, `:print` will bail out and the unhelpful result will be `<term> = (_t1::t1)` (where `t1` is a metavariable). Beware: <term> can have nested `forall`s even if its definition doesn't use RankNTypes! Here is an example from #14828: class Functor f where fmap :: (a -> b) -> f a -> f b Somewhat surprisingly, `:print fmap` considers the type of fmap to have nested foralls. This is because the GHCi debugger sees the type `fmap :: forall f. Functor f => forall a b. (a -> b) -> f a -> f b`. We could envision deeply instantiating this type to get the type `forall f a b. Functor f => (a -> b) -> f a -> f b`, but this trick wouldn't work for higher-rank types. Instead, we adopt a simpler fix: enable `ImpredicativeTypes` when using `:print` and friends in the GHCi debugger. This is allows metavariables to unify with types that have nested (or higher-rank) `forall`s/`=>`s, which makes `:print fmap` display as `fmap = (_t1::forall a b. Functor f => (a -> b) -> f a -> f b)`, as expected. Although ImpredicativeTypes is a somewhat unpredictable from a type inference perspective, there is no danger in using it in the GHCi debugger, since all of the terms that the GHCi debugger deals with have already been typechecked. - - - - - 2a2f51d7 by Sylvain Henry at 2020-03-02T17:14:38-05:00 Use configure script to detect that we should use in-tree GMP on Windows - - - - - 8c663c2c by Andreas Klebinger at 2020-03-04T16:12:14+01:00 Be explicit about how stack usage of mvar primops are covered. This fixes #17893 [skip-ci] - - - - - cedd6f30 by Ben Gamari at 2020-03-05T14:53:12-05:00 rts: Add getCurrentThreadCPUTime helper - - - - - ace618cd by Ben Gamari at 2020-03-05T14:53:12-05:00 nonmoving-gc: Track time usage of nonmoving marking - - - - - 022b5ad5 by Ben Gamari at 2020-03-05T14:53:12-05:00 Stats: Add sync pauses to +RTS -S output - - - - - 06763234 by Ben Gamari at 2020-03-05T14:53:12-05:00 rts: Report nonmoving collector statistics in machine-readable output - - - - - 70d2b995 by Ben Gamari at 2020-03-09T06:10:52-04:00 nonmoving: Fix collection of sparks Previously sparks living in the non-moving heap would be promptly GC'd by the minor collector since pruneSparkQueue uses the BF_EVACUATED flag, which non-moving heap blocks do not have set. Fix this by implementing proper support in pruneSparkQueue for determining reachability in the non-moving heap. The story is told in Note [Spark management in the nonmoving heap]. - - - - - 9668781a by Ben Gamari at 2020-03-09T06:11:30-04:00 gitlab-ci: Disable Sphinx documentation in Alpine build - - - - - 8eb2c263 by Jean-Baptiste Mazon at 2020-03-09T16:33:37-04:00 Fix Windows breakage by not touching locales on Windows - - - - - b8dab057 by Jean-Baptiste Mazon at 2020-03-09T16:33:37-04:00 rts: ensure C numerics in heap profiles using Windows locales if needed - - - - - 7d95260f by Jean-Baptiste Mazon at 2020-03-09T16:33:37-04:00 rts: refactor and comment profile locales - - - - - 5b627813 by Ryan Scott at 2020-03-09T16:34:14-04:00 Use InstanceSigs in GND/DerivingVia-generated code (#17899) Aside from making the generated code easier to read when `-ddump-deriv` is enabled, this makes the error message in `T15073` substantially simpler (see the updated `T15073` expected stderr). Fixes #17899. - - - - - 70b50778 by Ben Gamari at 2020-03-10T02:05:42-04:00 SysTools: Ensure that error parser can handle absolute paths on Windows This fixes #17786, where the error parser fails to correctly handle the drive name in absolute Windows paths. Unfortunately I couldn't find a satisfactory way to test this. - - - - - 85b861d8 by Ben Gamari at 2020-03-10T02:05:42-04:00 testsuite: Add test for #17786 This isn't pretty but it's perhaps better than nothing. - - - - - ee2c50cb by Sylvain Henry at 2020-03-10T02:06:33-04:00 Hadrian: track missing configure results - - - - - ca8f51d4 by Ömer Sinan Ağacan at 2020-03-10T02:07:22-04:00 Add regression test for T17904 Closes #17904 - - - - - 5fa9cb82 by Richard Eisenberg at 2020-03-10T12:29:46-04:00 anyRewritableTyVar now looks in RuntimeReps Previously, anyRewritableTyVar looked only at the arg and res of `arg -> res`, but their RuntimeReps are also subject to rewriting. Easy to fix. Test case: typecheck/should_compile/T17024 Fixes #17024. - - - - - 5ba01d83 by Ben Price at 2020-03-10T12:30:27-04:00 Clarify a Lint message When developing a plugin I had a shadowing problem, where I generated code app = \f{v r7B} x{v r7B} -> f{v r7B} x{v r7B} This is obviously wrong, since the occurrence of `f` to the right of the arrow refers to the `x` binder (they share a Unique). However, it is rather confusing when Lint reports Mismatch in type between binder and occurrence Var: x{v rB7} since it is printing the binder, rather than the occurrence. It is rather easy to read this as claiming there is something wrong with the `x` occurrence! We change the report to explicitly print both the binder and the occurrence variables. - - - - - 7b2c827b by Simon Peyton Jones at 2020-03-10T12:31:15-04:00 Comments only Clarify code added in #17852 and MR !2724 - - - - - 3300eeac by Krzysztof Gogolewski at 2020-03-10T12:31:54-04:00 Misc cleanup - Remove Note [Existentials in shift_con_pat]. The function shift_con_pat has been removed 15 years ago in 23f40f0e9be6d4. - Remove kcLookupTcTyCon - it's the same as tcLookupTcTyCon - Remove ASSERT in tyConAppArgN. It's already done by getNth, and it's the only reason getNth exists. - Remove unused function nextRole - - - - - abf5736b by Krzysztof Gogolewski at 2020-03-10T18:05:01+01:00 Typos in comments [skip ci] - - - - - bb586f89 by Ben Gamari at 2020-03-11T00:14:59-04:00 rts: Prefer darwin-specific getCurrentThreadCPUTime macOS Catalina now supports a non-POSIX-compliant version of clock_gettime which cannot use the clock_gettime codepath. Fixes #17906. - - - - - 20800b9a by Sylvain Henry at 2020-03-11T08:17:19-04:00 Split GHC.Iface.Utils module * GHC.Iface.Recomp: recompilation avoidance stuff * GHC.Iface.Make: mkIface* Moved `writeIfaceFile` into GHC.Iface.Load alongside `readIface` and renamed it `writeIface` for consistency. - - - - - 1daa2029 by Greg Steuck at 2020-03-11T08:17:56-04:00 Fixed a minor typo in codegen.rst - - - - - 0bc23338 by Ryan Scott at 2020-03-11T08:18:32-04:00 Re-quantify when generalising over rewrite rule types Previously, `tcRules` would check for naughty quantification candidates (see `Note [Naughty quantification candidates]` in `TcMType`) when generalising over the type of a rewrite rule. This caused sensible-looking rewrite rules (like those in #17710) to be rejected. A more permissing (and easier-to-implement) approach is to do what is described in `Note [Generalising in tcTyFamInstEqnGuts]` in `TcTyClsDecls`: just re-quantify all the type variable binders, regardless of the order in which the user specified them. After all, the notion of type variable specificity has no real meaning in rewrite rules, since one cannot "visibly apply" a rewrite rule. I have written up this wisdom in `Note [Re-quantify type variables in rules]` in `TcRules`. As a result of this patch, compiling the `ExplicitForAllRules1` test case now generates one fewer warning than it used to. As far as I can tell, this is benign, since the thing that the disappearing warning talked about was also mentioned in an entirely separate warning. Fixes #17710. - - - - - 336eac7e by Ben Gamari at 2020-03-11T08:19:08-04:00 testsuite: Mark ghci056 and ghcilink004 as fragile in unreg As noted in #17018. Also fix fragile declaration of T13786, which only runs in the normal way. - - - - - c61b9b02 by Simon Peyton Jones at 2020-03-11T08:19:44-04:00 Deepen call stack for isIn I see quite a few warnings like: WARNING: file compiler/utils/Util.hs, line 593 Over-long elem in unionLists But the call stack is uninformative. Better to add HasDebugCallStack to isIn. Ditto isn'tIn. - - - - - 3aa9b35f by Ömer Sinan Ağacan at 2020-03-11T08:20:27-04:00 Zero any slop after compaction in compacting GC In copying GC, with the relevant debug flags enabled, we release the old blocks after a GC, and the block allocator zeroes the space before releasing a block. This effectively zeros the old heap. In compacting GC we reuse the blocks and previously we didn't zero the unused space in a compacting generation after compaction. With this patch we zero the slop between the free pointer and the end of the block when we're done with compaction and when switching to a new block (because the current block doesn't have enough space for the next object we're shifting). - - - - - 8e6febce by Sylvain Henry at 2020-03-11T20:33:37-04:00 Refactor GHC.Driver.Session (Ways and Flags) * extract flags and ways into their own modules (with some renaming) * remove one SOURCE import of GHC.Driver.Session from GHC.Driver.Phases * when GHC uses dynamic linking (WayDyn), `interpWays` was only reporting WayDyn even if the host was profiled (WayProf). Now it returns both as expected (might fix #16803). * `mkBuildTag :: [Way] -> String` wasn't reporting a canonical tag for differently ordered lists. Now we sort and nub the list to fix this. - - - - - bc41e471 by Sylvain Henry at 2020-03-11T20:33:37-04:00 Refactor interpreterDynamic and interpreterProfiled * `interpreterDynamic` and `interpreterProfiled` now take `Interp` parameters instead of DynFlags * slight refactoring of `ExternalInterp` so that we can read the iserv configuration (which is pure) without reading an MVar. - - - - - a6989971 by Sylvain Henry at 2020-03-11T20:33:37-04:00 Use a Set to represent Ways Should make `member` queries faster and avoid messing up with missing `nubSort`. Metric Increase: hie002 - - - - - cb93a1a4 by Ryan Scott at 2020-03-11T20:34:14-04:00 Make DeriveFunctor-generated code require fewer beta reductions Issue #17880 demonstrates that `DeriveFunctor`-generated code is surprisingly fragile when rank-_n_ types are involved. The culprit is that `$fmap` (the algorithm used to generate `fmap` implementations) was too keen on applying arguments with rank-_n_ types to lambdas, which fail to typecheck more often than not. In this patch, I change `$fmap` (both the specification and the implementation) to produce code that avoids creating as many lambdas, avoiding problems when rank-_n_ field types arise. See the comments titled "Functor instances" in `TcGenFunctor` for a more detailed description. Not only does this fix #17880, but it also ensures that the code that `DeriveFunctor` generates will continue to work after simplified subsumption is implemented (see #17775). What is truly amazing is that #17880 is actually a regression (introduced in GHC 7.6.3) caused by commit 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e, the fix #7436. Prior to that commit, the version of `$fmap` that was used was almost identical to the one used in this patch! Why did that commit change `$fmap` then? It was to avoid severe performance issues that would arise for recursive `fmap` implementations, such as in the example below: ```hs data List a = Nil | Cons a (List a) deriving Functor -- ===> instance Functor List where fmap f Nil = Nil fmap f (Cons x xs) = Cons (f x) (fmap (\y -> f y) xs) ``` The fact that `\y -> f y` was eta expanded caused significant performance overheads. Commit 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e fixed this performance issue, but it went too far. As a result, this patch partially reverts 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e. To ensure that the performance issues pre-#7436 do not resurface, I have taken some precautionary measures: * I have added a special case to `$fmap` for situations where the last type variable in an application of some type occurs directly. If this special case fires, we avoid creating a lambda expression. This ensures that we generate `fmap f (Cons x xs) = Cons (f x) (fmap f xs)` in the derived `Functor List` instance above. For more details, see `Note [Avoid unnecessary eta expansion in derived fmap implementations]` in `TcGenFunctor`. * I have added a `T7436b` test case to ensure that the performance of this derived `Functor List`-style code does not regress. When implementing this, I discovered that `$replace`, the algorithm which generates implementations of `(<$)`, has a special case that is very similar to the `$fmap` special case described above. `$replace` marked this special case with a custom `Replacer` data type, which was a bit overkill. In order to use the same machinery for both `Functor` methods, I ripped out `Replacer` and instead implemented a simple way to detect the special case. See the updated commentary in `Note [Deriving <$]` for more details. - - - - - 1f9db3e7 by Kirill Elagin at 2020-03-12T09:45:51-04:00 pretty-printer: Properly parenthesise LastStmt After ApplicatveDo strips the last `return` during renaming, the pretty printer has to restore it. However, if the return was followed by `$`, the dollar was stripped too and not restored. For example, the last stamement in: ``` foo = do x <- ... ... return $ f x ``` would be printed as: ``` return f x ``` This commit preserved the dolar, so it becomes: ``` return $ f x ``` - - - - - 5cb93af7 by Kirill Elagin at 2020-03-12T09:45:51-04:00 pretty-printer: Do not print ApplicativeDo join * Do not print `join` in ApplictiveStmt, unless ppr-debug * Print parens around multiple parallel binds When ApplicativeDo is enabled, the renamer analyses the statements of a `do` block and in certain cases marks them as needing to be rewritten using `join`. For example, if you have: ``` foo = do a <- e1 b <- e2 doSomething a b ``` it will be desugared into: ``` foo = join (doSomething <$> e1 <*> e2) ``` After renaming but before desugaring the expression is stored essentially as: ``` foo = do [will need join] (a <- e1 | b <- e2) [no return] doSomething a b ``` Before this change, the pretty printer would print a call to `join`, even though it is not needed at this stage at all. The expression will be actually rewritten into one using join only at desugaring, at which point a literal call to join will be inserted. - - - - - 3a259092 by Simon Peyton Jones at 2020-03-12T09:46:29-04:00 Expose compulsory unfoldings always The unsafeCoerce# patch requires that unsafeCoerce# has a compulsory unfolding that is always available. So we have to be careful to expose compulsory unfoldings unconditionally and consistently. We didn't get this quite right: #17871. This patch fixes it. No real surprises here. See Note [Always expose compulsory unfoldings] in GHC.Iface.Tidy - - - - - 6a65b8c2 by Alp Mestanogullari at 2020-03-13T02:29:20-04:00 hadrian: improve dependency tracking for the check-* programs The code in Rules.Register responsible for finding all the build artifacts that Cabal installs when registering a library (static/shared libs, .hi files, ...) was looking in the wrong place. This patch fixes that logic and makes sure we gather all those artifacts in a list to declare that the rule for a given `.conf` file, our proxy for "Hadrian, please install this package in the package db for this stage", also produces those artifacts under the said package database. We also were completely missing some logic to declare that the check-* programs have dependencies besides their source code, at least when testing an in-tree compiler. Finally, this patch also removes redundant packages from 'testsuitePackages', since they should already be covered by the stage<N>Packages lists from Settings.Default. With this patch, after a complete build and freezing stage 1, a change to `compiler/parser/Parser.y` results in rebuilding the ghc lib, reinstalling it, and rebuilding the few programs that depend on it, _including_ `check-ppr` and `check-api-annotations` (therefore fixing #17273). - - - - - 44fad4a9 by Sylvain Henry at 2020-03-13T02:30:22-04:00 Rename isDllName I wanted to fix the dangling comment in `isDllName` ("This is the cause of #", #8696 is already mentioned earlier). I took the opportunity to change the function name to better reflect what it does. - - - - - 2f292db8 by Paavo at 2020-03-13T02:31:03-04:00 Update documentation for closureSize - - - - - f124ff0d by Ben Gamari at 2020-03-13T02:31:40-04:00 gitlab-ci: Rework triggering of release builds Use a push option instead of tagging. - - - - - 7f25557a by Ben Gamari at 2020-03-13T10:38:09-04:00 gitlab-ci: Distinguish integer-simple test envs Previously two integer-simple jobs declared the same test environment. One (the nightly job) was built in the perf way, the other in the validate way. Consequently they had appreciably different performance characteristics, causing in the nightly job to spuriously fail with performance changes. - - - - - c12a2ec5 by Simon Peyton Jones at 2020-03-14T05:25:30-04:00 Fix Lint Ticket #17590 pointed out a bug in the way the linter dealt with type lets, exposed by the new uniqAway story. The fix is described in Note [Linting type lets]. I ended up putting the in-scope Ids in a different env field, le_ids, rather than (as before) sneaking them into the TCvSubst. Surprisingly tiresome, but done. Metric Decrease: hie002 - - - - - b989845e by Sylvain Henry at 2020-03-14T05:26:11-04:00 Hadrian: fix absolute buildroot support (#17822) Shake's "**" wildcard doesn't match absolute root. We must use "//" instead. - - - - - 4f117135 by Sylvain Henry at 2020-03-14T05:26:49-04:00 Make: refactor GMP rules Document and use simpler rules for the ghc-gmp.h header. - - - - - 7432b327 by Sylvain Henry at 2020-03-14T05:27:28-04:00 Use correct option name (-opti) (fix #17314) s/pgmo/opti - - - - - 8f7dd571 by Judah Jacobson at 2020-03-14T05:28:07-04:00 Allow overriding LD_STAGE0 and AR_STAGE0 in the configure script. Previously it was possible to override the stage0 C compiler via `CC_STAGE0`, but you couldn't override `ld` or `ar` in stage0. This change allows overriding them by setting `LD_STAGE0` or `AR_STAGE0`, respectively. Our team uses this feature internally to take more control of our GHC build and make it run more hermetically. - - - - - 7c3e39a9 by Judah Jacobson at 2020-03-14T05:28:07-04:00 Use AC_ARG_VAR for LD_STAGE0 and AR_STAGE0. - - - - - 20d4d676 by Ben Gamari at 2020-03-14T05:28:43-04:00 nonmoving: Don't traverse filled segment list in pause The non-moving collector would previously walk the entire filled segment list during the preparatory pause. However, this is far more work than is strictly necessary. We can rather get away with merely collecting the allocators' filled segment list heads and process the lists themselves during the concurrent phase. This can significantly reduce the maximum gen1 GC pause time in programs with high rates of long-lived allocations. - - - - - fdfa2d01 by Ben Gamari at 2020-03-14T05:29:18-04:00 nonmoving: Remove redundant bitmap clearing nonmovingSweep already clears the bitmap in the sweep loop. There is no reason to do so a second time. - - - - - 2f8c7767 by Simon Peyton Jones at 2020-03-14T05:29:55-04:00 Simple refactor of cheapEqExpr No change in functionality. Just seems tidier (and signficantly more efficient) to deal with ticks directly than to call stripTicksTopE. - - - - - 88f7a762 by Simon Peyton Jones at 2020-03-14T05:29:55-04:00 Improve CSE.combineAlts This patch improves the way that CSE combines identical alternatives. See #17901. I'm still not happy about the duplication between CSE.combineAlts and GHC.Core.Utils.combineIdenticalAlts; see the Notes with those functions. But this patch is a step forward. Metric Decrease: T12425 T5642 - - - - - 8b95ddd3 by Ben Gamari at 2020-03-14T05:30:31-04:00 gitlab-ci: Add integer-simple release build for Windows Closes #16144. - - - - - e3c374cc by Simon Peyton Jones at 2020-03-14T05:31:07-04:00 Wrap an implication around class-sig kind errors Ticket #17841 showed that we can get a kind error in a class signature, but lack an enclosing implication that binds its skolems. This patch * Adds the wrapping implication: the new call to checkTvConstraints in tcClassDecl1 * Simplifies the API to checkTvConstraints, which was not otherwise called at all. * Simplifies TcErrors.report_unsolved by *not* initialising the TidyEnv from the typechecker lexical envt. It's enough to do so from the free vars of the unsolved constraints; and we get silly renamings if we add variables twice: once from the lexical scope and once from the implication constraint. - - - - - 73133a3b by Simon Peyton Jones at 2020-03-14T05:31:07-04:00 Refactoring in TcSMonad This patch is just refactoring: no change in behaviour. I removed the rather complicated checkConstraintsTcS checkTvConstraintsTcS in favour of simpler functions emitImplicationTcS emitTvImplicationTcS pushLevelNoWorkList The last of these is a little strange, but overall it's much better I think. - - - - - 93c88c26 by Ben Gamari at 2020-03-14T05:31:42-04:00 base: Make `open` calls interruptible As noted in #17912, `open` system calls were `safe` rather than `interruptible`. Consequently, the program could not be interrupted with SIGINT if stuck in a slow open operation. Fix this by marking `c_safe_open` as interruptible. - - - - - bee4cdad by Vladislav Zavialov at 2020-03-14T05:32:18-04:00 Remove second tcLookupTcTyCon in tcDataDefn Before this patch, tcDataDefn used to call tcLookupTcTyCon twice in a row: 1. in bindTyClTyVars itself 2. in the continuation passed to it Now bindTyClTyVars passes the TcTyCon to the continuation, making the second lookup unnecessary. - - - - - 3f116d35 by Cale Gibbard at 2020-03-14T19:34:42-04:00 Enable stage1 build of haddock The submodule has already been bumped to contain the fix. - - - - - 49e9d739 by Ömer Sinan Ağacan at 2020-03-14T19:35:24-04:00 rts: Fix printClosure when printing fwd ptrs - - - - - 1de3ab4a by Krzysztof Gogolewski at 2020-03-14T19:36:04-04:00 Remove unused field var_inline (#17915) - - - - - d30aeb4b by Krzysztof Gogolewski at 2020-03-15T03:57:41-04:00 Document restriction on SCC pragma syntax Currently, the names of cost centres must be quoted or be lowercase identifiers. Fixes #17916. - - - - - b4774598 by Brian Foley at 2020-03-15T03:58:18-04:00 Remove some dead code >From the notes.ghc.drop list found using weeder in #17713 - - - - - dd6ffe6b by Viktor Dukhovni at 2020-03-15T03:58:55-04:00 Note platform-specific Foreign.C.Types in context Also fix the markup in the general note at the top of the module. Haddock (usability trade-off), does not support multi-line emphasised text. - - - - - 2e82465f by Sylvain Henry at 2020-03-15T10:57:10-04:00 Refactor CmmToAsm (disentangle DynFlags) This patch disentangles a bit more DynFlags from the native code generator (CmmToAsm). In more details: - add a new NCGConfig datatype in GHC.CmmToAsm.Config which contains the configuration of a native code generation session - explicitly pass NCGConfig/Platform arguments when necessary - as a consequence `sdocWithPlatform` is gone and there are only a few `sdocWithDynFlags` left - remove the use of `unsafeGlobalDynFlags` from GHC.CmmToAsm.CFG - remove `sdocDebugLevel` (now we pass the debug level via NCGConfig) There are still some places where DynFlags is used, especially because of pretty-printing (CLabel), because of Cmm helpers (such as `cmmExprType`) and because of `Outputable` instance for the instructions. These are left for future refactoring as this patch is already big. - - - - - c35c545d by Judah Jacobson at 2020-03-15T10:57:48-04:00 Add a -no-haddock flag. This flag undoes the effect of a previous "-haddock" flag. Having both flags makes it easier for build systems to enable Haddock parsing in a set of global flags, but then disable it locally for specific targets (e.g., third-party packages whose comments don't pass the validation in the latest GHC). I added the flag to expected-undocumented-flags.txt since `-haddock` was alreadyin that list. - - - - - cfcc3c9a by Ömer Sinan Ağacan at 2020-03-15T10:58:27-04:00 Fix global_link of TSOs for threads reachable via dead weaks Fixes #17785 Here's how the problem occurs: - In generation 0 we have a TSO that is finished (i.e. it has no more work to do or it is killed). - The TSO only becomes reachable after collectDeadWeakPtrs(). - After collectDeadWeakPtrs() we switch to WeakDone phase where we don't move TSOs to different lists anymore (like the next gen's thread list or the resurrected_threads list). - So the TSO will never be moved to a generation's thread list, but it will be promoted to generation 1. - Generation 1 collected via mark-compact, and because the TSO is reachable it is marked, and its `global_link` field, which is bogus at this point (because the TSO is not in a list), will be threaded. - Chaos ensues. In other words, when these conditions hold: - A TSO is reachable only after collectDeadWeakPtrs() - It's finished (what_next is ThreadComplete or ThreadKilled) - It's retained by mark-compact collector (moving collector doesn't evacuate the global_list field) We end up doing random mutations on the heap because the TSO's global_list field is not valid, but it still looks like a heap pointer so we thread it during compacting GC. The fix is simple: when we traverse old_threads lists to resurrect unreachable threads the threads that won't be resurrected currently stays on the old_threads lists. Those threads will never be visited again by MarkWeak so we now reset the global_list fields. This way compacting GC does not thread pointers to nowhere. Testing ------- The reproducer in #17785 is quite large and hard to build, because of the dependencies, so I'm not adding a regression test. In my testing the reproducer would take a less than 5 seconds to run, and once in every ~5 runs would fail with a segfault or an assertion error. In other cases it also fails with a test failure. Because the tests never fail with the bug fix, assuming the code is correct, this also means that this bug can sometimes lead to incorrect runtime results. After the fix I was able to run the reproducer repeatedly for about an hour, with no runtime crashes or test failures. To run the reproducer clone the git repo: $ git clone https://github.com/osa1/streamly --branch ghc-segfault Then clone primitive and atomic-primops from their git repos and point to the clones in cabal.project.local. The project should then be buildable using GHC HEAD. Run the executable `properties` with `+RTS -c -DZ`. In addition to the reproducer above I run the test suite using: $ make slowtest EXTRA_HC_OPTS="-debug -with-rtsopts=-DS \ -with-rtsopts=-c +RTS -c -RTS" SKIPWAY='nonmoving nonmoving_thr' This enables compacting GC always in both GHC when building the test programs and when running the test programs, and also enables sanity checking when running the test programs. These set of flags are not compatible for all tests so there are some failures, but I got the same set of failures with this patch compared to GHC HEAD. - - - - - 818b3c38 by Lysxia at 2020-03-16T23:52:42-04:00 base: add strict IO functions: readFile', getContents', hGetContents' - - - - - 18a346a4 by Sylvain Henry at 2020-03-16T23:53:24-04:00 Modules: Core (#13009) Update submodule: haddock - - - - - 92327e3a by Ömer Sinan Ağacan at 2020-03-16T23:54:04-04:00 Update sanity checking for TSOs: - Remove an invalid assumption about GC checking what_next field. The GC doesn't care about what_next at all, if a TSO is reachable then all its pointers are followed (other than global_tso, which is only followed by compacting GC). - Remove checkSTACK in checkTSO: TSO stacks will be visited in checkHeapChain, or checkLargeObjects etc. - Add an assertion in checkTSO to check that the global_link field is sane. - Did some refactor to remove forward decls in checkGlobalTSOList and added braces around single-statement if statements. - - - - - e1aa4052 by PHO at 2020-03-17T07:36:09-04:00 Don't use non-portable operator "==" in configure.ac The test operator "==" is a Bash extension and produces a wrong result if /bin/sh is not Bash. - - - - - 89f034dd by Maximilian Tagher at 2020-03-17T07:36:48-04:00 Document the units of -ddump-timings Right now, in the output of -ddump-timings to a file, you can't tell what the units are: ``` CodeGen [TemplateTestImports]: alloc=22454880 time=14.597 ``` I believe bytes/milliseconds are the correct units, but confirmation would be appreciated. I'm basing it off of this snippet from `withTiming'`: ``` when (verbosity dflags >= 2 && prtimings == PrintTimings) $ liftIO $ logInfo dflags (defaultUserStyle dflags) (text "!!!" <+> what <> colon <+> text "finished in" <+> doublePrec 2 time <+> text "milliseconds" <> comma <+> text "allocated" <+> doublePrec 3 (realToFrac alloc / 1024 / 1024) <+> text "megabytes") ``` which implies time is in milliseconds, and allocations in bytes (which divided by 1024 would be KB, and again would be MB) - - - - - beffa147 by Simon Peyton Jones at 2020-03-17T07:37:25-04:00 Implement mapTyCo like foldTyCo This patch makes mapType use the successful idiom described in TyCoRep Note [Specialising foldType] I have not yet changed any functions to use mapType, though there may be some suitable candidates. This patch should be a no-op in terms of functionality but, because it inlines the mapper itself, I'm hoping that there may be some modest perf improvements. Metric Decrease: T5631 T5642 T3064 T9020 T14683 hie002 haddock.Cabal haddock.base haddock.compiler - - - - - 5800ebfe by Ömer Sinan Ağacan at 2020-03-17T07:38:08-04:00 Don't update ModDetails with CafInfos when opts are disabled This is consistent with the interface file behavior where we omit HsNoCafRefs annotations with -fomit-interface-pragmas (implied by -O0). ModDetails and ModIface are just different representations of the same thing, so they really need to be in sync. This patch does the right thing and does not need too much explanation, but here's an example of a problem not doing this causes in !2842: -- MyInteger.hs module MyInteger ( MyInteger (MyInteger) , ToMyInteger (toMyInteger) ) where newtype MyInteger = MyInteger Integer class ToMyInteger a where toMyInteger :: a -> MyInteger instance ToMyInteger Integer where toMyInteger = MyInteger {- . succ -} -- Main.hs module Main ( main ) where import MyInteger (MyInteger (MyInteger), toMyInteger) main :: IO () main = do let (MyInteger i) = (id . toMyInteger) (41 :: Integer) print i If I build this with -O0, without this fix, we generate a ModDetails with accurate LFInfo for toMyInteger (MyInteger.$fToMyIntegerInteger) which says that it's a LFReEntrant with arity 1. This means in the use site (Main) we tag the value: R3 = MyInteger.$fToMyIntegerInteger_closure + 1; R2 = GHC.Base.id_closure; R1 = GHC.Base.._closure; Sp = Sp - 16; call stg_ap_ppp_fast(R4, R3, R2, R1) args: 24, res: 0, upd: 24; Now we change the definition by uncommenting the `succ` part and it becomes a thunk: MyInteger.$fToMyIntegerInteger [InlPrag=INLINE (sat-args=0)] :: MyInteger.ToMyInteger GHC.Integer.Type.Integer [GblId[DFunId(nt)]] = {} \u [] $ctoMyInteger_rEA; and its LFInfo is now LFThunk. This change in LFInfo makes a difference in the use site: we can no longer tag it. But becuase the interface fingerprint does not change (because ModIface does not change) we don't rebuild Main and tag the thunk. (1.2% increase in allocations when building T12545 on armv7 because we generate more code without CafInfos) Metric Increase: T12545 - - - - - 5b632dad by Paavo at 2020-03-17T07:38:48-04:00 Add example for Data.Semigroup.diff - - - - - 4d85d68b by Paavo at 2020-03-17T07:38:48-04:00 Clean up - - - - - 75168d07 by Paavo at 2020-03-17T07:38:48-04:00 Make example collapsible - - - - - 53ff2cd0 by Richard Eisenberg at 2020-03-17T13:46:57+00:00 Fix #17021 by checking more return kinds All the details are in new Note [Datatype return kinds] in TcTyClsDecls. Test case: typecheck/should_fail/T17021{,b} typecheck/should_compile/T17021a Updates haddock submodule - - - - - 528df8ec by Sylvain Henry at 2020-03-18T10:06:43-04:00 Modules: Core operations (#13009) - - - - - 4e8a71c1 by Richard Eisenberg at 2020-03-18T10:07:19-04:00 Add release note about fix to #16502. We thought we needed to update the manual, but the fix for #16502 actually brings the implementation in line with the manual. So we just alert users of how to update their code. - - - - - 5cbf9934 by Andreas Klebinger at 2020-03-19T00:39:27-04:00 Update "GHC differences to the FFI Chapter" in user guide. The old entry had a heavy focus on how things had been. Which is not what I generally look for in a user guide. I also added a small section on behaviour of nested safe ffi calls. [skip-ci] - - - - - b03fd3bc by Sebastian Graf at 2020-03-19T00:40:06-04:00 PmCheck: Use ConLikeSet to model negative info In #17911, Simon recognised many warnings stemming from over-long list unions while coverage checking Cabal's `LicenseId` module. This patch introduces a new `PmAltConSet` type which uses a `UniqDSet` instead of an association list for `ConLike`s. For `PmLit`s, it will still use an assocation list, though, because a similar map data structure would entail a lot of busy work. Fixes #17911. - - - - - 64f20756 by Sylvain Henry at 2020-03-19T12:16:49-04:00 Refactoring: use Platform instead of DynFlags when possible Metric Decrease: ManyConstructors T12707 T13035 T1969 - - - - - cb1785d9 by Ömer Sinan Ağacan at 2020-03-19T12:16:54-04:00 FastString: fix eager reading of string ptr in hashStr This read causes NULL dereferencing when len is 0. Fixes #17909 In the reproducer in #17909 this bug is triggered as follows: - SimplOpt.dealWithStringLiteral is called with a single-char string ("=" in #17909) - tailFS gets called on the FastString of the single-char string. - tailFS checks the length of the string, which is 1, and calls mkFastStringByteString on the tail of the ByteString, which is an empty ByteString as the original ByteString has only one char. - ByteString's unsafeUseAsCStringLen returns (NULL, 0) for the empty ByteString, which is passed to mkFastStringWith. - mkFastStringWith gets hash of the NULL pointer via hashStr, which fails on empty strings because of this bug. - - - - - 73a7383e by Richard Eisenberg at 2020-03-20T20:42:56-04:00 Simplify treatment of heterogeneous equality Previously, if we had a [W] (a :: k1) ~ (rhs :: k2), we would spit out a [D] k1 ~ k2 and part the W as irreducible, hoping for a unification. But we needn't do this. Instead, we now spit out a [W] co :: k2 ~ k1 and then use co to cast the rhs of the original Wanted. This means that we retain the connection between the spat-out constraint and the original. The problem with this new approach is that we cannot use the casted equality for substitution; it's too like wanteds-rewriting- wanteds. So, we forbid CTyEqCans that mention coercion holes. All the details are in Note [Equalities with incompatible kinds] in TcCanonical. There are a few knock-on effects, documented where they occur. While debugging an error in this patch, Simon and I ran into infelicities in how patterns and matches are printed; we made small improvements. This patch includes mitigations for #17828, which causes spurious pattern-match warnings. When #17828 is fixed, these lines should be removed. - - - - - faa36e5b by Sylvain Henry at 2020-03-20T20:43:41-04:00 Hadrian: ignore in-tree GMP objects with ``--lint`` - - - - - 9a96ff6b by Richard Eisenberg at 2020-03-20T20:44:17-04:00 Update core spec to reflect changes to Core. Key changes: * Adds a new rule for forall-coercions over coercion variables, which was implemented but conspicuously missing from the spec. * Adds treatment for FunCo. * Adds treatment for ForAllTy over coercion variables. * Improves commentary (including restoring a Note lost in 03d4852658e1b7407abb4da84b1b03bfa6f6db3b) in the source. No changes to running code. - - - - - 7e0451c6 by Sergej Jaskiewicz at 2020-03-20T20:44:55-04:00 Fix event message in withTiming' This typo caused generating 'end' events without the corresponding 'begin' events. - - - - - 1542a626 by Ben Gamari at 2020-03-22T22:37:47-04:00 fs.h: Add missing declarations on Windows - - - - - 3bcf2ccd by Ben Gamari at 2020-03-22T22:37:47-04:00 Bump process submodule Avoids redundant case alternative warning. - - - - - 3b363ef9 by Ben Gamari at 2020-03-22T22:37:47-04:00 testsuite: Normalize slashes in ghc-api annotations output Enable `normalise_slashes` on `annotations`, `listcomps`, and `parseTree` to fix Windows failures. - - - - - 25fc9429 by Ben Gamari at 2020-03-22T22:37:47-04:00 testsuite: Update expected output on Windows - - - - - 7f58ec6d by Ben Gamari at 2020-03-22T22:37:47-04:00 testsuite: Fix TOP of T17786 - - - - - aadcd909 by GHC GitLab CI at 2020-03-22T22:37:47-04:00 testsuite: Update expected output on Windows - - - - - dc1eb10d by GHC GitLab CI at 2020-03-22T22:37:47-04:00 hadrian: Fix executable extension passed to testsuite driver - - - - - 58f62e2c by GHC GitLab CI at 2020-03-22T22:37:47-04:00 gitlab-ci: Require that Windows-hadrian job passes - - - - - 8dd2415d by Ben Gamari at 2020-03-22T22:37:47-04:00 hadrian: Eliminate redundant .exe from GHC path Previously we were invoking: bash -c "c:/GitLabRunner/builds/eEQrxK4p/0/ghc/ghc/toolchain/bin/ghc.exe.exe testsuite/mk/ghc-config.hs -o _build/test/bin/ghc-config.exe" - - - - - 373621f6 by Ben Gamari at 2020-03-22T22:37:47-04:00 Bump hsc2hs submodule - - - - - abc02b40 by Hécate at 2020-03-22T22:38:33-04:00 Annotate the non-total function in Data.Foldable as such - - - - - 19f12557 by Josef Svenningsson at 2020-03-23T14:05:33-04:00 Fix ApplicativeDo regression #17835 A previous fix for #15344 made sure that monadic 'fail' is used properly when translating ApplicativeDo. However, it didn't properly account for when a 'fail' will be inserted which resulted in some programs failing with a type error. - - - - - 2643ba46 by Paavo at 2020-03-24T08:31:32-04:00 Add example and doc for Arg (Fixes #17153) - - - - - 703221f4 by Roland Senn at 2020-03-25T14:45:04-04:00 Use export list of Main module in function TcRnDriver.hs:check_main (Fix #16453) - Provide the export list of the `Main` module as parameter to the `compiler/typecheck/TcRnDriver.hs:check_main` function. - Instead of `lookupOccRn_maybe` call the function `lookupInfoOccRn`. It returns the list `mains_all` of all the main functions in scope. - Select from this list `mains_all` all `main` functions that are in the export list of the `Main` module. - If this new list contains exactly one single `main` function, then typechecking continues. - Otherwise issue an appropriate error message. - - - - - 3e27205a by Sebastian Graf at 2020-03-25T14:45:40-04:00 Remove -fkill-absence and -fkill-one-shot flags They seem to be a benchmarking vestige of the Cardinality paper and probably shouldn't have been merged to HEAD in the first place. - - - - - 262e42aa by Peter Trommler at 2020-03-25T22:41:39-04:00 Do not panic on linker errors - - - - - 0de03cd7 by Sylvain Henry at 2020-03-25T22:42:02-04:00 DynFlags refactoring III Use Platform instead of DynFlags when possible: * `tARGET_MIN_INT` et al. replaced with `platformMinInt` et al. * no more DynFlags in PreRules: added a new `RuleOpts` datatype * don't use `wORD_SIZE` in the compiler * make `wordAlignment` use `Platform` * make `dOUBLE_SIZE` a constant Metric Decrease: T13035 T1969 - - - - - 7a04920b by Tristan Cacqueray at 2020-03-25T22:42:06-04:00 Base: fix a typo in liftA doc This change removes an extra '|' that should not be rendered in the liftA documentation. Tracking: #17929 - - - - - 1c5a15f7 by Tristan Cacqueray at 2020-03-25T22:42:06-04:00 Base: add Control.Applicative optional example This change adds an optional example. Tracking: #17929 - - - - - 6d172e63 by Tristan Cacqueray at 2020-03-25T22:42:06-04:00 Base: add markup around Except - - - - - eb2162c8 by John Ericson at 2020-03-26T12:37:08-04:00 Remove unused `ghciTablesNextToCode` from compiler proper - - - - - f51efc4b by Joachim Breitner at 2020-03-26T12:37:09-04:00 Prepare to use run-time tablesNextToCode in compiler exclusively Factor out CPP as much as possible to prepare for runtime determinattion. Progress towards #15548 - - - - - 1c446220 by Joachim Breitner at 2020-03-26T12:37:09-04:00 Use run-time tablesNextToCode in compiler exclusively (#15548) Summary: - There is no more use of the TABLES_NEXT_TO_CODE CPP macro in `compiler/`. GHCI_TABLES_NEXT_TO_CODE is also removed entirely. The field within `PlatformMisc` within `DynFlags` is used instead. - The field is still not exposed as a CLI flag. We might consider some way to ensure the right RTS / libraries are used before doing that. Original reviewers: Original subscribers: TerrorJack, rwbarton, carter Original Differential Revision: https://phabricator.haskell.org/D5082 - - - - - 1941ef4f by Sylvain Henry at 2020-03-29T17:28:51-04:00 Modules: Types (#13009) Update Haddock submodule Metric Increase: haddock.compiler - - - - - 1c7c6f1a by Sylvain Henry at 2020-03-29T17:28:51-04:00 Remove GHC.Types.Unique.Map module This module isn't used anywhere in GHC. - - - - - f1a6c73d by Sylvain Henry at 2020-03-29T17:28:51-04:00 Merge GHC.Types.CostCentre.Init into GHC.Driver.CodeOutput - - - - - 54250f2d by Simon Peyton Jones at 2020-03-29T17:29:30-04:00 Demand analysis: simplify the demand for a RHS Ticket #17932 showed that we were using a stupid demand for the RHS of a let-binding, when the result is a product. This was the result of a "fix" in 2013, which (happily) turns out to no longer be necessary. So I just deleted the code, which simplifies the demand analyser, and fixes #17932. That in turn uncovered that the anticipation of worker/wrapper in CPR analysis was inaccurate, hence the logic that decides whether to unbox an argument in WW was extracted into a function `wantToUnbox`, now consulted by CPR analysis. I tried nofib, and got 0.0% perf changes. All this came up when messing about with !2873 (ticket #17917), but is idependent of it. Unfortunately, this patch regresses #4267 and realised that it is now blocked on #16335. - - - - - 03060b2f by Ben Gamari at 2020-03-29T17:30:05-04:00 testsuite: Fix T17786 on Windows Fixes line ending normalization issue. - - - - - 1f7995ba by Ben Gamari at 2020-03-29T17:30:05-04:00 testsuite: Fix T17786 Fix missing quoting and expected exit code. - - - - - ef9c608e by Ben Gamari at 2020-03-29T17:30:05-04:00 testsuite: Mark T12971 as broken on Windows Due to #17945. - - - - - e54500c1 by Sylvain Henry at 2020-03-29T17:30:47-04:00 Store ComponentId details As far as GHC is concerned, installed package components ("units") are identified by an opaque ComponentId string provided by Cabal. But we don't want to display it to users (as it contains a hash) so GHC queries the database to retrieve some infos about the original source package (name, version, component name). This patch caches these infos in the ComponentId itself so that we don't need to provide DynFlags (which contains installed package informations) to print a ComponentId. In the future we want GHC to support several independent package states (e.g. for plugins and for target code), hence we need to avoid implicitly querying a single global package state. - - - - - 7e7cb714 by Marius Bakke at 2020-03-29T17:31:27-04:00 testsuite: Remove test that dlopens a PIE object. glibc 2.30 disallowed dlopening PIE objects, so just remove the test. Fixes #17952. - - - - - 6c8f80d8 by Andreas Klebinger at 2020-03-29T17:32:04-04:00 Correct haddocks for testBit in Data.Bits It conflated the nth bit with the bit at offset n. Now we instead give the definition in terms of `bit and `.&.` on top of clearer phrasing. - - - - - c916f190 by Andreas Klebinger at 2020-03-29T17:32:04-04:00 Apply suggestion to libraries/base/Data/Bits.hs - - - - - 64bf7f51 by Ben Gamari at 2020-03-29T17:32:41-04:00 gitlab-ci: Add FreeBSD release job - - - - - a0d8e92e by Ryan Scott at 2020-03-29T17:33:20-04:00 Run checkNewDataCon before constraint-solving newtype constructors Within `checkValidDataCon`, we used to run `checkValidType` on the argument types of a newtype constructor before running `checkNewDataCon`, which ensures that the user does not attempt non-sensical things such as newtypes with multiple arguments or constraints. This works out in most situations, but this falls over on a corner case revealed in #17955: ```hs newtype T = Coercible () T => T () ``` `checkValidType`, among other things, peforms an ambiguity check on the context of a data constructor, and that it turn invokes the constraint solver. It turns out that there is a special case in the constraint solver for representational equalities (read: `Coercible` constraints) that causes newtypes to be unwrapped (see `Note [Unwrap newtypes first]` in `TcCanonical`). This special case does not know how to cope with an ill formed newtype like `T`, so it ends up panicking. The solution is surprisingly simple: just invoke `checkNewDataCon` before `checkValidType` to ensure that the illicit newtype constructor context is detected before the constraint solver can run amok with it. Fixes #17955. - - - - - 45eb9d8c by Krzysztof Gogolewski at 2020-03-29T17:33:59-04:00 Minor cleanup - Simplify mkBuildExpr, the function newTyVars was called only on a one-element list. - TTG: use noExtCon in more places. This is more future-proof. - In zonkExpr, panic instead of printing a warning. - - - - - f024b6e3 by Sylvain Henry at 2020-03-30T12:48:39+02:00 Expect T4267 to pass Since 54250f2d8de910b094070c1b48f086030df634b1 we expected T4267 to fail, but it passes on CI. - - - - - 57b888c0 by Ryan Scott at 2020-03-31T10:54:20-04:00 Require GHC 8.8 as the minimum compiler for bootstrapping This allows us to remove several bits of CPP that are either always true or no longer reachable. As an added bonus, we no longer need to worry about importing `Control.Monad.Fail.fail` qualified to avoid clashing with `Control.Monad.fail`, since the latter is now the same as the former. - - - - - 33f09551 by Ryan Scott at 2020-03-31T10:54:57-04:00 Add regression test for #17963 The panic in #17963 happened to be fixed by commit e3c374cc5bd7eb49649b9f507f9f7740697e3f70. This patch adds a regression test to ensure that it remains fixed. Fixes #17963. - - - - - 09a36e80 by Ömer Sinan Ağacan at 2020-03-31T10:55:37-04:00 Simplify stderrSupportsAnsiColors The combinator andM is used only once, and the code is shorter and simpler if you inline it. - - - - - 95bccdd0 by Ben Gamari at 2020-03-31T10:56:19-04:00 base: Ensure that encoding global variables aren't inlined As noted in #17970, these (e.g. `getFileSystemEncoding` and `setFileSystemEncoding`) previously had unfoldings, which would break their global-ness. While not strictly necessary, I also add a NOINLINE on `initLocaleEncoding` since it is used in `System.IO`, ensuring that we only system's query the locale encoding once. Fixes #17970. - - - - - 982aaa83 by Andreas Klebinger at 2020-03-31T10:56:55-04:00 Update hadrian index revision. Required in order to build hadrian using ghc-8.10 - - - - - 4b9c5864 by Ben Gamari at 2020-03-31T10:57:32-04:00 integer-gmp: Bump version and add changelog entry - - - - - 9b39f2e6 by Ryan Scott at 2020-04-01T01:20:00-04:00 Clean up "Eta reduction for data families" Notes Before, there were two distinct Notes named "Eta reduction for data families". This renames one of them to "Implementing eta reduction for data families" to disambiguate the two and fixes references in other parts of the codebase to ensure that they are pointing to the right place. Fixes #17313. [ci skip] - - - - - 7627eab5 by Ryan Scott at 2020-04-01T01:20:38-04:00 Fix the changelog/@since information for hGetContents'/getContents'/readFile' Fixes #17979. [ci skip] - - - - - 0002db1b by Sylvain Henry at 2020-04-01T01:21:27-04:00 Kill wORDS_BIGENDIAN and replace it with platformByteOrder (#17957) Metric Decrease: T13035 T1969 - - - - - 7b217179 by Sebastian Graf at 2020-04-01T15:03:24-04:00 PmCheck: Adjust recursion depth for inhabitation test In #17977, we ran into the reduction depth limit of the typechecker. That was only a symptom of a much broader issue: The recursion depth of the coverage checker for trying to instantiate strict fields in the `nonVoid` test was far too high (100, the `defaultMaxTcBound`). As a result, we were performing quite poorly on `T17977`. Short of a proper termination analysis to prove emptyness of a type, we just arbitrarily default to a much lower recursion limit of 3. Fixes #17977. - - - - - 3c09f636 by Andreas Klebinger at 2020-04-01T15:03:59-04:00 Make hadrian pass on the no-colour setting to GHC. Fixes #17983. - - - - - b943b25d by Simon Peyton Jones at 2020-04-02T01:45:58-04:00 Re-engineer the binder-swap transformation The binder-swap transformation is implemented by the occurrence analyser -- see Note [Binder swap] in OccurAnal. However it had a very nasty corner in it, for the case where the case scrutinee was a GlobalId. This led to trouble and hacks, and ultimately to #16296. This patch re-engineers how the occurrence analyser implements the binder-swap, by actually carrying out a substitution rather than by adding a let-binding. It's all described in Note [The binder-swap substitution]. I did a few other things along the way * Fix a bug in StgCse, which could allow a loop breaker to be CSE'd away. See Note [Care with loop breakers] in StgCse. I think it can only show up if occurrence analyser sets up bad loop breakers, but still. * Better commenting in SimplUtils.prepareAlts * A little refactoring in CoreUnfold; nothing significant e.g. rename CoreUnfold.mkTopUnfolding to mkFinalUnfolding * Renamed CoreSyn.isFragileUnfolding to hasCoreUnfolding * Move mkRuleInfo to CoreFVs We observed respectively 4.6% and 5.9% allocation decreases for the following tests: Metric Decrease: T9961 haddock.base - - - - - 42d68364 by Sebastian Graf at 2020-04-02T01:46:34-04:00 Preserve precise exceptions in strictness analysis Fix #13380 and #17676 by 1. Changing `raiseIO#` to have `topDiv` instead of `botDiv` 2. Give it special treatment in `Simplifier.Util.mkArgInfo`, treating it as if it still had `botDiv`, to recover dead code elimination. This is the first commit of the plan outlined in https://gitlab.haskell.org/ghc/ghc/-/merge_requests/2525#note_260886. - - - - - 0a88dd11 by Ömer Sinan Ağacan at 2020-04-02T01:47:25-04:00 Fix a pointer format string in RTS - - - - - 5beac042 by Ömer Sinan Ağacan at 2020-04-02T01:48:05-04:00 Remove unused closure stg_IND_direct - - - - - 88f38b03 by Ben Gamari at 2020-04-02T01:48:42-04:00 Session: Memoize stderrSupportsAnsiColors Not only is this a reasonable efficiency measure but it avoids making reentrant calls into ncurses, which is not thread-safe. See #17922. - - - - - 27740f24 by Ryan Scott at 2020-04-02T01:49:21-04:00 Make Hadrian build with Cabal-3.2 GHC 8.10 ships with `Cabal-3.2.0.0`, so it would be convenient to make Hadrian supporting building against 3.2.* instead of having to rebuild the entirety of `Cabal-3.0.0.0`. There is one API change in `Cabal-3.2.*` that affects Hadrian: the `synopsis` and `description` functions now return `ShortText` instead of `String`. Since Hadrian manipulates these `String`s in various places, I found that the simplest fix was to use CPP to convert `ShortText` to `String`s where appropriate. - - - - - 49802002 by Sylvain Henry at 2020-04-02T01:50:00-04:00 Update Stack resolver for hadrian/build-stack Broken by 57b888c0e90be7189285a6b078c30b26d0923809 - - - - - 30a63e79 by Ryan Scott at 2020-04-02T01:50:36-04:00 Fix two ASSERT buglets in reifyDataCon Two `ASSERT`s in `reifyDataCon` were always using `arg_tys`, but `arg_tys` is not meaningful for GADT constructors. In fact, it's worse than non-meaningful, since using `arg_tys` when reifying a GADT constructor can lead to failed `ASSERT`ions, as #17305 demonstrates. This patch applies the simplest possible fix to the immediate problem. The `ASSERT`s now use `r_arg_tys` instead of `arg_tys`, as the former makes sure to give something meaningful for GADT constructors. This makes the panic go away at the very least. There is still an underlying issue with the way the internals of `reifyDataCon` work, as described in https://gitlab.haskell.org/ghc/ghc/issues/17305#note_227023, but we leave that as future work, since fixing the underlying issue is much trickier (see https://gitlab.haskell.org/ghc/ghc/issues/17305#note_227087). - - - - - ef7576c4 by Zubin Duggal at 2020-04-03T06:24:56-04:00 Add outputable instances for the types in GHC.Iface.Ext.Types, add -ddump-hie flag to dump pretty printed contents of the .hie file Metric Increase: hie002 Because of the regression on i386: compile_time/bytes allocated increased from i386-linux-deb9 baseline @ HEAD~10: Expected hie002 (normal) compile_time/bytes allocated: 583014888.0 +/-10% Lower bound hie002 (normal) compile_time/bytes allocated: 524713399 Upper bound hie002 (normal) compile_time/bytes allocated: 641316377 Actual hie002 (normal) compile_time/bytes allocated: 877986292 Deviation hie002 (normal) compile_time/bytes allocated: 50.6 % *** unexpected stat test failure for hie002(normal) - - - - - 9462452a by Andreas Klebinger at 2020-04-03T06:25:33-04:00 Improve and refactor StgToCmm codegen for DataCons. We now differentiate three cases of constructor bindings: 1)Bindings which we can "replace" with a reference to an existing closure. Reference the replacement closure when accessing the binding. 2)Bindings which we can "replace" as above. But we still generate a closure which will be referenced by modules importing this binding. 3)For any other binding generate a closure. Then reference it. Before this patch 1) did only apply to local bindings and we didn't do 2) at all. - - - - - a214d214 by Moritz Bruder at 2020-04-03T06:26:11-04:00 Add singleton to NonEmpty in libraries/base This adds a definition to construct a singleton non-empty list (Data.List.NonEmpty) according to issue #17851. - - - - - f7597aa0 by Sylvain Henry at 2020-04-03T06:26:54-04:00 Testsuite: measure compiler stats for T16190 We were mistakenly measuring program stats - - - - - a485c3c4 by Sylvain Henry at 2020-04-03T06:26:54-04:00 Move blob handling into StgToCmm Move handling of big literal strings from CmmToAsm to StgToCmm. It avoids the use of `sdocWithDynFlags` (cf #10143). We might need to move this handling even higher in the pipeline in the future (cf #17960): this patch will make it easier. - - - - - cc2918a0 by Sylvain Henry at 2020-04-03T06:26:54-04:00 Refactor CmmStatics In !2959 we noticed that there was some redundant code (in GHC.Cmm.Utils and GHC.Cmm.StgToCmm.Utils) used to deal with `CmmStatics` datatype (before SRT generation) and `RawCmmStatics` datatype (after SRT generation). This patch removes this redundant code by using a single GADT for (Raw)CmmStatics. - - - - - 9e60273d by Maxim Koltsov at 2020-04-03T06:27:32-04:00 Fix haddock formatting in Control.Monad.ST.Lazy.Imp.hs - - - - - 1b7e8a94 by Andreas Klebinger at 2020-04-03T06:28:08-04:00 Turn newlines into spaces for hadrian/ghci. The newlines break the command on windows. - - - - - 4291bdda by Simon Peyton Jones at 2020-04-03T06:28:44-04:00 Major improvements to the specialiser This patch is joint work of Alexis King and Simon PJ. It does some significant refactoring of the type-class specialiser. Main highlights: * We can specialise functions with types like f :: Eq a => a -> Ord b => b => blah where the classes aren't all at the front (#16473). Here we can correctly specialise 'f' based on a call like f @Int @Bool dEqInt x dOrdBool This change really happened in an earlier patch commit 2d0cf6252957b8980d89481ecd0b79891da4b14b Author: Sandy Maguire <sandy at sandymaguire.me> Date: Thu May 16 12:12:10 2019 -0400 work that this new patch builds directly on that work, and refactors it a bit. * We can specialise functions with implicit parameters (#17930) g :: (?foo :: Bool, Show a) => a -> String Previously we could not, but now they behave just like a non-class argument as in 'f' above. * We can specialise under-saturated calls, where some (but not all of the dictionary arguments are provided (#17966). For example, we can specialise the above 'f' based on a call map (f @Int dEqInt) xs even though we don't (and can't) give Ord dictionary. This may sound exotic, but #17966 is a program from the wild, and showed significant perf loss for functions like f, if you need saturation of all dictionaries. * We fix a buglet in which a floated dictionary had a bogus demand (#17810), by using zapIdDemandInfo in the NonRec case of specBind. * A tiny side benefit: we can drop dead arguments to specialised functions; see Note [Drop dead args from specialisations] * Fixed a bug in deciding what dictionaries are "interesting"; see Note [Keep the old dictionaries interesting] This is all achieved by by building on Sandy Macguire's work in defining SpecArg, which mkCallUDs uses to describe the arguments of the call. Main changes: * Main work is in specHeader, which marched down the [InBndr] from the function definition and the [SpecArg] from the call site, together. * specCalls no longer has an arity check; the entire mechanism now handles unders-saturated calls fine. * mkCallUDs decides on an argument-by-argument basis whether to specialise a particular dictionary argument; this is new. See mk_spec_arg in mkCallUDs. It looks as if there are many more lines of code, but I think that all the extra lines are comments! - - - - - 40a85563 by Ömer Sinan Ağacan at 2020-04-03T18:26:19+03:00 Revert accidental change in 9462452 [ci skip] - - - - - bd75e5da by Ryan Scott at 2020-04-04T07:07:58-04:00 Enable ImpredicativeTypes internally when typechecking selector bindings This is necessary for certain record selectors with higher-rank types, such as the examples in #18005. See `Note [Impredicative record selectors]` in `TcTyDecls`. Fixes #18005. - - - - - dcfe29c8 by Ömer Sinan Ağacan at 2020-04-06T13:16:08-04:00 Don't override proc CafInfos in ticky builds Fixes #17947 When we have a ticky label for a proc, IdLabels for the ticky counter and proc entry share the same Name. This caused overriding proc CafInfos with the ticky CafInfos (i.e. NoCafRefs) during SRT analysis. We now ignore the ticky labels when building SRTMaps. This makes sense because: - When building the current module they don't need to be in SRTMaps as they're initialized as non-CAFFY (see mkRednCountsLabel), so they don't take part in the dependency analysis and they're never added to SRTs. (Reminder: a "dependency" in the SRT analysis is a CAFFY dependency, non-CAFFY uses are not considered as dependencies for the algorithm) - They don't appear in the interfaces as they're not exported, so it doesn't matter for cross-module concerns whether they're in the SRTMap or not. See also the new Note [Ticky labels in SRT analysis]. - - - - - cec2c71f by Simon Peyton Jones at 2020-04-06T13:16:44-04:00 Fix an tricky specialiser loop Issue #17151 was a very tricky example of a bug in which the specialiser accidentally constructs a recurive dictionary, so that everything turns into bottom. I have fixed variants of this bug at least twice before: see Note [Avoiding loops]. It was a bit of a struggle to isolate the problem, greatly aided by the work that Alexey Kuleshevich did in distilling a test case. Once I'd understood the problem, it was not difficult to fix, though it did lead me a bit of refactoring in specImports. - - - - - e850d14f by Simon Peyton Jones at 2020-04-06T13:16:44-04:00 Refactoring only This refactors DictBinds into a data type rather than a pair. No change in behaviour, just better code - - - - - f38e8d61 by Daniel Gröber at 2020-04-07T02:00:05-04:00 rts: ProfHeap: Fix memory leak when not compiled with profiling If we're doing heap profiling on an unprofiled executable we keep allocating new space in initEra via nextEra on each profiler run but we don't have a corresponding freeEra call. We do free the last era in endHeapProfiling but previous eras will have been overwritten by initEra and will never get free()ed. Metric Decrease: space_leak_001 - - - - - bcd66859 by Sebastian Graf at 2020-04-07T02:00:41-04:00 Re-export GHC.Magic.noinline from base - - - - - 3d2991f8 by Ben Gamari at 2020-04-07T18:36:09-04:00 simplifier: Kill off ufKeenessFactor We used to have another factor, ufKeenessFactor, which would scale the discounts before they were subtracted from the size. This was justified with the following comment: -- We multiple the raw discounts (args_discount and result_discount) -- ty opt_UnfoldingKeenessFactor because the former have to do with -- *size* whereas the discounts imply that there's some extra -- *efficiency* to be gained (e.g. beta reductions, case reductions) -- by inlining. However, this is highly suspect since it means that we subtract a *scaled* size from an absolute size, resulting in crazy (e.g. negative) scores in some cases (#15304). We consequently killed off ufKeenessFactor and bumped up the ufUseThreshold to compensate. Adjustment of unfolding use threshold ===================================== Since this removes a discount from our inlining heuristic, I revisited our default choice of -funfolding-use-threshold to minimize the change in overall inlining behavior. Specifically, I measured runtime allocations and executable size of nofib and the testsuite performance tests built using compilers (and core libraries) built with several values of -funfolding-use-threshold. This comes as a result of a quantitative comparison of testsuite performance and code size as a function of ufUseThreshold, comparing GHC trees using values of 50, 60, 70, 80, 90, and 100. The test set consisted of nofib and the testsuite performance tests. A full summary of these measurements are found in the description of !2608 Comparing executable sizes (relative to the base commit) across all nofib tests, we see that sizes are similar to the baseline: gmean min max median thresh 50 -6.36% -7.04% -4.82% -6.46% 60 -5.04% -5.97% -3.83% -5.11% 70 -2.90% -3.84% -2.31% -2.92% 80 -0.75% -2.16% -0.42% -0.73% 90 +0.24% -0.41% +0.55% +0.26% 100 +1.36% +0.80% +1.64% +1.37% baseline +0.00% +0.00% +0.00% +0.00% Likewise, looking at runtime allocations we see that 80 gives slightly better optimisation than the baseline: gmean min max median thresh 50 +0.16% -0.16% +4.43% +0.00% 60 +0.09% -0.00% +3.10% +0.00% 70 +0.04% -0.09% +2.29% +0.00% 80 +0.02% -1.17% +2.29% +0.00% 90 -0.02% -2.59% +1.86% +0.00% 100 +0.00% -2.59% +7.51% -0.00% baseline +0.00% +0.00% +0.00% +0.00% Finally, I had to add a NOINLINE in T4306 to ensure that `upd` is worker-wrappered as the test expects. This makes me wonder whether the inlining heuristic is now too liberal as `upd` is quite a large function. The same measure was taken in T12600. Wall clock time compiling Cabal with -O0 thresh 50 60 70 80 90 100 baseline build-Cabal 93.88 89.58 92.59 90.09 100.26 94.81 89.13 Also, this change happens to avoid the spurious test output in `plugin-recomp-change` and `plugin-recomp-change-prof` (see #17308). Metric Decrease: hie002 T12234 T13035 T13719 T14683 T4801 T5631 T5642 T9020 T9872d T9961 Metric Increase: T12150 T12425 T13701 T14697 T15426 T1969 T3064 T5837 T6048 T9203 T9872a T9872b T9872c T9872d haddock.Cabal haddock.base haddock.compiler - - - - - 255418da by Sylvain Henry at 2020-04-07T18:36:49-04:00 Modules: type-checker (#13009) Update Haddock submodule - - - - - 04b6cf94 by Ryan Scott at 2020-04-07T19:43:20-04:00 Make NoExtCon fields strict This changes every unused TTG extension constructor to be strict in its field so that the pattern-match coverage checker is smart enough any such constructors are unreachable in pattern matches. This lets us remove nearly every use of `noExtCon` in the GHC API. The only ones we cannot remove are ones underneath uses of `ghcPass`, but that is only because GHC 8.8's and 8.10's coverage checkers weren't smart enough to perform this kind of reasoning. GHC HEAD's coverage checker, on the other hand, _is_ smart enough, so we guard these uses of `noExtCon` with CPP for now. Bumps the `haddock` submodule. Fixes #17992. - - - - - 7802fa17 by Ryan Scott at 2020-04-08T16:43:44-04:00 Handle promoted data constructors in typeToLHsType correctly Instead of using `nlHsTyVar`, which hardcodes `NotPromoted`, have `typeToLHsType` pick between `Promoted` and `NotPromoted` by checking if a type constructor is promoted using `isPromotedDataCon`. Fixes #18020. - - - - - ce481361 by Ben Gamari at 2020-04-09T16:17:21-04:00 hadrian: Use --export-dynamic when linking iserv As noticed in #17962, the make build system currently does this (see 3ce0e0ba) but the change was never ported to Hadrian. - - - - - fa66f143 by Ben Gamari at 2020-04-09T16:17:21-04:00 iserv: Don't pass --export-dynamic on FreeBSD This is definitely a hack but it's probably the best we can do for now. Hadrian does the right thing here by passing --export-dynamic only to the linker. - - - - - 39075176 by Ömer Sinan Ağacan at 2020-04-09T16:18:00-04:00 Fix CNF handling in compacting GC Fixes #17937 Previously compacting GC simply ignored CNFs. This is mostly fine as most (see "What about small compacts?" below) CNF objects don't have outgoing pointers, and are "large" (allocated in large blocks) and large objects are not moved or compacted. However if we do GC *during* sharing-preserving compaction then the CNF will have a hash table mapping objects that have been moved to the CNF to their location in the CNF, to be able to preserve sharing. This case is handled in the copying collector, in `scavenge_compact`, where we evacuate hash table entries and then rehash the table. Compacting GC ignored this case. We now visit CNFs in all generations when threading pointers to the compacted heap and thread hash table keys. A visited CNF is added to the list `nfdata_chain`. After compaction is done, we re-visit the CNFs in that list and rehash the tables. The overhead is minimal: the list is static in `Compact.c`, and link field is added to `StgCompactNFData` closure. Programs that don't use CNFs should not be affected. To test this CNF tests are now also run in a new way 'compacting_gc', which just passes `-c` to the RTS, enabling compacting GC for the oldest generation. Before this patch the result would be: Unexpected failures: compact_gc.run compact_gc [bad exit code (139)] (compacting_gc) compact_huge_array.run compact_huge_array [bad exit code (1)] (compacting_gc) With this patch all tests pass. I can also pass `-c -DS` without any failures. What about small compacts? Small CNFs are still not handled by the compacting GC. However so far I'm unable to write a test that triggers a runtime panic ("update_fwd: unknown/strange object") by allocating a small CNF in a compated heap. It's possible that I'm missing something and it's not possible to have a small CNF. NoFib Results: -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS +0.1% 0.0% 0.0% +0.0% +0.0% CSD +0.1% 0.0% 0.0% 0.0% 0.0% FS +0.1% 0.0% 0.0% 0.0% 0.0% S +0.1% 0.0% 0.0% 0.0% 0.0% VS +0.1% 0.0% 0.0% 0.0% 0.0% VSD +0.1% 0.0% +0.0% +0.0% -0.0% VSM +0.1% 0.0% +0.0% -0.0% 0.0% anna +0.0% 0.0% -0.0% -0.0% -0.0% ansi +0.1% 0.0% +0.0% +0.0% +0.0% atom +0.1% 0.0% +0.0% +0.0% +0.0% awards +0.1% 0.0% +0.0% +0.0% +0.0% banner +0.1% 0.0% +0.0% +0.0% +0.0% bernouilli +0.1% 0.0% 0.0% -0.0% +0.0% binary-trees +0.1% 0.0% -0.0% -0.0% 0.0% boyer +0.1% 0.0% +0.0% +0.0% +0.0% boyer2 +0.1% 0.0% +0.0% +0.0% +0.0% bspt +0.1% 0.0% -0.0% -0.0% -0.0% cacheprof +0.1% 0.0% -0.0% -0.0% -0.0% calendar +0.1% 0.0% +0.0% +0.0% +0.0% cichelli +0.1% 0.0% +0.0% +0.0% +0.0% circsim +0.1% 0.0% +0.0% +0.0% +0.0% clausify +0.1% 0.0% -0.0% +0.0% +0.0% comp_lab_zift +0.1% 0.0% +0.0% +0.0% +0.0% compress +0.1% 0.0% +0.0% +0.0% 0.0% compress2 +0.1% 0.0% -0.0% 0.0% 0.0% constraints +0.1% 0.0% +0.0% +0.0% +0.0% cryptarithm1 +0.1% 0.0% +0.0% +0.0% +0.0% cryptarithm2 +0.1% 0.0% +0.0% +0.0% +0.0% cse +0.1% 0.0% +0.0% +0.0% +0.0% digits-of-e1 +0.1% 0.0% +0.0% -0.0% -0.0% digits-of-e2 +0.1% 0.0% -0.0% -0.0% -0.0% dom-lt +0.1% 0.0% +0.0% +0.0% +0.0% eliza +0.1% 0.0% +0.0% +0.0% +0.0% event +0.1% 0.0% +0.0% +0.0% +0.0% exact-reals +0.1% 0.0% +0.0% +0.0% +0.0% exp3_8 +0.1% 0.0% +0.0% -0.0% 0.0% expert +0.1% 0.0% +0.0% +0.0% +0.0% fannkuch-redux +0.1% 0.0% -0.0% 0.0% 0.0% fasta +0.1% 0.0% -0.0% +0.0% +0.0% fem +0.1% 0.0% -0.0% +0.0% 0.0% fft +0.1% 0.0% -0.0% +0.0% +0.0% fft2 +0.1% 0.0% +0.0% +0.0% +0.0% fibheaps +0.1% 0.0% +0.0% +0.0% +0.0% fish +0.1% 0.0% +0.0% +0.0% +0.0% fluid +0.0% 0.0% +0.0% +0.0% +0.0% fulsom +0.1% 0.0% -0.0% +0.0% 0.0% gamteb +0.1% 0.0% +0.0% +0.0% 0.0% gcd +0.1% 0.0% +0.0% +0.0% +0.0% gen_regexps +0.1% 0.0% -0.0% +0.0% 0.0% genfft +0.1% 0.0% +0.0% +0.0% +0.0% gg +0.1% 0.0% 0.0% +0.0% +0.0% grep +0.1% 0.0% -0.0% +0.0% +0.0% hidden +0.1% 0.0% +0.0% -0.0% 0.0% hpg +0.1% 0.0% -0.0% -0.0% -0.0% ida +0.1% 0.0% +0.0% +0.0% +0.0% infer +0.1% 0.0% +0.0% 0.0% -0.0% integer +0.1% 0.0% +0.0% +0.0% +0.0% integrate +0.1% 0.0% -0.0% -0.0% -0.0% k-nucleotide +0.1% 0.0% +0.0% +0.0% 0.0% kahan +0.1% 0.0% +0.0% +0.0% +0.0% knights +0.1% 0.0% -0.0% -0.0% -0.0% lambda +0.1% 0.0% +0.0% +0.0% -0.0% last-piece +0.1% 0.0% +0.0% 0.0% 0.0% lcss +0.1% 0.0% +0.0% +0.0% 0.0% life +0.1% 0.0% -0.0% +0.0% +0.0% lift +0.1% 0.0% +0.0% +0.0% +0.0% linear +0.1% 0.0% -0.0% +0.0% 0.0% listcompr +0.1% 0.0% +0.0% +0.0% +0.0% listcopy +0.1% 0.0% +0.0% +0.0% +0.0% maillist +0.1% 0.0% +0.0% -0.0% -0.0% mandel +0.1% 0.0% +0.0% +0.0% 0.0% mandel2 +0.1% 0.0% +0.0% +0.0% +0.0% mate +0.1% 0.0% +0.0% 0.0% +0.0% minimax +0.1% 0.0% -0.0% 0.0% -0.0% mkhprog +0.1% 0.0% +0.0% +0.0% +0.0% multiplier +0.1% 0.0% +0.0% 0.0% 0.0% n-body +0.1% 0.0% +0.0% +0.0% +0.0% nucleic2 +0.1% 0.0% +0.0% +0.0% +0.0% para +0.1% 0.0% 0.0% +0.0% +0.0% paraffins +0.1% 0.0% +0.0% -0.0% 0.0% parser +0.1% 0.0% -0.0% -0.0% -0.0% parstof +0.1% 0.0% +0.0% +0.0% +0.0% pic +0.1% 0.0% -0.0% -0.0% 0.0% pidigits +0.1% 0.0% +0.0% -0.0% -0.0% power +0.1% 0.0% +0.0% +0.0% +0.0% pretty +0.1% 0.0% -0.0% -0.0% -0.1% primes +0.1% 0.0% -0.0% -0.0% -0.0% primetest +0.1% 0.0% -0.0% -0.0% -0.0% prolog +0.1% 0.0% -0.0% -0.0% -0.0% puzzle +0.1% 0.0% -0.0% -0.0% -0.0% queens +0.1% 0.0% +0.0% +0.0% +0.0% reptile +0.1% 0.0% -0.0% -0.0% +0.0% reverse-complem +0.1% 0.0% +0.0% 0.0% -0.0% rewrite +0.1% 0.0% -0.0% -0.0% -0.0% rfib +0.1% 0.0% +0.0% +0.0% +0.0% rsa +0.1% 0.0% -0.0% +0.0% -0.0% scc +0.1% 0.0% -0.0% -0.0% -0.1% sched +0.1% 0.0% +0.0% +0.0% +0.0% scs +0.1% 0.0% +0.0% +0.0% +0.0% simple +0.1% 0.0% -0.0% -0.0% -0.0% solid +0.1% 0.0% +0.0% +0.0% +0.0% sorting +0.1% 0.0% -0.0% -0.0% -0.0% spectral-norm +0.1% 0.0% +0.0% +0.0% +0.0% sphere +0.1% 0.0% -0.0% -0.0% -0.0% symalg +0.1% 0.0% -0.0% -0.0% -0.0% tak +0.1% 0.0% +0.0% +0.0% +0.0% transform +0.1% 0.0% +0.0% +0.0% +0.0% treejoin +0.1% 0.0% +0.0% -0.0% -0.0% typecheck +0.1% 0.0% +0.0% +0.0% +0.0% veritas +0.0% 0.0% +0.0% +0.0% +0.0% wang +0.1% 0.0% 0.0% +0.0% +0.0% wave4main +0.1% 0.0% +0.0% +0.0% +0.0% wheel-sieve1 +0.1% 0.0% +0.0% +0.0% +0.0% wheel-sieve2 +0.1% 0.0% +0.0% +0.0% +0.0% x2n1 +0.1% 0.0% +0.0% +0.0% +0.0% -------------------------------------------------------------------------------- Min +0.0% 0.0% -0.0% -0.0% -0.1% Max +0.1% 0.0% +0.0% +0.0% +0.0% Geometric Mean +0.1% -0.0% -0.0% -0.0% -0.0% Bumping numbers of nonsensical perf tests: Metric Increase: T12150 T12234 T12425 T13035 T5837 T6048 It's simply not possible for this patch to increase allocations, and I've wasted enough time on these test in the past (see #17686). I think these tests should not be perf tests, but for now I'll bump the numbers. - - - - - dce50062 by Sylvain Henry at 2020-04-09T16:18:44-04:00 Rts: show errno on failure (#18033) - - - - - 045139f4 by Hécate at 2020-04-09T23:10:44-04:00 Add an example to liftIO and explain its purpose - - - - - 101fab6e by Sebastian Graf at 2020-04-09T23:11:21-04:00 Special case `isConstraintKindCon` on `AlgTyCon` Previously, the `tyConUnique` record selector would unfold into a huge case expression that would be inlined in all call sites, such as the `INLINE`-annotated `coreView`, see #18026. `constraintKindTyConKey` only occurs as the `Unique` of an `AlgTyCon` anyway, so we can make the code a lot more compact, but have to move it to GHC.Core.TyCon. Metric Decrease: T12150 T12234 - - - - - f5212dfc by Sebastian Graf at 2020-04-09T23:11:57-04:00 DmdAnal: No need to attach a StrictSig to DataCon workers In GHC.Types.Id.Make we were giving a strictness signature to every data constructor wrapper Id that we weren't looking at in demand analysis anyway. We used to use its CPR info, but that has its own CPR signature now. `Note [Data-con worker strictness]` then felt very out of place, so I moved it to GHC.Core.DataCon. - - - - - 75a185dc by Sylvain Henry at 2020-04-09T23:12:37-04:00 Hadrian: fix --summary - - - - - 723062ed by Ömer Sinan Ağacan at 2020-04-10T09:18:14+03:00 testsuite: Move no_lint to the top level, tweak hie002 - We don't want to benchmark linting so disable lints in hie002 perf test - Move no_lint to the top-level to be able to use it in tests other than those in `testsuite/tests/perf/compiler`. - Filter out -dstg-lint in no_lint. - hie002 allocation numbers on 32-bit are unstable, so skip it on 32-bit Metric Decrease: hie002 ManyConstructors T12150 T12234 T13035 T1969 T4801 T9233 T9961 - - - - - bcafaa82 by Peter Trommler at 2020-04-10T19:29:33-04:00 Testsuite: mark T11531 fragile The test depends on a link editor allowing undefined symbols in an ELF shared object. This is the standard but it seems some distributions patch their link editor. See the report by @hsyl20 in #11531. Fixes #11531 - - - - - 0889f5ee by Takenobu Tani at 2020-04-12T11:44:52+09:00 testsuite: Fix comment for a language extension [skip ci] - - - - - cd4f92b5 by Simon Peyton Jones at 2020-04-12T11:20:58-04:00 Significant refactor of Lint This refactoring of Lint was triggered by #17923, which is fixed by this patch. The main change is this. Instead of lintType :: Type -> LintM LintedKind we now have lintType :: Type -> LintM LintedType Previously, all of typeKind was effectively duplicate in lintType. Moreover, since we have an ambient substitution, we still had to apply the substition here and there, sometimes more than once. It was all very tricky, in the end, and made my head hurt. Now, lintType returns a fully linted type, with all substitutions performed on it. This is much simpler. The same thing is needed for Coercions. Instead of lintCoercion :: OutCoercion -> LintM (LintedKind, LintedKind, LintedType, LintedType, Role) we now have lintCoercion :: Coercion -> LintM LintedCoercion Much simpler! The code is shorter and less bug-prone. There are a lot of knock on effects. But life is now better. Metric Decrease: T1969 - - - - - 0efaf301 by Josh Meredith at 2020-04-12T11:21:34-04:00 Implement extensible interface files - - - - - 54ca66a7 by Ryan Scott at 2020-04-12T11:22:10-04:00 Use conLikeUserTyVarBinders to quantify field selector types This patch: 1. Writes up a specification for how the types of top-level field selectors should be determined in a new section of the GHC User's Guide, and 2. Makes GHC actually implement that specification by using `conLikeUserTyVarBinders` in `mkOneRecordSelector` to preserve the order and specificity of type variables written by the user. Fixes #18023. - - - - - 35799dda by Ben Gamari at 2020-04-12T11:22:50-04:00 hadrian: Don't --export-dynamic on Darwin When fixing #17962 I neglected to consider that --export-dynamic is only supported on ELF platforms. - - - - - e8029816 by Alexis King at 2020-04-12T11:23:27-04:00 Add an INLINE pragma to Control.Category.>>> This fixes #18013 by adding INLINE pragmas to both Control.Category.>>> and GHC.Desugar.>>>. The functional change in this patch is tiny (just two lines of pragmas!), but an accompanying Note explains in gory detail what’s going on. - - - - - 0da186c1 by Krzysztof Gogolewski at 2020-04-14T07:55:20-04:00 Change zipWith to zipWithEqual in a few places - - - - - 074c1ccd by Andreas Klebinger at 2020-04-14T07:55:55-04:00 Small change to the windows ticker. We already have a function to go from time to ms so use it. Also expand on the state of timer resolution. - - - - - b69cc884 by Alp Mestanogullari at 2020-04-14T07:56:38-04:00 hadrian: get rid of unnecessary levels of nesting in source-dist - - - - - d0c3b069 by Julien Debon at 2020-04-14T07:57:16-04:00 doc (Foldable): Add examples to Data.Foldable See #17929 - - - - - 5b08e0c0 by Ben Gamari at 2020-04-14T23:28:20-04:00 StgCRun: Enable unwinding only on Linux It's broken on macOS due and SmartOS due to assembler differences (#15207) so let's be conservative in enabling it. Also, refactor things to make the intent clearer. - - - - - 27cc2e7b by Ben Gamari at 2020-04-14T23:28:57-04:00 rts: Don't mark evacuate_large as inline This function has two callsites and is quite large. GCC consequently decides not to inline and warns instead. Given the situation, I can't blame it. Let's just remove the inline specifier. - - - - - 9853fc5e by Ben Gamari at 2020-04-14T23:29:48-04:00 base: Enable large file support for OFD locking impl. Not only is this a good idea in general but this should also avoid issue #17950 by ensuring that off_t is 64-bits. - - - - - 7b41f21b by Matthew Pickering at 2020-04-14T23:30:24-04:00 Hadrian: Make -i paths absolute The primary reason for this change is that ghcide does not work with relative paths. It also matches what cabal and stack do, they always pass absolute paths. - - - - - 41230e26 by Daniel Gröber at 2020-04-14T23:31:01-04:00 Zero out pinned block alignment slop when profiling The heap profiler currently cannot traverse pinned blocks because of alignment slop. This used to just be a minor annoyance as the whole block is accounted into a special cost center rather than the respective object's CCS, cf. #7275. However for the new root profiler we would like to be able to visit _every_ closure on the heap. We need to do this so we can get rid of the current 'flip' bit hack in the heap traversal code. Since info pointers are always non-zero we can in principle skip all the slop in the profiler if we can rely on it being zeroed. This assumption caused problems in the past though, commit a586b33f8e ("rts: Correct handling of LARGE ARR_WORDS in LDV profiler"), part of !1118, tried to use the same trick for BF_LARGE objects but neglected to take into account that shrink*Array# functions don't ensure that slop is zeroed when not compiling with profiling. Later, commit 0c114c6599 ("Handle large ARR_WORDS in heap census (fix as we will only be assuming slop is zeroed when profiling is on. This commit also reduces the ammount of slop we introduce in the first place by calculating the needed alignment before doing the allocation for small objects where we know the next available address. For large objects we don't know how much alignment we'll have to do yet since those details are hidden behind the allocateMightFail function so there we continue to allocate the maximum additional words we'll need to do the alignment. So we don't have to duplicate all this logic in the cmm code we pull it into the RTS allocatePinned function instead. Metric Decrease: T7257 haddock.Cabal haddock.base - - - - - 15fa9bd6 by Daniel Gröber at 2020-04-14T23:31:01-04:00 rts: Expand and add more notes regarding slop - - - - - caf3f444 by Daniel Gröber at 2020-04-14T23:31:01-04:00 rts: allocatePinned: Fix confusion about word/byte units - - - - - c3c0f662 by Daniel Gröber at 2020-04-14T23:31:01-04:00 rts: Underline some Notes as is conventional - - - - - e149dea9 by Daniel Gröber at 2020-04-14T23:31:38-04:00 rts: Fix nomenclature in OVERWRITING_CLOSURE macros The additional commentary introduced by commit 8916e64e5437 ("Implement shrinkSmallMutableArray# and resizeSmallMutableArray#.") unfortunately got this wrong. We set 'prim' to true in overwritingClosureOfs because we _don't_ want to call LDV_recordDead(). The reason is because of this "inherently used" distinction made in the LDV profiler so I rename the variable to be more appropriate. - - - - - 1dd3d18c by Daniel Gröber at 2020-04-14T23:31:38-04:00 Remove call to LDV_RECORD_CREATE for array resizing - - - - - 19de2fb0 by Daniel Gröber at 2020-04-14T23:31:38-04:00 rts: Assert LDV_recordDead is not called for inherently used closures The comments make it clear LDV_recordDead should not be called for inhererently used closures, so add an assertion to codify this fact. - - - - - 0b934e30 by Ryan Scott at 2020-04-14T23:32:14-04:00 Bump template-haskell version to 2.17.0.0 This requires bumping the `exceptions` and `text` submodules to bring in commits that bump their respective upper version bounds on `template-haskell`. Fixes #17645. Fixes #17696. Note that the new `text` commit includes a fair number of additions to the Haddocks in that library. As a result, Haddock has to do more work during the `haddock.Cabal` test case, increasing the number of allocations it requires. Therefore, ------------------------- Metric Increase: haddock.Cabal ------------------------- - - - - - 22cc8e51 by Ryan Scott at 2020-04-15T17:48:47-04:00 Fix #18052 by using pprPrefixOcc in more places This fixes several small oversights in the choice of pretty-printing function to use. Fixes #18052. - - - - - ec77b2f1 by Daniel Gröber at 2020-04-15T17:49:24-04:00 rts: ProfHeap: Fix wrong time in last heap profile sample We've had this longstanding issue in the heap profiler, where the time of the last sample in the profile is sometimes way off causing the rendered graph to be quite useless for long runs. It seems to me the problem is that we use mut_user_time() for the last sample as opposed to getRTSStats(), which we use when calling heapProfile() in GC.c. The former is equivalent to getProcessCPUTime() but the latter does some additional stuff: getProcessCPUTime() - end_init_cpu - stats.gc_cpu_ns - stats.nonmoving_gc_cpu_ns So to fix this just use getRTSStats() in both places. - - - - - 85fc32f0 by Sylvain Henry at 2020-04-17T12:45:25-04:00 Hadrian: fix dyn_o/dyn_hi rule (#17534) - - - - - bfde3b76 by Ryan Scott at 2020-04-17T12:46:02-04:00 Fix #18065 by fixing an InstCo oversight in Core Lint There was a small thinko in Core Lint's treatment of `InstCo` coercions that ultimately led to #18065. The fix: add an apostrophe. That's it! Fixes #18065. Co-authored-by: Simon Peyton Jones <simonpj at microsoft.com> - - - - - a05348eb by Cale Gibbard at 2020-04-17T13:08:47-04:00 Change the fail operator argument of BindStmt to be a Maybe Don't use noSyntaxExpr for it. There is no good way to defensively case on that, nor is it clear one ought to do so. - - - - - 79e27144 by John Ericson at 2020-04-17T13:08:47-04:00 Use trees that grow for rebindable operators for `<-` binds Also add more documentation. - - - - - 18bc16ed by Cale Gibbard at 2020-04-17T13:08:47-04:00 Use FailOperator in more places, define a couple datatypes (XBindStmtRn and XBindStmtTc) to help clarify the meaning of XBindStmt in the renamer and typechecker - - - - - 84cc8394 by Simon Peyton Jones at 2020-04-18T13:20:29-04:00 Add a missing zonk in tcHsPartialType I omitted a vital zonk when refactoring tcHsPartialType in commit 48fb3482f8cbc8a4b37161021e846105f980eed4 Author: Simon Peyton Jones <simonpj at microsoft.com> Date: Wed Jun 5 08:55:17 2019 +0100 Fix typechecking of partial type signatures This patch fixes it and adds commentary to explain why. Fixes #18008 - - - - - 2ee96ac1 by Ben Gamari at 2020-04-18T13:21:05-04:00 gitlab-ci: Bump FreeBSD bootstrap compiler to 8.10.1 - - - - - 434312e5 by Ben Gamari at 2020-04-18T13:21:05-04:00 gitlab-ci: Enable FreeBSD job for so-labelled MRs - - - - - ddffb227 by Ben Gamari at 2020-04-18T13:21:05-04:00 gitlab-ci: Use rules syntax for conditional jobs - - - - - e2586828 by Ben Gamari at 2020-04-18T13:21:05-04:00 Bump hsc2hs submodule - - - - - 15ab6cd5 by Ömer Sinan Ağacan at 2020-04-18T13:21:44-04:00 Improve prepForeignCall error reporting Show parameters and description of the error code when ffi_prep_cif fails. This may be helpful for debugging #17018. - - - - - 3ca52151 by Sylvain Henry at 2020-04-18T20:04:14+02:00 GHC.Core.Opt renaming * GHC.Core.Op => GHC.Core.Opt * GHC.Core.Opt.Simplify.Driver => GHC.Core.Opt.Driver * GHC.Core.Opt.Tidy => GHC.Core.Tidy * GHC.Core.Opt.WorkWrap.Lib => GHC.Core.Opt.WorkWrap.Utils As discussed in: * https://mail.haskell.org/pipermail/ghc-devs/2020-April/018758.html * https://gitlab.haskell.org/ghc/ghc/issues/13009#note_264650 - - - - - 15312bbb by Sylvain Henry at 2020-04-18T20:04:46+02:00 Modules (#13009) * SysTools * Parser * GHC.Builtin * GHC.Iface.Recomp * Settings Update Haddock submodule Metric Decrease: Naperian parsing001 - - - - - eaed0a32 by Alexis King at 2020-04-19T03:16:44-04:00 Add missing addInScope call for letrec binders in OccurAnal This fixes #18044, where a shadowed variable was incorrectly substituted by the binder swap on the RHS of a floated-in letrec. This can only happen when the uniques line up *just* right, so writing a regression test would be very difficult, but at least the fix is small and straightforward. - - - - - 36882493 by Shayne Fletcher at 2020-04-20T04:36:43-04:00 Derive Ord instance for Extension Metric Increase: T12150 T12234 - - - - - b43365ad by Simon Peyton Jones at 2020-04-20T04:37:20-04:00 Fix a buglet in redundant-constraint warnings Ticket #18036 pointed out that we were reporting a redundant constraint when it really really wasn't. Turned out to be a buglet in the SkolemInfo for the relevant implication constraint. Easily fixed! - - - - - d5fae7da by Ömer Sinan Ağacan at 2020-04-20T14:39:28-04:00 Mark T12010 fragile on 32-bit - - - - - bca02fca by Adam Sandberg Ericsson at 2020-04-21T06:38:45-04:00 docs: drop note about not supporting shared libraries on unix systems [skip ci] - - - - - 6655f933 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Use ParserFlags in GHC.Runtime.Eval (#17957) Instead of passing `DynFlags` to functions such as `isStmt` and `hasImport` in `GHC.Runtime.Eval` we pass `ParserFlags`. It's a much simpler structure that can be created purely with `mkParserFlags'`. - - - - - 70be0fbc by Sylvain Henry at 2020-04-21T06:39:32-04:00 GHC.Runtime: avoid DynFlags (#17957) * add `getPlatform :: TcM Platform` helper * remove unused `DynFlags` parameter from `emptyPLS` - - - - - 35e43d48 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Avoid DynFlags in Ppr code (#17957) * replace `DynFlags` parameters with `SDocContext` parameters for a few Ppr related functions: `bufLeftRenderSDoc`, `printSDoc`, `printSDocLn`, `showSDocOneLine`. * remove the use of `pprCols :: DynFlags -> Int` in Outputable. We already have the information via `sdocLineLength :: SDocContext -> Int` - - - - - ce5c2999 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Avoid using sdocWithDynFlags (#17957) Remove one use of `sdocWithDynFlags` from `GHC.CmmToLlvm.llvmCodeGen'` and from `GHC.Driver.CodeOutput.profilingInitCode` - - - - - f2a98996 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Avoid `sdocWithDynFlags` in `pprCLbl` (#17957) * add a `DynFlags` parameter to `pprCLbl` * put `maybe_underscore` and `pprAsmCLbl` in a `where` clause to avoid `DynFlags` parameters - - - - - 747093b7 by Sylvain Henry at 2020-04-21T06:39:32-04:00 CmmToAsm DynFlags refactoring (#17957) * Remove `DynFlags` parameter from `isDynLinkName`: `isDynLinkName` used to test the global `ExternalDynamicRefs` flag. Now we test it outside of `isDynLinkName` * Add new fields into `NCGConfig`: current unit id, sse/bmi versions, externalDynamicRefs, etc. * Replace many uses of `DynFlags` by `NCGConfig` * Moved `BMI/SSE` datatypes into `GHC.Platform` - - - - - ffd7eef2 by Takenobu Tani at 2020-04-22T23:09:50-04:00 stg-spec: Modify file paths according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * GHC/Stg/Syntax.hs <= stgSyn/StgSyn.hs * GHC/Types/Literal.hs <= basicTypes/Literal.hs * GHC/Types/CostCentre.hs <= profiling/CostCentre.hs This patch also updates old file path [2]: * utils/genapply/Main.hs <= utils/genapply/GenApply.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: commit 0cc4aad36f [skip ci] - - - - - e8a5d81b by Jonathan DK Gibbons at 2020-04-22T23:10:28-04:00 Refactor the `MatchResult` type in the desugarer This way, it does a better job of proving whether or not the fail operator is used. - - - - - dcb7fe5a by John Ericson at 2020-04-22T23:10:28-04:00 Remove panic in dsHandleMonadicFailure Rework dsHandleMonadicFailure to be correct by construction instead of using an unreachable panic. - - - - - cde23cd4 by John Ericson at 2020-04-22T23:10:28-04:00 Inline `adjustMatchResult` It is just `fmap` - - - - - 72cb6bcc by John Ericson at 2020-04-22T23:10:28-04:00 Generalize type of `matchCanFail` - - - - - 401f7bb3 by John Ericson at 2020-04-22T23:10:28-04:00 `MatchResult'` -> `MatchResult` Inline `MatchResult` alias accordingly. - - - - - 6c9fae23 by Alexis King at 2020-04-22T23:11:12-04:00 Mark DataCon wrappers CONLIKE Now that DataCon wrappers don’t inline until phase 0 (see commit b78cc64e923716ac0512c299f42d4d0012306c05), it’s important that case-of-known-constructor and RULE matching be able to see saturated applications of DataCon wrappers in unfoldings. Making them conlike is a natural way to do it, since they are, in fact, precisely the sort of thing the CONLIKE pragma exists to solve. Fixes #18012. This also bumps the version of the parsec submodule to incorporate a patch that avoids a metric increase on the haddock perf tests. The increase was not really a flaw in this patch, as parsec was implicitly relying on inlining heuristics. The patch to parsec just adds some INLINABLE pragmas, and we get a nice performance bump out of it (well beyond the performance we lost from this patch). Metric Decrease: T12234 WWRec haddock.Cabal haddock.base haddock.compiler - - - - - 48b8951e by Roland Senn at 2020-04-22T23:11:51-04:00 Fix tab-completion for :break (#17989) In tab-completion for the `:break` command, only those identifiers should be shown, that are accepted in the `:break` command. Hence these identifiers must be - defined in an interpreted module - top-level - currently in scope - listed in a `ModBreaks` value as a possible breakpoint. The identifiers my be qualified or unqualified. To get all possible top-level breakpoints for tab-completeion with the correct qualification do: 1. Build the list called `pifsBreaks` of all pairs of (Identifier, module-filename) from the `ModBreaks` values. Here all identifiers are unqualified. 2. Build the list called `pifInscope` of all pairs of (Identifiers, module-filename) with identifiers from the `GlobalRdrEnv`. Take only those identifiers that are in scope and have the correct prefix. Here the identifiers may be qualified. 3. From the `pifInscope` list seclect all pairs that can be found in the `pifsBreaks` list, by comparing only the unqualified part of the identifier. The remaining identifiers can be used for tab-completion. This ensures, that we show only identifiers, that can be used in a `:break` command. - - - - - 34a45ee6 by Peter Trommler at 2020-04-22T23:12:27-04:00 PPC NCG: Add DWARF constants and debug labels Fixes #11261 - - - - - ffde2348 by Simon Peyton Jones at 2020-04-22T23:13:06-04:00 Do eager instantation in terms This patch implements eager instantiation, a small but critical change to the type inference engine, #17173. The main change is this: When inferring types, always return an instantiated type (for now, deeply instantiated; in future shallowly instantiated) There is more discussion in https://www.tweag.io/posts/2020-04-02-lazy-eager-instantiation.html There is quite a bit of refactoring in this patch: * The ir_inst field of GHC.Tc.Utils.TcType.InferResultk has entirely gone. So tcInferInst and tcInferNoInst have collapsed into tcInfer. * Type inference of applications, via tcInferApp and tcInferAppHead, are substantially refactored, preparing the way for Quick Look impredicativity. * New pure function GHC.Tc.Gen.Expr.collectHsArgs and applyHsArgs are beatifully dual. We can see the zipper! * GHC.Tc.Gen.Expr.tcArgs is now much nicer; no longer needs to return a wrapper * In HsExpr, HsTypeApp now contains the the actual type argument, and is used in desugaring, rather than putting it in a mysterious wrapper. * I struggled a bit with good error reporting in Unify.matchActualFunTysPart. It's a little bit simpler than before, but still not great. Some smaller things * Rename tcPolyExpr --> tcCheckExpr tcMonoExpr --> tcLExpr * tcPatSig moves from GHC.Tc.Gen.HsType to GHC.Tc.Gen.Pat Metric Decrease: T9961 Reduction of 1.6% in comiler allocation on T9961, I think. - - - - - 6f84aca3 by Ben Gamari at 2020-04-22T23:13:43-04:00 rts: Ensure that sigaction structs are initialized I noticed these may have uninitialized fields when looking into #18037. The reporter says that zeroing them doesn't fix the MSAN failures they observe but zeroing them is the right thing to do regardless. - - - - - c29f0fa6 by Andreas Klebinger at 2020-04-22T23:14:21-04:00 Add "ddump-cmm-opt" as alias for "ddump-opt-cmm". - - - - - 4b4a8b60 by Ben Gamari at 2020-04-22T23:14:57-04:00 llvmGen: Remove -fast-llvm flag Issue #18076 drew my attention to the undocumented `-fast-llvm` flag for the LLVM code generator introduced in 22733532171330136d87533d523f565f2a4f102f. Speaking to Moritz about this, the motivation for this flag was to avoid potential incompatibilities between LLVM and the assembler/linker toolchain by making LLVM responsible for machine-code generation. Unfortunately, this cannot possibly work: the LLVM backend's mangler performs a number of transforms on the assembler generated by LLVM that are necessary for correctness. These are currently: * mangling Haskell functions' symbol types to be `object` instead of `function` on ELF platforms (necessary for tables-next-to-code) * mangling AVX instructions to ensure that we don't assume alignment (which LLVM otherwise does) * mangling Darwin's subsections-via-symbols directives Given that these are all necessary I don't believe that we can support `-fast-llvm`. Let's rather remove it. - - - - - 831b6642 by Moritz Angermann at 2020-04-22T23:15:33-04:00 Fix build warning; add more informative information to the linker; fix linker for empty sections - - - - - c409961a by Ryan Scott at 2020-04-22T23:16:12-04:00 Update commentary and slightly refactor GHC.Tc.Deriv.Infer There was some out-of-date commentary in `GHC.Tc.Deriv.Infer` that has been modernized. Along the way, I removed the `bad` constraints in `simplifyDeriv`, which did not serve any useful purpose (besides being printed in debugging output). Fixes #18073. - - - - - 125aa2b8 by Ömer Sinan Ağacan at 2020-04-22T23:16:51-04:00 Remove leftover comment in tcRnModule', redundant bind The code for the comment was moved in dc8c03b2a5c but the comment was forgotten. - - - - - 8ea37b01 by Sylvain Henry at 2020-04-22T23:17:34-04:00 RTS: workaround a Linux kernel bug in timerfd Reading a timerfd may return 0: https://lkml.org/lkml/2019/8/16/335. This is currently undocumented behavior and documentation "won't happen anytime soon" (https://lkml.org/lkml/2020/2/13/295). With this patch, we just ignore the result instead of crashing. It may fix #18033 but we can't be sure because we don't have enough information. See also this discussion about the kernel bug: https://github.com/Azure/sonic-swss-common/pull/302/files/1f070e7920c2e5d63316c0105bf4481e73d72dc9 - - - - - cd8409c2 by Ryan Scott at 2020-04-23T11:39:24-04:00 Create di_scoped_tvs for associated data family instances properly See `Note [Associated data family instances and di_scoped_tvs]` in `GHC.Tc.TyCl.Instance`, which explains all of the moving parts. Fixes #18055. - - - - - 339e8ece by Ben Gamari at 2020-04-23T11:40:02-04:00 hadrian/ghci: Allow arguments to be passed to GHCi Previously the arguments passed to hadrian/ghci were passed both to `hadrian` and GHCi. This is rather odd given that there are essentially not arguments in the intersection of the two. Let's just pass them to GHCi; this allows `hadrian/ghci -Werror`. - - - - - 5946c85a by Ben Gamari at 2020-04-23T11:40:38-04:00 testsuite: Don't attempt to read .std{err,out} files if they don't exist Simon reports that he was previously seeing framework failures due to an attempt to read the non-existing T13456.stderr. While I don't know exactly what this is due to, it does seem like a non-existing .std{out,err} file should be equivalent to an empty file. Teach the testsuite driver to treat it as such. - - - - - c42754d5 by John Ericson at 2020-04-23T18:32:43-04:00 Trees That Grow refactor for `ConPat` and `CoPat` - `ConPat{In,Out}` -> `ConPat` - `CoPat` -> `XPat (CoPat ..)` Note that `GHC.HS.*` still uses `HsWrap`, but only when `p ~ GhcTc`. After this change, moving the type family instances out of `GHC.HS.*` is sufficient to break the cycle. Add XCollectPat class to decide how binders are collected from XXPat based on the pass. Previously we did this with IsPass, but that doesn't work for Haddock's DocNameI, and the constraint doesn't express what actual distinction is being made. Perhaps a class for collecting binders more generally is in order, but we haven't attempted this yet. Pure refactor of code around ConPat - InPat/OutPat synonyms removed - rename several identifiers - redundant constraints removed - move extension field in ConPat to be first - make ConPat use record syntax more consistently Fix T6145 (ConPatIn became ConPat) Add comments from SPJ. Add comment about haddock's use of CollectPass. Updates haddock submodule. - - - - - 72da0c29 by mniip at 2020-04-23T18:33:21-04:00 Add :doc to GHC.Prim - - - - - 2c23e2e3 by mniip at 2020-04-23T18:33:21-04:00 Include docs for non-primop entries in primops.txt as well - - - - - 0ac29c88 by mniip at 2020-04-23T18:33:21-04:00 GHC.Prim docs: note and test - - - - - b0fbfc75 by John Ericson at 2020-04-24T12:07:14-04:00 Switch order on `GhcMake.IsBoot` In !1798 we were requested to replace many `Bool`s with this data type. But those bools had `False` meaning `NotBoot`, so the `Ord` instance would be flipped if we use this data-type as-is. Since the planned formally-`Bool` occurrences vastly outnumber the current occurrences, we figured it would be better to conform the `Ord` instance to how the `Bool` is used now, fixing any issues, rather than fix them currently with the bigger refactor later in !1798. That way, !1798 can be a "pure" refactor with no behavioral changes. - - - - - af332442 by Sylvain Henry at 2020-04-26T13:55:14-04:00 Modules: Utils and Data (#13009) Update Haddock submodule Metric Increase: haddock.compiler - - - - - cd4434c8 by Sylvain Henry at 2020-04-26T13:55:16-04:00 Fix misleading Ptr phantom type in SerializedCompact (#15653) - - - - - 22bf5c73 by Ömer Sinan Ağacan at 2020-04-26T13:55:22-04:00 Tweak includes in non-moving GC headers We don't use hash tables in non-moving GC so remove the includes. This breaks Compact.c as existing includes no longer include Hash.h, so include Hash.h explicitly in Compact.c. - - - - - 99823ed2 by Sylvain Henry at 2020-04-27T20:24:46-04:00 TH: fix Show/Eq/Ord instances for Bytes (#16457) We shouldn't compare pointer values but the actual bytes. - - - - - c62271a2 by Alp Mestanogullari at 2020-04-27T20:25:33-04:00 hadrian: always capture both stdout and stderr when running a builder fails The idea being that when a builder('s command) fails, we quite likely want to have all the information available to figure out why. Depending on the builder _and_ the particular problem, the useful bits of information can be printed on stdout or stderr. We accomplish this by defining a simple wrapper for Shake's `cmd` function, that just _always_ captures both streams in case the command returns a non-zero exit code, and by using this wrapper everywhere in `hadrian/src/Builder.hs`. Fixes #18089. - - - - - 4b9764db by Ryan Scott at 2020-04-28T15:40:04-04:00 Define a Quote IO instance Fixes #18103. - - - - - 518a63d4 by Ryan Scott at 2020-04-28T15:40:42-04:00 Make boxed 1-tuples have known keys Unlike other tuples, which use special syntax and are "known" by way of a special `isBuiltInOcc_maybe` code path, boxed 1-tuples do not use special syntax. Therefore, in order to make sure that the internals of GHC are aware of the `data Unit a = Unit a` definition in `GHC.Tuple`, we give `Unit` known keys. For the full details, see `Note [One-tuples] (Wrinkle: Make boxed one-tuple names have known keys)` in `GHC.Builtin.Types`. Fixes #18097. - - - - - 2cfc4ab9 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Document backpack fields in DynFlags - - - - - 10a2ba90 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Refactor UnitInfo * Rename InstalledPackageInfo into GenericUnitInfo The name InstalledPackageInfo is only kept for alleged backward compatibility reason in Cabal. ghc-boot has its own stripped down copy of this datatype but it doesn't need to keep the name. Internally we already use type aliases (UnitInfo in GHC, PackageCacheFormat in ghc-pkg). * Rename UnitInfo fields: add "unit" prefix and fix misleading names * Add comments on every UnitInfo field * Rename SourcePackageId into PackageId "Package" already indicates that it's a "source package". Installed package components are called units. Update Haddock submodule - - - - - 69562e34 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Remove unused `emptyGenericUnitInfo` - - - - - 9e2c8e0e by Sylvain Henry at 2020-04-30T01:56:56-04:00 Refactor UnitInfo load/store from databases Converting between UnitInfo stored in package databases and UnitInfo as they are used in ghc-pkg and ghc was done in a very convoluted way (via BinaryStringRep and DbUnitModuleRep type classes using fun deps, etc.). It was difficult to understand and even more to modify (I wanted to try to use a GADT for UnitId but fun deps got in the way). The new code uses much more straightforward functions to convert between the different representations. Much simpler. - - - - - ea717aa4 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Factorize mungePackagePaths code This patch factorizes the duplicated code used in ghc-pkg and in GHC to munge package paths/urls. It also fixes haddock-html munging in GHC (allowed to be either a file or a url) to mimic ghc-pkg behavior. - - - - - 10d15f1e by Sylvain Henry at 2020-04-30T01:56:56-04:00 Refactoring unit management code Over the years the unit management code has been modified a lot to keep up with changes in Cabal (e.g. support for several library components in the same package), to integrate BackPack, etc. I found it very hard to understand as the terminology wasn't consistent, was referring to past concepts, etc. The terminology is now explained as clearly as I could in the Note "About Units" and the code is refactored to reflect it. ------------------- Many names were misleading: UnitId is not an Id but could be a virtual unit (an indefinite one instantiated on the fly), IndefUnitId constructor may contain a definite instantiated unit, etc. * Rename IndefUnitId into InstantiatedUnit * Rename IndefModule into InstantiatedModule * Rename UnitId type into Unit * Rename IndefiniteUnitId constructor into VirtUnit * Rename DefiniteUnitId constructor into RealUnit * Rename packageConfigId into mkUnit * Rename getPackageDetails into unsafeGetUnitInfo * Rename InstalledUnitId into UnitId Remove references to misleading ComponentId: a ComponentId is just an indefinite unit-id to be instantiated. * Rename ComponentId into IndefUnitId * Rename ComponentDetails into UnitPprInfo * Fix display of UnitPprInfo with empty version: this is now used for units dynamically generated by BackPack Generalize several types (Module, Unit, etc.) so that they can be used with different unit identifier types: UnitKey, UnitId, Unit, etc. * GenModule: Module, InstantiatedModule and InstalledModule are now instances of this type * Generalize DefUnitId, IndefUnitId, Unit, InstantiatedUnit, PackageDatabase Replace BackPack fake "hole" UnitId by a proper HoleUnit constructor. Add basic support for UnitKey. They should be used more in the future to avoid mixing them up with UnitId as we do now. Add many comments. Update Haddock submodule - - - - - 8bfb0219 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Unit: split and rename modules Introduce GHC.Unit.* hierarchy for everything concerning units, packages and modules. Update Haddock submodule - - - - - 71484b09 by Alexis King at 2020-04-30T01:57:35-04:00 Allow block arguments in arrow control operators Arrow control operators have their own entries in the grammar, so they did not cooperate with BlockArguments. This was just a minor oversight, so this patch adjusts the grammar to add the desired behavior. fixes #18050 - - - - - a48cd2a0 by Alexis King at 2020-04-30T01:57:35-04:00 Allow LambdaCase to be used as a command in proc notation - - - - - f4d3773c by Alexis King at 2020-04-30T01:57:35-04:00 Document BlockArguments/LambdaCase support in arrow notation - - - - - 5bdfdd13 by Simon Peyton Jones at 2020-04-30T01:58:15-04:00 Add tests for #17873 - - - - - 19b701c2 by Simon Peyton Jones at 2020-04-30T07:30:13-04:00 Mark rule args as non-tail-called This was just an omission...b I'd failed to call markAllNonTailCall on rule args. I think this bug has been here a long time, but it's quite hard to trigger. Fixes #18098 - - - - - 014ef4a3 by Matthew Pickering at 2020-04-30T07:30:50-04:00 Hadrian: Improve tool-args command to support more components There is a new command to hadrian, tool:path/to/file.hs, which returns the options needed to compile that file in GHCi. This is now used in the ghci script with argument `ghc/Main.hs` but its main purpose is to support the new multi-component branch of ghcide. - - - - - 2aa67611 by Ben Gamari at 2020-04-30T21:34:44-04:00 nonmoving: Clear bitmap after initializing block size Previously nonmovingInitSegment would clear the bitmap before initializing the segment's block size. This is broken since nonmovingClearBitmap looks at the segment's block size to determine how much bitmap to clear. - - - - - 54dad3cf by Ben Gamari at 2020-04-30T21:34:44-04:00 nonmoving: Explicitly memoize block count A profile cast doubt on whether the compiler hoisted the bound out the loop as I would have expected here. It turns out it did but nevertheless it seems clearer to just do this manually. - - - - - 99ff8145 by Ben Gamari at 2020-04-30T21:34:44-04:00 nonmoving: Eagerly flush all capabilities' update remembered sets (cherry picked from commit 2fa79119570b358a4db61446396889b8260d7957) - - - - - 05b0a9fd by Ömer Sinan Ağacan at 2020-04-30T21:35:24-04:00 Remove OneShotInfo field of LFReEntrant, document OneShotInfo The field is only used in withNewTickyCounterFun and it's easier to directly pass a parameter for one-shot info to withNewTickyCounterFun instead of passing it via LFReEntrant. This also makes !2842 simpler. Other changes: - New Note (by SPJ) [OneShotInfo overview] added. - Arity argument of thunkCode removed as it's always 0. - - - - - a43620c6 by Ömer Sinan Ağacan at 2020-04-30T21:35:24-04:00 GHC.StgToCmm.Ticky: remove a few unused stuff - - - - - 780de9e1 by Sylvain Henry at 2020-05-01T10:37:39-04:00 Use platform in Iface Binary - - - - - f8386c7b by Sylvain Henry at 2020-05-01T10:37:39-04:00 Refactor PprDebug handling If `-dppr-debug` is set, then PprUser and PprDump styles are silently replaced with PprDebug style. This was done in `mkUserStyle` and `mkDumpStyle` smart constructors. As a consequence they needed a DynFlags parameter. Now we keep the original PprUser and PprDump styles until they are used to create an `SDocContext`. I.e. the substitution is only performed in `initSDocContext`. - - - - - b3df9e78 by Sylvain Henry at 2020-05-01T10:37:39-04:00 Remove PprStyle param of logging actions Use `withPprStyle` instead to apply a specific style to a SDoc. - - - - - de9fc995 by Sylvain Henry at 2020-05-01T10:37:39-04:00 Fully remove PprDebug PprDebug was a pain to deal with consistently as it is implied by `-dppr-debug` but it isn't really a PprStyle. We remove it completely and query the appropriate SDoc flag instead (`sdocPprDebug`) via helpers (`getPprDebug` and its friends). - - - - - 8b51fcbd by Sebastian Graf at 2020-05-01T10:38:16-04:00 PmCheck: Only call checkSingle if we would report warnings - - - - - fd7ea0fe by Sebastian Graf at 2020-05-01T10:38:16-04:00 PmCheck: Pick up `EvVar`s bound in `HsWrapper`s for long-distance info `HsWrapper`s introduce evidence bindings through `WpEvLam` which the pattern-match coverage checker should be made aware of. Failing to do so caused #18049, where the resulting impreciseness of imcompleteness warnings seemingly contradicted with `-Winaccessible-code`. The solution is simple: Collect all the evidence binders of an `HsWrapper` and add it to the ambient `Deltas` before desugaring the wrapped expression. But that means we pick up many more evidence bindings, even when they wrap around code without a single pattern match to check! That regressed `T3064` by over 300%, so now we are adding long-distance info lazily through judicious use of `unsafeInterleaveIO`. Fixes #18049. - - - - - 7bfe9ac5 by Ben Gamari at 2020-05-03T04:41:33-04:00 rts: Enable tracing of nonmoving heap census with -ln Previously this was not easily available to the user. Fix this. Non-moving collection lifecycle events are now reported with -lg. - - - - - c560dd07 by Ben Gamari at 2020-05-03T04:41:33-04:00 users guide: Move eventlog documentation users guide - - - - - 02543d5e by Ben Gamari at 2020-05-03T04:41:33-04:00 users guide: Add documentation for non-moving GC events - - - - - b465dd45 by Alexis King at 2020-05-03T04:42:12-04:00 Flatten nested casts in the simple optimizer Normally, we aren’t supposed to generated any nested casts, since mkCast takes care to flatten them, but the simple optimizer didn’t use mkCast, so they could show up after inlining. This isn’t really a problem, since the simplifier will clean them up immediately anyway, but it can clutter the -ddump-ds output, and it’s an extremely easy fix. closes #18112 - - - - - 8bdc03d6 by Simon Peyton Jones at 2020-05-04T01:56:59-04:00 Don't return a panic in tcNestedSplice In GHC.Tc.Gen.Splice.tcNestedSplice we were returning a typechecked expression of "panic". That is usually OK, because the result is discarded. But it happens that tcApp now looks at the typechecked expression, trivially, to ask if it is tagToEnum. So being bottom is bad. Moreover a debug-trace might print it out. So better to return a civilised expression, even though it is usually discarded. - - - - - 0bf640b1 by Baldur Blöndal at 2020-05-04T01:57:36-04:00 Don't require parentheses around via type (`-XDerivingVia'). Fixes #18130". - - - - - 30272412 by Artem Pelenitsyn at 2020-05-04T13:19:59-04:00 Remove custom ExceptionMonad class (#18075) (updating haddock submodule accordingly) - - - - - b9f7c08f by jneira at 2020-05-04T13:20:37-04:00 Remove unused hs-boot file - - - - - 1d8f80cd by Sylvain Henry at 2020-05-05T03:22:46-04:00 Remove references to -package-key * remove references to `-package-key` which has been removed in 2016 (240ddd7c39536776e955e881d709bbb039b48513) * remove support for `-this-package-key` which has been deprecated at the same time - - - - - 7bc3a65b by Sylvain Henry at 2020-05-05T03:23:31-04:00 Remove SpecConstrAnnotation (#13681) This has been deprecated since 2013. Use GHC.Types.SPEC instead. Make GHC.Exts "not-home" for haddock Metric Decrease: haddock.base - - - - - 3c862f63 by DenisFrezzato at 2020-05-05T03:24:15-04:00 Fix Haskell98 short description in documentation - - - - - 2420c555 by Ryan Scott at 2020-05-05T03:24:53-04:00 Add regression tests for #16244, #16245, #16758 Commit e3c374cc5bd7eb49649b9f507f9f7740697e3f70 ended up fixing quite a few bugs: * This commit fixes #16244 completely. A regression test has been added. * This commit fixes one program from #16245. (The program in https://gitlab.haskell.org/ghc/ghc/issues/16245#note_211369 still panics, and the program in https://gitlab.haskell.org/ghc/ghc/issues/16245#note_211400 still loops infinitely.) A regression test has been added for this program. * This commit fixes #16758. Accordingly, this patch removes the `expect_broken` label from the `T16758` test case, moves it from `should_compile` to `should_fail` (as it should produce an error message), and checks in the expected stderr. - - - - - 40c71c2c by Sylvain Henry at 2020-05-05T03:25:31-04:00 Fix colorized error messages (#18128) In b3df9e780fb2f5658412c644849cd0f1e6f50331 I broke colorized messages by using "dump" style instead of "user" style. This commits fixes it. - - - - - 7ab6ab09 by Richard Eisenberg at 2020-05-06T04:39:32-04:00 Refactor hole constraints. Previously, holes (both expression holes / out of scope variables and partial-type-signature wildcards) were emitted as *constraints* via the CHoleCan constructor. While this worked fine for error reporting, there was a fair amount of faff in keeping these constraints in line. In particular, and unlike other constraints, we could never change a CHoleCan to become CNonCanonical. In addition: * the "predicate" of a CHoleCan constraint was really the type of the hole, which is not a predicate at all * type-level holes (partial type signature wildcards) carried evidence, which was never used * tcNormalise (used in the pattern-match checker) had to create a hole constraint just to extract it again; it was quite messy The new approach is to record holes directly in WantedConstraints. It flows much more nicely now. Along the way, I did some cleaning up of commentary in GHC.Tc.Errors.Hole, which I had a hard time understanding. This was instigated by a future patch that will refactor the way predicates are handled. The fact that CHoleCan's "predicate" wasn't really a predicate is incompatible with that future patch. No test case, because this is meant to be purely internal. It turns out that this change improves the performance of the pattern-match checker, likely because fewer constraints are sloshing about in tcNormalise. I have not investigated deeply, but an improvement is not a surprise here: ------------------------- Metric Decrease: PmSeriesG ------------------------- - - - - - 420b957d by Ben Gamari at 2020-05-06T04:40:08-04:00 rts: Zero block flags with -DZ Block flags are very useful for determining the state of a block. However, some block allocator users don't touch them, leading to misleading values. Ensure that we zero then when zero-on-gc is set. This is safe and makes the flags more useful during debugging. - - - - - 740b3b8d by Ben Gamari at 2020-05-06T04:40:08-04:00 nonmoving: Fix incorrect failed_to_evac value during deadlock gc Previously we would incorrectly set the failed_to_evac flag if we evacuated a value due to a deadlock GC. This would cause us to mark more things as dirty than strictly necessary. It also turned up a nasty but which I will fix next. - - - - - b2d72c75 by Ben Gamari at 2020-05-06T04:40:08-04:00 nonmoving: Fix handling of dirty objects Previously we (incorrectly) relied on failed_to_evac to be "precise". That is, we expected it to only be true if *all* of an object's fields lived outside of the non-moving heap. However, does not match the behavior of failed_to_evac, which is true if *any* of the object's fields weren't promoted (meaning that some others *may* live in the non-moving heap). This is problematic as we skip the non-moving write barrier for dirty objects (which we can only safely do if *all* fields point outside of the non-moving heap). Clearly this arises due to a fundamental difference in the behavior expected of failed_to_evac in the moving and non-moving collector. e.g., in the moving collector it is always safe to conservatively say failed_to_evac=true whereas in the non-moving collector the safe value is false. This issue went unnoticed as I never wrote down the dirtiness invariant enforced by the non-moving collector. We now define this invariant as An object being marked as dirty implies that all of its fields are on the mark queue (or, equivalently, update remembered set). To maintain this invariant we teach nonmovingScavengeOne to push the fields of objects which we fail to evacuate to the update remembered set. This is a simple and reasonably cheap solution and avoids the complexity and fragility that other, more strict alternative invariants would require. All of this is described in a new Note, Note [Dirty flags in the non-moving collector] in NonMoving.c. - - - - - 9f3e6884 by Zubin Duggal at 2020-05-06T04:41:08-04:00 Allow atomic update of NameCache in readHieFile The situation arises in ghcide where multiple different threads may need to update the name cache, therefore with the older interface it could happen that you start reading a hie file with name cache A and produce name cache A + B, but another thread in the meantime updated the namecache to A + C. Therefore if you write the new namecache you will lose the A' updates from the second thread. Updates haddock submodule - - - - - edec6a6c by Ryan Scott at 2020-05-06T04:41:57-04:00 Make isTauTy detect higher-rank contexts Previously, `isTauTy` would only detect higher-rank `forall`s, not higher-rank contexts, which led to some minor bugs observed in #18127. Easily fixed by adding a case for `(FunTy InvisArg _ _)`. Fixes #18127. - - - - - a95e7fe0 by Ömer Sinan Ağacan at 2020-05-06T04:42:39-04:00 ELF linker: increment curSymbol after filling in fields of current entry The bug was introduced in a8b7cef4d45 which added a field to the `symbols` array elements and then updated this code incorrectly: - oc->symbols[curSymbol++] = nm; + oc->symbols[curSymbol++].name = nm; + oc->symbols[curSymbol].addr = symbol->addr; - - - - - cab1871a by Sylvain Henry at 2020-05-06T04:43:21-04:00 Move LeadingUnderscore into Platform (#17957) Avoid direct use of DynFlags to know if symbols must be prefixed by an underscore. - - - - - 94e7c563 by Sylvain Henry at 2020-05-06T04:43:21-04:00 Don't use DynFlags in showLinkerState (#17957) - - - - - 9afd9251 by Ryan Scott at 2020-05-06T04:43:58-04:00 Refactoring: Use bindSigTyVarsFV in rnMethodBinds `rnMethodBinds` was explicitly using `xoptM` to determine if `ScopedTypeVariables` is enabled before bringing type variables bound by the class/instance header into scope. However, this `xoptM` logic is already performed by the `bindSigTyVarsFV` function. This patch uses `bindSigTyVarsFV` in `rnMethodBinds` to reduce the number of places where we need to consult if `ScopedTypeVariables` is on. This is purely refactoring, and there should be no user-visible change in behavior. - - - - - 6f6d72b2 by Brian Foley at 2020-05-08T15:29:25-04:00 Remove further dead code found by a simple Python script. Avoid removing some functions that are part of an API even though they're not used in-tree at the moment. - - - - - 78bf8bf9 by Julien Debon at 2020-05-08T15:29:28-04:00 Add doc examples for Bifoldable See #17929 - - - - - 66f0a847 by Julien Debon at 2020-05-08T15:29:29-04:00 doc (Bitraversable): Add examples to Bitraversable * Add examples to Data.Bitraversable * Fix formatting for (,) in Bitraversable and Bifoldable * Fix mistake on bimapAccumR documentation See #17929 - - - - - 9749fe12 by Baldur Blöndal at 2020-05-08T15:29:32-04:00 Specify kind variables for inferred kinds in base. - - - - - 4e9aef9e by John Ericson at 2020-05-08T15:29:36-04:00 HsSigWcTypeScoping: Pull in documentation from stray location - - - - - f4d5c6df by John Ericson at 2020-05-08T15:29:36-04:00 Rename local `real_fvs` to `implicit_vs` It doesn't make sense to call the "free" variables we are about to implicitly bind the real ones. - - - - - 20570b4b by John Ericson at 2020-05-08T15:29:36-04:00 A few tiny style nits with renaming - Use case rather than guards that repeatedly scrutenize same thing. - No need for view pattern when `L` is fine. - Use type synnonym to convey the intent like elsewhere. - - - - - 09ac8de5 by John Ericson at 2020-05-08T15:29:36-04:00 Add `forAllOrNothing` function with note - - - - - bb35c0e5 by Joseph C. Sible at 2020-05-08T15:29:40-04:00 Document lawlessness of Ap's Num instance - - - - - cdd229ff by Joseph C. Sible at 2020-05-08T15:29:40-04:00 Apply suggestion to libraries/base/Data/Monoid.hs - - - - - 926d2aab by Joseph C. Sible at 2020-05-08T15:29:40-04:00 Apply more suggestions from Simon Jakobi - - - - - 7a763cff by Adam Gundry at 2020-05-08T15:29:41-04:00 Reject all duplicate declarations involving DuplicateRecordFields (fixes #17965) This fixes a bug that resulted in some programs being accepted that used the same identifier as a field label and another declaration, depending on the order they appeared in the source code. - - - - - 88e3c815 by Simon Peyton Jones at 2020-05-08T15:29:41-04:00 Fix specialisation for DFuns When specialising a DFun we must take care to saturate the unfolding. See Note [Specialising DFuns] in Specialise. Fixes #18120 - - - - - 86c77b36 by Greg Steuck at 2020-05-08T15:29:45-04:00 Remove unused SEGMENT_PROT_RWX It's been unused for a year and is problematic on any OS which requires W^X for security. - - - - - 9d97f4b5 by nineonine at 2020-05-08T15:30:03-04:00 Add test for #16167 - - - - - aa318338 by Ryan Scott at 2020-05-08T15:30:04-04:00 Bump exceptions submodule so that dist-boot is .gitignore'd `exceptions` is a stage-0 boot library as of commit 30272412fa437ab8e7a8035db94a278e10513413, which means that building `exceptions` in a GHC tree will generate a `dist-boot` directory. However, this directory was not specified in `exceptions`' `.gitignore` file, which causes it to dirty up the current `git` working directory. Accordingly, this bumps the `exceptions` submodule to commit ghc/packages/exceptions at 23c0b8a50d7592af37ca09beeec16b93080df98f, which adds `dist-boot` to the `.gitignore` file. - - - - - ea86360f by Ömer Sinan Ağacan at 2020-05-08T15:30:30-04:00 Linker.c: initialize n_symbols of ObjectCode with other fields - - - - - 951c1fb0 by Sylvain Henry at 2020-05-09T21:46:38-04:00 Fix unboxed-sums GC ptr-slot rubbish value (#17791) This patch allows boot libraries to use unboxed sums without implicitly depending on `base` package because of `absentSumFieldError`. See updated Note [aBSENT_SUM_FIELD_ERROR_ID] in GHC.Core.Make - - - - - b352d63c by Ben Gamari at 2020-05-09T21:47:14-04:00 rts: Make non-existent linker search path merely a warning As noted in #18105, previously this resulted in a rather intrusive error message. This is in contrast to the general expectation that search paths are merely places to look, not places that must exist. Fixes #18105. - - - - - cf4f1e2f by Ben Gamari at 2020-05-13T02:02:33-04:00 rts/CNF: Fix fixup comparison function Previously we would implicitly convert the difference between two words to an int, resulting in an integer overflow on 64-bit machines. Fixes #16992 - - - - - a03da9bf by Ömer Sinan Ağacan at 2020-05-13T02:03:16-04:00 Pack some of IdInfo fields into a bit field This reduces residency of compiler quite a bit on some programs. Example stats when building T10370: Before: 2,871,242,832 bytes allocated in the heap 4,693,328,008 bytes copied during GC 33,941,448 bytes maximum residency (276 sample(s)) 375,976 bytes maximum slop 83 MiB total memory in use (0 MB lost due to fragmentation) After: 2,858,897,344 bytes allocated in the heap 4,629,255,440 bytes copied during GC 32,616,624 bytes maximum residency (278 sample(s)) 314,400 bytes maximum slop 80 MiB total memory in use (0 MB lost due to fragmentation) So -3.9% residency, -1.3% bytes copied and -0.4% allocations. Fixes #17497 Metric Decrease: T9233 T9675 - - - - - 670c3e5c by Ben Gamari at 2020-05-13T02:03:54-04:00 get-win32-tarballs: Fix base URL Revert a change previously made for testing purposes. - - - - - 8ad8dc41 by Ben Gamari at 2020-05-13T02:03:54-04:00 get-win32-tarballs: Improve diagnostics output - - - - - 8c0740b7 by Simon Jakobi at 2020-05-13T02:04:33-04:00 docs: Add examples for Data.Semigroup.Arg{Min,Max} Context: #17153 - - - - - cb22348f by Ben Gamari at 2020-05-13T02:05:11-04:00 Add few cleanups of the CAF logic Give the NameSet of non-CAFfy names a proper newtype to distinguish it from all of the other NameSets floating about. - - - - - 90e38b81 by Emeka Nkurumeh at 2020-05-13T02:05:51-04:00 fix printf warning when using with ghc with clang on mingw - - - - - 86d8ac22 by Sebastian Graf at 2020-05-13T02:06:29-04:00 CprAnal: Don't attach CPR sigs to expandable bindings (#18154) Instead, look through expandable unfoldings in `cprTransform`. See the new Note [CPR for expandable unfoldings]: ``` Long static data structures (whether top-level or not) like xs = x1 : xs1 xs1 = x2 : xs2 xs2 = x3 : xs3 should not get CPR signatures, because they * Never get WW'd, so their CPR signature should be irrelevant after analysis (in fact the signature might even be harmful for that reason) * Would need to be inlined/expanded to see their constructed product * Recording CPR on them blows up interface file sizes and is redundant with their unfolding. In case of Nested CPR, this blow-up can be quadratic! But we can't just stop giving DataCon application bindings the CPR property, for example fac 0 = 1 fac n = n * fac (n-1) fac certainly has the CPR property and should be WW'd! But FloatOut will transform the first clause to lvl = 1 fac 0 = lvl If lvl doesn't have the CPR property, fac won't either. But lvl doesn't have a CPR signature to extrapolate into a CPR transformer ('cprTransform'). So instead we keep on cprAnal'ing through *expandable* unfoldings for these arity 0 bindings via 'cprExpandUnfolding_maybe'. In practice, GHC generates a lot of (nested) TyCon and KindRep bindings, one for each data declaration. It's wasteful to attach CPR signatures to each of them (and intractable in case of Nested CPR). ``` Fixes #18154. - - - - - e34bf656 by Ben Gamari at 2020-05-13T02:07:08-04:00 users-guide: Add discussion of shared object naming Fixes #18074. - - - - - 5d0f2445 by Ben Gamari at 2020-05-13T02:07:47-04:00 testsuite: Print sign of performance changes Executes the minor formatting change in the tabulated performance changes suggested in #18135. - - - - - 9e4b981f by Ben Gamari at 2020-05-13T02:08:24-04:00 testsuite: Add testcase for #18129 - - - - - 266310c3 by Ivan-Yudin at 2020-05-13T02:09:03-04:00 doc: Reformulate the opening paragraph of Ch. 4 in User's guide Removes mentioning of Hugs (it is not helpful for new users anymore). Changes the wording for the rest of the paragraph. Fixes #18132. - - - - - 55e35c0b by Baldur Blöndal at 2020-05-13T20:02:48-04:00 Predicate, Equivalence derive via `.. -> a -> All' - - - - - d7e0b57f by Alp Mestanogullari at 2020-05-13T20:03:30-04:00 hadrian: add a --freeze2 option to freeze stage 1 and 2 - - - - - d880d6b2 by Artem Pelenitsyn at 2020-05-13T20:04:11-04:00 Don't reload environment files on every setSessionDynFlags Makes `interpretPackageEnv` (which loads envirinment files) a part of `parseDynamicFlags` (parsing command-line arguments, which is typically done once) instead of `setSessionDynFlags` (which is typically called several times). Making several (transitive) calls to `interpretPackageEnv`, as before, caused #18125 #16318, which should be fixed now. - - - - - 102cfd67 by Ryan Scott at 2020-05-13T20:04:46-04:00 Factor out HsPatSigType for pat sigs/RULE term sigs (#16762) This implements chunks (2) and (3) of https://gitlab.haskell.org/ghc/ghc/issues/16762#note_270170. Namely, it introduces a dedicated `HsPatSigType` AST type, which represents the types that can appear in pattern signatures and term-level `RULE` binders. Previously, these were represented with `LHsSigWcType`. Although `LHsSigWcType` is isomorphic to `HsPatSigType`, the intended semantics of the two types are slightly different, as evidenced by the fact that they have different code paths in the renamer and typechecker. See also the new `Note [Pattern signature binders and scoping]` in `GHC.Hs.Types`. - - - - - b17574f7 by Hécate at 2020-05-13T20:05:28-04:00 fix(documentation): Fix the RST links to GHC.Prim - - - - - df021fb1 by Baldur Blöndal at 2020-05-13T20:06:06-04:00 Document (->) using inferred quantification for its runtime representations. Fixes #18142. - - - - - 1a93ea57 by Takenobu Tani at 2020-05-13T20:06:54-04:00 Tweak man page for ghc command This commit updates the ghc command's man page as followings: * Enable `man_show_urls` to show URL addresses in the `DESCRIPTION` section of ghc.rst, because sphinx currently removes hyperlinks for man pages. * Add a `SEE ALSO` section to point to the GHC homepage - - - - - a951e1ba by Takenobu Tani at 2020-05-13T20:07:37-04:00 GHCi: Add link to the user's guide in help message This commit adds a link to the user's guide in ghci's `:help` message. Newcomers could easily reach to details of ghci. - - - - - 404581ea by Jeff Happily at 2020-05-13T20:08:15-04:00 Handle single unused import - - - - - 1c999e5d by Ben Gamari at 2020-05-13T20:09:07-04:00 Ensure that printMinimalImports closes handle Fixes #18166. - - - - - c9f5a8f4 by Ben Gamari at 2020-05-13T20:09:51-04:00 hadrian: Tell testsuite driver about LLVM availability This reflects the logic present in the Make build system into Hadrian. Fixes #18167. - - - - - c05c0659 by Simon Jakobi at 2020-05-14T03:31:21-04:00 Improve some folds over Uniq[D]FM * Replace some non-deterministic lazy folds with strict folds. * Replace some O(n log n) folds in deterministic order with O(n) non-deterministic folds. * Replace some folds with set-operations on the underlying IntMaps. This reduces max residency when compiling `nofib/spectral/simple/Main.hs` with -O0 by about 1%. Maximum residency when compiling Cabal also seems reduced on the order of 3-9%. - - - - - 477f13bb by Simon Jakobi at 2020-05-14T03:31:58-04:00 Use Data.IntMap.disjoint Data.IntMap gained a dedicated `disjoint` function in containers-0.6.2.1. This patch applies this function where appropriate in hopes of modest compiler performance improvements. Closes #16806. - - - - - e9c0110c by Ben Gamari at 2020-05-14T12:25:53-04:00 IdInfo: Add reference to bitfield-packing ticket - - - - - 9bd20e83 by Sebastian Graf at 2020-05-15T10:42:09-04:00 DmdAnal: Improve handling of precise exceptions This patch does two things: Fix possible unsoundness in what was called the "IO hack" and implement part 2.1 of the "fixing precise exceptions" plan in https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions, which, in combination with !2956, supersedes !3014 and !2525. **IO hack** The "IO hack" (which is a fallback to preserve precise exceptions semantics and thus soundness, rather than some smart thing that increases precision) is called `exprMayThrowPreciseException` now. I came up with two testcases exemplifying possible unsoundness (if twisted enough) in the old approach: - `T13380d`: Demonstrating unsoundness of the "IO hack" when resorting to manual state token threading and direct use of primops. More details below. - `T13380e`: Demonstrating unsoundness of the "IO hack" when we have Nested CPR. Not currently relevant, as we don't have Nested CPR yet. - `T13380f`: Demonstrating unsoundness of the "IO hack" for safe FFI calls. Basically, the IO hack assumed that precise exceptions can only be thrown from a case scrutinee of type `(# State# RealWorld, _ #)`. I couldn't come up with a program using the `IO` abstraction that violates this assumption. But it's easy to do so via manual state token threading and direct use of primops, see `T13380d`. Also similar code might be generated by Nested CPR in the (hopefully not too) distant future, see `T13380e`. Hence, we now have a more careful test in `forcesRealWorld` that passes `T13380{d,e}` (and will hopefully be robust to Nested CPR). **Precise exceptions** In #13380 and #17676 we saw that we didn't preserve precise exception semantics in demand analysis. We fixed that with minimal changes in !2956, but that was terribly unprincipled. That unprincipledness resulted in a loss of precision, which is tracked by these new test cases: - `T13380b`: Regression in dead code elimination, because !2956 was too syntactic about `raiseIO#` - `T13380c`: No need to apply the "IO hack" when the IO action may not throw a precise exception (and the existing IO hack doesn't detect that) Fixing both issues in !3014 turned out to be too complicated and had the potential to regress in the future. Hence we decided to only fix `T13380b` and augment the `Divergence` lattice with a new middle-layer element, `ExnOrDiv`, which means either `Diverges` (, throws an imprecise exception) or throws a *precise* exception. See the wiki page on Step 2.1 for more implementational details: https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions#dead-code-elimination-for-raiseio-with-isdeadenddiv-introducing-exnordiv-step-21 - - - - - 568d7279 by Ben Gamari at 2020-05-15T10:42:46-04:00 GHC.Cmm.Opt: Handle MO_XX_Conv This MachOp was introduced by 2c959a1894311e59cd2fd469c1967491c1e488f3 but a wildcard match in cmmMachOpFoldM hid the fact that it wasn't handled. Ideally we would eliminate the match but this appears to be a larger task. Fixes #18141. - - - - - 5bcf8606 by Ryan Scott at 2020-05-17T08:46:38-04:00 Remove duplicate Note [When to print foralls] in GHC.Core.TyCo.Ppr There are two different Notes named `[When to print foralls]`. The most up-to-date one is in `GHC.Iface.Type`, but there is a second one in `GHC.Core.TyCo.Ppr`. The latter is less up-to-date, as it was written before GHC switched over to using ifaces to pretty-print types. I decided to just remove the latter and replace it with a reference to the former. [ci skip] - - - - - 55f0e783 by Fumiaki Kinoshita at 2020-05-21T12:10:44-04:00 base: Add Generic instances to various datatypes under GHC.* * GHC.Fingerprint.Types: Fingerprint * GHC.RTS.Flags: GiveGCStats, GCFlags, ConcFlags, DebugFlags, CCFlags, DoHeapProfile, ProfFlags, DoTrace, TraceFlags, TickyFlags, ParFlags and RTSFlags * GHC.Stats: RTSStats and GCStats * GHC.ByteOrder: ByteOrder * GHC.Unicode: GeneralCategory * GHC.Stack.Types: SrcLoc Metric Increase: haddock.base - - - - - a9311cd5 by Gert-Jan Bottu at 2020-05-21T12:11:31-04:00 Explicit Specificity Implementation for Ticket #16393. Explicit specificity allows users to manually create inferred type variables, by marking them with braces. This way, the user determines which variables can be instantiated through visible type application. The additional syntax is included in the parser, allowing users to write braces in type variable binders (type signatures, data constructors etc). This information is passed along through the renamer and verified in the type checker. The AST for type variable binders, data constructors, pattern synonyms, partial signatures and Template Haskell has been updated to include the specificity of type variables. Minor notes: - Bumps haddock submodule - Disables pattern match checking in GHC.Iface.Type with GHC 8.8 - - - - - 24e61aad by Ben Price at 2020-05-21T12:12:17-04:00 Lint should say when it is checking a rule It is rather confusing that when lint finds an error in a rule attached to a binder, it reports the error as in the RHS, not the rule: ... In the RHS of foo We add a clarifying line: ... In the RHS of foo In a rule attached to foo The implication that the rule lives inside the RHS is a bit odd, but this niggle is already present for unfoldings, whose pattern we are following. - - - - - 78c6523c by Ben Gamari at 2020-05-21T12:13:01-04:00 nonmoving: Optimise the write barrier - - - - - 13f6c9d0 by Andreas Klebinger at 2020-05-21T12:13:45-04:00 Refactor linear reg alloc to remember past assignments. When assigning registers we now first try registers we assigned to in the past, instead of picking the "first" one. This is in extremely helpful when dealing with loops for which variables are dead for part of the loop. This is important for patterns like this: foo = arg1 loop: use(foo) ... foo = getVal() goto loop; There we: * assign foo to the register of arg1. * use foo, it's dead after this use as it's overwritten after. * do other things. * look for a register to put foo in. If we pick an arbitrary one it might differ from the register the start of the loop expect's foo to be in. To fix this we simply look for past register assignments for the given variable. If we find one and the register is free we use that register. This reduces the need for fixup blocks which match the register assignment between blocks. In the example above between the end and the head of the loop. This patch also moves branch weight estimation ahead of register allocation and adds a flag to control it (cmm-static-pred). * It means the linear allocator is more likely to assign the hotter code paths first. * If it assign these first we are: + Less likely to spill on the hot path. + Less likely to introduce fixup blocks on the hot path. These two measure combined are surprisingly effective. Based on nofib we get in the mean: * -0.9% instructions executed * -0.1% reads/writes * -0.2% code size. * -0.1% compiler allocations. * -0.9% compile time. * -0.8% runtime. Most of the benefits are simply a result of removing redundant moves and spills. Reduced compiler allocations likely are the result of less code being generated. (The added lookup is mostly non-allocating). - - - - - edc2cc58 by Andreas Klebinger at 2020-05-21T12:14:25-04:00 NCG: Codelayout: Distinguish conditional and other branches. In #18053 we ended up with a suboptimal code layout because the code layout algorithm didn't distinguish between conditional and unconditional control flow. We can completely eliminate unconditional control flow instructions by placing blocks next to each other, not so much for conditionals. In terms of implementation we simply give conditional branches less weight before computing the layout. Fixes #18053 - - - - - b7a6b2f4 by Gleb Popov at 2020-05-21T12:15:26-04:00 gitlab-ci: Set locale to C.UTF-8. - - - - - a8c27cf6 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Allow spaces in GHCi :script file names This patch updates the user interface of GHCi so that file names passed to the ':script' command may contain spaces escaped with a backslash. For example: :script foo\ bar.script The implementation uses a modified version of 'words' that does not break on escaped spaces. Fixes #18027. - - - - - 82663959 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Add extra tests for GHCi :script syntax checks The syntax for GHCi's ":script" command allows for only a single file name to be passed as an argument. This patch adds a test for the cases in which a file name is missing or multiple file names are passed. Related to #T18027. - - - - - a0b79e1b by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Allow GHCi :script file names in double quotes This patch updates the user interface of GHCi so that file names passed to the ':script' command can be wrapped in double quotes. For example: :script "foo bar.script" The implementation uses a modified version of 'words' that treats character sequences enclosed in double quotes as single words. Fixes #18027. - - - - - cf566330 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Update documentation for GHCi :script This patch adds the fixes that allow for file names containing spaces to be passed to GHCi's ':script' command to the release notes for 8.12 and expands the user-guide documentation for ':script' by mentioning how such file names can be passed. Related to #18027. - - - - - 0004ccb8 by Tuan Le at 2020-05-21T12:16:46-04:00 llvmGen: Consider Relocatable read-only data as not constantReferences: #18137 - - - - - 964d3ea2 by John Ericson at 2020-05-21T12:17:30-04:00 Use `Checker` for `tc_pat` - - - - - b797aa42 by John Ericson at 2020-05-21T12:17:30-04:00 Use `Checker` for `tc_lpat` and `tc_lpats` - - - - - 5108e84a by John Ericson at 2020-05-21T12:17:30-04:00 More judiciously panic in `ts_pat` - - - - - 510e0451 by John Ericson at 2020-05-21T12:17:30-04:00 Put `PatEnv` first in `GHC.Tc.Gen.Pat.Checker` - - - - - cb4231db by John Ericson at 2020-05-21T12:17:30-04:00 Tiny cleaup eta-reduce away a function argument In GHC, not in the code being compiled! - - - - - 6890c38d by John Ericson at 2020-05-21T12:17:30-04:00 Use braces with do in `SplicePat` case for consistency - - - - - 3451584f by buggymcbugfix at 2020-05-21T12:18:06-04:00 Fix spelling mistakes and typos - - - - - b552e531 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Add INLINABLE pragmas to Enum list producers The INLINABLE pragmas ensure that we export stable (unoptimised) unfoldings in the interface file so we can do list fusion at usage sites. Related tickets: #15185, #8763, #18178. - - - - - e7480063 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Piggyback on Enum Word methods for Word64 If we are on a 64 bit platform, we can use the efficient Enum Word methods for the Enum Word64 instance. - - - - - 892b0c41 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Document INLINE(ABLE) pragmas that enable fusion - - - - - 2b363ebb by Richard Eisenberg at 2020-05-21T12:18:45-04:00 MR template should ask for key part - - - - - a95bbd0b by Sebastian Graf at 2020-05-21T12:19:37-04:00 Make `Int`'s `mod` and `rem` strict in their first arguments They used to be strict until 4d2ac2d (9 years ago). It's obviously better to be strict for performance reasons. It also blocks #18067. NoFib results: ``` -------------------------------------------------------------------------------- Program Allocs Instrs -------------------------------------------------------------------------------- integer -1.1% +0.4% wheel-sieve2 +21.2% +20.7% -------------------------------------------------------------------------------- Min -1.1% -0.0% Max +21.2% +20.7% Geometric Mean +0.2% +0.2% ``` The regression in `wheel-sieve2` is due to reboxing that likely will go away with the resolution of #18067. See !3282 for details. Fixes #18187. - - - - - d3d055b8 by Galen Huntington at 2020-05-21T12:20:18-04:00 Clarify pitfalls of NegativeLiterals; see #18022. - - - - - 1b508a9e by Alexey Kuleshevich at 2020-05-21T12:21:02-04:00 Fix wording in primops documentation to reflect the correct reasoning: * Besides resizing functions, shrinking ones also mutate the size of a mutable array and because of those two `sizeofMutabeByteArray` and `sizeofSmallMutableArray` are now deprecated * Change reference in documentation to the newer functions `getSizeof*` instead of `sizeof*` for shrinking functions * Fix incorrect mention of "byte" instead of "small" - - - - - 4ca0c8a1 by Andreas Klebinger at 2020-05-21T12:21:53-04:00 Don't variable-length encode magic iface constant. We changed to use variable length encodings for many types by default, including Word32. This makes sense for numbers but not when Word32 is meant to represent four bytes. I added a FixedLengthEncoding newtype to Binary who's instances interpret their argument as a collection of bytes instead of a number. We then use this when writing/reading magic numbers to the iface file. I also took the libery to remove the dummy iface field. This fixes #18180. - - - - - a1275081 by Krzysztof Gogolewski at 2020-05-21T12:22:35-04:00 Add a regression test for #11506 The testcase works now. See explanation in https://gitlab.haskell.org/ghc/ghc/issues/11506#note_273202 - - - - - 8a816e5f by Krzysztof Gogolewski at 2020-05-21T12:23:55-04:00 Sort deterministically metric output Previously, we sorted according to the test name and way, but the metrics (max_bytes_used/peak_megabytes_allocated etc.) were appearing in nondeterministic order. - - - - - 566cc73f by Sylvain Henry at 2020-05-21T12:24:45-04:00 Move isDynLinkName into GHC.Types.Name It doesn't belong into GHC.Unit.State - - - - - d830bbc9 by Adam Sandberg Ericsson at 2020-05-23T13:36:20-04:00 docs: fix formatting and add some links [skip ci] - - - - - 49301ad6 by Andrew Martin at 2020-05-23T13:37:01-04:00 Implement cstringLength# and FinalPtr This function and its accompanying rule resolve issue #5218. A future PR to the bytestring library will make the internal Data.ByteString.Internal.unsafePackAddress compute string length with cstringLength#. This will improve the status quo because it is eligible for constant folding. Additionally, introduce a new data constructor to ForeignPtrContents named FinalPtr. This additional data constructor, when used in the IsString instance for ByteString, leads to more Core-to-Core optimization opportunities, fewer runtime allocations, and smaller binaries. Also, this commit re-exports all the functions from GHC.CString (including cstringLength#) in GHC.Exts. It also adds a new test driver. This test driver is used to perform substring matches on Core that is dumped after all the simplifier passes. In this commit, it is used to check that constant folding of cstringLength# works. - - - - - dcd6bdcc by Ben Gamari at 2020-05-23T13:37:48-04:00 simplCore: Ignore ticks in rule templates This fixes #17619, where a tick snuck in to the template of a rule, resulting in a panic during rule matching. The tick in question was introduced via post-inlining, as discussed in `Note [Simplifying rules]`. The solution we decided upon was to simply ignore ticks in the rule template, as discussed in `Note [Tick annotations in RULE matching]`. Fixes #18162. Fixes #17619. - - - - - 82cb8913 by John Ericson at 2020-05-23T13:38:32-04:00 Fix #18145 and also avoid needless work with implicit vars - `forAllOrNothing` now is monadic, so we can trace whether we bind an explicit `forall` or not. - #18145 arose because the free vars calculation was needlessly complex. It is now greatly simplified. - Replaced some other implicit var code with `filterFreeVarsToBind`. Co-authored-by: Ryan Scott <ryan.gl.scott at gmail.com> - - - - - a60dc835 by Ben Gamari at 2020-05-23T13:39:12-04:00 Bump process submodule Fixes #17926. - - - - - 856adf54 by Ben Gamari at 2020-05-23T13:40:21-04:00 users-guide: Clarify meaning of -haddock flag Fixes #18206. - - - - - 7ae57afd by Ben Gamari at 2020-05-23T13:41:03-04:00 git: Add ignored commits file This can be used to tell git to ignore bulk renaming commits like the recently-finished module hierarchy refactoring. Configured with, git config blame.ignoreRevsFile .git-ignore-revs - - - - - 63d30e60 by jneira at 2020-05-24T01:54:42-04:00 Add hie-bios script for windows systems It is a direct translation of the sh script - - - - - 59182b88 by jneira at 2020-05-24T01:54:42-04:00 Honour previous values for CABAL and CABFLAGS The immediate goal is let the hie-bios.bat script set CABFLAGS with `-v0` and remove all cabal output except the compiler arguments - - - - - 932dc54e by jneira at 2020-05-24T01:54:42-04:00 Add specific configuration for windows in hie.yaml - - - - - e0eda070 by jneira at 2020-05-24T01:54:42-04:00 Remove not needed hie-bios output - - - - - a0ea59d6 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Move Config module into GHC.Settings - - - - - 37430251 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Rename GHC.Core.Arity into GHC.Core.Opt.Arity - - - - - a426abb9 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Rename GHC.Hs.Types into GHC.Hs.Type See discussion in https://gitlab.haskell.org/ghc/ghc/issues/13009#note_268610 - - - - - 1c91a7a0 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Bump haddock submodule - - - - - 66bd24d1 by Ryan Scott at 2020-05-24T01:56:03-04:00 Add orderingTyCon to wiredInTyCons (#18185) `Ordering` needs to be wired in for use in the built-in `CmpNat` and `CmpSymbol` type families, but somehow it was never added to the list of `wiredInTyCons`, leading to the various oddities observed in #18185. Easily fixed by moving `orderingTyCon` from `basicKnownKeyNames` to `wiredInTyCons`. Fixes #18185. - - - - - 01c43634 by Matthew Pickering at 2020-05-24T01:56:42-04:00 Remove unused hs-boot file - - - - - 7a07aa71 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix cross-compiler build (#16051) - - - - - 15ccca16 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix distDir per stage - - - - - b420fb24 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix hp2ps error during cross-compilation Fixed by @alp (see https://gitlab.haskell.org/ghc/ghc/issues/16051#note_274265) - - - - - cd339ef0 by Joshua Price at 2020-05-24T15:22:56-04:00 Make Unicode brackets opening/closing tokens (#18225) The tokens `[|`, `|]`, `(|`, and `|)` are opening/closing tokens as described in GHC Proposal #229. This commit makes the unicode variants (`⟦`, `⟧`, `⦇`, and `⦈`) act the same as their ASCII counterparts. - - - - - 013d7120 by Ben Gamari at 2020-05-25T09:48:17-04:00 Revert "Specify kind variables for inferred kinds in base." As noted in !3132, this has rather severe knock-on consequences in user-code. We'll need to revisit this before merging something along these lines. This reverts commit 9749fe1223d182b1f8e7e4f7378df661c509f396. - - - - - 4c4312ed by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Drop redundant ad-hoc boot module check To determine whether the module is a boot module Coverage.addTicksToBinds was checking for a `boot` suffix in the module source filename. This is quite ad-hoc and shouldn't be necessary; the callsite in `deSugar` already checks that the module isn't a boot module. - - - - - 1abf3c84 by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Make tickBoxCount strict This could otherwise easily cause a leak of (+) thunks. - - - - - b2813750 by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Make ccIndices strict This just seems like a good idea. - - - - - 02e278eb by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Don't produce ModBreaks if not HscInterpreted emptyModBreaks contains a bottom and consequently it's important that we don't use it unless necessary. - - - - - b8c014ce by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Factor out addMixEntry - - - - - 53814a64 by Zubin Duggal at 2020-05-26T03:03:24-04:00 Add info about typeclass evidence to .hie files See `testsuite/tests/hiefile/should_run/HieQueries.hs` and `testsuite/tests/hiefile/should_run/HieQueries.stdout` for an example of this We add two new fields, `EvidenceVarBind` and `EvidenceVarUse` to the `ContextInfo` associated with an Identifier. These are associated with the appropriate identifiers for the evidence variables collected when we come across `HsWrappers`, `TcEvBinds` and `IPBinds` while traversing the AST. Instance dictionary and superclass selector dictionaries from `tcg_insts` and classes defined in `tcg_tcs` are also recorded in the AST as originating from their definition span This allows us to save a complete picture of the evidence constructed by the constraint solver, and will let us report this to the user, enabling features like going to the instance definition from the invocation of a class method(or any other method taking a constraint) and finding all usages of a particular instance. Additionally, - Mark NodeInfo with an origin so we can differentiate between bindings origininating in the source vs those in ghc - Along with typeclass evidence info, also include information on Implicit Parameters - Add a few utility functions to HieUtils in order to query the new info Updates haddock submodule - - - - - 6604906c by Sebastian Graf at 2020-05-26T03:04:04-04:00 Make WorkWrap.Lib.isWorkerSmallEnough aware of the old arity We should allow a wrapper with up to 82 parameters when the original function had 82 parameters to begin with. I verified that this made no difference on NoFib, but then again it doesn't use huge records... Fixes #18122. - - - - - cf772f19 by Sylvain Henry at 2020-05-26T03:04:45-04:00 Enhance Note [About units] for Backpack - - - - - ede24126 by Takenobu Tani at 2020-05-27T00:13:55-04:00 core-spec: Modify file paths according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * GHC/Core.hs <= coreSyn/CoreSyn.hs * GHC/Core/Coercion.hs <= types/Coercion.hs * GHC/Core/Coercion/Axiom.hs <= types/CoAxiom.hs * GHC/Core/Coercion/Opt.hs <= types/OptCoercion.hs * GHC/Core/DataCon.hs <= basicTypes/DataCon.hs * GHC/Core/FamInstEnv.hs <= types/FamInstEnv.hs * GHC/Core/Lint.hs <= coreSyn/CoreLint.hs * GHC/Core/Subst.hs <= coreSyn/CoreSubst.hs * GHC/Core/TyCo/Rep.hs <= types/TyCoRep.hs * GHC/Core/TyCon.hs <= types/TyCon.hs * GHC/Core/Type.hs <= types/Type.hs * GHC/Core/Unify.hs <= types/Unify.hs * GHC/Types/Literal.hs <= basicTypes/Literal.hs * GHC/Types/Var.hs <= basicTypes/Var.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [skip ci] - - - - - 04750304 by Ben Gamari at 2020-05-27T00:14:33-04:00 eventlog: Fix racy flushing Previously no attempt was made to avoid multiple threads writing their capability-local eventlog buffers to the eventlog writer simultaneously. This could result in multiple eventlog streams being interleaved. Fix this by documenting that the EventLogWriter's write() and flush() functions may be called reentrantly and fix the default writer to protect its FILE* by a mutex. Fixes #18210. - - - - - d6203f24 by Joshua Price at 2020-05-27T00:15:17-04:00 Make `identifier` parse unparenthesized `->` (#18060) - - - - - 28deee28 by Ben Gamari at 2020-05-28T16:23:21-04:00 GHC.Core.Unfold: Refactor traceInline This reduces duplication as well as fixes a bug wherein -dinlining-check would override -ddump-inlinings. Moreover, the new variant - - - - - 1f393e1e by Ben Gamari at 2020-05-28T16:23:21-04:00 Avoid unnecessary allocations due to tracing utilities While ticky-profiling the typechecker I noticed that hundreds of millions of SDocs are being allocated just in case -ddump-*-trace is enabled. This is awful. We avoid this by ensuring that the dump flag check is inlined into the call site, ensuring that the tracing document needn't be allocated unless it's actually needed. See Note [INLINE conditional tracing utilities] for details. Fixes #18168. Metric Decrease: T9961 haddock.Cabal haddock.base haddock.compiler - - - - - 5f621a78 by Vladislav Zavialov at 2020-05-28T16:23:58-04:00 Add Semigroup/Monoid for Q (#18123) - - - - - dc5f004c by Xavier Denis at 2020-05-28T16:24:37-04:00 Fix #18071 Run the core linter on candidate instances to ensure they are well-kinded. Better handle quantified constraints by using a CtWanted to avoid having unsolved constraints thrown away at the end by the solver. - - - - - 10e6982c by Sebastian Graf at 2020-05-28T16:25:14-04:00 FloatOut: Only eta-expand dead-end RHS if arity will increase (#18231) Otherwise we risk turning trivial RHS into non-trivial RHS, introducing unnecessary bindings in the next Simplifier run, resulting in more churn. Fixes #18231. - - - - - 08dab5f7 by Sebastian Graf at 2020-05-28T16:25:14-04:00 DmdAnal: Recognise precise exceptions from case alternatives (#18086) Consider ```hs m :: IO () m = do putStrLn "foo" error "bar" ``` `m` (from #18086) always throws a (precise or imprecise) exception or diverges. Yet demand analysis infers `<L,A>` as demand signature instead of `<L,A>x` for it. That's because the demand analyser sees `putStrLn` occuring in a case scrutinee and decides that it has to `deferAfterPreciseException`, because `putStrLn` throws a precise exception on some control flow paths. This will mask the `botDiv` `Divergence`of the single case alt containing `error` to `topDiv`. Since `putStrLn` has `topDiv` itself, the final `Divergence` is `topDiv`. This is easily fixed: `deferAfterPreciseException` works by `lub`ing with the demand type of a virtual case branch denoting the precise exceptional control flow. We used `nopDmdType` before, but we can be more precise and use `exnDmdType`, which is `nopDmdType` with `exnDiv`. Now the `Divergence` from the case alt will degrade `botDiv` to `exnDiv` instead of `topDiv`, which combines with the result from the scrutinee to `exnDiv`, and all is well. Fixes #18086. - - - - - aef95f11 by Ben Gamari at 2020-05-28T16:25:53-04:00 Ticky-ticky: Record DataCon name in ticker name This makes it significantly easier to spot the nature of allocations regressions and comes at a reasonably low cost. - - - - - 8f021b8c by Ben Gamari at 2020-05-28T16:26:34-04:00 hadrian: Don't track GHC's verbosity argument Teach hadrian to ignore GHC's -v argument in its recompilation check, thus fixing #18131. - - - - - 13d9380b by Ben Gamari at 2020-05-28T16:27:20-04:00 Rip out CmmStackInfo(updfr_space) As noted in #18232, this field is currently completely unused and moreover doesn't have a clear meaning. - - - - - f10d11fa by Andreas Klebinger at 2020-05-29T01:38:42-04:00 Fix "build/elem" RULE. An redundant constraint prevented the rule from matching. Fixing this allows a call to elem on a known list to be translated into a series of equality checks, and eventually a simple case expression. Surprisingly this seems to regress elem for strings. To avoid this we now also allow foldrCString to inline and add an UTF8 variant. This results in elem being compiled to a tight non-allocating loop over the primitive string literal which performs a linear search. In the process this commit adds UTF8 variants for some of the functions in GHC.CString. This is required to make this work for both ASCII and UTF8 strings. There are also small tweaks to the CString related rules. We now allow ourselfes the luxury to compare the folding function via eqExpr, which helps to ensure the rule fires before we inline foldrCString*. Together with a few changes to allow matching on both the UTF8 and ASCII variants of the CString functions. - - - - - bbeb2389 by Ben Gamari at 2020-05-29T01:39:19-04:00 CoreToStg: Add Outputable ArgInfo instance - - - - - 0e3361ca by Simon Peyton Jones at 2020-05-29T01:39:19-04:00 Make Lint check return type of a join point Consider join x = rhs in body It's important that the type of 'rhs' is the same as the type of 'body', but Lint wasn't checking that invariant. Now it does! This was exposed by investigation into !3113. - - - - - c49f7df0 by Simon Peyton Jones at 2020-05-29T01:39:19-04:00 Do not float join points in exprIsConApp_maybe We hvae been making exprIsConApp_maybe cleverer in recent times: commit b78cc64e923716ac0512c299f42d4d0012306c05 Date: Thu Nov 15 17:14:31 2018 +0100 Make constructor wrappers inline only during the final phase commit 7833cf407d1f608bebb1d38bb99d3035d8d735e6 Date: Thu Jan 24 17:58:50 2019 +0100 Look through newtype wrappers (Trac #16254) commit c25b135ff5b9c69a90df0ccf51b04952c2dc6ee1 Date: Thu Feb 21 12:03:22 2019 +0000 Fix exprIsConApp_maybe But alas there was still a bug, now immortalised in Note [Don't float join points] in SimpleOpt. It's quite hard to trigger because it requires a dead join point, but it came up when compiling Cabal Cabal.Distribution.Fields.Lexer.hs, when working on !3113. Happily, the fix is extremly easy. Finding the bug was not so easy. - - - - - 46720997 by Ben Gamari at 2020-05-29T01:39:19-04:00 Allow simplification through runRW# Because runRW# inlines so late, we were previously able to do very little simplification across it. For instance, given even a simple program like case runRW# (\s -> let n = I# 42# in n) of I# n# -> f n# we previously had no way to avoid the allocation of the I#. This patch allows the simplifier to push strict contexts into the continuation of a runRW# application, as explained in in Note [Simplification of runRW#] in GHC.CoreToStg.Prep. Fixes #15127. Metric Increase: T9961 Metric Decrease: ManyConstructors Co-Authored-By: Simon Peyton-Jone <simonpj at microsoft.com> - - - - - 277c2f26 by Ben Gamari at 2020-05-29T01:39:55-04:00 Eta expand un-saturated primops Now since we no longer try to predict CAFfyness we have no need for the solution to #16846. Eta expanding unsaturated primop applications is conceptually simpler, especially in the presence of levity polymorphism. This essentially reverts cac8dc9f51e31e4c0a6cd9bc302f7e1bc7c03beb, as suggested in #18079. Closes #18079. - - - - - f44d7ae0 by Simon Jakobi at 2020-05-29T01:40:34-04:00 base: Scrap deprecation plan for Data.Monoid.{First,Last} See the discussion on the libraries mailing list for context: https://mail.haskell.org/pipermail/libraries/2020-April/030357.html - - - - - 8b494895 by Jeremy Schlatter at 2020-05-29T01:41:12-04:00 Fix typo in documentation - - - - - 998450f4 by Gleb Popov at 2020-05-29T01:41:53-04:00 Always define USE_PTHREAD_FOR_ITIMER for FreeBSD. - - - - - f9a513e0 by Alp Mestanogullari at 2020-05-29T01:42:36-04:00 hadrian: introduce 'install' target Its logic is very simple. It `need`s the `binary-dist-dir` target and runs suitable `configure` and `make install` commands for the user. A new `--prefix` command line argument is introduced to specify where GHC should be installed. - - - - - 67738db1 by Travis Whitaker at 2020-05-29T13:34:48-04:00 Build a threaded stage 1 if the bootstrapping GHC supports it. - - - - - aac19e6c by Peter Trommler at 2020-05-29T13:35:24-04:00 PPC NCG: No per-symbol .section ".toc" directives All position independent symbols are collected during code generation and emitted in one go. Prepending each symbol with a .section ".toc" directive is redundant. This patch drops the per-symbol directives leading to smaller assembler files. Fixes #18250 - - - - - 4413828b by Ben Gamari at 2020-05-30T06:07:31-04:00 rts: Teach getNumProcessors to return available processors Previously we would report the number of physical processors, which can be quite wrong in a containerized setting. Now we rather return how many processors are in our affinity mask when possible. I also refactored the code to prefer platform-specific since this will report logical CPUs instead of physical (using `machdep.cpu.thread_count` on Darwin and `cpuset_getaffinity` on FreeBSD). Fixes #14781. - - - - - 1449435c by Ben Gamari at 2020-05-30T06:07:31-04:00 users-guide: Note change in getNumProcessors in users guide - - - - - 3d960169 by Ben Gamari at 2020-05-30T06:07:31-04:00 rts: Drop compatibility shims for Windows Vista We can now assume that the thread and processor group interfaces are available. - - - - - 7f8f948c by Peter Trommler at 2020-05-30T06:08:07-04:00 PPC NCG: Fix .size directive on powerpc64 ELF v1 Thanks to Sergei Trofimovich for pointing out the issue. Fixes #18237 - - - - - 7c555b05 by Andreas Klebinger at 2020-05-30T06:08:43-04:00 Optimize GHC.Utils.Monad. Many functions in this module are recursive and as such are marked loop breakers. Which means they are unlikely to get an unfolding. This is *bad*. We always want to specialize them to specific Monads. Which requires a visible unfolding at the use site. I rewrote the recursive ones from: foo f x = ... foo x' ... to foo f x = go x where go x = ... As well as giving some pragmas to make all of them available for specialization. The end result is a reduction of allocations of about -1.4% for nofib/spectral/simple/Main.hs when compiled with `-O`. ------------------------- Metric Decrease: T12425 T14683 T5631 T9233 T9675 T9961 WWRec ------------------------- - - - - - 8b1cb5df by Ben Gamari at 2020-05-30T06:09:20-04:00 Windows: Bump Windows toolchain to 0.2 - - - - - 6947231a by Zubin Duggal at 2020-05-30T06:10:02-04:00 Simplify contexts in GHC.Iface.Ext.Ast - - - - - 2ee4f36c by Daniel Gröber at 2020-06-01T06:32:56-04:00 Cleanup OVERWRITING_CLOSURE logic The code is just more confusing than it needs to be. We don't need to mix the threaded check with the ldv profiling check since ldv's init already checks for this. Hence they can be two separate checks. Taking the sanity checking into account is also cleaner via DebugFlags.sanity. No need for checking the DEBUG define. The ZERO_SLOP_FOR_LDV_PROF and ZERO_SLOP_FOR_SANITY_CHECK definitions the old code had also make things a lot more opaque IMO so I removed those. - - - - - 6159559b by Daniel Gröber at 2020-06-01T06:32:56-04:00 Fix OVERWRITING_CLOSURE assuming closures are not inherently used The new ASSERT in LDV_recordDead() was being tripped up by MVars when removeFromMVarBlockedQueue() calls OVERWRITING_CLOSURE() via OVERWRITE_INFO(). - - - - - 38992085 by Daniel Gröber at 2020-06-01T06:32:56-04:00 Always zero shrunk mutable array slop when profiling When shrinking arrays in the profiling way we currently don't always zero the leftover slop. This means we can't traverse such closures in the heap profiler. The old Note [zeroing slop] and #8402 have some rationale for why this is so but I belive the reasoning doesn't apply to mutable closures. There users already have to ensure multiple threads don't step on each other's toes so zeroing should be safe. - - - - - b0c1f2a6 by Ben Gamari at 2020-06-01T06:33:37-04:00 testsuite: Add test for #18151 - - - - - 9a99a178 by Ben Gamari at 2020-06-01T06:33:37-04:00 testsuite: Add test for desugaring of PostfixOperators - - - - - 2b89ca5b by Ben Gamari at 2020-06-01T06:33:37-04:00 HsToCore: Eta expand left sections Strangely, the comment next to this code already alluded to the fact that even simply eta-expanding will sacrifice laziness. It's quite unclear how we regressed so far. See #18151. - - - - - d412d7a3 by Kirill Elagin at 2020-06-01T06:34:21-04:00 Winferred-safe-imports: Do not exit with error Currently, when -Winferred-safe-imports is enabled, even when it is not turned into an error, the compiler will still exit with exit code 1 if this warning was emitted. Make sure it is really treated as a warning. - - - - - f945eea5 by Ben Gamari at 2020-06-01T06:34:58-04:00 nonmoving: Optimise log2_ceil - - - - - aab606e4 by Bodigrim at 2020-06-01T06:35:36-04:00 Clarify description of fromListN - - - - - 7e5220e2 by Bodigrim at 2020-06-01T06:35:36-04:00 Apply suggestion to libraries/base/GHC/Exts.hs - - - - - f3fb1ce9 by fendor at 2020-06-01T06:36:18-04:00 Add `isInScope` check to `lintCoercion` Mirrors the behaviour of `lintType`. - - - - - 5ac4d946 by fendor at 2020-06-01T06:36:18-04:00 Lint rhs of IfaceRule - - - - - 1cef6126 by Jeremy Schlatter at 2020-06-01T06:37:00-04:00 Fix wording in documentation The duplicate "orphan instance" phrase here doesn't make sense, and was probably an accident. - - - - - 5aaf08f2 by Takenobu Tani at 2020-06-01T06:37:43-04:00 configure: Modify aclocal.m4 according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * Rename: * compiler/GHC/Parser.hs <= compiler/parser/Parser.hs * compiler/GHC/Parser/Lexer.hs <= compiler/Parser/Lexer.hs * Add: * compiler/GHC/Cmm/Lexer.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular - - - - - 15857ad8 by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Don't fail if we can't unlink __symlink_test Afterall, it's possible we were unable to create it due to lack of symlink permission. - - - - - 4a7229ef by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Refactor ghostscript detection Tamar reported that he saw crashes due to unhandled exceptions. - - - - - 2ab37eaf by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite/perf_notes: Fix ill-typed assignments - - - - - e45d5b66 by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite/testutil: Fix bytes/str mismatch - - - - - 7002d0cb by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Work around spurious mypy failure - - - - - 11390e3a by Takenobu Tani at 2020-06-01T06:39:05-04:00 Clean up file paths for new module hierarchy This updates comments only. This patch replaces file references according to new module hierarchy. See also: * https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular * https://gitlab.haskell.org/ghc/ghc/issues/13009 - - - - - 8f2e5732 by Takenobu Tani at 2020-06-01T06:39:05-04:00 Modify file paths to module paths for new module hierarchy This updates comments only. This patch replaces module references according to new module hierarchy [1][2]. For files under the `compiler/` directory, I replace them as module paths instead of file paths. For instance, `GHC.Unit.State` instead of `compiler/GHC/Unit/State.hs` [3]. For current and future haddock's markup, this patch encloses the module name with "" [4]. [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: https://gitlab.haskell.org/ghc/ghc/issues/13009 [3]: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3375#note_276613 [4]: https://haskell-haddock.readthedocs.io/en/latest/markup.html#linking-to-modules - - - - - 68b71c4a by Tom Ellis at 2020-06-01T06:39:55-04:00 Rename the singleton tuple GHC.Tuple.Unit to GHC.Tuple.Solo - - - - - 95da76c2 by Sylvain Henry at 2020-06-01T06:40:41-04:00 Hadrian: fix binary-dist target for cross-compilation - - - - - 730fcd54 by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for the @-operator Since GHC diverges from the Haskell Report by allowing the user to define (@) as an infix operator, we better give a good error message when the user does so unintentionally. In general, this is rather hard to do, as some failures will be discovered only in the renamer or the type checker: x :: (Integer, Integer) x @ (a, b) = (1, 2) This patch does *not* address this general case. However, it gives much better error messages when the binding is not syntactically valid: pairs xs @ (_:xs') = zip xs xs' Before this patch, the error message was rather puzzling: <interactive>:1:1: error: Parse error in pattern: pairs After this patch, the error message includes a hint: <interactive>:1:1: error: Parse error in pattern: pairs In a function binding for the ‘@’ operator. Perhaps you meant an as-pattern, which must not be surrounded by whitespace - - - - - 0fde5377 by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for TypeApplications With this patch, we always parse f @t as a type application, thereby producing better error messages. This steals two syntactic forms: * Prefix form of the @-operator in expressions. Since the @-operator is a divergence from the Haskell Report anyway, this is not a major loss. * Prefix form of @-patterns. Since we are stealing loose infix form anyway, might as well sacrifice the prefix form for the sake of much better error messages. - - - - - c68e7e1e by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for TemplateHaskellQuotes While [e| |], [t| |], [d| |], and so on, steal syntax from list comprehensions, [| |] and [|| ||] do not steal any syntax. Thus we can improve error messages by always accepting them in the lexer. Turns out the renamer already performs necessary validation. - - - - - 120aedbd by Ben Gamari at 2020-06-01T16:07:02-04:00 gitlab-ci: Disable use of ld.lld on ARMv7 It turns out that lld non-deterministically fails on ARMv7. I suspect this may be due to the a kernel regression as this only started happening when we upgraded to 5.4. Nevertheless, easily avoided by simply sticking with gold. Works around #18280. - - - - - d6279ff0 by Ben Gamari at 2020-06-02T13:03:30-04:00 gitlab-ci: Ensure that workaround for #18280 applies to bindisttest We need to ensure that the `configure` flags working around #18280 are propagated to the bindisttest `configure` as well. - - - - - cb5c31b5 by Ben Gamari at 2020-06-03T17:55:04-04:00 gitlab-ci: Allow ARMv7 job to fail Due to #18298. - - - - - 32a4ae90 by John Ericson at 2020-06-04T04:34:42-04:00 Clean up boot vs non-boot disambiguating types We often have (ModuleName, Bool) or (Module, Bool) pairs for "extended" module names (without or with a unit id) disambiguating boot and normal modules. We think this is important enough across the compiler that it deserves a new nominal product type. We do this with synnoyms and a functor named with a `Gen` prefix, matching other newly created definitions. It was also requested that we keep custom `IsBoot` / `NotBoot` sum type. So we have it too. This means changing many the many bools to use that instead. Updates `haddock` submodule. - - - - - c05756cd by Niklas Hambüchen at 2020-06-04T04:35:24-04:00 docs: Add more details on InterruptibleFFI. Details from https://gitlab.haskell.org/ghc/ghc/issues/8684 and https://github.com/takano-akio/filelock/pull/7#discussion_r280332430 - - - - - 1b975aed by Andrew Martin at 2020-06-04T04:36:03-04:00 Allow finalizeForeignPtr to be called on FinalPtr/PlainPtr. MR 2165 (commit 49301ad6226d9a83d110bee8c419615dd94f5ded) regressed finalizeForeignPtr by throwing exceptions when PlainPtr was encounterd. This regression did not make it into a release of GHC. Here, the original behavior is restored, and FinalPtr is given the same treatment as PlainPtr. - - - - - 2bd3929a by Luke Lau at 2020-06-04T04:36:41-04:00 Fix documentation on type families not being extracted It looks like the location of the Names used for CoAxioms on type families are now located at their type constructors. Previously, Docs.hs thought the Names were located in the RHS, so the RealSrcSpan in the instanceMap and getInstLoc didn't match up. Fixes #18241 - - - - - 6735b9d9 by Ben Gamari at 2020-06-04T04:37:21-04:00 GHC.Hs.Instances: Compile with -O0 This module contains exclusively Data instances, which are going to be slow no matter what we do. Furthermore, they are incredibly slow to compile with optimisation (see #9557). Consequently we compile this with -O0. See #18254. - - - - - c330331a by nineonine at 2020-06-04T04:37:59-04:00 Add test for #17669 - - - - - cab684f0 by Ben Gamari at 2020-06-04T04:38:36-04:00 rts: Add Windows-specific implementation of rtsSleep Previously we would use the POSIX path, which uses `nanosleep`. However, it turns out that `nanosleep` is provided by `libpthread` on Windows. In general we don't want to incur such a dependency. Avoid this by simply using `Sleep` on Windows. Fixes #18272. - - - - - ad44b504 by Ben Gamari at 2020-06-04T04:38:36-04:00 compiler: Disable use of process jobs with process < 1.6.9 Due to #17926. - - - - - 6a4098a4 by Moritz Angermann at 2020-06-04T04:55:51-04:00 [linker] Adds void printLoadedObjects(void); This allows us to dump in-memory object code locations for debugging. Fixup printLoadedObjects prototype - - - - - af5e3a88 by Artem Pelenitsyn at 2020-06-05T03:18:49-04:00 base: fix sign confusion in log1mexp implementation (fix #17125) author: claude (https://gitlab.haskell.org/trac-claude) The correct threshold for log1mexp is -(log 2) with the current specification of log1mexp. This change improves accuracy for large negative inputs. To avoid code duplication, a small helper function is added; it isn't the default implementation in Floating because it needs Ord. This patch does nothing to address that the Haskell specification is different from that in common use in other languages. - - - - - 2b792fac by Simon Peyton Jones at 2020-06-05T09:27:50-04:00 Simple subsumption This patch simplifies GHC to use simple subsumption. Ticket #17775 Implements GHC proposal #287 https://github.com/ghc-proposals/ghc-proposals/blob/master/ proposals/0287-simplify-subsumption.rst All the motivation is described there; I will not repeat it here. The implementation payload: * tcSubType and friends become noticably simpler, because it no longer uses eta-expansion when checking subsumption. * No deeplyInstantiate or deeplySkolemise That in turn means that some tests fail, by design; they can all be fixed by eta expansion. There is a list of such changes below. Implementing the patch led me into a variety of sticky corners, so the patch includes several othe changes, some quite significant: * I made String wired-in, so that "foo" :: String rather than "foo" :: [Char] This improves error messages, and fixes #15679 * The pattern match checker relies on knowing about in-scope equality constraints, andd adds them to the desugarer's environment using addTyCsDs. But the co_fn in a FunBind was missed, and for some reason simple-subsumption ends up with dictionaries there. So I added a call to addTyCsDs. This is really part of #18049. * I moved the ic_telescope field out of Implication and into ForAllSkol instead. This is a nice win; just expresses the code much better. * There was a bug in GHC.Tc.TyCl.Instance.tcDataFamInstHeader. We called checkDataKindSig inside tc_kind_sig, /before/ solveEqualities and zonking. Obviously wrong, easily fixed. * solveLocalEqualitiesX: there was a whole mess in here, around failing fast enough. I discovered a bad latent bug where we could successfully kind-check a type signature, and use it, but have unsolved constraints that could fill in coercion holes in that signature -- aargh. It's all explained in Note [Failure in local type signatures] in GHC.Tc.Solver. Much better now. * I fixed a serious bug in anonymous type holes. IN f :: Int -> (forall a. a -> _) -> Int that "_" should be a unification variable at the /outer/ level; it cannot be instantiated to 'a'. This was plain wrong. New fields mode_lvl and mode_holes in TcTyMode, and auxiliary data type GHC.Tc.Gen.HsType.HoleMode. This fixes #16292, but makes no progress towards the more ambitious #16082 * I got sucked into an enormous refactoring of the reporting of equality errors in GHC.Tc.Errors, especially in mkEqErr1 mkTyVarEqErr misMatchMsg misMatchMsgOrCND In particular, the very tricky mkExpectedActualMsg function is gone. It took me a full day. But the result is far easier to understand. (Still not easy!) This led to various minor improvements in error output, and an enormous number of test-case error wibbles. One particular point: for occurs-check errors I now just say Can't match 'a' against '[a]' rather than using the intimidating language of "occurs check". * Pretty-printing AbsBinds Tests review * Eta expansions T11305: one eta expansion T12082: one eta expansion (undefined) T13585a: one eta expansion T3102: one eta expansion T3692: two eta expansions (tricky) T2239: two eta expansions T16473: one eta determ004: two eta expansions (undefined) annfail06: two eta (undefined) T17923: four eta expansions (a strange program indeed!) tcrun035: one eta expansion * Ambiguity check at higher rank. Now that we have simple subsumption, a type like f :: (forall a. Eq a => Int) -> Int is no longer ambiguous, because we could write g :: (forall a. Eq a => Int) -> Int g = f and it'd typecheck just fine. But f's type is a bit suspicious, and we might want to consider making the ambiguity check do a check on each sub-term. Meanwhile, these tests are accepted, whereas they were previously rejected as ambiguous: T7220a T15438 T10503 T9222 * Some more interesting error message wibbles T13381: Fine: one error (Int ~ Exp Int) rather than two (Int ~ Exp Int, Exp Int ~ Int) T9834: Small change in error (improvement) T10619: Improved T2414: Small change, due to order of unification, fine T2534: A very simple case in which a change of unification order means we get tow unsolved constraints instead of one tc211: bizarre impredicative tests; just accept this for now Updates Cabal and haddock submodules. Metric Increase: T12150 T12234 T5837 haddock.base Metric Decrease: haddock.compiler haddock.Cabal haddock.base Merge note: This appears to break the `UnliftedNewtypesDifficultUnification` test. It has been marked as broken in the interest of merging. (cherry picked from commit 66b7b195cb3dce93ed5078b80bf568efae904cc5) - - - - - 2dff8141 by Ryan Scott at 2020-06-05T14:21:24-04:00 Simplify bindLHsTyVarBndrs and bindHsQTyVars Both `bindLHsTyVarBndrs` and `bindHsQTyVars` take two separate `Maybe` arguments, which I find terribly confusing. Thankfully, it's possible to remove one `Maybe` argument from each of these functions, which this patch accomplishes: * `bindHsQTyVars` takes a `Maybe SDoc` argument, which is `Just` if GHC should warn about any of the quantified type variables going unused. However, every call site uses `Nothing` in practice. This makes sense, since it doesn't really make sense to warn about unused type variables bound by an `LHsQTyVars`. For instance, you wouldn't warn about the `a` in `data Proxy a = Proxy` going unused. As a result, I simply remove this `Maybe SDoc` argument altogether. * `bindLHsTyVarBndrs` also takes a `Maybe SDoc` argument for the same reasons that `bindHsQTyVars` took one. To make things more confusing, however, `bindLHsTyVarBndrs` also takes a separate `HsDocContext` argument, which is pretty-printed (to an `SDoc`) in warnings and error messages. In practice, the `Maybe SDoc` and the `HsDocContext` often contain the same text. See the call sites for `bindLHsTyVarBndrs` in `rnFamInstEqn` and `rnConDecl`, for instance. There are only a handful of call sites where the text differs between the `Maybe SDoc` and `HsDocContext` arguments: * In `rnHsRuleDecl`, where the `Maybe SDoc` says "`In the rule`" and the `HsDocContext` says "`In the transformation rule`". * In `rnHsTyKi`/`rn_ty`, where the `Maybe SDoc` says "`In the type`" but the `HsDocContext` is inhereted from the surrounding context (e.g., if `rnHsTyKi` were called on a top-level type signature, the `HsDocContext` would be "`In the type signature`" instead) In both cases, warnings/error messages arguably _improve_ by unifying making the `Maybe SDoc`'s text match that of the `HsDocContext`. As a result, I decided to remove the `Maybe SDoc` argument to `bindLHsTyVarBndrs` entirely and simply reuse the text from the `HsDocContext`. (I decided to change the phrase "transformation rule" to "rewrite rule" while I was in the area.) The `Maybe SDoc` argument has one other purpose: signaling when to emit "`Unused quantified type variable`" warnings. To recover this functionality, I replaced the `Maybe SDoc` argument with a boolean-like `WarnUnusedForalls` argument. The only `bindLHsTyVarBndrs` call site that chooses _not_ to emit these warnings in `bindHsQTyVars`. - - - - - e372331b by Ben Gamari at 2020-06-07T08:46:41-04:00 hadrian: Add missing deriveConstants dependency on ghcplatform.h deriveConstants wants to compile C sources which #include PosixSource.h, which itself #includes ghcplatform.h. Make sure that Hadrian knows about this dependency. Fixes #18290. - - - - - b022051a by Moritz Angermann at 2020-06-07T08:46:42-04:00 ghc-prim needs to depend on libc and libm libm is just an empty shell on musl, and all the math functions are contained in libc. - - - - - 6dae6548 by Moritz Angermann at 2020-06-07T08:46:42-04:00 Disable DLL loading if without system linker Some platforms (musl, aarch64) do not have a working dynamic linker implemented in the libc, even though we might see dlopen. It will ultimately just return that this is not supported. Hence we'll add a flag to the compiler to flat our disable loading dlls. This is needed as we will otherwise try to load the shared library even if this will subsequently fail. At that point we have given up looking for static options though. - - - - - 4a158ffc by Moritz Angermann at 2020-06-07T08:46:43-04:00 Range is actually +/-2^32, not +/-2^31 See also: https://static.docs.arm.com/ihi0056/g/aaelf64.pdf - - - - - f1bfb806 by Ben Gamari at 2020-06-07T10:49:30-04:00 OccurAnal: Avoid exponential behavior due to where clauses Previously the `Var` case of `occAnalApp` could in some cases (namely in the case of `runRW#` applications) call `occAnalRhs` two. In the case of nested `runRW#`s this results in exponential complexity. In some cases the compilation time that resulted would be very long indeed (see #18296). Fixes #18296. Metric Decrease: T9961 T12150 T12234 - - - - - 9b607671 by Takenobu Tani at 2020-06-09T08:05:46-04:00 Add link to GHC's wiki in the GHC API header This adds a URL to point to GHC's wiki in the GHC API header. Newcomers could easily find more information from the GHC API's web like [1]. [1]: Current version, https://ghc.gitlab.haskell.org/ghc/doc/libraries/ghc-8.11.0.20200604/index.html [skip ci] - - - - - 72c7fe9a by Ryan Scott at 2020-06-09T08:06:24-04:00 Make GADT constructors adhere to the forall-or-nothing rule properly Issue #18191 revealed that the types of GADT constructors don't quite adhere to the `forall`-or-nothing rule. This patch serves to clean up this sad state of affairs somewhat. The main change is not in the code itself, but in the documentation, as this patch introduces two sections to the GHC User's Guide: * A "Formal syntax for GADTs" section that presents a BNF-style grammar for what is and isn't allowed in GADT constructor types. This mostly exists to codify GHC's existing behavior, but it also imposes a new restriction that addresses #18191: the outermost `forall` and/or context in a GADT constructor is not allowed to be surrounded by parentheses. Doing so would make these `forall`s/contexts nested, and GADTs do not support nested `forall`s/contexts at present. * A "`forall`-or-nothing rule" section that describes exactly what the `forall`-or-nothing rule is all about. Surprisingly, there was no mention of this anywhere in the User's Guide up until now! To adhere the new specification in the "Formal syntax for GADTs" section of the User's Guide, the following code changes were made: * A new function, `GHC.Hs.Type.splitLHsGADTPrefixTy`, was introduced. This is very much like `splitLHsSigmaTy`, except that it avoids splitting apart any parentheses, which can be syntactically significant for GADT types. See `Note [No nested foralls or contexts in GADT constructors]` in `GHC.Hs.Type`. * `ConDeclGADTPrefixPs`, an extension constructor for `XConDecl`, was introduced so that `GHC.Parser.PostProcess.mkGadtDecl` can return it when given a prefix GADT constructor. Unlike `ConDeclGADT`, `ConDeclGADTPrefixPs` does not split the GADT type into its argument and result types, as this cannot be done until after the type is renamed (see `Note [GADT abstract syntax]` in `GHC.Hs.Decls` for why this is the case). * `GHC.Renamer.Module.rnConDecl` now has an additional case for `ConDeclGADTPrefixPs` that (1) splits apart the full `LHsType` into its `forall`s, context, argument types, and result type, and (2) checks for nested `forall`s/contexts. Step (2) used to be performed the typechecker (in `GHC.Tc.TyCl.badDataConTyCon`) rather than the renamer, but now the relevant code from the typechecker can simply be deleted. One nice side effect of this change is that we are able to give a more accurate error message for GADT constructors that use visible dependent quantification (e.g., `MkFoo :: forall a -> a -> Foo a`), which improves the stderr in the `T16326_Fail6` test case. Fixes #18191. Bumps the Haddock submodule. - - - - - a47e6442 by Ryan Scott at 2020-06-10T03:39:12-04:00 Always use rnImplicitBndrs to bring implicit tyvars into scope This implements a first step towards #16762 by changing the renamer to always use `rnImplicitBndrs` to bring implicitly bound type variables into scope. The main change is in `rnFamInstEqn` and `bindHsQTyVars`, which previously used _ad hoc_ methods of binding their implicit tyvars. There are a number of knock-on consequences: * One of the reasons that `rnFamInstEqn` used an _ad hoc_ binding mechanism was to give more precise source locations in `-Wunused-type-patterns` warnings. (See https://gitlab.haskell.org/ghc/ghc/issues/16762#note_273343 for an example of this.) However, these warnings are actually a little _too_ precise, since implicitly bound type variables don't have exact binding sites like explicitly bound type variables do. A similar problem existed for "`Different names for the same type variable`" errors involving implicit tyvars bound by `bindHsQTyVars`. Therefore, we simply accept the less precise (but more accurate) source locations from `rnImplicitBndrs` in `rnFamInstEqn` and `bindHsQTyVars`. See `Note [Source locations for implicitly bound type variables]` in `GHC.Rename.HsType` for the full story. * In order for `rnImplicitBndrs` to work in `rnFamInstEqn`, it needs to be able to look up names from the parent class (in the event that we are renaming an associated type family instance). As a result, `rnImplicitBndrs` now takes an argument of type `Maybe assoc`, which is `Just` in the event that a type family instance is associated with a class. * Previously, GHC kept track of three type synonyms for free type variables in the renamer: `FreeKiTyVars`, `FreeKiTyVarsDups` (which are allowed to contain duplicates), and `FreeKiTyVarsNoDups` (which contain no duplicates). However, making is a distinction between `-Dups` and `-NoDups` is now pointless, as all code that returns `FreeKiTyVars{,Dups,NoDups}` will eventually end up being passed to `rnImplicitBndrs`, which removes duplicates. As a result, I decided to just get rid of `FreeKiTyVarsDups` and `FreeKiTyVarsNoDups`, leaving only `FreeKiTyVars`. * The `bindLRdrNames` and `deleteBys` functions are now dead code, so I took the liberty of removing them. - - - - - 24879129 by Takenobu Tani at 2020-06-10T03:39:59-04:00 Clarify leaf module names for new module hierarchy This updates comments only. This patch replaces leaf module names according to new module hierarchy [1][2] as followings: * Expand leaf names to easily find the module path: for instance, `Id.hs` to `GHC.Types.Id`. * Modify leaf names according to new module hierarchy: for instance, `Convert.hs` to `GHC.ThToHs`. * Fix typo: for instance, `GHC.Core.TyCo.Rep.hs` to `GHC.Core.TyCo.Rep` See also !3375 [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: https://gitlab.haskell.org/ghc/ghc/issues/13009 - - - - - 92de9e25 by Ömer Sinan Ağacan at 2020-06-10T03:41:07-04:00 rts: Remove unused GET_ENTRY closure macro This macro is not used and got broken in the meantime, as ENTRY_CODE was deleted. - - - - - 87102928 by Ömer Sinan Ağacan at 2020-06-10T03:41:50-04:00 Fix -fkeep-cafs flag name in users guide - - - - - ccd6843d by Shayne Fletcher at 2020-06-10T04:14:57-04:00 Expose impliedGFlags, impledOffGFlags, impliedXFlags - - - - - 7a737e89 by Ömer Sinan Ağacan at 2020-06-10T04:14:58-04:00 Cross-module LambdaFormInfo passing - Store LambdaFormInfos of exported Ids in interface files - Use them in importing modules This is for optimization purposes: if we know LambdaFormInfo of imported Ids we can generate more efficient calling code, see `getCallMethod`. Exporting (putting them in interface files or in ModDetails) and importing (reading them from interface files) are both optional. We don't assume known LambdaFormInfos anywhere and do not change how we call Ids with unknown LambdaFormInfos. Runtime, allocation, and residency numbers when building Cabal-the-library (commit 0d4ee7ba3): (Log and .hp files are in the MR: !2842) | | GHC HEAD | This patch | Diff | |-----|----------|------------|----------------| | -O0 | 0:35.89 | 0:34.10 | -1.78s, -4.98% | | -O1 | 2:24.01 | 2:23.62 | -0.39s, -0.27% | | -O2 | 2:52.23 | 2:51.35 | -0.88s, -0.51% | | | GHC HEAD | This patch | Diff | |-----|-----------------|-----------------|----------------------------| | -O0 | 54,843,608,416 | 54,878,769,544 | +35,161,128 bytes, +0.06% | | -O1 | 227,136,076,400 | 227,569,045,168 | +432,968,768 bytes, +0.19% | | -O2 | 266,147,063,296 | 266,749,643,440 | +602,580,144 bytes, +0.22% | NOTE: Residency is measured with extra runtime args: `-i0 -h` which effectively turn all GCs into major GCs, and do GC more often. | | GHC HEAD | This patch | Diff | |-----|----------------------------|------------------------------|----------------------------| | -O0 | 410,284,000 (910 samples) | 411,745,008 (906 samples) | +1,461,008 bytes, +0.35% | | -O1 | 928,580,856 (2109 samples) | 943,506,552 (2103 samples) | +14,925,696 bytes, +1.60% | | -O2 | 993,951,352 (2549 samples) | 1,010,156,328 (2545 samples) | +16,204,9760 bytes, +1.63% | NoFib results: -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS 0.0% 0.0% +0.0% +0.0% +0.0% CSD 0.0% 0.0% 0.0% +0.0% +0.0% FS 0.0% 0.0% +0.0% +0.0% +0.0% S 0.0% 0.0% +0.0% +0.0% +0.0% VS 0.0% 0.0% +0.0% +0.0% +0.0% VSD 0.0% 0.0% +0.0% +0.0% +0.1% VSM 0.0% 0.0% +0.0% +0.0% +0.0% anna 0.0% 0.0% -0.3% -0.8% -0.0% ansi 0.0% 0.0% -0.0% -0.0% 0.0% atom 0.0% 0.0% -0.0% -0.0% 0.0% awards 0.0% 0.0% -0.1% -0.3% 0.0% banner 0.0% 0.0% -0.0% -0.0% -0.0% bernouilli 0.0% 0.0% -0.0% -0.0% -0.0% binary-trees 0.0% 0.0% -0.0% -0.0% +0.0% boyer 0.0% 0.0% -0.0% -0.0% 0.0% boyer2 0.0% 0.0% -0.0% -0.0% 0.0% bspt 0.0% 0.0% -0.0% -0.2% 0.0% cacheprof 0.0% 0.0% -0.1% -0.4% +0.0% calendar 0.0% 0.0% -0.0% -0.0% 0.0% cichelli 0.0% 0.0% -0.9% -2.4% 0.0% circsim 0.0% 0.0% -0.0% -0.0% 0.0% clausify 0.0% 0.0% -0.1% -0.3% 0.0% comp_lab_zift 0.0% 0.0% -0.0% -0.0% +0.0% compress 0.0% 0.0% -0.0% -0.0% -0.0% compress2 0.0% 0.0% -0.0% -0.0% 0.0% constraints 0.0% 0.0% -0.1% -0.2% -0.0% cryptarithm1 0.0% 0.0% -0.0% -0.0% 0.0% cryptarithm2 0.0% 0.0% -1.4% -4.1% -0.0% cse 0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e1 0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e2 0.0% 0.0% -0.0% -0.0% -0.0% dom-lt 0.0% 0.0% -0.1% -0.2% 0.0% eliza 0.0% 0.0% -0.5% -1.5% 0.0% event 0.0% 0.0% -0.0% -0.0% -0.0% exact-reals 0.0% 0.0% -0.1% -0.3% +0.0% exp3_8 0.0% 0.0% -0.0% -0.0% -0.0% expert 0.0% 0.0% -0.3% -1.0% -0.0% fannkuch-redux 0.0% 0.0% +0.0% +0.0% +0.0% fasta 0.0% 0.0% -0.0% -0.0% +0.0% fem 0.0% 0.0% -0.0% -0.0% 0.0% fft 0.0% 0.0% -0.0% -0.0% 0.0% fft2 0.0% 0.0% -0.0% -0.0% 0.0% fibheaps 0.0% 0.0% -0.0% -0.0% +0.0% fish 0.0% 0.0% 0.0% -0.0% +0.0% fluid 0.0% 0.0% -0.4% -1.2% +0.0% fulsom 0.0% 0.0% -0.0% -0.0% 0.0% gamteb 0.0% 0.0% -0.1% -0.3% 0.0% gcd 0.0% 0.0% -0.0% -0.0% 0.0% gen_regexps 0.0% 0.0% -0.0% -0.0% -0.0% genfft 0.0% 0.0% -0.0% -0.0% 0.0% gg 0.0% 0.0% -0.0% -0.0% +0.0% grep 0.0% 0.0% -0.0% -0.0% -0.0% hidden 0.0% 0.0% -0.1% -0.4% -0.0% hpg 0.0% 0.0% -0.2% -0.5% +0.0% ida 0.0% 0.0% -0.0% -0.0% +0.0% infer 0.0% 0.0% -0.3% -0.8% -0.0% integer 0.0% 0.0% -0.0% -0.0% +0.0% integrate 0.0% 0.0% -0.0% -0.0% 0.0% k-nucleotide 0.0% 0.0% -0.0% -0.0% +0.0% kahan 0.0% 0.0% -0.0% -0.0% +0.0% knights 0.0% 0.0% -2.2% -5.4% 0.0% lambda 0.0% 0.0% -0.6% -1.8% 0.0% last-piece 0.0% 0.0% -0.0% -0.0% 0.0% lcss 0.0% 0.0% -0.0% -0.1% 0.0% life 0.0% 0.0% -0.0% -0.1% 0.0% lift 0.0% 0.0% -0.2% -0.6% +0.0% linear 0.0% 0.0% -0.0% -0.0% -0.0% listcompr 0.0% 0.0% -0.0% -0.0% 0.0% listcopy 0.0% 0.0% -0.0% -0.0% 0.0% maillist 0.0% 0.0% -0.1% -0.3% +0.0% mandel 0.0% 0.0% -0.0% -0.0% 0.0% mandel2 0.0% 0.0% -0.0% -0.0% -0.0% mate +0.0% 0.0% -0.0% -0.0% -0.0% minimax 0.0% 0.0% -0.2% -1.0% 0.0% mkhprog 0.0% 0.0% -0.1% -0.2% -0.0% multiplier 0.0% 0.0% -0.0% -0.0% -0.0% n-body 0.0% 0.0% -0.0% -0.0% +0.0% nucleic2 0.0% 0.0% -0.1% -0.2% 0.0% para 0.0% 0.0% -0.0% -0.0% -0.0% paraffins 0.0% 0.0% -0.0% -0.0% 0.0% parser 0.0% 0.0% -0.2% -0.7% 0.0% parstof 0.0% 0.0% -0.0% -0.0% +0.0% pic 0.0% 0.0% -0.0% -0.0% 0.0% pidigits 0.0% 0.0% +0.0% +0.0% +0.0% power 0.0% 0.0% -0.2% -0.6% +0.0% pretty 0.0% 0.0% -0.0% -0.0% -0.0% primes 0.0% 0.0% -0.0% -0.0% 0.0% primetest 0.0% 0.0% -0.0% -0.0% -0.0% prolog 0.0% 0.0% -0.3% -1.1% 0.0% puzzle 0.0% 0.0% -0.0% -0.0% 0.0% queens 0.0% 0.0% -0.0% -0.0% +0.0% reptile 0.0% 0.0% -0.0% -0.0% 0.0% reverse-complem 0.0% 0.0% -0.0% -0.0% +0.0% rewrite 0.0% 0.0% -0.7% -2.5% -0.0% rfib 0.0% 0.0% -0.0% -0.0% 0.0% rsa 0.0% 0.0% -0.0% -0.0% 0.0% scc 0.0% 0.0% -0.1% -0.2% -0.0% sched 0.0% 0.0% -0.0% -0.0% -0.0% scs 0.0% 0.0% -1.0% -2.6% +0.0% simple 0.0% 0.0% +0.0% -0.0% +0.0% solid 0.0% 0.0% -0.0% -0.0% 0.0% sorting 0.0% 0.0% -0.6% -1.6% 0.0% spectral-norm 0.0% 0.0% +0.0% 0.0% +0.0% sphere 0.0% 0.0% -0.0% -0.0% -0.0% symalg 0.0% 0.0% -0.0% -0.0% +0.0% tak 0.0% 0.0% -0.0% -0.0% 0.0% transform 0.0% 0.0% -0.0% -0.0% 0.0% treejoin 0.0% 0.0% -0.0% -0.0% 0.0% typecheck 0.0% 0.0% -0.0% -0.0% +0.0% veritas +0.0% 0.0% -0.2% -0.4% +0.0% wang 0.0% 0.0% -0.0% -0.0% 0.0% wave4main 0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve1 0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve2 0.0% 0.0% -0.0% -0.0% +0.0% x2n1 0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min 0.0% 0.0% -2.2% -5.4% -0.0% Max +0.0% 0.0% +0.0% +0.0% +0.1% Geometric Mean -0.0% -0.0% -0.1% -0.3% +0.0% Metric increases micro benchmarks tracked in #17686: Metric Increase: T12150 T12234 T12425 T13035 T5837 T6048 T9233 Co-authored-by: Andreas Klebinger <klebinger.andreas at gmx.at> - - - - - 3b22b14a by Shayne Fletcher at 2020-06-10T04:15:01-04:00 Give Language a Bounded instance - - - - - 9454511b by Simon Peyton Jones at 2020-06-10T04:17:06-04:00 Optimisation in Unique.Supply This patch switches on -fno-state-hack in GHC.Types.Unique.Supply. It turned out that my fixes for #18078 (coercion floating) changed the optimisation pathway for mkSplitUniqSupply in such a way that we had an extra allocation inside the inner loop. Adding -fno-state-hack fixed that -- and indeed the loop in mkSplitUniqSupply is a classic example of the way in which -fno-state-hack can be bad; see #18238. Moreover, the new code is better than the old. They allocate the same, but the old code ends up with a partial application. The net effect is that the test perf/should_run/UniqLoop runs 20% faster! From 2.5s down to 2.0s. The allocation numbers are the same -- but elapsed time falls. Good! The bad thing about this is that it's terribly delicate. But at least it's a good example of such delicacy in action. There is a long Note [Optimising the unique supply] which now explains all this. - - - - - 6d49d5be by Simon Peyton Jones at 2020-06-10T04:17:06-04:00 Implement cast worker/wrapper properly The cast worker/wrapper transformation transforms x = e |> co into y = e x = y |> co This is done by the simplifier, but we were being careless about transferring IdInfo from x to y, and about what to do if x is a NOINLNE function. This resulted in a series of bugs: #17673, #18093, #18078. This patch fixes all that: * Main change is in GHC.Core.Opt.Simplify, and the new prepareBinding function, which does this cast worker/wrapper transform. See Note [Cast worker/wrappers]. * There is quite a bit of refactoring around prepareRhs, makeTrivial etc. It's nicer now. * Some wrappers from strictness and cast w/w, notably those for a function with a NOINLINE, should inline very late. There wasn't really a mechanism for that, which was an existing bug really; so I invented a new finalPhase = Phase (-1). It's used for all simplifier runs after the user-visible phase 2,1,0 have run. (No new runs of the simplifier are introduced thereby.) See new Note [Compiler phases] in GHC.Types.Basic; the main changes are in GHC.Core.Opt.Driver * Doing this made me trip over two places where the AnonArgFlag on a FunTy was being lost so we could end up with (Num a -> ty) rather than (Num a => ty) - In coercionLKind/coercionRKind - In contHoleType in the Simplifier I fixed the former by defining mkFunctionType and using it in coercionLKind/RKind. I could have done the same for the latter, but the information is almost to hand. So I fixed the latter by - adding sc_hole_ty to ApplyToVal (like ApplyToTy), - adding as_hole_ty to ValArg (like TyArg) - adding sc_fun_ty to StrictArg Turned out I could then remove ai_type from ArgInfo. This is just moving the deck chairs around, but it worked out nicely. See the new Note [AnonArgFlag] in GHC.Types.Var * When looking at the 'arity decrease' thing (#18093) I discovered that stable unfoldings had a much lower arity than the actual optimised function. That's what led to the arity-decrease message. Simple solution: eta-expand. It's described in Note [Eta-expand stable unfoldings] in GHC.Core.Opt.Simplify * I also discovered that unsafeCoerce wasn't being inlined if the context was boring. So (\x. f (unsafeCoerce x)) would create a thunk -- yikes! I fixed that by making inlineBoringOK a bit cleverer: see Note [Inline unsafeCoerce] in GHC.Core.Unfold. I also found that unsafeCoerceName was unused, so I removed it. I made a test case for #18078, and a very similar one for #17673. The net effect of all this on nofib is very modest, but positive: -------------------------------------------------------------------------------- Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- anna -0.4% -0.1% -3.1% -3.1% 0.0% fannkuch-redux -0.4% -0.3% -0.1% -0.1% 0.0% maillist -0.4% -0.1% -7.8% -1.0% -14.3% primetest -0.4% -15.6% -7.1% -6.6% 0.0% -------------------------------------------------------------------------------- Min -0.9% -15.6% -13.3% -14.2% -14.3% Max -0.3% 0.0% +12.1% +12.4% 0.0% Geometric Mean -0.4% -0.2% -2.3% -2.2% -0.1% All following metric decreases are compile-time allocation decreases between -1% and -3%: Metric Decrease: T5631 T13701 T14697 T15164 - - - - - 32fd37f5 by Luke Lau at 2020-06-10T04:17:22-04:00 Fix lookupGlobalOccRn_maybe sometimes reporting an error In some cases it was possible for lookupGlobalOccRn_maybe to return an error, when it should be returning a Nothing. If it called lookupExactOcc_either when there were no matching GlobalRdrElts in the otherwise case, it would return an error message. This could be caused when lookupThName_maybe in Template Haskell was looking in different namespaces (thRdrNameGuesses), guessing different namespaces that the name wasn't guaranteed to be found in. However, by addressing this some more accurate errors were being lost in the conversion to Maybes. So some of the lookup* functions have been shuffled about so that errors should always be ignored in lookup*_maybes, and propagated otherwise. This fixes #18263 - - - - - 9b283e1b by Roland Senn at 2020-06-10T04:17:34-04:00 Initialize the allocation counter in GHCi to 0 (Fixes #16012) According to the documentation for the function `getAllocationCounter` in [System.Mem](http://hackage.haskell.org/package/base-4.14.0.0/docs/System-Mem.html) initialize the allocationCounter also in GHCi to 0. - - - - - 8d07c48c by Sylvain Henry at 2020-06-10T04:17:36-04:00 test: fix conc038 We had spurious failures of conc038 test on CI with stdout: ``` newThread started -mainThread -Haskell: 2 newThread back again +mainThread 1 sec later shutting down +Haskell: 2 ``` - - - - - 4c7e9689 by Sebastian Graf at 2020-06-11T10:37:38+02:00 Release Notes: Add news from the pattern-match checker [skip ci] - - - - - 3445b965 by Sylvain Henry at 2020-06-13T02:13:01-04:00 Only test T16190 with the NCG T16190 is meant to test a NCG feature. It has already caused spurious failures in other MRs (e.g. !2165) when LLVM is used. - - - - - 2517a51c by Sylvain Henry at 2020-06-13T02:13:01-04:00 DynFlags refactoring VIII (#17957) * Remove several uses of `sdocWithDynFlags`, especially in GHC.Llvm.* * Add LlvmOpts datatype to store Llvm backend options * Remove Outputable instances (for LlvmVar, LlvmLit, LlvmStatic and Llvm.MetaExpr) which require LlvmOpts. * Rename ppMetaExpr into ppMetaAnnotExpr (pprMetaExpr is now used in place of `ppr :: MetaExpr -> SDoc`) - - - - - 7a02599a by Sylvain Henry at 2020-06-13T02:13:02-04:00 Remove unused code - - - - - 72d08610 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Refactor homeUnit * rename thisPackage into homeUnit * document and refactor several Backpack things - - - - - 8dc71f55 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Rename unsafeGetUnitInfo into unsafeLookupUnit - - - - - f6be6e43 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Add allowVirtualUnits field in PackageState Instead of always querying DynFlags to know whether we are allowed to use virtual units (i.e. instantiated on-the-fly, cf Note [About units] in GHC.Unit), we store it once for all in `PackageState.allowVirtualUnits`. This avoids using DynFlags too much (cf #17957) and is preliminary work for #14335. - - - - - e7272d53 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Enhance UnitId use * use UnitId instead of String to identify wired-in units * use UnitId instead of Unit in the backend (Unit are only use by Backpack to produce type-checked interfaces, not real code) * rename lookup functions for consistency * documentation - - - - - 9c5572cd by Sylvain Henry at 2020-06-13T02:13:02-04:00 Remove LinkerUnitId type alias - - - - - d345edfe by Sylvain Henry at 2020-06-13T02:13:02-04:00 Refactor WiredMap * Remove WiredInUnitId and WiredUnitId type aliases - - - - - 3d171cd6 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Document and refactor `mkUnit` and `mkUnitInfoMap` - - - - - d2109b4f by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove PreloadUnitId type alias - - - - - f50c19b8 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename listUnitInfoMap into listUnitInfo There is no Map involved - - - - - ed533ec2 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename Package into Unit The terminology changed over time and now package databases contain "units" (there can be several units compiled from a single Cabal package: one per-component, one for each option set, one per instantiation, etc.). We should try to be consistent internally and use "units": that's what this renaming does. Maybe one day we'll fix the UI too (e.g. replace -package-id with -unit-id, we already have -this-unit-id and ghc-pkg has -unit-id...) but it's not done in this patch. * rename getPkgFrameworkOpts into getUnitFrameworkOpts * rename UnitInfoMap into ClosureUnitInfoMap * rename InstalledPackageIndex into UnitInfoMap * rename UnusablePackages into UnusableUnits * rename PackagePrecedenceIndex into UnitPrecedenceMap * rename PackageDatabase into UnitDatabase * rename pkgDatabase into unitDatabases * rename pkgState into unitState * rename initPackages into initUnits * rename renamePackage into renameUnitInfo * rename UnusablePackageReason into UnusableUnitReason * rename getPackage* into getUnit* * etc. - - - - - 202728e5 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Make ClosureUnitInfoMap uses UnitInfoMap - - - - - 55b4263e by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove ClosureUnitInfoMap - - - - - 653d17bd by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename Package into Unit (2) * rename PackageState into UnitState * rename findWiredInPackages into findWiredInUnits * rename lookupModuleInAll[Packages,Units] * etc. - - - - - ae900605 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move dump_mod_map into initUnits - - - - - 598cc1dd by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move wiring of homeUnitInstantiations outside of mkUnitState - - - - - 437265eb by Sylvain Henry at 2020-06-13T02:13:03-04:00 Avoid timing module map dump in initUnits - - - - - 9400aa93 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove preload parameter of mkUnitState * Remove preload parameter (unused) * Don't explicitly return preloaded units: redundant because already returned as "preloadUnits" field of UnitState - - - - - 266bc3d9 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: refactor unwireUnit - - - - - 9e715c1b by Sylvain Henry at 2020-06-13T02:13:03-04:00 Document getPreloadUnitsAnd - - - - - bd5810dc by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: remove useless add_package parameter - - - - - 36e1daf0 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: make listVisibleModuleNames take a UnitState - - - - - 5226da37 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Refactor and document add_package - - - - - 4b53aac1 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Refactor and document closeUnitDeps - - - - - 42c054f6 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: findWiredInUnits - - - - - a444d01b by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: reportCycles, reportUnusable - - - - - 8408d521 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: merge_databases - - - - - fca2d25f by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: add UnitConfig datatype Avoid directly querying flags from DynFlags to build the UnitState. Instead go via UnitConfig so that we could reuse this to make another UnitState for plugins. - - - - - 4274688a by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move distrustAll into mkUnitState - - - - - 28d804e1 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Create helper upd_wired_in_home_instantiations - - - - - ac964c83 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Put database cache in UnitConfig - - - - - bfd0a78c by Sylvain Henry at 2020-06-13T02:13:03-04:00 Don't return preload units when we set DyNFlags Preload units can be retrieved in UnitState when needed (i.e. in GHCi) - - - - - 1fbb4bf5 by Sylvain Henry at 2020-06-13T02:13:03-04:00 NCGConfig: remove useless ncgUnitId field - - - - - c10ff7e7 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Doc: fix some comments - - - - - 456e17f0 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Bump haddock submodule and allow metric decrease Metric Decrease: T12150 T12234 T5837 Metric Increase: T16190 - - - - - 42953902 by Simon Peyton Jones at 2020-06-13T02:13:03-04:00 Trim the demand for recursive product types Ticket #18304 showed that we need to be very careful when exploring the demand (esp usage demand) on recursive product types. This patch solves the problem by trimming the demand on such types -- in effect, a form of "widening". See the Note [Trimming a demand to a type] in DmdAnal, which explains how I did this by piggy-backing on an existing mechansim for trimming demands becuase of GADTs. The significant payload of this patch is very small indeed: * Make GHC.Core.Opt.WorkWrap.Utils.typeShape use RecTcChecker to avoid looking through recursive types. But on the way * I found that ae_rec_tc was entirely inoperative and did nothing. So I removed it altogether from DmdAnal. * I moved some code around in DmdAnal and Demand. (There are no actual changes in dmdFix.) * I changed the API of DmsAnal.dmdAnalRhsLetDown to return a StrictSig rather than a decorated Id * I removed the dead function peelTsFuns from Demand Performance effects: Nofib: 0.0% changes. Not surprising, because they don't use recursive products Perf tests T12227: 1% increase in compiler allocation, becuase $cto gets w/w'd. It did not w/w before because it takes a deeply nested argument, so the worker gets too many args, so we abandon w/w altogether (see GHC.Core.Opt.WorkWrap.Utils.isWorkerSmallEnough) With this patch we trim the demands. That is not strictly necessary (since these Generic type constructors are like tuples -- they can't cause a loop) but the net result is that we now w/w $cto which is fine. UniqLoop: 16% decrease in /runtime/ allocation. The UniqSupply is a recursive product, so currently we abandon all strictness on 'churn'. With this patch 'churn' gets useful strictness, and we w/w it. Hooray Metric Decrease: UniqLoop Metric Increase: T12227 - - - - - 87d504f4 by Viktor Dukhovni at 2020-06-13T02:13:05-04:00 Add introductory prose for Data.Traversable - - - - - 9f09b608 by Oleg Grenrus at 2020-06-13T02:13:07-04:00 Fix #12073: Add MonadFix Q instance - - - - - 220c2d34 by Ben Gamari at 2020-06-13T02:13:07-04:00 testsuite: Increase size of T12150 As noted in #18319, this test was previously very fragile. Increase its size to make it more likely that its fails with its newly-increased acceptance threshold. Metric Increase: T12150 - - - - - 8bba1c26 by Ben Gamari at 2020-06-13T04:59:06-04:00 gitlab-ci: Always push perf notes Previously we ci.sh would run with `set -e` implying that we wouldn't push perf notes if the testsuite were to fail, even if it *only* failed due to perf notes. This rendered the whole performance testing story quite fragile as a single regressing commit would cause every successive commit to fail since a new baseline would not be uploaded. Fix this by ensuring that we always push performance notes. - - - - - 7a773f16 by Ben Gamari at 2020-06-13T15:10:55-04:00 gitlab-ci: Eliminate redundant push of CI metrics - - - - - a31218f7 by Ryan Scott at 2020-06-13T15:58:37-04:00 Use HsForAllTelescope to avoid inferred, visible foralls Currently, `HsForAllTy` permits the combination of `ForallVis` and `Inferred`, but you can't actually typecheck code that uses it (e.g., `forall {a} ->`). This patch refactors `HsForAllTy` to use a new `HsForAllTelescope` data type that makes a type-level distinction between visible and invisible `forall`s such that visible `forall`s do not track `Specificity`. That part of the patch is actually quite small; the rest is simply changing consumers of `HsType` to accommodate this new type. Fixes #18235. Bumps the `haddock` submodule. - - - - - c0e6dee9 by Tamar Christina at 2020-06-14T09:07:44-04:00 winio: Add Atomic Exchange PrimOp and implement Atomic Ptr exchanges. The initial version was rewritten by Tamar Christina. It was rewritten in large parts by Andreas Klebinger. Co-authored-by: Andreas Klebinger <klebinger.andreas at gmx.at> - - - - - 9a7462fb by Ben Gamari at 2020-06-14T15:35:23-04:00 codeGen: Don't discard live case binders in unsafeEqualityProof logic Previously CoreToStg would unconditionally discard cases of the form: case unsafeEqualityProof of wild { _ -> rhs } and rather replace the whole thing with `rhs`. However, in some cases (see #18227) the case binder is still live, resulting in unbound occurrences in `rhs`. Fix this by only discarding the case if the case binder is dead. Fixes #18227. - - - - - e4137c48 by Ben Gamari at 2020-06-14T15:35:23-04:00 testsuite: Add tests for #18227 T18227A is the original issue which gave rise to the ticket and depends upon bytestring. T18227B is a minimized reproducer. - - - - - 8bab9ff1 by Ben Gamari at 2020-06-14T15:35:59-04:00 hadrian: Fix rts include and library paths Fixes two bugs: * (?) and (<>) associated in a surprising way * We neglected to include libdw paths in the rts configure flags - - - - - bd761185 by Ben Gamari at 2020-06-14T15:35:59-04:00 hadrian: Drop redundant GHC arguments Cabal should already be passing this arguments to GHC. - - - - - 01f7052c by Peter Trommler at 2020-06-14T15:36:38-04:00 FFI: Fix pass small ints in foreign call wrappers The Haskell calling convention requires integer parameters smaller than wordsize to be promoted to wordsize (where the upper bits are don't care). To access such small integer parameter read a word from the parameter array and then cast that word to the small integer target type. Fixes #15933 - - - - - 502647f7 by Krzysztof Gogolewski at 2020-06-14T15:37:14-04:00 Fix "ndecreasingIndentation" in manual (#18116) - - - - - 9a9cc089 by Simon Jakobi at 2020-06-15T13:10:00-04:00 Use foldl' in unionManyUniqDSets - - - - - 761dcb84 by Moritz Angermann at 2020-06-15T13:10:36-04:00 Load .lo as well. Some archives contain so called linker objects, with the affectionate .lo suffic. For example the musl libc.a will come in that form. We still want to load those objects, hence we should not discard them and look for .lo as well. Ultimately we might want to fix this proerly by looking at the file magic. - - - - - cf01477f by Vladislav Zavialov at 2020-06-15T13:11:20-04:00 User's Guide: KnownNat evidence is Natural This bit of documentation got outdated after commit 1fcede43d2b30f33b7505e25eb6b1f321be0407f - - - - - d0dcbfe6 by Jan Hrček at 2020-06-16T20:36:38+02:00 Fix typos and formatting in user guide - - - - - 56a9e95f by Jan Hrček at 2020-06-16T20:36:38+02:00 Resolve TODO - - - - - 3e884d14 by Jan Hrček at 2020-06-16T20:36:38+02:00 Rename TcHoleErrors to GHC.Tc.Errors.Hole - - - - - d23fc678 by Stefan Schulze Frielinghaus at 2020-06-17T15:31:09-04:00 hadrian: Build with threaded runtime if available See #16873. - - - - - 0639dc10 by Sylvain Henry at 2020-06-17T15:31:53-04:00 T16190: only measure bytes_allocated Just adding `{-# LANGUAGE BangPatterns #-}` makes the two other metrics fluctuate by 13%. - - - - - 4cab6897 by Adam Sandberg Ericsson at 2020-06-17T15:32:44-04:00 docs: fix formatting in users guide - - - - - eb8115a8 by Sylvain Henry at 2020-06-17T15:33:23-04:00 Move CLabel assertions into smart constructors (#17957) It avoids using DynFlags in the Outputable instance of Clabel to check assertions at pretty-printing time. - - - - - 7faa4509 by Ben Gamari at 2020-06-17T15:43:31-04:00 base: Bump to 4.15.0.0 - - - - - 20616959 by Ben Gamari at 2020-06-17T15:43:31-04:00 configure: Use grep -q instead of --quiet The latter is apparently not supported by busybox. - - - - - 40fa237e by Krzysztof Gogolewski at 2020-06-17T16:21:58-04:00 Linear types (#15981) This is the first step towards implementation of the linear types proposal (https://github.com/ghc-proposals/ghc-proposals/pull/111). It features * A language extension -XLinearTypes * Syntax for linear functions in the surface language * Linearity checking in Core Lint, enabled with -dlinear-core-lint * Core-to-core passes are mostly compatible with linearity * Fields in a data type can be linear or unrestricted; linear fields have multiplicity-polymorphic constructors. If -XLinearTypes is disabled, the GADT syntax defaults to linear fields The following items are not yet supported: * a # m -> b syntax (only prefix FUN is supported for now) * Full multiplicity inference (multiplicities are really only checked) * Decent linearity error messages * Linear let, where, and case expressions in the surface language (each of these currently introduce the unrestricted variant) * Multiplicity-parametric fields * Syntax for annotating lambda-bound or let-bound with a multiplicity * Syntax for non-linear/multiple-field-multiplicity records * Linear projections for records with a single linear field * Linear pattern synonyms * Multiplicity coercions (test LinearPolyType) A high-level description can be found at https://ghc.haskell.org/trac/ghc/wiki/LinearTypes/Implementation Following the link above you will find a description of the changes made to Core. This commit has been authored by * Richard Eisenberg * Krzysztof Gogolewski * Matthew Pickering * Arnaud Spiwack With contributions from: * Mark Barbone * Alexander Vershilov Updates haddock submodule. - - - - - 6cb84c46 by Krzysztof Gogolewski at 2020-06-17T16:22:03-04:00 Various performance improvements This implements several general performance improvements to GHC, to offset the effect of the linear types change. General optimisations: - Add a `coreFullView` function which iterates `coreView` on the head. This avoids making function recursive solely because the iterate `coreView` themselves. As a consequence, this functions can be inlined, and trigger case-of-known constructor (_e.g._ `kindRep_maybe`, `isLiftedRuntimeRep`, `isMultiplicityTy`, `getTyVar_maybe`, `splitAppTy_maybe`, `splitFunType_maybe`, `tyConAppTyCon_maybe`). The common pattern about all these functions is that they are almost always used as views, and immediately consumed by a case expression. This commit also mark them asx `INLINE`. - In `subst_ty` add a special case for nullary `TyConApp`, which avoid allocations altogether. - Use `mkTyConApp` in `subst_ty` for the general `TyConApp`. This required quite a bit of module shuffling. case. `myTyConApp` enforces crucial sharing, which was lost during substitution. See also !2952 . - Make `subst_ty` stricter. - In `eqType` (specifically, in `nonDetCmpType`), add a special case, tested first, for the very common case of nullary `TyConApp`. `nonDetCmpType` has been made `INLINE` otherwise it is actually a regression. This is similar to the optimisations in !2952. Linear-type specific optimisations: - Use `tyConAppTyCon_maybe` instead of the more complex `eqType` in the definition of the pattern synonyms `One` and `Many`. - Break the `hs-boot` cycles between `Multiplicity.hs` and `Type.hs`: `Multiplicity` now import `Type` normally, rather than from the `hs-boot`. This way `tyConAppTyCon_maybe` can inline properly in the `One` and `Many` pattern synonyms. - Make `updateIdTypeAndMult` strict in its type and multiplicity - The `scaleIdBy` gets a specialised definition rather than being an alias to `scaleVarBy` - `splitFunTy_maybe` is given the type `Type -> Maybe (Mult, Type, Type)` instead of `Type -> Maybe (Scaled Type, Type)` - Remove the `MultMul` pattern synonym in favour of a view `isMultMul` because pattern synonyms appear not to inline well. - in `eqType`, in a `FunTy`, compare multiplicities last: they are almost always both `Many`, so it helps failing faster. - Cache `manyDataConTy` in `mkTyConApp`, to make sure that all the instances of `TyConApp ManyDataConTy []` are physically the same. This commit has been authored by * Richard Eisenberg * Krzysztof Gogolewski * Arnaud Spiwack Metric Decrease: haddock.base T12227 T12545 T12990 T1969 T3064 T5030 T9872b Metric Increase: haddock.base haddock.Cabal haddock.compiler T12150 T12234 T12425 T12707 T13035 T13056 T15164 T16190 T18304 T1969 T3064 T3294 T5631 T5642 T5837 T6048 T9020 T9233 T9675 T9872a T9961 WWRec - - - - - 57db91d8 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Remove integer-simple integer-simple uses lists of words (`[Word]`) to represent big numbers instead of ByteArray#: * it is less efficient than the newer ghc-bignum native backend * it isn't compatible with the big number representation that is now shared by all the ghc-bignum backends (based on the one that was used only in integer-gmp before). As a consequence, we simply drop integer-simple - - - - - 9f96bc12 by Sylvain Henry at 2020-06-17T16:22:03-04:00 ghc-bignum library ghc-bignum is a newer package that aims to replace the legacy integer-simple and integer-gmp packages. * it supports several backends. In particular GMP is still supported and most of the code from integer-gmp has been merged in the "gmp" backend. * the pure Haskell "native" backend is new and is much faster than the previous pure Haskell implementation provided by integer-simple * new backends are easier to write because they only have to provide a few well defined functions. All the other code is common to all backends. In particular they all share the efficient small/big number distinction previously used only in integer-gmp. * backends can all be tested against the "native" backend with a simple Cabal flag. Backends are only allowed to differ in performance, their results should be the same. * Add `integer-gmp` compat package: provide some pattern synonyms and function aliases for those in `ghc-bignum`. It is intended to avoid breaking packages that depend on `integer-gmp` internals. Update submodules: text, bytestring Metric Decrease: Conversions ManyAlternatives ManyConstructors Naperian T10359 T10547 T10678 T12150 T12227 T12234 T12425 T13035 T13719 T14936 T1969 T4801 T4830 T5237 T5549 T5837 T8766 T9020 parsing001 space_leak_001 T16190 haddock.base On ARM and i386, T17499 regresses (+6% > 5%). On x86_64 unregistered, T13701 sometimes regresses (+2.2% > 2%). Metric Increase: T17499 T13701 - - - - - 96aa5787 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update compiler Thanks to ghc-bignum, the compiler can be simplified: * Types and constructors of Integer and Natural can be wired-in. It means that we don't have to query them from interfaces. It also means that numeric literals don't have to carry their type with them. * The same code is used whatever ghc-bignum backend is enabled. In particular, conversion of bignum literals into final Core expressions is now much more straightforward. Bignum closure inspection too. * GHC itself doesn't depend on any integer-* package anymore * The `integerLibrary` setting is gone. - - - - - 0f67e344 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update `base` package * GHC.Natural isn't implemented in `base` anymore. It is provided by ghc-bignum in GHC.Num.Natural. It means that we can safely use Natural primitives in `base` without fearing issues with built-in rewrite rules (cf #15286) * `base` doesn't conditionally depend on an integer-* package anymore, it depends on ghc-bignum * Some duplicated code in integer-* can now be factored in GHC.Float * ghc-bignum tries to use a uniform naming convention so most of the other changes are renaming - - - - - aa9e7b71 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update `make` based build system * replace integer-* package selection with ghc-bignum backend selection - - - - - f817d816 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Update testsuite * support detection of slow ghc-bignum backend (to replace the detection of integer-simple use). There are still some test cases that the native backend doesn't handle efficiently enough. * remove tests for GMP only functions that have been removed from ghc-bignum * fix test results showing dependent packages (e.g. integer-gmp) or showing suggested instances * fix test using Integer/Natural API or showing internal names - - - - - dceecb09 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Update Hadrian * support ghc-bignum backend selection in flavours and command-line * support ghc-bignum "--check" flag (compare results of selected backend against results of the native one) in flavours and command-line (e.g. pass --bignum=check-gmp" to check the "gmp" backend) * remove the hack to workaround #15286 * build GMP only when the gmp backend is used * remove hacks to workaround `text` package flags about integer-*. We fix `text` to use ghc-bignum unconditionally in another patch - - - - - fa4281d6 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Bump bytestring and text submodules - - - - - 1a3f6f34 by Adam Sandberg Ericsson at 2020-06-18T23:03:36-04:00 docs: mention -hiedir in docs for -outputdir [skip ci] - - - - - 729bcb02 by Sylvain Henry at 2020-06-18T23:04:17-04:00 Hadrian: fix build on Mac OS Catalina (#17798) - - - - - 95e18292 by Andreas Klebinger at 2020-06-18T23:04:58-04:00 Relax allocation threshold for T12150. This test performs little work, so the most minor allocation changes often cause the test to fail. Increasing the threshold to 2% should help with this. - - - - - 8ce6c393 by Sebastian Graf at 2020-06-18T23:05:36-04:00 hadrian: Bump pinned cabal.project to an existent index-state - - - - - 08c1cb0f by Ömer Sinan Ağacan at 2020-06-18T23:06:21-04:00 Fix uninitialized field read in Linker.c Valgrind report of the bug when running the test `linker_unload`: ==29666== Conditional jump or move depends on uninitialised value(s) ==29666== at 0x369C5B4: setOcInitialStatus (Linker.c:1305) ==29666== by 0x369C6C5: mkOc (Linker.c:1347) ==29666== by 0x36C027A: loadArchive_ (LoadArchive.c:522) ==29666== by 0x36C0600: loadArchive (LoadArchive.c:626) ==29666== by 0x2C144CD: ??? (in /home/omer/haskell/ghc_2/testsuite/tests/rts/linker/linker_unload.run/linker_unload) ==29666== ==29666== Conditional jump or move depends on uninitialised value(s) ==29666== at 0x369C5B4: setOcInitialStatus (Linker.c:1305) ==29666== by 0x369C6C5: mkOc (Linker.c:1347) ==29666== by 0x369C9F6: preloadObjectFile (Linker.c:1507) ==29666== by 0x369CA8D: loadObj_ (Linker.c:1536) ==29666== by 0x369CB17: loadObj (Linker.c:1557) ==29666== by 0x3866BC: main (linker_unload.c:33) The problem is `mkOc` allocates a new `ObjectCode` and calls `setOcInitialStatus` without initializing the `status` field. `setOcInitialStatus` reads the field as first thing: static void setOcInitialStatus(ObjectCode* oc) { if (oc->status == OBJECT_DONT_RESOLVE) return; if (oc->archiveMemberName == NULL) { oc->status = OBJECT_NEEDED; } else { oc->status = OBJECT_LOADED; } } `setOcInitialStatus` is unsed in two places for two different purposes: in `mkOc` where we don't have the `status` field initialized yet (`mkOc` is supposed to initialize it), and `loadOc` where we do have `status` field initialized and we want to update it. Instead of splitting the function into two functions which are both called just once I inline the functions in the use sites and remove it. Fixes #18342 - - - - - da18ff99 by Tamar Christina at 2020-06-18T23:07:03-04:00 fix windows bootstrap due to linker changes - - - - - 2af0ec90 by Sylvain Henry at 2020-06-18T23:07:47-04:00 DynFlags: store default depth in SDocContext (#17957) It avoids having to use DynFlags to reach for pprUserLength. - - - - - d4a0be75 by Sylvain Henry at 2020-06-18T23:08:35-04:00 Move tablesNextToCode field into Platform tablesNextToCode is a platform setting and doesn't belong into DynFlags (#17957). Doing this is also a prerequisite to fix #14335 where we deal with two platforms (target and host) that may have different platform settings. - - - - - 809caedf by John Ericson at 2020-06-23T22:47:37-04:00 Switch from HscSource to IsBootInterface for module lookup in GhcMake We look up modules by their name, and not their contents. There is no way to separately reference a signature vs regular module; you get what you get. Only boot files can be referenced indepenently with `import {-# SOURCE #-}`. - - - - - 7750bd45 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Cmm: introduce SAVE_REGS/RESTORE_REGS We don't want to save both Fn and Dn register sets on x86-64 as they are aliased to the same arch register (XMMn). Moreover, when SAVE_STGREGS was used in conjunction with `jump foo [*]` which makes a set of Cmm registers alive so that they cover all arch registers used to pass parameter, we could have Fn, Dn and XMMn alive at the same time. It made the LLVM code generator choke (see #17920). Now `SAVE_REGS/RESTORE_REGS` and `jump foo [*]` use the same set of registers. - - - - - 2636794d by Sylvain Henry at 2020-06-23T22:48:18-04:00 CmmToC: don't add extern decl to parsed Cmm data Previously, if a .cmm file *not in the RTS* contained something like: ```cmm section "rodata" { msg : bits8[] "Test\n"; } ``` It would get compiled by CmmToC into: ```c ERW_(msg); const char msg[] = "Test\012"; ``` and fail with: ``` /tmp/ghc32129_0/ghc_4.hc:5:12: error: error: conflicting types for \u2018msg\u2019 const char msg[] = "Test\012"; ^~~ In file included from /tmp/ghc32129_0/ghc_4.hc:3:0: error: /tmp/ghc32129_0/ghc_4.hc:4:6: error: note: previous declaration of \u2018msg\u2019 was here ERW_(msg); ^ /builds/hsyl20/ghc/_build/install/lib/ghc-8.11.0.20200605/lib/../lib/x86_64-linux-ghc-8.11.0.20200605/rts-1.0/include/Stg.h:253:46: error: note: in definition of macro \u2018ERW_\u2019 #define ERW_(X) extern StgWordArray (X) ^ ``` See the rationale for this on https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/backends/ppr-c#prototypes Now we don't generate these extern declarations (ERW_, etc.) for top-level data. It shouldn't change anything for the RTS (the only place we use .cmm files) as it is already special cased in `GHC.Cmm.CLabel.needsCDecl`. And hand-written Cmm can use explicit extern declarations when needed. Note that it allows `cgrun069` test to pass with CmmToC (cf #15467). - - - - - 5f6a0665 by Sylvain Henry at 2020-06-23T22:48:18-04:00 LLVM: refactor and comment register padding code (#17920) - - - - - cad62ef1 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Add tests for #17920 Metric Decrease: T12150 T12234 - - - - - a2a9006b by Xavier Denis at 2020-06-23T22:48:56-04:00 Fix issue #18262 by zonking constraints after solving Zonk residual constraints in checkForExistence to reveal user type errors. Previously when `:instances` was used with instances that have TypeError constraints the result would look something like: instance [safe] s0 => Err 'A -- Defined at ../Bug2.hs:8:10 whereas after zonking, `:instances` now sees the `TypeError` and properly eliminates the constraint from the results. - - - - - 181516bc by Simon Peyton Jones at 2020-06-23T22:49:33-04:00 Fix a buglet in Simplify.simplCast This bug, revealed by #18347, is just a missing update to sc_hole_ty in simplCast. I'd missed a code path when I made the recentchanges in commit 6d49d5be904c0c01788fa7aae1b112d5b4dfaf1c Author: Simon Peyton Jones <simonpj at microsoft.com> Date: Thu May 21 12:53:35 2020 +0100 Implement cast worker/wrapper properly The fix is very easy. Two other minor changes * Tidy up in SimpleOpt.simple_opt_expr. In fact I think this is an outright bug, introduced in the fix to #18112: we were simplifying the same coercion twice *with the same substitution*, which is just wrong. It'd be a hard bug to trigger, so I just fixed it; less code too. * Better debug printing of ApplyToVal - - - - - 625a7f54 by Simon Peyton Jones at 2020-06-23T22:50:11-04:00 Two small tweaks to Coercion.simplifyArgsWorker These tweaks affect the inner loop of simplifyArgsWorker, which in turn is called from the flattener in Flatten.hs. This is a key perf bottleneck to T9872{a,b,c,d}. These two small changes have a modest but useful benefit. No change in functionality whatsoever. Relates to #18354 - - - - - b5768cce by Sylvain Henry at 2020-06-23T22:50:49-04:00 Don't use timesInt2# with GHC < 8.11 (fix #18358) - - - - - 7ad4085c by Sylvain Henry at 2020-06-23T22:51:27-04:00 Fix invalid printf format - - - - - a1f34d37 by Krzysztof Gogolewski at 2020-06-23T22:52:09-04:00 Add missing entry to freeNamesItem (#18369) - - - - - 03a708ba by Andreas Klebinger at 2020-06-25T03:54:37-04:00 Enable large address space optimization on windows. Starting with Win 8.1/Server 2012 windows no longer preallocates page tables for reserverd memory eagerly, which prevented us from using this approach in the past. We also try to allocate the heap high in the memory space. Hopefully this makes it easier to allocate things in the low 4GB of memory that need to be there. Like jump islands for the linker. - - - - - 7e6d3d09 by Roland Senn at 2020-06-25T03:54:38-04:00 In `:break ident` allow out of scope and nested identifiers (Fix #3000) This patch fixes the bug and implements the feature request of #3000. 1. If `Module` is a real module name and `identifier` a name of a top-level function in `Module` then `:break Module.identifer` works also for an `identifier` that is out of scope. 2. Extend the syntax for `:break identifier` to: :break [ModQual.]topLevelIdent[.nestedIdent]...[.nestedIdent] `ModQual` is optional and is either the effective name of a module or the local alias of a qualified import statement. `topLevelIdent` is the name of a top level function in the module referenced by `ModQual`. `nestedIdent` is optional and the name of a function nested in a let or where clause inside the previously mentioned function `nestedIdent` or `topLevelIdent`. If `ModQual` is a module name, then `topLevelIdent` can be any top level identifier in this module. If `ModQual` is missing or a local alias of a qualified import, then `topLevelIdent` must be in scope. Breakpoints can be set on arbitrarily deeply nested functions, but the whole chain of nested function names must be specified. 3. To support the new functionality rewrite the code to tab complete `:break`. - - - - - 30e42652 by Ben Gamari at 2020-06-25T03:54:39-04:00 make: Respect XELATEX variable Previously we simply ignored the XELATEX variable when building PDF documentation. - - - - - 4acc2934 by Ben Gamari at 2020-06-25T03:54:39-04:00 hadrian/make: Detect makeindex Previously we would simply assume that makeindex was available. Now we correctly detect it in `configure` and respect this conclusion in hadrian and make. - - - - - 0d61f866 by Simon Peyton Jones at 2020-06-25T03:54:40-04:00 Expunge GhcTcId GHC.Hs.Extension had type GhcPs = GhcPass 'Parsed type GhcRn = GhcPass 'Renamed type GhcTc = GhcPass 'Typechecked type GhcTcId = GhcTc The last of these, GhcTcId, is a vestige of the past. This patch expunges it from GHC. - - - - - 8ddbed4a by Adam Wespiser at 2020-06-25T03:54:40-04:00 add examples to Data.Traversable - - - - - 284001d0 by Oleg Grenrus at 2020-06-25T03:54:42-04:00 Export readBinIface_ - - - - - 90f43872 by Zubin Duggal at 2020-06-25T03:54:43-04:00 Export everything from HsToCore. This lets us reuse these functions in haddock, avoiding synchronization bugs. Also fixed some divergences with haddock in that file Updates haddock submodule - - - - - c7dd6da7 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part1) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Hs.* - GHC.Core.* - GHC.Stg.* - GHC.Cmm.* - GHC.Types.* - GHC.Data.* - GHC.Builtin.* - GHC.Parser.* - GHC.Driver.* - GHC top - - - - - 1eb997a8 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part2) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Iface.* - GHC.Llvm.* - GHC.Rename.* - GHC.Tc.* - GHC.HsToCore.* - GHC.StgToCmm.* - GHC.CmmToAsm.* - GHC.Runtime.* - GHC.Unit.* - GHC.Utils.* - GHC.SysTools.* - - - - - 67a86b4d by Oleg Grenrus at 2020-06-25T03:54:46-04:00 Add MonadZip and MonadFix instances for Complex These instances are taken from https://hackage.haskell.org/package/linear-1.21/docs/Linear-Instances.html They are the unique possible, so let they be in `base`. - - - - - c50ef26e by Artem Pelenitsyn at 2020-06-25T03:54:47-04:00 test suite: add reproducer for #17516 - - - - - fe281b27 by Roland Senn at 2020-06-25T03:54:48-04:00 Enable maxBound checks for OverloadedLists (Fixes #18172) Consider the Literal `[256] :: [Data.Word.Word8]` When the `OverloadedLists` extension is not active, then the `ol_ext` field in the `OverLitTc` record that is passed to the function `getIntegralLit` contains the type `Word8`. This is a simple type, and we can use its type constructor immediately for the `warnAboutOverflowedLiterals` function. When the `OverloadedLists` extension is active, then the `ol_ext` field contains the type family `Item [Word8]`. The function `nomaliseType` is used to convert it to the needed type `Word8`. - - - - - a788d4d1 by Ben Gamari at 2020-06-25T03:54:52-04:00 rts/Hash: Simplify freeing of HashListChunks While looking at #18348 I noticed that the treatment of HashLists are a bit more complex than necessary (which lead to some initial confusion on my part). Specifically, we allocate HashLists in chunks. Each chunk allocation makes two allocations: one for the chunk itself and one for a HashListChunk to link together the chunks for the purposes of freeing. Simplify this (and hopefully make the relationship between these clearer) but allocating the HashLists and HashListChunk in a single malloc. This will both make the implementation easier to follow and reduce C heap fragmentation. Note that even after this patch we fail to bound the size of the free HashList pool. However, this is a separate bug. - - - - - d3c2d59b by Sylvain Henry at 2020-06-25T03:54:55-04:00 RTS: avoid overflow on 32-bit arch (#18375) We're now correctly computing allocated bytes on 32-bit arch, so we get huge increases. Metric Increase: haddock.Cabal haddock.base haddock.compiler space_leak_001 - - - - - a3d69dc6 by Sebastian Graf at 2020-06-25T23:06:18-04:00 GHC.Core.Unify: Make UM actions one-shot by default This MR makes the UM monad in GHC.Core.Unify into a one-shot monad. See the long Note [The one-shot state monad trick]. See also #18202 and !3309, which applies this to all Reader/State-like monads in GHC for compile-time perf improvements. The pattern used here enables something similar to the state-hack, but is applicable to user-defined monads, not just `IO`. Metric Decrease 'runtime/bytes allocated' (test_env='i386-linux-deb9'): haddock.Cabal - - - - - 9ee58f8d by Matthias Pall Gissurarson at 2020-06-26T17:12:45+00:00 Implement the proposed -XQualifiedDo extension Co-authored-by: Facundo Domínguez <facundo.dominguez at tweag.io> QualifiedDo is implemented using the same placeholders for operation names in the AST that were devised for RebindableSyntax. Whenever the renamer checks which names to use for do syntax, it first checks if the do block is qualified (e.g. M.do { stmts }), in which case it searches for qualified names in the module M. This allows users to write {-# LANGUAGE QualifiedDo #-} import qualified SomeModule as M f x = M.do -- desugars to: y <- M.return x -- M.return x M.>>= \y -> M.return y -- M.return y M.>> M.return y -- M.return y See Note [QualifiedDo] and the users' guide for more details. Issue #18214 Proposal: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0216-qualified-do.rst Since we change the constructors `ITdo` and `ITmdo` to carry the new module name, we need to bump the haddock submodule to account or the new shape of these constructors. - - - - - ce987865 by Ryan Scott at 2020-06-27T11:55:21-04:00 Revamp the treatment of auxiliary bindings for derived instances This started as a simple fix for #18321 that organically grew into a much more sweeping refactor of how auxiliary bindings for derived instances are handled. I have rewritten `Note [Auxiliary binders]` in `GHC.Tc.Deriv.Generate` to explain all of the moving parts, but the highlights are: * Previously, the OccName of each auxiliary binding would be given a suffix containing a hash of its package name, module name, and parent data type to avoid name clashes. This was needlessly complicated, so we take the more direct approach of generating `Exact` `RdrName`s for each auxiliary binding with the same `OccName`, but using an underlying `System` `Name` with a fresh `Unique` for each binding. Unlike hashes, allocating new `Unique`s does not require any cleverness and avoid name clashes all the same... * ...speaking of which, in order to convince the renamer that multiple auxiliary bindings with the same `OccName` (but different `Unique`s) are kosher, we now use `rnLocalValBindsLHS` instead of `rnTopBindsLHS` to rename auxiliary bindings. Again, see `Note [Auxiliary binders]` for the full story. * I have removed the `DerivHsBind` constructor for `DerivStuff`—which was only used for `Data.Data`-related auxiliary bindings—and refactored `gen_Data_binds` to use `DerivAuxBind` instead. This brings the treatment of `Data.Data`-related auxiliary bindings in line with every other form of auxiliary binding. Fixes #18321. - - - - - a403eb91 by Sylvain Henry at 2020-06-27T11:55:59-04:00 ghc-bignum: fix division by zero (#18359) - - - - - 1b3d13b6 by Sylvain Henry at 2020-06-27T11:55:59-04:00 Fix ghc-bignum exceptions We must ensure that exceptions are not simplified. Previously we used: case raiseDivZero of _ -> 0## -- dummyValue But it was wrong because the evaluation of `raiseDivZero` was removed and the dummy value was directly returned. See new Note [ghc-bignum exceptions]. I've also removed the exception triggering primops which were fragile. We don't need them to be primops, we can have them exported by ghc-prim. I've also added a test for #18359 which triggered this patch. - - - - - a74ec37c by Simon Peyton Jones at 2020-06-27T11:56:34-04:00 Better loop detection in findTypeShape Andreas pointed out, in !3466, that my fix for #18304 was not quite right. This patch fixes it properly, by having just one RecTcChecker rather than (implicitly) two nested ones, in findTypeShape. - - - - - a04020b8 by Sylvain Henry at 2020-06-27T11:57:11-04:00 DynFlags: don't store buildTag `DynFlags.buildTag` was a field created from the set of Ways in `DynFlags.ways`. It had to be kept in sync with `DynFlags.ways` which was fragile. We want to avoid global state like this (#17957). Moreover in #14335 we also want to support loading units with different ways: target units would still use `DynFlags.ways` but plugins would use `GHC.Driver.Ways.hostFullWays`. To avoid having to deal both with build tag and with ways, we recompute the buildTag on-the-fly (should be pretty cheap) and we remove `DynFlags.buildTag` field. - - - - - 0e83efa2 by Krzysztof Gogolewski at 2020-06-27T11:57:49-04:00 Don't generalize when typechecking a tuple section The code is simpler and cleaner. - - - - - d8ba9e6f by Peter Trommler at 2020-06-28T09:19:11-04:00 RTS: Refactor Haskell-C glue for PPC 64-bit Make sure the stack is 16 byte aligned even when reserved stack bytes are not a multiple of 16 bytes. Avoid saving r2 (TOC). On ELF v1 the function descriptor of StgReturn has the same TOC as StgRun, on ELF v2 the TOC is recomputed in the function prologue. Use the ABI provided functions to save clobbered GPRs and FPRs. Improve comments. Describe what the stack looks like and how it relates to the respective ABIs. - - - - - 42f797b0 by Ryan Scott at 2020-06-28T09:19:46-04:00 Use NHsCoreTy to embed types into GND-generated code `GeneralizedNewtypeDeriving` is in the unique situation where it must produce an `LHsType GhcPs` from a Core `Type`. Historically, this was done with the `typeToLHsType` function, which walked over the entire `Type` and attempted to construct an `LHsType` with the same overall structure. `typeToLHsType` is quite complicated, however, and has been the subject of numerous bugs over the years (e.g., #14579). Luckily, there is an easier way to accomplish the same thing: the `XHsType` constructor of `HsType`. `XHsType` bundles an `NHsCoreTy`, which allows embedding a Core `Type` directly into an `HsType`, avoiding the need to laboriously convert from one to another (as `typeToLHsType` did). Moreover, renaming and typechecking an `XHsType` is simple, since one doesn't need to do anything to a Core `Type`... ...well, almost. For the reasons described in `Note [Typechecking NHsCoreTys]` in `GHC.Tc.Gen.HsType`, we must apply a substitution that we build from the local `tcl_env` type environment. But that's a relatively modest price to pay. Now that `GeneralizedNewtypeDeriving` uses `NHsCoreTy`, the `typeToLHsType` function no longer has any uses in GHC, so this patch rips it out. Some additional tweaks to `hsTypeNeedsParens` were necessary to make the new `-ddump-deriv` output correctly parenthesized, but other than that, this patch is quite straightforward. This is a mostly internal refactoring, although it is likely that `GeneralizedNewtypeDeriving`-generated code will now need fewer language extensions in certain situations than it did before. - - - - - 68530b1c by Jan Hrček at 2020-06-28T09:20:22-04:00 Fix duplicated words and typos in comments and user guide - - - - - 15b79bef by Ryan Scott at 2020-06-28T09:20:57-04:00 Add integer-gmp's ghc.mk and GNUmakefile to .gitignore - - - - - bfa5698b by Simon Peyton Jones at 2020-06-28T09:21:32-04:00 Fix a typo in Lint This simple error in GHC.Core.Litn.lintJoinLams meant that Lint reported bogus errors. Fixes #18399 - - - - - 71006532 by Ryan Scott at 2020-06-30T07:10:42-04:00 Reject nested foralls/contexts in instance types more consistently GHC is very wishy-washy about rejecting instance declarations with nested `forall`s or contexts that are surrounded by outermost parentheses. This can even lead to some strange interactions with `ScopedTypeVariables`, as demonstrated in #18240. This patch makes GHC more consistently reject instance types with nested `forall`s/contexts so as to prevent these strange interactions. On the implementation side, this patch tweaks `splitLHsInstDeclTy` and `getLHsInstDeclHead` to not look through parentheses, which can be semantically significant. I've added a `Note [No nested foralls or contexts in instance types]` in `GHC.Hs.Type` to explain why. This also introduces a `no_nested_foralls_contexts_err` function in `GHC.Rename.HsType` to catch nested `forall`s/contexts in instance types. This function is now used in `rnClsInstDecl` (for ordinary instance declarations) and `rnSrcDerivDecl` (for standalone `deriving` declarations), the latter of which fixes #18271. On the documentation side, this adds a new "Formal syntax for instance declaration types" section to the GHC User's Guide that presents a BNF-style grammar for what is and isn't allowed in instance types. Fixes #18240. Fixes #18271. - - - - - bccf3351 by Sylvain Henry at 2020-06-30T07:10:46-04:00 Add ghc-bignum to 8.12 release notes - - - - - 81704a6f by David Eichmann at 2020-06-30T07:10:48-04:00 Update ssh keys in CI performance metrics upload script - - - - - 85310fb8 by Joshua Price at 2020-06-30T07:10:49-04:00 Add missing Ix instances for tuples of size 6 through 15 (#16643) - - - - - cbb6b62f by Vladislav Zavialov at 2020-07-01T15:41:38-04:00 Implement -XLexicalNegation (GHC Proposal #229) This patch introduces a new extension, -XLexicalNegation, which detects whether the minus sign stands for negation or subtraction using the whitespace-based rules described in GHC Proposal #229. Updates haddock submodule. - - - - - fb5a0d01 by Martin Handley at 2020-07-01T15:42:14-04:00 #17169: Clarify Fixed's Enum instance. - - - - - b316804d by Simon Peyton Jones at 2020-07-01T15:42:49-04:00 Improve debug tracing for substitution This patch improves debug tracing a bit (#18395) * Remove the ancient SDoc argument to substitution, replacing it with a HasDebugCallStack constraint. The latter does the same job (indicate the call site) but much better. * Add HasDebugCallStack to simpleOptExpr, exprIsConApp_maybe I needed this to help nail the lookupIdSubst panic in #18326, #17784 - - - - - 5c9fabb8 by Hécate at 2020-07-01T15:43:25-04:00 Add most common return values for `os` and `arch` - - - - - 76d8cc74 by Ryan Scott at 2020-07-01T15:44:01-04:00 Desugar quoted uses of DerivingVia and expression type signatures properly The way that `GHC.HsToCore.Quote` desugared quoted `via` types (e.g., `deriving via forall a. [a] instance Eq a => Eq (List a)`) and explicit type annotations in signatures (e.g., `f = id @a :: forall a. a -> a`) was completely wrong, as it did not implement the scoping guidelines laid out in `Note [Scoped type variables in bindings]`. This is easily fixed. While I was in town, I did some minor cleanup of related Notes: * `Note [Scoped type variables in bindings]` and `Note [Scoped type variables in class and instance declarations]` say very nearly the same thing. I decided to just consolidate the two Notes into `Note [Scoped type variables in quotes]`. * `Note [Don't quantify implicit type variables in quotes]` is somewhat outdated, as it predates GHC 8.10, where the `forall`-or-nothing rule requires kind variables to be explicitly quantified in the presence of an explicit `forall`. As a result, the running example in that Note doesn't even compile. I have changed the example to something simpler that illustrates the same point that the original Note was making. Fixes #18388. - - - - - 44d6a335 by Andreas Klebinger at 2020-07-02T02:54:54-04:00 T16012: Be verbose on failure. - - - - - f9853330 by Ryan Scott at 2020-07-02T02:55:29-04:00 Bump ghc-prim version to 0.7.0 Fixes #18279. Bumps the `text` submodule. - - - - - 23e4e047 by Sylvain Henry at 2020-07-02T10:46:31-04:00 Hadrian: fix PowerPC64le support (#17601) [ci skip] - - - - - 3cdd8d69 by Sylvain Henry at 2020-07-02T10:47:08-04:00 NCG: correctly handle addresses with huge offsets (#15570) Before this patch we could generate addresses of this form: movzbl cP0_str+-9223372036854775808,%eax The linker can't handle them because the offset is too large: ld.lld: error: Main.o:(.text+0xB3): relocation R_X86_64_32S out of range: -9223372036852653050 is not in [-2147483648, 2147483647] With this patch we detect those cases and generate: movq $-9223372036854775808,%rax addq $cP0_str,%rax movzbl (%rax),%eax I've also refactored `getAmode` a little bit to make it easier to understand and to trace. - - - - - 4d90b3ff by Gabor Greif at 2020-07-02T20:07:59-04:00 No need for CURSES_INCLUDE_DIRS This is a leftover from ef63ff27251a20ff11e58c9303677fa31e609a88 - - - - - f08d6316 by Sylvain Henry at 2020-07-02T20:08:36-04:00 Replace Opt_SccProfilingOn flag with sccProfilingEnabled helper function SCC profiling was enabled in a convoluted way: if WayProf was enabled, Opt_SccProfilingOn general flag was set (in `GHC.Driver.Ways.wayGeneralFlags`), and then this flag was queried in various places. There is no need to go via general flags, so this patch defines a `sccProfilingEnabled :: DynFlags -> Bool` helper function that just checks whether WayProf is enabled. - - - - - 8cc7274b by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Only allocate the Censuses that we need When not LDV profiling there is no reason to allocate 32 Censuses; one will do. This is a very small memory footprint optimisation, but it comes for free. - - - - - b835112c by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Free old allocations when reinitialising Censuses Previously when not LDV profiling we would repeatedly reinitialise `censuses[0]` with `initEra`. This failed to free the `Arena` and `HashTable` from the old census, resulting in a memory leak. Fixes #18348. - - - - - 34be6523 by Valery Tolstov at 2020-07-03T02:50:03-04:00 Mention flags that are not enabled by -Wall (#18372) * Mention missing flags that are not actually enabled by -Wall (docs/users_guide/using-warnings.rst) * Additionally remove -Wmissing-monadfail-instances from the list of flags enabled by -Wcompat, as it is not the case since 8.8 - - - - - edc8d22b by Sylvain Henry at 2020-07-03T02:50:40-04:00 LLVM: support R9 and R10 registers d535ef006d85dbdb7cda2b09c5bc35cb80108909 allowed the use of up to 10 vanilla registers but didn't update LLVM backend to support them. This patch fixes it. - - - - - 4bf18646 by Simon Peyton Jones at 2020-07-03T08:37:42+01:00 Improve handling of data type return kinds Following a long conversation with Richard, this patch tidies up the handling of return kinds for data/newtype declarations (vanilla, family, and instance). I have substantially edited the Notes in TyCl, so they would bear careful reading. Fixes #18300, #18357 In GHC.Tc.Instance.Family.newFamInst we were checking some Lint-like properties with ASSSERT. Instead Richard and I have added a proper linter for axioms, and called it from lintGblEnv, which in turn is called in tcRnModuleTcRnM New tests (T18300, T18357) cause an ASSERT failure in HEAD. - - - - - 41d26492 by Sylvain Henry at 2020-07-03T17:33:59-04:00 DynFlags: avoid the use of sdocWithDynFlags in GHC.Core.Rules (#17957) - - - - - 7aa6ef11 by Hécate at 2020-07-03T17:34:36-04:00 Add the __GHC_FULL_VERSION__ CPP macro to expose the full GHC version - - - - - e61d5395 by Chaitanya Koparkar at 2020-07-07T13:55:59-04:00 ghc-prim: Turn some comments into haddocks [ci skip] - - - - - 37743f91 by John Ericson at 2020-07-07T13:56:00-04:00 Support `timesInt2#` in LLVM backend - - - - - 46397e53 by John Ericson at 2020-07-07T13:56:00-04:00 `genericIntMul2Op`: Call `genericWordMul2Op` directly This unblocks a refactor, and removes partiality. It might be a PowerPC regression but that should be fixable. - - - - - 8a1c0584 by John Ericson at 2020-07-07T13:56:00-04:00 Simplify `PrimopCmmEmit` Follow @simonpj's suggestion of pushing the "into regs" logic into `emitPrimOp`. With the previous commit getting rid of the recursion in `genericIntMul2Op`, this is now an easy refactor. - - - - - 6607f203 by John Ericson at 2020-07-07T13:56:00-04:00 `opAllDone` -> `opIntoRegs` The old name was and terrible and became worse after the previous commit's refactor moved non-trivial funcationlity into its body. - - - - - fdcc53ba by Sylvain Henry at 2020-07-07T13:56:00-04:00 Optimise genericIntMul2Op We shouldn't directly call 'genericWordMul2Op' in genericIntMul2Op because a target may provide a faster primop for 'WordMul2Op': we'd better use it! - - - - - 686e7225 by Moritz Angermann at 2020-07-07T13:56:01-04:00 [linker/rtsSymbols] More linker symbols Mostly symbols needed for aarch64/armv7l and in combination with musl, where we have to rely on loading *all* objects/archives - __stack_chk_* only when not DYNAMIC - - - - - 3f60b94d by Moritz Angermann at 2020-07-07T13:56:01-04:00 better if guards. - - - - - 7abffced by Moritz Angermann at 2020-07-07T13:56:01-04:00 Fix (1) - - - - - cdfeb3f2 by Moritz Angermann at 2020-07-07T13:56:01-04:00 AArch32 symbols only on aarch32. - - - - - f496c955 by Adam Sandberg Ericsson at 2020-07-07T13:56:02-04:00 add -flink-rts flag to link the rts when linking a shared or static library #18072 By default we don't link the RTS when linking shared libraries because in the most usual mode a shared library is an intermediary product, for example a Haskell library, that will be linked into some executable in the end. So we wish to defer the RTS flavour to link to the final link. However sometimes the final product is the shared library, for example when writing a plugin for some other system, so we do wish the shared library to link the RTS. For consistency we also make -staticlib honor this flag and its inversion. -staticlib currently implies -flink-shared. - - - - - c59faf67 by Stefan Schulze Frielinghaus at 2020-07-07T13:56:04-04:00 hadrian: link check-ppr against debugging RTS if ghcDebugged - - - - - 0effc57d by Adam Sandberg Ericsson at 2020-07-07T13:56:05-04:00 rts linker: teach the linker about GLIBC's special handling of *stat, mknod and atexit functions #7072 - - - - - 96153433 by Adam Sandberg Ericsson at 2020-07-07T13:56:06-04:00 hadrian: make hadrian/ghci use the bootstrap compiler from configure #18190 - - - - - 4d24f886 by Adam Sandberg Ericsson at 2020-07-07T13:56:07-04:00 hadrian: ignore cabal configure verbosity related flags #18131 - - - - - 7332bbff by Ben Gamari at 2020-07-07T13:56:08-04:00 testsuite: Widen T12234 acceptance window to 2% Previously it wasn't uncommon to see +/-1% fluctuations in compiler allocations on this test. - - - - - 180b6313 by Gabor Greif at 2020-07-07T13:56:08-04:00 When running libtool, report it as such - - - - - d3bd6897 by Sylvain Henry at 2020-07-07T13:56:11-04:00 BigNum: rename BigNat types Before this patch BigNat names were confusing because we had: * GHC.Num.BigNat.BigNat: unlifted type used everywhere else * GHC.Num.BigNat.BigNatW: lifted type only used to share static constants * GHC.Natural.BigNat: lifted type only used for backward compatibility After this patch we have: * GHC.Num.BigNat.BigNat#: unlifted type * GHC.Num.BigNat.BigNat: lifted type (reexported from GHC.Natural) Thanks to @RyanGlScott for spotting this. - - - - - 929d26db by Sylvain Henry at 2020-07-07T13:56:12-04:00 Bignum: don't build ghc-bignum with stage0 Noticed by @Ericson2314 - - - - - d25b6851 by Sylvain Henry at 2020-07-07T13:56:12-04:00 Hadrian: ghc-gmp.h shouldn't be a compiler dependency - - - - - 0ddae2ba by Sylvain Henry at 2020-07-07T13:56:14-04:00 DynFlags: factor out pprUnitId from "Outputable UnitId" instance - - - - - 204f3f5d by Krzysztof Gogolewski at 2020-07-07T13:56:18-04:00 Remove unused function pprHsForAllExtra (#18423) The function `pprHsForAllExtra` was called only on `Nothing` since 2015 (1e041b7382b6aa). - - - - - 3033e0e4 by Adam Sandberg Ericsson at 2020-07-08T20:36:49-04:00 hadrian: add flag to skip rebuilding dependency information #17636 - - - - - b7de4b96 by Stefan Schulze Frielinghaus at 2020-07-09T09:49:22-04:00 Fix GHCi :print on big-endian platforms On big-endian platforms executing import GHC.Exts data Foo = Foo Float# deriving Show foo = Foo 42.0# foo :print foo results in an arithmetic overflow exception which is caused by function index where moveBytes equals word_size - (r + item_size_b) * 8 Here we have a mixture of units. Both, word_size and item_size_b have unit bytes whereas r has unit bits. On 64-bit platforms moveBytes equals then 8 - (0 + 4) * 8 which results in a negative and therefore invalid second parameter for a shiftL operation. In order to make things more clear the expression (word .&. (mask `shiftL` moveBytes)) `shiftR` moveBytes is equivalent to (word `shiftR` moveBytes) .&. mask On big-endian platforms the shift must be a left shift instead of a right shift. For symmetry reasons not a mask is used but two shifts in order to zero out bits. Thus the fixed version equals case endian of BigEndian -> (word `shiftL` moveBits) `shiftR` zeroOutBits `shiftL` zeroOutBits LittleEndian -> (word `shiftR` moveBits) `shiftL` zeroOutBits `shiftR` zeroOutBits Fixes #16548 and #14455 - - - - - 3656dff8 by Sylvain Henry at 2020-07-09T09:50:01-04:00 LLVM: fix MO_S_Mul2 support (#18434) The value indicating if the carry is useful wasn't taken into account. - - - - - d9f09506 by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Define multiShotIO and use it in mkSplitUniqueSupply This patch is part of the ongoing eta-expansion saga; see #18238. It implements a neat trick (suggested by Sebastian Graf) that allows the programmer to disable the default one-shot behaviour of IO (the "state hack"). The trick is to use a new multiShotIO function; see Note [multiShotIO]. For now, multiShotIO is defined here in Unique.Supply; but it should ultimately be moved to the IO library. The change is necessary to get good code for GHC's unique supply; see Note [Optimising the unique supply]. However it makes no difference to GHC as-is. Rather, it makes a difference when a subsequent commit Improve eta-expansion using ArityType lands. - - - - - bce695cc by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Make arityType deal with join points As Note [Eta-expansion and join points] describes, this patch makes arityType deal correctly with join points. What was there before was not wrong, but yielded lower arities than it could. Fixes #18328 In base GHC this makes no difference to nofib. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- n-body -0.1% -0.1% -1.2% -1.1% 0.0% -------------------------------------------------------------------------------- Min -0.1% -0.1% -55.0% -56.5% 0.0% Max -0.0% 0.0% +16.1% +13.4% 0.0% Geometric Mean -0.0% -0.0% -30.1% -31.0% -0.0% But it starts to make real difference when we land the change to the way mkDupableAlts handles StrictArg, in fixing #13253 and friends. I think this is because we then get more non-inlined join points. - - - - - 2b7c71cb by Simon Peyton Jones at 2020-07-11T12:17:02-04:00 Improve eta-expansion using ArityType As #18355 shows, we were failing to preserve one-shot info when eta-expanding. It's rather easy to fix, by using ArityType more, rather than just Arity. This patch is important to suport the one-shot monad trick; see #18202. But the extra tracking of one-shot-ness requires the patch Define multiShotIO and use it in mkSplitUniqueSupply If that patch is missing, ths patch makes things worse in GHC.Types.Uniq.Supply. With it, however, we see these improvements T3064 compiler bytes allocated -2.2% T3294 compiler bytes allocated -1.3% T12707 compiler bytes allocated -1.3% T13056 compiler bytes allocated -2.2% Metric Decrease: T3064 T3294 T12707 T13056 - - - - - de139cc4 by Artem Pelenitsyn at 2020-07-12T02:53:20-04:00 add reproducer for #15630 - - - - - c4de6a7a by Andreas Klebinger at 2020-07-12T02:53:55-04:00 Give Uniq[D]FM a phantom type for its key. This fixes #17667 and should help to avoid such issues going forward. The changes are mostly mechanical in nature. With two notable exceptions. * The register allocator. The register allocator references registers by distinct uniques. However they come from the types of VirtualReg, Reg or Unique in various places. As a result we sometimes cast the key type of the map and use functions which operate on the now typed map but take a raw Unique as actual key. The logic itself has not changed it just becomes obvious where we do so now. * <Type>Env Modules. As an example a ClassEnv is currently queried using the types `Class`, `Name`, and `TyCon`. This is safe since for a distinct class value all these expressions give the same unique. getUnique cls getUnique (classTyCon cls) getUnique (className cls) getUnique (tcName $ classTyCon cls) This is for the most part contained within the modules defining the interface. However it requires us to play dirty when we are given a `Name` to lookup in a `UniqFM Class a` map. But again the logic did not change and it's for the most part hidden behind the Env Module. Some of these cases could be avoided by refactoring but this is left for future work. We also bump the haddock submodule as it uses UniqFM. - - - - - c2cfdfde by Aaron Allen at 2020-07-13T09:00:33-04:00 Warn about empty Char enumerations (#18402) Currently the "Enumeration is empty" warning (-Wempty-enumerations) only fires for numeric literals. This patch adds support for `Char` literals so that enumerating an empty list of `Char`s will also trigger the warning. - - - - - c3ac87ec by Stefan Schulze Frielinghaus at 2020-07-13T09:01:10-04:00 hadrian: build check-ppr dynamic if GHC is build dynamic Fixes #18361 - - - - - 9ad072b4 by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Use dumpStyle when printing inlinings This just makes debug-printing consistent, and more informative. - - - - - e78c4efb by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Comments only - - - - - 7ccb760b by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Reduce result discount in conSize Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c - - - - - 7f0b671e by Ben Gamari at 2020-07-13T14:52:49-04:00 testsuite: Widen acceptance threshold on T5837 This test is positively tiny and consequently the bytes allocated measurement will be relatively noisy. Consequently I have seen this fail spuriously quite often. - - - - - 118e1c3d by Alp Mestanogullari at 2020-07-14T21:30:52-04:00 compiler: re-engineer the treatment of rebindable if Executing on the plan described in #17582, this patch changes the way if expressions are handled in the compiler in the presence of rebindable syntax. We get rid of the SyntaxExpr field of HsIf and instead, when rebindable syntax is on, we rewrite the HsIf node to the appropriate sequence of applications of the local `ifThenElse` function. In order to be able to report good error messages, with expressions as they were written by the user (and not as desugared by the renamer), we make use of TTG extensions to extend GhcRn expression ASTs with an `HsExpansion` construct, which keeps track of a source (GhcPs) expression and the desugared (GhcRn) expression that it gives rise to. This way, we can typecheck the latter while reporting the former in error messages. In order to discard the error context lines that arise from typechecking the desugared expressions (because they talk about expressions that the user has not written), we carefully give a special treatment to the nodes fabricated by this new renaming-time transformation when typechecking them. See Note [Rebindable syntax and HsExpansion] for more details. The note also includes a recipe to apply the same treatment to other rebindable constructs. Tests 'rebindable11' and 'rebindable12' have been added to make sure we report identical error messages as before this patch under various circumstances. We also now disable rebindable syntax when processing untyped TH quotes, as per the discussion in #18102 and document the interaction of rebindable syntax and Template Haskell, both in Note [Template Haskell quotes and Rebindable Syntax] and in the user guide, adding a test to make sure that we do not regress in that regard. - - - - - 64c774b0 by Andreas Klebinger at 2020-07-14T21:31:27-04:00 Explain why keeping DynFlags in AnalEnv saves allocation. - - - - - 254245d0 by Ben Gamari at 2020-07-14T21:32:03-04:00 docs/users-guide: Update default -funfolding-use-threshold value This was changed in 3d2991f8 but I neglected to update the documentation. Fixes #18419. - - - - - 4c259f86 by Andreas Klebinger at 2020-07-14T21:32:41-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. - - - - - 23797224 by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 .gitlab: re-enable integer-simple substitute (BIGNUM_BACKEND) Recently build system migrated from INTEGER_LIBRARY to BIGNUM_BACKEND. But gitlab CI was never updated. Let's enable BIGNUM_BACKEND=native. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - e0db878a by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 ghc-bignum: bring in sync .hs-boot files with module declarations Before this change `BIGNUM_BACKEND=native` build was failing as: ``` libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs:708:16: error: * Variable not in scope: naturalFromBigNat# :: WordArray# -> t * Perhaps you meant one of these: `naturalFromBigNat' (imported from GHC.Num.Natural), `naturalToBigNat' (imported from GHC.Num.Natural) | 708 | m' = naturalFromBigNat# m | ``` This happens because `.hs-boot` files are slightly out of date. This change brings in data and function types in sync. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - c9f65c36 by Stefan Schulze Frielinghaus at 2020-07-14T21:33:57-04:00 rts/Disassembler.c: Use FMT_HexWord for printing values in hex format - - - - - 58ae62eb by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 macOS: Load frameworks without stating them first. macOS Big Sur makes the following change to how frameworks are shipped with the OS: > New in macOS Big Sur 11 beta, the system ships with a built-in > dynamic linker cache of all system-provided libraries. As part of > this change, copies of dynamic libraries are no longer present on > the filesystem. Code that attempts to check for dynamic library > presence by looking for a file at a path or enumerating a directory > will fail. Instead, check for library presence by attempting to > dlopen() the path, which will correctly check for the library in the > cache. (62986286) https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/ Therefore, the previous method of checking whether a library exists before attempting to load it makes GHC.Runtime.Linker.loadFramework fail to find frameworks installed at /System/Library/Frameworks. GHC.Runtime.Linker.loadFramework now opportunistically loads the framework libraries without checking for their existence first, failing only if all attempts to load a given framework from any of the various possible locations fail. - - - - - cdc4a6b0 by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 loadFramework: Output the errors collected in all loading attempts. With the recent change away from first finding and then loading a framework, loadFramework had no way of communicating the real reason why loadDLL failed if it was any reason other than the framework missing from the file system. It now collects all loading attempt errors into a list and concatenates them into a string to return to the caller. - - - - - 51dbfa52 by Ben Gamari at 2020-07-15T04:05:34-04:00 StgToCmm: Use CmmRegOff smart constructor Previously we would generate expressions of the form `CmmRegOff BaseReg 0`. This should do no harm (and really should be handled by the NCG anyways) but it's better to just generate a plain `CmmReg`. - - - - - ae11bdfd by Ben Gamari at 2020-07-15T04:06:08-04:00 testsuite: Add regression test for #17744 Test due to @monoidal. - - - - - 0e3c277a by Ben Gamari at 2020-07-15T16:41:01-04:00 Bump Cabal submodule Updates a variety of tests as Cabal is now more strict about Cabal file form. - - - - - ceed994a by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Drop Windows Vista support, require Windows 7 - - - - - 00a23bfd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Update Windows FileSystem wrapper utilities. - - - - - 459e1c5f by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Use SlimReaderLocks and ConditonalVariables provided by the OS instead of emulated ones - - - - - 763088fc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Small linker comment and ifdef cleanups - - - - - 1a228ff9 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Flush event logs eagerly. - - - - - e9e04dda by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Refactor Buffer structures to be able to track async operations - - - - - 356dc3fe by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Implement new Console API - - - - - 90e69f77 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add IOPort synchronization primitive - - - - - 71245fcc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add new io-manager cmdline options - - - - - d548a3b3 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Init Windows console Codepage to UTF-8. - - - - - 58ef6366 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add unsafeSplat to GHC.Event.Array - - - - - d660725e by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add size and iterate to GHC.Event.IntTable. - - - - - 050da6dd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Switch Testsuite to test winio by default - - - - - 4bf542bf by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Multiple refactorings and support changes. - - - - - 4489af6b by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core threaded I/O manager - - - - - 64d8f2fe by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core non-threaded I/O manager - - - - - 8da15a09 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix a scheduler bug with the threaded-runtime. - - - - - 84ea3d14 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Relaxing some constraints in io-manager. - - - - - ccf0d107 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix issues with non-threaded I/O manager after split. - - - - - b492fe6e by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Remove some barf statements that are a bit strict. - - - - - 01423fd2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Expand comments describing non-threaded loop - - - - - 4b69004f by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: fix FileSize unstat-able handles - - - - - 9b384270 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Implement new tempfile routines for winio - - - - - f1e0be82 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix input truncation when reading from handle. This was caused by not upholding the read buffer invariant that bufR == bufL == 0 for empty read buffers. - - - - - e176b625 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix output truncation for writes larger than buffer size - - - - - a831ce0e by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Rewrite bufWrite. I think it's far easier to follow the code now. It's also correct now as I had still missed a spot where we didn't update the offset. - - - - - 6aefdf62 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix offset set by bufReadEmpty. bufReadEmpty returns the bytes read *including* content that was already buffered, But for calculating the offset we only care about the number of bytes read into the new buffer. - - - - - 750ebaee by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Clean up code surrounding IOPort primitives. According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc. - - - - - ffd31db9 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix multi threaded threadDelay and a few other small changes. Multithreaded threadDelay suffered from a race condition based on the ioManagerStatus. Since the status isn't needed for WIO I removed it completely. This resulted in a light refactoring, as consequence we will always wake up the IO manager using interruptSystemManager, which uses `postQueuedCompletionStatus` internally. I also added a few comments which hopefully makes the code easier to dive into for the next person diving in. - - - - - 6ec26df2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 wionio: Make IO subsystem check a no-op on non-windows platforms. - - - - - 29bcd936 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Set handle offset when opening files in Append mode. Otherwise we would truncate the file. - - - - - 55c29700 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Remove debug event log trace - - - - - 9acb9f40 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix sqrt and openFile009 test cases - - - - - 57017cb7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Allow hp2ps to build with -DDEBUG - - - - - b8cd9995 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update output of T9681 since we now actually run it. - - - - - 10af5b14 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: A few more improvements to the IOPort primitives. - - - - - 39afc4a7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix expected tempfiles output. Tempfiles now works properly on windows, as such we can delete the win32 specific output. - - - - - 99db46e0 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Assign thread labels to IOManager threads. - - - - - be6af732 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Properly check for the tso of an incall to be zero. - - - - - e2c6dac7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark FD instances as unsupported under WINIO. - - - - - fd02ceed by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix threadDelay maxBound invocations. Instead of letting the ns timer overflow now clamp it at (maxBound :: Word64) ns. That still gives a few hundred years. - - - - - bc79f9f1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comments/cleanup an import in base - - - - - 1d197f4b by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark outstanding_service_requests volatile. As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration. - - - - - dc438186 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Make last_event a local variable - - - - - 2fc957c5 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comment about thread safety of processCompletion. - - - - - 4c026b6c by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: nonthreaded: Create io processing threads in main thread. We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread. - - - - - f47c7208 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add an exported isHeapAlloced function to the RTS - - - - - cc5d7bb1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Queue IO processing threads at the front of the queue. This will unblock the IO thread sooner hopefully leading to higher throughput in some situations. - - - - - e7630115 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: ThreadDelay001: Use higher resolution timer. - - - - - 451b5f96 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update T9681 output, disable T4808 on windows. T4808 tests functionality of the FD interface which won't be supported under WINIO. T9681 just has it's expected output tweaked. - - - - - dd06f930 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Wake io manager once per registerTimeout. Which is implicitly done in editTimeouts, so need to wake it up twice. - - - - - e87d0bf9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update placeholder comment with actual function name. - - - - - fc9025db by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Always lock win32 event queue - - - - - c24c9a1f by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Display thread labels when tracing scheduler events. - - - - - 06542b03 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Refactor non-threaded runner thread and scheduler interface. Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event. - - - - - 256299b1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove outstanding_requests from runner. We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port. - - - - - 3ebd8ad9 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Various fixes related to rebase and testdriver - - - - - 6be6bcba by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Fix rebase artifacts - - - - - 2c649dc3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename unsafeSplat to unsafeCopyFromBuffer - - - - - a18b73f3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove unused size/iterate operations from IntTable - - - - - 16bab48e by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Detect running IO Backend via peeking at RtsConfig - - - - - 8b8405a0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update temp path so GCC etc can handle it. Also fix PIPE support, clean up error casting, fix memory leaks - - - - - 2092bc54 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Minor comments/renamings - - - - - a5b5b6c0 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Checking if an error code indicates completion is now a function. - - - - - 362176fd by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Small refactor in withOverlappedEx - - - - - 32e20597 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: A few comments and commented out dbxIO - - - - - a4bfc1d9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't drop buffer offset in byteView/cwcharView - - - - - b3ad2a54 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: revert BHandle changes. - - - - - 3dcd87e2 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Fix imports - - - - - 5a371890 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update ghc-cabal to handle new Cabal submodule bump - - - - - d07ebe0d by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Only compile sources on Windows - - - - - dcb42393 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Actually return Nothing on EOF for non-blocking read - - - - - 895a3beb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate logic in encodeMultiByte[Raw]IO. - - - - - e06e6734 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate openFile logic - - - - - b59430c0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: fix -werror issue in encoding file - - - - - f8d39a51 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't mention windows specific functions when building on Linux. - - - - - 6a533d2a by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add a note about file locking in the RTS. - - - - - cf37ce34 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Add version to @since annotation - - - - - 0fafa2eb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename GHC.Conc.IOCP -> GHC.Conc.WinIO - - - - - 1854fc23 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Expand GHC.Conc.POSIX description It now explains users may not use these functions when using the old IO manager. - - - - - fcc7ba41 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Fix potential spaceleak in __createUUIDTempFileErrNo - - - - - 6b3fd9fa by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant -Wno-missing-signatures pragmas - - - - - 916fc861 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Make it explicit that we only create one IO manager - - - - - f260a721 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Note why we don't use blocking waits. - - - - - aa0a4bbf by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove commented out pragma - - - - - d679b544 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant buffer write in Handle/Text.hs:bufReadEmpty - - - - - d3f94368 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename SmartHandles to StdHandles - - - - - bd6b8ec1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add comment stating failure behaviour for getUniqueFileInfo. - - - - - 12846b85 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update IOPort haddocks. - - - - - 9f39fb14 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Add a note cross reference - - - - - 62dd5a73 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Name Haskell/OS I/O Manager explicitly in Note - - - - - fa807828 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Expand BlockedOnIOCompletion description. - - - - - f0880a1d by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove historical todos - - - - - 8e58e714 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Update note, remove debugging pragma. - - - - - aa4d84d5 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: flushCharReadBuffer shouldn't need to adjust offsets. - - - - - e580893a by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove obsolete comment about cond. variables - - - - - d54e9d79 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix initial linux validate build - - - - - 3cd4de46 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix ThreadDelay001 CPP - - - - - c88b1b9f by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix openFile009 merge conflict leftover - - - - - 849e8889 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept T9681 output. GHC now reports String instead of [Char]. - - - - - e7701818 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix cabal006 after upgrading cabal submodule Demand cabal 2.0 syntax instead of >= 1.20 as required by newer cabal versions. - - - - - a44f0373 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix stderr output for ghci/linking/dyn tests. We used to filter rtsopts, i opted to instead just accept the warning of it having no effect. This works both for -rtsopts, as well as -with-rtsopts which winio adds. - - - - - 515d9896 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T15261b stdout for --io-manager flag. - - - - - 949aaacc by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T5435_dyn_asm stderr The warning about rtsopts having no consequences is expected. So accept new stderr. - - - - - 7d424e1e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Also accept T7037 stderr - - - - - 1f009768 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal04 by filtering rts args - - - - - 981a9f2e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal01 by accepting expected stderr - - - - - b7b0464e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix safePkg01 by accepting expected stderr - - - - - 32734b29 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix T5435_dyn_gcc by accepting expected stderr - - - - - acc5cebf by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix tempfiles test on linux - - - - - c577b789 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for T3807 - - - - - c108c527 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload - - - - - 2b0b9a08 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload_multiple_objs - - - - - 67afb03c by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify wording on conditional variables. - - - - - 3bd41572 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify comment on cooked mode. - - - - - ded58a03 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: update lockfile signature and remove mistaken symbol in rts. - - - - - 2143c492 by Ben Gamari at 2020-07-15T16:41:04-04:00 testsuite: Add winio and winio_threaded ways Reverts many of the testsuite changes - - - - - c0979cc5 by Ben Gamari at 2020-07-16T10:56:54-04:00 Merge remote-tracking branch 'origin/wip/winio' - - - - - 750a1595 by Ben Gamari at 2020-07-18T07:26:41-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. - - - - - 6ba6a881 by Hécate at 2020-07-18T07:26:42-04:00 Implement `fullCompilerVersion` Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403 This MR adds `fullCompilerVersion`, a function that shares the same backend as the `--numeric-version` GHC flag, exposing a full, three-digit version datatype. - - - - - e6cf27df by Hécate at 2020-07-18T07:26:43-04:00 Add a Lint hadrian rule and an .hlint.yaml file in base/ - - - - - bcb177dd by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Allow multiple case branches to have a higher rank type As #18412 points out, it should be OK for multiple case alternatives to have a higher rank type, provided they are all the same. This patch implements that change. It sweeps away GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it with an enhanced version of fillInferResult. The basic change to fillInferResult is to permit the case in which another case alternative has already filled in the result; and in that case simply unify. It's very simple actually. See the new Note [fillInferResult] in TcMType Other refactoring: - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType (previously some of it was in Unify) - Move tcInstType and friends from TcMType to Instantiate, where it more properly belongs. (TCMType was getting very long.) - - - - - e5525a51 by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Improve typechecking of NPlusK patterns This patch (due to Richard Eisenberg) improves documentation of the wrapper returned by tcSubMult (see Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify). And, more substantially, it cleans up the multiplicity handling in the typechecking of NPlusKPat - - - - - 12f90352 by Krzysztof Gogolewski at 2020-07-18T07:26:45-04:00 Remove {-# CORE #-} pragma (part of #18048) This pragma has no effect since 2011. It was introduced for External Core, which no longer exists. Updates haddock submodule. - - - - - e504c913 by Simon Peyton Jones at 2020-07-18T07:26:45-04:00 Refactor the simplification of join binders This MR (for #18449) refactors the Simplifier's treatment of join-point binders. Specifically, it puts together, into GHC.Core.Opt.Simplify.Env.adjustJoinPointType two currently-separate ways in which we adjust the type of a join point. As the comment says: -- (adjustJoinPointType mult new_res_ty join_id) does two things: -- -- 1. Set the return type of the join_id to new_res_ty -- See Note [Return type for join points] -- -- 2. Adjust the multiplicity of arrows in join_id's type, as -- directed by 'mult'. See Note [Scaling join point arguments] I think this actually fixes a latent bug, by ensuring that the seIdSubst and seInScope have the right multiplicity on the type of join points. I did some tidying up while I was at it. No more setJoinResTy, or modifyJoinResTy: instead it's done locally in Simplify.Env.adjustJoinPointType - - - - - 49b265f0 by Chaitanya Koparkar at 2020-07-18T07:26:46-04:00 Fix minor typos in a Core.hs note - - - - - 8d59aed6 by Stefan Schulze Frielinghaus at 2020-07-18T07:26:47-04:00 GHCi: Fix isLittleEndian - - - - - c26e81d1 by Ben Gamari at 2020-07-18T07:26:47-04:00 testsuite: Mark ghci tests as fragile under unreg compiler In particular I have seen T16012 fail repeatedly under the unregisterised compiler. - - - - - 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - f218cfc9 by Ben Gamari at 2020-07-21T15:27:01-04:00 Bump version to 9.0 - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - a10505e7 by Ben Gamari at 2020-07-28T15:24:29-04:00 Bump haddock submodule - - - - - edf765f8 by Ben Gamari at 2020-08-08T17:32:29-04:00 Merge commit '735f9d6bac316a0c1c68a8b49bba465f07b01cdd' into ghc-9.0 - - - - - 76bbfa1a by Tamar Christina at 2020-08-08T17:32:43-04:00 winio: restore console cp on exit (cherry picked from commit cdd0ff16f20ce920c74f9128a1067cbe1bd378c2) - - - - - 9a5d0cd7 by Tamar Christina at 2020-08-08T17:32:47-04:00 winio: change memory allocation strategy and fix double free errors. (cherry picked from commit c1f4f81d3a439cd1a8128e4ab11c7caac7cc0ad8) - - - - - 5e81de1c by Stefan Schulze Frielinghaus at 2020-08-08T17:33:15-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 (cherry picked from commit fc0f6fbcd95f2dc69a8efabbee2d8a485c34cc47) - - - - - 2a2f3818 by Matthias Andreas Benkard at 2020-08-08T17:33:25-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. (cherry picked from commit a7c4439a407ad85b76aab9301fda61e7c10183ff) - - - - - f412d83b by Ben Gamari at 2020-08-08T17:33:30-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. (cherry picked from commit da7269a4472856ba701d956a247599f721e9915e) - - - - - 738a40f1 by Ben Gamari at 2020-08-08T17:33:36-04:00 testsuite: Update win32 output for parseTree (cherry picked from commit f153a1d0a3351ad4d94cef4cef8e63bab5b47008) - - - - - 08897bff by Ben Gamari at 2020-08-08T17:33:42-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. (cherry picked from commit e91672f0b7185bbafbe8ed1f2ae2cb775111f950) - - - - - 224b8b01 by Ben Gamari at 2020-08-08T17:33:45-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. (cherry picked from commit 9cbfe0868418a531da0872b0c477a15aa67f8861) - - - - - ae4af600 by Tamar Christina at 2020-08-08T17:33:54-04:00 winio: remove dead argument to stg_newIOPortzh (cherry picked from commit 8236925fc8cc2e6e3fed61a0676fa65270a4a538) - - - - - 733e6c2c by Tamar Christina at 2020-08-08T17:33:58-04:00 winio: fix detection of tty terminals (cherry picked from commit ce0a1d678fbc8efa5fd384fd0227b7b3dc97cadd) - - - - - 45ea6120 by Tamar Christina at 2020-08-08T17:34:04-04:00 winio: update codeowners (cherry picked from commit 52685cf7c077c51e3719e3c4dd5ca8257a99c4ea) - - - - - 6b4a0886 by Ben Gamari at 2020-08-08T17:34:10-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. (cherry picked from commit aa054d32a8ff69c334293a0d6c9d11b83a236a96) - - - - - 15de0d56 by Simon Peyton Jones at 2020-08-08T17:34:20-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 (cherry picked from commit 3d345c9680ab3d766ef43dd8389ccc1eaeca066c) - - - - - 84f47156 by Ben Gamari at 2020-08-08T17:34:26-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. (cherry picked from commit 57aca6bba1c000f8542ce94e8b724b0334ff96d4) - - - - - 67e327ad by Ben Gamari at 2020-08-08T17:34:30-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. (cherry picked from commit 0a815cea9fa11ce6ef22aec3525dd7a0df541daf) - - - - - 7f519481 by Simon Peyton Jones at 2020-08-08T17:34:35-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 (cherry picked from commit 0bd60059b0edfee9e8f66c6817257bbb946656cd) - - - - - 34a3bcb8 by Sylvain Henry at 2020-08-08T17:34:42-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. (cherry picked from commit 6ee07b494ddd0131d53ea2fd6a4bb29cd05f4dd8) - - - - - f4b701f0 by Sergei Trofimovich at 2020-08-08T17:34:56-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> (cherry picked from commit 39c89862161bf488a6aca9372cbb67690f436ce7) - - - - - 2938b485 by Felix Wiemuth at 2020-08-08T17:35:03-04:00 Fix typo (cherry picked from commit b9a880fce484d0a87bb794b9d2d8a73e54819011) - - - - - b6e065ed by Simon Peyton Jones at 2020-08-08T17:35:22-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 (cherry picked from commit bbc5191640761ca9773abc898c077363b7beb4e7) - - - - - 72023072 by Sylvain Henry at 2020-08-08T17:39:22-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). (cherry picked from commit 96c31ea1f0303ebabc59edccff2e88444fe02722) - - - - - f9e2bee5 by John Ericson at 2020-08-08T17:39:49-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. (cherry picked from commit 6c68a84254d70280e2dc73485f361787a3503850) - - - - - 66c6b838 by Simon Peyton Jones at 2020-08-08T17:40:20-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d (cherry picked from commit 9f71f69714255165d0fdc2790a588487ff9439dc) - - - - - 8083208d by Sylvain Henry at 2020-08-08T17:40:25-04:00 Fix minimal imports dump for boot files (fix #18497) (cherry picked from commit 7c274cd530cc42a26028050b75d56b3437e06ec1) - - - - - e4ad9038 by Sylvain Henry at 2020-08-08T17:40:32-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. (cherry picked from commit 380638a33691ba43fdcd2e18bca636750e5f66f1) - - - - - 66818b11 by Leon Schoorl at 2020-08-08T17:40:50-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 (cherry picked from commit f2d1accf67cb6e1dab6b2c78fef4b64526c31a4a) - - - - - 3d654faa by Niklas Hambüchen at 2020-08-08T17:40:57-04:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. (cherry picked from commit 947206f478d4eef641dfc58cb4c13471a23260c3) - - - - - 79982db3 by Sylvain Henry at 2020-08-08T17:42:07-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test (cherry picked from commit d613ed7624cbf39192d2a8cf29ab0c0fd2980a15) - - - - - e500e187 by Sylvain Henry at 2020-08-08T17:42:13-04:00 Bignum: add more BigNat compat functions in integer-gmp (cherry picked from commit 3f2f771869c65125ba013a5dd2b213061efe0fc2) - - - - - 85f3d8a2 by Krzysztof Gogolewski at 2020-08-08T17:42:20-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. (cherry picked from commit 5e12cd1733b581f48a5873b12971b6974778eabb) - - - - - 89c804c3 by Ben Gamari at 2020-08-08T17:42:26-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. (cherry picked from commit 2bff2f87e43985e02bdde8c6fa39279df86cb617) - - - - - e88a7570 by Ben Gamari at 2020-08-08T17:42:29-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. (cherry picked from commit 53ce0db5a06598c88c6b8cb32043b878e7083dd4) - - - - - 088f2a60 by Ryan Scott at 2020-08-08T17:42:35-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. (cherry picked from commit fbcb886d503dd7aaebc4c40e59615068b3fd0bd7) - - - - - 6c1048c1 by Vladislav Zavialov at 2020-08-08T17:43:30-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. (cherry picked from commit aee45d9ea8c6cf4ebad4d5c732748923c7865cbe) - - - - - 9c9d9b1d by Takenobu Tani at 2020-08-08T17:43:33-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] (cherry picked from commit 9570c21295a2b4a1d1e40939869124f0b9b9bf91) - - - - - 1e55c8ae by Ben Gamari at 2020-08-08T17:44:01-04:00 cmm: Clean up Notes a bit (cherry picked from commit 5f03606319f745b10e9918c76a47426b293f0bf9) - - - - - ef8a2e8e by Ben Gamari at 2020-08-08T17:44:04-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. (cherry picked from commit 6402c1240d5bd768b8fe8b4368413932bedbe107) - - - - - ac11571e by Ben Gamari at 2020-08-08T17:44:08-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. (cherry picked from commit 15b36de030ecdd60897bc7a6a02bdeabd0825be4) - - - - - 6e254dba by Ben Gamari at 2020-08-08T17:44:11-04:00 testsuite: Add test for #18527 (cherry picked from commit 3847ae0ccf67bddf73304a39f5320c3ba285aa48) - - - - - 704af893 by Ben Gamari at 2020-08-08T17:44:15-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. (cherry picked from commit dd51d53be42114c105b5ab15fcbdb387526b1c17) - - - - - b5f46af9 by Alan Zimmerman at 2020-08-08T17:44:20-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. (cherry picked from commit e4f1b73ad9f292a6bbeb21fee44b0ba1a7f3c33b) - - - - - 75e9c0bd by Ben Gamari at 2020-08-08T17:44:24-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. (cherry picked from commit 8a665db6174eaedbbae925c0ccb4c22b3f29bcaf) - - - - - 20 changed files: - .ghcid - + .git-ignore-revs - .gitlab-ci.yml - + .gitlab/ci.sh - − .gitlab/darwin-init.sh - + .gitlab/linters/check-changelogs.sh - .gitlab/linters/check-cpp.py - .gitlab/merge_request_templates/merge-request.md - − .gitlab/prepare-system.sh - − .gitlab/push-test-metrics.sh - + .gitlab/test-metrics.sh - − .gitlab/win32-init.sh - .gitmodules - CODEOWNERS - HACKING.md - Makefile - aclocal.m4 - boot - + compiler/GHC.hs - + compiler/GHC/Builtin/Names.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/29204b1c4f52ea34d84da33593052ee839293bf2...75e9c0bdedd747263900cdf51419cc88870f4a22 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/29204b1c4f52ea34d84da33593052ee839293bf2...75e9c0bdedd747263900cdf51419cc88870f4a22 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 9 10:14:11 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Sun, 09 Aug 2020 06:14:11 -0400 Subject: [Git][ghc/ghc][wip/az/anns-2] Api Annotations : Adjust SrcSpans for prefix bang (!). Message-ID: <5f2fcc7360eb9_80b3f846910c0c071988e4@gitlab.haskell.org.mail> Alan Zimmerman pushed to branch wip/az/anns-2 at Glasgow Haskell Compiler / GHC Commits: 701463ec by Alan Zimmerman at 2020-08-09T11:09:32+01:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 3 changed files: - compiler/GHC/Parser/PostProcess.hs - testsuite/tests/ghc-api/annotations/Makefile - testsuite/tests/ghc-api/annotations/T10358.stdout Changes: ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -1201,13 +1201,14 @@ makeFunBind fn ms checkPatBind :: LPat GhcPs -> Located (a,GRHSs GhcPs (LHsExpr GhcPs)) -> P ([AddAnn],HsBind GhcPs) -checkPatBind lhs (L match_span (_,grhss)) +checkPatBind lhs (L rhs_span (_,grhss)) | BangPat _ p <- unLoc lhs , VarPat _ v <- unLoc p = return ([], makeFunBind v [L match_span (m v)]) where + match_span = combineSrcSpans (getLoc lhs) rhs_span m v = Match { m_ext = noExtField - , m_ctxt = FunRhs { mc_fun = L (getLoc lhs) (unLoc v) + , m_ctxt = FunRhs { mc_fun = v , mc_fixity = Prefix , mc_strictness = SrcStrict } , m_pats = [] ===================================== testsuite/tests/ghc-api/annotations/Makefile ===================================== @@ -39,7 +39,8 @@ listcomps: .PHONY: T10358 T10358: - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358.hs + # Ignore result code, we have an unattached (superfluous) AnnBang + - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358.hs .PHONY: T10396 T10396: ===================================== testsuite/tests/ghc-api/annotations/T10358.stdout ===================================== @@ -1,5 +1,5 @@ ---Unattached Annotation Problems (should be empty list)--- -[] +[(AnnBang, Test10358.hs:5:19)] ---Ann before enclosing span problem (should be empty list)--- [ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/701463ec9998c679b03dcc848912a7ce9da9a66a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/701463ec9998c679b03dcc848912a7ce9da9a66a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 9 13:37:32 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 09 Aug 2020 09:37:32 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18550 Message-ID: <5f2ffc1c60bde_80b8ca3ed072083be@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T18550 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18550 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 9 15:26:42 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Sun, 09 Aug 2020 11:26:42 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] 340 commits: RTS: Refactor Haskell-C glue for PPC 64-bit Message-ID: <5f3015b2cd03d_80b3f848c1e06f4721899c@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: d8ba9e6f by Peter Trommler at 2020-06-28T09:19:11-04:00 RTS: Refactor Haskell-C glue for PPC 64-bit Make sure the stack is 16 byte aligned even when reserved stack bytes are not a multiple of 16 bytes. Avoid saving r2 (TOC). On ELF v1 the function descriptor of StgReturn has the same TOC as StgRun, on ELF v2 the TOC is recomputed in the function prologue. Use the ABI provided functions to save clobbered GPRs and FPRs. Improve comments. Describe what the stack looks like and how it relates to the respective ABIs. - - - - - 42f797b0 by Ryan Scott at 2020-06-28T09:19:46-04:00 Use NHsCoreTy to embed types into GND-generated code `GeneralizedNewtypeDeriving` is in the unique situation where it must produce an `LHsType GhcPs` from a Core `Type`. Historically, this was done with the `typeToLHsType` function, which walked over the entire `Type` and attempted to construct an `LHsType` with the same overall structure. `typeToLHsType` is quite complicated, however, and has been the subject of numerous bugs over the years (e.g., #14579). Luckily, there is an easier way to accomplish the same thing: the `XHsType` constructor of `HsType`. `XHsType` bundles an `NHsCoreTy`, which allows embedding a Core `Type` directly into an `HsType`, avoiding the need to laboriously convert from one to another (as `typeToLHsType` did). Moreover, renaming and typechecking an `XHsType` is simple, since one doesn't need to do anything to a Core `Type`... ...well, almost. For the reasons described in `Note [Typechecking NHsCoreTys]` in `GHC.Tc.Gen.HsType`, we must apply a substitution that we build from the local `tcl_env` type environment. But that's a relatively modest price to pay. Now that `GeneralizedNewtypeDeriving` uses `NHsCoreTy`, the `typeToLHsType` function no longer has any uses in GHC, so this patch rips it out. Some additional tweaks to `hsTypeNeedsParens` were necessary to make the new `-ddump-deriv` output correctly parenthesized, but other than that, this patch is quite straightforward. This is a mostly internal refactoring, although it is likely that `GeneralizedNewtypeDeriving`-generated code will now need fewer language extensions in certain situations than it did before. - - - - - 68530b1c by Jan Hrček at 2020-06-28T09:20:22-04:00 Fix duplicated words and typos in comments and user guide - - - - - 15b79bef by Ryan Scott at 2020-06-28T09:20:57-04:00 Add integer-gmp's ghc.mk and GNUmakefile to .gitignore - - - - - bfa5698b by Simon Peyton Jones at 2020-06-28T09:21:32-04:00 Fix a typo in Lint This simple error in GHC.Core.Litn.lintJoinLams meant that Lint reported bogus errors. Fixes #18399 - - - - - 71006532 by Ryan Scott at 2020-06-30T07:10:42-04:00 Reject nested foralls/contexts in instance types more consistently GHC is very wishy-washy about rejecting instance declarations with nested `forall`s or contexts that are surrounded by outermost parentheses. This can even lead to some strange interactions with `ScopedTypeVariables`, as demonstrated in #18240. This patch makes GHC more consistently reject instance types with nested `forall`s/contexts so as to prevent these strange interactions. On the implementation side, this patch tweaks `splitLHsInstDeclTy` and `getLHsInstDeclHead` to not look through parentheses, which can be semantically significant. I've added a `Note [No nested foralls or contexts in instance types]` in `GHC.Hs.Type` to explain why. This also introduces a `no_nested_foralls_contexts_err` function in `GHC.Rename.HsType` to catch nested `forall`s/contexts in instance types. This function is now used in `rnClsInstDecl` (for ordinary instance declarations) and `rnSrcDerivDecl` (for standalone `deriving` declarations), the latter of which fixes #18271. On the documentation side, this adds a new "Formal syntax for instance declaration types" section to the GHC User's Guide that presents a BNF-style grammar for what is and isn't allowed in instance types. Fixes #18240. Fixes #18271. - - - - - bccf3351 by Sylvain Henry at 2020-06-30T07:10:46-04:00 Add ghc-bignum to 8.12 release notes - - - - - 81704a6f by David Eichmann at 2020-06-30T07:10:48-04:00 Update ssh keys in CI performance metrics upload script - - - - - 85310fb8 by Joshua Price at 2020-06-30T07:10:49-04:00 Add missing Ix instances for tuples of size 6 through 15 (#16643) - - - - - cbb6b62f by Vladislav Zavialov at 2020-07-01T15:41:38-04:00 Implement -XLexicalNegation (GHC Proposal #229) This patch introduces a new extension, -XLexicalNegation, which detects whether the minus sign stands for negation or subtraction using the whitespace-based rules described in GHC Proposal #229. Updates haddock submodule. - - - - - fb5a0d01 by Martin Handley at 2020-07-01T15:42:14-04:00 #17169: Clarify Fixed's Enum instance. - - - - - b316804d by Simon Peyton Jones at 2020-07-01T15:42:49-04:00 Improve debug tracing for substitution This patch improves debug tracing a bit (#18395) * Remove the ancient SDoc argument to substitution, replacing it with a HasDebugCallStack constraint. The latter does the same job (indicate the call site) but much better. * Add HasDebugCallStack to simpleOptExpr, exprIsConApp_maybe I needed this to help nail the lookupIdSubst panic in #18326, #17784 - - - - - 5c9fabb8 by Hécate at 2020-07-01T15:43:25-04:00 Add most common return values for `os` and `arch` - - - - - 76d8cc74 by Ryan Scott at 2020-07-01T15:44:01-04:00 Desugar quoted uses of DerivingVia and expression type signatures properly The way that `GHC.HsToCore.Quote` desugared quoted `via` types (e.g., `deriving via forall a. [a] instance Eq a => Eq (List a)`) and explicit type annotations in signatures (e.g., `f = id @a :: forall a. a -> a`) was completely wrong, as it did not implement the scoping guidelines laid out in `Note [Scoped type variables in bindings]`. This is easily fixed. While I was in town, I did some minor cleanup of related Notes: * `Note [Scoped type variables in bindings]` and `Note [Scoped type variables in class and instance declarations]` say very nearly the same thing. I decided to just consolidate the two Notes into `Note [Scoped type variables in quotes]`. * `Note [Don't quantify implicit type variables in quotes]` is somewhat outdated, as it predates GHC 8.10, where the `forall`-or-nothing rule requires kind variables to be explicitly quantified in the presence of an explicit `forall`. As a result, the running example in that Note doesn't even compile. I have changed the example to something simpler that illustrates the same point that the original Note was making. Fixes #18388. - - - - - 44d6a335 by Andreas Klebinger at 2020-07-02T02:54:54-04:00 T16012: Be verbose on failure. - - - - - f9853330 by Ryan Scott at 2020-07-02T02:55:29-04:00 Bump ghc-prim version to 0.7.0 Fixes #18279. Bumps the `text` submodule. - - - - - 23e4e047 by Sylvain Henry at 2020-07-02T10:46:31-04:00 Hadrian: fix PowerPC64le support (#17601) [ci skip] - - - - - 3cdd8d69 by Sylvain Henry at 2020-07-02T10:47:08-04:00 NCG: correctly handle addresses with huge offsets (#15570) Before this patch we could generate addresses of this form: movzbl cP0_str+-9223372036854775808,%eax The linker can't handle them because the offset is too large: ld.lld: error: Main.o:(.text+0xB3): relocation R_X86_64_32S out of range: -9223372036852653050 is not in [-2147483648, 2147483647] With this patch we detect those cases and generate: movq $-9223372036854775808,%rax addq $cP0_str,%rax movzbl (%rax),%eax I've also refactored `getAmode` a little bit to make it easier to understand and to trace. - - - - - 4d90b3ff by Gabor Greif at 2020-07-02T20:07:59-04:00 No need for CURSES_INCLUDE_DIRS This is a leftover from ef63ff27251a20ff11e58c9303677fa31e609a88 - - - - - f08d6316 by Sylvain Henry at 2020-07-02T20:08:36-04:00 Replace Opt_SccProfilingOn flag with sccProfilingEnabled helper function SCC profiling was enabled in a convoluted way: if WayProf was enabled, Opt_SccProfilingOn general flag was set (in `GHC.Driver.Ways.wayGeneralFlags`), and then this flag was queried in various places. There is no need to go via general flags, so this patch defines a `sccProfilingEnabled :: DynFlags -> Bool` helper function that just checks whether WayProf is enabled. - - - - - 8cc7274b by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Only allocate the Censuses that we need When not LDV profiling there is no reason to allocate 32 Censuses; one will do. This is a very small memory footprint optimisation, but it comes for free. - - - - - b835112c by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Free old allocations when reinitialising Censuses Previously when not LDV profiling we would repeatedly reinitialise `censuses[0]` with `initEra`. This failed to free the `Arena` and `HashTable` from the old census, resulting in a memory leak. Fixes #18348. - - - - - 34be6523 by Valery Tolstov at 2020-07-03T02:50:03-04:00 Mention flags that are not enabled by -Wall (#18372) * Mention missing flags that are not actually enabled by -Wall (docs/users_guide/using-warnings.rst) * Additionally remove -Wmissing-monadfail-instances from the list of flags enabled by -Wcompat, as it is not the case since 8.8 - - - - - edc8d22b by Sylvain Henry at 2020-07-03T02:50:40-04:00 LLVM: support R9 and R10 registers d535ef006d85dbdb7cda2b09c5bc35cb80108909 allowed the use of up to 10 vanilla registers but didn't update LLVM backend to support them. This patch fixes it. - - - - - 4bf18646 by Simon Peyton Jones at 2020-07-03T08:37:42+01:00 Improve handling of data type return kinds Following a long conversation with Richard, this patch tidies up the handling of return kinds for data/newtype declarations (vanilla, family, and instance). I have substantially edited the Notes in TyCl, so they would bear careful reading. Fixes #18300, #18357 In GHC.Tc.Instance.Family.newFamInst we were checking some Lint-like properties with ASSSERT. Instead Richard and I have added a proper linter for axioms, and called it from lintGblEnv, which in turn is called in tcRnModuleTcRnM New tests (T18300, T18357) cause an ASSERT failure in HEAD. - - - - - 41d26492 by Sylvain Henry at 2020-07-03T17:33:59-04:00 DynFlags: avoid the use of sdocWithDynFlags in GHC.Core.Rules (#17957) - - - - - 7aa6ef11 by Hécate at 2020-07-03T17:34:36-04:00 Add the __GHC_FULL_VERSION__ CPP macro to expose the full GHC version - - - - - e61d5395 by Chaitanya Koparkar at 2020-07-07T13:55:59-04:00 ghc-prim: Turn some comments into haddocks [ci skip] - - - - - 37743f91 by John Ericson at 2020-07-07T13:56:00-04:00 Support `timesInt2#` in LLVM backend - - - - - 46397e53 by John Ericson at 2020-07-07T13:56:00-04:00 `genericIntMul2Op`: Call `genericWordMul2Op` directly This unblocks a refactor, and removes partiality. It might be a PowerPC regression but that should be fixable. - - - - - 8a1c0584 by John Ericson at 2020-07-07T13:56:00-04:00 Simplify `PrimopCmmEmit` Follow @simonpj's suggestion of pushing the "into regs" logic into `emitPrimOp`. With the previous commit getting rid of the recursion in `genericIntMul2Op`, this is now an easy refactor. - - - - - 6607f203 by John Ericson at 2020-07-07T13:56:00-04:00 `opAllDone` -> `opIntoRegs` The old name was and terrible and became worse after the previous commit's refactor moved non-trivial funcationlity into its body. - - - - - fdcc53ba by Sylvain Henry at 2020-07-07T13:56:00-04:00 Optimise genericIntMul2Op We shouldn't directly call 'genericWordMul2Op' in genericIntMul2Op because a target may provide a faster primop for 'WordMul2Op': we'd better use it! - - - - - 686e7225 by Moritz Angermann at 2020-07-07T13:56:01-04:00 [linker/rtsSymbols] More linker symbols Mostly symbols needed for aarch64/armv7l and in combination with musl, where we have to rely on loading *all* objects/archives - __stack_chk_* only when not DYNAMIC - - - - - 3f60b94d by Moritz Angermann at 2020-07-07T13:56:01-04:00 better if guards. - - - - - 7abffced by Moritz Angermann at 2020-07-07T13:56:01-04:00 Fix (1) - - - - - cdfeb3f2 by Moritz Angermann at 2020-07-07T13:56:01-04:00 AArch32 symbols only on aarch32. - - - - - f496c955 by Adam Sandberg Ericsson at 2020-07-07T13:56:02-04:00 add -flink-rts flag to link the rts when linking a shared or static library #18072 By default we don't link the RTS when linking shared libraries because in the most usual mode a shared library is an intermediary product, for example a Haskell library, that will be linked into some executable in the end. So we wish to defer the RTS flavour to link to the final link. However sometimes the final product is the shared library, for example when writing a plugin for some other system, so we do wish the shared library to link the RTS. For consistency we also make -staticlib honor this flag and its inversion. -staticlib currently implies -flink-shared. - - - - - c59faf67 by Stefan Schulze Frielinghaus at 2020-07-07T13:56:04-04:00 hadrian: link check-ppr against debugging RTS if ghcDebugged - - - - - 0effc57d by Adam Sandberg Ericsson at 2020-07-07T13:56:05-04:00 rts linker: teach the linker about GLIBC's special handling of *stat, mknod and atexit functions #7072 - - - - - 96153433 by Adam Sandberg Ericsson at 2020-07-07T13:56:06-04:00 hadrian: make hadrian/ghci use the bootstrap compiler from configure #18190 - - - - - 4d24f886 by Adam Sandberg Ericsson at 2020-07-07T13:56:07-04:00 hadrian: ignore cabal configure verbosity related flags #18131 - - - - - 7332bbff by Ben Gamari at 2020-07-07T13:56:08-04:00 testsuite: Widen T12234 acceptance window to 2% Previously it wasn't uncommon to see +/-1% fluctuations in compiler allocations on this test. - - - - - 180b6313 by Gabor Greif at 2020-07-07T13:56:08-04:00 When running libtool, report it as such - - - - - d3bd6897 by Sylvain Henry at 2020-07-07T13:56:11-04:00 BigNum: rename BigNat types Before this patch BigNat names were confusing because we had: * GHC.Num.BigNat.BigNat: unlifted type used everywhere else * GHC.Num.BigNat.BigNatW: lifted type only used to share static constants * GHC.Natural.BigNat: lifted type only used for backward compatibility After this patch we have: * GHC.Num.BigNat.BigNat#: unlifted type * GHC.Num.BigNat.BigNat: lifted type (reexported from GHC.Natural) Thanks to @RyanGlScott for spotting this. - - - - - 929d26db by Sylvain Henry at 2020-07-07T13:56:12-04:00 Bignum: don't build ghc-bignum with stage0 Noticed by @Ericson2314 - - - - - d25b6851 by Sylvain Henry at 2020-07-07T13:56:12-04:00 Hadrian: ghc-gmp.h shouldn't be a compiler dependency - - - - - 0ddae2ba by Sylvain Henry at 2020-07-07T13:56:14-04:00 DynFlags: factor out pprUnitId from "Outputable UnitId" instance - - - - - 204f3f5d by Krzysztof Gogolewski at 2020-07-07T13:56:18-04:00 Remove unused function pprHsForAllExtra (#18423) The function `pprHsForAllExtra` was called only on `Nothing` since 2015 (1e041b7382b6aa). - - - - - 3033e0e4 by Adam Sandberg Ericsson at 2020-07-08T20:36:49-04:00 hadrian: add flag to skip rebuilding dependency information #17636 - - - - - b7de4b96 by Stefan Schulze Frielinghaus at 2020-07-09T09:49:22-04:00 Fix GHCi :print on big-endian platforms On big-endian platforms executing import GHC.Exts data Foo = Foo Float# deriving Show foo = Foo 42.0# foo :print foo results in an arithmetic overflow exception which is caused by function index where moveBytes equals word_size - (r + item_size_b) * 8 Here we have a mixture of units. Both, word_size and item_size_b have unit bytes whereas r has unit bits. On 64-bit platforms moveBytes equals then 8 - (0 + 4) * 8 which results in a negative and therefore invalid second parameter for a shiftL operation. In order to make things more clear the expression (word .&. (mask `shiftL` moveBytes)) `shiftR` moveBytes is equivalent to (word `shiftR` moveBytes) .&. mask On big-endian platforms the shift must be a left shift instead of a right shift. For symmetry reasons not a mask is used but two shifts in order to zero out bits. Thus the fixed version equals case endian of BigEndian -> (word `shiftL` moveBits) `shiftR` zeroOutBits `shiftL` zeroOutBits LittleEndian -> (word `shiftR` moveBits) `shiftL` zeroOutBits `shiftR` zeroOutBits Fixes #16548 and #14455 - - - - - 3656dff8 by Sylvain Henry at 2020-07-09T09:50:01-04:00 LLVM: fix MO_S_Mul2 support (#18434) The value indicating if the carry is useful wasn't taken into account. - - - - - d9f09506 by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Define multiShotIO and use it in mkSplitUniqueSupply This patch is part of the ongoing eta-expansion saga; see #18238. It implements a neat trick (suggested by Sebastian Graf) that allows the programmer to disable the default one-shot behaviour of IO (the "state hack"). The trick is to use a new multiShotIO function; see Note [multiShotIO]. For now, multiShotIO is defined here in Unique.Supply; but it should ultimately be moved to the IO library. The change is necessary to get good code for GHC's unique supply; see Note [Optimising the unique supply]. However it makes no difference to GHC as-is. Rather, it makes a difference when a subsequent commit Improve eta-expansion using ArityType lands. - - - - - bce695cc by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Make arityType deal with join points As Note [Eta-expansion and join points] describes, this patch makes arityType deal correctly with join points. What was there before was not wrong, but yielded lower arities than it could. Fixes #18328 In base GHC this makes no difference to nofib. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- n-body -0.1% -0.1% -1.2% -1.1% 0.0% -------------------------------------------------------------------------------- Min -0.1% -0.1% -55.0% -56.5% 0.0% Max -0.0% 0.0% +16.1% +13.4% 0.0% Geometric Mean -0.0% -0.0% -30.1% -31.0% -0.0% But it starts to make real difference when we land the change to the way mkDupableAlts handles StrictArg, in fixing #13253 and friends. I think this is because we then get more non-inlined join points. - - - - - 2b7c71cb by Simon Peyton Jones at 2020-07-11T12:17:02-04:00 Improve eta-expansion using ArityType As #18355 shows, we were failing to preserve one-shot info when eta-expanding. It's rather easy to fix, by using ArityType more, rather than just Arity. This patch is important to suport the one-shot monad trick; see #18202. But the extra tracking of one-shot-ness requires the patch Define multiShotIO and use it in mkSplitUniqueSupply If that patch is missing, ths patch makes things worse in GHC.Types.Uniq.Supply. With it, however, we see these improvements T3064 compiler bytes allocated -2.2% T3294 compiler bytes allocated -1.3% T12707 compiler bytes allocated -1.3% T13056 compiler bytes allocated -2.2% Metric Decrease: T3064 T3294 T12707 T13056 - - - - - de139cc4 by Artem Pelenitsyn at 2020-07-12T02:53:20-04:00 add reproducer for #15630 - - - - - c4de6a7a by Andreas Klebinger at 2020-07-12T02:53:55-04:00 Give Uniq[D]FM a phantom type for its key. This fixes #17667 and should help to avoid such issues going forward. The changes are mostly mechanical in nature. With two notable exceptions. * The register allocator. The register allocator references registers by distinct uniques. However they come from the types of VirtualReg, Reg or Unique in various places. As a result we sometimes cast the key type of the map and use functions which operate on the now typed map but take a raw Unique as actual key. The logic itself has not changed it just becomes obvious where we do so now. * <Type>Env Modules. As an example a ClassEnv is currently queried using the types `Class`, `Name`, and `TyCon`. This is safe since for a distinct class value all these expressions give the same unique. getUnique cls getUnique (classTyCon cls) getUnique (className cls) getUnique (tcName $ classTyCon cls) This is for the most part contained within the modules defining the interface. However it requires us to play dirty when we are given a `Name` to lookup in a `UniqFM Class a` map. But again the logic did not change and it's for the most part hidden behind the Env Module. Some of these cases could be avoided by refactoring but this is left for future work. We also bump the haddock submodule as it uses UniqFM. - - - - - c2cfdfde by Aaron Allen at 2020-07-13T09:00:33-04:00 Warn about empty Char enumerations (#18402) Currently the "Enumeration is empty" warning (-Wempty-enumerations) only fires for numeric literals. This patch adds support for `Char` literals so that enumerating an empty list of `Char`s will also trigger the warning. - - - - - c3ac87ec by Stefan Schulze Frielinghaus at 2020-07-13T09:01:10-04:00 hadrian: build check-ppr dynamic if GHC is build dynamic Fixes #18361 - - - - - 9ad072b4 by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Use dumpStyle when printing inlinings This just makes debug-printing consistent, and more informative. - - - - - e78c4efb by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Comments only - - - - - 7ccb760b by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Reduce result discount in conSize Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c - - - - - 7f0b671e by Ben Gamari at 2020-07-13T14:52:49-04:00 testsuite: Widen acceptance threshold on T5837 This test is positively tiny and consequently the bytes allocated measurement will be relatively noisy. Consequently I have seen this fail spuriously quite often. - - - - - 118e1c3d by Alp Mestanogullari at 2020-07-14T21:30:52-04:00 compiler: re-engineer the treatment of rebindable if Executing on the plan described in #17582, this patch changes the way if expressions are handled in the compiler in the presence of rebindable syntax. We get rid of the SyntaxExpr field of HsIf and instead, when rebindable syntax is on, we rewrite the HsIf node to the appropriate sequence of applications of the local `ifThenElse` function. In order to be able to report good error messages, with expressions as they were written by the user (and not as desugared by the renamer), we make use of TTG extensions to extend GhcRn expression ASTs with an `HsExpansion` construct, which keeps track of a source (GhcPs) expression and the desugared (GhcRn) expression that it gives rise to. This way, we can typecheck the latter while reporting the former in error messages. In order to discard the error context lines that arise from typechecking the desugared expressions (because they talk about expressions that the user has not written), we carefully give a special treatment to the nodes fabricated by this new renaming-time transformation when typechecking them. See Note [Rebindable syntax and HsExpansion] for more details. The note also includes a recipe to apply the same treatment to other rebindable constructs. Tests 'rebindable11' and 'rebindable12' have been added to make sure we report identical error messages as before this patch under various circumstances. We also now disable rebindable syntax when processing untyped TH quotes, as per the discussion in #18102 and document the interaction of rebindable syntax and Template Haskell, both in Note [Template Haskell quotes and Rebindable Syntax] and in the user guide, adding a test to make sure that we do not regress in that regard. - - - - - 64c774b0 by Andreas Klebinger at 2020-07-14T21:31:27-04:00 Explain why keeping DynFlags in AnalEnv saves allocation. - - - - - 254245d0 by Ben Gamari at 2020-07-14T21:32:03-04:00 docs/users-guide: Update default -funfolding-use-threshold value This was changed in 3d2991f8 but I neglected to update the documentation. Fixes #18419. - - - - - 4c259f86 by Andreas Klebinger at 2020-07-14T21:32:41-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. - - - - - 23797224 by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 .gitlab: re-enable integer-simple substitute (BIGNUM_BACKEND) Recently build system migrated from INTEGER_LIBRARY to BIGNUM_BACKEND. But gitlab CI was never updated. Let's enable BIGNUM_BACKEND=native. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - e0db878a by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 ghc-bignum: bring in sync .hs-boot files with module declarations Before this change `BIGNUM_BACKEND=native` build was failing as: ``` libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs:708:16: error: * Variable not in scope: naturalFromBigNat# :: WordArray# -> t * Perhaps you meant one of these: `naturalFromBigNat' (imported from GHC.Num.Natural), `naturalToBigNat' (imported from GHC.Num.Natural) | 708 | m' = naturalFromBigNat# m | ``` This happens because `.hs-boot` files are slightly out of date. This change brings in data and function types in sync. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - c9f65c36 by Stefan Schulze Frielinghaus at 2020-07-14T21:33:57-04:00 rts/Disassembler.c: Use FMT_HexWord for printing values in hex format - - - - - 58ae62eb by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 macOS: Load frameworks without stating them first. macOS Big Sur makes the following change to how frameworks are shipped with the OS: > New in macOS Big Sur 11 beta, the system ships with a built-in > dynamic linker cache of all system-provided libraries. As part of > this change, copies of dynamic libraries are no longer present on > the filesystem. Code that attempts to check for dynamic library > presence by looking for a file at a path or enumerating a directory > will fail. Instead, check for library presence by attempting to > dlopen() the path, which will correctly check for the library in the > cache. (62986286) https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/ Therefore, the previous method of checking whether a library exists before attempting to load it makes GHC.Runtime.Linker.loadFramework fail to find frameworks installed at /System/Library/Frameworks. GHC.Runtime.Linker.loadFramework now opportunistically loads the framework libraries without checking for their existence first, failing only if all attempts to load a given framework from any of the various possible locations fail. - - - - - cdc4a6b0 by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 loadFramework: Output the errors collected in all loading attempts. With the recent change away from first finding and then loading a framework, loadFramework had no way of communicating the real reason why loadDLL failed if it was any reason other than the framework missing from the file system. It now collects all loading attempt errors into a list and concatenates them into a string to return to the caller. - - - - - 51dbfa52 by Ben Gamari at 2020-07-15T04:05:34-04:00 StgToCmm: Use CmmRegOff smart constructor Previously we would generate expressions of the form `CmmRegOff BaseReg 0`. This should do no harm (and really should be handled by the NCG anyways) but it's better to just generate a plain `CmmReg`. - - - - - ae11bdfd by Ben Gamari at 2020-07-15T04:06:08-04:00 testsuite: Add regression test for #17744 Test due to @monoidal. - - - - - 0e3c277a by Ben Gamari at 2020-07-15T16:41:01-04:00 Bump Cabal submodule Updates a variety of tests as Cabal is now more strict about Cabal file form. - - - - - ceed994a by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Drop Windows Vista support, require Windows 7 - - - - - 00a23bfd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Update Windows FileSystem wrapper utilities. - - - - - 459e1c5f by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Use SlimReaderLocks and ConditonalVariables provided by the OS instead of emulated ones - - - - - 763088fc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Small linker comment and ifdef cleanups - - - - - 1a228ff9 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Flush event logs eagerly. - - - - - e9e04dda by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Refactor Buffer structures to be able to track async operations - - - - - 356dc3fe by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Implement new Console API - - - - - 90e69f77 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add IOPort synchronization primitive - - - - - 71245fcc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add new io-manager cmdline options - - - - - d548a3b3 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Init Windows console Codepage to UTF-8. - - - - - 58ef6366 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add unsafeSplat to GHC.Event.Array - - - - - d660725e by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add size and iterate to GHC.Event.IntTable. - - - - - 050da6dd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Switch Testsuite to test winio by default - - - - - 4bf542bf by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Multiple refactorings and support changes. - - - - - 4489af6b by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core threaded I/O manager - - - - - 64d8f2fe by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core non-threaded I/O manager - - - - - 8da15a09 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix a scheduler bug with the threaded-runtime. - - - - - 84ea3d14 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Relaxing some constraints in io-manager. - - - - - ccf0d107 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix issues with non-threaded I/O manager after split. - - - - - b492fe6e by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Remove some barf statements that are a bit strict. - - - - - 01423fd2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Expand comments describing non-threaded loop - - - - - 4b69004f by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: fix FileSize unstat-able handles - - - - - 9b384270 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Implement new tempfile routines for winio - - - - - f1e0be82 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix input truncation when reading from handle. This was caused by not upholding the read buffer invariant that bufR == bufL == 0 for empty read buffers. - - - - - e176b625 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix output truncation for writes larger than buffer size - - - - - a831ce0e by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Rewrite bufWrite. I think it's far easier to follow the code now. It's also correct now as I had still missed a spot where we didn't update the offset. - - - - - 6aefdf62 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix offset set by bufReadEmpty. bufReadEmpty returns the bytes read *including* content that was already buffered, But for calculating the offset we only care about the number of bytes read into the new buffer. - - - - - 750ebaee by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Clean up code surrounding IOPort primitives. According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc. - - - - - ffd31db9 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix multi threaded threadDelay and a few other small changes. Multithreaded threadDelay suffered from a race condition based on the ioManagerStatus. Since the status isn't needed for WIO I removed it completely. This resulted in a light refactoring, as consequence we will always wake up the IO manager using interruptSystemManager, which uses `postQueuedCompletionStatus` internally. I also added a few comments which hopefully makes the code easier to dive into for the next person diving in. - - - - - 6ec26df2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 wionio: Make IO subsystem check a no-op on non-windows platforms. - - - - - 29bcd936 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Set handle offset when opening files in Append mode. Otherwise we would truncate the file. - - - - - 55c29700 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Remove debug event log trace - - - - - 9acb9f40 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix sqrt and openFile009 test cases - - - - - 57017cb7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Allow hp2ps to build with -DDEBUG - - - - - b8cd9995 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update output of T9681 since we now actually run it. - - - - - 10af5b14 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: A few more improvements to the IOPort primitives. - - - - - 39afc4a7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix expected tempfiles output. Tempfiles now works properly on windows, as such we can delete the win32 specific output. - - - - - 99db46e0 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Assign thread labels to IOManager threads. - - - - - be6af732 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Properly check for the tso of an incall to be zero. - - - - - e2c6dac7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark FD instances as unsupported under WINIO. - - - - - fd02ceed by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix threadDelay maxBound invocations. Instead of letting the ns timer overflow now clamp it at (maxBound :: Word64) ns. That still gives a few hundred years. - - - - - bc79f9f1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comments/cleanup an import in base - - - - - 1d197f4b by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark outstanding_service_requests volatile. As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration. - - - - - dc438186 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Make last_event a local variable - - - - - 2fc957c5 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comment about thread safety of processCompletion. - - - - - 4c026b6c by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: nonthreaded: Create io processing threads in main thread. We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread. - - - - - f47c7208 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add an exported isHeapAlloced function to the RTS - - - - - cc5d7bb1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Queue IO processing threads at the front of the queue. This will unblock the IO thread sooner hopefully leading to higher throughput in some situations. - - - - - e7630115 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: ThreadDelay001: Use higher resolution timer. - - - - - 451b5f96 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update T9681 output, disable T4808 on windows. T4808 tests functionality of the FD interface which won't be supported under WINIO. T9681 just has it's expected output tweaked. - - - - - dd06f930 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Wake io manager once per registerTimeout. Which is implicitly done in editTimeouts, so need to wake it up twice. - - - - - e87d0bf9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update placeholder comment with actual function name. - - - - - fc9025db by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Always lock win32 event queue - - - - - c24c9a1f by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Display thread labels when tracing scheduler events. - - - - - 06542b03 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Refactor non-threaded runner thread and scheduler interface. Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event. - - - - - 256299b1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove outstanding_requests from runner. We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port. - - - - - 3ebd8ad9 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Various fixes related to rebase and testdriver - - - - - 6be6bcba by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Fix rebase artifacts - - - - - 2c649dc3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename unsafeSplat to unsafeCopyFromBuffer - - - - - a18b73f3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove unused size/iterate operations from IntTable - - - - - 16bab48e by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Detect running IO Backend via peeking at RtsConfig - - - - - 8b8405a0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update temp path so GCC etc can handle it. Also fix PIPE support, clean up error casting, fix memory leaks - - - - - 2092bc54 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Minor comments/renamings - - - - - a5b5b6c0 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Checking if an error code indicates completion is now a function. - - - - - 362176fd by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Small refactor in withOverlappedEx - - - - - 32e20597 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: A few comments and commented out dbxIO - - - - - a4bfc1d9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't drop buffer offset in byteView/cwcharView - - - - - b3ad2a54 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: revert BHandle changes. - - - - - 3dcd87e2 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Fix imports - - - - - 5a371890 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update ghc-cabal to handle new Cabal submodule bump - - - - - d07ebe0d by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Only compile sources on Windows - - - - - dcb42393 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Actually return Nothing on EOF for non-blocking read - - - - - 895a3beb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate logic in encodeMultiByte[Raw]IO. - - - - - e06e6734 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate openFile logic - - - - - b59430c0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: fix -werror issue in encoding file - - - - - f8d39a51 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't mention windows specific functions when building on Linux. - - - - - 6a533d2a by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add a note about file locking in the RTS. - - - - - cf37ce34 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Add version to @since annotation - - - - - 0fafa2eb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename GHC.Conc.IOCP -> GHC.Conc.WinIO - - - - - 1854fc23 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Expand GHC.Conc.POSIX description It now explains users may not use these functions when using the old IO manager. - - - - - fcc7ba41 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Fix potential spaceleak in __createUUIDTempFileErrNo - - - - - 6b3fd9fa by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant -Wno-missing-signatures pragmas - - - - - 916fc861 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Make it explicit that we only create one IO manager - - - - - f260a721 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Note why we don't use blocking waits. - - - - - aa0a4bbf by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove commented out pragma - - - - - d679b544 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant buffer write in Handle/Text.hs:bufReadEmpty - - - - - d3f94368 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename SmartHandles to StdHandles - - - - - bd6b8ec1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add comment stating failure behaviour for getUniqueFileInfo. - - - - - 12846b85 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update IOPort haddocks. - - - - - 9f39fb14 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Add a note cross reference - - - - - 62dd5a73 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Name Haskell/OS I/O Manager explicitly in Note - - - - - fa807828 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Expand BlockedOnIOCompletion description. - - - - - f0880a1d by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove historical todos - - - - - 8e58e714 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Update note, remove debugging pragma. - - - - - aa4d84d5 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: flushCharReadBuffer shouldn't need to adjust offsets. - - - - - e580893a by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove obsolete comment about cond. variables - - - - - d54e9d79 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix initial linux validate build - - - - - 3cd4de46 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix ThreadDelay001 CPP - - - - - c88b1b9f by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix openFile009 merge conflict leftover - - - - - 849e8889 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept T9681 output. GHC now reports String instead of [Char]. - - - - - e7701818 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix cabal006 after upgrading cabal submodule Demand cabal 2.0 syntax instead of >= 1.20 as required by newer cabal versions. - - - - - a44f0373 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix stderr output for ghci/linking/dyn tests. We used to filter rtsopts, i opted to instead just accept the warning of it having no effect. This works both for -rtsopts, as well as -with-rtsopts which winio adds. - - - - - 515d9896 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T15261b stdout for --io-manager flag. - - - - - 949aaacc by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T5435_dyn_asm stderr The warning about rtsopts having no consequences is expected. So accept new stderr. - - - - - 7d424e1e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Also accept T7037 stderr - - - - - 1f009768 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal04 by filtering rts args - - - - - 981a9f2e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal01 by accepting expected stderr - - - - - b7b0464e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix safePkg01 by accepting expected stderr - - - - - 32734b29 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix T5435_dyn_gcc by accepting expected stderr - - - - - acc5cebf by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix tempfiles test on linux - - - - - c577b789 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for T3807 - - - - - c108c527 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload - - - - - 2b0b9a08 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload_multiple_objs - - - - - 67afb03c by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify wording on conditional variables. - - - - - 3bd41572 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify comment on cooked mode. - - - - - ded58a03 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: update lockfile signature and remove mistaken symbol in rts. - - - - - 2143c492 by Ben Gamari at 2020-07-15T16:41:04-04:00 testsuite: Add winio and winio_threaded ways Reverts many of the testsuite changes - - - - - c0979cc5 by Ben Gamari at 2020-07-16T10:56:54-04:00 Merge remote-tracking branch 'origin/wip/winio' - - - - - 750a1595 by Ben Gamari at 2020-07-18T07:26:41-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. - - - - - 6ba6a881 by Hécate at 2020-07-18T07:26:42-04:00 Implement `fullCompilerVersion` Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403 This MR adds `fullCompilerVersion`, a function that shares the same backend as the `--numeric-version` GHC flag, exposing a full, three-digit version datatype. - - - - - e6cf27df by Hécate at 2020-07-18T07:26:43-04:00 Add a Lint hadrian rule and an .hlint.yaml file in base/ - - - - - bcb177dd by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Allow multiple case branches to have a higher rank type As #18412 points out, it should be OK for multiple case alternatives to have a higher rank type, provided they are all the same. This patch implements that change. It sweeps away GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it with an enhanced version of fillInferResult. The basic change to fillInferResult is to permit the case in which another case alternative has already filled in the result; and in that case simply unify. It's very simple actually. See the new Note [fillInferResult] in TcMType Other refactoring: - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType (previously some of it was in Unify) - Move tcInstType and friends from TcMType to Instantiate, where it more properly belongs. (TCMType was getting very long.) - - - - - e5525a51 by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Improve typechecking of NPlusK patterns This patch (due to Richard Eisenberg) improves documentation of the wrapper returned by tcSubMult (see Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify). And, more substantially, it cleans up the multiplicity handling in the typechecking of NPlusKPat - - - - - 12f90352 by Krzysztof Gogolewski at 2020-07-18T07:26:45-04:00 Remove {-# CORE #-} pragma (part of #18048) This pragma has no effect since 2011. It was introduced for External Core, which no longer exists. Updates haddock submodule. - - - - - e504c913 by Simon Peyton Jones at 2020-07-18T07:26:45-04:00 Refactor the simplification of join binders This MR (for #18449) refactors the Simplifier's treatment of join-point binders. Specifically, it puts together, into GHC.Core.Opt.Simplify.Env.adjustJoinPointType two currently-separate ways in which we adjust the type of a join point. As the comment says: -- (adjustJoinPointType mult new_res_ty join_id) does two things: -- -- 1. Set the return type of the join_id to new_res_ty -- See Note [Return type for join points] -- -- 2. Adjust the multiplicity of arrows in join_id's type, as -- directed by 'mult'. See Note [Scaling join point arguments] I think this actually fixes a latent bug, by ensuring that the seIdSubst and seInScope have the right multiplicity on the type of join points. I did some tidying up while I was at it. No more setJoinResTy, or modifyJoinResTy: instead it's done locally in Simplify.Env.adjustJoinPointType - - - - - 49b265f0 by Chaitanya Koparkar at 2020-07-18T07:26:46-04:00 Fix minor typos in a Core.hs note - - - - - 8d59aed6 by Stefan Schulze Frielinghaus at 2020-07-18T07:26:47-04:00 GHCi: Fix isLittleEndian - - - - - c26e81d1 by Ben Gamari at 2020-07-18T07:26:47-04:00 testsuite: Mark ghci tests as fragile under unreg compiler In particular I have seen T16012 fail repeatedly under the unregisterised compiler. - - - - - 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - a94db475 by Matthew Pickering at 2020-08-07T20:42:39+02:00 rts: Implement ghc-debug API (#18405) There are four components to this patch which make it possible to implement `ghc-debug`. 1. Add four new functions to the RtsAPI. * rts_pause and rts_unpause allow an external process to completely pause and unpause the RTS. * rts_listThreads and rts_listMiscRoots are used to find the current roots of the garbage collector. These changes also mean that `Task.h` is exposed to the user. 2. Generalise the `ghc-heap` API so that raw `Word`s can be returned rather than actual objects. This is necessary when trying to decode closures on an external process because the pointers in such closures are correct for the internal rather than external process. If you used the previous API then you would get a segfault as the garbage collector would try to traverse into these nonsensical branches. ``` -- before getClosureData :: a -> IO Closure -- after getClosureDataX :: (forall c . c -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) ``` For the normal case `b` is instantiated to `Box`, which contains a pointer to a heap object. ``` data Box = Box a -- GenClosure Box ``` For `ghc-debug` we instead just take the word of the address as we have to explicitly interpret it on the external process. ``` GenClosure Word ``` 3. Support for decoding `TSO` and `STACK` closures is partially implemented. There is still quite a bit of work to do to finish both but these at least allow us to make some more progress. 4. findPtr is generalised to take a callback argument. This means that its result can be communicated to the debugger rather than just printing out the result. The debugger has a function which invokes `findPtr` and passes a callback which sends the result over a socket. Co-authored-by: Ben Gamari <ben at smart-cactus.org> - - - - - 529748e0 by Sven Tennie at 2020-08-07T20:42:39+02:00 Decode more StgTSO and StgStack fields (#18405) Use hsc2hs to get an understandable and stable mapping from the C structs to Haskell. It's important to keep StgTSO and StgStack decoding downwards compatible. This is especially needed for hadrian/ghci. - - - - - d6818f95 by Sven Tennie at 2020-08-07T20:42:39+02:00 Add test for StgTSO decoding (#18405) This makes sure ghc-heap decodes StgTSO and StgStack correctly. To assert - otherwise dynamic - properties, a new, non-running TSO is created in create_tso() (create_tso.c). size is renamed to stack_size to use a dedicated type. size was already defined as a HalfWord in GenClosure, which is only equivalent to Word32 on 64bit architectures. - - - - - ec9ac470 by Sven Tennie at 2020-08-07T20:42:39+02:00 Add documentation to ghc-debug functions (#18405) - - - - - 6dadcfbf by Sven Tennie at 2020-08-07T20:42:39+02:00 Adjust type of getClosureX to type of getClosureDataX (#18405) After a rebase the compiler complained: libraries/ghc-heap/GHC/Exts/Heap.hs:89:23: error: • Couldn't match type: a -> IO (Ptr StgInfoTable, [Word], [b]) with: forall c. c -> IO (Ptr StgInfoTable, [Word], [b]) Expected: (forall c. c -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) Actual: (a -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) • In the expression: getClosureX In an equation for ‘getClosureDataX’: getClosureDataX = getClosureX In the instance declaration for ‘HasHeapRep a’ • Relevant bindings include getClosureDataX :: (forall c. c -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) (bound at libraries/ghc-heap/GHC/Exts/Heap.hs:89:5) | 89 | getClosureDataX = getClosureX | ^^^^^^^^^^^ ) - - - - - 7f6c1f68 by Sven Tennie at 2020-08-07T20:42:39+02:00 Add test for rts_pause and rts_unpause (#18405) - - - - - b7ed92ad by Sven Tennie at 2020-08-07T20:42:39+02:00 Add test list_threads_and_misc_roots (#18405) It uses rts_listThreads() and rts_listMiscRoots(). - - - - - bed7bdf7 by Sven Tennie at 2020-08-07T20:42:39+02:00 Introduce rts_isPaused() (#18405) Some operations are only save when the RTS is paused. This predicate helps to make such checks. - - - - - 2caa89e7 by Sven Tennie at 2020-08-07T20:42:39+02:00 Decode CostCentreStacks, CostCentres and InfoTables (#18405) - - - - - 883f8f9c by Sven Tennie at 2020-08-07T20:42:39+02:00 Use cache and loop breakers for CostCentre, CostCentreStack and IndexTable decoding (#18405) - - - - - 653ca4b8 by Sven Tennie at 2020-08-07T20:42:39+02:00 Cleanup - - - - - e5515e8c by Sven Tennie at 2020-08-07T20:42:39+02:00 Query caches once, not twice - - - - - db843dfb by Sven Tennie at 2020-08-07T20:42:39+02:00 Fix Haddock for EndTSOQueue - - - - - 201462ab by Sven Tennie at 2020-08-07T20:42:40+02:00 Run prof_info test only in prof_ways (#18405) That's the required way for collecting PROFILING data (e.g. CostCentres). - - - - - 198ef9dc by Sven Tennie at 2020-08-07T20:42:40+02:00 Skip WIP test (Red on CI) - - - - - 1ff404be by Sven Tennie at 2020-08-07T20:42:40+02:00 Add missing module to ghc-heap.cabal - - - - - 69bf5cb3 by Sven Tennie at 2020-08-07T20:42:40+02:00 Rearrange #ifdef with GHC version This prevents some "unused" warnings. - - - - - c45f50b7 by Sven Tennie at 2020-08-07T20:42:40+02:00 Fix cpp redefinition warnings With --Werror this made the build fail. - - - - - ec554f4c by Sven Tennie at 2020-08-07T20:42:40+02:00 Add dummy import for PeekProfInfo_ProfilingEnabled for non-profiled builds This circumvents #15197. Otherwise PeekProfInfo_ProfilingEnabled wouldn't be available for make-based builds. - - - - - 7ea0717a by Sven Tennie at 2020-08-09T17:24:05+02:00 Add assertions to prof_info test (#18405) - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/test-metrics.sh - CODEOWNERS - Makefile - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - + compiler/GHC/Builtin/RebindableNames.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/ByteCode/Types.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/Graph.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Monad.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2db2bfb3a0d2a0017864e1d4c1491910213bb880...7ea0717a6e3f90ab40715438a9ef85b080156460 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2db2bfb3a0d2a0017864e1d4c1491910213bb880...7ea0717a6e3f90ab40715438a9ef85b080156460 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 9 16:50:50 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Sun, 09 Aug 2020 12:50:50 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] 3 commits: Fix types in tests Message-ID: <5f30296a50ac6_80b3f8486a507f472310d9@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: edc224a6 by Sven Tennie at 2020-08-09T17:53:09+02:00 Fix types in tests Use `Ptr ()` instead of `Word` to communicate that addresses/pointers are meant. - - - - - 8bbec88b by Sven Tennie at 2020-08-09T18:23:39+02:00 Cleanup - - - - - c3aae56d by Sven Tennie at 2020-08-09T18:50:18+02:00 Introduce LiftedClosure This is a representation for closures that do not have a represantation in the Haskell language. I.e. things like TSOs. - - - - - 4 changed files: - libraries/ghc-heap/GHC/Exts/Heap.hs - libraries/ghc-heap/tests/list_threads_and_misc_roots.hs - libraries/ghc-heap/tests/prof_info.hs - libraries/ghc-heap/tests/tso_and_stack_closures.hs Changes: ===================================== libraries/ghc-heap/GHC/Exts/Heap.hs ===================================== @@ -24,6 +24,7 @@ values, i.e. to investigate sharing and lazy evaluation. module GHC.Exts.Heap ( -- * Closure types Closure + , LiftedClosure , GenClosure(..) , ClosureType(..) , PrimType(..) @@ -90,6 +91,12 @@ import Foreign foreign import ccall "isEndTsoQueue" isEndTsoQueue_c :: Addr# -> Bool +-- | Some closures (e.g.TSOs) don't have corresponding types to represent them in Haskell. +-- So when we have a pointer to such closure that we want to inspect, we `unsafeCoerce` it +-- into the following `LiftedClosure` lifted type (could be any lifted type) so that the +-- appropriate `instance HasHeapRep (a :: TYPE 'LiftedRep)` is used to decode the closure. +data LiftedClosure + class HasHeapRep (a :: TYPE rep) where -- | Decode a closure to it's heap representation ('GenClosure'). @@ -97,8 +104,7 @@ class HasHeapRep (a :: TYPE rep) where -- containing a thunk or an evaluated heap object. Outside it can be a -- 'Word' for "raw" usage of pointers. --- TODO: Remove Show constraint - getClosureDataX :: Show b => + getClosureDataX :: (forall c . c -> IO (Ptr StgInfoTable, [Word], [b])) -- ^ Helper function to get info table, memory and pointers of the -- closure. The order of @[b]@ is significant and determined by @@ -188,8 +194,7 @@ getClosureData = getClosureDataX getClosureRaw -- -- For most use cases 'getClosureData' is an easier to use alternative. --- TODO: Remove Show constraint -getClosureX :: forall a b. Show b => +getClosureX :: forall a b. (forall c . c -> IO (Ptr StgInfoTable, [Word], [b])) -- ^ Helper function to get info table, memory and pointers of the -- closure @@ -347,10 +352,6 @@ getClosureX get_closure_raw x = do allocaArray (length wds) (\ptr -> do pokeArray ptr wds --- TODO: remove prints - print $ "tso ptr : " ++ show ptr - print $ "tso pts : " ++ show pts - print $ "tso info table : " ++ show itbl -- TODO: Does this work? I.e. do we emit EndTSOQueues? if isEndTsoQueue_c (unpackPtr ptr) then pure $ EndTSOQueue { info = itbl } ===================================== libraries/ghc-heap/tests/list_threads_and_misc_roots.hs ===================================== @@ -7,12 +7,6 @@ import Control.Concurrent import GHC.Exts.Heap import GHC.Exts - --- Invent a type to bypass the type constraints of getClosureData. --- Infact this will be a Word#, that is directly given to unpackClosure# --- (which is a primop that expects a pointer to a closure). -data FoolClosure - foreign import ccall safe "list_threads_and_misc_roots_c.h listThreadsAndMiscRoots" listThreadsAndMiscRoots_c :: IO () @@ -20,13 +14,13 @@ foreign import ccall safe "list_threads_and_misc_roots_c.h getTSOCount" getTSOCount_c :: IO Int foreign import ccall safe "list_threads_and_misc_roots_c.h getTSOs" - getTSOs_c :: IO (Ptr Word) + getTSOs_c :: IO (Ptr (Ptr ())) foreign import ccall safe "list_threads_and_misc_roots_c.h getMiscRootsCount" getMiscRootsCount_c :: IO Int foreign import ccall safe "list_threads_and_misc_roots_c.h getMiscRoots" - getMiscRoots_c :: IO (Ptr Word) + getMiscRoots_c :: IO (Ptr (Ptr ())) main :: IO () main = do @@ -50,13 +44,13 @@ main = do return () -createClosure :: Word -> IO (GenClosure Box) +createClosure :: Ptr () -> IO (GenClosure Box) createClosure tsoPtr = do - let wPtr = unpackWord# tsoPtr - getClosureData ((unsafeCoerce# wPtr) :: FoolClosure) + let addr = unpackAddr# tsoPtr + getClosureData ((unsafeCoerce# addr) :: LiftedClosure) -unpackWord# :: Word -> Word# -unpackWord# (W# w#) = w# +unpackAddr# :: Ptr () -> Addr# +unpackAddr# (Ptr addr) = addr assertEqual :: (Show a, Eq a) => a -> a -> IO () assertEqual a b ===================================== libraries/ghc-heap/tests/prof_info.hs ===================================== @@ -14,18 +14,13 @@ import Data.List (find) #include "rts/Constants.h" foreign import ccall unsafe "create_tso.h create_tso" - c_create_tso:: IO Word - --- Invent a type to bypass the type constraints of getClosureData. --- Infact this will be a Word#, that is directly given to unpackClosure# --- (which is a primop that expects a pointer to a closure). -data FoolStgTSO + c_create_tso:: IO (Ptr ()) createTSOClosure :: IO (GenClosure Box) createTSOClosure = do ptr <- {-# SCC "MyCostCentre" #-} c_create_tso - let wPtr = unpackWord# ptr - getClosureData ((unsafeCoerce# wPtr) :: FoolStgTSO) + let addr = unpackAddr# ptr + getClosureData ((unsafeCoerce# addr) :: LiftedClosure) -- We can make some assumptions about the - otherwise dynamic - properties of -- StgTSO and StgStack, because a new, non-running TSO is created with @@ -50,8 +45,8 @@ main = do assertEqual (cc_link myCostCentre) Nothing Nothing -> error "MyCostCentre not found!" -unpackWord# :: Word -> Word# -unpackWord# (W# w#) = w# +unpackAddr# :: Ptr () -> Addr# +unpackAddr# (Ptr addr) = addr linkedCostCentres :: Maybe CostCentre -> [CostCentre] linkedCostCentres Nothing = [] ===================================== libraries/ghc-heap/tests/tso_and_stack_closures.hs ===================================== @@ -11,12 +11,7 @@ import GHC.Word #include "rts/Constants.h" foreign import ccall unsafe "create_tso.h create_tso" - c_create_tso:: IO Word - --- Invent a type to bypass the type constraints of getClosureData. --- Infact this will be a Word#, that is directly given to unpackClosure# --- (which is a primop that expects a pointer to a closure). -data FoolStgTSO + c_create_tso:: IO (Ptr ()) -- We can make some assumptions about the - otherwise dynamic - properties of -- StgTSO and StgStack, because a new, non-running TSO is created with @@ -60,11 +55,11 @@ main = do createTSOClosure :: IO (GenClosure Box) createTSOClosure = do ptr <- c_create_tso - let wPtr = unpackWord# ptr - getClosureData ((unsafeCoerce# wPtr) :: FoolStgTSO) + let addr = unpackAddr# ptr + getClosureData ((unsafeCoerce# addr) :: LiftedClosure) -unpackWord# :: Word -> Word# -unpackWord# (W# w#) = w# +unpackAddr# :: Ptr () -> Addr# +unpackAddr# (Ptr addr) = addr assertEqual :: (Show a, Eq a) => a -> a -> IO () assertEqual a b View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7ea0717a6e3f90ab40715438a9ef85b080156460...c3aae56da68ed36bd043ee1840c582492ccc3ae0 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7ea0717a6e3f90ab40715438a9ef85b080156460...c3aae56da68ed36bd043ee1840c582492ccc3ae0 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 9 19:22:10 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 09 Aug 2020 15:22:10 -0400 Subject: [Git][ghc/ghc][ghc-8.10] 2 commits: Set RELEASE=NO Message-ID: <5f304ce211073_80b3f846910c0c0724991b@gitlab.haskell.org.mail> Ben Gamari pushed to branch ghc-8.10 at Glasgow Haskell Compiler / GHC Commits: 430e69ec by Ben Gamari at 2020-08-09T14:26:14-04:00 Set RELEASE=NO - - - - - fac083e7 by Ben Gamari at 2020-08-09T14:26:14-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit aa2e5863699306920513b216f337de09e29b5bb8. - - - - - 2 changed files: - configure.ac - rts/RtsSymbols.c Changes: ===================================== configure.ac ===================================== @@ -16,7 +16,7 @@ dnl AC_INIT([The Glorious Glasgow Haskell Compilation System], [8.10.2], [glasgow-haskell-bugs at haskell.org], [ghc-AC_PACKAGE_VERSION]) # Set this to YES for a released version, otherwise NO -: ${RELEASE=YES} +: ${RELEASE=NO} # The primary version (e.g. 7.5, 7.4.1) is set in the AC_INIT line # above. If this is not a released version, then we will append the ===================================== rts/RtsSymbols.c ===================================== @@ -58,6 +58,7 @@ SymI_HasProto(signal_handlers) \ SymI_HasProto(stg_sig_install) \ SymI_HasProto(rtsTimerSignal) \ + SymI_HasProto(atexit) \ SymI_NeedsDataProto(nocldstop) #endif @@ -976,213 +977,29 @@ RTS_USER_SIGNALS_SYMBOLS \ RTS_INTCHAR_SYMBOLS + // 64-bit support functions in libgcc.a -// See https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc -#define RTS_LIBGCC_SYMBOLS_32 \ - SymI_NeedsProto(__fixunsdfdi) \ - /* 4 The GCC low-level runtime library */\ - /* 4.1.1 Arithmetic functions */\ - /* SymI_NeedsProto(__ashlsi3) */\ - SymI_NeedsProto(__ashldi3) \ - /* SymI_NeedsProto(__ashlti3) */\ - /* These functions return the result of shifting a left by b bits. */\ - /* SymI_NeedsProto(__ashrsi3) */\ - SymI_NeedsProto(__ashrdi3) \ - /* SymI_NeedsProto(__ashrti3) */\ - /* These functions return the result of arithmetically shifting a right by b bits. */\ - /* SymI_NeedsProto(__divsi3) */\ - SymI_NeedsProto(__divdi3) \ - /* SymI_NeedsProto(__divti3) */\ - /* These functions return the quotient of the signed division of a and b. */\ - /* SymI_NeedsProto(__lshrsi3) */ \ - SymI_NeedsProto(__lshrdi3) \ - /* SymI_NeedsProto(__lshrti3) */ \ - /* These functions return the result of logically shifting a right by b bits. */\ - /* SymI_NeedsProto(__modsi3) */ \ - SymI_NeedsProto(__moddi3) \ - /* SymI_NeedsProto(__modti3) */ \ - /* These functions return the remainder of the signed division of a and b. */\ - /* SymI_NeedsProto(__mulsi3) */ \ - SymI_NeedsProto(__muldi3) \ - /* SymI_NeedsProto(__multi3) */ \ - /* These functions return the product of a and b. */\ - SymI_NeedsProto(__negdi2) \ - /* SymI_NeedsProto(__negti2) */ \ - /* These functions return the negation of a. */\ - /* SymI_NeedsProto(__udivsi3) */ \ - SymI_NeedsProto(__udivdi3) \ - /* SymI_NeedsProto(__udivti3) */ \ - /* These functions return the quotient of the unsigned division of a and b. */\ - SymI_NeedsProto(__udivmoddi4) \ - /* SymI_NeedsProto(__udivmodti4) */ \ - /* These functions calculate both the quotient and remainder of the unsigned division of a and b. The return value is the quotient, and the remainder is placed in variable pointed to by c. */\ - /* SymI_NeedsProto(__umodsi3) */ \ - SymI_NeedsProto(__umoddi3) \ - /* SymI_NeedsProto(__umodti3) */ \ - /* These functions return the remainder of the unsigned division of a and b. */\ - /* 4.1.2 Comparison functions */\ - /* The following functions implement integral comparisons. These functions implement a low-level compare, upon which the higher level comparison operators (such as less than and greater than or equal to) can be constructed. The returned values lie in the range zero to two, to allow the high-level operators to be implemented by testing the returned result using either signed or unsigned comparison. */\ - SymI_NeedsProto(__cmpdi2) \ - /* SymI_NeedsProto(__cmpti2) */ \ - /* These functions perform a signed comparison of a and b. If a is less than b, they return 0; if a is greater than b, they return 2; and if a and b are equal they return 1. */\ - SymI_NeedsProto(__ucmpdi2) \ - /* SymI_NeedsProto(__ucmpti2) */ \ - /* These functions perform an unsigned comparison of a and b. If a is less than b, they return 0; if a is greater than b, they return 2; and if a and b are equal they return 1. */\ - /* 4.1.3 Trapping arithmetic functions */\ - /* The following functions implement trapping arithmetic. These functions call the libc function abort upon signed arithmetic overflow. */\ - SymI_NeedsProto(__absvsi2) \ - SymI_NeedsProto(__absvdi2) \ - /* These functions return the absolute value of a. */\ - /* SymI_NeedsProto(__addvsi3) */ \ - SymI_NeedsProto(__addvdi3) \ - /* These functions return the sum of a and b; that is a + b. */\ - /* SymI_NeedsProto(__mulvsi3) */ \ - SymI_NeedsProto(__mulvdi3) \ - /* The functions return the product of a and b; that is a * b. */\ - SymI_NeedsProto(__negvsi2) \ - SymI_NeedsProto(__negvdi2) \ - /* These functions return the negation of a; that is -a. */\ - /* SymI_NeedsProto(__subvsi3) */ \ - SymI_NeedsProto(__subvdi3) \ - /* These functions return the difference between b and a; that is a - b. */\ - /* 4.1.4 Bit operations */\ - SymI_NeedsProto(__clzsi2) \ - SymI_NeedsProto(__clzdi2) \ - /* SymI_NeedsProto(__clzti2) */ \ - /* These functions return the number of leading 0-bits in a, starting at the most significant bit position. If a is zero, the result is undefined. */\ - SymI_NeedsProto(__ctzsi2) \ - SymI_NeedsProto(__ctzdi2) \ - /* SymI_NeedsProto(__ctzti2) */ \ - /* These functions return the number of trailing 0-bits in a, starting at the least significant bit position. If a is zero, the result is undefined. */\ - SymI_NeedsProto(__ffsdi2) \ - /* SymI_NeedsProto(__ffsti2) */ \ - /* These functions return the index of the least significant 1-bit in a, or the value zero if a is zero. The least significant bit is index one. */\ - SymI_NeedsProto(__paritysi2) \ - SymI_NeedsProto(__paritydi2) \ - /* SymI_NeedsProto(__parityti2) */\ - /* These functions return the value zero if the number of bits set in a is even, and the value one otherwise. */\ - SymI_NeedsProto(__popcountsi2) \ - SymI_NeedsProto(__popcountdi2) \ - /* SymI_NeedsProto(__popcountti2) */ \ - /* These functions return the number of bits set in a. */\ - SymI_NeedsProto(__bswapsi2) \ - SymI_NeedsProto(__bswapdi2) -#define RTS_LIBGCC_SYMBOLS_aarch32 \ - /* armv6l */\ - /* TODO: should check for __ARM_EABI__ */\ - SymI_NeedsProto(__aeabi_d2f) \ - SymI_NeedsProto(__aeabi_d2iz) \ - SymI_NeedsProto(__aeabi_d2lz) \ - SymI_NeedsProto(__aeabi_d2uiz) \ - SymI_NeedsProto(__aeabi_d2ulz) \ - SymI_NeedsProto(__aeabi_dadd) \ - SymI_NeedsProto(__aeabi_dcmpeq) \ - SymI_NeedsProto(__aeabi_dcmpge) \ - SymI_NeedsProto(__aeabi_dcmpgt) \ - SymI_NeedsProto(__aeabi_dcmple) \ - SymI_NeedsProto(__aeabi_dcmplt) \ - SymI_NeedsProto(__aeabi_dcmpun) \ - SymI_NeedsProto(__aeabi_ddiv) \ - SymI_NeedsProto(__aeabi_dmul) \ - SymI_NeedsProto(__aeabi_dneg) \ - SymI_NeedsProto(__aeabi_dsub) \ - SymI_NeedsProto(__aeabi_f2d) \ - SymI_NeedsProto(__aeabi_f2iz) \ - SymI_NeedsProto(__aeabi_f2lz) \ - SymI_NeedsProto(__aeabi_f2uiz) \ - SymI_NeedsProto(__aeabi_f2ulz) \ - SymI_NeedsProto(__aeabi_fadd) \ - SymI_NeedsProto(__aeabi_fcmpeq) \ - SymI_NeedsProto(__aeabi_fcmpge) \ - SymI_NeedsProto(__aeabi_fcmpgt) \ - SymI_NeedsProto(__aeabi_fcmple) \ - SymI_NeedsProto(__aeabi_fcmplt) \ - SymI_NeedsProto(__aeabi_fcmpun) \ - SymI_NeedsProto(__aeabi_fdiv) \ - SymI_NeedsProto(__aeabi_fmul) \ - SymI_NeedsProto(__aeabi_fneg) \ - SymI_NeedsProto(__aeabi_fsub) \ - SymI_NeedsProto(__aeabi_i2d) \ - SymI_NeedsProto(__aeabi_i2f) \ - SymI_NeedsProto(__aeabi_idiv) \ - SymI_NeedsProto(__aeabi_idivmod) \ - SymI_NeedsProto(__aeabi_l2d) \ - SymI_NeedsProto(__aeabi_l2f) \ - SymI_NeedsProto(__aeabi_lasr) \ - SymI_NeedsProto(__aeabi_lcmp) \ - SymI_NeedsProto(__aeabi_ldivmod) \ - SymI_NeedsProto(__aeabi_llsl) \ - SymI_NeedsProto(__aeabi_llsr) \ - SymI_NeedsProto(__aeabi_lmul) \ - SymI_NeedsProto(__aeabi_ui2d) \ - SymI_NeedsProto(__aeabi_ui2f) \ - SymI_NeedsProto(__aeabi_uidiv) \ - SymI_NeedsProto(__aeabi_uidivmod) \ - SymI_NeedsProto(__aeabi_ul2d) \ - SymI_NeedsProto(__aeabi_ul2f) \ - SymI_NeedsProto(__aeabi_ulcmp) \ - SymI_NeedsProto(__aeabi_uldivmod) -#define RTS_LIBGCC_SYMBOLS_64 \ +#if defined(__GNUC__) && SIZEOF_VOID_P <= 4 && !defined(_ABIN32) +#define RTS_LIBGCC_SYMBOLS \ + SymI_NeedsProto(__divdi3) \ + SymI_NeedsProto(__udivdi3) \ + SymI_NeedsProto(__moddi3) \ + SymI_NeedsProto(__umoddi3) \ + SymI_NeedsProto(__muldi3) \ + SymI_NeedsProto(__ashldi3) \ + SymI_NeedsProto(__ashrdi3) \ + SymI_NeedsProto(__lshrdi3) \ + SymI_NeedsProto(__fixunsdfdi) +#elif defined(__GNUC__) && SIZEOF_VOID_P == 8 +#define RTS_LIBGCC_SYMBOLS \ SymI_NeedsProto(__udivti3) \ SymI_NeedsProto(__umodti3) - -/* for aarch64 */ -#define RTS_LIBGCC_SYMBOLS_aarch64 \ - SymI_NeedsProto(__netf2) \ - SymI_NeedsProto(__addtf3) \ - SymI_NeedsProto(__subtf3) \ - SymI_NeedsProto(__multf3) \ - SymI_NeedsProto(__extenddftf2) \ - SymI_NeedsProto(__fixtfsi) \ - SymI_NeedsProto(__fixunstfsi) \ - SymI_NeedsProto(__floatsitf) \ - SymI_NeedsProto(__floatunsitf) - -#if defined(__GNUC__) && SIZEOF_VOID_P <= 4 && defined(arm_HOST_OS) -#define RTS_LIBGCC_SYMBOLS RTS_LIBGCC_SYMBOLS_32 RTS_LIBGCC_SYMBOLS_aarch32 -#elif defined(__GNUC__) && SIZEOF_VOID_P <= 4 && !defined(_ABIN32) -#define RTS_LIBGCC_SYMBOLS RTS_LIBGCC_SYMBOLS_32 -#elif defined(__GNUC__) && SIZEOF_VOID_P == 8 && defined(aarch64_HOST_OS) -#define RTS_LIBGCC_SYMBOLS RTS_LIBGCC_SYMBOLS_64 RTS_LIBGCC_SYMBOLS_aarch64 -#elif defined(__GNUC__) && SIZEOF_VOID_P == 8 -#define RTS_LIBGCC_SYMBOLS RTS_LIBGCC_SYMBOLS_64 #else #define RTS_LIBGCC_SYMBOLS #endif -#if !defined(mingw32_HOST_OS) && !defined(DYNAMIC) && (defined(_FORTIFY_SOURCE) || defined(__SSP__)) -#define RTS_SSP_SYMBOLS \ - SymI_NeedsProto(__stack_chk_guard) \ - SymI_NeedsProto(__stack_chk_fail) -#else -#define RTS_SSP_SYMBOLS -#endif -#if !defined(DYNAMIC) && defined(linux_HOST_OS) -// we need these for static musl builds. However when -// linking shared objects (DLLs) this will fail, hence -// we do not include them when building with -DDYNAMIC -#define RTS_LINKER_SYMBOLS \ - SymI_NeedsProto(__fini_array_start) \ - SymI_NeedsProto(__fini_array_end) -#else -#define RTS_LINKER_SYMBOLS -#endif - -#if defined(darwin_HOST_OS) && defined(powerpc_HOST_ARCH) - // Symbols that don't have a leading underscore - // on Mac OS X. They have to receive special treatment, - // see machoInitSymbolsWithoutUnderscore() -#define RTS_MACHO_NOUNDERLINE_SYMBOLS \ - SymI_NeedsProto(saveFP) \ - SymI_NeedsProto(restFP) -#endif - /* entirely bogus claims about types of these symbols */ -/* to prevent a bit of define expansion, SymI_NeedsProto is a variadic - * macro. And we'll concat vvv with the __VA_ARGS__. This prevents - * vvv from getting macro expanded. - */ -#define SymI_NeedsProto(vvv,...) extern void vvv ## __VA_ARGS__ (void); +#define SymI_NeedsProto(vvv) extern void vvv(void); #define SymI_NeedsDataProto(vvv) extern StgWord vvv[]; #if defined(COMPILING_WINDOWS_DLL) #define SymE_HasProto(vvv) SymE_HasProto(vvv); @@ -1209,8 +1026,6 @@ RTS_DARWIN_ONLY_SYMBOLS RTS_OPENBSD_ONLY_SYMBOLS RTS_LIBGCC_SYMBOLS RTS_LIBFFI_SYMBOLS -RTS_SSP_SYMBOLS -RTS_LINKER_SYMBOLS #undef SymI_NeedsProto #undef SymI_NeedsDataProto #undef SymI_HasProto @@ -1230,7 +1045,7 @@ RTS_LINKER_SYMBOLS #define SymE_HasDataProto(vvv) \ SymE_HasProto(vvv) -#define SymI_NeedsProto(vvv,...) SymI_HasProto(vvv ## __VA_ARGS__) +#define SymI_NeedsProto(vvv) SymI_HasProto(vvv) #define SymI_NeedsDataProto(vvv) SymI_HasDataProto(vvv) #define SymE_NeedsProto(vvv) SymE_HasProto(vvv) #define SymE_NeedsDataProto(vvv) SymE_HasDataProto(vvv) @@ -1251,8 +1066,6 @@ RTS_LINKER_SYMBOLS #define SymI_HasProto_deprecated(vvv) \ { #vvv, (void*)0xBAADF00D, true }, -void *RTS_DYNAMIC = NULL; - RtsSymbolVal rtsSyms[] = { RTS_SYMBOLS RTS_RET_SYMBOLS @@ -1264,14 +1077,11 @@ RtsSymbolVal rtsSyms[] = { RTS_LIBGCC_SYMBOLS RTS_LIBFFI_SYMBOLS SymI_HasDataProto(nonmoving_write_barrier_enabled) - RTS_SSP_SYMBOLS - RTS_LINKER_SYMBOLS #if defined(darwin_HOST_OS) && defined(i386_HOST_ARCH) // dyld stub code contains references to this, // but it should never be called because we treat // lazy pointers as nonlazy. { "dyld_stub_binding_helper", (void*)0xDEADBEEF, false }, #endif - { "_DYNAMIC", (void*)(&RTS_DYNAMIC), false }, { 0, 0, false } /* sentinel */ }; View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/29204b1c4f52ea34d84da33593052ee839293bf2...fac083e7ac8a37b61a4082bbbca2848e52fd1bb2 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/29204b1c4f52ea34d84da33593052ee839293bf2...fac083e7ac8a37b61a4082bbbca2848e52fd1bb2 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 9 19:37:18 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sun, 09 Aug 2020 15:37:18 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 5 commits: ApiAnnotations; tweaks for ghc-exactprint update Message-ID: <5f30506e2ae5f_80b3f848a386fc872506c2@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - 95f1478b by Alan Zimmerman at 2020-08-09T15:37:09-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 090ca604 by Sylvain Henry at 2020-08-09T15:37:13-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 10 changed files: - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Annotation.hs - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Utils/Misc.hs - hadrian/src/Builder.hs - testsuite/tests/ghc-api/annotations/Makefile - testsuite/tests/ghc-api/annotations/T10358.stdout - utils/check-api-annotations/Main.hs Changes: ===================================== aclocal.m4 ===================================== @@ -2543,7 +2543,7 @@ AC_DEFUN([FIND_LD],[ # Sets $result to 0 if not affected, 1 otherwise AC_DEFUN([CHECK_FOR_GOLD_T22266],[ AC_MSG_CHECKING([for ld.gold object merging bug (binutils 22266)]) - if ! $1 --version | grep -v -q "GNU gold"; then + if ! $1 --version | grep -q "GNU gold"; then # Not gold result=0 elif test "$cross_compiling" = "yes"; then ===================================== compiler/GHC.hs ===================================== @@ -248,7 +248,7 @@ module GHC ( srcSpanStartCol, srcSpanEndCol, -- ** Located - GenLocated(..), Located, + GenLocated(..), Located, RealLocated, -- *** Constructing Located noLoc, mkGeneralLocated, @@ -274,7 +274,7 @@ module GHC ( parser, -- * API Annotations - ApiAnns(..),AnnKeywordId(..),AnnotationComment(..), + ApiAnns(..),AnnKeywordId(..),AnnotationComment(..), ApiAnnKey, getAnnotation, getAndRemoveAnnotation, getAnnotationComments, getAndRemoveAnnotationComments, unicodeAnn, ===================================== compiler/GHC/Parser.y ===================================== @@ -863,17 +863,17 @@ header_top_importdecls :: { [LImportDecl GhcPs] } -- The Export List maybeexports :: { (Maybe (Located [LIE GhcPs])) } - : '(' exportlist ')' {% amsL (comb2 $1 $>) [mop $1,mcp $3] >> - return (Just (sLL $1 $> (fromOL $2))) } + : '(' exportlist ')' {% amsL (comb2 $1 $>) ([mop $1,mcp $3] ++ (fst $2)) >> + return (Just (sLL $1 $> (fromOL $ snd $2))) } | {- empty -} { Nothing } -exportlist :: { OrdList (LIE GhcPs) } - : exportlist1 { $1 } - | {- empty -} { nilOL } +exportlist :: { ([AddAnn], OrdList (LIE GhcPs)) } + : exportlist1 { ([], $1) } + | {- empty -} { ([], nilOL) } -- trailing comma: - | exportlist1 ',' { $1 } - | ',' { nilOL } + | exportlist1 ',' { ([mj AnnComma $2], $1) } + | ',' { ([mj AnnComma $1], nilOL) } exportlist1 :: { OrdList (LIE GhcPs) } : exportlist1 ',' export @@ -1019,11 +1019,11 @@ maybeimpspec :: { Located (Maybe (Bool, Located [LIE GhcPs])) } impspec :: { Located (Bool, Located [LIE GhcPs]) } : '(' exportlist ')' {% ams (sLL $1 $> (False, - sLL $1 $> $ fromOL $2)) - [mop $1,mcp $3] } + sLL $1 $> $ fromOL (snd $2))) + ([mop $1,mcp $3] ++ (fst $2)) } | 'hiding' '(' exportlist ')' {% ams (sLL $1 $> (True, - sLL $1 $> $ fromOL $3)) - [mj AnnHiding $1,mop $2,mcp $4] } + sLL $1 $> $ fromOL (snd $3))) + ([mj AnnHiding $1,mop $2,mcp $4] ++ (fst $3)) } ----------------------------------------------------------------------------- -- Fixity Declarations ===================================== compiler/GHC/Parser/Annotation.hs ===================================== @@ -259,6 +259,8 @@ data AnnKeywordId | AnnLarrow -- ^ '<-' | AnnLarrowU -- ^ '<-', unicode variant | AnnLet + | AnnLolly -- ^ '#->' + | AnnLollyU -- ^ '#->', unicode variant | AnnMdo | AnnMinus -- ^ '-' | AnnModule @@ -291,8 +293,6 @@ data AnnKeywordId | AnnStatic -- ^ 'static' | AnnStock | AnnThen - | AnnThIdSplice -- ^ '$' - | AnnThIdTySplice -- ^ '$$' | AnnThTyQuote -- ^ double ''' | AnnTilde -- ^ '~' | AnnType @@ -364,6 +364,7 @@ unicodeAnn AnnOpenB = AnnOpenBU unicodeAnn AnnCloseB = AnnCloseBU unicodeAnn AnnOpenEQ = AnnOpenEQU unicodeAnn AnnCloseQ = AnnCloseQU +unicodeAnn AnnLolly = AnnLollyU unicodeAnn ann = ann ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -1201,13 +1201,14 @@ makeFunBind fn ms checkPatBind :: LPat GhcPs -> Located (a,GRHSs GhcPs (LHsExpr GhcPs)) -> P ([AddAnn],HsBind GhcPs) -checkPatBind lhs (L match_span (_,grhss)) +checkPatBind lhs (L rhs_span (_,grhss)) | BangPat _ p <- unLoc lhs , VarPat _ v <- unLoc p = return ([], makeFunBind v [L match_span (m v)]) where + match_span = combineSrcSpans (getLoc lhs) rhs_span m v = Match { m_ext = noExtField - , m_ctxt = FunRhs { mc_fun = L (getLoc lhs) (unLoc v) + , m_ctxt = FunRhs { mc_fun = v , mc_fixity = Prefix , mc_strictness = SrcStrict } , m_pats = [] ===================================== compiler/GHC/Utils/Misc.hs ===================================== @@ -774,12 +774,15 @@ dropList _ xs@[] = xs dropList (_:xs) (_:ys) = dropList xs ys +-- | Given two lists xs=x0..xn and ys=y0..ym, return `splitAt n ys`. splitAtList :: [b] -> [a] -> ([a], [a]) -splitAtList [] xs = ([], xs) -splitAtList _ xs@[] = (xs, xs) -splitAtList (_:xs) (y:ys) = (y:ys', ys'') - where - (ys', ys'') = splitAtList xs ys +splitAtList xs ys = go 0 xs ys + where + -- we are careful to avoid allocating when there are no leftover + -- arguments: in this case we can return "ys" directly (cf #18535) + go _ _ [] = (ys, []) -- len(ys) <= len(xs) + go n [] bs = (take n ys, bs) -- = splitAt n ys + go n (_:as) (_:bs) = go (n+1) as bs -- drop from the end of a list dropTail :: Int -> [a] -> [a] ===================================== hadrian/src/Builder.hs ===================================== @@ -30,6 +30,7 @@ import Hadrian.Utilities import Base import Context import Oracles.Flag +import Oracles.Setting (setting, Setting(..)) import Packages -- | C compiler can be used in two different modes: @@ -180,7 +181,11 @@ instance H.Builder Builder where Autoreconf dir -> return [dir -/- "configure.ac"] Configure dir -> return [dir -/- "configure"] - Ghc _ Stage0 -> includesDependencies Stage0 + Ghc _ Stage0 -> do + -- Read the boot GHC version here to make sure we rebuild when it + -- changes (#18001). + _bootGhcVersion <- setting GhcVersion + includesDependencies Stage0 Ghc _ stage -> do root <- buildRoot touchyPath <- programPath (vanillaContext Stage0 touchy) ===================================== testsuite/tests/ghc-api/annotations/Makefile ===================================== @@ -39,7 +39,8 @@ listcomps: .PHONY: T10358 T10358: - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358.hs + # Ignore result code, we have an unattached (superfluous) AnnBang + - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358.hs .PHONY: T10396 T10396: ===================================== testsuite/tests/ghc-api/annotations/T10358.stdout ===================================== @@ -1,5 +1,5 @@ ---Unattached Annotation Problems (should be empty list)--- -[] +[(AnnBang, Test10358.hs:5:19)] ---Ann before enclosing span problem (should be empty list)--- [ ===================================== utils/check-api-annotations/Main.hs ===================================== @@ -5,7 +5,6 @@ import Data.List import GHC import GHC.Driver.Session import GHC.Utils.Outputable -import GHC.Parser.Annotation import GHC.Types.SrcLoc import System.Environment( getArgs ) import System.Exit View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/15932b2a8d418a5e6b13acd4fc20e34fde9844df...090ca60400e8ecdcc4b35b28cf60d662b760a714 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/15932b2a8d418a5e6b13acd4fc20e34fde9844df...090ca60400e8ecdcc4b35b28cf60d662b760a714 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 9 20:01:32 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 09 Aug 2020 16:01:32 -0400 Subject: [Git][ghc/ghc][wip/unloading] Add loadNativeObj and unloadNativeObj Message-ID: <5f30561c31f93_80b3f849c1caa107259514@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/unloading at Glasgow Haskell Compiler / GHC Commits: 2cfcbcfa by Ray Shih at 2020-08-09T16:01:21-04:00 Add loadNativeObj and unloadNativeObj Summary: (This change is originally written by niteria) This adds two functions: * `loadNativeObj` * `unloadNativeObj` and implements them for Linux. They are useful if you want to load a shared object with Haskell code using the system linker and have GHC call dlclose() after the code is no longer referenced from the heap. Using the system linker allows you to load the shared object above outside the lowmem region. It also loads the DWARF sections in a way that `perf` understands. `dl_iterate_phdr` is what makes this implementation Linux specific. NOTE: this should be replaceable by whatever D4263 becomes Test Plan: manual testing Reviewers: simonmar, Phyx, bgamari, erikd Reviewed By: niteria Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4263 - - - - - 11 changed files: - includes/rts/Linker.h - includes/rts/storage/GC.h - rts/CheckUnload.c - rts/Linker.c - rts/LinkerInternals.h - rts/linker/LoadArchive.c - rts/sm/Storage.c - testsuite/tests/rts/linker/Makefile - testsuite/tests/rts/linker/all.T - + testsuite/tests/rts/linker/linker_unload_native.c - + testsuite/tests/rts/linker/linker_unload_native.stdout Changes: ===================================== includes/rts/Linker.h ===================================== @@ -76,6 +76,19 @@ HsInt loadArchive( pathchar *path ); /* resolve all the currently unlinked objects in memory */ HsInt resolveObjs( void ); +/* Load an .so using the system linker. + Returns a handle that can be passed to dlsym() or NULL on error. + + In the case of error, stores the error message in errmsg. The caller + is responsible for freeing it. */ +void *loadNativeObj( pathchar *path, char **errmsg ); + +/* Mark the .so loaded with the system linker for unloading. + The RTS will unload it when all the references to the .so disappear from + the heap. + Takes the handle returned from loadNativeObj() as an argument. */ +HsInt unloadNativeObj( void *handle ); + /* load a dynamic library */ const char *addDLL( pathchar* dll_name ); ===================================== includes/rts/storage/GC.h ===================================== @@ -230,6 +230,10 @@ void revertCAFs (void); // (preferably use RtsConfig.keep_cafs instead) void setKeepCAFs (void); +// Let the runtime know that all the CAFs in high mem are not +// to be retained. Useful in conjunction with loadNativeObj +void setHighMemDynamic (void); + /* ----------------------------------------------------------------------------- This is the write barrier for MUT_VARs, a.k.a. IORefs. A MUT_VAR_CLEAN object is not on the mutable list; a MUT_VAR_DIRTY ===================================== rts/CheckUnload.c ===================================== @@ -238,21 +238,45 @@ static void reserveOCSectionIndices(OCSectionIndices *s_indices, int len) // state. void insertOCSectionIndices(ObjectCode *oc) { - reserveOCSectionIndices(global_s_indices, oc->n_sections); + // after we finish the section table will no longer be sorted. global_s_indices->sorted = false; - int s_i = global_s_indices->n_sections; - for (int i = 0; i < oc->n_sections; i++) { - if (oc->sections[i].kind != SECTIONKIND_OTHER) { - global_s_indices->indices[s_i].start = (W_)oc->sections[i].start; - global_s_indices->indices[s_i].end = (W_)oc->sections[i].start - + oc->sections[i].size; - global_s_indices->indices[s_i].oc = oc; + if (oc->type == DYNAMIC_OBJECT) { + // First count the ranges + int n_ranges = 0; + for (NativeCodeRange *ncr = oc->nc_ranges; ncr != NULL; ncr = ncr->next) { + n_ranges++; + } + + // Next reserve the appropriate number of table entries... + reserveOCSectionIndices(global_s_indices, n_ranges); + + // Now insert the new ranges... + int s_i = global_s_indices->n_sections; + for (NativeCodeRange *ncr = oc->nc_ranges; ncr != NULL; ncr = ncr->next) { + OCSectionIndex *ent = &global_s_indices->indices[s_i]; + ent->start = (W_)ncr->start; + ent->end = (W_)ncr->end; + ent->oc = oc; s_i++; } - } - global_s_indices->n_sections = s_i; + global_s_indices->n_sections = s_i; + } else { + reserveOCSectionIndices(global_s_indices, oc->n_sections); + int s_i = global_s_indices->n_sections; + for (int i = 0; i < oc->n_sections; i++) { + if (oc->sections[i].kind != SECTIONKIND_OTHER) { + OCSectionIndex *ent = &global_s_indices->indices[s_i]; + ent->start = (W_)oc->sections[i].start; + ent->end = (W_)oc->sections[i].start + oc->sections[i].size; + ent->oc = oc; + s_i++; + } + } + + global_s_indices->n_sections = s_i; + } // Add object to 'objects' list if (objects != NULL) { @@ -443,6 +467,7 @@ void checkUnload() ObjectCode *next = NULL; for (ObjectCode *oc = old_objects; oc != NULL; oc = next) { next = oc->next; + ASSERT(oc->status == OBJECT_UNLOADED); removeOCSectionIndices(s_indices, oc); ===================================== rts/Linker.c ===================================== @@ -63,6 +63,7 @@ # include "linker/Elf.h" # include // regex is already used by dlopen() so this is OK // to use here without requiring an additional lib +# include #elif defined(OBJFORMAT_PEi386) # include "linker/PEi386.h" # include @@ -169,6 +170,8 @@ Mutex linker_mutex; /* Generic wrapper function to try and Resolve and RunInit oc files */ int ocTryLoad( ObjectCode* oc ); +static void freeNativeCode_ELF (ObjectCode *nc); + /* Link objects into the lower 2Gb on x86_64 and AArch64. GHC assumes the * small memory model on this architecture (see gcc docs, * -mcmodel=small). @@ -980,7 +983,9 @@ SymbolAddr* lookupSymbol( SymbolName* lbl ) again in unloadObj(). -------------------------------------------------------------------------- */ -static ObjectCode *loading_obj = NULL; +// volatile works around +// https://sourceware.org/ml/libc-alpha/2013-08/msg00465.html +static ForeignExportStablePtr ** volatile loading_fe_stable_ptr = NULL; StgStablePtr foreignExportStablePtr (StgPtr p) { @@ -989,12 +994,12 @@ StgStablePtr foreignExportStablePtr (StgPtr p) sptr = getStablePtr(p); - if (loading_obj != NULL) { + if (loading_fe_stable_ptr != NULL) { fe_sptr = stgMallocBytes(sizeof(ForeignExportStablePtr), "foreignExportStablePtr"); fe_sptr->stable_ptr = sptr; - fe_sptr->next = loading_obj->stable_ptrs; - loading_obj->stable_ptrs = fe_sptr; + fe_sptr->next = *loading_fe_stable_ptr; + *loading_fe_stable_ptr = fe_sptr; } return sptr; @@ -1267,18 +1272,18 @@ static void removeOcSymbols (ObjectCode *oc) * Release StablePtrs and free oc->stable_ptrs. * This operation is idempotent. */ -static void freeOcStablePtrs (ObjectCode *oc) +static void freeFEStablePtrs (ForeignExportStablePtr **code_stable_ptrs) { // Release any StablePtrs that were created when this // object module was initialized. ForeignExportStablePtr *fe_ptr, *next; - for (fe_ptr = oc->stable_ptrs; fe_ptr != NULL; fe_ptr = next) { + for (fe_ptr = *code_stable_ptrs; fe_ptr != NULL; fe_ptr = next) { next = fe_ptr->next; freeStablePtr(fe_ptr->stable_ptr); stgFree(fe_ptr); } - oc->stable_ptrs = NULL; + *code_stable_ptrs = NULL; } static void @@ -1308,6 +1313,16 @@ freePreloadObjectFile (ObjectCode *oc) */ void freeObjectCode (ObjectCode *oc) { + if (oc->type == DYNAMIC_OBJECT) { +#if defined(OBJFORMAT_ELF) + ACQUIRE_LOCK(&dl_mutex); + freeNativeCode_ELF(oc); + RELEASE_LOCK(&dl_mutex); +#else + barf("This shouldn't happen") +#endif + } + freePreloadObjectFile(oc); if (oc->symbols != NULL) { @@ -1390,7 +1405,7 @@ void freeObjectCode (ObjectCode *oc) } ObjectCode* -mkOc( pathchar *path, char *image, int imageSize, +mkOc( ObjectType type, pathchar *path, char *image, int imageSize, bool mapped, pathchar *archiveMemberName, int misalignment ) { ObjectCode* oc; @@ -1398,6 +1413,7 @@ mkOc( pathchar *path, char *image, int imageSize, oc = stgMallocBytes(sizeof(ObjectCode), "mkOc(oc)"); oc->info = NULL; + oc->type = type; # if defined(OBJFORMAT_ELF) oc->formatName = "ELF"; @@ -1458,6 +1474,10 @@ mkOc( pathchar *path, char *image, int imageSize, oc->rx_m32 = m32_allocator_new(true); #endif + oc->l_addr = NULL; + oc->nc_ranges = NULL; + oc->dlopen_handle = NULL; + IF_DEBUG(linker, debugBelch("mkOc: done\n")); return oc; } @@ -1585,7 +1605,7 @@ preloadObjectFile (pathchar *path) IF_DEBUG(linker, debugBelch("loadObj: preloaded image at %p\n", (void *) image)); /* FIXME (AP): =mapped= parameter unconditionally set to true */ - oc = mkOc(path, image, fileSize, true, NULL, misalignment); + oc = mkOc(STATIC_OBJECT, path, image, fileSize, true, NULL, misalignment); #if defined(OBJFORMAT_MACHO) if (ocVerifyImage_MachO( oc )) @@ -1620,7 +1640,7 @@ static HsInt loadObj_ (pathchar *path) if (! loadOc(oc)) { // failed; free everything we've allocated removeOcSymbols(oc); - // no need to freeOcStablePtrs, they aren't created until resolveObjs() + // no need to freeFEStablePtrs, they aren't created until resolveObjs() freeObjectCode(oc); return 0; } @@ -1794,7 +1814,8 @@ int ocTryLoad (ObjectCode* oc) { IF_DEBUG(linker, debugBelch("ocTryLoad: ocRunInit start\n")); - loading_obj = oc; // tells foreignExportStablePtr what to do + loading_fe_stable_ptr = &oc->stable_ptrs; + // tells foreignExportStablePtr what to do #if defined(OBJFORMAT_ELF) r = ocRunInit_ELF ( oc ); #elif defined(OBJFORMAT_PEi386) @@ -1804,7 +1825,7 @@ int ocTryLoad (ObjectCode* oc) { #else barf("ocTryLoad: initializers not implemented on this platform"); #endif - loading_obj = NULL; + loading_fe_stable_ptr = NULL; if (!r) { return r; } @@ -1871,7 +1892,7 @@ static HsInt unloadObj_ (pathchar *path, bool just_purge) // These are both idempotent, so in just_purge mode we can later // call unloadObj() to really unload the object. removeOcSymbols(oc); - freeOcStablePtrs(oc); + freeFEStablePtrs(&oc->stable_ptrs); unloadedAnyObj = true; @@ -2003,6 +2024,185 @@ addSection (Section *s, SectionKind kind, SectionAlloc alloc, size, kind )); } + +# if defined(OBJFORMAT_ELF) +static int loadNativeObjCb_(struct dl_phdr_info *info, + size_t _size GNUC3_ATTRIBUTE(__unused__), void *data) { + ObjectCode* nc = (ObjectCode*) data; + + // This logic mimicks _dl_addr_inside_object from glibc + // For reference: + // int + // internal_function + // _dl_addr_inside_object (struct link_map *l, const ElfW(Addr) addr) + // { + // int n = l->l_phnum; + // const ElfW(Addr) reladdr = addr - l->l_addr; + // + // while (--n >= 0) + // if (l->l_phdr[n].p_type == PT_LOAD + // && reladdr - l->l_phdr[n].p_vaddr >= 0 + // && reladdr - l->l_phdr[n].p_vaddr < l->l_phdr[n].p_memsz) + // return 1; + // return 0; + // } + + if ((void*) info->dlpi_addr == nc->l_addr) { + int n = info->dlpi_phnum; + while (--n >= 0) { + if (info->dlpi_phdr[n].p_type == PT_LOAD) { + NativeCodeRange* ncr = + stgMallocBytes(sizeof(NativeCodeRange), "loadNativeObjCb_"); + ncr->start = (void*) ((char*) nc->l_addr + info->dlpi_phdr[n].p_vaddr); + ncr->end = (void*) ((char*) ncr->start + info->dlpi_phdr[n].p_memsz); + + ncr->next = nc->nc_ranges; + nc->nc_ranges = ncr; + } + } + } + return 0; +} + +static void copyErrmsg(char** errmsg_dest, char* errmsg) { + if (errmsg == NULL) errmsg = "loadNativeObj_ELF: unknown error"; + *errmsg_dest = stgMallocBytes(strlen(errmsg)+1, "loadNativeObj_ELF"); + strcpy(*errmsg_dest, errmsg); +} + +// need dl_mutex +static void freeNativeCode_ELF (ObjectCode *nc) { + dlclose(nc->dlopen_handle); + + NativeCodeRange *ncr = nc->nc_ranges; + while (ncr) { + NativeCodeRange* last_ncr = ncr; + ncr = ncr->next; + stgFree(last_ncr); + } +} + +static void * loadNativeObj_ELF (pathchar *path, char **errmsg) +{ + ObjectCode* nc; + void *hdl, *retval; + + IF_DEBUG(linker, debugBelch("loadNativeObj_ELF %" PATH_FMT "\n", path)); + + retval = NULL; + ACQUIRE_LOCK(&dl_mutex); + + ForeignExportStablePtr *fe_sptr = NULL; + loading_fe_stable_ptr = &fe_sptr; + // dlopen will run foreignExportStablePtr adding StablePtrs from this DLL + // to fe_sptr + hdl = dlopen(path, RTLD_NOW|RTLD_LOCAL); + loading_fe_stable_ptr = NULL; + if (hdl == NULL) { + /* dlopen failed; save the message in errmsg */ + copyErrmsg(errmsg, dlerror()); + goto dlopen_fail; + } + + struct link_map *map; + if (dlinfo(hdl, RTLD_DI_LINKMAP, &map) == -1) { + /* dlinfo failed; save the message in errmsg */ + copyErrmsg(errmsg, dlerror()); + goto dlinfo_fail; + } + + nc = mkOc(DYNAMIC_OBJECT, path, NULL, 0, true, NULL, 0); + nc->l_addr = (void*) map->l_addr; + nc->dlopen_handle = hdl; + hdl = NULL; // pass handle ownership to nc + nc->stable_ptrs = fe_sptr; + fe_sptr = NULL; // pass the ownership to nc + + dl_iterate_phdr(loadNativeObjCb_, nc); + if (!nc->nc_ranges) { + copyErrmsg(errmsg, "dl_iterate_phdr failed to find obj"); + goto dl_iterate_phdr_fail; + } + + insertOCSectionIndices(nc); + + nc->next_loaded_object = loaded_objects; + loaded_objects = nc; + + retval = nc->dlopen_handle; + goto success; + +dl_iterate_phdr_fail: + // already have dl_mutex + freeNativeCode_ELF(nc); +dlinfo_fail: + if (hdl) dlclose(hdl); +dlopen_fail: + freeFEStablePtrs(&fe_sptr); +success: + + RELEASE_LOCK(&dl_mutex); + IF_DEBUG(linker, debugBelch("loadNativeObj_ELF result=%p\n", retval)); + + return retval; +} + +# endif + +#define UNUSED(x) (void)(x) + +void * loadNativeObj (pathchar *path, char **errmsg) +{ +#if defined(OBJFORMAT_ELF) + ACQUIRE_LOCK(&linker_mutex); + void *r = loadNativeObj_ELF(path, errmsg); + RELEASE_LOCK(&linker_mutex); + return r; +#else + UNUSED(path); + UNUSED(errmsg); + barf("loadNativeObj: not implemented on this platform"); +#endif +} + +HsInt unloadNativeObj (void *handle) +{ + bool unloadedAnyObj = false; + + IF_DEBUG(linker, debugBelch("unloadNativeObj: %p\n", handle)); + + ObjectCode *prev = NULL, *next; + for (ObjectCode *nc = loaded_objects; nc; nc = next) { + next = nc->next_loaded_object; // we might move nc + + if (nc->type == DYNAMIC_OBJECT && nc->dlopen_handle == handle) { + nc->status = OBJECT_UNLOADED; + n_unloaded_objects += 1; + + // dynamic objects have no symbols + ASSERT(nc->symbols == NULL); + freeFEStablePtrs(&nc->stable_ptrs); + + // Remove object code from root set + if (prev == NULL) { + loaded_objects = nc->next_loaded_object; + } else { + prev->next_loaded_object = nc->next_loaded_object; + } + unloadedAnyObj = true; + } else { + prev = nc; + } + } + + if (unloadedAnyObj) { + return 1; + } else { + errorBelch("unloadObjNativeObj_ELF: can't find `%p' to unload", handle); + return 0; + } +} + /* ----------------------------------------------------------------------------- * Segment management */ ===================================== rts/LinkerInternals.h ===================================== @@ -32,6 +32,13 @@ typedef struct _Symbol SymbolAddr *addr; } Symbol_t; +typedef struct NativeCodeRange_ { + void *start, *end; + + /* Allow a chain of these things */ + struct NativeCodeRange_ *next; +} NativeCodeRange; + /* Indication of section kinds for loaded objects. Needed by the GC for deciding whether or not a pointer on the stack is a code pointer. @@ -169,6 +176,13 @@ typedef struct { #endif } SymbolExtra; +typedef enum { + /* Objects that were loaded by this linker */ + STATIC_OBJECT, + + /* Objects that were loaded by dlopen */ + DYNAMIC_OBJECT, +} ObjectType; /* Top-level structure for an object module. One of these is allocated * for each object file in use. @@ -177,7 +191,8 @@ typedef struct _ObjectCode { OStatus status; pathchar *fileName; int fileSize; /* also mapped image size when using mmap() */ - char* formatName; /* eg "ELF32", "DLL", "COFF", etc. */ + char* formatName; /* e.g. "ELF32", "DLL", "COFF", etc. */ + ObjectType type; /* who loaded this object? */ /* If this object is a member of an archive, archiveMemberName is * like "libarchive.a(object.o)". Otherwise it's NULL. @@ -278,6 +293,19 @@ typedef struct _ObjectCode { * (read-only/executable) code. */ m32_allocator *rw_m32, *rx_m32; #endif + + /* + * The following are only valid if .type == DYNAMIC_OBJECT + */ + + /* handle returned from dlopen */ + void *dlopen_handle; + + /* base virtual address of the loaded code */ + void *l_addr; + + /* virtual memory ranges of loaded code */ + NativeCodeRange *nc_ranges; } ObjectCode; #define OC_INFORMATIVE_FILENAME(OC) \ @@ -286,6 +314,7 @@ typedef struct _ObjectCode { (OC)->fileName \ ) + #if defined(THREADED_RTS) extern Mutex linker_mutex; #endif @@ -371,7 +400,7 @@ resolveSymbolAddr (pathchar* buffer, int size, HsInt isAlreadyLoaded( pathchar *path ); HsInt loadOc( ObjectCode* oc ); -ObjectCode* mkOc( pathchar *path, char *image, int imageSize, +ObjectCode* mkOc( ObjectType type, pathchar *path, char *image, int imageSize, bool mapped, pathchar *archiveMemberName, int misalignment ); ===================================== rts/linker/LoadArchive.c ===================================== @@ -521,7 +521,7 @@ static HsInt loadArchive_ (pathchar *path) pathprintf(archiveMemberName, size, WSTR("%" PATH_FMT "(%.*s)"), path, (int)thisFileNameSize, fileName); - ObjectCode *oc = mkOc(path, image, memberSize, false, archiveMemberName, + ObjectCode *oc = mkOc(STATIC_OBJECT, path, image, memberSize, false, archiveMemberName, misalignment); #if defined(OBJFORMAT_MACHO) ocInit_MachO( oc ); ===================================== rts/sm/Storage.c ===================================== @@ -45,6 +45,7 @@ StgIndStatic *dyn_caf_list = NULL; StgIndStatic *debug_caf_list = NULL; StgIndStatic *revertible_caf_list = NULL; bool keepCAFs; +bool highMemDynamic; W_ large_alloc_lim; /* GC if n_large_blocks in any nursery * reaches this. */ @@ -519,7 +520,7 @@ newCAF(StgRegTable *reg, StgIndStatic *caf) bh = lockCAF(reg, caf); if (!bh) return NULL; - if(keepCAFs) + if(keepCAFs && !(highMemDynamic && (void*) caf > (void*) 0x80000000)) { // Note [dyn_caf_list] // If we are in GHCi _and_ we are using dynamic libraries, @@ -573,6 +574,12 @@ setKeepCAFs (void) keepCAFs = 1; } +void +setHighMemDynamic (void) +{ + highMemDynamic = 1; +} + // An alternate version of newCAF which is used for dynamically loaded // object code in GHCi. In this case we want to retain *all* CAFs in // the object code, because they might be demanded at any time from an ===================================== testsuite/tests/rts/linker/Makefile ===================================== @@ -58,6 +58,23 @@ linker_unload: # -rtsopts causes a warning "$(TEST_HC)" LinkerUnload.hs -package ghc $(filter-out -rtsopts, $(TEST_HC_OPTS)) linker_unload.c -o linker_unload -no-hs-main -optc-Werror ./linker_unload "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" + +.PHONY: linker_unload_native +linker_unload_native: + $(RM) Test.o Test.hi Test.a Test.so Test2.so + "$(TEST_HC)" $(TEST_HC_OPTS) -c Test.hs -v0 -dynamic -fPIC -o Test.a + # only libraries without DT_NEEDED are supported + "$(CC)" -shared -Wl,-Bsymbolic -nostdlib -o Test.so -Wl,-nostdlib \ + -Wl,--whole-archive Test.a + cp Test.so Test2.so + + # -rtsopts causes a warning + "$(TEST_HC)" LinkerUnload.hs -optl-Wl,--export-dynamic -package ghc \ + $(filter-out -rtsopts, $(TEST_HC_OPTS)) linker_unload_native.c \ + -o linker_unload_native -no-hs-main -optc-Werror + ./linker_unload_native \ + "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" + # ----------------------------------------------------------------------------- # Testing failures in the RTS linker. We should be able to repeatedly ===================================== testsuite/tests/rts/linker/all.T ===================================== @@ -84,6 +84,11 @@ test('T5435_dyn_gcc', extra_files(['T5435.hs', 'T5435_gcc.c']) , makefile_test, test('linker_unload', [extra_files(['LinkerUnload.hs', 'Test.hs']), req_rts_linker], makefile_test, ['linker_unload']) + +test('linker_unload_native', + [extra_files(['LinkerUnload.hs', 'Test.hs']), req_rts_linker], + makefile_test, ['linker_unload_native']) + ###################################### test('linker_error1', [extra_files(['linker_error.c']), ===================================== testsuite/tests/rts/linker/linker_unload_native.c ===================================== @@ -0,0 +1,93 @@ +#include "ghcconfig.h" +#include +#include +#include "Rts.h" +#include +#include + +// poke into linker internals +extern void *objects; + +#define ITERATIONS 1000 + +#if defined(mingw32_HOST_OS) +#define OBJPATH L"Test.so" +#define OBJPATH2 L"Test2.so" +#else +#define OBJPATH "./Test.so" +#define OBJPATH2 "./Test2.so" +#endif + +typedef int testfun(int); + +extern void loadPackages(void); + +int main (int argc, char *argv[]) +{ + testfun *f, *f2; + int i, r; + + RtsConfig conf = defaultRtsConfig; + conf.rts_opts_enabled = RtsOptsAll; + // we want to preserve static CAFs and unload dynamic CAFs + conf.keep_cafs = true; + setHighMemDynamic(); + hs_init_ghc(&argc, &argv, conf); + + initLinker_(0); + + loadPackages(); + + for (i=0; i < ITERATIONS; i++) { + char* errmsg; + // load 2 libraries at once + void* handle = loadNativeObj(OBJPATH, &errmsg); + if (!handle) { + errorBelch("loadNativeObj(%s) failed: %s", OBJPATH, errmsg); + free(errmsg); + exit(1); + } + + void* handle2 = loadNativeObj(OBJPATH2, &errmsg); + if (!handle2) { + errorBelch("loadNativeObj(%s) failed: %s", OBJPATH2, errmsg); + free(errmsg); + exit(1); + } +#if LEADING_UNDERSCORE + f = dlsym(handle, "_f"); + f2 = dlsym(handle2, "_f"); +#else + f = dlsym(handle, "f"); + f2 = dlsym(handle2, "f"); +#endif + if (!f) { + errorBelch("dlsym failed"); + exit(1); + } + r = f(3); + if (r != 4) { + errorBelch("call failed; %d", r); + exit(1); + } + if (!f2) { + errorBelch("dlsym failed"); + exit(1); + } + r = f2(3); + if (r != 4) { + errorBelch("call failed; %d", r); + exit(1); + } + unloadNativeObj(handle); + unloadNativeObj(handle2); + performMajorGC(); + printf("%d ", i); + fflush(stdout); + } + + // Verify that Test.so isn't still loaded. + int res = getObjectLoadStatus("Test.so") != OBJECT_NOT_LOADED; + hs_exit(); + exit(res); +} ===================================== testsuite/tests/rts/linker/linker_unload_native.stdout ===================================== @@ -0,0 +1,3 @@ +[1 of 1] Compiling LinkerUnload ( LinkerUnload.hs, LinkerUnload.o ) +Linking linker_unload_native ... +0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 \ No newline at end of file View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2cfcbcfa90dd5cda84c7bdd3b4ef36786ea508c8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2cfcbcfa90dd5cda84c7bdd3b4ef36786ea508c8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 9 20:05:28 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 09 Aug 2020 16:05:28 -0400 Subject: [Git][ghc/ghc][wip/unloading] 27 commits: hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. Message-ID: <5f3057088ef14_80b3f8496224a70726504e@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/unloading at Glasgow Haskell Compiler / GHC Commits: 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - 46234542 by Ömer Sinan Ağacan at 2020-08-09T16:05:22-04:00 Fix and enable object unloading in GHCi Fixes #16525 See Note [Object unloading] in CheckUnload.c for details. NoFib results: -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS -0.2% 0.0% +0.0% +0.0% +0.0% CSD -0.2% 0.0% +0.0% +0.0% +0.0% FS -0.2% 0.0% +0.0% +0.0% -0.0% S -0.2% 0.0% +1.0% +1.1% +0.0% VS -0.2% 0.0% +0.0% +0.0% -0.0% VSD -0.1% 0.0% +0.0% +0.0% +0.0% VSM -0.1% 0.0% +0.0% +0.0% -0.0% anna -0.1% 0.0% +0.0% +0.0% +0.0% ansi -0.1% 0.0% +0.0% +0.0% 0.0% atom -0.1% 0.0% +0.0% +0.0% 0.0% awards -0.1% 0.0% +0.0% +0.0% 0.0% banner -0.1% 0.0% +0.0% +0.0% +0.0% bernouilli -0.1% 0.0% +0.0% +0.0% +0.0% binary-trees -0.1% 0.0% +0.0% +0.0% -0.0% boyer -0.1% 0.0% +0.1% +0.1% 0.0% boyer2 -0.1% 0.0% +0.0% +0.1% 0.0% bspt -0.1% 0.0% +0.0% +0.0% 0.0% cacheprof -0.1% 0.0% +0.0% +0.0% -0.0% calendar -0.1% 0.0% +0.0% +0.0% 0.0% cichelli -0.1% 0.0% +0.1% +0.2% +0.0% circsim -0.1% 0.0% +0.0% +0.0% +0.0% clausify -0.1% 0.0% +0.0% +0.0% +0.0% comp_lab_zift -0.1% 0.0% +0.0% +0.0% -0.0% compress -0.1% 0.0% +0.0% +0.0% +0.0% compress2 -0.1% 0.0% +0.0% +0.0% 0.0% constraints -0.1% 0.0% +0.0% +0.0% +0.0% cryptarithm1 -0.1% 0.0% +0.0% +0.0% 0.0% cryptarithm2 -0.1% 0.0% +0.0% +0.0% +0.0% cse -0.1% 0.0% +0.0% +0.0% 0.0% digits-of-e1 -0.1% 0.0% +0.0% +0.0% +0.0% digits-of-e2 -0.1% 0.0% +0.0% +0.0% -0.0% dom-lt -0.1% 0.0% +0.0% +0.0% -0.0% eliza -0.1% 0.0% +0.0% +0.0% +0.0% event -0.1% 0.0% +0.0% +0.1% 0.0% exact-reals -0.1% 0.0% +0.0% +0.0% -0.0% exp3_8 -0.1% 0.0% +0.0% +0.0% 0.0% expert -0.1% 0.0% +0.0% +0.0% +0.0% fannkuch-redux -0.1% 0.0% +0.0% +0.0% 0.0% fasta -0.1% 0.0% +0.0% +0.0% -0.0% fem -0.1% 0.0% +0.0% +0.0% 0.0% fft -0.1% 0.0% +0.0% +0.0% -0.0% fft2 -0.1% 0.0% +0.0% +0.0% 0.0% fibheaps -0.1% 0.0% +0.0% +0.0% -0.0% fish -0.1% 0.0% +0.0% +0.0% -0.0% fluid -0.1% 0.0% +0.1% +0.1% -0.0% fulsom -0.1% 0.0% +0.0% +0.0% 0.0% gamteb -0.1% 0.0% +0.0% +0.0% 0.0% gcd -0.1% 0.0% +0.0% +0.0% +0.0% gen_regexps -0.2% 0.0% +0.0% +0.0% -0.0% genfft -0.1% 0.0% +0.0% +0.0% -0.0% gg -0.1% 0.0% +0.1% +0.1% 0.0% grep -0.1% 0.0% +0.0% +0.0% 0.0% hidden -0.1% 0.0% +0.0% +0.0% +0.0% hpg -0.1% 0.0% +0.0% +0.0% +0.0% ida -0.1% 0.0% +0.0% +0.0% -0.0% infer -0.1% 0.0% +0.0% +0.0% +0.0% integer -0.1% 0.0% +0.0% +0.0% 0.0% integrate -0.1% 0.0% +0.0% +0.0% 0.0% k-nucleotide -0.1% 0.0% +0.0% +0.0% -0.0% kahan -0.1% 0.0% +0.0% +0.0% +0.0% knights -0.1% 0.0% +0.0% +0.0% 0.0% lambda -0.1% 0.0% +0.0% +0.0% +0.0% last-piece -0.1% 0.0% +0.0% +0.0% -0.0% lcss -0.1% 0.0% +0.0% +0.0% 0.0% life -0.1% 0.0% +0.0% +0.0% -0.0% lift -0.1% 0.0% +0.0% +0.0% +0.0% linear -0.1% 0.0% +0.0% +0.0% +0.0% listcompr -0.1% 0.0% +0.0% +0.0% -0.0% listcopy -0.1% 0.0% +0.0% +0.0% -0.0% maillist -0.1% 0.0% +0.0% +0.0% +0.0% mandel -0.1% 0.0% +0.0% +0.0% -0.0% mandel2 -0.1% 0.0% +0.0% +0.0% -0.0% mate -0.1% 0.0% +0.0% +0.0% -0.0% minimax -0.1% 0.0% +0.0% +0.0% -0.0% mkhprog -0.1% 0.0% +0.0% +0.0% +0.0% multiplier -0.1% 0.0% +0.0% +0.0% +0.0% n-body -0.1% 0.0% +0.0% +0.0% 0.0% nucleic2 -0.1% 0.0% +0.0% +0.0% -0.0% para -0.1% 0.0% +0.0% +0.0% 0.0% paraffins -0.1% 0.0% +0.0% +0.0% 0.0% parser -0.1% 0.0% +0.0% +0.0% +0.0% parstof -0.1% 0.0% +0.2% +0.2% -0.0% pic -0.1% 0.0% +0.1% +0.1% +0.0% pidigits -0.1% 0.0% +0.0% +0.0% -0.0% power -0.1% 0.0% +0.0% +0.0% +0.0% pretty -0.1% 0.0% +0.5% +0.6% -0.0% primes -0.1% 0.0% +0.0% +0.0% 0.0% primetest -0.1% 0.0% +0.0% +0.0% +0.0% prolog -0.1% 0.0% +0.0% +0.0% +0.0% puzzle -0.1% 0.0% +0.0% +0.0% -0.0% queens -0.1% 0.0% +0.0% +0.0% 0.0% reptile -0.1% 0.0% +0.0% +0.0% +0.0% reverse-complem -0.2% 0.0% +0.0% +0.0% 0.0% rewrite -0.1% 0.0% +0.0% +0.0% 0.0% rfib -0.1% 0.0% +0.0% +0.0% -0.0% rsa -0.1% 0.0% +0.0% +0.0% +0.0% scc -0.2% 0.0% +0.5% +0.7% +0.0% sched -0.1% 0.0% +0.0% +0.0% -0.0% scs -0.1% 0.0% +0.0% +0.0% +0.0% simple -0.1% 0.0% +0.3% +0.4% 0.0% solid -0.1% 0.0% +0.0% +0.0% 0.0% sorting -0.1% 0.0% +0.0% +0.0% -0.0% spectral-norm -0.1% 0.0% +0.0% +0.0% -0.0% sphere -0.1% 0.0% +0.0% +0.0% 0.0% symalg -0.1% 0.0% +0.0% +0.0% +0.0% tak -0.1% 0.0% +0.0% +0.0% +0.0% transform -0.1% 0.0% +0.0% +0.0% +0.0% treejoin -0.1% 0.0% +0.1% +0.1% 0.0% typecheck -0.1% 0.0% +0.0% +0.0% 0.0% veritas -0.1% 0.0% +0.0% +0.0% +0.0% wang -0.1% 0.0% +0.0% +0.0% +0.0% wave4main -0.1% 0.0% +0.0% +0.0% -0.0% wheel-sieve1 -0.1% 0.0% +0.0% +0.0% +0.0% wheel-sieve2 -0.1% 0.0% +0.0% +0.0% -0.0% x2n1 -0.1% 0.0% +0.0% +0.0% +0.0% -------------------------------------------------------------------------------- Min -0.2% 0.0% +0.0% +0.0% -0.0% Max -0.1% 0.0% +1.0% +1.1% +0.0% Geometric Mean -0.1% -0.0% +0.0% +0.0% -0.0% - - - - - b2658359 by Ray Shih at 2020-08-09T16:05:22-04:00 Add loadNativeObj and unloadNativeObj Summary: (This change is originally written by niteria) This adds two functions: * `loadNativeObj` * `unloadNativeObj` and implements them for Linux. They are useful if you want to load a shared object with Haskell code using the system linker and have GHC call dlclose() after the code is no longer referenced from the heap. Using the system linker allows you to load the shared object above outside the lowmem region. It also loads the DWARF sections in a way that `perf` understands. `dl_iterate_phdr` is what makes this implementation Linux specific. NOTE: this should be replaceable by whatever D4263 becomes Test Plan: manual testing Reviewers: simonmar, Phyx, bgamari, erikd Reviewed By: niteria Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4263 - - - - - 30 changed files: - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/CodeOutput.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Expr.hs-boot - compiler/GHC/HsToCore/ListComp.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Annotation.hs - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Platform/Profile.hs - compiler/GHC/Platform/Ways.hs - compiler/GHC/Runtime/Linker.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/StgToCmm/Foreign.hs - compiler/GHC/StgToCmm/Utils.hs - compiler/GHC/SysTools/Tasks.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2cfcbcfa90dd5cda84c7bdd3b4ef36786ea508c8...b2658359ca2493e4f5eccaffabd367d7bd550189 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2cfcbcfa90dd5cda84c7bdd3b4ef36786ea508c8...b2658359ca2493e4f5eccaffabd367d7bd550189 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 9 20:14:25 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 09 Aug 2020 16:14:25 -0400 Subject: [Git][ghc/ghc][wip/backports] Hardcode RTS includes to cope with unregistered builds Message-ID: <5f30592166bb9_80b3f848c1e06f47271153@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: 9244c555 by Alex Biehl at 2020-08-09T16:14:18-04:00 Hardcode RTS includes to cope with unregistered builds (cherry picked from commit ef2ae81a394df573510b12b7e11bba0c931249d8) - - - - - 1 changed file: - compiler/GHC/Driver/CodeOutput.hs Changes: ===================================== compiler/GHC/Driver/CodeOutput.hs ===================================== @@ -124,27 +124,10 @@ outputC :: DynFlags outputC dflags filenm cmm_stream packages = do withTiming dflags (text "C codegen") (\a -> seq a () {- FIXME -}) $ do - - -- figure out which header files to #include in the generated .hc file: - -- - -- * extra_includes from packages - -- * -#include options from the cmdline and OPTIONS pragmas - -- * the _stub.h file, if there is one. - -- - let rts = unsafeLookupUnitId (unitState dflags) rtsUnitId - - let cc_injects = unlines (map mk_include (unitIncludes rts)) - mk_include h_file = - case h_file of - '"':_{-"-} -> "#include "++h_file - '<':_ -> "#include "++h_file - _ -> "#include \""++h_file++"\"" - let pkg_names = map unitIdString packages - doOutput filenm $ \ h -> do hPutStr h ("/* GHC_PACKAGES " ++ unwords pkg_names ++ "\n*/\n") - hPutStr h cc_injects + hPutStr h "#include \"Stg.h\"\n" Stream.consume cmm_stream (writeC dflags h) {- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9244c55514d5cb990763fcc79d77e62165c3bcf2 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9244c55514d5cb990763fcc79d77e62165c3bcf2 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 9 20:27:58 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 09 Aug 2020 16:27:58 -0400 Subject: [Git][ghc/ghc][ghc-8.10] rts: Fix unused variable warning on Darwin Message-ID: <5f305c4e633ec_80b3f849c1caa10727469b@gitlab.haskell.org.mail> Ben Gamari pushed to branch ghc-8.10 at Glasgow Haskell Compiler / GHC Commits: 82f15edc by Ben Gamari at 2020-08-09T16:27:21-04:00 rts: Fix unused variable warning on Darwin - - - - - 1 changed file: - rts/posix/GetTime.c Changes: ===================================== rts/posix/GetTime.c ===================================== @@ -71,7 +71,6 @@ Time getCurrentThreadCPUTime(void) // support clock_getcpuclockid. Hence we prefer to use the Darwin-specific // path on Darwin, even if clock_gettime is available. #if defined(darwin_HOST_OS) - mach_port_t port = pthread_mach_thread_np(osThreadId()); thread_basic_info_data_t info = { 0 }; mach_msg_type_number_t info_count = THREAD_BASIC_INFO_COUNT; kern_return_t kern_err = thread_info(mach_thread_self(), THREAD_BASIC_INFO, View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/82f15edc506cdf91c63c2351603c8f0fb0379914 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/82f15edc506cdf91c63c2351603c8f0fb0379914 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 01:17:25 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sun, 09 Aug 2020 21:17:25 -0400 Subject: [Git][ghc/ghc][master] hadrian: depend on boot compiler version #18001 Message-ID: <5f30a025ac629_80b3f8496224a70729762d@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - 1 changed file: - hadrian/src/Builder.hs Changes: ===================================== hadrian/src/Builder.hs ===================================== @@ -30,6 +30,7 @@ import Hadrian.Utilities import Base import Context import Oracles.Flag +import Oracles.Setting (setting, Setting(..)) import Packages -- | C compiler can be used in two different modes: @@ -180,7 +181,11 @@ instance H.Builder Builder where Autoreconf dir -> return [dir -/- "configure.ac"] Configure dir -> return [dir -/- "configure"] - Ghc _ Stage0 -> includesDependencies Stage0 + Ghc _ Stage0 -> do + -- Read the boot GHC version here to make sure we rebuild when it + -- changes (#18001). + _bootGhcVersion <- setting GhcVersion + includesDependencies Stage0 Ghc _ stage -> do root <- buildRoot touchyPath <- programPath (vanillaContext Stage0 touchy) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a11c9678409b2e0a01e8aba153e094800f3641bf -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a11c9678409b2e0a01e8aba153e094800f3641bf You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 01:17:59 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sun, 09 Aug 2020 21:17:59 -0400 Subject: [Git][ghc/ghc][master] Api Annotations : Adjust SrcSpans for prefix bang (!). Message-ID: <5f30a0479b079_80b3f849c1caa10729822b@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 3 changed files: - compiler/GHC/Parser/PostProcess.hs - testsuite/tests/ghc-api/annotations/Makefile - testsuite/tests/ghc-api/annotations/T10358.stdout Changes: ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -1201,13 +1201,14 @@ makeFunBind fn ms checkPatBind :: LPat GhcPs -> Located (a,GRHSs GhcPs (LHsExpr GhcPs)) -> P ([AddAnn],HsBind GhcPs) -checkPatBind lhs (L match_span (_,grhss)) +checkPatBind lhs (L rhs_span (_,grhss)) | BangPat _ p <- unLoc lhs , VarPat _ v <- unLoc p = return ([], makeFunBind v [L match_span (m v)]) where + match_span = combineSrcSpans (getLoc lhs) rhs_span m v = Match { m_ext = noExtField - , m_ctxt = FunRhs { mc_fun = L (getLoc lhs) (unLoc v) + , m_ctxt = FunRhs { mc_fun = v , mc_fixity = Prefix , mc_strictness = SrcStrict } , m_pats = [] ===================================== testsuite/tests/ghc-api/annotations/Makefile ===================================== @@ -39,7 +39,8 @@ listcomps: .PHONY: T10358 T10358: - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358.hs + # Ignore result code, we have an unattached (superfluous) AnnBang + - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358.hs .PHONY: T10396 T10396: ===================================== testsuite/tests/ghc-api/annotations/T10358.stdout ===================================== @@ -1,5 +1,5 @@ ---Unattached Annotation Problems (should be empty list)--- -[] +[(AnnBang, Test10358.hs:5:19)] ---Ann before enclosing span problem (should be empty list)--- [ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c8873b52f6a16202c3cb839e988c1406b8f67cfe -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c8873b52f6a16202c3cb839e988c1406b8f67cfe You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 01:18:41 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sun, 09 Aug 2020 21:18:41 -0400 Subject: [Git][ghc/ghc][master] Avoid allocations in `splitAtList` (#18535) Message-ID: <5f30a07196fa8_80b3f846910c0c073029f3@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 1 changed file: - compiler/GHC/Utils/Misc.hs Changes: ===================================== compiler/GHC/Utils/Misc.hs ===================================== @@ -774,12 +774,15 @@ dropList _ xs@[] = xs dropList (_:xs) (_:ys) = dropList xs ys +-- | Given two lists xs=x0..xn and ys=y0..ym, return `splitAt n ys`. splitAtList :: [b] -> [a] -> ([a], [a]) -splitAtList [] xs = ([], xs) -splitAtList _ xs@[] = (xs, xs) -splitAtList (_:xs) (y:ys) = (y:ys', ys'') - where - (ys', ys'') = splitAtList xs ys +splitAtList xs ys = go 0 xs ys + where + -- we are careful to avoid allocating when there are no leftover + -- arguments: in this case we can return "ys" directly (cf #18535) + go _ _ [] = (ys, []) -- len(ys) <= len(xs) + go n [] bs = (take n ys, bs) -- = splitAt n ys + go n (_:as) (_:bs) = go (n+1) as bs -- drop from the end of a list dropTail :: Int -> [a] -> [a] View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/77398b678aba45ba25932a39b7e8a7a31d0dd6f3 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/77398b678aba45ba25932a39b7e8a7a31d0dd6f3 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 03:54:30 2020 From: gitlab at gitlab.haskell.org (Josh Meredith) Date: Sun, 09 Aug 2020 23:54:30 -0400 Subject: [Git][ghc/ghc][wip/pluginExtFields] 5 commits: hadrian: depend on boot compiler version #18001 Message-ID: <5f30c4f6af6cc_80b3f848a372f8c730836f@gitlab.haskell.org.mail> Josh Meredith pushed to branch wip/pluginExtFields at Glasgow Haskell Compiler / GHC Commits: a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - a74b1cf3 by Josh Meredith at 2020-08-09T23:54:28-04:00 Add machinery for plugins to write data to extensible interface fields - - - - - 95eb22d7 by Josh Meredith at 2020-08-09T23:54:28-04:00 Add function to remove plugin interface fields - - - - - 9 changed files: - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/IfaceToCore.hs - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Utils/Misc.hs - hadrian/src/Builder.hs - testsuite/tests/ghc-api/annotations/Makefile - testsuite/tests/ghc-api/annotations/T10358.stdout Changes: ===================================== compiler/GHC/Driver/Main.hs ===================================== @@ -198,6 +198,7 @@ newHscEnv dflags = do us <- mkSplitUniqSupply 'r' nc_var <- newIORef (initNameCache us knownKeyNames) fc_var <- newIORef emptyInstalledModuleEnv + ext_fs <- newIORef emptyExtensibleFields emptyDynLinker <- uninitializedLinker return HscEnv { hsc_dflags = dflags , hsc_targets = [] @@ -207,6 +208,7 @@ newHscEnv dflags = do , hsc_EPS = eps_var , hsc_NC = nc_var , hsc_FC = fc_var + , hsc_ext_fields = ext_fs , hsc_type_env_var = Nothing , hsc_interp = Nothing , hsc_dynLinker = emptyDynLinker @@ -810,11 +812,10 @@ finish summary tc_result mb_old_hash = do (cg_guts, details) <- {-# SCC "CoreTidy" #-} liftIO $ tidyProgram hsc_env simplified_guts - let !partial_iface = - {-# SCC "GHC.Driver.Main.mkPartialIface" #-} + !partial_iface <- {-# SCC "GHC.Driver.Main.mkPartialIface" #-} -- This `force` saves 2M residency in test T10370 -- See Note [Avoiding space leaks in toIface*] for details. - force (mkPartialIface hsc_env details simplified_guts) + liftIO $ force <$> (mkPartialIface hsc_env details simplified_guts) return HscRecomp { hscs_guts = cg_guts, hscs_mod_location = ms_location summary, ===================================== compiler/GHC/Driver/Types.hs ===================================== @@ -155,6 +155,8 @@ module GHC.Driver.Types ( readField, readIfaceField, readIfaceFieldWith, writeField, writeIfaceField, writeIfaceFieldWith, deleteField, deleteIfaceField, + registerInterfaceData, registerInterfaceDataWith, + unregisterInterfaceData, ) where #include "HsVersions.h" @@ -475,6 +477,10 @@ data HscEnv hsc_FC :: {-# UNPACK #-} !(IORef FinderCache), -- ^ The cached result of performing finding in the file system + hsc_ext_fields :: {-# UNPACK #-} !(IORef ExtensibleFields), + -- ^ Extensible interface field data stored by plugins to be later + -- output in the `.hi` file. + hsc_type_env_var :: Maybe (Module, IORef TypeEnv) -- ^ Used for one-shot compilation only, to initialise -- the 'IfGblEnv'. See 'GHC.Tc.Utils.tcg_type_env_var' for @@ -3404,3 +3410,17 @@ deleteField name (ExtensibleFields fs) = ExtensibleFields $ Map.delete name fs deleteIfaceField :: FieldName -> ModIface -> ModIface deleteIfaceField name iface = iface { mi_ext_fields = deleteField name (mi_ext_fields iface) } + +registerInterfaceData :: Binary a => FieldName -> HscEnv -> a -> IO () +registerInterfaceData name env x = registerInterfaceDataWith name env (`put_` x) + +registerInterfaceDataWith :: FieldName -> HscEnv -> (BinHandle -> IO ()) -> IO () +registerInterfaceDataWith name env write = do + ext_fs <- readIORef (hsc_ext_fields env) + ext_fs' <- writeFieldWith name write ext_fs + writeIORef (hsc_ext_fields env) ext_fs' + +unregisterInterfaceData :: FieldName -> HscEnv -> IO () +unregisterInterfaceData name env = do + ext_fs <- readIORef (hsc_ext_fields env) + writeIORef (hsc_ext_fields env) (deleteField name ext_fs) ===================================== compiler/GHC/Iface/Make.hs ===================================== @@ -82,7 +82,7 @@ import GHC.Driver.Plugins (LoadedPlugin(..)) mkPartialIface :: HscEnv -> ModDetails -> ModGuts - -> PartialModIface + -> IO PartialModIface mkPartialIface hsc_env mod_details ModGuts{ mg_module = this_mod , mg_hsc_src = hsc_src @@ -99,8 +99,11 @@ mkPartialIface hsc_env mod_details , mg_decl_docs = decl_docs , mg_arg_docs = arg_docs } - = mkIface_ hsc_env this_mod hsc_src used_th deps rdr_env fix_env warns hpc_info self_trust - safe_mode usages doc_hdr decl_docs arg_docs mod_details + = do ext_fs <- readIORef $ hsc_ext_fields hsc_env + return iface{mi_ext_fields = ext_fs} + where + iface = mkIface_ hsc_env this_mod hsc_src used_th deps rdr_env fix_env warns hpc_info self_trust + safe_mode usages doc_hdr decl_docs arg_docs mod_details -- | Fully instantiate an interface. Adds fingerprints and potentially code -- generator produced information. ===================================== compiler/GHC/IfaceToCore.hs ===================================== @@ -20,7 +20,9 @@ module GHC.IfaceToCore ( tcIfaceAnnotations, tcIfaceCompleteSigs, tcIfaceExpr, -- Desired by HERMIT (#7683) tcIfaceGlobal, - tcIfaceOneShot + tcIfaceOneShot, + tcIfaceType, + tcJoinInfo, ) where #include "HsVersions.h" ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -1201,13 +1201,14 @@ makeFunBind fn ms checkPatBind :: LPat GhcPs -> Located (a,GRHSs GhcPs (LHsExpr GhcPs)) -> P ([AddAnn],HsBind GhcPs) -checkPatBind lhs (L match_span (_,grhss)) +checkPatBind lhs (L rhs_span (_,grhss)) | BangPat _ p <- unLoc lhs , VarPat _ v <- unLoc p = return ([], makeFunBind v [L match_span (m v)]) where + match_span = combineSrcSpans (getLoc lhs) rhs_span m v = Match { m_ext = noExtField - , m_ctxt = FunRhs { mc_fun = L (getLoc lhs) (unLoc v) + , m_ctxt = FunRhs { mc_fun = v , mc_fixity = Prefix , mc_strictness = SrcStrict } , m_pats = [] ===================================== compiler/GHC/Utils/Misc.hs ===================================== @@ -774,12 +774,15 @@ dropList _ xs@[] = xs dropList (_:xs) (_:ys) = dropList xs ys +-- | Given two lists xs=x0..xn and ys=y0..ym, return `splitAt n ys`. splitAtList :: [b] -> [a] -> ([a], [a]) -splitAtList [] xs = ([], xs) -splitAtList _ xs@[] = (xs, xs) -splitAtList (_:xs) (y:ys) = (y:ys', ys'') - where - (ys', ys'') = splitAtList xs ys +splitAtList xs ys = go 0 xs ys + where + -- we are careful to avoid allocating when there are no leftover + -- arguments: in this case we can return "ys" directly (cf #18535) + go _ _ [] = (ys, []) -- len(ys) <= len(xs) + go n [] bs = (take n ys, bs) -- = splitAt n ys + go n (_:as) (_:bs) = go (n+1) as bs -- drop from the end of a list dropTail :: Int -> [a] -> [a] ===================================== hadrian/src/Builder.hs ===================================== @@ -30,6 +30,7 @@ import Hadrian.Utilities import Base import Context import Oracles.Flag +import Oracles.Setting (setting, Setting(..)) import Packages -- | C compiler can be used in two different modes: @@ -180,7 +181,11 @@ instance H.Builder Builder where Autoreconf dir -> return [dir -/- "configure.ac"] Configure dir -> return [dir -/- "configure"] - Ghc _ Stage0 -> includesDependencies Stage0 + Ghc _ Stage0 -> do + -- Read the boot GHC version here to make sure we rebuild when it + -- changes (#18001). + _bootGhcVersion <- setting GhcVersion + includesDependencies Stage0 Ghc _ stage -> do root <- buildRoot touchyPath <- programPath (vanillaContext Stage0 touchy) ===================================== testsuite/tests/ghc-api/annotations/Makefile ===================================== @@ -39,7 +39,8 @@ listcomps: .PHONY: T10358 T10358: - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358.hs + # Ignore result code, we have an unattached (superfluous) AnnBang + - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358.hs .PHONY: T10396 T10396: ===================================== testsuite/tests/ghc-api/annotations/T10358.stdout ===================================== @@ -1,5 +1,5 @@ ---Unattached Annotation Problems (should be empty list)--- -[] +[(AnnBang, Test10358.hs:5:19)] ---Ann before enclosing span problem (should be empty list)--- [ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1a68c2a3db5dbd89431474a9ded0f47050eb5410...95eb22d7fdfacf5dd6d7271368decde2c89f4d19 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1a68c2a3db5dbd89431474a9ded0f47050eb5410...95eb22d7fdfacf5dd6d7271368decde2c89f4d19 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 04:32:36 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 00:32:36 -0400 Subject: [Git][ghc/ghc][wip/unloading] Add loadNativeObj and unloadNativeObj Message-ID: <5f30cde437da_80b3f848a386fc873100a5@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/unloading at Glasgow Haskell Compiler / GHC Commits: 644df111 by Ray Shih at 2020-08-10T00:32:18-04:00 Add loadNativeObj and unloadNativeObj Summary: (This change is originally written by niteria) This adds two functions: * `loadNativeObj` * `unloadNativeObj` and implements them for Linux. They are useful if you want to load a shared object with Haskell code using the system linker and have GHC call dlclose() after the code is no longer referenced from the heap. Using the system linker allows you to load the shared object above outside the lowmem region. It also loads the DWARF sections in a way that `perf` understands. `dl_iterate_phdr` is what makes this implementation Linux specific. NOTE: this should be replaceable by whatever D4263 becomes Test Plan: manual testing Reviewers: simonmar, Phyx, bgamari, erikd Reviewed By: niteria Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4263 - - - - - 11 changed files: - includes/rts/Linker.h - includes/rts/storage/GC.h - rts/CheckUnload.c - rts/Linker.c - rts/LinkerInternals.h - rts/linker/LoadArchive.c - rts/sm/Storage.c - testsuite/tests/rts/linker/Makefile - testsuite/tests/rts/linker/all.T - + testsuite/tests/rts/linker/linker_unload_native.c - + testsuite/tests/rts/linker/linker_unload_native.stdout Changes: ===================================== includes/rts/Linker.h ===================================== @@ -76,6 +76,19 @@ HsInt loadArchive( pathchar *path ); /* resolve all the currently unlinked objects in memory */ HsInt resolveObjs( void ); +/* Load an .so using the system linker. + Returns a handle that can be passed to dlsym() or NULL on error. + + In the case of error, stores the error message in errmsg. The caller + is responsible for freeing it. */ +void *loadNativeObj( pathchar *path, char **errmsg ); + +/* Mark the .so loaded with the system linker for unloading. + The RTS will unload it when all the references to the .so disappear from + the heap. + Takes the handle returned from loadNativeObj() as an argument. */ +HsInt unloadNativeObj( void *handle ); + /* load a dynamic library */ const char *addDLL( pathchar* dll_name ); ===================================== includes/rts/storage/GC.h ===================================== @@ -230,6 +230,10 @@ void revertCAFs (void); // (preferably use RtsConfig.keep_cafs instead) void setKeepCAFs (void); +// Let the runtime know that all the CAFs in high mem are not +// to be retained. Useful in conjunction with loadNativeObj +void setHighMemDynamic (void); + /* ----------------------------------------------------------------------------- This is the write barrier for MUT_VARs, a.k.a. IORefs. A MUT_VAR_CLEAN object is not on the mutable list; a MUT_VAR_DIRTY ===================================== rts/CheckUnload.c ===================================== @@ -238,21 +238,45 @@ static void reserveOCSectionIndices(OCSectionIndices *s_indices, int len) // state. void insertOCSectionIndices(ObjectCode *oc) { - reserveOCSectionIndices(global_s_indices, oc->n_sections); + // after we finish the section table will no longer be sorted. global_s_indices->sorted = false; - int s_i = global_s_indices->n_sections; - for (int i = 0; i < oc->n_sections; i++) { - if (oc->sections[i].kind != SECTIONKIND_OTHER) { - global_s_indices->indices[s_i].start = (W_)oc->sections[i].start; - global_s_indices->indices[s_i].end = (W_)oc->sections[i].start - + oc->sections[i].size; - global_s_indices->indices[s_i].oc = oc; + if (oc->type == DYNAMIC_OBJECT) { + // First count the ranges + int n_ranges = 0; + for (NativeCodeRange *ncr = oc->nc_ranges; ncr != NULL; ncr = ncr->next) { + n_ranges++; + } + + // Next reserve the appropriate number of table entries... + reserveOCSectionIndices(global_s_indices, n_ranges); + + // Now insert the new ranges... + int s_i = global_s_indices->n_sections; + for (NativeCodeRange *ncr = oc->nc_ranges; ncr != NULL; ncr = ncr->next) { + OCSectionIndex *ent = &global_s_indices->indices[s_i]; + ent->start = (W_)ncr->start; + ent->end = (W_)ncr->end; + ent->oc = oc; s_i++; } - } - global_s_indices->n_sections = s_i; + global_s_indices->n_sections = s_i; + } else { + reserveOCSectionIndices(global_s_indices, oc->n_sections); + int s_i = global_s_indices->n_sections; + for (int i = 0; i < oc->n_sections; i++) { + if (oc->sections[i].kind != SECTIONKIND_OTHER) { + OCSectionIndex *ent = &global_s_indices->indices[s_i]; + ent->start = (W_)oc->sections[i].start; + ent->end = (W_)oc->sections[i].start + oc->sections[i].size; + ent->oc = oc; + s_i++; + } + } + + global_s_indices->n_sections = s_i; + } // Add object to 'objects' list if (objects != NULL) { @@ -443,6 +467,7 @@ void checkUnload() ObjectCode *next = NULL; for (ObjectCode *oc = old_objects; oc != NULL; oc = next) { next = oc->next; + ASSERT(oc->status == OBJECT_UNLOADED); removeOCSectionIndices(s_indices, oc); ===================================== rts/Linker.c ===================================== @@ -63,6 +63,7 @@ # include "linker/Elf.h" # include // regex is already used by dlopen() so this is OK // to use here without requiring an additional lib +# include #elif defined(OBJFORMAT_PEi386) # include "linker/PEi386.h" # include @@ -169,6 +170,8 @@ Mutex linker_mutex; /* Generic wrapper function to try and Resolve and RunInit oc files */ int ocTryLoad( ObjectCode* oc ); +static void freeNativeCode_ELF (ObjectCode *nc); + /* Link objects into the lower 2Gb on x86_64 and AArch64. GHC assumes the * small memory model on this architecture (see gcc docs, * -mcmodel=small). @@ -980,7 +983,9 @@ SymbolAddr* lookupSymbol( SymbolName* lbl ) again in unloadObj(). -------------------------------------------------------------------------- */ -static ObjectCode *loading_obj = NULL; +// volatile works around +// https://sourceware.org/ml/libc-alpha/2013-08/msg00465.html +static ForeignExportStablePtr ** volatile loading_fe_stable_ptr = NULL; StgStablePtr foreignExportStablePtr (StgPtr p) { @@ -989,12 +994,12 @@ StgStablePtr foreignExportStablePtr (StgPtr p) sptr = getStablePtr(p); - if (loading_obj != NULL) { + if (loading_fe_stable_ptr != NULL) { fe_sptr = stgMallocBytes(sizeof(ForeignExportStablePtr), "foreignExportStablePtr"); fe_sptr->stable_ptr = sptr; - fe_sptr->next = loading_obj->stable_ptrs; - loading_obj->stable_ptrs = fe_sptr; + fe_sptr->next = *loading_fe_stable_ptr; + *loading_fe_stable_ptr = fe_sptr; } return sptr; @@ -1267,18 +1272,18 @@ static void removeOcSymbols (ObjectCode *oc) * Release StablePtrs and free oc->stable_ptrs. * This operation is idempotent. */ -static void freeOcStablePtrs (ObjectCode *oc) +static void freeFEStablePtrs (ForeignExportStablePtr **code_stable_ptrs) { // Release any StablePtrs that were created when this // object module was initialized. ForeignExportStablePtr *fe_ptr, *next; - for (fe_ptr = oc->stable_ptrs; fe_ptr != NULL; fe_ptr = next) { + for (fe_ptr = *code_stable_ptrs; fe_ptr != NULL; fe_ptr = next) { next = fe_ptr->next; freeStablePtr(fe_ptr->stable_ptr); stgFree(fe_ptr); } - oc->stable_ptrs = NULL; + *code_stable_ptrs = NULL; } static void @@ -1308,6 +1313,16 @@ freePreloadObjectFile (ObjectCode *oc) */ void freeObjectCode (ObjectCode *oc) { + if (oc->type == DYNAMIC_OBJECT) { +#if defined(OBJFORMAT_ELF) + ACQUIRE_LOCK(&dl_mutex); + freeNativeCode_ELF(oc); + RELEASE_LOCK(&dl_mutex); +#else + barf("freeObjectCode: This shouldn't happen"); +#endif + } + freePreloadObjectFile(oc); if (oc->symbols != NULL) { @@ -1390,7 +1405,7 @@ void freeObjectCode (ObjectCode *oc) } ObjectCode* -mkOc( pathchar *path, char *image, int imageSize, +mkOc( ObjectType type, pathchar *path, char *image, int imageSize, bool mapped, pathchar *archiveMemberName, int misalignment ) { ObjectCode* oc; @@ -1398,6 +1413,7 @@ mkOc( pathchar *path, char *image, int imageSize, oc = stgMallocBytes(sizeof(ObjectCode), "mkOc(oc)"); oc->info = NULL; + oc->type = type; # if defined(OBJFORMAT_ELF) oc->formatName = "ELF"; @@ -1458,6 +1474,10 @@ mkOc( pathchar *path, char *image, int imageSize, oc->rx_m32 = m32_allocator_new(true); #endif + oc->l_addr = NULL; + oc->nc_ranges = NULL; + oc->dlopen_handle = NULL; + IF_DEBUG(linker, debugBelch("mkOc: done\n")); return oc; } @@ -1585,7 +1605,7 @@ preloadObjectFile (pathchar *path) IF_DEBUG(linker, debugBelch("loadObj: preloaded image at %p\n", (void *) image)); /* FIXME (AP): =mapped= parameter unconditionally set to true */ - oc = mkOc(path, image, fileSize, true, NULL, misalignment); + oc = mkOc(STATIC_OBJECT, path, image, fileSize, true, NULL, misalignment); #if defined(OBJFORMAT_MACHO) if (ocVerifyImage_MachO( oc )) @@ -1620,7 +1640,7 @@ static HsInt loadObj_ (pathchar *path) if (! loadOc(oc)) { // failed; free everything we've allocated removeOcSymbols(oc); - // no need to freeOcStablePtrs, they aren't created until resolveObjs() + // no need to freeFEStablePtrs, they aren't created until resolveObjs() freeObjectCode(oc); return 0; } @@ -1794,7 +1814,8 @@ int ocTryLoad (ObjectCode* oc) { IF_DEBUG(linker, debugBelch("ocTryLoad: ocRunInit start\n")); - loading_obj = oc; // tells foreignExportStablePtr what to do + loading_fe_stable_ptr = &oc->stable_ptrs; + // tells foreignExportStablePtr what to do #if defined(OBJFORMAT_ELF) r = ocRunInit_ELF ( oc ); #elif defined(OBJFORMAT_PEi386) @@ -1804,7 +1825,7 @@ int ocTryLoad (ObjectCode* oc) { #else barf("ocTryLoad: initializers not implemented on this platform"); #endif - loading_obj = NULL; + loading_fe_stable_ptr = NULL; if (!r) { return r; } @@ -1871,7 +1892,7 @@ static HsInt unloadObj_ (pathchar *path, bool just_purge) // These are both idempotent, so in just_purge mode we can later // call unloadObj() to really unload the object. removeOcSymbols(oc); - freeOcStablePtrs(oc); + freeFEStablePtrs(&oc->stable_ptrs); unloadedAnyObj = true; @@ -2003,6 +2024,185 @@ addSection (Section *s, SectionKind kind, SectionAlloc alloc, size, kind )); } + +# if defined(OBJFORMAT_ELF) +static int loadNativeObjCb_(struct dl_phdr_info *info, + size_t _size GNUC3_ATTRIBUTE(__unused__), void *data) { + ObjectCode* nc = (ObjectCode*) data; + + // This logic mimicks _dl_addr_inside_object from glibc + // For reference: + // int + // internal_function + // _dl_addr_inside_object (struct link_map *l, const ElfW(Addr) addr) + // { + // int n = l->l_phnum; + // const ElfW(Addr) reladdr = addr - l->l_addr; + // + // while (--n >= 0) + // if (l->l_phdr[n].p_type == PT_LOAD + // && reladdr - l->l_phdr[n].p_vaddr >= 0 + // && reladdr - l->l_phdr[n].p_vaddr < l->l_phdr[n].p_memsz) + // return 1; + // return 0; + // } + + if ((void*) info->dlpi_addr == nc->l_addr) { + int n = info->dlpi_phnum; + while (--n >= 0) { + if (info->dlpi_phdr[n].p_type == PT_LOAD) { + NativeCodeRange* ncr = + stgMallocBytes(sizeof(NativeCodeRange), "loadNativeObjCb_"); + ncr->start = (void*) ((char*) nc->l_addr + info->dlpi_phdr[n].p_vaddr); + ncr->end = (void*) ((char*) ncr->start + info->dlpi_phdr[n].p_memsz); + + ncr->next = nc->nc_ranges; + nc->nc_ranges = ncr; + } + } + } + return 0; +} + +static void copyErrmsg(char** errmsg_dest, char* errmsg) { + if (errmsg == NULL) errmsg = "loadNativeObj_ELF: unknown error"; + *errmsg_dest = stgMallocBytes(strlen(errmsg)+1, "loadNativeObj_ELF"); + strcpy(*errmsg_dest, errmsg); +} + +// need dl_mutex +static void freeNativeCode_ELF (ObjectCode *nc) { + dlclose(nc->dlopen_handle); + + NativeCodeRange *ncr = nc->nc_ranges; + while (ncr) { + NativeCodeRange* last_ncr = ncr; + ncr = ncr->next; + stgFree(last_ncr); + } +} + +static void * loadNativeObj_ELF (pathchar *path, char **errmsg) +{ + ObjectCode* nc; + void *hdl, *retval; + + IF_DEBUG(linker, debugBelch("loadNativeObj_ELF %" PATH_FMT "\n", path)); + + retval = NULL; + ACQUIRE_LOCK(&dl_mutex); + + ForeignExportStablePtr *fe_sptr = NULL; + loading_fe_stable_ptr = &fe_sptr; + // dlopen will run foreignExportStablePtr adding StablePtrs from this DLL + // to fe_sptr + hdl = dlopen(path, RTLD_NOW|RTLD_LOCAL); + loading_fe_stable_ptr = NULL; + if (hdl == NULL) { + /* dlopen failed; save the message in errmsg */ + copyErrmsg(errmsg, dlerror()); + goto dlopen_fail; + } + + struct link_map *map; + if (dlinfo(hdl, RTLD_DI_LINKMAP, &map) == -1) { + /* dlinfo failed; save the message in errmsg */ + copyErrmsg(errmsg, dlerror()); + goto dlinfo_fail; + } + + nc = mkOc(DYNAMIC_OBJECT, path, NULL, 0, true, NULL, 0); + nc->l_addr = (void*) map->l_addr; + nc->dlopen_handle = hdl; + hdl = NULL; // pass handle ownership to nc + nc->stable_ptrs = fe_sptr; + fe_sptr = NULL; // pass the ownership to nc + + dl_iterate_phdr(loadNativeObjCb_, nc); + if (!nc->nc_ranges) { + copyErrmsg(errmsg, "dl_iterate_phdr failed to find obj"); + goto dl_iterate_phdr_fail; + } + + insertOCSectionIndices(nc); + + nc->next_loaded_object = loaded_objects; + loaded_objects = nc; + + retval = nc->dlopen_handle; + goto success; + +dl_iterate_phdr_fail: + // already have dl_mutex + freeNativeCode_ELF(nc); +dlinfo_fail: + if (hdl) dlclose(hdl); +dlopen_fail: + freeFEStablePtrs(&fe_sptr); +success: + + RELEASE_LOCK(&dl_mutex); + IF_DEBUG(linker, debugBelch("loadNativeObj_ELF result=%p\n", retval)); + + return retval; +} + +# endif + +#define UNUSED(x) (void)(x) + +void * loadNativeObj (pathchar *path, char **errmsg) +{ +#if defined(OBJFORMAT_ELF) + ACQUIRE_LOCK(&linker_mutex); + void *r = loadNativeObj_ELF(path, errmsg); + RELEASE_LOCK(&linker_mutex); + return r; +#else + UNUSED(path); + UNUSED(errmsg); + barf("loadNativeObj: not implemented on this platform"); +#endif +} + +HsInt unloadNativeObj (void *handle) +{ + bool unloadedAnyObj = false; + + IF_DEBUG(linker, debugBelch("unloadNativeObj: %p\n", handle)); + + ObjectCode *prev = NULL, *next; + for (ObjectCode *nc = loaded_objects; nc; nc = next) { + next = nc->next_loaded_object; // we might move nc + + if (nc->type == DYNAMIC_OBJECT && nc->dlopen_handle == handle) { + nc->status = OBJECT_UNLOADED; + n_unloaded_objects += 1; + + // dynamic objects have no symbols + ASSERT(nc->symbols == NULL); + freeFEStablePtrs(&nc->stable_ptrs); + + // Remove object code from root set + if (prev == NULL) { + loaded_objects = nc->next_loaded_object; + } else { + prev->next_loaded_object = nc->next_loaded_object; + } + unloadedAnyObj = true; + } else { + prev = nc; + } + } + + if (unloadedAnyObj) { + return 1; + } else { + errorBelch("unloadObjNativeObj_ELF: can't find `%p' to unload", handle); + return 0; + } +} + /* ----------------------------------------------------------------------------- * Segment management */ ===================================== rts/LinkerInternals.h ===================================== @@ -32,6 +32,13 @@ typedef struct _Symbol SymbolAddr *addr; } Symbol_t; +typedef struct NativeCodeRange_ { + void *start, *end; + + /* Allow a chain of these things */ + struct NativeCodeRange_ *next; +} NativeCodeRange; + /* Indication of section kinds for loaded objects. Needed by the GC for deciding whether or not a pointer on the stack is a code pointer. @@ -169,6 +176,13 @@ typedef struct { #endif } SymbolExtra; +typedef enum { + /* Objects that were loaded by this linker */ + STATIC_OBJECT, + + /* Objects that were loaded by dlopen */ + DYNAMIC_OBJECT, +} ObjectType; /* Top-level structure for an object module. One of these is allocated * for each object file in use. @@ -177,7 +191,8 @@ typedef struct _ObjectCode { OStatus status; pathchar *fileName; int fileSize; /* also mapped image size when using mmap() */ - char* formatName; /* eg "ELF32", "DLL", "COFF", etc. */ + char* formatName; /* e.g. "ELF32", "DLL", "COFF", etc. */ + ObjectType type; /* who loaded this object? */ /* If this object is a member of an archive, archiveMemberName is * like "libarchive.a(object.o)". Otherwise it's NULL. @@ -278,6 +293,19 @@ typedef struct _ObjectCode { * (read-only/executable) code. */ m32_allocator *rw_m32, *rx_m32; #endif + + /* + * The following are only valid if .type == DYNAMIC_OBJECT + */ + + /* handle returned from dlopen */ + void *dlopen_handle; + + /* base virtual address of the loaded code */ + void *l_addr; + + /* virtual memory ranges of loaded code */ + NativeCodeRange *nc_ranges; } ObjectCode; #define OC_INFORMATIVE_FILENAME(OC) \ @@ -286,6 +314,7 @@ typedef struct _ObjectCode { (OC)->fileName \ ) + #if defined(THREADED_RTS) extern Mutex linker_mutex; #endif @@ -371,7 +400,7 @@ resolveSymbolAddr (pathchar* buffer, int size, HsInt isAlreadyLoaded( pathchar *path ); HsInt loadOc( ObjectCode* oc ); -ObjectCode* mkOc( pathchar *path, char *image, int imageSize, +ObjectCode* mkOc( ObjectType type, pathchar *path, char *image, int imageSize, bool mapped, pathchar *archiveMemberName, int misalignment ); ===================================== rts/linker/LoadArchive.c ===================================== @@ -521,7 +521,7 @@ static HsInt loadArchive_ (pathchar *path) pathprintf(archiveMemberName, size, WSTR("%" PATH_FMT "(%.*s)"), path, (int)thisFileNameSize, fileName); - ObjectCode *oc = mkOc(path, image, memberSize, false, archiveMemberName, + ObjectCode *oc = mkOc(STATIC_OBJECT, path, image, memberSize, false, archiveMemberName, misalignment); #if defined(OBJFORMAT_MACHO) ocInit_MachO( oc ); ===================================== rts/sm/Storage.c ===================================== @@ -45,6 +45,7 @@ StgIndStatic *dyn_caf_list = NULL; StgIndStatic *debug_caf_list = NULL; StgIndStatic *revertible_caf_list = NULL; bool keepCAFs; +bool highMemDynamic; W_ large_alloc_lim; /* GC if n_large_blocks in any nursery * reaches this. */ @@ -519,7 +520,7 @@ newCAF(StgRegTable *reg, StgIndStatic *caf) bh = lockCAF(reg, caf); if (!bh) return NULL; - if(keepCAFs) + if(keepCAFs && !(highMemDynamic && (void*) caf > (void*) 0x80000000)) { // Note [dyn_caf_list] // If we are in GHCi _and_ we are using dynamic libraries, @@ -573,6 +574,12 @@ setKeepCAFs (void) keepCAFs = 1; } +void +setHighMemDynamic (void) +{ + highMemDynamic = 1; +} + // An alternate version of newCAF which is used for dynamically loaded // object code in GHCi. In this case we want to retain *all* CAFs in // the object code, because they might be demanded at any time from an ===================================== testsuite/tests/rts/linker/Makefile ===================================== @@ -58,6 +58,23 @@ linker_unload: # -rtsopts causes a warning "$(TEST_HC)" LinkerUnload.hs -package ghc $(filter-out -rtsopts, $(TEST_HC_OPTS)) linker_unload.c -o linker_unload -no-hs-main -optc-Werror ./linker_unload "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" + +.PHONY: linker_unload_native +linker_unload_native: + $(RM) Test.o Test.hi Test.a Test.so Test2.so + "$(TEST_HC)" $(TEST_HC_OPTS) -c Test.hs -v0 -dynamic -fPIC -o Test.a + # only libraries without DT_NEEDED are supported + "$(CC)" -shared -Wl,-Bsymbolic -nostdlib -o Test.so -Wl,-nostdlib \ + -Wl,--whole-archive Test.a + cp Test.so Test2.so + + # -rtsopts causes a warning + "$(TEST_HC)" LinkerUnload.hs -optl-Wl,--export-dynamic -package ghc \ + $(filter-out -rtsopts, $(TEST_HC_OPTS)) linker_unload_native.c \ + -o linker_unload_native -no-hs-main -optc-Werror + ./linker_unload_native \ + "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" + # ----------------------------------------------------------------------------- # Testing failures in the RTS linker. We should be able to repeatedly ===================================== testsuite/tests/rts/linker/all.T ===================================== @@ -84,6 +84,11 @@ test('T5435_dyn_gcc', extra_files(['T5435.hs', 'T5435_gcc.c']) , makefile_test, test('linker_unload', [extra_files(['LinkerUnload.hs', 'Test.hs']), req_rts_linker], makefile_test, ['linker_unload']) + +test('linker_unload_native', + [extra_files(['LinkerUnload.hs', 'Test.hs']), req_rts_linker], + makefile_test, ['linker_unload_native']) + ###################################### test('linker_error1', [extra_files(['linker_error.c']), ===================================== testsuite/tests/rts/linker/linker_unload_native.c ===================================== @@ -0,0 +1,93 @@ +#include "ghcconfig.h" +#include +#include +#include "Rts.h" +#include +#include + +// poke into linker internals +extern void *objects; + +#define ITERATIONS 1000 + +#if defined(mingw32_HOST_OS) +#define OBJPATH L"Test.so" +#define OBJPATH2 L"Test2.so" +#else +#define OBJPATH "./Test.so" +#define OBJPATH2 "./Test2.so" +#endif + +typedef int testfun(int); + +extern void loadPackages(void); + +int main (int argc, char *argv[]) +{ + testfun *f, *f2; + int i, r; + + RtsConfig conf = defaultRtsConfig; + conf.rts_opts_enabled = RtsOptsAll; + // we want to preserve static CAFs and unload dynamic CAFs + conf.keep_cafs = true; + setHighMemDynamic(); + hs_init_ghc(&argc, &argv, conf); + + initLinker_(0); + + loadPackages(); + + for (i=0; i < ITERATIONS; i++) { + char* errmsg; + // load 2 libraries at once + void* handle = loadNativeObj(OBJPATH, &errmsg); + if (!handle) { + errorBelch("loadNativeObj(%s) failed: %s", OBJPATH, errmsg); + free(errmsg); + exit(1); + } + + void* handle2 = loadNativeObj(OBJPATH2, &errmsg); + if (!handle2) { + errorBelch("loadNativeObj(%s) failed: %s", OBJPATH2, errmsg); + free(errmsg); + exit(1); + } +#if LEADING_UNDERSCORE + f = dlsym(handle, "_f"); + f2 = dlsym(handle2, "_f"); +#else + f = dlsym(handle, "f"); + f2 = dlsym(handle2, "f"); +#endif + if (!f) { + errorBelch("dlsym failed"); + exit(1); + } + r = f(3); + if (r != 4) { + errorBelch("call failed; %d", r); + exit(1); + } + if (!f2) { + errorBelch("dlsym failed"); + exit(1); + } + r = f2(3); + if (r != 4) { + errorBelch("call failed; %d", r); + exit(1); + } + unloadNativeObj(handle); + unloadNativeObj(handle2); + performMajorGC(); + printf("%d ", i); + fflush(stdout); + } + + // Verify that Test.so isn't still loaded. + int res = getObjectLoadStatus("Test.so") != OBJECT_NOT_LOADED; + hs_exit(); + exit(res); +} ===================================== testsuite/tests/rts/linker/linker_unload_native.stdout ===================================== @@ -0,0 +1,3 @@ +[1 of 1] Compiling LinkerUnload ( LinkerUnload.hs, LinkerUnload.o ) +Linking linker_unload_native ... +0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 \ No newline at end of file View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/644df1114aef51b2d378ca0d497de599b79b32f9 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/644df1114aef51b2d378ca0d497de599b79b32f9 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 05:24:50 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Mon, 10 Aug 2020 01:24:50 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] Fix prof_info test Message-ID: <5f30da22e79a6_80b3f849c1caa1073105f7@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: 9d8fc068 by Sven Tennie at 2020-08-10T07:24:26+02:00 Fix prof_info test Line number of self defined cost centre changed. - - - - - 1 changed file: - libraries/ghc-heap/tests/prof_info.hs Changes: ===================================== libraries/ghc-heap/tests/prof_info.hs ===================================== @@ -38,7 +38,7 @@ main = do assertEqual (cc_ccID myCostCentre) 1 assertEqual (cc_label myCostCentre) "MyCostCentre" assertEqual (cc_module myCostCentre) "Main" - assertEqual (cc_srcloc myCostCentre) (Just "prof_info.hs:26:39-50") + assertEqual (cc_srcloc myCostCentre) (Just "prof_info.hs:21:39-50") assertEqual (cc_mem_alloc myCostCentre) 0 assertEqual (cc_time_ticks myCostCentre) 0 assertEqual (cc_is_caf myCostCentre) False View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9d8fc06849738ce5d581a29356117d5148aed16b -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9d8fc06849738ce5d581a29356117d5148aed16b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 13:22:17 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 09:22:17 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18422 Message-ID: <5f314a098989b_80b3f848c1e06f473788d6@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T18422 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18422 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 13:24:15 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 09:24:15 -0400 Subject: [Git][ghc/ghc][wip/T18422] llvm-targets: Add i686 targets Message-ID: <5f314a7fd983e_80b3f848a386fc87380475@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18422 at Glasgow Haskell Compiler / GHC Commits: 12dadd04 by Ben Gamari at 2020-08-10T09:24:07-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - 2 changed files: - llvm-targets - utils/llvm-targets/gen-data-layout.sh Changes: ===================================== llvm-targets ===================================== @@ -24,6 +24,9 @@ ,("i386-unknown-linux-gnu", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("i386-unknown-linux-musl", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("i386-unknown-linux", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux-gnu", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux-musl", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("x86_64-unknown-linux-gnu", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ,("x86_64-unknown-linux-musl", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ,("x86_64-unknown-linux", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ===================================== utils/llvm-targets/gen-data-layout.sh ===================================== @@ -59,6 +59,9 @@ TARGETS=( "i386-unknown-linux-gnu" "i386-unknown-linux-musl" "i386-unknown-linux" + "i686-unknown-linux-gnu" + "i686-unknown-linux-musl" + "i686-unknown-linux" "x86_64-unknown-linux-gnu" "x86_64-unknown-linux-musl" "x86_64-unknown-linux" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/12dadd04a09c23c91d7da6f5b17ef78688d93fe7 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/12dadd04a09c23c91d7da6f5b17ef78688d93fe7 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 14:18:00 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 10:18:00 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18545 Message-ID: <5f31571846bfc_80b3f848c1e06f47416038@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T18545 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18545 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 14:25:09 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 10:25:09 -0400 Subject: [Git][ghc/ghc][wip/T18118] testsuite: Add test for #18118 Message-ID: <5f3158c5a974f_80b3f8486a507f47423579@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18118 at Glasgow Haskell Compiler / GHC Commits: 2cdb72a5 by Ben Gamari at 2020-08-10T10:25:01-04:00 testsuite: Add test for #18118 - - - - - 3 changed files: - + testsuite/tests/typecheck/should_compile/T18118.hs - + testsuite/tests/typecheck/should_compile/T18118A.hs - testsuite/tests/typecheck/should_compile/all.T Changes: ===================================== testsuite/tests/typecheck/should_compile/T18118.hs ===================================== @@ -0,0 +1,5 @@ +module T18118 (myfun) where + +import T18118A + +{-# SPECIALISE myfun :: Double #-} ===================================== testsuite/tests/typecheck/should_compile/T18118A.hs ===================================== @@ -0,0 +1,5 @@ +module T18118A where + +myfun :: a +myfun = undefined + ===================================== testsuite/tests/typecheck/should_compile/all.T ===================================== @@ -717,5 +717,6 @@ test('T17775-viewpats-a', normal, compile, ['']) test('T17775-viewpats-b', normal, compile_fail, ['']) test('T17775-viewpats-c', normal, compile_fail, ['']) test('T17775-viewpats-d', normal, compile_fail, ['']) +test('T18118', normal, multimod_compile, ['T18118', '-v0']) test('T18412', normal, compile, ['']) test('T18470', normal, compile, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2cdb72a569f6049a390626bca0dd6e362045ed65 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2cdb72a569f6049a390626bca0dd6e362045ed65 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 14:29:30 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 10:29:30 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/fix-T17516 Message-ID: <5f3159ca4f1e3_80b3f848a372f8c74241e0@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/fix-T17516 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/fix-T17516 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 16:05:10 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Mon, 10 Aug 2020 12:05:10 -0400 Subject: [Git][ghc/ghc][wip/T18126] 30 commits: hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. Message-ID: <5f317036d9e21_80b3f848c1e06f47454614@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18126 at Glasgow Haskell Compiler / GHC Commits: 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - ae1a310c by Simon Peyton Jones at 2020-08-10T15:53:52+01:00 Implement Quick Look impredicativity This patch implements Quick Look impredicativity (#18126), sticking very closely to the design in A quick look at impredicativity, Serrano et al, ICFP 2020 The main change is that a big chunk of GHC.Tc.Gen.Expr has been extracted to two new modules GHC.Tc.Gen.App GHC.Tc.Gen.Head which deal with typechecking n-ary applications, and the head of such applications, respectively. Both contain a good deal of documentation. Three other loosely-related changes are in this patch: * I implemented (partly by accident) point (2) of the accepted GHC proposal "Clean up printing of foralls", namely https://github.com/ghc-proposals/ghc-proposals/blob/ master/proposals/0179-printing-foralls.rst In particular, see Note [TcRnExprMode] in GHC.Tc.Module - :type instantiates /inferred/, but not /specified/, quantifiers - :type +d instantiates /all/ quantifiers - :type +v is killed off * HsRecFld (which the renamer introduces for record field selectors), is now preserved by the typechecker, rather than being rewritten back to HsVar. This is more uniform, and turned out to be more convenient in the new scheme of things. * The GHCi debugger uses a non-standard unification that allows the unification variables to unify with polytypes. We used to hack this by using ImpredicativeTypes, but that doesn't work anymore so I introduces RuntimeUnkTv. See Note [RuntimeUnkTv] in GHC.Runtime.Heap.Inspect WARNING: this patch won't validate on its own. It was too hard to fully disentangle it from the following patch, on type errors and kind generalisation. Changes to tests * Fixes #9730 (test added) * Fixes #7026 (test added) * Fixes most of #8808, except function `g2'` which uses a section (which doesn't play with QL yet -- see #18126) Test added * Fixes #1330. NB Church1.hs subsumes Church2.hs, which is now deleted * Fixes #17332 (test added) * Fixes #4295 * This patch makes typecheck/should_run/T7861 fail. But that turns out to be a pre-existing bug: #18467. So I have just made T7861 into expect_broken(18467) - - - - - 675d82eb by Simon Peyton Jones at 2020-08-10T17:04:12+01:00 Improve kind generalisation, error messages This patch does two things: * It refactors GHC.Tc.Errors a bit. In debugging Quick Look I was forced to look in detail at error messages, and ended up doing a bit of refactoring, esp in mkTyVarEqErr'. It's still quite a mess, but a bit better, I think. * It makes a significant improvement to the kind checking of type and class declarations. Specifically, we now ensure that if kind checking fails with an unsolved constraint, all the skolems are in scope. That wasn't the case before, which led to some obscure error messages; and occasional failures with "no skolem info" (eg #16245). Both of these, and the main Quick Look patch itself, affect a /lot/ of error messages, as you can see from the number of files changed. I've checked them all; I think they are as good or better than before. Smaller things * I documented the various instances of VarBndr better. See Note [The VarBndr tyep and its uses] in GHC.Types.Var * Renamed GHC.Tc.Solver.simpl_top to simplifyTopWanteds * A bit of refactoring in bindExplicitTKTele, to avoid the footwork with Either. Simpler now. * Move promoteTyVar from GHC.Tc.Solver to GHC.Tc.Utils.TcMType Fixes #16245 (comment 211369), memorialised as typeecheck/polykinds/T16245a - - - - - 30 changed files: - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Core/TyCon.hs - compiler/GHC/Driver/CodeOutput.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/HsToCore/Coverage.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Expr.hs-boot - compiler/GHC/HsToCore/ListComp.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Annotation.hs - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Platform/Profile.hs - compiler/GHC/Platform/Ways.hs - compiler/GHC/Rename/Pat.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/567c4d0316c3b75403854b38afe730c9a640327a...675d82ebe58d14ad567ec41a5d66237faebee559 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/567c4d0316c3b75403854b38afe730c9a640327a...675d82ebe58d14ad567ec41a5d66237faebee559 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 16:06:54 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Mon, 10 Aug 2020 12:06:54 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18533 Message-ID: <5f31709e2e257_80b3f849c1caa1074558d6@gitlab.haskell.org.mail> Sebastian Graf pushed new branch wip/T18533 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18533 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 16:07:37 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Mon, 10 Aug 2020 12:07:37 -0400 Subject: [Git][ghc/ghc][wip/T18533] 29 commits: hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. Message-ID: <5f3170c9f0a84_80b3f846910c0c07456020@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18533 at Glasgow Haskell Compiler / GHC Commits: 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - adbe6bf8 by Sebastian Graf at 2020-08-10T18:07:25+02:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - 30 changed files: - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Driver/CodeOutput.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Expr.hs-boot - compiler/GHC/HsToCore/GuardedRHSs.hs - compiler/GHC/HsToCore/ListComp.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/Monad.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Annotation.hs - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Platform/Profile.hs - compiler/GHC/Platform/Ways.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1fb471136c0d9b2b08d31f539b2e873b2741116d...adbe6bf8c5ac6513d5c05076272225915444fe15 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1fb471136c0d9b2b08d31f539b2e873b2741116d...adbe6bf8c5ac6513d5c05076272225915444fe15 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 17:26:41 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 13:26:41 -0400 Subject: [Git][ghc/ghc][wip/T18291] 18 commits: Grammar for types and data/newtype constructors Message-ID: <5f3183517ff10_80b3f848a386fc87472422@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18291 at Glasgow Haskell Compiler / GHC Commits: 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - 3d496ac4 by Ben Gamari at 2020-08-10T13:26:36-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - db7b78d8 by Ben Gamari at 2020-08-10T13:26:36-04:00 testsuite: Add test for #18291 - - - - - 30 changed files: - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/Core/Lint.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/CoreToStg/Prep.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Expr.hs-boot - compiler/GHC/HsToCore/ListComp.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Annotation.hs - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Platform/Profile.hs - compiler/GHC/Platform/Ways.hs - compiler/GHC/StgToCmm/Foreign.hs - compiler/GHC/StgToCmm/Utils.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Unit/State.hs - docs/users_guide/8.12.1-notes.rst → docs/users_guide/9.0.1-notes.rst - docs/users_guide/exts/lambda_case.rst - docs/users_guide/exts/lexical_negation.rst - docs/users_guide/exts/linear_types.rst The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/58c31aa741110776e9357077ab9d3d1f64472838...db7b78d8fab415ee657dc31b5daa9939655b156a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/58c31aa741110776e9357077ab9d3d1f64472838...db7b78d8fab415ee657dc31b5daa9939655b156a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 17:28:42 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 13:28:42 -0400 Subject: [Git][ghc/ghc][wip/unloading] Add loadNativeObj and unloadNativeObj Message-ID: <5f3183ca1c5e7_80b3f846910c0c07473180@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/unloading at Glasgow Haskell Compiler / GHC Commits: 7be3df49 by Ray Shih at 2020-08-10T13:28:12-04:00 Add loadNativeObj and unloadNativeObj (This change is originally written by niteria) This adds two functions: * `loadNativeObj` * `unloadNativeObj` and implements them for Linux. They are useful if you want to load a shared object with Haskell code using the system linker and have GHC call dlclose() after the code is no longer referenced from the heap. Using the system linker allows you to load the shared object above outside the low-mem region. It also loads the DWARF sections in a way that `perf` understands. `dl_iterate_phdr` is what makes this implementation Linux specific. - - - - - 11 changed files: - includes/rts/Linker.h - includes/rts/storage/GC.h - rts/CheckUnload.c - rts/Linker.c - rts/LinkerInternals.h - rts/linker/LoadArchive.c - rts/sm/Storage.c - testsuite/tests/rts/linker/Makefile - testsuite/tests/rts/linker/all.T - + testsuite/tests/rts/linker/linker_unload_native.c - + testsuite/tests/rts/linker/linker_unload_native.stdout Changes: ===================================== includes/rts/Linker.h ===================================== @@ -76,6 +76,19 @@ HsInt loadArchive( pathchar *path ); /* resolve all the currently unlinked objects in memory */ HsInt resolveObjs( void ); +/* Load an .so using the system linker. + Returns a handle that can be passed to dlsym() or NULL on error. + + In the case of error, stores the error message in errmsg. The caller + is responsible for freeing it. */ +void *loadNativeObj( pathchar *path, char **errmsg ); + +/* Mark the .so loaded with the system linker for unloading. + The RTS will unload it when all the references to the .so disappear from + the heap. + Takes the handle returned from loadNativeObj() as an argument. */ +HsInt unloadNativeObj( void *handle ); + /* load a dynamic library */ const char *addDLL( pathchar* dll_name ); ===================================== includes/rts/storage/GC.h ===================================== @@ -230,6 +230,10 @@ void revertCAFs (void); // (preferably use RtsConfig.keep_cafs instead) void setKeepCAFs (void); +// Let the runtime know that all the CAFs in high mem are not +// to be retained. Useful in conjunction with loadNativeObj +void setHighMemDynamic (void); + /* ----------------------------------------------------------------------------- This is the write barrier for MUT_VARs, a.k.a. IORefs. A MUT_VAR_CLEAN object is not on the mutable list; a MUT_VAR_DIRTY ===================================== rts/CheckUnload.c ===================================== @@ -238,21 +238,45 @@ static void reserveOCSectionIndices(OCSectionIndices *s_indices, int len) // state. void insertOCSectionIndices(ObjectCode *oc) { - reserveOCSectionIndices(global_s_indices, oc->n_sections); + // after we finish the section table will no longer be sorted. global_s_indices->sorted = false; - int s_i = global_s_indices->n_sections; - for (int i = 0; i < oc->n_sections; i++) { - if (oc->sections[i].kind != SECTIONKIND_OTHER) { - global_s_indices->indices[s_i].start = (W_)oc->sections[i].start; - global_s_indices->indices[s_i].end = (W_)oc->sections[i].start - + oc->sections[i].size; - global_s_indices->indices[s_i].oc = oc; + if (oc->type == DYNAMIC_OBJECT) { + // First count the ranges + int n_ranges = 0; + for (NativeCodeRange *ncr = oc->nc_ranges; ncr != NULL; ncr = ncr->next) { + n_ranges++; + } + + // Next reserve the appropriate number of table entries... + reserveOCSectionIndices(global_s_indices, n_ranges); + + // Now insert the new ranges... + int s_i = global_s_indices->n_sections; + for (NativeCodeRange *ncr = oc->nc_ranges; ncr != NULL; ncr = ncr->next) { + OCSectionIndex *ent = &global_s_indices->indices[s_i]; + ent->start = (W_)ncr->start; + ent->end = (W_)ncr->end; + ent->oc = oc; s_i++; } - } - global_s_indices->n_sections = s_i; + global_s_indices->n_sections = s_i; + } else { + reserveOCSectionIndices(global_s_indices, oc->n_sections); + int s_i = global_s_indices->n_sections; + for (int i = 0; i < oc->n_sections; i++) { + if (oc->sections[i].kind != SECTIONKIND_OTHER) { + OCSectionIndex *ent = &global_s_indices->indices[s_i]; + ent->start = (W_)oc->sections[i].start; + ent->end = (W_)oc->sections[i].start + oc->sections[i].size; + ent->oc = oc; + s_i++; + } + } + + global_s_indices->n_sections = s_i; + } // Add object to 'objects' list if (objects != NULL) { @@ -443,6 +467,7 @@ void checkUnload() ObjectCode *next = NULL; for (ObjectCode *oc = old_objects; oc != NULL; oc = next) { next = oc->next; + ASSERT(oc->status == OBJECT_UNLOADED); removeOCSectionIndices(s_indices, oc); ===================================== rts/Linker.c ===================================== @@ -63,6 +63,7 @@ # include "linker/Elf.h" # include // regex is already used by dlopen() so this is OK // to use here without requiring an additional lib +# include #elif defined(OBJFORMAT_PEi386) # include "linker/PEi386.h" # include @@ -169,6 +170,8 @@ Mutex linker_mutex; /* Generic wrapper function to try and Resolve and RunInit oc files */ int ocTryLoad( ObjectCode* oc ); +static void freeNativeCode_ELF (ObjectCode *nc); + /* Link objects into the lower 2Gb on x86_64 and AArch64. GHC assumes the * small memory model on this architecture (see gcc docs, * -mcmodel=small). @@ -980,7 +983,9 @@ SymbolAddr* lookupSymbol( SymbolName* lbl ) again in unloadObj(). -------------------------------------------------------------------------- */ -static ObjectCode *loading_obj = NULL; +// volatile works around +// https://sourceware.org/ml/libc-alpha/2013-08/msg00465.html +static ForeignExportStablePtr ** volatile loading_fe_stable_ptr = NULL; StgStablePtr foreignExportStablePtr (StgPtr p) { @@ -989,12 +994,12 @@ StgStablePtr foreignExportStablePtr (StgPtr p) sptr = getStablePtr(p); - if (loading_obj != NULL) { + if (loading_fe_stable_ptr != NULL) { fe_sptr = stgMallocBytes(sizeof(ForeignExportStablePtr), "foreignExportStablePtr"); fe_sptr->stable_ptr = sptr; - fe_sptr->next = loading_obj->stable_ptrs; - loading_obj->stable_ptrs = fe_sptr; + fe_sptr->next = *loading_fe_stable_ptr; + *loading_fe_stable_ptr = fe_sptr; } return sptr; @@ -1267,18 +1272,18 @@ static void removeOcSymbols (ObjectCode *oc) * Release StablePtrs and free oc->stable_ptrs. * This operation is idempotent. */ -static void freeOcStablePtrs (ObjectCode *oc) +static void freeFEStablePtrs (ForeignExportStablePtr **code_stable_ptrs) { // Release any StablePtrs that were created when this // object module was initialized. ForeignExportStablePtr *fe_ptr, *next; - for (fe_ptr = oc->stable_ptrs; fe_ptr != NULL; fe_ptr = next) { + for (fe_ptr = *code_stable_ptrs; fe_ptr != NULL; fe_ptr = next) { next = fe_ptr->next; freeStablePtr(fe_ptr->stable_ptr); stgFree(fe_ptr); } - oc->stable_ptrs = NULL; + *code_stable_ptrs = NULL; } static void @@ -1308,6 +1313,16 @@ freePreloadObjectFile (ObjectCode *oc) */ void freeObjectCode (ObjectCode *oc) { + if (oc->type == DYNAMIC_OBJECT) { +#if defined(OBJFORMAT_ELF) + ACQUIRE_LOCK(&dl_mutex); + freeNativeCode_ELF(oc); + RELEASE_LOCK(&dl_mutex); +#else + barf("freeObjectCode: This shouldn't happen"); +#endif + } + freePreloadObjectFile(oc); if (oc->symbols != NULL) { @@ -1390,7 +1405,7 @@ void freeObjectCode (ObjectCode *oc) } ObjectCode* -mkOc( pathchar *path, char *image, int imageSize, +mkOc( ObjectType type, pathchar *path, char *image, int imageSize, bool mapped, pathchar *archiveMemberName, int misalignment ) { ObjectCode* oc; @@ -1398,6 +1413,7 @@ mkOc( pathchar *path, char *image, int imageSize, oc = stgMallocBytes(sizeof(ObjectCode), "mkOc(oc)"); oc->info = NULL; + oc->type = type; # if defined(OBJFORMAT_ELF) oc->formatName = "ELF"; @@ -1458,6 +1474,10 @@ mkOc( pathchar *path, char *image, int imageSize, oc->rx_m32 = m32_allocator_new(true); #endif + oc->l_addr = NULL; + oc->nc_ranges = NULL; + oc->dlopen_handle = NULL; + IF_DEBUG(linker, debugBelch("mkOc: done\n")); return oc; } @@ -1585,7 +1605,7 @@ preloadObjectFile (pathchar *path) IF_DEBUG(linker, debugBelch("loadObj: preloaded image at %p\n", (void *) image)); /* FIXME (AP): =mapped= parameter unconditionally set to true */ - oc = mkOc(path, image, fileSize, true, NULL, misalignment); + oc = mkOc(STATIC_OBJECT, path, image, fileSize, true, NULL, misalignment); #if defined(OBJFORMAT_MACHO) if (ocVerifyImage_MachO( oc )) @@ -1620,7 +1640,7 @@ static HsInt loadObj_ (pathchar *path) if (! loadOc(oc)) { // failed; free everything we've allocated removeOcSymbols(oc); - // no need to freeOcStablePtrs, they aren't created until resolveObjs() + // no need to freeFEStablePtrs, they aren't created until resolveObjs() freeObjectCode(oc); return 0; } @@ -1794,7 +1814,8 @@ int ocTryLoad (ObjectCode* oc) { IF_DEBUG(linker, debugBelch("ocTryLoad: ocRunInit start\n")); - loading_obj = oc; // tells foreignExportStablePtr what to do + loading_fe_stable_ptr = &oc->stable_ptrs; + // tells foreignExportStablePtr what to do #if defined(OBJFORMAT_ELF) r = ocRunInit_ELF ( oc ); #elif defined(OBJFORMAT_PEi386) @@ -1804,7 +1825,7 @@ int ocTryLoad (ObjectCode* oc) { #else barf("ocTryLoad: initializers not implemented on this platform"); #endif - loading_obj = NULL; + loading_fe_stable_ptr = NULL; if (!r) { return r; } @@ -1871,7 +1892,7 @@ static HsInt unloadObj_ (pathchar *path, bool just_purge) // These are both idempotent, so in just_purge mode we can later // call unloadObj() to really unload the object. removeOcSymbols(oc); - freeOcStablePtrs(oc); + freeFEStablePtrs(&oc->stable_ptrs); unloadedAnyObj = true; @@ -2003,6 +2024,185 @@ addSection (Section *s, SectionKind kind, SectionAlloc alloc, size, kind )); } + +# if defined(OBJFORMAT_ELF) +static int loadNativeObjCb_(struct dl_phdr_info *info, + size_t _size GNUC3_ATTRIBUTE(__unused__), void *data) { + ObjectCode* nc = (ObjectCode*) data; + + // This logic mimicks _dl_addr_inside_object from glibc + // For reference: + // int + // internal_function + // _dl_addr_inside_object (struct link_map *l, const ElfW(Addr) addr) + // { + // int n = l->l_phnum; + // const ElfW(Addr) reladdr = addr - l->l_addr; + // + // while (--n >= 0) + // if (l->l_phdr[n].p_type == PT_LOAD + // && reladdr - l->l_phdr[n].p_vaddr >= 0 + // && reladdr - l->l_phdr[n].p_vaddr < l->l_phdr[n].p_memsz) + // return 1; + // return 0; + // } + + if ((void*) info->dlpi_addr == nc->l_addr) { + int n = info->dlpi_phnum; + while (--n >= 0) { + if (info->dlpi_phdr[n].p_type == PT_LOAD) { + NativeCodeRange* ncr = + stgMallocBytes(sizeof(NativeCodeRange), "loadNativeObjCb_"); + ncr->start = (void*) ((char*) nc->l_addr + info->dlpi_phdr[n].p_vaddr); + ncr->end = (void*) ((char*) ncr->start + info->dlpi_phdr[n].p_memsz); + + ncr->next = nc->nc_ranges; + nc->nc_ranges = ncr; + } + } + } + return 0; +} + +static void copyErrmsg(char** errmsg_dest, char* errmsg) { + if (errmsg == NULL) errmsg = "loadNativeObj_ELF: unknown error"; + *errmsg_dest = stgMallocBytes(strlen(errmsg)+1, "loadNativeObj_ELF"); + strcpy(*errmsg_dest, errmsg); +} + +// need dl_mutex +static void freeNativeCode_ELF (ObjectCode *nc) { + dlclose(nc->dlopen_handle); + + NativeCodeRange *ncr = nc->nc_ranges; + while (ncr) { + NativeCodeRange* last_ncr = ncr; + ncr = ncr->next; + stgFree(last_ncr); + } +} + +static void * loadNativeObj_ELF (pathchar *path, char **errmsg) +{ + ObjectCode* nc; + void *hdl, *retval; + + IF_DEBUG(linker, debugBelch("loadNativeObj_ELF %" PATH_FMT "\n", path)); + + retval = NULL; + ACQUIRE_LOCK(&dl_mutex); + + ForeignExportStablePtr *fe_sptr = NULL; + loading_fe_stable_ptr = &fe_sptr; + // dlopen will run foreignExportStablePtr adding StablePtrs from this DLL + // to fe_sptr + hdl = dlopen(path, RTLD_NOW|RTLD_LOCAL); + loading_fe_stable_ptr = NULL; + if (hdl == NULL) { + /* dlopen failed; save the message in errmsg */ + copyErrmsg(errmsg, dlerror()); + goto dlopen_fail; + } + + struct link_map *map; + if (dlinfo(hdl, RTLD_DI_LINKMAP, &map) == -1) { + /* dlinfo failed; save the message in errmsg */ + copyErrmsg(errmsg, dlerror()); + goto dlinfo_fail; + } + + nc = mkOc(DYNAMIC_OBJECT, path, NULL, 0, true, NULL, 0); + nc->l_addr = (void*) map->l_addr; + nc->dlopen_handle = hdl; + hdl = NULL; // pass handle ownership to nc + nc->stable_ptrs = fe_sptr; + fe_sptr = NULL; // pass the ownership to nc + + dl_iterate_phdr(loadNativeObjCb_, nc); + if (!nc->nc_ranges) { + copyErrmsg(errmsg, "dl_iterate_phdr failed to find obj"); + goto dl_iterate_phdr_fail; + } + + insertOCSectionIndices(nc); + + nc->next_loaded_object = loaded_objects; + loaded_objects = nc; + + retval = nc->dlopen_handle; + goto success; + +dl_iterate_phdr_fail: + // already have dl_mutex + freeNativeCode_ELF(nc); +dlinfo_fail: + if (hdl) dlclose(hdl); +dlopen_fail: + freeFEStablePtrs(&fe_sptr); +success: + + RELEASE_LOCK(&dl_mutex); + IF_DEBUG(linker, debugBelch("loadNativeObj_ELF result=%p\n", retval)); + + return retval; +} + +# endif + +#define UNUSED(x) (void)(x) + +void * loadNativeObj (pathchar *path, char **errmsg) +{ +#if defined(OBJFORMAT_ELF) + ACQUIRE_LOCK(&linker_mutex); + void *r = loadNativeObj_ELF(path, errmsg); + RELEASE_LOCK(&linker_mutex); + return r; +#else + UNUSED(path); + UNUSED(errmsg); + barf("loadNativeObj: not implemented on this platform"); +#endif +} + +HsInt unloadNativeObj (void *handle) +{ + bool unloadedAnyObj = false; + + IF_DEBUG(linker, debugBelch("unloadNativeObj: %p\n", handle)); + + ObjectCode *prev = NULL, *next; + for (ObjectCode *nc = loaded_objects; nc; nc = next) { + next = nc->next_loaded_object; // we might move nc + + if (nc->type == DYNAMIC_OBJECT && nc->dlopen_handle == handle) { + nc->status = OBJECT_UNLOADED; + n_unloaded_objects += 1; + + // dynamic objects have no symbols + ASSERT(nc->symbols == NULL); + freeFEStablePtrs(&nc->stable_ptrs); + + // Remove object code from root set + if (prev == NULL) { + loaded_objects = nc->next_loaded_object; + } else { + prev->next_loaded_object = nc->next_loaded_object; + } + unloadedAnyObj = true; + } else { + prev = nc; + } + } + + if (unloadedAnyObj) { + return 1; + } else { + errorBelch("unloadObjNativeObj_ELF: can't find `%p' to unload", handle); + return 0; + } +} + /* ----------------------------------------------------------------------------- * Segment management */ ===================================== rts/LinkerInternals.h ===================================== @@ -32,6 +32,13 @@ typedef struct _Symbol SymbolAddr *addr; } Symbol_t; +typedef struct NativeCodeRange_ { + void *start, *end; + + /* Allow a chain of these things */ + struct NativeCodeRange_ *next; +} NativeCodeRange; + /* Indication of section kinds for loaded objects. Needed by the GC for deciding whether or not a pointer on the stack is a code pointer. @@ -169,6 +176,13 @@ typedef struct { #endif } SymbolExtra; +typedef enum { + /* Objects that were loaded by this linker */ + STATIC_OBJECT, + + /* Objects that were loaded by dlopen */ + DYNAMIC_OBJECT, +} ObjectType; /* Top-level structure for an object module. One of these is allocated * for each object file in use. @@ -177,7 +191,8 @@ typedef struct _ObjectCode { OStatus status; pathchar *fileName; int fileSize; /* also mapped image size when using mmap() */ - char* formatName; /* eg "ELF32", "DLL", "COFF", etc. */ + char* formatName; /* e.g. "ELF32", "DLL", "COFF", etc. */ + ObjectType type; /* who loaded this object? */ /* If this object is a member of an archive, archiveMemberName is * like "libarchive.a(object.o)". Otherwise it's NULL. @@ -278,6 +293,19 @@ typedef struct _ObjectCode { * (read-only/executable) code. */ m32_allocator *rw_m32, *rx_m32; #endif + + /* + * The following are only valid if .type == DYNAMIC_OBJECT + */ + + /* handle returned from dlopen */ + void *dlopen_handle; + + /* base virtual address of the loaded code */ + void *l_addr; + + /* virtual memory ranges of loaded code */ + NativeCodeRange *nc_ranges; } ObjectCode; #define OC_INFORMATIVE_FILENAME(OC) \ @@ -286,6 +314,7 @@ typedef struct _ObjectCode { (OC)->fileName \ ) + #if defined(THREADED_RTS) extern Mutex linker_mutex; #endif @@ -371,7 +400,7 @@ resolveSymbolAddr (pathchar* buffer, int size, HsInt isAlreadyLoaded( pathchar *path ); HsInt loadOc( ObjectCode* oc ); -ObjectCode* mkOc( pathchar *path, char *image, int imageSize, +ObjectCode* mkOc( ObjectType type, pathchar *path, char *image, int imageSize, bool mapped, pathchar *archiveMemberName, int misalignment ); ===================================== rts/linker/LoadArchive.c ===================================== @@ -521,7 +521,7 @@ static HsInt loadArchive_ (pathchar *path) pathprintf(archiveMemberName, size, WSTR("%" PATH_FMT "(%.*s)"), path, (int)thisFileNameSize, fileName); - ObjectCode *oc = mkOc(path, image, memberSize, false, archiveMemberName, + ObjectCode *oc = mkOc(STATIC_OBJECT, path, image, memberSize, false, archiveMemberName, misalignment); #if defined(OBJFORMAT_MACHO) ocInit_MachO( oc ); ===================================== rts/sm/Storage.c ===================================== @@ -45,6 +45,7 @@ StgIndStatic *dyn_caf_list = NULL; StgIndStatic *debug_caf_list = NULL; StgIndStatic *revertible_caf_list = NULL; bool keepCAFs; +bool highMemDynamic; W_ large_alloc_lim; /* GC if n_large_blocks in any nursery * reaches this. */ @@ -519,7 +520,7 @@ newCAF(StgRegTable *reg, StgIndStatic *caf) bh = lockCAF(reg, caf); if (!bh) return NULL; - if(keepCAFs) + if(keepCAFs && !(highMemDynamic && (void*) caf > (void*) 0x80000000)) { // Note [dyn_caf_list] // If we are in GHCi _and_ we are using dynamic libraries, @@ -573,6 +574,12 @@ setKeepCAFs (void) keepCAFs = 1; } +void +setHighMemDynamic (void) +{ + highMemDynamic = 1; +} + // An alternate version of newCAF which is used for dynamically loaded // object code in GHCi. In this case we want to retain *all* CAFs in // the object code, because they might be demanded at any time from an ===================================== testsuite/tests/rts/linker/Makefile ===================================== @@ -58,6 +58,23 @@ linker_unload: # -rtsopts causes a warning "$(TEST_HC)" LinkerUnload.hs -package ghc $(filter-out -rtsopts, $(TEST_HC_OPTS)) linker_unload.c -o linker_unload -no-hs-main -optc-Werror ./linker_unload "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" + +.PHONY: linker_unload_native +linker_unload_native: + $(RM) Test.o Test.hi Test.a Test.so Test2.so + "$(TEST_HC)" $(TEST_HC_OPTS) -c Test.hs -v0 -dynamic -fPIC -o Test.a + # only libraries without DT_NEEDED are supported + "$(CC)" -shared -Wl,-Bsymbolic -nostdlib -o Test.so -Wl,-nostdlib \ + -Wl,--whole-archive Test.a + cp Test.so Test2.so + + # -rtsopts causes a warning + "$(TEST_HC)" LinkerUnload.hs -optl-Wl,--export-dynamic -package ghc \ + $(filter-out -rtsopts, $(TEST_HC_OPTS)) linker_unload_native.c \ + -o linker_unload_native -no-hs-main -optc-Werror + ./linker_unload_native \ + "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" + # ----------------------------------------------------------------------------- # Testing failures in the RTS linker. We should be able to repeatedly ===================================== testsuite/tests/rts/linker/all.T ===================================== @@ -85,6 +85,12 @@ test('linker_unload', [extra_files(['LinkerUnload.hs', 'Test.hs']), req_rts_linker], makefile_test, ['linker_unload']) +test('linker_unload_native', + [extra_files(['LinkerUnload.hs', 'Test.hs']), req_rts_linker, + when(opsys('darwin') or opsys('mingw32'), skip)], + makefile_test, ['linker_unload_native']) + + ###################################### test('linker_error1', [extra_files(['linker_error.c']), ignore_stderr], makefile_test, ['linker_error1']) ===================================== testsuite/tests/rts/linker/linker_unload_native.c ===================================== @@ -0,0 +1,93 @@ +#include "ghcconfig.h" +#include +#include +#include "Rts.h" +#include +#include + +// poke into linker internals +extern void *objects; + +#define ITERATIONS 1000 + +#if defined(mingw32_HOST_OS) +#define OBJPATH L"Test.so" +#define OBJPATH2 L"Test2.so" +#else +#define OBJPATH "./Test.so" +#define OBJPATH2 "./Test2.so" +#endif + +typedef int testfun(int); + +extern void loadPackages(void); + +int main (int argc, char *argv[]) +{ + testfun *f, *f2; + int i, r; + + RtsConfig conf = defaultRtsConfig; + conf.rts_opts_enabled = RtsOptsAll; + // we want to preserve static CAFs and unload dynamic CAFs + conf.keep_cafs = true; + setHighMemDynamic(); + hs_init_ghc(&argc, &argv, conf); + + initLinker_(0); + + loadPackages(); + + for (i=0; i < ITERATIONS; i++) { + char* errmsg; + // load 2 libraries at once + void* handle = loadNativeObj(OBJPATH, &errmsg); + if (!handle) { + errorBelch("loadNativeObj(%s) failed: %s", OBJPATH, errmsg); + free(errmsg); + exit(1); + } + + void* handle2 = loadNativeObj(OBJPATH2, &errmsg); + if (!handle2) { + errorBelch("loadNativeObj(%s) failed: %s", OBJPATH2, errmsg); + free(errmsg); + exit(1); + } +#if LEADING_UNDERSCORE + f = dlsym(handle, "_f"); + f2 = dlsym(handle2, "_f"); +#else + f = dlsym(handle, "f"); + f2 = dlsym(handle2, "f"); +#endif + if (!f) { + errorBelch("dlsym failed"); + exit(1); + } + r = f(3); + if (r != 4) { + errorBelch("call failed; %d", r); + exit(1); + } + if (!f2) { + errorBelch("dlsym failed"); + exit(1); + } + r = f2(3); + if (r != 4) { + errorBelch("call failed; %d", r); + exit(1); + } + unloadNativeObj(handle); + unloadNativeObj(handle2); + performMajorGC(); + printf("%d ", i); + fflush(stdout); + } + + // Verify that Test.so isn't still loaded. + int res = getObjectLoadStatus("Test.so") != OBJECT_NOT_LOADED; + hs_exit(); + exit(res); +} ===================================== testsuite/tests/rts/linker/linker_unload_native.stdout ===================================== @@ -0,0 +1,3 @@ +[1 of 1] Compiling LinkerUnload ( LinkerUnload.hs, LinkerUnload.o ) +Linking linker_unload_native ... +0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 \ No newline at end of file View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/7be3df495f49d5faaf137f21e09edf00a980c5ef -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/7be3df495f49d5faaf137f21e09edf00a980c5ef You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 17:31:09 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 13:31:09 -0400 Subject: [Git][ghc/ghc][wip/T18545] parser: Suggest ImportQualifiedPost in prepositive import warning Message-ID: <5f31845d2568c_80b3f8496224a7074751a2@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18545 at Glasgow Haskell Compiler / GHC Commits: 7632c73a by Ben Gamari at 2020-08-10T13:31:03-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 2 changed files: - compiler/GHC/Parser/PostProcess.hs - testsuite/tests/module/mod184.stderr Changes: ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -2610,6 +2610,7 @@ warnPrepositiveQualifiedModule span = <+> text "in prepositive position" $$ text "Suggested fix: place " <+> quotes (text "qualified") <+> text "after the module name instead." + $$ text "To allow this, enable language extension 'ImportQualifiedPost'" failOpNotEnabledImportQualifiedPost :: SrcSpan -> P () failOpNotEnabledImportQualifiedPost loc = addError loc msg ===================================== testsuite/tests/module/mod184.stderr ===================================== @@ -1,3 +1,4 @@ mod184.hs:6:8: warning: [-Wprepositive-qualified-module] Found ‘qualified’ in prepositive position Suggested fix: place ‘qualified’ after the module name instead. + To allow this, enable language extension 'ImportQualifiedPost' View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/7632c73a86cffae9090cb7f778148746b8d09aca -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/7632c73a86cffae9090cb7f778148746b8d09aca You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 18:23:25 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Mon, 10 Aug 2020 14:23:25 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 5 commits: Api Annotations : Adjust SrcSpans for prefix bang (!). Message-ID: <5f31909d9767c_80b3f8468e02b5474801f5@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 1f57f526 by Felix Yan at 2020-08-10T14:23:18-04:00 Correct a typo in ghc.mk - - - - - 1358f83f by Felix Yan at 2020-08-10T14:23:19-04:00 Add a closing parenthesis too - - - - - 01655ec5 by Sylvain Henry at 2020-08-10T14:23:23-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - 5 changed files: - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Utils/Misc.hs - testsuite/tests/ghc-api/annotations/Makefile - testsuite/tests/ghc-api/annotations/T10358.stdout - utils/ghc-pkg/ghc.mk Changes: ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -1201,13 +1201,14 @@ makeFunBind fn ms checkPatBind :: LPat GhcPs -> Located (a,GRHSs GhcPs (LHsExpr GhcPs)) -> P ([AddAnn],HsBind GhcPs) -checkPatBind lhs (L match_span (_,grhss)) +checkPatBind lhs (L rhs_span (_,grhss)) | BangPat _ p <- unLoc lhs , VarPat _ v <- unLoc p = return ([], makeFunBind v [L match_span (m v)]) where + match_span = combineSrcSpans (getLoc lhs) rhs_span m v = Match { m_ext = noExtField - , m_ctxt = FunRhs { mc_fun = L (getLoc lhs) (unLoc v) + , m_ctxt = FunRhs { mc_fun = v , mc_fixity = Prefix , mc_strictness = SrcStrict } , m_pats = [] ===================================== compiler/GHC/Utils/Misc.hs ===================================== @@ -6,6 +6,7 @@ {-# LANGUAGE BangPatterns #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE MagicHash #-} {-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} @@ -774,12 +775,18 @@ dropList _ xs@[] = xs dropList (_:xs) (_:ys) = dropList xs ys +-- | Given two lists xs and ys, return `splitAt (length xs) ys`. splitAtList :: [b] -> [a] -> ([a], [a]) -splitAtList [] xs = ([], xs) -splitAtList _ xs@[] = (xs, xs) -splitAtList (_:xs) (y:ys) = (y:ys', ys'') - where - (ys', ys'') = splitAtList xs ys +splitAtList xs ys = go 0# xs ys + where + -- we are careful to avoid allocating when there are no leftover + -- arguments: in this case we can return "ys" directly (cf #18535) + -- + -- We make `xs` strict because in the general case `ys` isn't `[]` so we + -- will have to evaluate `xs` anyway. + go _ !_ [] = (ys, []) -- length ys <= length xs + go n [] bs = (take (I# n) ys, bs) -- = splitAt n ys + go n (_:as) (_:bs) = go (n +# 1#) as bs -- drop from the end of a list dropTail :: Int -> [a] -> [a] ===================================== testsuite/tests/ghc-api/annotations/Makefile ===================================== @@ -39,7 +39,8 @@ listcomps: .PHONY: T10358 T10358: - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358.hs + # Ignore result code, we have an unattached (superfluous) AnnBang + - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358.hs .PHONY: T10396 T10396: ===================================== testsuite/tests/ghc-api/annotations/T10358.stdout ===================================== @@ -1,5 +1,5 @@ ---Unattached Annotation Problems (should be empty list)--- -[] +[(AnnBang, Test10358.hs:5:19)] ---Ann before enclosing span problem (should be empty list)--- [ ===================================== utils/ghc-pkg/ghc.mk ===================================== @@ -61,8 +61,8 @@ endif $(eval $(call build-prog,utils/ghc-pkg,dist,0)) # ghc-pkg uses `settings` to figure out the target platform to figure out a -# subdirectory for the user pkg db. So make sure `settings` exists (alterative -# is to specify global package db only. +# subdirectory for the user pkg db. So make sure `settings` exists (alternative +# is to specify global package db only). $(ghc-pkg_INPLACE) : | $(INPLACE_PACKAGE_CONF)/. $(INPLACE_LIB)/settings # ----------------------------------------------------------------------------- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/090ca60400e8ecdcc4b35b28cf60d662b760a714...01655ec5a1c858c3fa36e295a63e854b8acce184 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/090ca60400e8ecdcc4b35b28cf60d662b760a714...01655ec5a1c858c3fa36e295a63e854b8acce184 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 19:24:03 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 15:24:03 -0400 Subject: [Git][ghc/ghc][wip/gc/parallel-marking] 910 commits: doc(List): Add examples to GHC.List Message-ID: <5f319ed38ff74_80b8ca3ed07490699@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/gc/parallel-marking at Glasgow Haskell Compiler / GHC Commits: 70a90110 by Julien Debon at 2020-02-20T21:19:27-05:00 doc(List): Add examples to GHC.List * Add examples * Cleanup documentation * Clarify merge process and Marge bot - - - - - c8439fc7 by Peter Trommler at 2020-02-20T21:20:05-05:00 Fix testsuite on powerpc64le Remove expect broken on recomp tests, #11260 was closed by !2264 and #11323 most likely by !2264 as well. GHCi scripts tests work on GHCi but not the external interpreter, adjust test configuration accordingly. Fixes unexpected passes. Mark test requiring DWARF expect fail on powerpc64[le] for #11261. - - - - - 65b7256a by Ömer Sinan Ağacan at 2020-02-20T21:20:45-05:00 Use concatMap(M) instead of `concat . map` and the monadic variant - - - - - 8b76d457 by Roland Senn at 2020-02-20T21:21:28-05:00 Fix #17832: Weird handling of exports named main in 8.10-rc1 Switching from `lookupGlobalOccRn_maybe` to `lookupInfoOccRn` to check whether a `main` function is in scope. Unfortunately `lookupGlobalOccRn_maybe` complains if there are multiple `main` functions in scope. - - - - - 466e1ad5 by Krzysztof Gogolewski at 2020-02-20T21:22:11-05:00 Use TTG for HsSplicedT constructor The constructor HsSplicedT occurs only in the GhcTc pass. This enforces this fact statically via TTG. - - - - - 4e622fca by Alexis King at 2020-02-20T21:22:49-05:00 Normalize types when dropping absent arguments from workers fixes #17852 - - - - - a533e547 by Adam Sandberg Eriksson at 2020-02-20T21:23:31-05:00 Mention users guide and release notes in merge request template - - - - - 05251b17 by Ben Gamari at 2020-02-20T21:24:08-05:00 gitlab-ci: Fix typo in BIN_DIST_PREP_TAR_COMP variable name - - - - - f44c7e67 by Ben Gamari at 2020-02-20T21:24:46-05:00 gitlab-ci: Avoid duplicating ~/.cabal contents with every build Previously our attempt to cache the cabal store would `cp cabal-cache ~/.cabal`. However, if the latter already existed this meant that we would end up with ~/.cabal/cabal-cache. Not only would this not help caching but it would exponentially grow the size of ~/.cabal. Not good! - - - - - c5ec9965 by Ben Gamari at 2020-02-20T21:56:13-05:00 GHC.Hs.Extension: Use Type instead of * - - - - - 89cb4cc4 by Ben Gamari at 2020-02-20T21:56:13-05:00 Use Type instead of * in GHC - - - - - 04eb0d6c by Ben Gamari at 2020-02-20T21:56:13-05:00 Enable -Wstar-is-type in -Wall As noted in [proposal 0143][proposal] this is supposed to happen in 8.12. Also fix an incorrect claim in the users guide that -Wstar-is-type is enabled by default. [proposal]: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0143-remove-star-kind.rst - - - - - 6de966f1 by Andreas Klebinger at 2020-02-20T21:56:15-05:00 Fix #17724 by having occAnal preserve used bindings. It sometimes happened that occAnal would remove bindings as dead code by relying on bindings to be in dependency order. The fix was contributed by SPJ. - - - - - abd7f962 by Ben Gamari at 2020-02-20T21:56:15-05:00 users-guide: Mention dependency on `exceptions` in release notes Fixes #17845. - - - - - 58175379 by Sylvain Henry at 2020-02-20T21:56:20-05:00 Hadrian: minor GMP refactoring Somehow I forgot to totally remove `gmpContext` in d7029cc09edc052c2f97effe33233c53340fcce0. This patch fixes it and adds some additional comments. - - - - - 33fa8d94 by Ryan Scott at 2020-02-20T21:56:21-05:00 Generalize liftData to work over any Quote (#17857) The Overloaded Quotations proposal generalized the type of `lift` to work over any `Quote`, but not the type of `liftData`, leading to #17857. Thankfully, generalizing `liftData` is extremely straightforward. Fixes #17857. - - - - - 3cea6795 by Sylvain Henry at 2020-02-20T21:56:23-05:00 Make: fix sdist target (#17848) - - - - - e2cce997 by Sylvain Henry at 2020-02-20T21:56:23-05:00 Hadrian: fix source-dist target (#17849) - - - - - 0a4c89b2 by Matthew Pickering at 2020-02-21T20:44:45-05:00 Special case `mkTyConApp liftedTypeKind []` We really need to make sure that these are shared because otherwise GHC will allocate thousands of identical `TyConApp` nodes. See #17292 ------------------------- Metric Decrease: haddock.Cabal T14683 ------------------------- - - - - - 0482f58a by Matthew Pickering at 2020-02-21T20:45:21-05:00 TH: wrapGenSyns, don't split the element type too much The invariant which allowed the pervious method of splitting the type of the body to find the type of the elements didn't work in the new overloaded quotation world as the type can be something like `WriterT () m a` rather than `Q a` like before. Fixes #17839 - - - - - be7068a6 by Vladislav Zavialov at 2020-02-21T20:45:59-05:00 Parser API annotations: RealSrcLoc During parsing, GHC collects lexical information about AST nodes and stores it in a map. It is needed to faithfully restore original source code, e.g. compare these expressions: a = b a = b The position of the equality sign is not recorded in the AST, so it must be stored elsewhere. This system is described in Note [Api annotations]. Before this patch, the mapping was represented by: Map (SrcSpan, AnnKeywordId) SrcSpan After this patch, the mapping is represented by: Map (RealSrcSpan, AnnKeywordId) RealSrcSpan The motivation behind this change is to avoid using the Ord SrcSpan instance (required by Map here), as it interferes with #17632 (see the discussion there). SrcSpan is isomorphic to Either String RealSrcSpan, but we shouldn't use those strings as Map keys. Those strings are intended as hints to the user, e.g. "<interactive>" or "<compiler-generated code>", so they are not a valid way to identify nodes in the source code. - - - - - 240f5bf6 by Sylvain Henry at 2020-02-21T20:46:40-05:00 Modules: Driver (#13009) submodule updates: nofib, haddock - - - - - 9d094111 by Sylvain Henry at 2020-02-21T20:47:19-05:00 Hadrian: `docs` rule needs `configure` (#17840) - - - - - 1674353a by Ben Gamari at 2020-02-23T17:31:19-05:00 fs: Port fixes from ghc-jailbreak repository * Override rename, unlink, and remove * Factor out wchar conversion - - - - - 853210f2 by Adam Sandberg Ericsson at 2020-02-23T17:32:03-05:00 show gcc linker options in configure summary - - - - - 2831544a by Adam Sandberg Ericsson at 2020-02-23T17:32:44-05:00 hadrian: docs depend on stage1 ghc - - - - - 1d9df9e0 by Adam Sandberg Ericsson at 2020-02-23T17:33:23-05:00 ci: after 5ce63d52fed the linux bindist for doc-tarball has changed name - - - - - 26e8fff3 by Vladislav Zavialov at 2020-02-24T02:05:30-05:00 Remove Ord SrcLoc, Ord SrcSpan Before this patch, GHC relied on Ord SrcSpan to identify source elements, by using SrcSpan as Map keys: blackList :: Map SrcSpan () -- compiler/GHC/HsToCore/Coverage.hs instanceMap :: Map SrcSpan Name -- compiler/GHC/HsToCore/Docs.hs Firstly, this design is not valid in presence of UnhelpfulSpan, as it distinguishes between UnhelpfulSpan "X" and UnhelpfulSpan "Y", but those strings are messages for the user, unfit to serve as identifiers for source elements. Secondly, this design made it hard to extend SrcSpan with additional data. Recall that the definition of SrcSpan is: data SrcSpan = RealSrcSpan !RealSrcSpan | UnhelpfulSpan !FastString Say we want to extend the RealSrcSpan constructor with additional information: data SrcSpan = RealSrcSpan !RealSrcSpan !AdditionalInformation | UnhelpfulSpan !FastString getAdditionalInformation :: SrcSpan -> AdditionalInformation getAdditionalInformation (RealSrcSpan _ a) = a Now, in order for Map SrcSpan to keep working correctly, we must *ignore* additional information when comparing SrcSpan values: instance Ord SrcSpan where compare (RealSrcSpan r1 _) (RealSrcSpan r2 _) = compare r1 r2 ... However, this would violate an important law: a == b therefore f a == f b Ignoring AdditionalInformation in comparisons would mean that with f=getAdditionalInformation, the law above does not hold. A more robust design is to avoid Ord SrcSpan altogether, which is what this patch implements. The mappings are changed to use RealSrcSpan instead: blackList :: Set RealSrcSpan -- compiler/GHC/HsToCore/Coverage.hs instanceMap :: Map RealSrcSpan Name -- compiler/GHC/HsToCore/Docs.hs All SrcSpan comparisons are now done with explicit comparison strategies: SrcLoc.leftmost_smallest SrcLoc.leftmost_largest SrcLoc.rightmost_smallest These strategies are not subject to the law mentioned above and can easily discard both the string stored in UnhelpfulSpan and AdditionalInformation. Updates haddock submodule. - - - - - 5aa6c188 by Ben Gamari at 2020-02-24T02:06:09-05:00 users-guide: Shuffle text - - - - - e3f17413 by Ben Gamari at 2020-02-24T02:06:09-05:00 users-guide: Drop old release notes - - - - - 84dd9610 by Ben Gamari at 2020-02-24T02:06:09-05:00 Bump directory submodule to 1.3.6.0 - - - - - e295a024 by Stefan Pavikevik at 2020-02-24T20:53:44-05:00 check for safe arguments, raising error when invalid (fix #17720) - - - - - 354e2787 by Krzysztof Gogolewski at 2020-02-24T20:54:35-05:00 Comments, small refactor * Remove outdated Note [HsForAllTy tyvar binders] and [Context quantification]. Since the wildcard refactor 1e041b7382, HsForAllTy no longer has an flag controlling explicity. The field `hsq_implicit` is gone too. The current situation is covered by Note [HsType binders] which is already linked from LHsQTyVars. * Small refactor in CoreLint, extracting common code to a function * Remove "not so sure about WpFun" in TcEvidence, per Richard's comment https://gitlab.haskell.org/ghc/ghc/merge_requests/852#note_223226 * Use mkIfThenElse in Foreign/Call, as it does exactly what we need. - - - - - 1b1067d1 by Sylvain Henry at 2020-02-24T20:55:25-05:00 Modules: CmmToAsm (#13009) - - - - - 621468f6 by Alexis King at 2020-02-26T15:08:09-05:00 Treat coercions as arguments for floating and inlining This reverts commit 8924224ecfa065ebc67b96a90d01cf9d2edd0e77 and fixes #17787. - - - - - def486c9 by Ben Gamari at 2020-02-26T15:08:47-05:00 hadrian: Allow libnuma library path to be specified - - - - - ed03d4e7 by Ben Gamari at 2020-02-26T15:08:47-05:00 hadrian: Refactor gmp arguments Move the gmp configuration to its own binding. - - - - - 09b88384 by Ben Gamari at 2020-02-26T15:08:47-05:00 hadrian: Tell Cabal about integer-gmp library location - - - - - 161e08c5 by Krzysztof Gogolewski at 2020-02-26T15:09:30-05:00 Remove dead code * FailablePattern can no longer be created since ab51bee40c82 Therefore, Opt_WarnMissingMonadFailInstances has no effect anymore. * XWrap is no longer used, it was moved to an extension field - - - - - e0d09db3 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Use 8.8.3 to bootstrap on Windows This should fix #17861. - - - - - 972bcf3a by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Fix symlink test Needs to `write` bytes, not str. - - - - - 273e60de by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Add shell subcommand for debugging within CI environment - - - - - 43b13ed3 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Fix colors on Darwin Darwin sh doesn't support \e. - - - - - 217546a7 by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Flush stdout buffers in InitEventLogging Otherwise we are sensitive to libc's buffering strategy. Similar to the issue fixed in 543dfaab166c81f46ac4af76918ce32190aaab22. - - - - - c7d4fa55 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Add run_hadrian subcommand I've ruined two trees already by failing to pass --flavour to hadrian. Let's factor this out so it can be reused during troubleshooting. - - - - - 7dc54873 by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Allow tests to be marked as broken on the command line This allows us to work-around distribution-specific breakage easily. - - - - - 25e2458e by Ben Gamari at 2020-02-26T15:10:09-05:00 hadrian: Add --broken-test flag This exposes the flag of the same name supported by the testsuite driver. - - - - - 55769996 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Mark some tests as broken on Alpine - - - - - 9ee7f87d by Ben Gamari at 2020-02-26T15:10:09-05:00 SysTools: Don't use process jobs if they are broken - - - - - bfaa3961 by Ben Gamari at 2020-02-26T15:10:09-05:00 Bump hsc2hs submodule Fixes name of C compiler. - - - - - b2b49a0a by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Make hasMetricsFile RHS more descriptive - - - - - 817f93ea by Sylvain Henry at 2020-02-26T15:10:58-05:00 Modules: Core (#13009) Update haddock submodule - - - - - 74311e10 by Sebastian Graf at 2020-02-27T16:22:45-05:00 PmCheck: Implement Long-distance information with Covered sets Consider ```hs data T = A | B | C f :: T -> Int f A = 1 f x = case x of A -> 2 B -> 3 C -> 4 ``` Clearly, the RHS returning 2 is redundant. But we don't currently see that, because our approximation to the covered set of the inner case expression just picks up the positive information from surrounding pattern matches. It lacks the context sensivity that `x` can't be `A` anymore! Therefore, we adopt the conceptually and practically superior approach of reusing the covered set of a particular GRHS from an outer pattern match. In this case, we begin checking the `case` expression with the covered set of `f`s second clause, which encodes the information that `x` can't be `A` anymore. After this MR, we will successfully warn about the RHS returning 2 being redundant. Perhaps surprisingly, this was a great simplification to the code of both the coverage checker and the desugarer. Found a redundant case alternative in `unix` submodule, so we have to bump it with a fix. Metric Decrease: T12227 - - - - - 59c023ba by Adam Sandberg Ericsson at 2020-02-27T16:23:25-05:00 configure: correctly generate LIBRARY_template_haskell_VERSION - - - - - 9be82389 by Krzysztof Gogolewski at 2020-02-28T02:35:35-05:00 boot: Remove remote origin check Previously, we used relative paths in submodules. When cloning from GitHub, they had to be manually tweaked. Since a76b233d we use absolute paths, so this workaround can be removed. - - - - - f4b6b594 by Ben Gamari at 2020-02-28T02:36:12-05:00 nonmoving: Fix marking in compact regions Previously we were tracing the object we were asked to mark, even if it lives in a compact region. However, there is no need to do this; we need only to mark the region itself as live. I have seen a segfault due to this due to the concurrent mark seeing a an object in the process of being compacted by the mutator. - - - - - f97d1fb6 by Alp Mestanogullari at 2020-02-28T02:36:59-05:00 base: use an explicit import list in System.Environment.ExecutablePath This was making -Werror builds fail on Windows (at least with Hadrian). - - - - - 66f5d6d6 by Simon Peyton Jones at 2020-02-28T22:03:23-05:00 Improve error handling for VTA + deferred type errors This fixes #17792 See Note [VTA for out-of-scope functions] in TcExpr - - - - - 37f12603 by Ilias Tsitsimpis at 2020-02-28T22:04:04-05:00 llvm-targets: Add arm-unknown-linux-gnueabi Add arm-unknown-linux-gnueabi, which is used by Debian's ARM EABI port (armel), as an LLVM target. - - - - - 327b29e1 by Vladislav Zavialov at 2020-02-29T05:06:31-05:00 Monotonic locations (#17632) When GHC is parsing a file generated by a tool, e.g. by the C preprocessor, the tool may insert #line pragmas to adjust the locations reported to the user. As the result, the locations recorded in RealSrcLoc are not monotonic. Elements that appear later in the StringBuffer are not guaranteed to have a higher line/column number. In fact, there are no guarantees whatsoever, as #line pragmas can arbitrarily modify locations. This lack of guarantees makes ideas such as #17544 infeasible. This patch adds an additional bit of information to every SrcLoc: newtype BufPos = BufPos { bufPos :: Int } A BufPos represents the location in the StringBuffer, unaffected by any pragmas. Updates haddock submodule. Metric Increase: haddock.Cabal haddock.base haddock.compiler MultiLayerModules Naperian parsing001 T12150 - - - - - 99d2de86 by Ben Gamari at 2020-02-29T05:07:10-05:00 plugins: Ensure that loadInterface plugins can see annotations loadInterface replaces the `mi_decls`, `mi_insts`, `mi_fam_insts`, `mi_rules`, `mi_anns` fields of ModIface with `undefined` before inserting the interface into the EPS. However, we still want to give loadInterface plugins access to these fields. Consequently, we want to pass the unmodified `ModIface` the plugin. - - - - - a999ee96 by Xavier Denis at 2020-02-29T05:07:50-05:00 Rename ghci.sh and build.sh to ghci and build respectively Convert hadrian buildscripts to unsuffixed, dashed form final cleanups - - - - - b5fb58fd by Ömer Sinan Ağacan at 2020-02-29T05:08:36-05:00 Document and refactor a few things around bitmap scavenging - Added a few comments in StgPAP - Added a few comments and assertions in scavenge_small_bitmap and walk_large_bitmap - Did tiny refactor in GHC.Data.Bitmap: added some comments, deleted dead code, used PlatformWordSize type. - - - - - 18757cab by Sylvain Henry at 2020-02-29T05:09:25-05:00 Refactor runtime interpreter code In #14335 we want to be able to use both the internal interpreter (for the plugins) and the external interpreter (for TH and GHCi) at the same time. This patch performs some preliminary refactoring: the `hsc_interp` field of HscEnv replaces `hsc_iserv` and is now used to indicate which interpreter (internal, external) to use to execute TH and GHCi. Opt_ExternalInterpreter flag and iserv options in DynFlags are now queried only when we set the session DynFlags. It should help making GHC multi-target in the future by selecting an interpreter according to the selected target. - - - - - b86a6395 by Adam Sandberg Ericsson at 2020-02-29T05:10:06-05:00 docs: correct relative links to haddocks from users guide (fixes #17866) - - - - - 0f55df7f by Adam Sandberg Ericsson at 2020-02-29T05:10:06-05:00 docs: correct link to th haddocks from users guide - - - - - 252e5117 by Jean-Baptiste Mazon at 2020-02-29T05:10:46-05:00 rts: enforce POSIX numeric locale for heap profiles - - - - - 34c7d230 by Sylvain Henry at 2020-02-29T05:11:27-05:00 Fix Hadrian's ``--configure`` (fix #17883) - - - - - 04d30137 by Ömer Sinan Ağacan at 2020-02-29T05:12:06-05:00 Simplify IfaceIdInfo type IfaceIdInfo type is confusing: there's practically no difference between `NoInfo` and `HasInfo []`. The comments say NoInfo is used when -fomit-interface-pragmas is enabled, but we don't need to distinguish `NoInfo` from `HasInfo []` in when reading the interface so the distinction is not important. This patch simplifies the type by removing NoInfo. When we have no info we use an empty list. With this change we no longer read the info list lazily when reading an IfaceInfoItem, but when reading an IfaceId the ifIdInfo field is read lazily, so I doubt this is going to be a problem. - - - - - 3979485b by Roland Senn at 2020-02-29T17:36:59+01:00 Show breakpoint locations of breakpoints which were ignored during :force (#2950) GHCi is split up into 2 major parts: The user-interface (UI) and the byte-code interpreter. With `-fexternal-interpreter` they even run in different processes. Communication between the UI and the Interpreter (called `iserv`) is done using messages over a pipe. This is called `Remote GHCI` and explained in the Note [Remote GHCi] in `compiler/ghci/GHCi.hs`. To process a `:force` command the UI sends a `Seq` message to the `iserv` process. Then `iserv` does the effective evaluation of the value. When during this process a breakpoint is hit, the `iserv` process has no additional information to enhance the `Ignoring breakpoint` output with the breakpoint location. To be able to print additional breakpoint information, there are 2 possible implementation choices: 1. Store the needed information in the `iserv` process. 2. Print the `Ignoring breakpoint` from the UI process. For option 1 we need to store the breakpoint info redundantely in 2 places and this is bad. Therfore option 2 was implemented in this MR: - The user enters a `force` command - The UI sends a `Seq` message to the `iserv` process. - If processing of the `Seq` message hits a breakpoint, the `iserv` process returns control to the UI process. - The UI looks up the source location of the breakpoint, and prints the enhanced `Ignoring breakpoint` output. - The UI sends a `ResumeSeq` message to the `iserv` process, to continue forcing. - - - - - 3cf7303b by Krzysztof Gogolewski at 2020-03-02T01:18:33-05:00 Remove dead code * The names in PrelName and THNames are no longer used since TH merged types and kinds, Typeable is kind-polymorphic, .net support was removed * unqualQuasiQuote no longer used since 6f8ff0bbad3b9fa3 - - - - - dbea7e9d by Ilias Tsitsimpis at 2020-03-02T01:19:12-05:00 Do not define hs_atomic{read,write}64() on non-64bit Do not define hs_atomicread64() and hs_atomicwrite64() on machines where WORD_SIZE_IN_BITS is less than 64, just like we do with the rest of the atomic functions which work on 64-bit values. Without this, compilation fails on MIPSel and PowerPC with the following error: /usr/bin/ld: /<<PKGBUILDDIR>>/libraries/ghc-prim/dist-install/build/libHSghc-prim-0.5.3_p.a(atomic.p_o): in function `hs_atomicread64': atomic.c:(.text.hs_atomicread64+0x8): undefined reference to `__sync_add_and_fetch_8' /usr/bin/ld: /<<PKGBUILDDIR>>/libraries/ghc-prim/dist-install/build/libHSghc-prim-0.5.3_p.a(atomic.p_o): in function `hs_atomicwrite64': atomic.c:(.text.hs_atomicwrite64+0x38): undefined reference to `__sync_bool_compare_and_swap_8' Fixes #17886. - - - - - 7c0c76fb by Roland Senn at 2020-03-02T17:13:55-05:00 Set `ImpredicativeTypes` during :print command. (#14828) If ImpredicativeTypes is not enabled, then `:print <term>` will fail if the type of <term> has nested `forall`s or `=>`s. This is because the GHCi debugger's internals will attempt to unify a metavariable with the type of <term> and then display the result, but if the type has nested `forall`s or `=>`s, then unification will fail. As a result, `:print` will bail out and the unhelpful result will be `<term> = (_t1::t1)` (where `t1` is a metavariable). Beware: <term> can have nested `forall`s even if its definition doesn't use RankNTypes! Here is an example from #14828: class Functor f where fmap :: (a -> b) -> f a -> f b Somewhat surprisingly, `:print fmap` considers the type of fmap to have nested foralls. This is because the GHCi debugger sees the type `fmap :: forall f. Functor f => forall a b. (a -> b) -> f a -> f b`. We could envision deeply instantiating this type to get the type `forall f a b. Functor f => (a -> b) -> f a -> f b`, but this trick wouldn't work for higher-rank types. Instead, we adopt a simpler fix: enable `ImpredicativeTypes` when using `:print` and friends in the GHCi debugger. This is allows metavariables to unify with types that have nested (or higher-rank) `forall`s/`=>`s, which makes `:print fmap` display as `fmap = (_t1::forall a b. Functor f => (a -> b) -> f a -> f b)`, as expected. Although ImpredicativeTypes is a somewhat unpredictable from a type inference perspective, there is no danger in using it in the GHCi debugger, since all of the terms that the GHCi debugger deals with have already been typechecked. - - - - - 2a2f51d7 by Sylvain Henry at 2020-03-02T17:14:38-05:00 Use configure script to detect that we should use in-tree GMP on Windows - - - - - 8c663c2c by Andreas Klebinger at 2020-03-04T16:12:14+01:00 Be explicit about how stack usage of mvar primops are covered. This fixes #17893 [skip-ci] - - - - - cedd6f30 by Ben Gamari at 2020-03-05T14:53:12-05:00 rts: Add getCurrentThreadCPUTime helper - - - - - ace618cd by Ben Gamari at 2020-03-05T14:53:12-05:00 nonmoving-gc: Track time usage of nonmoving marking - - - - - 022b5ad5 by Ben Gamari at 2020-03-05T14:53:12-05:00 Stats: Add sync pauses to +RTS -S output - - - - - 06763234 by Ben Gamari at 2020-03-05T14:53:12-05:00 rts: Report nonmoving collector statistics in machine-readable output - - - - - 70d2b995 by Ben Gamari at 2020-03-09T06:10:52-04:00 nonmoving: Fix collection of sparks Previously sparks living in the non-moving heap would be promptly GC'd by the minor collector since pruneSparkQueue uses the BF_EVACUATED flag, which non-moving heap blocks do not have set. Fix this by implementing proper support in pruneSparkQueue for determining reachability in the non-moving heap. The story is told in Note [Spark management in the nonmoving heap]. - - - - - 9668781a by Ben Gamari at 2020-03-09T06:11:30-04:00 gitlab-ci: Disable Sphinx documentation in Alpine build - - - - - 8eb2c263 by Jean-Baptiste Mazon at 2020-03-09T16:33:37-04:00 Fix Windows breakage by not touching locales on Windows - - - - - b8dab057 by Jean-Baptiste Mazon at 2020-03-09T16:33:37-04:00 rts: ensure C numerics in heap profiles using Windows locales if needed - - - - - 7d95260f by Jean-Baptiste Mazon at 2020-03-09T16:33:37-04:00 rts: refactor and comment profile locales - - - - - 5b627813 by Ryan Scott at 2020-03-09T16:34:14-04:00 Use InstanceSigs in GND/DerivingVia-generated code (#17899) Aside from making the generated code easier to read when `-ddump-deriv` is enabled, this makes the error message in `T15073` substantially simpler (see the updated `T15073` expected stderr). Fixes #17899. - - - - - 70b50778 by Ben Gamari at 2020-03-10T02:05:42-04:00 SysTools: Ensure that error parser can handle absolute paths on Windows This fixes #17786, where the error parser fails to correctly handle the drive name in absolute Windows paths. Unfortunately I couldn't find a satisfactory way to test this. - - - - - 85b861d8 by Ben Gamari at 2020-03-10T02:05:42-04:00 testsuite: Add test for #17786 This isn't pretty but it's perhaps better than nothing. - - - - - ee2c50cb by Sylvain Henry at 2020-03-10T02:06:33-04:00 Hadrian: track missing configure results - - - - - ca8f51d4 by Ömer Sinan Ağacan at 2020-03-10T02:07:22-04:00 Add regression test for T17904 Closes #17904 - - - - - 5fa9cb82 by Richard Eisenberg at 2020-03-10T12:29:46-04:00 anyRewritableTyVar now looks in RuntimeReps Previously, anyRewritableTyVar looked only at the arg and res of `arg -> res`, but their RuntimeReps are also subject to rewriting. Easy to fix. Test case: typecheck/should_compile/T17024 Fixes #17024. - - - - - 5ba01d83 by Ben Price at 2020-03-10T12:30:27-04:00 Clarify a Lint message When developing a plugin I had a shadowing problem, where I generated code app = \f{v r7B} x{v r7B} -> f{v r7B} x{v r7B} This is obviously wrong, since the occurrence of `f` to the right of the arrow refers to the `x` binder (they share a Unique). However, it is rather confusing when Lint reports Mismatch in type between binder and occurrence Var: x{v rB7} since it is printing the binder, rather than the occurrence. It is rather easy to read this as claiming there is something wrong with the `x` occurrence! We change the report to explicitly print both the binder and the occurrence variables. - - - - - 7b2c827b by Simon Peyton Jones at 2020-03-10T12:31:15-04:00 Comments only Clarify code added in #17852 and MR !2724 - - - - - 3300eeac by Krzysztof Gogolewski at 2020-03-10T12:31:54-04:00 Misc cleanup - Remove Note [Existentials in shift_con_pat]. The function shift_con_pat has been removed 15 years ago in 23f40f0e9be6d4. - Remove kcLookupTcTyCon - it's the same as tcLookupTcTyCon - Remove ASSERT in tyConAppArgN. It's already done by getNth, and it's the only reason getNth exists. - Remove unused function nextRole - - - - - abf5736b by Krzysztof Gogolewski at 2020-03-10T18:05:01+01:00 Typos in comments [skip ci] - - - - - bb586f89 by Ben Gamari at 2020-03-11T00:14:59-04:00 rts: Prefer darwin-specific getCurrentThreadCPUTime macOS Catalina now supports a non-POSIX-compliant version of clock_gettime which cannot use the clock_gettime codepath. Fixes #17906. - - - - - 20800b9a by Sylvain Henry at 2020-03-11T08:17:19-04:00 Split GHC.Iface.Utils module * GHC.Iface.Recomp: recompilation avoidance stuff * GHC.Iface.Make: mkIface* Moved `writeIfaceFile` into GHC.Iface.Load alongside `readIface` and renamed it `writeIface` for consistency. - - - - - 1daa2029 by Greg Steuck at 2020-03-11T08:17:56-04:00 Fixed a minor typo in codegen.rst - - - - - 0bc23338 by Ryan Scott at 2020-03-11T08:18:32-04:00 Re-quantify when generalising over rewrite rule types Previously, `tcRules` would check for naughty quantification candidates (see `Note [Naughty quantification candidates]` in `TcMType`) when generalising over the type of a rewrite rule. This caused sensible-looking rewrite rules (like those in #17710) to be rejected. A more permissing (and easier-to-implement) approach is to do what is described in `Note [Generalising in tcTyFamInstEqnGuts]` in `TcTyClsDecls`: just re-quantify all the type variable binders, regardless of the order in which the user specified them. After all, the notion of type variable specificity has no real meaning in rewrite rules, since one cannot "visibly apply" a rewrite rule. I have written up this wisdom in `Note [Re-quantify type variables in rules]` in `TcRules`. As a result of this patch, compiling the `ExplicitForAllRules1` test case now generates one fewer warning than it used to. As far as I can tell, this is benign, since the thing that the disappearing warning talked about was also mentioned in an entirely separate warning. Fixes #17710. - - - - - 336eac7e by Ben Gamari at 2020-03-11T08:19:08-04:00 testsuite: Mark ghci056 and ghcilink004 as fragile in unreg As noted in #17018. Also fix fragile declaration of T13786, which only runs in the normal way. - - - - - c61b9b02 by Simon Peyton Jones at 2020-03-11T08:19:44-04:00 Deepen call stack for isIn I see quite a few warnings like: WARNING: file compiler/utils/Util.hs, line 593 Over-long elem in unionLists But the call stack is uninformative. Better to add HasDebugCallStack to isIn. Ditto isn'tIn. - - - - - 3aa9b35f by Ömer Sinan Ağacan at 2020-03-11T08:20:27-04:00 Zero any slop after compaction in compacting GC In copying GC, with the relevant debug flags enabled, we release the old blocks after a GC, and the block allocator zeroes the space before releasing a block. This effectively zeros the old heap. In compacting GC we reuse the blocks and previously we didn't zero the unused space in a compacting generation after compaction. With this patch we zero the slop between the free pointer and the end of the block when we're done with compaction and when switching to a new block (because the current block doesn't have enough space for the next object we're shifting). - - - - - 8e6febce by Sylvain Henry at 2020-03-11T20:33:37-04:00 Refactor GHC.Driver.Session (Ways and Flags) * extract flags and ways into their own modules (with some renaming) * remove one SOURCE import of GHC.Driver.Session from GHC.Driver.Phases * when GHC uses dynamic linking (WayDyn), `interpWays` was only reporting WayDyn even if the host was profiled (WayProf). Now it returns both as expected (might fix #16803). * `mkBuildTag :: [Way] -> String` wasn't reporting a canonical tag for differently ordered lists. Now we sort and nub the list to fix this. - - - - - bc41e471 by Sylvain Henry at 2020-03-11T20:33:37-04:00 Refactor interpreterDynamic and interpreterProfiled * `interpreterDynamic` and `interpreterProfiled` now take `Interp` parameters instead of DynFlags * slight refactoring of `ExternalInterp` so that we can read the iserv configuration (which is pure) without reading an MVar. - - - - - a6989971 by Sylvain Henry at 2020-03-11T20:33:37-04:00 Use a Set to represent Ways Should make `member` queries faster and avoid messing up with missing `nubSort`. Metric Increase: hie002 - - - - - cb93a1a4 by Ryan Scott at 2020-03-11T20:34:14-04:00 Make DeriveFunctor-generated code require fewer beta reductions Issue #17880 demonstrates that `DeriveFunctor`-generated code is surprisingly fragile when rank-_n_ types are involved. The culprit is that `$fmap` (the algorithm used to generate `fmap` implementations) was too keen on applying arguments with rank-_n_ types to lambdas, which fail to typecheck more often than not. In this patch, I change `$fmap` (both the specification and the implementation) to produce code that avoids creating as many lambdas, avoiding problems when rank-_n_ field types arise. See the comments titled "Functor instances" in `TcGenFunctor` for a more detailed description. Not only does this fix #17880, but it also ensures that the code that `DeriveFunctor` generates will continue to work after simplified subsumption is implemented (see #17775). What is truly amazing is that #17880 is actually a regression (introduced in GHC 7.6.3) caused by commit 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e, the fix #7436. Prior to that commit, the version of `$fmap` that was used was almost identical to the one used in this patch! Why did that commit change `$fmap` then? It was to avoid severe performance issues that would arise for recursive `fmap` implementations, such as in the example below: ```hs data List a = Nil | Cons a (List a) deriving Functor -- ===> instance Functor List where fmap f Nil = Nil fmap f (Cons x xs) = Cons (f x) (fmap (\y -> f y) xs) ``` The fact that `\y -> f y` was eta expanded caused significant performance overheads. Commit 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e fixed this performance issue, but it went too far. As a result, this patch partially reverts 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e. To ensure that the performance issues pre-#7436 do not resurface, I have taken some precautionary measures: * I have added a special case to `$fmap` for situations where the last type variable in an application of some type occurs directly. If this special case fires, we avoid creating a lambda expression. This ensures that we generate `fmap f (Cons x xs) = Cons (f x) (fmap f xs)` in the derived `Functor List` instance above. For more details, see `Note [Avoid unnecessary eta expansion in derived fmap implementations]` in `TcGenFunctor`. * I have added a `T7436b` test case to ensure that the performance of this derived `Functor List`-style code does not regress. When implementing this, I discovered that `$replace`, the algorithm which generates implementations of `(<$)`, has a special case that is very similar to the `$fmap` special case described above. `$replace` marked this special case with a custom `Replacer` data type, which was a bit overkill. In order to use the same machinery for both `Functor` methods, I ripped out `Replacer` and instead implemented a simple way to detect the special case. See the updated commentary in `Note [Deriving <$]` for more details. - - - - - 1f9db3e7 by Kirill Elagin at 2020-03-12T09:45:51-04:00 pretty-printer: Properly parenthesise LastStmt After ApplicatveDo strips the last `return` during renaming, the pretty printer has to restore it. However, if the return was followed by `$`, the dollar was stripped too and not restored. For example, the last stamement in: ``` foo = do x <- ... ... return $ f x ``` would be printed as: ``` return f x ``` This commit preserved the dolar, so it becomes: ``` return $ f x ``` - - - - - 5cb93af7 by Kirill Elagin at 2020-03-12T09:45:51-04:00 pretty-printer: Do not print ApplicativeDo join * Do not print `join` in ApplictiveStmt, unless ppr-debug * Print parens around multiple parallel binds When ApplicativeDo is enabled, the renamer analyses the statements of a `do` block and in certain cases marks them as needing to be rewritten using `join`. For example, if you have: ``` foo = do a <- e1 b <- e2 doSomething a b ``` it will be desugared into: ``` foo = join (doSomething <$> e1 <*> e2) ``` After renaming but before desugaring the expression is stored essentially as: ``` foo = do [will need join] (a <- e1 | b <- e2) [no return] doSomething a b ``` Before this change, the pretty printer would print a call to `join`, even though it is not needed at this stage at all. The expression will be actually rewritten into one using join only at desugaring, at which point a literal call to join will be inserted. - - - - - 3a259092 by Simon Peyton Jones at 2020-03-12T09:46:29-04:00 Expose compulsory unfoldings always The unsafeCoerce# patch requires that unsafeCoerce# has a compulsory unfolding that is always available. So we have to be careful to expose compulsory unfoldings unconditionally and consistently. We didn't get this quite right: #17871. This patch fixes it. No real surprises here. See Note [Always expose compulsory unfoldings] in GHC.Iface.Tidy - - - - - 6a65b8c2 by Alp Mestanogullari at 2020-03-13T02:29:20-04:00 hadrian: improve dependency tracking for the check-* programs The code in Rules.Register responsible for finding all the build artifacts that Cabal installs when registering a library (static/shared libs, .hi files, ...) was looking in the wrong place. This patch fixes that logic and makes sure we gather all those artifacts in a list to declare that the rule for a given `.conf` file, our proxy for "Hadrian, please install this package in the package db for this stage", also produces those artifacts under the said package database. We also were completely missing some logic to declare that the check-* programs have dependencies besides their source code, at least when testing an in-tree compiler. Finally, this patch also removes redundant packages from 'testsuitePackages', since they should already be covered by the stage<N>Packages lists from Settings.Default. With this patch, after a complete build and freezing stage 1, a change to `compiler/parser/Parser.y` results in rebuilding the ghc lib, reinstalling it, and rebuilding the few programs that depend on it, _including_ `check-ppr` and `check-api-annotations` (therefore fixing #17273). - - - - - 44fad4a9 by Sylvain Henry at 2020-03-13T02:30:22-04:00 Rename isDllName I wanted to fix the dangling comment in `isDllName` ("This is the cause of #", #8696 is already mentioned earlier). I took the opportunity to change the function name to better reflect what it does. - - - - - 2f292db8 by Paavo at 2020-03-13T02:31:03-04:00 Update documentation for closureSize - - - - - f124ff0d by Ben Gamari at 2020-03-13T02:31:40-04:00 gitlab-ci: Rework triggering of release builds Use a push option instead of tagging. - - - - - 7f25557a by Ben Gamari at 2020-03-13T10:38:09-04:00 gitlab-ci: Distinguish integer-simple test envs Previously two integer-simple jobs declared the same test environment. One (the nightly job) was built in the perf way, the other in the validate way. Consequently they had appreciably different performance characteristics, causing in the nightly job to spuriously fail with performance changes. - - - - - c12a2ec5 by Simon Peyton Jones at 2020-03-14T05:25:30-04:00 Fix Lint Ticket #17590 pointed out a bug in the way the linter dealt with type lets, exposed by the new uniqAway story. The fix is described in Note [Linting type lets]. I ended up putting the in-scope Ids in a different env field, le_ids, rather than (as before) sneaking them into the TCvSubst. Surprisingly tiresome, but done. Metric Decrease: hie002 - - - - - b989845e by Sylvain Henry at 2020-03-14T05:26:11-04:00 Hadrian: fix absolute buildroot support (#17822) Shake's "**" wildcard doesn't match absolute root. We must use "//" instead. - - - - - 4f117135 by Sylvain Henry at 2020-03-14T05:26:49-04:00 Make: refactor GMP rules Document and use simpler rules for the ghc-gmp.h header. - - - - - 7432b327 by Sylvain Henry at 2020-03-14T05:27:28-04:00 Use correct option name (-opti) (fix #17314) s/pgmo/opti - - - - - 8f7dd571 by Judah Jacobson at 2020-03-14T05:28:07-04:00 Allow overriding LD_STAGE0 and AR_STAGE0 in the configure script. Previously it was possible to override the stage0 C compiler via `CC_STAGE0`, but you couldn't override `ld` or `ar` in stage0. This change allows overriding them by setting `LD_STAGE0` or `AR_STAGE0`, respectively. Our team uses this feature internally to take more control of our GHC build and make it run more hermetically. - - - - - 7c3e39a9 by Judah Jacobson at 2020-03-14T05:28:07-04:00 Use AC_ARG_VAR for LD_STAGE0 and AR_STAGE0. - - - - - 20d4d676 by Ben Gamari at 2020-03-14T05:28:43-04:00 nonmoving: Don't traverse filled segment list in pause The non-moving collector would previously walk the entire filled segment list during the preparatory pause. However, this is far more work than is strictly necessary. We can rather get away with merely collecting the allocators' filled segment list heads and process the lists themselves during the concurrent phase. This can significantly reduce the maximum gen1 GC pause time in programs with high rates of long-lived allocations. - - - - - fdfa2d01 by Ben Gamari at 2020-03-14T05:29:18-04:00 nonmoving: Remove redundant bitmap clearing nonmovingSweep already clears the bitmap in the sweep loop. There is no reason to do so a second time. - - - - - 2f8c7767 by Simon Peyton Jones at 2020-03-14T05:29:55-04:00 Simple refactor of cheapEqExpr No change in functionality. Just seems tidier (and signficantly more efficient) to deal with ticks directly than to call stripTicksTopE. - - - - - 88f7a762 by Simon Peyton Jones at 2020-03-14T05:29:55-04:00 Improve CSE.combineAlts This patch improves the way that CSE combines identical alternatives. See #17901. I'm still not happy about the duplication between CSE.combineAlts and GHC.Core.Utils.combineIdenticalAlts; see the Notes with those functions. But this patch is a step forward. Metric Decrease: T12425 T5642 - - - - - 8b95ddd3 by Ben Gamari at 2020-03-14T05:30:31-04:00 gitlab-ci: Add integer-simple release build for Windows Closes #16144. - - - - - e3c374cc by Simon Peyton Jones at 2020-03-14T05:31:07-04:00 Wrap an implication around class-sig kind errors Ticket #17841 showed that we can get a kind error in a class signature, but lack an enclosing implication that binds its skolems. This patch * Adds the wrapping implication: the new call to checkTvConstraints in tcClassDecl1 * Simplifies the API to checkTvConstraints, which was not otherwise called at all. * Simplifies TcErrors.report_unsolved by *not* initialising the TidyEnv from the typechecker lexical envt. It's enough to do so from the free vars of the unsolved constraints; and we get silly renamings if we add variables twice: once from the lexical scope and once from the implication constraint. - - - - - 73133a3b by Simon Peyton Jones at 2020-03-14T05:31:07-04:00 Refactoring in TcSMonad This patch is just refactoring: no change in behaviour. I removed the rather complicated checkConstraintsTcS checkTvConstraintsTcS in favour of simpler functions emitImplicationTcS emitTvImplicationTcS pushLevelNoWorkList The last of these is a little strange, but overall it's much better I think. - - - - - 93c88c26 by Ben Gamari at 2020-03-14T05:31:42-04:00 base: Make `open` calls interruptible As noted in #17912, `open` system calls were `safe` rather than `interruptible`. Consequently, the program could not be interrupted with SIGINT if stuck in a slow open operation. Fix this by marking `c_safe_open` as interruptible. - - - - - bee4cdad by Vladislav Zavialov at 2020-03-14T05:32:18-04:00 Remove second tcLookupTcTyCon in tcDataDefn Before this patch, tcDataDefn used to call tcLookupTcTyCon twice in a row: 1. in bindTyClTyVars itself 2. in the continuation passed to it Now bindTyClTyVars passes the TcTyCon to the continuation, making the second lookup unnecessary. - - - - - 3f116d35 by Cale Gibbard at 2020-03-14T19:34:42-04:00 Enable stage1 build of haddock The submodule has already been bumped to contain the fix. - - - - - 49e9d739 by Ömer Sinan Ağacan at 2020-03-14T19:35:24-04:00 rts: Fix printClosure when printing fwd ptrs - - - - - 1de3ab4a by Krzysztof Gogolewski at 2020-03-14T19:36:04-04:00 Remove unused field var_inline (#17915) - - - - - d30aeb4b by Krzysztof Gogolewski at 2020-03-15T03:57:41-04:00 Document restriction on SCC pragma syntax Currently, the names of cost centres must be quoted or be lowercase identifiers. Fixes #17916. - - - - - b4774598 by Brian Foley at 2020-03-15T03:58:18-04:00 Remove some dead code >From the notes.ghc.drop list found using weeder in #17713 - - - - - dd6ffe6b by Viktor Dukhovni at 2020-03-15T03:58:55-04:00 Note platform-specific Foreign.C.Types in context Also fix the markup in the general note at the top of the module. Haddock (usability trade-off), does not support multi-line emphasised text. - - - - - 2e82465f by Sylvain Henry at 2020-03-15T10:57:10-04:00 Refactor CmmToAsm (disentangle DynFlags) This patch disentangles a bit more DynFlags from the native code generator (CmmToAsm). In more details: - add a new NCGConfig datatype in GHC.CmmToAsm.Config which contains the configuration of a native code generation session - explicitly pass NCGConfig/Platform arguments when necessary - as a consequence `sdocWithPlatform` is gone and there are only a few `sdocWithDynFlags` left - remove the use of `unsafeGlobalDynFlags` from GHC.CmmToAsm.CFG - remove `sdocDebugLevel` (now we pass the debug level via NCGConfig) There are still some places where DynFlags is used, especially because of pretty-printing (CLabel), because of Cmm helpers (such as `cmmExprType`) and because of `Outputable` instance for the instructions. These are left for future refactoring as this patch is already big. - - - - - c35c545d by Judah Jacobson at 2020-03-15T10:57:48-04:00 Add a -no-haddock flag. This flag undoes the effect of a previous "-haddock" flag. Having both flags makes it easier for build systems to enable Haddock parsing in a set of global flags, but then disable it locally for specific targets (e.g., third-party packages whose comments don't pass the validation in the latest GHC). I added the flag to expected-undocumented-flags.txt since `-haddock` was alreadyin that list. - - - - - cfcc3c9a by Ömer Sinan Ağacan at 2020-03-15T10:58:27-04:00 Fix global_link of TSOs for threads reachable via dead weaks Fixes #17785 Here's how the problem occurs: - In generation 0 we have a TSO that is finished (i.e. it has no more work to do or it is killed). - The TSO only becomes reachable after collectDeadWeakPtrs(). - After collectDeadWeakPtrs() we switch to WeakDone phase where we don't move TSOs to different lists anymore (like the next gen's thread list or the resurrected_threads list). - So the TSO will never be moved to a generation's thread list, but it will be promoted to generation 1. - Generation 1 collected via mark-compact, and because the TSO is reachable it is marked, and its `global_link` field, which is bogus at this point (because the TSO is not in a list), will be threaded. - Chaos ensues. In other words, when these conditions hold: - A TSO is reachable only after collectDeadWeakPtrs() - It's finished (what_next is ThreadComplete or ThreadKilled) - It's retained by mark-compact collector (moving collector doesn't evacuate the global_list field) We end up doing random mutations on the heap because the TSO's global_list field is not valid, but it still looks like a heap pointer so we thread it during compacting GC. The fix is simple: when we traverse old_threads lists to resurrect unreachable threads the threads that won't be resurrected currently stays on the old_threads lists. Those threads will never be visited again by MarkWeak so we now reset the global_list fields. This way compacting GC does not thread pointers to nowhere. Testing ------- The reproducer in #17785 is quite large and hard to build, because of the dependencies, so I'm not adding a regression test. In my testing the reproducer would take a less than 5 seconds to run, and once in every ~5 runs would fail with a segfault or an assertion error. In other cases it also fails with a test failure. Because the tests never fail with the bug fix, assuming the code is correct, this also means that this bug can sometimes lead to incorrect runtime results. After the fix I was able to run the reproducer repeatedly for about an hour, with no runtime crashes or test failures. To run the reproducer clone the git repo: $ git clone https://github.com/osa1/streamly --branch ghc-segfault Then clone primitive and atomic-primops from their git repos and point to the clones in cabal.project.local. The project should then be buildable using GHC HEAD. Run the executable `properties` with `+RTS -c -DZ`. In addition to the reproducer above I run the test suite using: $ make slowtest EXTRA_HC_OPTS="-debug -with-rtsopts=-DS \ -with-rtsopts=-c +RTS -c -RTS" SKIPWAY='nonmoving nonmoving_thr' This enables compacting GC always in both GHC when building the test programs and when running the test programs, and also enables sanity checking when running the test programs. These set of flags are not compatible for all tests so there are some failures, but I got the same set of failures with this patch compared to GHC HEAD. - - - - - 818b3c38 by Lysxia at 2020-03-16T23:52:42-04:00 base: add strict IO functions: readFile', getContents', hGetContents' - - - - - 18a346a4 by Sylvain Henry at 2020-03-16T23:53:24-04:00 Modules: Core (#13009) Update submodule: haddock - - - - - 92327e3a by Ömer Sinan Ağacan at 2020-03-16T23:54:04-04:00 Update sanity checking for TSOs: - Remove an invalid assumption about GC checking what_next field. The GC doesn't care about what_next at all, if a TSO is reachable then all its pointers are followed (other than global_tso, which is only followed by compacting GC). - Remove checkSTACK in checkTSO: TSO stacks will be visited in checkHeapChain, or checkLargeObjects etc. - Add an assertion in checkTSO to check that the global_link field is sane. - Did some refactor to remove forward decls in checkGlobalTSOList and added braces around single-statement if statements. - - - - - e1aa4052 by PHO at 2020-03-17T07:36:09-04:00 Don't use non-portable operator "==" in configure.ac The test operator "==" is a Bash extension and produces a wrong result if /bin/sh is not Bash. - - - - - 89f034dd by Maximilian Tagher at 2020-03-17T07:36:48-04:00 Document the units of -ddump-timings Right now, in the output of -ddump-timings to a file, you can't tell what the units are: ``` CodeGen [TemplateTestImports]: alloc=22454880 time=14.597 ``` I believe bytes/milliseconds are the correct units, but confirmation would be appreciated. I'm basing it off of this snippet from `withTiming'`: ``` when (verbosity dflags >= 2 && prtimings == PrintTimings) $ liftIO $ logInfo dflags (defaultUserStyle dflags) (text "!!!" <+> what <> colon <+> text "finished in" <+> doublePrec 2 time <+> text "milliseconds" <> comma <+> text "allocated" <+> doublePrec 3 (realToFrac alloc / 1024 / 1024) <+> text "megabytes") ``` which implies time is in milliseconds, and allocations in bytes (which divided by 1024 would be KB, and again would be MB) - - - - - beffa147 by Simon Peyton Jones at 2020-03-17T07:37:25-04:00 Implement mapTyCo like foldTyCo This patch makes mapType use the successful idiom described in TyCoRep Note [Specialising foldType] I have not yet changed any functions to use mapType, though there may be some suitable candidates. This patch should be a no-op in terms of functionality but, because it inlines the mapper itself, I'm hoping that there may be some modest perf improvements. Metric Decrease: T5631 T5642 T3064 T9020 T14683 hie002 haddock.Cabal haddock.base haddock.compiler - - - - - 5800ebfe by Ömer Sinan Ağacan at 2020-03-17T07:38:08-04:00 Don't update ModDetails with CafInfos when opts are disabled This is consistent with the interface file behavior where we omit HsNoCafRefs annotations with -fomit-interface-pragmas (implied by -O0). ModDetails and ModIface are just different representations of the same thing, so they really need to be in sync. This patch does the right thing and does not need too much explanation, but here's an example of a problem not doing this causes in !2842: -- MyInteger.hs module MyInteger ( MyInteger (MyInteger) , ToMyInteger (toMyInteger) ) where newtype MyInteger = MyInteger Integer class ToMyInteger a where toMyInteger :: a -> MyInteger instance ToMyInteger Integer where toMyInteger = MyInteger {- . succ -} -- Main.hs module Main ( main ) where import MyInteger (MyInteger (MyInteger), toMyInteger) main :: IO () main = do let (MyInteger i) = (id . toMyInteger) (41 :: Integer) print i If I build this with -O0, without this fix, we generate a ModDetails with accurate LFInfo for toMyInteger (MyInteger.$fToMyIntegerInteger) which says that it's a LFReEntrant with arity 1. This means in the use site (Main) we tag the value: R3 = MyInteger.$fToMyIntegerInteger_closure + 1; R2 = GHC.Base.id_closure; R1 = GHC.Base.._closure; Sp = Sp - 16; call stg_ap_ppp_fast(R4, R3, R2, R1) args: 24, res: 0, upd: 24; Now we change the definition by uncommenting the `succ` part and it becomes a thunk: MyInteger.$fToMyIntegerInteger [InlPrag=INLINE (sat-args=0)] :: MyInteger.ToMyInteger GHC.Integer.Type.Integer [GblId[DFunId(nt)]] = {} \u [] $ctoMyInteger_rEA; and its LFInfo is now LFThunk. This change in LFInfo makes a difference in the use site: we can no longer tag it. But becuase the interface fingerprint does not change (because ModIface does not change) we don't rebuild Main and tag the thunk. (1.2% increase in allocations when building T12545 on armv7 because we generate more code without CafInfos) Metric Increase: T12545 - - - - - 5b632dad by Paavo at 2020-03-17T07:38:48-04:00 Add example for Data.Semigroup.diff - - - - - 4d85d68b by Paavo at 2020-03-17T07:38:48-04:00 Clean up - - - - - 75168d07 by Paavo at 2020-03-17T07:38:48-04:00 Make example collapsible - - - - - 53ff2cd0 by Richard Eisenberg at 2020-03-17T13:46:57+00:00 Fix #17021 by checking more return kinds All the details are in new Note [Datatype return kinds] in TcTyClsDecls. Test case: typecheck/should_fail/T17021{,b} typecheck/should_compile/T17021a Updates haddock submodule - - - - - 528df8ec by Sylvain Henry at 2020-03-18T10:06:43-04:00 Modules: Core operations (#13009) - - - - - 4e8a71c1 by Richard Eisenberg at 2020-03-18T10:07:19-04:00 Add release note about fix to #16502. We thought we needed to update the manual, but the fix for #16502 actually brings the implementation in line with the manual. So we just alert users of how to update their code. - - - - - 5cbf9934 by Andreas Klebinger at 2020-03-19T00:39:27-04:00 Update "GHC differences to the FFI Chapter" in user guide. The old entry had a heavy focus on how things had been. Which is not what I generally look for in a user guide. I also added a small section on behaviour of nested safe ffi calls. [skip-ci] - - - - - b03fd3bc by Sebastian Graf at 2020-03-19T00:40:06-04:00 PmCheck: Use ConLikeSet to model negative info In #17911, Simon recognised many warnings stemming from over-long list unions while coverage checking Cabal's `LicenseId` module. This patch introduces a new `PmAltConSet` type which uses a `UniqDSet` instead of an association list for `ConLike`s. For `PmLit`s, it will still use an assocation list, though, because a similar map data structure would entail a lot of busy work. Fixes #17911. - - - - - 64f20756 by Sylvain Henry at 2020-03-19T12:16:49-04:00 Refactoring: use Platform instead of DynFlags when possible Metric Decrease: ManyConstructors T12707 T13035 T1969 - - - - - cb1785d9 by Ömer Sinan Ağacan at 2020-03-19T12:16:54-04:00 FastString: fix eager reading of string ptr in hashStr This read causes NULL dereferencing when len is 0. Fixes #17909 In the reproducer in #17909 this bug is triggered as follows: - SimplOpt.dealWithStringLiteral is called with a single-char string ("=" in #17909) - tailFS gets called on the FastString of the single-char string. - tailFS checks the length of the string, which is 1, and calls mkFastStringByteString on the tail of the ByteString, which is an empty ByteString as the original ByteString has only one char. - ByteString's unsafeUseAsCStringLen returns (NULL, 0) for the empty ByteString, which is passed to mkFastStringWith. - mkFastStringWith gets hash of the NULL pointer via hashStr, which fails on empty strings because of this bug. - - - - - 73a7383e by Richard Eisenberg at 2020-03-20T20:42:56-04:00 Simplify treatment of heterogeneous equality Previously, if we had a [W] (a :: k1) ~ (rhs :: k2), we would spit out a [D] k1 ~ k2 and part the W as irreducible, hoping for a unification. But we needn't do this. Instead, we now spit out a [W] co :: k2 ~ k1 and then use co to cast the rhs of the original Wanted. This means that we retain the connection between the spat-out constraint and the original. The problem with this new approach is that we cannot use the casted equality for substitution; it's too like wanteds-rewriting- wanteds. So, we forbid CTyEqCans that mention coercion holes. All the details are in Note [Equalities with incompatible kinds] in TcCanonical. There are a few knock-on effects, documented where they occur. While debugging an error in this patch, Simon and I ran into infelicities in how patterns and matches are printed; we made small improvements. This patch includes mitigations for #17828, which causes spurious pattern-match warnings. When #17828 is fixed, these lines should be removed. - - - - - faa36e5b by Sylvain Henry at 2020-03-20T20:43:41-04:00 Hadrian: ignore in-tree GMP objects with ``--lint`` - - - - - 9a96ff6b by Richard Eisenberg at 2020-03-20T20:44:17-04:00 Update core spec to reflect changes to Core. Key changes: * Adds a new rule for forall-coercions over coercion variables, which was implemented but conspicuously missing from the spec. * Adds treatment for FunCo. * Adds treatment for ForAllTy over coercion variables. * Improves commentary (including restoring a Note lost in 03d4852658e1b7407abb4da84b1b03bfa6f6db3b) in the source. No changes to running code. - - - - - 7e0451c6 by Sergej Jaskiewicz at 2020-03-20T20:44:55-04:00 Fix event message in withTiming' This typo caused generating 'end' events without the corresponding 'begin' events. - - - - - 1542a626 by Ben Gamari at 2020-03-22T22:37:47-04:00 fs.h: Add missing declarations on Windows - - - - - 3bcf2ccd by Ben Gamari at 2020-03-22T22:37:47-04:00 Bump process submodule Avoids redundant case alternative warning. - - - - - 3b363ef9 by Ben Gamari at 2020-03-22T22:37:47-04:00 testsuite: Normalize slashes in ghc-api annotations output Enable `normalise_slashes` on `annotations`, `listcomps`, and `parseTree` to fix Windows failures. - - - - - 25fc9429 by Ben Gamari at 2020-03-22T22:37:47-04:00 testsuite: Update expected output on Windows - - - - - 7f58ec6d by Ben Gamari at 2020-03-22T22:37:47-04:00 testsuite: Fix TOP of T17786 - - - - - aadcd909 by GHC GitLab CI at 2020-03-22T22:37:47-04:00 testsuite: Update expected output on Windows - - - - - dc1eb10d by GHC GitLab CI at 2020-03-22T22:37:47-04:00 hadrian: Fix executable extension passed to testsuite driver - - - - - 58f62e2c by GHC GitLab CI at 2020-03-22T22:37:47-04:00 gitlab-ci: Require that Windows-hadrian job passes - - - - - 8dd2415d by Ben Gamari at 2020-03-22T22:37:47-04:00 hadrian: Eliminate redundant .exe from GHC path Previously we were invoking: bash -c "c:/GitLabRunner/builds/eEQrxK4p/0/ghc/ghc/toolchain/bin/ghc.exe.exe testsuite/mk/ghc-config.hs -o _build/test/bin/ghc-config.exe" - - - - - 373621f6 by Ben Gamari at 2020-03-22T22:37:47-04:00 Bump hsc2hs submodule - - - - - abc02b40 by Hécate at 2020-03-22T22:38:33-04:00 Annotate the non-total function in Data.Foldable as such - - - - - 19f12557 by Josef Svenningsson at 2020-03-23T14:05:33-04:00 Fix ApplicativeDo regression #17835 A previous fix for #15344 made sure that monadic 'fail' is used properly when translating ApplicativeDo. However, it didn't properly account for when a 'fail' will be inserted which resulted in some programs failing with a type error. - - - - - 2643ba46 by Paavo at 2020-03-24T08:31:32-04:00 Add example and doc for Arg (Fixes #17153) - - - - - 703221f4 by Roland Senn at 2020-03-25T14:45:04-04:00 Use export list of Main module in function TcRnDriver.hs:check_main (Fix #16453) - Provide the export list of the `Main` module as parameter to the `compiler/typecheck/TcRnDriver.hs:check_main` function. - Instead of `lookupOccRn_maybe` call the function `lookupInfoOccRn`. It returns the list `mains_all` of all the main functions in scope. - Select from this list `mains_all` all `main` functions that are in the export list of the `Main` module. - If this new list contains exactly one single `main` function, then typechecking continues. - Otherwise issue an appropriate error message. - - - - - 3e27205a by Sebastian Graf at 2020-03-25T14:45:40-04:00 Remove -fkill-absence and -fkill-one-shot flags They seem to be a benchmarking vestige of the Cardinality paper and probably shouldn't have been merged to HEAD in the first place. - - - - - 262e42aa by Peter Trommler at 2020-03-25T22:41:39-04:00 Do not panic on linker errors - - - - - 0de03cd7 by Sylvain Henry at 2020-03-25T22:42:02-04:00 DynFlags refactoring III Use Platform instead of DynFlags when possible: * `tARGET_MIN_INT` et al. replaced with `platformMinInt` et al. * no more DynFlags in PreRules: added a new `RuleOpts` datatype * don't use `wORD_SIZE` in the compiler * make `wordAlignment` use `Platform` * make `dOUBLE_SIZE` a constant Metric Decrease: T13035 T1969 - - - - - 7a04920b by Tristan Cacqueray at 2020-03-25T22:42:06-04:00 Base: fix a typo in liftA doc This change removes an extra '|' that should not be rendered in the liftA documentation. Tracking: #17929 - - - - - 1c5a15f7 by Tristan Cacqueray at 2020-03-25T22:42:06-04:00 Base: add Control.Applicative optional example This change adds an optional example. Tracking: #17929 - - - - - 6d172e63 by Tristan Cacqueray at 2020-03-25T22:42:06-04:00 Base: add markup around Except - - - - - eb2162c8 by John Ericson at 2020-03-26T12:37:08-04:00 Remove unused `ghciTablesNextToCode` from compiler proper - - - - - f51efc4b by Joachim Breitner at 2020-03-26T12:37:09-04:00 Prepare to use run-time tablesNextToCode in compiler exclusively Factor out CPP as much as possible to prepare for runtime determinattion. Progress towards #15548 - - - - - 1c446220 by Joachim Breitner at 2020-03-26T12:37:09-04:00 Use run-time tablesNextToCode in compiler exclusively (#15548) Summary: - There is no more use of the TABLES_NEXT_TO_CODE CPP macro in `compiler/`. GHCI_TABLES_NEXT_TO_CODE is also removed entirely. The field within `PlatformMisc` within `DynFlags` is used instead. - The field is still not exposed as a CLI flag. We might consider some way to ensure the right RTS / libraries are used before doing that. Original reviewers: Original subscribers: TerrorJack, rwbarton, carter Original Differential Revision: https://phabricator.haskell.org/D5082 - - - - - 1941ef4f by Sylvain Henry at 2020-03-29T17:28:51-04:00 Modules: Types (#13009) Update Haddock submodule Metric Increase: haddock.compiler - - - - - 1c7c6f1a by Sylvain Henry at 2020-03-29T17:28:51-04:00 Remove GHC.Types.Unique.Map module This module isn't used anywhere in GHC. - - - - - f1a6c73d by Sylvain Henry at 2020-03-29T17:28:51-04:00 Merge GHC.Types.CostCentre.Init into GHC.Driver.CodeOutput - - - - - 54250f2d by Simon Peyton Jones at 2020-03-29T17:29:30-04:00 Demand analysis: simplify the demand for a RHS Ticket #17932 showed that we were using a stupid demand for the RHS of a let-binding, when the result is a product. This was the result of a "fix" in 2013, which (happily) turns out to no longer be necessary. So I just deleted the code, which simplifies the demand analyser, and fixes #17932. That in turn uncovered that the anticipation of worker/wrapper in CPR analysis was inaccurate, hence the logic that decides whether to unbox an argument in WW was extracted into a function `wantToUnbox`, now consulted by CPR analysis. I tried nofib, and got 0.0% perf changes. All this came up when messing about with !2873 (ticket #17917), but is idependent of it. Unfortunately, this patch regresses #4267 and realised that it is now blocked on #16335. - - - - - 03060b2f by Ben Gamari at 2020-03-29T17:30:05-04:00 testsuite: Fix T17786 on Windows Fixes line ending normalization issue. - - - - - 1f7995ba by Ben Gamari at 2020-03-29T17:30:05-04:00 testsuite: Fix T17786 Fix missing quoting and expected exit code. - - - - - ef9c608e by Ben Gamari at 2020-03-29T17:30:05-04:00 testsuite: Mark T12971 as broken on Windows Due to #17945. - - - - - e54500c1 by Sylvain Henry at 2020-03-29T17:30:47-04:00 Store ComponentId details As far as GHC is concerned, installed package components ("units") are identified by an opaque ComponentId string provided by Cabal. But we don't want to display it to users (as it contains a hash) so GHC queries the database to retrieve some infos about the original source package (name, version, component name). This patch caches these infos in the ComponentId itself so that we don't need to provide DynFlags (which contains installed package informations) to print a ComponentId. In the future we want GHC to support several independent package states (e.g. for plugins and for target code), hence we need to avoid implicitly querying a single global package state. - - - - - 7e7cb714 by Marius Bakke at 2020-03-29T17:31:27-04:00 testsuite: Remove test that dlopens a PIE object. glibc 2.30 disallowed dlopening PIE objects, so just remove the test. Fixes #17952. - - - - - 6c8f80d8 by Andreas Klebinger at 2020-03-29T17:32:04-04:00 Correct haddocks for testBit in Data.Bits It conflated the nth bit with the bit at offset n. Now we instead give the definition in terms of `bit and `.&.` on top of clearer phrasing. - - - - - c916f190 by Andreas Klebinger at 2020-03-29T17:32:04-04:00 Apply suggestion to libraries/base/Data/Bits.hs - - - - - 64bf7f51 by Ben Gamari at 2020-03-29T17:32:41-04:00 gitlab-ci: Add FreeBSD release job - - - - - a0d8e92e by Ryan Scott at 2020-03-29T17:33:20-04:00 Run checkNewDataCon before constraint-solving newtype constructors Within `checkValidDataCon`, we used to run `checkValidType` on the argument types of a newtype constructor before running `checkNewDataCon`, which ensures that the user does not attempt non-sensical things such as newtypes with multiple arguments or constraints. This works out in most situations, but this falls over on a corner case revealed in #17955: ```hs newtype T = Coercible () T => T () ``` `checkValidType`, among other things, peforms an ambiguity check on the context of a data constructor, and that it turn invokes the constraint solver. It turns out that there is a special case in the constraint solver for representational equalities (read: `Coercible` constraints) that causes newtypes to be unwrapped (see `Note [Unwrap newtypes first]` in `TcCanonical`). This special case does not know how to cope with an ill formed newtype like `T`, so it ends up panicking. The solution is surprisingly simple: just invoke `checkNewDataCon` before `checkValidType` to ensure that the illicit newtype constructor context is detected before the constraint solver can run amok with it. Fixes #17955. - - - - - 45eb9d8c by Krzysztof Gogolewski at 2020-03-29T17:33:59-04:00 Minor cleanup - Simplify mkBuildExpr, the function newTyVars was called only on a one-element list. - TTG: use noExtCon in more places. This is more future-proof. - In zonkExpr, panic instead of printing a warning. - - - - - f024b6e3 by Sylvain Henry at 2020-03-30T12:48:39+02:00 Expect T4267 to pass Since 54250f2d8de910b094070c1b48f086030df634b1 we expected T4267 to fail, but it passes on CI. - - - - - 57b888c0 by Ryan Scott at 2020-03-31T10:54:20-04:00 Require GHC 8.8 as the minimum compiler for bootstrapping This allows us to remove several bits of CPP that are either always true or no longer reachable. As an added bonus, we no longer need to worry about importing `Control.Monad.Fail.fail` qualified to avoid clashing with `Control.Monad.fail`, since the latter is now the same as the former. - - - - - 33f09551 by Ryan Scott at 2020-03-31T10:54:57-04:00 Add regression test for #17963 The panic in #17963 happened to be fixed by commit e3c374cc5bd7eb49649b9f507f9f7740697e3f70. This patch adds a regression test to ensure that it remains fixed. Fixes #17963. - - - - - 09a36e80 by Ömer Sinan Ağacan at 2020-03-31T10:55:37-04:00 Simplify stderrSupportsAnsiColors The combinator andM is used only once, and the code is shorter and simpler if you inline it. - - - - - 95bccdd0 by Ben Gamari at 2020-03-31T10:56:19-04:00 base: Ensure that encoding global variables aren't inlined As noted in #17970, these (e.g. `getFileSystemEncoding` and `setFileSystemEncoding`) previously had unfoldings, which would break their global-ness. While not strictly necessary, I also add a NOINLINE on `initLocaleEncoding` since it is used in `System.IO`, ensuring that we only system's query the locale encoding once. Fixes #17970. - - - - - 982aaa83 by Andreas Klebinger at 2020-03-31T10:56:55-04:00 Update hadrian index revision. Required in order to build hadrian using ghc-8.10 - - - - - 4b9c5864 by Ben Gamari at 2020-03-31T10:57:32-04:00 integer-gmp: Bump version and add changelog entry - - - - - 9b39f2e6 by Ryan Scott at 2020-04-01T01:20:00-04:00 Clean up "Eta reduction for data families" Notes Before, there were two distinct Notes named "Eta reduction for data families". This renames one of them to "Implementing eta reduction for data families" to disambiguate the two and fixes references in other parts of the codebase to ensure that they are pointing to the right place. Fixes #17313. [ci skip] - - - - - 7627eab5 by Ryan Scott at 2020-04-01T01:20:38-04:00 Fix the changelog/@since information for hGetContents'/getContents'/readFile' Fixes #17979. [ci skip] - - - - - 0002db1b by Sylvain Henry at 2020-04-01T01:21:27-04:00 Kill wORDS_BIGENDIAN and replace it with platformByteOrder (#17957) Metric Decrease: T13035 T1969 - - - - - 7b217179 by Sebastian Graf at 2020-04-01T15:03:24-04:00 PmCheck: Adjust recursion depth for inhabitation test In #17977, we ran into the reduction depth limit of the typechecker. That was only a symptom of a much broader issue: The recursion depth of the coverage checker for trying to instantiate strict fields in the `nonVoid` test was far too high (100, the `defaultMaxTcBound`). As a result, we were performing quite poorly on `T17977`. Short of a proper termination analysis to prove emptyness of a type, we just arbitrarily default to a much lower recursion limit of 3. Fixes #17977. - - - - - 3c09f636 by Andreas Klebinger at 2020-04-01T15:03:59-04:00 Make hadrian pass on the no-colour setting to GHC. Fixes #17983. - - - - - b943b25d by Simon Peyton Jones at 2020-04-02T01:45:58-04:00 Re-engineer the binder-swap transformation The binder-swap transformation is implemented by the occurrence analyser -- see Note [Binder swap] in OccurAnal. However it had a very nasty corner in it, for the case where the case scrutinee was a GlobalId. This led to trouble and hacks, and ultimately to #16296. This patch re-engineers how the occurrence analyser implements the binder-swap, by actually carrying out a substitution rather than by adding a let-binding. It's all described in Note [The binder-swap substitution]. I did a few other things along the way * Fix a bug in StgCse, which could allow a loop breaker to be CSE'd away. See Note [Care with loop breakers] in StgCse. I think it can only show up if occurrence analyser sets up bad loop breakers, but still. * Better commenting in SimplUtils.prepareAlts * A little refactoring in CoreUnfold; nothing significant e.g. rename CoreUnfold.mkTopUnfolding to mkFinalUnfolding * Renamed CoreSyn.isFragileUnfolding to hasCoreUnfolding * Move mkRuleInfo to CoreFVs We observed respectively 4.6% and 5.9% allocation decreases for the following tests: Metric Decrease: T9961 haddock.base - - - - - 42d68364 by Sebastian Graf at 2020-04-02T01:46:34-04:00 Preserve precise exceptions in strictness analysis Fix #13380 and #17676 by 1. Changing `raiseIO#` to have `topDiv` instead of `botDiv` 2. Give it special treatment in `Simplifier.Util.mkArgInfo`, treating it as if it still had `botDiv`, to recover dead code elimination. This is the first commit of the plan outlined in https://gitlab.haskell.org/ghc/ghc/-/merge_requests/2525#note_260886. - - - - - 0a88dd11 by Ömer Sinan Ağacan at 2020-04-02T01:47:25-04:00 Fix a pointer format string in RTS - - - - - 5beac042 by Ömer Sinan Ağacan at 2020-04-02T01:48:05-04:00 Remove unused closure stg_IND_direct - - - - - 88f38b03 by Ben Gamari at 2020-04-02T01:48:42-04:00 Session: Memoize stderrSupportsAnsiColors Not only is this a reasonable efficiency measure but it avoids making reentrant calls into ncurses, which is not thread-safe. See #17922. - - - - - 27740f24 by Ryan Scott at 2020-04-02T01:49:21-04:00 Make Hadrian build with Cabal-3.2 GHC 8.10 ships with `Cabal-3.2.0.0`, so it would be convenient to make Hadrian supporting building against 3.2.* instead of having to rebuild the entirety of `Cabal-3.0.0.0`. There is one API change in `Cabal-3.2.*` that affects Hadrian: the `synopsis` and `description` functions now return `ShortText` instead of `String`. Since Hadrian manipulates these `String`s in various places, I found that the simplest fix was to use CPP to convert `ShortText` to `String`s where appropriate. - - - - - 49802002 by Sylvain Henry at 2020-04-02T01:50:00-04:00 Update Stack resolver for hadrian/build-stack Broken by 57b888c0e90be7189285a6b078c30b26d0923809 - - - - - 30a63e79 by Ryan Scott at 2020-04-02T01:50:36-04:00 Fix two ASSERT buglets in reifyDataCon Two `ASSERT`s in `reifyDataCon` were always using `arg_tys`, but `arg_tys` is not meaningful for GADT constructors. In fact, it's worse than non-meaningful, since using `arg_tys` when reifying a GADT constructor can lead to failed `ASSERT`ions, as #17305 demonstrates. This patch applies the simplest possible fix to the immediate problem. The `ASSERT`s now use `r_arg_tys` instead of `arg_tys`, as the former makes sure to give something meaningful for GADT constructors. This makes the panic go away at the very least. There is still an underlying issue with the way the internals of `reifyDataCon` work, as described in https://gitlab.haskell.org/ghc/ghc/issues/17305#note_227023, but we leave that as future work, since fixing the underlying issue is much trickier (see https://gitlab.haskell.org/ghc/ghc/issues/17305#note_227087). - - - - - ef7576c4 by Zubin Duggal at 2020-04-03T06:24:56-04:00 Add outputable instances for the types in GHC.Iface.Ext.Types, add -ddump-hie flag to dump pretty printed contents of the .hie file Metric Increase: hie002 Because of the regression on i386: compile_time/bytes allocated increased from i386-linux-deb9 baseline @ HEAD~10: Expected hie002 (normal) compile_time/bytes allocated: 583014888.0 +/-10% Lower bound hie002 (normal) compile_time/bytes allocated: 524713399 Upper bound hie002 (normal) compile_time/bytes allocated: 641316377 Actual hie002 (normal) compile_time/bytes allocated: 877986292 Deviation hie002 (normal) compile_time/bytes allocated: 50.6 % *** unexpected stat test failure for hie002(normal) - - - - - 9462452a by Andreas Klebinger at 2020-04-03T06:25:33-04:00 Improve and refactor StgToCmm codegen for DataCons. We now differentiate three cases of constructor bindings: 1)Bindings which we can "replace" with a reference to an existing closure. Reference the replacement closure when accessing the binding. 2)Bindings which we can "replace" as above. But we still generate a closure which will be referenced by modules importing this binding. 3)For any other binding generate a closure. Then reference it. Before this patch 1) did only apply to local bindings and we didn't do 2) at all. - - - - - a214d214 by Moritz Bruder at 2020-04-03T06:26:11-04:00 Add singleton to NonEmpty in libraries/base This adds a definition to construct a singleton non-empty list (Data.List.NonEmpty) according to issue #17851. - - - - - f7597aa0 by Sylvain Henry at 2020-04-03T06:26:54-04:00 Testsuite: measure compiler stats for T16190 We were mistakenly measuring program stats - - - - - a485c3c4 by Sylvain Henry at 2020-04-03T06:26:54-04:00 Move blob handling into StgToCmm Move handling of big literal strings from CmmToAsm to StgToCmm. It avoids the use of `sdocWithDynFlags` (cf #10143). We might need to move this handling even higher in the pipeline in the future (cf #17960): this patch will make it easier. - - - - - cc2918a0 by Sylvain Henry at 2020-04-03T06:26:54-04:00 Refactor CmmStatics In !2959 we noticed that there was some redundant code (in GHC.Cmm.Utils and GHC.Cmm.StgToCmm.Utils) used to deal with `CmmStatics` datatype (before SRT generation) and `RawCmmStatics` datatype (after SRT generation). This patch removes this redundant code by using a single GADT for (Raw)CmmStatics. - - - - - 9e60273d by Maxim Koltsov at 2020-04-03T06:27:32-04:00 Fix haddock formatting in Control.Monad.ST.Lazy.Imp.hs - - - - - 1b7e8a94 by Andreas Klebinger at 2020-04-03T06:28:08-04:00 Turn newlines into spaces for hadrian/ghci. The newlines break the command on windows. - - - - - 4291bdda by Simon Peyton Jones at 2020-04-03T06:28:44-04:00 Major improvements to the specialiser This patch is joint work of Alexis King and Simon PJ. It does some significant refactoring of the type-class specialiser. Main highlights: * We can specialise functions with types like f :: Eq a => a -> Ord b => b => blah where the classes aren't all at the front (#16473). Here we can correctly specialise 'f' based on a call like f @Int @Bool dEqInt x dOrdBool This change really happened in an earlier patch commit 2d0cf6252957b8980d89481ecd0b79891da4b14b Author: Sandy Maguire <sandy at sandymaguire.me> Date: Thu May 16 12:12:10 2019 -0400 work that this new patch builds directly on that work, and refactors it a bit. * We can specialise functions with implicit parameters (#17930) g :: (?foo :: Bool, Show a) => a -> String Previously we could not, but now they behave just like a non-class argument as in 'f' above. * We can specialise under-saturated calls, where some (but not all of the dictionary arguments are provided (#17966). For example, we can specialise the above 'f' based on a call map (f @Int dEqInt) xs even though we don't (and can't) give Ord dictionary. This may sound exotic, but #17966 is a program from the wild, and showed significant perf loss for functions like f, if you need saturation of all dictionaries. * We fix a buglet in which a floated dictionary had a bogus demand (#17810), by using zapIdDemandInfo in the NonRec case of specBind. * A tiny side benefit: we can drop dead arguments to specialised functions; see Note [Drop dead args from specialisations] * Fixed a bug in deciding what dictionaries are "interesting"; see Note [Keep the old dictionaries interesting] This is all achieved by by building on Sandy Macguire's work in defining SpecArg, which mkCallUDs uses to describe the arguments of the call. Main changes: * Main work is in specHeader, which marched down the [InBndr] from the function definition and the [SpecArg] from the call site, together. * specCalls no longer has an arity check; the entire mechanism now handles unders-saturated calls fine. * mkCallUDs decides on an argument-by-argument basis whether to specialise a particular dictionary argument; this is new. See mk_spec_arg in mkCallUDs. It looks as if there are many more lines of code, but I think that all the extra lines are comments! - - - - - 40a85563 by Ömer Sinan Ağacan at 2020-04-03T18:26:19+03:00 Revert accidental change in 9462452 [ci skip] - - - - - bd75e5da by Ryan Scott at 2020-04-04T07:07:58-04:00 Enable ImpredicativeTypes internally when typechecking selector bindings This is necessary for certain record selectors with higher-rank types, such as the examples in #18005. See `Note [Impredicative record selectors]` in `TcTyDecls`. Fixes #18005. - - - - - dcfe29c8 by Ömer Sinan Ağacan at 2020-04-06T13:16:08-04:00 Don't override proc CafInfos in ticky builds Fixes #17947 When we have a ticky label for a proc, IdLabels for the ticky counter and proc entry share the same Name. This caused overriding proc CafInfos with the ticky CafInfos (i.e. NoCafRefs) during SRT analysis. We now ignore the ticky labels when building SRTMaps. This makes sense because: - When building the current module they don't need to be in SRTMaps as they're initialized as non-CAFFY (see mkRednCountsLabel), so they don't take part in the dependency analysis and they're never added to SRTs. (Reminder: a "dependency" in the SRT analysis is a CAFFY dependency, non-CAFFY uses are not considered as dependencies for the algorithm) - They don't appear in the interfaces as they're not exported, so it doesn't matter for cross-module concerns whether they're in the SRTMap or not. See also the new Note [Ticky labels in SRT analysis]. - - - - - cec2c71f by Simon Peyton Jones at 2020-04-06T13:16:44-04:00 Fix an tricky specialiser loop Issue #17151 was a very tricky example of a bug in which the specialiser accidentally constructs a recurive dictionary, so that everything turns into bottom. I have fixed variants of this bug at least twice before: see Note [Avoiding loops]. It was a bit of a struggle to isolate the problem, greatly aided by the work that Alexey Kuleshevich did in distilling a test case. Once I'd understood the problem, it was not difficult to fix, though it did lead me a bit of refactoring in specImports. - - - - - e850d14f by Simon Peyton Jones at 2020-04-06T13:16:44-04:00 Refactoring only This refactors DictBinds into a data type rather than a pair. No change in behaviour, just better code - - - - - f38e8d61 by Daniel Gröber at 2020-04-07T02:00:05-04:00 rts: ProfHeap: Fix memory leak when not compiled with profiling If we're doing heap profiling on an unprofiled executable we keep allocating new space in initEra via nextEra on each profiler run but we don't have a corresponding freeEra call. We do free the last era in endHeapProfiling but previous eras will have been overwritten by initEra and will never get free()ed. Metric Decrease: space_leak_001 - - - - - bcd66859 by Sebastian Graf at 2020-04-07T02:00:41-04:00 Re-export GHC.Magic.noinline from base - - - - - 3d2991f8 by Ben Gamari at 2020-04-07T18:36:09-04:00 simplifier: Kill off ufKeenessFactor We used to have another factor, ufKeenessFactor, which would scale the discounts before they were subtracted from the size. This was justified with the following comment: -- We multiple the raw discounts (args_discount and result_discount) -- ty opt_UnfoldingKeenessFactor because the former have to do with -- *size* whereas the discounts imply that there's some extra -- *efficiency* to be gained (e.g. beta reductions, case reductions) -- by inlining. However, this is highly suspect since it means that we subtract a *scaled* size from an absolute size, resulting in crazy (e.g. negative) scores in some cases (#15304). We consequently killed off ufKeenessFactor and bumped up the ufUseThreshold to compensate. Adjustment of unfolding use threshold ===================================== Since this removes a discount from our inlining heuristic, I revisited our default choice of -funfolding-use-threshold to minimize the change in overall inlining behavior. Specifically, I measured runtime allocations and executable size of nofib and the testsuite performance tests built using compilers (and core libraries) built with several values of -funfolding-use-threshold. This comes as a result of a quantitative comparison of testsuite performance and code size as a function of ufUseThreshold, comparing GHC trees using values of 50, 60, 70, 80, 90, and 100. The test set consisted of nofib and the testsuite performance tests. A full summary of these measurements are found in the description of !2608 Comparing executable sizes (relative to the base commit) across all nofib tests, we see that sizes are similar to the baseline: gmean min max median thresh 50 -6.36% -7.04% -4.82% -6.46% 60 -5.04% -5.97% -3.83% -5.11% 70 -2.90% -3.84% -2.31% -2.92% 80 -0.75% -2.16% -0.42% -0.73% 90 +0.24% -0.41% +0.55% +0.26% 100 +1.36% +0.80% +1.64% +1.37% baseline +0.00% +0.00% +0.00% +0.00% Likewise, looking at runtime allocations we see that 80 gives slightly better optimisation than the baseline: gmean min max median thresh 50 +0.16% -0.16% +4.43% +0.00% 60 +0.09% -0.00% +3.10% +0.00% 70 +0.04% -0.09% +2.29% +0.00% 80 +0.02% -1.17% +2.29% +0.00% 90 -0.02% -2.59% +1.86% +0.00% 100 +0.00% -2.59% +7.51% -0.00% baseline +0.00% +0.00% +0.00% +0.00% Finally, I had to add a NOINLINE in T4306 to ensure that `upd` is worker-wrappered as the test expects. This makes me wonder whether the inlining heuristic is now too liberal as `upd` is quite a large function. The same measure was taken in T12600. Wall clock time compiling Cabal with -O0 thresh 50 60 70 80 90 100 baseline build-Cabal 93.88 89.58 92.59 90.09 100.26 94.81 89.13 Also, this change happens to avoid the spurious test output in `plugin-recomp-change` and `plugin-recomp-change-prof` (see #17308). Metric Decrease: hie002 T12234 T13035 T13719 T14683 T4801 T5631 T5642 T9020 T9872d T9961 Metric Increase: T12150 T12425 T13701 T14697 T15426 T1969 T3064 T5837 T6048 T9203 T9872a T9872b T9872c T9872d haddock.Cabal haddock.base haddock.compiler - - - - - 255418da by Sylvain Henry at 2020-04-07T18:36:49-04:00 Modules: type-checker (#13009) Update Haddock submodule - - - - - 04b6cf94 by Ryan Scott at 2020-04-07T19:43:20-04:00 Make NoExtCon fields strict This changes every unused TTG extension constructor to be strict in its field so that the pattern-match coverage checker is smart enough any such constructors are unreachable in pattern matches. This lets us remove nearly every use of `noExtCon` in the GHC API. The only ones we cannot remove are ones underneath uses of `ghcPass`, but that is only because GHC 8.8's and 8.10's coverage checkers weren't smart enough to perform this kind of reasoning. GHC HEAD's coverage checker, on the other hand, _is_ smart enough, so we guard these uses of `noExtCon` with CPP for now. Bumps the `haddock` submodule. Fixes #17992. - - - - - 7802fa17 by Ryan Scott at 2020-04-08T16:43:44-04:00 Handle promoted data constructors in typeToLHsType correctly Instead of using `nlHsTyVar`, which hardcodes `NotPromoted`, have `typeToLHsType` pick between `Promoted` and `NotPromoted` by checking if a type constructor is promoted using `isPromotedDataCon`. Fixes #18020. - - - - - ce481361 by Ben Gamari at 2020-04-09T16:17:21-04:00 hadrian: Use --export-dynamic when linking iserv As noticed in #17962, the make build system currently does this (see 3ce0e0ba) but the change was never ported to Hadrian. - - - - - fa66f143 by Ben Gamari at 2020-04-09T16:17:21-04:00 iserv: Don't pass --export-dynamic on FreeBSD This is definitely a hack but it's probably the best we can do for now. Hadrian does the right thing here by passing --export-dynamic only to the linker. - - - - - 39075176 by Ömer Sinan Ağacan at 2020-04-09T16:18:00-04:00 Fix CNF handling in compacting GC Fixes #17937 Previously compacting GC simply ignored CNFs. This is mostly fine as most (see "What about small compacts?" below) CNF objects don't have outgoing pointers, and are "large" (allocated in large blocks) and large objects are not moved or compacted. However if we do GC *during* sharing-preserving compaction then the CNF will have a hash table mapping objects that have been moved to the CNF to their location in the CNF, to be able to preserve sharing. This case is handled in the copying collector, in `scavenge_compact`, where we evacuate hash table entries and then rehash the table. Compacting GC ignored this case. We now visit CNFs in all generations when threading pointers to the compacted heap and thread hash table keys. A visited CNF is added to the list `nfdata_chain`. After compaction is done, we re-visit the CNFs in that list and rehash the tables. The overhead is minimal: the list is static in `Compact.c`, and link field is added to `StgCompactNFData` closure. Programs that don't use CNFs should not be affected. To test this CNF tests are now also run in a new way 'compacting_gc', which just passes `-c` to the RTS, enabling compacting GC for the oldest generation. Before this patch the result would be: Unexpected failures: compact_gc.run compact_gc [bad exit code (139)] (compacting_gc) compact_huge_array.run compact_huge_array [bad exit code (1)] (compacting_gc) With this patch all tests pass. I can also pass `-c -DS` without any failures. What about small compacts? Small CNFs are still not handled by the compacting GC. However so far I'm unable to write a test that triggers a runtime panic ("update_fwd: unknown/strange object") by allocating a small CNF in a compated heap. It's possible that I'm missing something and it's not possible to have a small CNF. NoFib Results: -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS +0.1% 0.0% 0.0% +0.0% +0.0% CSD +0.1% 0.0% 0.0% 0.0% 0.0% FS +0.1% 0.0% 0.0% 0.0% 0.0% S +0.1% 0.0% 0.0% 0.0% 0.0% VS +0.1% 0.0% 0.0% 0.0% 0.0% VSD +0.1% 0.0% +0.0% +0.0% -0.0% VSM +0.1% 0.0% +0.0% -0.0% 0.0% anna +0.0% 0.0% -0.0% -0.0% -0.0% ansi +0.1% 0.0% +0.0% +0.0% +0.0% atom +0.1% 0.0% +0.0% +0.0% +0.0% awards +0.1% 0.0% +0.0% +0.0% +0.0% banner +0.1% 0.0% +0.0% +0.0% +0.0% bernouilli +0.1% 0.0% 0.0% -0.0% +0.0% binary-trees +0.1% 0.0% -0.0% -0.0% 0.0% boyer +0.1% 0.0% +0.0% +0.0% +0.0% boyer2 +0.1% 0.0% +0.0% +0.0% +0.0% bspt +0.1% 0.0% -0.0% -0.0% -0.0% cacheprof +0.1% 0.0% -0.0% -0.0% -0.0% calendar +0.1% 0.0% +0.0% +0.0% +0.0% cichelli +0.1% 0.0% +0.0% +0.0% +0.0% circsim +0.1% 0.0% +0.0% +0.0% +0.0% clausify +0.1% 0.0% -0.0% +0.0% +0.0% comp_lab_zift +0.1% 0.0% +0.0% +0.0% +0.0% compress +0.1% 0.0% +0.0% +0.0% 0.0% compress2 +0.1% 0.0% -0.0% 0.0% 0.0% constraints +0.1% 0.0% +0.0% +0.0% +0.0% cryptarithm1 +0.1% 0.0% +0.0% +0.0% +0.0% cryptarithm2 +0.1% 0.0% +0.0% +0.0% +0.0% cse +0.1% 0.0% +0.0% +0.0% +0.0% digits-of-e1 +0.1% 0.0% +0.0% -0.0% -0.0% digits-of-e2 +0.1% 0.0% -0.0% -0.0% -0.0% dom-lt +0.1% 0.0% +0.0% +0.0% +0.0% eliza +0.1% 0.0% +0.0% +0.0% +0.0% event +0.1% 0.0% +0.0% +0.0% +0.0% exact-reals +0.1% 0.0% +0.0% +0.0% +0.0% exp3_8 +0.1% 0.0% +0.0% -0.0% 0.0% expert +0.1% 0.0% +0.0% +0.0% +0.0% fannkuch-redux +0.1% 0.0% -0.0% 0.0% 0.0% fasta +0.1% 0.0% -0.0% +0.0% +0.0% fem +0.1% 0.0% -0.0% +0.0% 0.0% fft +0.1% 0.0% -0.0% +0.0% +0.0% fft2 +0.1% 0.0% +0.0% +0.0% +0.0% fibheaps +0.1% 0.0% +0.0% +0.0% +0.0% fish +0.1% 0.0% +0.0% +0.0% +0.0% fluid +0.0% 0.0% +0.0% +0.0% +0.0% fulsom +0.1% 0.0% -0.0% +0.0% 0.0% gamteb +0.1% 0.0% +0.0% +0.0% 0.0% gcd +0.1% 0.0% +0.0% +0.0% +0.0% gen_regexps +0.1% 0.0% -0.0% +0.0% 0.0% genfft +0.1% 0.0% +0.0% +0.0% +0.0% gg +0.1% 0.0% 0.0% +0.0% +0.0% grep +0.1% 0.0% -0.0% +0.0% +0.0% hidden +0.1% 0.0% +0.0% -0.0% 0.0% hpg +0.1% 0.0% -0.0% -0.0% -0.0% ida +0.1% 0.0% +0.0% +0.0% +0.0% infer +0.1% 0.0% +0.0% 0.0% -0.0% integer +0.1% 0.0% +0.0% +0.0% +0.0% integrate +0.1% 0.0% -0.0% -0.0% -0.0% k-nucleotide +0.1% 0.0% +0.0% +0.0% 0.0% kahan +0.1% 0.0% +0.0% +0.0% +0.0% knights +0.1% 0.0% -0.0% -0.0% -0.0% lambda +0.1% 0.0% +0.0% +0.0% -0.0% last-piece +0.1% 0.0% +0.0% 0.0% 0.0% lcss +0.1% 0.0% +0.0% +0.0% 0.0% life +0.1% 0.0% -0.0% +0.0% +0.0% lift +0.1% 0.0% +0.0% +0.0% +0.0% linear +0.1% 0.0% -0.0% +0.0% 0.0% listcompr +0.1% 0.0% +0.0% +0.0% +0.0% listcopy +0.1% 0.0% +0.0% +0.0% +0.0% maillist +0.1% 0.0% +0.0% -0.0% -0.0% mandel +0.1% 0.0% +0.0% +0.0% 0.0% mandel2 +0.1% 0.0% +0.0% +0.0% +0.0% mate +0.1% 0.0% +0.0% 0.0% +0.0% minimax +0.1% 0.0% -0.0% 0.0% -0.0% mkhprog +0.1% 0.0% +0.0% +0.0% +0.0% multiplier +0.1% 0.0% +0.0% 0.0% 0.0% n-body +0.1% 0.0% +0.0% +0.0% +0.0% nucleic2 +0.1% 0.0% +0.0% +0.0% +0.0% para +0.1% 0.0% 0.0% +0.0% +0.0% paraffins +0.1% 0.0% +0.0% -0.0% 0.0% parser +0.1% 0.0% -0.0% -0.0% -0.0% parstof +0.1% 0.0% +0.0% +0.0% +0.0% pic +0.1% 0.0% -0.0% -0.0% 0.0% pidigits +0.1% 0.0% +0.0% -0.0% -0.0% power +0.1% 0.0% +0.0% +0.0% +0.0% pretty +0.1% 0.0% -0.0% -0.0% -0.1% primes +0.1% 0.0% -0.0% -0.0% -0.0% primetest +0.1% 0.0% -0.0% -0.0% -0.0% prolog +0.1% 0.0% -0.0% -0.0% -0.0% puzzle +0.1% 0.0% -0.0% -0.0% -0.0% queens +0.1% 0.0% +0.0% +0.0% +0.0% reptile +0.1% 0.0% -0.0% -0.0% +0.0% reverse-complem +0.1% 0.0% +0.0% 0.0% -0.0% rewrite +0.1% 0.0% -0.0% -0.0% -0.0% rfib +0.1% 0.0% +0.0% +0.0% +0.0% rsa +0.1% 0.0% -0.0% +0.0% -0.0% scc +0.1% 0.0% -0.0% -0.0% -0.1% sched +0.1% 0.0% +0.0% +0.0% +0.0% scs +0.1% 0.0% +0.0% +0.0% +0.0% simple +0.1% 0.0% -0.0% -0.0% -0.0% solid +0.1% 0.0% +0.0% +0.0% +0.0% sorting +0.1% 0.0% -0.0% -0.0% -0.0% spectral-norm +0.1% 0.0% +0.0% +0.0% +0.0% sphere +0.1% 0.0% -0.0% -0.0% -0.0% symalg +0.1% 0.0% -0.0% -0.0% -0.0% tak +0.1% 0.0% +0.0% +0.0% +0.0% transform +0.1% 0.0% +0.0% +0.0% +0.0% treejoin +0.1% 0.0% +0.0% -0.0% -0.0% typecheck +0.1% 0.0% +0.0% +0.0% +0.0% veritas +0.0% 0.0% +0.0% +0.0% +0.0% wang +0.1% 0.0% 0.0% +0.0% +0.0% wave4main +0.1% 0.0% +0.0% +0.0% +0.0% wheel-sieve1 +0.1% 0.0% +0.0% +0.0% +0.0% wheel-sieve2 +0.1% 0.0% +0.0% +0.0% +0.0% x2n1 +0.1% 0.0% +0.0% +0.0% +0.0% -------------------------------------------------------------------------------- Min +0.0% 0.0% -0.0% -0.0% -0.1% Max +0.1% 0.0% +0.0% +0.0% +0.0% Geometric Mean +0.1% -0.0% -0.0% -0.0% -0.0% Bumping numbers of nonsensical perf tests: Metric Increase: T12150 T12234 T12425 T13035 T5837 T6048 It's simply not possible for this patch to increase allocations, and I've wasted enough time on these test in the past (see #17686). I think these tests should not be perf tests, but for now I'll bump the numbers. - - - - - dce50062 by Sylvain Henry at 2020-04-09T16:18:44-04:00 Rts: show errno on failure (#18033) - - - - - 045139f4 by Hécate at 2020-04-09T23:10:44-04:00 Add an example to liftIO and explain its purpose - - - - - 101fab6e by Sebastian Graf at 2020-04-09T23:11:21-04:00 Special case `isConstraintKindCon` on `AlgTyCon` Previously, the `tyConUnique` record selector would unfold into a huge case expression that would be inlined in all call sites, such as the `INLINE`-annotated `coreView`, see #18026. `constraintKindTyConKey` only occurs as the `Unique` of an `AlgTyCon` anyway, so we can make the code a lot more compact, but have to move it to GHC.Core.TyCon. Metric Decrease: T12150 T12234 - - - - - f5212dfc by Sebastian Graf at 2020-04-09T23:11:57-04:00 DmdAnal: No need to attach a StrictSig to DataCon workers In GHC.Types.Id.Make we were giving a strictness signature to every data constructor wrapper Id that we weren't looking at in demand analysis anyway. We used to use its CPR info, but that has its own CPR signature now. `Note [Data-con worker strictness]` then felt very out of place, so I moved it to GHC.Core.DataCon. - - - - - 75a185dc by Sylvain Henry at 2020-04-09T23:12:37-04:00 Hadrian: fix --summary - - - - - 723062ed by Ömer Sinan Ağacan at 2020-04-10T09:18:14+03:00 testsuite: Move no_lint to the top level, tweak hie002 - We don't want to benchmark linting so disable lints in hie002 perf test - Move no_lint to the top-level to be able to use it in tests other than those in `testsuite/tests/perf/compiler`. - Filter out -dstg-lint in no_lint. - hie002 allocation numbers on 32-bit are unstable, so skip it on 32-bit Metric Decrease: hie002 ManyConstructors T12150 T12234 T13035 T1969 T4801 T9233 T9961 - - - - - bcafaa82 by Peter Trommler at 2020-04-10T19:29:33-04:00 Testsuite: mark T11531 fragile The test depends on a link editor allowing undefined symbols in an ELF shared object. This is the standard but it seems some distributions patch their link editor. See the report by @hsyl20 in #11531. Fixes #11531 - - - - - 0889f5ee by Takenobu Tani at 2020-04-12T11:44:52+09:00 testsuite: Fix comment for a language extension [skip ci] - - - - - cd4f92b5 by Simon Peyton Jones at 2020-04-12T11:20:58-04:00 Significant refactor of Lint This refactoring of Lint was triggered by #17923, which is fixed by this patch. The main change is this. Instead of lintType :: Type -> LintM LintedKind we now have lintType :: Type -> LintM LintedType Previously, all of typeKind was effectively duplicate in lintType. Moreover, since we have an ambient substitution, we still had to apply the substition here and there, sometimes more than once. It was all very tricky, in the end, and made my head hurt. Now, lintType returns a fully linted type, with all substitutions performed on it. This is much simpler. The same thing is needed for Coercions. Instead of lintCoercion :: OutCoercion -> LintM (LintedKind, LintedKind, LintedType, LintedType, Role) we now have lintCoercion :: Coercion -> LintM LintedCoercion Much simpler! The code is shorter and less bug-prone. There are a lot of knock on effects. But life is now better. Metric Decrease: T1969 - - - - - 0efaf301 by Josh Meredith at 2020-04-12T11:21:34-04:00 Implement extensible interface files - - - - - 54ca66a7 by Ryan Scott at 2020-04-12T11:22:10-04:00 Use conLikeUserTyVarBinders to quantify field selector types This patch: 1. Writes up a specification for how the types of top-level field selectors should be determined in a new section of the GHC User's Guide, and 2. Makes GHC actually implement that specification by using `conLikeUserTyVarBinders` in `mkOneRecordSelector` to preserve the order and specificity of type variables written by the user. Fixes #18023. - - - - - 35799dda by Ben Gamari at 2020-04-12T11:22:50-04:00 hadrian: Don't --export-dynamic on Darwin When fixing #17962 I neglected to consider that --export-dynamic is only supported on ELF platforms. - - - - - e8029816 by Alexis King at 2020-04-12T11:23:27-04:00 Add an INLINE pragma to Control.Category.>>> This fixes #18013 by adding INLINE pragmas to both Control.Category.>>> and GHC.Desugar.>>>. The functional change in this patch is tiny (just two lines of pragmas!), but an accompanying Note explains in gory detail what’s going on. - - - - - 0da186c1 by Krzysztof Gogolewski at 2020-04-14T07:55:20-04:00 Change zipWith to zipWithEqual in a few places - - - - - 074c1ccd by Andreas Klebinger at 2020-04-14T07:55:55-04:00 Small change to the windows ticker. We already have a function to go from time to ms so use it. Also expand on the state of timer resolution. - - - - - b69cc884 by Alp Mestanogullari at 2020-04-14T07:56:38-04:00 hadrian: get rid of unnecessary levels of nesting in source-dist - - - - - d0c3b069 by Julien Debon at 2020-04-14T07:57:16-04:00 doc (Foldable): Add examples to Data.Foldable See #17929 - - - - - 5b08e0c0 by Ben Gamari at 2020-04-14T23:28:20-04:00 StgCRun: Enable unwinding only on Linux It's broken on macOS due and SmartOS due to assembler differences (#15207) so let's be conservative in enabling it. Also, refactor things to make the intent clearer. - - - - - 27cc2e7b by Ben Gamari at 2020-04-14T23:28:57-04:00 rts: Don't mark evacuate_large as inline This function has two callsites and is quite large. GCC consequently decides not to inline and warns instead. Given the situation, I can't blame it. Let's just remove the inline specifier. - - - - - 9853fc5e by Ben Gamari at 2020-04-14T23:29:48-04:00 base: Enable large file support for OFD locking impl. Not only is this a good idea in general but this should also avoid issue #17950 by ensuring that off_t is 64-bits. - - - - - 7b41f21b by Matthew Pickering at 2020-04-14T23:30:24-04:00 Hadrian: Make -i paths absolute The primary reason for this change is that ghcide does not work with relative paths. It also matches what cabal and stack do, they always pass absolute paths. - - - - - 41230e26 by Daniel Gröber at 2020-04-14T23:31:01-04:00 Zero out pinned block alignment slop when profiling The heap profiler currently cannot traverse pinned blocks because of alignment slop. This used to just be a minor annoyance as the whole block is accounted into a special cost center rather than the respective object's CCS, cf. #7275. However for the new root profiler we would like to be able to visit _every_ closure on the heap. We need to do this so we can get rid of the current 'flip' bit hack in the heap traversal code. Since info pointers are always non-zero we can in principle skip all the slop in the profiler if we can rely on it being zeroed. This assumption caused problems in the past though, commit a586b33f8e ("rts: Correct handling of LARGE ARR_WORDS in LDV profiler"), part of !1118, tried to use the same trick for BF_LARGE objects but neglected to take into account that shrink*Array# functions don't ensure that slop is zeroed when not compiling with profiling. Later, commit 0c114c6599 ("Handle large ARR_WORDS in heap census (fix as we will only be assuming slop is zeroed when profiling is on. This commit also reduces the ammount of slop we introduce in the first place by calculating the needed alignment before doing the allocation for small objects where we know the next available address. For large objects we don't know how much alignment we'll have to do yet since those details are hidden behind the allocateMightFail function so there we continue to allocate the maximum additional words we'll need to do the alignment. So we don't have to duplicate all this logic in the cmm code we pull it into the RTS allocatePinned function instead. Metric Decrease: T7257 haddock.Cabal haddock.base - - - - - 15fa9bd6 by Daniel Gröber at 2020-04-14T23:31:01-04:00 rts: Expand and add more notes regarding slop - - - - - caf3f444 by Daniel Gröber at 2020-04-14T23:31:01-04:00 rts: allocatePinned: Fix confusion about word/byte units - - - - - c3c0f662 by Daniel Gröber at 2020-04-14T23:31:01-04:00 rts: Underline some Notes as is conventional - - - - - e149dea9 by Daniel Gröber at 2020-04-14T23:31:38-04:00 rts: Fix nomenclature in OVERWRITING_CLOSURE macros The additional commentary introduced by commit 8916e64e5437 ("Implement shrinkSmallMutableArray# and resizeSmallMutableArray#.") unfortunately got this wrong. We set 'prim' to true in overwritingClosureOfs because we _don't_ want to call LDV_recordDead(). The reason is because of this "inherently used" distinction made in the LDV profiler so I rename the variable to be more appropriate. - - - - - 1dd3d18c by Daniel Gröber at 2020-04-14T23:31:38-04:00 Remove call to LDV_RECORD_CREATE for array resizing - - - - - 19de2fb0 by Daniel Gröber at 2020-04-14T23:31:38-04:00 rts: Assert LDV_recordDead is not called for inherently used closures The comments make it clear LDV_recordDead should not be called for inhererently used closures, so add an assertion to codify this fact. - - - - - 0b934e30 by Ryan Scott at 2020-04-14T23:32:14-04:00 Bump template-haskell version to 2.17.0.0 This requires bumping the `exceptions` and `text` submodules to bring in commits that bump their respective upper version bounds on `template-haskell`. Fixes #17645. Fixes #17696. Note that the new `text` commit includes a fair number of additions to the Haddocks in that library. As a result, Haddock has to do more work during the `haddock.Cabal` test case, increasing the number of allocations it requires. Therefore, ------------------------- Metric Increase: haddock.Cabal ------------------------- - - - - - 22cc8e51 by Ryan Scott at 2020-04-15T17:48:47-04:00 Fix #18052 by using pprPrefixOcc in more places This fixes several small oversights in the choice of pretty-printing function to use. Fixes #18052. - - - - - ec77b2f1 by Daniel Gröber at 2020-04-15T17:49:24-04:00 rts: ProfHeap: Fix wrong time in last heap profile sample We've had this longstanding issue in the heap profiler, where the time of the last sample in the profile is sometimes way off causing the rendered graph to be quite useless for long runs. It seems to me the problem is that we use mut_user_time() for the last sample as opposed to getRTSStats(), which we use when calling heapProfile() in GC.c. The former is equivalent to getProcessCPUTime() but the latter does some additional stuff: getProcessCPUTime() - end_init_cpu - stats.gc_cpu_ns - stats.nonmoving_gc_cpu_ns So to fix this just use getRTSStats() in both places. - - - - - 85fc32f0 by Sylvain Henry at 2020-04-17T12:45:25-04:00 Hadrian: fix dyn_o/dyn_hi rule (#17534) - - - - - bfde3b76 by Ryan Scott at 2020-04-17T12:46:02-04:00 Fix #18065 by fixing an InstCo oversight in Core Lint There was a small thinko in Core Lint's treatment of `InstCo` coercions that ultimately led to #18065. The fix: add an apostrophe. That's it! Fixes #18065. Co-authored-by: Simon Peyton Jones <simonpj at microsoft.com> - - - - - a05348eb by Cale Gibbard at 2020-04-17T13:08:47-04:00 Change the fail operator argument of BindStmt to be a Maybe Don't use noSyntaxExpr for it. There is no good way to defensively case on that, nor is it clear one ought to do so. - - - - - 79e27144 by John Ericson at 2020-04-17T13:08:47-04:00 Use trees that grow for rebindable operators for `<-` binds Also add more documentation. - - - - - 18bc16ed by Cale Gibbard at 2020-04-17T13:08:47-04:00 Use FailOperator in more places, define a couple datatypes (XBindStmtRn and XBindStmtTc) to help clarify the meaning of XBindStmt in the renamer and typechecker - - - - - 84cc8394 by Simon Peyton Jones at 2020-04-18T13:20:29-04:00 Add a missing zonk in tcHsPartialType I omitted a vital zonk when refactoring tcHsPartialType in commit 48fb3482f8cbc8a4b37161021e846105f980eed4 Author: Simon Peyton Jones <simonpj at microsoft.com> Date: Wed Jun 5 08:55:17 2019 +0100 Fix typechecking of partial type signatures This patch fixes it and adds commentary to explain why. Fixes #18008 - - - - - 2ee96ac1 by Ben Gamari at 2020-04-18T13:21:05-04:00 gitlab-ci: Bump FreeBSD bootstrap compiler to 8.10.1 - - - - - 434312e5 by Ben Gamari at 2020-04-18T13:21:05-04:00 gitlab-ci: Enable FreeBSD job for so-labelled MRs - - - - - ddffb227 by Ben Gamari at 2020-04-18T13:21:05-04:00 gitlab-ci: Use rules syntax for conditional jobs - - - - - e2586828 by Ben Gamari at 2020-04-18T13:21:05-04:00 Bump hsc2hs submodule - - - - - 15ab6cd5 by Ömer Sinan Ağacan at 2020-04-18T13:21:44-04:00 Improve prepForeignCall error reporting Show parameters and description of the error code when ffi_prep_cif fails. This may be helpful for debugging #17018. - - - - - 3ca52151 by Sylvain Henry at 2020-04-18T20:04:14+02:00 GHC.Core.Opt renaming * GHC.Core.Op => GHC.Core.Opt * GHC.Core.Opt.Simplify.Driver => GHC.Core.Opt.Driver * GHC.Core.Opt.Tidy => GHC.Core.Tidy * GHC.Core.Opt.WorkWrap.Lib => GHC.Core.Opt.WorkWrap.Utils As discussed in: * https://mail.haskell.org/pipermail/ghc-devs/2020-April/018758.html * https://gitlab.haskell.org/ghc/ghc/issues/13009#note_264650 - - - - - 15312bbb by Sylvain Henry at 2020-04-18T20:04:46+02:00 Modules (#13009) * SysTools * Parser * GHC.Builtin * GHC.Iface.Recomp * Settings Update Haddock submodule Metric Decrease: Naperian parsing001 - - - - - eaed0a32 by Alexis King at 2020-04-19T03:16:44-04:00 Add missing addInScope call for letrec binders in OccurAnal This fixes #18044, where a shadowed variable was incorrectly substituted by the binder swap on the RHS of a floated-in letrec. This can only happen when the uniques line up *just* right, so writing a regression test would be very difficult, but at least the fix is small and straightforward. - - - - - 36882493 by Shayne Fletcher at 2020-04-20T04:36:43-04:00 Derive Ord instance for Extension Metric Increase: T12150 T12234 - - - - - b43365ad by Simon Peyton Jones at 2020-04-20T04:37:20-04:00 Fix a buglet in redundant-constraint warnings Ticket #18036 pointed out that we were reporting a redundant constraint when it really really wasn't. Turned out to be a buglet in the SkolemInfo for the relevant implication constraint. Easily fixed! - - - - - d5fae7da by Ömer Sinan Ağacan at 2020-04-20T14:39:28-04:00 Mark T12010 fragile on 32-bit - - - - - bca02fca by Adam Sandberg Ericsson at 2020-04-21T06:38:45-04:00 docs: drop note about not supporting shared libraries on unix systems [skip ci] - - - - - 6655f933 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Use ParserFlags in GHC.Runtime.Eval (#17957) Instead of passing `DynFlags` to functions such as `isStmt` and `hasImport` in `GHC.Runtime.Eval` we pass `ParserFlags`. It's a much simpler structure that can be created purely with `mkParserFlags'`. - - - - - 70be0fbc by Sylvain Henry at 2020-04-21T06:39:32-04:00 GHC.Runtime: avoid DynFlags (#17957) * add `getPlatform :: TcM Platform` helper * remove unused `DynFlags` parameter from `emptyPLS` - - - - - 35e43d48 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Avoid DynFlags in Ppr code (#17957) * replace `DynFlags` parameters with `SDocContext` parameters for a few Ppr related functions: `bufLeftRenderSDoc`, `printSDoc`, `printSDocLn`, `showSDocOneLine`. * remove the use of `pprCols :: DynFlags -> Int` in Outputable. We already have the information via `sdocLineLength :: SDocContext -> Int` - - - - - ce5c2999 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Avoid using sdocWithDynFlags (#17957) Remove one use of `sdocWithDynFlags` from `GHC.CmmToLlvm.llvmCodeGen'` and from `GHC.Driver.CodeOutput.profilingInitCode` - - - - - f2a98996 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Avoid `sdocWithDynFlags` in `pprCLbl` (#17957) * add a `DynFlags` parameter to `pprCLbl` * put `maybe_underscore` and `pprAsmCLbl` in a `where` clause to avoid `DynFlags` parameters - - - - - 747093b7 by Sylvain Henry at 2020-04-21T06:39:32-04:00 CmmToAsm DynFlags refactoring (#17957) * Remove `DynFlags` parameter from `isDynLinkName`: `isDynLinkName` used to test the global `ExternalDynamicRefs` flag. Now we test it outside of `isDynLinkName` * Add new fields into `NCGConfig`: current unit id, sse/bmi versions, externalDynamicRefs, etc. * Replace many uses of `DynFlags` by `NCGConfig` * Moved `BMI/SSE` datatypes into `GHC.Platform` - - - - - ffd7eef2 by Takenobu Tani at 2020-04-22T23:09:50-04:00 stg-spec: Modify file paths according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * GHC/Stg/Syntax.hs <= stgSyn/StgSyn.hs * GHC/Types/Literal.hs <= basicTypes/Literal.hs * GHC/Types/CostCentre.hs <= profiling/CostCentre.hs This patch also updates old file path [2]: * utils/genapply/Main.hs <= utils/genapply/GenApply.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: commit 0cc4aad36f [skip ci] - - - - - e8a5d81b by Jonathan DK Gibbons at 2020-04-22T23:10:28-04:00 Refactor the `MatchResult` type in the desugarer This way, it does a better job of proving whether or not the fail operator is used. - - - - - dcb7fe5a by John Ericson at 2020-04-22T23:10:28-04:00 Remove panic in dsHandleMonadicFailure Rework dsHandleMonadicFailure to be correct by construction instead of using an unreachable panic. - - - - - cde23cd4 by John Ericson at 2020-04-22T23:10:28-04:00 Inline `adjustMatchResult` It is just `fmap` - - - - - 72cb6bcc by John Ericson at 2020-04-22T23:10:28-04:00 Generalize type of `matchCanFail` - - - - - 401f7bb3 by John Ericson at 2020-04-22T23:10:28-04:00 `MatchResult'` -> `MatchResult` Inline `MatchResult` alias accordingly. - - - - - 6c9fae23 by Alexis King at 2020-04-22T23:11:12-04:00 Mark DataCon wrappers CONLIKE Now that DataCon wrappers don’t inline until phase 0 (see commit b78cc64e923716ac0512c299f42d4d0012306c05), it’s important that case-of-known-constructor and RULE matching be able to see saturated applications of DataCon wrappers in unfoldings. Making them conlike is a natural way to do it, since they are, in fact, precisely the sort of thing the CONLIKE pragma exists to solve. Fixes #18012. This also bumps the version of the parsec submodule to incorporate a patch that avoids a metric increase on the haddock perf tests. The increase was not really a flaw in this patch, as parsec was implicitly relying on inlining heuristics. The patch to parsec just adds some INLINABLE pragmas, and we get a nice performance bump out of it (well beyond the performance we lost from this patch). Metric Decrease: T12234 WWRec haddock.Cabal haddock.base haddock.compiler - - - - - 48b8951e by Roland Senn at 2020-04-22T23:11:51-04:00 Fix tab-completion for :break (#17989) In tab-completion for the `:break` command, only those identifiers should be shown, that are accepted in the `:break` command. Hence these identifiers must be - defined in an interpreted module - top-level - currently in scope - listed in a `ModBreaks` value as a possible breakpoint. The identifiers my be qualified or unqualified. To get all possible top-level breakpoints for tab-completeion with the correct qualification do: 1. Build the list called `pifsBreaks` of all pairs of (Identifier, module-filename) from the `ModBreaks` values. Here all identifiers are unqualified. 2. Build the list called `pifInscope` of all pairs of (Identifiers, module-filename) with identifiers from the `GlobalRdrEnv`. Take only those identifiers that are in scope and have the correct prefix. Here the identifiers may be qualified. 3. From the `pifInscope` list seclect all pairs that can be found in the `pifsBreaks` list, by comparing only the unqualified part of the identifier. The remaining identifiers can be used for tab-completion. This ensures, that we show only identifiers, that can be used in a `:break` command. - - - - - 34a45ee6 by Peter Trommler at 2020-04-22T23:12:27-04:00 PPC NCG: Add DWARF constants and debug labels Fixes #11261 - - - - - ffde2348 by Simon Peyton Jones at 2020-04-22T23:13:06-04:00 Do eager instantation in terms This patch implements eager instantiation, a small but critical change to the type inference engine, #17173. The main change is this: When inferring types, always return an instantiated type (for now, deeply instantiated; in future shallowly instantiated) There is more discussion in https://www.tweag.io/posts/2020-04-02-lazy-eager-instantiation.html There is quite a bit of refactoring in this patch: * The ir_inst field of GHC.Tc.Utils.TcType.InferResultk has entirely gone. So tcInferInst and tcInferNoInst have collapsed into tcInfer. * Type inference of applications, via tcInferApp and tcInferAppHead, are substantially refactored, preparing the way for Quick Look impredicativity. * New pure function GHC.Tc.Gen.Expr.collectHsArgs and applyHsArgs are beatifully dual. We can see the zipper! * GHC.Tc.Gen.Expr.tcArgs is now much nicer; no longer needs to return a wrapper * In HsExpr, HsTypeApp now contains the the actual type argument, and is used in desugaring, rather than putting it in a mysterious wrapper. * I struggled a bit with good error reporting in Unify.matchActualFunTysPart. It's a little bit simpler than before, but still not great. Some smaller things * Rename tcPolyExpr --> tcCheckExpr tcMonoExpr --> tcLExpr * tcPatSig moves from GHC.Tc.Gen.HsType to GHC.Tc.Gen.Pat Metric Decrease: T9961 Reduction of 1.6% in comiler allocation on T9961, I think. - - - - - 6f84aca3 by Ben Gamari at 2020-04-22T23:13:43-04:00 rts: Ensure that sigaction structs are initialized I noticed these may have uninitialized fields when looking into #18037. The reporter says that zeroing them doesn't fix the MSAN failures they observe but zeroing them is the right thing to do regardless. - - - - - c29f0fa6 by Andreas Klebinger at 2020-04-22T23:14:21-04:00 Add "ddump-cmm-opt" as alias for "ddump-opt-cmm". - - - - - 4b4a8b60 by Ben Gamari at 2020-04-22T23:14:57-04:00 llvmGen: Remove -fast-llvm flag Issue #18076 drew my attention to the undocumented `-fast-llvm` flag for the LLVM code generator introduced in 22733532171330136d87533d523f565f2a4f102f. Speaking to Moritz about this, the motivation for this flag was to avoid potential incompatibilities between LLVM and the assembler/linker toolchain by making LLVM responsible for machine-code generation. Unfortunately, this cannot possibly work: the LLVM backend's mangler performs a number of transforms on the assembler generated by LLVM that are necessary for correctness. These are currently: * mangling Haskell functions' symbol types to be `object` instead of `function` on ELF platforms (necessary for tables-next-to-code) * mangling AVX instructions to ensure that we don't assume alignment (which LLVM otherwise does) * mangling Darwin's subsections-via-symbols directives Given that these are all necessary I don't believe that we can support `-fast-llvm`. Let's rather remove it. - - - - - 831b6642 by Moritz Angermann at 2020-04-22T23:15:33-04:00 Fix build warning; add more informative information to the linker; fix linker for empty sections - - - - - c409961a by Ryan Scott at 2020-04-22T23:16:12-04:00 Update commentary and slightly refactor GHC.Tc.Deriv.Infer There was some out-of-date commentary in `GHC.Tc.Deriv.Infer` that has been modernized. Along the way, I removed the `bad` constraints in `simplifyDeriv`, which did not serve any useful purpose (besides being printed in debugging output). Fixes #18073. - - - - - 125aa2b8 by Ömer Sinan Ağacan at 2020-04-22T23:16:51-04:00 Remove leftover comment in tcRnModule', redundant bind The code for the comment was moved in dc8c03b2a5c but the comment was forgotten. - - - - - 8ea37b01 by Sylvain Henry at 2020-04-22T23:17:34-04:00 RTS: workaround a Linux kernel bug in timerfd Reading a timerfd may return 0: https://lkml.org/lkml/2019/8/16/335. This is currently undocumented behavior and documentation "won't happen anytime soon" (https://lkml.org/lkml/2020/2/13/295). With this patch, we just ignore the result instead of crashing. It may fix #18033 but we can't be sure because we don't have enough information. See also this discussion about the kernel bug: https://github.com/Azure/sonic-swss-common/pull/302/files/1f070e7920c2e5d63316c0105bf4481e73d72dc9 - - - - - cd8409c2 by Ryan Scott at 2020-04-23T11:39:24-04:00 Create di_scoped_tvs for associated data family instances properly See `Note [Associated data family instances and di_scoped_tvs]` in `GHC.Tc.TyCl.Instance`, which explains all of the moving parts. Fixes #18055. - - - - - 339e8ece by Ben Gamari at 2020-04-23T11:40:02-04:00 hadrian/ghci: Allow arguments to be passed to GHCi Previously the arguments passed to hadrian/ghci were passed both to `hadrian` and GHCi. This is rather odd given that there are essentially not arguments in the intersection of the two. Let's just pass them to GHCi; this allows `hadrian/ghci -Werror`. - - - - - 5946c85a by Ben Gamari at 2020-04-23T11:40:38-04:00 testsuite: Don't attempt to read .std{err,out} files if they don't exist Simon reports that he was previously seeing framework failures due to an attempt to read the non-existing T13456.stderr. While I don't know exactly what this is due to, it does seem like a non-existing .std{out,err} file should be equivalent to an empty file. Teach the testsuite driver to treat it as such. - - - - - c42754d5 by John Ericson at 2020-04-23T18:32:43-04:00 Trees That Grow refactor for `ConPat` and `CoPat` - `ConPat{In,Out}` -> `ConPat` - `CoPat` -> `XPat (CoPat ..)` Note that `GHC.HS.*` still uses `HsWrap`, but only when `p ~ GhcTc`. After this change, moving the type family instances out of `GHC.HS.*` is sufficient to break the cycle. Add XCollectPat class to decide how binders are collected from XXPat based on the pass. Previously we did this with IsPass, but that doesn't work for Haddock's DocNameI, and the constraint doesn't express what actual distinction is being made. Perhaps a class for collecting binders more generally is in order, but we haven't attempted this yet. Pure refactor of code around ConPat - InPat/OutPat synonyms removed - rename several identifiers - redundant constraints removed - move extension field in ConPat to be first - make ConPat use record syntax more consistently Fix T6145 (ConPatIn became ConPat) Add comments from SPJ. Add comment about haddock's use of CollectPass. Updates haddock submodule. - - - - - 72da0c29 by mniip at 2020-04-23T18:33:21-04:00 Add :doc to GHC.Prim - - - - - 2c23e2e3 by mniip at 2020-04-23T18:33:21-04:00 Include docs for non-primop entries in primops.txt as well - - - - - 0ac29c88 by mniip at 2020-04-23T18:33:21-04:00 GHC.Prim docs: note and test - - - - - b0fbfc75 by John Ericson at 2020-04-24T12:07:14-04:00 Switch order on `GhcMake.IsBoot` In !1798 we were requested to replace many `Bool`s with this data type. But those bools had `False` meaning `NotBoot`, so the `Ord` instance would be flipped if we use this data-type as-is. Since the planned formally-`Bool` occurrences vastly outnumber the current occurrences, we figured it would be better to conform the `Ord` instance to how the `Bool` is used now, fixing any issues, rather than fix them currently with the bigger refactor later in !1798. That way, !1798 can be a "pure" refactor with no behavioral changes. - - - - - af332442 by Sylvain Henry at 2020-04-26T13:55:14-04:00 Modules: Utils and Data (#13009) Update Haddock submodule Metric Increase: haddock.compiler - - - - - cd4434c8 by Sylvain Henry at 2020-04-26T13:55:16-04:00 Fix misleading Ptr phantom type in SerializedCompact (#15653) - - - - - 22bf5c73 by Ömer Sinan Ağacan at 2020-04-26T13:55:22-04:00 Tweak includes in non-moving GC headers We don't use hash tables in non-moving GC so remove the includes. This breaks Compact.c as existing includes no longer include Hash.h, so include Hash.h explicitly in Compact.c. - - - - - 99823ed2 by Sylvain Henry at 2020-04-27T20:24:46-04:00 TH: fix Show/Eq/Ord instances for Bytes (#16457) We shouldn't compare pointer values but the actual bytes. - - - - - c62271a2 by Alp Mestanogullari at 2020-04-27T20:25:33-04:00 hadrian: always capture both stdout and stderr when running a builder fails The idea being that when a builder('s command) fails, we quite likely want to have all the information available to figure out why. Depending on the builder _and_ the particular problem, the useful bits of information can be printed on stdout or stderr. We accomplish this by defining a simple wrapper for Shake's `cmd` function, that just _always_ captures both streams in case the command returns a non-zero exit code, and by using this wrapper everywhere in `hadrian/src/Builder.hs`. Fixes #18089. - - - - - 4b9764db by Ryan Scott at 2020-04-28T15:40:04-04:00 Define a Quote IO instance Fixes #18103. - - - - - 518a63d4 by Ryan Scott at 2020-04-28T15:40:42-04:00 Make boxed 1-tuples have known keys Unlike other tuples, which use special syntax and are "known" by way of a special `isBuiltInOcc_maybe` code path, boxed 1-tuples do not use special syntax. Therefore, in order to make sure that the internals of GHC are aware of the `data Unit a = Unit a` definition in `GHC.Tuple`, we give `Unit` known keys. For the full details, see `Note [One-tuples] (Wrinkle: Make boxed one-tuple names have known keys)` in `GHC.Builtin.Types`. Fixes #18097. - - - - - 2cfc4ab9 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Document backpack fields in DynFlags - - - - - 10a2ba90 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Refactor UnitInfo * Rename InstalledPackageInfo into GenericUnitInfo The name InstalledPackageInfo is only kept for alleged backward compatibility reason in Cabal. ghc-boot has its own stripped down copy of this datatype but it doesn't need to keep the name. Internally we already use type aliases (UnitInfo in GHC, PackageCacheFormat in ghc-pkg). * Rename UnitInfo fields: add "unit" prefix and fix misleading names * Add comments on every UnitInfo field * Rename SourcePackageId into PackageId "Package" already indicates that it's a "source package". Installed package components are called units. Update Haddock submodule - - - - - 69562e34 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Remove unused `emptyGenericUnitInfo` - - - - - 9e2c8e0e by Sylvain Henry at 2020-04-30T01:56:56-04:00 Refactor UnitInfo load/store from databases Converting between UnitInfo stored in package databases and UnitInfo as they are used in ghc-pkg and ghc was done in a very convoluted way (via BinaryStringRep and DbUnitModuleRep type classes using fun deps, etc.). It was difficult to understand and even more to modify (I wanted to try to use a GADT for UnitId but fun deps got in the way). The new code uses much more straightforward functions to convert between the different representations. Much simpler. - - - - - ea717aa4 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Factorize mungePackagePaths code This patch factorizes the duplicated code used in ghc-pkg and in GHC to munge package paths/urls. It also fixes haddock-html munging in GHC (allowed to be either a file or a url) to mimic ghc-pkg behavior. - - - - - 10d15f1e by Sylvain Henry at 2020-04-30T01:56:56-04:00 Refactoring unit management code Over the years the unit management code has been modified a lot to keep up with changes in Cabal (e.g. support for several library components in the same package), to integrate BackPack, etc. I found it very hard to understand as the terminology wasn't consistent, was referring to past concepts, etc. The terminology is now explained as clearly as I could in the Note "About Units" and the code is refactored to reflect it. ------------------- Many names were misleading: UnitId is not an Id but could be a virtual unit (an indefinite one instantiated on the fly), IndefUnitId constructor may contain a definite instantiated unit, etc. * Rename IndefUnitId into InstantiatedUnit * Rename IndefModule into InstantiatedModule * Rename UnitId type into Unit * Rename IndefiniteUnitId constructor into VirtUnit * Rename DefiniteUnitId constructor into RealUnit * Rename packageConfigId into mkUnit * Rename getPackageDetails into unsafeGetUnitInfo * Rename InstalledUnitId into UnitId Remove references to misleading ComponentId: a ComponentId is just an indefinite unit-id to be instantiated. * Rename ComponentId into IndefUnitId * Rename ComponentDetails into UnitPprInfo * Fix display of UnitPprInfo with empty version: this is now used for units dynamically generated by BackPack Generalize several types (Module, Unit, etc.) so that they can be used with different unit identifier types: UnitKey, UnitId, Unit, etc. * GenModule: Module, InstantiatedModule and InstalledModule are now instances of this type * Generalize DefUnitId, IndefUnitId, Unit, InstantiatedUnit, PackageDatabase Replace BackPack fake "hole" UnitId by a proper HoleUnit constructor. Add basic support for UnitKey. They should be used more in the future to avoid mixing them up with UnitId as we do now. Add many comments. Update Haddock submodule - - - - - 8bfb0219 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Unit: split and rename modules Introduce GHC.Unit.* hierarchy for everything concerning units, packages and modules. Update Haddock submodule - - - - - 71484b09 by Alexis King at 2020-04-30T01:57:35-04:00 Allow block arguments in arrow control operators Arrow control operators have their own entries in the grammar, so they did not cooperate with BlockArguments. This was just a minor oversight, so this patch adjusts the grammar to add the desired behavior. fixes #18050 - - - - - a48cd2a0 by Alexis King at 2020-04-30T01:57:35-04:00 Allow LambdaCase to be used as a command in proc notation - - - - - f4d3773c by Alexis King at 2020-04-30T01:57:35-04:00 Document BlockArguments/LambdaCase support in arrow notation - - - - - 5bdfdd13 by Simon Peyton Jones at 2020-04-30T01:58:15-04:00 Add tests for #17873 - - - - - 19b701c2 by Simon Peyton Jones at 2020-04-30T07:30:13-04:00 Mark rule args as non-tail-called This was just an omission...b I'd failed to call markAllNonTailCall on rule args. I think this bug has been here a long time, but it's quite hard to trigger. Fixes #18098 - - - - - 014ef4a3 by Matthew Pickering at 2020-04-30T07:30:50-04:00 Hadrian: Improve tool-args command to support more components There is a new command to hadrian, tool:path/to/file.hs, which returns the options needed to compile that file in GHCi. This is now used in the ghci script with argument `ghc/Main.hs` but its main purpose is to support the new multi-component branch of ghcide. - - - - - 2aa67611 by Ben Gamari at 2020-04-30T21:34:44-04:00 nonmoving: Clear bitmap after initializing block size Previously nonmovingInitSegment would clear the bitmap before initializing the segment's block size. This is broken since nonmovingClearBitmap looks at the segment's block size to determine how much bitmap to clear. - - - - - 54dad3cf by Ben Gamari at 2020-04-30T21:34:44-04:00 nonmoving: Explicitly memoize block count A profile cast doubt on whether the compiler hoisted the bound out the loop as I would have expected here. It turns out it did but nevertheless it seems clearer to just do this manually. - - - - - 99ff8145 by Ben Gamari at 2020-04-30T21:34:44-04:00 nonmoving: Eagerly flush all capabilities' update remembered sets (cherry picked from commit 2fa79119570b358a4db61446396889b8260d7957) - - - - - 05b0a9fd by Ömer Sinan Ağacan at 2020-04-30T21:35:24-04:00 Remove OneShotInfo field of LFReEntrant, document OneShotInfo The field is only used in withNewTickyCounterFun and it's easier to directly pass a parameter for one-shot info to withNewTickyCounterFun instead of passing it via LFReEntrant. This also makes !2842 simpler. Other changes: - New Note (by SPJ) [OneShotInfo overview] added. - Arity argument of thunkCode removed as it's always 0. - - - - - a43620c6 by Ömer Sinan Ağacan at 2020-04-30T21:35:24-04:00 GHC.StgToCmm.Ticky: remove a few unused stuff - - - - - 780de9e1 by Sylvain Henry at 2020-05-01T10:37:39-04:00 Use platform in Iface Binary - - - - - f8386c7b by Sylvain Henry at 2020-05-01T10:37:39-04:00 Refactor PprDebug handling If `-dppr-debug` is set, then PprUser and PprDump styles are silently replaced with PprDebug style. This was done in `mkUserStyle` and `mkDumpStyle` smart constructors. As a consequence they needed a DynFlags parameter. Now we keep the original PprUser and PprDump styles until they are used to create an `SDocContext`. I.e. the substitution is only performed in `initSDocContext`. - - - - - b3df9e78 by Sylvain Henry at 2020-05-01T10:37:39-04:00 Remove PprStyle param of logging actions Use `withPprStyle` instead to apply a specific style to a SDoc. - - - - - de9fc995 by Sylvain Henry at 2020-05-01T10:37:39-04:00 Fully remove PprDebug PprDebug was a pain to deal with consistently as it is implied by `-dppr-debug` but it isn't really a PprStyle. We remove it completely and query the appropriate SDoc flag instead (`sdocPprDebug`) via helpers (`getPprDebug` and its friends). - - - - - 8b51fcbd by Sebastian Graf at 2020-05-01T10:38:16-04:00 PmCheck: Only call checkSingle if we would report warnings - - - - - fd7ea0fe by Sebastian Graf at 2020-05-01T10:38:16-04:00 PmCheck: Pick up `EvVar`s bound in `HsWrapper`s for long-distance info `HsWrapper`s introduce evidence bindings through `WpEvLam` which the pattern-match coverage checker should be made aware of. Failing to do so caused #18049, where the resulting impreciseness of imcompleteness warnings seemingly contradicted with `-Winaccessible-code`. The solution is simple: Collect all the evidence binders of an `HsWrapper` and add it to the ambient `Deltas` before desugaring the wrapped expression. But that means we pick up many more evidence bindings, even when they wrap around code without a single pattern match to check! That regressed `T3064` by over 300%, so now we are adding long-distance info lazily through judicious use of `unsafeInterleaveIO`. Fixes #18049. - - - - - 7bfe9ac5 by Ben Gamari at 2020-05-03T04:41:33-04:00 rts: Enable tracing of nonmoving heap census with -ln Previously this was not easily available to the user. Fix this. Non-moving collection lifecycle events are now reported with -lg. - - - - - c560dd07 by Ben Gamari at 2020-05-03T04:41:33-04:00 users guide: Move eventlog documentation users guide - - - - - 02543d5e by Ben Gamari at 2020-05-03T04:41:33-04:00 users guide: Add documentation for non-moving GC events - - - - - b465dd45 by Alexis King at 2020-05-03T04:42:12-04:00 Flatten nested casts in the simple optimizer Normally, we aren’t supposed to generated any nested casts, since mkCast takes care to flatten them, but the simple optimizer didn’t use mkCast, so they could show up after inlining. This isn’t really a problem, since the simplifier will clean them up immediately anyway, but it can clutter the -ddump-ds output, and it’s an extremely easy fix. closes #18112 - - - - - 8bdc03d6 by Simon Peyton Jones at 2020-05-04T01:56:59-04:00 Don't return a panic in tcNestedSplice In GHC.Tc.Gen.Splice.tcNestedSplice we were returning a typechecked expression of "panic". That is usually OK, because the result is discarded. But it happens that tcApp now looks at the typechecked expression, trivially, to ask if it is tagToEnum. So being bottom is bad. Moreover a debug-trace might print it out. So better to return a civilised expression, even though it is usually discarded. - - - - - 0bf640b1 by Baldur Blöndal at 2020-05-04T01:57:36-04:00 Don't require parentheses around via type (`-XDerivingVia'). Fixes #18130". - - - - - 30272412 by Artem Pelenitsyn at 2020-05-04T13:19:59-04:00 Remove custom ExceptionMonad class (#18075) (updating haddock submodule accordingly) - - - - - b9f7c08f by jneira at 2020-05-04T13:20:37-04:00 Remove unused hs-boot file - - - - - 1d8f80cd by Sylvain Henry at 2020-05-05T03:22:46-04:00 Remove references to -package-key * remove references to `-package-key` which has been removed in 2016 (240ddd7c39536776e955e881d709bbb039b48513) * remove support for `-this-package-key` which has been deprecated at the same time - - - - - 7bc3a65b by Sylvain Henry at 2020-05-05T03:23:31-04:00 Remove SpecConstrAnnotation (#13681) This has been deprecated since 2013. Use GHC.Types.SPEC instead. Make GHC.Exts "not-home" for haddock Metric Decrease: haddock.base - - - - - 3c862f63 by DenisFrezzato at 2020-05-05T03:24:15-04:00 Fix Haskell98 short description in documentation - - - - - 2420c555 by Ryan Scott at 2020-05-05T03:24:53-04:00 Add regression tests for #16244, #16245, #16758 Commit e3c374cc5bd7eb49649b9f507f9f7740697e3f70 ended up fixing quite a few bugs: * This commit fixes #16244 completely. A regression test has been added. * This commit fixes one program from #16245. (The program in https://gitlab.haskell.org/ghc/ghc/issues/16245#note_211369 still panics, and the program in https://gitlab.haskell.org/ghc/ghc/issues/16245#note_211400 still loops infinitely.) A regression test has been added for this program. * This commit fixes #16758. Accordingly, this patch removes the `expect_broken` label from the `T16758` test case, moves it from `should_compile` to `should_fail` (as it should produce an error message), and checks in the expected stderr. - - - - - 40c71c2c by Sylvain Henry at 2020-05-05T03:25:31-04:00 Fix colorized error messages (#18128) In b3df9e780fb2f5658412c644849cd0f1e6f50331 I broke colorized messages by using "dump" style instead of "user" style. This commits fixes it. - - - - - 7ab6ab09 by Richard Eisenberg at 2020-05-06T04:39:32-04:00 Refactor hole constraints. Previously, holes (both expression holes / out of scope variables and partial-type-signature wildcards) were emitted as *constraints* via the CHoleCan constructor. While this worked fine for error reporting, there was a fair amount of faff in keeping these constraints in line. In particular, and unlike other constraints, we could never change a CHoleCan to become CNonCanonical. In addition: * the "predicate" of a CHoleCan constraint was really the type of the hole, which is not a predicate at all * type-level holes (partial type signature wildcards) carried evidence, which was never used * tcNormalise (used in the pattern-match checker) had to create a hole constraint just to extract it again; it was quite messy The new approach is to record holes directly in WantedConstraints. It flows much more nicely now. Along the way, I did some cleaning up of commentary in GHC.Tc.Errors.Hole, which I had a hard time understanding. This was instigated by a future patch that will refactor the way predicates are handled. The fact that CHoleCan's "predicate" wasn't really a predicate is incompatible with that future patch. No test case, because this is meant to be purely internal. It turns out that this change improves the performance of the pattern-match checker, likely because fewer constraints are sloshing about in tcNormalise. I have not investigated deeply, but an improvement is not a surprise here: ------------------------- Metric Decrease: PmSeriesG ------------------------- - - - - - 420b957d by Ben Gamari at 2020-05-06T04:40:08-04:00 rts: Zero block flags with -DZ Block flags are very useful for determining the state of a block. However, some block allocator users don't touch them, leading to misleading values. Ensure that we zero then when zero-on-gc is set. This is safe and makes the flags more useful during debugging. - - - - - 740b3b8d by Ben Gamari at 2020-05-06T04:40:08-04:00 nonmoving: Fix incorrect failed_to_evac value during deadlock gc Previously we would incorrectly set the failed_to_evac flag if we evacuated a value due to a deadlock GC. This would cause us to mark more things as dirty than strictly necessary. It also turned up a nasty but which I will fix next. - - - - - b2d72c75 by Ben Gamari at 2020-05-06T04:40:08-04:00 nonmoving: Fix handling of dirty objects Previously we (incorrectly) relied on failed_to_evac to be "precise". That is, we expected it to only be true if *all* of an object's fields lived outside of the non-moving heap. However, does not match the behavior of failed_to_evac, which is true if *any* of the object's fields weren't promoted (meaning that some others *may* live in the non-moving heap). This is problematic as we skip the non-moving write barrier for dirty objects (which we can only safely do if *all* fields point outside of the non-moving heap). Clearly this arises due to a fundamental difference in the behavior expected of failed_to_evac in the moving and non-moving collector. e.g., in the moving collector it is always safe to conservatively say failed_to_evac=true whereas in the non-moving collector the safe value is false. This issue went unnoticed as I never wrote down the dirtiness invariant enforced by the non-moving collector. We now define this invariant as An object being marked as dirty implies that all of its fields are on the mark queue (or, equivalently, update remembered set). To maintain this invariant we teach nonmovingScavengeOne to push the fields of objects which we fail to evacuate to the update remembered set. This is a simple and reasonably cheap solution and avoids the complexity and fragility that other, more strict alternative invariants would require. All of this is described in a new Note, Note [Dirty flags in the non-moving collector] in NonMoving.c. - - - - - 9f3e6884 by Zubin Duggal at 2020-05-06T04:41:08-04:00 Allow atomic update of NameCache in readHieFile The situation arises in ghcide where multiple different threads may need to update the name cache, therefore with the older interface it could happen that you start reading a hie file with name cache A and produce name cache A + B, but another thread in the meantime updated the namecache to A + C. Therefore if you write the new namecache you will lose the A' updates from the second thread. Updates haddock submodule - - - - - edec6a6c by Ryan Scott at 2020-05-06T04:41:57-04:00 Make isTauTy detect higher-rank contexts Previously, `isTauTy` would only detect higher-rank `forall`s, not higher-rank contexts, which led to some minor bugs observed in #18127. Easily fixed by adding a case for `(FunTy InvisArg _ _)`. Fixes #18127. - - - - - a95e7fe0 by Ömer Sinan Ağacan at 2020-05-06T04:42:39-04:00 ELF linker: increment curSymbol after filling in fields of current entry The bug was introduced in a8b7cef4d45 which added a field to the `symbols` array elements and then updated this code incorrectly: - oc->symbols[curSymbol++] = nm; + oc->symbols[curSymbol++].name = nm; + oc->symbols[curSymbol].addr = symbol->addr; - - - - - cab1871a by Sylvain Henry at 2020-05-06T04:43:21-04:00 Move LeadingUnderscore into Platform (#17957) Avoid direct use of DynFlags to know if symbols must be prefixed by an underscore. - - - - - 94e7c563 by Sylvain Henry at 2020-05-06T04:43:21-04:00 Don't use DynFlags in showLinkerState (#17957) - - - - - 9afd9251 by Ryan Scott at 2020-05-06T04:43:58-04:00 Refactoring: Use bindSigTyVarsFV in rnMethodBinds `rnMethodBinds` was explicitly using `xoptM` to determine if `ScopedTypeVariables` is enabled before bringing type variables bound by the class/instance header into scope. However, this `xoptM` logic is already performed by the `bindSigTyVarsFV` function. This patch uses `bindSigTyVarsFV` in `rnMethodBinds` to reduce the number of places where we need to consult if `ScopedTypeVariables` is on. This is purely refactoring, and there should be no user-visible change in behavior. - - - - - 6f6d72b2 by Brian Foley at 2020-05-08T15:29:25-04:00 Remove further dead code found by a simple Python script. Avoid removing some functions that are part of an API even though they're not used in-tree at the moment. - - - - - 78bf8bf9 by Julien Debon at 2020-05-08T15:29:28-04:00 Add doc examples for Bifoldable See #17929 - - - - - 66f0a847 by Julien Debon at 2020-05-08T15:29:29-04:00 doc (Bitraversable): Add examples to Bitraversable * Add examples to Data.Bitraversable * Fix formatting for (,) in Bitraversable and Bifoldable * Fix mistake on bimapAccumR documentation See #17929 - - - - - 9749fe12 by Baldur Blöndal at 2020-05-08T15:29:32-04:00 Specify kind variables for inferred kinds in base. - - - - - 4e9aef9e by John Ericson at 2020-05-08T15:29:36-04:00 HsSigWcTypeScoping: Pull in documentation from stray location - - - - - f4d5c6df by John Ericson at 2020-05-08T15:29:36-04:00 Rename local `real_fvs` to `implicit_vs` It doesn't make sense to call the "free" variables we are about to implicitly bind the real ones. - - - - - 20570b4b by John Ericson at 2020-05-08T15:29:36-04:00 A few tiny style nits with renaming - Use case rather than guards that repeatedly scrutenize same thing. - No need for view pattern when `L` is fine. - Use type synnonym to convey the intent like elsewhere. - - - - - 09ac8de5 by John Ericson at 2020-05-08T15:29:36-04:00 Add `forAllOrNothing` function with note - - - - - bb35c0e5 by Joseph C. Sible at 2020-05-08T15:29:40-04:00 Document lawlessness of Ap's Num instance - - - - - cdd229ff by Joseph C. Sible at 2020-05-08T15:29:40-04:00 Apply suggestion to libraries/base/Data/Monoid.hs - - - - - 926d2aab by Joseph C. Sible at 2020-05-08T15:29:40-04:00 Apply more suggestions from Simon Jakobi - - - - - 7a763cff by Adam Gundry at 2020-05-08T15:29:41-04:00 Reject all duplicate declarations involving DuplicateRecordFields (fixes #17965) This fixes a bug that resulted in some programs being accepted that used the same identifier as a field label and another declaration, depending on the order they appeared in the source code. - - - - - 88e3c815 by Simon Peyton Jones at 2020-05-08T15:29:41-04:00 Fix specialisation for DFuns When specialising a DFun we must take care to saturate the unfolding. See Note [Specialising DFuns] in Specialise. Fixes #18120 - - - - - 86c77b36 by Greg Steuck at 2020-05-08T15:29:45-04:00 Remove unused SEGMENT_PROT_RWX It's been unused for a year and is problematic on any OS which requires W^X for security. - - - - - 9d97f4b5 by nineonine at 2020-05-08T15:30:03-04:00 Add test for #16167 - - - - - aa318338 by Ryan Scott at 2020-05-08T15:30:04-04:00 Bump exceptions submodule so that dist-boot is .gitignore'd `exceptions` is a stage-0 boot library as of commit 30272412fa437ab8e7a8035db94a278e10513413, which means that building `exceptions` in a GHC tree will generate a `dist-boot` directory. However, this directory was not specified in `exceptions`' `.gitignore` file, which causes it to dirty up the current `git` working directory. Accordingly, this bumps the `exceptions` submodule to commit ghc/packages/exceptions at 23c0b8a50d7592af37ca09beeec16b93080df98f, which adds `dist-boot` to the `.gitignore` file. - - - - - ea86360f by Ömer Sinan Ağacan at 2020-05-08T15:30:30-04:00 Linker.c: initialize n_symbols of ObjectCode with other fields - - - - - 951c1fb0 by Sylvain Henry at 2020-05-09T21:46:38-04:00 Fix unboxed-sums GC ptr-slot rubbish value (#17791) This patch allows boot libraries to use unboxed sums without implicitly depending on `base` package because of `absentSumFieldError`. See updated Note [aBSENT_SUM_FIELD_ERROR_ID] in GHC.Core.Make - - - - - b352d63c by Ben Gamari at 2020-05-09T21:47:14-04:00 rts: Make non-existent linker search path merely a warning As noted in #18105, previously this resulted in a rather intrusive error message. This is in contrast to the general expectation that search paths are merely places to look, not places that must exist. Fixes #18105. - - - - - cf4f1e2f by Ben Gamari at 2020-05-13T02:02:33-04:00 rts/CNF: Fix fixup comparison function Previously we would implicitly convert the difference between two words to an int, resulting in an integer overflow on 64-bit machines. Fixes #16992 - - - - - a03da9bf by Ömer Sinan Ağacan at 2020-05-13T02:03:16-04:00 Pack some of IdInfo fields into a bit field This reduces residency of compiler quite a bit on some programs. Example stats when building T10370: Before: 2,871,242,832 bytes allocated in the heap 4,693,328,008 bytes copied during GC 33,941,448 bytes maximum residency (276 sample(s)) 375,976 bytes maximum slop 83 MiB total memory in use (0 MB lost due to fragmentation) After: 2,858,897,344 bytes allocated in the heap 4,629,255,440 bytes copied during GC 32,616,624 bytes maximum residency (278 sample(s)) 314,400 bytes maximum slop 80 MiB total memory in use (0 MB lost due to fragmentation) So -3.9% residency, -1.3% bytes copied and -0.4% allocations. Fixes #17497 Metric Decrease: T9233 T9675 - - - - - 670c3e5c by Ben Gamari at 2020-05-13T02:03:54-04:00 get-win32-tarballs: Fix base URL Revert a change previously made for testing purposes. - - - - - 8ad8dc41 by Ben Gamari at 2020-05-13T02:03:54-04:00 get-win32-tarballs: Improve diagnostics output - - - - - 8c0740b7 by Simon Jakobi at 2020-05-13T02:04:33-04:00 docs: Add examples for Data.Semigroup.Arg{Min,Max} Context: #17153 - - - - - cb22348f by Ben Gamari at 2020-05-13T02:05:11-04:00 Add few cleanups of the CAF logic Give the NameSet of non-CAFfy names a proper newtype to distinguish it from all of the other NameSets floating about. - - - - - 90e38b81 by Emeka Nkurumeh at 2020-05-13T02:05:51-04:00 fix printf warning when using with ghc with clang on mingw - - - - - 86d8ac22 by Sebastian Graf at 2020-05-13T02:06:29-04:00 CprAnal: Don't attach CPR sigs to expandable bindings (#18154) Instead, look through expandable unfoldings in `cprTransform`. See the new Note [CPR for expandable unfoldings]: ``` Long static data structures (whether top-level or not) like xs = x1 : xs1 xs1 = x2 : xs2 xs2 = x3 : xs3 should not get CPR signatures, because they * Never get WW'd, so their CPR signature should be irrelevant after analysis (in fact the signature might even be harmful for that reason) * Would need to be inlined/expanded to see their constructed product * Recording CPR on them blows up interface file sizes and is redundant with their unfolding. In case of Nested CPR, this blow-up can be quadratic! But we can't just stop giving DataCon application bindings the CPR property, for example fac 0 = 1 fac n = n * fac (n-1) fac certainly has the CPR property and should be WW'd! But FloatOut will transform the first clause to lvl = 1 fac 0 = lvl If lvl doesn't have the CPR property, fac won't either. But lvl doesn't have a CPR signature to extrapolate into a CPR transformer ('cprTransform'). So instead we keep on cprAnal'ing through *expandable* unfoldings for these arity 0 bindings via 'cprExpandUnfolding_maybe'. In practice, GHC generates a lot of (nested) TyCon and KindRep bindings, one for each data declaration. It's wasteful to attach CPR signatures to each of them (and intractable in case of Nested CPR). ``` Fixes #18154. - - - - - e34bf656 by Ben Gamari at 2020-05-13T02:07:08-04:00 users-guide: Add discussion of shared object naming Fixes #18074. - - - - - 5d0f2445 by Ben Gamari at 2020-05-13T02:07:47-04:00 testsuite: Print sign of performance changes Executes the minor formatting change in the tabulated performance changes suggested in #18135. - - - - - 9e4b981f by Ben Gamari at 2020-05-13T02:08:24-04:00 testsuite: Add testcase for #18129 - - - - - 266310c3 by Ivan-Yudin at 2020-05-13T02:09:03-04:00 doc: Reformulate the opening paragraph of Ch. 4 in User's guide Removes mentioning of Hugs (it is not helpful for new users anymore). Changes the wording for the rest of the paragraph. Fixes #18132. - - - - - 55e35c0b by Baldur Blöndal at 2020-05-13T20:02:48-04:00 Predicate, Equivalence derive via `.. -> a -> All' - - - - - d7e0b57f by Alp Mestanogullari at 2020-05-13T20:03:30-04:00 hadrian: add a --freeze2 option to freeze stage 1 and 2 - - - - - d880d6b2 by Artem Pelenitsyn at 2020-05-13T20:04:11-04:00 Don't reload environment files on every setSessionDynFlags Makes `interpretPackageEnv` (which loads envirinment files) a part of `parseDynamicFlags` (parsing command-line arguments, which is typically done once) instead of `setSessionDynFlags` (which is typically called several times). Making several (transitive) calls to `interpretPackageEnv`, as before, caused #18125 #16318, which should be fixed now. - - - - - 102cfd67 by Ryan Scott at 2020-05-13T20:04:46-04:00 Factor out HsPatSigType for pat sigs/RULE term sigs (#16762) This implements chunks (2) and (3) of https://gitlab.haskell.org/ghc/ghc/issues/16762#note_270170. Namely, it introduces a dedicated `HsPatSigType` AST type, which represents the types that can appear in pattern signatures and term-level `RULE` binders. Previously, these were represented with `LHsSigWcType`. Although `LHsSigWcType` is isomorphic to `HsPatSigType`, the intended semantics of the two types are slightly different, as evidenced by the fact that they have different code paths in the renamer and typechecker. See also the new `Note [Pattern signature binders and scoping]` in `GHC.Hs.Types`. - - - - - b17574f7 by Hécate at 2020-05-13T20:05:28-04:00 fix(documentation): Fix the RST links to GHC.Prim - - - - - df021fb1 by Baldur Blöndal at 2020-05-13T20:06:06-04:00 Document (->) using inferred quantification for its runtime representations. Fixes #18142. - - - - - 1a93ea57 by Takenobu Tani at 2020-05-13T20:06:54-04:00 Tweak man page for ghc command This commit updates the ghc command's man page as followings: * Enable `man_show_urls` to show URL addresses in the `DESCRIPTION` section of ghc.rst, because sphinx currently removes hyperlinks for man pages. * Add a `SEE ALSO` section to point to the GHC homepage - - - - - a951e1ba by Takenobu Tani at 2020-05-13T20:07:37-04:00 GHCi: Add link to the user's guide in help message This commit adds a link to the user's guide in ghci's `:help` message. Newcomers could easily reach to details of ghci. - - - - - 404581ea by Jeff Happily at 2020-05-13T20:08:15-04:00 Handle single unused import - - - - - 1c999e5d by Ben Gamari at 2020-05-13T20:09:07-04:00 Ensure that printMinimalImports closes handle Fixes #18166. - - - - - c9f5a8f4 by Ben Gamari at 2020-05-13T20:09:51-04:00 hadrian: Tell testsuite driver about LLVM availability This reflects the logic present in the Make build system into Hadrian. Fixes #18167. - - - - - c05c0659 by Simon Jakobi at 2020-05-14T03:31:21-04:00 Improve some folds over Uniq[D]FM * Replace some non-deterministic lazy folds with strict folds. * Replace some O(n log n) folds in deterministic order with O(n) non-deterministic folds. * Replace some folds with set-operations on the underlying IntMaps. This reduces max residency when compiling `nofib/spectral/simple/Main.hs` with -O0 by about 1%. Maximum residency when compiling Cabal also seems reduced on the order of 3-9%. - - - - - 477f13bb by Simon Jakobi at 2020-05-14T03:31:58-04:00 Use Data.IntMap.disjoint Data.IntMap gained a dedicated `disjoint` function in containers-0.6.2.1. This patch applies this function where appropriate in hopes of modest compiler performance improvements. Closes #16806. - - - - - e9c0110c by Ben Gamari at 2020-05-14T12:25:53-04:00 IdInfo: Add reference to bitfield-packing ticket - - - - - 9bd20e83 by Sebastian Graf at 2020-05-15T10:42:09-04:00 DmdAnal: Improve handling of precise exceptions This patch does two things: Fix possible unsoundness in what was called the "IO hack" and implement part 2.1 of the "fixing precise exceptions" plan in https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions, which, in combination with !2956, supersedes !3014 and !2525. **IO hack** The "IO hack" (which is a fallback to preserve precise exceptions semantics and thus soundness, rather than some smart thing that increases precision) is called `exprMayThrowPreciseException` now. I came up with two testcases exemplifying possible unsoundness (if twisted enough) in the old approach: - `T13380d`: Demonstrating unsoundness of the "IO hack" when resorting to manual state token threading and direct use of primops. More details below. - `T13380e`: Demonstrating unsoundness of the "IO hack" when we have Nested CPR. Not currently relevant, as we don't have Nested CPR yet. - `T13380f`: Demonstrating unsoundness of the "IO hack" for safe FFI calls. Basically, the IO hack assumed that precise exceptions can only be thrown from a case scrutinee of type `(# State# RealWorld, _ #)`. I couldn't come up with a program using the `IO` abstraction that violates this assumption. But it's easy to do so via manual state token threading and direct use of primops, see `T13380d`. Also similar code might be generated by Nested CPR in the (hopefully not too) distant future, see `T13380e`. Hence, we now have a more careful test in `forcesRealWorld` that passes `T13380{d,e}` (and will hopefully be robust to Nested CPR). **Precise exceptions** In #13380 and #17676 we saw that we didn't preserve precise exception semantics in demand analysis. We fixed that with minimal changes in !2956, but that was terribly unprincipled. That unprincipledness resulted in a loss of precision, which is tracked by these new test cases: - `T13380b`: Regression in dead code elimination, because !2956 was too syntactic about `raiseIO#` - `T13380c`: No need to apply the "IO hack" when the IO action may not throw a precise exception (and the existing IO hack doesn't detect that) Fixing both issues in !3014 turned out to be too complicated and had the potential to regress in the future. Hence we decided to only fix `T13380b` and augment the `Divergence` lattice with a new middle-layer element, `ExnOrDiv`, which means either `Diverges` (, throws an imprecise exception) or throws a *precise* exception. See the wiki page on Step 2.1 for more implementational details: https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions#dead-code-elimination-for-raiseio-with-isdeadenddiv-introducing-exnordiv-step-21 - - - - - 568d7279 by Ben Gamari at 2020-05-15T10:42:46-04:00 GHC.Cmm.Opt: Handle MO_XX_Conv This MachOp was introduced by 2c959a1894311e59cd2fd469c1967491c1e488f3 but a wildcard match in cmmMachOpFoldM hid the fact that it wasn't handled. Ideally we would eliminate the match but this appears to be a larger task. Fixes #18141. - - - - - 5bcf8606 by Ryan Scott at 2020-05-17T08:46:38-04:00 Remove duplicate Note [When to print foralls] in GHC.Core.TyCo.Ppr There are two different Notes named `[When to print foralls]`. The most up-to-date one is in `GHC.Iface.Type`, but there is a second one in `GHC.Core.TyCo.Ppr`. The latter is less up-to-date, as it was written before GHC switched over to using ifaces to pretty-print types. I decided to just remove the latter and replace it with a reference to the former. [ci skip] - - - - - 55f0e783 by Fumiaki Kinoshita at 2020-05-21T12:10:44-04:00 base: Add Generic instances to various datatypes under GHC.* * GHC.Fingerprint.Types: Fingerprint * GHC.RTS.Flags: GiveGCStats, GCFlags, ConcFlags, DebugFlags, CCFlags, DoHeapProfile, ProfFlags, DoTrace, TraceFlags, TickyFlags, ParFlags and RTSFlags * GHC.Stats: RTSStats and GCStats * GHC.ByteOrder: ByteOrder * GHC.Unicode: GeneralCategory * GHC.Stack.Types: SrcLoc Metric Increase: haddock.base - - - - - a9311cd5 by Gert-Jan Bottu at 2020-05-21T12:11:31-04:00 Explicit Specificity Implementation for Ticket #16393. Explicit specificity allows users to manually create inferred type variables, by marking them with braces. This way, the user determines which variables can be instantiated through visible type application. The additional syntax is included in the parser, allowing users to write braces in type variable binders (type signatures, data constructors etc). This information is passed along through the renamer and verified in the type checker. The AST for type variable binders, data constructors, pattern synonyms, partial signatures and Template Haskell has been updated to include the specificity of type variables. Minor notes: - Bumps haddock submodule - Disables pattern match checking in GHC.Iface.Type with GHC 8.8 - - - - - 24e61aad by Ben Price at 2020-05-21T12:12:17-04:00 Lint should say when it is checking a rule It is rather confusing that when lint finds an error in a rule attached to a binder, it reports the error as in the RHS, not the rule: ... In the RHS of foo We add a clarifying line: ... In the RHS of foo In a rule attached to foo The implication that the rule lives inside the RHS is a bit odd, but this niggle is already present for unfoldings, whose pattern we are following. - - - - - 78c6523c by Ben Gamari at 2020-05-21T12:13:01-04:00 nonmoving: Optimise the write barrier - - - - - 13f6c9d0 by Andreas Klebinger at 2020-05-21T12:13:45-04:00 Refactor linear reg alloc to remember past assignments. When assigning registers we now first try registers we assigned to in the past, instead of picking the "first" one. This is in extremely helpful when dealing with loops for which variables are dead for part of the loop. This is important for patterns like this: foo = arg1 loop: use(foo) ... foo = getVal() goto loop; There we: * assign foo to the register of arg1. * use foo, it's dead after this use as it's overwritten after. * do other things. * look for a register to put foo in. If we pick an arbitrary one it might differ from the register the start of the loop expect's foo to be in. To fix this we simply look for past register assignments for the given variable. If we find one and the register is free we use that register. This reduces the need for fixup blocks which match the register assignment between blocks. In the example above between the end and the head of the loop. This patch also moves branch weight estimation ahead of register allocation and adds a flag to control it (cmm-static-pred). * It means the linear allocator is more likely to assign the hotter code paths first. * If it assign these first we are: + Less likely to spill on the hot path. + Less likely to introduce fixup blocks on the hot path. These two measure combined are surprisingly effective. Based on nofib we get in the mean: * -0.9% instructions executed * -0.1% reads/writes * -0.2% code size. * -0.1% compiler allocations. * -0.9% compile time. * -0.8% runtime. Most of the benefits are simply a result of removing redundant moves and spills. Reduced compiler allocations likely are the result of less code being generated. (The added lookup is mostly non-allocating). - - - - - edc2cc58 by Andreas Klebinger at 2020-05-21T12:14:25-04:00 NCG: Codelayout: Distinguish conditional and other branches. In #18053 we ended up with a suboptimal code layout because the code layout algorithm didn't distinguish between conditional and unconditional control flow. We can completely eliminate unconditional control flow instructions by placing blocks next to each other, not so much for conditionals. In terms of implementation we simply give conditional branches less weight before computing the layout. Fixes #18053 - - - - - b7a6b2f4 by Gleb Popov at 2020-05-21T12:15:26-04:00 gitlab-ci: Set locale to C.UTF-8. - - - - - a8c27cf6 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Allow spaces in GHCi :script file names This patch updates the user interface of GHCi so that file names passed to the ':script' command may contain spaces escaped with a backslash. For example: :script foo\ bar.script The implementation uses a modified version of 'words' that does not break on escaped spaces. Fixes #18027. - - - - - 82663959 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Add extra tests for GHCi :script syntax checks The syntax for GHCi's ":script" command allows for only a single file name to be passed as an argument. This patch adds a test for the cases in which a file name is missing or multiple file names are passed. Related to #T18027. - - - - - a0b79e1b by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Allow GHCi :script file names in double quotes This patch updates the user interface of GHCi so that file names passed to the ':script' command can be wrapped in double quotes. For example: :script "foo bar.script" The implementation uses a modified version of 'words' that treats character sequences enclosed in double quotes as single words. Fixes #18027. - - - - - cf566330 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Update documentation for GHCi :script This patch adds the fixes that allow for file names containing spaces to be passed to GHCi's ':script' command to the release notes for 8.12 and expands the user-guide documentation for ':script' by mentioning how such file names can be passed. Related to #18027. - - - - - 0004ccb8 by Tuan Le at 2020-05-21T12:16:46-04:00 llvmGen: Consider Relocatable read-only data as not constantReferences: #18137 - - - - - 964d3ea2 by John Ericson at 2020-05-21T12:17:30-04:00 Use `Checker` for `tc_pat` - - - - - b797aa42 by John Ericson at 2020-05-21T12:17:30-04:00 Use `Checker` for `tc_lpat` and `tc_lpats` - - - - - 5108e84a by John Ericson at 2020-05-21T12:17:30-04:00 More judiciously panic in `ts_pat` - - - - - 510e0451 by John Ericson at 2020-05-21T12:17:30-04:00 Put `PatEnv` first in `GHC.Tc.Gen.Pat.Checker` - - - - - cb4231db by John Ericson at 2020-05-21T12:17:30-04:00 Tiny cleaup eta-reduce away a function argument In GHC, not in the code being compiled! - - - - - 6890c38d by John Ericson at 2020-05-21T12:17:30-04:00 Use braces with do in `SplicePat` case for consistency - - - - - 3451584f by buggymcbugfix at 2020-05-21T12:18:06-04:00 Fix spelling mistakes and typos - - - - - b552e531 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Add INLINABLE pragmas to Enum list producers The INLINABLE pragmas ensure that we export stable (unoptimised) unfoldings in the interface file so we can do list fusion at usage sites. Related tickets: #15185, #8763, #18178. - - - - - e7480063 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Piggyback on Enum Word methods for Word64 If we are on a 64 bit platform, we can use the efficient Enum Word methods for the Enum Word64 instance. - - - - - 892b0c41 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Document INLINE(ABLE) pragmas that enable fusion - - - - - 2b363ebb by Richard Eisenberg at 2020-05-21T12:18:45-04:00 MR template should ask for key part - - - - - a95bbd0b by Sebastian Graf at 2020-05-21T12:19:37-04:00 Make `Int`'s `mod` and `rem` strict in their first arguments They used to be strict until 4d2ac2d (9 years ago). It's obviously better to be strict for performance reasons. It also blocks #18067. NoFib results: ``` -------------------------------------------------------------------------------- Program Allocs Instrs -------------------------------------------------------------------------------- integer -1.1% +0.4% wheel-sieve2 +21.2% +20.7% -------------------------------------------------------------------------------- Min -1.1% -0.0% Max +21.2% +20.7% Geometric Mean +0.2% +0.2% ``` The regression in `wheel-sieve2` is due to reboxing that likely will go away with the resolution of #18067. See !3282 for details. Fixes #18187. - - - - - d3d055b8 by Galen Huntington at 2020-05-21T12:20:18-04:00 Clarify pitfalls of NegativeLiterals; see #18022. - - - - - 1b508a9e by Alexey Kuleshevich at 2020-05-21T12:21:02-04:00 Fix wording in primops documentation to reflect the correct reasoning: * Besides resizing functions, shrinking ones also mutate the size of a mutable array and because of those two `sizeofMutabeByteArray` and `sizeofSmallMutableArray` are now deprecated * Change reference in documentation to the newer functions `getSizeof*` instead of `sizeof*` for shrinking functions * Fix incorrect mention of "byte" instead of "small" - - - - - 4ca0c8a1 by Andreas Klebinger at 2020-05-21T12:21:53-04:00 Don't variable-length encode magic iface constant. We changed to use variable length encodings for many types by default, including Word32. This makes sense for numbers but not when Word32 is meant to represent four bytes. I added a FixedLengthEncoding newtype to Binary who's instances interpret their argument as a collection of bytes instead of a number. We then use this when writing/reading magic numbers to the iface file. I also took the libery to remove the dummy iface field. This fixes #18180. - - - - - a1275081 by Krzysztof Gogolewski at 2020-05-21T12:22:35-04:00 Add a regression test for #11506 The testcase works now. See explanation in https://gitlab.haskell.org/ghc/ghc/issues/11506#note_273202 - - - - - 8a816e5f by Krzysztof Gogolewski at 2020-05-21T12:23:55-04:00 Sort deterministically metric output Previously, we sorted according to the test name and way, but the metrics (max_bytes_used/peak_megabytes_allocated etc.) were appearing in nondeterministic order. - - - - - 566cc73f by Sylvain Henry at 2020-05-21T12:24:45-04:00 Move isDynLinkName into GHC.Types.Name It doesn't belong into GHC.Unit.State - - - - - d830bbc9 by Adam Sandberg Ericsson at 2020-05-23T13:36:20-04:00 docs: fix formatting and add some links [skip ci] - - - - - 49301ad6 by Andrew Martin at 2020-05-23T13:37:01-04:00 Implement cstringLength# and FinalPtr This function and its accompanying rule resolve issue #5218. A future PR to the bytestring library will make the internal Data.ByteString.Internal.unsafePackAddress compute string length with cstringLength#. This will improve the status quo because it is eligible for constant folding. Additionally, introduce a new data constructor to ForeignPtrContents named FinalPtr. This additional data constructor, when used in the IsString instance for ByteString, leads to more Core-to-Core optimization opportunities, fewer runtime allocations, and smaller binaries. Also, this commit re-exports all the functions from GHC.CString (including cstringLength#) in GHC.Exts. It also adds a new test driver. This test driver is used to perform substring matches on Core that is dumped after all the simplifier passes. In this commit, it is used to check that constant folding of cstringLength# works. - - - - - dcd6bdcc by Ben Gamari at 2020-05-23T13:37:48-04:00 simplCore: Ignore ticks in rule templates This fixes #17619, where a tick snuck in to the template of a rule, resulting in a panic during rule matching. The tick in question was introduced via post-inlining, as discussed in `Note [Simplifying rules]`. The solution we decided upon was to simply ignore ticks in the rule template, as discussed in `Note [Tick annotations in RULE matching]`. Fixes #18162. Fixes #17619. - - - - - 82cb8913 by John Ericson at 2020-05-23T13:38:32-04:00 Fix #18145 and also avoid needless work with implicit vars - `forAllOrNothing` now is monadic, so we can trace whether we bind an explicit `forall` or not. - #18145 arose because the free vars calculation was needlessly complex. It is now greatly simplified. - Replaced some other implicit var code with `filterFreeVarsToBind`. Co-authored-by: Ryan Scott <ryan.gl.scott at gmail.com> - - - - - a60dc835 by Ben Gamari at 2020-05-23T13:39:12-04:00 Bump process submodule Fixes #17926. - - - - - 856adf54 by Ben Gamari at 2020-05-23T13:40:21-04:00 users-guide: Clarify meaning of -haddock flag Fixes #18206. - - - - - 7ae57afd by Ben Gamari at 2020-05-23T13:41:03-04:00 git: Add ignored commits file This can be used to tell git to ignore bulk renaming commits like the recently-finished module hierarchy refactoring. Configured with, git config blame.ignoreRevsFile .git-ignore-revs - - - - - 63d30e60 by jneira at 2020-05-24T01:54:42-04:00 Add hie-bios script for windows systems It is a direct translation of the sh script - - - - - 59182b88 by jneira at 2020-05-24T01:54:42-04:00 Honour previous values for CABAL and CABFLAGS The immediate goal is let the hie-bios.bat script set CABFLAGS with `-v0` and remove all cabal output except the compiler arguments - - - - - 932dc54e by jneira at 2020-05-24T01:54:42-04:00 Add specific configuration for windows in hie.yaml - - - - - e0eda070 by jneira at 2020-05-24T01:54:42-04:00 Remove not needed hie-bios output - - - - - a0ea59d6 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Move Config module into GHC.Settings - - - - - 37430251 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Rename GHC.Core.Arity into GHC.Core.Opt.Arity - - - - - a426abb9 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Rename GHC.Hs.Types into GHC.Hs.Type See discussion in https://gitlab.haskell.org/ghc/ghc/issues/13009#note_268610 - - - - - 1c91a7a0 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Bump haddock submodule - - - - - 66bd24d1 by Ryan Scott at 2020-05-24T01:56:03-04:00 Add orderingTyCon to wiredInTyCons (#18185) `Ordering` needs to be wired in for use in the built-in `CmpNat` and `CmpSymbol` type families, but somehow it was never added to the list of `wiredInTyCons`, leading to the various oddities observed in #18185. Easily fixed by moving `orderingTyCon` from `basicKnownKeyNames` to `wiredInTyCons`. Fixes #18185. - - - - - 01c43634 by Matthew Pickering at 2020-05-24T01:56:42-04:00 Remove unused hs-boot file - - - - - 7a07aa71 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix cross-compiler build (#16051) - - - - - 15ccca16 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix distDir per stage - - - - - b420fb24 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix hp2ps error during cross-compilation Fixed by @alp (see https://gitlab.haskell.org/ghc/ghc/issues/16051#note_274265) - - - - - cd339ef0 by Joshua Price at 2020-05-24T15:22:56-04:00 Make Unicode brackets opening/closing tokens (#18225) The tokens `[|`, `|]`, `(|`, and `|)` are opening/closing tokens as described in GHC Proposal #229. This commit makes the unicode variants (`⟦`, `⟧`, `⦇`, and `⦈`) act the same as their ASCII counterparts. - - - - - 013d7120 by Ben Gamari at 2020-05-25T09:48:17-04:00 Revert "Specify kind variables for inferred kinds in base." As noted in !3132, this has rather severe knock-on consequences in user-code. We'll need to revisit this before merging something along these lines. This reverts commit 9749fe1223d182b1f8e7e4f7378df661c509f396. - - - - - 4c4312ed by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Drop redundant ad-hoc boot module check To determine whether the module is a boot module Coverage.addTicksToBinds was checking for a `boot` suffix in the module source filename. This is quite ad-hoc and shouldn't be necessary; the callsite in `deSugar` already checks that the module isn't a boot module. - - - - - 1abf3c84 by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Make tickBoxCount strict This could otherwise easily cause a leak of (+) thunks. - - - - - b2813750 by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Make ccIndices strict This just seems like a good idea. - - - - - 02e278eb by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Don't produce ModBreaks if not HscInterpreted emptyModBreaks contains a bottom and consequently it's important that we don't use it unless necessary. - - - - - b8c014ce by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Factor out addMixEntry - - - - - 53814a64 by Zubin Duggal at 2020-05-26T03:03:24-04:00 Add info about typeclass evidence to .hie files See `testsuite/tests/hiefile/should_run/HieQueries.hs` and `testsuite/tests/hiefile/should_run/HieQueries.stdout` for an example of this We add two new fields, `EvidenceVarBind` and `EvidenceVarUse` to the `ContextInfo` associated with an Identifier. These are associated with the appropriate identifiers for the evidence variables collected when we come across `HsWrappers`, `TcEvBinds` and `IPBinds` while traversing the AST. Instance dictionary and superclass selector dictionaries from `tcg_insts` and classes defined in `tcg_tcs` are also recorded in the AST as originating from their definition span This allows us to save a complete picture of the evidence constructed by the constraint solver, and will let us report this to the user, enabling features like going to the instance definition from the invocation of a class method(or any other method taking a constraint) and finding all usages of a particular instance. Additionally, - Mark NodeInfo with an origin so we can differentiate between bindings origininating in the source vs those in ghc - Along with typeclass evidence info, also include information on Implicit Parameters - Add a few utility functions to HieUtils in order to query the new info Updates haddock submodule - - - - - 6604906c by Sebastian Graf at 2020-05-26T03:04:04-04:00 Make WorkWrap.Lib.isWorkerSmallEnough aware of the old arity We should allow a wrapper with up to 82 parameters when the original function had 82 parameters to begin with. I verified that this made no difference on NoFib, but then again it doesn't use huge records... Fixes #18122. - - - - - cf772f19 by Sylvain Henry at 2020-05-26T03:04:45-04:00 Enhance Note [About units] for Backpack - - - - - ede24126 by Takenobu Tani at 2020-05-27T00:13:55-04:00 core-spec: Modify file paths according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * GHC/Core.hs <= coreSyn/CoreSyn.hs * GHC/Core/Coercion.hs <= types/Coercion.hs * GHC/Core/Coercion/Axiom.hs <= types/CoAxiom.hs * GHC/Core/Coercion/Opt.hs <= types/OptCoercion.hs * GHC/Core/DataCon.hs <= basicTypes/DataCon.hs * GHC/Core/FamInstEnv.hs <= types/FamInstEnv.hs * GHC/Core/Lint.hs <= coreSyn/CoreLint.hs * GHC/Core/Subst.hs <= coreSyn/CoreSubst.hs * GHC/Core/TyCo/Rep.hs <= types/TyCoRep.hs * GHC/Core/TyCon.hs <= types/TyCon.hs * GHC/Core/Type.hs <= types/Type.hs * GHC/Core/Unify.hs <= types/Unify.hs * GHC/Types/Literal.hs <= basicTypes/Literal.hs * GHC/Types/Var.hs <= basicTypes/Var.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [skip ci] - - - - - 04750304 by Ben Gamari at 2020-05-27T00:14:33-04:00 eventlog: Fix racy flushing Previously no attempt was made to avoid multiple threads writing their capability-local eventlog buffers to the eventlog writer simultaneously. This could result in multiple eventlog streams being interleaved. Fix this by documenting that the EventLogWriter's write() and flush() functions may be called reentrantly and fix the default writer to protect its FILE* by a mutex. Fixes #18210. - - - - - d6203f24 by Joshua Price at 2020-05-27T00:15:17-04:00 Make `identifier` parse unparenthesized `->` (#18060) - - - - - 28deee28 by Ben Gamari at 2020-05-28T16:23:21-04:00 GHC.Core.Unfold: Refactor traceInline This reduces duplication as well as fixes a bug wherein -dinlining-check would override -ddump-inlinings. Moreover, the new variant - - - - - 1f393e1e by Ben Gamari at 2020-05-28T16:23:21-04:00 Avoid unnecessary allocations due to tracing utilities While ticky-profiling the typechecker I noticed that hundreds of millions of SDocs are being allocated just in case -ddump-*-trace is enabled. This is awful. We avoid this by ensuring that the dump flag check is inlined into the call site, ensuring that the tracing document needn't be allocated unless it's actually needed. See Note [INLINE conditional tracing utilities] for details. Fixes #18168. Metric Decrease: T9961 haddock.Cabal haddock.base haddock.compiler - - - - - 5f621a78 by Vladislav Zavialov at 2020-05-28T16:23:58-04:00 Add Semigroup/Monoid for Q (#18123) - - - - - dc5f004c by Xavier Denis at 2020-05-28T16:24:37-04:00 Fix #18071 Run the core linter on candidate instances to ensure they are well-kinded. Better handle quantified constraints by using a CtWanted to avoid having unsolved constraints thrown away at the end by the solver. - - - - - 10e6982c by Sebastian Graf at 2020-05-28T16:25:14-04:00 FloatOut: Only eta-expand dead-end RHS if arity will increase (#18231) Otherwise we risk turning trivial RHS into non-trivial RHS, introducing unnecessary bindings in the next Simplifier run, resulting in more churn. Fixes #18231. - - - - - 08dab5f7 by Sebastian Graf at 2020-05-28T16:25:14-04:00 DmdAnal: Recognise precise exceptions from case alternatives (#18086) Consider ```hs m :: IO () m = do putStrLn "foo" error "bar" ``` `m` (from #18086) always throws a (precise or imprecise) exception or diverges. Yet demand analysis infers `<L,A>` as demand signature instead of `<L,A>x` for it. That's because the demand analyser sees `putStrLn` occuring in a case scrutinee and decides that it has to `deferAfterPreciseException`, because `putStrLn` throws a precise exception on some control flow paths. This will mask the `botDiv` `Divergence`of the single case alt containing `error` to `topDiv`. Since `putStrLn` has `topDiv` itself, the final `Divergence` is `topDiv`. This is easily fixed: `deferAfterPreciseException` works by `lub`ing with the demand type of a virtual case branch denoting the precise exceptional control flow. We used `nopDmdType` before, but we can be more precise and use `exnDmdType`, which is `nopDmdType` with `exnDiv`. Now the `Divergence` from the case alt will degrade `botDiv` to `exnDiv` instead of `topDiv`, which combines with the result from the scrutinee to `exnDiv`, and all is well. Fixes #18086. - - - - - aef95f11 by Ben Gamari at 2020-05-28T16:25:53-04:00 Ticky-ticky: Record DataCon name in ticker name This makes it significantly easier to spot the nature of allocations regressions and comes at a reasonably low cost. - - - - - 8f021b8c by Ben Gamari at 2020-05-28T16:26:34-04:00 hadrian: Don't track GHC's verbosity argument Teach hadrian to ignore GHC's -v argument in its recompilation check, thus fixing #18131. - - - - - 13d9380b by Ben Gamari at 2020-05-28T16:27:20-04:00 Rip out CmmStackInfo(updfr_space) As noted in #18232, this field is currently completely unused and moreover doesn't have a clear meaning. - - - - - f10d11fa by Andreas Klebinger at 2020-05-29T01:38:42-04:00 Fix "build/elem" RULE. An redundant constraint prevented the rule from matching. Fixing this allows a call to elem on a known list to be translated into a series of equality checks, and eventually a simple case expression. Surprisingly this seems to regress elem for strings. To avoid this we now also allow foldrCString to inline and add an UTF8 variant. This results in elem being compiled to a tight non-allocating loop over the primitive string literal which performs a linear search. In the process this commit adds UTF8 variants for some of the functions in GHC.CString. This is required to make this work for both ASCII and UTF8 strings. There are also small tweaks to the CString related rules. We now allow ourselfes the luxury to compare the folding function via eqExpr, which helps to ensure the rule fires before we inline foldrCString*. Together with a few changes to allow matching on both the UTF8 and ASCII variants of the CString functions. - - - - - bbeb2389 by Ben Gamari at 2020-05-29T01:39:19-04:00 CoreToStg: Add Outputable ArgInfo instance - - - - - 0e3361ca by Simon Peyton Jones at 2020-05-29T01:39:19-04:00 Make Lint check return type of a join point Consider join x = rhs in body It's important that the type of 'rhs' is the same as the type of 'body', but Lint wasn't checking that invariant. Now it does! This was exposed by investigation into !3113. - - - - - c49f7df0 by Simon Peyton Jones at 2020-05-29T01:39:19-04:00 Do not float join points in exprIsConApp_maybe We hvae been making exprIsConApp_maybe cleverer in recent times: commit b78cc64e923716ac0512c299f42d4d0012306c05 Date: Thu Nov 15 17:14:31 2018 +0100 Make constructor wrappers inline only during the final phase commit 7833cf407d1f608bebb1d38bb99d3035d8d735e6 Date: Thu Jan 24 17:58:50 2019 +0100 Look through newtype wrappers (Trac #16254) commit c25b135ff5b9c69a90df0ccf51b04952c2dc6ee1 Date: Thu Feb 21 12:03:22 2019 +0000 Fix exprIsConApp_maybe But alas there was still a bug, now immortalised in Note [Don't float join points] in SimpleOpt. It's quite hard to trigger because it requires a dead join point, but it came up when compiling Cabal Cabal.Distribution.Fields.Lexer.hs, when working on !3113. Happily, the fix is extremly easy. Finding the bug was not so easy. - - - - - 46720997 by Ben Gamari at 2020-05-29T01:39:19-04:00 Allow simplification through runRW# Because runRW# inlines so late, we were previously able to do very little simplification across it. For instance, given even a simple program like case runRW# (\s -> let n = I# 42# in n) of I# n# -> f n# we previously had no way to avoid the allocation of the I#. This patch allows the simplifier to push strict contexts into the continuation of a runRW# application, as explained in in Note [Simplification of runRW#] in GHC.CoreToStg.Prep. Fixes #15127. Metric Increase: T9961 Metric Decrease: ManyConstructors Co-Authored-By: Simon Peyton-Jone <simonpj at microsoft.com> - - - - - 277c2f26 by Ben Gamari at 2020-05-29T01:39:55-04:00 Eta expand un-saturated primops Now since we no longer try to predict CAFfyness we have no need for the solution to #16846. Eta expanding unsaturated primop applications is conceptually simpler, especially in the presence of levity polymorphism. This essentially reverts cac8dc9f51e31e4c0a6cd9bc302f7e1bc7c03beb, as suggested in #18079. Closes #18079. - - - - - f44d7ae0 by Simon Jakobi at 2020-05-29T01:40:34-04:00 base: Scrap deprecation plan for Data.Monoid.{First,Last} See the discussion on the libraries mailing list for context: https://mail.haskell.org/pipermail/libraries/2020-April/030357.html - - - - - 8b494895 by Jeremy Schlatter at 2020-05-29T01:41:12-04:00 Fix typo in documentation - - - - - 998450f4 by Gleb Popov at 2020-05-29T01:41:53-04:00 Always define USE_PTHREAD_FOR_ITIMER for FreeBSD. - - - - - f9a513e0 by Alp Mestanogullari at 2020-05-29T01:42:36-04:00 hadrian: introduce 'install' target Its logic is very simple. It `need`s the `binary-dist-dir` target and runs suitable `configure` and `make install` commands for the user. A new `--prefix` command line argument is introduced to specify where GHC should be installed. - - - - - 67738db1 by Travis Whitaker at 2020-05-29T13:34:48-04:00 Build a threaded stage 1 if the bootstrapping GHC supports it. - - - - - aac19e6c by Peter Trommler at 2020-05-29T13:35:24-04:00 PPC NCG: No per-symbol .section ".toc" directives All position independent symbols are collected during code generation and emitted in one go. Prepending each symbol with a .section ".toc" directive is redundant. This patch drops the per-symbol directives leading to smaller assembler files. Fixes #18250 - - - - - 4413828b by Ben Gamari at 2020-05-30T06:07:31-04:00 rts: Teach getNumProcessors to return available processors Previously we would report the number of physical processors, which can be quite wrong in a containerized setting. Now we rather return how many processors are in our affinity mask when possible. I also refactored the code to prefer platform-specific since this will report logical CPUs instead of physical (using `machdep.cpu.thread_count` on Darwin and `cpuset_getaffinity` on FreeBSD). Fixes #14781. - - - - - 1449435c by Ben Gamari at 2020-05-30T06:07:31-04:00 users-guide: Note change in getNumProcessors in users guide - - - - - 3d960169 by Ben Gamari at 2020-05-30T06:07:31-04:00 rts: Drop compatibility shims for Windows Vista We can now assume that the thread and processor group interfaces are available. - - - - - 7f8f948c by Peter Trommler at 2020-05-30T06:08:07-04:00 PPC NCG: Fix .size directive on powerpc64 ELF v1 Thanks to Sergei Trofimovich for pointing out the issue. Fixes #18237 - - - - - 7c555b05 by Andreas Klebinger at 2020-05-30T06:08:43-04:00 Optimize GHC.Utils.Monad. Many functions in this module are recursive and as such are marked loop breakers. Which means they are unlikely to get an unfolding. This is *bad*. We always want to specialize them to specific Monads. Which requires a visible unfolding at the use site. I rewrote the recursive ones from: foo f x = ... foo x' ... to foo f x = go x where go x = ... As well as giving some pragmas to make all of them available for specialization. The end result is a reduction of allocations of about -1.4% for nofib/spectral/simple/Main.hs when compiled with `-O`. ------------------------- Metric Decrease: T12425 T14683 T5631 T9233 T9675 T9961 WWRec ------------------------- - - - - - 8b1cb5df by Ben Gamari at 2020-05-30T06:09:20-04:00 Windows: Bump Windows toolchain to 0.2 - - - - - 6947231a by Zubin Duggal at 2020-05-30T06:10:02-04:00 Simplify contexts in GHC.Iface.Ext.Ast - - - - - 2ee4f36c by Daniel Gröber at 2020-06-01T06:32:56-04:00 Cleanup OVERWRITING_CLOSURE logic The code is just more confusing than it needs to be. We don't need to mix the threaded check with the ldv profiling check since ldv's init already checks for this. Hence they can be two separate checks. Taking the sanity checking into account is also cleaner via DebugFlags.sanity. No need for checking the DEBUG define. The ZERO_SLOP_FOR_LDV_PROF and ZERO_SLOP_FOR_SANITY_CHECK definitions the old code had also make things a lot more opaque IMO so I removed those. - - - - - 6159559b by Daniel Gröber at 2020-06-01T06:32:56-04:00 Fix OVERWRITING_CLOSURE assuming closures are not inherently used The new ASSERT in LDV_recordDead() was being tripped up by MVars when removeFromMVarBlockedQueue() calls OVERWRITING_CLOSURE() via OVERWRITE_INFO(). - - - - - 38992085 by Daniel Gröber at 2020-06-01T06:32:56-04:00 Always zero shrunk mutable array slop when profiling When shrinking arrays in the profiling way we currently don't always zero the leftover slop. This means we can't traverse such closures in the heap profiler. The old Note [zeroing slop] and #8402 have some rationale for why this is so but I belive the reasoning doesn't apply to mutable closures. There users already have to ensure multiple threads don't step on each other's toes so zeroing should be safe. - - - - - b0c1f2a6 by Ben Gamari at 2020-06-01T06:33:37-04:00 testsuite: Add test for #18151 - - - - - 9a99a178 by Ben Gamari at 2020-06-01T06:33:37-04:00 testsuite: Add test for desugaring of PostfixOperators - - - - - 2b89ca5b by Ben Gamari at 2020-06-01T06:33:37-04:00 HsToCore: Eta expand left sections Strangely, the comment next to this code already alluded to the fact that even simply eta-expanding will sacrifice laziness. It's quite unclear how we regressed so far. See #18151. - - - - - d412d7a3 by Kirill Elagin at 2020-06-01T06:34:21-04:00 Winferred-safe-imports: Do not exit with error Currently, when -Winferred-safe-imports is enabled, even when it is not turned into an error, the compiler will still exit with exit code 1 if this warning was emitted. Make sure it is really treated as a warning. - - - - - f945eea5 by Ben Gamari at 2020-06-01T06:34:58-04:00 nonmoving: Optimise log2_ceil - - - - - aab606e4 by Bodigrim at 2020-06-01T06:35:36-04:00 Clarify description of fromListN - - - - - 7e5220e2 by Bodigrim at 2020-06-01T06:35:36-04:00 Apply suggestion to libraries/base/GHC/Exts.hs - - - - - f3fb1ce9 by fendor at 2020-06-01T06:36:18-04:00 Add `isInScope` check to `lintCoercion` Mirrors the behaviour of `lintType`. - - - - - 5ac4d946 by fendor at 2020-06-01T06:36:18-04:00 Lint rhs of IfaceRule - - - - - 1cef6126 by Jeremy Schlatter at 2020-06-01T06:37:00-04:00 Fix wording in documentation The duplicate "orphan instance" phrase here doesn't make sense, and was probably an accident. - - - - - 5aaf08f2 by Takenobu Tani at 2020-06-01T06:37:43-04:00 configure: Modify aclocal.m4 according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * Rename: * compiler/GHC/Parser.hs <= compiler/parser/Parser.hs * compiler/GHC/Parser/Lexer.hs <= compiler/Parser/Lexer.hs * Add: * compiler/GHC/Cmm/Lexer.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular - - - - - 15857ad8 by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Don't fail if we can't unlink __symlink_test Afterall, it's possible we were unable to create it due to lack of symlink permission. - - - - - 4a7229ef by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Refactor ghostscript detection Tamar reported that he saw crashes due to unhandled exceptions. - - - - - 2ab37eaf by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite/perf_notes: Fix ill-typed assignments - - - - - e45d5b66 by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite/testutil: Fix bytes/str mismatch - - - - - 7002d0cb by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Work around spurious mypy failure - - - - - 11390e3a by Takenobu Tani at 2020-06-01T06:39:05-04:00 Clean up file paths for new module hierarchy This updates comments only. This patch replaces file references according to new module hierarchy. See also: * https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular * https://gitlab.haskell.org/ghc/ghc/issues/13009 - - - - - 8f2e5732 by Takenobu Tani at 2020-06-01T06:39:05-04:00 Modify file paths to module paths for new module hierarchy This updates comments only. This patch replaces module references according to new module hierarchy [1][2]. For files under the `compiler/` directory, I replace them as module paths instead of file paths. For instance, `GHC.Unit.State` instead of `compiler/GHC/Unit/State.hs` [3]. For current and future haddock's markup, this patch encloses the module name with "" [4]. [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: https://gitlab.haskell.org/ghc/ghc/issues/13009 [3]: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3375#note_276613 [4]: https://haskell-haddock.readthedocs.io/en/latest/markup.html#linking-to-modules - - - - - 68b71c4a by Tom Ellis at 2020-06-01T06:39:55-04:00 Rename the singleton tuple GHC.Tuple.Unit to GHC.Tuple.Solo - - - - - 95da76c2 by Sylvain Henry at 2020-06-01T06:40:41-04:00 Hadrian: fix binary-dist target for cross-compilation - - - - - 730fcd54 by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for the @-operator Since GHC diverges from the Haskell Report by allowing the user to define (@) as an infix operator, we better give a good error message when the user does so unintentionally. In general, this is rather hard to do, as some failures will be discovered only in the renamer or the type checker: x :: (Integer, Integer) x @ (a, b) = (1, 2) This patch does *not* address this general case. However, it gives much better error messages when the binding is not syntactically valid: pairs xs @ (_:xs') = zip xs xs' Before this patch, the error message was rather puzzling: <interactive>:1:1: error: Parse error in pattern: pairs After this patch, the error message includes a hint: <interactive>:1:1: error: Parse error in pattern: pairs In a function binding for the ‘@’ operator. Perhaps you meant an as-pattern, which must not be surrounded by whitespace - - - - - 0fde5377 by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for TypeApplications With this patch, we always parse f @t as a type application, thereby producing better error messages. This steals two syntactic forms: * Prefix form of the @-operator in expressions. Since the @-operator is a divergence from the Haskell Report anyway, this is not a major loss. * Prefix form of @-patterns. Since we are stealing loose infix form anyway, might as well sacrifice the prefix form for the sake of much better error messages. - - - - - c68e7e1e by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for TemplateHaskellQuotes While [e| |], [t| |], [d| |], and so on, steal syntax from list comprehensions, [| |] and [|| ||] do not steal any syntax. Thus we can improve error messages by always accepting them in the lexer. Turns out the renamer already performs necessary validation. - - - - - 120aedbd by Ben Gamari at 2020-06-01T16:07:02-04:00 gitlab-ci: Disable use of ld.lld on ARMv7 It turns out that lld non-deterministically fails on ARMv7. I suspect this may be due to the a kernel regression as this only started happening when we upgraded to 5.4. Nevertheless, easily avoided by simply sticking with gold. Works around #18280. - - - - - d6279ff0 by Ben Gamari at 2020-06-02T13:03:30-04:00 gitlab-ci: Ensure that workaround for #18280 applies to bindisttest We need to ensure that the `configure` flags working around #18280 are propagated to the bindisttest `configure` as well. - - - - - cb5c31b5 by Ben Gamari at 2020-06-03T17:55:04-04:00 gitlab-ci: Allow ARMv7 job to fail Due to #18298. - - - - - 32a4ae90 by John Ericson at 2020-06-04T04:34:42-04:00 Clean up boot vs non-boot disambiguating types We often have (ModuleName, Bool) or (Module, Bool) pairs for "extended" module names (without or with a unit id) disambiguating boot and normal modules. We think this is important enough across the compiler that it deserves a new nominal product type. We do this with synnoyms and a functor named with a `Gen` prefix, matching other newly created definitions. It was also requested that we keep custom `IsBoot` / `NotBoot` sum type. So we have it too. This means changing many the many bools to use that instead. Updates `haddock` submodule. - - - - - c05756cd by Niklas Hambüchen at 2020-06-04T04:35:24-04:00 docs: Add more details on InterruptibleFFI. Details from https://gitlab.haskell.org/ghc/ghc/issues/8684 and https://github.com/takano-akio/filelock/pull/7#discussion_r280332430 - - - - - 1b975aed by Andrew Martin at 2020-06-04T04:36:03-04:00 Allow finalizeForeignPtr to be called on FinalPtr/PlainPtr. MR 2165 (commit 49301ad6226d9a83d110bee8c419615dd94f5ded) regressed finalizeForeignPtr by throwing exceptions when PlainPtr was encounterd. This regression did not make it into a release of GHC. Here, the original behavior is restored, and FinalPtr is given the same treatment as PlainPtr. - - - - - 2bd3929a by Luke Lau at 2020-06-04T04:36:41-04:00 Fix documentation on type families not being extracted It looks like the location of the Names used for CoAxioms on type families are now located at their type constructors. Previously, Docs.hs thought the Names were located in the RHS, so the RealSrcSpan in the instanceMap and getInstLoc didn't match up. Fixes #18241 - - - - - 6735b9d9 by Ben Gamari at 2020-06-04T04:37:21-04:00 GHC.Hs.Instances: Compile with -O0 This module contains exclusively Data instances, which are going to be slow no matter what we do. Furthermore, they are incredibly slow to compile with optimisation (see #9557). Consequently we compile this with -O0. See #18254. - - - - - c330331a by nineonine at 2020-06-04T04:37:59-04:00 Add test for #17669 - - - - - cab684f0 by Ben Gamari at 2020-06-04T04:38:36-04:00 rts: Add Windows-specific implementation of rtsSleep Previously we would use the POSIX path, which uses `nanosleep`. However, it turns out that `nanosleep` is provided by `libpthread` on Windows. In general we don't want to incur such a dependency. Avoid this by simply using `Sleep` on Windows. Fixes #18272. - - - - - ad44b504 by Ben Gamari at 2020-06-04T04:38:36-04:00 compiler: Disable use of process jobs with process < 1.6.9 Due to #17926. - - - - - 6a4098a4 by Moritz Angermann at 2020-06-04T04:55:51-04:00 [linker] Adds void printLoadedObjects(void); This allows us to dump in-memory object code locations for debugging. Fixup printLoadedObjects prototype - - - - - af5e3a88 by Artem Pelenitsyn at 2020-06-05T03:18:49-04:00 base: fix sign confusion in log1mexp implementation (fix #17125) author: claude (https://gitlab.haskell.org/trac-claude) The correct threshold for log1mexp is -(log 2) with the current specification of log1mexp. This change improves accuracy for large negative inputs. To avoid code duplication, a small helper function is added; it isn't the default implementation in Floating because it needs Ord. This patch does nothing to address that the Haskell specification is different from that in common use in other languages. - - - - - 2b792fac by Simon Peyton Jones at 2020-06-05T09:27:50-04:00 Simple subsumption This patch simplifies GHC to use simple subsumption. Ticket #17775 Implements GHC proposal #287 https://github.com/ghc-proposals/ghc-proposals/blob/master/ proposals/0287-simplify-subsumption.rst All the motivation is described there; I will not repeat it here. The implementation payload: * tcSubType and friends become noticably simpler, because it no longer uses eta-expansion when checking subsumption. * No deeplyInstantiate or deeplySkolemise That in turn means that some tests fail, by design; they can all be fixed by eta expansion. There is a list of such changes below. Implementing the patch led me into a variety of sticky corners, so the patch includes several othe changes, some quite significant: * I made String wired-in, so that "foo" :: String rather than "foo" :: [Char] This improves error messages, and fixes #15679 * The pattern match checker relies on knowing about in-scope equality constraints, andd adds them to the desugarer's environment using addTyCsDs. But the co_fn in a FunBind was missed, and for some reason simple-subsumption ends up with dictionaries there. So I added a call to addTyCsDs. This is really part of #18049. * I moved the ic_telescope field out of Implication and into ForAllSkol instead. This is a nice win; just expresses the code much better. * There was a bug in GHC.Tc.TyCl.Instance.tcDataFamInstHeader. We called checkDataKindSig inside tc_kind_sig, /before/ solveEqualities and zonking. Obviously wrong, easily fixed. * solveLocalEqualitiesX: there was a whole mess in here, around failing fast enough. I discovered a bad latent bug where we could successfully kind-check a type signature, and use it, but have unsolved constraints that could fill in coercion holes in that signature -- aargh. It's all explained in Note [Failure in local type signatures] in GHC.Tc.Solver. Much better now. * I fixed a serious bug in anonymous type holes. IN f :: Int -> (forall a. a -> _) -> Int that "_" should be a unification variable at the /outer/ level; it cannot be instantiated to 'a'. This was plain wrong. New fields mode_lvl and mode_holes in TcTyMode, and auxiliary data type GHC.Tc.Gen.HsType.HoleMode. This fixes #16292, but makes no progress towards the more ambitious #16082 * I got sucked into an enormous refactoring of the reporting of equality errors in GHC.Tc.Errors, especially in mkEqErr1 mkTyVarEqErr misMatchMsg misMatchMsgOrCND In particular, the very tricky mkExpectedActualMsg function is gone. It took me a full day. But the result is far easier to understand. (Still not easy!) This led to various minor improvements in error output, and an enormous number of test-case error wibbles. One particular point: for occurs-check errors I now just say Can't match 'a' against '[a]' rather than using the intimidating language of "occurs check". * Pretty-printing AbsBinds Tests review * Eta expansions T11305: one eta expansion T12082: one eta expansion (undefined) T13585a: one eta expansion T3102: one eta expansion T3692: two eta expansions (tricky) T2239: two eta expansions T16473: one eta determ004: two eta expansions (undefined) annfail06: two eta (undefined) T17923: four eta expansions (a strange program indeed!) tcrun035: one eta expansion * Ambiguity check at higher rank. Now that we have simple subsumption, a type like f :: (forall a. Eq a => Int) -> Int is no longer ambiguous, because we could write g :: (forall a. Eq a => Int) -> Int g = f and it'd typecheck just fine. But f's type is a bit suspicious, and we might want to consider making the ambiguity check do a check on each sub-term. Meanwhile, these tests are accepted, whereas they were previously rejected as ambiguous: T7220a T15438 T10503 T9222 * Some more interesting error message wibbles T13381: Fine: one error (Int ~ Exp Int) rather than two (Int ~ Exp Int, Exp Int ~ Int) T9834: Small change in error (improvement) T10619: Improved T2414: Small change, due to order of unification, fine T2534: A very simple case in which a change of unification order means we get tow unsolved constraints instead of one tc211: bizarre impredicative tests; just accept this for now Updates Cabal and haddock submodules. Metric Increase: T12150 T12234 T5837 haddock.base Metric Decrease: haddock.compiler haddock.Cabal haddock.base Merge note: This appears to break the `UnliftedNewtypesDifficultUnification` test. It has been marked as broken in the interest of merging. (cherry picked from commit 66b7b195cb3dce93ed5078b80bf568efae904cc5) - - - - - 2dff8141 by Ryan Scott at 2020-06-05T14:21:24-04:00 Simplify bindLHsTyVarBndrs and bindHsQTyVars Both `bindLHsTyVarBndrs` and `bindHsQTyVars` take two separate `Maybe` arguments, which I find terribly confusing. Thankfully, it's possible to remove one `Maybe` argument from each of these functions, which this patch accomplishes: * `bindHsQTyVars` takes a `Maybe SDoc` argument, which is `Just` if GHC should warn about any of the quantified type variables going unused. However, every call site uses `Nothing` in practice. This makes sense, since it doesn't really make sense to warn about unused type variables bound by an `LHsQTyVars`. For instance, you wouldn't warn about the `a` in `data Proxy a = Proxy` going unused. As a result, I simply remove this `Maybe SDoc` argument altogether. * `bindLHsTyVarBndrs` also takes a `Maybe SDoc` argument for the same reasons that `bindHsQTyVars` took one. To make things more confusing, however, `bindLHsTyVarBndrs` also takes a separate `HsDocContext` argument, which is pretty-printed (to an `SDoc`) in warnings and error messages. In practice, the `Maybe SDoc` and the `HsDocContext` often contain the same text. See the call sites for `bindLHsTyVarBndrs` in `rnFamInstEqn` and `rnConDecl`, for instance. There are only a handful of call sites where the text differs between the `Maybe SDoc` and `HsDocContext` arguments: * In `rnHsRuleDecl`, where the `Maybe SDoc` says "`In the rule`" and the `HsDocContext` says "`In the transformation rule`". * In `rnHsTyKi`/`rn_ty`, where the `Maybe SDoc` says "`In the type`" but the `HsDocContext` is inhereted from the surrounding context (e.g., if `rnHsTyKi` were called on a top-level type signature, the `HsDocContext` would be "`In the type signature`" instead) In both cases, warnings/error messages arguably _improve_ by unifying making the `Maybe SDoc`'s text match that of the `HsDocContext`. As a result, I decided to remove the `Maybe SDoc` argument to `bindLHsTyVarBndrs` entirely and simply reuse the text from the `HsDocContext`. (I decided to change the phrase "transformation rule" to "rewrite rule" while I was in the area.) The `Maybe SDoc` argument has one other purpose: signaling when to emit "`Unused quantified type variable`" warnings. To recover this functionality, I replaced the `Maybe SDoc` argument with a boolean-like `WarnUnusedForalls` argument. The only `bindLHsTyVarBndrs` call site that chooses _not_ to emit these warnings in `bindHsQTyVars`. - - - - - e372331b by Ben Gamari at 2020-06-07T08:46:41-04:00 hadrian: Add missing deriveConstants dependency on ghcplatform.h deriveConstants wants to compile C sources which #include PosixSource.h, which itself #includes ghcplatform.h. Make sure that Hadrian knows about this dependency. Fixes #18290. - - - - - b022051a by Moritz Angermann at 2020-06-07T08:46:42-04:00 ghc-prim needs to depend on libc and libm libm is just an empty shell on musl, and all the math functions are contained in libc. - - - - - 6dae6548 by Moritz Angermann at 2020-06-07T08:46:42-04:00 Disable DLL loading if without system linker Some platforms (musl, aarch64) do not have a working dynamic linker implemented in the libc, even though we might see dlopen. It will ultimately just return that this is not supported. Hence we'll add a flag to the compiler to flat our disable loading dlls. This is needed as we will otherwise try to load the shared library even if this will subsequently fail. At that point we have given up looking for static options though. - - - - - 4a158ffc by Moritz Angermann at 2020-06-07T08:46:43-04:00 Range is actually +/-2^32, not +/-2^31 See also: https://static.docs.arm.com/ihi0056/g/aaelf64.pdf - - - - - f1bfb806 by Ben Gamari at 2020-06-07T10:49:30-04:00 OccurAnal: Avoid exponential behavior due to where clauses Previously the `Var` case of `occAnalApp` could in some cases (namely in the case of `runRW#` applications) call `occAnalRhs` two. In the case of nested `runRW#`s this results in exponential complexity. In some cases the compilation time that resulted would be very long indeed (see #18296). Fixes #18296. Metric Decrease: T9961 T12150 T12234 - - - - - 9b607671 by Takenobu Tani at 2020-06-09T08:05:46-04:00 Add link to GHC's wiki in the GHC API header This adds a URL to point to GHC's wiki in the GHC API header. Newcomers could easily find more information from the GHC API's web like [1]. [1]: Current version, https://ghc.gitlab.haskell.org/ghc/doc/libraries/ghc-8.11.0.20200604/index.html [skip ci] - - - - - 72c7fe9a by Ryan Scott at 2020-06-09T08:06:24-04:00 Make GADT constructors adhere to the forall-or-nothing rule properly Issue #18191 revealed that the types of GADT constructors don't quite adhere to the `forall`-or-nothing rule. This patch serves to clean up this sad state of affairs somewhat. The main change is not in the code itself, but in the documentation, as this patch introduces two sections to the GHC User's Guide: * A "Formal syntax for GADTs" section that presents a BNF-style grammar for what is and isn't allowed in GADT constructor types. This mostly exists to codify GHC's existing behavior, but it also imposes a new restriction that addresses #18191: the outermost `forall` and/or context in a GADT constructor is not allowed to be surrounded by parentheses. Doing so would make these `forall`s/contexts nested, and GADTs do not support nested `forall`s/contexts at present. * A "`forall`-or-nothing rule" section that describes exactly what the `forall`-or-nothing rule is all about. Surprisingly, there was no mention of this anywhere in the User's Guide up until now! To adhere the new specification in the "Formal syntax for GADTs" section of the User's Guide, the following code changes were made: * A new function, `GHC.Hs.Type.splitLHsGADTPrefixTy`, was introduced. This is very much like `splitLHsSigmaTy`, except that it avoids splitting apart any parentheses, which can be syntactically significant for GADT types. See `Note [No nested foralls or contexts in GADT constructors]` in `GHC.Hs.Type`. * `ConDeclGADTPrefixPs`, an extension constructor for `XConDecl`, was introduced so that `GHC.Parser.PostProcess.mkGadtDecl` can return it when given a prefix GADT constructor. Unlike `ConDeclGADT`, `ConDeclGADTPrefixPs` does not split the GADT type into its argument and result types, as this cannot be done until after the type is renamed (see `Note [GADT abstract syntax]` in `GHC.Hs.Decls` for why this is the case). * `GHC.Renamer.Module.rnConDecl` now has an additional case for `ConDeclGADTPrefixPs` that (1) splits apart the full `LHsType` into its `forall`s, context, argument types, and result type, and (2) checks for nested `forall`s/contexts. Step (2) used to be performed the typechecker (in `GHC.Tc.TyCl.badDataConTyCon`) rather than the renamer, but now the relevant code from the typechecker can simply be deleted. One nice side effect of this change is that we are able to give a more accurate error message for GADT constructors that use visible dependent quantification (e.g., `MkFoo :: forall a -> a -> Foo a`), which improves the stderr in the `T16326_Fail6` test case. Fixes #18191. Bumps the Haddock submodule. - - - - - a47e6442 by Ryan Scott at 2020-06-10T03:39:12-04:00 Always use rnImplicitBndrs to bring implicit tyvars into scope This implements a first step towards #16762 by changing the renamer to always use `rnImplicitBndrs` to bring implicitly bound type variables into scope. The main change is in `rnFamInstEqn` and `bindHsQTyVars`, which previously used _ad hoc_ methods of binding their implicit tyvars. There are a number of knock-on consequences: * One of the reasons that `rnFamInstEqn` used an _ad hoc_ binding mechanism was to give more precise source locations in `-Wunused-type-patterns` warnings. (See https://gitlab.haskell.org/ghc/ghc/issues/16762#note_273343 for an example of this.) However, these warnings are actually a little _too_ precise, since implicitly bound type variables don't have exact binding sites like explicitly bound type variables do. A similar problem existed for "`Different names for the same type variable`" errors involving implicit tyvars bound by `bindHsQTyVars`. Therefore, we simply accept the less precise (but more accurate) source locations from `rnImplicitBndrs` in `rnFamInstEqn` and `bindHsQTyVars`. See `Note [Source locations for implicitly bound type variables]` in `GHC.Rename.HsType` for the full story. * In order for `rnImplicitBndrs` to work in `rnFamInstEqn`, it needs to be able to look up names from the parent class (in the event that we are renaming an associated type family instance). As a result, `rnImplicitBndrs` now takes an argument of type `Maybe assoc`, which is `Just` in the event that a type family instance is associated with a class. * Previously, GHC kept track of three type synonyms for free type variables in the renamer: `FreeKiTyVars`, `FreeKiTyVarsDups` (which are allowed to contain duplicates), and `FreeKiTyVarsNoDups` (which contain no duplicates). However, making is a distinction between `-Dups` and `-NoDups` is now pointless, as all code that returns `FreeKiTyVars{,Dups,NoDups}` will eventually end up being passed to `rnImplicitBndrs`, which removes duplicates. As a result, I decided to just get rid of `FreeKiTyVarsDups` and `FreeKiTyVarsNoDups`, leaving only `FreeKiTyVars`. * The `bindLRdrNames` and `deleteBys` functions are now dead code, so I took the liberty of removing them. - - - - - 24879129 by Takenobu Tani at 2020-06-10T03:39:59-04:00 Clarify leaf module names for new module hierarchy This updates comments only. This patch replaces leaf module names according to new module hierarchy [1][2] as followings: * Expand leaf names to easily find the module path: for instance, `Id.hs` to `GHC.Types.Id`. * Modify leaf names according to new module hierarchy: for instance, `Convert.hs` to `GHC.ThToHs`. * Fix typo: for instance, `GHC.Core.TyCo.Rep.hs` to `GHC.Core.TyCo.Rep` See also !3375 [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: https://gitlab.haskell.org/ghc/ghc/issues/13009 - - - - - 92de9e25 by Ömer Sinan Ağacan at 2020-06-10T03:41:07-04:00 rts: Remove unused GET_ENTRY closure macro This macro is not used and got broken in the meantime, as ENTRY_CODE was deleted. - - - - - 87102928 by Ömer Sinan Ağacan at 2020-06-10T03:41:50-04:00 Fix -fkeep-cafs flag name in users guide - - - - - ccd6843d by Shayne Fletcher at 2020-06-10T04:14:57-04:00 Expose impliedGFlags, impledOffGFlags, impliedXFlags - - - - - 7a737e89 by Ömer Sinan Ağacan at 2020-06-10T04:14:58-04:00 Cross-module LambdaFormInfo passing - Store LambdaFormInfos of exported Ids in interface files - Use them in importing modules This is for optimization purposes: if we know LambdaFormInfo of imported Ids we can generate more efficient calling code, see `getCallMethod`. Exporting (putting them in interface files or in ModDetails) and importing (reading them from interface files) are both optional. We don't assume known LambdaFormInfos anywhere and do not change how we call Ids with unknown LambdaFormInfos. Runtime, allocation, and residency numbers when building Cabal-the-library (commit 0d4ee7ba3): (Log and .hp files are in the MR: !2842) | | GHC HEAD | This patch | Diff | |-----|----------|------------|----------------| | -O0 | 0:35.89 | 0:34.10 | -1.78s, -4.98% | | -O1 | 2:24.01 | 2:23.62 | -0.39s, -0.27% | | -O2 | 2:52.23 | 2:51.35 | -0.88s, -0.51% | | | GHC HEAD | This patch | Diff | |-----|-----------------|-----------------|----------------------------| | -O0 | 54,843,608,416 | 54,878,769,544 | +35,161,128 bytes, +0.06% | | -O1 | 227,136,076,400 | 227,569,045,168 | +432,968,768 bytes, +0.19% | | -O2 | 266,147,063,296 | 266,749,643,440 | +602,580,144 bytes, +0.22% | NOTE: Residency is measured with extra runtime args: `-i0 -h` which effectively turn all GCs into major GCs, and do GC more often. | | GHC HEAD | This patch | Diff | |-----|----------------------------|------------------------------|----------------------------| | -O0 | 410,284,000 (910 samples) | 411,745,008 (906 samples) | +1,461,008 bytes, +0.35% | | -O1 | 928,580,856 (2109 samples) | 943,506,552 (2103 samples) | +14,925,696 bytes, +1.60% | | -O2 | 993,951,352 (2549 samples) | 1,010,156,328 (2545 samples) | +16,204,9760 bytes, +1.63% | NoFib results: -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS 0.0% 0.0% +0.0% +0.0% +0.0% CSD 0.0% 0.0% 0.0% +0.0% +0.0% FS 0.0% 0.0% +0.0% +0.0% +0.0% S 0.0% 0.0% +0.0% +0.0% +0.0% VS 0.0% 0.0% +0.0% +0.0% +0.0% VSD 0.0% 0.0% +0.0% +0.0% +0.1% VSM 0.0% 0.0% +0.0% +0.0% +0.0% anna 0.0% 0.0% -0.3% -0.8% -0.0% ansi 0.0% 0.0% -0.0% -0.0% 0.0% atom 0.0% 0.0% -0.0% -0.0% 0.0% awards 0.0% 0.0% -0.1% -0.3% 0.0% banner 0.0% 0.0% -0.0% -0.0% -0.0% bernouilli 0.0% 0.0% -0.0% -0.0% -0.0% binary-trees 0.0% 0.0% -0.0% -0.0% +0.0% boyer 0.0% 0.0% -0.0% -0.0% 0.0% boyer2 0.0% 0.0% -0.0% -0.0% 0.0% bspt 0.0% 0.0% -0.0% -0.2% 0.0% cacheprof 0.0% 0.0% -0.1% -0.4% +0.0% calendar 0.0% 0.0% -0.0% -0.0% 0.0% cichelli 0.0% 0.0% -0.9% -2.4% 0.0% circsim 0.0% 0.0% -0.0% -0.0% 0.0% clausify 0.0% 0.0% -0.1% -0.3% 0.0% comp_lab_zift 0.0% 0.0% -0.0% -0.0% +0.0% compress 0.0% 0.0% -0.0% -0.0% -0.0% compress2 0.0% 0.0% -0.0% -0.0% 0.0% constraints 0.0% 0.0% -0.1% -0.2% -0.0% cryptarithm1 0.0% 0.0% -0.0% -0.0% 0.0% cryptarithm2 0.0% 0.0% -1.4% -4.1% -0.0% cse 0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e1 0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e2 0.0% 0.0% -0.0% -0.0% -0.0% dom-lt 0.0% 0.0% -0.1% -0.2% 0.0% eliza 0.0% 0.0% -0.5% -1.5% 0.0% event 0.0% 0.0% -0.0% -0.0% -0.0% exact-reals 0.0% 0.0% -0.1% -0.3% +0.0% exp3_8 0.0% 0.0% -0.0% -0.0% -0.0% expert 0.0% 0.0% -0.3% -1.0% -0.0% fannkuch-redux 0.0% 0.0% +0.0% +0.0% +0.0% fasta 0.0% 0.0% -0.0% -0.0% +0.0% fem 0.0% 0.0% -0.0% -0.0% 0.0% fft 0.0% 0.0% -0.0% -0.0% 0.0% fft2 0.0% 0.0% -0.0% -0.0% 0.0% fibheaps 0.0% 0.0% -0.0% -0.0% +0.0% fish 0.0% 0.0% 0.0% -0.0% +0.0% fluid 0.0% 0.0% -0.4% -1.2% +0.0% fulsom 0.0% 0.0% -0.0% -0.0% 0.0% gamteb 0.0% 0.0% -0.1% -0.3% 0.0% gcd 0.0% 0.0% -0.0% -0.0% 0.0% gen_regexps 0.0% 0.0% -0.0% -0.0% -0.0% genfft 0.0% 0.0% -0.0% -0.0% 0.0% gg 0.0% 0.0% -0.0% -0.0% +0.0% grep 0.0% 0.0% -0.0% -0.0% -0.0% hidden 0.0% 0.0% -0.1% -0.4% -0.0% hpg 0.0% 0.0% -0.2% -0.5% +0.0% ida 0.0% 0.0% -0.0% -0.0% +0.0% infer 0.0% 0.0% -0.3% -0.8% -0.0% integer 0.0% 0.0% -0.0% -0.0% +0.0% integrate 0.0% 0.0% -0.0% -0.0% 0.0% k-nucleotide 0.0% 0.0% -0.0% -0.0% +0.0% kahan 0.0% 0.0% -0.0% -0.0% +0.0% knights 0.0% 0.0% -2.2% -5.4% 0.0% lambda 0.0% 0.0% -0.6% -1.8% 0.0% last-piece 0.0% 0.0% -0.0% -0.0% 0.0% lcss 0.0% 0.0% -0.0% -0.1% 0.0% life 0.0% 0.0% -0.0% -0.1% 0.0% lift 0.0% 0.0% -0.2% -0.6% +0.0% linear 0.0% 0.0% -0.0% -0.0% -0.0% listcompr 0.0% 0.0% -0.0% -0.0% 0.0% listcopy 0.0% 0.0% -0.0% -0.0% 0.0% maillist 0.0% 0.0% -0.1% -0.3% +0.0% mandel 0.0% 0.0% -0.0% -0.0% 0.0% mandel2 0.0% 0.0% -0.0% -0.0% -0.0% mate +0.0% 0.0% -0.0% -0.0% -0.0% minimax 0.0% 0.0% -0.2% -1.0% 0.0% mkhprog 0.0% 0.0% -0.1% -0.2% -0.0% multiplier 0.0% 0.0% -0.0% -0.0% -0.0% n-body 0.0% 0.0% -0.0% -0.0% +0.0% nucleic2 0.0% 0.0% -0.1% -0.2% 0.0% para 0.0% 0.0% -0.0% -0.0% -0.0% paraffins 0.0% 0.0% -0.0% -0.0% 0.0% parser 0.0% 0.0% -0.2% -0.7% 0.0% parstof 0.0% 0.0% -0.0% -0.0% +0.0% pic 0.0% 0.0% -0.0% -0.0% 0.0% pidigits 0.0% 0.0% +0.0% +0.0% +0.0% power 0.0% 0.0% -0.2% -0.6% +0.0% pretty 0.0% 0.0% -0.0% -0.0% -0.0% primes 0.0% 0.0% -0.0% -0.0% 0.0% primetest 0.0% 0.0% -0.0% -0.0% -0.0% prolog 0.0% 0.0% -0.3% -1.1% 0.0% puzzle 0.0% 0.0% -0.0% -0.0% 0.0% queens 0.0% 0.0% -0.0% -0.0% +0.0% reptile 0.0% 0.0% -0.0% -0.0% 0.0% reverse-complem 0.0% 0.0% -0.0% -0.0% +0.0% rewrite 0.0% 0.0% -0.7% -2.5% -0.0% rfib 0.0% 0.0% -0.0% -0.0% 0.0% rsa 0.0% 0.0% -0.0% -0.0% 0.0% scc 0.0% 0.0% -0.1% -0.2% -0.0% sched 0.0% 0.0% -0.0% -0.0% -0.0% scs 0.0% 0.0% -1.0% -2.6% +0.0% simple 0.0% 0.0% +0.0% -0.0% +0.0% solid 0.0% 0.0% -0.0% -0.0% 0.0% sorting 0.0% 0.0% -0.6% -1.6% 0.0% spectral-norm 0.0% 0.0% +0.0% 0.0% +0.0% sphere 0.0% 0.0% -0.0% -0.0% -0.0% symalg 0.0% 0.0% -0.0% -0.0% +0.0% tak 0.0% 0.0% -0.0% -0.0% 0.0% transform 0.0% 0.0% -0.0% -0.0% 0.0% treejoin 0.0% 0.0% -0.0% -0.0% 0.0% typecheck 0.0% 0.0% -0.0% -0.0% +0.0% veritas +0.0% 0.0% -0.2% -0.4% +0.0% wang 0.0% 0.0% -0.0% -0.0% 0.0% wave4main 0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve1 0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve2 0.0% 0.0% -0.0% -0.0% +0.0% x2n1 0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min 0.0% 0.0% -2.2% -5.4% -0.0% Max +0.0% 0.0% +0.0% +0.0% +0.1% Geometric Mean -0.0% -0.0% -0.1% -0.3% +0.0% Metric increases micro benchmarks tracked in #17686: Metric Increase: T12150 T12234 T12425 T13035 T5837 T6048 T9233 Co-authored-by: Andreas Klebinger <klebinger.andreas at gmx.at> - - - - - 3b22b14a by Shayne Fletcher at 2020-06-10T04:15:01-04:00 Give Language a Bounded instance - - - - - 9454511b by Simon Peyton Jones at 2020-06-10T04:17:06-04:00 Optimisation in Unique.Supply This patch switches on -fno-state-hack in GHC.Types.Unique.Supply. It turned out that my fixes for #18078 (coercion floating) changed the optimisation pathway for mkSplitUniqSupply in such a way that we had an extra allocation inside the inner loop. Adding -fno-state-hack fixed that -- and indeed the loop in mkSplitUniqSupply is a classic example of the way in which -fno-state-hack can be bad; see #18238. Moreover, the new code is better than the old. They allocate the same, but the old code ends up with a partial application. The net effect is that the test perf/should_run/UniqLoop runs 20% faster! From 2.5s down to 2.0s. The allocation numbers are the same -- but elapsed time falls. Good! The bad thing about this is that it's terribly delicate. But at least it's a good example of such delicacy in action. There is a long Note [Optimising the unique supply] which now explains all this. - - - - - 6d49d5be by Simon Peyton Jones at 2020-06-10T04:17:06-04:00 Implement cast worker/wrapper properly The cast worker/wrapper transformation transforms x = e |> co into y = e x = y |> co This is done by the simplifier, but we were being careless about transferring IdInfo from x to y, and about what to do if x is a NOINLNE function. This resulted in a series of bugs: #17673, #18093, #18078. This patch fixes all that: * Main change is in GHC.Core.Opt.Simplify, and the new prepareBinding function, which does this cast worker/wrapper transform. See Note [Cast worker/wrappers]. * There is quite a bit of refactoring around prepareRhs, makeTrivial etc. It's nicer now. * Some wrappers from strictness and cast w/w, notably those for a function with a NOINLINE, should inline very late. There wasn't really a mechanism for that, which was an existing bug really; so I invented a new finalPhase = Phase (-1). It's used for all simplifier runs after the user-visible phase 2,1,0 have run. (No new runs of the simplifier are introduced thereby.) See new Note [Compiler phases] in GHC.Types.Basic; the main changes are in GHC.Core.Opt.Driver * Doing this made me trip over two places where the AnonArgFlag on a FunTy was being lost so we could end up with (Num a -> ty) rather than (Num a => ty) - In coercionLKind/coercionRKind - In contHoleType in the Simplifier I fixed the former by defining mkFunctionType and using it in coercionLKind/RKind. I could have done the same for the latter, but the information is almost to hand. So I fixed the latter by - adding sc_hole_ty to ApplyToVal (like ApplyToTy), - adding as_hole_ty to ValArg (like TyArg) - adding sc_fun_ty to StrictArg Turned out I could then remove ai_type from ArgInfo. This is just moving the deck chairs around, but it worked out nicely. See the new Note [AnonArgFlag] in GHC.Types.Var * When looking at the 'arity decrease' thing (#18093) I discovered that stable unfoldings had a much lower arity than the actual optimised function. That's what led to the arity-decrease message. Simple solution: eta-expand. It's described in Note [Eta-expand stable unfoldings] in GHC.Core.Opt.Simplify * I also discovered that unsafeCoerce wasn't being inlined if the context was boring. So (\x. f (unsafeCoerce x)) would create a thunk -- yikes! I fixed that by making inlineBoringOK a bit cleverer: see Note [Inline unsafeCoerce] in GHC.Core.Unfold. I also found that unsafeCoerceName was unused, so I removed it. I made a test case for #18078, and a very similar one for #17673. The net effect of all this on nofib is very modest, but positive: -------------------------------------------------------------------------------- Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- anna -0.4% -0.1% -3.1% -3.1% 0.0% fannkuch-redux -0.4% -0.3% -0.1% -0.1% 0.0% maillist -0.4% -0.1% -7.8% -1.0% -14.3% primetest -0.4% -15.6% -7.1% -6.6% 0.0% -------------------------------------------------------------------------------- Min -0.9% -15.6% -13.3% -14.2% -14.3% Max -0.3% 0.0% +12.1% +12.4% 0.0% Geometric Mean -0.4% -0.2% -2.3% -2.2% -0.1% All following metric decreases are compile-time allocation decreases between -1% and -3%: Metric Decrease: T5631 T13701 T14697 T15164 - - - - - 32fd37f5 by Luke Lau at 2020-06-10T04:17:22-04:00 Fix lookupGlobalOccRn_maybe sometimes reporting an error In some cases it was possible for lookupGlobalOccRn_maybe to return an error, when it should be returning a Nothing. If it called lookupExactOcc_either when there were no matching GlobalRdrElts in the otherwise case, it would return an error message. This could be caused when lookupThName_maybe in Template Haskell was looking in different namespaces (thRdrNameGuesses), guessing different namespaces that the name wasn't guaranteed to be found in. However, by addressing this some more accurate errors were being lost in the conversion to Maybes. So some of the lookup* functions have been shuffled about so that errors should always be ignored in lookup*_maybes, and propagated otherwise. This fixes #18263 - - - - - 9b283e1b by Roland Senn at 2020-06-10T04:17:34-04:00 Initialize the allocation counter in GHCi to 0 (Fixes #16012) According to the documentation for the function `getAllocationCounter` in [System.Mem](http://hackage.haskell.org/package/base-4.14.0.0/docs/System-Mem.html) initialize the allocationCounter also in GHCi to 0. - - - - - 8d07c48c by Sylvain Henry at 2020-06-10T04:17:36-04:00 test: fix conc038 We had spurious failures of conc038 test on CI with stdout: ``` newThread started -mainThread -Haskell: 2 newThread back again +mainThread 1 sec later shutting down +Haskell: 2 ``` - - - - - 4c7e9689 by Sebastian Graf at 2020-06-11T10:37:38+02:00 Release Notes: Add news from the pattern-match checker [skip ci] - - - - - 3445b965 by Sylvain Henry at 2020-06-13T02:13:01-04:00 Only test T16190 with the NCG T16190 is meant to test a NCG feature. It has already caused spurious failures in other MRs (e.g. !2165) when LLVM is used. - - - - - 2517a51c by Sylvain Henry at 2020-06-13T02:13:01-04:00 DynFlags refactoring VIII (#17957) * Remove several uses of `sdocWithDynFlags`, especially in GHC.Llvm.* * Add LlvmOpts datatype to store Llvm backend options * Remove Outputable instances (for LlvmVar, LlvmLit, LlvmStatic and Llvm.MetaExpr) which require LlvmOpts. * Rename ppMetaExpr into ppMetaAnnotExpr (pprMetaExpr is now used in place of `ppr :: MetaExpr -> SDoc`) - - - - - 7a02599a by Sylvain Henry at 2020-06-13T02:13:02-04:00 Remove unused code - - - - - 72d08610 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Refactor homeUnit * rename thisPackage into homeUnit * document and refactor several Backpack things - - - - - 8dc71f55 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Rename unsafeGetUnitInfo into unsafeLookupUnit - - - - - f6be6e43 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Add allowVirtualUnits field in PackageState Instead of always querying DynFlags to know whether we are allowed to use virtual units (i.e. instantiated on-the-fly, cf Note [About units] in GHC.Unit), we store it once for all in `PackageState.allowVirtualUnits`. This avoids using DynFlags too much (cf #17957) and is preliminary work for #14335. - - - - - e7272d53 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Enhance UnitId use * use UnitId instead of String to identify wired-in units * use UnitId instead of Unit in the backend (Unit are only use by Backpack to produce type-checked interfaces, not real code) * rename lookup functions for consistency * documentation - - - - - 9c5572cd by Sylvain Henry at 2020-06-13T02:13:02-04:00 Remove LinkerUnitId type alias - - - - - d345edfe by Sylvain Henry at 2020-06-13T02:13:02-04:00 Refactor WiredMap * Remove WiredInUnitId and WiredUnitId type aliases - - - - - 3d171cd6 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Document and refactor `mkUnit` and `mkUnitInfoMap` - - - - - d2109b4f by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove PreloadUnitId type alias - - - - - f50c19b8 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename listUnitInfoMap into listUnitInfo There is no Map involved - - - - - ed533ec2 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename Package into Unit The terminology changed over time and now package databases contain "units" (there can be several units compiled from a single Cabal package: one per-component, one for each option set, one per instantiation, etc.). We should try to be consistent internally and use "units": that's what this renaming does. Maybe one day we'll fix the UI too (e.g. replace -package-id with -unit-id, we already have -this-unit-id and ghc-pkg has -unit-id...) but it's not done in this patch. * rename getPkgFrameworkOpts into getUnitFrameworkOpts * rename UnitInfoMap into ClosureUnitInfoMap * rename InstalledPackageIndex into UnitInfoMap * rename UnusablePackages into UnusableUnits * rename PackagePrecedenceIndex into UnitPrecedenceMap * rename PackageDatabase into UnitDatabase * rename pkgDatabase into unitDatabases * rename pkgState into unitState * rename initPackages into initUnits * rename renamePackage into renameUnitInfo * rename UnusablePackageReason into UnusableUnitReason * rename getPackage* into getUnit* * etc. - - - - - 202728e5 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Make ClosureUnitInfoMap uses UnitInfoMap - - - - - 55b4263e by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove ClosureUnitInfoMap - - - - - 653d17bd by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename Package into Unit (2) * rename PackageState into UnitState * rename findWiredInPackages into findWiredInUnits * rename lookupModuleInAll[Packages,Units] * etc. - - - - - ae900605 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move dump_mod_map into initUnits - - - - - 598cc1dd by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move wiring of homeUnitInstantiations outside of mkUnitState - - - - - 437265eb by Sylvain Henry at 2020-06-13T02:13:03-04:00 Avoid timing module map dump in initUnits - - - - - 9400aa93 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove preload parameter of mkUnitState * Remove preload parameter (unused) * Don't explicitly return preloaded units: redundant because already returned as "preloadUnits" field of UnitState - - - - - 266bc3d9 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: refactor unwireUnit - - - - - 9e715c1b by Sylvain Henry at 2020-06-13T02:13:03-04:00 Document getPreloadUnitsAnd - - - - - bd5810dc by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: remove useless add_package parameter - - - - - 36e1daf0 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: make listVisibleModuleNames take a UnitState - - - - - 5226da37 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Refactor and document add_package - - - - - 4b53aac1 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Refactor and document closeUnitDeps - - - - - 42c054f6 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: findWiredInUnits - - - - - a444d01b by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: reportCycles, reportUnusable - - - - - 8408d521 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: merge_databases - - - - - fca2d25f by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: add UnitConfig datatype Avoid directly querying flags from DynFlags to build the UnitState. Instead go via UnitConfig so that we could reuse this to make another UnitState for plugins. - - - - - 4274688a by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move distrustAll into mkUnitState - - - - - 28d804e1 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Create helper upd_wired_in_home_instantiations - - - - - ac964c83 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Put database cache in UnitConfig - - - - - bfd0a78c by Sylvain Henry at 2020-06-13T02:13:03-04:00 Don't return preload units when we set DyNFlags Preload units can be retrieved in UnitState when needed (i.e. in GHCi) - - - - - 1fbb4bf5 by Sylvain Henry at 2020-06-13T02:13:03-04:00 NCGConfig: remove useless ncgUnitId field - - - - - c10ff7e7 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Doc: fix some comments - - - - - 456e17f0 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Bump haddock submodule and allow metric decrease Metric Decrease: T12150 T12234 T5837 Metric Increase: T16190 - - - - - 42953902 by Simon Peyton Jones at 2020-06-13T02:13:03-04:00 Trim the demand for recursive product types Ticket #18304 showed that we need to be very careful when exploring the demand (esp usage demand) on recursive product types. This patch solves the problem by trimming the demand on such types -- in effect, a form of "widening". See the Note [Trimming a demand to a type] in DmdAnal, which explains how I did this by piggy-backing on an existing mechansim for trimming demands becuase of GADTs. The significant payload of this patch is very small indeed: * Make GHC.Core.Opt.WorkWrap.Utils.typeShape use RecTcChecker to avoid looking through recursive types. But on the way * I found that ae_rec_tc was entirely inoperative and did nothing. So I removed it altogether from DmdAnal. * I moved some code around in DmdAnal and Demand. (There are no actual changes in dmdFix.) * I changed the API of DmsAnal.dmdAnalRhsLetDown to return a StrictSig rather than a decorated Id * I removed the dead function peelTsFuns from Demand Performance effects: Nofib: 0.0% changes. Not surprising, because they don't use recursive products Perf tests T12227: 1% increase in compiler allocation, becuase $cto gets w/w'd. It did not w/w before because it takes a deeply nested argument, so the worker gets too many args, so we abandon w/w altogether (see GHC.Core.Opt.WorkWrap.Utils.isWorkerSmallEnough) With this patch we trim the demands. That is not strictly necessary (since these Generic type constructors are like tuples -- they can't cause a loop) but the net result is that we now w/w $cto which is fine. UniqLoop: 16% decrease in /runtime/ allocation. The UniqSupply is a recursive product, so currently we abandon all strictness on 'churn'. With this patch 'churn' gets useful strictness, and we w/w it. Hooray Metric Decrease: UniqLoop Metric Increase: T12227 - - - - - 87d504f4 by Viktor Dukhovni at 2020-06-13T02:13:05-04:00 Add introductory prose for Data.Traversable - - - - - 9f09b608 by Oleg Grenrus at 2020-06-13T02:13:07-04:00 Fix #12073: Add MonadFix Q instance - - - - - 220c2d34 by Ben Gamari at 2020-06-13T02:13:07-04:00 testsuite: Increase size of T12150 As noted in #18319, this test was previously very fragile. Increase its size to make it more likely that its fails with its newly-increased acceptance threshold. Metric Increase: T12150 - - - - - 8bba1c26 by Ben Gamari at 2020-06-13T04:59:06-04:00 gitlab-ci: Always push perf notes Previously we ci.sh would run with `set -e` implying that we wouldn't push perf notes if the testsuite were to fail, even if it *only* failed due to perf notes. This rendered the whole performance testing story quite fragile as a single regressing commit would cause every successive commit to fail since a new baseline would not be uploaded. Fix this by ensuring that we always push performance notes. - - - - - 7a773f16 by Ben Gamari at 2020-06-13T15:10:55-04:00 gitlab-ci: Eliminate redundant push of CI metrics - - - - - a31218f7 by Ryan Scott at 2020-06-13T15:58:37-04:00 Use HsForAllTelescope to avoid inferred, visible foralls Currently, `HsForAllTy` permits the combination of `ForallVis` and `Inferred`, but you can't actually typecheck code that uses it (e.g., `forall {a} ->`). This patch refactors `HsForAllTy` to use a new `HsForAllTelescope` data type that makes a type-level distinction between visible and invisible `forall`s such that visible `forall`s do not track `Specificity`. That part of the patch is actually quite small; the rest is simply changing consumers of `HsType` to accommodate this new type. Fixes #18235. Bumps the `haddock` submodule. - - - - - c0e6dee9 by Tamar Christina at 2020-06-14T09:07:44-04:00 winio: Add Atomic Exchange PrimOp and implement Atomic Ptr exchanges. The initial version was rewritten by Tamar Christina. It was rewritten in large parts by Andreas Klebinger. Co-authored-by: Andreas Klebinger <klebinger.andreas at gmx.at> - - - - - 9a7462fb by Ben Gamari at 2020-06-14T15:35:23-04:00 codeGen: Don't discard live case binders in unsafeEqualityProof logic Previously CoreToStg would unconditionally discard cases of the form: case unsafeEqualityProof of wild { _ -> rhs } and rather replace the whole thing with `rhs`. However, in some cases (see #18227) the case binder is still live, resulting in unbound occurrences in `rhs`. Fix this by only discarding the case if the case binder is dead. Fixes #18227. - - - - - e4137c48 by Ben Gamari at 2020-06-14T15:35:23-04:00 testsuite: Add tests for #18227 T18227A is the original issue which gave rise to the ticket and depends upon bytestring. T18227B is a minimized reproducer. - - - - - 8bab9ff1 by Ben Gamari at 2020-06-14T15:35:59-04:00 hadrian: Fix rts include and library paths Fixes two bugs: * (?) and (<>) associated in a surprising way * We neglected to include libdw paths in the rts configure flags - - - - - bd761185 by Ben Gamari at 2020-06-14T15:35:59-04:00 hadrian: Drop redundant GHC arguments Cabal should already be passing this arguments to GHC. - - - - - 01f7052c by Peter Trommler at 2020-06-14T15:36:38-04:00 FFI: Fix pass small ints in foreign call wrappers The Haskell calling convention requires integer parameters smaller than wordsize to be promoted to wordsize (where the upper bits are don't care). To access such small integer parameter read a word from the parameter array and then cast that word to the small integer target type. Fixes #15933 - - - - - 502647f7 by Krzysztof Gogolewski at 2020-06-14T15:37:14-04:00 Fix "ndecreasingIndentation" in manual (#18116) - - - - - 9a9cc089 by Simon Jakobi at 2020-06-15T13:10:00-04:00 Use foldl' in unionManyUniqDSets - - - - - 761dcb84 by Moritz Angermann at 2020-06-15T13:10:36-04:00 Load .lo as well. Some archives contain so called linker objects, with the affectionate .lo suffic. For example the musl libc.a will come in that form. We still want to load those objects, hence we should not discard them and look for .lo as well. Ultimately we might want to fix this proerly by looking at the file magic. - - - - - cf01477f by Vladislav Zavialov at 2020-06-15T13:11:20-04:00 User's Guide: KnownNat evidence is Natural This bit of documentation got outdated after commit 1fcede43d2b30f33b7505e25eb6b1f321be0407f - - - - - d0dcbfe6 by Jan Hrček at 2020-06-16T20:36:38+02:00 Fix typos and formatting in user guide - - - - - 56a9e95f by Jan Hrček at 2020-06-16T20:36:38+02:00 Resolve TODO - - - - - 3e884d14 by Jan Hrček at 2020-06-16T20:36:38+02:00 Rename TcHoleErrors to GHC.Tc.Errors.Hole - - - - - d23fc678 by Stefan Schulze Frielinghaus at 2020-06-17T15:31:09-04:00 hadrian: Build with threaded runtime if available See #16873. - - - - - 0639dc10 by Sylvain Henry at 2020-06-17T15:31:53-04:00 T16190: only measure bytes_allocated Just adding `{-# LANGUAGE BangPatterns #-}` makes the two other metrics fluctuate by 13%. - - - - - 4cab6897 by Adam Sandberg Ericsson at 2020-06-17T15:32:44-04:00 docs: fix formatting in users guide - - - - - eb8115a8 by Sylvain Henry at 2020-06-17T15:33:23-04:00 Move CLabel assertions into smart constructors (#17957) It avoids using DynFlags in the Outputable instance of Clabel to check assertions at pretty-printing time. - - - - - 7faa4509 by Ben Gamari at 2020-06-17T15:43:31-04:00 base: Bump to 4.15.0.0 - - - - - 20616959 by Ben Gamari at 2020-06-17T15:43:31-04:00 configure: Use grep -q instead of --quiet The latter is apparently not supported by busybox. - - - - - 40fa237e by Krzysztof Gogolewski at 2020-06-17T16:21:58-04:00 Linear types (#15981) This is the first step towards implementation of the linear types proposal (https://github.com/ghc-proposals/ghc-proposals/pull/111). It features * A language extension -XLinearTypes * Syntax for linear functions in the surface language * Linearity checking in Core Lint, enabled with -dlinear-core-lint * Core-to-core passes are mostly compatible with linearity * Fields in a data type can be linear or unrestricted; linear fields have multiplicity-polymorphic constructors. If -XLinearTypes is disabled, the GADT syntax defaults to linear fields The following items are not yet supported: * a # m -> b syntax (only prefix FUN is supported for now) * Full multiplicity inference (multiplicities are really only checked) * Decent linearity error messages * Linear let, where, and case expressions in the surface language (each of these currently introduce the unrestricted variant) * Multiplicity-parametric fields * Syntax for annotating lambda-bound or let-bound with a multiplicity * Syntax for non-linear/multiple-field-multiplicity records * Linear projections for records with a single linear field * Linear pattern synonyms * Multiplicity coercions (test LinearPolyType) A high-level description can be found at https://ghc.haskell.org/trac/ghc/wiki/LinearTypes/Implementation Following the link above you will find a description of the changes made to Core. This commit has been authored by * Richard Eisenberg * Krzysztof Gogolewski * Matthew Pickering * Arnaud Spiwack With contributions from: * Mark Barbone * Alexander Vershilov Updates haddock submodule. - - - - - 6cb84c46 by Krzysztof Gogolewski at 2020-06-17T16:22:03-04:00 Various performance improvements This implements several general performance improvements to GHC, to offset the effect of the linear types change. General optimisations: - Add a `coreFullView` function which iterates `coreView` on the head. This avoids making function recursive solely because the iterate `coreView` themselves. As a consequence, this functions can be inlined, and trigger case-of-known constructor (_e.g._ `kindRep_maybe`, `isLiftedRuntimeRep`, `isMultiplicityTy`, `getTyVar_maybe`, `splitAppTy_maybe`, `splitFunType_maybe`, `tyConAppTyCon_maybe`). The common pattern about all these functions is that they are almost always used as views, and immediately consumed by a case expression. This commit also mark them asx `INLINE`. - In `subst_ty` add a special case for nullary `TyConApp`, which avoid allocations altogether. - Use `mkTyConApp` in `subst_ty` for the general `TyConApp`. This required quite a bit of module shuffling. case. `myTyConApp` enforces crucial sharing, which was lost during substitution. See also !2952 . - Make `subst_ty` stricter. - In `eqType` (specifically, in `nonDetCmpType`), add a special case, tested first, for the very common case of nullary `TyConApp`. `nonDetCmpType` has been made `INLINE` otherwise it is actually a regression. This is similar to the optimisations in !2952. Linear-type specific optimisations: - Use `tyConAppTyCon_maybe` instead of the more complex `eqType` in the definition of the pattern synonyms `One` and `Many`. - Break the `hs-boot` cycles between `Multiplicity.hs` and `Type.hs`: `Multiplicity` now import `Type` normally, rather than from the `hs-boot`. This way `tyConAppTyCon_maybe` can inline properly in the `One` and `Many` pattern synonyms. - Make `updateIdTypeAndMult` strict in its type and multiplicity - The `scaleIdBy` gets a specialised definition rather than being an alias to `scaleVarBy` - `splitFunTy_maybe` is given the type `Type -> Maybe (Mult, Type, Type)` instead of `Type -> Maybe (Scaled Type, Type)` - Remove the `MultMul` pattern synonym in favour of a view `isMultMul` because pattern synonyms appear not to inline well. - in `eqType`, in a `FunTy`, compare multiplicities last: they are almost always both `Many`, so it helps failing faster. - Cache `manyDataConTy` in `mkTyConApp`, to make sure that all the instances of `TyConApp ManyDataConTy []` are physically the same. This commit has been authored by * Richard Eisenberg * Krzysztof Gogolewski * Arnaud Spiwack Metric Decrease: haddock.base T12227 T12545 T12990 T1969 T3064 T5030 T9872b Metric Increase: haddock.base haddock.Cabal haddock.compiler T12150 T12234 T12425 T12707 T13035 T13056 T15164 T16190 T18304 T1969 T3064 T3294 T5631 T5642 T5837 T6048 T9020 T9233 T9675 T9872a T9961 WWRec - - - - - 57db91d8 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Remove integer-simple integer-simple uses lists of words (`[Word]`) to represent big numbers instead of ByteArray#: * it is less efficient than the newer ghc-bignum native backend * it isn't compatible with the big number representation that is now shared by all the ghc-bignum backends (based on the one that was used only in integer-gmp before). As a consequence, we simply drop integer-simple - - - - - 9f96bc12 by Sylvain Henry at 2020-06-17T16:22:03-04:00 ghc-bignum library ghc-bignum is a newer package that aims to replace the legacy integer-simple and integer-gmp packages. * it supports several backends. In particular GMP is still supported and most of the code from integer-gmp has been merged in the "gmp" backend. * the pure Haskell "native" backend is new and is much faster than the previous pure Haskell implementation provided by integer-simple * new backends are easier to write because they only have to provide a few well defined functions. All the other code is common to all backends. In particular they all share the efficient small/big number distinction previously used only in integer-gmp. * backends can all be tested against the "native" backend with a simple Cabal flag. Backends are only allowed to differ in performance, their results should be the same. * Add `integer-gmp` compat package: provide some pattern synonyms and function aliases for those in `ghc-bignum`. It is intended to avoid breaking packages that depend on `integer-gmp` internals. Update submodules: text, bytestring Metric Decrease: Conversions ManyAlternatives ManyConstructors Naperian T10359 T10547 T10678 T12150 T12227 T12234 T12425 T13035 T13719 T14936 T1969 T4801 T4830 T5237 T5549 T5837 T8766 T9020 parsing001 space_leak_001 T16190 haddock.base On ARM and i386, T17499 regresses (+6% > 5%). On x86_64 unregistered, T13701 sometimes regresses (+2.2% > 2%). Metric Increase: T17499 T13701 - - - - - 96aa5787 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update compiler Thanks to ghc-bignum, the compiler can be simplified: * Types and constructors of Integer and Natural can be wired-in. It means that we don't have to query them from interfaces. It also means that numeric literals don't have to carry their type with them. * The same code is used whatever ghc-bignum backend is enabled. In particular, conversion of bignum literals into final Core expressions is now much more straightforward. Bignum closure inspection too. * GHC itself doesn't depend on any integer-* package anymore * The `integerLibrary` setting is gone. - - - - - 0f67e344 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update `base` package * GHC.Natural isn't implemented in `base` anymore. It is provided by ghc-bignum in GHC.Num.Natural. It means that we can safely use Natural primitives in `base` without fearing issues with built-in rewrite rules (cf #15286) * `base` doesn't conditionally depend on an integer-* package anymore, it depends on ghc-bignum * Some duplicated code in integer-* can now be factored in GHC.Float * ghc-bignum tries to use a uniform naming convention so most of the other changes are renaming - - - - - aa9e7b71 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update `make` based build system * replace integer-* package selection with ghc-bignum backend selection - - - - - f817d816 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Update testsuite * support detection of slow ghc-bignum backend (to replace the detection of integer-simple use). There are still some test cases that the native backend doesn't handle efficiently enough. * remove tests for GMP only functions that have been removed from ghc-bignum * fix test results showing dependent packages (e.g. integer-gmp) or showing suggested instances * fix test using Integer/Natural API or showing internal names - - - - - dceecb09 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Update Hadrian * support ghc-bignum backend selection in flavours and command-line * support ghc-bignum "--check" flag (compare results of selected backend against results of the native one) in flavours and command-line (e.g. pass --bignum=check-gmp" to check the "gmp" backend) * remove the hack to workaround #15286 * build GMP only when the gmp backend is used * remove hacks to workaround `text` package flags about integer-*. We fix `text` to use ghc-bignum unconditionally in another patch - - - - - fa4281d6 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Bump bytestring and text submodules - - - - - 1a3f6f34 by Adam Sandberg Ericsson at 2020-06-18T23:03:36-04:00 docs: mention -hiedir in docs for -outputdir [skip ci] - - - - - 729bcb02 by Sylvain Henry at 2020-06-18T23:04:17-04:00 Hadrian: fix build on Mac OS Catalina (#17798) - - - - - 95e18292 by Andreas Klebinger at 2020-06-18T23:04:58-04:00 Relax allocation threshold for T12150. This test performs little work, so the most minor allocation changes often cause the test to fail. Increasing the threshold to 2% should help with this. - - - - - 8ce6c393 by Sebastian Graf at 2020-06-18T23:05:36-04:00 hadrian: Bump pinned cabal.project to an existent index-state - - - - - 08c1cb0f by Ömer Sinan Ağacan at 2020-06-18T23:06:21-04:00 Fix uninitialized field read in Linker.c Valgrind report of the bug when running the test `linker_unload`: ==29666== Conditional jump or move depends on uninitialised value(s) ==29666== at 0x369C5B4: setOcInitialStatus (Linker.c:1305) ==29666== by 0x369C6C5: mkOc (Linker.c:1347) ==29666== by 0x36C027A: loadArchive_ (LoadArchive.c:522) ==29666== by 0x36C0600: loadArchive (LoadArchive.c:626) ==29666== by 0x2C144CD: ??? (in /home/omer/haskell/ghc_2/testsuite/tests/rts/linker/linker_unload.run/linker_unload) ==29666== ==29666== Conditional jump or move depends on uninitialised value(s) ==29666== at 0x369C5B4: setOcInitialStatus (Linker.c:1305) ==29666== by 0x369C6C5: mkOc (Linker.c:1347) ==29666== by 0x369C9F6: preloadObjectFile (Linker.c:1507) ==29666== by 0x369CA8D: loadObj_ (Linker.c:1536) ==29666== by 0x369CB17: loadObj (Linker.c:1557) ==29666== by 0x3866BC: main (linker_unload.c:33) The problem is `mkOc` allocates a new `ObjectCode` and calls `setOcInitialStatus` without initializing the `status` field. `setOcInitialStatus` reads the field as first thing: static void setOcInitialStatus(ObjectCode* oc) { if (oc->status == OBJECT_DONT_RESOLVE) return; if (oc->archiveMemberName == NULL) { oc->status = OBJECT_NEEDED; } else { oc->status = OBJECT_LOADED; } } `setOcInitialStatus` is unsed in two places for two different purposes: in `mkOc` where we don't have the `status` field initialized yet (`mkOc` is supposed to initialize it), and `loadOc` where we do have `status` field initialized and we want to update it. Instead of splitting the function into two functions which are both called just once I inline the functions in the use sites and remove it. Fixes #18342 - - - - - da18ff99 by Tamar Christina at 2020-06-18T23:07:03-04:00 fix windows bootstrap due to linker changes - - - - - 2af0ec90 by Sylvain Henry at 2020-06-18T23:07:47-04:00 DynFlags: store default depth in SDocContext (#17957) It avoids having to use DynFlags to reach for pprUserLength. - - - - - d4a0be75 by Sylvain Henry at 2020-06-18T23:08:35-04:00 Move tablesNextToCode field into Platform tablesNextToCode is a platform setting and doesn't belong into DynFlags (#17957). Doing this is also a prerequisite to fix #14335 where we deal with two platforms (target and host) that may have different platform settings. - - - - - 809caedf by John Ericson at 2020-06-23T22:47:37-04:00 Switch from HscSource to IsBootInterface for module lookup in GhcMake We look up modules by their name, and not their contents. There is no way to separately reference a signature vs regular module; you get what you get. Only boot files can be referenced indepenently with `import {-# SOURCE #-}`. - - - - - 7750bd45 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Cmm: introduce SAVE_REGS/RESTORE_REGS We don't want to save both Fn and Dn register sets on x86-64 as they are aliased to the same arch register (XMMn). Moreover, when SAVE_STGREGS was used in conjunction with `jump foo [*]` which makes a set of Cmm registers alive so that they cover all arch registers used to pass parameter, we could have Fn, Dn and XMMn alive at the same time. It made the LLVM code generator choke (see #17920). Now `SAVE_REGS/RESTORE_REGS` and `jump foo [*]` use the same set of registers. - - - - - 2636794d by Sylvain Henry at 2020-06-23T22:48:18-04:00 CmmToC: don't add extern decl to parsed Cmm data Previously, if a .cmm file *not in the RTS* contained something like: ```cmm section "rodata" { msg : bits8[] "Test\n"; } ``` It would get compiled by CmmToC into: ```c ERW_(msg); const char msg[] = "Test\012"; ``` and fail with: ``` /tmp/ghc32129_0/ghc_4.hc:5:12: error: error: conflicting types for \u2018msg\u2019 const char msg[] = "Test\012"; ^~~ In file included from /tmp/ghc32129_0/ghc_4.hc:3:0: error: /tmp/ghc32129_0/ghc_4.hc:4:6: error: note: previous declaration of \u2018msg\u2019 was here ERW_(msg); ^ /builds/hsyl20/ghc/_build/install/lib/ghc-8.11.0.20200605/lib/../lib/x86_64-linux-ghc-8.11.0.20200605/rts-1.0/include/Stg.h:253:46: error: note: in definition of macro \u2018ERW_\u2019 #define ERW_(X) extern StgWordArray (X) ^ ``` See the rationale for this on https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/backends/ppr-c#prototypes Now we don't generate these extern declarations (ERW_, etc.) for top-level data. It shouldn't change anything for the RTS (the only place we use .cmm files) as it is already special cased in `GHC.Cmm.CLabel.needsCDecl`. And hand-written Cmm can use explicit extern declarations when needed. Note that it allows `cgrun069` test to pass with CmmToC (cf #15467). - - - - - 5f6a0665 by Sylvain Henry at 2020-06-23T22:48:18-04:00 LLVM: refactor and comment register padding code (#17920) - - - - - cad62ef1 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Add tests for #17920 Metric Decrease: T12150 T12234 - - - - - a2a9006b by Xavier Denis at 2020-06-23T22:48:56-04:00 Fix issue #18262 by zonking constraints after solving Zonk residual constraints in checkForExistence to reveal user type errors. Previously when `:instances` was used with instances that have TypeError constraints the result would look something like: instance [safe] s0 => Err 'A -- Defined at ../Bug2.hs:8:10 whereas after zonking, `:instances` now sees the `TypeError` and properly eliminates the constraint from the results. - - - - - 181516bc by Simon Peyton Jones at 2020-06-23T22:49:33-04:00 Fix a buglet in Simplify.simplCast This bug, revealed by #18347, is just a missing update to sc_hole_ty in simplCast. I'd missed a code path when I made the recentchanges in commit 6d49d5be904c0c01788fa7aae1b112d5b4dfaf1c Author: Simon Peyton Jones <simonpj at microsoft.com> Date: Thu May 21 12:53:35 2020 +0100 Implement cast worker/wrapper properly The fix is very easy. Two other minor changes * Tidy up in SimpleOpt.simple_opt_expr. In fact I think this is an outright bug, introduced in the fix to #18112: we were simplifying the same coercion twice *with the same substitution*, which is just wrong. It'd be a hard bug to trigger, so I just fixed it; less code too. * Better debug printing of ApplyToVal - - - - - 625a7f54 by Simon Peyton Jones at 2020-06-23T22:50:11-04:00 Two small tweaks to Coercion.simplifyArgsWorker These tweaks affect the inner loop of simplifyArgsWorker, which in turn is called from the flattener in Flatten.hs. This is a key perf bottleneck to T9872{a,b,c,d}. These two small changes have a modest but useful benefit. No change in functionality whatsoever. Relates to #18354 - - - - - b5768cce by Sylvain Henry at 2020-06-23T22:50:49-04:00 Don't use timesInt2# with GHC < 8.11 (fix #18358) - - - - - 7ad4085c by Sylvain Henry at 2020-06-23T22:51:27-04:00 Fix invalid printf format - - - - - a1f34d37 by Krzysztof Gogolewski at 2020-06-23T22:52:09-04:00 Add missing entry to freeNamesItem (#18369) - - - - - 03a708ba by Andreas Klebinger at 2020-06-25T03:54:37-04:00 Enable large address space optimization on windows. Starting with Win 8.1/Server 2012 windows no longer preallocates page tables for reserverd memory eagerly, which prevented us from using this approach in the past. We also try to allocate the heap high in the memory space. Hopefully this makes it easier to allocate things in the low 4GB of memory that need to be there. Like jump islands for the linker. - - - - - 7e6d3d09 by Roland Senn at 2020-06-25T03:54:38-04:00 In `:break ident` allow out of scope and nested identifiers (Fix #3000) This patch fixes the bug and implements the feature request of #3000. 1. If `Module` is a real module name and `identifier` a name of a top-level function in `Module` then `:break Module.identifer` works also for an `identifier` that is out of scope. 2. Extend the syntax for `:break identifier` to: :break [ModQual.]topLevelIdent[.nestedIdent]...[.nestedIdent] `ModQual` is optional and is either the effective name of a module or the local alias of a qualified import statement. `topLevelIdent` is the name of a top level function in the module referenced by `ModQual`. `nestedIdent` is optional and the name of a function nested in a let or where clause inside the previously mentioned function `nestedIdent` or `topLevelIdent`. If `ModQual` is a module name, then `topLevelIdent` can be any top level identifier in this module. If `ModQual` is missing or a local alias of a qualified import, then `topLevelIdent` must be in scope. Breakpoints can be set on arbitrarily deeply nested functions, but the whole chain of nested function names must be specified. 3. To support the new functionality rewrite the code to tab complete `:break`. - - - - - 30e42652 by Ben Gamari at 2020-06-25T03:54:39-04:00 make: Respect XELATEX variable Previously we simply ignored the XELATEX variable when building PDF documentation. - - - - - 4acc2934 by Ben Gamari at 2020-06-25T03:54:39-04:00 hadrian/make: Detect makeindex Previously we would simply assume that makeindex was available. Now we correctly detect it in `configure` and respect this conclusion in hadrian and make. - - - - - 0d61f866 by Simon Peyton Jones at 2020-06-25T03:54:40-04:00 Expunge GhcTcId GHC.Hs.Extension had type GhcPs = GhcPass 'Parsed type GhcRn = GhcPass 'Renamed type GhcTc = GhcPass 'Typechecked type GhcTcId = GhcTc The last of these, GhcTcId, is a vestige of the past. This patch expunges it from GHC. - - - - - 8ddbed4a by Adam Wespiser at 2020-06-25T03:54:40-04:00 add examples to Data.Traversable - - - - - 284001d0 by Oleg Grenrus at 2020-06-25T03:54:42-04:00 Export readBinIface_ - - - - - 90f43872 by Zubin Duggal at 2020-06-25T03:54:43-04:00 Export everything from HsToCore. This lets us reuse these functions in haddock, avoiding synchronization bugs. Also fixed some divergences with haddock in that file Updates haddock submodule - - - - - c7dd6da7 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part1) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Hs.* - GHC.Core.* - GHC.Stg.* - GHC.Cmm.* - GHC.Types.* - GHC.Data.* - GHC.Builtin.* - GHC.Parser.* - GHC.Driver.* - GHC top - - - - - 1eb997a8 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part2) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Iface.* - GHC.Llvm.* - GHC.Rename.* - GHC.Tc.* - GHC.HsToCore.* - GHC.StgToCmm.* - GHC.CmmToAsm.* - GHC.Runtime.* - GHC.Unit.* - GHC.Utils.* - GHC.SysTools.* - - - - - 67a86b4d by Oleg Grenrus at 2020-06-25T03:54:46-04:00 Add MonadZip and MonadFix instances for Complex These instances are taken from https://hackage.haskell.org/package/linear-1.21/docs/Linear-Instances.html They are the unique possible, so let they be in `base`. - - - - - c50ef26e by Artem Pelenitsyn at 2020-06-25T03:54:47-04:00 test suite: add reproducer for #17516 - - - - - fe281b27 by Roland Senn at 2020-06-25T03:54:48-04:00 Enable maxBound checks for OverloadedLists (Fixes #18172) Consider the Literal `[256] :: [Data.Word.Word8]` When the `OverloadedLists` extension is not active, then the `ol_ext` field in the `OverLitTc` record that is passed to the function `getIntegralLit` contains the type `Word8`. This is a simple type, and we can use its type constructor immediately for the `warnAboutOverflowedLiterals` function. When the `OverloadedLists` extension is active, then the `ol_ext` field contains the type family `Item [Word8]`. The function `nomaliseType` is used to convert it to the needed type `Word8`. - - - - - a788d4d1 by Ben Gamari at 2020-06-25T03:54:52-04:00 rts/Hash: Simplify freeing of HashListChunks While looking at #18348 I noticed that the treatment of HashLists are a bit more complex than necessary (which lead to some initial confusion on my part). Specifically, we allocate HashLists in chunks. Each chunk allocation makes two allocations: one for the chunk itself and one for a HashListChunk to link together the chunks for the purposes of freeing. Simplify this (and hopefully make the relationship between these clearer) but allocating the HashLists and HashListChunk in a single malloc. This will both make the implementation easier to follow and reduce C heap fragmentation. Note that even after this patch we fail to bound the size of the free HashList pool. However, this is a separate bug. - - - - - d3c2d59b by Sylvain Henry at 2020-06-25T03:54:55-04:00 RTS: avoid overflow on 32-bit arch (#18375) We're now correctly computing allocated bytes on 32-bit arch, so we get huge increases. Metric Increase: haddock.Cabal haddock.base haddock.compiler space_leak_001 - - - - - a3d69dc6 by Sebastian Graf at 2020-06-25T23:06:18-04:00 GHC.Core.Unify: Make UM actions one-shot by default This MR makes the UM monad in GHC.Core.Unify into a one-shot monad. See the long Note [The one-shot state monad trick]. See also #18202 and !3309, which applies this to all Reader/State-like monads in GHC for compile-time perf improvements. The pattern used here enables something similar to the state-hack, but is applicable to user-defined monads, not just `IO`. Metric Decrease 'runtime/bytes allocated' (test_env='i386-linux-deb9'): haddock.Cabal - - - - - 9ee58f8d by Matthias Pall Gissurarson at 2020-06-26T17:12:45+00:00 Implement the proposed -XQualifiedDo extension Co-authored-by: Facundo Domínguez <facundo.dominguez at tweag.io> QualifiedDo is implemented using the same placeholders for operation names in the AST that were devised for RebindableSyntax. Whenever the renamer checks which names to use for do syntax, it first checks if the do block is qualified (e.g. M.do { stmts }), in which case it searches for qualified names in the module M. This allows users to write {-# LANGUAGE QualifiedDo #-} import qualified SomeModule as M f x = M.do -- desugars to: y <- M.return x -- M.return x M.>>= \y -> M.return y -- M.return y M.>> M.return y -- M.return y See Note [QualifiedDo] and the users' guide for more details. Issue #18214 Proposal: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0216-qualified-do.rst Since we change the constructors `ITdo` and `ITmdo` to carry the new module name, we need to bump the haddock submodule to account or the new shape of these constructors. - - - - - ce987865 by Ryan Scott at 2020-06-27T11:55:21-04:00 Revamp the treatment of auxiliary bindings for derived instances This started as a simple fix for #18321 that organically grew into a much more sweeping refactor of how auxiliary bindings for derived instances are handled. I have rewritten `Note [Auxiliary binders]` in `GHC.Tc.Deriv.Generate` to explain all of the moving parts, but the highlights are: * Previously, the OccName of each auxiliary binding would be given a suffix containing a hash of its package name, module name, and parent data type to avoid name clashes. This was needlessly complicated, so we take the more direct approach of generating `Exact` `RdrName`s for each auxiliary binding with the same `OccName`, but using an underlying `System` `Name` with a fresh `Unique` for each binding. Unlike hashes, allocating new `Unique`s does not require any cleverness and avoid name clashes all the same... * ...speaking of which, in order to convince the renamer that multiple auxiliary bindings with the same `OccName` (but different `Unique`s) are kosher, we now use `rnLocalValBindsLHS` instead of `rnTopBindsLHS` to rename auxiliary bindings. Again, see `Note [Auxiliary binders]` for the full story. * I have removed the `DerivHsBind` constructor for `DerivStuff`—which was only used for `Data.Data`-related auxiliary bindings—and refactored `gen_Data_binds` to use `DerivAuxBind` instead. This brings the treatment of `Data.Data`-related auxiliary bindings in line with every other form of auxiliary binding. Fixes #18321. - - - - - a403eb91 by Sylvain Henry at 2020-06-27T11:55:59-04:00 ghc-bignum: fix division by zero (#18359) - - - - - 1b3d13b6 by Sylvain Henry at 2020-06-27T11:55:59-04:00 Fix ghc-bignum exceptions We must ensure that exceptions are not simplified. Previously we used: case raiseDivZero of _ -> 0## -- dummyValue But it was wrong because the evaluation of `raiseDivZero` was removed and the dummy value was directly returned. See new Note [ghc-bignum exceptions]. I've also removed the exception triggering primops which were fragile. We don't need them to be primops, we can have them exported by ghc-prim. I've also added a test for #18359 which triggered this patch. - - - - - a74ec37c by Simon Peyton Jones at 2020-06-27T11:56:34-04:00 Better loop detection in findTypeShape Andreas pointed out, in !3466, that my fix for #18304 was not quite right. This patch fixes it properly, by having just one RecTcChecker rather than (implicitly) two nested ones, in findTypeShape. - - - - - a04020b8 by Sylvain Henry at 2020-06-27T11:57:11-04:00 DynFlags: don't store buildTag `DynFlags.buildTag` was a field created from the set of Ways in `DynFlags.ways`. It had to be kept in sync with `DynFlags.ways` which was fragile. We want to avoid global state like this (#17957). Moreover in #14335 we also want to support loading units with different ways: target units would still use `DynFlags.ways` but plugins would use `GHC.Driver.Ways.hostFullWays`. To avoid having to deal both with build tag and with ways, we recompute the buildTag on-the-fly (should be pretty cheap) and we remove `DynFlags.buildTag` field. - - - - - 0e83efa2 by Krzysztof Gogolewski at 2020-06-27T11:57:49-04:00 Don't generalize when typechecking a tuple section The code is simpler and cleaner. - - - - - d8ba9e6f by Peter Trommler at 2020-06-28T09:19:11-04:00 RTS: Refactor Haskell-C glue for PPC 64-bit Make sure the stack is 16 byte aligned even when reserved stack bytes are not a multiple of 16 bytes. Avoid saving r2 (TOC). On ELF v1 the function descriptor of StgReturn has the same TOC as StgRun, on ELF v2 the TOC is recomputed in the function prologue. Use the ABI provided functions to save clobbered GPRs and FPRs. Improve comments. Describe what the stack looks like and how it relates to the respective ABIs. - - - - - 42f797b0 by Ryan Scott at 2020-06-28T09:19:46-04:00 Use NHsCoreTy to embed types into GND-generated code `GeneralizedNewtypeDeriving` is in the unique situation where it must produce an `LHsType GhcPs` from a Core `Type`. Historically, this was done with the `typeToLHsType` function, which walked over the entire `Type` and attempted to construct an `LHsType` with the same overall structure. `typeToLHsType` is quite complicated, however, and has been the subject of numerous bugs over the years (e.g., #14579). Luckily, there is an easier way to accomplish the same thing: the `XHsType` constructor of `HsType`. `XHsType` bundles an `NHsCoreTy`, which allows embedding a Core `Type` directly into an `HsType`, avoiding the need to laboriously convert from one to another (as `typeToLHsType` did). Moreover, renaming and typechecking an `XHsType` is simple, since one doesn't need to do anything to a Core `Type`... ...well, almost. For the reasons described in `Note [Typechecking NHsCoreTys]` in `GHC.Tc.Gen.HsType`, we must apply a substitution that we build from the local `tcl_env` type environment. But that's a relatively modest price to pay. Now that `GeneralizedNewtypeDeriving` uses `NHsCoreTy`, the `typeToLHsType` function no longer has any uses in GHC, so this patch rips it out. Some additional tweaks to `hsTypeNeedsParens` were necessary to make the new `-ddump-deriv` output correctly parenthesized, but other than that, this patch is quite straightforward. This is a mostly internal refactoring, although it is likely that `GeneralizedNewtypeDeriving`-generated code will now need fewer language extensions in certain situations than it did before. - - - - - 68530b1c by Jan Hrček at 2020-06-28T09:20:22-04:00 Fix duplicated words and typos in comments and user guide - - - - - 15b79bef by Ryan Scott at 2020-06-28T09:20:57-04:00 Add integer-gmp's ghc.mk and GNUmakefile to .gitignore - - - - - bfa5698b by Simon Peyton Jones at 2020-06-28T09:21:32-04:00 Fix a typo in Lint This simple error in GHC.Core.Litn.lintJoinLams meant that Lint reported bogus errors. Fixes #18399 - - - - - 71006532 by Ryan Scott at 2020-06-30T07:10:42-04:00 Reject nested foralls/contexts in instance types more consistently GHC is very wishy-washy about rejecting instance declarations with nested `forall`s or contexts that are surrounded by outermost parentheses. This can even lead to some strange interactions with `ScopedTypeVariables`, as demonstrated in #18240. This patch makes GHC more consistently reject instance types with nested `forall`s/contexts so as to prevent these strange interactions. On the implementation side, this patch tweaks `splitLHsInstDeclTy` and `getLHsInstDeclHead` to not look through parentheses, which can be semantically significant. I've added a `Note [No nested foralls or contexts in instance types]` in `GHC.Hs.Type` to explain why. This also introduces a `no_nested_foralls_contexts_err` function in `GHC.Rename.HsType` to catch nested `forall`s/contexts in instance types. This function is now used in `rnClsInstDecl` (for ordinary instance declarations) and `rnSrcDerivDecl` (for standalone `deriving` declarations), the latter of which fixes #18271. On the documentation side, this adds a new "Formal syntax for instance declaration types" section to the GHC User's Guide that presents a BNF-style grammar for what is and isn't allowed in instance types. Fixes #18240. Fixes #18271. - - - - - bccf3351 by Sylvain Henry at 2020-06-30T07:10:46-04:00 Add ghc-bignum to 8.12 release notes - - - - - 81704a6f by David Eichmann at 2020-06-30T07:10:48-04:00 Update ssh keys in CI performance metrics upload script - - - - - 85310fb8 by Joshua Price at 2020-06-30T07:10:49-04:00 Add missing Ix instances for tuples of size 6 through 15 (#16643) - - - - - cbb6b62f by Vladislav Zavialov at 2020-07-01T15:41:38-04:00 Implement -XLexicalNegation (GHC Proposal #229) This patch introduces a new extension, -XLexicalNegation, which detects whether the minus sign stands for negation or subtraction using the whitespace-based rules described in GHC Proposal #229. Updates haddock submodule. - - - - - fb5a0d01 by Martin Handley at 2020-07-01T15:42:14-04:00 #17169: Clarify Fixed's Enum instance. - - - - - b316804d by Simon Peyton Jones at 2020-07-01T15:42:49-04:00 Improve debug tracing for substitution This patch improves debug tracing a bit (#18395) * Remove the ancient SDoc argument to substitution, replacing it with a HasDebugCallStack constraint. The latter does the same job (indicate the call site) but much better. * Add HasDebugCallStack to simpleOptExpr, exprIsConApp_maybe I needed this to help nail the lookupIdSubst panic in #18326, #17784 - - - - - 5c9fabb8 by Hécate at 2020-07-01T15:43:25-04:00 Add most common return values for `os` and `arch` - - - - - 76d8cc74 by Ryan Scott at 2020-07-01T15:44:01-04:00 Desugar quoted uses of DerivingVia and expression type signatures properly The way that `GHC.HsToCore.Quote` desugared quoted `via` types (e.g., `deriving via forall a. [a] instance Eq a => Eq (List a)`) and explicit type annotations in signatures (e.g., `f = id @a :: forall a. a -> a`) was completely wrong, as it did not implement the scoping guidelines laid out in `Note [Scoped type variables in bindings]`. This is easily fixed. While I was in town, I did some minor cleanup of related Notes: * `Note [Scoped type variables in bindings]` and `Note [Scoped type variables in class and instance declarations]` say very nearly the same thing. I decided to just consolidate the two Notes into `Note [Scoped type variables in quotes]`. * `Note [Don't quantify implicit type variables in quotes]` is somewhat outdated, as it predates GHC 8.10, where the `forall`-or-nothing rule requires kind variables to be explicitly quantified in the presence of an explicit `forall`. As a result, the running example in that Note doesn't even compile. I have changed the example to something simpler that illustrates the same point that the original Note was making. Fixes #18388. - - - - - 44d6a335 by Andreas Klebinger at 2020-07-02T02:54:54-04:00 T16012: Be verbose on failure. - - - - - f9853330 by Ryan Scott at 2020-07-02T02:55:29-04:00 Bump ghc-prim version to 0.7.0 Fixes #18279. Bumps the `text` submodule. - - - - - 23e4e047 by Sylvain Henry at 2020-07-02T10:46:31-04:00 Hadrian: fix PowerPC64le support (#17601) [ci skip] - - - - - 3cdd8d69 by Sylvain Henry at 2020-07-02T10:47:08-04:00 NCG: correctly handle addresses with huge offsets (#15570) Before this patch we could generate addresses of this form: movzbl cP0_str+-9223372036854775808,%eax The linker can't handle them because the offset is too large: ld.lld: error: Main.o:(.text+0xB3): relocation R_X86_64_32S out of range: -9223372036852653050 is not in [-2147483648, 2147483647] With this patch we detect those cases and generate: movq $-9223372036854775808,%rax addq $cP0_str,%rax movzbl (%rax),%eax I've also refactored `getAmode` a little bit to make it easier to understand and to trace. - - - - - 4d90b3ff by Gabor Greif at 2020-07-02T20:07:59-04:00 No need for CURSES_INCLUDE_DIRS This is a leftover from ef63ff27251a20ff11e58c9303677fa31e609a88 - - - - - f08d6316 by Sylvain Henry at 2020-07-02T20:08:36-04:00 Replace Opt_SccProfilingOn flag with sccProfilingEnabled helper function SCC profiling was enabled in a convoluted way: if WayProf was enabled, Opt_SccProfilingOn general flag was set (in `GHC.Driver.Ways.wayGeneralFlags`), and then this flag was queried in various places. There is no need to go via general flags, so this patch defines a `sccProfilingEnabled :: DynFlags -> Bool` helper function that just checks whether WayProf is enabled. - - - - - 8cc7274b by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Only allocate the Censuses that we need When not LDV profiling there is no reason to allocate 32 Censuses; one will do. This is a very small memory footprint optimisation, but it comes for free. - - - - - b835112c by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Free old allocations when reinitialising Censuses Previously when not LDV profiling we would repeatedly reinitialise `censuses[0]` with `initEra`. This failed to free the `Arena` and `HashTable` from the old census, resulting in a memory leak. Fixes #18348. - - - - - 34be6523 by Valery Tolstov at 2020-07-03T02:50:03-04:00 Mention flags that are not enabled by -Wall (#18372) * Mention missing flags that are not actually enabled by -Wall (docs/users_guide/using-warnings.rst) * Additionally remove -Wmissing-monadfail-instances from the list of flags enabled by -Wcompat, as it is not the case since 8.8 - - - - - edc8d22b by Sylvain Henry at 2020-07-03T02:50:40-04:00 LLVM: support R9 and R10 registers d535ef006d85dbdb7cda2b09c5bc35cb80108909 allowed the use of up to 10 vanilla registers but didn't update LLVM backend to support them. This patch fixes it. - - - - - 4bf18646 by Simon Peyton Jones at 2020-07-03T08:37:42+01:00 Improve handling of data type return kinds Following a long conversation with Richard, this patch tidies up the handling of return kinds for data/newtype declarations (vanilla, family, and instance). I have substantially edited the Notes in TyCl, so they would bear careful reading. Fixes #18300, #18357 In GHC.Tc.Instance.Family.newFamInst we were checking some Lint-like properties with ASSSERT. Instead Richard and I have added a proper linter for axioms, and called it from lintGblEnv, which in turn is called in tcRnModuleTcRnM New tests (T18300, T18357) cause an ASSERT failure in HEAD. - - - - - 41d26492 by Sylvain Henry at 2020-07-03T17:33:59-04:00 DynFlags: avoid the use of sdocWithDynFlags in GHC.Core.Rules (#17957) - - - - - 7aa6ef11 by Hécate at 2020-07-03T17:34:36-04:00 Add the __GHC_FULL_VERSION__ CPP macro to expose the full GHC version - - - - - e61d5395 by Chaitanya Koparkar at 2020-07-07T13:55:59-04:00 ghc-prim: Turn some comments into haddocks [ci skip] - - - - - 37743f91 by John Ericson at 2020-07-07T13:56:00-04:00 Support `timesInt2#` in LLVM backend - - - - - 46397e53 by John Ericson at 2020-07-07T13:56:00-04:00 `genericIntMul2Op`: Call `genericWordMul2Op` directly This unblocks a refactor, and removes partiality. It might be a PowerPC regression but that should be fixable. - - - - - 8a1c0584 by John Ericson at 2020-07-07T13:56:00-04:00 Simplify `PrimopCmmEmit` Follow @simonpj's suggestion of pushing the "into regs" logic into `emitPrimOp`. With the previous commit getting rid of the recursion in `genericIntMul2Op`, this is now an easy refactor. - - - - - 6607f203 by John Ericson at 2020-07-07T13:56:00-04:00 `opAllDone` -> `opIntoRegs` The old name was and terrible and became worse after the previous commit's refactor moved non-trivial funcationlity into its body. - - - - - fdcc53ba by Sylvain Henry at 2020-07-07T13:56:00-04:00 Optimise genericIntMul2Op We shouldn't directly call 'genericWordMul2Op' in genericIntMul2Op because a target may provide a faster primop for 'WordMul2Op': we'd better use it! - - - - - 686e7225 by Moritz Angermann at 2020-07-07T13:56:01-04:00 [linker/rtsSymbols] More linker symbols Mostly symbols needed for aarch64/armv7l and in combination with musl, where we have to rely on loading *all* objects/archives - __stack_chk_* only when not DYNAMIC - - - - - 3f60b94d by Moritz Angermann at 2020-07-07T13:56:01-04:00 better if guards. - - - - - 7abffced by Moritz Angermann at 2020-07-07T13:56:01-04:00 Fix (1) - - - - - cdfeb3f2 by Moritz Angermann at 2020-07-07T13:56:01-04:00 AArch32 symbols only on aarch32. - - - - - f496c955 by Adam Sandberg Ericsson at 2020-07-07T13:56:02-04:00 add -flink-rts flag to link the rts when linking a shared or static library #18072 By default we don't link the RTS when linking shared libraries because in the most usual mode a shared library is an intermediary product, for example a Haskell library, that will be linked into some executable in the end. So we wish to defer the RTS flavour to link to the final link. However sometimes the final product is the shared library, for example when writing a plugin for some other system, so we do wish the shared library to link the RTS. For consistency we also make -staticlib honor this flag and its inversion. -staticlib currently implies -flink-shared. - - - - - c59faf67 by Stefan Schulze Frielinghaus at 2020-07-07T13:56:04-04:00 hadrian: link check-ppr against debugging RTS if ghcDebugged - - - - - 0effc57d by Adam Sandberg Ericsson at 2020-07-07T13:56:05-04:00 rts linker: teach the linker about GLIBC's special handling of *stat, mknod and atexit functions #7072 - - - - - 96153433 by Adam Sandberg Ericsson at 2020-07-07T13:56:06-04:00 hadrian: make hadrian/ghci use the bootstrap compiler from configure #18190 - - - - - 4d24f886 by Adam Sandberg Ericsson at 2020-07-07T13:56:07-04:00 hadrian: ignore cabal configure verbosity related flags #18131 - - - - - 7332bbff by Ben Gamari at 2020-07-07T13:56:08-04:00 testsuite: Widen T12234 acceptance window to 2% Previously it wasn't uncommon to see +/-1% fluctuations in compiler allocations on this test. - - - - - 180b6313 by Gabor Greif at 2020-07-07T13:56:08-04:00 When running libtool, report it as such - - - - - d3bd6897 by Sylvain Henry at 2020-07-07T13:56:11-04:00 BigNum: rename BigNat types Before this patch BigNat names were confusing because we had: * GHC.Num.BigNat.BigNat: unlifted type used everywhere else * GHC.Num.BigNat.BigNatW: lifted type only used to share static constants * GHC.Natural.BigNat: lifted type only used for backward compatibility After this patch we have: * GHC.Num.BigNat.BigNat#: unlifted type * GHC.Num.BigNat.BigNat: lifted type (reexported from GHC.Natural) Thanks to @RyanGlScott for spotting this. - - - - - 929d26db by Sylvain Henry at 2020-07-07T13:56:12-04:00 Bignum: don't build ghc-bignum with stage0 Noticed by @Ericson2314 - - - - - d25b6851 by Sylvain Henry at 2020-07-07T13:56:12-04:00 Hadrian: ghc-gmp.h shouldn't be a compiler dependency - - - - - 0ddae2ba by Sylvain Henry at 2020-07-07T13:56:14-04:00 DynFlags: factor out pprUnitId from "Outputable UnitId" instance - - - - - 204f3f5d by Krzysztof Gogolewski at 2020-07-07T13:56:18-04:00 Remove unused function pprHsForAllExtra (#18423) The function `pprHsForAllExtra` was called only on `Nothing` since 2015 (1e041b7382b6aa). - - - - - 3033e0e4 by Adam Sandberg Ericsson at 2020-07-08T20:36:49-04:00 hadrian: add flag to skip rebuilding dependency information #17636 - - - - - b7de4b96 by Stefan Schulze Frielinghaus at 2020-07-09T09:49:22-04:00 Fix GHCi :print on big-endian platforms On big-endian platforms executing import GHC.Exts data Foo = Foo Float# deriving Show foo = Foo 42.0# foo :print foo results in an arithmetic overflow exception which is caused by function index where moveBytes equals word_size - (r + item_size_b) * 8 Here we have a mixture of units. Both, word_size and item_size_b have unit bytes whereas r has unit bits. On 64-bit platforms moveBytes equals then 8 - (0 + 4) * 8 which results in a negative and therefore invalid second parameter for a shiftL operation. In order to make things more clear the expression (word .&. (mask `shiftL` moveBytes)) `shiftR` moveBytes is equivalent to (word `shiftR` moveBytes) .&. mask On big-endian platforms the shift must be a left shift instead of a right shift. For symmetry reasons not a mask is used but two shifts in order to zero out bits. Thus the fixed version equals case endian of BigEndian -> (word `shiftL` moveBits) `shiftR` zeroOutBits `shiftL` zeroOutBits LittleEndian -> (word `shiftR` moveBits) `shiftL` zeroOutBits `shiftR` zeroOutBits Fixes #16548 and #14455 - - - - - 3656dff8 by Sylvain Henry at 2020-07-09T09:50:01-04:00 LLVM: fix MO_S_Mul2 support (#18434) The value indicating if the carry is useful wasn't taken into account. - - - - - d9f09506 by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Define multiShotIO and use it in mkSplitUniqueSupply This patch is part of the ongoing eta-expansion saga; see #18238. It implements a neat trick (suggested by Sebastian Graf) that allows the programmer to disable the default one-shot behaviour of IO (the "state hack"). The trick is to use a new multiShotIO function; see Note [multiShotIO]. For now, multiShotIO is defined here in Unique.Supply; but it should ultimately be moved to the IO library. The change is necessary to get good code for GHC's unique supply; see Note [Optimising the unique supply]. However it makes no difference to GHC as-is. Rather, it makes a difference when a subsequent commit Improve eta-expansion using ArityType lands. - - - - - bce695cc by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Make arityType deal with join points As Note [Eta-expansion and join points] describes, this patch makes arityType deal correctly with join points. What was there before was not wrong, but yielded lower arities than it could. Fixes #18328 In base GHC this makes no difference to nofib. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- n-body -0.1% -0.1% -1.2% -1.1% 0.0% -------------------------------------------------------------------------------- Min -0.1% -0.1% -55.0% -56.5% 0.0% Max -0.0% 0.0% +16.1% +13.4% 0.0% Geometric Mean -0.0% -0.0% -30.1% -31.0% -0.0% But it starts to make real difference when we land the change to the way mkDupableAlts handles StrictArg, in fixing #13253 and friends. I think this is because we then get more non-inlined join points. - - - - - 2b7c71cb by Simon Peyton Jones at 2020-07-11T12:17:02-04:00 Improve eta-expansion using ArityType As #18355 shows, we were failing to preserve one-shot info when eta-expanding. It's rather easy to fix, by using ArityType more, rather than just Arity. This patch is important to suport the one-shot monad trick; see #18202. But the extra tracking of one-shot-ness requires the patch Define multiShotIO and use it in mkSplitUniqueSupply If that patch is missing, ths patch makes things worse in GHC.Types.Uniq.Supply. With it, however, we see these improvements T3064 compiler bytes allocated -2.2% T3294 compiler bytes allocated -1.3% T12707 compiler bytes allocated -1.3% T13056 compiler bytes allocated -2.2% Metric Decrease: T3064 T3294 T12707 T13056 - - - - - de139cc4 by Artem Pelenitsyn at 2020-07-12T02:53:20-04:00 add reproducer for #15630 - - - - - c4de6a7a by Andreas Klebinger at 2020-07-12T02:53:55-04:00 Give Uniq[D]FM a phantom type for its key. This fixes #17667 and should help to avoid such issues going forward. The changes are mostly mechanical in nature. With two notable exceptions. * The register allocator. The register allocator references registers by distinct uniques. However they come from the types of VirtualReg, Reg or Unique in various places. As a result we sometimes cast the key type of the map and use functions which operate on the now typed map but take a raw Unique as actual key. The logic itself has not changed it just becomes obvious where we do so now. * <Type>Env Modules. As an example a ClassEnv is currently queried using the types `Class`, `Name`, and `TyCon`. This is safe since for a distinct class value all these expressions give the same unique. getUnique cls getUnique (classTyCon cls) getUnique (className cls) getUnique (tcName $ classTyCon cls) This is for the most part contained within the modules defining the interface. However it requires us to play dirty when we are given a `Name` to lookup in a `UniqFM Class a` map. But again the logic did not change and it's for the most part hidden behind the Env Module. Some of these cases could be avoided by refactoring but this is left for future work. We also bump the haddock submodule as it uses UniqFM. - - - - - c2cfdfde by Aaron Allen at 2020-07-13T09:00:33-04:00 Warn about empty Char enumerations (#18402) Currently the "Enumeration is empty" warning (-Wempty-enumerations) only fires for numeric literals. This patch adds support for `Char` literals so that enumerating an empty list of `Char`s will also trigger the warning. - - - - - c3ac87ec by Stefan Schulze Frielinghaus at 2020-07-13T09:01:10-04:00 hadrian: build check-ppr dynamic if GHC is build dynamic Fixes #18361 - - - - - 9ad072b4 by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Use dumpStyle when printing inlinings This just makes debug-printing consistent, and more informative. - - - - - e78c4efb by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Comments only - - - - - 7ccb760b by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Reduce result discount in conSize Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c - - - - - 7f0b671e by Ben Gamari at 2020-07-13T14:52:49-04:00 testsuite: Widen acceptance threshold on T5837 This test is positively tiny and consequently the bytes allocated measurement will be relatively noisy. Consequently I have seen this fail spuriously quite often. - - - - - 118e1c3d by Alp Mestanogullari at 2020-07-14T21:30:52-04:00 compiler: re-engineer the treatment of rebindable if Executing on the plan described in #17582, this patch changes the way if expressions are handled in the compiler in the presence of rebindable syntax. We get rid of the SyntaxExpr field of HsIf and instead, when rebindable syntax is on, we rewrite the HsIf node to the appropriate sequence of applications of the local `ifThenElse` function. In order to be able to report good error messages, with expressions as they were written by the user (and not as desugared by the renamer), we make use of TTG extensions to extend GhcRn expression ASTs with an `HsExpansion` construct, which keeps track of a source (GhcPs) expression and the desugared (GhcRn) expression that it gives rise to. This way, we can typecheck the latter while reporting the former in error messages. In order to discard the error context lines that arise from typechecking the desugared expressions (because they talk about expressions that the user has not written), we carefully give a special treatment to the nodes fabricated by this new renaming-time transformation when typechecking them. See Note [Rebindable syntax and HsExpansion] for more details. The note also includes a recipe to apply the same treatment to other rebindable constructs. Tests 'rebindable11' and 'rebindable12' have been added to make sure we report identical error messages as before this patch under various circumstances. We also now disable rebindable syntax when processing untyped TH quotes, as per the discussion in #18102 and document the interaction of rebindable syntax and Template Haskell, both in Note [Template Haskell quotes and Rebindable Syntax] and in the user guide, adding a test to make sure that we do not regress in that regard. - - - - - 64c774b0 by Andreas Klebinger at 2020-07-14T21:31:27-04:00 Explain why keeping DynFlags in AnalEnv saves allocation. - - - - - 254245d0 by Ben Gamari at 2020-07-14T21:32:03-04:00 docs/users-guide: Update default -funfolding-use-threshold value This was changed in 3d2991f8 but I neglected to update the documentation. Fixes #18419. - - - - - 4c259f86 by Andreas Klebinger at 2020-07-14T21:32:41-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. - - - - - 23797224 by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 .gitlab: re-enable integer-simple substitute (BIGNUM_BACKEND) Recently build system migrated from INTEGER_LIBRARY to BIGNUM_BACKEND. But gitlab CI was never updated. Let's enable BIGNUM_BACKEND=native. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - e0db878a by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 ghc-bignum: bring in sync .hs-boot files with module declarations Before this change `BIGNUM_BACKEND=native` build was failing as: ``` libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs:708:16: error: * Variable not in scope: naturalFromBigNat# :: WordArray# -> t * Perhaps you meant one of these: `naturalFromBigNat' (imported from GHC.Num.Natural), `naturalToBigNat' (imported from GHC.Num.Natural) | 708 | m' = naturalFromBigNat# m | ``` This happens because `.hs-boot` files are slightly out of date. This change brings in data and function types in sync. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - c9f65c36 by Stefan Schulze Frielinghaus at 2020-07-14T21:33:57-04:00 rts/Disassembler.c: Use FMT_HexWord for printing values in hex format - - - - - 58ae62eb by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 macOS: Load frameworks without stating them first. macOS Big Sur makes the following change to how frameworks are shipped with the OS: > New in macOS Big Sur 11 beta, the system ships with a built-in > dynamic linker cache of all system-provided libraries. As part of > this change, copies of dynamic libraries are no longer present on > the filesystem. Code that attempts to check for dynamic library > presence by looking for a file at a path or enumerating a directory > will fail. Instead, check for library presence by attempting to > dlopen() the path, which will correctly check for the library in the > cache. (62986286) https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/ Therefore, the previous method of checking whether a library exists before attempting to load it makes GHC.Runtime.Linker.loadFramework fail to find frameworks installed at /System/Library/Frameworks. GHC.Runtime.Linker.loadFramework now opportunistically loads the framework libraries without checking for their existence first, failing only if all attempts to load a given framework from any of the various possible locations fail. - - - - - cdc4a6b0 by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 loadFramework: Output the errors collected in all loading attempts. With the recent change away from first finding and then loading a framework, loadFramework had no way of communicating the real reason why loadDLL failed if it was any reason other than the framework missing from the file system. It now collects all loading attempt errors into a list and concatenates them into a string to return to the caller. - - - - - 51dbfa52 by Ben Gamari at 2020-07-15T04:05:34-04:00 StgToCmm: Use CmmRegOff smart constructor Previously we would generate expressions of the form `CmmRegOff BaseReg 0`. This should do no harm (and really should be handled by the NCG anyways) but it's better to just generate a plain `CmmReg`. - - - - - ae11bdfd by Ben Gamari at 2020-07-15T04:06:08-04:00 testsuite: Add regression test for #17744 Test due to @monoidal. - - - - - 0e3c277a by Ben Gamari at 2020-07-15T16:41:01-04:00 Bump Cabal submodule Updates a variety of tests as Cabal is now more strict about Cabal file form. - - - - - ceed994a by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Drop Windows Vista support, require Windows 7 - - - - - 00a23bfd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Update Windows FileSystem wrapper utilities. - - - - - 459e1c5f by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Use SlimReaderLocks and ConditonalVariables provided by the OS instead of emulated ones - - - - - 763088fc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Small linker comment and ifdef cleanups - - - - - 1a228ff9 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Flush event logs eagerly. - - - - - e9e04dda by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Refactor Buffer structures to be able to track async operations - - - - - 356dc3fe by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Implement new Console API - - - - - 90e69f77 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add IOPort synchronization primitive - - - - - 71245fcc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add new io-manager cmdline options - - - - - d548a3b3 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Init Windows console Codepage to UTF-8. - - - - - 58ef6366 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add unsafeSplat to GHC.Event.Array - - - - - d660725e by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add size and iterate to GHC.Event.IntTable. - - - - - 050da6dd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Switch Testsuite to test winio by default - - - - - 4bf542bf by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Multiple refactorings and support changes. - - - - - 4489af6b by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core threaded I/O manager - - - - - 64d8f2fe by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core non-threaded I/O manager - - - - - 8da15a09 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix a scheduler bug with the threaded-runtime. - - - - - 84ea3d14 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Relaxing some constraints in io-manager. - - - - - ccf0d107 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix issues with non-threaded I/O manager after split. - - - - - b492fe6e by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Remove some barf statements that are a bit strict. - - - - - 01423fd2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Expand comments describing non-threaded loop - - - - - 4b69004f by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: fix FileSize unstat-able handles - - - - - 9b384270 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Implement new tempfile routines for winio - - - - - f1e0be82 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix input truncation when reading from handle. This was caused by not upholding the read buffer invariant that bufR == bufL == 0 for empty read buffers. - - - - - e176b625 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix output truncation for writes larger than buffer size - - - - - a831ce0e by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Rewrite bufWrite. I think it's far easier to follow the code now. It's also correct now as I had still missed a spot where we didn't update the offset. - - - - - 6aefdf62 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix offset set by bufReadEmpty. bufReadEmpty returns the bytes read *including* content that was already buffered, But for calculating the offset we only care about the number of bytes read into the new buffer. - - - - - 750ebaee by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Clean up code surrounding IOPort primitives. According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc. - - - - - ffd31db9 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix multi threaded threadDelay and a few other small changes. Multithreaded threadDelay suffered from a race condition based on the ioManagerStatus. Since the status isn't needed for WIO I removed it completely. This resulted in a light refactoring, as consequence we will always wake up the IO manager using interruptSystemManager, which uses `postQueuedCompletionStatus` internally. I also added a few comments which hopefully makes the code easier to dive into for the next person diving in. - - - - - 6ec26df2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 wionio: Make IO subsystem check a no-op on non-windows platforms. - - - - - 29bcd936 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Set handle offset when opening files in Append mode. Otherwise we would truncate the file. - - - - - 55c29700 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Remove debug event log trace - - - - - 9acb9f40 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix sqrt and openFile009 test cases - - - - - 57017cb7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Allow hp2ps to build with -DDEBUG - - - - - b8cd9995 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update output of T9681 since we now actually run it. - - - - - 10af5b14 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: A few more improvements to the IOPort primitives. - - - - - 39afc4a7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix expected tempfiles output. Tempfiles now works properly on windows, as such we can delete the win32 specific output. - - - - - 99db46e0 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Assign thread labels to IOManager threads. - - - - - be6af732 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Properly check for the tso of an incall to be zero. - - - - - e2c6dac7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark FD instances as unsupported under WINIO. - - - - - fd02ceed by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix threadDelay maxBound invocations. Instead of letting the ns timer overflow now clamp it at (maxBound :: Word64) ns. That still gives a few hundred years. - - - - - bc79f9f1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comments/cleanup an import in base - - - - - 1d197f4b by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark outstanding_service_requests volatile. As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration. - - - - - dc438186 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Make last_event a local variable - - - - - 2fc957c5 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comment about thread safety of processCompletion. - - - - - 4c026b6c by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: nonthreaded: Create io processing threads in main thread. We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread. - - - - - f47c7208 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add an exported isHeapAlloced function to the RTS - - - - - cc5d7bb1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Queue IO processing threads at the front of the queue. This will unblock the IO thread sooner hopefully leading to higher throughput in some situations. - - - - - e7630115 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: ThreadDelay001: Use higher resolution timer. - - - - - 451b5f96 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update T9681 output, disable T4808 on windows. T4808 tests functionality of the FD interface which won't be supported under WINIO. T9681 just has it's expected output tweaked. - - - - - dd06f930 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Wake io manager once per registerTimeout. Which is implicitly done in editTimeouts, so need to wake it up twice. - - - - - e87d0bf9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update placeholder comment with actual function name. - - - - - fc9025db by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Always lock win32 event queue - - - - - c24c9a1f by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Display thread labels when tracing scheduler events. - - - - - 06542b03 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Refactor non-threaded runner thread and scheduler interface. Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event. - - - - - 256299b1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove outstanding_requests from runner. We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port. - - - - - 3ebd8ad9 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Various fixes related to rebase and testdriver - - - - - 6be6bcba by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Fix rebase artifacts - - - - - 2c649dc3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename unsafeSplat to unsafeCopyFromBuffer - - - - - a18b73f3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove unused size/iterate operations from IntTable - - - - - 16bab48e by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Detect running IO Backend via peeking at RtsConfig - - - - - 8b8405a0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update temp path so GCC etc can handle it. Also fix PIPE support, clean up error casting, fix memory leaks - - - - - 2092bc54 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Minor comments/renamings - - - - - a5b5b6c0 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Checking if an error code indicates completion is now a function. - - - - - 362176fd by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Small refactor in withOverlappedEx - - - - - 32e20597 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: A few comments and commented out dbxIO - - - - - a4bfc1d9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't drop buffer offset in byteView/cwcharView - - - - - b3ad2a54 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: revert BHandle changes. - - - - - 3dcd87e2 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Fix imports - - - - - 5a371890 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update ghc-cabal to handle new Cabal submodule bump - - - - - d07ebe0d by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Only compile sources on Windows - - - - - dcb42393 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Actually return Nothing on EOF for non-blocking read - - - - - 895a3beb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate logic in encodeMultiByte[Raw]IO. - - - - - e06e6734 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate openFile logic - - - - - b59430c0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: fix -werror issue in encoding file - - - - - f8d39a51 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't mention windows specific functions when building on Linux. - - - - - 6a533d2a by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add a note about file locking in the RTS. - - - - - cf37ce34 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Add version to @since annotation - - - - - 0fafa2eb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename GHC.Conc.IOCP -> GHC.Conc.WinIO - - - - - 1854fc23 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Expand GHC.Conc.POSIX description It now explains users may not use these functions when using the old IO manager. - - - - - fcc7ba41 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Fix potential spaceleak in __createUUIDTempFileErrNo - - - - - 6b3fd9fa by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant -Wno-missing-signatures pragmas - - - - - 916fc861 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Make it explicit that we only create one IO manager - - - - - f260a721 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Note why we don't use blocking waits. - - - - - aa0a4bbf by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove commented out pragma - - - - - d679b544 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant buffer write in Handle/Text.hs:bufReadEmpty - - - - - d3f94368 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename SmartHandles to StdHandles - - - - - bd6b8ec1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add comment stating failure behaviour for getUniqueFileInfo. - - - - - 12846b85 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update IOPort haddocks. - - - - - 9f39fb14 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Add a note cross reference - - - - - 62dd5a73 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Name Haskell/OS I/O Manager explicitly in Note - - - - - fa807828 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Expand BlockedOnIOCompletion description. - - - - - f0880a1d by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove historical todos - - - - - 8e58e714 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Update note, remove debugging pragma. - - - - - aa4d84d5 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: flushCharReadBuffer shouldn't need to adjust offsets. - - - - - e580893a by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove obsolete comment about cond. variables - - - - - d54e9d79 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix initial linux validate build - - - - - 3cd4de46 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix ThreadDelay001 CPP - - - - - c88b1b9f by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix openFile009 merge conflict leftover - - - - - 849e8889 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept T9681 output. GHC now reports String instead of [Char]. - - - - - e7701818 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix cabal006 after upgrading cabal submodule Demand cabal 2.0 syntax instead of >= 1.20 as required by newer cabal versions. - - - - - a44f0373 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix stderr output for ghci/linking/dyn tests. We used to filter rtsopts, i opted to instead just accept the warning of it having no effect. This works both for -rtsopts, as well as -with-rtsopts which winio adds. - - - - - 515d9896 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T15261b stdout for --io-manager flag. - - - - - 949aaacc by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T5435_dyn_asm stderr The warning about rtsopts having no consequences is expected. So accept new stderr. - - - - - 7d424e1e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Also accept T7037 stderr - - - - - 1f009768 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal04 by filtering rts args - - - - - 981a9f2e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal01 by accepting expected stderr - - - - - b7b0464e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix safePkg01 by accepting expected stderr - - - - - 32734b29 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix T5435_dyn_gcc by accepting expected stderr - - - - - acc5cebf by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix tempfiles test on linux - - - - - c577b789 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for T3807 - - - - - c108c527 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload - - - - - 2b0b9a08 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload_multiple_objs - - - - - 67afb03c by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify wording on conditional variables. - - - - - 3bd41572 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify comment on cooked mode. - - - - - ded58a03 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: update lockfile signature and remove mistaken symbol in rts. - - - - - 2143c492 by Ben Gamari at 2020-07-15T16:41:04-04:00 testsuite: Add winio and winio_threaded ways Reverts many of the testsuite changes - - - - - c0979cc5 by Ben Gamari at 2020-07-16T10:56:54-04:00 Merge remote-tracking branch 'origin/wip/winio' - - - - - 750a1595 by Ben Gamari at 2020-07-18T07:26:41-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. - - - - - 6ba6a881 by Hécate at 2020-07-18T07:26:42-04:00 Implement `fullCompilerVersion` Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403 This MR adds `fullCompilerVersion`, a function that shares the same backend as the `--numeric-version` GHC flag, exposing a full, three-digit version datatype. - - - - - e6cf27df by Hécate at 2020-07-18T07:26:43-04:00 Add a Lint hadrian rule and an .hlint.yaml file in base/ - - - - - bcb177dd by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Allow multiple case branches to have a higher rank type As #18412 points out, it should be OK for multiple case alternatives to have a higher rank type, provided they are all the same. This patch implements that change. It sweeps away GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it with an enhanced version of fillInferResult. The basic change to fillInferResult is to permit the case in which another case alternative has already filled in the result; and in that case simply unify. It's very simple actually. See the new Note [fillInferResult] in TcMType Other refactoring: - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType (previously some of it was in Unify) - Move tcInstType and friends from TcMType to Instantiate, where it more properly belongs. (TCMType was getting very long.) - - - - - e5525a51 by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Improve typechecking of NPlusK patterns This patch (due to Richard Eisenberg) improves documentation of the wrapper returned by tcSubMult (see Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify). And, more substantially, it cleans up the multiplicity handling in the typechecking of NPlusKPat - - - - - 12f90352 by Krzysztof Gogolewski at 2020-07-18T07:26:45-04:00 Remove {-# CORE #-} pragma (part of #18048) This pragma has no effect since 2011. It was introduced for External Core, which no longer exists. Updates haddock submodule. - - - - - e504c913 by Simon Peyton Jones at 2020-07-18T07:26:45-04:00 Refactor the simplification of join binders This MR (for #18449) refactors the Simplifier's treatment of join-point binders. Specifically, it puts together, into GHC.Core.Opt.Simplify.Env.adjustJoinPointType two currently-separate ways in which we adjust the type of a join point. As the comment says: -- (adjustJoinPointType mult new_res_ty join_id) does two things: -- -- 1. Set the return type of the join_id to new_res_ty -- See Note [Return type for join points] -- -- 2. Adjust the multiplicity of arrows in join_id's type, as -- directed by 'mult'. See Note [Scaling join point arguments] I think this actually fixes a latent bug, by ensuring that the seIdSubst and seInScope have the right multiplicity on the type of join points. I did some tidying up while I was at it. No more setJoinResTy, or modifyJoinResTy: instead it's done locally in Simplify.Env.adjustJoinPointType - - - - - 49b265f0 by Chaitanya Koparkar at 2020-07-18T07:26:46-04:00 Fix minor typos in a Core.hs note - - - - - 8d59aed6 by Stefan Schulze Frielinghaus at 2020-07-18T07:26:47-04:00 GHCi: Fix isLittleEndian - - - - - c26e81d1 by Ben Gamari at 2020-07-18T07:26:47-04:00 testsuite: Mark ghci tests as fragile under unreg compiler In particular I have seen T16012 fail repeatedly under the unregisterised compiler. - - - - - 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 638ef490 by Ben Gamari at 2020-08-09T19:32:25-04:00 nonmoving: Clarify length of MarkQueueBlock and other comment issues - - - - - 8d0fb721 by Ben Gamari at 2020-08-09T19:33:52-04:00 nonmoving: Eliminate redundant information from MarkQueue Previously we kept a pointer to both the bdescr of the MarkQueueBlock at the head of the queue and the MarkQueueBlock itself. This is unnecessary. - - - - - 198cadde by Ben Gamari at 2020-08-09T19:34:44-04:00 nonmoving: Decouple UpdRemSet from MarkQueue This is in preparation for parallel marking. - - - - - 7268ee5c by Ben Gamari at 2020-08-09T19:34:44-04:00 More - - - - - 91bad2de by Ben Gamari at 2020-08-09T19:38:01-04:00 Rename updateRemembSetPushClosureRegs - - - - - 911028f8 by Ben Gamari at 2020-08-09T19:48:15-04:00 MarkContext refactoring - - - - - e559f307 by Ben Gamari at 2020-08-09T19:48:16-04:00 Fix it - - - - - 5a486f98 by Ben Gamari at 2020-08-10T15:03:00-04:00 Fix it - - - - - 0264b720 by Ben Gamari at 2020-08-10T15:06:07-04:00 Make gc_alloc_block_spin a proper Mutex - - - - - c89e4f41 by Ben Gamari at 2020-08-10T15:23:45-04:00 Assert SM lock is held in freeGroup - - - - - 16 changed files: - .ghcid - + .git-ignore-revs - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/linters/check-cpp.py - .gitlab/merge_request_templates/merge-request.md - .gitlab/test-metrics.sh - .gitmodules - CODEOWNERS - HACKING.md - Makefile - aclocal.m4 - boot - + compiler/GHC.hs - + compiler/GHC/Builtin/Names.hs - + compiler/GHC/Builtin/Names/TH.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f5d5ae2c1f3010e603bed7289cfd7fcec95c313c...c89e4f413ea274a9f2574605669f369f1c0d77eb -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f5d5ae2c1f3010e603bed7289cfd7fcec95c313c...c89e4f413ea274a9f2574605669f369f1c0d77eb You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 19:56:09 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 15:56:09 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18560 Message-ID: <5f31a659e878c_80b3f846910c0c074960e7@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T18560 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18560 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 22:33:41 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Mon, 10 Aug 2020 18:33:41 -0400 Subject: [Git][ghc/ghc][wip/az/ghc-9.0-anns] ApiAnnotations: Fix parser for new GHC 9.0 features Message-ID: <5f31cb4563b6_80b3f849c1caa107514659@gitlab.haskell.org.mail> Alan Zimmerman pushed to branch wip/az/ghc-9.0-anns at Glasgow Haskell Compiler / GHC Commits: d88bc94a by Alan Zimmerman at 2020-08-10T23:32:26+01:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 1 changed file: - compiler/GHC/Parser.y Changes: ===================================== compiler/GHC/Parser.y ===================================== @@ -1961,7 +1961,7 @@ type :: { LHsType GhcPs } | btype '#->' ctype {% hintLinear (getLoc $2) >> ams (sLL $1 $> $ HsFunTy noExtField HsLinearArrow $1 $3) - [mu AnnRarrow $2] } + [mu AnnLolly $2] } mult :: { LHsType GhcPs } : btype { $1 } @@ -2080,10 +2080,10 @@ tv_bndrs :: { [LHsTyVarBndr Specificity GhcPs] } tv_bndr :: { LHsTyVarBndr Specificity GhcPs } : tv_bndr_no_braces { $1 } | '{' tyvar '}' {% ams (sLL $1 $> (UserTyVar noExtField InferredSpec $2)) - [mop $1, mcp $3] } + [moc $1, mcc $3] } | '{' tyvar '::' kind '}' {% ams (sLL $1 $> (KindedTyVar noExtField InferredSpec $2 $4)) - [mop $1,mu AnnDcolon $3 - ,mcp $5] } + [moc $1,mu AnnDcolon $3 + ,mcc $5] } tv_bndr_no_braces :: { LHsTyVarBndr Specificity GhcPs } : tyvar { sL1 $1 (UserTyVar noExtField SpecifiedSpec $1) } @@ -3717,6 +3717,7 @@ isUnicode (L _ (ITcparenbar iu)) = iu == UnicodeSyntax isUnicode (L _ (ITopenExpQuote _ iu)) = iu == UnicodeSyntax isUnicode (L _ (ITcloseQuote iu)) = iu == UnicodeSyntax isUnicode (L _ (ITstar iu)) = iu == UnicodeSyntax +isUnicode (L _ (ITlolly iu)) = iu == UnicodeSyntax isUnicode _ = False hasE :: Located Token -> Bool View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d88bc94affafe24c3af7cb5f1fe095d1b9e676bf -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d88bc94affafe24c3af7cb5f1fe095d1b9e676bf You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 10 23:03:25 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 19:03:25 -0400 Subject: [Git][ghc/ghc][wip/gc/parallel-marking] Fix it Message-ID: <5f31d23d56a61_80b3f848a372f8c75196ab@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/gc/parallel-marking at Glasgow Haskell Compiler / GHC Commits: 71e9f4e6 by GHC GitLab CI at 2020-08-10T22:43:04+00:00 Fix it - - - - - 1 changed file: - rts/sm/NonMovingMark.c Changes: ===================================== rts/sm/NonMovingMark.c ===================================== @@ -337,7 +337,7 @@ upd_rem_set_push(UpdRemSet *rs, MarkQueueEnt *ent) ACQUIRE_SM_LOCK; nonmovingAddUpdRemSetBlocks(rs); bdescr *bd = allocGroup(MARK_QUEUE_BLOCKS); - bd->link = markQueueBlockBdescr(rs->block); + bd->link = NULL; rs->block = (MarkQueueBlock *) bd->start; rs->block->head = 0; RELEASE_SM_LOCK; @@ -390,10 +390,10 @@ STATIC_INLINE void push(struct MarkContext *mc, MarkQueueEnt *ent) { mark_queue_push(mc->in_conc_mark.queue, ent); break; case MARK_CTX_IN_MOVING_GC: - upd_rem_set_push(mc->in_moving_gc.rset, ent); + upd_rem_set_push_gc(mc->in_moving_gc.rset, ent); break; case MARK_CTX_IN_MUTATOR: - upd_rem_set_push_gc(mc->in_mutator.rset, ent); + upd_rem_set_push(mc->in_mutator.rset, ent); break; } } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/71e9f4e67b6a97dbc33edca22e9ad5c94b7a44b1 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/71e9f4e67b6a97dbc33edca22e9ad5c94b7a44b1 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 11 00:23:34 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Mon, 10 Aug 2020 20:23:34 -0400 Subject: [Git][ghc/ghc][master] 2 commits: Correct a typo in ghc.mk Message-ID: <5f31e5066efa2_80b3f8496224a707540120@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - 1 changed file: - utils/ghc-pkg/ghc.mk Changes: ===================================== utils/ghc-pkg/ghc.mk ===================================== @@ -61,8 +61,8 @@ endif $(eval $(call build-prog,utils/ghc-pkg,dist,0)) # ghc-pkg uses `settings` to figure out the target platform to figure out a -# subdirectory for the user pkg db. So make sure `settings` exists (alterative -# is to specify global package db only. +# subdirectory for the user pkg db. So make sure `settings` exists (alternative +# is to specify global package db only). $(ghc-pkg_INPLACE) : | $(INPLACE_PACKAGE_CONF)/. $(INPLACE_LIB)/settings # ----------------------------------------------------------------------------- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/77398b678aba45ba25932a39b7e8a7a31d0dd6f3...1c4692641dcaca3e90116c28d012c506108b386f -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/77398b678aba45ba25932a39b7e8a7a31d0dd6f3...1c4692641dcaca3e90116c28d012c506108b386f You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 11 00:24:14 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Mon, 10 Aug 2020 20:24:14 -0400 Subject: [Git][ghc/ghc][master] Make splitAtList strict in its arguments Message-ID: <5f31e52e475bc_80b3f848a386fc875435f6@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - 1 changed file: - compiler/GHC/Utils/Misc.hs Changes: ===================================== compiler/GHC/Utils/Misc.hs ===================================== @@ -6,6 +6,7 @@ {-# LANGUAGE BangPatterns #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE MagicHash #-} {-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} @@ -774,15 +775,18 @@ dropList _ xs@[] = xs dropList (_:xs) (_:ys) = dropList xs ys --- | Given two lists xs=x0..xn and ys=y0..ym, return `splitAt n ys`. +-- | Given two lists xs and ys, return `splitAt (length xs) ys`. splitAtList :: [b] -> [a] -> ([a], [a]) -splitAtList xs ys = go 0 xs ys +splitAtList xs ys = go 0# xs ys where -- we are careful to avoid allocating when there are no leftover -- arguments: in this case we can return "ys" directly (cf #18535) - go _ _ [] = (ys, []) -- len(ys) <= len(xs) - go n [] bs = (take n ys, bs) -- = splitAt n ys - go n (_:as) (_:bs) = go (n+1) as bs + -- + -- We make `xs` strict because in the general case `ys` isn't `[]` so we + -- will have to evaluate `xs` anyway. + go _ !_ [] = (ys, []) -- length ys <= length xs + go n [] bs = (take (I# n) ys, bs) -- = splitAt n ys + go n (_:as) (_:bs) = go (n +# 1#) as bs -- drop from the end of a list dropTail :: Int -> [a] -> [a] View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/acf537f9fefa31883b7cb28ff61b837ab7f8a44a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/acf537f9fefa31883b7cb28ff61b837ab7f8a44a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 11 02:20:17 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 22:20:17 -0400 Subject: [Git][ghc/ghc][wip/gc/parallel-marking] 120 commits: Fix dead link to haskell prime discussion Message-ID: <5f3200614f4a1_80b3f8468e02b547548983@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/gc/parallel-marking at Glasgow Haskell Compiler / GHC Commits: 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 7467d9e8 by Ben Gamari at 2020-08-10T19:06:59-04:00 nonmoving: Clarify length of MarkQueueBlock and other comment issues - - - - - 93df47f7 by Ben Gamari at 2020-08-10T19:06:59-04:00 nonmoving: Eliminate redundant information from MarkQueue Previously we kept a pointer to both the bdescr of the MarkQueueBlock at the head of the queue and the MarkQueueBlock itself. This is unnecessary. - - - - - 61bb5b64 by Ben Gamari at 2020-08-10T19:06:59-04:00 nonmoving: Decouple UpdRemSet from MarkQueue This is in preparation for parallel marking. - - - - - b43a21f9 by Ben Gamari at 2020-08-10T19:06:59-04:00 More - - - - - 83cef0c7 by Ben Gamari at 2020-08-10T19:07:00-04:00 Rename updateRemembSetPushClosureRegs - - - - - 2b97a280 by Ben Gamari at 2020-08-10T19:07:00-04:00 MarkContext refactoring - - - - - d9a3ce97 by Ben Gamari at 2020-08-10T20:44:42-04:00 Drop dead field - - - - - 8c435776 by Ben Gamari at 2020-08-10T22:20:04-04:00 nonmoving: Parallel marking? - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/test-metrics.sh - CODEOWNERS - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/Graph.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Monad.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Switch/Implement.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/Config.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/71e9f4e67b6a97dbc33edca22e9ad5c94b7a44b1...8c435776910cc68e30dbd890e8b2251353b63ce1 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/71e9f4e67b6a97dbc33edca22e9ad5c94b7a44b1...8c435776910cc68e30dbd890e8b2251353b63ce1 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 11 02:25:29 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 10 Aug 2020 22:25:29 -0400 Subject: [Git][ghc/ghc][wip/gc/parallel-marking] nonmoving: Parallel marking? Message-ID: <5f320199968d0_80b3f848c1e06f475491b9@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/gc/parallel-marking at Glasgow Haskell Compiler / GHC Commits: cfd77aba by Ben Gamari at 2020-08-10T22:25:22-04:00 nonmoving: Parallel marking? - - - - - 3 changed files: - rts/sm/NonMoving.c - rts/sm/NonMovingMark.c - rts/sm/NonMovingMark.h Changes: ===================================== rts/sm/NonMoving.c ===================================== @@ -714,6 +714,7 @@ void nonmovingInit(void) nonmovingHeap.allocators[i] = alloc_nonmoving_allocator(n_capabilities); } nonmovingMarkInitUpdRemSet(); + nonmovingInitMarkState(); } // Stop any nonmoving collection in preparation for RTS shutdown. @@ -915,9 +916,9 @@ void nonmovingCollect(StgWeak **dead_weaks, StgTSO **resurrected_threads) ASSERT(nonmoving_marked_compact_objects == NULL); ASSERT(n_nonmoving_marked_compact_blocks == 0); - MarkQueue *mark_queue = stgMallocBytes(sizeof(MarkQueue), "mark queue"); - initMarkQueue(mark_queue); - current_mark_queue = mark_queue; + // First initialize a MarkQueue for the leader thread: + startMarkThreads(1); + MarkQueue *mark_queue = mark_state.queues[0]; // Mark roots trace(TRACE_nonmoving_gc, "Marking roots for nonmoving GC"); @@ -981,6 +982,8 @@ void nonmovingCollect(StgWeak **dead_weaks, StgTSO **resurrected_threads) nonmovingConcurrentMark, mark_queue) != 0) { barf("nonmovingCollect: failed to spawn mark thread: %s", strerror(errno)); } + // Start the mark worker threads... + startMarkThreads(3); } else { nonmovingConcurrentMark(mark_queue); } @@ -998,7 +1001,7 @@ static void nonmovingMarkThreadsWeaks(MarkQueue *mark_queue) { while (true) { // Propagate marks - nonmovingMark(mark_queue); + nonmovingMarkLeader(); // Tidy threads and weaks nonmovingTidyThreads(); @@ -1102,7 +1105,7 @@ static void nonmovingMark_(MarkQueue *mark_queue, StgWeak **dead_weaks, StgTSO * // Do last marking of weak pointers while (true) { // Propagate marks - nonmovingMark(mark_queue); + nonmovingMarkLeader(); if (!nonmovingTidyWeaks(mark_queue)) break; @@ -1176,9 +1179,8 @@ static void nonmovingMark_(MarkQueue *mark_queue, StgWeak **dead_weaks, StgTSO * nonmovingFinishFlush(task); #endif - current_mark_queue = NULL; - freeMarkQueue(mark_queue); - stgFree(mark_queue); + // tear down the mark threads' state + stopMarkThreads(); oldest_gen->live_estimate = nonmoving_live_words; oldest_gen->n_old_blocks = 0; ===================================== rts/sm/NonMovingMark.c ===================================== @@ -24,6 +24,7 @@ #include "Stats.h" #include "STM.h" #include "MarkWeak.h" +#include "RtsUtils.h" #include "sm/Storage.h" #include "CNF.h" @@ -117,6 +118,8 @@ StgWeak *nonmoving_weak_ptr_list = NULL; StgIndStatic *debug_caf_list_snapshot = (StgIndStatic*)END_OF_CAF_LIST; #endif +struct MarkState mark_state; + /* Note [Update remembered set] * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * The concurrent non-moving collector uses a remembered set to ensure @@ -365,7 +368,6 @@ upd_rem_set_push_gc(UpdRemSet *rs, MarkQueueEnt *ent) markQueueBlockPush(rs->block, ent); } - STATIC_INLINE void mark_queue_push (MarkQueue *q, const MarkQueueEnt *ent) { @@ -375,7 +377,15 @@ mark_queue_push (MarkQueue *q, const MarkQueueEnt *ent) // Allocate a fresh block. ACQUIRE_SM_LOCK; bdescr *bd = allocGroup(MARK_QUEUE_BLOCKS); - bd->link = markQueueBlockBdescr(q->top); + + // First try pushing onto local deque... + if (q->rest != NULL && pushWSDeque(q->rest, q->top)) { + bd->link = NULL; + } else { + // deque overflowed. link onto the new block's list. + bd->link = markQueueBlockBdescr(q->top); + } + q->top = (MarkQueueBlock *) bd->start; q->top->head = 0; RELEASE_SM_LOCK; @@ -386,7 +396,7 @@ mark_queue_push (MarkQueue *q, const MarkQueueEnt *ent) STATIC_INLINE void push(struct MarkContext *mc, MarkQueueEnt *ent) { switch (mc->kind) { - case MARK_CTX_IN_CONC_MARK: + case MARK_CTX_IN_CONC_MARK: mark_queue_push(mc->in_conc_mark.queue, ent); break; case MARK_CTX_IN_MOVING_GC: @@ -410,7 +420,7 @@ void nonmovingMarkInitUpdRemSet() { #if defined(THREADED_RTS) && defined(DEBUG) static uint32_t markQueueLength(MarkQueue *q); #endif -static void init_mark_queue_(MarkQueue *queue); +static void init_mark_queue(MarkQueue *queue); /* Transfers the given capability's update-remembered set to the global * remembered set. Must hold SM lock/allocation spinlock. @@ -875,6 +885,17 @@ void markQueueAddRoot (MarkQueue* q, StgClosure** root) * Popping from the mark queue *********************************************************/ +static MarkQueueBlock *try_stealing(void) +{ + for (uint32_t i = 0; i < mark_state.n_mark_threads; i++) { + MarkQueueBlock *b = (MarkQueueBlock *) stealWSDeque(mark_state.queues[i]->rest); + if (b != NULL) { + return b; + } + } + return NULL; +} + // Returns invalid MarkQueueEnt if queue is empty. static MarkQueueEnt markQueuePop_ (MarkQueue *q) { @@ -887,19 +908,41 @@ again: if (top->head == 0) { bdescr *old_block = markQueueBlockBdescr(q->top); // Is this the only block in the queue? - if (old_block->link == NULL) { - // Yes, therefore queue is empty... - MarkQueueEnt none = { .null_entry = { .p = NULL } }; - return none; - } else { + if (old_block->link != NULL) { // No, unwind to the previous block and try popping again... bdescr *new_block = old_block->link; q->top = (MarkQueueBlock*) new_block->start; ACQUIRE_SM_LOCK; - freeGroup(old_block); // TODO: hold on to a block to avoid repeated allocation/deallocation? + freeGroup(old_block); + // TODO: hold on to a block to avoid repeated allocation/deallocation? RELEASE_SM_LOCK; goto again; } + + // Yes, this is the only block therefore queue is empty... + // Next we try pulling from our own deque... + MarkQueueBlock *new = (MarkQueueBlock *) popWSDeque(q->rest); + if (new != NULL) { + q->top = new; + ACQUIRE_SM_LOCK; + freeGroup(old_block); + RELEASE_SM_LOCK; + goto again; + } + + // Our deque is also empty... + // Now try pulling from other threads deques... + new = try_stealing(); + if (new != NULL) { + q->top = new; + ACQUIRE_SM_LOCK; + freeGroup(old_block); + RELEASE_SM_LOCK; + goto again; + } + + const MarkQueueEnt none = { .null_entry = { .p = NULL } }; + return none; } top->head--; @@ -961,23 +1004,20 @@ void init_upd_rem_set (UpdRemSet *queue) } /* Must hold sm_mutex. */ -static void init_mark_queue_ (MarkQueue *queue) +static void init_mark_queue (MarkQueue *queue) { bdescr *bd = allocGroup(MARK_QUEUE_BLOCKS); queue->top = (MarkQueueBlock *) bd->start; queue->top->head = 0; + queue->rest = newWSDeque(MARK_QUEUE_DEQUE_SIZE); + queue->mark_thread_n = -1; + queue->thread_id = -1; #if MARK_PREFETCH_QUEUE_DEPTH > 0 memset(&queue->prefetch_queue, 0, sizeof(queue->prefetch_queue)); queue->prefetch_head = 0; #endif } -/* Must hold sm_mutex. */ -void initMarkQueue (MarkQueue *queue) -{ - init_mark_queue_(queue); -} - void reset_upd_rem_set (UpdRemSet *rset) { // UpdRemSets always have one block for the mark queue. This assertion is to @@ -986,7 +1026,8 @@ void reset_upd_rem_set (UpdRemSet *rset) rset->block->head = 0; } -void freeMarkQueue (MarkQueue *queue) +static void +freeMarkQueue (MarkQueue *queue) { freeChain_lock(markQueueBlockBdescr(queue->top)); } @@ -1759,8 +1800,8 @@ done: * c. the mark queue has been seeded with a set of roots. * */ -GNUC_ATTR_HOT void -nonmovingMark (MarkQueue *queue) +static GNUC_ATTR_HOT void +nonmovingMarkLoop (MarkQueue *queue) { struct MarkContext mctx = markContextInConcMark(queue); traceConcMarkBegin(); @@ -1793,17 +1834,17 @@ nonmovingMark (MarkQueue *queue) case NULL_ENTRY: // Perhaps the update remembered set has more to mark... if (upd_rem_set_block_list) { - ACQUIRE_LOCK(&upd_rem_set_lock); + ACQUIRE_SM_LOCK; bdescr *old = markQueueBlockBdescr(queue->top); + freeGroup(old); + RELEASE_SM_LOCK; + + ACQUIRE_LOCK(&upd_rem_set_lock); queue->top = (MarkQueueBlock *) upd_rem_set_block_list->start; upd_rem_set_block_list = NULL; RELEASE_LOCK(&upd_rem_set_lock); - - ACQUIRE_SM_LOCK; - freeGroup(old); - RELEASE_SM_LOCK; } else { - // Nothing more to do + // We are out of work... debugTrace(DEBUG_nonmoving_gc, "Finished mark pass: %d", count); traceConcMarkEnd(count); return; @@ -1812,6 +1853,112 @@ nonmovingMark (MarkQueue *queue) } } +/* + * This is the mark loop run by the leader thread (mark_thread_n == 0). It + * kicks the worker threads, starts marking itself, and waits until everyone + * finishes. + */ +void +nonmovingMarkLeader () +{ + broadcastCondition(&mark_state.new_work_cond); + nonmovingMarkLoop(mark_state.queues[0]); + + ACQUIRE_LOCK(&mark_state.lock); + while (mark_state.active_mark_threads > 0) { + waitCondition(&mark_state.phase_done_cond, &mark_state.lock); + } + RELEASE_LOCK(&mark_state.lock); +} + +/* + * This is the loop run by the worker threads. + */ +static void * +nonmoving_mark_worker (void *user) +{ + MarkQueue *queue = (MarkQueue *) user; + const uint32_t mark_thread_n = queue->mark_thread_n; + + ACQUIRE_LOCK(&mark_state.lock); + while (mark_thread_n > mark_state.n_mark_threads - 1) { + RELEASE_LOCK(&mark_state.lock); + nonmovingMarkLoop(queue); + ACQUIRE_LOCK(&mark_state.lock); + + mark_state.active_mark_threads --; + if (mark_state.active_mark_threads == 0) { + signalCondition(&mark_state.phase_done_cond); + } + if (mark_thread_n != 0) { + waitCondition(&mark_state.new_work_cond, &mark_state.lock); + } + } + return NULL; +} + +void +nonmovingInitMarkState() +{ + initMutex(&mark_state.lock); + initCondition(&mark_state.phase_done_cond); + initCondition(&mark_state.new_work_cond); + mark_state.n_mark_threads = 0; + mark_state.active_mark_threads = 0; +} + +void +startMarkThreads(int n_mark_threads) +{ + ACQUIRE_LOCK(&mark_state.lock); + ASSERT(mark_state.n_mark_threads == 0); + ASSERT(n_mark_threads >= 1); + + MarkQueue **old_queues = mark_state.queues; + mark_state.queues = stgMallocBytes(sizeof(MarkQueue*) * n_mark_threads, "startMarkThreads"); + if (old_queues != NULL) { + memcpy(mark_state.queues, old_queues, sizeof(MarkQueue*) * mark_state.n_mark_threads); + stgFree(old_queues); + } + + for (int i = mark_state.n_mark_threads; i < n_mark_threads; i++) { + MarkQueue *q = stgMallocBytes(sizeof(MarkQueue*), "startMarkThreads"); + mark_state.queues[i] = q; + init_mark_queue(q); + + q->mark_thread_n = i; + mark_state.active_mark_threads ++; + mark_state.n_mark_threads ++; + + // N.B. mark thread 0 runs in the context of the main mark thread. + if (i > 0) { + int res = createOSThread(&q->thread_id, "concurrent mark thread", nonmoving_mark_worker, q); + if (res != 0) { + barf("startMarkThreads"); + } + } + } + RELEASE_LOCK(&mark_state.lock); +} + +void +stopMarkThreads() +{ + ACQUIRE_LOCK(&mark_state.lock); + // ensure that there are no active threads since we will be freeing + // the MarkQueues shortly. + ASSERT(mark_state.active_mark_threads == 0); + mark_state.n_mark_threads = 0; + broadcastCondition(&mark_state.new_work_cond); + + for (uint32_t i = 0; i < mark_state.n_mark_threads; i++) { + freeMarkQueue(mark_state.queues[i]); + } + stgFree(mark_state.queues); + mark_state.queues = NULL; + RELEASE_LOCK(&mark_state.lock); +} + // A variant of `isAlive` that works for non-moving heap. Used for: // // - Collecting weak pointers; checking key of a weak pointer. ===================================== rts/sm/NonMovingMark.h ===================================== @@ -10,6 +10,7 @@ #include "Task.h" #include "NonMoving.h" +#include "WSDeque.h" #include "BeginPrivate.h" @@ -101,6 +102,9 @@ INLINE_HEADER bdescr *markQueueBlockBdescr(MarkQueueBlock *b) // How far ahead in mark queue to prefetch? #define MARK_PREFETCH_QUEUE_DEPTH 5 +// How many blocks to keep on the deque? +#define MARK_QUEUE_DEQUE_SIZE 32 + /* The mark queue is not capable of concurrent read or write. * * invariants: @@ -115,6 +119,12 @@ typedef struct MarkQueue_ { // Bdescr(q->top)->link->start MarkQueueBlock *top; + // A WSDeque of MarkQueueBlock*s which mark threads can steal from. When + // the deque overflows we link blocks onto Bdescr(top)->link. + WSDeque *rest; + + int mark_thread_n; + OSThreadId thread_id; #if MARK_PREFETCH_QUEUE_DEPTH > 0 // A ring-buffer of entries which we will mark next @@ -124,6 +134,25 @@ typedef struct MarkQueue_ { #endif } MarkQueue; +struct MarkState { + // protects active_mark_threads and n_mark_threads. + Mutex lock; + // signalled when all marking threads have finished a round of marking. + Condition phase_done_cond; + // signalled to wake up marking threads for a new round of marking + // (or terminate if .n_mark_threads > thread.mark_thread_n). + Condition new_work_cond; + // how many threads are currently marking? + uint32_t active_mark_threads; + // how many threads have been created? + // this is currently static throughout marking. + uint32_t n_mark_threads; + // an array of MarkQueue*s, one per mark thread + MarkQueue **queues; +}; + +extern struct MarkState mark_state; + /* The update remembered set. * * invariants: @@ -173,9 +202,10 @@ void nonmovingFinishFlush(Task *task); void markQueueAddRoot(MarkQueue* q, StgClosure** root); -void initMarkQueue(MarkQueue *queue); -void freeMarkQueue(MarkQueue *queue); -void nonmovingMark(struct MarkQueue_ *restrict queue); +void startMarkThreads(int n_mark_threads); +void stopMarkThreads(void); +void nonmovingInitMarkState(void); +void nonmovingMarkLeader(void); bool nonmovingTidyWeaks(struct MarkQueue_ *queue); void nonmovingTidyThreads(void); View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cfd77aba805f8bc8e81a39a4f3b67ea8b2c23ea4 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cfd77aba805f8bc8e81a39a4f3b67ea8b2c23ea4 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 11 08:18:36 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Tue, 11 Aug 2020 04:18:36 -0400 Subject: [Git][ghc/ghc][wip/T18126] 2 commits: Implement Quick Look impredicativity Message-ID: <5f32545c6bb2e_80b3f848a386fc875579df@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18126 at Glasgow Haskell Compiler / GHC Commits: df22930c by Simon Peyton Jones at 2020-08-11T09:18:10+01:00 Implement Quick Look impredicativity This patch implements Quick Look impredicativity (#18126), sticking very closely to the design in A quick look at impredicativity, Serrano et al, ICFP 2020 The main change is that a big chunk of GHC.Tc.Gen.Expr has been extracted to two new modules GHC.Tc.Gen.App GHC.Tc.Gen.Head which deal with typechecking n-ary applications, and the head of such applications, respectively. Both contain a good deal of documentation. Three other loosely-related changes are in this patch: * I implemented (partly by accident) point (2) of the accepted GHC proposal "Clean up printing of foralls", namely https://github.com/ghc-proposals/ghc-proposals/blob/ master/proposals/0179-printing-foralls.rst In particular, see Note [TcRnExprMode] in GHC.Tc.Module - :type instantiates /inferred/, but not /specified/, quantifiers - :type +d instantiates /all/ quantifiers - :type +v is killed off * HsRecFld (which the renamer introduces for record field selectors), is now preserved by the typechecker, rather than being rewritten back to HsVar. This is more uniform, and turned out to be more convenient in the new scheme of things. * The GHCi debugger uses a non-standard unification that allows the unification variables to unify with polytypes. We used to hack this by using ImpredicativeTypes, but that doesn't work anymore so I introduces RuntimeUnkTv. See Note [RuntimeUnkTv] in GHC.Runtime.Heap.Inspect WARNING: this patch won't validate on its own. It was too hard to fully disentangle it from the following patch, on type errors and kind generalisation. Changes to tests * Fixes #9730 (test added) * Fixes #7026 (test added) * Fixes most of #8808, except function `g2'` which uses a section (which doesn't play with QL yet -- see #18126) Test added * Fixes #1330. NB Church1.hs subsumes Church2.hs, which is now deleted * Fixes #17332 (test added) * Fixes #4295 * This patch makes typecheck/should_run/T7861 fail. But that turns out to be a pre-existing bug: #18467. So I have just made T7861 into expect_broken(18467) - - - - - 0b2e16b2 by Simon Peyton Jones at 2020-08-11T09:18:10+01:00 Improve kind generalisation, error messages This patch does two things: * It refactors GHC.Tc.Errors a bit. In debugging Quick Look I was forced to look in detail at error messages, and ended up doing a bit of refactoring, esp in mkTyVarEqErr'. It's still quite a mess, but a bit better, I think. * It makes a significant improvement to the kind checking of type and class declarations. Specifically, we now ensure that if kind checking fails with an unsolved constraint, all the skolems are in scope. That wasn't the case before, which led to some obscure error messages; and occasional failures with "no skolem info" (eg #16245). Both of these, and the main Quick Look patch itself, affect a /lot/ of error messages, as you can see from the number of files changed. I've checked them all; I think they are as good or better than before. Smaller things * I documented the various instances of VarBndr better. See Note [The VarBndr tyep and its uses] in GHC.Types.Var * Renamed GHC.Tc.Solver.simpl_top to simplifyTopWanteds * A bit of refactoring in bindExplicitTKTele, to avoid the footwork with Either. Simpler now. * Move promoteTyVar from GHC.Tc.Solver to GHC.Tc.Utils.TcMType Fixes #16245 (comment 211369), memorialised as typeecheck/polykinds/T16245a - - - - - 18 changed files: - compiler/GHC/Core/TyCon.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/HsToCore/Coverage.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Rename/Pat.hs - compiler/GHC/Runtime/Eval.hs - compiler/GHC/Runtime/Heap/Inspect.hs - compiler/GHC/Tc/Deriv/Generate.hs - compiler/GHC/Tc/Errors.hs - compiler/GHC/Tc/Errors/Hole.hs - + compiler/GHC/Tc/Gen/App.hs - compiler/GHC/Tc/Gen/Arrow.hs - compiler/GHC/Tc/Gen/Default.hs - compiler/GHC/Tc/Gen/Expr.hs - compiler/GHC/Tc/Gen/Expr.hs-boot The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/675d82ebe58d14ad567ec41a5d66237faebee559...0b2e16b2bafa4cb386f61a287bf00a972d4cec51 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/675d82ebe58d14ad567ec41a5d66237faebee559...0b2e16b2bafa4cb386f61a287bf00a972d4cec51 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 11 10:36:27 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Tue, 11 Aug 2020 06:36:27 -0400 Subject: [Git][ghc/ghc][wip/T8095-spj] 38 commits: hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. Message-ID: <5f3274ab27d0d_80b3f8496224a7075854d6@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T8095-spj at Glasgow Haskell Compiler / GHC Commits: 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - 170d5f0b by Simon Peyton Jones at 2020-08-11T11:35:54+01:00 Zap coercions (take 2) This is Simon's take on coercion zapping. The basic approach remains the same: add a UnivProv for a zapped coercion, controlled by -ddrop-coercions. Particular features: * A zapped coercion is born in one place only: in GHC.Tc.Utils.Zonk, when zonking a coercion. By that time all coercion holes are filled in, so there is no issue about looking for free holes. * Flattening and solving are unaffected. They'll allocate coercions -- but my plan (not yet brought to fruition) is that they are never traversed when we have -ddrop-coercions * There will, therefore, be no perf gain in the type checker; but the entire rest of the compiler will benefit. - - - - - dda74075 by Simon Peyton Jones at 2020-08-11T11:35:54+01:00 CI adjustments This patch temporarily * Marks -ddump-coercions as undocumented (so that CI doesn't stumble) * Adds -ddump-coercions to TEST_HC so that all tests run with it on - - - - - 67ef75dc by Simon Peyton Jones at 2020-08-11T11:35:54+01:00 Free-var fixes This should stop the perf regressions - - - - - a7ff3a30 by Simon Peyton Jones at 2020-08-11T11:35:54+01:00 Simplify TyCoFolder This commit removes the 'env' part of TyCoFolder. A nice simplification! - - - - - 229c908f by Simon Peyton Jones at 2020-08-11T11:35:54+01:00 Tidy up and documentation Notes - - - - - f255f49b by Simon Peyton Jones at 2020-08-11T11:35:55+01:00 Two perf wibbles - - - - - dd4b25f1 by Simon Peyton Jones at 2020-08-11T11:35:55+01:00 Further wibbles - - - - - 30 changed files: - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/Coercion/Opt.hs - compiler/GHC/Core/FVs.hs - compiler/GHC/Core/Lint.hs - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/TyCo/FVs.hs - compiler/GHC/Core/TyCo/Ppr.hs - compiler/GHC/Core/TyCo/Rep.hs - compiler/GHC/Core/TyCo/Subst.hs - compiler/GHC/Core/TyCo/Tidy.hs - compiler/GHC/Core/Type.hs - compiler/GHC/Core/Unify.hs - compiler/GHC/CoreToIface.hs - compiler/GHC/Driver/CodeOutput.hs - compiler/GHC/Driver/Flags.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Expr.hs-boot - compiler/GHC/HsToCore/ListComp.hs - compiler/GHC/HsToCore/Utils.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d35f1fefd24846dee79a6572c6b957309814d3fd...dd4b25f1d6d6b990769098d07b047f70b3fd48a4 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d35f1fefd24846dee79a6572c6b957309814d3fd...dd4b25f1d6d6b990769098d07b047f70b3fd48a4 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 11 14:06:16 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 11 Aug 2020 10:06:16 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T16916 Message-ID: <5f32a5d84747e_80b3f8468e02b5475957ad@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T16916 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T16916 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 11 14:27:49 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 11 Aug 2020 10:27:49 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 7 commits: Correct a typo in ghc.mk Message-ID: <5f32aae51c657_80b3f8486220de076016ec@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - 4fbe929d by Ben Gamari at 2020-08-11T10:27:44-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - d9845759 by Ben Gamari at 2020-08-11T10:27:44-04:00 testsuite: Add test for #18118 - - - - - 83c40ee9 by Sven Tennie at 2020-08-11T10:27:44-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - 14575e70 by Ben Gamari at 2020-08-11T10:27:44-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - 8 changed files: - compiler/GHC/Tc/Gen/Sig.hs - compiler/GHC/Utils/Misc.hs - + libraries/ghc-heap/hie.yaml - testsuite/tests/perf/compiler/all.T - + testsuite/tests/typecheck/should_compile/T18118.hs - + testsuite/tests/typecheck/should_compile/T18118A.hs - testsuite/tests/typecheck/should_compile/all.T - utils/ghc-pkg/ghc.mk Changes: ===================================== compiler/GHC/Tc/Gen/Sig.hs ===================================== @@ -826,9 +826,13 @@ tcImpPrags prags tcImpSpec :: (Name, Sig GhcRn) -> TcM [TcSpecPrag] tcImpSpec (name, prag) = do { id <- tcLookupId name - ; unless (isAnyInlinePragma (idInlinePragma id)) - (addWarnTc NoReason (impSpecErr name)) - ; tcSpecPrag id prag } + ; if isAnyInlinePragma (idInlinePragma id) + then tcSpecPrag id prag + else do { addWarnTc NoReason (impSpecErr name) + ; return [] } } + -- If there is no INLINE/INLINABLE pragma there will be no unfolding. In + -- that case, just delete the SPECIALISE pragma altogether, lest the + -- desugarer fall over because it can't find the unfolding. See #18118. impSpecErr :: Name -> SDoc impSpecErr name ===================================== compiler/GHC/Utils/Misc.hs ===================================== @@ -6,6 +6,7 @@ {-# LANGUAGE BangPatterns #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE MagicHash #-} {-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} @@ -774,15 +775,18 @@ dropList _ xs@[] = xs dropList (_:xs) (_:ys) = dropList xs ys --- | Given two lists xs=x0..xn and ys=y0..ym, return `splitAt n ys`. +-- | Given two lists xs and ys, return `splitAt (length xs) ys`. splitAtList :: [b] -> [a] -> ([a], [a]) -splitAtList xs ys = go 0 xs ys +splitAtList xs ys = go 0# xs ys where -- we are careful to avoid allocating when there are no leftover -- arguments: in this case we can return "ys" directly (cf #18535) - go _ _ [] = (ys, []) -- len(ys) <= len(xs) - go n [] bs = (take n ys, bs) -- = splitAt n ys - go n (_:as) (_:bs) = go (n+1) as bs + -- + -- We make `xs` strict because in the general case `ys` isn't `[]` so we + -- will have to evaluate `xs` anyway. + go _ !_ [] = (ys, []) -- length ys <= length xs + go n [] bs = (take (I# n) ys, bs) -- = splitAt n ys + go n (_:as) (_:bs) = go (n +# 1#) as bs -- drop from the end of a list dropTail :: Int -> [a] -> [a] ===================================== libraries/ghc-heap/hie.yaml ===================================== @@ -0,0 +1,12 @@ +cradle: + multi: + - path: ./GHC/ + config: + cradle: + cabal: + component: 'lib:ghc-heap' + - path: ./tests + config: + cradle: + direct: + arguments: [] ===================================== testsuite/tests/perf/compiler/all.T ===================================== @@ -370,7 +370,7 @@ test('T16190', test('T16473', normal, makefile_test, ['T16473']) test('T17516', - [ collect_compiler_stats(), + [ collect_compiler_stats('bytes allocated', 5), extra_clean(['T17516A.hi', 'T17516A.o']) ], multimod_compile, ===================================== testsuite/tests/typecheck/should_compile/T18118.hs ===================================== @@ -0,0 +1,5 @@ +module T18118 (myfun) where + +import T18118A + +{-# SPECIALISE myfun :: Double #-} ===================================== testsuite/tests/typecheck/should_compile/T18118A.hs ===================================== @@ -0,0 +1,5 @@ +module T18118A where + +myfun :: a +myfun = undefined + ===================================== testsuite/tests/typecheck/should_compile/all.T ===================================== @@ -717,5 +717,6 @@ test('T17775-viewpats-a', normal, compile, ['']) test('T17775-viewpats-b', normal, compile_fail, ['']) test('T17775-viewpats-c', normal, compile_fail, ['']) test('T17775-viewpats-d', normal, compile_fail, ['']) +test('T18118', normal, multimod_compile, ['T18118', '-v0']) test('T18412', normal, compile, ['']) test('T18470', normal, compile, ['']) ===================================== utils/ghc-pkg/ghc.mk ===================================== @@ -61,8 +61,8 @@ endif $(eval $(call build-prog,utils/ghc-pkg,dist,0)) # ghc-pkg uses `settings` to figure out the target platform to figure out a -# subdirectory for the user pkg db. So make sure `settings` exists (alterative -# is to specify global package db only. +# subdirectory for the user pkg db. So make sure `settings` exists (alternative +# is to specify global package db only). $(ghc-pkg_INPLACE) : | $(INPLACE_PACKAGE_CONF)/. $(INPLACE_LIB)/settings # ----------------------------------------------------------------------------- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/01655ec5a1c858c3fa36e295a63e854b8acce184...14575e70224a5a0e6cacb58d0c9a69e17bbc2821 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/01655ec5a1c858c3fa36e295a63e854b8acce184...14575e70224a5a0e6cacb58d0c9a69e17bbc2821 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 11 14:27:59 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 11 Aug 2020 10:27:59 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/copyArray_barrier Message-ID: <5f32aaefb181e_80b3f848688539876068e6@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/copyArray_barrier at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/copyArray_barrier You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 11 15:22:16 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Tue, 11 Aug 2020 11:22:16 -0400 Subject: [Git][ghc/ghc][wip/T18126] Improve kind generalisation, error messages Message-ID: <5f32b7a8755b3_80b3f84693c1eb4762292f@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18126 at Glasgow Haskell Compiler / GHC Commits: 710aad27 by Simon Peyton Jones at 2020-08-11T16:21:54+01:00 Improve kind generalisation, error messages This patch does two things: * It refactors GHC.Tc.Errors a bit. In debugging Quick Look I was forced to look in detail at error messages, and ended up doing a bit of refactoring, esp in mkTyVarEqErr'. It's still quite a mess, but a bit better, I think. * It makes a significant improvement to the kind checking of type and class declarations. Specifically, we now ensure that if kind checking fails with an unsolved constraint, all the skolems are in scope. That wasn't the case before, which led to some obscure error messages; and occasional failures with "no skolem info" (eg #16245). Both of these, and the main Quick Look patch itself, affect a /lot/ of error messages, as you can see from the number of files changed. I've checked them all; I think they are as good or better than before. Smaller things * I documented the various instances of VarBndr better. See Note [The VarBndr tyep and its uses] in GHC.Types.Var * Renamed GHC.Tc.Solver.simpl_top to simplifyTopWanteds * A bit of refactoring in bindExplicitTKTele, to avoid the footwork with Either. Simpler now. * Move promoteTyVar from GHC.Tc.Solver to GHC.Tc.Utils.TcMType Fixes #16245 (comment 211369), memorialised as typeecheck/polykinds/T16245a - - - - - 30 changed files: - compiler/GHC/Core/TyCon.hs - compiler/GHC/Tc/Errors.hs - compiler/GHC/Tc/Errors/Hole.hs - compiler/GHC/Tc/Gen/Default.hs - compiler/GHC/Tc/Gen/HsType.hs - compiler/GHC/Tc/Gen/Sig.hs - compiler/GHC/Tc/Gen/Splice.hs - compiler/GHC/Tc/Module.hs - compiler/GHC/Tc/Solver.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Tc/TyCl/Instance.hs - compiler/GHC/Tc/Types/Evidence.hs - compiler/GHC/Tc/Utils/TcMType.hs - compiler/GHC/Types/Var.hs - docs/users_guide/9.0.1-notes.rst - docs/users_guide/exts/explicit_forall.rst - docs/users_guide/exts/instances.rst - docs/users_guide/ghci.rst - testsuite/tests/dependent/should_fail/T13780a.stderr - testsuite/tests/dependent/should_fail/T14066e.stderr - testsuite/tests/dependent/should_fail/T15859.hs - testsuite/tests/dependent/should_fail/T15859.stderr - + testsuite/tests/dependent/should_fail/T15859a.hs - + testsuite/tests/dependent/should_fail/T15859a.stderr - testsuite/tests/dependent/should_fail/T16344a.stderr - testsuite/tests/dependent/should_fail/all.T - testsuite/tests/gadt/T12468.stderr - testsuite/tests/gadt/gadt-escape1.stderr - testsuite/tests/gadt/gadt13.stderr - testsuite/tests/gadt/gadt7.stderr The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/710aad27519856b30a60f69bbf2910298e650166 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/710aad27519856b30a60f69bbf2910298e650166 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 11 17:22:40 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Tue, 11 Aug 2020 13:22:40 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/az/anns-3 Message-ID: <5f32d3e0f2b56_80b3f8487168730765829f@gitlab.haskell.org.mail> Alan Zimmerman pushed new branch wip/az/anns-3 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/az/anns-3 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 11 18:06:23 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Tue, 11 Aug 2020 14:06:23 -0400 Subject: [Git][ghc/ghc][wip/T18533] PmCheck: Better long-distance info for where bindings (#18533) Message-ID: <5f32de1fd8f05_80b3f8486298278767236b@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18533 at Glasgow Haskell Compiler / GHC Commits: 19e9c8e3 by Sebastian Graf at 2020-08-11T20:06:14+02:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - 9 changed files: - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/GuardedRHSs.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/Monad.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - + testsuite/tests/pmcheck/should_compile/T18533.hs - testsuite/tests/pmcheck/should_compile/all.T Changes: ===================================== compiler/GHC/HsToCore/Binds.hs ===================================== @@ -33,7 +33,7 @@ import {-# SOURCE #-} GHC.HsToCore.Match ( matchWrapper ) import GHC.HsToCore.Monad import GHC.HsToCore.GuardedRHSs import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck ( addTyCsDs, checkGuardMatches ) +import GHC.HsToCore.PmCheck ( addTyCsDs, checkGRHSs ) import GHC.Hs -- lots of things import GHC.Core -- lots of things @@ -76,7 +76,6 @@ import GHC.Types.Unique.Set( nonDetEltsUniqSet ) import GHC.Utils.Monad import qualified GHC.LanguageExtensions as LangExt import Control.Monad -import Data.List.NonEmpty ( nonEmpty ) {-********************************************************************** * * @@ -183,8 +182,8 @@ dsHsBind dflags b@(FunBind { fun_id = L loc fun dsHsBind dflags (PatBind { pat_lhs = pat, pat_rhs = grhss , pat_ext = NPatBindTc _ ty , pat_ticks = (rhs_tick, var_ticks) }) - = do { rhss_deltas <- checkGuardMatches PatBindGuards grhss - ; body_expr <- dsGuarded grhss ty (nonEmpty rhss_deltas) + = do { rhss_deltas <- checkGRHSs PatBindGuards grhss + ; body_expr <- dsGuarded grhss ty rhss_deltas ; let body' = mkOptTickBox rhs_tick body_expr pat' = decideBangHood dflags pat ; (force_var,sel_binds) <- mkSelectorBinds var_ticks pat body' ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -31,7 +31,7 @@ import GHC.HsToCore.ListComp import GHC.HsToCore.Utils import GHC.HsToCore.Arrows import GHC.HsToCore.Monad -import GHC.HsToCore.PmCheck ( addTyCsDs, checkGuardMatches ) +import GHC.HsToCore.PmCheck ( addTyCsDs, checkGRHSs ) import GHC.Types.Name import GHC.Types.Name.Env import GHC.Core.FamInstEnv( topNormaliseType ) @@ -69,7 +69,6 @@ import GHC.Utils.Outputable as Outputable import GHC.Core.PatSyn import Control.Monad -import Data.List.NonEmpty ( nonEmpty ) {- ************************************************************************ @@ -215,8 +214,8 @@ dsUnliftedBind (PatBind {pat_lhs = pat, pat_rhs = grhss , pat_ext = NPatBindTc _ ty }) body = -- let C x# y# = rhs in body -- ==> case rhs of C x# y# -> body - do { rhs_deltas <- checkGuardMatches PatBindGuards grhss - ; rhs <- dsGuarded grhss ty (nonEmpty rhs_deltas) + do { match_deltas <- checkGRHSs PatBindGuards grhss + ; rhs <- dsGuarded grhss ty match_deltas ; let upat = unLoc pat eqn = EqnInfo { eqn_pats = [upat], eqn_orig = FromSource, @@ -486,8 +485,8 @@ dsExpr (HsMultiIf res_ty alts) | otherwise = do { let grhss = GRHSs noExtField alts (noLoc emptyLocalBinds) - ; rhss_deltas <- checkGuardMatches IfAlt grhss - ; match_result <- dsGRHSs IfAlt grhss res_ty (nonEmpty rhss_deltas) + ; rhss_deltas <- checkGRHSs IfAlt grhss + ; match_result <- dsGRHSs IfAlt grhss res_ty rhss_deltas ; error_expr <- mkErrorExpr ; extractMatchResult match_result error_expr } where ===================================== compiler/GHC/HsToCore/GuardedRHSs.hs ===================================== @@ -25,7 +25,7 @@ import GHC.Core.Utils (bindNonRec) import GHC.HsToCore.Monad import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck.Types ( Deltas, initDeltas ) +import GHC.HsToCore.PmCheck.Types ( Deltas ) import GHC.Core.Type ( Type ) import GHC.Utils.Misc import GHC.Types.SrcLoc @@ -47,9 +47,9 @@ producing an expression with a runtime error in the corner if necessary. The type argument gives the type of the @ei at . -} -dsGuarded :: GRHSs GhcTc (LHsExpr GhcTc) -> Type -> Maybe (NonEmpty Deltas) -> DsM CoreExpr -dsGuarded grhss rhs_ty mb_rhss_deltas = do - match_result <- dsGRHSs PatBindRhs grhss rhs_ty mb_rhss_deltas +dsGuarded :: GRHSs GhcTc (LHsExpr GhcTc) -> Type -> NonEmpty Deltas -> DsM CoreExpr +dsGuarded grhss rhs_ty rhss_deltas = do + match_result <- dsGRHSs PatBindRhs grhss rhs_ty rhss_deltas error_expr <- mkErrorAppDs nON_EXHAUSTIVE_GUARDS_ERROR_ID rhs_ty empty extractMatchResult match_result error_expr @@ -58,25 +58,28 @@ dsGuarded grhss rhs_ty mb_rhss_deltas = do dsGRHSs :: HsMatchContext GhcRn -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ Guarded RHSs -> Type -- ^ Type of RHS - -> Maybe (NonEmpty Deltas) -- ^ Refined pattern match checking - -- models, one for each GRHS. Defaults - -- to 'initDeltas' if 'Nothing'. + -> NonEmpty Deltas -- ^ Refined pattern match checking + -- models, one for the pattern part and + -- one for each GRHS. -> DsM (MatchResult CoreExpr) -dsGRHSs hs_ctx (GRHSs _ grhss binds) rhs_ty mb_rhss_deltas +dsGRHSs hs_ctx (GRHSs _ grhss binds) rhs_ty rhss_deltas = ASSERT( notNull grhss ) - do { match_results <- case toList <$> mb_rhss_deltas of - Nothing -> mapM (dsGRHS hs_ctx rhs_ty initDeltas) grhss - Just rhss_deltas -> ASSERT( length grhss == length rhss_deltas ) - zipWithM (dsGRHS hs_ctx rhs_ty) rhss_deltas grhss - ; let match_result1 = foldr1 combineMatchResults match_results - match_result2 = adjustMatchResultDs (dsLocalBinds binds) match_result1 + do { match_results <- ASSERT( length grhss == length rhss_deltas ) + zipWithM (dsGRHS hs_ctx rhs_ty) (toList rhss_deltas) grhss + ; deltas <- getPmDeltas + -- We need to remember the Deltas from the particular match context we + -- are in, which might be different to when dsLocalBinds is actually + -- called. + ; let ds_binds = updPmDeltas deltas . dsLocalBinds binds + match_result1 = foldr1 combineMatchResults match_results + match_result2 = adjustMatchResultDs ds_binds match_result1 -- NB: nested dsLet inside matchResult ; return match_result2 } dsGRHS :: HsMatchContext GhcRn -> Type -> Deltas -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM (MatchResult CoreExpr) dsGRHS hs_ctx rhs_ty rhs_deltas (L _ (GRHS _ guards rhs)) - = updPmDeltas rhs_deltas (matchGuards (map unLoc guards) (PatGuard hs_ctx) rhs rhs_ty) + = matchGuards (map unLoc guards) (PatGuard hs_ctx) rhs_deltas rhs rhs_ty {- ************************************************************************ @@ -88,6 +91,7 @@ dsGRHS hs_ctx rhs_ty rhs_deltas (L _ (GRHS _ guards rhs)) matchGuards :: [GuardStmt GhcTc] -- Guard -> HsStmtContext GhcRn -- Context + -> Deltas -- The RHS's covered set for PmCheck -> LHsExpr GhcTc -- RHS -> Type -- Type of RHS of guard -> DsM (MatchResult CoreExpr) @@ -95,8 +99,8 @@ matchGuards :: [GuardStmt GhcTc] -- Guard -- See comments with HsExpr.Stmt re what a BodyStmt means -- Here we must be in a guard context (not do-expression, nor list-comp) -matchGuards [] _ rhs _ - = do { core_rhs <- dsLExpr rhs +matchGuards [] _ deltas rhs _ + = do { core_rhs <- updPmDeltas deltas (dsLExpr rhs) ; return (cantFailMatchResult core_rhs) } -- BodyStmts must be guards @@ -106,41 +110,41 @@ matchGuards [] _ rhs _ -- NB: The success of this clause depends on the typechecker not -- wrapping the 'otherwise' in empty HsTyApp or HsWrap constructors -- If it does, you'll get bogus overlap warnings -matchGuards (BodyStmt _ e _ _ : stmts) ctx rhs rhs_ty +matchGuards (BodyStmt _ e _ _ : stmts) ctx deltas rhs rhs_ty | Just addTicks <- isTrueLHsExpr e = do - match_result <- matchGuards stmts ctx rhs rhs_ty + match_result <- matchGuards stmts ctx deltas rhs rhs_ty return (adjustMatchResultDs addTicks match_result) -matchGuards (BodyStmt _ expr _ _ : stmts) ctx rhs rhs_ty = do - match_result <- matchGuards stmts ctx rhs rhs_ty +matchGuards (BodyStmt _ expr _ _ : stmts) ctx deltas rhs rhs_ty = do + match_result <- matchGuards stmts ctx deltas rhs rhs_ty pred_expr <- dsLExpr expr return (mkGuardedMatchResult pred_expr match_result) -matchGuards (LetStmt _ binds : stmts) ctx rhs rhs_ty = do - match_result <- matchGuards stmts ctx rhs rhs_ty +matchGuards (LetStmt _ binds : stmts) ctx deltas rhs rhs_ty = do + match_result <- matchGuards stmts ctx deltas rhs rhs_ty return (adjustMatchResultDs (dsLocalBinds binds) match_result) -- NB the dsLet occurs inside the match_result -- Reason: dsLet takes the body expression as its argument -- so we can't desugar the bindings without the -- body expression in hand -matchGuards (BindStmt _ pat bind_rhs : stmts) ctx rhs rhs_ty = do +matchGuards (BindStmt _ pat bind_rhs : stmts) ctx deltas rhs rhs_ty = do let upat = unLoc pat match_var <- selectMatchVar Many upat -- We only allow unrestricted patterns in guard, hence the `Many` -- above. It isn't clear what linear patterns would mean, maybe we will -- figure it out in the future. - match_result <- matchGuards stmts ctx rhs rhs_ty + match_result <- matchGuards stmts ctx deltas rhs rhs_ty core_rhs <- dsLExpr bind_rhs match_result' <- matchSinglePatVar match_var (StmtCtxt ctx) pat rhs_ty match_result pure $ bindNonRec match_var core_rhs <$> match_result' -matchGuards (LastStmt {} : _) _ _ _ = panic "matchGuards LastStmt" -matchGuards (ParStmt {} : _) _ _ _ = panic "matchGuards ParStmt" -matchGuards (TransStmt {} : _) _ _ _ = panic "matchGuards TransStmt" -matchGuards (RecStmt {} : _) _ _ _ = panic "matchGuards RecStmt" -matchGuards (ApplicativeStmt {} : _) _ _ _ = +matchGuards (LastStmt {} : _) _ _ _ _ = panic "matchGuards LastStmt" +matchGuards (ParStmt {} : _) _ _ _ _ = panic "matchGuards ParStmt" +matchGuards (TransStmt {} : _) _ _ _ _ = panic "matchGuards TransStmt" +matchGuards (RecStmt {} : _) _ _ _ _ = panic "matchGuards RecStmt" +matchGuards (ApplicativeStmt {} : _) _ _ _ _ = panic "matchGuards ApplicativeLastStmt" {- ===================================== compiler/GHC/HsToCore/Match.hs ===================================== @@ -35,6 +35,7 @@ import GHC.Tc.Utils.Zonk import GHC.Tc.Types.Evidence import GHC.Tc.Utils.Monad import GHC.HsToCore.PmCheck +import GHC.HsToCore.PmCheck.Types ( Deltas, initDeltas ) import GHC.Core import GHC.Types.Literal import GHC.Core.Utils @@ -64,7 +65,7 @@ import GHC.Data.FastString import GHC.Types.Unique import GHC.Types.Unique.DFM -import Control.Monad( unless ) +import Control.Monad(zipWithM, unless ) import Data.List.NonEmpty (NonEmpty(..)) import qualified Data.List.NonEmpty as NEL import qualified Data.Map as Map @@ -766,49 +767,46 @@ matchWrapper ctxt mb_scr (MG { mg_alts = L _ matches -- Pattern match check warnings for /this match-group/. -- @rhss_deltas@ is a flat list of covered Deltas for each RHS. -- Each Match will split off one Deltas for its RHSs from this. - ; rhss_deltas <- if isMatchContextPmChecked dflags origin ctxt + ; matches_deltas <- if isMatchContextPmChecked dflags origin ctxt then addScrutTmCs mb_scr new_vars $ - -- See Note [Type and Term Equality Propagation] - checkMatches (DsMatchContext ctxt locn) new_vars matches - else pure [] -- Ultimately this will result in passing Nothing - -- to dsGRHSs as match_deltas + -- See Note [Type and Term Equality Propagation] + checkMatches (DsMatchContext ctxt locn) new_vars matches + else pure (initDeltasMatches matches) - ; eqns_info <- mk_eqn_infos matches rhss_deltas + ; eqns_info <- zipWithM mk_eqn_info matches matches_deltas ; result_expr <- handleWarnings $ matchEquations ctxt new_vars eqns_info rhs_ty ; return (new_vars, result_expr) } where - -- rhss_deltas is a flat list, whereas there are multiple GRHSs per match. - -- mk_eqn_infos will thread rhss_deltas as state through calls to - -- mk_eqn_info, distributing each rhss_deltas to a GRHS. - mk_eqn_infos (L _ match : matches) rhss_deltas - = do { (info, rhss_deltas') <- mk_eqn_info match rhss_deltas - ; infos <- mk_eqn_infos matches rhss_deltas' - ; return (info:infos) } - mk_eqn_infos [] _ = return [] -- Called once per equation in the match, or alternative in the case - mk_eqn_info (Match { m_pats = pats, m_grhss = grhss }) rhss_deltas - | GRHSs _ grhss' _ <- grhss, let n_grhss = length grhss' + mk_eqn_info :: LMatch GhcTc (LHsExpr GhcTc) -> (Deltas, NonEmpty Deltas) -> DsM EquationInfo + mk_eqn_info (L _ (Match { m_pats = pats, m_grhss = grhss })) (pat_deltas, rhss_deltas) = do { dflags <- getDynFlags ; let upats = map (unLoc . decideBangHood dflags) pats - -- Split off one Deltas for each GRHS of the current Match from the - -- flat list of GRHS Deltas *for all matches* (see the call to - -- checkMatches above). - ; let (match_deltas, rhss_deltas') = splitAt n_grhss rhss_deltas - -- The list of Deltas is empty iff we don't perform any coverage - -- checking, in which case nonEmpty does the right thing by passing - -- Nothing. - ; match_result <- dsGRHSs ctxt grhss rhs_ty (NEL.nonEmpty match_deltas) - ; return ( EqnInfo { eqn_pats = upats - , eqn_orig = FromSource - , eqn_rhs = match_result } - , rhss_deltas' ) } + -- pat_deltas is the covered set *after* matching the pattern, but + -- before any of the GRHSs. It is the evidence that is visible in + -- the associated where clauses of the match. + ; match_result <- updPmDeltas pat_deltas $ + dsGRHSs ctxt grhss rhs_ty rhss_deltas + ; return EqnInfo { eqn_pats = upats + , eqn_orig = FromSource + , eqn_rhs = match_result } } handleWarnings = if isGenerated origin then discardWarningsDs else id + initDeltasMatches :: [LMatch GhcTc b] -> [(Deltas, NonEmpty Deltas)] + initDeltasMatches ms + = map (\(L _ m) -> (initDeltas, initDeltasGRHSs (m_grhss m))) ms + + initDeltasGRHSs :: GRHSs GhcTc b -> NonEmpty Deltas + initDeltasGRHSs m = expectJust "GRHSs non-empty" + $ NEL.nonEmpty + $ replicate (length (grhssGRHSs m)) initDeltas + + matchEquations :: HsMatchContext GhcRn -> [MatchId] -> [EquationInfo] -> Type -> DsM CoreExpr ===================================== compiler/GHC/HsToCore/Monad.hs ===================================== @@ -405,7 +405,7 @@ getPmDeltas = do { env <- getLclEnv; return (dsl_deltas env) } -- | Set the pattern match oracle state within the scope of the given action. -- See 'dsl_deltas'. updPmDeltas :: Deltas -> DsM a -> DsM a -updPmDeltas delta = updLclEnv (\env -> env { dsl_deltas = delta }) +updPmDeltas deltas = updLclEnv (\env -> env { dsl_deltas = deltas }) getSrcSpanDs :: DsM SrcSpan getSrcSpanDs = do { env <- getLclEnv ===================================== compiler/GHC/HsToCore/PmCheck.hs ===================================== @@ -13,7 +13,7 @@ Pattern Matching Coverage Checking. module GHC.HsToCore.PmCheck ( -- Checking and printing - checkSingle, checkMatches, checkGuardMatches, + checkSingle, checkMatches, checkGRHSs, isMatchContextPmChecked, -- See Note [Type and Term Equality Propagation] @@ -65,6 +65,7 @@ import GHC.Utils.Monad (concatMapM) import Control.Monad (when, forM_, zipWithM) import Data.List (elemIndex) import qualified Data.Semigroup as Semi +import Data.List.NonEmpty (NonEmpty(..)) {- This module checks pattern matches for: @@ -149,13 +150,11 @@ data GrdTree -- ^ @Guard grd t@ will try to match @grd@ and on success continue to match -- @t at . Falls through if either match fails. Models left-to-right semantics -- of pattern matching. - | Sequence !GrdTree !GrdTree - -- ^ @Sequence l r@ first matches against @l@, and then matches all - -- fallen-through values against @r at . Models top-to-bottom semantics of - -- pattern matching. - | Empty - -- ^ A @GrdTree@ that always fails. Most useful for - -- Note [Checking EmptyCase]. A neutral element to 'Sequence'. + | Sequence ![GrdTree] + -- ^ @Sequence (t:ts)@ matches against @t@, and then matches all + -- fallen-through values against @Sequence ts at . Models top-to-bottom semantics + -- of pattern matching. + -- @Sequence []@ always fails; it is useful for Note [Checking EmptyCase]. -- | The digest of 'checkGrdTree', representing the annotated pattern-match -- tree. 'redundantAndInaccessibleRhss' can figure out redundant and proper @@ -169,10 +168,10 @@ data AnnotatedTree | MayDiverge !AnnotatedTree -- ^ Asserts that the tree may force diverging values, so not all of its -- clauses can be redundant. - | SequenceAnn !AnnotatedTree !AnnotatedTree - -- ^ Mirrors 'Sequence' for preserving the skeleton of a 'GrdTree's. - | EmptyAnn - -- ^ Mirrors 'Empty' for preserving the skeleton of a 'GrdTree's. + | SequenceAnn !Deltas ![AnnotatedTree] + -- ^ @SequenceAnn inc ts@ mirrors @'Sequence' ts@ for preserving the + -- skeleton of a 'GrdTree's @ts at . It also carries the set of incoming values + -- @inc at . pprRhsInfo :: RhsInfo -> SDoc pprRhsInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) @@ -188,23 +187,15 @@ instance Outputable GrdTree where collect_grds t = (t, []) prefix [] = [] prefix (s:sdocs) = char '|' <+> s : map (comma <+>) sdocs - -- Format nested Sequences in blocks "{ grds1; grds2; ... }" - ppr t at Sequence{} = braces (space <> fsep (punctuate semi (collect_seqs t)) <> space) - where - collect_seqs (Sequence l r) = collect_seqs l ++ collect_seqs r - collect_seqs t = [ppr t] - ppr Empty = text "" + ppr (Sequence []) = text "" + ppr (Sequence ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) instance Outputable AnnotatedTree where - ppr (AccessibleRhs _ info) = pprRhsInfo info + ppr (AccessibleRhs _delta info) = parens (ppr _delta) <+> pprRhsInfo info ppr (InaccessibleRhs info) = text "inaccessible" <+> pprRhsInfo info ppr (MayDiverge t) = text "div" <+> ppr t - -- Format nested Sequences in blocks "{ grds1; grds2; ... }" - ppr t at SequenceAnn{} = braces (space <> fsep (punctuate semi (collect_seqs t)) <> space) - where - collect_seqs (SequenceAnn l r) = collect_seqs l ++ collect_seqs r - collect_seqs t = [ppr t] - ppr EmptyAnn = text "" + ppr (SequenceAnn _ []) = text "" + ppr (SequenceAnn _ ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) -- | Lift 'addPmCts' over 'Deltas'. addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas @@ -263,7 +254,7 @@ checkSingle dflags ctxt@(DsMatchContext kind locn) var p = do -- Omitting checking this flag emits redundancy warnings twice in obscure -- cases like #17646. when (exhaustive dflags kind) $ do - -- TODO: This could probably call checkMatches, like checkGuardMatches. + -- TODO: This could probably call checkMatches, like checkGRHSs. missing <- getPmDeltas tracePm "checkSingle: missing" (ppr missing) fam_insts <- dsGetFamInstEnvs @@ -273,12 +264,12 @@ checkSingle dflags ctxt@(DsMatchContext kind locn) var p = do -- | Exhaustive for guard matches, is used for guards in pattern bindings and -- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. -checkGuardMatches +checkGRHSs :: HsMatchContext GhcRn -- ^ Match context, for warning messages -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check - -> DsM [Deltas] -- ^ Covered 'Deltas' for each RHS, for long + -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long -- distance info -checkGuardMatches hs_ctx guards@(GRHSs _ grhss _) = do +checkGRHSs hs_ctx guards@(GRHSs _ grhss _) = do let combinedLoc = foldl1 combineSrcSpans (map getLoc grhss) dsMatchContext = DsMatchContext hs_ctx combinedLoc match = L combinedLoc $ @@ -286,7 +277,8 @@ checkGuardMatches hs_ctx guards@(GRHSs _ grhss _) = do , m_ctxt = hs_ctx , m_pats = [] , m_grhss = guards } - checkMatches dsMatchContext [] [match] + [(_, deltas)] <- checkMatches dsMatchContext [] [match] + pure deltas -- | Check a list of syntactic /match/es (part of case, functions, etc.), each -- with a /pat/ and one or more /grhss/: @@ -305,10 +297,9 @@ checkMatches :: DsMatchContext -- ^ Match context, for warnings messages -> [Id] -- ^ Match variables, i.e. x and y above -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches - -> DsM [Deltas] -- ^ One covered 'Deltas' per RHS, for long + -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per RHS, for long -- distance info. checkMatches ctxt vars matches = do - dflags <- getDynFlags tracePm "checkMatches" (hang (vcat [ppr ctxt , ppr vars , text "Matches:"]) @@ -321,25 +312,45 @@ checkMatches ctxt vars matches = do [] | [var] <- vars -> addPmCtDeltas init_deltas (PmNotBotCt var) _ -> pure init_deltas fam_insts <- dsGetFamInstEnvs - grd_tree <- mkGrdTreeMany [] <$> mapM (translateMatch fam_insts vars) matches + grd_tree <- translateMatches fam_insts vars matches res <- checkGrdTree grd_tree missing + dflags <- getDynFlags dsPmWarn dflags ctxt vars res - return (extractRhsDeltas init_deltas (cr_clauses res)) + return (extractRhsDeltas (cr_clauses res)) --- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree'. +-- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree' for a match +-- group. -- For 'AccessibleRhs's, this is stored in the tree node, whereas -- 'InaccessibleRhs's fall back to the supplied original 'Deltas'. -- See @Note [Recovering from unsatisfiable pattern-matching constraints]@. -extractRhsDeltas :: Deltas -> AnnotatedTree -> [Deltas] -extractRhsDeltas orig_deltas = fromOL . go +extractRhsDeltas :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] +extractRhsDeltas = go_matches where - go (AccessibleRhs deltas _) = unitOL deltas - go (InaccessibleRhs _) = unitOL orig_deltas - go (MayDiverge t) = go t - go (SequenceAnn l r) = go l Semi.<> go r - go EmptyAnn = nilOL + go_matches :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] + go_matches (SequenceAnn def ts) = map (go_match def) ts -- -XEmptyCase handled here! + go_matches t = pprPanic "extractRhsDeltas.go_matches" (text "Matches must start with SequenceAnn. But was" $$ ppr t) + + go_match :: Deltas -> AnnotatedTree -> (Deltas, NonEmpty Deltas) + -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ + -- is non-empty! + go_match def (SequenceAnn pat ts) = (pat, foldMap1 (text "go_match: empty SequenceAnn") (go_grhss def) ts) + go_match def (MayDiverge t) = go_match def t + -- Even if there's only a single GRHS, we wrap it in a SequenceAnn for the + -- Deltas covered by the pattern. So the remaining cases are impossible! + go_match _ t = pprPanic "extractRhsDeltas.go_match" (text "Single GRHS must be wrapped in SequenceAnn. But got " $$ ppr t) + + go_grhss :: Deltas -> AnnotatedTree -> NonEmpty Deltas + -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ + -- is non-empty! + go_grhss def (SequenceAnn _ ts) = foldMap1 (text "go_grhss: empty SequenceAnn") (go_grhss def) ts + go_grhss def (MayDiverge t) = go_grhss def t + go_grhss _ (AccessibleRhs deltas _) = deltas :| [] + go_grhss def (InaccessibleRhs _) = def :| [] + + foldMap1 msg _ [] = pprPanic "extractRhsDeltas.foldMap1" msg + foldMap1 _ f (x:xs) = foldl' (\acc x -> acc Semi.<> f x) (f x) xs {- Note [Checking EmptyCase] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -628,34 +639,43 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- 1. 2. 3. pure (con_grd : bang_grds ++ arg_grds) -mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree -mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) - -mkGrdTreeMany :: GrdVec -> [GrdTree] -> GrdTree -mkGrdTreeMany _ [] = Empty -mkGrdTreeMany grds trees = foldr Guard (foldr1 Sequence trees) grds +-- | Translate a the 'Match'es of a 'MatchGroup' +translateMatches :: FamInstEnvs -> [Id] -> [LMatch GhcTc (LHsExpr GhcTc)] + -> DsM GrdTree +translateMatches fam_insts vars matches = + -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. + -- 'extractRhsDeltas' needs this to recover 'MatchGroup' structure. + Sequence <$> traverse (translateMatch fam_insts vars) matches -- Translate a single match translateMatch :: FamInstEnvs -> [Id] -> LMatch GhcTc (LHsExpr GhcTc) -> DsM GrdTree translateMatch fam_insts vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do - pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats - grhss' <- mapM (translateLGRHS fam_insts match_loc pats) (grhssGRHSs grhss) - -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss, ppr grhss']) - return (mkGrdTreeMany pats' grhss') + pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats + grhss' <- translateGRHSs fam_insts match_loc (sep (map ppr pats)) grhss + -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss']) + return (foldr Guard grhss' pats') --- ----------------------------------------------------------------------- --- * Transform source guards (GuardStmt Id) to simpler PmGrds +mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree +mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) + +translateGRHSs :: FamInstEnvs -> SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM GrdTree +translateGRHSs fam_insts match_loc pp_pats grhss = + -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. + -- 'extractRhsDeltas' needs this to recover 'GRHSs' structure. + Sequence <$> traverse (translateLGRHS fam_insts match_loc pp_pats) (grhssGRHSs grhss) -- | Translate a guarded right-hand side to a single 'GrdTree' -translateLGRHS :: FamInstEnvs -> SrcSpan -> [LPat GhcTc] -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateLGRHS fam_insts match_loc pats (L _loc (GRHS _ gs _)) = - -- _loc apparently points to the match separator that comes after the guards.. +translateLGRHS :: FamInstEnvs -> SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree +translateLGRHS fam_insts match_loc pp_pats (L _loc (GRHS _ gs _)) = + -- _loc points to the match separator (ie =, ->) that comes after the guards.. mkGrdTreeRhs loc_sdoc <$> concatMapM (translateGuard fam_insts . unLoc) gs where loc_sdoc - | null gs = L match_loc (sep (map ppr pats)) - | otherwise = L grd_loc (sep (map ppr pats) <+> vbar <+> interpp'SP gs) + -- pp_pats is the space-separated pattern of the current Match this + -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . + | null gs = L match_loc pp_pats + | otherwise = L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) L grd_loc _ = head gs -- | Translate a guard statement to a 'GrdVec' @@ -970,6 +990,7 @@ checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do unc_this <- addPmCtDeltas deltas (PmNotConCt x con) deltas' <- addPmCtsDeltas deltas $ listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args + -- tracePm "checkGrdTree:Con" (ppr deltas $$ ppr x $$ ppr con $$ ppr dicts $$ ppr deltas') CheckResult tree' unc_inner prec <- checkGrdTree' tree deltas' limit <- maxPmCheckModels <$> getDynFlags let (prec', unc') = throttle limit deltas (unc_this Semi.<> unc_inner) @@ -978,19 +999,21 @@ checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do , cr_uncov = unc' , cr_approx = prec Semi.<> prec' } -- Sequence: Thread residual uncovered sets from equation to equation -checkGrdTree' (Sequence l r) unc_0 = do - CheckResult l' unc_1 prec_l <- checkGrdTree' l unc_0 - CheckResult r' unc_2 prec_r <- checkGrdTree' r unc_1 - pure CheckResult - { cr_clauses = SequenceAnn l' r' - , cr_uncov = unc_2 - , cr_approx = prec_l Semi.<> prec_r } --- Empty: Fall through for all values -checkGrdTree' Empty unc = do - pure CheckResult - { cr_clauses = EmptyAnn - , cr_uncov = unc - , cr_approx = Precise } +checkGrdTree' (Sequence ts) init_unc = go [] init_unc Precise ts + where + -- | Accumulates a CheckResult. Its type is more like + -- @CheckResult -> [GrdTree] -> CheckResult@, but cr_clauses is a single + -- 'AnnotatedTree', not a list thereof. Hence 3 parameters to thread the + -- fields. + go :: [AnnotatedTree] -> Deltas -> Precision -> [GrdTree] -> DsM CheckResult + -- No cases left: Fall through for all values + go ts' unc prec [] = pure CheckResult + { cr_clauses = SequenceAnn init_unc (reverse ts') + , cr_uncov = unc + , cr_approx = prec } + go ts' unc prec (t:ts) = do + CheckResult t' unc_1 prec_t <- checkGrdTree' t unc + go (t':ts') unc_1 (prec_t Semi.<> prec) ts -- | Print diagnostic info and actually call 'checkGrdTree''. checkGrdTree :: GrdTree -> Deltas -> DsM CheckResult @@ -1116,8 +1139,7 @@ redundantAndInaccessibleRhss tree = (fromOL ol_red, fromOL ol_inacc) (acc, inacc, red) | isNilOL acc && isNilOL inacc -> (nilOL, red, nilOL) res -> res - go (SequenceAnn l r) = go l Semi.<> go r - go EmptyAnn = (nilOL, nilOL, nilOL) + go (SequenceAnn _ ts) = foldMap go ts {- Note [Determining inaccessible clauses] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/HsToCore/PmCheck/Oracle.hs ===================================== @@ -1069,7 +1069,8 @@ ensureAllPossibleMatchesInhabited delta at MkDelta{ delta_tm_st = TmSt env reps } = runMaybeT (set_tm_cs_env delta <$> traverseSDIE go env) where set_tm_cs_env delta env = delta{ delta_tm_st = TmSt env reps } - go vi = MaybeT (ensureInhabited delta vi) + go vi = MaybeT $ + initPossibleMatches (delta_ty_st delta) vi >>= ensureInhabited delta -------------------------------------- -- * Term oracle unification procedure @@ -1667,7 +1668,7 @@ addCoreCt :: Delta -> Id -> CoreExpr -> MaybeT DsM Delta addCoreCt delta x e = do dflags <- getDynFlags let e' = simpleOptExpr dflags e - lift $ tracePm "addCoreCt" (ppr x $$ ppr e $$ ppr e') + lift $ tracePm "addCoreCt" (ppr x <+> dcolon <+> ppr (idType x) $$ ppr e $$ ppr e') execStateT (core_expr x e') delta where -- | Takes apart a 'CoreExpr' and tries to extract as much information about ===================================== testsuite/tests/pmcheck/should_compile/T18533.hs ===================================== @@ -0,0 +1,24 @@ +{-# OPTIONS_GHC -Wincomplete-patterns -fforce-recomp #-} +{-# LANGUAGE GADTs, DataKinds, TypeFamilies, BangPatterns #-} + +module T18533 where + +data SBool (b :: Bool) where + STrue :: SBool 'True + SFalse :: SBool 'False + +type family Fam (b :: Bool) +type instance Fam 'True = T + +data T = T Bool + +f :: Fam b -> SBool b -> Bool +f !t s = case s of + STrue -> a where a = case t of T a -> a + _ -> False + + +g :: Bool -> Bool +g x = case x of + True -> a where a = case x of True -> False + False -> True ===================================== testsuite/tests/pmcheck/should_compile/all.T ===================================== @@ -122,6 +122,8 @@ test('T18049', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T18478', collect_compiler_stats('bytes allocated',10), compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) +test('T18533', normal, compile, + ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) # Other tests test('pmc001', [], compile, View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/19e9c8e3932a0a7d30c1024640b3b65ca89a2c44 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/19e9c8e3932a0a7d30c1024640b3b65ca89a2c44 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 11 19:58:00 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 11 Aug 2020 15:58:00 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: typecheck: Drop SPECIALISE pragmas when there is no unfolding Message-ID: <5f32f8485078d_80b3f84693c1eb477023d6@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 229d3e6e by Ben Gamari at 2020-08-11T15:57:57-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 85c35c0e by Ben Gamari at 2020-08-11T15:57:57-04:00 testsuite: Add test for #18118 - - - - - 22968ac1 by Sven Tennie at 2020-08-11T15:57:57-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - 7fef72f6 by Ben Gamari at 2020-08-11T15:57:57-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - 6 changed files: - compiler/GHC/Tc/Gen/Sig.hs - + libraries/ghc-heap/hie.yaml - testsuite/tests/perf/compiler/all.T - + testsuite/tests/typecheck/should_compile/T18118.hs - + testsuite/tests/typecheck/should_compile/T18118A.hs - testsuite/tests/typecheck/should_compile/all.T Changes: ===================================== compiler/GHC/Tc/Gen/Sig.hs ===================================== @@ -826,9 +826,13 @@ tcImpPrags prags tcImpSpec :: (Name, Sig GhcRn) -> TcM [TcSpecPrag] tcImpSpec (name, prag) = do { id <- tcLookupId name - ; unless (isAnyInlinePragma (idInlinePragma id)) - (addWarnTc NoReason (impSpecErr name)) - ; tcSpecPrag id prag } + ; if isAnyInlinePragma (idInlinePragma id) + then tcSpecPrag id prag + else do { addWarnTc NoReason (impSpecErr name) + ; return [] } } + -- If there is no INLINE/INLINABLE pragma there will be no unfolding. In + -- that case, just delete the SPECIALISE pragma altogether, lest the + -- desugarer fall over because it can't find the unfolding. See #18118. impSpecErr :: Name -> SDoc impSpecErr name ===================================== libraries/ghc-heap/hie.yaml ===================================== @@ -0,0 +1,12 @@ +cradle: + multi: + - path: ./GHC/ + config: + cradle: + cabal: + component: 'lib:ghc-heap' + - path: ./tests + config: + cradle: + direct: + arguments: [] ===================================== testsuite/tests/perf/compiler/all.T ===================================== @@ -370,7 +370,7 @@ test('T16190', test('T16473', normal, makefile_test, ['T16473']) test('T17516', - [ collect_compiler_stats(), + [ collect_compiler_stats('bytes allocated', 5), extra_clean(['T17516A.hi', 'T17516A.o']) ], multimod_compile, ===================================== testsuite/tests/typecheck/should_compile/T18118.hs ===================================== @@ -0,0 +1,5 @@ +module T18118 (myfun) where + +import T18118A + +{-# SPECIALISE myfun :: Double #-} ===================================== testsuite/tests/typecheck/should_compile/T18118A.hs ===================================== @@ -0,0 +1,5 @@ +module T18118A where + +myfun :: a +myfun = undefined + ===================================== testsuite/tests/typecheck/should_compile/all.T ===================================== @@ -717,5 +717,6 @@ test('T17775-viewpats-a', normal, compile, ['']) test('T17775-viewpats-b', normal, compile_fail, ['']) test('T17775-viewpats-c', normal, compile_fail, ['']) test('T17775-viewpats-d', normal, compile_fail, ['']) +test('T18118', normal, multimod_compile, ['T18118', '-v0']) test('T18412', normal, compile, ['']) test('T18470', normal, compile, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/14575e70224a5a0e6cacb58d0c9a69e17bbc2821...7fef72f6860bc89af0a8096a4f00b789a96616f9 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/14575e70224a5a0e6cacb58d0c9a69e17bbc2821...7fef72f6860bc89af0a8096a4f00b789a96616f9 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 12 02:18:10 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 11 Aug 2020 22:18:10 -0400 Subject: [Git][ghc/ghc][master] 2 commits: typecheck: Drop SPECIALISE pragmas when there is no unfolding Message-ID: <5f335162e2317_80b40e7e107725979@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - 4 changed files: - compiler/GHC/Tc/Gen/Sig.hs - + testsuite/tests/typecheck/should_compile/T18118.hs - + testsuite/tests/typecheck/should_compile/T18118A.hs - testsuite/tests/typecheck/should_compile/all.T Changes: ===================================== compiler/GHC/Tc/Gen/Sig.hs ===================================== @@ -826,9 +826,13 @@ tcImpPrags prags tcImpSpec :: (Name, Sig GhcRn) -> TcM [TcSpecPrag] tcImpSpec (name, prag) = do { id <- tcLookupId name - ; unless (isAnyInlinePragma (idInlinePragma id)) - (addWarnTc NoReason (impSpecErr name)) - ; tcSpecPrag id prag } + ; if isAnyInlinePragma (idInlinePragma id) + then tcSpecPrag id prag + else do { addWarnTc NoReason (impSpecErr name) + ; return [] } } + -- If there is no INLINE/INLINABLE pragma there will be no unfolding. In + -- that case, just delete the SPECIALISE pragma altogether, lest the + -- desugarer fall over because it can't find the unfolding. See #18118. impSpecErr :: Name -> SDoc impSpecErr name ===================================== testsuite/tests/typecheck/should_compile/T18118.hs ===================================== @@ -0,0 +1,5 @@ +module T18118 (myfun) where + +import T18118A + +{-# SPECIALISE myfun :: Double #-} ===================================== testsuite/tests/typecheck/should_compile/T18118A.hs ===================================== @@ -0,0 +1,5 @@ +module T18118A where + +myfun :: a +myfun = undefined + ===================================== testsuite/tests/typecheck/should_compile/all.T ===================================== @@ -717,5 +717,6 @@ test('T17775-viewpats-a', normal, compile, ['']) test('T17775-viewpats-b', normal, compile_fail, ['']) test('T17775-viewpats-c', normal, compile_fail, ['']) test('T17775-viewpats-d', normal, compile_fail, ['']) +test('T18118', normal, multimod_compile, ['T18118', '-v0']) test('T18412', normal, compile, ['']) test('T18470', normal, compile, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/acf537f9fefa31883b7cb28ff61b837ab7f8a44a...0ac8c0a551619b52e0f151d6781b11dd66cf2110 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/acf537f9fefa31883b7cb28ff61b837ab7f8a44a...0ac8c0a551619b52e0f151d6781b11dd66cf2110 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 12 02:18:44 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 11 Aug 2020 22:18:44 -0400 Subject: [Git][ghc/ghc][master] Add hie.yaml to ghc-heap Message-ID: <5f3351841ac82_80b3f8486b5b7c0772683d@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - 1 changed file: - + libraries/ghc-heap/hie.yaml Changes: ===================================== libraries/ghc-heap/hie.yaml ===================================== @@ -0,0 +1,12 @@ +cradle: + multi: + - path: ./GHC/ + config: + cradle: + cabal: + component: 'lib:ghc-heap' + - path: ./tests + config: + cradle: + direct: + arguments: [] View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c43078d7b78b4722dd30b56674c27189d2689ffe -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c43078d7b78b4722dd30b56674c27189d2689ffe You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 12 02:19:22 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 11 Aug 2020 22:19:22 -0400 Subject: [Git][ghc/ghc][master] testsuite: Specify metrics collected by T17516 Message-ID: <5f3351aa360d5_80b3f8486b5b7c07731013@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - 1 changed file: - testsuite/tests/perf/compiler/all.T Changes: ===================================== testsuite/tests/perf/compiler/all.T ===================================== @@ -370,7 +370,7 @@ test('T16190', test('T16473', normal, makefile_test, ['T16473']) test('T17516', - [ collect_compiler_stats(), + [ collect_compiler_stats('bytes allocated', 5), extra_clean(['T17516A.hi', 'T17516A.o']) ], multimod_compile, View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f1088b3f31ceddf918a319c97557fb1f08a9a387 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f1088b3f31ceddf918a319c97557fb1f08a9a387 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 12 02:50:05 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 11 Aug 2020 22:50:05 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 6 commits: typecheck: Drop SPECIALISE pragmas when there is no unfolding Message-ID: <5f3358dd67cb7_80b3f8486b5b7c0773325@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - 568608de by Sylvain Henry at 2020-08-11T22:50:01-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - efab28da by Ben Gamari at 2020-08-11T22:50:02-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - 30 changed files: - compiler/GHC.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - compiler/GHC/CmmToAsm/CPrim.hs - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Format.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7fef72f6860bc89af0a8096a4f00b789a96616f9...efab28daa8f790c65402c051e09264b4a3458da4 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7fef72f6860bc89af0a8096a4f00b789a96616f9...efab28daa8f790c65402c051e09264b4a3458da4 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 12 06:35:06 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Wed, 12 Aug 2020 02:35:06 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] Expect stack_marking starting from GHC 8.10 Message-ID: <5f338d9a3485b_80b3f8495bc8b047739119@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: b9ff4bad by Sven Tennie at 2020-08-10T07:53:21+02:00 Expect stack_marking starting from GHC 8.10 This field was introduced with GHC 8.10. - - - - - 2 changed files: - libraries/ghc-heap/GHC/Exts/Heap/Closures.hs - libraries/ghc-heap/GHC/Exts/Heap/FFIClosures.hsc Changes: ===================================== libraries/ghc-heap/GHC/Exts/Heap/Closures.hs ===================================== @@ -302,7 +302,7 @@ data GenClosure b { info :: !StgInfoTable , stack_size :: !Word32 -- ^ stack size in *words* , stack_dirty :: !Word8 -- ^ non-zero => dirty -#if __GLASGOW_HASKELL__ >= 811 +#if __GLASGOW_HASKELL__ >= 810 , stack_marking :: Word8 #endif , stackPointer :: !b -- ^ current stack pointer ===================================== libraries/ghc-heap/GHC/Exts/Heap/FFIClosures.hsc ===================================== @@ -53,7 +53,7 @@ peekTSOFields peekProfInfo ptr = do data StackFields = StackFields { stack_size :: Word32, stack_dirty :: Word8, -#if __GLASGOW_HASKELL__ >= 811 +#if __GLASGOW_HASKELL__ >= 810 stack_marking :: Word8, #endif stack :: [Word] @@ -64,7 +64,7 @@ peekStackFields :: Ptr a -> IO StackFields peekStackFields ptr = do stack_size' <- (#peek struct StgStack_, stack_size) ptr ::IO Word32 dirty' <- (#peek struct StgStack_, dirty) ptr -#if __GLASGOW_HASKELL__ >= 811 +#if __GLASGOW_HASKELL__ >= 810 marking' <- (#peek struct StgStack_, marking) ptr #endif @@ -74,7 +74,7 @@ peekStackFields ptr = do return StackFields { stack_size = stack_size', stack_dirty = dirty', -#if __GLASGOW_HASKELL__ >= 811 +#if __GLASGOW_HASKELL__ >= 810 stack_marking = marking', #endif stack = stack' View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b9ff4bad26ccd32a2e4e6827e734c0fb3a63de0a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b9ff4bad26ccd32a2e4e6827e734c0fb3a63de0a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 12 07:50:18 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 12 Aug 2020 03:50:18 -0400 Subject: [Git][ghc/ghc][master] DynFlags: disentangle Outputable Message-ID: <5f339f3a113e8_80b3f84865febec7740440@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - 30 changed files: - compiler/GHC.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - compiler/GHC/CmmToAsm/CPrim.hs - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Format.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/accbc242e555822a2060091af7188ce6e9b0144e -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/accbc242e555822a2060091af7188ce6e9b0144e You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 12 07:50:55 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 12 Aug 2020 03:50:55 -0400 Subject: [Git][ghc/ghc][master] testsuite: Increase tolerance of T16916 Message-ID: <5f339f5fbc5c7_80b3f848629827877469b9@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - 1 changed file: - testsuite/tests/lib/base/T16916.hs Changes: ===================================== testsuite/tests/lib/base/T16916.hs ===================================== @@ -46,4 +46,4 @@ main = do -- CPU consumption should roughly be the same when just idling vs -- when idling after the event been triggered - print $ eventTriggeredUsage / noEventUsage < 10.0 + print $ eventTriggeredUsage / noEventUsage < 100.0 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/db6dd810eb7986a39657f7f028f1f4de92b321dd -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/db6dd810eb7986a39657f7f028f1f4de92b321dd You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 12 09:08:08 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Wed, 12 Aug 2020 05:08:08 -0400 Subject: [Git][ghc/ghc][wip/T18533] PmCheck: Better long-distance info for where bindings (#18533) Message-ID: <5f33b178c90eb_80b3f84865febec77557a3@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18533 at Glasgow Haskell Compiler / GHC Commits: 5b1e3a72 by Sebastian Graf at 2020-08-12T11:07:58+02:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - 15 changed files: - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Core/Coercion/Opt.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/GuardedRHSs.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/Monad.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - compiler/GHC/Tc/Errors/Hole.hs - compiler/GHC/Tc/Gen/HsType.hs - + testsuite/tests/pmcheck/should_compile/T18533.hs - testsuite/tests/pmcheck/should_compile/all.T Changes: ===================================== compiler/GHC/Cmm/DebugBlock.hs ===================================== @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiWayIf #-} @@ -109,7 +110,9 @@ cmmDebugGen modLoc decls = map (blocksForScope Nothing) topScopes -- recover by copying ticks below. scp' | SubScope _ scp' <- scp = scp' | CombinedScope scp' _ <- scp = scp' +#if __GLASGOW_HASKELL__ <= 810 | otherwise = panic "findP impossible" +#endif scopeMap = foldr (uncurry insertMulti) Map.empty childScopes ===================================== compiler/GHC/Core/Coercion/Opt.hs ===================================== @@ -555,7 +555,10 @@ opt_univ env sym prov role oty1 oty2 where prov' = case prov of +#if __GLASGOW_HASKELL__ <= 810 +-- This alt is redundant with the first match of the FunDef PhantomProv kco -> PhantomProv $ opt_co4_wrap env sym False Nominal kco +#endif ProofIrrelProv kco -> ProofIrrelProv $ opt_co4_wrap env sym False Nominal kco PluginProv _ -> prov ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -1242,7 +1242,9 @@ ppr_infix_expr (HsConLikeOut _ c) = Just (pprInfixOcc (conLikeName c)) ppr_infix_expr (HsRecFld _ f) = Just (pprInfixOcc f) ppr_infix_expr (HsUnboundVar _ occ) = Just (pprInfixOcc occ) ppr_infix_expr (XExpr x) = case (ghcPass @p, x) of +#if __GLASGOW_HASKELL__ <= 810 (GhcPs, _) -> Nothing +#endif (GhcRn, HsExpanded a _) -> ppr_infix_expr a (GhcTc, WrapExpr (HsWrap _ e)) -> ppr_infix_expr e (GhcTc, ExpansionExpr (HsExpanded a _)) -> ppr_infix_expr a ===================================== compiler/GHC/Hs/Pat.hs ===================================== @@ -845,8 +845,10 @@ patNeedsParens p = go go (SigPat {}) = p >= sigPrec go (ViewPat {}) = True go (XPat ext) = case ghcPass @p of +#if __GLASGOW_HASKELL__ <= 810 GhcPs -> noExtCon ext GhcRn -> noExtCon ext +#endif GhcTc -> go inner where CoPat _ inner _ = ext go (WildPat {}) = False ===================================== compiler/GHC/HsToCore/Binds.hs ===================================== @@ -33,7 +33,7 @@ import {-# SOURCE #-} GHC.HsToCore.Match ( matchWrapper ) import GHC.HsToCore.Monad import GHC.HsToCore.GuardedRHSs import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck ( addTyCsDs, checkGuardMatches ) +import GHC.HsToCore.PmCheck ( addTyCsDs, checkGRHSs ) import GHC.Hs -- lots of things import GHC.Core -- lots of things @@ -76,7 +76,6 @@ import GHC.Types.Unique.Set( nonDetEltsUniqSet ) import GHC.Utils.Monad import qualified GHC.LanguageExtensions as LangExt import Control.Monad -import Data.List.NonEmpty ( nonEmpty ) {-********************************************************************** * * @@ -183,8 +182,8 @@ dsHsBind dflags b@(FunBind { fun_id = L loc fun dsHsBind dflags (PatBind { pat_lhs = pat, pat_rhs = grhss , pat_ext = NPatBindTc _ ty , pat_ticks = (rhs_tick, var_ticks) }) - = do { rhss_deltas <- checkGuardMatches PatBindGuards grhss - ; body_expr <- dsGuarded grhss ty (nonEmpty rhss_deltas) + = do { rhss_deltas <- checkGRHSs PatBindGuards grhss + ; body_expr <- dsGuarded grhss ty rhss_deltas ; let body' = mkOptTickBox rhs_tick body_expr pat' = decideBangHood dflags pat ; (force_var,sel_binds) <- mkSelectorBinds var_ticks pat body' ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -31,7 +31,7 @@ import GHC.HsToCore.ListComp import GHC.HsToCore.Utils import GHC.HsToCore.Arrows import GHC.HsToCore.Monad -import GHC.HsToCore.PmCheck ( addTyCsDs, checkGuardMatches ) +import GHC.HsToCore.PmCheck ( addTyCsDs, checkGRHSs ) import GHC.Types.Name import GHC.Types.Name.Env import GHC.Core.FamInstEnv( topNormaliseType ) @@ -69,7 +69,6 @@ import GHC.Utils.Outputable as Outputable import GHC.Core.PatSyn import Control.Monad -import Data.List.NonEmpty ( nonEmpty ) {- ************************************************************************ @@ -215,8 +214,8 @@ dsUnliftedBind (PatBind {pat_lhs = pat, pat_rhs = grhss , pat_ext = NPatBindTc _ ty }) body = -- let C x# y# = rhs in body -- ==> case rhs of C x# y# -> body - do { rhs_deltas <- checkGuardMatches PatBindGuards grhss - ; rhs <- dsGuarded grhss ty (nonEmpty rhs_deltas) + do { match_deltas <- checkGRHSs PatBindGuards grhss + ; rhs <- dsGuarded grhss ty match_deltas ; let upat = unLoc pat eqn = EqnInfo { eqn_pats = [upat], eqn_orig = FromSource, @@ -486,8 +485,8 @@ dsExpr (HsMultiIf res_ty alts) | otherwise = do { let grhss = GRHSs noExtField alts (noLoc emptyLocalBinds) - ; rhss_deltas <- checkGuardMatches IfAlt grhss - ; match_result <- dsGRHSs IfAlt grhss res_ty (nonEmpty rhss_deltas) + ; rhss_deltas <- checkGRHSs IfAlt grhss + ; match_result <- dsGRHSs IfAlt grhss res_ty rhss_deltas ; error_expr <- mkErrorExpr ; extractMatchResult match_result error_expr } where ===================================== compiler/GHC/HsToCore/GuardedRHSs.hs ===================================== @@ -25,7 +25,7 @@ import GHC.Core.Utils (bindNonRec) import GHC.HsToCore.Monad import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck.Types ( Deltas, initDeltas ) +import GHC.HsToCore.PmCheck.Types ( Deltas ) import GHC.Core.Type ( Type ) import GHC.Utils.Misc import GHC.Types.SrcLoc @@ -47,9 +47,9 @@ producing an expression with a runtime error in the corner if necessary. The type argument gives the type of the @ei at . -} -dsGuarded :: GRHSs GhcTc (LHsExpr GhcTc) -> Type -> Maybe (NonEmpty Deltas) -> DsM CoreExpr -dsGuarded grhss rhs_ty mb_rhss_deltas = do - match_result <- dsGRHSs PatBindRhs grhss rhs_ty mb_rhss_deltas +dsGuarded :: GRHSs GhcTc (LHsExpr GhcTc) -> Type -> NonEmpty Deltas -> DsM CoreExpr +dsGuarded grhss rhs_ty rhss_deltas = do + match_result <- dsGRHSs PatBindRhs grhss rhs_ty rhss_deltas error_expr <- mkErrorAppDs nON_EXHAUSTIVE_GUARDS_ERROR_ID rhs_ty empty extractMatchResult match_result error_expr @@ -58,25 +58,28 @@ dsGuarded grhss rhs_ty mb_rhss_deltas = do dsGRHSs :: HsMatchContext GhcRn -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ Guarded RHSs -> Type -- ^ Type of RHS - -> Maybe (NonEmpty Deltas) -- ^ Refined pattern match checking - -- models, one for each GRHS. Defaults - -- to 'initDeltas' if 'Nothing'. + -> NonEmpty Deltas -- ^ Refined pattern match checking + -- models, one for the pattern part and + -- one for each GRHS. -> DsM (MatchResult CoreExpr) -dsGRHSs hs_ctx (GRHSs _ grhss binds) rhs_ty mb_rhss_deltas +dsGRHSs hs_ctx (GRHSs _ grhss binds) rhs_ty rhss_deltas = ASSERT( notNull grhss ) - do { match_results <- case toList <$> mb_rhss_deltas of - Nothing -> mapM (dsGRHS hs_ctx rhs_ty initDeltas) grhss - Just rhss_deltas -> ASSERT( length grhss == length rhss_deltas ) - zipWithM (dsGRHS hs_ctx rhs_ty) rhss_deltas grhss - ; let match_result1 = foldr1 combineMatchResults match_results - match_result2 = adjustMatchResultDs (dsLocalBinds binds) match_result1 + do { match_results <- ASSERT( length grhss == length rhss_deltas ) + zipWithM (dsGRHS hs_ctx rhs_ty) (toList rhss_deltas) grhss + ; deltas <- getPmDeltas + -- We need to remember the Deltas from the particular match context we + -- are in, which might be different to when dsLocalBinds is actually + -- called. + ; let ds_binds = updPmDeltas deltas . dsLocalBinds binds + match_result1 = foldr1 combineMatchResults match_results + match_result2 = adjustMatchResultDs ds_binds match_result1 -- NB: nested dsLet inside matchResult ; return match_result2 } dsGRHS :: HsMatchContext GhcRn -> Type -> Deltas -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM (MatchResult CoreExpr) dsGRHS hs_ctx rhs_ty rhs_deltas (L _ (GRHS _ guards rhs)) - = updPmDeltas rhs_deltas (matchGuards (map unLoc guards) (PatGuard hs_ctx) rhs rhs_ty) + = matchGuards (map unLoc guards) (PatGuard hs_ctx) rhs_deltas rhs rhs_ty {- ************************************************************************ @@ -88,6 +91,7 @@ dsGRHS hs_ctx rhs_ty rhs_deltas (L _ (GRHS _ guards rhs)) matchGuards :: [GuardStmt GhcTc] -- Guard -> HsStmtContext GhcRn -- Context + -> Deltas -- The RHS's covered set for PmCheck -> LHsExpr GhcTc -- RHS -> Type -- Type of RHS of guard -> DsM (MatchResult CoreExpr) @@ -95,8 +99,8 @@ matchGuards :: [GuardStmt GhcTc] -- Guard -- See comments with HsExpr.Stmt re what a BodyStmt means -- Here we must be in a guard context (not do-expression, nor list-comp) -matchGuards [] _ rhs _ - = do { core_rhs <- dsLExpr rhs +matchGuards [] _ deltas rhs _ + = do { core_rhs <- updPmDeltas deltas (dsLExpr rhs) ; return (cantFailMatchResult core_rhs) } -- BodyStmts must be guards @@ -106,41 +110,41 @@ matchGuards [] _ rhs _ -- NB: The success of this clause depends on the typechecker not -- wrapping the 'otherwise' in empty HsTyApp or HsWrap constructors -- If it does, you'll get bogus overlap warnings -matchGuards (BodyStmt _ e _ _ : stmts) ctx rhs rhs_ty +matchGuards (BodyStmt _ e _ _ : stmts) ctx deltas rhs rhs_ty | Just addTicks <- isTrueLHsExpr e = do - match_result <- matchGuards stmts ctx rhs rhs_ty + match_result <- matchGuards stmts ctx deltas rhs rhs_ty return (adjustMatchResultDs addTicks match_result) -matchGuards (BodyStmt _ expr _ _ : stmts) ctx rhs rhs_ty = do - match_result <- matchGuards stmts ctx rhs rhs_ty +matchGuards (BodyStmt _ expr _ _ : stmts) ctx deltas rhs rhs_ty = do + match_result <- matchGuards stmts ctx deltas rhs rhs_ty pred_expr <- dsLExpr expr return (mkGuardedMatchResult pred_expr match_result) -matchGuards (LetStmt _ binds : stmts) ctx rhs rhs_ty = do - match_result <- matchGuards stmts ctx rhs rhs_ty +matchGuards (LetStmt _ binds : stmts) ctx deltas rhs rhs_ty = do + match_result <- matchGuards stmts ctx deltas rhs rhs_ty return (adjustMatchResultDs (dsLocalBinds binds) match_result) -- NB the dsLet occurs inside the match_result -- Reason: dsLet takes the body expression as its argument -- so we can't desugar the bindings without the -- body expression in hand -matchGuards (BindStmt _ pat bind_rhs : stmts) ctx rhs rhs_ty = do +matchGuards (BindStmt _ pat bind_rhs : stmts) ctx deltas rhs rhs_ty = do let upat = unLoc pat match_var <- selectMatchVar Many upat -- We only allow unrestricted patterns in guard, hence the `Many` -- above. It isn't clear what linear patterns would mean, maybe we will -- figure it out in the future. - match_result <- matchGuards stmts ctx rhs rhs_ty + match_result <- matchGuards stmts ctx deltas rhs rhs_ty core_rhs <- dsLExpr bind_rhs match_result' <- matchSinglePatVar match_var (StmtCtxt ctx) pat rhs_ty match_result pure $ bindNonRec match_var core_rhs <$> match_result' -matchGuards (LastStmt {} : _) _ _ _ = panic "matchGuards LastStmt" -matchGuards (ParStmt {} : _) _ _ _ = panic "matchGuards ParStmt" -matchGuards (TransStmt {} : _) _ _ _ = panic "matchGuards TransStmt" -matchGuards (RecStmt {} : _) _ _ _ = panic "matchGuards RecStmt" -matchGuards (ApplicativeStmt {} : _) _ _ _ = +matchGuards (LastStmt {} : _) _ _ _ _ = panic "matchGuards LastStmt" +matchGuards (ParStmt {} : _) _ _ _ _ = panic "matchGuards ParStmt" +matchGuards (TransStmt {} : _) _ _ _ _ = panic "matchGuards TransStmt" +matchGuards (RecStmt {} : _) _ _ _ _ = panic "matchGuards RecStmt" +matchGuards (ApplicativeStmt {} : _) _ _ _ _ = panic "matchGuards ApplicativeLastStmt" {- ===================================== compiler/GHC/HsToCore/Match.hs ===================================== @@ -35,6 +35,7 @@ import GHC.Tc.Utils.Zonk import GHC.Tc.Types.Evidence import GHC.Tc.Utils.Monad import GHC.HsToCore.PmCheck +import GHC.HsToCore.PmCheck.Types ( Deltas, initDeltas ) import GHC.Core import GHC.Types.Literal import GHC.Core.Utils @@ -64,7 +65,7 @@ import GHC.Data.FastString import GHC.Types.Unique import GHC.Types.Unique.DFM -import Control.Monad( unless ) +import Control.Monad(zipWithM, unless ) import Data.List.NonEmpty (NonEmpty(..)) import qualified Data.List.NonEmpty as NEL import qualified Data.Map as Map @@ -766,49 +767,46 @@ matchWrapper ctxt mb_scr (MG { mg_alts = L _ matches -- Pattern match check warnings for /this match-group/. -- @rhss_deltas@ is a flat list of covered Deltas for each RHS. -- Each Match will split off one Deltas for its RHSs from this. - ; rhss_deltas <- if isMatchContextPmChecked dflags origin ctxt + ; matches_deltas <- if isMatchContextPmChecked dflags origin ctxt then addScrutTmCs mb_scr new_vars $ - -- See Note [Type and Term Equality Propagation] - checkMatches (DsMatchContext ctxt locn) new_vars matches - else pure [] -- Ultimately this will result in passing Nothing - -- to dsGRHSs as match_deltas + -- See Note [Type and Term Equality Propagation] + checkMatches (DsMatchContext ctxt locn) new_vars matches + else pure (initDeltasMatches matches) - ; eqns_info <- mk_eqn_infos matches rhss_deltas + ; eqns_info <- zipWithM mk_eqn_info matches matches_deltas ; result_expr <- handleWarnings $ matchEquations ctxt new_vars eqns_info rhs_ty ; return (new_vars, result_expr) } where - -- rhss_deltas is a flat list, whereas there are multiple GRHSs per match. - -- mk_eqn_infos will thread rhss_deltas as state through calls to - -- mk_eqn_info, distributing each rhss_deltas to a GRHS. - mk_eqn_infos (L _ match : matches) rhss_deltas - = do { (info, rhss_deltas') <- mk_eqn_info match rhss_deltas - ; infos <- mk_eqn_infos matches rhss_deltas' - ; return (info:infos) } - mk_eqn_infos [] _ = return [] -- Called once per equation in the match, or alternative in the case - mk_eqn_info (Match { m_pats = pats, m_grhss = grhss }) rhss_deltas - | GRHSs _ grhss' _ <- grhss, let n_grhss = length grhss' + mk_eqn_info :: LMatch GhcTc (LHsExpr GhcTc) -> (Deltas, NonEmpty Deltas) -> DsM EquationInfo + mk_eqn_info (L _ (Match { m_pats = pats, m_grhss = grhss })) (pat_deltas, rhss_deltas) = do { dflags <- getDynFlags ; let upats = map (unLoc . decideBangHood dflags) pats - -- Split off one Deltas for each GRHS of the current Match from the - -- flat list of GRHS Deltas *for all matches* (see the call to - -- checkMatches above). - ; let (match_deltas, rhss_deltas') = splitAt n_grhss rhss_deltas - -- The list of Deltas is empty iff we don't perform any coverage - -- checking, in which case nonEmpty does the right thing by passing - -- Nothing. - ; match_result <- dsGRHSs ctxt grhss rhs_ty (NEL.nonEmpty match_deltas) - ; return ( EqnInfo { eqn_pats = upats - , eqn_orig = FromSource - , eqn_rhs = match_result } - , rhss_deltas' ) } + -- pat_deltas is the covered set *after* matching the pattern, but + -- before any of the GRHSs. It is the evidence that is visible in + -- the associated where clauses of the match. + ; match_result <- updPmDeltas pat_deltas $ + dsGRHSs ctxt grhss rhs_ty rhss_deltas + ; return EqnInfo { eqn_pats = upats + , eqn_orig = FromSource + , eqn_rhs = match_result } } handleWarnings = if isGenerated origin then discardWarningsDs else id + initDeltasMatches :: [LMatch GhcTc b] -> [(Deltas, NonEmpty Deltas)] + initDeltasMatches ms + = map (\(L _ m) -> (initDeltas, initDeltasGRHSs (m_grhss m))) ms + + initDeltasGRHSs :: GRHSs GhcTc b -> NonEmpty Deltas + initDeltasGRHSs m = expectJust "GRHSs non-empty" + $ NEL.nonEmpty + $ replicate (length (grhssGRHSs m)) initDeltas + + matchEquations :: HsMatchContext GhcRn -> [MatchId] -> [EquationInfo] -> Type -> DsM CoreExpr ===================================== compiler/GHC/HsToCore/Monad.hs ===================================== @@ -405,7 +405,7 @@ getPmDeltas = do { env <- getLclEnv; return (dsl_deltas env) } -- | Set the pattern match oracle state within the scope of the given action. -- See 'dsl_deltas'. updPmDeltas :: Deltas -> DsM a -> DsM a -updPmDeltas delta = updLclEnv (\env -> env { dsl_deltas = delta }) +updPmDeltas deltas = updLclEnv (\env -> env { dsl_deltas = deltas }) getSrcSpanDs :: DsM SrcSpan getSrcSpanDs = do { env <- getLclEnv ===================================== compiler/GHC/HsToCore/PmCheck.hs ===================================== @@ -13,7 +13,7 @@ Pattern Matching Coverage Checking. module GHC.HsToCore.PmCheck ( -- Checking and printing - checkSingle, checkMatches, checkGuardMatches, + checkSingle, checkMatches, checkGRHSs, isMatchContextPmChecked, -- See Note [Type and Term Equality Propagation] @@ -65,6 +65,7 @@ import GHC.Utils.Monad (concatMapM) import Control.Monad (when, forM_, zipWithM) import Data.List (elemIndex) import qualified Data.Semigroup as Semi +import Data.List.NonEmpty (NonEmpty(..)) {- This module checks pattern matches for: @@ -149,13 +150,11 @@ data GrdTree -- ^ @Guard grd t@ will try to match @grd@ and on success continue to match -- @t at . Falls through if either match fails. Models left-to-right semantics -- of pattern matching. - | Sequence !GrdTree !GrdTree - -- ^ @Sequence l r@ first matches against @l@, and then matches all - -- fallen-through values against @r at . Models top-to-bottom semantics of - -- pattern matching. - | Empty - -- ^ A @GrdTree@ that always fails. Most useful for - -- Note [Checking EmptyCase]. A neutral element to 'Sequence'. + | Sequence ![GrdTree] + -- ^ @Sequence (t:ts)@ matches against @t@, and then matches all + -- fallen-through values against @Sequence ts at . Models top-to-bottom semantics + -- of pattern matching. + -- @Sequence []@ always fails; it is useful for Note [Checking EmptyCase]. -- | The digest of 'checkGrdTree', representing the annotated pattern-match -- tree. 'redundantAndInaccessibleRhss' can figure out redundant and proper @@ -169,10 +168,10 @@ data AnnotatedTree | MayDiverge !AnnotatedTree -- ^ Asserts that the tree may force diverging values, so not all of its -- clauses can be redundant. - | SequenceAnn !AnnotatedTree !AnnotatedTree - -- ^ Mirrors 'Sequence' for preserving the skeleton of a 'GrdTree's. - | EmptyAnn - -- ^ Mirrors 'Empty' for preserving the skeleton of a 'GrdTree's. + | SequenceAnn !Deltas ![AnnotatedTree] + -- ^ @SequenceAnn inc ts@ mirrors @'Sequence' ts@ for preserving the + -- skeleton of a 'GrdTree's @ts at . It also carries the set of incoming values + -- @inc at . pprRhsInfo :: RhsInfo -> SDoc pprRhsInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) @@ -188,23 +187,15 @@ instance Outputable GrdTree where collect_grds t = (t, []) prefix [] = [] prefix (s:sdocs) = char '|' <+> s : map (comma <+>) sdocs - -- Format nested Sequences in blocks "{ grds1; grds2; ... }" - ppr t at Sequence{} = braces (space <> fsep (punctuate semi (collect_seqs t)) <> space) - where - collect_seqs (Sequence l r) = collect_seqs l ++ collect_seqs r - collect_seqs t = [ppr t] - ppr Empty = text "" + ppr (Sequence []) = text "" + ppr (Sequence ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) instance Outputable AnnotatedTree where - ppr (AccessibleRhs _ info) = pprRhsInfo info + ppr (AccessibleRhs _delta info) = parens (ppr _delta) <+> pprRhsInfo info ppr (InaccessibleRhs info) = text "inaccessible" <+> pprRhsInfo info ppr (MayDiverge t) = text "div" <+> ppr t - -- Format nested Sequences in blocks "{ grds1; grds2; ... }" - ppr t at SequenceAnn{} = braces (space <> fsep (punctuate semi (collect_seqs t)) <> space) - where - collect_seqs (SequenceAnn l r) = collect_seqs l ++ collect_seqs r - collect_seqs t = [ppr t] - ppr EmptyAnn = text "" + ppr (SequenceAnn _ []) = text "" + ppr (SequenceAnn _ ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) -- | Lift 'addPmCts' over 'Deltas'. addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas @@ -263,7 +254,7 @@ checkSingle dflags ctxt@(DsMatchContext kind locn) var p = do -- Omitting checking this flag emits redundancy warnings twice in obscure -- cases like #17646. when (exhaustive dflags kind) $ do - -- TODO: This could probably call checkMatches, like checkGuardMatches. + -- TODO: This could probably call checkMatches, like checkGRHSs. missing <- getPmDeltas tracePm "checkSingle: missing" (ppr missing) fam_insts <- dsGetFamInstEnvs @@ -273,12 +264,12 @@ checkSingle dflags ctxt@(DsMatchContext kind locn) var p = do -- | Exhaustive for guard matches, is used for guards in pattern bindings and -- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. -checkGuardMatches +checkGRHSs :: HsMatchContext GhcRn -- ^ Match context, for warning messages -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check - -> DsM [Deltas] -- ^ Covered 'Deltas' for each RHS, for long + -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long -- distance info -checkGuardMatches hs_ctx guards@(GRHSs _ grhss _) = do +checkGRHSs hs_ctx guards@(GRHSs _ grhss _) = do let combinedLoc = foldl1 combineSrcSpans (map getLoc grhss) dsMatchContext = DsMatchContext hs_ctx combinedLoc match = L combinedLoc $ @@ -286,7 +277,8 @@ checkGuardMatches hs_ctx guards@(GRHSs _ grhss _) = do , m_ctxt = hs_ctx , m_pats = [] , m_grhss = guards } - checkMatches dsMatchContext [] [match] + [(_, deltas)] <- checkMatches dsMatchContext [] [match] + pure deltas -- | Check a list of syntactic /match/es (part of case, functions, etc.), each -- with a /pat/ and one or more /grhss/: @@ -305,10 +297,9 @@ checkMatches :: DsMatchContext -- ^ Match context, for warnings messages -> [Id] -- ^ Match variables, i.e. x and y above -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches - -> DsM [Deltas] -- ^ One covered 'Deltas' per RHS, for long + -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per RHS, for long -- distance info. checkMatches ctxt vars matches = do - dflags <- getDynFlags tracePm "checkMatches" (hang (vcat [ppr ctxt , ppr vars , text "Matches:"]) @@ -321,25 +312,45 @@ checkMatches ctxt vars matches = do [] | [var] <- vars -> addPmCtDeltas init_deltas (PmNotBotCt var) _ -> pure init_deltas fam_insts <- dsGetFamInstEnvs - grd_tree <- mkGrdTreeMany [] <$> mapM (translateMatch fam_insts vars) matches + grd_tree <- translateMatches fam_insts vars matches res <- checkGrdTree grd_tree missing + dflags <- getDynFlags dsPmWarn dflags ctxt vars res - return (extractRhsDeltas init_deltas (cr_clauses res)) + return (extractRhsDeltas (cr_clauses res)) --- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree'. +-- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree' for a match +-- group. -- For 'AccessibleRhs's, this is stored in the tree node, whereas -- 'InaccessibleRhs's fall back to the supplied original 'Deltas'. -- See @Note [Recovering from unsatisfiable pattern-matching constraints]@. -extractRhsDeltas :: Deltas -> AnnotatedTree -> [Deltas] -extractRhsDeltas orig_deltas = fromOL . go +extractRhsDeltas :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] +extractRhsDeltas = go_matches where - go (AccessibleRhs deltas _) = unitOL deltas - go (InaccessibleRhs _) = unitOL orig_deltas - go (MayDiverge t) = go t - go (SequenceAnn l r) = go l Semi.<> go r - go EmptyAnn = nilOL + go_matches :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] + go_matches (SequenceAnn def ts) = map (go_match def) ts -- -XEmptyCase handled here! + go_matches t = pprPanic "extractRhsDeltas.go_matches" (text "Matches must start with SequenceAnn. But was" $$ ppr t) + + go_match :: Deltas -> AnnotatedTree -> (Deltas, NonEmpty Deltas) + -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ + -- is non-empty! + go_match def (SequenceAnn pat ts) = (pat, foldMap1 (text "go_match: empty SequenceAnn") (go_grhss def) ts) + go_match def (MayDiverge t) = go_match def t + -- Even if there's only a single GRHS, we wrap it in a SequenceAnn for the + -- Deltas covered by the pattern. So the remaining cases are impossible! + go_match _ t = pprPanic "extractRhsDeltas.go_match" (text "Single GRHS must be wrapped in SequenceAnn. But got " $$ ppr t) + + go_grhss :: Deltas -> AnnotatedTree -> NonEmpty Deltas + -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ + -- is non-empty! + go_grhss def (SequenceAnn _ ts) = foldMap1 (text "go_grhss: empty SequenceAnn") (go_grhss def) ts + go_grhss def (MayDiverge t) = go_grhss def t + go_grhss _ (AccessibleRhs deltas _) = deltas :| [] + go_grhss def (InaccessibleRhs _) = def :| [] + + foldMap1 msg _ [] = pprPanic "extractRhsDeltas.foldMap1" msg + foldMap1 _ f (x:xs) = foldl' (\acc x -> acc Semi.<> f x) (f x) xs {- Note [Checking EmptyCase] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -628,34 +639,43 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- 1. 2. 3. pure (con_grd : bang_grds ++ arg_grds) -mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree -mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) - -mkGrdTreeMany :: GrdVec -> [GrdTree] -> GrdTree -mkGrdTreeMany _ [] = Empty -mkGrdTreeMany grds trees = foldr Guard (foldr1 Sequence trees) grds +-- | Translate a the 'Match'es of a 'MatchGroup' +translateMatches :: FamInstEnvs -> [Id] -> [LMatch GhcTc (LHsExpr GhcTc)] + -> DsM GrdTree +translateMatches fam_insts vars matches = + -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. + -- 'extractRhsDeltas' needs this to recover 'MatchGroup' structure. + Sequence <$> traverse (translateMatch fam_insts vars) matches -- Translate a single match translateMatch :: FamInstEnvs -> [Id] -> LMatch GhcTc (LHsExpr GhcTc) -> DsM GrdTree translateMatch fam_insts vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do - pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats - grhss' <- mapM (translateLGRHS fam_insts match_loc pats) (grhssGRHSs grhss) - -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss, ppr grhss']) - return (mkGrdTreeMany pats' grhss') + pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats + grhss' <- translateGRHSs fam_insts match_loc (sep (map ppr pats)) grhss + -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss']) + return (foldr Guard grhss' pats') --- ----------------------------------------------------------------------- --- * Transform source guards (GuardStmt Id) to simpler PmGrds +mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree +mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) + +translateGRHSs :: FamInstEnvs -> SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM GrdTree +translateGRHSs fam_insts match_loc pp_pats grhss = + -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. + -- 'extractRhsDeltas' needs this to recover 'GRHSs' structure. + Sequence <$> traverse (translateLGRHS fam_insts match_loc pp_pats) (grhssGRHSs grhss) -- | Translate a guarded right-hand side to a single 'GrdTree' -translateLGRHS :: FamInstEnvs -> SrcSpan -> [LPat GhcTc] -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateLGRHS fam_insts match_loc pats (L _loc (GRHS _ gs _)) = - -- _loc apparently points to the match separator that comes after the guards.. +translateLGRHS :: FamInstEnvs -> SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree +translateLGRHS fam_insts match_loc pp_pats (L _loc (GRHS _ gs _)) = + -- _loc points to the match separator (ie =, ->) that comes after the guards.. mkGrdTreeRhs loc_sdoc <$> concatMapM (translateGuard fam_insts . unLoc) gs where loc_sdoc - | null gs = L match_loc (sep (map ppr pats)) - | otherwise = L grd_loc (sep (map ppr pats) <+> vbar <+> interpp'SP gs) + -- pp_pats is the space-separated pattern of the current Match this + -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . + | null gs = L match_loc pp_pats + | otherwise = L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) L grd_loc _ = head gs -- | Translate a guard statement to a 'GrdVec' @@ -970,6 +990,7 @@ checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do unc_this <- addPmCtDeltas deltas (PmNotConCt x con) deltas' <- addPmCtsDeltas deltas $ listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args + -- tracePm "checkGrdTree:Con" (ppr deltas $$ ppr x $$ ppr con $$ ppr dicts $$ ppr deltas') CheckResult tree' unc_inner prec <- checkGrdTree' tree deltas' limit <- maxPmCheckModels <$> getDynFlags let (prec', unc') = throttle limit deltas (unc_this Semi.<> unc_inner) @@ -978,19 +999,21 @@ checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do , cr_uncov = unc' , cr_approx = prec Semi.<> prec' } -- Sequence: Thread residual uncovered sets from equation to equation -checkGrdTree' (Sequence l r) unc_0 = do - CheckResult l' unc_1 prec_l <- checkGrdTree' l unc_0 - CheckResult r' unc_2 prec_r <- checkGrdTree' r unc_1 - pure CheckResult - { cr_clauses = SequenceAnn l' r' - , cr_uncov = unc_2 - , cr_approx = prec_l Semi.<> prec_r } --- Empty: Fall through for all values -checkGrdTree' Empty unc = do - pure CheckResult - { cr_clauses = EmptyAnn - , cr_uncov = unc - , cr_approx = Precise } +checkGrdTree' (Sequence ts) init_unc = go [] init_unc Precise ts + where + -- | Accumulates a CheckResult. Its type is more like + -- @CheckResult -> [GrdTree] -> CheckResult@, but cr_clauses is a single + -- 'AnnotatedTree', not a list thereof. Hence 3 parameters to thread the + -- fields. + go :: [AnnotatedTree] -> Deltas -> Precision -> [GrdTree] -> DsM CheckResult + -- No cases left: Fall through for all values + go ts' unc prec [] = pure CheckResult + { cr_clauses = SequenceAnn init_unc (reverse ts') + , cr_uncov = unc + , cr_approx = prec } + go ts' unc prec (t:ts) = do + CheckResult t' unc_1 prec_t <- checkGrdTree' t unc + go (t':ts') unc_1 (prec_t Semi.<> prec) ts -- | Print diagnostic info and actually call 'checkGrdTree''. checkGrdTree :: GrdTree -> Deltas -> DsM CheckResult @@ -1116,8 +1139,7 @@ redundantAndInaccessibleRhss tree = (fromOL ol_red, fromOL ol_inacc) (acc, inacc, red) | isNilOL acc && isNilOL inacc -> (nilOL, red, nilOL) res -> res - go (SequenceAnn l r) = go l Semi.<> go r - go EmptyAnn = (nilOL, nilOL, nilOL) + go (SequenceAnn _ ts) = foldMap go ts {- Note [Determining inaccessible clauses] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/HsToCore/PmCheck/Oracle.hs ===================================== @@ -1069,7 +1069,8 @@ ensureAllPossibleMatchesInhabited delta at MkDelta{ delta_tm_st = TmSt env reps } = runMaybeT (set_tm_cs_env delta <$> traverseSDIE go env) where set_tm_cs_env delta env = delta{ delta_tm_st = TmSt env reps } - go vi = MaybeT (ensureInhabited delta vi) + go vi = MaybeT $ + initPossibleMatches (delta_ty_st delta) vi >>= ensureInhabited delta -------------------------------------- -- * Term oracle unification procedure @@ -1667,7 +1668,7 @@ addCoreCt :: Delta -> Id -> CoreExpr -> MaybeT DsM Delta addCoreCt delta x e = do dflags <- getDynFlags let e' = simpleOptExpr dflags e - lift $ tracePm "addCoreCt" (ppr x $$ ppr e $$ ppr e') + lift $ tracePm "addCoreCt" (ppr x <+> dcolon <+> ppr (idType x) $$ ppr e $$ ppr e') execStateT (core_expr x e') delta where -- | Takes apart a 'CoreExpr' and tries to extract as much information about ===================================== compiler/GHC/Tc/Errors/Hole.hs ===================================== @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ExistentialQuantification #-} {-# OPTIONS_GHC -Wno-incomplete-record-updates #-} @@ -778,7 +779,9 @@ tcFilterHoleFits limit typed_hole ht@(hole_ty, _) candidates = Just (dataConWrapId con, dataConNonlinearType con) _ -> Nothing } where name = case hfc of +#if __GLASGOW_HASKELL__ <= 810 IdHFCand id -> idName id +#endif GreHFCand gre -> gre_name gre NameHFCand name -> name discard_it = go subs seen maxleft ty elts ===================================== compiler/GHC/Tc/Gen/HsType.hs ===================================== @@ -1078,7 +1078,9 @@ tc_hs_type mode rn_ty@(HsTupleTy _ hs_tup_sort tys) exp_kind HsUnboxedTuple -> UnboxedTuple HsBoxedTuple -> BoxedTuple HsConstraintTuple -> ConstraintTuple +#if __GLASGOW_HASKELL__ <= 810 _ -> panic "tc_hs_type HsTupleTy" +#endif tc_hs_type mode rn_ty@(HsSumTy _ hs_tys) exp_kind = do { let arity = length hs_tys ===================================== testsuite/tests/pmcheck/should_compile/T18533.hs ===================================== @@ -0,0 +1,24 @@ +{-# OPTIONS_GHC -Wincomplete-patterns -fforce-recomp #-} +{-# LANGUAGE GADTs, DataKinds, TypeFamilies, BangPatterns #-} + +module T18533 where + +data SBool (b :: Bool) where + STrue :: SBool 'True + SFalse :: SBool 'False + +type family Fam (b :: Bool) +type instance Fam 'True = T + +data T = T Bool + +f :: Fam b -> SBool b -> Bool +f !t s = case s of + STrue -> a where a = case t of T a -> a + _ -> False + + +g :: Bool -> Bool +g x = case x of + True -> a where a = case x of True -> False + False -> True ===================================== testsuite/tests/pmcheck/should_compile/all.T ===================================== @@ -122,6 +122,8 @@ test('T18049', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T18478', collect_compiler_stats('bytes allocated',10), compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) +test('T18533', normal, compile, + ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) # Other tests test('pmc001', [], compile, View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5b1e3a72e05867a26de5ea3efdfb101746492499 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5b1e3a72e05867a26de5ea3efdfb101746492499 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 12 12:52:28 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 12 Aug 2020 08:52:28 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 5 commits: DynFlags: disentangle Outputable Message-ID: <5f33e60c9797f_80b3f84693c1eb4779156@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - 44a28637 by Sylvain Henry at 2020-08-12T08:52:24-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 21428579 by Hécate at 2020-08-12T08:52:25-04:00 Re-add BangPatterns to CodePage.hs - - - - - a4a1660c by Hécate at 2020-08-12T08:52:25-04:00 fixup! Re-add BangPatterns to CodePage.hs - - - - - 30 changed files: - compiler/GHC.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - compiler/GHC/CmmToAsm/CPrim.hs - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Format.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/efab28daa8f790c65402c051e09264b4a3458da4...a4a1660cfea13d5b918c8d9240c76026c411b04e -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/efab28daa8f790c65402c051e09264b4a3458da4...a4a1660cfea13d5b918c8d9240c76026c411b04e You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 12 13:24:18 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Wed, 12 Aug 2020 09:24:18 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] Add WhatNext, WhyBlocked and TsoFlags Message-ID: <5f33ed824a144_80b3f8486b5b7c077997fe@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: 5291dd15 by Sven Tennie at 2020-08-12T15:24:05+02:00 Add WhatNext, WhyBlocked and TsoFlags Additionally extract TestUtils with common test functions. - - - - - 9 changed files: - libraries/ghc-heap/GHC/Exts/Heap.hs - libraries/ghc-heap/GHC/Exts/Heap/Closures.hs - libraries/ghc-heap/GHC/Exts/Heap/FFIClosures.hsc - + libraries/ghc-heap/tests/TestUtils.hs - libraries/ghc-heap/tests/all.T - libraries/ghc-heap/tests/list_threads_and_misc_roots.hs - libraries/ghc-heap/tests/prof_info.hs - libraries/ghc-heap/tests/tso_and_stack_closures.hs - libraries/ghci/GHCi/Message.hs Changes: ===================================== libraries/ghc-heap/GHC/Exts/Heap.hs ===================================== @@ -28,6 +28,9 @@ module GHC.Exts.Heap ( , GenClosure(..) , ClosureType(..) , PrimType(..) + , WhatNext(..) + , WhyBlocked(..) + , TsoFlags(..) , HasHeapRep(getClosureDataX) , getClosureData ===================================== libraries/ghc-heap/GHC/Exts/Heap/Closures.hs ===================================== @@ -12,6 +12,9 @@ module GHC.Exts.Heap.Closures ( Closure , GenClosure(..) , PrimType(..) + , WhatNext(..) + , WhyBlocked(..) + , TsoFlags(..) , allClosures #if __GLASGOW_HASKELL__ >= 809 -- The closureSize# primop is unsupported on earlier GHC releases but we @@ -283,9 +286,9 @@ data GenClosure b , blocked_exceptions :: !b , bq :: !b -- values - , what_next :: Word16 - , why_blocked :: Word16 - , flags :: Word32 + , what_next :: WhatNext + , why_blocked :: WhyBlocked + , flags :: [TsoFlags] , threadId :: Word64 , saved_errno :: Word32 , tso_dirty:: Word32 -- ^ non-zero => dirty @@ -373,6 +376,43 @@ data PrimType | PDouble deriving (Eq, Show, Generic) +data WhatNext + = ThreadRunGHC + | ThreadInterpret + | ThreadKilled + | ThreadComplete + | WhatNextUnknownValue -- ^ Please report this as a bug + deriving (Eq, Show, Generic) + +data WhyBlocked + = NotBlocked + | BlockedOnMVar + | BlockedOnMVarRead + | BlockedOnBlackHole + | BlockedOnRead + | BlockedOnWrite + | BlockedOnDelay + | BlockedOnSTM + | BlockedOnDoProc + | BlockedOnCCall + | BlockedOnCCall_Interruptible + | BlockedOnMsgThrowTo + | ThreadMigrating + | BlockedOnIOCompletion + | WhyBlockedUnknownValue -- ^ Please report this as a bug + deriving (Eq, Show, Generic) + +data TsoFlags + = TsoLocked + | TsoBlockx + | TsoInterruptible + | TsoStoppedOnBreakpoint + | TsoMarked + | TsoSqueezed + | TsoAllocLimit + | TsoFlagsUnknownValue -- ^ Please report this as a bug + deriving (Eq, Show, Generic) + -- | For generic code, this function returns all referenced closures. allClosures :: GenClosure b -> [b] allClosures (ConstrClosure {..}) = ptrArgs ===================================== libraries/ghc-heap/GHC/Exts/Heap/FFIClosures.hsc ===================================== @@ -6,13 +6,14 @@ module GHC.Exts.Heap.FFIClosures where import Prelude import Foreign import GHC.Exts.Heap.ProfInfo.Types +import GHC.Exts.Heap.Closures(WhatNext(..), WhyBlocked(..), TsoFlags(..)) -- TODO use sum type for what_next, why_blocked, flags? data TSOFields = TSOFields { - tso_what_next :: Word16, - tso_why_blocked :: Word16, - tso_flags :: Word32, + tso_what_next :: WhatNext, + tso_why_blocked :: WhyBlocked, + tso_flags :: [TsoFlags], -- Unfortunately block_info is a union without clear discriminator. -- block_info :: TDB, tso_threadId :: Word64, @@ -39,17 +40,50 @@ peekTSOFields peekProfInfo ptr = do tso_prof' <- peekProfInfo ptr return TSOFields { - tso_what_next = what_next', - tso_why_blocked = why_blocked', - tso_flags = flags', + tso_what_next = parseWhatNext what_next', + tso_why_blocked = parseWhyBlocked why_blocked', + tso_flags = parseTsoFlags flags', tso_threadId = threadId', tso_saved_errno = saved_errno', - tso_dirty= dirty', + tso_dirty = dirty', tso_alloc_limit = alloc_limit', tso_tot_stack_size = tot_stack_size', tso_prof = tso_prof' } +parseWhatNext :: Word16 -> WhatNext +parseWhatNext w = case w of + (#const ThreadRunGHC) -> ThreadRunGHC + (#const ThreadInterpret) -> ThreadInterpret + (#const ThreadKilled) -> ThreadKilled + (#const ThreadComplete) -> ThreadComplete + _ -> WhatNextUnknownValue + +-- TODO: define mapping +parseWhyBlocked :: Word16 -> WhyBlocked +parseWhyBlocked w = case w of + (#const NotBlocked) -> NotBlocked + (#const BlockedOnMVar) -> BlockedOnMVar + (#const BlockedOnMVarRead) -> BlockedOnMVarRead + (#const BlockedOnBlackHole) -> BlockedOnBlackHole + (#const BlockedOnRead) -> BlockedOnRead + (#const BlockedOnWrite) -> BlockedOnWrite + (#const BlockedOnDelay) -> BlockedOnDelay + (#const BlockedOnSTM) -> BlockedOnSTM + (#const BlockedOnDoProc) -> BlockedOnDoProc + (#const BlockedOnCCall) -> BlockedOnCCall + (#const BlockedOnCCall_Interruptible) -> BlockedOnCCall_Interruptible + (#const BlockedOnMsgThrowTo) -> BlockedOnMsgThrowTo + (#const ThreadMigrating) -> ThreadMigrating +#if __GLASGOW_HASKELL__ >= 810 + (#const BlockedOnIOCompletion) -> BlockedOnIOCompletion +#endif + _ -> WhyBlockedUnknownValue + +-- TODO: define mapping +parseTsoFlags :: Word32 -> [TsoFlags] +parseTsoFlags _ = [] + data StackFields = StackFields { stack_size :: Word32, stack_dirty :: Word8, ===================================== libraries/ghc-heap/tests/TestUtils.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE MagicHash #-} +module TestUtils where + +import GHC.Exts.Heap (getClosureData, LiftedClosure, Box, GenClosure) +import Foreign (Ptr) +import GHC.Exts (Ptr, Addr#, unsafeCoerce#) +import GHC.Ptr (Ptr(Ptr)) + +assertEqual :: (Show a, Eq a) => a -> a -> IO () +assertEqual a b + | a /= b = error (show a ++ " /= " ++ show b) + | otherwise = return () + +createClosure :: Ptr () -> IO (GenClosure Box) +createClosure tsoPtr = do + let addr = unpackAddr# tsoPtr + getClosureData ((unsafeCoerce# addr) :: LiftedClosure) + +unpackAddr# :: Ptr () -> Addr# +unpackAddr# (Ptr addr) = addr ===================================== libraries/ghc-heap/tests/all.T ===================================== @@ -37,21 +37,21 @@ test('closure_size_noopt', compile_and_run, ['']) test('tso_and_stack_closures', - [extra_files(['create_tso.c','create_tso.h']), + [extra_files(['create_tso.c','create_tso.h', 'TestUtils.hs']), ignore_stdout, ignore_stderr ], multi_compile_and_run, ['tso_and_stack_closures', [('create_tso.c','')], '']) test('list_threads_and_misc_roots', - [extra_files(['list_threads_and_misc_roots_c.c','list_threads_and_misc_roots_c.h']), + [extra_files(['list_threads_and_misc_roots_c.c','list_threads_and_misc_roots_c.h','TestUtils.hs']), ignore_stdout, ignore_stderr ], multi_compile_and_run, ['list_threads_and_misc_roots', [('list_threads_and_misc_roots_c.c','')], '-threaded']) test('prof_info', - [extra_files(['create_tso.c','create_tso.h']), + [extra_files(['create_tso.c','create_tso.h','TestUtils.hs']), ignore_stdout, ignore_stderr, when(have_profiling(), extra_ways(['prof'])), ===================================== libraries/ghc-heap/tests/list_threads_and_misc_roots.hs ===================================== @@ -7,6 +7,8 @@ import Control.Concurrent import GHC.Exts.Heap import GHC.Exts +import TestUtils + foreign import ccall safe "list_threads_and_misc_roots_c.h listThreadsAndMiscRoots" listThreadsAndMiscRoots_c :: IO () @@ -44,19 +46,6 @@ main = do return () -createClosure :: Ptr () -> IO (GenClosure Box) -createClosure tsoPtr = do - let addr = unpackAddr# tsoPtr - getClosureData ((unsafeCoerce# addr) :: LiftedClosure) - -unpackAddr# :: Ptr () -> Addr# -unpackAddr# (Ptr addr) = addr - -assertEqual :: (Show a, Eq a) => a -> a -> IO () -assertEqual a b - | a /= b = error (show a ++ " /= " ++ show b) - | otherwise = return () - assertIsClosureType :: ClosureType -> IO () assertIsClosureType t | t `elem` enumerate = return () ===================================== libraries/ghc-heap/tests/prof_info.hs ===================================== @@ -10,6 +10,8 @@ import Data.Functor import GHC.Word import Data.List (find) +import TestUtils + #include "ghcconfig.h" #include "rts/Constants.h" @@ -35,25 +37,17 @@ main = do Nothing -> error $ "No CostCentre found in TSO: " ++ show tso Just _ -> case findMyCostCentre (linkedCostCentres costCentre) of Just myCostCentre -> do - assertEqual (cc_ccID myCostCentre) 1 assertEqual (cc_label myCostCentre) "MyCostCentre" assertEqual (cc_module myCostCentre) "Main" - assertEqual (cc_srcloc myCostCentre) (Just "prof_info.hs:21:39-50") + assertEqual (cc_srcloc myCostCentre) (Just "prof_info.hs:23:39-50") assertEqual (cc_mem_alloc myCostCentre) 0 assertEqual (cc_time_ticks myCostCentre) 0 assertEqual (cc_is_caf myCostCentre) False - assertEqual (cc_link myCostCentre) Nothing Nothing -> error "MyCostCentre not found!" -unpackAddr# :: Ptr () -> Addr# -unpackAddr# (Ptr addr) = addr - linkedCostCentres :: Maybe CostCentre -> [CostCentre] linkedCostCentres Nothing = [] linkedCostCentres (Just cc) = cc : linkedCostCentres (cc_link cc) findMyCostCentre:: [CostCentre] -> Maybe CostCentre findMyCostCentre ccs = find (\cc -> cc_label cc == "MyCostCentre") ccs - -assertEqual :: (Eq a, Show a) => a -> a -> IO () -assertEqual x y = if x == y then return () else error $ "assertEqual: " ++ show x ++ " /= " ++ show y ===================================== libraries/ghc-heap/tests/tso_and_stack_closures.hs ===================================== @@ -1,4 +1,4 @@ -{-# LANGUAGE ForeignFunctionInterface, MagicHash, CPP, BangPatterns #-} +{-# LANGUAGE ForeignFunctionInterface, MagicHash, BangPatterns #-} import Foreign import Foreign.C.Types @@ -7,8 +7,7 @@ import GHC.Exts import GHC.Word -#include "ghcconfig.h" -#include "rts/Constants.h" +import TestUtils foreign import ccall unsafe "create_tso.h create_tso" c_create_tso:: IO (Ptr ()) @@ -55,16 +54,7 @@ main = do createTSOClosure :: IO (GenClosure Box) createTSOClosure = do ptr <- c_create_tso - let addr = unpackAddr# ptr - getClosureData ((unsafeCoerce# addr) :: LiftedClosure) - -unpackAddr# :: Ptr () -> Addr# -unpackAddr# (Ptr addr) = addr - -assertEqual :: (Show a, Eq a) => a -> a -> IO () -assertEqual a b - | a /= b = error (show a ++ " /= " ++ show b) - | otherwise = return () + createClosure ptr getClosureType :: GenClosure b -> ClosureType getClosureType = tipe . info ===================================== libraries/ghci/GHCi/Message.hs ===================================== @@ -455,6 +455,9 @@ instance Binary Heap.StgTSOProfInfo instance Binary Heap.CostCentreStack instance Binary Heap.CostCentre instance Binary Heap.IndexTable +instance Binary Heap.WhatNext +instance Binary Heap.WhyBlocked +instance Binary Heap.TsoFlags #endif instance Binary Heap.StgInfoTable View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5291dd1525692f5a9cc0613a6a85c94143c5639d -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5291dd1525692f5a9cc0613a6a85c94143c5639d You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 12 16:50:01 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Wed, 12 Aug 2020 12:50:01 -0400 Subject: [Git][ghc/ghc][wip/T18533] PmCheck: Better long-distance info for where bindings (#18533) Message-ID: <5f341db92e427_80b3f8495bc8b047832066@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18533 at Glasgow Haskell Compiler / GHC Commits: 2d93ea2e by Sebastian Graf at 2020-08-12T18:49:51+02:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - 15 changed files: - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Core/Coercion/Opt.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/GuardedRHSs.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/Monad.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - compiler/GHC/Tc/Errors/Hole.hs - compiler/GHC/Tc/Gen/HsType.hs - + testsuite/tests/pmcheck/should_compile/T18533.hs - testsuite/tests/pmcheck/should_compile/all.T Changes: ===================================== compiler/GHC/Cmm/DebugBlock.hs ===================================== @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiWayIf #-} @@ -109,7 +110,9 @@ cmmDebugGen modLoc decls = map (blocksForScope Nothing) topScopes -- recover by copying ticks below. scp' | SubScope _ scp' <- scp = scp' | CombinedScope scp' _ <- scp = scp' +#if __GLASGOW_HASKELL__ <= 810 | otherwise = panic "findP impossible" +#endif scopeMap = foldr (uncurry insertMulti) Map.empty childScopes ===================================== compiler/GHC/Core/Coercion/Opt.hs ===================================== @@ -555,7 +555,10 @@ opt_univ env sym prov role oty1 oty2 where prov' = case prov of +#if __GLASGOW_HASKELL__ <= 810 +-- This alt is redundant with the first match of the FunDef PhantomProv kco -> PhantomProv $ opt_co4_wrap env sym False Nominal kco +#endif ProofIrrelProv kco -> ProofIrrelProv $ opt_co4_wrap env sym False Nominal kco PluginProv _ -> prov ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -1242,7 +1242,9 @@ ppr_infix_expr (HsConLikeOut _ c) = Just (pprInfixOcc (conLikeName c)) ppr_infix_expr (HsRecFld _ f) = Just (pprInfixOcc f) ppr_infix_expr (HsUnboundVar _ occ) = Just (pprInfixOcc occ) ppr_infix_expr (XExpr x) = case (ghcPass @p, x) of +#if __GLASGOW_HASKELL__ <= 810 (GhcPs, _) -> Nothing +#endif (GhcRn, HsExpanded a _) -> ppr_infix_expr a (GhcTc, WrapExpr (HsWrap _ e)) -> ppr_infix_expr e (GhcTc, ExpansionExpr (HsExpanded a _)) -> ppr_infix_expr a ===================================== compiler/GHC/Hs/Pat.hs ===================================== @@ -845,8 +845,10 @@ patNeedsParens p = go go (SigPat {}) = p >= sigPrec go (ViewPat {}) = True go (XPat ext) = case ghcPass @p of +#if __GLASGOW_HASKELL__ <= 810 GhcPs -> noExtCon ext GhcRn -> noExtCon ext +#endif GhcTc -> go inner where CoPat _ inner _ = ext go (WildPat {}) = False ===================================== compiler/GHC/HsToCore/Binds.hs ===================================== @@ -33,7 +33,7 @@ import {-# SOURCE #-} GHC.HsToCore.Match ( matchWrapper ) import GHC.HsToCore.Monad import GHC.HsToCore.GuardedRHSs import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck ( addTyCsDs, checkGuardMatches ) +import GHC.HsToCore.PmCheck ( addTyCsDs, checkGRHSs ) import GHC.Hs -- lots of things import GHC.Core -- lots of things @@ -76,7 +76,6 @@ import GHC.Types.Unique.Set( nonDetEltsUniqSet ) import GHC.Utils.Monad import qualified GHC.LanguageExtensions as LangExt import Control.Monad -import Data.List.NonEmpty ( nonEmpty ) {-********************************************************************** * * @@ -183,8 +182,8 @@ dsHsBind dflags b@(FunBind { fun_id = L loc fun dsHsBind dflags (PatBind { pat_lhs = pat, pat_rhs = grhss , pat_ext = NPatBindTc _ ty , pat_ticks = (rhs_tick, var_ticks) }) - = do { rhss_deltas <- checkGuardMatches PatBindGuards grhss - ; body_expr <- dsGuarded grhss ty (nonEmpty rhss_deltas) + = do { rhss_deltas <- checkGRHSs PatBindGuards grhss + ; body_expr <- dsGuarded grhss ty rhss_deltas ; let body' = mkOptTickBox rhs_tick body_expr pat' = decideBangHood dflags pat ; (force_var,sel_binds) <- mkSelectorBinds var_ticks pat body' ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -31,7 +31,7 @@ import GHC.HsToCore.ListComp import GHC.HsToCore.Utils import GHC.HsToCore.Arrows import GHC.HsToCore.Monad -import GHC.HsToCore.PmCheck ( addTyCsDs, checkGuardMatches ) +import GHC.HsToCore.PmCheck ( addTyCsDs, checkGRHSs ) import GHC.Types.Name import GHC.Types.Name.Env import GHC.Core.FamInstEnv( topNormaliseType ) @@ -69,7 +69,6 @@ import GHC.Utils.Outputable as Outputable import GHC.Core.PatSyn import Control.Monad -import Data.List.NonEmpty ( nonEmpty ) {- ************************************************************************ @@ -215,8 +214,8 @@ dsUnliftedBind (PatBind {pat_lhs = pat, pat_rhs = grhss , pat_ext = NPatBindTc _ ty }) body = -- let C x# y# = rhs in body -- ==> case rhs of C x# y# -> body - do { rhs_deltas <- checkGuardMatches PatBindGuards grhss - ; rhs <- dsGuarded grhss ty (nonEmpty rhs_deltas) + do { match_deltas <- checkGRHSs PatBindGuards grhss + ; rhs <- dsGuarded grhss ty match_deltas ; let upat = unLoc pat eqn = EqnInfo { eqn_pats = [upat], eqn_orig = FromSource, @@ -486,8 +485,8 @@ dsExpr (HsMultiIf res_ty alts) | otherwise = do { let grhss = GRHSs noExtField alts (noLoc emptyLocalBinds) - ; rhss_deltas <- checkGuardMatches IfAlt grhss - ; match_result <- dsGRHSs IfAlt grhss res_ty (nonEmpty rhss_deltas) + ; rhss_deltas <- checkGRHSs IfAlt grhss + ; match_result <- dsGRHSs IfAlt grhss res_ty rhss_deltas ; error_expr <- mkErrorExpr ; extractMatchResult match_result error_expr } where ===================================== compiler/GHC/HsToCore/GuardedRHSs.hs ===================================== @@ -25,7 +25,7 @@ import GHC.Core.Utils (bindNonRec) import GHC.HsToCore.Monad import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck.Types ( Deltas, initDeltas ) +import GHC.HsToCore.PmCheck.Types ( Deltas ) import GHC.Core.Type ( Type ) import GHC.Utils.Misc import GHC.Types.SrcLoc @@ -47,9 +47,9 @@ producing an expression with a runtime error in the corner if necessary. The type argument gives the type of the @ei at . -} -dsGuarded :: GRHSs GhcTc (LHsExpr GhcTc) -> Type -> Maybe (NonEmpty Deltas) -> DsM CoreExpr -dsGuarded grhss rhs_ty mb_rhss_deltas = do - match_result <- dsGRHSs PatBindRhs grhss rhs_ty mb_rhss_deltas +dsGuarded :: GRHSs GhcTc (LHsExpr GhcTc) -> Type -> NonEmpty Deltas -> DsM CoreExpr +dsGuarded grhss rhs_ty rhss_deltas = do + match_result <- dsGRHSs PatBindRhs grhss rhs_ty rhss_deltas error_expr <- mkErrorAppDs nON_EXHAUSTIVE_GUARDS_ERROR_ID rhs_ty empty extractMatchResult match_result error_expr @@ -58,25 +58,28 @@ dsGuarded grhss rhs_ty mb_rhss_deltas = do dsGRHSs :: HsMatchContext GhcRn -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ Guarded RHSs -> Type -- ^ Type of RHS - -> Maybe (NonEmpty Deltas) -- ^ Refined pattern match checking - -- models, one for each GRHS. Defaults - -- to 'initDeltas' if 'Nothing'. + -> NonEmpty Deltas -- ^ Refined pattern match checking + -- models, one for the pattern part and + -- one for each GRHS. -> DsM (MatchResult CoreExpr) -dsGRHSs hs_ctx (GRHSs _ grhss binds) rhs_ty mb_rhss_deltas +dsGRHSs hs_ctx (GRHSs _ grhss binds) rhs_ty rhss_deltas = ASSERT( notNull grhss ) - do { match_results <- case toList <$> mb_rhss_deltas of - Nothing -> mapM (dsGRHS hs_ctx rhs_ty initDeltas) grhss - Just rhss_deltas -> ASSERT( length grhss == length rhss_deltas ) - zipWithM (dsGRHS hs_ctx rhs_ty) rhss_deltas grhss - ; let match_result1 = foldr1 combineMatchResults match_results - match_result2 = adjustMatchResultDs (dsLocalBinds binds) match_result1 + do { match_results <- ASSERT( length grhss == length rhss_deltas ) + zipWithM (dsGRHS hs_ctx rhs_ty) (toList rhss_deltas) grhss + ; deltas <- getPmDeltas + -- We need to remember the Deltas from the particular match context we + -- are in, which might be different to when dsLocalBinds is actually + -- called. + ; let ds_binds = updPmDeltas deltas . dsLocalBinds binds + match_result1 = foldr1 combineMatchResults match_results + match_result2 = adjustMatchResultDs ds_binds match_result1 -- NB: nested dsLet inside matchResult ; return match_result2 } dsGRHS :: HsMatchContext GhcRn -> Type -> Deltas -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM (MatchResult CoreExpr) dsGRHS hs_ctx rhs_ty rhs_deltas (L _ (GRHS _ guards rhs)) - = updPmDeltas rhs_deltas (matchGuards (map unLoc guards) (PatGuard hs_ctx) rhs rhs_ty) + = matchGuards (map unLoc guards) (PatGuard hs_ctx) rhs_deltas rhs rhs_ty {- ************************************************************************ @@ -88,6 +91,7 @@ dsGRHS hs_ctx rhs_ty rhs_deltas (L _ (GRHS _ guards rhs)) matchGuards :: [GuardStmt GhcTc] -- Guard -> HsStmtContext GhcRn -- Context + -> Deltas -- The RHS's covered set for PmCheck -> LHsExpr GhcTc -- RHS -> Type -- Type of RHS of guard -> DsM (MatchResult CoreExpr) @@ -95,8 +99,8 @@ matchGuards :: [GuardStmt GhcTc] -- Guard -- See comments with HsExpr.Stmt re what a BodyStmt means -- Here we must be in a guard context (not do-expression, nor list-comp) -matchGuards [] _ rhs _ - = do { core_rhs <- dsLExpr rhs +matchGuards [] _ deltas rhs _ + = do { core_rhs <- updPmDeltas deltas (dsLExpr rhs) ; return (cantFailMatchResult core_rhs) } -- BodyStmts must be guards @@ -106,41 +110,41 @@ matchGuards [] _ rhs _ -- NB: The success of this clause depends on the typechecker not -- wrapping the 'otherwise' in empty HsTyApp or HsWrap constructors -- If it does, you'll get bogus overlap warnings -matchGuards (BodyStmt _ e _ _ : stmts) ctx rhs rhs_ty +matchGuards (BodyStmt _ e _ _ : stmts) ctx deltas rhs rhs_ty | Just addTicks <- isTrueLHsExpr e = do - match_result <- matchGuards stmts ctx rhs rhs_ty + match_result <- matchGuards stmts ctx deltas rhs rhs_ty return (adjustMatchResultDs addTicks match_result) -matchGuards (BodyStmt _ expr _ _ : stmts) ctx rhs rhs_ty = do - match_result <- matchGuards stmts ctx rhs rhs_ty +matchGuards (BodyStmt _ expr _ _ : stmts) ctx deltas rhs rhs_ty = do + match_result <- matchGuards stmts ctx deltas rhs rhs_ty pred_expr <- dsLExpr expr return (mkGuardedMatchResult pred_expr match_result) -matchGuards (LetStmt _ binds : stmts) ctx rhs rhs_ty = do - match_result <- matchGuards stmts ctx rhs rhs_ty +matchGuards (LetStmt _ binds : stmts) ctx deltas rhs rhs_ty = do + match_result <- matchGuards stmts ctx deltas rhs rhs_ty return (adjustMatchResultDs (dsLocalBinds binds) match_result) -- NB the dsLet occurs inside the match_result -- Reason: dsLet takes the body expression as its argument -- so we can't desugar the bindings without the -- body expression in hand -matchGuards (BindStmt _ pat bind_rhs : stmts) ctx rhs rhs_ty = do +matchGuards (BindStmt _ pat bind_rhs : stmts) ctx deltas rhs rhs_ty = do let upat = unLoc pat match_var <- selectMatchVar Many upat -- We only allow unrestricted patterns in guard, hence the `Many` -- above. It isn't clear what linear patterns would mean, maybe we will -- figure it out in the future. - match_result <- matchGuards stmts ctx rhs rhs_ty + match_result <- matchGuards stmts ctx deltas rhs rhs_ty core_rhs <- dsLExpr bind_rhs match_result' <- matchSinglePatVar match_var (StmtCtxt ctx) pat rhs_ty match_result pure $ bindNonRec match_var core_rhs <$> match_result' -matchGuards (LastStmt {} : _) _ _ _ = panic "matchGuards LastStmt" -matchGuards (ParStmt {} : _) _ _ _ = panic "matchGuards ParStmt" -matchGuards (TransStmt {} : _) _ _ _ = panic "matchGuards TransStmt" -matchGuards (RecStmt {} : _) _ _ _ = panic "matchGuards RecStmt" -matchGuards (ApplicativeStmt {} : _) _ _ _ = +matchGuards (LastStmt {} : _) _ _ _ _ = panic "matchGuards LastStmt" +matchGuards (ParStmt {} : _) _ _ _ _ = panic "matchGuards ParStmt" +matchGuards (TransStmt {} : _) _ _ _ _ = panic "matchGuards TransStmt" +matchGuards (RecStmt {} : _) _ _ _ _ = panic "matchGuards RecStmt" +matchGuards (ApplicativeStmt {} : _) _ _ _ _ = panic "matchGuards ApplicativeLastStmt" {- ===================================== compiler/GHC/HsToCore/Match.hs ===================================== @@ -35,6 +35,7 @@ import GHC.Tc.Utils.Zonk import GHC.Tc.Types.Evidence import GHC.Tc.Utils.Monad import GHC.HsToCore.PmCheck +import GHC.HsToCore.PmCheck.Types ( Deltas, initDeltas ) import GHC.Core import GHC.Types.Literal import GHC.Core.Utils @@ -64,7 +65,7 @@ import GHC.Data.FastString import GHC.Types.Unique import GHC.Types.Unique.DFM -import Control.Monad( unless ) +import Control.Monad(zipWithM, unless ) import Data.List.NonEmpty (NonEmpty(..)) import qualified Data.List.NonEmpty as NEL import qualified Data.Map as Map @@ -766,49 +767,47 @@ matchWrapper ctxt mb_scr (MG { mg_alts = L _ matches -- Pattern match check warnings for /this match-group/. -- @rhss_deltas@ is a flat list of covered Deltas for each RHS. -- Each Match will split off one Deltas for its RHSs from this. - ; rhss_deltas <- if isMatchContextPmChecked dflags origin ctxt + ; matches_deltas <- if isMatchContextPmChecked dflags origin ctxt then addScrutTmCs mb_scr new_vars $ - -- See Note [Type and Term Equality Propagation] - checkMatches (DsMatchContext ctxt locn) new_vars matches - else pure [] -- Ultimately this will result in passing Nothing - -- to dsGRHSs as match_deltas + -- See Note [Type and Term Equality Propagation] + checkMatches (DsMatchContext ctxt locn) new_vars matches + else pure (initDeltasMatches matches) - ; eqns_info <- mk_eqn_infos matches rhss_deltas + ; eqns_info <- zipWithM mk_eqn_info matches matches_deltas ; result_expr <- handleWarnings $ matchEquations ctxt new_vars eqns_info rhs_ty ; return (new_vars, result_expr) } where - -- rhss_deltas is a flat list, whereas there are multiple GRHSs per match. - -- mk_eqn_infos will thread rhss_deltas as state through calls to - -- mk_eqn_info, distributing each rhss_deltas to a GRHS. - mk_eqn_infos (L _ match : matches) rhss_deltas - = do { (info, rhss_deltas') <- mk_eqn_info match rhss_deltas - ; infos <- mk_eqn_infos matches rhss_deltas' - ; return (info:infos) } - mk_eqn_infos [] _ = return [] -- Called once per equation in the match, or alternative in the case - mk_eqn_info (Match { m_pats = pats, m_grhss = grhss }) rhss_deltas - | GRHSs _ grhss' _ <- grhss, let n_grhss = length grhss' + mk_eqn_info :: LMatch GhcTc (LHsExpr GhcTc) -> (Deltas, NonEmpty Deltas) -> DsM EquationInfo + mk_eqn_info (L _ (Match { m_pats = pats, m_grhss = grhss })) (pat_deltas, rhss_deltas) = do { dflags <- getDynFlags ; let upats = map (unLoc . decideBangHood dflags) pats - -- Split off one Deltas for each GRHS of the current Match from the - -- flat list of GRHS Deltas *for all matches* (see the call to - -- checkMatches above). - ; let (match_deltas, rhss_deltas') = splitAt n_grhss rhss_deltas - -- The list of Deltas is empty iff we don't perform any coverage - -- checking, in which case nonEmpty does the right thing by passing - -- Nothing. - ; match_result <- dsGRHSs ctxt grhss rhs_ty (NEL.nonEmpty match_deltas) - ; return ( EqnInfo { eqn_pats = upats - , eqn_orig = FromSource - , eqn_rhs = match_result } - , rhss_deltas' ) } + -- pat_deltas is the covered set *after* matching the pattern, but + -- before any of the GRHSs. We extend the environment with pat_deltas + -- (via updPmDeltas) so that the where-clause of 'grhss' can profit + -- from that knowledge (#18533) + ; match_result <- updPmDeltas pat_deltas $ + dsGRHSs ctxt grhss rhs_ty rhss_deltas + ; return EqnInfo { eqn_pats = upats + , eqn_orig = FromSource + , eqn_rhs = match_result } } handleWarnings = if isGenerated origin then discardWarningsDs else id + initDeltasMatches :: [LMatch GhcTc b] -> [(Deltas, NonEmpty Deltas)] + initDeltasMatches ms + = map (\(L _ m) -> (initDeltas, initDeltasGRHSs (m_grhss m))) ms + + initDeltasGRHSs :: GRHSs GhcTc b -> NonEmpty Deltas + initDeltasGRHSs m = expectJust "GRHSs non-empty" + $ NEL.nonEmpty + $ replicate (length (grhssGRHSs m)) initDeltas + + matchEquations :: HsMatchContext GhcRn -> [MatchId] -> [EquationInfo] -> Type -> DsM CoreExpr ===================================== compiler/GHC/HsToCore/Monad.hs ===================================== @@ -405,7 +405,7 @@ getPmDeltas = do { env <- getLclEnv; return (dsl_deltas env) } -- | Set the pattern match oracle state within the scope of the given action. -- See 'dsl_deltas'. updPmDeltas :: Deltas -> DsM a -> DsM a -updPmDeltas delta = updLclEnv (\env -> env { dsl_deltas = delta }) +updPmDeltas deltas = updLclEnv (\env -> env { dsl_deltas = deltas }) getSrcSpanDs :: DsM SrcSpan getSrcSpanDs = do { env <- getLclEnv ===================================== compiler/GHC/HsToCore/PmCheck.hs ===================================== @@ -13,7 +13,7 @@ Pattern Matching Coverage Checking. module GHC.HsToCore.PmCheck ( -- Checking and printing - checkSingle, checkMatches, checkGuardMatches, + checkSingle, checkMatches, checkGRHSs, isMatchContextPmChecked, -- See Note [Type and Term Equality Propagation] @@ -65,6 +65,7 @@ import GHC.Utils.Monad (concatMapM) import Control.Monad (when, forM_, zipWithM) import Data.List (elemIndex) import qualified Data.Semigroup as Semi +import Data.List.NonEmpty (NonEmpty(..)) {- This module checks pattern matches for: @@ -149,13 +150,11 @@ data GrdTree -- ^ @Guard grd t@ will try to match @grd@ and on success continue to match -- @t at . Falls through if either match fails. Models left-to-right semantics -- of pattern matching. - | Sequence !GrdTree !GrdTree - -- ^ @Sequence l r@ first matches against @l@, and then matches all - -- fallen-through values against @r at . Models top-to-bottom semantics of - -- pattern matching. - | Empty - -- ^ A @GrdTree@ that always fails. Most useful for - -- Note [Checking EmptyCase]. A neutral element to 'Sequence'. + | Sequence ![GrdTree] + -- ^ @Sequence (t:ts)@ matches against @t@, and then matches all + -- fallen-through values against @Sequence ts at . Models top-to-bottom semantics + -- of pattern matching. + -- @Sequence []@ always fails; it is useful for Note [Checking EmptyCase]. -- | The digest of 'checkGrdTree', representing the annotated pattern-match -- tree. 'redundantAndInaccessibleRhss' can figure out redundant and proper @@ -169,10 +168,10 @@ data AnnotatedTree | MayDiverge !AnnotatedTree -- ^ Asserts that the tree may force diverging values, so not all of its -- clauses can be redundant. - | SequenceAnn !AnnotatedTree !AnnotatedTree - -- ^ Mirrors 'Sequence' for preserving the skeleton of a 'GrdTree's. - | EmptyAnn - -- ^ Mirrors 'Empty' for preserving the skeleton of a 'GrdTree's. + | SequenceAnn !Deltas ![AnnotatedTree] + -- ^ @SequenceAnn inc ts@ mirrors @'Sequence' ts@ for preserving the + -- skeleton of a 'GrdTree's @ts at . It also carries the set of incoming values + -- @inc at . pprRhsInfo :: RhsInfo -> SDoc pprRhsInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) @@ -188,23 +187,15 @@ instance Outputable GrdTree where collect_grds t = (t, []) prefix [] = [] prefix (s:sdocs) = char '|' <+> s : map (comma <+>) sdocs - -- Format nested Sequences in blocks "{ grds1; grds2; ... }" - ppr t at Sequence{} = braces (space <> fsep (punctuate semi (collect_seqs t)) <> space) - where - collect_seqs (Sequence l r) = collect_seqs l ++ collect_seqs r - collect_seqs t = [ppr t] - ppr Empty = text "" + ppr (Sequence []) = text "" + ppr (Sequence ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) instance Outputable AnnotatedTree where - ppr (AccessibleRhs _ info) = pprRhsInfo info + ppr (AccessibleRhs _delta info) = parens (ppr _delta) <+> pprRhsInfo info ppr (InaccessibleRhs info) = text "inaccessible" <+> pprRhsInfo info ppr (MayDiverge t) = text "div" <+> ppr t - -- Format nested Sequences in blocks "{ grds1; grds2; ... }" - ppr t at SequenceAnn{} = braces (space <> fsep (punctuate semi (collect_seqs t)) <> space) - where - collect_seqs (SequenceAnn l r) = collect_seqs l ++ collect_seqs r - collect_seqs t = [ppr t] - ppr EmptyAnn = text "" + ppr (SequenceAnn _ []) = text "" + ppr (SequenceAnn _ ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) -- | Lift 'addPmCts' over 'Deltas'. addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas @@ -263,7 +254,7 @@ checkSingle dflags ctxt@(DsMatchContext kind locn) var p = do -- Omitting checking this flag emits redundancy warnings twice in obscure -- cases like #17646. when (exhaustive dflags kind) $ do - -- TODO: This could probably call checkMatches, like checkGuardMatches. + -- TODO: This could probably call checkMatches, like checkGRHSs. missing <- getPmDeltas tracePm "checkSingle: missing" (ppr missing) fam_insts <- dsGetFamInstEnvs @@ -273,12 +264,12 @@ checkSingle dflags ctxt@(DsMatchContext kind locn) var p = do -- | Exhaustive for guard matches, is used for guards in pattern bindings and -- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. -checkGuardMatches +checkGRHSs :: HsMatchContext GhcRn -- ^ Match context, for warning messages -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check - -> DsM [Deltas] -- ^ Covered 'Deltas' for each RHS, for long + -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long -- distance info -checkGuardMatches hs_ctx guards@(GRHSs _ grhss _) = do +checkGRHSs hs_ctx guards@(GRHSs _ grhss _) = do let combinedLoc = foldl1 combineSrcSpans (map getLoc grhss) dsMatchContext = DsMatchContext hs_ctx combinedLoc match = L combinedLoc $ @@ -286,7 +277,8 @@ checkGuardMatches hs_ctx guards@(GRHSs _ grhss _) = do , m_ctxt = hs_ctx , m_pats = [] , m_grhss = guards } - checkMatches dsMatchContext [] [match] + [(_, deltas)] <- checkMatches dsMatchContext [] [match] + pure deltas -- | Check a list of syntactic /match/es (part of case, functions, etc.), each -- with a /pat/ and one or more /grhss/: @@ -305,10 +297,9 @@ checkMatches :: DsMatchContext -- ^ Match context, for warnings messages -> [Id] -- ^ Match variables, i.e. x and y above -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches - -> DsM [Deltas] -- ^ One covered 'Deltas' per RHS, for long + -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per RHS, for long -- distance info. checkMatches ctxt vars matches = do - dflags <- getDynFlags tracePm "checkMatches" (hang (vcat [ppr ctxt , ppr vars , text "Matches:"]) @@ -321,25 +312,45 @@ checkMatches ctxt vars matches = do [] | [var] <- vars -> addPmCtDeltas init_deltas (PmNotBotCt var) _ -> pure init_deltas fam_insts <- dsGetFamInstEnvs - grd_tree <- mkGrdTreeMany [] <$> mapM (translateMatch fam_insts vars) matches + grd_tree <- translateMatches fam_insts vars matches res <- checkGrdTree grd_tree missing + dflags <- getDynFlags dsPmWarn dflags ctxt vars res - return (extractRhsDeltas init_deltas (cr_clauses res)) + return (extractRhsDeltas (cr_clauses res)) --- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree'. +-- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree' for a match +-- group. -- For 'AccessibleRhs's, this is stored in the tree node, whereas -- 'InaccessibleRhs's fall back to the supplied original 'Deltas'. -- See @Note [Recovering from unsatisfiable pattern-matching constraints]@. -extractRhsDeltas :: Deltas -> AnnotatedTree -> [Deltas] -extractRhsDeltas orig_deltas = fromOL . go +extractRhsDeltas :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] +extractRhsDeltas = go_matches where - go (AccessibleRhs deltas _) = unitOL deltas - go (InaccessibleRhs _) = unitOL orig_deltas - go (MayDiverge t) = go t - go (SequenceAnn l r) = go l Semi.<> go r - go EmptyAnn = nilOL + go_matches :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] + go_matches (SequenceAnn def ts) = map (go_match def) ts -- -XEmptyCase handled here! + go_matches t = pprPanic "extractRhsDeltas.go_matches" (text "Matches must start with SequenceAnn. But was" $$ ppr t) + + go_match :: Deltas -> AnnotatedTree -> (Deltas, NonEmpty Deltas) + -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ + -- is non-empty! + go_match def (SequenceAnn pat ts) = (pat, foldMap1 (text "go_match: empty SequenceAnn") (go_grhss def) ts) + go_match def (MayDiverge t) = go_match def t + -- Even if there's only a single GRHS, we wrap it in a SequenceAnn for the + -- Deltas covered by the pattern. So the remaining cases are impossible! + go_match _ t = pprPanic "extractRhsDeltas.go_match" (text "Single GRHS must be wrapped in SequenceAnn. But got " $$ ppr t) + + go_grhss :: Deltas -> AnnotatedTree -> NonEmpty Deltas + -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ + -- is non-empty! + go_grhss def (SequenceAnn _ ts) = foldMap1 (text "go_grhss: empty SequenceAnn") (go_grhss def) ts + go_grhss def (MayDiverge t) = go_grhss def t + go_grhss _ (AccessibleRhs deltas _) = deltas :| [] + go_grhss def (InaccessibleRhs _) = def :| [] + + foldMap1 msg _ [] = pprPanic "extractRhsDeltas.foldMap1" msg + foldMap1 _ f (x:xs) = foldl' (\acc x -> acc Semi.<> f x) (f x) xs {- Note [Checking EmptyCase] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -628,34 +639,43 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- 1. 2. 3. pure (con_grd : bang_grds ++ arg_grds) -mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree -mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) - -mkGrdTreeMany :: GrdVec -> [GrdTree] -> GrdTree -mkGrdTreeMany _ [] = Empty -mkGrdTreeMany grds trees = foldr Guard (foldr1 Sequence trees) grds +-- | Translate a the 'Match'es of a 'MatchGroup' +translateMatches :: FamInstEnvs -> [Id] -> [LMatch GhcTc (LHsExpr GhcTc)] + -> DsM GrdTree +translateMatches fam_insts vars matches = + -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. + -- 'extractRhsDeltas' needs this to recover 'MatchGroup' structure. + Sequence <$> traverse (translateMatch fam_insts vars) matches -- Translate a single match translateMatch :: FamInstEnvs -> [Id] -> LMatch GhcTc (LHsExpr GhcTc) -> DsM GrdTree translateMatch fam_insts vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do - pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats - grhss' <- mapM (translateLGRHS fam_insts match_loc pats) (grhssGRHSs grhss) - -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss, ppr grhss']) - return (mkGrdTreeMany pats' grhss') + pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats + grhss' <- translateGRHSs fam_insts match_loc (sep (map ppr pats)) grhss + -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss']) + return (foldr Guard grhss' pats') --- ----------------------------------------------------------------------- --- * Transform source guards (GuardStmt Id) to simpler PmGrds +mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree +mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) + +translateGRHSs :: FamInstEnvs -> SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM GrdTree +translateGRHSs fam_insts match_loc pp_pats grhss = + -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. + -- 'extractRhsDeltas' needs this to recover 'GRHSs' structure. + Sequence <$> traverse (translateLGRHS fam_insts match_loc pp_pats) (grhssGRHSs grhss) -- | Translate a guarded right-hand side to a single 'GrdTree' -translateLGRHS :: FamInstEnvs -> SrcSpan -> [LPat GhcTc] -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateLGRHS fam_insts match_loc pats (L _loc (GRHS _ gs _)) = - -- _loc apparently points to the match separator that comes after the guards.. +translateLGRHS :: FamInstEnvs -> SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree +translateLGRHS fam_insts match_loc pp_pats (L _loc (GRHS _ gs _)) = + -- _loc points to the match separator (ie =, ->) that comes after the guards.. mkGrdTreeRhs loc_sdoc <$> concatMapM (translateGuard fam_insts . unLoc) gs where loc_sdoc - | null gs = L match_loc (sep (map ppr pats)) - | otherwise = L grd_loc (sep (map ppr pats) <+> vbar <+> interpp'SP gs) + -- pp_pats is the space-separated pattern of the current Match this + -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . + | null gs = L match_loc pp_pats + | otherwise = L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) L grd_loc _ = head gs -- | Translate a guard statement to a 'GrdVec' @@ -970,6 +990,7 @@ checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do unc_this <- addPmCtDeltas deltas (PmNotConCt x con) deltas' <- addPmCtsDeltas deltas $ listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args + -- tracePm "checkGrdTree:Con" (ppr deltas $$ ppr x $$ ppr con $$ ppr dicts $$ ppr deltas') CheckResult tree' unc_inner prec <- checkGrdTree' tree deltas' limit <- maxPmCheckModels <$> getDynFlags let (prec', unc') = throttle limit deltas (unc_this Semi.<> unc_inner) @@ -978,19 +999,21 @@ checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do , cr_uncov = unc' , cr_approx = prec Semi.<> prec' } -- Sequence: Thread residual uncovered sets from equation to equation -checkGrdTree' (Sequence l r) unc_0 = do - CheckResult l' unc_1 prec_l <- checkGrdTree' l unc_0 - CheckResult r' unc_2 prec_r <- checkGrdTree' r unc_1 - pure CheckResult - { cr_clauses = SequenceAnn l' r' - , cr_uncov = unc_2 - , cr_approx = prec_l Semi.<> prec_r } --- Empty: Fall through for all values -checkGrdTree' Empty unc = do - pure CheckResult - { cr_clauses = EmptyAnn - , cr_uncov = unc - , cr_approx = Precise } +checkGrdTree' (Sequence ts) init_unc = go [] init_unc Precise ts + where + -- | Accumulates a CheckResult. Its type is more like + -- @CheckResult -> [GrdTree] -> CheckResult@, but cr_clauses is a single + -- 'AnnotatedTree', not a list thereof. Hence 3 parameters to thread the + -- fields. + go :: [AnnotatedTree] -> Deltas -> Precision -> [GrdTree] -> DsM CheckResult + -- No cases left: Fall through for all values + go ts' unc prec [] = pure CheckResult + { cr_clauses = SequenceAnn init_unc (reverse ts') + , cr_uncov = unc + , cr_approx = prec } + go ts' unc prec (t:ts) = do + CheckResult t' unc_1 prec_t <- checkGrdTree' t unc + go (t':ts') unc_1 (prec_t Semi.<> prec) ts -- | Print diagnostic info and actually call 'checkGrdTree''. checkGrdTree :: GrdTree -> Deltas -> DsM CheckResult @@ -1116,8 +1139,7 @@ redundantAndInaccessibleRhss tree = (fromOL ol_red, fromOL ol_inacc) (acc, inacc, red) | isNilOL acc && isNilOL inacc -> (nilOL, red, nilOL) res -> res - go (SequenceAnn l r) = go l Semi.<> go r - go EmptyAnn = (nilOL, nilOL, nilOL) + go (SequenceAnn _ ts) = foldMap go ts {- Note [Determining inaccessible clauses] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/HsToCore/PmCheck/Oracle.hs ===================================== @@ -1069,7 +1069,8 @@ ensureAllPossibleMatchesInhabited delta at MkDelta{ delta_tm_st = TmSt env reps } = runMaybeT (set_tm_cs_env delta <$> traverseSDIE go env) where set_tm_cs_env delta env = delta{ delta_tm_st = TmSt env reps } - go vi = MaybeT (ensureInhabited delta vi) + go vi = MaybeT $ + initPossibleMatches (delta_ty_st delta) vi >>= ensureInhabited delta -------------------------------------- -- * Term oracle unification procedure @@ -1667,7 +1668,7 @@ addCoreCt :: Delta -> Id -> CoreExpr -> MaybeT DsM Delta addCoreCt delta x e = do dflags <- getDynFlags let e' = simpleOptExpr dflags e - lift $ tracePm "addCoreCt" (ppr x $$ ppr e $$ ppr e') + lift $ tracePm "addCoreCt" (ppr x <+> dcolon <+> ppr (idType x) $$ ppr e $$ ppr e') execStateT (core_expr x e') delta where -- | Takes apart a 'CoreExpr' and tries to extract as much information about ===================================== compiler/GHC/Tc/Errors/Hole.hs ===================================== @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ExistentialQuantification #-} {-# OPTIONS_GHC -Wno-incomplete-record-updates #-} @@ -778,7 +779,9 @@ tcFilterHoleFits limit typed_hole ht@(hole_ty, _) candidates = Just (dataConWrapId con, dataConNonlinearType con) _ -> Nothing } where name = case hfc of +#if __GLASGOW_HASKELL__ <= 810 IdHFCand id -> idName id +#endif GreHFCand gre -> gre_name gre NameHFCand name -> name discard_it = go subs seen maxleft ty elts ===================================== compiler/GHC/Tc/Gen/HsType.hs ===================================== @@ -1078,7 +1078,9 @@ tc_hs_type mode rn_ty@(HsTupleTy _ hs_tup_sort tys) exp_kind HsUnboxedTuple -> UnboxedTuple HsBoxedTuple -> BoxedTuple HsConstraintTuple -> ConstraintTuple +#if __GLASGOW_HASKELL__ <= 810 _ -> panic "tc_hs_type HsTupleTy" +#endif tc_hs_type mode rn_ty@(HsSumTy _ hs_tys) exp_kind = do { let arity = length hs_tys ===================================== testsuite/tests/pmcheck/should_compile/T18533.hs ===================================== @@ -0,0 +1,24 @@ +{-# OPTIONS_GHC -Wincomplete-patterns -fforce-recomp #-} +{-# LANGUAGE GADTs, DataKinds, TypeFamilies, BangPatterns #-} + +module T18533 where + +data SBool (b :: Bool) where + STrue :: SBool 'True + SFalse :: SBool 'False + +type family Fam (b :: Bool) +type instance Fam 'True = T + +data T = T Bool + +f :: Fam b -> SBool b -> Bool +f !t s = case s of + STrue -> a where a = case t of T a -> a + _ -> False + + +g :: Bool -> Bool +g x = case x of + True -> a where a = case x of True -> False + False -> True ===================================== testsuite/tests/pmcheck/should_compile/all.T ===================================== @@ -122,6 +122,8 @@ test('T18049', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T18478', collect_compiler_stats('bytes allocated',10), compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) +test('T18533', normal, compile, + ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) # Other tests test('pmc001', [], compile, View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2d93ea2ee6537c7baa2325bc94404a381b8882b6 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2d93ea2ee6537c7baa2325bc94404a381b8882b6 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 12 18:22:44 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 12 Aug 2020 14:22:44 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 2 commits: Rewrite and move the monad-state hack note Message-ID: <5f34337461ed1_80b3f8486b5b7c07875563@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: a182ec32 by Sylvain Henry at 2020-08-12T14:22:40-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 855f71a9 by Alan Zimmerman at 2020-08-12T14:22:41-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 5 changed files: - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/Simplify/Monad.hs - compiler/GHC/Core/Unify.hs - compiler/GHC/Parser.y - compiler/GHC/Utils/Monad.hs Changes: ===================================== compiler/GHC/Core/Opt/Arity.hs ===================================== @@ -1031,7 +1031,7 @@ one-shot flag from the inner \s{osf}. By expanding with the ArityType gotten from analysing the RHS, we achieve this neatly. This makes a big difference to the one-shot monad trick; -see Note [The one-shot state monad trick] in GHC.Core.Unify. +see Note [The one-shot state monad trick] in GHC.Utils.Monad. -} -- | @etaExpand n e@ returns an expression with ===================================== compiler/GHC/Core/Opt/Simplify/Monad.hs ===================================== @@ -71,7 +71,7 @@ pattern SM :: (SimplTopEnv -> UniqSupply -> SimplCount -- This pattern synonym makes the simplifier monad eta-expand, -- which as a very beneficial effect on compiler performance -- (worth a 1-2% reduction in bytes-allocated). See #18202. --- See Note [The one-shot state monad trick] in GHC.Core.Unify +-- See Note [The one-shot state monad trick] in GHC.Utils.Monad pattern SM m <- SM' m where SM m = SM' (oneShot m) ===================================== compiler/GHC/Core/Unify.hs ===================================== @@ -1212,77 +1212,6 @@ data BindFlag ************************************************************************ -} -{- Note [The one-shot state monad trick] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Many places in GHC use a state monad, and we really want those -functions to be eta-expanded (#18202). Consider - - newtype M a = MkM (State -> (State, a)) - - instance Monad M where - mf >>= k = MkM (\s -> case mf of MkM f -> - case f s of (s',r) -> - case k r of MkM g -> - g s') - - foo :: Int -> M Int - foo x = g y >>= \r -> h r - where - y = expensive x - -In general, you might say (map (foo 4) xs), and expect (expensive 4) -to be evaluated only once. So foo should have arity 1 (not 2). -But that's rare, and if you /aren't/ re-using (M a) values it's much -more efficient to make foo have arity 2. - -See https://www.joachim-breitner.de/blog/763-Faster_Winter_5__Eta-Expanding_ReaderT - -So here is the trick. Define - - data M a = MkM' (State -> (State, a)) - pattern MkM f <- MkM' f - where - MkM f = MkM' (oneShot f) - -The patten synonm means that whenever we write (MkM f), we'll -actually get (MkM' (oneShot f)), so we'll pin a one-shot flag -on f's lambda-binder. Now look at foo: - - foo = \x. g (expensive x) >>= \r -> h r - = \x. let mf = g (expensive x) - k = \r -> h r - in MkM' (oneShot (\s -> case mf of MkM' f -> - case f s of (s',r) -> - case k r of MkM' g -> - g s')) - -- The MkM' are just newtype casts nt_co - = \x. let mf = g (expensive x) - k = \r -> h r - in (\s{os}. case (mf |> nt_co) s of (s',r) -> - (k r) |> nt_co s') - |> sym nt_co - - -- Float into that \s{os} - = \x. (\s{os}. case (g (expensive x) |> nt_co) s of (s',r) -> - h r |> nt_co s') - |> sym nt_co - -and voila! In summary: - -* It's a very simple, two-line change - -* It eta-expands all uses of the monad, automatically - -* It is very similar to the built-in "state hack" (see - GHC.Core.Opt.Arity Note [The state-transformer hack]) but the trick - described here is applicable on a monad-by-monad basis under - programmer control. - -* Beware: itt changes the behaviour of - map (foo 3) xs - ToDo: explain what to do if you want to do this --} - data UMEnv = UMEnv { um_unif :: AmIUnifying @@ -1311,11 +1240,11 @@ data UMState = UMState newtype UM a = UM' { unUM :: UMState -> UnifyResultM (UMState, a) } - -- See Note [The one-shot state monad trick] + -- See Note [The one-shot state monad trick] in GHC.Utils.Monad deriving (Functor) pattern UM :: (UMState -> UnifyResultM (UMState, a)) -> UM a --- See Note [The one-shot state monad trick] +-- See Note [The one-shot state monad trick] in GHC.Utils.Monad pattern UM m <- UM' m where UM m = UM' (oneShot m) ===================================== compiler/GHC/Parser.y ===================================== @@ -1961,7 +1961,7 @@ type :: { LHsType GhcPs } | btype '#->' ctype {% hintLinear (getLoc $2) >> ams (sLL $1 $> $ HsFunTy noExtField HsLinearArrow $1 $3) - [mu AnnRarrow $2] } + [mu AnnLolly $2] } mult :: { LHsType GhcPs } : btype { $1 } @@ -2089,10 +2089,10 @@ tv_bndrs :: { [LHsTyVarBndr Specificity GhcPs] } tv_bndr :: { LHsTyVarBndr Specificity GhcPs } : tv_bndr_no_braces { $1 } | '{' tyvar '}' {% ams (sLL $1 $> (UserTyVar noExtField InferredSpec $2)) - [mop $1, mcp $3] } + [moc $1, mcc $3] } | '{' tyvar '::' kind '}' {% ams (sLL $1 $> (KindedTyVar noExtField InferredSpec $2 $4)) - [mop $1,mu AnnDcolon $3 - ,mcp $5] } + [moc $1,mu AnnDcolon $3 + ,mcc $5] } tv_bndr_no_braces :: { LHsTyVarBndr Specificity GhcPs } : tyvar { sL1 $1 (UserTyVar noExtField SpecifiedSpec $1) } @@ -3728,6 +3728,7 @@ isUnicode (L _ (ITcparenbar iu)) = iu == UnicodeSyntax isUnicode (L _ (ITopenExpQuote _ iu)) = iu == UnicodeSyntax isUnicode (L _ (ITcloseQuote iu)) = iu == UnicodeSyntax isUnicode (L _ (ITstar iu)) = iu == UnicodeSyntax +isUnicode (L _ (ITlolly iu)) = iu == UnicodeSyntax isUnicode _ = False hasE :: Located Token -> Bool ===================================== compiler/GHC/Utils/Monad.hs ===================================== @@ -226,3 +226,175 @@ unlessM condM acc = do { cond <- condM filterOutM :: (Applicative m) => (a -> m Bool) -> [a] -> m [a] filterOutM p = foldr (\ x -> liftA2 (\ flg -> if flg then id else (x:)) (p x)) (pure []) + +{- Note [The one-shot state monad trick] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Summary: many places in GHC use a state monad, and we really want those +functions to be eta-expanded (#18202). + +The problem +~~~~~~~~~~~ +Consider + newtype M a = MkM (State -> (State, a)) + + instance Monad M where + mf >>= k = MkM (\s -> case mf of MkM f -> + case f s of (s',r) -> + case k r of MkM g -> + g s') + + fooM :: Int -> M Int + fooM x = g y >>= \r -> h r + where + y = expensive x + +Now suppose you say (repeat 20 (fooM 4)), where + repeat :: Int -> M Int -> M Int +performs its argument n times. You would expect (expensive 4) to be +evaluated only once, not 20 times. So foo should have arity 1 (not 2); +it should look like this (modulo casts) + + fooM x = let y = expensive x in + \s -> case g y of ... + +But creating and then repeating, a monadic computation is rare. If you +/aren't/ re-using (M a) value, it's /much/ more efficient to make +foo have arity 2, thus: + + fooM x s = case g (expensive x) of ... + +Why more efficient? Because now foo takes its argument both at once, +rather than one at a time, creating a heap-allocated function closure. See +https://www.joachim-breitner.de/blog/763-Faster_Winter_5__Eta-Expanding_ReaderT +for a very good explanation of the issue which led to these optimisations +into GHC. + +The trick +~~~~~~~~~ +With state monads like M the general case is that we *aren't* reusing +(M a) values so it is much more efficient to avoid allocating a +function closure for them. So the state monad trick is a way to keep +the monadic syntax but to make GHC eta-expand functions like `fooM`. +To do that we use the "oneShot" magic function. + +Here is the trick: + * Define a "smart constructor" + mkM :: (State -> (State,a)) -> M a + mkM f = MkM (oneShot m) + + * Never call MkM directly, as a constructor. Instead, always call mkM. + +And that's it! The magic 'oneShot' function does this transformation: + oneShot (\s. e) ==> \s{os}. e +which pins a one-shot flag {os} onto the binder 's'. That tells GHC +that it can assume the lambda is called only once, and thus can freely +float computations in and out of the lambda. + +To be concrete, let's see what happens to fooM: + + fooM = \x. g (expensive x) >>= \r -> h r + = \x. let mf = g (expensive x) + k = \r -> h r + in MkM (oneShot (\s -> case mf of MkM' f -> + case f s of (s',r) -> + case k r of MkM' g -> + g s')) + -- The MkM' are just newtype casts nt_co + = \x. let mf = g (expensive x) + k = \r -> h r + in (\s{os}. case (mf |> nt_co) s of (s',r) -> + (k r) |> nt_co s') + |> sym nt_co + + -- Crucial step: float let-bindings into that \s{os} + = \x. (\s{os}. case (g (expensive x) |> nt_co) s of (s',r) -> + h r |> nt_co s') + |> sym nt_co + +and voila! fooM has arity 2. + +The trick is very similar to the built-in "state hack" +(see Note [The state-transformer hack] in "GHC.Core.Opt.Arity") but is +applicable on a monad-by-monad basis under programmer control. + +Using pattern synonyms +~~~~~~~~~~~~~~~~~~~~~~ +Using a smart constructor is fine, but there is no way to check that we +have found *all* uses, especially if the uses escape a single module. +A neat (but more sophisticated) alternative is to use pattern synonyms: + + -- We rename the existing constructor. + newtype M a = MkM' (State -> (State, a)) + + -- The pattern has the old constructor name. + pattern MkM f <- MkM' f + where + MkM f = MkM' (oneShot f) + +Now we can simply grep to check that there are no uses of MkM' +/anywhere/, to guarantee that we have not missed any. (Using the +smart constructor alone we still need the data constructor in +patterns.) That's the advantage of the pattern-synonym approach, but +it is more elaborate. + +The pattern synonym approach is due to Sebastian Graaf (#18238) + +Derived instances +~~~~~~~~~~~~~~~~~ +One caveat of both approaches is that derived instances don't use the smart +constructor /or/ the pattern synonym. So they won't benefit from the automatic +insertion of "oneShot". + + data M a = MkM' (State -> (State,a)) + deriving (Functor) <-- Functor implementation will use MkM'! + +Conclusion: don't use 'derviving' in these cases. + +Multi-shot actions (cf #18238) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Sometimes we really *do* want computations to be shared! Remember our +example (repeat 20 (fooM 4)). See Note [multiShotIO] in GHC.Types.Unique.Supply + +We can force fooM to have arity 1 using multiShot: + + fooM :: Int -> M Int + fooM x = multiShotM (g y >>= \r -> h r) + where + y = expensive x + + multiShotM :: M a -> M a + {-# INLINE multiShotM #-} + multiShotM (MkM m) = MkM (\s -> inline m s) + -- Really uses the data constructor, + -- not the smart constructor! + +Now we can see how fooM optimises (ignoring casts) + + multiShotM (g y >>= \r -> h r) + ==> {inline (>>=)} + multiShotM (\s{os}. case g y s of ...) + ==> {inline multiShotM} + let m = \s{os}. case g y s of ... + in \s. inline m s + ==> {inline m} + \s. (\s{os}. case g y s of ...) s + ==> \s. case g y s of ... + +and voila! the one-shot flag has gone. It's possible that y has been +replaced by (expensive x), but full laziness should pull it back out. +(This part seems less robust.) + +The magic `inline` function does two things +* It prevents eta reduction. If we wrote just + multiShotIO (IO m) = IO (\s -> m s) + the lamda would eta-reduce to 'm' and all would be lost. + +* It helps ensure that 'm' really does inline. + +Note that 'inline' evaporates in phase 0. See Note [inlineIdMagic] +in GHC.Core.Opt.ConstantFold.match_inline. + +The INLINE pragma on multiShotM is very important, else the +'inline' call will evaporate when compiling the module that +defines 'multiShotM', before it is ever exported. +-} View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a4a1660cfea13d5b918c8d9240c76026c411b04e...855f71a9c639a72833b63cd03061cc92785c2228 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a4a1660cfea13d5b918c8d9240c76026c411b04e...855f71a9c639a72833b63cd03061cc92785c2228 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 12 19:32:41 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Wed, 12 Aug 2020 15:32:41 -0400 Subject: [Git][ghc/ghc][wip/T18545] 13 commits: hadrian: depend on boot compiler version #18001 Message-ID: <5f3443d9dd1a3_80b3f84693c1eb47890611@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18545 at Glasgow Haskell Compiler / GHC Commits: a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - 77386e6c by Ben Gamari at 2020-08-12T15:32:39-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 30 changed files: - compiler/GHC.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - compiler/GHC/CmmToAsm/CPrim.hs - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Format.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7632c73a86cffae9090cb7f778148746b8d09aca...77386e6c35b2c0a01ae25a5f2d926e6b0dcd072b -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7632c73a86cffae9090cb7f778148746b8d09aca...77386e6c35b2c0a01ae25a5f2d926e6b0dcd072b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 00:52:54 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 12 Aug 2020 20:52:54 -0400 Subject: [Git][ghc/ghc][master] Rewrite and move the monad-state hack note Message-ID: <5f348ee65c5a2_80b3f8486298278790714d@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 4 changed files: - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/Simplify/Monad.hs - compiler/GHC/Core/Unify.hs - compiler/GHC/Utils/Monad.hs Changes: ===================================== compiler/GHC/Core/Opt/Arity.hs ===================================== @@ -1031,7 +1031,7 @@ one-shot flag from the inner \s{osf}. By expanding with the ArityType gotten from analysing the RHS, we achieve this neatly. This makes a big difference to the one-shot monad trick; -see Note [The one-shot state monad trick] in GHC.Core.Unify. +see Note [The one-shot state monad trick] in GHC.Utils.Monad. -} -- | @etaExpand n e@ returns an expression with ===================================== compiler/GHC/Core/Opt/Simplify/Monad.hs ===================================== @@ -71,7 +71,7 @@ pattern SM :: (SimplTopEnv -> UniqSupply -> SimplCount -- This pattern synonym makes the simplifier monad eta-expand, -- which as a very beneficial effect on compiler performance -- (worth a 1-2% reduction in bytes-allocated). See #18202. --- See Note [The one-shot state monad trick] in GHC.Core.Unify +-- See Note [The one-shot state monad trick] in GHC.Utils.Monad pattern SM m <- SM' m where SM m = SM' (oneShot m) ===================================== compiler/GHC/Core/Unify.hs ===================================== @@ -1212,77 +1212,6 @@ data BindFlag ************************************************************************ -} -{- Note [The one-shot state monad trick] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Many places in GHC use a state monad, and we really want those -functions to be eta-expanded (#18202). Consider - - newtype M a = MkM (State -> (State, a)) - - instance Monad M where - mf >>= k = MkM (\s -> case mf of MkM f -> - case f s of (s',r) -> - case k r of MkM g -> - g s') - - foo :: Int -> M Int - foo x = g y >>= \r -> h r - where - y = expensive x - -In general, you might say (map (foo 4) xs), and expect (expensive 4) -to be evaluated only once. So foo should have arity 1 (not 2). -But that's rare, and if you /aren't/ re-using (M a) values it's much -more efficient to make foo have arity 2. - -See https://www.joachim-breitner.de/blog/763-Faster_Winter_5__Eta-Expanding_ReaderT - -So here is the trick. Define - - data M a = MkM' (State -> (State, a)) - pattern MkM f <- MkM' f - where - MkM f = MkM' (oneShot f) - -The patten synonm means that whenever we write (MkM f), we'll -actually get (MkM' (oneShot f)), so we'll pin a one-shot flag -on f's lambda-binder. Now look at foo: - - foo = \x. g (expensive x) >>= \r -> h r - = \x. let mf = g (expensive x) - k = \r -> h r - in MkM' (oneShot (\s -> case mf of MkM' f -> - case f s of (s',r) -> - case k r of MkM' g -> - g s')) - -- The MkM' are just newtype casts nt_co - = \x. let mf = g (expensive x) - k = \r -> h r - in (\s{os}. case (mf |> nt_co) s of (s',r) -> - (k r) |> nt_co s') - |> sym nt_co - - -- Float into that \s{os} - = \x. (\s{os}. case (g (expensive x) |> nt_co) s of (s',r) -> - h r |> nt_co s') - |> sym nt_co - -and voila! In summary: - -* It's a very simple, two-line change - -* It eta-expands all uses of the monad, automatically - -* It is very similar to the built-in "state hack" (see - GHC.Core.Opt.Arity Note [The state-transformer hack]) but the trick - described here is applicable on a monad-by-monad basis under - programmer control. - -* Beware: itt changes the behaviour of - map (foo 3) xs - ToDo: explain what to do if you want to do this --} - data UMEnv = UMEnv { um_unif :: AmIUnifying @@ -1311,11 +1240,11 @@ data UMState = UMState newtype UM a = UM' { unUM :: UMState -> UnifyResultM (UMState, a) } - -- See Note [The one-shot state monad trick] + -- See Note [The one-shot state monad trick] in GHC.Utils.Monad deriving (Functor) pattern UM :: (UMState -> UnifyResultM (UMState, a)) -> UM a --- See Note [The one-shot state monad trick] +-- See Note [The one-shot state monad trick] in GHC.Utils.Monad pattern UM m <- UM' m where UM m = UM' (oneShot m) ===================================== compiler/GHC/Utils/Monad.hs ===================================== @@ -226,3 +226,175 @@ unlessM condM acc = do { cond <- condM filterOutM :: (Applicative m) => (a -> m Bool) -> [a] -> m [a] filterOutM p = foldr (\ x -> liftA2 (\ flg -> if flg then id else (x:)) (p x)) (pure []) + +{- Note [The one-shot state monad trick] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Summary: many places in GHC use a state monad, and we really want those +functions to be eta-expanded (#18202). + +The problem +~~~~~~~~~~~ +Consider + newtype M a = MkM (State -> (State, a)) + + instance Monad M where + mf >>= k = MkM (\s -> case mf of MkM f -> + case f s of (s',r) -> + case k r of MkM g -> + g s') + + fooM :: Int -> M Int + fooM x = g y >>= \r -> h r + where + y = expensive x + +Now suppose you say (repeat 20 (fooM 4)), where + repeat :: Int -> M Int -> M Int +performs its argument n times. You would expect (expensive 4) to be +evaluated only once, not 20 times. So foo should have arity 1 (not 2); +it should look like this (modulo casts) + + fooM x = let y = expensive x in + \s -> case g y of ... + +But creating and then repeating, a monadic computation is rare. If you +/aren't/ re-using (M a) value, it's /much/ more efficient to make +foo have arity 2, thus: + + fooM x s = case g (expensive x) of ... + +Why more efficient? Because now foo takes its argument both at once, +rather than one at a time, creating a heap-allocated function closure. See +https://www.joachim-breitner.de/blog/763-Faster_Winter_5__Eta-Expanding_ReaderT +for a very good explanation of the issue which led to these optimisations +into GHC. + +The trick +~~~~~~~~~ +With state monads like M the general case is that we *aren't* reusing +(M a) values so it is much more efficient to avoid allocating a +function closure for them. So the state monad trick is a way to keep +the monadic syntax but to make GHC eta-expand functions like `fooM`. +To do that we use the "oneShot" magic function. + +Here is the trick: + * Define a "smart constructor" + mkM :: (State -> (State,a)) -> M a + mkM f = MkM (oneShot m) + + * Never call MkM directly, as a constructor. Instead, always call mkM. + +And that's it! The magic 'oneShot' function does this transformation: + oneShot (\s. e) ==> \s{os}. e +which pins a one-shot flag {os} onto the binder 's'. That tells GHC +that it can assume the lambda is called only once, and thus can freely +float computations in and out of the lambda. + +To be concrete, let's see what happens to fooM: + + fooM = \x. g (expensive x) >>= \r -> h r + = \x. let mf = g (expensive x) + k = \r -> h r + in MkM (oneShot (\s -> case mf of MkM' f -> + case f s of (s',r) -> + case k r of MkM' g -> + g s')) + -- The MkM' are just newtype casts nt_co + = \x. let mf = g (expensive x) + k = \r -> h r + in (\s{os}. case (mf |> nt_co) s of (s',r) -> + (k r) |> nt_co s') + |> sym nt_co + + -- Crucial step: float let-bindings into that \s{os} + = \x. (\s{os}. case (g (expensive x) |> nt_co) s of (s',r) -> + h r |> nt_co s') + |> sym nt_co + +and voila! fooM has arity 2. + +The trick is very similar to the built-in "state hack" +(see Note [The state-transformer hack] in "GHC.Core.Opt.Arity") but is +applicable on a monad-by-monad basis under programmer control. + +Using pattern synonyms +~~~~~~~~~~~~~~~~~~~~~~ +Using a smart constructor is fine, but there is no way to check that we +have found *all* uses, especially if the uses escape a single module. +A neat (but more sophisticated) alternative is to use pattern synonyms: + + -- We rename the existing constructor. + newtype M a = MkM' (State -> (State, a)) + + -- The pattern has the old constructor name. + pattern MkM f <- MkM' f + where + MkM f = MkM' (oneShot f) + +Now we can simply grep to check that there are no uses of MkM' +/anywhere/, to guarantee that we have not missed any. (Using the +smart constructor alone we still need the data constructor in +patterns.) That's the advantage of the pattern-synonym approach, but +it is more elaborate. + +The pattern synonym approach is due to Sebastian Graaf (#18238) + +Derived instances +~~~~~~~~~~~~~~~~~ +One caveat of both approaches is that derived instances don't use the smart +constructor /or/ the pattern synonym. So they won't benefit from the automatic +insertion of "oneShot". + + data M a = MkM' (State -> (State,a)) + deriving (Functor) <-- Functor implementation will use MkM'! + +Conclusion: don't use 'derviving' in these cases. + +Multi-shot actions (cf #18238) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Sometimes we really *do* want computations to be shared! Remember our +example (repeat 20 (fooM 4)). See Note [multiShotIO] in GHC.Types.Unique.Supply + +We can force fooM to have arity 1 using multiShot: + + fooM :: Int -> M Int + fooM x = multiShotM (g y >>= \r -> h r) + where + y = expensive x + + multiShotM :: M a -> M a + {-# INLINE multiShotM #-} + multiShotM (MkM m) = MkM (\s -> inline m s) + -- Really uses the data constructor, + -- not the smart constructor! + +Now we can see how fooM optimises (ignoring casts) + + multiShotM (g y >>= \r -> h r) + ==> {inline (>>=)} + multiShotM (\s{os}. case g y s of ...) + ==> {inline multiShotM} + let m = \s{os}. case g y s of ... + in \s. inline m s + ==> {inline m} + \s. (\s{os}. case g y s of ...) s + ==> \s. case g y s of ... + +and voila! the one-shot flag has gone. It's possible that y has been +replaced by (expensive x), but full laziness should pull it back out. +(This part seems less robust.) + +The magic `inline` function does two things +* It prevents eta reduction. If we wrote just + multiShotIO (IO m) = IO (\s -> m s) + the lamda would eta-reduce to 'm' and all would be lost. + +* It helps ensure that 'm' really does inline. + +Note that 'inline' evaporates in phase 0. See Note [inlineIdMagic] +in GHC.Core.Opt.ConstantFold.match_inline. + +The INLINE pragma on multiShotM is very important, else the +'inline' call will evaporate when compiling the module that +defines 'multiShotM', before it is ever exported. +-} View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bee43aca827387aa81a64801d82adcb596d01d9a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bee43aca827387aa81a64801d82adcb596d01d9a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 00:53:31 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 12 Aug 2020 20:53:31 -0400 Subject: [Git][ghc/ghc][master] ApiAnnotations: Fix parser for new GHC 9.0 features Message-ID: <5f348f0be7242_80b3f84865febec790974c@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 1 changed file: - compiler/GHC/Parser.y Changes: ===================================== compiler/GHC/Parser.y ===================================== @@ -1961,7 +1961,7 @@ type :: { LHsType GhcPs } | btype '#->' ctype {% hintLinear (getLoc $2) >> ams (sLL $1 $> $ HsFunTy noExtField HsLinearArrow $1 $3) - [mu AnnRarrow $2] } + [mu AnnLolly $2] } mult :: { LHsType GhcPs } : btype { $1 } @@ -2089,10 +2089,10 @@ tv_bndrs :: { [LHsTyVarBndr Specificity GhcPs] } tv_bndr :: { LHsTyVarBndr Specificity GhcPs } : tv_bndr_no_braces { $1 } | '{' tyvar '}' {% ams (sLL $1 $> (UserTyVar noExtField InferredSpec $2)) - [mop $1, mcp $3] } + [moc $1, mcc $3] } | '{' tyvar '::' kind '}' {% ams (sLL $1 $> (KindedTyVar noExtField InferredSpec $2 $4)) - [mop $1,mu AnnDcolon $3 - ,mcp $5] } + [moc $1,mu AnnDcolon $3 + ,mcc $5] } tv_bndr_no_braces :: { LHsTyVarBndr Specificity GhcPs } : tyvar { sL1 $1 (UserTyVar noExtField SpecifiedSpec $1) } @@ -3728,6 +3728,7 @@ isUnicode (L _ (ITcparenbar iu)) = iu == UnicodeSyntax isUnicode (L _ (ITopenExpQuote _ iu)) = iu == UnicodeSyntax isUnicode (L _ (ITcloseQuote iu)) = iu == UnicodeSyntax isUnicode (L _ (ITstar iu)) = iu == UnicodeSyntax +isUnicode (L _ (ITlolly iu)) = iu == UnicodeSyntax isUnicode _ = False hasE :: Located Token -> Bool View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/25fdf25eb574d6d291673603ab36ac5ec7e37066 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/25fdf25eb574d6d291673603ab36ac5ec7e37066 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 01:24:18 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 12 Aug 2020 21:24:18 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 5 commits: Rewrite and move the monad-state hack note Message-ID: <5f3496429d33e_80b3f84693c1eb479147f3@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - cff2bb3d by Ben Gamari at 2020-08-12T21:24:09-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 01ea86e2 by Sebastian Graf at 2020-08-12T21:24:09-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - 23fac683 by Hécate at 2020-08-12T21:24:11-04:00 Re-add BangPatterns to CodePage.hs - - - - - 23 changed files: - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Core/Coercion/Opt.hs - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/Simplify/Monad.hs - compiler/GHC/Core/Unify.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/GuardedRHSs.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/Monad.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Tc/Errors/Hole.hs - compiler/GHC/Tc/Gen/HsType.hs - compiler/GHC/Utils/Monad.hs - libraries/base/GHC/IO/Encoding/CodePage.hs - testsuite/tests/module/mod184.stderr - + testsuite/tests/pmcheck/should_compile/T18533.hs - testsuite/tests/pmcheck/should_compile/all.T Changes: ===================================== compiler/GHC/Cmm/DebugBlock.hs ===================================== @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiWayIf #-} @@ -110,7 +111,9 @@ cmmDebugGen modLoc decls = map (blocksForScope Nothing) topScopes -- recover by copying ticks below. scp' | SubScope _ scp' <- scp = scp' | CombinedScope scp' _ <- scp = scp' +#if __GLASGOW_HASKELL__ <= 810 | otherwise = panic "findP impossible" +#endif scopeMap = foldr (uncurry insertMulti) Map.empty childScopes ===================================== compiler/GHC/Core/Coercion/Opt.hs ===================================== @@ -559,7 +559,10 @@ opt_univ env sym prov role oty1 oty2 where prov' = case prov of +#if __GLASGOW_HASKELL__ <= 810 +-- This alt is redundant with the first match of the FunDef PhantomProv kco -> PhantomProv $ opt_co4_wrap env sym False Nominal kco +#endif ProofIrrelProv kco -> ProofIrrelProv $ opt_co4_wrap env sym False Nominal kco PluginProv _ -> prov ===================================== compiler/GHC/Core/Opt/Arity.hs ===================================== @@ -1031,7 +1031,7 @@ one-shot flag from the inner \s{osf}. By expanding with the ArityType gotten from analysing the RHS, we achieve this neatly. This makes a big difference to the one-shot monad trick; -see Note [The one-shot state monad trick] in GHC.Core.Unify. +see Note [The one-shot state monad trick] in GHC.Utils.Monad. -} -- | @etaExpand n e@ returns an expression with ===================================== compiler/GHC/Core/Opt/Simplify/Monad.hs ===================================== @@ -71,7 +71,7 @@ pattern SM :: (SimplTopEnv -> UniqSupply -> SimplCount -- This pattern synonym makes the simplifier monad eta-expand, -- which as a very beneficial effect on compiler performance -- (worth a 1-2% reduction in bytes-allocated). See #18202. --- See Note [The one-shot state monad trick] in GHC.Core.Unify +-- See Note [The one-shot state monad trick] in GHC.Utils.Monad pattern SM m <- SM' m where SM m = SM' (oneShot m) ===================================== compiler/GHC/Core/Unify.hs ===================================== @@ -1212,77 +1212,6 @@ data BindFlag ************************************************************************ -} -{- Note [The one-shot state monad trick] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Many places in GHC use a state monad, and we really want those -functions to be eta-expanded (#18202). Consider - - newtype M a = MkM (State -> (State, a)) - - instance Monad M where - mf >>= k = MkM (\s -> case mf of MkM f -> - case f s of (s',r) -> - case k r of MkM g -> - g s') - - foo :: Int -> M Int - foo x = g y >>= \r -> h r - where - y = expensive x - -In general, you might say (map (foo 4) xs), and expect (expensive 4) -to be evaluated only once. So foo should have arity 1 (not 2). -But that's rare, and if you /aren't/ re-using (M a) values it's much -more efficient to make foo have arity 2. - -See https://www.joachim-breitner.de/blog/763-Faster_Winter_5__Eta-Expanding_ReaderT - -So here is the trick. Define - - data M a = MkM' (State -> (State, a)) - pattern MkM f <- MkM' f - where - MkM f = MkM' (oneShot f) - -The patten synonm means that whenever we write (MkM f), we'll -actually get (MkM' (oneShot f)), so we'll pin a one-shot flag -on f's lambda-binder. Now look at foo: - - foo = \x. g (expensive x) >>= \r -> h r - = \x. let mf = g (expensive x) - k = \r -> h r - in MkM' (oneShot (\s -> case mf of MkM' f -> - case f s of (s',r) -> - case k r of MkM' g -> - g s')) - -- The MkM' are just newtype casts nt_co - = \x. let mf = g (expensive x) - k = \r -> h r - in (\s{os}. case (mf |> nt_co) s of (s',r) -> - (k r) |> nt_co s') - |> sym nt_co - - -- Float into that \s{os} - = \x. (\s{os}. case (g (expensive x) |> nt_co) s of (s',r) -> - h r |> nt_co s') - |> sym nt_co - -and voila! In summary: - -* It's a very simple, two-line change - -* It eta-expands all uses of the monad, automatically - -* It is very similar to the built-in "state hack" (see - GHC.Core.Opt.Arity Note [The state-transformer hack]) but the trick - described here is applicable on a monad-by-monad basis under - programmer control. - -* Beware: itt changes the behaviour of - map (foo 3) xs - ToDo: explain what to do if you want to do this --} - data UMEnv = UMEnv { um_unif :: AmIUnifying @@ -1311,11 +1240,11 @@ data UMState = UMState newtype UM a = UM' { unUM :: UMState -> UnifyResultM (UMState, a) } - -- See Note [The one-shot state monad trick] + -- See Note [The one-shot state monad trick] in GHC.Utils.Monad deriving (Functor) pattern UM :: (UMState -> UnifyResultM (UMState, a)) -> UM a --- See Note [The one-shot state monad trick] +-- See Note [The one-shot state monad trick] in GHC.Utils.Monad pattern UM m <- UM' m where UM m = UM' (oneShot m) ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -1243,7 +1243,9 @@ ppr_infix_expr (HsConLikeOut _ c) = Just (pprInfixOcc (conLikeName c)) ppr_infix_expr (HsRecFld _ f) = Just (pprInfixOcc f) ppr_infix_expr (HsUnboundVar _ occ) = Just (pprInfixOcc occ) ppr_infix_expr (XExpr x) = case (ghcPass @p, x) of +#if __GLASGOW_HASKELL__ <= 810 (GhcPs, _) -> Nothing +#endif (GhcRn, HsExpanded a _) -> ppr_infix_expr a (GhcTc, WrapExpr (HsWrap _ e)) -> ppr_infix_expr e (GhcTc, ExpansionExpr (HsExpanded a _)) -> ppr_infix_expr a ===================================== compiler/GHC/Hs/Pat.hs ===================================== @@ -845,8 +845,10 @@ patNeedsParens p = go go (SigPat {}) = p >= sigPrec go (ViewPat {}) = True go (XPat ext) = case ghcPass @p of +#if __GLASGOW_HASKELL__ <= 810 GhcPs -> noExtCon ext GhcRn -> noExtCon ext +#endif GhcTc -> go inner where CoPat _ inner _ = ext go (WildPat {}) = False ===================================== compiler/GHC/HsToCore/Binds.hs ===================================== @@ -33,7 +33,7 @@ import {-# SOURCE #-} GHC.HsToCore.Match ( matchWrapper ) import GHC.HsToCore.Monad import GHC.HsToCore.GuardedRHSs import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck ( addTyCsDs, checkGuardMatches ) +import GHC.HsToCore.PmCheck ( addTyCsDs, checkGRHSs ) import GHC.Hs -- lots of things import GHC.Core -- lots of things @@ -78,7 +78,6 @@ import GHC.Types.Unique.Set( nonDetEltsUniqSet ) import GHC.Utils.Monad import qualified GHC.LanguageExtensions as LangExt import Control.Monad -import Data.List.NonEmpty ( nonEmpty ) {-********************************************************************** * * @@ -185,8 +184,8 @@ dsHsBind dflags b@(FunBind { fun_id = L loc fun dsHsBind dflags (PatBind { pat_lhs = pat, pat_rhs = grhss , pat_ext = NPatBindTc _ ty , pat_ticks = (rhs_tick, var_ticks) }) - = do { rhss_deltas <- checkGuardMatches PatBindGuards grhss - ; body_expr <- dsGuarded grhss ty (nonEmpty rhss_deltas) + = do { rhss_deltas <- checkGRHSs PatBindGuards grhss + ; body_expr <- dsGuarded grhss ty rhss_deltas ; let body' = mkOptTickBox rhs_tick body_expr pat' = decideBangHood dflags pat ; (force_var,sel_binds) <- mkSelectorBinds var_ticks pat body' ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -31,7 +31,7 @@ import GHC.HsToCore.ListComp import GHC.HsToCore.Utils import GHC.HsToCore.Arrows import GHC.HsToCore.Monad -import GHC.HsToCore.PmCheck ( addTyCsDs, checkGuardMatches ) +import GHC.HsToCore.PmCheck ( addTyCsDs, checkGRHSs ) import GHC.Types.Name import GHC.Types.Name.Env import GHC.Core.FamInstEnv( topNormaliseType ) @@ -70,7 +70,6 @@ import GHC.Utils.Panic import GHC.Core.PatSyn import Control.Monad -import Data.List.NonEmpty ( nonEmpty ) {- ************************************************************************ @@ -216,8 +215,8 @@ dsUnliftedBind (PatBind {pat_lhs = pat, pat_rhs = grhss , pat_ext = NPatBindTc _ ty }) body = -- let C x# y# = rhs in body -- ==> case rhs of C x# y# -> body - do { rhs_deltas <- checkGuardMatches PatBindGuards grhss - ; rhs <- dsGuarded grhss ty (nonEmpty rhs_deltas) + do { match_deltas <- checkGRHSs PatBindGuards grhss + ; rhs <- dsGuarded grhss ty match_deltas ; let upat = unLoc pat eqn = EqnInfo { eqn_pats = [upat], eqn_orig = FromSource, @@ -487,8 +486,8 @@ dsExpr (HsMultiIf res_ty alts) | otherwise = do { let grhss = GRHSs noExtField alts (noLoc emptyLocalBinds) - ; rhss_deltas <- checkGuardMatches IfAlt grhss - ; match_result <- dsGRHSs IfAlt grhss res_ty (nonEmpty rhss_deltas) + ; rhss_deltas <- checkGRHSs IfAlt grhss + ; match_result <- dsGRHSs IfAlt grhss res_ty rhss_deltas ; error_expr <- mkErrorExpr ; extractMatchResult match_result error_expr } where ===================================== compiler/GHC/HsToCore/GuardedRHSs.hs ===================================== @@ -25,7 +25,7 @@ import GHC.Core.Utils (bindNonRec) import GHC.HsToCore.Monad import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck.Types ( Deltas, initDeltas ) +import GHC.HsToCore.PmCheck.Types ( Deltas ) import GHC.Core.Type ( Type ) import GHC.Utils.Misc import GHC.Types.SrcLoc @@ -48,9 +48,9 @@ producing an expression with a runtime error in the corner if necessary. The type argument gives the type of the @ei at . -} -dsGuarded :: GRHSs GhcTc (LHsExpr GhcTc) -> Type -> Maybe (NonEmpty Deltas) -> DsM CoreExpr -dsGuarded grhss rhs_ty mb_rhss_deltas = do - match_result <- dsGRHSs PatBindRhs grhss rhs_ty mb_rhss_deltas +dsGuarded :: GRHSs GhcTc (LHsExpr GhcTc) -> Type -> NonEmpty Deltas -> DsM CoreExpr +dsGuarded grhss rhs_ty rhss_deltas = do + match_result <- dsGRHSs PatBindRhs grhss rhs_ty rhss_deltas error_expr <- mkErrorAppDs nON_EXHAUSTIVE_GUARDS_ERROR_ID rhs_ty empty extractMatchResult match_result error_expr @@ -59,25 +59,28 @@ dsGuarded grhss rhs_ty mb_rhss_deltas = do dsGRHSs :: HsMatchContext GhcRn -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ Guarded RHSs -> Type -- ^ Type of RHS - -> Maybe (NonEmpty Deltas) -- ^ Refined pattern match checking - -- models, one for each GRHS. Defaults - -- to 'initDeltas' if 'Nothing'. + -> NonEmpty Deltas -- ^ Refined pattern match checking + -- models, one for the pattern part and + -- one for each GRHS. -> DsM (MatchResult CoreExpr) -dsGRHSs hs_ctx (GRHSs _ grhss binds) rhs_ty mb_rhss_deltas +dsGRHSs hs_ctx (GRHSs _ grhss binds) rhs_ty rhss_deltas = ASSERT( notNull grhss ) - do { match_results <- case toList <$> mb_rhss_deltas of - Nothing -> mapM (dsGRHS hs_ctx rhs_ty initDeltas) grhss - Just rhss_deltas -> ASSERT( length grhss == length rhss_deltas ) - zipWithM (dsGRHS hs_ctx rhs_ty) rhss_deltas grhss - ; let match_result1 = foldr1 combineMatchResults match_results - match_result2 = adjustMatchResultDs (dsLocalBinds binds) match_result1 + do { match_results <- ASSERT( length grhss == length rhss_deltas ) + zipWithM (dsGRHS hs_ctx rhs_ty) (toList rhss_deltas) grhss + ; deltas <- getPmDeltas + -- We need to remember the Deltas from the particular match context we + -- are in, which might be different to when dsLocalBinds is actually + -- called. + ; let ds_binds = updPmDeltas deltas . dsLocalBinds binds + match_result1 = foldr1 combineMatchResults match_results + match_result2 = adjustMatchResultDs ds_binds match_result1 -- NB: nested dsLet inside matchResult ; return match_result2 } dsGRHS :: HsMatchContext GhcRn -> Type -> Deltas -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM (MatchResult CoreExpr) dsGRHS hs_ctx rhs_ty rhs_deltas (L _ (GRHS _ guards rhs)) - = updPmDeltas rhs_deltas (matchGuards (map unLoc guards) (PatGuard hs_ctx) rhs rhs_ty) + = matchGuards (map unLoc guards) (PatGuard hs_ctx) rhs_deltas rhs rhs_ty {- ************************************************************************ @@ -89,6 +92,7 @@ dsGRHS hs_ctx rhs_ty rhs_deltas (L _ (GRHS _ guards rhs)) matchGuards :: [GuardStmt GhcTc] -- Guard -> HsStmtContext GhcRn -- Context + -> Deltas -- The RHS's covered set for PmCheck -> LHsExpr GhcTc -- RHS -> Type -- Type of RHS of guard -> DsM (MatchResult CoreExpr) @@ -96,8 +100,8 @@ matchGuards :: [GuardStmt GhcTc] -- Guard -- See comments with HsExpr.Stmt re what a BodyStmt means -- Here we must be in a guard context (not do-expression, nor list-comp) -matchGuards [] _ rhs _ - = do { core_rhs <- dsLExpr rhs +matchGuards [] _ deltas rhs _ + = do { core_rhs <- updPmDeltas deltas (dsLExpr rhs) ; return (cantFailMatchResult core_rhs) } -- BodyStmts must be guards @@ -107,41 +111,41 @@ matchGuards [] _ rhs _ -- NB: The success of this clause depends on the typechecker not -- wrapping the 'otherwise' in empty HsTyApp or HsWrap constructors -- If it does, you'll get bogus overlap warnings -matchGuards (BodyStmt _ e _ _ : stmts) ctx rhs rhs_ty +matchGuards (BodyStmt _ e _ _ : stmts) ctx deltas rhs rhs_ty | Just addTicks <- isTrueLHsExpr e = do - match_result <- matchGuards stmts ctx rhs rhs_ty + match_result <- matchGuards stmts ctx deltas rhs rhs_ty return (adjustMatchResultDs addTicks match_result) -matchGuards (BodyStmt _ expr _ _ : stmts) ctx rhs rhs_ty = do - match_result <- matchGuards stmts ctx rhs rhs_ty +matchGuards (BodyStmt _ expr _ _ : stmts) ctx deltas rhs rhs_ty = do + match_result <- matchGuards stmts ctx deltas rhs rhs_ty pred_expr <- dsLExpr expr return (mkGuardedMatchResult pred_expr match_result) -matchGuards (LetStmt _ binds : stmts) ctx rhs rhs_ty = do - match_result <- matchGuards stmts ctx rhs rhs_ty +matchGuards (LetStmt _ binds : stmts) ctx deltas rhs rhs_ty = do + match_result <- matchGuards stmts ctx deltas rhs rhs_ty return (adjustMatchResultDs (dsLocalBinds binds) match_result) -- NB the dsLet occurs inside the match_result -- Reason: dsLet takes the body expression as its argument -- so we can't desugar the bindings without the -- body expression in hand -matchGuards (BindStmt _ pat bind_rhs : stmts) ctx rhs rhs_ty = do +matchGuards (BindStmt _ pat bind_rhs : stmts) ctx deltas rhs rhs_ty = do let upat = unLoc pat match_var <- selectMatchVar Many upat -- We only allow unrestricted patterns in guard, hence the `Many` -- above. It isn't clear what linear patterns would mean, maybe we will -- figure it out in the future. - match_result <- matchGuards stmts ctx rhs rhs_ty + match_result <- matchGuards stmts ctx deltas rhs rhs_ty core_rhs <- dsLExpr bind_rhs match_result' <- matchSinglePatVar match_var (StmtCtxt ctx) pat rhs_ty match_result pure $ bindNonRec match_var core_rhs <$> match_result' -matchGuards (LastStmt {} : _) _ _ _ = panic "matchGuards LastStmt" -matchGuards (ParStmt {} : _) _ _ _ = panic "matchGuards ParStmt" -matchGuards (TransStmt {} : _) _ _ _ = panic "matchGuards TransStmt" -matchGuards (RecStmt {} : _) _ _ _ = panic "matchGuards RecStmt" -matchGuards (ApplicativeStmt {} : _) _ _ _ = +matchGuards (LastStmt {} : _) _ _ _ _ = panic "matchGuards LastStmt" +matchGuards (ParStmt {} : _) _ _ _ _ = panic "matchGuards ParStmt" +matchGuards (TransStmt {} : _) _ _ _ _ = panic "matchGuards TransStmt" +matchGuards (RecStmt {} : _) _ _ _ _ = panic "matchGuards RecStmt" +matchGuards (ApplicativeStmt {} : _) _ _ _ _ = panic "matchGuards ApplicativeLastStmt" {- ===================================== compiler/GHC/HsToCore/Match.hs ===================================== @@ -35,6 +35,7 @@ import GHC.Tc.Utils.Zonk import GHC.Tc.Types.Evidence import GHC.Tc.Utils.Monad import GHC.HsToCore.PmCheck +import GHC.HsToCore.PmCheck.Types ( Deltas, initDeltas ) import GHC.Core import GHC.Types.Literal import GHC.Core.Utils @@ -65,7 +66,7 @@ import GHC.Data.FastString import GHC.Types.Unique import GHC.Types.Unique.DFM -import Control.Monad( unless ) +import Control.Monad(zipWithM, unless ) import Data.List.NonEmpty (NonEmpty(..)) import qualified Data.List.NonEmpty as NEL import qualified Data.Map as Map @@ -767,49 +768,47 @@ matchWrapper ctxt mb_scr (MG { mg_alts = L _ matches -- Pattern match check warnings for /this match-group/. -- @rhss_deltas@ is a flat list of covered Deltas for each RHS. -- Each Match will split off one Deltas for its RHSs from this. - ; rhss_deltas <- if isMatchContextPmChecked dflags origin ctxt + ; matches_deltas <- if isMatchContextPmChecked dflags origin ctxt then addScrutTmCs mb_scr new_vars $ - -- See Note [Type and Term Equality Propagation] - checkMatches (DsMatchContext ctxt locn) new_vars matches - else pure [] -- Ultimately this will result in passing Nothing - -- to dsGRHSs as match_deltas + -- See Note [Type and Term Equality Propagation] + checkMatches (DsMatchContext ctxt locn) new_vars matches + else pure (initDeltasMatches matches) - ; eqns_info <- mk_eqn_infos matches rhss_deltas + ; eqns_info <- zipWithM mk_eqn_info matches matches_deltas ; result_expr <- handleWarnings $ matchEquations ctxt new_vars eqns_info rhs_ty ; return (new_vars, result_expr) } where - -- rhss_deltas is a flat list, whereas there are multiple GRHSs per match. - -- mk_eqn_infos will thread rhss_deltas as state through calls to - -- mk_eqn_info, distributing each rhss_deltas to a GRHS. - mk_eqn_infos (L _ match : matches) rhss_deltas - = do { (info, rhss_deltas') <- mk_eqn_info match rhss_deltas - ; infos <- mk_eqn_infos matches rhss_deltas' - ; return (info:infos) } - mk_eqn_infos [] _ = return [] -- Called once per equation in the match, or alternative in the case - mk_eqn_info (Match { m_pats = pats, m_grhss = grhss }) rhss_deltas - | GRHSs _ grhss' _ <- grhss, let n_grhss = length grhss' + mk_eqn_info :: LMatch GhcTc (LHsExpr GhcTc) -> (Deltas, NonEmpty Deltas) -> DsM EquationInfo + mk_eqn_info (L _ (Match { m_pats = pats, m_grhss = grhss })) (pat_deltas, rhss_deltas) = do { dflags <- getDynFlags ; let upats = map (unLoc . decideBangHood dflags) pats - -- Split off one Deltas for each GRHS of the current Match from the - -- flat list of GRHS Deltas *for all matches* (see the call to - -- checkMatches above). - ; let (match_deltas, rhss_deltas') = splitAt n_grhss rhss_deltas - -- The list of Deltas is empty iff we don't perform any coverage - -- checking, in which case nonEmpty does the right thing by passing - -- Nothing. - ; match_result <- dsGRHSs ctxt grhss rhs_ty (NEL.nonEmpty match_deltas) - ; return ( EqnInfo { eqn_pats = upats - , eqn_orig = FromSource - , eqn_rhs = match_result } - , rhss_deltas' ) } + -- pat_deltas is the covered set *after* matching the pattern, but + -- before any of the GRHSs. We extend the environment with pat_deltas + -- (via updPmDeltas) so that the where-clause of 'grhss' can profit + -- from that knowledge (#18533) + ; match_result <- updPmDeltas pat_deltas $ + dsGRHSs ctxt grhss rhs_ty rhss_deltas + ; return EqnInfo { eqn_pats = upats + , eqn_orig = FromSource + , eqn_rhs = match_result } } handleWarnings = if isGenerated origin then discardWarningsDs else id + initDeltasMatches :: [LMatch GhcTc b] -> [(Deltas, NonEmpty Deltas)] + initDeltasMatches ms + = map (\(L _ m) -> (initDeltas, initDeltasGRHSs (m_grhss m))) ms + + initDeltasGRHSs :: GRHSs GhcTc b -> NonEmpty Deltas + initDeltasGRHSs m = expectJust "GRHSs non-empty" + $ NEL.nonEmpty + $ replicate (length (grhssGRHSs m)) initDeltas + + matchEquations :: HsMatchContext GhcRn -> [MatchId] -> [EquationInfo] -> Type -> DsM CoreExpr ===================================== compiler/GHC/HsToCore/Monad.hs ===================================== @@ -407,7 +407,7 @@ getPmDeltas = do { env <- getLclEnv; return (dsl_deltas env) } -- | Set the pattern match oracle state within the scope of the given action. -- See 'dsl_deltas'. updPmDeltas :: Deltas -> DsM a -> DsM a -updPmDeltas delta = updLclEnv (\env -> env { dsl_deltas = delta }) +updPmDeltas deltas = updLclEnv (\env -> env { dsl_deltas = deltas }) getSrcSpanDs :: DsM SrcSpan getSrcSpanDs = do { env <- getLclEnv ===================================== compiler/GHC/HsToCore/PmCheck.hs ===================================== @@ -13,7 +13,7 @@ Pattern Matching Coverage Checking. module GHC.HsToCore.PmCheck ( -- Checking and printing - checkSingle, checkMatches, checkGuardMatches, + checkSingle, checkMatches, checkGRHSs, isMatchContextPmChecked, -- See Note [Type and Term Equality Propagation] @@ -66,6 +66,7 @@ import GHC.Utils.Monad (concatMapM) import Control.Monad (when, forM_, zipWithM) import Data.List (elemIndex) import qualified Data.Semigroup as Semi +import Data.List.NonEmpty (NonEmpty(..)) {- This module checks pattern matches for: @@ -150,13 +151,11 @@ data GrdTree -- ^ @Guard grd t@ will try to match @grd@ and on success continue to match -- @t at . Falls through if either match fails. Models left-to-right semantics -- of pattern matching. - | Sequence !GrdTree !GrdTree - -- ^ @Sequence l r@ first matches against @l@, and then matches all - -- fallen-through values against @r at . Models top-to-bottom semantics of - -- pattern matching. - | Empty - -- ^ A @GrdTree@ that always fails. Most useful for - -- Note [Checking EmptyCase]. A neutral element to 'Sequence'. + | Sequence ![GrdTree] + -- ^ @Sequence (t:ts)@ matches against @t@, and then matches all + -- fallen-through values against @Sequence ts at . Models top-to-bottom semantics + -- of pattern matching. + -- @Sequence []@ always fails; it is useful for Note [Checking EmptyCase]. -- | The digest of 'checkGrdTree', representing the annotated pattern-match -- tree. 'redundantAndInaccessibleRhss' can figure out redundant and proper @@ -170,10 +169,10 @@ data AnnotatedTree | MayDiverge !AnnotatedTree -- ^ Asserts that the tree may force diverging values, so not all of its -- clauses can be redundant. - | SequenceAnn !AnnotatedTree !AnnotatedTree - -- ^ Mirrors 'Sequence' for preserving the skeleton of a 'GrdTree's. - | EmptyAnn - -- ^ Mirrors 'Empty' for preserving the skeleton of a 'GrdTree's. + | SequenceAnn !Deltas ![AnnotatedTree] + -- ^ @SequenceAnn inc ts@ mirrors @'Sequence' ts@ for preserving the + -- skeleton of a 'GrdTree's @ts at . It also carries the set of incoming values + -- @inc at . pprRhsInfo :: RhsInfo -> SDoc pprRhsInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) @@ -189,23 +188,15 @@ instance Outputable GrdTree where collect_grds t = (t, []) prefix [] = [] prefix (s:sdocs) = char '|' <+> s : map (comma <+>) sdocs - -- Format nested Sequences in blocks "{ grds1; grds2; ... }" - ppr t at Sequence{} = braces (space <> fsep (punctuate semi (collect_seqs t)) <> space) - where - collect_seqs (Sequence l r) = collect_seqs l ++ collect_seqs r - collect_seqs t = [ppr t] - ppr Empty = text "" + ppr (Sequence []) = text "" + ppr (Sequence ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) instance Outputable AnnotatedTree where - ppr (AccessibleRhs _ info) = pprRhsInfo info + ppr (AccessibleRhs _delta info) = parens (ppr _delta) <+> pprRhsInfo info ppr (InaccessibleRhs info) = text "inaccessible" <+> pprRhsInfo info ppr (MayDiverge t) = text "div" <+> ppr t - -- Format nested Sequences in blocks "{ grds1; grds2; ... }" - ppr t at SequenceAnn{} = braces (space <> fsep (punctuate semi (collect_seqs t)) <> space) - where - collect_seqs (SequenceAnn l r) = collect_seqs l ++ collect_seqs r - collect_seqs t = [ppr t] - ppr EmptyAnn = text "" + ppr (SequenceAnn _ []) = text "" + ppr (SequenceAnn _ ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) -- | Lift 'addPmCts' over 'Deltas'. addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas @@ -264,7 +255,7 @@ checkSingle dflags ctxt@(DsMatchContext kind locn) var p = do -- Omitting checking this flag emits redundancy warnings twice in obscure -- cases like #17646. when (exhaustive dflags kind) $ do - -- TODO: This could probably call checkMatches, like checkGuardMatches. + -- TODO: This could probably call checkMatches, like checkGRHSs. missing <- getPmDeltas tracePm "checkSingle: missing" (ppr missing) fam_insts <- dsGetFamInstEnvs @@ -274,12 +265,12 @@ checkSingle dflags ctxt@(DsMatchContext kind locn) var p = do -- | Exhaustive for guard matches, is used for guards in pattern bindings and -- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. -checkGuardMatches +checkGRHSs :: HsMatchContext GhcRn -- ^ Match context, for warning messages -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check - -> DsM [Deltas] -- ^ Covered 'Deltas' for each RHS, for long + -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long -- distance info -checkGuardMatches hs_ctx guards@(GRHSs _ grhss _) = do +checkGRHSs hs_ctx guards@(GRHSs _ grhss _) = do let combinedLoc = foldl1 combineSrcSpans (map getLoc grhss) dsMatchContext = DsMatchContext hs_ctx combinedLoc match = L combinedLoc $ @@ -287,7 +278,8 @@ checkGuardMatches hs_ctx guards@(GRHSs _ grhss _) = do , m_ctxt = hs_ctx , m_pats = [] , m_grhss = guards } - checkMatches dsMatchContext [] [match] + [(_, deltas)] <- checkMatches dsMatchContext [] [match] + pure deltas -- | Check a list of syntactic /match/es (part of case, functions, etc.), each -- with a /pat/ and one or more /grhss/: @@ -306,10 +298,9 @@ checkMatches :: DsMatchContext -- ^ Match context, for warnings messages -> [Id] -- ^ Match variables, i.e. x and y above -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches - -> DsM [Deltas] -- ^ One covered 'Deltas' per RHS, for long + -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per RHS, for long -- distance info. checkMatches ctxt vars matches = do - dflags <- getDynFlags tracePm "checkMatches" (hang (vcat [ppr ctxt , ppr vars , text "Matches:"]) @@ -322,25 +313,45 @@ checkMatches ctxt vars matches = do [] | [var] <- vars -> addPmCtDeltas init_deltas (PmNotBotCt var) _ -> pure init_deltas fam_insts <- dsGetFamInstEnvs - grd_tree <- mkGrdTreeMany [] <$> mapM (translateMatch fam_insts vars) matches + grd_tree <- translateMatches fam_insts vars matches res <- checkGrdTree grd_tree missing + dflags <- getDynFlags dsPmWarn dflags ctxt vars res - return (extractRhsDeltas init_deltas (cr_clauses res)) + return (extractRhsDeltas (cr_clauses res)) --- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree'. +-- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree' for a match +-- group. -- For 'AccessibleRhs's, this is stored in the tree node, whereas -- 'InaccessibleRhs's fall back to the supplied original 'Deltas'. -- See @Note [Recovering from unsatisfiable pattern-matching constraints]@. -extractRhsDeltas :: Deltas -> AnnotatedTree -> [Deltas] -extractRhsDeltas orig_deltas = fromOL . go +extractRhsDeltas :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] +extractRhsDeltas = go_matches where - go (AccessibleRhs deltas _) = unitOL deltas - go (InaccessibleRhs _) = unitOL orig_deltas - go (MayDiverge t) = go t - go (SequenceAnn l r) = go l Semi.<> go r - go EmptyAnn = nilOL + go_matches :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] + go_matches (SequenceAnn def ts) = map (go_match def) ts -- -XEmptyCase handled here! + go_matches t = pprPanic "extractRhsDeltas.go_matches" (text "Matches must start with SequenceAnn. But was" $$ ppr t) + + go_match :: Deltas -> AnnotatedTree -> (Deltas, NonEmpty Deltas) + -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ + -- is non-empty! + go_match def (SequenceAnn pat ts) = (pat, foldMap1 (text "go_match: empty SequenceAnn") (go_grhss def) ts) + go_match def (MayDiverge t) = go_match def t + -- Even if there's only a single GRHS, we wrap it in a SequenceAnn for the + -- Deltas covered by the pattern. So the remaining cases are impossible! + go_match _ t = pprPanic "extractRhsDeltas.go_match" (text "Single GRHS must be wrapped in SequenceAnn. But got " $$ ppr t) + + go_grhss :: Deltas -> AnnotatedTree -> NonEmpty Deltas + -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ + -- is non-empty! + go_grhss def (SequenceAnn _ ts) = foldMap1 (text "go_grhss: empty SequenceAnn") (go_grhss def) ts + go_grhss def (MayDiverge t) = go_grhss def t + go_grhss _ (AccessibleRhs deltas _) = deltas :| [] + go_grhss def (InaccessibleRhs _) = def :| [] + + foldMap1 msg _ [] = pprPanic "extractRhsDeltas.foldMap1" msg + foldMap1 _ f (x:xs) = foldl' (\acc x -> acc Semi.<> f x) (f x) xs {- Note [Checking EmptyCase] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -629,34 +640,43 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- 1. 2. 3. pure (con_grd : bang_grds ++ arg_grds) -mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree -mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) - -mkGrdTreeMany :: GrdVec -> [GrdTree] -> GrdTree -mkGrdTreeMany _ [] = Empty -mkGrdTreeMany grds trees = foldr Guard (foldr1 Sequence trees) grds +-- | Translate a the 'Match'es of a 'MatchGroup' +translateMatches :: FamInstEnvs -> [Id] -> [LMatch GhcTc (LHsExpr GhcTc)] + -> DsM GrdTree +translateMatches fam_insts vars matches = + -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. + -- 'extractRhsDeltas' needs this to recover 'MatchGroup' structure. + Sequence <$> traverse (translateMatch fam_insts vars) matches -- Translate a single match translateMatch :: FamInstEnvs -> [Id] -> LMatch GhcTc (LHsExpr GhcTc) -> DsM GrdTree translateMatch fam_insts vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do - pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats - grhss' <- mapM (translateLGRHS fam_insts match_loc pats) (grhssGRHSs grhss) - -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss, ppr grhss']) - return (mkGrdTreeMany pats' grhss') + pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats + grhss' <- translateGRHSs fam_insts match_loc (sep (map ppr pats)) grhss + -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss']) + return (foldr Guard grhss' pats') --- ----------------------------------------------------------------------- --- * Transform source guards (GuardStmt Id) to simpler PmGrds +mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree +mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) + +translateGRHSs :: FamInstEnvs -> SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM GrdTree +translateGRHSs fam_insts match_loc pp_pats grhss = + -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. + -- 'extractRhsDeltas' needs this to recover 'GRHSs' structure. + Sequence <$> traverse (translateLGRHS fam_insts match_loc pp_pats) (grhssGRHSs grhss) -- | Translate a guarded right-hand side to a single 'GrdTree' -translateLGRHS :: FamInstEnvs -> SrcSpan -> [LPat GhcTc] -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateLGRHS fam_insts match_loc pats (L _loc (GRHS _ gs _)) = - -- _loc apparently points to the match separator that comes after the guards.. +translateLGRHS :: FamInstEnvs -> SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree +translateLGRHS fam_insts match_loc pp_pats (L _loc (GRHS _ gs _)) = + -- _loc points to the match separator (ie =, ->) that comes after the guards.. mkGrdTreeRhs loc_sdoc <$> concatMapM (translateGuard fam_insts . unLoc) gs where loc_sdoc - | null gs = L match_loc (sep (map ppr pats)) - | otherwise = L grd_loc (sep (map ppr pats) <+> vbar <+> interpp'SP gs) + -- pp_pats is the space-separated pattern of the current Match this + -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . + | null gs = L match_loc pp_pats + | otherwise = L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) L grd_loc _ = head gs -- | Translate a guard statement to a 'GrdVec' @@ -971,6 +991,7 @@ checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do unc_this <- addPmCtDeltas deltas (PmNotConCt x con) deltas' <- addPmCtsDeltas deltas $ listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args + -- tracePm "checkGrdTree:Con" (ppr deltas $$ ppr x $$ ppr con $$ ppr dicts $$ ppr deltas') CheckResult tree' unc_inner prec <- checkGrdTree' tree deltas' limit <- maxPmCheckModels <$> getDynFlags let (prec', unc') = throttle limit deltas (unc_this Semi.<> unc_inner) @@ -979,19 +1000,21 @@ checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do , cr_uncov = unc' , cr_approx = prec Semi.<> prec' } -- Sequence: Thread residual uncovered sets from equation to equation -checkGrdTree' (Sequence l r) unc_0 = do - CheckResult l' unc_1 prec_l <- checkGrdTree' l unc_0 - CheckResult r' unc_2 prec_r <- checkGrdTree' r unc_1 - pure CheckResult - { cr_clauses = SequenceAnn l' r' - , cr_uncov = unc_2 - , cr_approx = prec_l Semi.<> prec_r } --- Empty: Fall through for all values -checkGrdTree' Empty unc = do - pure CheckResult - { cr_clauses = EmptyAnn - , cr_uncov = unc - , cr_approx = Precise } +checkGrdTree' (Sequence ts) init_unc = go [] init_unc Precise ts + where + -- | Accumulates a CheckResult. Its type is more like + -- @CheckResult -> [GrdTree] -> CheckResult@, but cr_clauses is a single + -- 'AnnotatedTree', not a list thereof. Hence 3 parameters to thread the + -- fields. + go :: [AnnotatedTree] -> Deltas -> Precision -> [GrdTree] -> DsM CheckResult + -- No cases left: Fall through for all values + go ts' unc prec [] = pure CheckResult + { cr_clauses = SequenceAnn init_unc (reverse ts') + , cr_uncov = unc + , cr_approx = prec } + go ts' unc prec (t:ts) = do + CheckResult t' unc_1 prec_t <- checkGrdTree' t unc + go (t':ts') unc_1 (prec_t Semi.<> prec) ts -- | Print diagnostic info and actually call 'checkGrdTree''. checkGrdTree :: GrdTree -> Deltas -> DsM CheckResult @@ -1117,8 +1140,7 @@ redundantAndInaccessibleRhss tree = (fromOL ol_red, fromOL ol_inacc) (acc, inacc, red) | isNilOL acc && isNilOL inacc -> (nilOL, red, nilOL) res -> res - go (SequenceAnn l r) = go l Semi.<> go r - go EmptyAnn = (nilOL, nilOL, nilOL) + go (SequenceAnn _ ts) = foldMap go ts {- Note [Determining inaccessible clauses] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/HsToCore/PmCheck/Oracle.hs ===================================== @@ -1070,7 +1070,8 @@ ensureAllPossibleMatchesInhabited delta at MkDelta{ delta_tm_st = TmSt env reps } = runMaybeT (set_tm_cs_env delta <$> traverseSDIE go env) where set_tm_cs_env delta env = delta{ delta_tm_st = TmSt env reps } - go vi = MaybeT (ensureInhabited delta vi) + go vi = MaybeT $ + initPossibleMatches (delta_ty_st delta) vi >>= ensureInhabited delta -------------------------------------- -- * Term oracle unification procedure @@ -1668,7 +1669,7 @@ addCoreCt :: Delta -> Id -> CoreExpr -> MaybeT DsM Delta addCoreCt delta x e = do dflags <- getDynFlags let e' = simpleOptExpr dflags e - lift $ tracePm "addCoreCt" (ppr x $$ ppr e $$ ppr e') + lift $ tracePm "addCoreCt" (ppr x <+> dcolon <+> ppr (idType x) $$ ppr e $$ ppr e') execStateT (core_expr x e') delta where -- | Takes apart a 'CoreExpr' and tries to extract as much information about ===================================== compiler/GHC/Parser.y ===================================== @@ -1961,7 +1961,7 @@ type :: { LHsType GhcPs } | btype '#->' ctype {% hintLinear (getLoc $2) >> ams (sLL $1 $> $ HsFunTy noExtField HsLinearArrow $1 $3) - [mu AnnRarrow $2] } + [mu AnnLolly $2] } mult :: { LHsType GhcPs } : btype { $1 } @@ -2089,10 +2089,10 @@ tv_bndrs :: { [LHsTyVarBndr Specificity GhcPs] } tv_bndr :: { LHsTyVarBndr Specificity GhcPs } : tv_bndr_no_braces { $1 } | '{' tyvar '}' {% ams (sLL $1 $> (UserTyVar noExtField InferredSpec $2)) - [mop $1, mcp $3] } + [moc $1, mcc $3] } | '{' tyvar '::' kind '}' {% ams (sLL $1 $> (KindedTyVar noExtField InferredSpec $2 $4)) - [mop $1,mu AnnDcolon $3 - ,mcp $5] } + [moc $1,mu AnnDcolon $3 + ,mcc $5] } tv_bndr_no_braces :: { LHsTyVarBndr Specificity GhcPs } : tyvar { sL1 $1 (UserTyVar noExtField SpecifiedSpec $1) } @@ -3728,6 +3728,7 @@ isUnicode (L _ (ITcparenbar iu)) = iu == UnicodeSyntax isUnicode (L _ (ITopenExpQuote _ iu)) = iu == UnicodeSyntax isUnicode (L _ (ITcloseQuote iu)) = iu == UnicodeSyntax isUnicode (L _ (ITstar iu)) = iu == UnicodeSyntax +isUnicode (L _ (ITlolly iu)) = iu == UnicodeSyntax isUnicode _ = False hasE :: Located Token -> Bool ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -2612,6 +2612,7 @@ warnPrepositiveQualifiedModule span = <+> text "in prepositive position" $$ text "Suggested fix: place " <+> quotes (text "qualified") <+> text "after the module name instead." + $$ text "To allow this, enable language extension 'ImportQualifiedPost'" failOpNotEnabledImportQualifiedPost :: SrcSpan -> P () failOpNotEnabledImportQualifiedPost loc = addError loc msg ===================================== compiler/GHC/Tc/Errors/Hole.hs ===================================== @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ExistentialQuantification #-} {-# OPTIONS_GHC -Wno-incomplete-record-updates #-} @@ -779,7 +780,9 @@ tcFilterHoleFits limit typed_hole ht@(hole_ty, _) candidates = Just (dataConWrapId con, dataConNonlinearType con) _ -> Nothing } where name = case hfc of +#if __GLASGOW_HASKELL__ <= 810 IdHFCand id -> idName id +#endif GreHFCand gre -> gre_name gre NameHFCand name -> name discard_it = go subs seen maxleft ty elts ===================================== compiler/GHC/Tc/Gen/HsType.hs ===================================== @@ -1079,7 +1079,9 @@ tc_hs_type mode rn_ty@(HsTupleTy _ hs_tup_sort tys) exp_kind HsUnboxedTuple -> UnboxedTuple HsBoxedTuple -> BoxedTuple HsConstraintTuple -> ConstraintTuple +#if __GLASGOW_HASKELL__ <= 810 _ -> panic "tc_hs_type HsTupleTy" +#endif tc_hs_type mode rn_ty@(HsSumTy _ hs_tys) exp_kind = do { let arity = length hs_tys ===================================== compiler/GHC/Utils/Monad.hs ===================================== @@ -226,3 +226,175 @@ unlessM condM acc = do { cond <- condM filterOutM :: (Applicative m) => (a -> m Bool) -> [a] -> m [a] filterOutM p = foldr (\ x -> liftA2 (\ flg -> if flg then id else (x:)) (p x)) (pure []) + +{- Note [The one-shot state monad trick] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Summary: many places in GHC use a state monad, and we really want those +functions to be eta-expanded (#18202). + +The problem +~~~~~~~~~~~ +Consider + newtype M a = MkM (State -> (State, a)) + + instance Monad M where + mf >>= k = MkM (\s -> case mf of MkM f -> + case f s of (s',r) -> + case k r of MkM g -> + g s') + + fooM :: Int -> M Int + fooM x = g y >>= \r -> h r + where + y = expensive x + +Now suppose you say (repeat 20 (fooM 4)), where + repeat :: Int -> M Int -> M Int +performs its argument n times. You would expect (expensive 4) to be +evaluated only once, not 20 times. So foo should have arity 1 (not 2); +it should look like this (modulo casts) + + fooM x = let y = expensive x in + \s -> case g y of ... + +But creating and then repeating, a monadic computation is rare. If you +/aren't/ re-using (M a) value, it's /much/ more efficient to make +foo have arity 2, thus: + + fooM x s = case g (expensive x) of ... + +Why more efficient? Because now foo takes its argument both at once, +rather than one at a time, creating a heap-allocated function closure. See +https://www.joachim-breitner.de/blog/763-Faster_Winter_5__Eta-Expanding_ReaderT +for a very good explanation of the issue which led to these optimisations +into GHC. + +The trick +~~~~~~~~~ +With state monads like M the general case is that we *aren't* reusing +(M a) values so it is much more efficient to avoid allocating a +function closure for them. So the state monad trick is a way to keep +the monadic syntax but to make GHC eta-expand functions like `fooM`. +To do that we use the "oneShot" magic function. + +Here is the trick: + * Define a "smart constructor" + mkM :: (State -> (State,a)) -> M a + mkM f = MkM (oneShot m) + + * Never call MkM directly, as a constructor. Instead, always call mkM. + +And that's it! The magic 'oneShot' function does this transformation: + oneShot (\s. e) ==> \s{os}. e +which pins a one-shot flag {os} onto the binder 's'. That tells GHC +that it can assume the lambda is called only once, and thus can freely +float computations in and out of the lambda. + +To be concrete, let's see what happens to fooM: + + fooM = \x. g (expensive x) >>= \r -> h r + = \x. let mf = g (expensive x) + k = \r -> h r + in MkM (oneShot (\s -> case mf of MkM' f -> + case f s of (s',r) -> + case k r of MkM' g -> + g s')) + -- The MkM' are just newtype casts nt_co + = \x. let mf = g (expensive x) + k = \r -> h r + in (\s{os}. case (mf |> nt_co) s of (s',r) -> + (k r) |> nt_co s') + |> sym nt_co + + -- Crucial step: float let-bindings into that \s{os} + = \x. (\s{os}. case (g (expensive x) |> nt_co) s of (s',r) -> + h r |> nt_co s') + |> sym nt_co + +and voila! fooM has arity 2. + +The trick is very similar to the built-in "state hack" +(see Note [The state-transformer hack] in "GHC.Core.Opt.Arity") but is +applicable on a monad-by-monad basis under programmer control. + +Using pattern synonyms +~~~~~~~~~~~~~~~~~~~~~~ +Using a smart constructor is fine, but there is no way to check that we +have found *all* uses, especially if the uses escape a single module. +A neat (but more sophisticated) alternative is to use pattern synonyms: + + -- We rename the existing constructor. + newtype M a = MkM' (State -> (State, a)) + + -- The pattern has the old constructor name. + pattern MkM f <- MkM' f + where + MkM f = MkM' (oneShot f) + +Now we can simply grep to check that there are no uses of MkM' +/anywhere/, to guarantee that we have not missed any. (Using the +smart constructor alone we still need the data constructor in +patterns.) That's the advantage of the pattern-synonym approach, but +it is more elaborate. + +The pattern synonym approach is due to Sebastian Graaf (#18238) + +Derived instances +~~~~~~~~~~~~~~~~~ +One caveat of both approaches is that derived instances don't use the smart +constructor /or/ the pattern synonym. So they won't benefit from the automatic +insertion of "oneShot". + + data M a = MkM' (State -> (State,a)) + deriving (Functor) <-- Functor implementation will use MkM'! + +Conclusion: don't use 'derviving' in these cases. + +Multi-shot actions (cf #18238) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Sometimes we really *do* want computations to be shared! Remember our +example (repeat 20 (fooM 4)). See Note [multiShotIO] in GHC.Types.Unique.Supply + +We can force fooM to have arity 1 using multiShot: + + fooM :: Int -> M Int + fooM x = multiShotM (g y >>= \r -> h r) + where + y = expensive x + + multiShotM :: M a -> M a + {-# INLINE multiShotM #-} + multiShotM (MkM m) = MkM (\s -> inline m s) + -- Really uses the data constructor, + -- not the smart constructor! + +Now we can see how fooM optimises (ignoring casts) + + multiShotM (g y >>= \r -> h r) + ==> {inline (>>=)} + multiShotM (\s{os}. case g y s of ...) + ==> {inline multiShotM} + let m = \s{os}. case g y s of ... + in \s. inline m s + ==> {inline m} + \s. (\s{os}. case g y s of ...) s + ==> \s. case g y s of ... + +and voila! the one-shot flag has gone. It's possible that y has been +replaced by (expensive x), but full laziness should pull it back out. +(This part seems less robust.) + +The magic `inline` function does two things +* It prevents eta reduction. If we wrote just + multiShotIO (IO m) = IO (\s -> m s) + the lamda would eta-reduce to 'm' and all would be lost. + +* It helps ensure that 'm' really does inline. + +Note that 'inline' evaporates in phase 0. See Note [inlineIdMagic] +in GHC.Core.Opt.ConstantFold.match_inline. + +The INLINE pragma on multiShotM is very important, else the +'inline' call will evaporate when compiling the module that +defines 'multiShotM', before it is ever exported. +-} ===================================== libraries/base/GHC/IO/Encoding/CodePage.hs ===================================== @@ -1,4 +1,6 @@ +{-# LANGUAGE BangPatterns #-} {-# LANGUAGE CPP #-} +{-# LANGUAGE MagicHash #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE NondecreasingIndentation #-} {-# LANGUAGE Trustworthy #-} ===================================== testsuite/tests/module/mod184.stderr ===================================== @@ -1,3 +1,4 @@ mod184.hs:6:8: warning: [-Wprepositive-qualified-module] Found ‘qualified’ in prepositive position Suggested fix: place ‘qualified’ after the module name instead. + To allow this, enable language extension 'ImportQualifiedPost' ===================================== testsuite/tests/pmcheck/should_compile/T18533.hs ===================================== @@ -0,0 +1,24 @@ +{-# OPTIONS_GHC -Wincomplete-patterns -fforce-recomp #-} +{-# LANGUAGE GADTs, DataKinds, TypeFamilies, BangPatterns #-} + +module T18533 where + +data SBool (b :: Bool) where + STrue :: SBool 'True + SFalse :: SBool 'False + +type family Fam (b :: Bool) +type instance Fam 'True = T + +data T = T Bool + +f :: Fam b -> SBool b -> Bool +f !t s = case s of + STrue -> a where a = case t of T a -> a + _ -> False + + +g :: Bool -> Bool +g x = case x of + True -> a where a = case x of True -> False + False -> True ===================================== testsuite/tests/pmcheck/should_compile/all.T ===================================== @@ -122,6 +122,8 @@ test('T18049', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T18478', collect_compiler_stats('bytes allocated',10), compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) +test('T18533', normal, compile, + ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) # Other tests test('pmc001', [], compile, View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/855f71a9c639a72833b63cd03061cc92785c2228...23fac6834bba3181c13250aee54a28ddbeb3bddb -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/855f71a9c639a72833b63cd03061cc92785c2228...23fac6834bba3181c13250aee54a28ddbeb3bddb You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 06:04:12 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Thu, 13 Aug 2020 02:04:12 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] Parse TSO flags Message-ID: <5f34d7dca6f69_80b3f8495bc8b0479200eb@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: 2fa1768c by Sven Tennie at 2020-08-13T08:03:56+02:00 Parse TSO flags - - - - - 3 changed files: - libraries/ghc-heap/GHC/Exts/Heap/FFIClosures.hsc - libraries/ghc-heap/tests/all.T - + libraries/ghc-heap/tests/parse_tso_flags.hs Changes: ===================================== libraries/ghc-heap/GHC/Exts/Heap/FFIClosures.hsc ===================================== @@ -8,8 +8,6 @@ import Foreign import GHC.Exts.Heap.ProfInfo.Types import GHC.Exts.Heap.Closures(WhatNext(..), WhyBlocked(..), TsoFlags(..)) --- TODO use sum type for what_next, why_blocked, flags? - data TSOFields = TSOFields { tso_what_next :: WhatNext, tso_why_blocked :: WhyBlocked, @@ -59,7 +57,6 @@ parseWhatNext w = case w of (#const ThreadComplete) -> ThreadComplete _ -> WhatNextUnknownValue --- TODO: define mapping parseWhyBlocked :: Word16 -> WhyBlocked parseWhyBlocked w = case w of (#const NotBlocked) -> NotBlocked @@ -80,9 +77,22 @@ parseWhyBlocked w = case w of #endif _ -> WhyBlockedUnknownValue --- TODO: define mapping parseTsoFlags :: Word32 -> [TsoFlags] -parseTsoFlags _ = [] +parseTsoFlags w | isSet (#const TSO_LOCKED) w = TsoLocked : parseTsoFlags (unset (#const TSO_LOCKED) w) + | isSet (#const TSO_BLOCKEX) w = TsoBlockx : parseTsoFlags (unset (#const TSO_BLOCKEX) w) + | isSet (#const TSO_INTERRUPTIBLE) w = TsoInterruptible : parseTsoFlags (unset (#const TSO_INTERRUPTIBLE) w) + | isSet (#const TSO_STOPPED_ON_BREAKPOINT) w = TsoStoppedOnBreakpoint : parseTsoFlags (unset (#const TSO_STOPPED_ON_BREAKPOINT) w) + | isSet (#const TSO_MARKED) w = TsoMarked : parseTsoFlags (unset (#const TSO_MARKED) w) + | isSet (#const TSO_SQUEEZED) w = TsoSqueezed : parseTsoFlags (unset (#const TSO_SQUEEZED) w) + | isSet (#const TSO_ALLOC_LIMIT) w = TsoAllocLimit : parseTsoFlags (unset (#const TSO_ALLOC_LIMIT) w) +parseTsoFlags 0 = [] +parseTsoFlags _ = [TsoFlagsUnknownValue] + +isSet :: Word32 -> Word32 -> Bool +isSet bitMask w = w .&. bitMask /= 0 + +unset :: Word32 -> Word32 -> Word32 +unset bitMask w = w `xor` bitMask data StackFields = StackFields { stack_size :: Word32, ===================================== libraries/ghc-heap/tests/all.T ===================================== @@ -58,3 +58,11 @@ test('prof_info', only_ways(prof_ways) ], multi_compile_and_run, ['prof_info', [('create_tso.c','')], '-prof']) + +test('parse_tso_flags', + [extra_files(['TestUtils.hs']), + only_ways(['normal']), + ignore_stdout, + ignore_stderr + ], + compile_and_run, ['']) ===================================== libraries/ghc-heap/tests/parse_tso_flags.hs ===================================== @@ -0,0 +1,17 @@ +import GHC.Exts.Heap.Closures +import GHC.Exts.Heap.FFIClosures +import TestUtils + +main :: IO() +main = do + assertEqual (parseTsoFlags 0) [] + assertEqual (parseTsoFlags 1) [TsoFlagsUnknownValue] + assertEqual (parseTsoFlags 2) [TsoLocked] + assertEqual (parseTsoFlags 4) [TsoBlockx] + assertEqual (parseTsoFlags 8) [TsoInterruptible] + assertEqual (parseTsoFlags 16) [TsoStoppedOnBreakpoint] + assertEqual (parseTsoFlags 64) [TsoMarked] + assertEqual (parseTsoFlags 128) [TsoSqueezed] + assertEqual (parseTsoFlags 256) [TsoAllocLimit] + + assertEqual (parseTsoFlags 6) [TsoLocked, TsoBlockx] View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2fa1768cbcafb24e08f21ee479bf1ce11d53ac27 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2fa1768cbcafb24e08f21ee479bf1ce11d53ac27 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 07:44:22 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 13 Aug 2020 03:44:22 -0400 Subject: [Git][ghc/ghc][master] parser: Suggest ImportQualifiedPost in prepositive import warning Message-ID: <5f34ef5649576_80b3f84865febec79242d1@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 2 changed files: - compiler/GHC/Parser/PostProcess.hs - testsuite/tests/module/mod184.stderr Changes: ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -2612,6 +2612,7 @@ warnPrepositiveQualifiedModule span = <+> text "in prepositive position" $$ text "Suggested fix: place " <+> quotes (text "qualified") <+> text "after the module name instead." + $$ text "To allow this, enable language extension 'ImportQualifiedPost'" failOpNotEnabledImportQualifiedPost :: SrcSpan -> P () failOpNotEnabledImportQualifiedPost loc = addError loc msg ===================================== testsuite/tests/module/mod184.stderr ===================================== @@ -1,3 +1,4 @@ mod184.hs:6:8: warning: [-Wprepositive-qualified-module] Found ‘qualified’ in prepositive position Suggested fix: place ‘qualified’ after the module name instead. + To allow this, enable language extension 'ImportQualifiedPost' View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/7831fe05021caa90d4696ca91ae2b31a82e65b3d -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/7831fe05021caa90d4696ca91ae2b31a82e65b3d You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 07:45:02 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 13 Aug 2020 03:45:02 -0400 Subject: [Git][ghc/ghc][master] PmCheck: Better long-distance info for where bindings (#18533) Message-ID: <5f34ef7e364f5_80b3f8468e8ce9479307dc@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - 15 changed files: - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Core/Coercion/Opt.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/GuardedRHSs.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/Monad.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - compiler/GHC/Tc/Errors/Hole.hs - compiler/GHC/Tc/Gen/HsType.hs - + testsuite/tests/pmcheck/should_compile/T18533.hs - testsuite/tests/pmcheck/should_compile/all.T Changes: ===================================== compiler/GHC/Cmm/DebugBlock.hs ===================================== @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiWayIf #-} @@ -110,7 +111,9 @@ cmmDebugGen modLoc decls = map (blocksForScope Nothing) topScopes -- recover by copying ticks below. scp' | SubScope _ scp' <- scp = scp' | CombinedScope scp' _ <- scp = scp' +#if __GLASGOW_HASKELL__ <= 810 | otherwise = panic "findP impossible" +#endif scopeMap = foldr (uncurry insertMulti) Map.empty childScopes ===================================== compiler/GHC/Core/Coercion/Opt.hs ===================================== @@ -559,7 +559,10 @@ opt_univ env sym prov role oty1 oty2 where prov' = case prov of +#if __GLASGOW_HASKELL__ <= 810 +-- This alt is redundant with the first match of the FunDef PhantomProv kco -> PhantomProv $ opt_co4_wrap env sym False Nominal kco +#endif ProofIrrelProv kco -> ProofIrrelProv $ opt_co4_wrap env sym False Nominal kco PluginProv _ -> prov ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -1243,7 +1243,9 @@ ppr_infix_expr (HsConLikeOut _ c) = Just (pprInfixOcc (conLikeName c)) ppr_infix_expr (HsRecFld _ f) = Just (pprInfixOcc f) ppr_infix_expr (HsUnboundVar _ occ) = Just (pprInfixOcc occ) ppr_infix_expr (XExpr x) = case (ghcPass @p, x) of +#if __GLASGOW_HASKELL__ <= 810 (GhcPs, _) -> Nothing +#endif (GhcRn, HsExpanded a _) -> ppr_infix_expr a (GhcTc, WrapExpr (HsWrap _ e)) -> ppr_infix_expr e (GhcTc, ExpansionExpr (HsExpanded a _)) -> ppr_infix_expr a ===================================== compiler/GHC/Hs/Pat.hs ===================================== @@ -845,8 +845,10 @@ patNeedsParens p = go go (SigPat {}) = p >= sigPrec go (ViewPat {}) = True go (XPat ext) = case ghcPass @p of +#if __GLASGOW_HASKELL__ <= 810 GhcPs -> noExtCon ext GhcRn -> noExtCon ext +#endif GhcTc -> go inner where CoPat _ inner _ = ext go (WildPat {}) = False ===================================== compiler/GHC/HsToCore/Binds.hs ===================================== @@ -33,7 +33,7 @@ import {-# SOURCE #-} GHC.HsToCore.Match ( matchWrapper ) import GHC.HsToCore.Monad import GHC.HsToCore.GuardedRHSs import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck ( addTyCsDs, checkGuardMatches ) +import GHC.HsToCore.PmCheck ( addTyCsDs, checkGRHSs ) import GHC.Hs -- lots of things import GHC.Core -- lots of things @@ -78,7 +78,6 @@ import GHC.Types.Unique.Set( nonDetEltsUniqSet ) import GHC.Utils.Monad import qualified GHC.LanguageExtensions as LangExt import Control.Monad -import Data.List.NonEmpty ( nonEmpty ) {-********************************************************************** * * @@ -185,8 +184,8 @@ dsHsBind dflags b@(FunBind { fun_id = L loc fun dsHsBind dflags (PatBind { pat_lhs = pat, pat_rhs = grhss , pat_ext = NPatBindTc _ ty , pat_ticks = (rhs_tick, var_ticks) }) - = do { rhss_deltas <- checkGuardMatches PatBindGuards grhss - ; body_expr <- dsGuarded grhss ty (nonEmpty rhss_deltas) + = do { rhss_deltas <- checkGRHSs PatBindGuards grhss + ; body_expr <- dsGuarded grhss ty rhss_deltas ; let body' = mkOptTickBox rhs_tick body_expr pat' = decideBangHood dflags pat ; (force_var,sel_binds) <- mkSelectorBinds var_ticks pat body' ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -31,7 +31,7 @@ import GHC.HsToCore.ListComp import GHC.HsToCore.Utils import GHC.HsToCore.Arrows import GHC.HsToCore.Monad -import GHC.HsToCore.PmCheck ( addTyCsDs, checkGuardMatches ) +import GHC.HsToCore.PmCheck ( addTyCsDs, checkGRHSs ) import GHC.Types.Name import GHC.Types.Name.Env import GHC.Core.FamInstEnv( topNormaliseType ) @@ -70,7 +70,6 @@ import GHC.Utils.Panic import GHC.Core.PatSyn import Control.Monad -import Data.List.NonEmpty ( nonEmpty ) {- ************************************************************************ @@ -216,8 +215,8 @@ dsUnliftedBind (PatBind {pat_lhs = pat, pat_rhs = grhss , pat_ext = NPatBindTc _ ty }) body = -- let C x# y# = rhs in body -- ==> case rhs of C x# y# -> body - do { rhs_deltas <- checkGuardMatches PatBindGuards grhss - ; rhs <- dsGuarded grhss ty (nonEmpty rhs_deltas) + do { match_deltas <- checkGRHSs PatBindGuards grhss + ; rhs <- dsGuarded grhss ty match_deltas ; let upat = unLoc pat eqn = EqnInfo { eqn_pats = [upat], eqn_orig = FromSource, @@ -487,8 +486,8 @@ dsExpr (HsMultiIf res_ty alts) | otherwise = do { let grhss = GRHSs noExtField alts (noLoc emptyLocalBinds) - ; rhss_deltas <- checkGuardMatches IfAlt grhss - ; match_result <- dsGRHSs IfAlt grhss res_ty (nonEmpty rhss_deltas) + ; rhss_deltas <- checkGRHSs IfAlt grhss + ; match_result <- dsGRHSs IfAlt grhss res_ty rhss_deltas ; error_expr <- mkErrorExpr ; extractMatchResult match_result error_expr } where ===================================== compiler/GHC/HsToCore/GuardedRHSs.hs ===================================== @@ -25,7 +25,7 @@ import GHC.Core.Utils (bindNonRec) import GHC.HsToCore.Monad import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck.Types ( Deltas, initDeltas ) +import GHC.HsToCore.PmCheck.Types ( Deltas ) import GHC.Core.Type ( Type ) import GHC.Utils.Misc import GHC.Types.SrcLoc @@ -48,9 +48,9 @@ producing an expression with a runtime error in the corner if necessary. The type argument gives the type of the @ei at . -} -dsGuarded :: GRHSs GhcTc (LHsExpr GhcTc) -> Type -> Maybe (NonEmpty Deltas) -> DsM CoreExpr -dsGuarded grhss rhs_ty mb_rhss_deltas = do - match_result <- dsGRHSs PatBindRhs grhss rhs_ty mb_rhss_deltas +dsGuarded :: GRHSs GhcTc (LHsExpr GhcTc) -> Type -> NonEmpty Deltas -> DsM CoreExpr +dsGuarded grhss rhs_ty rhss_deltas = do + match_result <- dsGRHSs PatBindRhs grhss rhs_ty rhss_deltas error_expr <- mkErrorAppDs nON_EXHAUSTIVE_GUARDS_ERROR_ID rhs_ty empty extractMatchResult match_result error_expr @@ -59,25 +59,28 @@ dsGuarded grhss rhs_ty mb_rhss_deltas = do dsGRHSs :: HsMatchContext GhcRn -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ Guarded RHSs -> Type -- ^ Type of RHS - -> Maybe (NonEmpty Deltas) -- ^ Refined pattern match checking - -- models, one for each GRHS. Defaults - -- to 'initDeltas' if 'Nothing'. + -> NonEmpty Deltas -- ^ Refined pattern match checking + -- models, one for the pattern part and + -- one for each GRHS. -> DsM (MatchResult CoreExpr) -dsGRHSs hs_ctx (GRHSs _ grhss binds) rhs_ty mb_rhss_deltas +dsGRHSs hs_ctx (GRHSs _ grhss binds) rhs_ty rhss_deltas = ASSERT( notNull grhss ) - do { match_results <- case toList <$> mb_rhss_deltas of - Nothing -> mapM (dsGRHS hs_ctx rhs_ty initDeltas) grhss - Just rhss_deltas -> ASSERT( length grhss == length rhss_deltas ) - zipWithM (dsGRHS hs_ctx rhs_ty) rhss_deltas grhss - ; let match_result1 = foldr1 combineMatchResults match_results - match_result2 = adjustMatchResultDs (dsLocalBinds binds) match_result1 + do { match_results <- ASSERT( length grhss == length rhss_deltas ) + zipWithM (dsGRHS hs_ctx rhs_ty) (toList rhss_deltas) grhss + ; deltas <- getPmDeltas + -- We need to remember the Deltas from the particular match context we + -- are in, which might be different to when dsLocalBinds is actually + -- called. + ; let ds_binds = updPmDeltas deltas . dsLocalBinds binds + match_result1 = foldr1 combineMatchResults match_results + match_result2 = adjustMatchResultDs ds_binds match_result1 -- NB: nested dsLet inside matchResult ; return match_result2 } dsGRHS :: HsMatchContext GhcRn -> Type -> Deltas -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM (MatchResult CoreExpr) dsGRHS hs_ctx rhs_ty rhs_deltas (L _ (GRHS _ guards rhs)) - = updPmDeltas rhs_deltas (matchGuards (map unLoc guards) (PatGuard hs_ctx) rhs rhs_ty) + = matchGuards (map unLoc guards) (PatGuard hs_ctx) rhs_deltas rhs rhs_ty {- ************************************************************************ @@ -89,6 +92,7 @@ dsGRHS hs_ctx rhs_ty rhs_deltas (L _ (GRHS _ guards rhs)) matchGuards :: [GuardStmt GhcTc] -- Guard -> HsStmtContext GhcRn -- Context + -> Deltas -- The RHS's covered set for PmCheck -> LHsExpr GhcTc -- RHS -> Type -- Type of RHS of guard -> DsM (MatchResult CoreExpr) @@ -96,8 +100,8 @@ matchGuards :: [GuardStmt GhcTc] -- Guard -- See comments with HsExpr.Stmt re what a BodyStmt means -- Here we must be in a guard context (not do-expression, nor list-comp) -matchGuards [] _ rhs _ - = do { core_rhs <- dsLExpr rhs +matchGuards [] _ deltas rhs _ + = do { core_rhs <- updPmDeltas deltas (dsLExpr rhs) ; return (cantFailMatchResult core_rhs) } -- BodyStmts must be guards @@ -107,41 +111,41 @@ matchGuards [] _ rhs _ -- NB: The success of this clause depends on the typechecker not -- wrapping the 'otherwise' in empty HsTyApp or HsWrap constructors -- If it does, you'll get bogus overlap warnings -matchGuards (BodyStmt _ e _ _ : stmts) ctx rhs rhs_ty +matchGuards (BodyStmt _ e _ _ : stmts) ctx deltas rhs rhs_ty | Just addTicks <- isTrueLHsExpr e = do - match_result <- matchGuards stmts ctx rhs rhs_ty + match_result <- matchGuards stmts ctx deltas rhs rhs_ty return (adjustMatchResultDs addTicks match_result) -matchGuards (BodyStmt _ expr _ _ : stmts) ctx rhs rhs_ty = do - match_result <- matchGuards stmts ctx rhs rhs_ty +matchGuards (BodyStmt _ expr _ _ : stmts) ctx deltas rhs rhs_ty = do + match_result <- matchGuards stmts ctx deltas rhs rhs_ty pred_expr <- dsLExpr expr return (mkGuardedMatchResult pred_expr match_result) -matchGuards (LetStmt _ binds : stmts) ctx rhs rhs_ty = do - match_result <- matchGuards stmts ctx rhs rhs_ty +matchGuards (LetStmt _ binds : stmts) ctx deltas rhs rhs_ty = do + match_result <- matchGuards stmts ctx deltas rhs rhs_ty return (adjustMatchResultDs (dsLocalBinds binds) match_result) -- NB the dsLet occurs inside the match_result -- Reason: dsLet takes the body expression as its argument -- so we can't desugar the bindings without the -- body expression in hand -matchGuards (BindStmt _ pat bind_rhs : stmts) ctx rhs rhs_ty = do +matchGuards (BindStmt _ pat bind_rhs : stmts) ctx deltas rhs rhs_ty = do let upat = unLoc pat match_var <- selectMatchVar Many upat -- We only allow unrestricted patterns in guard, hence the `Many` -- above. It isn't clear what linear patterns would mean, maybe we will -- figure it out in the future. - match_result <- matchGuards stmts ctx rhs rhs_ty + match_result <- matchGuards stmts ctx deltas rhs rhs_ty core_rhs <- dsLExpr bind_rhs match_result' <- matchSinglePatVar match_var (StmtCtxt ctx) pat rhs_ty match_result pure $ bindNonRec match_var core_rhs <$> match_result' -matchGuards (LastStmt {} : _) _ _ _ = panic "matchGuards LastStmt" -matchGuards (ParStmt {} : _) _ _ _ = panic "matchGuards ParStmt" -matchGuards (TransStmt {} : _) _ _ _ = panic "matchGuards TransStmt" -matchGuards (RecStmt {} : _) _ _ _ = panic "matchGuards RecStmt" -matchGuards (ApplicativeStmt {} : _) _ _ _ = +matchGuards (LastStmt {} : _) _ _ _ _ = panic "matchGuards LastStmt" +matchGuards (ParStmt {} : _) _ _ _ _ = panic "matchGuards ParStmt" +matchGuards (TransStmt {} : _) _ _ _ _ = panic "matchGuards TransStmt" +matchGuards (RecStmt {} : _) _ _ _ _ = panic "matchGuards RecStmt" +matchGuards (ApplicativeStmt {} : _) _ _ _ _ = panic "matchGuards ApplicativeLastStmt" {- ===================================== compiler/GHC/HsToCore/Match.hs ===================================== @@ -35,6 +35,7 @@ import GHC.Tc.Utils.Zonk import GHC.Tc.Types.Evidence import GHC.Tc.Utils.Monad import GHC.HsToCore.PmCheck +import GHC.HsToCore.PmCheck.Types ( Deltas, initDeltas ) import GHC.Core import GHC.Types.Literal import GHC.Core.Utils @@ -65,7 +66,7 @@ import GHC.Data.FastString import GHC.Types.Unique import GHC.Types.Unique.DFM -import Control.Monad( unless ) +import Control.Monad(zipWithM, unless ) import Data.List.NonEmpty (NonEmpty(..)) import qualified Data.List.NonEmpty as NEL import qualified Data.Map as Map @@ -767,49 +768,47 @@ matchWrapper ctxt mb_scr (MG { mg_alts = L _ matches -- Pattern match check warnings for /this match-group/. -- @rhss_deltas@ is a flat list of covered Deltas for each RHS. -- Each Match will split off one Deltas for its RHSs from this. - ; rhss_deltas <- if isMatchContextPmChecked dflags origin ctxt + ; matches_deltas <- if isMatchContextPmChecked dflags origin ctxt then addScrutTmCs mb_scr new_vars $ - -- See Note [Type and Term Equality Propagation] - checkMatches (DsMatchContext ctxt locn) new_vars matches - else pure [] -- Ultimately this will result in passing Nothing - -- to dsGRHSs as match_deltas + -- See Note [Type and Term Equality Propagation] + checkMatches (DsMatchContext ctxt locn) new_vars matches + else pure (initDeltasMatches matches) - ; eqns_info <- mk_eqn_infos matches rhss_deltas + ; eqns_info <- zipWithM mk_eqn_info matches matches_deltas ; result_expr <- handleWarnings $ matchEquations ctxt new_vars eqns_info rhs_ty ; return (new_vars, result_expr) } where - -- rhss_deltas is a flat list, whereas there are multiple GRHSs per match. - -- mk_eqn_infos will thread rhss_deltas as state through calls to - -- mk_eqn_info, distributing each rhss_deltas to a GRHS. - mk_eqn_infos (L _ match : matches) rhss_deltas - = do { (info, rhss_deltas') <- mk_eqn_info match rhss_deltas - ; infos <- mk_eqn_infos matches rhss_deltas' - ; return (info:infos) } - mk_eqn_infos [] _ = return [] -- Called once per equation in the match, or alternative in the case - mk_eqn_info (Match { m_pats = pats, m_grhss = grhss }) rhss_deltas - | GRHSs _ grhss' _ <- grhss, let n_grhss = length grhss' + mk_eqn_info :: LMatch GhcTc (LHsExpr GhcTc) -> (Deltas, NonEmpty Deltas) -> DsM EquationInfo + mk_eqn_info (L _ (Match { m_pats = pats, m_grhss = grhss })) (pat_deltas, rhss_deltas) = do { dflags <- getDynFlags ; let upats = map (unLoc . decideBangHood dflags) pats - -- Split off one Deltas for each GRHS of the current Match from the - -- flat list of GRHS Deltas *for all matches* (see the call to - -- checkMatches above). - ; let (match_deltas, rhss_deltas') = splitAt n_grhss rhss_deltas - -- The list of Deltas is empty iff we don't perform any coverage - -- checking, in which case nonEmpty does the right thing by passing - -- Nothing. - ; match_result <- dsGRHSs ctxt grhss rhs_ty (NEL.nonEmpty match_deltas) - ; return ( EqnInfo { eqn_pats = upats - , eqn_orig = FromSource - , eqn_rhs = match_result } - , rhss_deltas' ) } + -- pat_deltas is the covered set *after* matching the pattern, but + -- before any of the GRHSs. We extend the environment with pat_deltas + -- (via updPmDeltas) so that the where-clause of 'grhss' can profit + -- from that knowledge (#18533) + ; match_result <- updPmDeltas pat_deltas $ + dsGRHSs ctxt grhss rhs_ty rhss_deltas + ; return EqnInfo { eqn_pats = upats + , eqn_orig = FromSource + , eqn_rhs = match_result } } handleWarnings = if isGenerated origin then discardWarningsDs else id + initDeltasMatches :: [LMatch GhcTc b] -> [(Deltas, NonEmpty Deltas)] + initDeltasMatches ms + = map (\(L _ m) -> (initDeltas, initDeltasGRHSs (m_grhss m))) ms + + initDeltasGRHSs :: GRHSs GhcTc b -> NonEmpty Deltas + initDeltasGRHSs m = expectJust "GRHSs non-empty" + $ NEL.nonEmpty + $ replicate (length (grhssGRHSs m)) initDeltas + + matchEquations :: HsMatchContext GhcRn -> [MatchId] -> [EquationInfo] -> Type -> DsM CoreExpr ===================================== compiler/GHC/HsToCore/Monad.hs ===================================== @@ -407,7 +407,7 @@ getPmDeltas = do { env <- getLclEnv; return (dsl_deltas env) } -- | Set the pattern match oracle state within the scope of the given action. -- See 'dsl_deltas'. updPmDeltas :: Deltas -> DsM a -> DsM a -updPmDeltas delta = updLclEnv (\env -> env { dsl_deltas = delta }) +updPmDeltas deltas = updLclEnv (\env -> env { dsl_deltas = deltas }) getSrcSpanDs :: DsM SrcSpan getSrcSpanDs = do { env <- getLclEnv ===================================== compiler/GHC/HsToCore/PmCheck.hs ===================================== @@ -13,7 +13,7 @@ Pattern Matching Coverage Checking. module GHC.HsToCore.PmCheck ( -- Checking and printing - checkSingle, checkMatches, checkGuardMatches, + checkSingle, checkMatches, checkGRHSs, isMatchContextPmChecked, -- See Note [Type and Term Equality Propagation] @@ -66,6 +66,7 @@ import GHC.Utils.Monad (concatMapM) import Control.Monad (when, forM_, zipWithM) import Data.List (elemIndex) import qualified Data.Semigroup as Semi +import Data.List.NonEmpty (NonEmpty(..)) {- This module checks pattern matches for: @@ -150,13 +151,11 @@ data GrdTree -- ^ @Guard grd t@ will try to match @grd@ and on success continue to match -- @t at . Falls through if either match fails. Models left-to-right semantics -- of pattern matching. - | Sequence !GrdTree !GrdTree - -- ^ @Sequence l r@ first matches against @l@, and then matches all - -- fallen-through values against @r at . Models top-to-bottom semantics of - -- pattern matching. - | Empty - -- ^ A @GrdTree@ that always fails. Most useful for - -- Note [Checking EmptyCase]. A neutral element to 'Sequence'. + | Sequence ![GrdTree] + -- ^ @Sequence (t:ts)@ matches against @t@, and then matches all + -- fallen-through values against @Sequence ts at . Models top-to-bottom semantics + -- of pattern matching. + -- @Sequence []@ always fails; it is useful for Note [Checking EmptyCase]. -- | The digest of 'checkGrdTree', representing the annotated pattern-match -- tree. 'redundantAndInaccessibleRhss' can figure out redundant and proper @@ -170,10 +169,10 @@ data AnnotatedTree | MayDiverge !AnnotatedTree -- ^ Asserts that the tree may force diverging values, so not all of its -- clauses can be redundant. - | SequenceAnn !AnnotatedTree !AnnotatedTree - -- ^ Mirrors 'Sequence' for preserving the skeleton of a 'GrdTree's. - | EmptyAnn - -- ^ Mirrors 'Empty' for preserving the skeleton of a 'GrdTree's. + | SequenceAnn !Deltas ![AnnotatedTree] + -- ^ @SequenceAnn inc ts@ mirrors @'Sequence' ts@ for preserving the + -- skeleton of a 'GrdTree's @ts at . It also carries the set of incoming values + -- @inc at . pprRhsInfo :: RhsInfo -> SDoc pprRhsInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) @@ -189,23 +188,15 @@ instance Outputable GrdTree where collect_grds t = (t, []) prefix [] = [] prefix (s:sdocs) = char '|' <+> s : map (comma <+>) sdocs - -- Format nested Sequences in blocks "{ grds1; grds2; ... }" - ppr t at Sequence{} = braces (space <> fsep (punctuate semi (collect_seqs t)) <> space) - where - collect_seqs (Sequence l r) = collect_seqs l ++ collect_seqs r - collect_seqs t = [ppr t] - ppr Empty = text "" + ppr (Sequence []) = text "" + ppr (Sequence ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) instance Outputable AnnotatedTree where - ppr (AccessibleRhs _ info) = pprRhsInfo info + ppr (AccessibleRhs _delta info) = parens (ppr _delta) <+> pprRhsInfo info ppr (InaccessibleRhs info) = text "inaccessible" <+> pprRhsInfo info ppr (MayDiverge t) = text "div" <+> ppr t - -- Format nested Sequences in blocks "{ grds1; grds2; ... }" - ppr t at SequenceAnn{} = braces (space <> fsep (punctuate semi (collect_seqs t)) <> space) - where - collect_seqs (SequenceAnn l r) = collect_seqs l ++ collect_seqs r - collect_seqs t = [ppr t] - ppr EmptyAnn = text "" + ppr (SequenceAnn _ []) = text "" + ppr (SequenceAnn _ ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) -- | Lift 'addPmCts' over 'Deltas'. addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas @@ -264,7 +255,7 @@ checkSingle dflags ctxt@(DsMatchContext kind locn) var p = do -- Omitting checking this flag emits redundancy warnings twice in obscure -- cases like #17646. when (exhaustive dflags kind) $ do - -- TODO: This could probably call checkMatches, like checkGuardMatches. + -- TODO: This could probably call checkMatches, like checkGRHSs. missing <- getPmDeltas tracePm "checkSingle: missing" (ppr missing) fam_insts <- dsGetFamInstEnvs @@ -274,12 +265,12 @@ checkSingle dflags ctxt@(DsMatchContext kind locn) var p = do -- | Exhaustive for guard matches, is used for guards in pattern bindings and -- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. -checkGuardMatches +checkGRHSs :: HsMatchContext GhcRn -- ^ Match context, for warning messages -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check - -> DsM [Deltas] -- ^ Covered 'Deltas' for each RHS, for long + -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long -- distance info -checkGuardMatches hs_ctx guards@(GRHSs _ grhss _) = do +checkGRHSs hs_ctx guards@(GRHSs _ grhss _) = do let combinedLoc = foldl1 combineSrcSpans (map getLoc grhss) dsMatchContext = DsMatchContext hs_ctx combinedLoc match = L combinedLoc $ @@ -287,7 +278,8 @@ checkGuardMatches hs_ctx guards@(GRHSs _ grhss _) = do , m_ctxt = hs_ctx , m_pats = [] , m_grhss = guards } - checkMatches dsMatchContext [] [match] + [(_, deltas)] <- checkMatches dsMatchContext [] [match] + pure deltas -- | Check a list of syntactic /match/es (part of case, functions, etc.), each -- with a /pat/ and one or more /grhss/: @@ -306,10 +298,9 @@ checkMatches :: DsMatchContext -- ^ Match context, for warnings messages -> [Id] -- ^ Match variables, i.e. x and y above -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches - -> DsM [Deltas] -- ^ One covered 'Deltas' per RHS, for long + -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per RHS, for long -- distance info. checkMatches ctxt vars matches = do - dflags <- getDynFlags tracePm "checkMatches" (hang (vcat [ppr ctxt , ppr vars , text "Matches:"]) @@ -322,25 +313,45 @@ checkMatches ctxt vars matches = do [] | [var] <- vars -> addPmCtDeltas init_deltas (PmNotBotCt var) _ -> pure init_deltas fam_insts <- dsGetFamInstEnvs - grd_tree <- mkGrdTreeMany [] <$> mapM (translateMatch fam_insts vars) matches + grd_tree <- translateMatches fam_insts vars matches res <- checkGrdTree grd_tree missing + dflags <- getDynFlags dsPmWarn dflags ctxt vars res - return (extractRhsDeltas init_deltas (cr_clauses res)) + return (extractRhsDeltas (cr_clauses res)) --- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree'. +-- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree' for a match +-- group. -- For 'AccessibleRhs's, this is stored in the tree node, whereas -- 'InaccessibleRhs's fall back to the supplied original 'Deltas'. -- See @Note [Recovering from unsatisfiable pattern-matching constraints]@. -extractRhsDeltas :: Deltas -> AnnotatedTree -> [Deltas] -extractRhsDeltas orig_deltas = fromOL . go +extractRhsDeltas :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] +extractRhsDeltas = go_matches where - go (AccessibleRhs deltas _) = unitOL deltas - go (InaccessibleRhs _) = unitOL orig_deltas - go (MayDiverge t) = go t - go (SequenceAnn l r) = go l Semi.<> go r - go EmptyAnn = nilOL + go_matches :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] + go_matches (SequenceAnn def ts) = map (go_match def) ts -- -XEmptyCase handled here! + go_matches t = pprPanic "extractRhsDeltas.go_matches" (text "Matches must start with SequenceAnn. But was" $$ ppr t) + + go_match :: Deltas -> AnnotatedTree -> (Deltas, NonEmpty Deltas) + -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ + -- is non-empty! + go_match def (SequenceAnn pat ts) = (pat, foldMap1 (text "go_match: empty SequenceAnn") (go_grhss def) ts) + go_match def (MayDiverge t) = go_match def t + -- Even if there's only a single GRHS, we wrap it in a SequenceAnn for the + -- Deltas covered by the pattern. So the remaining cases are impossible! + go_match _ t = pprPanic "extractRhsDeltas.go_match" (text "Single GRHS must be wrapped in SequenceAnn. But got " $$ ppr t) + + go_grhss :: Deltas -> AnnotatedTree -> NonEmpty Deltas + -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ + -- is non-empty! + go_grhss def (SequenceAnn _ ts) = foldMap1 (text "go_grhss: empty SequenceAnn") (go_grhss def) ts + go_grhss def (MayDiverge t) = go_grhss def t + go_grhss _ (AccessibleRhs deltas _) = deltas :| [] + go_grhss def (InaccessibleRhs _) = def :| [] + + foldMap1 msg _ [] = pprPanic "extractRhsDeltas.foldMap1" msg + foldMap1 _ f (x:xs) = foldl' (\acc x -> acc Semi.<> f x) (f x) xs {- Note [Checking EmptyCase] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -629,34 +640,43 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- 1. 2. 3. pure (con_grd : bang_grds ++ arg_grds) -mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree -mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) - -mkGrdTreeMany :: GrdVec -> [GrdTree] -> GrdTree -mkGrdTreeMany _ [] = Empty -mkGrdTreeMany grds trees = foldr Guard (foldr1 Sequence trees) grds +-- | Translate a the 'Match'es of a 'MatchGroup' +translateMatches :: FamInstEnvs -> [Id] -> [LMatch GhcTc (LHsExpr GhcTc)] + -> DsM GrdTree +translateMatches fam_insts vars matches = + -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. + -- 'extractRhsDeltas' needs this to recover 'MatchGroup' structure. + Sequence <$> traverse (translateMatch fam_insts vars) matches -- Translate a single match translateMatch :: FamInstEnvs -> [Id] -> LMatch GhcTc (LHsExpr GhcTc) -> DsM GrdTree translateMatch fam_insts vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do - pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats - grhss' <- mapM (translateLGRHS fam_insts match_loc pats) (grhssGRHSs grhss) - -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss, ppr grhss']) - return (mkGrdTreeMany pats' grhss') + pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats + grhss' <- translateGRHSs fam_insts match_loc (sep (map ppr pats)) grhss + -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss']) + return (foldr Guard grhss' pats') --- ----------------------------------------------------------------------- --- * Transform source guards (GuardStmt Id) to simpler PmGrds +mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree +mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) + +translateGRHSs :: FamInstEnvs -> SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM GrdTree +translateGRHSs fam_insts match_loc pp_pats grhss = + -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. + -- 'extractRhsDeltas' needs this to recover 'GRHSs' structure. + Sequence <$> traverse (translateLGRHS fam_insts match_loc pp_pats) (grhssGRHSs grhss) -- | Translate a guarded right-hand side to a single 'GrdTree' -translateLGRHS :: FamInstEnvs -> SrcSpan -> [LPat GhcTc] -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateLGRHS fam_insts match_loc pats (L _loc (GRHS _ gs _)) = - -- _loc apparently points to the match separator that comes after the guards.. +translateLGRHS :: FamInstEnvs -> SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree +translateLGRHS fam_insts match_loc pp_pats (L _loc (GRHS _ gs _)) = + -- _loc points to the match separator (ie =, ->) that comes after the guards.. mkGrdTreeRhs loc_sdoc <$> concatMapM (translateGuard fam_insts . unLoc) gs where loc_sdoc - | null gs = L match_loc (sep (map ppr pats)) - | otherwise = L grd_loc (sep (map ppr pats) <+> vbar <+> interpp'SP gs) + -- pp_pats is the space-separated pattern of the current Match this + -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . + | null gs = L match_loc pp_pats + | otherwise = L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) L grd_loc _ = head gs -- | Translate a guard statement to a 'GrdVec' @@ -971,6 +991,7 @@ checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do unc_this <- addPmCtDeltas deltas (PmNotConCt x con) deltas' <- addPmCtsDeltas deltas $ listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args + -- tracePm "checkGrdTree:Con" (ppr deltas $$ ppr x $$ ppr con $$ ppr dicts $$ ppr deltas') CheckResult tree' unc_inner prec <- checkGrdTree' tree deltas' limit <- maxPmCheckModels <$> getDynFlags let (prec', unc') = throttle limit deltas (unc_this Semi.<> unc_inner) @@ -979,19 +1000,21 @@ checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do , cr_uncov = unc' , cr_approx = prec Semi.<> prec' } -- Sequence: Thread residual uncovered sets from equation to equation -checkGrdTree' (Sequence l r) unc_0 = do - CheckResult l' unc_1 prec_l <- checkGrdTree' l unc_0 - CheckResult r' unc_2 prec_r <- checkGrdTree' r unc_1 - pure CheckResult - { cr_clauses = SequenceAnn l' r' - , cr_uncov = unc_2 - , cr_approx = prec_l Semi.<> prec_r } --- Empty: Fall through for all values -checkGrdTree' Empty unc = do - pure CheckResult - { cr_clauses = EmptyAnn - , cr_uncov = unc - , cr_approx = Precise } +checkGrdTree' (Sequence ts) init_unc = go [] init_unc Precise ts + where + -- | Accumulates a CheckResult. Its type is more like + -- @CheckResult -> [GrdTree] -> CheckResult@, but cr_clauses is a single + -- 'AnnotatedTree', not a list thereof. Hence 3 parameters to thread the + -- fields. + go :: [AnnotatedTree] -> Deltas -> Precision -> [GrdTree] -> DsM CheckResult + -- No cases left: Fall through for all values + go ts' unc prec [] = pure CheckResult + { cr_clauses = SequenceAnn init_unc (reverse ts') + , cr_uncov = unc + , cr_approx = prec } + go ts' unc prec (t:ts) = do + CheckResult t' unc_1 prec_t <- checkGrdTree' t unc + go (t':ts') unc_1 (prec_t Semi.<> prec) ts -- | Print diagnostic info and actually call 'checkGrdTree''. checkGrdTree :: GrdTree -> Deltas -> DsM CheckResult @@ -1117,8 +1140,7 @@ redundantAndInaccessibleRhss tree = (fromOL ol_red, fromOL ol_inacc) (acc, inacc, red) | isNilOL acc && isNilOL inacc -> (nilOL, red, nilOL) res -> res - go (SequenceAnn l r) = go l Semi.<> go r - go EmptyAnn = (nilOL, nilOL, nilOL) + go (SequenceAnn _ ts) = foldMap go ts {- Note [Determining inaccessible clauses] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/HsToCore/PmCheck/Oracle.hs ===================================== @@ -1070,7 +1070,8 @@ ensureAllPossibleMatchesInhabited delta at MkDelta{ delta_tm_st = TmSt env reps } = runMaybeT (set_tm_cs_env delta <$> traverseSDIE go env) where set_tm_cs_env delta env = delta{ delta_tm_st = TmSt env reps } - go vi = MaybeT (ensureInhabited delta vi) + go vi = MaybeT $ + initPossibleMatches (delta_ty_st delta) vi >>= ensureInhabited delta -------------------------------------- -- * Term oracle unification procedure @@ -1668,7 +1669,7 @@ addCoreCt :: Delta -> Id -> CoreExpr -> MaybeT DsM Delta addCoreCt delta x e = do dflags <- getDynFlags let e' = simpleOptExpr dflags e - lift $ tracePm "addCoreCt" (ppr x $$ ppr e $$ ppr e') + lift $ tracePm "addCoreCt" (ppr x <+> dcolon <+> ppr (idType x) $$ ppr e $$ ppr e') execStateT (core_expr x e') delta where -- | Takes apart a 'CoreExpr' and tries to extract as much information about ===================================== compiler/GHC/Tc/Errors/Hole.hs ===================================== @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ExistentialQuantification #-} {-# OPTIONS_GHC -Wno-incomplete-record-updates #-} @@ -779,7 +780,9 @@ tcFilterHoleFits limit typed_hole ht@(hole_ty, _) candidates = Just (dataConWrapId con, dataConNonlinearType con) _ -> Nothing } where name = case hfc of +#if __GLASGOW_HASKELL__ <= 810 IdHFCand id -> idName id +#endif GreHFCand gre -> gre_name gre NameHFCand name -> name discard_it = go subs seen maxleft ty elts ===================================== compiler/GHC/Tc/Gen/HsType.hs ===================================== @@ -1079,7 +1079,9 @@ tc_hs_type mode rn_ty@(HsTupleTy _ hs_tup_sort tys) exp_kind HsUnboxedTuple -> UnboxedTuple HsBoxedTuple -> BoxedTuple HsConstraintTuple -> ConstraintTuple +#if __GLASGOW_HASKELL__ <= 810 _ -> panic "tc_hs_type HsTupleTy" +#endif tc_hs_type mode rn_ty@(HsSumTy _ hs_tys) exp_kind = do { let arity = length hs_tys ===================================== testsuite/tests/pmcheck/should_compile/T18533.hs ===================================== @@ -0,0 +1,24 @@ +{-# OPTIONS_GHC -Wincomplete-patterns -fforce-recomp #-} +{-# LANGUAGE GADTs, DataKinds, TypeFamilies, BangPatterns #-} + +module T18533 where + +data SBool (b :: Bool) where + STrue :: SBool 'True + SFalse :: SBool 'False + +type family Fam (b :: Bool) +type instance Fam 'True = T + +data T = T Bool + +f :: Fam b -> SBool b -> Bool +f !t s = case s of + STrue -> a where a = case t of T a -> a + _ -> False + + +g :: Bool -> Bool +g x = case x of + True -> a where a = case x of True -> False + False -> True ===================================== testsuite/tests/pmcheck/should_compile/all.T ===================================== @@ -122,6 +122,8 @@ test('T18049', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T18478', collect_compiler_stats('bytes allocated',10), compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) +test('T18533', normal, compile, + ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) # Other tests test('pmc001', [], compile, View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/55dec4dc6e8f8430810d212c73e78ffbb92e0a48 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/55dec4dc6e8f8430810d212c73e78ffbb92e0a48 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 07:45:34 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 13 Aug 2020 03:45:34 -0400 Subject: [Git][ghc/ghc][master] Re-add BangPatterns to CodePage.hs Message-ID: <5f34ef9e9c1c9_80b3f84865febec7931959@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - 1 changed file: - libraries/base/GHC/IO/Encoding/CodePage.hs Changes: ===================================== libraries/base/GHC/IO/Encoding/CodePage.hs ===================================== @@ -1,4 +1,6 @@ +{-# LANGUAGE BangPatterns #-} {-# LANGUAGE CPP #-} +{-# LANGUAGE MagicHash #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE NondecreasingIndentation #-} {-# LANGUAGE Trustworthy #-} View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cf97889a38edc3314a7b61e6e0b6e6d0f434c8a2 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cf97889a38edc3314a7b61e6e0b6e6d0f434c8a2 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 09:32:08 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Thu, 13 Aug 2020 05:32:08 -0400 Subject: [Git][ghc/ghc][wip/T8095-spj] 18 commits: typecheck: Drop SPECIALISE pragmas when there is no unfolding Message-ID: <5f3508987c3e6_80b3f84862982787958898@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T8095-spj at Glasgow Haskell Compiler / GHC Commits: ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - 9607899e by Simon Peyton Jones at 2020-08-13T10:29:29+01:00 Zap coercions (take 2) This is Simon's take on coercion zapping. The basic approach remains the same: add a UnivProv for a zapped coercion, controlled by -ddrop-coercions. Particular features: * A zapped coercion is born in one place only: in GHC.Tc.Utils.Zonk, when zonking a coercion. By that time all coercion holes are filled in, so there is no issue about looking for free holes. * Flattening and solving are unaffected. They'll allocate coercions -- but my plan (not yet brought to fruition) is that they are never traversed when we have -ddrop-coercions * There will, therefore, be no perf gain in the type checker; but the entire rest of the compiler will benefit. - - - - - ccfe42c0 by Simon Peyton Jones at 2020-08-13T10:29:29+01:00 CI adjustments This patch temporarily * Marks -ddump-coercions as undocumented (so that CI doesn't stumble) * Adds -ddump-coercions to TEST_HC so that all tests run with it on - - - - - ab54854d by Simon Peyton Jones at 2020-08-13T10:29:29+01:00 Free-var fixes This should stop the perf regressions - - - - - 40e45c9c by Simon Peyton Jones at 2020-08-13T10:30:32+01:00 Simplify TyCoFolder This commit removes the 'env' part of TyCoFolder. A nice simplification! - - - - - 584d2919 by Simon Peyton Jones at 2020-08-13T10:30:33+01:00 Tidy up and documentation Notes - - - - - cf275920 by Simon Peyton Jones at 2020-08-13T10:30:33+01:00 Two perf wibbles - - - - - 44401c66 by Simon Peyton Jones at 2020-08-13T10:31:46+01:00 Further wibbles - - - - - 30 changed files: - compiler/GHC.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - compiler/GHC/CmmToAsm/CPrim.hs - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Format.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/dd4b25f1d6d6b990769098d07b047f70b3fd48a4...44401c6648aec012ca0f6c49a784e46654e6ec83 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/dd4b25f1d6d6b990769098d07b047f70b3fd48a4...44401c6648aec012ca0f6c49a784e46654e6ec83 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 09:39:32 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Thu, 13 Aug 2020 05:39:32 -0400 Subject: [Git][ghc/ghc][wip/T18126] Fix HIE-processing for HsUnboundVar Message-ID: <5f350a54ba4ce_80b3f8468e8ce94796184a@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18126 at Glasgow Haskell Compiler / GHC Commits: 53904905 by Simon Peyton Jones at 2020-08-13T10:38:51+01:00 Fix HIE-processing for HsUnboundVar - - - - - 1 changed file: - compiler/GHC/Iface/Ext/Ast.hs Changes: ===================================== compiler/GHC/Iface/Ext/Ast.hs ===================================== @@ -785,6 +785,7 @@ class ( IsPass p , Data (HsTupArg (GhcPass p)) , Data (IPBind (GhcPass p)) , ToHie (Context (Located (IdGhcP p))) + , ToHie (Context (Located (XUnboundVar (GhcPass p)))) , ToHie (RFContext (Located (AmbiguousFieldOcc (GhcPass p)))) , ToHie (RFContext (Located (FieldOcc (GhcPass p)))) , ToHie (TScoped (LHsWcType (GhcPass (NoGhcTcPass p)))) @@ -799,6 +800,9 @@ instance HiePass 'Renamed where instance HiePass 'Typechecked where hiePass = HieTc +instance ToHie (Context (Located NoExtField)) where + toHie _ = pure [] + instance HiePass p => ToHie (BindContext (Located (HsBind (GhcPass p)))) where toHie (BC context scope b@(L span bind)) = concatM $ getTypeNode b : case bind of @@ -1042,8 +1046,8 @@ instance HiePass p => ToHie (Located (HsExpr (GhcPass p))) where [ toHie $ C Use (L mspan var) -- Patch up var location since typechecker removes it ] - HsUnboundVar _ _ -> - [] + HsUnboundVar var _ -> + [ toHie $ C Use (L mspan var) ] HsConLikeOut _ con -> [ toHie $ C Use $ L mspan $ conLikeName con ] View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/53904905fc1bf26a1834f344bbd52eeb9be6937f -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/53904905fc1bf26a1834f344bbd52eeb9be6937f You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 12:19:33 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Thu, 13 Aug 2020 08:19:33 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18565 Message-ID: <5f352fd5dd084_80b1075951c799899d@gitlab.haskell.org.mail> Sebastian Graf pushed new branch wip/T18565 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18565 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 19:30:15 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 13 Aug 2020 15:30:15 -0400 Subject: [Git][ghc/ghc][wip/backports] testsuite: Specify metrics collected by T17516 Message-ID: <5f3594c7146e0_80b3f84865febec805278b@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: 58f2b5d1 by Ben Gamari at 2020-08-13T15:02:33-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". (cherry picked from commit f1088b3f31ceddf918a319c97557fb1f08a9a387) - - - - - 1 changed file: - testsuite/tests/perf/compiler/all.T Changes: ===================================== testsuite/tests/perf/compiler/all.T ===================================== @@ -370,7 +370,7 @@ test('T16190', test('T16473', normal, makefile_test, ['T16473']) test('T17516', - [ collect_compiler_stats(), + [ collect_compiler_stats('bytes allocated', 5), extra_clean(['T17516A.hi', 'T17516A.o']) ], multimod_compile, View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/58f2b5d13bd1d1744c3615f806bac2f6af0f45d6 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/58f2b5d13bd1d1744c3615f806bac2f6af0f45d6 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 19:48:31 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 13 Aug 2020 15:48:31 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 5 commits: parser: Suggest ImportQualifiedPost in prepositive import warning Message-ID: <5f35990f3da88_80b3f8486b5b7c08055073@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 349e7c47 by Sylvain Henry at 2020-08-13T15:48:28-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 30 changed files: - compiler/GHC.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Core/Coercion/Opt.hs - compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/CoreToStg/Prep.hs - compiler/GHC/Data/IOEnv.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Driver/Finder.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Make.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/HsToCore.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/GuardedRHSs.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/Monad.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - compiler/GHC/HsToCore/Usage.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/Iface/Recomp.hs - compiler/GHC/Iface/Recomp/Flags.hs - compiler/GHC/Iface/Rename.hs - compiler/GHC/Iface/Tidy.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/23fac6834bba3181c13250aee54a28ddbeb3bddb...349e7c4765d0d3f9f2127dd533d38fda6cf7dc60 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/23fac6834bba3181c13250aee54a28ddbeb3bddb...349e7c4765d0d3f9f2127dd533d38fda6cf7dc60 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 22:20:09 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 13 Aug 2020 18:20:09 -0400 Subject: [Git][ghc/ghc][ghc-9.0] 5 commits: Bignum: add support for negative shifts (fix #18499) Message-ID: <5f35bc99714a_80b3f8486b5b7c080632a5@gitlab.haskell.org.mail> Ben Gamari pushed to branch ghc-9.0 at Glasgow Haskell Compiler / GHC Commits: 32496789 by Sylvain Henry at 2020-08-11T17:43:13+02:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - b4cccab3 by Sylvain Henry at 2020-08-11T17:48:05+02:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - 817f94f5 by Sylvain Henry at 2020-08-11T17:48:22+02:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - eab2511e by Sylvain Henry at 2020-08-12T11:43:42+02:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3745bdb6 by Sylvain Henry at 2020-08-12T11:43:42+02:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 19 changed files: - libraries/base/Data/Bits.hs - libraries/base/tests/isValidNatural.hs - libraries/base/tests/isValidNatural.stdout - libraries/ghc-bignum/src/GHC/Num/BigNat.hs - libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs - libraries/ghc-bignum/src/GHC/Num/Natural.hs - libraries/ghc-bignum/src/GHC/Num/WordArray.hs - libraries/integer-gmp/integer-gmp.cabal - libraries/integer-gmp/src/GHC/Integer/GMP/Internals.hs - testsuite/tests/lib/integer/all.T - testsuite/tests/lib/integer/integerPowMod.hs - testsuite/tests/lib/integer/integerPowMod.stdout - + testsuite/tests/numeric/should_run/T18499.hs - + testsuite/tests/numeric/should_run/T18499.stdout - + testsuite/tests/numeric/should_run/T18509.hs - + testsuite/tests/numeric/should_run/T18509.stdout - + testsuite/tests/numeric/should_run/T18515.hs - + testsuite/tests/numeric/should_run/T18515.stdout - testsuite/tests/numeric/should_run/all.T Changes: ===================================== libraries/base/Data/Bits.hs ===================================== @@ -537,8 +537,14 @@ instance Bits Integer where (.|.) = integerOr xor = integerXor complement = integerComplement - shiftR x i = integerShiftR x (fromIntegral i) - shiftL x i = integerShiftL x (fromIntegral i) + unsafeShiftR x i = integerShiftR x (fromIntegral i) + unsafeShiftL x i = integerShiftL x (fromIntegral i) + shiftR x i@(I# i#) + | isTrue# (i# >=# 0#) = unsafeShiftR x i + | otherwise = overflowError + shiftL x i@(I# i#) + | isTrue# (i# >=# 0#) = unsafeShiftL x i + | otherwise = overflowError shift x i | i >= 0 = integerShiftL x (fromIntegral i) | otherwise = integerShiftR x (fromIntegral (negate i)) testBit x i = integerTestBit x (fromIntegral i) @@ -560,8 +566,14 @@ instance Bits Natural where xor = naturalXor complement _ = errorWithoutStackTrace "Bits.complement: Natural complement undefined" - shiftR x i = naturalShiftR x (fromIntegral i) - shiftL x i = naturalShiftL x (fromIntegral i) + unsafeShiftR x i = naturalShiftR x (fromIntegral i) + unsafeShiftL x i = naturalShiftL x (fromIntegral i) + shiftR x i@(I# i#) + | isTrue# (i# >=# 0#) = unsafeShiftR x i + | otherwise = overflowError + shiftL x i@(I# i#) + | isTrue# (i# >=# 0#) = unsafeShiftL x i + | otherwise = overflowError shift x i | i >= 0 = naturalShiftL x (fromIntegral i) | otherwise = naturalShiftR x (fromIntegral (negate i)) ===================================== libraries/base/tests/isValidNatural.hs ===================================== @@ -1,10 +1,19 @@ -{-# language MagicHash #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE UnboxedTuples #-} import GHC.Num.Natural import GHC.Num.BigNat import GHC.Exts +import GHC.IO -main = print $ map naturalCheck [0, 1, maxWord, maxWord + 1, invalid] - where - maxWord = fromIntegral (maxBound :: Word) - invalid = NB (bigNatOne# void#) -- 1 would fit into the NS constructor. +main = do + let + maxWord = fromIntegral (maxBound :: Word) + invalid = NB (bigNatOne# void#) -- 1 would fit into the NS constructor. + + -- byteArray whose size is not a multiple of Word size + invalid2 <- IO $ \s -> case newByteArray# 27# s of + (# s', mba #) -> case unsafeFreezeByteArray# mba s' of + (# s'', ba #) -> (# s'', NB ba #) + + print $ map naturalCheck [0, 1, maxWord, maxWord + 1, invalid, invalid2] ===================================== libraries/base/tests/isValidNatural.stdout ===================================== @@ -1 +1 @@ -[True,True,True,True,False] +[True,True,True,True,False,False] ===================================== libraries/ghc-bignum/src/GHC/Num/BigNat.hs ===================================== @@ -80,6 +80,10 @@ data BigNat = BN# { unBigNat :: BigNat# } bigNatCheck# :: BigNat# -> Bool# bigNatCheck# bn | 0# <- bigNatSize# bn = 1# + -- check that size is a multiple of Word size + | r <- remInt# (sizeofByteArray# bn) WORD_SIZE_IN_BYTES# + , isTrue# (r /=# 0#) = 0# + -- check that most-significant limb isn't zero | 0## <- bigNatIndex# bn (bigNatSize# bn -# 1#) = 0# | True = 1# @@ -228,8 +232,8 @@ bigNatToWordList bn = go (bigNatSize# bn) -- | Convert two Word# (most-significant first) into a BigNat bigNatFromWord2# :: Word# -> Word# -> BigNat# bigNatFromWord2# 0## 0## = bigNatZero# void# -bigNatFromWord2# 0## n = bigNatFromWord# n -bigNatFromWord2# w1 w2 = wordArrayFromWord2# w1 w2 +bigNatFromWord2# 0## l = bigNatFromWord# l +bigNatFromWord2# h l = wordArrayFromWord2# h l -- | Convert a BigNat into a Word# bigNatToWord# :: BigNat# -> Word# ===================================== libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs ===================================== @@ -349,7 +349,8 @@ bignat_powmod -> State# RealWorld -> State# RealWorld bignat_powmod r b e m s = - ioVoid (integer_gmp_powm# r b (wordArraySize# b) e (wordArraySize# e) m (wordArraySize# m)) s + case ioInt# (integer_gmp_powm# r b (wordArraySize# b) e (wordArraySize# e) m (wordArraySize# m)) s of + (# s', n #) -> mwaSetSize# r (narrowGmpSize# n) s' ---------------------------------------------------------------------- ===================================== libraries/ghc-bignum/src/GHC/Num/Natural.hs ===================================== @@ -86,8 +86,8 @@ naturalFromWord# x = NS x -- | Convert two Word# (most-significant first) into a Natural naturalFromWord2# :: Word# -> Word# -> Natural naturalFromWord2# 0## 0## = naturalZero -naturalFromWord2# 0## n = NS n -naturalFromWord2# w1 w2 = NB (bigNatFromWord2# w2 w1) +naturalFromWord2# 0## l = NS l +naturalFromWord2# h l = NB (bigNatFromWord2# h l) -- | Create a Natural from a Word naturalFromWord :: Word -> Natural ===================================== libraries/ghc-bignum/src/GHC/Num/WordArray.hs ===================================== @@ -121,12 +121,14 @@ withNewWordArrayTrimedMaybe# sz act = case runRW# io of (# _, a #) -> a -- | Create a WordArray# from two Word# -- --- `byteArrayFromWord2# msw lsw = lsw:msw` +-- `wordArrayFromWord2# h l +-- where h is the most significant word +-- l is the least significant word wordArrayFromWord2# :: Word# -> Word# -> WordArray# -wordArrayFromWord2# msw lsw = +wordArrayFromWord2# h l = withNewWordArray# 2# \mwa s -> - case mwaWrite# mwa 0# lsw s of - s -> mwaWrite# mwa 1# msw s + case mwaWrite# mwa 0# l s of + s -> mwaWrite# mwa 1# h s -- | Create a WordArray# from one Word# wordArrayFromWord# :: Word# -> WordArray# ===================================== libraries/integer-gmp/integer-gmp.cabal ===================================== @@ -26,6 +26,7 @@ library build-depends: base >= 4.11 && < 5 , ghc-prim + , ghc-bignum exposed-modules: GHC.Integer.GMP.Internals ===================================== libraries/integer-gmp/src/GHC/Integer/GMP/Internals.hs ===================================== @@ -5,6 +5,7 @@ {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE BlockArguments #-} #include "MachDeps.h" @@ -42,12 +43,73 @@ module GHC.Integer.GMP.Internals , GmpLimb, GmpLimb# , GmpSize, GmpSize# + -- ** + + , isValidBigNat# + , sizeofBigNat# + , zeroBigNat + , oneBigNat + + -- ** 'BigNat' arithmetic operations + , plusBigNat + , plusBigNatWord + , timesBigNat + , timesBigNatWord + , sqrBigNat + + , quotRemBigNat + , quotRemBigNatWord + , quotBigNatWord + , quotBigNat + , remBigNat + , remBigNatWord + + , gcdBigNat + , gcdBigNatWord + + -- ** 'BigNat' logic operations + , shiftRBigNat + , shiftLBigNat + , testBitBigNat + , clearBitBigNat + , complementBitBigNat + , setBitBigNat + , andBigNat + , xorBigNat + , popCountBigNat + , orBigNat + , bitBigNat + + -- ** 'BigNat' comparison predicates + , isZeroBigNat + + , compareBigNatWord + , compareBigNat + , eqBigNatWord + , eqBigNatWord# + , eqBigNat + , eqBigNat# + , gtBigNatWord# + + -- * Import/export functions + -- ** Compute size of serialisation + , sizeInBaseBigNat + , sizeInBaseInteger + , sizeInBaseWord# + + -- ** Export + , exportBigNatToAddr + + -- ** Import + , importBigNatFromAddr ) where import GHC.Integer import GHC.Natural import GHC.Num.Integer (Integer(..)) import qualified GHC.Num.Integer as I +import qualified GHC.Num.BigNat as B +import qualified GHC.Num.Primitives as P import GHC.Types import GHC.Prim @@ -112,3 +174,173 @@ type GmpLimb = Word type GmpLimb# = Word# type GmpSize = Int type GmpSize# = Int# + +{-# DEPRECATED sizeofBigNat# "Use bigNatSize# instead" #-} +sizeofBigNat# :: BigNat -> GmpSize# +sizeofBigNat# (BN# i) = B.bigNatSize# i + +{-# DEPRECATED isValidBigNat# "Use bigNatCheck# instead" #-} +isValidBigNat# :: BigNat -> Int# +isValidBigNat# (BN# i) = B.bigNatCheck# i + +{-# DEPRECATED zeroBigNat "Use bigNatZero instead" #-} +zeroBigNat :: BigNat +zeroBigNat = B.bigNatZero + +{-# DEPRECATED oneBigNat "Use bigNatOne instead" #-} +oneBigNat :: BigNat +oneBigNat = B.bigNatOne + +{-# DEPRECATED plusBigNat "Use bigNatAdd instead" #-} +plusBigNat :: BigNat -> BigNat -> BigNat +plusBigNat (BN# a) (BN# b) = BN# (B.bigNatAdd a b) + +{-# DEPRECATED plusBigNatWord "Use bigNatAddWord# instead" #-} +plusBigNatWord :: BigNat -> GmpLimb# -> BigNat +plusBigNatWord (BN# a) w = BN# (B.bigNatAddWord# a w) + +{-# DEPRECATED timesBigNat "Use bigNatMul instead" #-} +timesBigNat :: BigNat -> BigNat -> BigNat +timesBigNat (BN# a) (BN# b) = BN# (B.bigNatMul a b) + +{-# DEPRECATED timesBigNatWord "Use bigNatMulWord# instead" #-} +timesBigNatWord :: BigNat -> GmpLimb# -> BigNat +timesBigNatWord (BN# a) w = BN# (B.bigNatMulWord# a w) + +{-# DEPRECATED sqrBigNat "Use bigNatSqr instead" #-} +sqrBigNat :: BigNat -> BigNat +sqrBigNat (BN# a) = BN# (B.bigNatSqr a) + +{-# DEPRECATED quotRemBigNat "Use bigNatQuotRem# instead" #-} +quotRemBigNat :: BigNat -> BigNat -> (# BigNat,BigNat #) +quotRemBigNat (BN# a) (BN# b) = case B.bigNatQuotRem# a b of + (# q, r #) -> (# BN# q, BN# r #) + +{-# DEPRECATED quotRemBigNatWord "Use bigNatQuotRemWord# instead" #-} +quotRemBigNatWord :: BigNat -> GmpLimb# -> (# BigNat, GmpLimb# #) +quotRemBigNatWord (BN# a) b = case B.bigNatQuotRemWord# a b of + (# q, r #) -> (# BN# q, r #) + +{-# DEPRECATED quotBigNat "Use bigNatQuot instead" #-} +quotBigNat :: BigNat -> BigNat -> BigNat +quotBigNat (BN# a) (BN# b) = BN# (B.bigNatQuot a b) + +{-# DEPRECATED quotBigNatWord "Use bigNatQuotWord# instead" #-} +quotBigNatWord :: BigNat -> GmpLimb# -> BigNat +quotBigNatWord (BN# a) b = BN# (B.bigNatQuotWord# a b) + +{-# DEPRECATED remBigNat "Use bigNatRem instead" #-} +remBigNat :: BigNat -> BigNat -> BigNat +remBigNat (BN# a) (BN# b) = BN# (B.bigNatRem a b) + +{-# DEPRECATED remBigNatWord "Use bigNatRemWord# instead" #-} +remBigNatWord :: BigNat -> GmpLimb# -> Word# +remBigNatWord (BN# a) b = B.bigNatRemWord# a b + +{-# DEPRECATED gcdBigNatWord "Use bigNatGcdWord# instead" #-} +gcdBigNatWord :: BigNat -> Word# -> Word# +gcdBigNatWord (BN# a) b = B.bigNatGcdWord# a b + +{-# DEPRECATED gcdBigNat "Use bigNatGcd instead" #-} +gcdBigNat:: BigNat -> BigNat -> BigNat +gcdBigNat (BN# a) (BN# b) = BN# (B.bigNatGcd a b) + +{-# DEPRECATED shiftRBigNat "Use bigNatShiftR# instead" #-} +shiftRBigNat :: BigNat -> Int# -> BigNat +shiftRBigNat (BN# a) i = BN# (B.bigNatShiftR# a (int2Word# i)) + +{-# DEPRECATED shiftLBigNat "Use bigNatShiftL# instead" #-} +shiftLBigNat :: BigNat -> Int# -> BigNat +shiftLBigNat (BN# a) i = BN# (B.bigNatShiftL# a (int2Word# i)) + +{-# DEPRECATED testBitBigNat "Use bigNatTestBit# instead" #-} +testBitBigNat :: BigNat -> Int# -> Bool +testBitBigNat (BN# a) i = isTrue# (B.bigNatTestBit# a (int2Word# i)) + +{-# DEPRECATED clearBitBigNat "Use bigNatClearBit# instead" #-} +clearBitBigNat :: BigNat -> Int# -> BigNat +clearBitBigNat (BN# a) i = BN# (B.bigNatClearBit# a (int2Word# i)) + +{-# DEPRECATED complementBitBigNat "Use bigNatComplementBit# instead" #-} +complementBitBigNat :: BigNat -> Int# -> BigNat +complementBitBigNat (BN# a) i = BN# (B.bigNatComplementBit# a (int2Word# i)) + +{-# DEPRECATED setBitBigNat "Use bigNatSetBit# instead" #-} +setBitBigNat :: BigNat -> Int# -> BigNat +setBitBigNat (BN# a) i = BN# (B.bigNatSetBit# a (int2Word# i)) + +{-# DEPRECATED andBigNat "Use bigNatAnd instead" #-} +andBigNat :: BigNat -> BigNat -> BigNat +andBigNat (BN# a) (BN# b) = BN# (B.bigNatAnd a b) + +{-# DEPRECATED orBigNat "Use bigNatOr instead" #-} +orBigNat :: BigNat -> BigNat -> BigNat +orBigNat (BN# a) (BN# b) = BN# (B.bigNatOr a b) + +{-# DEPRECATED xorBigNat "Use bigNatXor instead" #-} +xorBigNat :: BigNat -> BigNat -> BigNat +xorBigNat (BN# a) (BN# b) = BN# (B.bigNatXor a b) + +{-# DEPRECATED popCountBigNat "Use bigNatPopCount# instead" #-} +popCountBigNat :: BigNat -> Int# +popCountBigNat (BN# a) = word2Int# (B.bigNatPopCount# a) + +{-# DEPRECATED bitBigNat "Use bigNatBit# instead" #-} +bitBigNat :: Int# -> BigNat +bitBigNat i = BN# (B.bigNatBit# (int2Word# i)) + +{-# DEPRECATED isZeroBigNat "Use bigNatIsZero instead" #-} +isZeroBigNat :: BigNat -> Bool +isZeroBigNat (BN# a) = B.bigNatIsZero a + +{-# DEPRECATED compareBigNat "Use bigNatCompare instead" #-} +compareBigNat :: BigNat -> BigNat -> Ordering +compareBigNat (BN# a) (BN# b) = B.bigNatCompare a b + +{-# DEPRECATED compareBigNatWord "Use bigNatCompareWord# instead" #-} +compareBigNatWord :: BigNat -> GmpLimb# -> Ordering +compareBigNatWord (BN# a) w = B.bigNatCompareWord# a w + +{-# DEPRECATED eqBigNatWord "Use bigNatEqWord# instead" #-} +eqBigNatWord :: BigNat -> GmpLimb# -> Bool +eqBigNatWord (BN# a) w = isTrue# (B.bigNatEqWord# a w) + +{-# DEPRECATED eqBigNatWord# "Use bigNatEqWord# instead" #-} +eqBigNatWord# :: BigNat -> GmpLimb# -> Int# +eqBigNatWord# (BN# a) w = B.bigNatEqWord# a w + +{-# DEPRECATED eqBigNat# "Use bigNatEq# instead" #-} +eqBigNat# :: BigNat -> BigNat -> Int# +eqBigNat# (BN# a) (BN# b) = B.bigNatEq# a b + +{-# DEPRECATED eqBigNat "Use bigNatEq instead" #-} +eqBigNat :: BigNat -> BigNat -> Bool +eqBigNat (BN# a) (BN# b) = B.bigNatEq a b + +{-# DEPRECATED gtBigNatWord# "Use bigNatGtWord# instead" #-} +gtBigNatWord# :: BigNat -> GmpLimb# -> Int# +gtBigNatWord# (BN# a) w = B.bigNatGtWord# a w + +{-# DEPRECATED sizeInBaseBigNat "Use bigNatSizeInBase# instead" #-} +sizeInBaseBigNat :: BigNat -> Int# -> Word# +sizeInBaseBigNat (BN# a) b = B.bigNatSizeInBase# (int2Word# b) a + +{-# DEPRECATED sizeInBaseInteger "Use integerSizeInBase# instead" #-} +sizeInBaseInteger :: Integer -> Int# -> Word# +sizeInBaseInteger i b = I.integerSizeInBase# (int2Word# b) i + +{-# DEPRECATED sizeInBaseWord# "Use wordSizeInBase# instead" #-} +sizeInBaseWord# :: Word# -> Int# -> Word# +sizeInBaseWord# a b = P.wordSizeInBase# (int2Word# b) a + +{-# DEPRECATED importBigNatFromAddr "Use bigNatFromAddr# instead" #-} +importBigNatFromAddr :: Addr# -> Word# -> Int# -> IO BigNat +importBigNatFromAddr addr sz endian = IO \s -> + case B.bigNatFromAddr# sz addr endian s of + (# s', b #) -> (# s', BN# b #) + +{-# DEPRECATED exportBigNatToAddr "Use bigNatToAddr# instead" #-} +exportBigNatToAddr :: BigNat -> Addr# -> Int# -> IO Word +exportBigNatToAddr (BN# b) addr endian = IO \s -> + case B.bigNatToAddr# b addr endian s of + (# s', w #) -> (# s', W# w #) ===================================== testsuite/tests/lib/integer/all.T ===================================== @@ -5,11 +5,11 @@ test('integerConstantFolding', normal, makefile_test, ['integerConstantFolding'] test('fromToInteger', [], makefile_test, ['fromToInteger']) test('IntegerConversionRules', [], makefile_test, ['IntegerConversionRules']) test('gcdInteger', normal, compile_and_run, ['']) +test('integerPowMod', [], compile_and_run, ['']) # skip ghci as it doesn't support unboxed tuples test('integerImportExport', [omit_ways(['ghci'])], compile_and_run, ['']) # Disable GMP only tests #test('integerGcdExt', [omit_ways(['ghci'])], compile_and_run, ['']) -#test('integerPowMod', [], compile_and_run, ['']) #test('integerGmpInternals', [], compile_and_run, ['']) ===================================== testsuite/tests/lib/integer/integerPowMod.hs ===================================== @@ -7,19 +7,12 @@ import Control.Monad import GHC.Word import GHC.Base -import qualified GHC.Integer.GMP.Internals as I - -powModSecInteger :: Integer -> Integer -> Integer -> Integer -powModSecInteger = I.powModSecInteger - -powModInteger :: Integer -> Integer -> Integer -> Integer -powModInteger = I.powModInteger +import GHC.Natural main :: IO () main = do - print $ powModInteger b e m - print $ powModInteger b e (m-1) - print $ powModSecInteger b e (m-1) + print $ powModNatural b e m + print $ powModNatural b e (m-1) where b = 2988348162058574136915891421498819466320163312926952423791023078876139 ===================================== testsuite/tests/lib/integer/integerPowMod.stdout ===================================== @@ -1,3 +1,2 @@ 1527229998585248450016808958343740453059 682382427572745901624116300491295556924 -682382427572745901624116300491295556924 ===================================== testsuite/tests/numeric/should_run/T18499.hs ===================================== @@ -0,0 +1,27 @@ +import Data.Bits +import Numeric.Natural +import GHC.Exception.Type +import Control.Exception + +main :: IO () +main = do + test ((42 `shiftR` (-1)) :: Integer) + test ((42 `shiftL` (-1)) :: Integer) + test ((42 `shiftR` (-1)) :: Natural) + test ((42 `shiftL` (-1)) :: Natural) + test ((42 `shiftR` (-1)) :: Word) + test ((42 `shiftL` (-1)) :: Word) + test ((42 `shiftR` (-1)) :: Int) + test ((42 `shiftL` (-1)) :: Int) + + test ((42 `unsafeShiftR` 2) :: Integer) + test ((42 `unsafeShiftL` 2) :: Integer) + test ((42 `unsafeShiftR` 2) :: Natural) + test ((42 `unsafeShiftL` 2) :: Natural) + test ((42 `unsafeShiftR` 2) :: Word) + test ((42 `unsafeShiftL` 2) :: Word) + test ((42 `unsafeShiftR` 2) :: Int) + test ((42 `unsafeShiftL` 2) :: Int) + +test :: Show a => a -> IO () +test a = print a `catch` (\Overflow -> putStrLn "Overflow!") ===================================== testsuite/tests/numeric/should_run/T18499.stdout ===================================== @@ -0,0 +1,16 @@ +Overflow! +Overflow! +Overflow! +Overflow! +Overflow! +Overflow! +Overflow! +Overflow! +10 +168 +10 +168 +10 +168 +10 +168 ===================================== testsuite/tests/numeric/should_run/T18509.hs ===================================== @@ -0,0 +1,6 @@ +import Numeric.Natural + +main :: IO () +main = do + print $ (0xFFFFFFFF0 * 0xFFFFFFFF0 :: Natural) + print $ (2 :: Natural) ^ (190 :: Int) ===================================== testsuite/tests/numeric/should_run/T18509.stdout ===================================== @@ -0,0 +1,2 @@ +4722366480670621958400 +1569275433846670190958947355801916604025588861116008628224 ===================================== testsuite/tests/numeric/should_run/T18515.hs ===================================== @@ -0,0 +1,12 @@ +{-# LANGUAGE MagicHash #-} + +import GHC.Num.BigNat +import GHC.Num.Integer + +main :: IO () +main = + let b = integerToBigNatClamp# 251943445928310882947152017889649234 + e = integerToBigNatClamp# 503886891856621765894304035779298468 + m = integerToBigNatClamp# 503886891856621765894304035779298469 + r = integerFromBigNat# (bigNatPowMod b e m) + in print r ===================================== testsuite/tests/numeric/should_run/T18515.stdout ===================================== @@ -0,0 +1 @@ +1 ===================================== testsuite/tests/numeric/should_run/all.T ===================================== @@ -70,3 +70,6 @@ test('T15301', normal, compile_and_run, ['-O2']) test('T497', normal, compile_and_run, ['-O']) test('T17303', normal, compile_and_run, ['']) test('T18359', normal, compile_and_run, ['']) +test('T18499', normal, compile_and_run, ['']) +test('T18509', normal, compile_and_run, ['']) +test('T18515', normal, compile_and_run, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a10505e74ad9833d37d84afb9bf2cd031fd0ea71...3745bdb69b19e43da5b6a26597e1a95d17cca929 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a10505e74ad9833d37d84afb9bf2cd031fd0ea71...3745bdb69b19e43da5b6a26597e1a95d17cca929 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 22:22:57 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 13 Aug 2020 18:22:57 -0400 Subject: [Git][ghc/ghc][wip/backports] 61 commits: Bignum: add support for negative shifts (fix #18499) Message-ID: <5f35bd4127075_80b3f8486b5b7c08063514@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: 32496789 by Sylvain Henry at 2020-08-11T17:43:13+02:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - b4cccab3 by Sylvain Henry at 2020-08-11T17:48:05+02:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - 817f94f5 by Sylvain Henry at 2020-08-11T17:48:22+02:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - eab2511e by Sylvain Henry at 2020-08-12T11:43:42+02:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3745bdb6 by Sylvain Henry at 2020-08-12T11:43:42+02:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 7cf007cc by David Binder at 2020-08-13T18:22:38-04:00 Fix dead link to haskell prime discussion - - - - - 205f168c by BinderDavid at 2020-08-13T18:22:38-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 29794212 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Remove length field from FastString - - - - - f8804cd8 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 5acdf506 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - a9b46ec3 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - fcb9e94d by Daniel Gröber at 2020-08-13T18:22:38-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 44b28e97 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - f0fe989d by Daniel Gröber at 2020-08-13T18:22:38-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 59cd5cd4 by Daniel Gröber at 2020-08-13T18:22:38-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - 0f66e49e by Ben Gamari at 2020-08-13T18:22:38-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 3ecac53c by Andreas Klebinger at 2020-08-13T18:22:39-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - dbf77b79 by Sylvain Henry at 2020-08-13T18:22:39-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - 4e22de2a by Sylvain Henry at 2020-08-13T18:22:39-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - e27698ce by Sylvain Henry at 2020-08-13T18:22:39-04:00 Remove unused sGhcWithNativeCodeGen - - - - - 666acbd4 by Sylvain Henry at 2020-08-13T18:22:39-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - ce5408c0 by Sylvain Henry at 2020-08-13T18:22:39-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - 9751d499 by Tamar Christina at 2020-08-13T18:22:39-04:00 winio: restore console cp on exit (cherry picked from commit cdd0ff16f20ce920c74f9128a1067cbe1bd378c2) - - - - - 5438dcec by Tamar Christina at 2020-08-13T18:22:39-04:00 winio: change memory allocation strategy and fix double free errors. (cherry picked from commit c1f4f81d3a439cd1a8128e4ab11c7caac7cc0ad8) - - - - - 5544d17a by Stefan Schulze Frielinghaus at 2020-08-13T18:22:39-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 (cherry picked from commit fc0f6fbcd95f2dc69a8efabbee2d8a485c34cc47) - - - - - e66e281d by Matthias Andreas Benkard at 2020-08-13T18:22:39-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. (cherry picked from commit a7c4439a407ad85b76aab9301fda61e7c10183ff) - - - - - 986063cf by Ben Gamari at 2020-08-13T18:22:39-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. (cherry picked from commit da7269a4472856ba701d956a247599f721e9915e) - - - - - b2f8c6a7 by Ben Gamari at 2020-08-13T18:22:39-04:00 testsuite: Update win32 output for parseTree (cherry picked from commit f153a1d0a3351ad4d94cef4cef8e63bab5b47008) - - - - - 83a0649c by Ben Gamari at 2020-08-13T18:22:39-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. (cherry picked from commit e91672f0b7185bbafbe8ed1f2ae2cb775111f950) - - - - - 97ac5b2a by Ben Gamari at 2020-08-13T18:22:39-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. (cherry picked from commit 9cbfe0868418a531da0872b0c477a15aa67f8861) - - - - - 8f1154d3 by Tamar Christina at 2020-08-13T18:22:39-04:00 winio: remove dead argument to stg_newIOPortzh (cherry picked from commit 8236925fc8cc2e6e3fed61a0676fa65270a4a538) - - - - - 39c6fbae by Tamar Christina at 2020-08-13T18:22:39-04:00 winio: fix detection of tty terminals (cherry picked from commit ce0a1d678fbc8efa5fd384fd0227b7b3dc97cadd) - - - - - b784c75a by Tamar Christina at 2020-08-13T18:22:40-04:00 winio: update codeowners (cherry picked from commit 52685cf7c077c51e3719e3c4dd5ca8257a99c4ea) - - - - - 8388567e by Ben Gamari at 2020-08-13T18:22:40-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. (cherry picked from commit aa054d32a8ff69c334293a0d6c9d11b83a236a96) - - - - - 353521ab by Simon Peyton Jones at 2020-08-13T18:22:40-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 (cherry picked from commit 3d345c9680ab3d766ef43dd8389ccc1eaeca066c) - - - - - c0a3283a by Ben Gamari at 2020-08-13T18:22:40-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. (cherry picked from commit 57aca6bba1c000f8542ce94e8b724b0334ff96d4) - - - - - e14ee26b by Ben Gamari at 2020-08-13T18:22:40-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. (cherry picked from commit 0a815cea9fa11ce6ef22aec3525dd7a0df541daf) - - - - - cf9a6c17 by Simon Peyton Jones at 2020-08-13T18:22:40-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 (cherry picked from commit 0bd60059b0edfee9e8f66c6817257bbb946656cd) - - - - - 6ba13945 by Sergei Trofimovich at 2020-08-13T18:22:40-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> (cherry picked from commit 39c89862161bf488a6aca9372cbb67690f436ce7) - - - - - 59226e20 by Felix Wiemuth at 2020-08-13T18:22:40-04:00 Fix typo (cherry picked from commit b9a880fce484d0a87bb794b9d2d8a73e54819011) - - - - - 9166d4d6 by Simon Peyton Jones at 2020-08-13T18:22:40-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 (cherry picked from commit bbc5191640761ca9773abc898c077363b7beb4e7) - - - - - 505a9d68 by John Ericson at 2020-08-13T18:22:40-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. (cherry picked from commit 6c68a84254d70280e2dc73485f361787a3503850) - - - - - bd365c1d by Simon Peyton Jones at 2020-08-13T18:22:40-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d (cherry picked from commit 9f71f69714255165d0fdc2790a588487ff9439dc) - - - - - 6653e139 by Sylvain Henry at 2020-08-13T18:22:40-04:00 Fix minimal imports dump for boot files (fix #18497) (cherry picked from commit 7c274cd530cc42a26028050b75d56b3437e06ec1) - - - - - 2c86713b by Leon Schoorl at 2020-08-13T18:22:41-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 (cherry picked from commit f2d1accf67cb6e1dab6b2c78fef4b64526c31a4a) - - - - - 36d8cd6f by Niklas Hambüchen at 2020-08-13T18:22:41-04:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. (cherry picked from commit 947206f478d4eef641dfc58cb4c13471a23260c3) - - - - - 01534bf9 by Krzysztof Gogolewski at 2020-08-13T18:22:48-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. (cherry picked from commit 5e12cd1733b581f48a5873b12971b6974778eabb) - - - - - 20a45d0c by Ben Gamari at 2020-08-13T18:22:48-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. (cherry picked from commit 2bff2f87e43985e02bdde8c6fa39279df86cb617) - - - - - 2911d640 by Ben Gamari at 2020-08-13T18:22:48-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. (cherry picked from commit 53ce0db5a06598c88c6b8cb32043b878e7083dd4) - - - - - cb3e202a by Ryan Scott at 2020-08-13T18:22:48-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. (cherry picked from commit fbcb886d503dd7aaebc4c40e59615068b3fd0bd7) - - - - - bd506bd6 by Vladislav Zavialov at 2020-08-13T18:22:48-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. (cherry picked from commit aee45d9ea8c6cf4ebad4d5c732748923c7865cbe) - - - - - bc186461 by Takenobu Tani at 2020-08-13T18:22:48-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] (cherry picked from commit 9570c21295a2b4a1d1e40939869124f0b9b9bf91) - - - - - 77653d5c by Ben Gamari at 2020-08-13T18:22:48-04:00 cmm: Clean up Notes a bit (cherry picked from commit 5f03606319f745b10e9918c76a47426b293f0bf9) - - - - - 47de152f by Ben Gamari at 2020-08-13T18:22:48-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. (cherry picked from commit 6402c1240d5bd768b8fe8b4368413932bedbe107) - - - - - e64ac078 by Ben Gamari at 2020-08-13T18:22:48-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. (cherry picked from commit 15b36de030ecdd60897bc7a6a02bdeabd0825be4) - - - - - 24c230ce by Ben Gamari at 2020-08-13T18:22:48-04:00 testsuite: Add test for #18527 (cherry picked from commit 3847ae0ccf67bddf73304a39f5320c3ba285aa48) - - - - - ee2ed876 by Ben Gamari at 2020-08-13T18:22:48-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. (cherry picked from commit dd51d53be42114c105b5ab15fcbdb387526b1c17) - - - - - b4c33250 by Alan Zimmerman at 2020-08-13T18:22:48-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. (cherry picked from commit e4f1b73ad9f292a6bbeb21fee44b0ba1a7f3c33b) - - - - - cb39cfdc by Ben Gamari at 2020-08-13T18:22:48-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. (cherry picked from commit 8a665db6174eaedbbae925c0ccb4c22b3f29bcaf) - - - - - b221b571 by Alex Biehl at 2020-08-13T18:22:48-04:00 Hardcode RTS includes to cope with unregistered builds (cherry picked from commit ef2ae81a394df573510b12b7e11bba0c931249d8) - - - - - c15fb71b by Ben Gamari at 2020-08-13T18:22:48-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". (cherry picked from commit f1088b3f31ceddf918a319c97557fb1f08a9a387) - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/test-metrics.sh - CODEOWNERS - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/Opt/OccurAnal.hs - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/SetLevels.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Monad.hs - compiler/GHC/Core/Opt/Simplify/Utils.hs - compiler/GHC/Core/SimpleOpt.hs - compiler/GHC/Data/FastString.hs - compiler/GHC/Data/StringBuffer.hs - + compiler/GHC/Driver/Backend.hs - compiler/GHC/Driver/CodeOutput.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Make.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Annotation.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/58f2b5d13bd1d1744c3615f806bac2f6af0f45d6...c15fb71bed0924e5eec0ee877684f183f10265af -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/58f2b5d13bd1d1744c3615f806bac2f6af0f45d6...c15fb71bed0924e5eec0ee877684f183f10265af You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 13 23:54:21 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 13 Aug 2020 19:54:21 -0400 Subject: [Git][ghc/ghc][wip/gc/parallel-marking] nonmoving: Parallel marking? Message-ID: <5f35d2adce54d_80b3f84871687308064314@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/gc/parallel-marking at Glasgow Haskell Compiler / GHC Commits: 709288ea by Ben Gamari at 2020-08-13T23:35:02+00:00 nonmoving: Parallel marking? - - - - - 3 changed files: - rts/sm/NonMoving.c - rts/sm/NonMovingMark.c - rts/sm/NonMovingMark.h Changes: ===================================== rts/sm/NonMoving.c ===================================== @@ -714,6 +714,7 @@ void nonmovingInit(void) nonmovingHeap.allocators[i] = alloc_nonmoving_allocator(n_capabilities); } nonmovingMarkInitUpdRemSet(); + nonmovingInitMarkState(); } // Stop any nonmoving collection in preparation for RTS shutdown. @@ -915,9 +916,9 @@ void nonmovingCollect(StgWeak **dead_weaks, StgTSO **resurrected_threads) ASSERT(nonmoving_marked_compact_objects == NULL); ASSERT(n_nonmoving_marked_compact_blocks == 0); - MarkQueue *mark_queue = stgMallocBytes(sizeof(MarkQueue), "mark queue"); - initMarkQueue(mark_queue); - current_mark_queue = mark_queue; + // First initialize a MarkQueue for the leader thread: + startMarkThreads(1); + MarkQueue *mark_queue = mark_state.queues[0]; // Mark roots trace(TRACE_nonmoving_gc, "Marking roots for nonmoving GC"); @@ -981,6 +982,8 @@ void nonmovingCollect(StgWeak **dead_weaks, StgTSO **resurrected_threads) nonmovingConcurrentMark, mark_queue) != 0) { barf("nonmovingCollect: failed to spawn mark thread: %s", strerror(errno)); } + // Start the mark worker threads... + startMarkThreads(3); } else { nonmovingConcurrentMark(mark_queue); } @@ -998,7 +1001,7 @@ static void nonmovingMarkThreadsWeaks(MarkQueue *mark_queue) { while (true) { // Propagate marks - nonmovingMark(mark_queue); + nonmovingMarkLeader(); // Tidy threads and weaks nonmovingTidyThreads(); @@ -1102,7 +1105,7 @@ static void nonmovingMark_(MarkQueue *mark_queue, StgWeak **dead_weaks, StgTSO * // Do last marking of weak pointers while (true) { // Propagate marks - nonmovingMark(mark_queue); + nonmovingMarkLeader(); if (!nonmovingTidyWeaks(mark_queue)) break; @@ -1111,7 +1114,7 @@ static void nonmovingMark_(MarkQueue *mark_queue, StgWeak **dead_weaks, StgTSO * nonmovingMarkDeadWeaks(mark_queue, dead_weaks); // Propagate marks - nonmovingMark(mark_queue); + nonmovingMarkLeader(); // Now remove all dead objects from the mut_list to ensure that a younger // generation collection doesn't attempt to look at them after we've swept. @@ -1176,9 +1179,8 @@ static void nonmovingMark_(MarkQueue *mark_queue, StgWeak **dead_weaks, StgTSO * nonmovingFinishFlush(task); #endif - current_mark_queue = NULL; - freeMarkQueue(mark_queue); - stgFree(mark_queue); + // tear down the mark threads' state + stopMarkThreads(); oldest_gen->live_estimate = nonmoving_live_words; oldest_gen->n_old_blocks = 0; ===================================== rts/sm/NonMovingMark.c ===================================== @@ -24,6 +24,7 @@ #include "Stats.h" #include "STM.h" #include "MarkWeak.h" +#include "RtsUtils.h" #include "sm/Storage.h" #include "CNF.h" @@ -117,6 +118,8 @@ StgWeak *nonmoving_weak_ptr_list = NULL; StgIndStatic *debug_caf_list_snapshot = (StgIndStatic*)END_OF_CAF_LIST; #endif +struct MarkState mark_state; + /* Note [Update remembered set] * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * The concurrent non-moving collector uses a remembered set to ensure @@ -365,7 +368,6 @@ upd_rem_set_push_gc(UpdRemSet *rs, MarkQueueEnt *ent) markQueueBlockPush(rs->block, ent); } - STATIC_INLINE void mark_queue_push (MarkQueue *q, const MarkQueueEnt *ent) { @@ -375,7 +377,15 @@ mark_queue_push (MarkQueue *q, const MarkQueueEnt *ent) // Allocate a fresh block. ACQUIRE_SM_LOCK; bdescr *bd = allocGroup(MARK_QUEUE_BLOCKS); - bd->link = markQueueBlockBdescr(q->top); + + // First try pushing onto local deque... + if (q->rest != NULL && pushWSDeque(q->rest, q->top)) { + bd->link = NULL; + } else { + // deque overflowed. link onto the new block's list. + bd->link = markQueueBlockBdescr(q->top); + } + q->top = (MarkQueueBlock *) bd->start; q->top->head = 0; RELEASE_SM_LOCK; @@ -386,7 +396,7 @@ mark_queue_push (MarkQueue *q, const MarkQueueEnt *ent) STATIC_INLINE void push(struct MarkContext *mc, MarkQueueEnt *ent) { switch (mc->kind) { - case MARK_CTX_IN_CONC_MARK: + case MARK_CTX_IN_CONC_MARK: mark_queue_push(mc->in_conc_mark.queue, ent); break; case MARK_CTX_IN_MOVING_GC: @@ -410,7 +420,7 @@ void nonmovingMarkInitUpdRemSet() { #if defined(THREADED_RTS) && defined(DEBUG) static uint32_t markQueueLength(MarkQueue *q); #endif -static void init_mark_queue_(MarkQueue *queue); +static void init_mark_queue(MarkQueue *queue); /* Transfers the given capability's update-remembered set to the global * remembered set. Must hold SM lock/allocation spinlock. @@ -875,6 +885,17 @@ void markQueueAddRoot (MarkQueue* q, StgClosure** root) * Popping from the mark queue *********************************************************/ +static MarkQueueBlock *try_stealing(void) +{ + for (uint32_t i = 0; i < mark_state.n_mark_threads; i++) { + MarkQueueBlock *b = (MarkQueueBlock *) stealWSDeque(mark_state.queues[i]->rest); + if (b != NULL) { + return b; + } + } + return NULL; +} + // Returns invalid MarkQueueEnt if queue is empty. static MarkQueueEnt markQueuePop_ (MarkQueue *q) { @@ -887,19 +908,41 @@ again: if (top->head == 0) { bdescr *old_block = markQueueBlockBdescr(q->top); // Is this the only block in the queue? - if (old_block->link == NULL) { - // Yes, therefore queue is empty... - MarkQueueEnt none = { .null_entry = { .p = NULL } }; - return none; - } else { + if (old_block->link != NULL) { // No, unwind to the previous block and try popping again... bdescr *new_block = old_block->link; q->top = (MarkQueueBlock*) new_block->start; ACQUIRE_SM_LOCK; - freeGroup(old_block); // TODO: hold on to a block to avoid repeated allocation/deallocation? + freeGroup(old_block); + // TODO: hold on to a block to avoid repeated allocation/deallocation? + RELEASE_SM_LOCK; + goto again; + } + + // Yes, this is the only block therefore queue is empty... + // Next we try pulling from our own deque... + MarkQueueBlock *new = (MarkQueueBlock *) popWSDeque(q->rest); + if (new != NULL) { + q->top = new; + ACQUIRE_SM_LOCK; + freeGroup(old_block); RELEASE_SM_LOCK; goto again; } + + // Our deque is also empty... + // Now try pulling from other threads deques... + new = try_stealing(); + if (new != NULL) { + q->top = new; + ACQUIRE_SM_LOCK; + freeGroup(old_block); + RELEASE_SM_LOCK; + goto again; + } + + const MarkQueueEnt none = { .null_entry = { .p = NULL } }; + return none; } top->head--; @@ -961,23 +1004,20 @@ void init_upd_rem_set (UpdRemSet *queue) } /* Must hold sm_mutex. */ -static void init_mark_queue_ (MarkQueue *queue) +static void init_mark_queue (MarkQueue *queue) { bdescr *bd = allocGroup(MARK_QUEUE_BLOCKS); queue->top = (MarkQueueBlock *) bd->start; queue->top->head = 0; + queue->rest = newWSDeque(MARK_QUEUE_DEQUE_SIZE); + queue->mark_thread_n = -1; + queue->thread_id = -1; #if MARK_PREFETCH_QUEUE_DEPTH > 0 memset(&queue->prefetch_queue, 0, sizeof(queue->prefetch_queue)); queue->prefetch_head = 0; #endif } -/* Must hold sm_mutex. */ -void initMarkQueue (MarkQueue *queue) -{ - init_mark_queue_(queue); -} - void reset_upd_rem_set (UpdRemSet *rset) { // UpdRemSets always have one block for the mark queue. This assertion is to @@ -986,7 +1026,8 @@ void reset_upd_rem_set (UpdRemSet *rset) rset->block->head = 0; } -void freeMarkQueue (MarkQueue *queue) +static void +freeMarkQueue (MarkQueue *queue) { freeChain_lock(markQueueBlockBdescr(queue->top)); } @@ -1759,8 +1800,8 @@ done: * c. the mark queue has been seeded with a set of roots. * */ -GNUC_ATTR_HOT void -nonmovingMark (MarkQueue *queue) +static GNUC_ATTR_HOT void +nonmovingMarkLoop (MarkQueue *queue) { struct MarkContext mctx = markContextInConcMark(queue); traceConcMarkBegin(); @@ -1792,8 +1833,9 @@ nonmovingMark (MarkQueue *queue) } case NULL_ENTRY: // Perhaps the update remembered set has more to mark... + + ACQUIRE_LOCK(&upd_rem_set_lock); if (upd_rem_set_block_list) { - ACQUIRE_LOCK(&upd_rem_set_lock); bdescr *old = markQueueBlockBdescr(queue->top); queue->top = (MarkQueueBlock *) upd_rem_set_block_list->start; upd_rem_set_block_list = NULL; @@ -1803,7 +1845,8 @@ nonmovingMark (MarkQueue *queue) freeGroup(old); RELEASE_SM_LOCK; } else { - // Nothing more to do + // We are out of work... + RELEASE_LOCK(&upd_rem_set_lock); debugTrace(DEBUG_nonmoving_gc, "Finished mark pass: %d", count); traceConcMarkEnd(count); return; @@ -1812,6 +1855,129 @@ nonmovingMark (MarkQueue *queue) } } +/* + * This is the mark loop run by the leader thread (mark_thread_n == 0). It + * kicks the worker threads, starts marking itself, and waits until everyone + * finishes. + */ +void +nonmovingMarkLeader () +{ + ACQUIRE_LOCK(&mark_state.lock); + mark_state.active_mark_threads ++; + broadcastCondition(&mark_state.new_work_cond); + RELEASE_LOCK(&mark_state.lock); + nonmovingMarkLoop(mark_state.queues[0]); + + ACQUIRE_LOCK(&mark_state.lock); + mark_state.active_mark_threads --; + while (mark_state.active_mark_threads > 0) { + waitCondition(&mark_state.phase_done_cond, &mark_state.lock); + } + + // Sanity check +#if defined(DEBUG) + for (int i=0; i < mark_state.n_mark_threads; i++) { + ASSERT(stealWSDeque(mark_state.queues[i]->rest) == NULL); + ASSERT(markQueueBlockIsEmpty(mark_state.queues[i]->top)); + } +#endif + + RELEASE_LOCK(&mark_state.lock); +} + +/* + * This is the loop run by the worker threads. + */ +static void * +nonmoving_mark_worker (void *user) +{ + MarkQueue *queue = (MarkQueue *) user; + const uint32_t mark_thread_n = queue->mark_thread_n; + + ACQUIRE_LOCK(&mark_state.lock); + mark_state.active_mark_threads --; + while (mark_thread_n < mark_state.n_mark_threads) { + // N.B. we hold mark_state.lock here + mark_state.active_mark_threads ++; + RELEASE_LOCK(&mark_state.lock); + nonmovingMarkLoop(queue); + ACQUIRE_LOCK(&mark_state.lock); + + mark_state.active_mark_threads --; + if (mark_state.active_mark_threads == 0) { + signalCondition(&mark_state.phase_done_cond); + } + if (mark_thread_n != 0) { + waitCondition(&mark_state.new_work_cond, &mark_state.lock); + } + } + RELEASE_LOCK(&mark_state.lock); + return NULL; +} + +void +nonmovingInitMarkState() +{ + initMutex(&mark_state.lock); + initCondition(&mark_state.phase_done_cond); + initCondition(&mark_state.new_work_cond); + mark_state.n_mark_threads = 0; + mark_state.active_mark_threads = 0; +} + +void +startMarkThreads(int n_mark_threads) +{ + ACQUIRE_LOCK(&mark_state.lock); + //ASSERT(mark_state.n_mark_threads == 0); + ASSERT(n_mark_threads >= 1); + + MarkQueue **old_queues = mark_state.queues; + mark_state.queues = stgMallocBytes(sizeof(MarkQueue*) * n_mark_threads, "startMarkThreads"); + if (old_queues != NULL) { + memcpy(mark_state.queues, old_queues, sizeof(MarkQueue*) * mark_state.n_mark_threads); + stgFree(old_queues); + } + + for (int i = mark_state.n_mark_threads; i < n_mark_threads; i++) { + MarkQueue *q = stgMallocBytes(sizeof(MarkQueue), "startMarkThreads"); + mark_state.queues[i] = q; + init_mark_queue(q); + + q->mark_thread_n = i; + mark_state.n_mark_threads ++; + + // N.B. mark thread 0 runs in the context of the main mark thread. + if (i > 0) { + mark_state.active_mark_threads ++; + int res = createOSThread(&q->thread_id, "concurrent mark thread", nonmoving_mark_worker, q); + if (res != 0) { + barf("startMarkThreads"); + } + } + } + RELEASE_LOCK(&mark_state.lock); +} + +void +stopMarkThreads() +{ + ACQUIRE_LOCK(&mark_state.lock); + // ensure that there are no active threads since we will be freeing + // the MarkQueues shortly. + ASSERT(mark_state.active_mark_threads == 0); + mark_state.n_mark_threads = 0; + broadcastCondition(&mark_state.new_work_cond); + + for (uint32_t i = 0; i < mark_state.n_mark_threads; i++) { + freeMarkQueue(mark_state.queues[i]); + } + stgFree(mark_state.queues); + mark_state.queues = NULL; + RELEASE_LOCK(&mark_state.lock); +} + // A variant of `isAlive` that works for non-moving heap. Used for: // // - Collecting weak pointers; checking key of a weak pointer. ===================================== rts/sm/NonMovingMark.h ===================================== @@ -10,6 +10,7 @@ #include "Task.h" #include "NonMoving.h" +#include "WSDeque.h" #include "BeginPrivate.h" @@ -88,6 +89,11 @@ INLINE_HEADER bool markQueueBlockIsFull(MarkQueueBlock *b) return b->head == MARK_QUEUE_BLOCK_ENTRIES; } +INLINE_HEADER bool markQueueBlockIsEmpty(MarkQueueBlock *b) +{ + return b->head == 0; +} + INLINE_HEADER MarkQueueBlock *markQueueBlockFromBdescr(bdescr *bd) { return (MarkQueueBlock *) bd->start; @@ -101,6 +107,9 @@ INLINE_HEADER bdescr *markQueueBlockBdescr(MarkQueueBlock *b) // How far ahead in mark queue to prefetch? #define MARK_PREFETCH_QUEUE_DEPTH 5 +// How many blocks to keep on the deque? +#define MARK_QUEUE_DEQUE_SIZE 32 + /* The mark queue is not capable of concurrent read or write. * * invariants: @@ -115,6 +124,12 @@ typedef struct MarkQueue_ { // Bdescr(q->top)->link->start MarkQueueBlock *top; + // A WSDeque of MarkQueueBlock*s which mark threads can steal from. When + // the deque overflows we link blocks onto Bdescr(top)->link. + WSDeque *rest; + + int mark_thread_n; + OSThreadId thread_id; #if MARK_PREFETCH_QUEUE_DEPTH > 0 // A ring-buffer of entries which we will mark next @@ -124,6 +139,25 @@ typedef struct MarkQueue_ { #endif } MarkQueue; +struct MarkState { + // protects active_mark_threads and n_mark_threads. + Mutex lock; + // signalled when all marking threads have finished a round of marking. + Condition phase_done_cond; + // signalled to wake up marking threads for a new round of marking + // (or terminate if .n_mark_threads > thread.mark_thread_n). + Condition new_work_cond; + // how many threads are currently marking? + uint32_t active_mark_threads; + // how many threads have been created? + // this is currently static throughout marking. + uint32_t n_mark_threads; + // an array of MarkQueue*s, one per mark thread + MarkQueue **queues; +}; + +extern struct MarkState mark_state; + /* The update remembered set. * * invariants: @@ -173,9 +207,10 @@ void nonmovingFinishFlush(Task *task); void markQueueAddRoot(MarkQueue* q, StgClosure** root); -void initMarkQueue(MarkQueue *queue); -void freeMarkQueue(MarkQueue *queue); -void nonmovingMark(struct MarkQueue_ *restrict queue); +void startMarkThreads(int n_mark_threads); +void stopMarkThreads(void); +void nonmovingInitMarkState(void); +void nonmovingMarkLeader(void); bool nonmovingTidyWeaks(struct MarkQueue_ *queue); void nonmovingTidyThreads(void); View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/709288ea154816116f374e9760e300807e239537 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/709288ea154816116f374e9760e300807e239537 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 00:35:49 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 13 Aug 2020 20:35:49 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18566 Message-ID: <5f35dc65eb05a_80b3f84693c1eb480647f2@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T18566 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18566 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 00:44:23 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 13 Aug 2020 20:44:23 -0400 Subject: [Git][ghc/ghc][wip/explicit-perf-baseline] 28 commits: A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure Message-ID: <5f35de67c1d3d_80b3f8495bc8b048067898@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/explicit-perf-baseline at Glasgow Haskell Compiler / GHC Commits: 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - b03e1a20 by Ben Gamari at 2020-08-13T20:44:21-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - 33757f25 by Ben Gamari at 2020-08-13T20:44:21-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4b91e5edf64363eff7d087731c2806464033447c...33757f25c7e5ae564b5c1ff643aad75c7960d65a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4b91e5edf64363eff7d087731c2806464033447c...33757f25c7e5ae564b5c1ff643aad75c7960d65a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 00:44:49 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 13 Aug 2020 20:44:49 -0400 Subject: [Git][ghc/ghc][wip/backports] 2 commits: testsuite: Allow baseline commit to be set explicitly Message-ID: <5f35de81ac71_80b3f8486298278806848d@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: 3bda53ad by Ben Gamari at 2020-08-13T20:44:39-04:00 testsuite: Allow baseline commit to be set explicitly (cherry picked from commit bbde6ea0ce80a154735f1302251d073a56606c20) - - - - - 682cf7c6 by Ben Gamari at 2020-08-13T20:44:39-04:00 gitlab-ci: Use MR base commit as performance baseline (cherry picked from commit 4b91e5edf64363eff7d087731c2806464033447c) - - - - - 8 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - hadrian/src/Settings/Builders/RunTest.hs - testsuite/driver/perf_notes.py - testsuite/driver/runtests.py - testsuite/driver/testglobals.py - testsuite/driver/testlib.py - testsuite/mk/test.mk Changes: ===================================== .gitlab-ci.yml ===================================== @@ -26,12 +26,28 @@ stages: - testing # head.hackage correctness and compiler performance testing - deploy # push documentation +# Note [The CI Story] +# ~~~~~~~~~~~~~~~~~~~ +# +# There are two different types of pipelines: +# +# - marge-bot merges to `master`. Here we perform an exhaustive validation +# across all of the platforms which we support. In addition, we push +# performance metric notes upstream, providing a persistent record of the +# performance characteristics of the compiler. +# +# - merge requests. Here we perform a slightly less exhaustive battery of +# testing. Namely we omit some configurations (e.g. the unregisterised job). +# These use the merge request's base commit for performance metric +# comparisons. +# + workflow: - # N.B.Don't run on wip/ branches, instead on run on merge requests. + # N.B. Don't run on wip/ branches, instead on run on merge requests. rules: - if: $CI_MERGE_REQUEST_ID - if: $CI_COMMIT_TAG - - if: '$CI_COMMIT_BRANCH == "master"' + - if: '$CI_COMMIT_BRANCH == "wip/marge_bot_batch_merge_job"' - if: '$CI_COMMIT_BRANCH =~ /ghc-[0.9]+\.[0-9]+/' - if: '$CI_PIPELINE_SOURCE == "web"' ===================================== .gitlab/ci.sh ===================================== @@ -363,6 +363,13 @@ function push_perf_notes() { "$TOP/.gitlab/test-metrics.sh" push } +# Figure out which commit should be used by the testsuite driver as a +# performance baseline. See Note [The CI Story]. +function determine_metric_baseline() { + export PERF_BASELINE_COMMIT="$(git merge-base $CI_MERGE_REQUEST_TARGET_BRANCH_NAME HEAD)" + info "Using $PERF_BASELINE_COMMIT for performance metric baseline..." +} + function test_make() { run "$MAKE" test_bindist TEST_PREP=YES run "$MAKE" V=0 test \ ===================================== hadrian/src/Settings/Builders/RunTest.hs ===================================== @@ -78,6 +78,7 @@ runTestBuilderArgs = builder RunTest ? do <*> (maybe False (=="YES") <$> lookupEnv "OS") (testEnv, testMetricsFile) <- expr . liftIO $ (,) <$> lookupEnv "TEST_ENV" <*> lookupEnv "METRICS_FILE" + perfBaseline <- expr . liftIO $ lookupEnv "PERF_BASELINE_COMMIT" threads <- shakeThreads <$> expr getShakeOptions os <- getTestSetting TestHostOS @@ -141,6 +142,9 @@ runTestBuilderArgs = builder RunTest ? do , arg "--config", arg $ "timeout_prog=" ++ show (top -/- timeoutProg) , arg "--config", arg $ "stats_files_dir=" ++ statsFilesDir , arg $ "--threads=" ++ show threads + , case perfBaseline of + Just commit | not (null commit) -> arg ("--perf-baseline=" ++ show commit) + _ -> mempty , emitWhenSet testEnv $ \env -> arg ("--test-env=" ++ show env) , emitWhenSet testMetricsFile $ \file -> arg ("--metrics-file=" ++ file) , getTestArgs -- User-provided arguments from command line. ===================================== testsuite/driver/perf_notes.py ===================================== @@ -76,8 +76,7 @@ PerfStat = NamedTuple('PerfStat', [('test_env', TestEnv), # A baseline recovered form stored metrics. Baseline = NamedTuple('Baseline', [('perfStat', PerfStat), - ('commit', GitHash), - ('commitDepth', int)]) + ('commit', GitHash)]) class MetricChange(Enum): # The metric appears to have no baseline and is presumably a new test. @@ -402,7 +401,8 @@ def baseline_metric(commit: GitHash, name: TestName, test_env: TestEnv, metric: MetricName, - way: WayName + way: WayName, + baseline_ref: Optional[GitRef] ) -> Optional[Baseline]: # For performance reasons (in order to avoid calling commit_hash), we assert # commit is already a commit hash. @@ -411,6 +411,8 @@ def baseline_metric(commit: GitHash, # Get all recent commit hashes. commit_hashes = baseline_commit_log(commit) + baseline_commit = commit_hash(baseline_ref) if baseline_ref else None + def has_expected_change(commit: GitHash) -> bool: return get_allowed_perf_changes(commit).get(name) is not None @@ -418,11 +420,18 @@ def baseline_metric(commit: GitHash, def find_baseline(namespace: NoteNamespace, test_env: TestEnv ) -> Optional[Baseline]: + if baseline_commit is not None: + current_metric = get_commit_metric(namespace, baseline_commit, test_env, name, metric, way) + if current_metric is not None: + return Baseline(current_metric, baseline_commit) + else: + return None + for depth, current_commit in list(enumerate(commit_hashes))[1:]: # Check for a metric on this commit. current_metric = get_commit_metric(namespace, current_commit, test_env, name, metric, way) if current_metric is not None: - return Baseline(current_metric, current_commit, depth) + return Baseline(current_metric, current_commit) # Stop if there is an expected change at this commit. In that case # metrics on ancestor commits will not be a valid baseline. @@ -552,7 +561,7 @@ def check_stats_change(actual: PerfStat, result = passed() if not change_allowed: error = str(change) + ' from ' + baseline.perfStat.test_env + \ - ' baseline @ HEAD~' + str(baseline.commitDepth) + ' baseline @ %s' % baseline.commit print(actual.metric, error + ':') result = failBecause('stat ' + error, tag='stat') ===================================== testsuite/driver/runtests.py ===================================== @@ -27,7 +27,7 @@ from testutil import getStdout, Watcher, str_warn, str_info from testglobals import getConfig, ghc_env, getTestRun, TestConfig, \ TestOptions, brokens, PerfMetric from my_typing import TestName -from perf_notes import MetricChange, inside_git_repo, is_worktree_dirty, format_perf_stat +from perf_notes import MetricChange, GitRef, inside_git_repo, is_worktree_dirty, format_perf_stat from junit import junit import term_color from term_color import Color, colored @@ -70,6 +70,7 @@ parser.add_argument("--verbose", type=int, choices=[0,1,2,3,4,5], help="verbose parser.add_argument("--junit", type=argparse.FileType('wb'), help="output testsuite summary in JUnit format") parser.add_argument("--broken-test", action="append", default=[], help="a test name to mark as broken for this run") parser.add_argument("--test-env", default='local', help="Override default chosen test-env.") +parser.add_argument("--perf-baseline", type=GitRef, metavar='COMMIT', help="Baseline commit for performance comparsons.") perf_group.add_argument("--skip-perf-tests", action="store_true", help="skip performance tests") perf_group.add_argument("--only-perf-tests", action="store_true", help="Only do performance tests") @@ -101,6 +102,7 @@ config.metrics_file = args.metrics_file hasMetricsFile = config.metrics_file is not None config.summary_file = args.summary_file config.no_print_summary = args.no_print_summary +config.baseline_commit = args.perf_baseline if args.only: config.only = args.only @@ -351,8 +353,8 @@ def tabulate_metrics(metrics: List[PerfMetric]) -> None: rel = 100 * (val1 - val0) / val0 print("{space:24} {herald:40} {value:15.3f} [{direction}, {rel:2.1f}%]".format( space = "", - herald = "(baseline @ HEAD~{depth})".format( - depth = metric.baseline.commitDepth), + herald = "(baseline @ {commit})".format( + commit = metric.baseline.commit), value = val0, direction = metric.change, rel = rel @@ -422,6 +424,8 @@ else: # Dump metrics data. print("\nPerformance Metrics (test environment: {}):\n".format(config.test_env)) + if config.baseline_commit: + print('Performance baseline: %s\n' % config.baseline_commit) if any(t.metrics): tabulate_metrics(t.metrics) else: @@ -477,19 +481,19 @@ else: summary(t, sys.stdout, config.no_print_summary, config.supports_colors) # Write perf stats if any exist or if a metrics file is specified. - stats = [stat for (_, stat, __) in t.metrics] + stats_metrics = [stat for (_, stat, __) in t.metrics] # type: List[PerfStat] if hasMetricsFile: - print('Appending ' + str(len(stats)) + ' stats to file: ' + config.metrics_file) + print('Appending ' + str(len(stats_metrics)) + ' stats to file: ' + config.metrics_file) with open(config.metrics_file, 'a') as f: - f.write("\n" + Perf.format_perf_stat(stats)) - elif inside_git_repo() and any(stats): + f.write("\n" + Perf.format_perf_stat(stats_metrics)) + elif inside_git_repo() and any(stats_metrics): if is_worktree_dirty(): print() print(str_warn('Performance Metrics NOT Saved') + \ ' working tree is dirty. Commit changes or use ' + \ '--metrics-file to save metrics to a file.') else: - Perf.append_perf_stat(stats) + Perf.append_perf_stat(stats_metrics) # Write summary if config.summary_file: ===================================== testsuite/driver/testglobals.py ===================================== @@ -4,7 +4,7 @@ from my_typing import * from pathlib import Path -from perf_notes import MetricChange, PerfStat, Baseline, MetricOracles +from perf_notes import MetricChange, PerfStat, Baseline, MetricOracles, GitRef from datetime import datetime # ----------------------------------------------------------------------------- @@ -160,6 +160,9 @@ class TestConfig: # run. self.broken_tests = set() # type: Set[TestName] + # Baseline commit for performane metric comparisons. + self.baseline_commit = None # type: Optional[GitRef] + # Should we skip performance tests self.skip_perf_tests = False ===================================== testsuite/driver/testlib.py ===================================== @@ -477,7 +477,8 @@ def _collect_stats(name: TestName, opts, metrics, deviation, is_compiler_stats_t metric = '{}/{}'.format(tag, metric_name) def baselineByWay(way, target_commit, metric=metric): return Perf.baseline_metric( \ - target_commit, name, config.test_env, metric, way) + target_commit, name, config.test_env, metric, way, \ + config.baseline_commit ) opts.stats_range_fields[metric] = MetricOracles(baseline=baselineByWay, deviation=deviation) ===================================== testsuite/mk/test.mk ===================================== @@ -226,6 +226,10 @@ ifneq "$(VERBOSE)" "" RUNTEST_OPTS += --verbose=$(VERBOSE) endif +ifneq "$(PERF_TEST_BASELINE_COMMIT)" "" +RUNTEST_OPTS += --perf-baseline=$(PERF_TEST_BASELINE_COMMIT) +endif + ifeq "$(SKIP_PERF_TESTS)" "YES" RUNTEST_OPTS += --skip-perf-tests endif View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c15fb71bed0924e5eec0ee877684f183f10265af...682cf7c6e266b7fcadc1e8ddf0b23991a008e39f -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c15fb71bed0924e5eec0ee877684f183f10265af...682cf7c6e266b7fcadc1e8ddf0b23991a008e39f You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 00:45:39 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 13 Aug 2020 20:45:39 -0400 Subject: [Git][ghc/ghc][wip/perf-ci] 28 commits: A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure Message-ID: <5f35deb3e8241_80b3f84865febec807238d@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/perf-ci at Glasgow Haskell Compiler / GHC Commits: 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - 6c6bc169 by Ben Gamari at 2020-08-13T20:45:37-04:00 ci.sh: Factor out common utilities - - - - - 43bda605 by Ben Gamari at 2020-08-13T20:45:37-04:00 ci: Add ad-hoc performance testing rule - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - + .gitlab/common.sh - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0fa6f7494ec6ebb03e5f8d108604d39f497a2b41...43bda605b34f7302e68f4d6455ac84a118679fe5 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0fa6f7494ec6ebb03e5f8d108604d39f497a2b41...43bda605b34f7302e68f4d6455ac84a118679fe5 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 00:48:23 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 13 Aug 2020 20:48:23 -0400 Subject: [Git][ghc/ghc][wip/T18291] 19 commits: hadrian: depend on boot compiler version #18001 Message-ID: <5f35df5752d46_80b3f848629827880773d7@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18291 at Glasgow Haskell Compiler / GHC Commits: a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - 2f0bae73 by Ben Gamari at 2020-08-13T20:48:22-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 6c7785f8 by Ben Gamari at 2020-08-13T20:48:22-04:00 testsuite: Add test for #18291 - - - - - 30 changed files: - compiler/GHC.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - compiler/GHC/CmmToAsm/CPrim.hs - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Format.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/db7b78d8fab415ee657dc31b5daa9939655b156a...6c7785f8e17a43a2578366134f74fd1989077b73 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/db7b78d8fab415ee657dc31b5daa9939655b156a...6c7785f8e17a43a2578366134f74fd1989077b73 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 01:08:44 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 13 Aug 2020 21:08:44 -0400 Subject: [Git][ghc/ghc][master] Add HomeUnit type Message-ID: <5f35e41c526d0_80b3f8486b5b7c0808215b@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 30 changed files: - compiler/GHC.hs - compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/CoreToStg/Prep.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Driver/Finder.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Make.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/HsToCore.hs - compiler/GHC/HsToCore/Monad.hs - compiler/GHC/HsToCore/Usage.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/Iface/Recomp.hs - compiler/GHC/Iface/Recomp/Flags.hs - compiler/GHC/Iface/Rename.hs - compiler/GHC/Iface/Tidy.hs - compiler/GHC/Parser/Lexer.x - compiler/GHC/Rename/Module.hs - compiler/GHC/Rename/Names.hs - compiler/GHC/Runtime/Eval.hs - compiler/GHC/Runtime/Linker.hs - compiler/GHC/SysTools.hs - compiler/GHC/SysTools/ExtraObj.hs - compiler/GHC/Tc/Module.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Tc/Utils/Backpack.hs - compiler/GHC/Tc/Utils/Env.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ffc0d578ea22de02a68c64c094602701e65d8895 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ffc0d578ea22de02a68c64c094602701e65d8895 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 01:09:22 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 13 Aug 2020 21:09:22 -0400 Subject: [Git][ghc/ghc][master] Make IOEnv monad one-shot (#18202) Message-ID: <5f35e44277100_80b1075951c80848ca@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 1 changed file: - compiler/GHC/Data/IOEnv.hs Changes: ===================================== compiler/GHC/Data/IOEnv.hs ===================================== @@ -1,6 +1,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DerivingVia #-} +{-# LANGUAGE PatternSynonyms #-} -- -- (c) The University of Glasgow 2002-2006 -- @@ -48,16 +49,25 @@ import Control.Monad.Trans.Reader import Control.Monad.Catch (MonadCatch, MonadMask, MonadThrow) import GHC.Utils.Monad import Control.Applicative (Alternative(..)) +import GHC.Exts( oneShot ) ---------------------------------------------------------------------- -- Defining the monad type ---------------------------------------------------------------------- -newtype IOEnv env a = IOEnv (env -> IO a) +newtype IOEnv env a = IOEnv' (env -> IO a) deriving (Functor) deriving (MonadThrow, MonadCatch, MonadMask, MonadIO) via (ReaderT env IO) +-- See Note [The one-shot state monad trick] in GHC.Utils.Monad +pattern IOEnv :: forall env a. (env -> IO a) -> IOEnv env a +pattern IOEnv m <- IOEnv' m + where + IOEnv m = IOEnv' (oneShot m) + +{-# COMPLETE IOEnv #-} + unIOEnv :: IOEnv env a -> (env -> IO a) unIOEnv (IOEnv m) = m View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8a51b2ab7433c06bddca9699b0dfd8ab1d11879b -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8a51b2ab7433c06bddca9699b0dfd8ab1d11879b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 01:31:41 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Thu, 13 Aug 2020 21:31:41 -0400 Subject: [Git][ghc/ghc][wip/T18566] Add CALLER_CC pragma Message-ID: <5f35e97d8f6f9_80b40e7e10808597f@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18566 at Glasgow Haskell Compiler / GHC Commits: e6c0d6b0 by Ben Gamari at 2020-08-14T01:31:12+00:00 Add CALLER_CC pragma - - - - - 21 changed files: - compiler/GHC/Core/CallerCc.hs → compiler/GHC/Core/AddCallerCcs.hs - compiler/GHC/Core/Lint.hs - − compiler/GHC/Core/Opt/AddCallerCcs.hs - compiler/GHC/Core/Opt/Monad.hs - compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/WorkWrap.hs - compiler/GHC/CoreToIface.hs - compiler/GHC/Driver/Flags.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Extension.hs - compiler/GHC/HsToCore/Quote.hs - compiler/GHC/Iface/Syntax.hs - compiler/GHC/IfaceToCore.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Lexer.x - compiler/GHC/Rename/Bind.hs - compiler/GHC/Tc/Gen/Sig.hs - compiler/GHC/Types/Id.hs - compiler/GHC/Types/Id/Info.hs - compiler/ghc.cabal.in Changes: ===================================== compiler/GHC/Core/CallerCc.hs → compiler/GHC/Core/AddCallerCcs.hs ===================================== @@ -6,28 +6,28 @@ {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE TupleSections #-} -module GHC.Core.CallerCc (addCallerCcs) where - -import Data.Maybe -import Data.Data -import qualified Data.Generics as SYB -import GHC.Generics +module GHC.Core.AddCallerCcs (addCallerCcs) where import Control.Monad.Trans.State.Strict -import qualified Data.ByteString.Lazy as BSL -import qualified Data.Binary as B -import Data.List (intercalate) -import GHC import GHC.Prelude -import GHC.Serialized import GHC.Utils.Outputable +import GHC.Driver.Session +import GHC.Driver.Types import GHC.Types.CostCentre import GHC.Types.CostCentre.State +import GHC.Types.Name (nameSrcSpan) +import GHC.Types.SrcLoc +import GHC.Types.Var +import GHC.Unit.Types +import GHC.Data.FastString +import GHC.Types.Id.Info import GHC.Core +import GHC.Core.Opt.Monad -addCallerCcs :: DynFlags -> ModGuts -> ModGuts -addCallerCcs dflags guts = do +addCallerCcs :: ModGuts -> CoreM ModGuts +addCallerCcs guts = do + dflags <- getDynFlags let env :: Env env = Env { thisModule = mg_module guts @@ -35,9 +35,7 @@ addCallerCcs dflags guts = do , dflags = dflags , revParents = [] } - in guts { mg_binds = doCoreProgram env (mg_binds guts) - , mg_anns = anns' - } + return $ guts { mg_binds = doCoreProgram env (mg_binds guts) } doCoreProgram :: Env -> CoreProgram -> CoreProgram doCoreProgram env binds = flip evalState newCostCentreState $ do @@ -51,12 +49,12 @@ doBind env (Rec bs) = Rec <$> mapM doPair bs doExpr :: Env -> CoreExpr -> M CoreExpr doExpr env e@(Var v) - | needsCallSiteCostCentre env v = do + | needsCallSiteCostCentre v = do let nameDoc :: SDoc nameDoc = fsep (punctuate dot (map ppr (parents env))) <> parens (text "calling " <> ppr v) ccName :: CcName - ccName = mkFastString $ showSDoc (dflags env) nameDoc + ccName = mkFastString $ showSDocOneLine (initSDocContext (dflags env) defaultUserStyle) nameDoc ccIdx <- getCCIndex' ccName let span = case revParents env of top:_ -> nameSrcSpan $ varName top @@ -66,7 +64,7 @@ doExpr env e@(Var v) tick = ProfNote cc True True pure $ Tick tick e | otherwise = pure e -doExpr env e@(Lit _) = pure e +doExpr _env e@(Lit _) = pure e doExpr env (f `App` x) = App <$> doExpr env f <*> doExpr env x doExpr env (Lam b x) = Lam b <$> doExpr env x doExpr env (Let b rhs) = Let <$> doBind env b <*> doExpr env rhs @@ -76,8 +74,8 @@ doExpr env (Case scrut b ty alts) = doAlt (con, bs, rhs) = (con, bs,) <$> doExpr env rhs doExpr env (Cast expr co) = Cast <$> doExpr env expr <*> pure co doExpr env (Tick t e) = Tick t <$> doExpr env e -doExpr env e@(Type _) = pure e -doExpr env e@(Coercion _) = pure e +doExpr _env e@(Type _) = pure e +doExpr _env e@(Coercion _) = pure e type M = State CostCentreState @@ -97,8 +95,8 @@ addParent i env = env { revParents = i : revParents env } parents :: Env -> [Id] parents env = reverse (revParents env) -needsCallSiteCostCentre :: Env -> Id -> Bool -needsCallSiteCostCentre env i = +needsCallSiteCostCentre :: Id -> Bool +needsCallSiteCostCentre i = case callerCcInfo $ idInfo i of WantsCallerCc -> True NoCallerCc -> False ===================================== compiler/GHC/Core/Lint.hs ===================================== @@ -349,6 +349,7 @@ coreDumpFlag CoreTidy = Just Opt_D_dump_simpl coreDumpFlag CorePrep = Just Opt_D_dump_prep coreDumpFlag CoreOccurAnal = Just Opt_D_dump_occur_anal +coreDumpFlag CoreAddCallerCcs = Nothing coreDumpFlag CoreDoPrintCore = Nothing coreDumpFlag (CoreDoRuleCheck {}) = Nothing coreDumpFlag CoreDoNothing = Nothing ===================================== compiler/GHC/Core/Opt/AddCallerCcs.hs deleted ===================================== @@ -1,104 +0,0 @@ -{-# LANGUAGE NamedFieldPuns #-} -{-# LANGUAGE TypeApplications #-} -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE DeriveDataTypeable #-} -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE DerivingStrategies #-} -{-# LANGUAGE TupleSections #-} - -module GHC.Opt.Core.AddCallerCcs (addCallerCcs) where - -import Data.Maybe -import Data.Data -import qualified Data.Generics as SYB -import GHC.Generics - -import Control.Monad.Trans.State.Strict -import qualified Data.ByteString.Lazy as BSL -import qualified Data.Binary as B -import Data.List (intercalate) - -import GHC -import GHC.Prelude -import GHC.Serialized -import GHC.Utils.Outputable -import GHC.Types.CostCentre -import GHC.Types.CostCentre.State -import GHC.Core - -addCallerCcs :: DynFlags -> ModGuts -> ModGuts -addCallerCcs dflags guts = do - let env :: Env - env = Env - { thisModule = mg_module guts - , ccState = newCostCentreState - , dflags = dflags - , revParents = [] - } - in guts { mg_binds = doCoreProgram env (mg_binds guts) - , mg_anns = anns' - } - -doCoreProgram :: Env -> CoreProgram -> CoreProgram -doCoreProgram env binds = flip evalState newCostCentreState $ do - mapM (doBind env) binds - -doBind :: Env -> CoreBind -> M CoreBind -doBind env (NonRec b rhs) = NonRec b <$> doExpr (addParent b env) rhs -doBind env (Rec bs) = Rec <$> mapM doPair bs - where - doPair (b,rhs) = (b,) <$> doExpr (addParent b env) rhs - -doExpr :: Env -> CoreExpr -> M CoreExpr -doExpr env e@(Var v) - | needsCallSiteCostCentre env v = do - let nameDoc :: SDoc - nameDoc = fsep (punctuate dot (map ppr (parents env))) <> parens (text "calling " <> ppr v) - - ccName :: CcName - ccName = mkFastString $ showSDoc (dflags env) nameDoc - ccIdx <- getCCIndex' ccName - let span = case revParents env of - top:_ -> nameSrcSpan $ varName top - _ -> noSrcSpan - cc = NormalCC (ExprCC ccIdx) ccName (thisModule env) span - tick :: Tickish Id - tick = ProfNote cc True True - pure $ Tick tick e - | otherwise = pure e -doExpr env e@(Lit _) = pure e -doExpr env (f `App` x) = App <$> doExpr env f <*> doExpr env x -doExpr env (Lam b x) = Lam b <$> doExpr env x -doExpr env (Let b rhs) = Let <$> doBind env b <*> doExpr env rhs -doExpr env (Case scrut b ty alts) = - Case <$> doExpr env scrut <*> pure b <*> pure ty <*> mapM doAlt alts - where - doAlt (con, bs, rhs) = (con, bs,) <$> doExpr env rhs -doExpr env (Cast expr co) = Cast <$> doExpr env expr <*> pure co -doExpr env (Tick t e) = Tick t <$> doExpr env e -doExpr env e@(Type _) = pure e -doExpr env e@(Coercion _) = pure e - -type M = State CostCentreState - -getCCIndex' :: FastString -> M CostCentreIndex -getCCIndex' name = state (getCCIndex name) - -data Env = Env - { thisModule :: !Module - , dflags :: !DynFlags - , ccState :: !CostCentreState - , revParents :: [Id] - } - -addParent :: Id -> Env -> Env -addParent i env = env { revParents = i : revParents env } - -parents :: Env -> [Id] -parents env = reverse (revParents env) - -needsCallSiteCostCentre :: Env -> Id -> Bool -needsCallSiteCostCentre env i = - case callerCcInfo $ idInfo i of - WantsCallerCc -> True - NoCallerCc -> False ===================================== compiler/GHC/Core/Opt/Monad.hs ===================================== @@ -121,6 +121,7 @@ data CoreToDo -- These are diff core-to-core passes, | CoreTidy | CorePrep + | CoreAddCallerCcs | CoreOccurAnal instance Outputable CoreToDo where ===================================== compiler/GHC/Core/Opt/Pipeline.hs ===================================== @@ -50,6 +50,7 @@ import GHC.Core.Opt.CprAnal ( cprAnalProgram ) import GHC.Core.Opt.CallArity ( callArityAnalProgram ) import GHC.Core.Opt.Exitify ( exitifyProgram ) import GHC.Core.Opt.WorkWrap ( wwTopBinds ) +import GHC.Core.AddCallerCcs ( addCallerCcs ) import GHC.Types.SrcLoc import GHC.Utils.Misc import GHC.Unit.Module.Env @@ -140,6 +141,7 @@ getCoreToDo dflags eta_expand_on = gopt Opt_DoLambdaEtaExpansion dflags ww_on = gopt Opt_WorkerWrapper dflags static_ptrs = xopt LangExt.StaticPointers dflags + profiling = gopt Opt_ProfCallerCcs dflags maybe_rule_check phase = runMaybe rule_check (CoreDoRuleCheck phase) @@ -347,7 +349,9 @@ getCoreToDo dflags -- can become /exponentially/ more expensive. See #11731, #12996. runWhen (strictness || late_dmd_anal) CoreDoDemand, - maybe_rule_check FinalPhase + maybe_rule_check FinalPhase, + + runWhen profiling CoreAddCallerCcs ] -- Remove 'CoreDoNothing' and flatten 'CoreDoPasses' for clarity. @@ -464,6 +468,8 @@ doCorePass CoreDoSpecialising = {-# SCC "Specialise" #-} doCorePass CoreDoSpecConstr = {-# SCC "SpecConstr" #-} specConstrProgram +doCorePass CoreAddCallerCcs = {-# SCC "AddCallerCcs" #-} + addCallerCcs doCorePass CoreDoPrintCore = observe printCore doCorePass (CoreDoRuleCheck phase pat) = ruleCheckPass phase pat ===================================== compiler/GHC/Core/Opt/WorkWrap.hs ===================================== @@ -622,6 +622,8 @@ splitFun dflags fam_envs fn_id fn_info wrap_dmds div cpr rhs `setIdDemandInfo` worker_demand + `setIdCallerCcInfo` callerCcInfo fn_info + `setIdArity` work_arity -- Set the arity so that the Core Lint check that the -- arity is consistent with the demand type goes ===================================== compiler/GHC/CoreToIface.hs ===================================== @@ -450,10 +450,15 @@ toIfaceIdDetails other = pprTrace "toIfaceIdDetails" (ppr other) toIfaceIdInfo :: IdInfo -> IfaceIdInfo toIfaceIdInfo id_info = catMaybes [arity_hsinfo, caf_hsinfo, strict_hsinfo, cpr_hsinfo, - inline_hsinfo, unfold_hsinfo, levity_hsinfo] + inline_hsinfo, unfold_hsinfo, levity_hsinfo, caller_cc_hsinfo] -- NB: strictness and arity must appear in the list before unfolding -- See GHC.IfaceToCore.tcUnfolding where + ------------ CALLER_CC -------------- + caller_cc_hsinfo = case callerCcInfo id_info of + WantsCallerCc -> Just HsWantsCallerCc + _ -> Nothing + ------------ Arity -------------- arity_info = arityInfo id_info arity_hsinfo | arity_info == 0 = Nothing ===================================== compiler/GHC/Driver/Flags.hs ===================================== @@ -214,6 +214,7 @@ data GeneralFlag -- profiling opts | Opt_AutoSccsOnIndividualCafs | Opt_ProfCountEntries + | Opt_ProfCallerCcs -- misc opts | Opt_Pp ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -3535,6 +3535,7 @@ fFlagsDeps = [ flagSpec "print-typechecker-elaboration" Opt_PrintTypecheckerElaboration, flagSpec "prof-cafs" Opt_AutoSccsOnIndividualCafs, flagSpec "prof-count-entries" Opt_ProfCountEntries, + flagSpec "prof-caller-ccs" Opt_ProfCallerCcs, flagSpec "regs-graph" Opt_RegsGraph, flagSpec "regs-iterative" Opt_RegsIterative, depFlagSpec' "rewrite-rules" Opt_EnableRewriteRules @@ -3852,6 +3853,7 @@ defaultFlags settings Opt_OmitYields, Opt_PrintBindContents, Opt_ProfCountEntries, + Opt_ProfCallerCcs, Opt_RPath, Opt_SharedImplib, Opt_SimplPreInlining, ===================================== compiler/GHC/Hs/Binds.hs ===================================== @@ -1016,6 +1016,12 @@ data Sig pass SourceText -- Note [Pragma source text] in GHC.Types.Basic (XRec pass (IdP pass)) -- Function name (Maybe (XRec pass StringLiteral)) + + -- | A @CALLER_CC@ pragma for a declaration. + | CallerCcSig (XCallerCcSig pass) + SourceText + (XRec pass (IdP pass)) + -- | A complete match pragma -- -- > {-# COMPLETE C, D [:: T] #-} @@ -1027,6 +1033,7 @@ data Sig pass SourceText (XRec pass [XRec pass (IdP pass)]) (Maybe (XRec pass (IdP pass))) + | XSig !(XXSig pass) type instance XTypeSig (GhcPass p) = NoExtField @@ -1039,6 +1046,7 @@ type instance XSpecSig (GhcPass p) = NoExtField type instance XSpecInstSig (GhcPass p) = NoExtField type instance XMinimalSig (GhcPass p) = NoExtField type instance XSCCFunSig (GhcPass p) = NoExtField +type instance XCallerCcSig (GhcPass p) = NoExtField type instance XCompleteMatchSig (GhcPass p) = NoExtField type instance XXSig (GhcPass p) = NoExtCon @@ -1108,8 +1116,9 @@ isPragLSig :: forall p. UnXRec p => LSig p -> Bool isPragLSig (unXRec @p -> SpecSig {}) = True isPragLSig (unXRec @p -> InlineSig {}) = True isPragLSig (unXRec @p -> SCCFunSig {}) = True +isPragLSig (unXRec @p -> CallerCcSig {}) = True isPragLSig (unXRec @p -> CompleteMatchSig {}) = True -isPragLSig _ = False +isPragLSig _ = False isInlineLSig :: forall p. UnXRec p => LSig p -> Bool -- Identifies inline pragmas @@ -1124,6 +1133,10 @@ isSCCFunSig :: forall p. UnXRec p => LSig p -> Bool isSCCFunSig (unXRec @p -> SCCFunSig {}) = True isSCCFunSig _ = False +isCallerCCSig :: forall p. UnXRec p => LSig p -> Bool +isCallerCCSig (unXRec @p -> CallerCcSig {}) = True +isCallerCCSig _ = False + isCompleteMatchSig :: forall p. UnXRec p => LSig p -> Bool isCompleteMatchSig (unXRec @p -> CompleteMatchSig {} ) = True isCompleteMatchSig _ = False @@ -1143,6 +1156,7 @@ hsSigDoc (SpecInstSig _ src _) hsSigDoc (FixSig {}) = text "fixity declaration" hsSigDoc (MinimalSig {}) = text "MINIMAL pragma" hsSigDoc (SCCFunSig {}) = text "SCC pragma" +hsSigDoc (CallerCcSig {}) = text "CALLER_CC pragma" hsSigDoc (CompleteMatchSig {}) = text "COMPLETE pragma" hsSigDoc (XSig {}) = text "XSIG TTG extension" @@ -1180,6 +1194,8 @@ ppr_sig (PatSynSig _ names sig_ty) = text "pattern" <+> pprVarSig (map unLoc names) (ppr sig_ty) ppr_sig (SCCFunSig _ src fn mlabel) = pragSrcBrackets src "{-# SCC" (ppr fn <+> maybe empty ppr mlabel ) +ppr_sig (CallerCcSig _ src fn) + = pragSrcBrackets src "{-# CALLER_CC" (ppr fn) ppr_sig (CompleteMatchSig _ src cs mty) = pragSrcBrackets src "{-# COMPLETE" ((hsep (punctuate comma (map ppr (unLoc cs)))) ===================================== compiler/GHC/Hs/Extension.hs ===================================== @@ -370,6 +370,7 @@ type family XSpecSig x type family XSpecInstSig x type family XMinimalSig x type family XSCCFunSig x +type family XCallerCcSig x type family XCompleteMatchSig x type family XXSig x ===================================== compiler/GHC/HsToCore/Quote.hs ===================================== @@ -993,6 +993,7 @@ rep_sig (L loc (SpecSig _ nm tys ispec)) rep_sig (L loc (SpecInstSig _ _ ty)) = rep_specialiseInst ty loc rep_sig (L _ (MinimalSig {})) = notHandled "MINIMAL pragmas" empty rep_sig (L _ (SCCFunSig {})) = notHandled "SCC pragmas" empty +rep_sig (L _ (CallerCcSig {})) = notHandled "CALLER_CC pragmas" empty rep_sig (L loc (CompleteMatchSig _ _st cls mty)) = rep_complete_sig cls mty loc ===================================== compiler/GHC/Iface/Syntax.hs ===================================== @@ -353,6 +353,7 @@ data IfaceInfoItem | HsNoCafRefs | HsLevity -- Present <=> never levity polymorphic | HsLFInfo IfaceLFInfo + | HsWantsCallerCc -- NB: Specialisations and rules come in separately and are -- only later attached to the Id. Partial reason: some are orphans. @@ -1460,6 +1461,7 @@ instance Outputable IfaceInfoItem where ppr HsNoCafRefs = text "HasNoCafRefs" ppr HsLevity = text "Never levity-polymorphic" ppr (HsLFInfo lf_info) = text "LambdaFormInfo:" <+> ppr lf_info + ppr HsWantsCallerCc = text "WantsCallerCC" instance Outputable IfaceJoinInfo where ppr IfaceNotJoinPoint = empty @@ -2223,6 +2225,7 @@ instance Binary IfaceInfoItem where put_ bh HsLevity = putByte bh 5 put_ bh (HsCpr cpr) = putByte bh 6 >> put_ bh cpr put_ bh (HsLFInfo lf_info) = putByte bh 7 >> put_ bh lf_info + put_ bh HsWantsCallerCc = putByte bh 8 get bh = do h <- getByte bh @@ -2236,7 +2239,9 @@ instance Binary IfaceInfoItem where 4 -> return HsNoCafRefs 5 -> return HsLevity 6 -> HsCpr <$> get bh - _ -> HsLFInfo <$> get bh + 7 -> HsLFInfo <$> get bh + 8 -> return HsWantsCallerCc + _ -> fail "Binary(IfaceInfoItem): Invalid value" instance Binary IfaceUnfolding where put_ bh (IfCoreUnfold s e) = do ===================================== compiler/GHC/IfaceToCore.hs ===================================== @@ -1491,6 +1491,7 @@ tcIdInfo ignore_prags toplvl name ty info = do tcPrag :: IdInfo -> IfaceInfoItem -> IfL IdInfo tcPrag info HsNoCafRefs = return (info `setCafInfo` NoCafRefs) + tcPrag info HsWantsCallerCc = return (info `setCallerCcInfo` WantsCallerCc) tcPrag info (HsArity arity) = return (info `setArityInfo` arity) tcPrag info (HsStrictness str) = return (info `setStrictnessInfo` str) tcPrag info (HsCpr cpr) = return (info `setCprInfo` cpr) ===================================== compiler/GHC/Parser.y ===================================== @@ -527,6 +527,7 @@ are the most common patterns, rewritten as regular expressions for clarity: '{-# OVERLAPS' { L _ (IToverlaps_prag _) } '{-# INCOHERENT' { L _ (ITincoherent_prag _) } '{-# COMPLETE' { L _ (ITcomplete_prag _) } + '{-# CALLER_CC' { L _ (ITcaller_cc_prag _) } '#-}' { L _ ITclose_prag } '..' { L _ ITdotdot } -- reserved symbols @@ -2397,6 +2398,10 @@ sigdecl :: { LHsDecl GhcPs } (snd $2))))) ((mo $1:fst $2) ++ [mc $4]) } + | '{-# CALLER_CC' qvar '#-}' + {% ams ((sLL $1 $> $ SigD noExtField (CallerCcSig noExtField (getCALLER_CC_PRAGs $1) $2))) + [mo $1, mc $3] } + | '{-# SCC' qvar '#-}' {% ams (sLL $1 $> (SigD noExtField (SCCFunSig noExtField (getSCC_PRAGs $1) $2 Nothing))) [mo $1, mc $3] } @@ -3681,6 +3686,7 @@ getINLINE (L _ (ITinline_prag _ inl conl)) = (inl,conl) getSPEC_INLINE (L _ (ITspec_inline_prag _ True)) = (Inline, FunLike) getSPEC_INLINE (L _ (ITspec_inline_prag _ False)) = (NoInline,FunLike) getCOMPLETE_PRAGs (L _ (ITcomplete_prag x)) = x +getCALLER_CC_PRAGs (L _ (ITcaller_cc_prag x)) = x getVOCURLY (L (RealSrcSpan l _) ITvocurly) = srcSpanStartCol l getINTEGERs (L _ (ITinteger (IL src _ _))) = src ===================================== compiler/GHC/Parser/Lexer.x ===================================== @@ -758,6 +758,7 @@ data Token | IToverlaps_prag SourceText -- instance overlap mode | ITincoherent_prag SourceText -- instance overlap mode | ITctype SourceText + | ITcaller_cc_prag SourceText | ITcomment_line_prag -- See Note [Nested comment line pragmas] | ITdotdot -- reserved symbols @@ -3298,6 +3299,7 @@ oneWordPrags = Map.fromList [ ("incoherent", strtoken (\s -> ITincoherent_prag (SourceText s))), ("ctype", strtoken (\s -> ITctype (SourceText s))), ("complete", strtoken (\s -> ITcomplete_prag (SourceText s))), + ("caller_cc", strtoken (\s -> ITcaller_cc_prag (SourceText s))), ("column", columnPrag) ] ===================================== compiler/GHC/Rename/Bind.hs ===================================== @@ -1027,6 +1027,10 @@ renameSig ctxt sig@(SCCFunSig _ st v s) = do { new_v <- lookupSigOccRn ctxt sig v ; return (SCCFunSig noExtField st new_v s, emptyFVs) } +renameSig ctxt sig@(CallerCcSig _ st v) + = do { new_v <- lookupSigOccRn ctxt sig v + ; return (CallerCcSig noExtField st new_v, emptyFVs) } + -- COMPLETE Sigs can refer to imported IDs which is why we use -- lookupLocatedOccRn rather than lookupSigOccRn renameSig _ctxt sig@(CompleteMatchSig _ s (L l bf) mty) @@ -1109,6 +1113,9 @@ okHsSig ctxt (L _ sig) (SCCFunSig {}, HsBootCtxt {}) -> False (SCCFunSig {}, _) -> True + (CallerCcSig {}, HsBootCtxt {}) -> False + (CallerCcSig {}, _) -> True + (CompleteMatchSig {}, TopSigCtxt {} ) -> True (CompleteMatchSig {}, _) -> False ===================================== compiler/GHC/Tc/Gen/Sig.hs ===================================== @@ -46,7 +46,9 @@ import GHC.Driver.Session import GHC.Driver.Backend import GHC.Driver.Ppr import GHC.Types.Var ( TyVar, Specificity(..), tyVarKind, binderVars ) -import GHC.Types.Id ( Id, idName, idType, idInlinePragma, setInlinePragma, mkLocalId ) +import GHC.Types.Id ( Id, idName, idType, mkLocalId, + idInlinePragma, setInlinePragma, setIdCallerCcInfo ) +import GHC.Types.Id.Info ( CallerCcInfo(..) ) import GHC.Builtin.Names( mkUnboundName ) import GHC.Types.Basic import GHC.Unit.Module( getModule ) @@ -570,6 +572,8 @@ mkPragEnv sigs binds = Just (nm, L l $ InlineSig x lnm (add_arity nm inl)) get_sig (L l (SCCFunSig x st lnm@(L _ nm) str)) = Just (nm, L l $ SCCFunSig x st lnm str) + get_sig (L l (CallerCcSig x st lnm@(L _ nm))) + = Just (nm, L l $ CallerCcSig x st lnm) get_sig _ = Nothing add_arity n inl_prag -- Adjust inl_sat field to match visible arity of function @@ -598,12 +602,23 @@ lhsBindArity _ env = env -- PatBind/VarBind -- | Attach information from pragmas to an 'Id'\'s 'IdInfo'. addIdPrags :: TcId -> [LSig GhcRn] -> TcM TcId addIdPrags poly_id prags_for_me - = addInlinePrags poly_id prags_for_me + = do poly_id' <- addCallerCcPrag poly_id prags_for_me + addInlinePrags poly_id' prags_for_me + +addCallerCcPrag :: TcId -> [LSig GhcRn] -> TcM TcId +addCallerCcPrag poly_id prags_for_me + | _ : _ <- ccc_prags + = do { -- TODO: Warn on multiple pragmas + ; return (setIdCallerCcInfo poly_id WantsCallerCc) } + | otherwise + = return poly_id + where + ccc_prags = [loc | L loc (CallerCcSig _ _ _) <- prags_for_me] -addInlinePrags :: TcId -> [LSig GhcRc] -> TcM TcId +addInlinePrags :: TcId -> [LSig GhcRn] -> TcM TcId addInlinePrags poly_id prags_for_me | inl@(L _ prag) : inls <- inl_prags - = do { traceTc "addInlinePrag" (ppr poly_id $$ ppr prag) + = do { traceTc "addIdPrags" (ppr poly_id $$ ppr prag) ; unless (null inls) (warn_multiple_inlines inl inls) ; return (poly_id `setInlinePragma` prag) } | otherwise @@ -751,7 +766,7 @@ tcSpecPrags poly_id prag_sigs where spec_sigs = filter isSpecLSig prag_sigs bad_sigs = filter is_bad_sig prag_sigs - is_bad_sig s = not (isSpecLSig s || isInlineLSig s || isSCCFunSig s) + is_bad_sig s = not (isSpecLSig s || isInlineLSig s || isSCCFunSig s || isCallerCCSig s) warn_discarded_sigs = addWarnTc NoReason ===================================== compiler/GHC/Types/Id.hs ===================================== @@ -100,6 +100,7 @@ module GHC.Types.Id ( isNeverLevPolyId, -- ** Writing 'IdInfo' fields + setIdCallerCcInfo, setIdUnfolding, setCaseBndrEvald, setIdArity, setIdCallArity, @@ -169,6 +170,7 @@ infixl 1 `setIdUnfolding`, `setIdCallArity`, `setIdOccInfo`, `setIdOneShotInfo`, + `setIdCallerCcInfo`, `setIdSpecialisation`, `setInlinePragma`, @@ -645,6 +647,9 @@ asJoinId_maybe id Nothing = zapJoinId id ************************************************************************ -} +setIdCallerCcInfo :: Id -> CallerCcInfo -> Id +setIdCallerCcInfo id ccinfo = modifyIdInfo (`setCallerCcInfo` ccinfo) id + --------------------------------- -- ARITY idArity :: Id -> Arity ===================================== compiler/GHC/Types/Id/Info.hs ===================================== @@ -46,6 +46,10 @@ module GHC.Types.Id.Info ( cprInfo, setCprInfo, demandInfo, setDemandInfo, pprStrictness, + -- ** Caller-CC Info + callerCcInfo, setCallerCcInfo, + CallerCcInfo(..), + -- ** Unfolding Info unfoldingInfo, setUnfoldingInfo, @@ -287,6 +291,7 @@ data IdInfo -- - Bit 0 (1): OneShotInfo -- - Bit 1 (1): CafInfo -- - Bit 2 (1): LevityInfo +-- - Bit 3 (1): CallerCcInfo -- - Bits 16-32(16): Call Arity info -- - Bits 32-48(16): Arity info -- @@ -307,6 +312,10 @@ bitfieldGetLevityInfo :: BitField -> LevityInfo bitfieldGetLevityInfo (BitField bits) = if testBit bits 2 then NeverLevityPolymorphic else NoLevityInfo +bitfieldGetCallerCcInfo :: BitField -> CallerCcInfo +bitfieldGetCallerCcInfo (BitField bits) = + if testBit bits 3 then WantsCallerCc else NoCallerCc + bitfieldGetCallArityInfo :: BitField -> ArityInfo bitfieldGetCallArityInfo bf = fromIntegral $ getBits bitRangeCallArityInfo bf @@ -333,6 +342,12 @@ bitfieldSetLevityInfo info (BitField bits) = NoLevityInfo -> BitField (clearBit bits 2) NeverLevityPolymorphic -> BitField (setBit bits 2) +bitfieldSetCallerCcInfo :: CallerCcInfo -> BitField -> BitField +bitfieldSetCallerCcInfo info (BitField bits) = + case info of + NoCallerCc -> BitField (clearBit bits 3) + WantsCallerCc -> BitField (setBit bits 3) + bitfieldSetCallArityInfo :: ArityInfo -> BitField -> BitField bitfieldSetCallArityInfo info bf = setBits bitRangeCallArityInfo (fromIntegral info) bf @@ -376,6 +391,9 @@ levityInfo = bitfieldGetLevityInfo . bitfield oneShotInfo :: IdInfo -> OneShotInfo oneShotInfo = bitfieldGetOneShotInfo . bitfield +callerCcInfo :: IdInfo -> CallerCcInfo +callerCcInfo = bitfieldGetCallerCcInfo . bitfield + -- | 'Id' arity, as computed by "GHC.Core.Opt.Arity". Specifies how many arguments -- this 'Id' has to be applied to before it doesn any meaningful work. arityInfo :: IdInfo -> ArityInfo @@ -409,6 +427,10 @@ setUnfoldingInfo info uf -- seqUnfolding uf `seq` info { unfoldingInfo = uf } +setCallerCcInfo :: IdInfo -> CallerCcInfo -> IdInfo +setCallerCcInfo info cc = + info { bitfield = bitfieldSetCallerCcInfo cc (bitfield info) } + setArityInfo :: IdInfo -> ArityInfo -> IdInfo setArityInfo info ar = info { bitfield = bitfieldSetArityInfo ar (bitfield info) } @@ -453,6 +475,7 @@ vanillaIdInfo bitfieldSetCallArityInfo unknownArity $ bitfieldSetOneShotInfo NoOneShotInfo $ bitfieldSetLevityInfo NoLevityInfo $ + bitfieldSetCallerCcInfo NoCallerCc $ emptyBitField, lfInfo = Nothing } @@ -462,6 +485,9 @@ noCafIdInfo :: IdInfo noCafIdInfo = vanillaIdInfo `setCafInfo` NoCafRefs -- Used for built-in type Ids in GHC.Types.Id.Make. +-- | Whether an 'Id' was marked with a @CALLER_CC@ pragma. +data CallerCcInfo = WantsCallerCc | NoCallerCc + {- ************************************************************************ * * ===================================== compiler/ghc.cabal.in ===================================== @@ -433,6 +433,7 @@ Library GHC.Core.Opt.Simplify.Monad GHC.Core.Opt.Simplify.Utils GHC.Core.Opt.Simplify + GHC.Core.AddCallerCcs GHC.Stg.Pipeline GHC.Stg.Stats GHC.Stg.CSE View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e6c0d6b04f10c861066954fb3b2421f1d881720d -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e6c0d6b04f10c861066954fb3b2421f1d881720d You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 01:40:03 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 13 Aug 2020 21:40:03 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 3 commits: Make IOEnv monad one-shot (#18202) Message-ID: <5f35eb7312f9e_80b3f8486b5b7c080874c0@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - d0418d8d by Ben Gamari at 2020-08-13T21:39:59-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 4f867bd4 by Ben Gamari at 2020-08-13T21:40:00-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - 4 changed files: - compiler/GHC/Data/IOEnv.hs - llvm-targets - testsuite/mk/test.mk - utils/llvm-targets/gen-data-layout.sh Changes: ===================================== compiler/GHC/Data/IOEnv.hs ===================================== @@ -1,6 +1,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DerivingVia #-} +{-# LANGUAGE PatternSynonyms #-} -- -- (c) The University of Glasgow 2002-2006 -- @@ -48,16 +49,25 @@ import Control.Monad.Trans.Reader import Control.Monad.Catch (MonadCatch, MonadMask, MonadThrow) import GHC.Utils.Monad import Control.Applicative (Alternative(..)) +import GHC.Exts( oneShot ) ---------------------------------------------------------------------- -- Defining the monad type ---------------------------------------------------------------------- -newtype IOEnv env a = IOEnv (env -> IO a) +newtype IOEnv env a = IOEnv' (env -> IO a) deriving (Functor) deriving (MonadThrow, MonadCatch, MonadMask, MonadIO) via (ReaderT env IO) +-- See Note [The one-shot state monad trick] in GHC.Utils.Monad +pattern IOEnv :: forall env a. (env -> IO a) -> IOEnv env a +pattern IOEnv m <- IOEnv' m + where + IOEnv m = IOEnv' (oneShot m) + +{-# COMPLETE IOEnv #-} + unIOEnv :: IOEnv env a -> (env -> IO a) unIOEnv (IOEnv m) = m ===================================== llvm-targets ===================================== @@ -24,6 +24,9 @@ ,("i386-unknown-linux-gnu", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("i386-unknown-linux-musl", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("i386-unknown-linux", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux-gnu", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux-musl", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("x86_64-unknown-linux-gnu", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ,("x86_64-unknown-linux-musl", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ,("x86_64-unknown-linux", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ===================================== testsuite/mk/test.mk ===================================== @@ -60,7 +60,7 @@ TEST_HC_OPTS += -Werror=compat # removing this line. TEST_HC_OPTS += -dno-debug-output -TEST_HC_OPTS_INTERACTIVE = $(TEST_HC_OPTS) --interactive -v0 -ignore-dot-ghci -fno-ghci-history +RTS --io-manager=native -RTS +TEST_HC_OPTS_INTERACTIVE = $(TEST_HC_OPTS) --interactive -v0 -ignore-dot-ghci -fno-ghci-history RUNTEST_OPTS = ===================================== utils/llvm-targets/gen-data-layout.sh ===================================== @@ -59,6 +59,9 @@ TARGETS=( "i386-unknown-linux-gnu" "i386-unknown-linux-musl" "i386-unknown-linux" + "i686-unknown-linux-gnu" + "i686-unknown-linux-musl" + "i686-unknown-linux" "x86_64-unknown-linux-gnu" "x86_64-unknown-linux-musl" "x86_64-unknown-linux" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/349e7c4765d0d3f9f2127dd533d38fda6cf7dc60...4f867bd487f18575fa3ee892696c2355795ef66e -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/349e7c4765d0d3f9f2127dd533d38fda6cf7dc60...4f867bd487f18575fa3ee892696c2355795ef66e You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 08:10:16 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 14 Aug 2020 04:10:16 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 2 commits: testsuite: Drop --io-manager flag from testsuite configuration Message-ID: <5f3646e871885_80b3f8486b5b7c08112995@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 91bcdfcb by Ben Gamari at 2020-08-14T04:10:13-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 93531ecb by Ben Gamari at 2020-08-14T04:10:13-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - 3 changed files: - llvm-targets - testsuite/mk/test.mk - utils/llvm-targets/gen-data-layout.sh Changes: ===================================== llvm-targets ===================================== @@ -24,6 +24,9 @@ ,("i386-unknown-linux-gnu", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("i386-unknown-linux-musl", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("i386-unknown-linux", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux-gnu", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux-musl", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("x86_64-unknown-linux-gnu", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ,("x86_64-unknown-linux-musl", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ,("x86_64-unknown-linux", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ===================================== testsuite/mk/test.mk ===================================== @@ -60,7 +60,7 @@ TEST_HC_OPTS += -Werror=compat # removing this line. TEST_HC_OPTS += -dno-debug-output -TEST_HC_OPTS_INTERACTIVE = $(TEST_HC_OPTS) --interactive -v0 -ignore-dot-ghci -fno-ghci-history +RTS --io-manager=native -RTS +TEST_HC_OPTS_INTERACTIVE = $(TEST_HC_OPTS) --interactive -v0 -ignore-dot-ghci -fno-ghci-history RUNTEST_OPTS = ===================================== utils/llvm-targets/gen-data-layout.sh ===================================== @@ -59,6 +59,9 @@ TARGETS=( "i386-unknown-linux-gnu" "i386-unknown-linux-musl" "i386-unknown-linux" + "i686-unknown-linux-gnu" + "i686-unknown-linux-musl" + "i686-unknown-linux" "x86_64-unknown-linux-gnu" "x86_64-unknown-linux-musl" "x86_64-unknown-linux" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4f867bd487f18575fa3ee892696c2355795ef66e...93531ecb3c8e811c364e12992ad6b8aadeb860da -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4f867bd487f18575fa3ee892696c2355795ef66e...93531ecb3c8e811c364e12992ad6b8aadeb860da You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 10:00:48 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Fri, 14 Aug 2020 06:00:48 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] Cache only CostCentres during ProfInfo decoding Message-ID: <5f3660d0e00ed_80b3f84865febec81274b0@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: 607d60a8 by Sven Tennie at 2020-08-14T11:58:03+02:00 Cache only CostCentres during ProfInfo decoding Looks like caches for CostCentreStacks and IndexTables are not needed. - - - - - 1 changed file: - libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc Changes: ===================================== libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc ===================================== @@ -40,19 +40,14 @@ type AddressSet = IntSet type AddressMap = IntMap data Cache = Cache { - ccCache :: AddressMap CostCentre, --- TODO: Remove ccsCache? Looks like it's not needed anymore due to loop breakers - ccsCache :: AddressMap CostCentreStack, --- TODO: Remove indexTableCache? Looks like it's not needed anymore due to loop breakers - indexTableCache :: AddressMap IndexTable + ccCache :: AddressMap CostCentre } type DecoderMonad a = StateT Cache IO a peekStgTSOProfInfo :: Ptr a -> IO (Maybe StgTSOProfInfo) peekStgTSOProfInfo tsoPtr = do - print $ "peekStgTSOProfInfo - tsoPtr : " ++ show tsoPtr cccs_ptr <- peekByteOff tsoPtr cccsOffset - cccs' <- evalStateT (peekCostCentreStack IntSet.empty cccs_ptr) $ Cache IntMap.empty IntMap.empty IntMap.empty + cccs' <- evalStateT (peekCostCentreStack IntSet.empty cccs_ptr) $ Cache IntMap.empty return $ Just StgTSOProfInfo { cccs = cccs' @@ -65,50 +60,38 @@ peekCostCentreStack :: AddressSet -> Ptr costCentreStack -> DecoderMonad (Maybe peekCostCentreStack _ ptr | ptr == nullPtr = return Nothing peekCostCentreStack loopBreakers ptr | IntSet.member (ptrToInt ptr) loopBreakers = return Nothing peekCostCentreStack loopBreakers ptr = do - cache <- get - case IntMap.lookup ptrAsInt (ccsCache cache) of - found@(Just _) -> do - liftIO $ print $ "CCS Cache hit : " ++ show ptr - return found - Nothing -> do - liftIO $ print $ "peekCostCentreStack - ptr : " ++ show ptr - ccs_ccsID' <- liftIO $ (#peek struct CostCentreStack_, ccsID) ptr - ccs_cc_ptr <- liftIO $ (#peek struct CostCentreStack_, cc) ptr - ccs_cc' <- peekCostCentre ccs_cc_ptr - ccs_prevStack_ptr <- liftIO $ (#peek struct CostCentreStack_, prevStack) ptr - let loopBreakers' = (IntSet.insert ptrAsInt loopBreakers) - ccs_prevStack' <- peekCostCentreStack loopBreakers' ccs_prevStack_ptr - ccs_indexTable_ptr <- liftIO $ (#peek struct CostCentreStack_, indexTable) ptr - ccs_indexTable' <- peekIndexTable loopBreakers' ccs_indexTable_ptr - ccs_root_ptr <- liftIO $ (#peek struct CostCentreStack_, root) ptr - ccs_root' <- peekCostCentreStack loopBreakers' ccs_root_ptr - ccs_depth' <- liftIO $ (#peek struct CostCentreStack_, depth) ptr - ccs_scc_count' <- liftIO $ (#peek struct CostCentreStack_, scc_count) ptr - ccs_selected' <- liftIO $ (#peek struct CostCentreStack_, selected) ptr - ccs_time_ticks' <- liftIO $ (#peek struct CostCentreStack_, time_ticks) ptr - ccs_mem_alloc' <- liftIO $ (#peek struct CostCentreStack_, mem_alloc) ptr - ccs_inherited_alloc' <- liftIO $ (#peek struct CostCentreStack_, inherited_alloc) ptr - ccs_inherited_ticks' <- liftIO $ (#peek struct CostCentreStack_, inherited_ticks) ptr - - let result = CostCentreStack { - ccs_ccsID = ccs_ccsID', - ccs_cc = ccs_cc', - ccs_prevStack = ccs_prevStack', - ccs_indexTable = ccs_indexTable', - ccs_root = ccs_root', - ccs_depth = ccs_depth', - ccs_scc_count = ccs_scc_count', - ccs_selected = ccs_selected', - ccs_time_ticks = ccs_time_ticks', - ccs_mem_alloc = ccs_mem_alloc', - ccs_inherited_alloc = ccs_inherited_alloc', - ccs_inherited_ticks = ccs_inherited_ticks' - } - - let updatedCCSCache = IntMap.insert ptrAsInt result (ccsCache cache) - put $ cache { ccsCache = updatedCCSCache } - - return $ Just result + ccs_ccsID' <- liftIO $ (#peek struct CostCentreStack_, ccsID) ptr + ccs_cc_ptr <- liftIO $ (#peek struct CostCentreStack_, cc) ptr + ccs_cc' <- peekCostCentre ccs_cc_ptr + ccs_prevStack_ptr <- liftIO $ (#peek struct CostCentreStack_, prevStack) ptr + let loopBreakers' = (IntSet.insert ptrAsInt loopBreakers) + ccs_prevStack' <- peekCostCentreStack loopBreakers' ccs_prevStack_ptr + ccs_indexTable_ptr <- liftIO $ (#peek struct CostCentreStack_, indexTable) ptr + ccs_indexTable' <- peekIndexTable loopBreakers' ccs_indexTable_ptr + ccs_root_ptr <- liftIO $ (#peek struct CostCentreStack_, root) ptr + ccs_root' <- peekCostCentreStack loopBreakers' ccs_root_ptr + ccs_depth' <- liftIO $ (#peek struct CostCentreStack_, depth) ptr + ccs_scc_count' <- liftIO $ (#peek struct CostCentreStack_, scc_count) ptr + ccs_selected' <- liftIO $ (#peek struct CostCentreStack_, selected) ptr + ccs_time_ticks' <- liftIO $ (#peek struct CostCentreStack_, time_ticks) ptr + ccs_mem_alloc' <- liftIO $ (#peek struct CostCentreStack_, mem_alloc) ptr + ccs_inherited_alloc' <- liftIO $ (#peek struct CostCentreStack_, inherited_alloc) ptr + ccs_inherited_ticks' <- liftIO $ (#peek struct CostCentreStack_, inherited_ticks) ptr + + return $ Just CostCentreStack { + ccs_ccsID = ccs_ccsID', + ccs_cc = ccs_cc', + ccs_prevStack = ccs_prevStack', + ccs_indexTable = ccs_indexTable', + ccs_root = ccs_root', + ccs_depth = ccs_depth', + ccs_scc_count = ccs_scc_count', + ccs_selected = ccs_selected', + ccs_time_ticks = ccs_time_ticks', + ccs_mem_alloc = ccs_mem_alloc', + ccs_inherited_alloc = ccs_inherited_alloc', + ccs_inherited_ticks = ccs_inherited_ticks' + } where ptrAsInt = ptrToInt ptr @@ -116,9 +99,7 @@ peekCostCentre :: Ptr costCentre -> DecoderMonad CostCentre peekCostCentre ptr = do cache <- get case IntMap.lookup ptrAsInt (ccCache cache) of - (Just a) -> do - liftIO $ print $ "CC Cache hit : " ++ show ptr - return a + (Just a) -> return a Nothing -> do cc_ccID' <- liftIO $ (#peek struct CostCentre_, ccID) ptr cc_label_ptr <- liftIO $ (#peek struct CostCentre_, label) ptr @@ -161,31 +142,20 @@ peekCostCentre ptr = do peekIndexTable :: AddressSet -> Ptr indexTable -> DecoderMonad (Maybe IndexTable) peekIndexTable _ ptr | ptr == nullPtr = return Nothing peekIndexTable loopBreakers ptr = do - cache <- get - case IntMap.lookup ptrAsInt (indexTableCache cache) of - found@(Just _) -> do - liftIO $ print $ "IndexTable Cache hit : " ++ show ptr - return found - Nothing -> do - it_cc_ptr <- liftIO $ (#peek struct IndexTable_, cc) ptr - it_cc' <- peekCostCentre it_cc_ptr - it_ccs_ptr <- liftIO $ (#peek struct IndexTable_, ccs) ptr - it_ccs' <- peekCostCentreStack loopBreakers it_ccs_ptr - it_next_ptr <- liftIO $ (#peek struct IndexTable_, next) ptr - it_next' <- peekIndexTable loopBreakers it_next_ptr - it_back_edge' <- liftIO $ (#peek struct IndexTable_, back_edge) ptr - - let result = IndexTable { - it_cc = it_cc', - it_ccs = it_ccs', - it_next = it_next', - it_back_edge = it_back_edge' - } - - let updatedIndexTableCache = IntMap.insert ptrAsInt result (indexTableCache cache) - put $ cache { indexTableCache = updatedIndexTableCache } - - return $ Just result + it_cc_ptr <- liftIO $ (#peek struct IndexTable_, cc) ptr + it_cc' <- peekCostCentre it_cc_ptr + it_ccs_ptr <- liftIO $ (#peek struct IndexTable_, ccs) ptr + it_ccs' <- peekCostCentreStack loopBreakers it_ccs_ptr + it_next_ptr <- liftIO $ (#peek struct IndexTable_, next) ptr + it_next' <- peekIndexTable loopBreakers it_next_ptr + it_back_edge' <- liftIO $ (#peek struct IndexTable_, back_edge) ptr + + return $ Just IndexTable { + it_cc = it_cc', + it_ccs = it_ccs', + it_next = it_next', + it_back_edge = it_back_edge' + } where ptrAsInt = ptrToInt ptr View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/607d60a88f4b214ff2125819eefd7e552ac39fde -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/607d60a88f4b214ff2125819eefd7e552ac39fde You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 12:05:53 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Fri, 14 Aug 2020 08:05:53 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] Fix warning Message-ID: <5f367e2156aaa_80b1075951c814145@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: 16dec2b6 by Sven Tennie at 2020-08-14T14:05:33+02:00 Fix warning - - - - - 1 changed file: - libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc Changes: ===================================== libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc ===================================== @@ -156,8 +156,6 @@ peekIndexTable loopBreakers ptr = do it_next = it_next', it_back_edge = it_back_edge' } - where - ptrAsInt = ptrToInt ptr #else import Prelude View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/16dec2b634dcbe2254559a2f3e167ba5ac0acee8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/16dec2b634dcbe2254559a2f3e167ba5ac0acee8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 12:36:29 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Fri, 14 Aug 2020 08:36:29 -0400 Subject: [Git][ghc/ghc][wip/T18323] 45 commits: hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. Message-ID: <5f36854dedb17_80b1075951c8144422@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18323 at Glasgow Haskell Compiler / GHC Commits: 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 780bbd78 by Simon Peyton Jones at 2020-08-14T13:36:07+01:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 30 changed files: - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/997c5ab975254481d30a9c46ab7c011bd857c2c9...780bbd78010173090d7ff49b410041a16bc65470 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/997c5ab975254481d30a9c46ab7c011bd857c2c9...780bbd78010173090d7ff49b410041a16bc65470 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 13:16:16 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Fri, 14 Aug 2020 09:16:16 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] 50 commits: ApiAnnotations; tweaks for ghc-exactprint update Message-ID: <5f368ea03d02a_80b40e7e1081465d7@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 10e5305c by Matthew Pickering at 2020-08-14T14:49:44+02:00 rts: Implement ghc-debug API (#18405) There are four components to this patch which make it possible to implement `ghc-debug`. 1. Add four new functions to the RtsAPI. * rts_pause and rts_unpause allow an external process to completely pause and unpause the RTS. * rts_listThreads and rts_listMiscRoots are used to find the current roots of the garbage collector. These changes also mean that `Task.h` is exposed to the user. 2. Generalise the `ghc-heap` API so that raw `Word`s can be returned rather than actual objects. This is necessary when trying to decode closures on an external process because the pointers in such closures are correct for the internal rather than external process. If you used the previous API then you would get a segfault as the garbage collector would try to traverse into these nonsensical branches. ``` -- before getClosureData :: a -> IO Closure -- after getClosureDataX :: (forall c . c -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) ``` For the normal case `b` is instantiated to `Box`, which contains a pointer to a heap object. ``` data Box = Box a -- GenClosure Box ``` For `ghc-debug` we instead just take the word of the address as we have to explicitly interpret it on the external process. ``` GenClosure Word ``` 3. Support for decoding `TSO` and `STACK` closures is partially implemented. There is still quite a bit of work to do to finish both but these at least allow us to make some more progress. 4. findPtr is generalised to take a callback argument. This means that its result can be communicated to the debugger rather than just printing out the result. The debugger has a function which invokes `findPtr` and passes a callback which sends the result over a socket. Co-authored-by: Ben Gamari <ben at smart-cactus.org> - - - - - 9c7b81fd by Sven Tennie at 2020-08-14T14:49:44+02:00 Decode more StgTSO and StgStack fields (#18405) Use hsc2hs to get an understandable and stable mapping from the C structs to Haskell. It's important to keep StgTSO and StgStack decoding downwards compatible. This is especially needed for hadrian/ghci. - - - - - dfc95d97 by Sven Tennie at 2020-08-14T14:49:44+02:00 Add test for StgTSO decoding (#18405) This makes sure ghc-heap decodes StgTSO and StgStack correctly. To assert - otherwise dynamic - properties, a new, non-running TSO is created in create_tso() (create_tso.c). size is renamed to stack_size to use a dedicated type. size was already defined as a HalfWord in GenClosure, which is only equivalent to Word32 on 64bit architectures. - - - - - 23af866a by Sven Tennie at 2020-08-14T14:49:44+02:00 Add documentation to ghc-debug functions (#18405) - - - - - a542b674 by Sven Tennie at 2020-08-14T14:49:44+02:00 Adjust type of getClosureX to type of getClosureDataX (#18405) After a rebase the compiler complained: libraries/ghc-heap/GHC/Exts/Heap.hs:89:23: error: • Couldn't match type: a -> IO (Ptr StgInfoTable, [Word], [b]) with: forall c. c -> IO (Ptr StgInfoTable, [Word], [b]) Expected: (forall c. c -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) Actual: (a -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) • In the expression: getClosureX In an equation for ‘getClosureDataX’: getClosureDataX = getClosureX In the instance declaration for ‘HasHeapRep a’ • Relevant bindings include getClosureDataX :: (forall c. c -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) (bound at libraries/ghc-heap/GHC/Exts/Heap.hs:89:5) | 89 | getClosureDataX = getClosureX | ^^^^^^^^^^^ ) - - - - - 0fa19e9f by Sven Tennie at 2020-08-14T14:49:44+02:00 Add test for rts_pause and rts_unpause (#18405) - - - - - 180f96a3 by Sven Tennie at 2020-08-14T14:49:44+02:00 Add test list_threads_and_misc_roots (#18405) It uses rts_listThreads() and rts_listMiscRoots(). - - - - - 225568db by Sven Tennie at 2020-08-14T14:49:44+02:00 Introduce rts_isPaused() (#18405) Some operations are only save when the RTS is paused. This predicate helps to make such checks. - - - - - d9c29efc by Sven Tennie at 2020-08-14T14:49:44+02:00 Decode CostCentreStacks, CostCentres and InfoTables (#18405) - - - - - 06224b19 by Sven Tennie at 2020-08-14T14:49:44+02:00 Use cache and loop breakers for CostCentre, CostCentreStack and IndexTable decoding (#18405) - - - - - 577b7c05 by Sven Tennie at 2020-08-14T14:49:44+02:00 Cleanup - - - - - af7737d1 by Sven Tennie at 2020-08-14T14:49:44+02:00 Query caches once, not twice - - - - - d1ecaae8 by Sven Tennie at 2020-08-14T14:49:44+02:00 Fix Haddock for EndTSOQueue - - - - - 43f493de by Sven Tennie at 2020-08-14T14:49:44+02:00 Run prof_info test only in prof_ways (#18405) That's the required way for collecting PROFILING data (e.g. CostCentres). - - - - - 4d136da2 by Sven Tennie at 2020-08-14T14:49:44+02:00 Skip WIP test (Red on CI) - - - - - f02527ce by Sven Tennie at 2020-08-14T14:49:44+02:00 Add missing module to ghc-heap.cabal - - - - - ffe2690d by Sven Tennie at 2020-08-14T14:49:44+02:00 Rearrange #ifdef with GHC version This prevents some "unused" warnings. - - - - - 578d15be by Sven Tennie at 2020-08-14T14:49:44+02:00 Fix cpp redefinition warnings With --Werror this made the build fail. - - - - - e453c951 by Sven Tennie at 2020-08-14T14:49:44+02:00 Add dummy import for PeekProfInfo_ProfilingEnabled for non-profiled builds This circumvents #15197. Otherwise PeekProfInfo_ProfilingEnabled wouldn't be available for make-based builds. - - - - - 4cfa7bb7 by Sven Tennie at 2020-08-14T14:49:44+02:00 Add assertions to prof_info test (#18405) - - - - - ab52f87b by Sven Tennie at 2020-08-14T14:49:44+02:00 Fix types in tests Use `Ptr ()` instead of `Word` to communicate that addresses/pointers are meant. - - - - - a67ed8c7 by Sven Tennie at 2020-08-14T14:49:44+02:00 Cleanup - - - - - c94f2904 by Sven Tennie at 2020-08-14T14:49:44+02:00 Introduce LiftedClosure This is a representation for closures that do not have a represantation in the Haskell language. I.e. things like TSOs. - - - - - 657c5bea by Sven Tennie at 2020-08-14T14:49:44+02:00 Fix prof_info test Line number of self defined cost centre changed. - - - - - da30f660 by Sven Tennie at 2020-08-14T14:49:44+02:00 Expect stack_marking starting from GHC 8.10 This field was introduced with GHC 8.10. - - - - - a07ff7de by Sven Tennie at 2020-08-14T14:49:44+02:00 Add WhatNext, WhyBlocked and TsoFlags Additionally extract TestUtils with common test functions. - - - - - 2e90f9d9 by Sven Tennie at 2020-08-14T14:49:44+02:00 Parse TSO flags - - - - - 125e4098 by Sven Tennie at 2020-08-14T14:49:44+02:00 Cache only CostCentres during ProfInfo decoding Looks like caches for CostCentreStacks and IndexTables are not needed. - - - - - d5dba4a3 by Sven Tennie at 2020-08-14T14:49:44+02:00 Fix warning - - - - - 30 changed files: - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/ByteCode/Types.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - compiler/GHC/CmmToAsm/CPrim.hs - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Format.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/16dec2b634dcbe2254559a2f3e167ba5ac0acee8...d5dba4a3223f7a1aafaa9deb8cc0bea87172aa31 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/16dec2b634dcbe2254559a2f3e167ba5ac0acee8...d5dba4a3223f7a1aafaa9deb8cc0bea87172aa31 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 14:00:31 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 14 Aug 2020 10:00:31 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 2 commits: testsuite: Drop --io-manager flag from testsuite configuration Message-ID: <5f3698ff8c62c_80b3f84693c1eb4815407a@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 789951d3 by Ben Gamari at 2020-08-14T10:00:28-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - e340997e by Ben Gamari at 2020-08-14T10:00:28-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - 3 changed files: - llvm-targets - testsuite/mk/test.mk - utils/llvm-targets/gen-data-layout.sh Changes: ===================================== llvm-targets ===================================== @@ -24,6 +24,9 @@ ,("i386-unknown-linux-gnu", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("i386-unknown-linux-musl", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("i386-unknown-linux", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux-gnu", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux-musl", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("x86_64-unknown-linux-gnu", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ,("x86_64-unknown-linux-musl", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ,("x86_64-unknown-linux", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ===================================== testsuite/mk/test.mk ===================================== @@ -60,7 +60,7 @@ TEST_HC_OPTS += -Werror=compat # removing this line. TEST_HC_OPTS += -dno-debug-output -TEST_HC_OPTS_INTERACTIVE = $(TEST_HC_OPTS) --interactive -v0 -ignore-dot-ghci -fno-ghci-history +RTS --io-manager=native -RTS +TEST_HC_OPTS_INTERACTIVE = $(TEST_HC_OPTS) --interactive -v0 -ignore-dot-ghci -fno-ghci-history RUNTEST_OPTS = ===================================== utils/llvm-targets/gen-data-layout.sh ===================================== @@ -59,6 +59,9 @@ TARGETS=( "i386-unknown-linux-gnu" "i386-unknown-linux-musl" "i386-unknown-linux" + "i686-unknown-linux-gnu" + "i686-unknown-linux-musl" + "i686-unknown-linux" "x86_64-unknown-linux-gnu" "x86_64-unknown-linux-musl" "x86_64-unknown-linux" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/93531ecb3c8e811c364e12992ad6b8aadeb860da...e340997e91828df27af37667f4f8fcbcd4b65e32 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/93531ecb3c8e811c364e12992ad6b8aadeb860da...e340997e91828df27af37667f4f8fcbcd4b65e32 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 19:50:39 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 14 Aug 2020 15:50:39 -0400 Subject: [Git][ghc/ghc][master] testsuite: Drop --io-manager flag from testsuite configuration Message-ID: <5f36eb0fdbf60_80b3f84871687308198321@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 1 changed file: - testsuite/mk/test.mk Changes: ===================================== testsuite/mk/test.mk ===================================== @@ -60,7 +60,7 @@ TEST_HC_OPTS += -Werror=compat # removing this line. TEST_HC_OPTS += -dno-debug-output -TEST_HC_OPTS_INTERACTIVE = $(TEST_HC_OPTS) --interactive -v0 -ignore-dot-ghci -fno-ghci-history +RTS --io-manager=native -RTS +TEST_HC_OPTS_INTERACTIVE = $(TEST_HC_OPTS) --interactive -v0 -ignore-dot-ghci -fno-ghci-history RUNTEST_OPTS = View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9f66fdf69b7bcdacbfc46e636668ad0fe509b1b6 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9f66fdf69b7bcdacbfc46e636668ad0fe509b1b6 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 14 19:51:16 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 14 Aug 2020 15:51:16 -0400 Subject: [Git][ghc/ghc][master] llvm-targets: Add i686 targets Message-ID: <5f36eb341dd97_80b3f848716873082011a8@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - 2 changed files: - llvm-targets - utils/llvm-targets/gen-data-layout.sh Changes: ===================================== llvm-targets ===================================== @@ -24,6 +24,9 @@ ,("i386-unknown-linux-gnu", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("i386-unknown-linux-musl", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("i386-unknown-linux", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux-gnu", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux-musl", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("x86_64-unknown-linux-gnu", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ,("x86_64-unknown-linux-musl", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ,("x86_64-unknown-linux", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ===================================== utils/llvm-targets/gen-data-layout.sh ===================================== @@ -59,6 +59,9 @@ TARGETS=( "i386-unknown-linux-gnu" "i386-unknown-linux-musl" "i386-unknown-linux" + "i686-unknown-linux-gnu" + "i686-unknown-linux-musl" + "i686-unknown-linux" "x86_64-unknown-linux-gnu" "x86_64-unknown-linux-musl" "x86_64-unknown-linux" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/55fd1dc55990623dcf3b2e6143e766242315d757 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/55fd1dc55990623dcf3b2e6143e766242315d757 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 15 09:55:58 2020 From: gitlab at gitlab.haskell.org (Peter Trommler) Date: Sat, 15 Aug 2020 05:55:58 -0400 Subject: [Git][ghc/ghc][wip/cross-ppr-floats] 141 commits: Revert "AArch32 symbols only on aarch32." Message-ID: <5f37b12ea5bc_80b3f8468e8ce94822698f@gitlab.haskell.org.mail> Peter Trommler pushed to branch wip/cross-ppr-floats at Glasgow Haskell Compiler / GHC Commits: 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - a938802b by Peter Trommler at 2020-08-15T05:55:54-04:00 PPC and X86: Portable printing of IEEE floats GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness. This was brought up in #18431 by @hsyl20. - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/test-metrics.sh - CODEOWNERS - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Graph.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Monad.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/180a446b920bb8d0a2999d52f1fbff8068d4722c...a938802b22922ab3bc66218b73a25775a8734fb9 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/180a446b920bb8d0a2999d52f1fbff8068d4722c...a938802b22922ab3bc66218b73a25775a8734fb9 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 15 12:37:48 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Sat, 15 Aug 2020 08:37:48 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] END_TSO_QUEUE is not a closure type on it's own Message-ID: <5f37d71ca25aa_80b40e7e1082351b6@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: 89178bf2 by Sven Tennie at 2020-08-15T14:37:33+02:00 END_TSO_QUEUE is not a closure type on it's own Indeed it's a CONSTR_NOCAF. - - - - - 5 changed files: - libraries/ghc-heap/GHC/Exts/Heap.hs - libraries/ghc-heap/GHC/Exts/Heap/Closures.hs - − libraries/ghc-heap/cbits/utils.c - libraries/ghc-heap/ghc-heap.cabal.in - libraries/ghc-heap/tests/tso_and_stack_closures.hs Changes: ===================================== libraries/ghc-heap/GHC/Exts/Heap.hs ===================================== @@ -92,8 +92,6 @@ import Foreign #include "ghcconfig.h" -foreign import ccall "isEndTsoQueue" isEndTsoQueue_c :: Addr# -> Bool - -- | Some closures (e.g.TSOs) don't have corresponding types to represent them in Haskell. -- So when we have a pointer to such closure that we want to inspect, we `unsafeCoerce` it -- into the following `LiftedClosure` lifted type (could be any lifted type) so that the @@ -355,30 +353,26 @@ getClosureX get_closure_raw x = do allocaArray (length wds) (\ptr -> do pokeArray ptr wds --- TODO: Does this work? I.e. do we emit EndTSOQueues? - if isEndTsoQueue_c (unpackPtr ptr) then - pure $ EndTSOQueue { info = itbl } - else do - fields <- FFIClosures.peekTSOFields peekStgTSOProfInfo ptr - - pure $ TSOClosure - { info = itbl - , _link = (pts !! 0) - , global_link = (pts !! 1) - , tsoStack = (pts !! 2) - , trec = (pts !! 3) - , blocked_exceptions = (pts !! 4) - , bq = (pts !! 5) - , what_next = FFIClosures.tso_what_next fields - , why_blocked = FFIClosures.tso_why_blocked fields - , flags = FFIClosures.tso_flags fields - , threadId = FFIClosures.tso_threadId fields - , saved_errno = FFIClosures.tso_saved_errno fields - , tso_dirty = FFIClosures.tso_dirty fields - , alloc_limit = FFIClosures.tso_alloc_limit fields - , tot_stack_size = FFIClosures.tso_tot_stack_size fields - , prof = FFIClosures.tso_prof fields - } + + fields <- FFIClosures.peekTSOFields peekStgTSOProfInfo ptr + pure $ TSOClosure + { info = itbl + , _link = (pts !! 0) + , global_link = (pts !! 1) + , tsoStack = (pts !! 2) + , trec = (pts !! 3) + , blocked_exceptions = (pts !! 4) + , bq = (pts !! 5) + , what_next = FFIClosures.tso_what_next fields + , why_blocked = FFIClosures.tso_why_blocked fields + , flags = FFIClosures.tso_flags fields + , threadId = FFIClosures.tso_threadId fields + , saved_errno = FFIClosures.tso_saved_errno fields + , tso_dirty = FFIClosures.tso_dirty fields + , alloc_limit = FFIClosures.tso_alloc_limit fields + , tot_stack_size = FFIClosures.tso_tot_stack_size fields + , prof = FFIClosures.tso_prof fields + } ) STACK -> do unless (length pts == 1) $ ===================================== libraries/ghc-heap/GHC/Exts/Heap/Closures.hs ===================================== @@ -296,10 +296,6 @@ data GenClosure b , tot_stack_size :: Word32 , prof :: Maybe StgTSOProfInfo } - -- | Marker for the end of TSO queues - -- Technically it has the same structure as an StgTSO, but most data isn't initialized. - | EndTSOQueue - { info :: !StgInfoTable } -- Representation of StgStack: The 'tsoStack' of a 'TSOClosure'. | StackClosure { info :: !StgInfoTable ===================================== libraries/ghc-heap/cbits/utils.c deleted ===================================== @@ -1,8 +0,0 @@ -#include -#include "Rts.h" - -bool isEndTsoQueue(StgTSO* tso){ - errorBelch("tso: %p", tso); - errorBelch("END_TSO_QUEUE: %p", END_TSO_QUEUE); - return tso == END_TSO_QUEUE; -} ===================================== libraries/ghc-heap/ghc-heap.cabal.in ===================================== @@ -30,7 +30,6 @@ library ghc-options: -Wall cmm-sources: cbits/HeapPrim.cmm - c-sources: cbits/utils.c default-extensions: NoImplicitPrelude ===================================== libraries/ghc-heap/tests/tso_and_stack_closures.hs ===================================== @@ -26,6 +26,7 @@ main = do let !_linkBox = _link tso _linkClosure <- getBoxedClosureData _linkBox assertEqual (name _linkClosure) "END_TSO_QUEUE" + assertEqual (getClosureType _linkClosure) CONSTR_NOCAF let !global_linkBox = global_link tso globalLinkClosure <- getBoxedClosureData global_linkBox View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/89178bf2199243f357a40b2b4ce6e597af0ff7cf -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/89178bf2199243f357a40b2b4ce6e597af0ff7cf You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 15 13:16:15 2020 From: gitlab at gitlab.haskell.org (Peter Trommler) Date: Sat, 15 Aug 2020 09:16:15 -0400 Subject: [Git][ghc/ghc][wip/cross-ppr-floats] Fix typo Message-ID: <5f37e01f23882_80b3f8486298278823682a@gitlab.haskell.org.mail> Peter Trommler pushed to branch wip/cross-ppr-floats at Glasgow Haskell Compiler / GHC Commits: d914ea7a by Peter Trommler at 2020-08-15T09:16:14-04:00 Fix typo - - - - - 1 changed file: - compiler/GHC/CmmToAsm/Ppr.hs Changes: ===================================== compiler/GHC/CmmToAsm/Ppr.hs ===================================== @@ -46,7 +46,7 @@ import GHC.Word -- ToDo: this code is currently shared between SPARC and LLVM. -- Similar functions for (single precision) floats are --- present in the SPARC backen only. We need to fix both +-- present in the SPARC backend only. We need to fix both -- LLVM and SPARC. castDoubleToWord8Array :: STUArray s Int Double -> ST s (STUArray s Int Word8) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d914ea7ab6d4ab3e26b31e558156bd6aec268a90 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d914ea7ab6d4ab3e26b31e558156bd6aec268a90 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 15 13:47:07 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Sat, 15 Aug 2020 09:47:07 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] Delete unused function Message-ID: <5f37e75bc4360_80b3f8486298278824069@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: 09c4be79 by Sven Tennie at 2020-08-15T15:46:59+02:00 Delete unused function - - - - - 1 changed file: - libraries/ghc-heap/GHC/Exts/Heap.hs Changes: ===================================== libraries/ghc-heap/GHC/Exts/Heap.hs ===================================== @@ -401,6 +401,3 @@ getClosureX get_closure_raw x = do -- | Like 'getClosureDataX', but taking a 'Box', so it is easier to work with. getBoxedClosureData :: Box -> IO Closure getBoxedClosureData (Box a) = getClosureData a - -unpackPtr :: Ptr a -> Addr# -unpackPtr (Ptr addr) = addr View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/09c4be79f581c9505af7272966a41b586ad741d7 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/09c4be79f581c9505af7272966a41b586ad741d7 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 15 16:20:06 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sat, 15 Aug 2020 12:20:06 -0400 Subject: [Git][ghc/ghc][wip/backports] 2 commits: gitlab-ci: Use MR base commit as performance baseline Message-ID: <5f380b36ec4ad_80b1075951c82495e5@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: ce32390c by Ben Gamari at 2020-08-15T12:19:32-04:00 gitlab-ci: Use MR base commit as performance baseline (cherry picked from commit 4b91e5edf64363eff7d087731c2806464033447c) Metric Decrease: T13056 T18304 T1969 T9233 - - - - - 1c7ebdcb by Ben Gamari at 2020-08-15T12:19:55-04:00 Accept performance shifts - - - - - 5 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - hadrian/src/Settings/Builders/RunTest.hs - libraries/bytestring - testsuite/mk/test.mk Changes: ===================================== .gitlab-ci.yml ===================================== @@ -26,12 +26,28 @@ stages: - testing # head.hackage correctness and compiler performance testing - deploy # push documentation +# Note [The CI Story] +# ~~~~~~~~~~~~~~~~~~~ +# +# There are two different types of pipelines: +# +# - marge-bot merges to `master`. Here we perform an exhaustive validation +# across all of the platforms which we support. In addition, we push +# performance metric notes upstream, providing a persistent record of the +# performance characteristics of the compiler. +# +# - merge requests. Here we perform a slightly less exhaustive battery of +# testing. Namely we omit some configurations (e.g. the unregisterised job). +# These use the merge request's base commit for performance metric +# comparisons. +# + workflow: - # N.B.Don't run on wip/ branches, instead on run on merge requests. + # N.B. Don't run on wip/ branches, instead on run on merge requests. rules: - if: $CI_MERGE_REQUEST_ID - if: $CI_COMMIT_TAG - - if: '$CI_COMMIT_BRANCH == "master"' + - if: '$CI_COMMIT_BRANCH == "wip/marge_bot_batch_merge_job"' - if: '$CI_COMMIT_BRANCH =~ /ghc-[0.9]+\.[0-9]+/' - if: '$CI_PIPELINE_SOURCE == "web"' ===================================== .gitlab/ci.sh ===================================== @@ -363,6 +363,13 @@ function push_perf_notes() { "$TOP/.gitlab/test-metrics.sh" push } +# Figure out which commit should be used by the testsuite driver as a +# performance baseline. See Note [The CI Story]. +function determine_metric_baseline() { + export PERF_BASELINE_COMMIT="$(git merge-base $CI_MERGE_REQUEST_TARGET_BRANCH_NAME HEAD)" + info "Using $PERF_BASELINE_COMMIT for performance metric baseline..." +} + function test_make() { run "$MAKE" test_bindist TEST_PREP=YES run "$MAKE" V=0 test \ ===================================== hadrian/src/Settings/Builders/RunTest.hs ===================================== @@ -78,6 +78,7 @@ runTestBuilderArgs = builder RunTest ? do <*> (maybe False (=="YES") <$> lookupEnv "OS") (testEnv, testMetricsFile) <- expr . liftIO $ (,) <$> lookupEnv "TEST_ENV" <*> lookupEnv "METRICS_FILE" + perfBaseline <- expr . liftIO $ lookupEnv "PERF_BASELINE_COMMIT" threads <- shakeThreads <$> expr getShakeOptions os <- getTestSetting TestHostOS @@ -141,6 +142,9 @@ runTestBuilderArgs = builder RunTest ? do , arg "--config", arg $ "timeout_prog=" ++ show (top -/- timeoutProg) , arg "--config", arg $ "stats_files_dir=" ++ statsFilesDir , arg $ "--threads=" ++ show threads + , case perfBaseline of + Just commit | not (null commit) -> arg ("--perf-baseline=" ++ show commit) + _ -> mempty , emitWhenSet testEnv $ \env -> arg ("--test-env=" ++ show env) , emitWhenSet testMetricsFile $ \file -> arg ("--metrics-file=" ++ file) , getTestArgs -- User-provided arguments from command line. ===================================== libraries/bytestring ===================================== @@ -1 +1 @@ -Subproject commit e6cb01e2ec0bfdd19298418c85f220925a9fa307 +Subproject commit 95fe6bdf13c9cc86c1c880164f7844d61d989574 ===================================== testsuite/mk/test.mk ===================================== @@ -226,6 +226,10 @@ ifneq "$(VERBOSE)" "" RUNTEST_OPTS += --verbose=$(VERBOSE) endif +ifneq "$(PERF_TEST_BASELINE_COMMIT)" "" +RUNTEST_OPTS += --perf-baseline=$(PERF_TEST_BASELINE_COMMIT) +endif + ifeq "$(SKIP_PERF_TESTS)" "YES" RUNTEST_OPTS += --skip-perf-tests endif View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/682cf7c6e266b7fcadc1e8ddf0b23991a008e39f...1c7ebdcb450750589445932205da91b82207c64a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/682cf7c6e266b7fcadc1e8ddf0b23991a008e39f...1c7ebdcb450750589445932205da91b82207c64a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 15 16:49:50 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sat, 15 Aug 2020 12:49:50 -0400 Subject: [Git][ghc/ghc][wip/backports] Deleted 1 commit: Accept performance shifts Message-ID: <5f38122eb7e46_80b40e7e1082503c1@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC WARNING: The push did not contain any new commits, but force pushed to delete the commits and changes below. Deleted commits: 1c7ebdcb by Ben Gamari at 2020-08-15T12:19:55-04:00 Accept performance shifts - - - - - 1 changed file: - libraries/bytestring Changes: ===================================== libraries/bytestring ===================================== @@ -1 +1 @@ -Subproject commit e6cb01e2ec0bfdd19298418c85f220925a9fa307 +Subproject commit 95fe6bdf13c9cc86c1c880164f7844d61d989574 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1c7ebdcb450750589445932205da91b82207c64a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1c7ebdcb450750589445932205da91b82207c64a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 16 05:13:58 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 16 Aug 2020 01:13:58 -0400 Subject: [Git][ghc/ghc][ghc-9.0] 58 commits: Fix dead link to haskell prime discussion Message-ID: <5f38c096c62e7_80b3f84865febec8268856@gitlab.haskell.org.mail> Ben Gamari pushed to branch ghc-9.0 at Glasgow Haskell Compiler / GHC Commits: 7cf007cc by David Binder at 2020-08-13T18:22:38-04:00 Fix dead link to haskell prime discussion - - - - - 205f168c by BinderDavid at 2020-08-13T18:22:38-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 29794212 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Remove length field from FastString - - - - - f8804cd8 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 5acdf506 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - a9b46ec3 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - fcb9e94d by Daniel Gröber at 2020-08-13T18:22:38-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 44b28e97 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - f0fe989d by Daniel Gröber at 2020-08-13T18:22:38-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 59cd5cd4 by Daniel Gröber at 2020-08-13T18:22:38-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - 0f66e49e by Ben Gamari at 2020-08-13T18:22:38-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 3ecac53c by Andreas Klebinger at 2020-08-13T18:22:39-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - dbf77b79 by Sylvain Henry at 2020-08-13T18:22:39-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - 4e22de2a by Sylvain Henry at 2020-08-13T18:22:39-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - e27698ce by Sylvain Henry at 2020-08-13T18:22:39-04:00 Remove unused sGhcWithNativeCodeGen - - - - - 666acbd4 by Sylvain Henry at 2020-08-13T18:22:39-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - ce5408c0 by Sylvain Henry at 2020-08-13T18:22:39-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - 9751d499 by Tamar Christina at 2020-08-13T18:22:39-04:00 winio: restore console cp on exit (cherry picked from commit cdd0ff16f20ce920c74f9128a1067cbe1bd378c2) - - - - - 5438dcec by Tamar Christina at 2020-08-13T18:22:39-04:00 winio: change memory allocation strategy and fix double free errors. (cherry picked from commit c1f4f81d3a439cd1a8128e4ab11c7caac7cc0ad8) - - - - - 5544d17a by Stefan Schulze Frielinghaus at 2020-08-13T18:22:39-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 (cherry picked from commit fc0f6fbcd95f2dc69a8efabbee2d8a485c34cc47) - - - - - e66e281d by Matthias Andreas Benkard at 2020-08-13T18:22:39-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. (cherry picked from commit a7c4439a407ad85b76aab9301fda61e7c10183ff) - - - - - 986063cf by Ben Gamari at 2020-08-13T18:22:39-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. (cherry picked from commit da7269a4472856ba701d956a247599f721e9915e) - - - - - b2f8c6a7 by Ben Gamari at 2020-08-13T18:22:39-04:00 testsuite: Update win32 output for parseTree (cherry picked from commit f153a1d0a3351ad4d94cef4cef8e63bab5b47008) - - - - - 83a0649c by Ben Gamari at 2020-08-13T18:22:39-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. (cherry picked from commit e91672f0b7185bbafbe8ed1f2ae2cb775111f950) - - - - - 97ac5b2a by Ben Gamari at 2020-08-13T18:22:39-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. (cherry picked from commit 9cbfe0868418a531da0872b0c477a15aa67f8861) - - - - - 8f1154d3 by Tamar Christina at 2020-08-13T18:22:39-04:00 winio: remove dead argument to stg_newIOPortzh (cherry picked from commit 8236925fc8cc2e6e3fed61a0676fa65270a4a538) - - - - - 39c6fbae by Tamar Christina at 2020-08-13T18:22:39-04:00 winio: fix detection of tty terminals (cherry picked from commit ce0a1d678fbc8efa5fd384fd0227b7b3dc97cadd) - - - - - b784c75a by Tamar Christina at 2020-08-13T18:22:40-04:00 winio: update codeowners (cherry picked from commit 52685cf7c077c51e3719e3c4dd5ca8257a99c4ea) - - - - - 8388567e by Ben Gamari at 2020-08-13T18:22:40-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. (cherry picked from commit aa054d32a8ff69c334293a0d6c9d11b83a236a96) - - - - - 353521ab by Simon Peyton Jones at 2020-08-13T18:22:40-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 (cherry picked from commit 3d345c9680ab3d766ef43dd8389ccc1eaeca066c) - - - - - c0a3283a by Ben Gamari at 2020-08-13T18:22:40-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. (cherry picked from commit 57aca6bba1c000f8542ce94e8b724b0334ff96d4) - - - - - e14ee26b by Ben Gamari at 2020-08-13T18:22:40-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. (cherry picked from commit 0a815cea9fa11ce6ef22aec3525dd7a0df541daf) - - - - - cf9a6c17 by Simon Peyton Jones at 2020-08-13T18:22:40-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 (cherry picked from commit 0bd60059b0edfee9e8f66c6817257bbb946656cd) - - - - - 6ba13945 by Sergei Trofimovich at 2020-08-13T18:22:40-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> (cherry picked from commit 39c89862161bf488a6aca9372cbb67690f436ce7) - - - - - 59226e20 by Felix Wiemuth at 2020-08-13T18:22:40-04:00 Fix typo (cherry picked from commit b9a880fce484d0a87bb794b9d2d8a73e54819011) - - - - - 9166d4d6 by Simon Peyton Jones at 2020-08-13T18:22:40-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 (cherry picked from commit bbc5191640761ca9773abc898c077363b7beb4e7) - - - - - 505a9d68 by John Ericson at 2020-08-13T18:22:40-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. (cherry picked from commit 6c68a84254d70280e2dc73485f361787a3503850) - - - - - bd365c1d by Simon Peyton Jones at 2020-08-13T18:22:40-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d (cherry picked from commit 9f71f69714255165d0fdc2790a588487ff9439dc) - - - - - 6653e139 by Sylvain Henry at 2020-08-13T18:22:40-04:00 Fix minimal imports dump for boot files (fix #18497) (cherry picked from commit 7c274cd530cc42a26028050b75d56b3437e06ec1) - - - - - 2c86713b by Leon Schoorl at 2020-08-13T18:22:41-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 (cherry picked from commit f2d1accf67cb6e1dab6b2c78fef4b64526c31a4a) - - - - - 36d8cd6f by Niklas Hambüchen at 2020-08-13T18:22:41-04:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. (cherry picked from commit 947206f478d4eef641dfc58cb4c13471a23260c3) - - - - - 01534bf9 by Krzysztof Gogolewski at 2020-08-13T18:22:48-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. (cherry picked from commit 5e12cd1733b581f48a5873b12971b6974778eabb) - - - - - 20a45d0c by Ben Gamari at 2020-08-13T18:22:48-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. (cherry picked from commit 2bff2f87e43985e02bdde8c6fa39279df86cb617) - - - - - 2911d640 by Ben Gamari at 2020-08-13T18:22:48-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. (cherry picked from commit 53ce0db5a06598c88c6b8cb32043b878e7083dd4) - - - - - cb3e202a by Ryan Scott at 2020-08-13T18:22:48-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. (cherry picked from commit fbcb886d503dd7aaebc4c40e59615068b3fd0bd7) - - - - - bd506bd6 by Vladislav Zavialov at 2020-08-13T18:22:48-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. (cherry picked from commit aee45d9ea8c6cf4ebad4d5c732748923c7865cbe) - - - - - bc186461 by Takenobu Tani at 2020-08-13T18:22:48-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] (cherry picked from commit 9570c21295a2b4a1d1e40939869124f0b9b9bf91) - - - - - 77653d5c by Ben Gamari at 2020-08-13T18:22:48-04:00 cmm: Clean up Notes a bit (cherry picked from commit 5f03606319f745b10e9918c76a47426b293f0bf9) - - - - - 47de152f by Ben Gamari at 2020-08-13T18:22:48-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. (cherry picked from commit 6402c1240d5bd768b8fe8b4368413932bedbe107) - - - - - e64ac078 by Ben Gamari at 2020-08-13T18:22:48-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. (cherry picked from commit 15b36de030ecdd60897bc7a6a02bdeabd0825be4) - - - - - 24c230ce by Ben Gamari at 2020-08-13T18:22:48-04:00 testsuite: Add test for #18527 (cherry picked from commit 3847ae0ccf67bddf73304a39f5320c3ba285aa48) - - - - - ee2ed876 by Ben Gamari at 2020-08-13T18:22:48-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. (cherry picked from commit dd51d53be42114c105b5ab15fcbdb387526b1c17) - - - - - b4c33250 by Alan Zimmerman at 2020-08-13T18:22:48-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. (cherry picked from commit e4f1b73ad9f292a6bbeb21fee44b0ba1a7f3c33b) - - - - - cb39cfdc by Ben Gamari at 2020-08-13T18:22:48-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. (cherry picked from commit 8a665db6174eaedbbae925c0ccb4c22b3f29bcaf) - - - - - b221b571 by Alex Biehl at 2020-08-13T18:22:48-04:00 Hardcode RTS includes to cope with unregistered builds (cherry picked from commit ef2ae81a394df573510b12b7e11bba0c931249d8) - - - - - c15fb71b by Ben Gamari at 2020-08-13T18:22:48-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". (cherry picked from commit f1088b3f31ceddf918a319c97557fb1f08a9a387) - - - - - 3bda53ad by Ben Gamari at 2020-08-13T20:44:39-04:00 testsuite: Allow baseline commit to be set explicitly (cherry picked from commit bbde6ea0ce80a154735f1302251d073a56606c20) - - - - - ce32390c by Ben Gamari at 2020-08-15T12:19:32-04:00 gitlab-ci: Use MR base commit as performance baseline (cherry picked from commit 4b91e5edf64363eff7d087731c2806464033447c) Metric Decrease: T13056 T18304 T1969 T9233 - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/test-metrics.sh - CODEOWNERS - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/Opt/OccurAnal.hs - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/SetLevels.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Monad.hs - compiler/GHC/Core/Opt/Simplify/Utils.hs - compiler/GHC/Core/SimpleOpt.hs - compiler/GHC/Data/FastString.hs - compiler/GHC/Data/StringBuffer.hs - + compiler/GHC/Driver/Backend.hs - compiler/GHC/Driver/CodeOutput.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Make.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Parser.y The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/3745bdb69b19e43da5b6a26597e1a95d17cca929...ce32390cd4221e2721c18f89bd6d08e3b8b884dc -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/3745bdb69b19e43da5b6a26597e1a95d17cca929...ce32390cd4221e2721c18f89bd6d08e3b8b884dc You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 16 14:12:59 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 16 Aug 2020 10:12:59 -0400 Subject: [Git][ghc/ghc][wip/T18560] testsuite: Only run llvm ways if llc is available Message-ID: <5f393eeb17ad9_80b3f8486b5b7c082796ae@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18560 at Glasgow Haskell Compiler / GHC Commits: 6a32f121 by Ben Gamari at 2020-08-16T10:12:50-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 4 changed files: - hadrian/src/Settings/Builders/RunTest.hs - testsuite/config/ghc - testsuite/driver/testglobals.py - testsuite/mk/test.mk Changes: ===================================== hadrian/src/Settings/Builders/RunTest.hs ===================================== @@ -70,7 +70,6 @@ runTestBuilderArgs = builder RunTest ? do withSMP <- getBooleanSetting TestGhcWithSMP debugged <- getBooleanSetting TestGhcDebugged keepFiles <- expr (testKeepFiles <$> userSetting defaultTestArgs) - withLlvm <- expr (not . null <$> settingsFileSetting SettingsFileSetting_LlcCommand) accept <- expr (testAccept <$> userSetting defaultTestArgs) (acceptPlatform, acceptOS) <- expr . liftIO $ @@ -125,8 +124,6 @@ runTestBuilderArgs = builder RunTest ? do , arg "-e", arg $ asBool "config.have_profiling=" (hasLibWay profiling) , arg "-e", arg $ asBool "config.have_fast_bignum=" (bignumBackend /= "native" && not bignumCheck) , arg "-e", arg $ asBool "ghc_with_smp=" withSMP - , arg "-e", arg $ asBool "ghc_with_llvm=" withLlvm - , arg "-e", arg $ "config.ghc_dynamic_by_default=" ++ show hasDynamicByDefault , arg "-e", arg $ "config.ghc_dynamic=" ++ show hasDynamic ===================================== testsuite/config/ghc ===================================== @@ -64,10 +64,6 @@ else: if (config.have_profiling and ghc_with_threaded_rts): config.run_ways.append('profthreaded') -if (ghc_with_llvm and not config.unregisterised): - config.compile_ways.append('optllvm') - config.run_ways.append('optllvm') - # WinIO I/O manager for Windows if windows: winio_ways = ['winio', 'winio_threaded'] @@ -195,6 +191,17 @@ def get_compiler_info(): config.have_ncg = compilerInfoDict.get("Have native code generator", "NO") == "YES" + # Detect whether an LLVM toolhain is available + llc_path = compilerInfoDict.get("LLVM llc command") + config.have_llvm = shutil.which(llc_path) is not None + if config.have_llvm: + config.compile_ways.append('optllvm') + config.run_ways.append('optllvm') + elif config.unregisterised: + print("Unregisterised build; skipping LLVM ways...") + else: + print("Failed to find `llc` command; skipping LLVM ways...") + # Whether GHC itself was built using the LLVM backend. We need to know this # since some tests in ext-interp fail when stage2 ghc is built using # LLVM. See #16087. ===================================== testsuite/driver/testglobals.py ===================================== @@ -115,6 +115,9 @@ class TestConfig: self.way_flags = {} # type: Dict[WayName, List[str]] self.way_rts_flags = {} # type: Dict[WayName, List[str]] + # Do we have a functional LLVM toolchain? + self.have_llvm = False + # Do we have vanilla libraries? self.have_vanilla = False ===================================== testsuite/mk/test.mk ===================================== @@ -194,18 +194,6 @@ else RUNTEST_OPTS += -e ghc_with_smp=False endif -# Does the LLVM backend work? -ifeq "$(LLC)" "" -RUNTEST_OPTS += -e ghc_with_llvm=False -else ifeq "$(TargetARCH_CPP)" "powerpc" -RUNTEST_OPTS += -e ghc_with_llvm=False -else ifneq "$(LLC)" "llc" -# If we have a real detected value for LLVM, then it really ought to work -RUNTEST_OPTS += -e ghc_with_llvm=True -else -RUNTEST_OPTS += -e ghc_with_llvm=False -endif - ifeq "$(WINDOWS)" "YES" RUNTEST_OPTS += -e windows=True else View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6a32f1212f49c3fed0da82b264864eb4f9756bdd -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6a32f1212f49c3fed0da82b264864eb4f9756bdd You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 16 14:13:25 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 16 Aug 2020 10:13:25 -0400 Subject: [Git][ghc/ghc][wip/T18560] testsuite: Only run llvm ways if llc is available Message-ID: <5f393f0575ff8_80b3f8495bc8b0482801f1@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18560 at Glasgow Haskell Compiler / GHC Commits: 27022c70 by Ben Gamari at 2020-08-16T10:13:19-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 4 changed files: - hadrian/src/Settings/Builders/RunTest.hs - testsuite/config/ghc - testsuite/driver/testglobals.py - testsuite/mk/test.mk Changes: ===================================== hadrian/src/Settings/Builders/RunTest.hs ===================================== @@ -70,7 +70,6 @@ runTestBuilderArgs = builder RunTest ? do withSMP <- getBooleanSetting TestGhcWithSMP debugged <- getBooleanSetting TestGhcDebugged keepFiles <- expr (testKeepFiles <$> userSetting defaultTestArgs) - withLlvm <- expr (not . null <$> settingsFileSetting SettingsFileSetting_LlcCommand) accept <- expr (testAccept <$> userSetting defaultTestArgs) (acceptPlatform, acceptOS) <- expr . liftIO $ @@ -125,8 +124,6 @@ runTestBuilderArgs = builder RunTest ? do , arg "-e", arg $ asBool "config.have_profiling=" (hasLibWay profiling) , arg "-e", arg $ asBool "config.have_fast_bignum=" (bignumBackend /= "native" && not bignumCheck) , arg "-e", arg $ asBool "ghc_with_smp=" withSMP - , arg "-e", arg $ asBool "ghc_with_llvm=" withLlvm - , arg "-e", arg $ "config.ghc_dynamic_by_default=" ++ show hasDynamicByDefault , arg "-e", arg $ "config.ghc_dynamic=" ++ show hasDynamic ===================================== testsuite/config/ghc ===================================== @@ -64,10 +64,6 @@ else: if (config.have_profiling and ghc_with_threaded_rts): config.run_ways.append('profthreaded') -if (ghc_with_llvm and not config.unregisterised): - config.compile_ways.append('optllvm') - config.run_ways.append('optllvm') - # WinIO I/O manager for Windows if windows: winio_ways = ['winio', 'winio_threaded'] @@ -195,6 +191,17 @@ def get_compiler_info(): config.have_ncg = compilerInfoDict.get("Have native code generator", "NO") == "YES" + # Detect whether an LLVM toolhain is available + llc_path = compilerInfoDict.get("LLVM llc command") + config.have_llvm = shutil.which(llc_path) is not None + if config.unregisterised: + print("Unregisterised build; skipping LLVM ways...") + elif config.have_llvm: + config.compile_ways.append('optllvm') + config.run_ways.append('optllvm') + else: + print("Failed to find `llc` command; skipping LLVM ways...") + # Whether GHC itself was built using the LLVM backend. We need to know this # since some tests in ext-interp fail when stage2 ghc is built using # LLVM. See #16087. ===================================== testsuite/driver/testglobals.py ===================================== @@ -115,6 +115,9 @@ class TestConfig: self.way_flags = {} # type: Dict[WayName, List[str]] self.way_rts_flags = {} # type: Dict[WayName, List[str]] + # Do we have a functional LLVM toolchain? + self.have_llvm = False + # Do we have vanilla libraries? self.have_vanilla = False ===================================== testsuite/mk/test.mk ===================================== @@ -194,18 +194,6 @@ else RUNTEST_OPTS += -e ghc_with_smp=False endif -# Does the LLVM backend work? -ifeq "$(LLC)" "" -RUNTEST_OPTS += -e ghc_with_llvm=False -else ifeq "$(TargetARCH_CPP)" "powerpc" -RUNTEST_OPTS += -e ghc_with_llvm=False -else ifneq "$(LLC)" "llc" -# If we have a real detected value for LLVM, then it really ought to work -RUNTEST_OPTS += -e ghc_with_llvm=True -else -RUNTEST_OPTS += -e ghc_with_llvm=False -endif - ifeq "$(WINDOWS)" "YES" RUNTEST_OPTS += -e windows=True else View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/27022c70a30cfff7a3b17817b1e33ab302cd5ecf -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/27022c70a30cfff7a3b17817b1e33ab302cd5ecf You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 16 14:23:21 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 16 Aug 2020 10:23:21 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18580 Message-ID: <5f39415947933_80b3f8486b5b7c082806dd@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T18580 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18580 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 16 14:30:02 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 16 Aug 2020 10:30:02 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18579 Message-ID: <5f3942ea9c191_80b3f842731681c8290382@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T18579 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18579 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 16 16:18:28 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 16 Aug 2020 12:18:28 -0400 Subject: [Git][ghc/ghc][wip/backports] 2 commits: Allow unsaturated runRW# applications Message-ID: <5f395c54a1a03_80b3f8495bc8b048295730@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: 57fd3ff0 by Ben Gamari at 2020-08-16T12:18:11-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. (cherry picked from commit 2f0bae734e2dc8737fbbb8465de7ded89c1121b6) - - - - - 0af2db18 by Ben Gamari at 2020-08-16T12:18:19-04:00 testsuite: Add test for #18291 (cherry picked from commit 6c7785f8e17a43a2578366134f74fd1989077b73) - - - - - 6 changed files: - compiler/GHC/Core/Lint.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/CoreToStg/Prep.hs - libraries/ghc-prim/GHC/Magic.hs - + testsuite/tests/codeGen/should_compile/T18291.hs - testsuite/tests/codeGen/should_compile/all.T Changes: ===================================== compiler/GHC/Core/Lint.hs ===================================== @@ -729,8 +729,6 @@ lintJoinLams join_arity enforce rhs where go 0 expr = lintCoreExpr expr go n (Lam var body) = lintLambda var $ go (n-1) body - -- N.B. join points can be cast. e.g. we consider ((\x -> ...) `cast` ...) - -- to be a join point at join arity 1. go n expr | Just bndr <- enforce -- Join point with too few RHS lambdas = failWithL $ mkBadJoinArityMsg bndr join_arity n rhs | otherwise -- Future join point, not yet eta-expanded @@ -779,36 +777,26 @@ hurts us here. Note [Linting of runRW#] ~~~~~~~~~~~~~~~~~~~~~~~~ -runRW# has some very peculiar behavior (see Note [runRW magic] in -GHC.CoreToStg.Prep) which CoreLint must accommodate. +runRW# has some very special behavior (see Note [runRW magic] in +GHC.CoreToStg.Prep) which CoreLint must accommodate, by allowing +join points in its argument. For example, this is fine: -As described in Note [Casts and lambdas] in -GHC.Core.Opt.Simplify.Utils, the simplifier pushes casts out of -lambdas. Concretely, the simplifier will transform + join j x = ... + in runRW# (\s. case v of + A -> j 3 + B -> j 4) - runRW# @r @ty (\s -> expr `cast` co) +Usually those calls to the join point 'j' would not be valid tail calls, +because they occur in a function argument. But in the case of runRW# +they are fine, because runRW# (\s.e) behaves operationally just like e. +(runRW# is ultimately inlined in GHC.CoreToStg.Prep.) -into - - runRW# @r @ty ((\s -> expr) `cast` co) - -Consequently we need to handle the case that the continuation is a -cast of a lambda. See Note [Casts and lambdas] in -GHC.Core.Opt.Simplify.Utils. - -In the event that the continuation is headed by a lambda (which -will bind the State# token) we can safely allow calls to join -points since CorePrep is going to apply the continuation to -RealWorld. - -In the case that the continuation is not a lambda we lint the -continuation disallowing join points, to rule out things like, +In the case that the continuation is /not/ a lambda we simply disable this +special behaviour. For example, this is /not/ fine: join j = ... - in runRW# @r @ty ( - let x = jump j - in x - ) + in runRW# @r @ty (jump j) + ************************************************************************ @@ -929,10 +917,6 @@ lintCoreExpr e@(App _ _) ; (fun_ty2, ue2) <- lintCoreArg fun_pair1 arg_ty2 -- See Note [Linting of runRW#] ; let lintRunRWCont :: CoreArg -> LintM (LintedType, UsageEnv) - lintRunRWCont (Cast expr co) = do - (ty, ue) <- lintRunRWCont expr - new_ty <- lintCastExpr expr ty co - return (new_ty, ue) lintRunRWCont expr@(Lam _ _) = do lintJoinLams 1 (Just fun) expr lintRunRWCont other = markAllJoinsBad $ lintCoreExpr other @@ -941,10 +925,6 @@ lintCoreExpr e@(App _ _) ; app_ty <- lintValApp arg3 fun_ty2 arg3_ty ue2 ue3 ; lintCoreArgs app_ty rest } - | Var fun <- fun - , fun `hasKey` runRWKey - = failWithL (text "Invalid runRW# application") - | otherwise = do { pair <- lintCoreFun fun (length args) ; lintCoreArgs pair args } ===================================== compiler/GHC/Core/Opt/Simplify.hs ===================================== @@ -1970,8 +1970,10 @@ rebuildCall env info (ApplyToTy { sc_arg_ty = arg_ty, sc_hole_ty = hole_ty, sc_c = rebuildCall env (addTyArgTo info arg_ty hole_ty) cont ---------- The runRW# rule. Do this after absorbing all arguments ------ +-- See Note [Simplification of runRW#] in GHC.CoreToSTG.Prep. +-- -- runRW# :: forall (r :: RuntimeRep) (o :: TYPE r). (State# RealWorld -> o) -> o --- K[ runRW# rr ty body ] --> runRW rr' ty' (\s. K[ body s ]) +-- K[ runRW# rr ty body ] --> runRW rr' ty' (\s. K[ body s ]) rebuildCall env (ArgInfo { ai_fun = fun_id, ai_args = rev_args }) (ApplyToVal { sc_arg = arg, sc_env = arg_se , sc_cont = cont, sc_hole_ty = fun_ty }) ===================================== compiler/GHC/CoreToStg/Prep.hs ===================================== @@ -721,18 +721,6 @@ instance Outputable ArgInfo where ppr (CpeCast co) = text "cast" <+> ppr co ppr (CpeTick tick) = text "tick" <+> ppr tick -{- - Note [runRW arg] -~~~~~~~~~~~~~~~~~~~ -If we got, say - runRW# (case bot of {}) -which happened in #11291, we do /not/ want to turn it into - (case bot of {}) realWorldPrimId# -because that gives a panic in CoreToStg.myCollectArgs, which expects -only variables in function position. But if we are sure to make -runRW# strict (which we do in GHC.Types.Id.Make), this can't happen --} - cpeApp :: CorePrepEnv -> CoreExpr -> UniqSM (Floats, CpeRhs) -- May return a CpeRhs because of saturating primops cpeApp top_env expr @@ -798,10 +786,6 @@ cpeApp top_env expr _ -> cpe_app env arg (CpeApp (Var realWorldPrimId) : rest) (n-1) -- TODO: What about casts? - cpe_app _env (Var f) args n - | f `hasKey` runRWKey - = pprPanic "cpe_app(runRW#)" (ppr args $$ ppr n) - cpe_app env (Var v) args depth = do { v1 <- fiddleCCall v ; let e2 = lookupCorePrepEnv env v1 @@ -923,34 +907,96 @@ optimization (right before lowering to STG, in CorePrep), we can ensure that no further floating will occur. This allows us to safely inline things like @runST@, which are otherwise needlessly expensive (see #10678 and #5916). -'runRW' is defined (for historical reasons) in GHC.Magic, with a NOINLINE -pragma. It is levity-polymorphic. +'runRW' has a variety of quirks: + + * 'runRW' is known-key with a NOINLINE definition in + GHC.Magic. This definition is used in cases where runRW is curried. + + * In addition to its normal Haskell definition in GHC.Magic, we give it + a special late inlining here in CorePrep and GHC.CoreToByteCode, avoiding + the incorrect sharing due to float-out noted above. + + * It is levity-polymorphic: runRW# :: forall (r1 :: RuntimeRep). (o :: TYPE r) => (State# RealWorld -> (# State# RealWorld, o #)) - -> (# State# RealWorld, o #) + -> (# State# RealWorld, o #) + + * It has some special simplification logic to allow unboxing of results when + runRW# appears in a strict context. See Note [Simplification of runRW#] + below. + + * Since its body is inlined, we allow runRW#'s argument to contain jumps to + join points. That is, the following is allowed: + + join j x = ... + in runRW# @_ @_ (\s -> ... jump j 42 ...) + + The Core Linter knows about this. See Note [Linting of runRW#] in + GHC.Core.Lint for details. + + The occurrence analyser and SetLevels also know about this, as described in + Note [Simplification of runRW#]. + +Other relevant Notes: -It's correctness needs no special treatment in GHC except this special inlining -here in CorePrep (and in GHC.CoreToByteCode). + * Note [Simplification of runRW#] below, describing a transformation of runRW + applications in strict contexts performed by the simplifier. + * Note [Linting of runRW#] in GHC.Core.Lint + * Note [runRW arg] below, describing a non-obvious case where the + late-inlining could go wrong. -However, there are a variety of optimisation opportunities that the simplifier -takes advantage of. See Note [Simplification of runRW#]. + + Note [runRW arg] +~~~~~~~~~~~~~~~~~~~ +Consider the Core program (from #11291), + + runRW# (case bot of {}) + +The late inlining logic in cpe_app would transform this into: + + (case bot of {}) realWorldPrimId# + +Which would rise to a panic in CoreToStg.myCollectArgs, which expects only +variables in function position. + +However, as runRW#'s strictness signature captures the fact that it will call +its argument this can't happen: the simplifier will transform the bottoming +application into simply (case bot of {}). + +Note that this reasoning does *not* apply to non-bottoming continuations like: + + hello :: Bool -> Int + hello n = + runRW# ( + case n of + True -> \s -> 23 + _ -> \s -> 10) + +Why? The difference is that (case bot of {}) is considered by okCpeArg to be +trivial, consequently cpeArg (which the catch-all case of cpe_app calls on both +the function and the arguments) will forgo binding it to a variable. By +contrast, in the non-bottoming case of `hello` above the function will be +deemed non-trivial and consequently will be case-bound. Note [Simplification of runRW#] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Consider the program, - case runRW# (\s -> let n = I# 42# in n) of + case runRW# (\s -> I# 42#) of I# n# -> f n# There is no reason why we should allocate an I# constructor given that we -immediately destructure it. To avoid this the simplifier will push strict -contexts into runRW's continuation. That is, it transforms +immediately destructure it. + +To avoid this the simplifier has a special transformation rule, specific to +runRW#, that pushes a strict context into runRW#'s continuation. See the +`runRW#` guard in `GHC.Core.Opt.Simplify.rebuildCall`. That is, it transforms K[ runRW# @r @ty cont ] ~> - runRW# @r @ty K[cont] + runRW# @r @ty (\s -> K[cont s]) This has a few interesting implications. Consider, for instance, this program: @@ -969,15 +1015,29 @@ Performing the transform described above would result in: If runRW# were a "normal" function this call to join point j would not be allowed in its continuation argument. However, since runRW# is inlined (as described in Note [runRW magic] above), such join point occurences are -completely fine. Both occurrence analysis and Core Lint have special treatment -for runRW# applications. See Note [Linting of runRW#] for details on the latter. +completely fine. Both occurrence analysis (see the runRW guard in occAnalApp) +and Core Lint (see the App case of lintCoreExpr) have special treatment for +runRW# applications. See Note [Linting of runRW#] for details on the latter. Moreover, it's helpful to ensure that runRW's continuation isn't floated out -(since doing so would then require a call, whereas we would otherwise end up -with straight-line). Consequently, GHC.Core.Opt.SetLevels.lvlApp has special -treatment for runRW# applications, ensure the arguments are not floated if +For instance, if we have + + runRW# (\s -> do_something) + +where do_something contains only top-level free variables, we may be tempted to +float the argument to the top-level. However, we must resist this urge as since +doing so would then require that runRW# produce an allocation and call, e.g.: + + let lvl = \s -> do_somethign + in + ....(runRW# lvl).... + +whereas without floating the inlining of the definition of runRW would result +in straight-line code. Consequently, GHC.Core.Opt.SetLevels.lvlApp has special +treatment for runRW# applications, ensure the arguments are not floated as MFEs. + Other considered designs ------------------------ ===================================== libraries/ghc-prim/GHC/Magic.hs ===================================== @@ -122,7 +122,7 @@ oneShot f = f runRW# :: forall (r :: RuntimeRep) (o :: TYPE r). (State# RealWorld -> o) -> o --- See Note [runRW magic] in CorePrep +-- See Note [runRW magic] in GHC.CoreToStg.Prep. {-# NOINLINE runRW# #-} -- runRW# is inlined manually in CorePrep #if !defined(__HADDOCK_VERSION__) runRW# m = m realWorld# ===================================== testsuite/tests/codeGen/should_compile/T18291.hs ===================================== @@ -0,0 +1,7 @@ +{-# LANGUAGE MagicHash #-} +module T18291 where + +import GHC.Magic + +hi :: Int +hi = runRW# $ \_ -> 42 ===================================== testsuite/tests/codeGen/should_compile/all.T ===================================== @@ -91,6 +91,7 @@ test('T17648', normal, makefile_test, []) test('T17904', normal, compile, ['-O']) test('T18227A', normal, compile, ['']) test('T18227B', normal, compile, ['']) +test('T18291', normal, compile, ['-O0']) test('T15570', when(unregisterised(), skip), compile, ['-Wno-overflowed-literals']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ce32390cd4221e2721c18f89bd6d08e3b8b884dc...0af2db189b8d1abf9939d9939da3b53eae287803 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ce32390cd4221e2721c18f89bd6d08e3b8b884dc...0af2db189b8d1abf9939d9939da3b53eae287803 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 16 16:53:32 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Sun, 16 Aug 2020 12:53:32 -0400 Subject: [Git][ghc/ghc][wip/backports] 3 commits: Bump Cabal submodule Message-ID: <5f39648c2a68c_80b1075951c8305534@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: 22602d10 by Ben Gamari at 2020-08-16T12:50:14-04:00 Bump Cabal submodule - - - - - 3df41207 by Ben Gamari at 2020-08-16T12:50:47-04:00 Bump bytestring submodule - - - - - de065343 by Ben Gamari at 2020-08-16T12:52:58-04:00 Bump binary submodule - - - - - 3 changed files: - libraries/Cabal - libraries/binary - libraries/bytestring Changes: ===================================== libraries/Cabal ===================================== @@ -1 +1 @@ -Subproject commit 32dad5c1cf70d65ecb93b0ec214445cf9c9f6615 +Subproject commit 42e18f763b6abc3e5f530e72300428065584ebb3 ===================================== libraries/binary ===================================== @@ -1 +1 @@ -Subproject commit dfaf780596328c9184758452b78288e8f405fcc1 +Subproject commit f9b1c92a2ff34cc3457fa27faf3e16b8203b4b9f ===================================== libraries/bytestring ===================================== @@ -1 +1 @@ -Subproject commit e6cb01e2ec0bfdd19298418c85f220925a9fa307 +Subproject commit e043aacfc4202a59ccae8b8c8cf0e1ad83a3f209 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0af2db189b8d1abf9939d9939da3b53eae287803...de065343bc9bf8ffd01eb88d33880cf18f273b16 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0af2db189b8d1abf9939d9939da3b53eae287803...de065343bc9bf8ffd01eb88d33880cf18f273b16 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 17 05:35:33 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 17 Aug 2020 01:35:33 -0400 Subject: [Git][ghc/ghc][wip/backports] 2 commits: Bump bytestring submodule Message-ID: <5f3a1725d6679_80b3f848716873084074ed@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: e1f5e616 by Ben Gamari at 2020-08-17T01:35:19-04:00 Bump bytestring submodule - - - - - 9e46de48 by Ben Gamari at 2020-08-17T01:35:19-04:00 Bump binary submodule - - - - - 2 changed files: - libraries/binary - libraries/bytestring Changes: ===================================== libraries/binary ===================================== @@ -1 +1 @@ -Subproject commit dfaf780596328c9184758452b78288e8f405fcc1 +Subproject commit f9b1c92a2ff34cc3457fa27faf3e16b8203b4b9f ===================================== libraries/bytestring ===================================== @@ -1 +1 @@ -Subproject commit e6cb01e2ec0bfdd19298418c85f220925a9fa307 +Subproject commit e043aacfc4202a59ccae8b8c8cf0e1ad83a3f209 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/de065343bc9bf8ffd01eb88d33880cf18f273b16...9e46de481cf97f0bfff4294e26115265d7d3ba64 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/de065343bc9bf8ffd01eb88d33880cf18f273b16...9e46de481cf97f0bfff4294e26115265d7d3ba64 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 17 06:10:09 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Mon, 17 Aug 2020 02:10:09 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] Rename boundTaskExiting and getTask (#18405) Message-ID: <5f3a1f4192c79_80b40e7e1084078d4@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: 78c049b6 by Sven Tennie at 2020-08-17T08:09:48+02:00 Rename boundTaskExiting and getTask (#18405) Both are directly related to myTask, which the new names now reflect. - - - - - 6 changed files: - includes/rts/Task.h - rts/RtsAPI.c - rts/Schedule.c - rts/Task.c - rts/Task.h - rts/sm/NonMoving.c Changes: ===================================== includes/rts/Task.h ===================================== @@ -15,9 +15,9 @@ typedef struct Task_ Task; -// Create a new Task for a bound thread. This Task must be released -// by calling boundTaskExiting. The Task is cached in -// thread-local storage and will remain even after boundTaskExiting() +// Create a new Task for a bound thread. This Task must be released +// by calling exitMyTask(). The Task is cached in +// thread-local storage and will remain even after exitMyTask() // has been called; to free the memory, see freeMyTask(). // Task* newBoundTask (void); @@ -25,11 +25,10 @@ Task* newBoundTask (void); // Return the current OS thread's Task, which is created if it doesn't already // exist. After you have finished using RTS APIs, you should call freeMyTask() // to release this thread's Task. -Task* getTask (void); +Task* getMyTask (void); -// The current task is a bound task that is exiting. -// -void boundTaskExiting (Task *task); +// Exit myTask - This is the counterpart of newBoundTask(). +void exitMyTask (void); // Free a Task if one was previously allocated by newBoundTask(). // This is not necessary unless the thread that called newBoundTask() @@ -37,4 +36,3 @@ void boundTaskExiting (Task *task); // functions. // void freeMyTask(void); - ===================================== rts/RtsAPI.c ===================================== @@ -621,21 +621,21 @@ rts_unlock (Capability *cap) task = cap->running_task; ASSERT_FULL_CAPABILITY_INVARIANTS(cap,task); - // Now release the Capability. With the capability released, GC - // may happen. NB. does not try to put the current Task on the + // Now release the Capability. With the capability released, GC + // may happen. NB. does not try to put the current Task on the // worker queue. - // NB. keep cap->lock held while we call boundTaskExiting(). This + // NB. keep cap->lock held while we call exitMyTask(). This // is necessary during shutdown, where we want the invariant that // after shutdownCapability(), all the Tasks associated with the - // Capability have completed their shutdown too. Otherwise we - // could have boundTaskExiting()/workerTaskStop() running at some + // Capability have completed their shutdown too. Otherwise we + // could have exitMyTask()/workerTaskStop() running at some // random point in the future, which causes problems for // freeTaskManager(). ACQUIRE_LOCK(&cap->lock); releaseCapability_(cap,false); // Finally, we can release the Task to the free list. - boundTaskExiting(task); + exitMyTask(); RELEASE_LOCK(&cap->lock); if (task->incall == NULL) { @@ -794,7 +794,7 @@ void rts_done (void) void hs_try_putmvar (/* in */ int capability, /* in */ HsStablePtr mvar) { - Task *task = getTask(); + Task *task = getMyTask(); Capability *cap; Capability *task_old_cap USED_IF_THREADS; ===================================== rts/Schedule.c ===================================== @@ -2082,7 +2082,7 @@ forkProcess(HsStablePtr *entry RELEASE_LOCK(&capabilities[i]->lock); } - boundTaskExiting(task); + exitMyTask(); // just return the pid return pid; @@ -2762,7 +2762,7 @@ exitScheduler (bool wait_foreign USED_IF_THREADS) // debugBelch("n_failed_trygrab_idles = %d, n_idle_caps = %d\n", // n_failed_trygrab_idles, n_idle_caps); - boundTaskExiting(task); + exitMyTask(); } void @@ -2821,7 +2821,7 @@ performGC_(bool force_major) waitForCapability(&cap,task); scheduleDoGC(&cap,task,force_major,false); releaseCapability(cap); - boundTaskExiting(task); + exitMyTask(); } void ===================================== rts/Task.c ===================================== @@ -116,7 +116,7 @@ freeTaskManager (void) return tasksRunning; } -Task* getTask (void) +Task* getMyTask (void) { Task *task; @@ -304,7 +304,7 @@ newBoundTask (void) stg_exit(EXIT_FAILURE); } - task = getTask(); + task = getMyTask(); task->stopped = false; @@ -315,13 +315,12 @@ newBoundTask (void) } void -boundTaskExiting (Task *task) +exitMyTask (void) { + Task* task = myTask(); #if defined(THREADED_RTS) ASSERT(osThreadId() == task->id); #endif - ASSERT(myTask() == task); - endInCall(task); // Set task->stopped, but only if this is the last call (#4850). @@ -522,7 +521,7 @@ void rts_setInCallCapability ( int preferred_capability, int affinity USED_IF_THREADS) { - Task *task = getTask(); + Task *task = getMyTask(); task->preferred_capability = preferred_capability; #if defined(THREADED_RTS) @@ -539,7 +538,7 @@ void rts_pinThreadToNumaNode ( { #if defined(THREADED_RTS) if (RtsFlags.GcFlags.numa) { - Task *task = getTask(); + Task *task = getMyTask(); task->node = capNoToNumaNode(node); if (!DEBUG_IS_ON || !RtsFlags.DebugFlags.numa) { // faking NUMA setThreadNode(numa_map[task->node]); ===================================== rts/Task.h ===================================== @@ -150,7 +150,7 @@ typedef struct Task_ { bool worker; // == true if this is a worker Task bool stopped; // == true between newBoundTask and - // boundTaskExiting, or in a worker Task. + // exitMyTask, or in a worker Task. // So that we can detect when a finalizer illegally calls back into Haskell bool running_finalizers; ===================================== rts/sm/NonMoving.c ===================================== @@ -1215,7 +1215,7 @@ static void nonmovingMark_(MarkQueue *mark_queue, StgWeak **dead_weaks, StgTSO * #if defined(THREADED_RTS) finish: - boundTaskExiting(task); + exitMyTask(); // We are done... mark_thread = 0; View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/78c049b6d52d6d01a6e9184c609a65c1041b8c3b -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/78c049b6d52d6d01a6e9184c609a65c1041b8c3b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 17 13:01:59 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 17 Aug 2020 09:01:59 -0400 Subject: [Git][ghc/ghc][wip/backports] Bump Cabal submodule Message-ID: <5f3a7fc711520_80b3f8495bc8b0484203b4@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: 8b16ddb5 by Ben Gamari at 2020-08-17T09:01:52-04:00 Bump Cabal submodule - - - - - 1 changed file: - libraries/Cabal Changes: ===================================== libraries/Cabal ===================================== @@ -1 +1 @@ -Subproject commit 32dad5c1cf70d65ecb93b0ec214445cf9c9f6615 +Subproject commit 1d886476c443b227bf93eba62781a6cad5012d9e View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8b16ddb52f70a85dd39db1bdf1b9a90fed0460b0 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8b16ddb52f70a85dd39db1bdf1b9a90fed0460b0 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 17 13:21:12 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 17 Aug 2020 09:21:12 -0400 Subject: [Git][ghc/ghc][wip/T18580] 6 commits: Add HomeUnit type Message-ID: <5f3a8448c4b00_80b3f8495bc8b0484244f@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18580 at Glasgow Haskell Compiler / GHC Commits: ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - 6e2ef839 by Ben Gamari at 2020-08-17T09:18:06-04:00 Clean up TBDs in changelog - - - - - f0778044 by Ben Gamari at 2020-08-17T09:21:04-04:00 base: Fail if `timeout` is used when exceptions are masked As pointed out in #18580, `timeout`'s implementation assumes that exceptions will be handled. Document and assert this precondition. Fixes #18580. - - - - - 30 changed files: - compiler/GHC.hs - compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/CoreToStg/Prep.hs - compiler/GHC/Data/IOEnv.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Driver/Finder.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Make.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/HsToCore.hs - compiler/GHC/HsToCore/Monad.hs - compiler/GHC/HsToCore/Usage.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/Iface/Recomp.hs - compiler/GHC/Iface/Recomp/Flags.hs - compiler/GHC/Iface/Rename.hs - compiler/GHC/Iface/Tidy.hs - compiler/GHC/Parser/Lexer.x - compiler/GHC/Rename/Module.hs - compiler/GHC/Rename/Names.hs - compiler/GHC/Runtime/Eval.hs - compiler/GHC/Runtime/Linker.hs - compiler/GHC/SysTools.hs - compiler/GHC/SysTools/ExtraObj.hs - compiler/GHC/Tc/Module.hs - compiler/GHC/Tc/TyCl.hs - compiler/GHC/Tc/Utils/Backpack.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/bde38aa1fe6a72311af4c650ae0608e057dc6750...f07780443c659b979e73f4c704f11daa8f1bf62e -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/bde38aa1fe6a72311af4c650ae0608e057dc6750...f07780443c659b979e73f4c704f11daa8f1bf62e You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 17 14:31:41 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 17 Aug 2020 10:31:41 -0400 Subject: [Git][ghc/ghc][wip/T18580] 2 commits: Clean up TBDs in changelog Message-ID: <5f3a94cdc5d4c_80b3f842731681c844556b@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18580 at Glasgow Haskell Compiler / GHC Commits: f6c37b88 by Ben Gamari at 2020-08-17T10:31:32-04:00 Clean up TBDs in changelog - - - - - 24d197ea by Ben Gamari at 2020-08-17T10:31:36-04:00 base: Fail if `timeout` is used when exceptions are masked As pointed out in #18580, `timeout`'s implementation assumes that exceptions will be handled. Document and assert this precondition. Fixes #18580. - - - - - 3 changed files: - libraries/base/System/Timeout.hs - libraries/base/changelog.md - libraries/template-haskell/changelog.md Changes: ===================================== libraries/base/System/Timeout.hs ===================================== @@ -27,7 +27,8 @@ import Control.Concurrent import Control.Exception (Exception(..), handleJust, bracket, uninterruptibleMask_, asyncExceptionToException, - asyncExceptionFromException) + asyncExceptionFromException, + getMaskingState, MaskingState(..)) import Data.Unique (Unique, newUnique) -- An internal type that is thrown as a dynamic exception to @@ -89,12 +90,16 @@ instance Exception Timeout where -- Note that 'timeout' cancels the computation by throwing it the 'Timeout' -- exception. Consequently blanket exception handlers (e.g. catching -- 'SomeException') within the computation will break the timeout behavior. -timeout :: Int -> IO a -> IO (Maybe a) +-- Moreover, 'timeout' cannot be used when in a context enclosed by +-- by 'Control.Exception.uninterruptibleMask'. +timeout :: HasCallStack => Int -> IO a -> IO (Maybe a) timeout n f | n < 0 = fmap Just f | n == 0 = return Nothing #if !defined(mingw32_HOST_OS) | rtsSupportsBoundThreads = do + checkNonUninterruptibleMask + -- In the threaded RTS, we use the Timer Manager to delay the -- (fairly expensive) 'forkIO' call until the timeout has expired. -- @@ -125,6 +130,7 @@ timeout n f (\_ -> fmap Just f)) #endif | otherwise = do + checkNonUninterruptibleMask pid <- myThreadId ex <- fmap Timeout newUnique handleJust (\e -> if e == ex then Just () else Nothing) @@ -134,3 +140,9 @@ timeout n f (uninterruptibleMask_ . killThread) (\_ -> fmap Just f)) -- #7719 explains why we need uninterruptibleMask_ above. + where + checkNonUninterruptibleMask :: HasCallStack => IO () + checkNonUninterruptibleMask = do + maskingState <- getMaskingState + when (maskingState == Unmasked) $ + error "System.Timeout.timeout called with exceptions uninterruptibly masked" ===================================== libraries/base/changelog.md ===================================== @@ -1,5 +1,11 @@ # Changelog for [`base` package](http://hackage.haskell.org/package/base) +## 4.16.0.0 *TBA* + + * `System.Timeout.timeout` now throws an error if called in a context where + exceptions have been masked since its implementation relies on exceptions to + interrupt its sub-computation (fixes #18580). + ## 4.15.0.0 *TBA* * `openFile` now calls the `open` system call with an `interruptible` FFI @@ -30,7 +36,7 @@ * Add `Ix` instances for tuples of size 6 through 15 -## 4.14.0.0 *TBA* +## 4.14.0.0 *Jan 2020 * Bundled with GHC 8.10.1 * Add a `TestEquality` instance for the `Compose` newtype. @@ -322,7 +328,7 @@ in constant space when applied to lists. (#10830) * `mkFunTy`, `mkAppTy`, and `mkTyConApp` from `Data.Typeable` no longer exist. - This functionality is superseded by the interfaces provided by + This functionality is superceded by the interfaces provided by `Type.Reflection`. * `mkTyCon3` is no longer exported by `Data.Typeable`. This function is ===================================== libraries/template-haskell/changelog.md ===================================== @@ -34,7 +34,9 @@ * The argument to `TExpQ` can now be levity polymorphic. -## 2.16.0.0 *TBA* +## 2.16.0.0 *Jan 2020* + + * Bundled with GHC 8.10.1 * Add support for tuple sections. (#15843) The type signatures of `TupE` and `UnboxedTupE` have changed from `[Exp] -> Exp` to `[Maybe Exp] -> Exp`. @@ -58,6 +60,8 @@ ## 2.15.0.0 *May 2019* + * Bundled with GHC 8.8.1 + * In `Language.Haskell.TH.Syntax`, `DataInstD`, `NewTypeInstD`, `TySynEqn`, and `RuleP` now all have a `Maybe [TyVarBndr]` argument, which contains a list of quantified type variables if an explicit `forall` is present, and @@ -80,6 +84,8 @@ ## 2.14.0.0 *September 2018* + * Bundled with GHC 8.6.1 + * Introduce an `addForeignFilePath` function, as well as a corresponding `qAddForeignFile` class method to `Quasi`. Unlike `addForeignFile`, which takes the contents of the file as an argument, `addForeignFilePath` takes View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f07780443c659b979e73f4c704f11daa8f1bf62e...24d197eac9ee5fb593de1ef7a46ca1bb24362a42 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f07780443c659b979e73f4c704f11daa8f1bf62e...24d197eac9ee5fb593de1ef7a46ca1bb24362a42 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 17 15:17:36 2020 From: gitlab at gitlab.haskell.org (Simon Jakobi) Date: Mon, 17 Aug 2020 11:17:36 -0400 Subject: [Git][ghc/ghc][wip/sjakobi/deprecate-option-v2] 380 commits: DynFlags: store default depth in SDocContext (#17957) Message-ID: <5f3a9f9017630_80b3f848629827884510db@gitlab.haskell.org.mail> Simon Jakobi pushed to branch wip/sjakobi/deprecate-option-v2 at Glasgow Haskell Compiler / GHC Commits: 2af0ec90 by Sylvain Henry at 2020-06-18T23:07:47-04:00 DynFlags: store default depth in SDocContext (#17957) It avoids having to use DynFlags to reach for pprUserLength. - - - - - d4a0be75 by Sylvain Henry at 2020-06-18T23:08:35-04:00 Move tablesNextToCode field into Platform tablesNextToCode is a platform setting and doesn't belong into DynFlags (#17957). Doing this is also a prerequisite to fix #14335 where we deal with two platforms (target and host) that may have different platform settings. - - - - - 809caedf by John Ericson at 2020-06-23T22:47:37-04:00 Switch from HscSource to IsBootInterface for module lookup in GhcMake We look up modules by their name, and not their contents. There is no way to separately reference a signature vs regular module; you get what you get. Only boot files can be referenced indepenently with `import {-# SOURCE #-}`. - - - - - 7750bd45 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Cmm: introduce SAVE_REGS/RESTORE_REGS We don't want to save both Fn and Dn register sets on x86-64 as they are aliased to the same arch register (XMMn). Moreover, when SAVE_STGREGS was used in conjunction with `jump foo [*]` which makes a set of Cmm registers alive so that they cover all arch registers used to pass parameter, we could have Fn, Dn and XMMn alive at the same time. It made the LLVM code generator choke (see #17920). Now `SAVE_REGS/RESTORE_REGS` and `jump foo [*]` use the same set of registers. - - - - - 2636794d by Sylvain Henry at 2020-06-23T22:48:18-04:00 CmmToC: don't add extern decl to parsed Cmm data Previously, if a .cmm file *not in the RTS* contained something like: ```cmm section "rodata" { msg : bits8[] "Test\n"; } ``` It would get compiled by CmmToC into: ```c ERW_(msg); const char msg[] = "Test\012"; ``` and fail with: ``` /tmp/ghc32129_0/ghc_4.hc:5:12: error: error: conflicting types for \u2018msg\u2019 const char msg[] = "Test\012"; ^~~ In file included from /tmp/ghc32129_0/ghc_4.hc:3:0: error: /tmp/ghc32129_0/ghc_4.hc:4:6: error: note: previous declaration of \u2018msg\u2019 was here ERW_(msg); ^ /builds/hsyl20/ghc/_build/install/lib/ghc-8.11.0.20200605/lib/../lib/x86_64-linux-ghc-8.11.0.20200605/rts-1.0/include/Stg.h:253:46: error: note: in definition of macro \u2018ERW_\u2019 #define ERW_(X) extern StgWordArray (X) ^ ``` See the rationale for this on https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/backends/ppr-c#prototypes Now we don't generate these extern declarations (ERW_, etc.) for top-level data. It shouldn't change anything for the RTS (the only place we use .cmm files) as it is already special cased in `GHC.Cmm.CLabel.needsCDecl`. And hand-written Cmm can use explicit extern declarations when needed. Note that it allows `cgrun069` test to pass with CmmToC (cf #15467). - - - - - 5f6a0665 by Sylvain Henry at 2020-06-23T22:48:18-04:00 LLVM: refactor and comment register padding code (#17920) - - - - - cad62ef1 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Add tests for #17920 Metric Decrease: T12150 T12234 - - - - - a2a9006b by Xavier Denis at 2020-06-23T22:48:56-04:00 Fix issue #18262 by zonking constraints after solving Zonk residual constraints in checkForExistence to reveal user type errors. Previously when `:instances` was used with instances that have TypeError constraints the result would look something like: instance [safe] s0 => Err 'A -- Defined at ../Bug2.hs:8:10 whereas after zonking, `:instances` now sees the `TypeError` and properly eliminates the constraint from the results. - - - - - 181516bc by Simon Peyton Jones at 2020-06-23T22:49:33-04:00 Fix a buglet in Simplify.simplCast This bug, revealed by #18347, is just a missing update to sc_hole_ty in simplCast. I'd missed a code path when I made the recentchanges in commit 6d49d5be904c0c01788fa7aae1b112d5b4dfaf1c Author: Simon Peyton Jones <simonpj at microsoft.com> Date: Thu May 21 12:53:35 2020 +0100 Implement cast worker/wrapper properly The fix is very easy. Two other minor changes * Tidy up in SimpleOpt.simple_opt_expr. In fact I think this is an outright bug, introduced in the fix to #18112: we were simplifying the same coercion twice *with the same substitution*, which is just wrong. It'd be a hard bug to trigger, so I just fixed it; less code too. * Better debug printing of ApplyToVal - - - - - 625a7f54 by Simon Peyton Jones at 2020-06-23T22:50:11-04:00 Two small tweaks to Coercion.simplifyArgsWorker These tweaks affect the inner loop of simplifyArgsWorker, which in turn is called from the flattener in Flatten.hs. This is a key perf bottleneck to T9872{a,b,c,d}. These two small changes have a modest but useful benefit. No change in functionality whatsoever. Relates to #18354 - - - - - b5768cce by Sylvain Henry at 2020-06-23T22:50:49-04:00 Don't use timesInt2# with GHC < 8.11 (fix #18358) - - - - - 7ad4085c by Sylvain Henry at 2020-06-23T22:51:27-04:00 Fix invalid printf format - - - - - a1f34d37 by Krzysztof Gogolewski at 2020-06-23T22:52:09-04:00 Add missing entry to freeNamesItem (#18369) - - - - - 03a708ba by Andreas Klebinger at 2020-06-25T03:54:37-04:00 Enable large address space optimization on windows. Starting with Win 8.1/Server 2012 windows no longer preallocates page tables for reserverd memory eagerly, which prevented us from using this approach in the past. We also try to allocate the heap high in the memory space. Hopefully this makes it easier to allocate things in the low 4GB of memory that need to be there. Like jump islands for the linker. - - - - - 7e6d3d09 by Roland Senn at 2020-06-25T03:54:38-04:00 In `:break ident` allow out of scope and nested identifiers (Fix #3000) This patch fixes the bug and implements the feature request of #3000. 1. If `Module` is a real module name and `identifier` a name of a top-level function in `Module` then `:break Module.identifer` works also for an `identifier` that is out of scope. 2. Extend the syntax for `:break identifier` to: :break [ModQual.]topLevelIdent[.nestedIdent]...[.nestedIdent] `ModQual` is optional and is either the effective name of a module or the local alias of a qualified import statement. `topLevelIdent` is the name of a top level function in the module referenced by `ModQual`. `nestedIdent` is optional and the name of a function nested in a let or where clause inside the previously mentioned function `nestedIdent` or `topLevelIdent`. If `ModQual` is a module name, then `topLevelIdent` can be any top level identifier in this module. If `ModQual` is missing or a local alias of a qualified import, then `topLevelIdent` must be in scope. Breakpoints can be set on arbitrarily deeply nested functions, but the whole chain of nested function names must be specified. 3. To support the new functionality rewrite the code to tab complete `:break`. - - - - - 30e42652 by Ben Gamari at 2020-06-25T03:54:39-04:00 make: Respect XELATEX variable Previously we simply ignored the XELATEX variable when building PDF documentation. - - - - - 4acc2934 by Ben Gamari at 2020-06-25T03:54:39-04:00 hadrian/make: Detect makeindex Previously we would simply assume that makeindex was available. Now we correctly detect it in `configure` and respect this conclusion in hadrian and make. - - - - - 0d61f866 by Simon Peyton Jones at 2020-06-25T03:54:40-04:00 Expunge GhcTcId GHC.Hs.Extension had type GhcPs = GhcPass 'Parsed type GhcRn = GhcPass 'Renamed type GhcTc = GhcPass 'Typechecked type GhcTcId = GhcTc The last of these, GhcTcId, is a vestige of the past. This patch expunges it from GHC. - - - - - 8ddbed4a by Adam Wespiser at 2020-06-25T03:54:40-04:00 add examples to Data.Traversable - - - - - 284001d0 by Oleg Grenrus at 2020-06-25T03:54:42-04:00 Export readBinIface_ - - - - - 90f43872 by Zubin Duggal at 2020-06-25T03:54:43-04:00 Export everything from HsToCore. This lets us reuse these functions in haddock, avoiding synchronization bugs. Also fixed some divergences with haddock in that file Updates haddock submodule - - - - - c7dd6da7 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part1) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Hs.* - GHC.Core.* - GHC.Stg.* - GHC.Cmm.* - GHC.Types.* - GHC.Data.* - GHC.Builtin.* - GHC.Parser.* - GHC.Driver.* - GHC top - - - - - 1eb997a8 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part2) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Iface.* - GHC.Llvm.* - GHC.Rename.* - GHC.Tc.* - GHC.HsToCore.* - GHC.StgToCmm.* - GHC.CmmToAsm.* - GHC.Runtime.* - GHC.Unit.* - GHC.Utils.* - GHC.SysTools.* - - - - - 67a86b4d by Oleg Grenrus at 2020-06-25T03:54:46-04:00 Add MonadZip and MonadFix instances for Complex These instances are taken from https://hackage.haskell.org/package/linear-1.21/docs/Linear-Instances.html They are the unique possible, so let they be in `base`. - - - - - c50ef26e by Artem Pelenitsyn at 2020-06-25T03:54:47-04:00 test suite: add reproducer for #17516 - - - - - fe281b27 by Roland Senn at 2020-06-25T03:54:48-04:00 Enable maxBound checks for OverloadedLists (Fixes #18172) Consider the Literal `[256] :: [Data.Word.Word8]` When the `OverloadedLists` extension is not active, then the `ol_ext` field in the `OverLitTc` record that is passed to the function `getIntegralLit` contains the type `Word8`. This is a simple type, and we can use its type constructor immediately for the `warnAboutOverflowedLiterals` function. When the `OverloadedLists` extension is active, then the `ol_ext` field contains the type family `Item [Word8]`. The function `nomaliseType` is used to convert it to the needed type `Word8`. - - - - - a788d4d1 by Ben Gamari at 2020-06-25T03:54:52-04:00 rts/Hash: Simplify freeing of HashListChunks While looking at #18348 I noticed that the treatment of HashLists are a bit more complex than necessary (which lead to some initial confusion on my part). Specifically, we allocate HashLists in chunks. Each chunk allocation makes two allocations: one for the chunk itself and one for a HashListChunk to link together the chunks for the purposes of freeing. Simplify this (and hopefully make the relationship between these clearer) but allocating the HashLists and HashListChunk in a single malloc. This will both make the implementation easier to follow and reduce C heap fragmentation. Note that even after this patch we fail to bound the size of the free HashList pool. However, this is a separate bug. - - - - - d3c2d59b by Sylvain Henry at 2020-06-25T03:54:55-04:00 RTS: avoid overflow on 32-bit arch (#18375) We're now correctly computing allocated bytes on 32-bit arch, so we get huge increases. Metric Increase: haddock.Cabal haddock.base haddock.compiler space_leak_001 - - - - - a3d69dc6 by Sebastian Graf at 2020-06-25T23:06:18-04:00 GHC.Core.Unify: Make UM actions one-shot by default This MR makes the UM monad in GHC.Core.Unify into a one-shot monad. See the long Note [The one-shot state monad trick]. See also #18202 and !3309, which applies this to all Reader/State-like monads in GHC for compile-time perf improvements. The pattern used here enables something similar to the state-hack, but is applicable to user-defined monads, not just `IO`. Metric Decrease 'runtime/bytes allocated' (test_env='i386-linux-deb9'): haddock.Cabal - - - - - 9ee58f8d by Matthias Pall Gissurarson at 2020-06-26T17:12:45+00:00 Implement the proposed -XQualifiedDo extension Co-authored-by: Facundo Domínguez <facundo.dominguez at tweag.io> QualifiedDo is implemented using the same placeholders for operation names in the AST that were devised for RebindableSyntax. Whenever the renamer checks which names to use for do syntax, it first checks if the do block is qualified (e.g. M.do { stmts }), in which case it searches for qualified names in the module M. This allows users to write {-# LANGUAGE QualifiedDo #-} import qualified SomeModule as M f x = M.do -- desugars to: y <- M.return x -- M.return x M.>>= \y -> M.return y -- M.return y M.>> M.return y -- M.return y See Note [QualifiedDo] and the users' guide for more details. Issue #18214 Proposal: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0216-qualified-do.rst Since we change the constructors `ITdo` and `ITmdo` to carry the new module name, we need to bump the haddock submodule to account or the new shape of these constructors. - - - - - ce987865 by Ryan Scott at 2020-06-27T11:55:21-04:00 Revamp the treatment of auxiliary bindings for derived instances This started as a simple fix for #18321 that organically grew into a much more sweeping refactor of how auxiliary bindings for derived instances are handled. I have rewritten `Note [Auxiliary binders]` in `GHC.Tc.Deriv.Generate` to explain all of the moving parts, but the highlights are: * Previously, the OccName of each auxiliary binding would be given a suffix containing a hash of its package name, module name, and parent data type to avoid name clashes. This was needlessly complicated, so we take the more direct approach of generating `Exact` `RdrName`s for each auxiliary binding with the same `OccName`, but using an underlying `System` `Name` with a fresh `Unique` for each binding. Unlike hashes, allocating new `Unique`s does not require any cleverness and avoid name clashes all the same... * ...speaking of which, in order to convince the renamer that multiple auxiliary bindings with the same `OccName` (but different `Unique`s) are kosher, we now use `rnLocalValBindsLHS` instead of `rnTopBindsLHS` to rename auxiliary bindings. Again, see `Note [Auxiliary binders]` for the full story. * I have removed the `DerivHsBind` constructor for `DerivStuff`—which was only used for `Data.Data`-related auxiliary bindings—and refactored `gen_Data_binds` to use `DerivAuxBind` instead. This brings the treatment of `Data.Data`-related auxiliary bindings in line with every other form of auxiliary binding. Fixes #18321. - - - - - a403eb91 by Sylvain Henry at 2020-06-27T11:55:59-04:00 ghc-bignum: fix division by zero (#18359) - - - - - 1b3d13b6 by Sylvain Henry at 2020-06-27T11:55:59-04:00 Fix ghc-bignum exceptions We must ensure that exceptions are not simplified. Previously we used: case raiseDivZero of _ -> 0## -- dummyValue But it was wrong because the evaluation of `raiseDivZero` was removed and the dummy value was directly returned. See new Note [ghc-bignum exceptions]. I've also removed the exception triggering primops which were fragile. We don't need them to be primops, we can have them exported by ghc-prim. I've also added a test for #18359 which triggered this patch. - - - - - a74ec37c by Simon Peyton Jones at 2020-06-27T11:56:34-04:00 Better loop detection in findTypeShape Andreas pointed out, in !3466, that my fix for #18304 was not quite right. This patch fixes it properly, by having just one RecTcChecker rather than (implicitly) two nested ones, in findTypeShape. - - - - - a04020b8 by Sylvain Henry at 2020-06-27T11:57:11-04:00 DynFlags: don't store buildTag `DynFlags.buildTag` was a field created from the set of Ways in `DynFlags.ways`. It had to be kept in sync with `DynFlags.ways` which was fragile. We want to avoid global state like this (#17957). Moreover in #14335 we also want to support loading units with different ways: target units would still use `DynFlags.ways` but plugins would use `GHC.Driver.Ways.hostFullWays`. To avoid having to deal both with build tag and with ways, we recompute the buildTag on-the-fly (should be pretty cheap) and we remove `DynFlags.buildTag` field. - - - - - 0e83efa2 by Krzysztof Gogolewski at 2020-06-27T11:57:49-04:00 Don't generalize when typechecking a tuple section The code is simpler and cleaner. - - - - - d8ba9e6f by Peter Trommler at 2020-06-28T09:19:11-04:00 RTS: Refactor Haskell-C glue for PPC 64-bit Make sure the stack is 16 byte aligned even when reserved stack bytes are not a multiple of 16 bytes. Avoid saving r2 (TOC). On ELF v1 the function descriptor of StgReturn has the same TOC as StgRun, on ELF v2 the TOC is recomputed in the function prologue. Use the ABI provided functions to save clobbered GPRs and FPRs. Improve comments. Describe what the stack looks like and how it relates to the respective ABIs. - - - - - 42f797b0 by Ryan Scott at 2020-06-28T09:19:46-04:00 Use NHsCoreTy to embed types into GND-generated code `GeneralizedNewtypeDeriving` is in the unique situation where it must produce an `LHsType GhcPs` from a Core `Type`. Historically, this was done with the `typeToLHsType` function, which walked over the entire `Type` and attempted to construct an `LHsType` with the same overall structure. `typeToLHsType` is quite complicated, however, and has been the subject of numerous bugs over the years (e.g., #14579). Luckily, there is an easier way to accomplish the same thing: the `XHsType` constructor of `HsType`. `XHsType` bundles an `NHsCoreTy`, which allows embedding a Core `Type` directly into an `HsType`, avoiding the need to laboriously convert from one to another (as `typeToLHsType` did). Moreover, renaming and typechecking an `XHsType` is simple, since one doesn't need to do anything to a Core `Type`... ...well, almost. For the reasons described in `Note [Typechecking NHsCoreTys]` in `GHC.Tc.Gen.HsType`, we must apply a substitution that we build from the local `tcl_env` type environment. But that's a relatively modest price to pay. Now that `GeneralizedNewtypeDeriving` uses `NHsCoreTy`, the `typeToLHsType` function no longer has any uses in GHC, so this patch rips it out. Some additional tweaks to `hsTypeNeedsParens` were necessary to make the new `-ddump-deriv` output correctly parenthesized, but other than that, this patch is quite straightforward. This is a mostly internal refactoring, although it is likely that `GeneralizedNewtypeDeriving`-generated code will now need fewer language extensions in certain situations than it did before. - - - - - 68530b1c by Jan Hrček at 2020-06-28T09:20:22-04:00 Fix duplicated words and typos in comments and user guide - - - - - 15b79bef by Ryan Scott at 2020-06-28T09:20:57-04:00 Add integer-gmp's ghc.mk and GNUmakefile to .gitignore - - - - - bfa5698b by Simon Peyton Jones at 2020-06-28T09:21:32-04:00 Fix a typo in Lint This simple error in GHC.Core.Litn.lintJoinLams meant that Lint reported bogus errors. Fixes #18399 - - - - - 71006532 by Ryan Scott at 2020-06-30T07:10:42-04:00 Reject nested foralls/contexts in instance types more consistently GHC is very wishy-washy about rejecting instance declarations with nested `forall`s or contexts that are surrounded by outermost parentheses. This can even lead to some strange interactions with `ScopedTypeVariables`, as demonstrated in #18240. This patch makes GHC more consistently reject instance types with nested `forall`s/contexts so as to prevent these strange interactions. On the implementation side, this patch tweaks `splitLHsInstDeclTy` and `getLHsInstDeclHead` to not look through parentheses, which can be semantically significant. I've added a `Note [No nested foralls or contexts in instance types]` in `GHC.Hs.Type` to explain why. This also introduces a `no_nested_foralls_contexts_err` function in `GHC.Rename.HsType` to catch nested `forall`s/contexts in instance types. This function is now used in `rnClsInstDecl` (for ordinary instance declarations) and `rnSrcDerivDecl` (for standalone `deriving` declarations), the latter of which fixes #18271. On the documentation side, this adds a new "Formal syntax for instance declaration types" section to the GHC User's Guide that presents a BNF-style grammar for what is and isn't allowed in instance types. Fixes #18240. Fixes #18271. - - - - - bccf3351 by Sylvain Henry at 2020-06-30T07:10:46-04:00 Add ghc-bignum to 8.12 release notes - - - - - 81704a6f by David Eichmann at 2020-06-30T07:10:48-04:00 Update ssh keys in CI performance metrics upload script - - - - - 85310fb8 by Joshua Price at 2020-06-30T07:10:49-04:00 Add missing Ix instances for tuples of size 6 through 15 (#16643) - - - - - cbb6b62f by Vladislav Zavialov at 2020-07-01T15:41:38-04:00 Implement -XLexicalNegation (GHC Proposal #229) This patch introduces a new extension, -XLexicalNegation, which detects whether the minus sign stands for negation or subtraction using the whitespace-based rules described in GHC Proposal #229. Updates haddock submodule. - - - - - fb5a0d01 by Martin Handley at 2020-07-01T15:42:14-04:00 #17169: Clarify Fixed's Enum instance. - - - - - b316804d by Simon Peyton Jones at 2020-07-01T15:42:49-04:00 Improve debug tracing for substitution This patch improves debug tracing a bit (#18395) * Remove the ancient SDoc argument to substitution, replacing it with a HasDebugCallStack constraint. The latter does the same job (indicate the call site) but much better. * Add HasDebugCallStack to simpleOptExpr, exprIsConApp_maybe I needed this to help nail the lookupIdSubst panic in #18326, #17784 - - - - - 5c9fabb8 by Hécate at 2020-07-01T15:43:25-04:00 Add most common return values for `os` and `arch` - - - - - 76d8cc74 by Ryan Scott at 2020-07-01T15:44:01-04:00 Desugar quoted uses of DerivingVia and expression type signatures properly The way that `GHC.HsToCore.Quote` desugared quoted `via` types (e.g., `deriving via forall a. [a] instance Eq a => Eq (List a)`) and explicit type annotations in signatures (e.g., `f = id @a :: forall a. a -> a`) was completely wrong, as it did not implement the scoping guidelines laid out in `Note [Scoped type variables in bindings]`. This is easily fixed. While I was in town, I did some minor cleanup of related Notes: * `Note [Scoped type variables in bindings]` and `Note [Scoped type variables in class and instance declarations]` say very nearly the same thing. I decided to just consolidate the two Notes into `Note [Scoped type variables in quotes]`. * `Note [Don't quantify implicit type variables in quotes]` is somewhat outdated, as it predates GHC 8.10, where the `forall`-or-nothing rule requires kind variables to be explicitly quantified in the presence of an explicit `forall`. As a result, the running example in that Note doesn't even compile. I have changed the example to something simpler that illustrates the same point that the original Note was making. Fixes #18388. - - - - - 44d6a335 by Andreas Klebinger at 2020-07-02T02:54:54-04:00 T16012: Be verbose on failure. - - - - - f9853330 by Ryan Scott at 2020-07-02T02:55:29-04:00 Bump ghc-prim version to 0.7.0 Fixes #18279. Bumps the `text` submodule. - - - - - 23e4e047 by Sylvain Henry at 2020-07-02T10:46:31-04:00 Hadrian: fix PowerPC64le support (#17601) [ci skip] - - - - - 3cdd8d69 by Sylvain Henry at 2020-07-02T10:47:08-04:00 NCG: correctly handle addresses with huge offsets (#15570) Before this patch we could generate addresses of this form: movzbl cP0_str+-9223372036854775808,%eax The linker can't handle them because the offset is too large: ld.lld: error: Main.o:(.text+0xB3): relocation R_X86_64_32S out of range: -9223372036852653050 is not in [-2147483648, 2147483647] With this patch we detect those cases and generate: movq $-9223372036854775808,%rax addq $cP0_str,%rax movzbl (%rax),%eax I've also refactored `getAmode` a little bit to make it easier to understand and to trace. - - - - - 4d90b3ff by Gabor Greif at 2020-07-02T20:07:59-04:00 No need for CURSES_INCLUDE_DIRS This is a leftover from ef63ff27251a20ff11e58c9303677fa31e609a88 - - - - - f08d6316 by Sylvain Henry at 2020-07-02T20:08:36-04:00 Replace Opt_SccProfilingOn flag with sccProfilingEnabled helper function SCC profiling was enabled in a convoluted way: if WayProf was enabled, Opt_SccProfilingOn general flag was set (in `GHC.Driver.Ways.wayGeneralFlags`), and then this flag was queried in various places. There is no need to go via general flags, so this patch defines a `sccProfilingEnabled :: DynFlags -> Bool` helper function that just checks whether WayProf is enabled. - - - - - 8cc7274b by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Only allocate the Censuses that we need When not LDV profiling there is no reason to allocate 32 Censuses; one will do. This is a very small memory footprint optimisation, but it comes for free. - - - - - b835112c by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Free old allocations when reinitialising Censuses Previously when not LDV profiling we would repeatedly reinitialise `censuses[0]` with `initEra`. This failed to free the `Arena` and `HashTable` from the old census, resulting in a memory leak. Fixes #18348. - - - - - 34be6523 by Valery Tolstov at 2020-07-03T02:50:03-04:00 Mention flags that are not enabled by -Wall (#18372) * Mention missing flags that are not actually enabled by -Wall (docs/users_guide/using-warnings.rst) * Additionally remove -Wmissing-monadfail-instances from the list of flags enabled by -Wcompat, as it is not the case since 8.8 - - - - - edc8d22b by Sylvain Henry at 2020-07-03T02:50:40-04:00 LLVM: support R9 and R10 registers d535ef006d85dbdb7cda2b09c5bc35cb80108909 allowed the use of up to 10 vanilla registers but didn't update LLVM backend to support them. This patch fixes it. - - - - - 4bf18646 by Simon Peyton Jones at 2020-07-03T08:37:42+01:00 Improve handling of data type return kinds Following a long conversation with Richard, this patch tidies up the handling of return kinds for data/newtype declarations (vanilla, family, and instance). I have substantially edited the Notes in TyCl, so they would bear careful reading. Fixes #18300, #18357 In GHC.Tc.Instance.Family.newFamInst we were checking some Lint-like properties with ASSSERT. Instead Richard and I have added a proper linter for axioms, and called it from lintGblEnv, which in turn is called in tcRnModuleTcRnM New tests (T18300, T18357) cause an ASSERT failure in HEAD. - - - - - 41d26492 by Sylvain Henry at 2020-07-03T17:33:59-04:00 DynFlags: avoid the use of sdocWithDynFlags in GHC.Core.Rules (#17957) - - - - - 7aa6ef11 by Hécate at 2020-07-03T17:34:36-04:00 Add the __GHC_FULL_VERSION__ CPP macro to expose the full GHC version - - - - - e61d5395 by Chaitanya Koparkar at 2020-07-07T13:55:59-04:00 ghc-prim: Turn some comments into haddocks [ci skip] - - - - - 37743f91 by John Ericson at 2020-07-07T13:56:00-04:00 Support `timesInt2#` in LLVM backend - - - - - 46397e53 by John Ericson at 2020-07-07T13:56:00-04:00 `genericIntMul2Op`: Call `genericWordMul2Op` directly This unblocks a refactor, and removes partiality. It might be a PowerPC regression but that should be fixable. - - - - - 8a1c0584 by John Ericson at 2020-07-07T13:56:00-04:00 Simplify `PrimopCmmEmit` Follow @simonpj's suggestion of pushing the "into regs" logic into `emitPrimOp`. With the previous commit getting rid of the recursion in `genericIntMul2Op`, this is now an easy refactor. - - - - - 6607f203 by John Ericson at 2020-07-07T13:56:00-04:00 `opAllDone` -> `opIntoRegs` The old name was and terrible and became worse after the previous commit's refactor moved non-trivial funcationlity into its body. - - - - - fdcc53ba by Sylvain Henry at 2020-07-07T13:56:00-04:00 Optimise genericIntMul2Op We shouldn't directly call 'genericWordMul2Op' in genericIntMul2Op because a target may provide a faster primop for 'WordMul2Op': we'd better use it! - - - - - 686e7225 by Moritz Angermann at 2020-07-07T13:56:01-04:00 [linker/rtsSymbols] More linker symbols Mostly symbols needed for aarch64/armv7l and in combination with musl, where we have to rely on loading *all* objects/archives - __stack_chk_* only when not DYNAMIC - - - - - 3f60b94d by Moritz Angermann at 2020-07-07T13:56:01-04:00 better if guards. - - - - - 7abffced by Moritz Angermann at 2020-07-07T13:56:01-04:00 Fix (1) - - - - - cdfeb3f2 by Moritz Angermann at 2020-07-07T13:56:01-04:00 AArch32 symbols only on aarch32. - - - - - f496c955 by Adam Sandberg Ericsson at 2020-07-07T13:56:02-04:00 add -flink-rts flag to link the rts when linking a shared or static library #18072 By default we don't link the RTS when linking shared libraries because in the most usual mode a shared library is an intermediary product, for example a Haskell library, that will be linked into some executable in the end. So we wish to defer the RTS flavour to link to the final link. However sometimes the final product is the shared library, for example when writing a plugin for some other system, so we do wish the shared library to link the RTS. For consistency we also make -staticlib honor this flag and its inversion. -staticlib currently implies -flink-shared. - - - - - c59faf67 by Stefan Schulze Frielinghaus at 2020-07-07T13:56:04-04:00 hadrian: link check-ppr against debugging RTS if ghcDebugged - - - - - 0effc57d by Adam Sandberg Ericsson at 2020-07-07T13:56:05-04:00 rts linker: teach the linker about GLIBC's special handling of *stat, mknod and atexit functions #7072 - - - - - 96153433 by Adam Sandberg Ericsson at 2020-07-07T13:56:06-04:00 hadrian: make hadrian/ghci use the bootstrap compiler from configure #18190 - - - - - 4d24f886 by Adam Sandberg Ericsson at 2020-07-07T13:56:07-04:00 hadrian: ignore cabal configure verbosity related flags #18131 - - - - - 7332bbff by Ben Gamari at 2020-07-07T13:56:08-04:00 testsuite: Widen T12234 acceptance window to 2% Previously it wasn't uncommon to see +/-1% fluctuations in compiler allocations on this test. - - - - - 180b6313 by Gabor Greif at 2020-07-07T13:56:08-04:00 When running libtool, report it as such - - - - - d3bd6897 by Sylvain Henry at 2020-07-07T13:56:11-04:00 BigNum: rename BigNat types Before this patch BigNat names were confusing because we had: * GHC.Num.BigNat.BigNat: unlifted type used everywhere else * GHC.Num.BigNat.BigNatW: lifted type only used to share static constants * GHC.Natural.BigNat: lifted type only used for backward compatibility After this patch we have: * GHC.Num.BigNat.BigNat#: unlifted type * GHC.Num.BigNat.BigNat: lifted type (reexported from GHC.Natural) Thanks to @RyanGlScott for spotting this. - - - - - 929d26db by Sylvain Henry at 2020-07-07T13:56:12-04:00 Bignum: don't build ghc-bignum with stage0 Noticed by @Ericson2314 - - - - - d25b6851 by Sylvain Henry at 2020-07-07T13:56:12-04:00 Hadrian: ghc-gmp.h shouldn't be a compiler dependency - - - - - 0ddae2ba by Sylvain Henry at 2020-07-07T13:56:14-04:00 DynFlags: factor out pprUnitId from "Outputable UnitId" instance - - - - - 204f3f5d by Krzysztof Gogolewski at 2020-07-07T13:56:18-04:00 Remove unused function pprHsForAllExtra (#18423) The function `pprHsForAllExtra` was called only on `Nothing` since 2015 (1e041b7382b6aa). - - - - - 3033e0e4 by Adam Sandberg Ericsson at 2020-07-08T20:36:49-04:00 hadrian: add flag to skip rebuilding dependency information #17636 - - - - - b7de4b96 by Stefan Schulze Frielinghaus at 2020-07-09T09:49:22-04:00 Fix GHCi :print on big-endian platforms On big-endian platforms executing import GHC.Exts data Foo = Foo Float# deriving Show foo = Foo 42.0# foo :print foo results in an arithmetic overflow exception which is caused by function index where moveBytes equals word_size - (r + item_size_b) * 8 Here we have a mixture of units. Both, word_size and item_size_b have unit bytes whereas r has unit bits. On 64-bit platforms moveBytes equals then 8 - (0 + 4) * 8 which results in a negative and therefore invalid second parameter for a shiftL operation. In order to make things more clear the expression (word .&. (mask `shiftL` moveBytes)) `shiftR` moveBytes is equivalent to (word `shiftR` moveBytes) .&. mask On big-endian platforms the shift must be a left shift instead of a right shift. For symmetry reasons not a mask is used but two shifts in order to zero out bits. Thus the fixed version equals case endian of BigEndian -> (word `shiftL` moveBits) `shiftR` zeroOutBits `shiftL` zeroOutBits LittleEndian -> (word `shiftR` moveBits) `shiftL` zeroOutBits `shiftR` zeroOutBits Fixes #16548 and #14455 - - - - - 3656dff8 by Sylvain Henry at 2020-07-09T09:50:01-04:00 LLVM: fix MO_S_Mul2 support (#18434) The value indicating if the carry is useful wasn't taken into account. - - - - - d9f09506 by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Define multiShotIO and use it in mkSplitUniqueSupply This patch is part of the ongoing eta-expansion saga; see #18238. It implements a neat trick (suggested by Sebastian Graf) that allows the programmer to disable the default one-shot behaviour of IO (the "state hack"). The trick is to use a new multiShotIO function; see Note [multiShotIO]. For now, multiShotIO is defined here in Unique.Supply; but it should ultimately be moved to the IO library. The change is necessary to get good code for GHC's unique supply; see Note [Optimising the unique supply]. However it makes no difference to GHC as-is. Rather, it makes a difference when a subsequent commit Improve eta-expansion using ArityType lands. - - - - - bce695cc by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Make arityType deal with join points As Note [Eta-expansion and join points] describes, this patch makes arityType deal correctly with join points. What was there before was not wrong, but yielded lower arities than it could. Fixes #18328 In base GHC this makes no difference to nofib. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- n-body -0.1% -0.1% -1.2% -1.1% 0.0% -------------------------------------------------------------------------------- Min -0.1% -0.1% -55.0% -56.5% 0.0% Max -0.0% 0.0% +16.1% +13.4% 0.0% Geometric Mean -0.0% -0.0% -30.1% -31.0% -0.0% But it starts to make real difference when we land the change to the way mkDupableAlts handles StrictArg, in fixing #13253 and friends. I think this is because we then get more non-inlined join points. - - - - - 2b7c71cb by Simon Peyton Jones at 2020-07-11T12:17:02-04:00 Improve eta-expansion using ArityType As #18355 shows, we were failing to preserve one-shot info when eta-expanding. It's rather easy to fix, by using ArityType more, rather than just Arity. This patch is important to suport the one-shot monad trick; see #18202. But the extra tracking of one-shot-ness requires the patch Define multiShotIO and use it in mkSplitUniqueSupply If that patch is missing, ths patch makes things worse in GHC.Types.Uniq.Supply. With it, however, we see these improvements T3064 compiler bytes allocated -2.2% T3294 compiler bytes allocated -1.3% T12707 compiler bytes allocated -1.3% T13056 compiler bytes allocated -2.2% Metric Decrease: T3064 T3294 T12707 T13056 - - - - - de139cc4 by Artem Pelenitsyn at 2020-07-12T02:53:20-04:00 add reproducer for #15630 - - - - - c4de6a7a by Andreas Klebinger at 2020-07-12T02:53:55-04:00 Give Uniq[D]FM a phantom type for its key. This fixes #17667 and should help to avoid such issues going forward. The changes are mostly mechanical in nature. With two notable exceptions. * The register allocator. The register allocator references registers by distinct uniques. However they come from the types of VirtualReg, Reg or Unique in various places. As a result we sometimes cast the key type of the map and use functions which operate on the now typed map but take a raw Unique as actual key. The logic itself has not changed it just becomes obvious where we do so now. * <Type>Env Modules. As an example a ClassEnv is currently queried using the types `Class`, `Name`, and `TyCon`. This is safe since for a distinct class value all these expressions give the same unique. getUnique cls getUnique (classTyCon cls) getUnique (className cls) getUnique (tcName $ classTyCon cls) This is for the most part contained within the modules defining the interface. However it requires us to play dirty when we are given a `Name` to lookup in a `UniqFM Class a` map. But again the logic did not change and it's for the most part hidden behind the Env Module. Some of these cases could be avoided by refactoring but this is left for future work. We also bump the haddock submodule as it uses UniqFM. - - - - - c2cfdfde by Aaron Allen at 2020-07-13T09:00:33-04:00 Warn about empty Char enumerations (#18402) Currently the "Enumeration is empty" warning (-Wempty-enumerations) only fires for numeric literals. This patch adds support for `Char` literals so that enumerating an empty list of `Char`s will also trigger the warning. - - - - - c3ac87ec by Stefan Schulze Frielinghaus at 2020-07-13T09:01:10-04:00 hadrian: build check-ppr dynamic if GHC is build dynamic Fixes #18361 - - - - - 9ad072b4 by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Use dumpStyle when printing inlinings This just makes debug-printing consistent, and more informative. - - - - - e78c4efb by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Comments only - - - - - 7ccb760b by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Reduce result discount in conSize Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c - - - - - 7f0b671e by Ben Gamari at 2020-07-13T14:52:49-04:00 testsuite: Widen acceptance threshold on T5837 This test is positively tiny and consequently the bytes allocated measurement will be relatively noisy. Consequently I have seen this fail spuriously quite often. - - - - - 118e1c3d by Alp Mestanogullari at 2020-07-14T21:30:52-04:00 compiler: re-engineer the treatment of rebindable if Executing on the plan described in #17582, this patch changes the way if expressions are handled in the compiler in the presence of rebindable syntax. We get rid of the SyntaxExpr field of HsIf and instead, when rebindable syntax is on, we rewrite the HsIf node to the appropriate sequence of applications of the local `ifThenElse` function. In order to be able to report good error messages, with expressions as they were written by the user (and not as desugared by the renamer), we make use of TTG extensions to extend GhcRn expression ASTs with an `HsExpansion` construct, which keeps track of a source (GhcPs) expression and the desugared (GhcRn) expression that it gives rise to. This way, we can typecheck the latter while reporting the former in error messages. In order to discard the error context lines that arise from typechecking the desugared expressions (because they talk about expressions that the user has not written), we carefully give a special treatment to the nodes fabricated by this new renaming-time transformation when typechecking them. See Note [Rebindable syntax and HsExpansion] for more details. The note also includes a recipe to apply the same treatment to other rebindable constructs. Tests 'rebindable11' and 'rebindable12' have been added to make sure we report identical error messages as before this patch under various circumstances. We also now disable rebindable syntax when processing untyped TH quotes, as per the discussion in #18102 and document the interaction of rebindable syntax and Template Haskell, both in Note [Template Haskell quotes and Rebindable Syntax] and in the user guide, adding a test to make sure that we do not regress in that regard. - - - - - 64c774b0 by Andreas Klebinger at 2020-07-14T21:31:27-04:00 Explain why keeping DynFlags in AnalEnv saves allocation. - - - - - 254245d0 by Ben Gamari at 2020-07-14T21:32:03-04:00 docs/users-guide: Update default -funfolding-use-threshold value This was changed in 3d2991f8 but I neglected to update the documentation. Fixes #18419. - - - - - 4c259f86 by Andreas Klebinger at 2020-07-14T21:32:41-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. - - - - - 23797224 by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 .gitlab: re-enable integer-simple substitute (BIGNUM_BACKEND) Recently build system migrated from INTEGER_LIBRARY to BIGNUM_BACKEND. But gitlab CI was never updated. Let's enable BIGNUM_BACKEND=native. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - e0db878a by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 ghc-bignum: bring in sync .hs-boot files with module declarations Before this change `BIGNUM_BACKEND=native` build was failing as: ``` libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs:708:16: error: * Variable not in scope: naturalFromBigNat# :: WordArray# -> t * Perhaps you meant one of these: `naturalFromBigNat' (imported from GHC.Num.Natural), `naturalToBigNat' (imported from GHC.Num.Natural) | 708 | m' = naturalFromBigNat# m | ``` This happens because `.hs-boot` files are slightly out of date. This change brings in data and function types in sync. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - c9f65c36 by Stefan Schulze Frielinghaus at 2020-07-14T21:33:57-04:00 rts/Disassembler.c: Use FMT_HexWord for printing values in hex format - - - - - 58ae62eb by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 macOS: Load frameworks without stating them first. macOS Big Sur makes the following change to how frameworks are shipped with the OS: > New in macOS Big Sur 11 beta, the system ships with a built-in > dynamic linker cache of all system-provided libraries. As part of > this change, copies of dynamic libraries are no longer present on > the filesystem. Code that attempts to check for dynamic library > presence by looking for a file at a path or enumerating a directory > will fail. Instead, check for library presence by attempting to > dlopen() the path, which will correctly check for the library in the > cache. (62986286) https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/ Therefore, the previous method of checking whether a library exists before attempting to load it makes GHC.Runtime.Linker.loadFramework fail to find frameworks installed at /System/Library/Frameworks. GHC.Runtime.Linker.loadFramework now opportunistically loads the framework libraries without checking for their existence first, failing only if all attempts to load a given framework from any of the various possible locations fail. - - - - - cdc4a6b0 by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 loadFramework: Output the errors collected in all loading attempts. With the recent change away from first finding and then loading a framework, loadFramework had no way of communicating the real reason why loadDLL failed if it was any reason other than the framework missing from the file system. It now collects all loading attempt errors into a list and concatenates them into a string to return to the caller. - - - - - 51dbfa52 by Ben Gamari at 2020-07-15T04:05:34-04:00 StgToCmm: Use CmmRegOff smart constructor Previously we would generate expressions of the form `CmmRegOff BaseReg 0`. This should do no harm (and really should be handled by the NCG anyways) but it's better to just generate a plain `CmmReg`. - - - - - ae11bdfd by Ben Gamari at 2020-07-15T04:06:08-04:00 testsuite: Add regression test for #17744 Test due to @monoidal. - - - - - 0e3c277a by Ben Gamari at 2020-07-15T16:41:01-04:00 Bump Cabal submodule Updates a variety of tests as Cabal is now more strict about Cabal file form. - - - - - ceed994a by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Drop Windows Vista support, require Windows 7 - - - - - 00a23bfd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Update Windows FileSystem wrapper utilities. - - - - - 459e1c5f by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Use SlimReaderLocks and ConditonalVariables provided by the OS instead of emulated ones - - - - - 763088fc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Small linker comment and ifdef cleanups - - - - - 1a228ff9 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Flush event logs eagerly. - - - - - e9e04dda by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Refactor Buffer structures to be able to track async operations - - - - - 356dc3fe by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Implement new Console API - - - - - 90e69f77 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add IOPort synchronization primitive - - - - - 71245fcc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add new io-manager cmdline options - - - - - d548a3b3 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Init Windows console Codepage to UTF-8. - - - - - 58ef6366 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add unsafeSplat to GHC.Event.Array - - - - - d660725e by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add size and iterate to GHC.Event.IntTable. - - - - - 050da6dd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Switch Testsuite to test winio by default - - - - - 4bf542bf by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Multiple refactorings and support changes. - - - - - 4489af6b by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core threaded I/O manager - - - - - 64d8f2fe by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core non-threaded I/O manager - - - - - 8da15a09 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix a scheduler bug with the threaded-runtime. - - - - - 84ea3d14 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Relaxing some constraints in io-manager. - - - - - ccf0d107 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix issues with non-threaded I/O manager after split. - - - - - b492fe6e by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Remove some barf statements that are a bit strict. - - - - - 01423fd2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Expand comments describing non-threaded loop - - - - - 4b69004f by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: fix FileSize unstat-able handles - - - - - 9b384270 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Implement new tempfile routines for winio - - - - - f1e0be82 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix input truncation when reading from handle. This was caused by not upholding the read buffer invariant that bufR == bufL == 0 for empty read buffers. - - - - - e176b625 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix output truncation for writes larger than buffer size - - - - - a831ce0e by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Rewrite bufWrite. I think it's far easier to follow the code now. It's also correct now as I had still missed a spot where we didn't update the offset. - - - - - 6aefdf62 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix offset set by bufReadEmpty. bufReadEmpty returns the bytes read *including* content that was already buffered, But for calculating the offset we only care about the number of bytes read into the new buffer. - - - - - 750ebaee by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Clean up code surrounding IOPort primitives. According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc. - - - - - ffd31db9 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix multi threaded threadDelay and a few other small changes. Multithreaded threadDelay suffered from a race condition based on the ioManagerStatus. Since the status isn't needed for WIO I removed it completely. This resulted in a light refactoring, as consequence we will always wake up the IO manager using interruptSystemManager, which uses `postQueuedCompletionStatus` internally. I also added a few comments which hopefully makes the code easier to dive into for the next person diving in. - - - - - 6ec26df2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 wionio: Make IO subsystem check a no-op on non-windows platforms. - - - - - 29bcd936 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Set handle offset when opening files in Append mode. Otherwise we would truncate the file. - - - - - 55c29700 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Remove debug event log trace - - - - - 9acb9f40 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix sqrt and openFile009 test cases - - - - - 57017cb7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Allow hp2ps to build with -DDEBUG - - - - - b8cd9995 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update output of T9681 since we now actually run it. - - - - - 10af5b14 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: A few more improvements to the IOPort primitives. - - - - - 39afc4a7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix expected tempfiles output. Tempfiles now works properly on windows, as such we can delete the win32 specific output. - - - - - 99db46e0 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Assign thread labels to IOManager threads. - - - - - be6af732 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Properly check for the tso of an incall to be zero. - - - - - e2c6dac7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark FD instances as unsupported under WINIO. - - - - - fd02ceed by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix threadDelay maxBound invocations. Instead of letting the ns timer overflow now clamp it at (maxBound :: Word64) ns. That still gives a few hundred years. - - - - - bc79f9f1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comments/cleanup an import in base - - - - - 1d197f4b by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark outstanding_service_requests volatile. As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration. - - - - - dc438186 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Make last_event a local variable - - - - - 2fc957c5 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comment about thread safety of processCompletion. - - - - - 4c026b6c by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: nonthreaded: Create io processing threads in main thread. We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread. - - - - - f47c7208 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add an exported isHeapAlloced function to the RTS - - - - - cc5d7bb1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Queue IO processing threads at the front of the queue. This will unblock the IO thread sooner hopefully leading to higher throughput in some situations. - - - - - e7630115 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: ThreadDelay001: Use higher resolution timer. - - - - - 451b5f96 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update T9681 output, disable T4808 on windows. T4808 tests functionality of the FD interface which won't be supported under WINIO. T9681 just has it's expected output tweaked. - - - - - dd06f930 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Wake io manager once per registerTimeout. Which is implicitly done in editTimeouts, so need to wake it up twice. - - - - - e87d0bf9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update placeholder comment with actual function name. - - - - - fc9025db by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Always lock win32 event queue - - - - - c24c9a1f by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Display thread labels when tracing scheduler events. - - - - - 06542b03 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Refactor non-threaded runner thread and scheduler interface. Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event. - - - - - 256299b1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove outstanding_requests from runner. We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port. - - - - - 3ebd8ad9 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Various fixes related to rebase and testdriver - - - - - 6be6bcba by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Fix rebase artifacts - - - - - 2c649dc3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename unsafeSplat to unsafeCopyFromBuffer - - - - - a18b73f3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove unused size/iterate operations from IntTable - - - - - 16bab48e by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Detect running IO Backend via peeking at RtsConfig - - - - - 8b8405a0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update temp path so GCC etc can handle it. Also fix PIPE support, clean up error casting, fix memory leaks - - - - - 2092bc54 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Minor comments/renamings - - - - - a5b5b6c0 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Checking if an error code indicates completion is now a function. - - - - - 362176fd by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Small refactor in withOverlappedEx - - - - - 32e20597 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: A few comments and commented out dbxIO - - - - - a4bfc1d9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't drop buffer offset in byteView/cwcharView - - - - - b3ad2a54 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: revert BHandle changes. - - - - - 3dcd87e2 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Fix imports - - - - - 5a371890 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update ghc-cabal to handle new Cabal submodule bump - - - - - d07ebe0d by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Only compile sources on Windows - - - - - dcb42393 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Actually return Nothing on EOF for non-blocking read - - - - - 895a3beb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate logic in encodeMultiByte[Raw]IO. - - - - - e06e6734 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate openFile logic - - - - - b59430c0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: fix -werror issue in encoding file - - - - - f8d39a51 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't mention windows specific functions when building on Linux. - - - - - 6a533d2a by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add a note about file locking in the RTS. - - - - - cf37ce34 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Add version to @since annotation - - - - - 0fafa2eb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename GHC.Conc.IOCP -> GHC.Conc.WinIO - - - - - 1854fc23 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Expand GHC.Conc.POSIX description It now explains users may not use these functions when using the old IO manager. - - - - - fcc7ba41 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Fix potential spaceleak in __createUUIDTempFileErrNo - - - - - 6b3fd9fa by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant -Wno-missing-signatures pragmas - - - - - 916fc861 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Make it explicit that we only create one IO manager - - - - - f260a721 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Note why we don't use blocking waits. - - - - - aa0a4bbf by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove commented out pragma - - - - - d679b544 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant buffer write in Handle/Text.hs:bufReadEmpty - - - - - d3f94368 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename SmartHandles to StdHandles - - - - - bd6b8ec1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add comment stating failure behaviour for getUniqueFileInfo. - - - - - 12846b85 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update IOPort haddocks. - - - - - 9f39fb14 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Add a note cross reference - - - - - 62dd5a73 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Name Haskell/OS I/O Manager explicitly in Note - - - - - fa807828 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Expand BlockedOnIOCompletion description. - - - - - f0880a1d by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove historical todos - - - - - 8e58e714 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Update note, remove debugging pragma. - - - - - aa4d84d5 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: flushCharReadBuffer shouldn't need to adjust offsets. - - - - - e580893a by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove obsolete comment about cond. variables - - - - - d54e9d79 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix initial linux validate build - - - - - 3cd4de46 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix ThreadDelay001 CPP - - - - - c88b1b9f by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix openFile009 merge conflict leftover - - - - - 849e8889 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept T9681 output. GHC now reports String instead of [Char]. - - - - - e7701818 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix cabal006 after upgrading cabal submodule Demand cabal 2.0 syntax instead of >= 1.20 as required by newer cabal versions. - - - - - a44f0373 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix stderr output for ghci/linking/dyn tests. We used to filter rtsopts, i opted to instead just accept the warning of it having no effect. This works both for -rtsopts, as well as -with-rtsopts which winio adds. - - - - - 515d9896 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T15261b stdout for --io-manager flag. - - - - - 949aaacc by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T5435_dyn_asm stderr The warning about rtsopts having no consequences is expected. So accept new stderr. - - - - - 7d424e1e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Also accept T7037 stderr - - - - - 1f009768 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal04 by filtering rts args - - - - - 981a9f2e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal01 by accepting expected stderr - - - - - b7b0464e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix safePkg01 by accepting expected stderr - - - - - 32734b29 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix T5435_dyn_gcc by accepting expected stderr - - - - - acc5cebf by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix tempfiles test on linux - - - - - c577b789 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for T3807 - - - - - c108c527 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload - - - - - 2b0b9a08 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload_multiple_objs - - - - - 67afb03c by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify wording on conditional variables. - - - - - 3bd41572 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify comment on cooked mode. - - - - - ded58a03 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: update lockfile signature and remove mistaken symbol in rts. - - - - - 2143c492 by Ben Gamari at 2020-07-15T16:41:04-04:00 testsuite: Add winio and winio_threaded ways Reverts many of the testsuite changes - - - - - c0979cc5 by Ben Gamari at 2020-07-16T10:56:54-04:00 Merge remote-tracking branch 'origin/wip/winio' - - - - - 750a1595 by Ben Gamari at 2020-07-18T07:26:41-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. - - - - - 6ba6a881 by Hécate at 2020-07-18T07:26:42-04:00 Implement `fullCompilerVersion` Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403 This MR adds `fullCompilerVersion`, a function that shares the same backend as the `--numeric-version` GHC flag, exposing a full, three-digit version datatype. - - - - - e6cf27df by Hécate at 2020-07-18T07:26:43-04:00 Add a Lint hadrian rule and an .hlint.yaml file in base/ - - - - - bcb177dd by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Allow multiple case branches to have a higher rank type As #18412 points out, it should be OK for multiple case alternatives to have a higher rank type, provided they are all the same. This patch implements that change. It sweeps away GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it with an enhanced version of fillInferResult. The basic change to fillInferResult is to permit the case in which another case alternative has already filled in the result; and in that case simply unify. It's very simple actually. See the new Note [fillInferResult] in TcMType Other refactoring: - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType (previously some of it was in Unify) - Move tcInstType and friends from TcMType to Instantiate, where it more properly belongs. (TCMType was getting very long.) - - - - - e5525a51 by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Improve typechecking of NPlusK patterns This patch (due to Richard Eisenberg) improves documentation of the wrapper returned by tcSubMult (see Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify). And, more substantially, it cleans up the multiplicity handling in the typechecking of NPlusKPat - - - - - 12f90352 by Krzysztof Gogolewski at 2020-07-18T07:26:45-04:00 Remove {-# CORE #-} pragma (part of #18048) This pragma has no effect since 2011. It was introduced for External Core, which no longer exists. Updates haddock submodule. - - - - - e504c913 by Simon Peyton Jones at 2020-07-18T07:26:45-04:00 Refactor the simplification of join binders This MR (for #18449) refactors the Simplifier's treatment of join-point binders. Specifically, it puts together, into GHC.Core.Opt.Simplify.Env.adjustJoinPointType two currently-separate ways in which we adjust the type of a join point. As the comment says: -- (adjustJoinPointType mult new_res_ty join_id) does two things: -- -- 1. Set the return type of the join_id to new_res_ty -- See Note [Return type for join points] -- -- 2. Adjust the multiplicity of arrows in join_id's type, as -- directed by 'mult'. See Note [Scaling join point arguments] I think this actually fixes a latent bug, by ensuring that the seIdSubst and seInScope have the right multiplicity on the type of join points. I did some tidying up while I was at it. No more setJoinResTy, or modifyJoinResTy: instead it's done locally in Simplify.Env.adjustJoinPointType - - - - - 49b265f0 by Chaitanya Koparkar at 2020-07-18T07:26:46-04:00 Fix minor typos in a Core.hs note - - - - - 8d59aed6 by Stefan Schulze Frielinghaus at 2020-07-18T07:26:47-04:00 GHCi: Fix isLittleEndian - - - - - c26e81d1 by Ben Gamari at 2020-07-18T07:26:47-04:00 testsuite: Mark ghci tests as fragile under unreg compiler In particular I have seen T16012 fail repeatedly under the unregisterised compiler. - - - - - 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - 2e997630 by Simon Jakobi at 2020-08-17T17:17:10+02:00 Deprecate Data.Semigroup.Option Libraries email: https://mail.haskell.org/pipermail/libraries/2018-April/028724.html GHC issue: https://gitlab.haskell.org/ghc/ghc/issues/15028 Corresponding PRs for deepseq: * https://github.com/haskell/deepseq/pull/55 * https://github.com/haskell/deepseq/pull/57 Bumps the deepseq submodule. - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/test-metrics.sh - CODEOWNERS - Makefile - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - + compiler/GHC/Builtin/RebindableNames.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/ByteCode/Types.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/Dataflow/Block.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Graph.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Lint.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/83a5500e4f1b4a0e5c1a46a3f17bc9011f430a21...2e997630fe267f1c3036fb4f04e303fedf3f42e5 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/83a5500e4f1b4a0e5c1a46a3f17bc9011f430a21...2e997630fe267f1c3036fb4f04e303fedf3f42e5 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 17 15:19:35 2020 From: gitlab at gitlab.haskell.org (Simon Jakobi) Date: Mon, 17 Aug 2020 11:19:35 -0400 Subject: [Git][ghc/ghc][wip/sjakobi/deprecate-option-v2] Deprecate Data.Semigroup.Option Message-ID: <5f3aa00716a50_80b3f8495bc8b048451828@gitlab.haskell.org.mail> Simon Jakobi pushed to branch wip/sjakobi/deprecate-option-v2 at Glasgow Haskell Compiler / GHC Commits: a90d1309 by Simon Jakobi at 2020-08-17T17:19:21+02:00 Deprecate Data.Semigroup.Option Libraries email: https://mail.haskell.org/pipermail/libraries/2018-April/028724.html GHC issue: https://gitlab.haskell.org/ghc/ghc/issues/15028 Corresponding PRs for deepseq: * https://github.com/haskell/deepseq/pull/55 * https://github.com/haskell/deepseq/pull/57 Bumps the deepseq submodule. - - - - - 3 changed files: - libraries/base/Data/Semigroup.hs - libraries/base/changelog.md - libraries/deepseq Changes: ===================================== libraries/base/Data/Semigroup.hs ===================================== @@ -347,8 +347,6 @@ instance Bifoldable Arg where instance Bitraversable Arg where bitraverse f g (Arg a b) = Arg <$> f a <*> g b --- | Use @'Option' ('First' a)@ to get the behavior of --- 'Data.Monoid.First' from "Data.Monoid". newtype First a = First { getFirst :: a } deriving ( Bounded -- ^ @since 4.9.0.0 , Eq -- ^ @since 4.9.0.0 @@ -405,8 +403,6 @@ instance Monad First where instance MonadFix First where mfix f = fix (f . getFirst) --- | Use @'Option' ('Last' a)@ to get the behavior of --- 'Data.Monoid.Last' from "Data.Monoid" newtype Last a = Last { getLast :: a } deriving ( Bounded -- ^ @since 4.9.0.0 , Eq -- ^ @since 4.9.0.0 @@ -511,6 +507,8 @@ mtimesDefault n x | n == 0 = mempty | otherwise = unwrapMonoid (stimes n (WrapMonoid x)) +{-# DEPRECATED Option, option "will be removed in GHC 9.2; use 'Maybe' instead." #-} + -- | 'Option' is effectively 'Maybe' with a better instance of -- 'Monoid', built off of an underlying 'Semigroup' instead of an -- underlying 'Monoid'. @@ -520,8 +518,7 @@ mtimesDefault n x -- -- In GHC 8.4 and higher, the 'Monoid' instance for 'Maybe' has been -- corrected to lift a 'Semigroup' instance instead of a 'Monoid' --- instance. Consequently, this type is no longer useful. It will be --- marked deprecated in GHC 8.8 and removed in GHC 8.10. +-- instance. Consequently, this type is no longer useful. newtype Option a = Option { getOption :: Maybe a } deriving ( Eq -- ^ @since 4.9.0.0 , Ord -- ^ @since 4.9.0.0 ===================================== libraries/base/changelog.md ===================================== @@ -14,6 +14,9 @@ * The planned deprecation of `Data.Monoid.First` and `Data.Monoid.Last` is scrapped due to difficulties with the suggested migration path. + * `Data.Semigroup.Option` and the accompanying `option` function are + deprecated and scheduled for removal in 4.16. + * Add `Generic` instances to `Fingerprint`, `GiveGCStats`, `GCFlags`, `ConcFlags`, `DebugFlags`, `CCFlags`, `DoHeapProfile`, `ProfFlags`, `DoTrace`, `TraceFlags`, `TickyFlags`, `ParFlags`, `RTSFlags`, `RTSStats`, ===================================== libraries/deepseq ===================================== @@ -1 +1 @@ -Subproject commit 13c1c84415da727ab56e9fa33aca5046b6683848 +Subproject commit b8c4fb4debaed6ef7eb6940ca4cfea6bd63cc212 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a90d13091ff82e954432bedd0bb20845c666eddb -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a90d13091ff82e954432bedd0bb20845c666eddb You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 17 16:21:51 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Mon, 17 Aug 2020 12:21:51 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/buggymcbugfix/arrayOf-static Message-ID: <5f3aae9f75b6_80b3f84693c1eb48460863@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed new branch wip/buggymcbugfix/arrayOf-static at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/buggymcbugfix/arrayOf-static You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 17 17:04:32 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 17 Aug 2020 13:04:32 -0400 Subject: [Git][ghc/ghc][wip/T18580] base: Fail if `timeout` is used when exceptions are masked Message-ID: <5f3ab8a04bb94_80b1075951c8463496@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18580 at Glasgow Haskell Compiler / GHC Commits: 6e409dcf by Ben Gamari at 2020-08-17T13:04:16-04:00 base: Fail if `timeout` is used when exceptions are masked As pointed out in #18580, `timeout`'s implementation assumes that exceptions will be handled. Document and assert this precondition. Fixes #18580. - - - - - 2 changed files: - libraries/base/System/Timeout.hs - libraries/base/changelog.md Changes: ===================================== libraries/base/System/Timeout.hs ===================================== @@ -27,8 +27,10 @@ import Control.Concurrent import Control.Exception (Exception(..), handleJust, bracket, uninterruptibleMask_, asyncExceptionToException, - asyncExceptionFromException) + asyncExceptionFromException, + getMaskingState, MaskingState(..)) import Data.Unique (Unique, newUnique) +import GHC.Stack.Types (HasCallStack) -- An internal type that is thrown as a dynamic exception to -- interrupt the running IO computation when the timeout has @@ -89,12 +91,16 @@ instance Exception Timeout where -- Note that 'timeout' cancels the computation by throwing it the 'Timeout' -- exception. Consequently blanket exception handlers (e.g. catching -- 'SomeException') within the computation will break the timeout behavior. -timeout :: Int -> IO a -> IO (Maybe a) +-- Moreover, 'timeout' cannot be used when in a context enclosed by +-- by 'Control.Exception.uninterruptibleMask'. +timeout :: HasCallStack => Int -> IO a -> IO (Maybe a) timeout n f | n < 0 = fmap Just f | n == 0 = return Nothing #if !defined(mingw32_HOST_OS) | rtsSupportsBoundThreads = do + checkNonUninterruptibleMask + -- In the threaded RTS, we use the Timer Manager to delay the -- (fairly expensive) 'forkIO' call until the timeout has expired. -- @@ -125,6 +131,7 @@ timeout n f (\_ -> fmap Just f)) #endif | otherwise = do + checkNonUninterruptibleMask pid <- myThreadId ex <- fmap Timeout newUnique handleJust (\e -> if e == ex then Just () else Nothing) @@ -134,3 +141,9 @@ timeout n f (uninterruptibleMask_ . killThread) (\_ -> fmap Just f)) -- #7719 explains why we need uninterruptibleMask_ above. + where + checkNonUninterruptibleMask :: HasCallStack => IO () + checkNonUninterruptibleMask = do + maskingState <- getMaskingState + when (maskingState == Unmasked) $ + error "System.Timeout.timeout called with exceptions uninterruptibly masked" ===================================== libraries/base/changelog.md ===================================== @@ -1,5 +1,11 @@ # Changelog for [`base` package](http://hackage.haskell.org/package/base) +## 4.16.0.0 *TBA* + + * `System.Timeout.timeout` now throws an error if called in a context where + exceptions have been masked since its implementation relies on exceptions to + interrupt its sub-computation (fixes #18580). + ## 4.15.0.0 *TBA* * `openFile` now calls the `open` system call with an `interruptible` FFI View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6e409dcf76e20e48e6365d44797982c8f13e79d0 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6e409dcf76e20e48e6365d44797982c8f13e79d0 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 17 17:11:34 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 17 Aug 2020 13:11:34 -0400 Subject: [Git][ghc/ghc][wip/gc/parallel-marking] 26 commits: Correct a typo in ghc.mk Message-ID: <5f3aba46ee0b2_80b3f84693c1eb4846392f@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/gc/parallel-marking at Glasgow Haskell Compiler / GHC Commits: 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - d5d92d82 by Ben Gamari at 2020-08-17T13:10:15-04:00 nonmoving: Clarify length of MarkQueueBlock and other comment issues - - - - - 1569b683 by Ben Gamari at 2020-08-17T13:10:15-04:00 nonmoving: Eliminate redundant information from MarkQueue Previously we kept a pointer to both the bdescr of the MarkQueueBlock at the head of the queue and the MarkQueueBlock itself. This is unnecessary. - - - - - 5e1d5097 by Ben Gamari at 2020-08-17T13:10:15-04:00 nonmoving: Decouple UpdRemSet from MarkQueue This is in preparation for parallel marking. - - - - - c478b187 by Ben Gamari at 2020-08-17T13:10:16-04:00 More - - - - - 9754bf57 by Ben Gamari at 2020-08-17T13:10:43-04:00 Rename updateRemembSetPushClosureRegs - - - - - b111c293 by Ben Gamari at 2020-08-17T13:11:21-04:00 MarkContext refactoring - - - - - b43889af by Ben Gamari at 2020-08-17T13:11:25-04:00 Drop dead field - - - - - aee6bfbf by Ben Gamari at 2020-08-17T13:11:25-04:00 nonmoving: Parallel marking? - - - - - 30 changed files: - compiler/GHC.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - compiler/GHC/CmmToAsm/CPrim.hs - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Format.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/709288ea154816116f374e9760e300807e239537...aee6bfbfb270778cfa952faac86f38d3d832d8b1 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/709288ea154816116f374e9760e300807e239537...aee6bfbfb270778cfa952faac86f38d3d832d8b1 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 17 19:09:35 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 17 Aug 2020 15:09:35 -0400 Subject: [Git][ghc/ghc][wip/backports] 2 commits: Clean up TBDs in changelog Message-ID: <5f3ad5ef6e44e_80b3f8495bc8b04847015f@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: e2ac0493 by Ben Gamari at 2020-08-17T09:17:45-04:00 Clean up TBDs in changelog (cherry picked from commit 4f334120c8e9cc4aefcbf11d99f169f648af9fde) - - - - - ca492b07 by Ben Gamari at 2020-08-17T15:09:27-04:00 Cabal - - - - - 3 changed files: - libraries/base/changelog.md - libraries/template-haskell/changelog.md - utils/ghc-cabal/ghc.mk Changes: ===================================== libraries/base/changelog.md ===================================== @@ -30,7 +30,7 @@ * Add `Ix` instances for tuples of size 6 through 15 -## 4.14.0.0 *TBA* +## 4.14.0.0 *Jan 2020 * Bundled with GHC 8.10.1 * Add a `TestEquality` instance for the `Compose` newtype. @@ -322,7 +322,7 @@ in constant space when applied to lists. (#10830) * `mkFunTy`, `mkAppTy`, and `mkTyConApp` from `Data.Typeable` no longer exist. - This functionality is superseded by the interfaces provided by + This functionality is superceded by the interfaces provided by `Type.Reflection`. * `mkTyCon3` is no longer exported by `Data.Typeable`. This function is ===================================== libraries/template-haskell/changelog.md ===================================== @@ -34,7 +34,9 @@ * The argument to `TExpQ` can now be levity polymorphic. -## 2.16.0.0 *TBA* +## 2.16.0.0 *Jan 2020* + + * Bundled with GHC 8.10.1 * Add support for tuple sections. (#15843) The type signatures of `TupE` and `UnboxedTupE` have changed from `[Exp] -> Exp` to `[Maybe Exp] -> Exp`. @@ -58,6 +60,8 @@ ## 2.15.0.0 *May 2019* + * Bundled with GHC 8.8.1 + * In `Language.Haskell.TH.Syntax`, `DataInstD`, `NewTypeInstD`, `TySynEqn`, and `RuleP` now all have a `Maybe [TyVarBndr]` argument, which contains a list of quantified type variables if an explicit `forall` is present, and @@ -80,6 +84,8 @@ ## 2.14.0.0 *September 2018* + * Bundled with GHC 8.6.1 + * Introduce an `addForeignFilePath` function, as well as a corresponding `qAddForeignFile` class method to `Quasi`. Unlike `addForeignFile`, which takes the contents of the file as an argument, `addForeignFilePath` takes ===================================== utils/ghc-cabal/ghc.mk ===================================== @@ -37,25 +37,13 @@ ifneq "$(BINDIST)" "YES" $(ghc-cabal_INPLACE) : $(ghc-cabal_DIST_BINARY) | $$(dir $$@)/. "$(CP)" $< $@ -# Minor hack, since we can't reuse the `hs-suffix-rules-srcdir` macro -ifneq ($(wildcard libraries/Cabal/Cabal/Distribution/Fields/Lexer.x),) -# Lexer.x exists so we have to call Alex ourselves -CABAL_LEXER_DEP := bootstrapping/Cabal/Distribution/Fields/Lexer.hs - -bootstrapping/Cabal/Distribution/Fields/Lexer.hs: libraries/Cabal/Cabal/Distribution/Fields/Lexer.x - mkdir -p bootstrapping/Cabal/Distribution/Fields - $(call cmd,ALEX) $< -o $@ -else -CABAL_LEXER_DEP := libraries/Cabal/Cabal/Distribution/Fields/Lexer.hs -endif - $(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*/*/*.hs) $(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*/*.hs) $(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*.hs) # N.B. Compile with -O0 since this is not a performance-critical executable # and the Cabal takes nearly twice as long to build with -O1. See #16817. -$(ghc-cabal_DIST_BINARY): $(CABAL_LEXER_DEP) utils/ghc-cabal/Main.hs $(TOUCH_DEP) | $$(dir $$@)/. bootstrapping/. +$(ghc-cabal_DIST_BINARY): utils/ghc-cabal/Main.hs $(TOUCH_DEP) | $$(dir $$@)/. bootstrapping/. "$(GHC)" $(SRC_HC_OPTS) \ $(addprefix -optc, $(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE0)) \ $(addprefix -optl, $(SRC_LD_OPTS) $(CONF_GCC_LINKER_OPTS_STAGE0)) \ @@ -69,7 +57,6 @@ $(ghc-cabal_DIST_BINARY): $(CABAL_LEXER_DEP) utils/ghc-cabal/Main.hs $(TOUCH_DEP -DBOOTSTRAPPING \ -odir bootstrapping \ -hidir bootstrapping \ - $(CABAL_LEXER_DEP) \ -ilibraries/Cabal/Cabal \ -ilibraries/binary/src \ -ilibraries/filepath \ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/8b16ddb52f70a85dd39db1bdf1b9a90fed0460b0...ca492b077bd33e069b43b6e5e6d5d4d979e05f55 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/8b16ddb52f70a85dd39db1bdf1b9a90fed0460b0...ca492b077bd33e069b43b6e5e6d5d4d979e05f55 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 17 19:15:09 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 17 Aug 2020 15:15:09 -0400 Subject: [Git][ghc/ghc][wip/backports] 4 commits: Clean up TBDs in changelog Message-ID: <5f3ad73d6debb_80b3f8486b5b7c08472513@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: 614ac76d by Ben Gamari at 2020-08-17T15:14:35-04:00 Clean up TBDs in changelog (cherry picked from commit 4f334120c8e9cc4aefcbf11d99f169f648af9fde) - - - - - 1a54d708 by Ben Gamari at 2020-08-17T15:14:35-04:00 Bump bytestring submodule - - - - - 20e19811 by Ben Gamari at 2020-08-17T15:14:35-04:00 Bump binary submodule - - - - - 1eaa606f by Ben Gamari at 2020-08-17T15:14:35-04:00 Bump Cabal submodule - - - - - 6 changed files: - libraries/Cabal - libraries/base/changelog.md - libraries/binary - libraries/bytestring - libraries/template-haskell/changelog.md - utils/ghc-cabal/ghc.mk Changes: ===================================== libraries/Cabal ===================================== @@ -1 +1 @@ -Subproject commit 32dad5c1cf70d65ecb93b0ec214445cf9c9f6615 +Subproject commit 1d886476c443b227bf93eba62781a6cad5012d9e ===================================== libraries/base/changelog.md ===================================== @@ -30,7 +30,7 @@ * Add `Ix` instances for tuples of size 6 through 15 -## 4.14.0.0 *TBA* +## 4.14.0.0 *Jan 2020 * Bundled with GHC 8.10.1 * Add a `TestEquality` instance for the `Compose` newtype. @@ -322,7 +322,7 @@ in constant space when applied to lists. (#10830) * `mkFunTy`, `mkAppTy`, and `mkTyConApp` from `Data.Typeable` no longer exist. - This functionality is superseded by the interfaces provided by + This functionality is superceded by the interfaces provided by `Type.Reflection`. * `mkTyCon3` is no longer exported by `Data.Typeable`. This function is ===================================== libraries/binary ===================================== @@ -1 +1 @@ -Subproject commit dfaf780596328c9184758452b78288e8f405fcc1 +Subproject commit f9b1c92a2ff34cc3457fa27faf3e16b8203b4b9f ===================================== libraries/bytestring ===================================== @@ -1 +1 @@ -Subproject commit e6cb01e2ec0bfdd19298418c85f220925a9fa307 +Subproject commit e043aacfc4202a59ccae8b8c8cf0e1ad83a3f209 ===================================== libraries/template-haskell/changelog.md ===================================== @@ -34,7 +34,9 @@ * The argument to `TExpQ` can now be levity polymorphic. -## 2.16.0.0 *TBA* +## 2.16.0.0 *Jan 2020* + + * Bundled with GHC 8.10.1 * Add support for tuple sections. (#15843) The type signatures of `TupE` and `UnboxedTupE` have changed from `[Exp] -> Exp` to `[Maybe Exp] -> Exp`. @@ -58,6 +60,8 @@ ## 2.15.0.0 *May 2019* + * Bundled with GHC 8.8.1 + * In `Language.Haskell.TH.Syntax`, `DataInstD`, `NewTypeInstD`, `TySynEqn`, and `RuleP` now all have a `Maybe [TyVarBndr]` argument, which contains a list of quantified type variables if an explicit `forall` is present, and @@ -80,6 +84,8 @@ ## 2.14.0.0 *September 2018* + * Bundled with GHC 8.6.1 + * Introduce an `addForeignFilePath` function, as well as a corresponding `qAddForeignFile` class method to `Quasi`. Unlike `addForeignFile`, which takes the contents of the file as an argument, `addForeignFilePath` takes ===================================== utils/ghc-cabal/ghc.mk ===================================== @@ -37,25 +37,13 @@ ifneq "$(BINDIST)" "YES" $(ghc-cabal_INPLACE) : $(ghc-cabal_DIST_BINARY) | $$(dir $$@)/. "$(CP)" $< $@ -# Minor hack, since we can't reuse the `hs-suffix-rules-srcdir` macro -ifneq ($(wildcard libraries/Cabal/Cabal/Distribution/Fields/Lexer.x),) -# Lexer.x exists so we have to call Alex ourselves -CABAL_LEXER_DEP := bootstrapping/Cabal/Distribution/Fields/Lexer.hs - -bootstrapping/Cabal/Distribution/Fields/Lexer.hs: libraries/Cabal/Cabal/Distribution/Fields/Lexer.x - mkdir -p bootstrapping/Cabal/Distribution/Fields - $(call cmd,ALEX) $< -o $@ -else -CABAL_LEXER_DEP := libraries/Cabal/Cabal/Distribution/Fields/Lexer.hs -endif - -$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*/*/*.hs) -$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*/*.hs) -$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*.hs) +$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/src/Distribution/*/*/*.hs) +$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/src/Distribution/*/*.hs) +$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/src/Distribution/*.hs) # N.B. Compile with -O0 since this is not a performance-critical executable # and the Cabal takes nearly twice as long to build with -O1. See #16817. -$(ghc-cabal_DIST_BINARY): $(CABAL_LEXER_DEP) utils/ghc-cabal/Main.hs $(TOUCH_DEP) | $$(dir $$@)/. bootstrapping/. +$(ghc-cabal_DIST_BINARY): utils/ghc-cabal/Main.hs $(TOUCH_DEP) | $$(dir $$@)/. bootstrapping/. "$(GHC)" $(SRC_HC_OPTS) \ $(addprefix -optc, $(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE0)) \ $(addprefix -optl, $(SRC_LD_OPTS) $(CONF_GCC_LINKER_OPTS_STAGE0)) \ @@ -69,8 +57,7 @@ $(ghc-cabal_DIST_BINARY): $(CABAL_LEXER_DEP) utils/ghc-cabal/Main.hs $(TOUCH_DEP -DBOOTSTRAPPING \ -odir bootstrapping \ -hidir bootstrapping \ - $(CABAL_LEXER_DEP) \ - -ilibraries/Cabal/Cabal \ + -ilibraries/Cabal/Cabal/src \ -ilibraries/binary/src \ -ilibraries/filepath \ -ilibraries/hpc \ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ca492b077bd33e069b43b6e5e6d5d4d979e05f55...1eaa606f36035a623b2b4c61f9f8b2c87a2752a2 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ca492b077bd33e069b43b6e5e6d5d4d979e05f55...1eaa606f36035a623b2b4c61f9f8b2c87a2752a2 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 17 20:09:42 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 17 Aug 2020 16:09:42 -0400 Subject: [Git][ghc/ghc][wip/backports] Bump Cabal submodule Message-ID: <5f3ae4066cae8_80b3f842731681c84741d6@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: 8c7e8e1c by Ben Gamari at 2020-08-17T20:09:30+00:00 Bump Cabal submodule - - - - - 5 changed files: - libraries/Cabal - utils/check-api-annotations/check-api-annotations.cabal - utils/check-ppr/check-ppr.cabal - utils/ghc-cabal/ghc-cabal.cabal - utils/ghc-cabal/ghc.mk Changes: ===================================== libraries/Cabal ===================================== @@ -1 +1 @@ -Subproject commit 32dad5c1cf70d65ecb93b0ec214445cf9c9f6615 +Subproject commit 1d886476c443b227bf93eba62781a6cad5012d9e ===================================== utils/check-api-annotations/check-api-annotations.cabal ===================================== @@ -24,6 +24,6 @@ Executable check-api-annotations Build-Depends: base >= 4 && < 5, containers, - Cabal >= 3.0 && < 3.4, + Cabal >= 3.0 && < 3.6, directory, ghc ===================================== utils/check-ppr/check-ppr.cabal ===================================== @@ -25,7 +25,7 @@ Executable check-ppr Build-Depends: base >= 4 && < 5, bytestring, containers, - Cabal >= 3.0 && < 3.4, + Cabal >= 3.0 && < 3.6, directory, filepath, ghc ===================================== utils/ghc-cabal/ghc-cabal.cabal ===================================== @@ -21,6 +21,6 @@ Executable ghc-cabal Build-Depends: base >= 3 && < 5, bytestring >= 0.10 && < 0.11, - Cabal >= 3.0 && < 3.4, + Cabal >= 3.2 && < 3.6, directory >= 1.1 && < 1.4, filepath >= 1.2 && < 1.5 ===================================== utils/ghc-cabal/ghc.mk ===================================== @@ -37,25 +37,13 @@ ifneq "$(BINDIST)" "YES" $(ghc-cabal_INPLACE) : $(ghc-cabal_DIST_BINARY) | $$(dir $$@)/. "$(CP)" $< $@ -# Minor hack, since we can't reuse the `hs-suffix-rules-srcdir` macro -ifneq ($(wildcard libraries/Cabal/Cabal/Distribution/Fields/Lexer.x),) -# Lexer.x exists so we have to call Alex ourselves -CABAL_LEXER_DEP := bootstrapping/Cabal/Distribution/Fields/Lexer.hs - -bootstrapping/Cabal/Distribution/Fields/Lexer.hs: libraries/Cabal/Cabal/Distribution/Fields/Lexer.x - mkdir -p bootstrapping/Cabal/Distribution/Fields - $(call cmd,ALEX) $< -o $@ -else -CABAL_LEXER_DEP := libraries/Cabal/Cabal/Distribution/Fields/Lexer.hs -endif - -$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*/*/*.hs) -$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*/*.hs) -$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*.hs) +$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/src/Distribution/*/*/*.hs) +$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/src/Distribution/*/*.hs) +$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/src/Distribution/*.hs) # N.B. Compile with -O0 since this is not a performance-critical executable # and the Cabal takes nearly twice as long to build with -O1. See #16817. -$(ghc-cabal_DIST_BINARY): $(CABAL_LEXER_DEP) utils/ghc-cabal/Main.hs $(TOUCH_DEP) | $$(dir $$@)/. bootstrapping/. +$(ghc-cabal_DIST_BINARY): utils/ghc-cabal/Main.hs $(TOUCH_DEP) | $$(dir $$@)/. bootstrapping/. "$(GHC)" $(SRC_HC_OPTS) \ $(addprefix -optc, $(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE0)) \ $(addprefix -optl, $(SRC_LD_OPTS) $(CONF_GCC_LINKER_OPTS_STAGE0)) \ @@ -69,8 +57,7 @@ $(ghc-cabal_DIST_BINARY): $(CABAL_LEXER_DEP) utils/ghc-cabal/Main.hs $(TOUCH_DEP -DBOOTSTRAPPING \ -odir bootstrapping \ -hidir bootstrapping \ - $(CABAL_LEXER_DEP) \ - -ilibraries/Cabal/Cabal \ + -ilibraries/Cabal/Cabal/src \ -ilibraries/binary/src \ -ilibraries/filepath \ -ilibraries/hpc \ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8c7e8e1c802791dda0f1d30c7658c995a8349c51 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8c7e8e1c802791dda0f1d30c7658c995a8349c51 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 02:29:26 2020 From: gitlab at gitlab.haskell.org (Moritz Angermann) Date: Mon, 17 Aug 2020 22:29:26 -0400 Subject: [Git][ghc/ghc][wip/angerman/aarch64-ncg] Revert the Spill/Reload fix; undo :got: loads. Message-ID: <5f3b3d06368a1_80b3f842731681c849242c@gitlab.haskell.org.mail> Moritz Angermann pushed to branch wip/angerman/aarch64-ncg at Glasgow Haskell Compiler / GHC Commits: cf52b0a1 by Moritz Angermann at 2020-08-18T02:29:12+00:00 Revert the Spill/Reload fix; undo :got: loads. This breaks dynamic, however we can build a working stage2 compiler with the following mk/build.mk BuildFlavour = quick ifneq "$(BuildFlavour)" "" include mk/flavours/$(BuildFlavour).mk endif STRIP_CMD = : DYNAMIC_BY_DEFAULT = NO DYNAMIC_GHC_PROGRAMS = NO - - - - - 10 changed files: - compiler/GHC/CmmToAsm/AArch64/Instr.hs - compiler/GHC/CmmToAsm/AArch64/Ppr.hs - compiler/GHC/CmmToAsm/Instr.hs - compiler/GHC/CmmToAsm/PPC/Instr.hs - compiler/GHC/CmmToAsm/Reg/Linear.hs - compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs - compiler/GHC/CmmToAsm/Reg/Linear/State.hs - compiler/GHC/CmmToAsm/Reg/Liveness.hs - compiler/GHC/CmmToAsm/SPARC/Instr.hs - compiler/GHC/CmmToAsm/X86/Instr.hs Changes: ===================================== compiler/GHC/CmmToAsm/AArch64/Instr.hs ===================================== @@ -1,5 +1,4 @@ - -{-# language CPP #-} +{-# language CPP, BangPatterns #-} module GHC.CmmToAsm.AArch64.Instr @@ -342,28 +341,47 @@ aarch64_mkSpillInstr -> Reg -- register to spill -> Int -- current stack delta -> Int -- spill slot to use - -> (Int, [Instr]) + -> Instr -- XXX this is stupid. We essentially do sp <- sp - 4095; str xN, [sp - ...] ; sp <- sp + 4095 +{- aarch64_mkSpillInstr config reg delta slot | (spillSlotToOffset config slot) - delta > 4095 - = let (d, isns) = aarch64_mkSpillInstr config reg (delta + 4095) slot - in (d, SUB sp sp (OpImm (ImmInt 4095)) : isns ++ [ADD sp sp (OpImm (ImmInt 4095))]) + = let (!d, !isns) = traceShow msg $ aarch64_mkSpillInstr config reg (delta + delta') slot + in traceShow "Spill(1) ret" (d, subIsn : isns ++ [addIsn]) + where delta' = 4095 + !addIsn = ADD sp sp (OpImm (ImmInt delta')) + !subIsn = SUB sp sp (OpImm (ImmInt delta')) + msg = "Spill(1): " ++ show (spillSlotToOffset config slot) ++ "; Delta: " ++ show delta ++ " -> " ++ show (delta + delta') aarch64_mkSpillInstr config reg delta slot | (spillSlotToOffset config slot) - delta > 255 - = let (d, isns) = aarch64_mkSpillInstr config reg (delta + delta') slot - in (d, SUB sp sp (OpImm (ImmInt delta')) : isns ++ [ADD sp sp (OpImm (ImmInt delta'))]) + = let (!d, !isns) = traceShow msg $ aarch64_mkSpillInstr config reg (delta + delta') slot + in traceShow "Spill(2) ret" (d, subIsn : isns ++ [addIsn]) where delta' = (spillSlotToOffset config slot) - delta + !addIsn = ADD sp sp (OpImm (ImmInt delta')) + !subIsn = SUB sp sp (OpImm (ImmInt delta')) + msg = "Spill(2): " ++ show (spillSlotToOffset config slot) ++ "; Delta: " ++ show delta ++ " -> " ++ show (delta + delta') aarch64_mkSpillInstr config reg delta slot | (spillSlotToOffset config slot) - delta < -4095 - = let (d, isns) = aarch64_mkSpillInstr config reg (delta - 4095) slot - in (d, ADD sp sp (OpImm (ImmInt 4095)) : isns ++ [SUB sp sp (OpImm (ImmInt 4095))]) + = let (!d, !isns) = traceShow msg $ aarch64_mkSpillInstr config reg (delta - delta') slot + in traceShow "Spill(3) ret" (d, addIsn : isns ++ [subIsn]) + where delta' = 4095 + !addIsn = ADD sp sp (OpImm (ImmInt delta')) + !subIsn = SUB sp sp (OpImm (ImmInt delta')) + msg = "Spill(3): " ++ show (spillSlotToOffset config slot) ++ "; Delta: " ++ show delta ++ " -> " ++ show (delta + delta') aarch64_mkSpillInstr config reg delta slot | (spillSlotToOffset config slot) - delta < -256 - = let (d, isns) = aarch64_mkSpillInstr config reg (delta + delta') slot - in (d, SUB sp sp (OpImm (ImmInt delta')) : isns ++ [ADD sp sp (OpImm (ImmInt delta'))]) + = let (!d, !isns) = traceShow msg $ aarch64_mkSpillInstr config reg (delta + delta') slot + in traceShow "Spill(4) ret" (d, subIsn : isns ++ [addIsn]) where delta' = (spillSlotToOffset config slot) - delta - + !addIsn = ADD sp sp (OpImm (ImmInt delta')) + !subIsn = SUB sp sp (OpImm (ImmInt delta')) + msg = "Spill(4): " ++ show (spillSlotToOffset config slot) ++ "; Delta: " ++ show delta ++ " -> " ++ show (delta + delta') +-} aarch64_mkSpillInstr config reg delta slot - = (delta, [ANN (text "Spill") $ STR fmt (OpReg W64 reg) (OpAddr (AddrRegImm (regSingle 31) (ImmInt $ off - delta)))]) + = --[ + -- ANN (text "Spill") $ + -- traceShow ("Spill: " ++ show (off - delta)) $ + STR fmt (OpReg W64 reg) (OpAddr (AddrRegImm (regSingle 31) (ImmInt $ off - delta))) + --] where fmt = case reg of RegReal (RealRegSingle n) | n < 32 -> II64 @@ -375,29 +393,40 @@ aarch64_mkLoadInstr -> Reg -- register to load -> Int -- current stack delta -> Int -- spill slot to use - -> (Int, [Instr]) + -> Instr -- XXX this is stupid. We essentially do sp <- sp - 4095; str xN, [sp - ...] ; sp <- sp + 4095 +{- aarch64_mkLoadInstr config reg delta slot | (spillSlotToOffset config slot) - delta > 4095 - = let (d, isns) = aarch64_mkLoadInstr config reg (delta + 4095) slot - in (d, SUB sp sp (OpImm (ImmInt 4095)) : isns ++ [ADD sp sp (OpImm (ImmInt 4095))]) + = let (!d, !isns) = traceShow msg $ aarch64_mkLoadInstr config reg (delta + delta') slot + in traceShow "Reload(1) ret" (d, SUB sp sp (OpImm (ImmInt 4095)) : isns ++ [ADD sp sp (OpImm (ImmInt 4095))]) + where delta' = 4095 + msg = "Reload(1): " ++ show (spillSlotToOffset config slot) ++ "; Delta: " ++ show delta ++ " -> " ++ show (delta + delta') aarch64_mkLoadInstr config reg delta slot | (spillSlotToOffset config slot) - delta > 255 - = let (d, isns) = aarch64_mkLoadInstr config reg (delta + delta') slot - in (d, SUB sp sp (OpImm (ImmInt delta')) : isns ++ [ADD sp sp (OpImm (ImmInt delta'))]) + = let (!d, !isns) = traceShow msg $ aarch64_mkLoadInstr config reg (delta + delta') slot + in traceShow "Reload(2) ret" (d, SUB sp sp (OpImm (ImmInt delta')) : isns ++ [ADD sp sp (OpImm (ImmInt delta'))]) where delta' = (spillSlotToOffset config slot) - delta + msg = "Reload(2): " ++ show (spillSlotToOffset config slot) ++ "; Delta: " ++ show delta ++ " -> " ++ show (delta + delta') aarch64_mkLoadInstr config reg delta slot | (spillSlotToOffset config slot) - delta < -4095 - = let (d, isns) = aarch64_mkLoadInstr config reg (delta - 4095) slot - in (d, ADD sp sp (OpImm (ImmInt 4095)) : isns ++ [SUB sp sp (OpImm (ImmInt 4095))]) + = let (!d, !isns) = traceShow msg $ aarch64_mkLoadInstr config reg (delta + delta') slot + in traceShow "Reload(3) ret" (d, ADD sp sp (OpImm (ImmInt 4095)) : isns ++ [SUB sp sp (OpImm (ImmInt 4095))]) + where delta' = -4095 + msg = "Reload(3): " ++ show (spillSlotToOffset config slot) ++ "; Delta: " ++ show delta ++ " -> " ++ show (delta + delta') aarch64_mkLoadInstr config reg delta slot | (spillSlotToOffset config slot) - delta < -256 - = let (d, isns) = aarch64_mkLoadInstr config reg (delta + delta') slot - in (d, SUB sp sp (OpImm (ImmInt delta')) : isns ++ [ADD sp sp (OpImm (ImmInt delta'))]) + = let (!d, !isns) = traceShow msg $ aarch64_mkLoadInstr config reg (delta + delta') slot + in traceShow "Reload(4) ret" (d, SUB sp sp (OpImm (ImmInt delta')) : isns ++ [ADD sp sp (OpImm (ImmInt delta'))]) where delta' = (spillSlotToOffset config slot) - delta + msg = "Reload(4): " ++ show (spillSlotToOffset config slot) ++ "; Delta: " ++ show delta ++ " -> " ++ show (delta + delta') - +-} aarch64_mkLoadInstr config reg delta slot - = (delta, [ANN (text "Reload") $ LDR fmt (OpReg W64 reg) (OpAddr (AddrRegImm (regSingle 31) (ImmInt $ off - delta)))]) + = --[ + -- ANN (text "Reload") $ + -- traceShow ("Reload: " ++ show (off - delta)) $ + LDR fmt (OpReg W64 reg) (OpAddr (AddrRegImm (regSingle 31) (ImmInt $ off - delta))) + -- ] where fmt = case reg of RegReal (RealRegSingle n) | n < 32 -> II64 ===================================== compiler/GHC/CmmToAsm/AArch64/Ppr.hs ===================================== @@ -449,9 +449,9 @@ pprInstr platform instr = case instr of -- 4. Branch Instructions ---------------------------------------------------- J t -> pprInstr platform (B t) - B (TBlock bid) -> text "\tb" <+> ppr (mkLocalBlockLabel (getUnique bid)) - B (TLabel lbl) -> text "\tb" <+> ppr lbl - B (TReg r) -> text "\tbr" <+> pprReg W64 r + B (TBlock bid) -> text "\tbl" <+> ppr (mkLocalBlockLabel (getUnique bid)) + B (TLabel lbl) -> text "\tbl" <+> ppr lbl + B (TReg r) -> text "\tblr" <+> pprReg W64 r BL (TBlock bid) -> text "\tbl" <+> ppr (mkLocalBlockLabel (getUnique bid)) BL (TLabel lbl) -> text "\tbl" <+> ppr lbl @@ -483,22 +483,22 @@ pprInstr platform instr = case instr of text "\tstrh" <+> pprOp o1 <> comma <+> pprOp o2 STR f o1 o2 -> text "\tstr" <+> pprOp o1 <> comma <+> pprOp o2 - -- LDR f o1 (OpImm (ImmIndex lbl off)) -> - -- text "\tadrp" <+> pprOp o1 <> comma <+> ppr lbl $$ - -- text "\tadd" <+> pprOp o1 <> comma <+> pprOp o1 <> comma <+> text ":lo12:" <> ppr lbl $$ - -- text "\tadd" <+> pprOp o1 <> comma <+> pprOp o1 <> comma <+> char '#' <> int off -- XXX: check that off is in 12bits. - -- always GOT loads LDR f o1 (OpImm (ImmIndex lbl off)) -> - text "\tadrp" <+> pprOp o1 <> comma <+> text ":got:" <> ppr lbl $$ - text "\tldr" <+> pprOp o1 <> comma <+> text "[" <> pprOp o1 <> comma <+> text":got_lo12:" <> ppr lbl <> text "]" $$ + text "\tadrp" <+> pprOp o1 <> comma <+> ppr lbl $$ + text "\tadd" <+> pprOp o1 <> comma <+> pprOp o1 <> comma <+> text ":lo12:" <> ppr lbl $$ text "\tadd" <+> pprOp o1 <> comma <+> pprOp o1 <> comma <+> char '#' <> int off -- XXX: check that off is in 12bits. + -- always GOT loads + -- LDR f o1 (OpImm (ImmIndex lbl off)) -> + -- text "\tadrp" <+> pprOp o1 <> comma <+> text ":got:" <> ppr lbl $$ + -- text "\tldr" <+> pprOp o1 <> comma <+> text "[" <> pprOp o1 <> comma <+> text":got_lo12:" <> ppr lbl <> text "]" $$ + -- text "\tadd" <+> pprOp o1 <> comma <+> pprOp o1 <> comma <+> char '#' <> int off -- XXX: check that off is in 12bits. - -- LDR f o1 (OpImm (ImmCLbl lbl)) -> - -- text "\tadrp" <+> pprOp o1 <> comma <+> ppr lbl $$ - -- text "\tadd" <+> pprOp o1 <> comma <+> pprOp o1 <> comma <+> text ":lo12:" <> ppr lbl LDR f o1 (OpImm (ImmCLbl lbl)) -> - text "\tadrp" <+> pprOp o1 <> comma <+> text ":got:" <> ppr lbl $$ - text "\tldr" <+> pprOp o1 <> comma <+> text "[" <> pprOp o1 <> comma <+> text":got_lo12:" <> ppr lbl <> text "]" + text "\tadrp" <+> pprOp o1 <> comma <+> ppr lbl $$ + text "\tadd" <+> pprOp o1 <> comma <+> pprOp o1 <> comma <+> text ":lo12:" <> ppr lbl + -- LDR f o1 (OpImm (ImmCLbl lbl)) -> + -- text "\tadrp" <+> pprOp o1 <> comma <+> text ":got:" <> ppr lbl $$ + -- text "\tldr" <+> pprOp o1 <> comma <+> text "[" <> pprOp o1 <> comma <+> text":got_lo12:" <> ppr lbl <> text "]" LDR f o1@(OpReg W8 (RegReal (RealRegSingle i))) o2 | i < 32 -> text "\tldrsb" <+> pprOp o1 <> comma <+> pprOp o2 ===================================== compiler/GHC/CmmToAsm/Instr.hs ===================================== @@ -141,7 +141,7 @@ class Instruction instr where -> Reg -- ^ the reg to spill -> Int -- ^ the current stack delta -> Int -- ^ spill slot to use - -> (Int, [instr]) -- ^ (new stack delta, instruction) + -> instr -- ^ instructions -- | An instruction to reload a register from a spill slot. @@ -150,7 +150,7 @@ class Instruction instr where -> Reg -- ^ the reg to reload. -> Int -- ^ the current stack delta -> Int -- ^ the spill slot to use - -> (Int, [instr]) -- ^ (new stack delta, instruction) + -> instr -- ^ instructions -- | See if this instruction is telling us the current C stack delta takeDeltaInstr ===================================== compiler/GHC/CmmToAsm/PPC/Instr.hs ===================================== @@ -541,7 +541,7 @@ ppc_mkSpillInstr -> Reg -- register to spill -> Int -- current stack delta -> Int -- spill slot to use - -> (Int, [Instr]) + -> Instr ppc_mkSpillInstr config reg delta slot = let platform = ncgPlatform config @@ -558,7 +558,7 @@ ppc_mkSpillInstr config reg delta slot Just _ -> ST Nothing -> STFAR -- pseudo instruction: 32 bit offsets - in (delta, [instr fmt reg (AddrRegImm sp (ImmInt (off-delta)))]) + in instr fmt reg (AddrRegImm sp (ImmInt (off-delta))) ppc_mkLoadInstr @@ -566,7 +566,7 @@ ppc_mkLoadInstr -> Reg -- register to load -> Int -- current stack delta -> Int -- spill slot to use - -> (Int, [Instr]) + -> Instr ppc_mkLoadInstr config reg delta slot = let platform = ncgPlatform config @@ -583,7 +583,7 @@ ppc_mkLoadInstr config reg delta slot Just _ -> LD Nothing -> LDFAR -- pseudo instruction: 32 bit offsets - in (delta, [instr fmt reg (AddrRegImm sp (ImmInt (off-delta)))]) + in instr fmt reg (AddrRegImm sp (ImmInt (off-delta))) -- | The size of a minimal stackframe header including minimal ===================================== compiler/GHC/CmmToAsm/Reg/Linear.hs ===================================== @@ -701,7 +701,7 @@ saveClobberedTemps clobbered dying let new_assign = addToUFM assig temp (InBoth reg slot) - clobber new_assign (spill ++ instrs) rest + clobber new_assign (spill : instrs) rest @@ -922,7 +922,7 @@ allocRegsAndSpill_spill reading keep spills alloc r rs assig spill_loc (spill_insn, slot) <- spillR (RegReal my_reg) temp_to_push_out let spill_store = (if reading then id else reverse) -- COMMENT (fsLit "spill alloc"): - spill_insn + [spill_insn] -- record that this temp was spilled recordSpill (SpillAlloc temp_to_push_out) @@ -972,7 +972,7 @@ loadTemp vreg (ReadMem slot) hreg spills = do insn <- loadR (RegReal hreg) slot recordSpill (SpillLoad $ getUnique vreg) - return $ {- COMMENT (fsLit "spill load") : -} insn ++ spills + return $ {- COMMENT (fsLit "spill load") : -} insn : spills loadTemp _ _ _ spills = return spills ===================================== compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs ===================================== @@ -28,8 +28,6 @@ import GHC.Types.Unique import GHC.Types.Unique.FM import GHC.Types.Unique.Set -import GHC.Utils.Monad (concatMapM) - -- | For a jump instruction at the end of a block, generate fixup code so its -- vregs are in the correct regs for its destination. -- @@ -306,7 +304,7 @@ handleComponent -- go via a spill slot. -- handleComponent delta _ (AcyclicSCC (DigraphNode vreg src dsts)) - = concatMapM (makeMove delta vreg src) dsts + = mapM (makeMove delta vreg src) dsts -- Handle some cyclic moves. @@ -340,7 +338,7 @@ handleComponent delta instr -- make sure to do all the reloads after all the spills, -- so we don't end up clobbering the source values. - return (instrSpill ++ concat remainingFixUps ++ instrLoad) + return ([instrSpill] ++ concat remainingFixUps ++ [instrLoad]) handleComponent _ _ (CyclicSCC _) = panic "Register Allocator: handleComponent cyclic" @@ -354,28 +352,22 @@ makeMove -> Unique -- ^ unique of the vreg that we're moving. -> Loc -- ^ source location. -> Loc -- ^ destination location. - -> RegM freeRegs [instr] -- ^ move instruction. + -> RegM freeRegs instr -- ^ move instruction. -makeMove _ vreg src dst +makeMove delta vreg src dst = do config <- getConfig let platform = ncgPlatform config case (src, dst) of (InReg s, InReg d) -> do recordSpill (SpillJoinRR vreg) - return $ [mkRegRegMoveInstr platform (RegReal s) (RegReal d)] + return $ mkRegRegMoveInstr platform (RegReal s) (RegReal d) (InMem s, InReg d) -> do recordSpill (SpillJoinRM vreg) - delta <- getDeltaR - let (new_delta, instrs) = mkLoadInstr config (RegReal d) delta s - setDeltaR new_delta - return instrs + return $ mkLoadInstr config (RegReal d) delta s (InReg s, InMem d) -> do recordSpill (SpillJoinRM vreg) - delta <- getDeltaR - let (new_delta, instrs) = mkSpillInstr config (RegReal s) delta d - setDeltaR new_delta - return instrs + return $ mkSpillInstr config (RegReal s) delta d _ -> -- we don't handle memory to memory moves. -- they shouldn't happen because we don't share ===================================== compiler/GHC/CmmToAsm/Reg/Linear/State.hs ===================================== @@ -127,22 +127,20 @@ makeRAStats state spillR :: Instruction instr - => Reg -> Unique -> RegM freeRegs ([instr], Int) + => Reg -> Unique -> RegM freeRegs (instr, Int) spillR reg temp = RegM $ \s -> let (stack1,slot) = getStackSlotFor (ra_stack s) temp - (new_delta, instrs) = mkSpillInstr (ra_config s) reg (ra_delta s) slot + instr = mkSpillInstr (ra_config s) reg (ra_delta s) slot in - RA_Result s{ra_stack=stack1, ra_delta=new_delta} (instrs,slot) + RA_Result s{ra_stack=stack1} (instr,slot) loadR :: Instruction instr - => Reg -> Int -> RegM freeRegs [instr] + => Reg -> Int -> RegM freeRegs instr loadR reg slot = RegM $ \s -> - let (new_delta, instrs) = mkLoadInstr (ra_config s) reg (ra_delta s) slot - in - RA_Result s{ra_delta=new_delta} instrs + RA_Result s (mkLoadInstr (ra_config s) reg (ra_delta s) slot) getFreeRegsR :: RegM freeRegs freeRegs getFreeRegsR = RegM $ \ s at RA_State{ra_freeregs = freeregs} -> ===================================== compiler/GHC/CmmToAsm/Reg/Liveness.hs ===================================== @@ -529,15 +529,11 @@ stripLiveBlock config (BasicBlock i lis) spillNat acc (LiveInstr (SPILL reg slot) _ : instrs) = do delta <- get - let (new_delta, instrs') = mkSpillInstr config reg delta slot - put new_delta - spillNat (instrs' ++ acc) instrs + spillNat (mkSpillInstr config reg delta slot : acc) instrs spillNat acc (LiveInstr (RELOAD slot reg) _ : instrs) = do delta <- get - let (new_delta, instrs') = mkLoadInstr config reg delta slot - put new_delta - spillNat (instrs' ++ acc) instrs + spillNat (mkLoadInstr config reg delta slot : acc) instrs spillNat acc (LiveInstr (Instr instr) _ : instrs) | Just i <- takeDeltaInstr instr ===================================== compiler/GHC/CmmToAsm/SPARC/Instr.hs ===================================== @@ -373,7 +373,7 @@ sparc_mkSpillInstr -> Reg -- ^ register to spill -> Int -- ^ current stack delta -> Int -- ^ spill slot to use - -> (Int, [Instr]) + -> Instr sparc_mkSpillInstr config reg delta slot = let platform = ncgPlatform config @@ -384,7 +384,7 @@ sparc_mkSpillInstr config reg delta slot RcFloat -> FF32 RcDouble -> FF64 - in (delta, [ST fmt reg (fpRel (negate off_w))]) + in ST fmt reg (fpRel (negate off_w)) -- | Make a spill reload instruction. @@ -393,7 +393,7 @@ sparc_mkLoadInstr -> Reg -- ^ register to load into -> Int -- ^ current stack delta -> Int -- ^ spill slot to use - -> (Int, [Instr]) + -> Instr sparc_mkLoadInstr config reg delta slot = let platform = ncgPlatform config @@ -404,7 +404,7 @@ sparc_mkLoadInstr config reg delta slot RcFloat -> FF32 RcDouble -> FF64 - in (delta, [LD fmt (fpRel (- off_w)) reg]) + in LD fmt (fpRel (- off_w)) reg -------------------------------------------------------------------------------- ===================================== compiler/GHC/CmmToAsm/X86/Instr.hs ===================================== @@ -668,15 +668,15 @@ x86_mkSpillInstr -> Reg -- register to spill -> Int -- current stack delta -> Int -- spill slot to use - -> (Int, [Instr]) + -> Instr x86_mkSpillInstr config reg delta slot = let off = spillSlotToOffset platform slot - delta in case targetClassOfReg platform reg of - RcInteger -> (delta, [MOV (archWordFormat is32Bit) - (OpReg reg) (OpAddr (spRel platform off))]) - RcDouble -> (delta, [MOV FF64 (OpReg reg) (OpAddr (spRel platform off))]) + RcInteger -> MOV (archWordFormat is32Bit) + (OpReg reg) (OpAddr (spRel platform off)) + RcDouble -> MOV FF64 (OpReg reg) (OpAddr (spRel platform off)) _ -> panic "X86.mkSpillInstr: no match" where platform = ncgPlatform config is32Bit = target32Bit platform @@ -687,15 +687,15 @@ x86_mkLoadInstr -> Reg -- register to load -> Int -- current stack delta -> Int -- spill slot to use - -> (Int, [Instr]) + -> Instr x86_mkLoadInstr config reg delta slot = let off = spillSlotToOffset platform slot - delta in case targetClassOfReg platform reg of - RcInteger -> (delta, [MOV (archWordFormat is32Bit) - (OpAddr (spRel platform off)) (OpReg reg)]) - RcDouble -> (delta, [MOV FF64 (OpAddr (spRel platform off)) (OpReg reg)]) + RcInteger -> MOV (archWordFormat is32Bit) + (OpAddr (spRel platform off)) (OpReg reg) + RcDouble -> MOV FF64 (OpAddr (spRel platform off)) (OpReg reg) _ -> panic "X86.x86_mkLoadInstr" where platform = ncgPlatform config is32Bit = target32Bit platform View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cf52b0a164ea3a0406d6aa4e581a24818da03786 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cf52b0a164ea3a0406d6aa4e581a24818da03786 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 04:58:43 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 18 Aug 2020 00:58:43 -0400 Subject: [Git][ghc/ghc] Deleted branch wip/backports Message-ID: <5f3b60036a5ce_80b3f8486298278849682a@gitlab.haskell.org.mail> Ben Gamari deleted branch wip/backports at Glasgow Haskell Compiler / GHC -- You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 04:58:45 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 18 Aug 2020 00:58:45 -0400 Subject: [Git][ghc/ghc][ghc-9.0] 6 commits: Allow unsaturated runRW# applications Message-ID: <5f3b6005affbb_80b3f8495bc8b048497059@gitlab.haskell.org.mail> Ben Gamari pushed to branch ghc-9.0 at Glasgow Haskell Compiler / GHC Commits: 57fd3ff0 by Ben Gamari at 2020-08-16T12:18:11-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. (cherry picked from commit 2f0bae734e2dc8737fbbb8465de7ded89c1121b6) - - - - - 0af2db18 by Ben Gamari at 2020-08-16T12:18:19-04:00 testsuite: Add test for #18291 (cherry picked from commit 6c7785f8e17a43a2578366134f74fd1989077b73) - - - - - 614ac76d by Ben Gamari at 2020-08-17T15:14:35-04:00 Clean up TBDs in changelog (cherry picked from commit 4f334120c8e9cc4aefcbf11d99f169f648af9fde) - - - - - 1a54d708 by Ben Gamari at 2020-08-17T15:14:35-04:00 Bump bytestring submodule - - - - - 20e19811 by Ben Gamari at 2020-08-17T15:14:35-04:00 Bump binary submodule - - - - - 8c7e8e1c by Ben Gamari at 2020-08-17T20:09:30+00:00 Bump Cabal submodule - - - - - 15 changed files: - compiler/GHC/Core/Lint.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/CoreToStg/Prep.hs - libraries/Cabal - libraries/base/changelog.md - libraries/binary - libraries/bytestring - libraries/ghc-prim/GHC/Magic.hs - libraries/template-haskell/changelog.md - + testsuite/tests/codeGen/should_compile/T18291.hs - testsuite/tests/codeGen/should_compile/all.T - utils/check-api-annotations/check-api-annotations.cabal - utils/check-ppr/check-ppr.cabal - utils/ghc-cabal/ghc-cabal.cabal - utils/ghc-cabal/ghc.mk Changes: ===================================== compiler/GHC/Core/Lint.hs ===================================== @@ -729,8 +729,6 @@ lintJoinLams join_arity enforce rhs where go 0 expr = lintCoreExpr expr go n (Lam var body) = lintLambda var $ go (n-1) body - -- N.B. join points can be cast. e.g. we consider ((\x -> ...) `cast` ...) - -- to be a join point at join arity 1. go n expr | Just bndr <- enforce -- Join point with too few RHS lambdas = failWithL $ mkBadJoinArityMsg bndr join_arity n rhs | otherwise -- Future join point, not yet eta-expanded @@ -779,36 +777,26 @@ hurts us here. Note [Linting of runRW#] ~~~~~~~~~~~~~~~~~~~~~~~~ -runRW# has some very peculiar behavior (see Note [runRW magic] in -GHC.CoreToStg.Prep) which CoreLint must accommodate. +runRW# has some very special behavior (see Note [runRW magic] in +GHC.CoreToStg.Prep) which CoreLint must accommodate, by allowing +join points in its argument. For example, this is fine: -As described in Note [Casts and lambdas] in -GHC.Core.Opt.Simplify.Utils, the simplifier pushes casts out of -lambdas. Concretely, the simplifier will transform + join j x = ... + in runRW# (\s. case v of + A -> j 3 + B -> j 4) - runRW# @r @ty (\s -> expr `cast` co) +Usually those calls to the join point 'j' would not be valid tail calls, +because they occur in a function argument. But in the case of runRW# +they are fine, because runRW# (\s.e) behaves operationally just like e. +(runRW# is ultimately inlined in GHC.CoreToStg.Prep.) -into - - runRW# @r @ty ((\s -> expr) `cast` co) - -Consequently we need to handle the case that the continuation is a -cast of a lambda. See Note [Casts and lambdas] in -GHC.Core.Opt.Simplify.Utils. - -In the event that the continuation is headed by a lambda (which -will bind the State# token) we can safely allow calls to join -points since CorePrep is going to apply the continuation to -RealWorld. - -In the case that the continuation is not a lambda we lint the -continuation disallowing join points, to rule out things like, +In the case that the continuation is /not/ a lambda we simply disable this +special behaviour. For example, this is /not/ fine: join j = ... - in runRW# @r @ty ( - let x = jump j - in x - ) + in runRW# @r @ty (jump j) + ************************************************************************ @@ -929,10 +917,6 @@ lintCoreExpr e@(App _ _) ; (fun_ty2, ue2) <- lintCoreArg fun_pair1 arg_ty2 -- See Note [Linting of runRW#] ; let lintRunRWCont :: CoreArg -> LintM (LintedType, UsageEnv) - lintRunRWCont (Cast expr co) = do - (ty, ue) <- lintRunRWCont expr - new_ty <- lintCastExpr expr ty co - return (new_ty, ue) lintRunRWCont expr@(Lam _ _) = do lintJoinLams 1 (Just fun) expr lintRunRWCont other = markAllJoinsBad $ lintCoreExpr other @@ -941,10 +925,6 @@ lintCoreExpr e@(App _ _) ; app_ty <- lintValApp arg3 fun_ty2 arg3_ty ue2 ue3 ; lintCoreArgs app_ty rest } - | Var fun <- fun - , fun `hasKey` runRWKey - = failWithL (text "Invalid runRW# application") - | otherwise = do { pair <- lintCoreFun fun (length args) ; lintCoreArgs pair args } ===================================== compiler/GHC/Core/Opt/Simplify.hs ===================================== @@ -1970,8 +1970,10 @@ rebuildCall env info (ApplyToTy { sc_arg_ty = arg_ty, sc_hole_ty = hole_ty, sc_c = rebuildCall env (addTyArgTo info arg_ty hole_ty) cont ---------- The runRW# rule. Do this after absorbing all arguments ------ +-- See Note [Simplification of runRW#] in GHC.CoreToSTG.Prep. +-- -- runRW# :: forall (r :: RuntimeRep) (o :: TYPE r). (State# RealWorld -> o) -> o --- K[ runRW# rr ty body ] --> runRW rr' ty' (\s. K[ body s ]) +-- K[ runRW# rr ty body ] --> runRW rr' ty' (\s. K[ body s ]) rebuildCall env (ArgInfo { ai_fun = fun_id, ai_args = rev_args }) (ApplyToVal { sc_arg = arg, sc_env = arg_se , sc_cont = cont, sc_hole_ty = fun_ty }) ===================================== compiler/GHC/CoreToStg/Prep.hs ===================================== @@ -721,18 +721,6 @@ instance Outputable ArgInfo where ppr (CpeCast co) = text "cast" <+> ppr co ppr (CpeTick tick) = text "tick" <+> ppr tick -{- - Note [runRW arg] -~~~~~~~~~~~~~~~~~~~ -If we got, say - runRW# (case bot of {}) -which happened in #11291, we do /not/ want to turn it into - (case bot of {}) realWorldPrimId# -because that gives a panic in CoreToStg.myCollectArgs, which expects -only variables in function position. But if we are sure to make -runRW# strict (which we do in GHC.Types.Id.Make), this can't happen --} - cpeApp :: CorePrepEnv -> CoreExpr -> UniqSM (Floats, CpeRhs) -- May return a CpeRhs because of saturating primops cpeApp top_env expr @@ -798,10 +786,6 @@ cpeApp top_env expr _ -> cpe_app env arg (CpeApp (Var realWorldPrimId) : rest) (n-1) -- TODO: What about casts? - cpe_app _env (Var f) args n - | f `hasKey` runRWKey - = pprPanic "cpe_app(runRW#)" (ppr args $$ ppr n) - cpe_app env (Var v) args depth = do { v1 <- fiddleCCall v ; let e2 = lookupCorePrepEnv env v1 @@ -923,34 +907,96 @@ optimization (right before lowering to STG, in CorePrep), we can ensure that no further floating will occur. This allows us to safely inline things like @runST@, which are otherwise needlessly expensive (see #10678 and #5916). -'runRW' is defined (for historical reasons) in GHC.Magic, with a NOINLINE -pragma. It is levity-polymorphic. +'runRW' has a variety of quirks: + + * 'runRW' is known-key with a NOINLINE definition in + GHC.Magic. This definition is used in cases where runRW is curried. + + * In addition to its normal Haskell definition in GHC.Magic, we give it + a special late inlining here in CorePrep and GHC.CoreToByteCode, avoiding + the incorrect sharing due to float-out noted above. + + * It is levity-polymorphic: runRW# :: forall (r1 :: RuntimeRep). (o :: TYPE r) => (State# RealWorld -> (# State# RealWorld, o #)) - -> (# State# RealWorld, o #) + -> (# State# RealWorld, o #) + + * It has some special simplification logic to allow unboxing of results when + runRW# appears in a strict context. See Note [Simplification of runRW#] + below. + + * Since its body is inlined, we allow runRW#'s argument to contain jumps to + join points. That is, the following is allowed: + + join j x = ... + in runRW# @_ @_ (\s -> ... jump j 42 ...) + + The Core Linter knows about this. See Note [Linting of runRW#] in + GHC.Core.Lint for details. + + The occurrence analyser and SetLevels also know about this, as described in + Note [Simplification of runRW#]. + +Other relevant Notes: -It's correctness needs no special treatment in GHC except this special inlining -here in CorePrep (and in GHC.CoreToByteCode). + * Note [Simplification of runRW#] below, describing a transformation of runRW + applications in strict contexts performed by the simplifier. + * Note [Linting of runRW#] in GHC.Core.Lint + * Note [runRW arg] below, describing a non-obvious case where the + late-inlining could go wrong. -However, there are a variety of optimisation opportunities that the simplifier -takes advantage of. See Note [Simplification of runRW#]. + + Note [runRW arg] +~~~~~~~~~~~~~~~~~~~ +Consider the Core program (from #11291), + + runRW# (case bot of {}) + +The late inlining logic in cpe_app would transform this into: + + (case bot of {}) realWorldPrimId# + +Which would rise to a panic in CoreToStg.myCollectArgs, which expects only +variables in function position. + +However, as runRW#'s strictness signature captures the fact that it will call +its argument this can't happen: the simplifier will transform the bottoming +application into simply (case bot of {}). + +Note that this reasoning does *not* apply to non-bottoming continuations like: + + hello :: Bool -> Int + hello n = + runRW# ( + case n of + True -> \s -> 23 + _ -> \s -> 10) + +Why? The difference is that (case bot of {}) is considered by okCpeArg to be +trivial, consequently cpeArg (which the catch-all case of cpe_app calls on both +the function and the arguments) will forgo binding it to a variable. By +contrast, in the non-bottoming case of `hello` above the function will be +deemed non-trivial and consequently will be case-bound. Note [Simplification of runRW#] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Consider the program, - case runRW# (\s -> let n = I# 42# in n) of + case runRW# (\s -> I# 42#) of I# n# -> f n# There is no reason why we should allocate an I# constructor given that we -immediately destructure it. To avoid this the simplifier will push strict -contexts into runRW's continuation. That is, it transforms +immediately destructure it. + +To avoid this the simplifier has a special transformation rule, specific to +runRW#, that pushes a strict context into runRW#'s continuation. See the +`runRW#` guard in `GHC.Core.Opt.Simplify.rebuildCall`. That is, it transforms K[ runRW# @r @ty cont ] ~> - runRW# @r @ty K[cont] + runRW# @r @ty (\s -> K[cont s]) This has a few interesting implications. Consider, for instance, this program: @@ -969,15 +1015,29 @@ Performing the transform described above would result in: If runRW# were a "normal" function this call to join point j would not be allowed in its continuation argument. However, since runRW# is inlined (as described in Note [runRW magic] above), such join point occurences are -completely fine. Both occurrence analysis and Core Lint have special treatment -for runRW# applications. See Note [Linting of runRW#] for details on the latter. +completely fine. Both occurrence analysis (see the runRW guard in occAnalApp) +and Core Lint (see the App case of lintCoreExpr) have special treatment for +runRW# applications. See Note [Linting of runRW#] for details on the latter. Moreover, it's helpful to ensure that runRW's continuation isn't floated out -(since doing so would then require a call, whereas we would otherwise end up -with straight-line). Consequently, GHC.Core.Opt.SetLevels.lvlApp has special -treatment for runRW# applications, ensure the arguments are not floated if +For instance, if we have + + runRW# (\s -> do_something) + +where do_something contains only top-level free variables, we may be tempted to +float the argument to the top-level. However, we must resist this urge as since +doing so would then require that runRW# produce an allocation and call, e.g.: + + let lvl = \s -> do_somethign + in + ....(runRW# lvl).... + +whereas without floating the inlining of the definition of runRW would result +in straight-line code. Consequently, GHC.Core.Opt.SetLevels.lvlApp has special +treatment for runRW# applications, ensure the arguments are not floated as MFEs. + Other considered designs ------------------------ ===================================== libraries/Cabal ===================================== @@ -1 +1 @@ -Subproject commit 32dad5c1cf70d65ecb93b0ec214445cf9c9f6615 +Subproject commit 1d886476c443b227bf93eba62781a6cad5012d9e ===================================== libraries/base/changelog.md ===================================== @@ -30,7 +30,7 @@ * Add `Ix` instances for tuples of size 6 through 15 -## 4.14.0.0 *TBA* +## 4.14.0.0 *Jan 2020 * Bundled with GHC 8.10.1 * Add a `TestEquality` instance for the `Compose` newtype. @@ -322,7 +322,7 @@ in constant space when applied to lists. (#10830) * `mkFunTy`, `mkAppTy`, and `mkTyConApp` from `Data.Typeable` no longer exist. - This functionality is superseded by the interfaces provided by + This functionality is superceded by the interfaces provided by `Type.Reflection`. * `mkTyCon3` is no longer exported by `Data.Typeable`. This function is ===================================== libraries/binary ===================================== @@ -1 +1 @@ -Subproject commit dfaf780596328c9184758452b78288e8f405fcc1 +Subproject commit f9b1c92a2ff34cc3457fa27faf3e16b8203b4b9f ===================================== libraries/bytestring ===================================== @@ -1 +1 @@ -Subproject commit e6cb01e2ec0bfdd19298418c85f220925a9fa307 +Subproject commit e043aacfc4202a59ccae8b8c8cf0e1ad83a3f209 ===================================== libraries/ghc-prim/GHC/Magic.hs ===================================== @@ -122,7 +122,7 @@ oneShot f = f runRW# :: forall (r :: RuntimeRep) (o :: TYPE r). (State# RealWorld -> o) -> o --- See Note [runRW magic] in CorePrep +-- See Note [runRW magic] in GHC.CoreToStg.Prep. {-# NOINLINE runRW# #-} -- runRW# is inlined manually in CorePrep #if !defined(__HADDOCK_VERSION__) runRW# m = m realWorld# ===================================== libraries/template-haskell/changelog.md ===================================== @@ -34,7 +34,9 @@ * The argument to `TExpQ` can now be levity polymorphic. -## 2.16.0.0 *TBA* +## 2.16.0.0 *Jan 2020* + + * Bundled with GHC 8.10.1 * Add support for tuple sections. (#15843) The type signatures of `TupE` and `UnboxedTupE` have changed from `[Exp] -> Exp` to `[Maybe Exp] -> Exp`. @@ -58,6 +60,8 @@ ## 2.15.0.0 *May 2019* + * Bundled with GHC 8.8.1 + * In `Language.Haskell.TH.Syntax`, `DataInstD`, `NewTypeInstD`, `TySynEqn`, and `RuleP` now all have a `Maybe [TyVarBndr]` argument, which contains a list of quantified type variables if an explicit `forall` is present, and @@ -80,6 +84,8 @@ ## 2.14.0.0 *September 2018* + * Bundled with GHC 8.6.1 + * Introduce an `addForeignFilePath` function, as well as a corresponding `qAddForeignFile` class method to `Quasi`. Unlike `addForeignFile`, which takes the contents of the file as an argument, `addForeignFilePath` takes ===================================== testsuite/tests/codeGen/should_compile/T18291.hs ===================================== @@ -0,0 +1,7 @@ +{-# LANGUAGE MagicHash #-} +module T18291 where + +import GHC.Magic + +hi :: Int +hi = runRW# $ \_ -> 42 ===================================== testsuite/tests/codeGen/should_compile/all.T ===================================== @@ -91,6 +91,7 @@ test('T17648', normal, makefile_test, []) test('T17904', normal, compile, ['-O']) test('T18227A', normal, compile, ['']) test('T18227B', normal, compile, ['']) +test('T18291', normal, compile, ['-O0']) test('T15570', when(unregisterised(), skip), compile, ['-Wno-overflowed-literals']) ===================================== utils/check-api-annotations/check-api-annotations.cabal ===================================== @@ -24,6 +24,6 @@ Executable check-api-annotations Build-Depends: base >= 4 && < 5, containers, - Cabal >= 3.0 && < 3.4, + Cabal >= 3.0 && < 3.6, directory, ghc ===================================== utils/check-ppr/check-ppr.cabal ===================================== @@ -25,7 +25,7 @@ Executable check-ppr Build-Depends: base >= 4 && < 5, bytestring, containers, - Cabal >= 3.0 && < 3.4, + Cabal >= 3.0 && < 3.6, directory, filepath, ghc ===================================== utils/ghc-cabal/ghc-cabal.cabal ===================================== @@ -21,6 +21,6 @@ Executable ghc-cabal Build-Depends: base >= 3 && < 5, bytestring >= 0.10 && < 0.11, - Cabal >= 3.0 && < 3.4, + Cabal >= 3.2 && < 3.6, directory >= 1.1 && < 1.4, filepath >= 1.2 && < 1.5 ===================================== utils/ghc-cabal/ghc.mk ===================================== @@ -37,25 +37,13 @@ ifneq "$(BINDIST)" "YES" $(ghc-cabal_INPLACE) : $(ghc-cabal_DIST_BINARY) | $$(dir $$@)/. "$(CP)" $< $@ -# Minor hack, since we can't reuse the `hs-suffix-rules-srcdir` macro -ifneq ($(wildcard libraries/Cabal/Cabal/Distribution/Fields/Lexer.x),) -# Lexer.x exists so we have to call Alex ourselves -CABAL_LEXER_DEP := bootstrapping/Cabal/Distribution/Fields/Lexer.hs - -bootstrapping/Cabal/Distribution/Fields/Lexer.hs: libraries/Cabal/Cabal/Distribution/Fields/Lexer.x - mkdir -p bootstrapping/Cabal/Distribution/Fields - $(call cmd,ALEX) $< -o $@ -else -CABAL_LEXER_DEP := libraries/Cabal/Cabal/Distribution/Fields/Lexer.hs -endif - -$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*/*/*.hs) -$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*/*.hs) -$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*.hs) +$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/src/Distribution/*/*/*.hs) +$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/src/Distribution/*/*.hs) +$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/src/Distribution/*.hs) # N.B. Compile with -O0 since this is not a performance-critical executable # and the Cabal takes nearly twice as long to build with -O1. See #16817. -$(ghc-cabal_DIST_BINARY): $(CABAL_LEXER_DEP) utils/ghc-cabal/Main.hs $(TOUCH_DEP) | $$(dir $$@)/. bootstrapping/. +$(ghc-cabal_DIST_BINARY): utils/ghc-cabal/Main.hs $(TOUCH_DEP) | $$(dir $$@)/. bootstrapping/. "$(GHC)" $(SRC_HC_OPTS) \ $(addprefix -optc, $(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE0)) \ $(addprefix -optl, $(SRC_LD_OPTS) $(CONF_GCC_LINKER_OPTS_STAGE0)) \ @@ -69,8 +57,7 @@ $(ghc-cabal_DIST_BINARY): $(CABAL_LEXER_DEP) utils/ghc-cabal/Main.hs $(TOUCH_DEP -DBOOTSTRAPPING \ -odir bootstrapping \ -hidir bootstrapping \ - $(CABAL_LEXER_DEP) \ - -ilibraries/Cabal/Cabal \ + -ilibraries/Cabal/Cabal/src \ -ilibraries/binary/src \ -ilibraries/filepath \ -ilibraries/hpc \ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ce32390cd4221e2721c18f89bd6d08e3b8b884dc...8c7e8e1c802791dda0f1d30c7658c995a8349c51 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ce32390cd4221e2721c18f89bd6d08e3b8b884dc...8c7e8e1c802791dda0f1d30c7658c995a8349c51 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 07:22:32 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Tue, 18 Aug 2020 03:22:32 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] 35 commits: testsuite: Drop --io-manager flag from testsuite configuration Message-ID: <5f3b81b89f422_80b3f8486b5b7c08501936@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - 4ac72b66 by Matthew Pickering at 2020-08-17T08:32:48+02:00 rts: Implement ghc-debug API (#18405) There are four components to this patch which make it possible to implement `ghc-debug`. 1. Add four new functions to the RtsAPI. * rts_pause and rts_unpause allow an external process to completely pause and unpause the RTS. * rts_listThreads and rts_listMiscRoots are used to find the current roots of the garbage collector. These changes also mean that `Task.h` is exposed to the user. 2. Generalise the `ghc-heap` API so that raw `Word`s can be returned rather than actual objects. This is necessary when trying to decode closures on an external process because the pointers in such closures are correct for the internal rather than external process. If you used the previous API then you would get a segfault as the garbage collector would try to traverse into these nonsensical branches. ``` -- before getClosureData :: a -> IO Closure -- after getClosureDataX :: (forall c . c -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) ``` For the normal case `b` is instantiated to `Box`, which contains a pointer to a heap object. ``` data Box = Box a -- GenClosure Box ``` For `ghc-debug` we instead just take the word of the address as we have to explicitly interpret it on the external process. ``` GenClosure Word ``` 3. Support for decoding `TSO` and `STACK` closures is partially implemented. There is still quite a bit of work to do to finish both but these at least allow us to make some more progress. 4. findPtr is generalised to take a callback argument. This means that its result can be communicated to the debugger rather than just printing out the result. The debugger has a function which invokes `findPtr` and passes a callback which sends the result over a socket. Co-authored-by: Ben Gamari <ben at smart-cactus.org> - - - - - 91057d88 by Sven Tennie at 2020-08-17T08:32:48+02:00 Decode more StgTSO and StgStack fields (#18405) Use hsc2hs to get an understandable and stable mapping from the C structs to Haskell. It's important to keep StgTSO and StgStack decoding downwards compatible. This is especially needed for hadrian/ghci. - - - - - fae266ce by Sven Tennie at 2020-08-17T08:32:48+02:00 Add test for StgTSO decoding (#18405) This makes sure ghc-heap decodes StgTSO and StgStack correctly. To assert - otherwise dynamic - properties, a new, non-running TSO is created in create_tso() (create_tso.c). size is renamed to stack_size to use a dedicated type. size was already defined as a HalfWord in GenClosure, which is only equivalent to Word32 on 64bit architectures. - - - - - 03bd6416 by Sven Tennie at 2020-08-17T08:32:48+02:00 Add documentation to ghc-debug functions (#18405) - - - - - 5a96f25d by Sven Tennie at 2020-08-17T08:32:48+02:00 Adjust type of getClosureX to type of getClosureDataX (#18405) After a rebase the compiler complained: libraries/ghc-heap/GHC/Exts/Heap.hs:89:23: error: • Couldn't match type: a -> IO (Ptr StgInfoTable, [Word], [b]) with: forall c. c -> IO (Ptr StgInfoTable, [Word], [b]) Expected: (forall c. c -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) Actual: (a -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) • In the expression: getClosureX In an equation for ‘getClosureDataX’: getClosureDataX = getClosureX In the instance declaration for ‘HasHeapRep a’ • Relevant bindings include getClosureDataX :: (forall c. c -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) (bound at libraries/ghc-heap/GHC/Exts/Heap.hs:89:5) | 89 | getClosureDataX = getClosureX | ^^^^^^^^^^^ ) - - - - - 93f49862 by Sven Tennie at 2020-08-17T08:32:48+02:00 Add test for rts_pause and rts_unpause (#18405) - - - - - 9368ddfe by Sven Tennie at 2020-08-17T08:32:48+02:00 Add test list_threads_and_misc_roots (#18405) It uses rts_listThreads() and rts_listMiscRoots(). - - - - - c4a4efdd by Sven Tennie at 2020-08-17T08:32:48+02:00 Introduce rts_isPaused() (#18405) Some operations are only save when the RTS is paused. This predicate helps to make such checks. - - - - - 1f0ae63b by Sven Tennie at 2020-08-17T08:32:48+02:00 Decode CostCentreStacks, CostCentres and InfoTables (#18405) - - - - - 8059d205 by Sven Tennie at 2020-08-17T08:32:48+02:00 Use cache and loop breakers for CostCentre, CostCentreStack and IndexTable decoding (#18405) - - - - - aa1d6ac3 by Sven Tennie at 2020-08-17T08:32:48+02:00 Cleanup - - - - - 9083b878 by Sven Tennie at 2020-08-17T08:32:48+02:00 Query caches once, not twice - - - - - 2d5ce49a by Sven Tennie at 2020-08-17T08:32:48+02:00 Fix Haddock for EndTSOQueue - - - - - 1a303bbb by Sven Tennie at 2020-08-17T08:32:48+02:00 Run prof_info test only in prof_ways (#18405) That's the required way for collecting PROFILING data (e.g. CostCentres). - - - - - 044af0f5 by Sven Tennie at 2020-08-17T08:32:48+02:00 Skip WIP test (Red on CI) - - - - - 88b56eae by Sven Tennie at 2020-08-17T08:32:48+02:00 Add missing module to ghc-heap.cabal - - - - - 0f6c75f4 by Sven Tennie at 2020-08-17T08:32:48+02:00 Rearrange #ifdef with GHC version This prevents some "unused" warnings. - - - - - 8144ad9e by Sven Tennie at 2020-08-17T08:32:48+02:00 Fix cpp redefinition warnings With --Werror this made the build fail. - - - - - 6cc475af by Sven Tennie at 2020-08-17T08:32:48+02:00 Add dummy import for PeekProfInfo_ProfilingEnabled for non-profiled builds This circumvents #15197. Otherwise PeekProfInfo_ProfilingEnabled wouldn't be available for make-based builds. - - - - - 248afdea by Sven Tennie at 2020-08-17T08:32:48+02:00 Add assertions to prof_info test (#18405) - - - - - 75d9d2c5 by Sven Tennie at 2020-08-17T08:32:48+02:00 Fix types in tests Use `Ptr ()` instead of `Word` to communicate that addresses/pointers are meant. - - - - - 3eed7e51 by Sven Tennie at 2020-08-17T08:32:48+02:00 Cleanup - - - - - ffa9b577 by Sven Tennie at 2020-08-17T08:32:48+02:00 Introduce LiftedClosure This is a representation for closures that do not have a represantation in the Haskell language. I.e. things like TSOs. - - - - - 0960d594 by Sven Tennie at 2020-08-17T08:32:48+02:00 Fix prof_info test Line number of self defined cost centre changed. - - - - - f0fe17f2 by Sven Tennie at 2020-08-17T08:32:48+02:00 Expect stack_marking starting from GHC 8.10 This field was introduced with GHC 8.10. - - - - - 9aac043f by Sven Tennie at 2020-08-17T08:32:48+02:00 Add WhatNext, WhyBlocked and TsoFlags Additionally extract TestUtils with common test functions. - - - - - 941a9990 by Sven Tennie at 2020-08-17T08:32:48+02:00 Parse TSO flags - - - - - 36b4f8a3 by Sven Tennie at 2020-08-17T08:32:48+02:00 Cache only CostCentres during ProfInfo decoding Looks like caches for CostCentreStacks and IndexTables are not needed. - - - - - 705912c7 by Sven Tennie at 2020-08-17T08:32:48+02:00 Fix warning - - - - - 4df1a44d by Sven Tennie at 2020-08-17T08:32:48+02:00 END_TSO_QUEUE is not a closure type on it's own Indeed it's a CONSTR_NOCAF. - - - - - 3a468673 by Sven Tennie at 2020-08-17T08:32:48+02:00 Delete unused function - - - - - a0bd62e4 by Sven Tennie at 2020-08-17T08:32:48+02:00 Rename boundTaskExiting and getTask (#18405) Both are directly related to myTask, which the new names now reflect. - - - - - 26f2302e by Sven Tennie at 2020-08-18T09:21:07+02:00 Mark unsafe accesses (#18405) StgTSO and StgStack are very dynamic by nature. Accesses to outdated pointers lead to segmentation faults or absolutely wrong results. So, make sure (by naming) that the users nows about these facts. - - - - - 30 changed files: - compiler/GHC/ByteCode/Types.hs - compiler/GHC/Runtime/Interpreter.hs - includes/Rts.h - includes/RtsAPI.h - + includes/rts/Task.h - includes/rts/storage/Heap.h - libraries/ghc-heap/GHC/Exts/Heap.hs - libraries/ghc-heap/GHC/Exts/Heap/ClosureTypes.hs - libraries/ghc-heap/GHC/Exts/Heap/Closures.hs - + libraries/ghc-heap/GHC/Exts/Heap/FFIClosures.hsc - + libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingDisabled.hsc - + libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc - + libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/Types.hs - + libraries/ghc-heap/GHC/Exts/Heap/Ptr/Utils.hs - libraries/ghc-heap/ghc-heap.cabal.in - + libraries/ghc-heap/tests/TestUtils.hs - libraries/ghc-heap/tests/all.T - + libraries/ghc-heap/tests/create_tso.c - + libraries/ghc-heap/tests/create_tso.h - + libraries/ghc-heap/tests/list_threads_and_misc_roots.hs - + libraries/ghc-heap/tests/list_threads_and_misc_roots_c.c - + libraries/ghc-heap/tests/list_threads_and_misc_roots_c.h - + libraries/ghc-heap/tests/parse_tso_flags.hs - + libraries/ghc-heap/tests/prof_info.hs - + libraries/ghc-heap/tests/tso_and_stack_closures.hs - libraries/ghci/GHCi/Message.hs - libraries/ghci/GHCi/Run.hs - llvm-targets - rts/Heap.c - rts/Printer.c The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/78c049b6d52d6d01a6e9184c609a65c1041b8c3b...26f2302e80c4d92f344997b120af5dba0c2fa4f9 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/78c049b6d52d6d01a6e9184c609a65c1041b8c3b...26f2302e80c4d92f344997b120af5dba0c2fa4f9 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 12:40:45 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Tue, 18 Aug 2020 08:40:45 -0400 Subject: [Git][ghc/ghc][wip/buggymcbugfix/arrayOf-primop] 2 commits: Syntax fix Message-ID: <5f3bcc4de29c5_80b3f8486b5b7c0851431b@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed to branch wip/buggymcbugfix/arrayOf-primop at Glasgow Haskell Compiler / GHC Commits: 05a9fb1c by buggymcbugfix at 2020-08-17T20:00:59+02:00 Syntax fix - - - - - cdf7f22d by buggymcbugfix at 2020-08-17T20:01:51+02:00 Point to some useful background information - - - - - 2 changed files: - docs/users_guide/exts/template_haskell.rst - libraries/ghc-prim/GHC/Tuple.hs Changes: ===================================== docs/users_guide/exts/template_haskell.rst ===================================== @@ -115,7 +115,7 @@ The :extension:`TemplateHaskellQuotes` extension is considered safe under -- monad used to build the representation are propagated when using nested -- splices. f :: (Quote m, C m) => m Exp - f = [| 5 | ] + f = [| 5 |] -- f is used in a nested splice so the constraint on f, namely C, is propagated -- to a constraint on the whole representation. @@ -769,5 +769,3 @@ Run "main" and here is your output: $ ./main 3 1 - - ===================================== libraries/ghc-prim/GHC/Tuple.hs ===================================== @@ -5,7 +5,7 @@ -- Module : GHC.Tuple -- Copyright : (c) The University of Glasgow 2001 -- License : BSD-style (see the file libraries/ghc-prim/LICENSE) --- +-- -- Maintainer : libraries at haskell.org -- Stability : experimental -- Portability : non-portable (GHC extensions) @@ -167,6 +167,8 @@ data (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a1,b1,c1,d1,e1,f1,g1,h = (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,n1,o1,p1,q1, r1,s1,t1,u1,v1,w1,x1,y1,z1,a2,b2,c2,d2,e2,f2,g2,h2,i2,j2) +-- [Why are GHC tuples limited to size 62?](https://stackoverflow.com/a/46416136) + {- Manuel says: Including one more declaration gives a segmentation fault. data (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__ k__ = (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__ k__ @@ -238,7 +240,7 @@ data (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, = (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__ k__ l__ m__ n__ o__ p__ q__ r__ s__ t__ u__ v__ w__ x__ y__ z__ a___ b___ c___ d___ e___ f___ g___ h___ i___ j___ k___ l___ m___ n___ o___ p___ q___ r___ data (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__ k__ l__ m__ n__ o__ p__ q__ r__ s__ t__ u__ v__ w__ x__ y__ z__ a___ b___ c___ d___ e___ f___ g___ h___ i___ j___ k___ l___ m___ n___ o___ p___ q___ r___ s___ = (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__ k__ l__ m__ n__ o__ p__ q__ r__ s__ t__ u__ v__ w__ x__ y__ z__ a___ b___ c___ d___ e___ f___ g___ h___ i___ j___ k___ l___ m___ n___ o___ p___ q___ r___ s___ -data (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__ k__ l__ m__ n__ o__ p__ q__ r__ s__ t__ u__ v__ w__ x__ y__ z__ a___ b___ c___ d___ e___ f___ g___ h___ i___ j___ k___ l___ m___ n___ o___ p___ q___ r___ s___ t___ +data (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__ k__ l__ m__ n__ o__ p__ q__ r__ s__ t__ u__ v__ w__ x__ y__ z__ a___ b___ c___ d___ e___ f___ g___ h___ i___ j___ k___ l___ m___ n___ o___ p___ q___ r___ s___ t___ = (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__ k__ l__ m__ n__ o__ p__ q__ r__ s__ t__ u__ v__ w__ x__ y__ z__ a___ b___ c___ d___ e___ f___ g___ h___ i___ j___ k___ l___ m___ n___ o___ p___ q___ r___ s___ t___ data (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__ k__ l__ m__ n__ o__ p__ q__ r__ s__ t__ u__ v__ w__ x__ y__ z__ a___ b___ c___ d___ e___ f___ g___ h___ i___ j___ k___ l___ m___ n___ o___ p___ q___ r___ s___ t___ u___ = (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o p q r s t u v w x y z a_ b_ c_ d_ e_ f_ g_ h_ i_ j_ k_ l_ m_ n_ o_ p_ q_ r_ s_ t_ u_ v_ w_ x_ y_ z_ a__ b__ c__ d__ e__ f__ g__ h__ i__ j__ k__ l__ m__ n__ o__ p__ q__ r__ s__ t__ u__ v__ w__ x__ y__ z__ a___ b___ c___ d___ e___ f___ g___ h___ i___ j___ k___ l___ m___ n___ o___ p___ q___ r___ s___ t___ u___ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9e33d989ff4557bfc495eb3e2d97eccedf8d6b8c...cdf7f22d793e26f2ce0aa022bee1d62a77c34459 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9e33d989ff4557bfc495eb3e2d97eccedf8d6b8c...cdf7f22d793e26f2ce0aa022bee1d62a77c34459 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 14:08:08 2020 From: gitlab at gitlab.haskell.org (David Eichmann) Date: Tue, 18 Aug 2020 10:08:08 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T17747 Message-ID: <5f3be0c8bd928_80b3f842731681c851851a@gitlab.haskell.org.mail> David Eichmann pushed new branch wip/T17747 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T17747 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 14:38:59 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 18 Aug 2020 10:38:59 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 8 commits: testsuite: Drop --io-manager flag from testsuite configuration Message-ID: <5f3be803c7ba_80b3f8486b5b7c0852396f@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - 39fd5279 by Ben Gamari at 2020-08-18T10:38:46-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 7481f277 by Ben Gamari at 2020-08-18T10:38:46-04:00 testsuite: Add test for #18291 - - - - - a0ff7cd7 by Eli Schwartz at 2020-08-18T10:38:48-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - bc966241 by Ben Gamari at 2020-08-18T10:38:48-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - f2d04708 by Ben Gamari at 2020-08-18T10:38:48-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 2330b4b9 by Fendor at 2020-08-18T10:38:50-04:00 Expose UnitInfoMap as it is part of the public API - - - - - 18 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - compiler/GHC/Core/Lint.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/CoreToStg/Prep.hs - compiler/GHC/Unit/State.hs - ghc.mk - hadrian/src/Settings/Builders/RunTest.hs - libraries/ghc-prim/GHC/Magic.hs - llvm-targets - testsuite/driver/perf_notes.py - testsuite/driver/runtests.py - testsuite/driver/testglobals.py - testsuite/driver/testlib.py - testsuite/mk/test.mk - + testsuite/tests/codeGen/should_compile/T18291.hs - testsuite/tests/codeGen/should_compile/all.T - utils/llvm-targets/gen-data-layout.sh Changes: ===================================== .gitlab-ci.yml ===================================== @@ -26,12 +26,28 @@ stages: - testing # head.hackage correctness and compiler performance testing - deploy # push documentation +# Note [The CI Story] +# ~~~~~~~~~~~~~~~~~~~ +# +# There are two different types of pipelines: +# +# - marge-bot merges to `master`. Here we perform an exhaustive validation +# across all of the platforms which we support. In addition, we push +# performance metric notes upstream, providing a persistent record of the +# performance characteristics of the compiler. +# +# - merge requests. Here we perform a slightly less exhaustive battery of +# testing. Namely we omit some configurations (e.g. the unregisterised job). +# These use the merge request's base commit for performance metric +# comparisons. +# + workflow: - # N.B.Don't run on wip/ branches, instead on run on merge requests. + # N.B. Don't run on wip/ branches, instead on run on merge requests. rules: - if: $CI_MERGE_REQUEST_ID - if: $CI_COMMIT_TAG - - if: '$CI_COMMIT_BRANCH == "master"' + - if: '$CI_COMMIT_BRANCH == "wip/marge_bot_batch_merge_job"' - if: '$CI_COMMIT_BRANCH =~ /ghc-[0.9]+\.[0-9]+/' - if: '$CI_PIPELINE_SOURCE == "web"' ===================================== .gitlab/ci.sh ===================================== @@ -363,6 +363,13 @@ function push_perf_notes() { "$TOP/.gitlab/test-metrics.sh" push } +# Figure out which commit should be used by the testsuite driver as a +# performance baseline. See Note [The CI Story]. +function determine_metric_baseline() { + export PERF_BASELINE_COMMIT="$(git merge-base $CI_MERGE_REQUEST_TARGET_BRANCH_NAME HEAD)" + info "Using $PERF_BASELINE_COMMIT for performance metric baseline..." +} + function test_make() { run "$MAKE" test_bindist TEST_PREP=YES run "$MAKE" V=0 test \ ===================================== compiler/GHC/Core/Lint.hs ===================================== @@ -731,8 +731,6 @@ lintJoinLams join_arity enforce rhs where go 0 expr = lintCoreExpr expr go n (Lam var body) = lintLambda var $ go (n-1) body - -- N.B. join points can be cast. e.g. we consider ((\x -> ...) `cast` ...) - -- to be a join point at join arity 1. go n expr | Just bndr <- enforce -- Join point with too few RHS lambdas = failWithL $ mkBadJoinArityMsg bndr join_arity n rhs | otherwise -- Future join point, not yet eta-expanded @@ -781,36 +779,26 @@ hurts us here. Note [Linting of runRW#] ~~~~~~~~~~~~~~~~~~~~~~~~ -runRW# has some very peculiar behavior (see Note [runRW magic] in -GHC.CoreToStg.Prep) which CoreLint must accommodate. +runRW# has some very special behavior (see Note [runRW magic] in +GHC.CoreToStg.Prep) which CoreLint must accommodate, by allowing +join points in its argument. For example, this is fine: -As described in Note [Casts and lambdas] in -GHC.Core.Opt.Simplify.Utils, the simplifier pushes casts out of -lambdas. Concretely, the simplifier will transform + join j x = ... + in runRW# (\s. case v of + A -> j 3 + B -> j 4) - runRW# @r @ty (\s -> expr `cast` co) +Usually those calls to the join point 'j' would not be valid tail calls, +because they occur in a function argument. But in the case of runRW# +they are fine, because runRW# (\s.e) behaves operationally just like e. +(runRW# is ultimately inlined in GHC.CoreToStg.Prep.) -into - - runRW# @r @ty ((\s -> expr) `cast` co) - -Consequently we need to handle the case that the continuation is a -cast of a lambda. See Note [Casts and lambdas] in -GHC.Core.Opt.Simplify.Utils. - -In the event that the continuation is headed by a lambda (which -will bind the State# token) we can safely allow calls to join -points since CorePrep is going to apply the continuation to -RealWorld. - -In the case that the continuation is not a lambda we lint the -continuation disallowing join points, to rule out things like, +In the case that the continuation is /not/ a lambda we simply disable this +special behaviour. For example, this is /not/ fine: join j = ... - in runRW# @r @ty ( - let x = jump j - in x - ) + in runRW# @r @ty (jump j) + ************************************************************************ @@ -931,10 +919,6 @@ lintCoreExpr e@(App _ _) ; (fun_ty2, ue2) <- lintCoreArg fun_pair1 arg_ty2 -- See Note [Linting of runRW#] ; let lintRunRWCont :: CoreArg -> LintM (LintedType, UsageEnv) - lintRunRWCont (Cast expr co) = do - (ty, ue) <- lintRunRWCont expr - new_ty <- lintCastExpr expr ty co - return (new_ty, ue) lintRunRWCont expr@(Lam _ _) = do lintJoinLams 1 (Just fun) expr lintRunRWCont other = markAllJoinsBad $ lintCoreExpr other @@ -943,10 +927,6 @@ lintCoreExpr e@(App _ _) ; app_ty <- lintValApp arg3 fun_ty2 arg3_ty ue2 ue3 ; lintCoreArgs app_ty rest } - | Var fun <- fun - , fun `hasKey` runRWKey - = failWithL (text "Invalid runRW# application") - | otherwise = do { pair <- lintCoreFun fun (length args) ; lintCoreArgs pair args } ===================================== compiler/GHC/Core/Opt/Simplify.hs ===================================== @@ -1972,8 +1972,10 @@ rebuildCall env info (ApplyToTy { sc_arg_ty = arg_ty, sc_hole_ty = hole_ty, sc_c = rebuildCall env (addTyArgTo info arg_ty hole_ty) cont ---------- The runRW# rule. Do this after absorbing all arguments ------ +-- See Note [Simplification of runRW#] in GHC.CoreToSTG.Prep. +-- -- runRW# :: forall (r :: RuntimeRep) (o :: TYPE r). (State# RealWorld -> o) -> o --- K[ runRW# rr ty body ] --> runRW rr' ty' (\s. K[ body s ]) +-- K[ runRW# rr ty body ] --> runRW rr' ty' (\s. K[ body s ]) rebuildCall env (ArgInfo { ai_fun = fun_id, ai_args = rev_args }) (ApplyToVal { sc_arg = arg, sc_env = arg_se , sc_cont = cont, sc_hole_ty = fun_ty }) ===================================== compiler/GHC/CoreToStg/Prep.hs ===================================== @@ -723,18 +723,6 @@ instance Outputable ArgInfo where ppr (CpeCast co) = text "cast" <+> ppr co ppr (CpeTick tick) = text "tick" <+> ppr tick -{- - Note [runRW arg] -~~~~~~~~~~~~~~~~~~~ -If we got, say - runRW# (case bot of {}) -which happened in #11291, we do /not/ want to turn it into - (case bot of {}) realWorldPrimId# -because that gives a panic in CoreToStg.myCollectArgs, which expects -only variables in function position. But if we are sure to make -runRW# strict (which we do in GHC.Types.Id.Make), this can't happen --} - cpeApp :: CorePrepEnv -> CoreExpr -> UniqSM (Floats, CpeRhs) -- May return a CpeRhs because of saturating primops cpeApp top_env expr @@ -800,10 +788,6 @@ cpeApp top_env expr _ -> cpe_app env arg (CpeApp (Var realWorldPrimId) : rest) (n-1) -- TODO: What about casts? - cpe_app _env (Var f) args n - | f `hasKey` runRWKey - = pprPanic "cpe_app(runRW#)" (ppr args $$ ppr n) - cpe_app env (Var v) args depth = do { v1 <- fiddleCCall v ; let e2 = lookupCorePrepEnv env v1 @@ -925,34 +909,96 @@ optimization (right before lowering to STG, in CorePrep), we can ensure that no further floating will occur. This allows us to safely inline things like @runST@, which are otherwise needlessly expensive (see #10678 and #5916). -'runRW' is defined (for historical reasons) in GHC.Magic, with a NOINLINE -pragma. It is levity-polymorphic. +'runRW' has a variety of quirks: + + * 'runRW' is known-key with a NOINLINE definition in + GHC.Magic. This definition is used in cases where runRW is curried. + + * In addition to its normal Haskell definition in GHC.Magic, we give it + a special late inlining here in CorePrep and GHC.CoreToByteCode, avoiding + the incorrect sharing due to float-out noted above. + + * It is levity-polymorphic: runRW# :: forall (r1 :: RuntimeRep). (o :: TYPE r) => (State# RealWorld -> (# State# RealWorld, o #)) - -> (# State# RealWorld, o #) + -> (# State# RealWorld, o #) + + * It has some special simplification logic to allow unboxing of results when + runRW# appears in a strict context. See Note [Simplification of runRW#] + below. + + * Since its body is inlined, we allow runRW#'s argument to contain jumps to + join points. That is, the following is allowed: + + join j x = ... + in runRW# @_ @_ (\s -> ... jump j 42 ...) + + The Core Linter knows about this. See Note [Linting of runRW#] in + GHC.Core.Lint for details. + + The occurrence analyser and SetLevels also know about this, as described in + Note [Simplification of runRW#]. + +Other relevant Notes: -It's correctness needs no special treatment in GHC except this special inlining -here in CorePrep (and in GHC.CoreToByteCode). + * Note [Simplification of runRW#] below, describing a transformation of runRW + applications in strict contexts performed by the simplifier. + * Note [Linting of runRW#] in GHC.Core.Lint + * Note [runRW arg] below, describing a non-obvious case where the + late-inlining could go wrong. -However, there are a variety of optimisation opportunities that the simplifier -takes advantage of. See Note [Simplification of runRW#]. + + Note [runRW arg] +~~~~~~~~~~~~~~~~~~~ +Consider the Core program (from #11291), + + runRW# (case bot of {}) + +The late inlining logic in cpe_app would transform this into: + + (case bot of {}) realWorldPrimId# + +Which would rise to a panic in CoreToStg.myCollectArgs, which expects only +variables in function position. + +However, as runRW#'s strictness signature captures the fact that it will call +its argument this can't happen: the simplifier will transform the bottoming +application into simply (case bot of {}). + +Note that this reasoning does *not* apply to non-bottoming continuations like: + + hello :: Bool -> Int + hello n = + runRW# ( + case n of + True -> \s -> 23 + _ -> \s -> 10) + +Why? The difference is that (case bot of {}) is considered by okCpeArg to be +trivial, consequently cpeArg (which the catch-all case of cpe_app calls on both +the function and the arguments) will forgo binding it to a variable. By +contrast, in the non-bottoming case of `hello` above the function will be +deemed non-trivial and consequently will be case-bound. Note [Simplification of runRW#] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Consider the program, - case runRW# (\s -> let n = I# 42# in n) of + case runRW# (\s -> I# 42#) of I# n# -> f n# There is no reason why we should allocate an I# constructor given that we -immediately destructure it. To avoid this the simplifier will push strict -contexts into runRW's continuation. That is, it transforms +immediately destructure it. + +To avoid this the simplifier has a special transformation rule, specific to +runRW#, that pushes a strict context into runRW#'s continuation. See the +`runRW#` guard in `GHC.Core.Opt.Simplify.rebuildCall`. That is, it transforms K[ runRW# @r @ty cont ] ~> - runRW# @r @ty K[cont] + runRW# @r @ty (\s -> K[cont s]) This has a few interesting implications. Consider, for instance, this program: @@ -971,15 +1017,29 @@ Performing the transform described above would result in: If runRW# were a "normal" function this call to join point j would not be allowed in its continuation argument. However, since runRW# is inlined (as described in Note [runRW magic] above), such join point occurences are -completely fine. Both occurrence analysis and Core Lint have special treatment -for runRW# applications. See Note [Linting of runRW#] for details on the latter. +completely fine. Both occurrence analysis (see the runRW guard in occAnalApp) +and Core Lint (see the App case of lintCoreExpr) have special treatment for +runRW# applications. See Note [Linting of runRW#] for details on the latter. Moreover, it's helpful to ensure that runRW's continuation isn't floated out -(since doing so would then require a call, whereas we would otherwise end up -with straight-line). Consequently, GHC.Core.Opt.SetLevels.lvlApp has special -treatment for runRW# applications, ensure the arguments are not floated if +For instance, if we have + + runRW# (\s -> do_something) + +where do_something contains only top-level free variables, we may be tempted to +float the argument to the top-level. However, we must resist this urge as since +doing so would then require that runRW# produce an allocation and call, e.g.: + + let lvl = \s -> do_somethign + in + ....(runRW# lvl).... + +whereas without floating the inlining of the definition of runRW would result +in straight-line code. Consequently, GHC.Core.Opt.SetLevels.lvlApp has special +treatment for runRW# applications, ensure the arguments are not floated as MFEs. + Other considered designs ------------------------ ===================================== compiler/GHC/Unit/State.hs ===================================== @@ -18,6 +18,7 @@ module GHC.Unit.State ( listUnitInfo, -- * Querying the package config + UnitInfoMap, lookupUnit, lookupUnit', unsafeLookupUnit, ===================================== ghc.mk ===================================== @@ -934,6 +934,11 @@ ifneq "$(INSTALL_HTML_DOC_DIRS)" "" for i in $(INSTALL_HTML_DOC_DIRS); do \ $(CP) -Rp $$i "$(DESTDIR)$(docdir)/html"; \ done + for i in "$(DESTDIR)$(docdir)/html"/*/.doctrees; do \ + if [ -d "$$i" ]; then \ + rm -r "$$i"; \ + fi \ + done endif INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d ===================================== hadrian/src/Settings/Builders/RunTest.hs ===================================== @@ -78,6 +78,7 @@ runTestBuilderArgs = builder RunTest ? do <*> (maybe False (=="YES") <$> lookupEnv "OS") (testEnv, testMetricsFile) <- expr . liftIO $ (,) <$> lookupEnv "TEST_ENV" <*> lookupEnv "METRICS_FILE" + perfBaseline <- expr . liftIO $ lookupEnv "PERF_BASELINE_COMMIT" threads <- shakeThreads <$> expr getShakeOptions os <- getTestSetting TestHostOS @@ -141,6 +142,9 @@ runTestBuilderArgs = builder RunTest ? do , arg "--config", arg $ "timeout_prog=" ++ show (top -/- timeoutProg) , arg "--config", arg $ "stats_files_dir=" ++ statsFilesDir , arg $ "--threads=" ++ show threads + , case perfBaseline of + Just commit | not (null commit) -> arg ("--perf-baseline=" ++ show commit) + _ -> mempty , emitWhenSet testEnv $ \env -> arg ("--test-env=" ++ show env) , emitWhenSet testMetricsFile $ \file -> arg ("--metrics-file=" ++ file) , getTestArgs -- User-provided arguments from command line. ===================================== libraries/ghc-prim/GHC/Magic.hs ===================================== @@ -122,7 +122,7 @@ oneShot f = f runRW# :: forall (r :: RuntimeRep) (o :: TYPE r). (State# RealWorld -> o) -> o --- See Note [runRW magic] in CorePrep +-- See Note [runRW magic] in GHC.CoreToStg.Prep. {-# NOINLINE runRW# #-} -- runRW# is inlined manually in CorePrep #if !defined(__HADDOCK_VERSION__) runRW# m = m realWorld# ===================================== llvm-targets ===================================== @@ -24,6 +24,9 @@ ,("i386-unknown-linux-gnu", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("i386-unknown-linux-musl", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("i386-unknown-linux", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux-gnu", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux-musl", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) +,("i686-unknown-linux", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", "")) ,("x86_64-unknown-linux-gnu", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ,("x86_64-unknown-linux-musl", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ,("x86_64-unknown-linux", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", "")) ===================================== testsuite/driver/perf_notes.py ===================================== @@ -76,8 +76,7 @@ PerfStat = NamedTuple('PerfStat', [('test_env', TestEnv), # A baseline recovered form stored metrics. Baseline = NamedTuple('Baseline', [('perfStat', PerfStat), - ('commit', GitHash), - ('commitDepth', int)]) + ('commit', GitHash)]) class MetricChange(Enum): # The metric appears to have no baseline and is presumably a new test. @@ -402,7 +401,8 @@ def baseline_metric(commit: GitHash, name: TestName, test_env: TestEnv, metric: MetricName, - way: WayName + way: WayName, + baseline_ref: Optional[GitRef] ) -> Optional[Baseline]: # For performance reasons (in order to avoid calling commit_hash), we assert # commit is already a commit hash. @@ -411,6 +411,8 @@ def baseline_metric(commit: GitHash, # Get all recent commit hashes. commit_hashes = baseline_commit_log(commit) + baseline_commit = commit_hash(baseline_ref) if baseline_ref else None + def has_expected_change(commit: GitHash) -> bool: return get_allowed_perf_changes(commit).get(name) is not None @@ -418,11 +420,18 @@ def baseline_metric(commit: GitHash, def find_baseline(namespace: NoteNamespace, test_env: TestEnv ) -> Optional[Baseline]: + if baseline_commit is not None: + current_metric = get_commit_metric(namespace, baseline_commit, test_env, name, metric, way) + if current_metric is not None: + return Baseline(current_metric, baseline_commit) + else: + return None + for depth, current_commit in list(enumerate(commit_hashes))[1:]: # Check for a metric on this commit. current_metric = get_commit_metric(namespace, current_commit, test_env, name, metric, way) if current_metric is not None: - return Baseline(current_metric, current_commit, depth) + return Baseline(current_metric, current_commit) # Stop if there is an expected change at this commit. In that case # metrics on ancestor commits will not be a valid baseline. @@ -552,7 +561,7 @@ def check_stats_change(actual: PerfStat, result = passed() if not change_allowed: error = str(change) + ' from ' + baseline.perfStat.test_env + \ - ' baseline @ HEAD~' + str(baseline.commitDepth) + ' baseline @ %s' % baseline.commit print(actual.metric, error + ':') result = failBecause('stat ' + error, tag='stat') ===================================== testsuite/driver/runtests.py ===================================== @@ -27,7 +27,7 @@ from testutil import getStdout, Watcher, str_warn, str_info from testglobals import getConfig, ghc_env, getTestRun, TestConfig, \ TestOptions, brokens, PerfMetric from my_typing import TestName -from perf_notes import MetricChange, inside_git_repo, is_worktree_dirty, format_perf_stat +from perf_notes import MetricChange, GitRef, inside_git_repo, is_worktree_dirty, format_perf_stat from junit import junit import term_color from term_color import Color, colored @@ -70,6 +70,7 @@ parser.add_argument("--verbose", type=int, choices=[0,1,2,3,4,5], help="verbose parser.add_argument("--junit", type=argparse.FileType('wb'), help="output testsuite summary in JUnit format") parser.add_argument("--broken-test", action="append", default=[], help="a test name to mark as broken for this run") parser.add_argument("--test-env", default='local', help="Override default chosen test-env.") +parser.add_argument("--perf-baseline", type=GitRef, metavar='COMMIT', help="Baseline commit for performance comparsons.") perf_group.add_argument("--skip-perf-tests", action="store_true", help="skip performance tests") perf_group.add_argument("--only-perf-tests", action="store_true", help="Only do performance tests") @@ -101,6 +102,7 @@ config.metrics_file = args.metrics_file hasMetricsFile = config.metrics_file is not None config.summary_file = args.summary_file config.no_print_summary = args.no_print_summary +config.baseline_commit = args.perf_baseline if args.only: config.only = args.only @@ -351,8 +353,8 @@ def tabulate_metrics(metrics: List[PerfMetric]) -> None: rel = 100 * (val1 - val0) / val0 print("{space:24} {herald:40} {value:15.3f} [{direction}, {rel:2.1f}%]".format( space = "", - herald = "(baseline @ HEAD~{depth})".format( - depth = metric.baseline.commitDepth), + herald = "(baseline @ {commit})".format( + commit = metric.baseline.commit), value = val0, direction = metric.change, rel = rel @@ -422,6 +424,8 @@ else: # Dump metrics data. print("\nPerformance Metrics (test environment: {}):\n".format(config.test_env)) + if config.baseline_commit: + print('Performance baseline: %s\n' % config.baseline_commit) if any(t.metrics): tabulate_metrics(t.metrics) else: @@ -477,19 +481,19 @@ else: summary(t, sys.stdout, config.no_print_summary, config.supports_colors) # Write perf stats if any exist or if a metrics file is specified. - stats = [stat for (_, stat, __) in t.metrics] + stats_metrics = [stat for (_, stat, __) in t.metrics] # type: List[PerfStat] if hasMetricsFile: - print('Appending ' + str(len(stats)) + ' stats to file: ' + config.metrics_file) + print('Appending ' + str(len(stats_metrics)) + ' stats to file: ' + config.metrics_file) with open(config.metrics_file, 'a') as f: - f.write("\n" + Perf.format_perf_stat(stats)) - elif inside_git_repo() and any(stats): + f.write("\n" + Perf.format_perf_stat(stats_metrics)) + elif inside_git_repo() and any(stats_metrics): if is_worktree_dirty(): print() print(str_warn('Performance Metrics NOT Saved') + \ ' working tree is dirty. Commit changes or use ' + \ '--metrics-file to save metrics to a file.') else: - Perf.append_perf_stat(stats) + Perf.append_perf_stat(stats_metrics) # Write summary if config.summary_file: ===================================== testsuite/driver/testglobals.py ===================================== @@ -4,7 +4,7 @@ from my_typing import * from pathlib import Path -from perf_notes import MetricChange, PerfStat, Baseline, MetricOracles +from perf_notes import MetricChange, PerfStat, Baseline, MetricOracles, GitRef from datetime import datetime # ----------------------------------------------------------------------------- @@ -163,6 +163,9 @@ class TestConfig: # run. self.broken_tests = set() # type: Set[TestName] + # Baseline commit for performane metric comparisons. + self.baseline_commit = None # type: Optional[GitRef] + # Should we skip performance tests self.skip_perf_tests = False ===================================== testsuite/driver/testlib.py ===================================== @@ -477,7 +477,8 @@ def _collect_stats(name: TestName, opts, metrics, deviation, is_compiler_stats_t metric = '{}/{}'.format(tag, metric_name) def baselineByWay(way, target_commit, metric=metric): return Perf.baseline_metric( \ - target_commit, name, config.test_env, metric, way) + target_commit, name, config.test_env, metric, way, \ + config.baseline_commit ) opts.stats_range_fields[metric] = MetricOracles(baseline=baselineByWay, deviation=deviation) ===================================== testsuite/mk/test.mk ===================================== @@ -60,7 +60,7 @@ TEST_HC_OPTS += -Werror=compat # removing this line. TEST_HC_OPTS += -dno-debug-output -TEST_HC_OPTS_INTERACTIVE = $(TEST_HC_OPTS) --interactive -v0 -ignore-dot-ghci -fno-ghci-history +RTS --io-manager=native -RTS +TEST_HC_OPTS_INTERACTIVE = $(TEST_HC_OPTS) --interactive -v0 -ignore-dot-ghci -fno-ghci-history RUNTEST_OPTS = @@ -232,6 +232,10 @@ ifneq "$(VERBOSE)" "" RUNTEST_OPTS += --verbose=$(VERBOSE) endif +ifneq "$(PERF_TEST_BASELINE_COMMIT)" "" +RUNTEST_OPTS += --perf-baseline=$(PERF_TEST_BASELINE_COMMIT) +endif + ifeq "$(SKIP_PERF_TESTS)" "YES" RUNTEST_OPTS += --skip-perf-tests endif ===================================== testsuite/tests/codeGen/should_compile/T18291.hs ===================================== @@ -0,0 +1,7 @@ +{-# LANGUAGE MagicHash #-} +module T18291 where + +import GHC.Magic + +hi :: Int +hi = runRW# $ \_ -> 42 ===================================== testsuite/tests/codeGen/should_compile/all.T ===================================== @@ -91,6 +91,7 @@ test('T17648', normal, makefile_test, []) test('T17904', normal, compile, ['-O']) test('T18227A', normal, compile, ['']) test('T18227B', normal, compile, ['']) +test('T18291', normal, compile, ['-O0']) test('T15570', when(unregisterised(), skip), compile, ['-Wno-overflowed-literals']) ===================================== utils/llvm-targets/gen-data-layout.sh ===================================== @@ -59,6 +59,9 @@ TARGETS=( "i386-unknown-linux-gnu" "i386-unknown-linux-musl" "i386-unknown-linux" + "i686-unknown-linux-gnu" + "i686-unknown-linux-musl" + "i686-unknown-linux" "x86_64-unknown-linux-gnu" "x86_64-unknown-linux-musl" "x86_64-unknown-linux" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e340997e91828df27af37667f4f8fcbcd4b65e32...2330b4b9709ca4f20cb029bc39a0c7c6a33d73b0 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e340997e91828df27af37667f4f8fcbcd4b65e32...2330b4b9709ca4f20cb029bc39a0c7c6a33d73b0 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 15:47:53 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 18 Aug 2020 11:47:53 -0400 Subject: [Git][ghc/ghc][wip/T17856] 367 commits: Enable large address space optimization on windows. Message-ID: <5f3bf82987c7e_80b3f84693c1eb4854231c@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T17856 at Glasgow Haskell Compiler / GHC Commits: 03a708ba by Andreas Klebinger at 2020-06-25T03:54:37-04:00 Enable large address space optimization on windows. Starting with Win 8.1/Server 2012 windows no longer preallocates page tables for reserverd memory eagerly, which prevented us from using this approach in the past. We also try to allocate the heap high in the memory space. Hopefully this makes it easier to allocate things in the low 4GB of memory that need to be there. Like jump islands for the linker. - - - - - 7e6d3d09 by Roland Senn at 2020-06-25T03:54:38-04:00 In `:break ident` allow out of scope and nested identifiers (Fix #3000) This patch fixes the bug and implements the feature request of #3000. 1. If `Module` is a real module name and `identifier` a name of a top-level function in `Module` then `:break Module.identifer` works also for an `identifier` that is out of scope. 2. Extend the syntax for `:break identifier` to: :break [ModQual.]topLevelIdent[.nestedIdent]...[.nestedIdent] `ModQual` is optional and is either the effective name of a module or the local alias of a qualified import statement. `topLevelIdent` is the name of a top level function in the module referenced by `ModQual`. `nestedIdent` is optional and the name of a function nested in a let or where clause inside the previously mentioned function `nestedIdent` or `topLevelIdent`. If `ModQual` is a module name, then `topLevelIdent` can be any top level identifier in this module. If `ModQual` is missing or a local alias of a qualified import, then `topLevelIdent` must be in scope. Breakpoints can be set on arbitrarily deeply nested functions, but the whole chain of nested function names must be specified. 3. To support the new functionality rewrite the code to tab complete `:break`. - - - - - 30e42652 by Ben Gamari at 2020-06-25T03:54:39-04:00 make: Respect XELATEX variable Previously we simply ignored the XELATEX variable when building PDF documentation. - - - - - 4acc2934 by Ben Gamari at 2020-06-25T03:54:39-04:00 hadrian/make: Detect makeindex Previously we would simply assume that makeindex was available. Now we correctly detect it in `configure` and respect this conclusion in hadrian and make. - - - - - 0d61f866 by Simon Peyton Jones at 2020-06-25T03:54:40-04:00 Expunge GhcTcId GHC.Hs.Extension had type GhcPs = GhcPass 'Parsed type GhcRn = GhcPass 'Renamed type GhcTc = GhcPass 'Typechecked type GhcTcId = GhcTc The last of these, GhcTcId, is a vestige of the past. This patch expunges it from GHC. - - - - - 8ddbed4a by Adam Wespiser at 2020-06-25T03:54:40-04:00 add examples to Data.Traversable - - - - - 284001d0 by Oleg Grenrus at 2020-06-25T03:54:42-04:00 Export readBinIface_ - - - - - 90f43872 by Zubin Duggal at 2020-06-25T03:54:43-04:00 Export everything from HsToCore. This lets us reuse these functions in haddock, avoiding synchronization bugs. Also fixed some divergences with haddock in that file Updates haddock submodule - - - - - c7dd6da7 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part1) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Hs.* - GHC.Core.* - GHC.Stg.* - GHC.Cmm.* - GHC.Types.* - GHC.Data.* - GHC.Builtin.* - GHC.Parser.* - GHC.Driver.* - GHC top - - - - - 1eb997a8 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part2) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Iface.* - GHC.Llvm.* - GHC.Rename.* - GHC.Tc.* - GHC.HsToCore.* - GHC.StgToCmm.* - GHC.CmmToAsm.* - GHC.Runtime.* - GHC.Unit.* - GHC.Utils.* - GHC.SysTools.* - - - - - 67a86b4d by Oleg Grenrus at 2020-06-25T03:54:46-04:00 Add MonadZip and MonadFix instances for Complex These instances are taken from https://hackage.haskell.org/package/linear-1.21/docs/Linear-Instances.html They are the unique possible, so let they be in `base`. - - - - - c50ef26e by Artem Pelenitsyn at 2020-06-25T03:54:47-04:00 test suite: add reproducer for #17516 - - - - - fe281b27 by Roland Senn at 2020-06-25T03:54:48-04:00 Enable maxBound checks for OverloadedLists (Fixes #18172) Consider the Literal `[256] :: [Data.Word.Word8]` When the `OverloadedLists` extension is not active, then the `ol_ext` field in the `OverLitTc` record that is passed to the function `getIntegralLit` contains the type `Word8`. This is a simple type, and we can use its type constructor immediately for the `warnAboutOverflowedLiterals` function. When the `OverloadedLists` extension is active, then the `ol_ext` field contains the type family `Item [Word8]`. The function `nomaliseType` is used to convert it to the needed type `Word8`. - - - - - a788d4d1 by Ben Gamari at 2020-06-25T03:54:52-04:00 rts/Hash: Simplify freeing of HashListChunks While looking at #18348 I noticed that the treatment of HashLists are a bit more complex than necessary (which lead to some initial confusion on my part). Specifically, we allocate HashLists in chunks. Each chunk allocation makes two allocations: one for the chunk itself and one for a HashListChunk to link together the chunks for the purposes of freeing. Simplify this (and hopefully make the relationship between these clearer) but allocating the HashLists and HashListChunk in a single malloc. This will both make the implementation easier to follow and reduce C heap fragmentation. Note that even after this patch we fail to bound the size of the free HashList pool. However, this is a separate bug. - - - - - d3c2d59b by Sylvain Henry at 2020-06-25T03:54:55-04:00 RTS: avoid overflow on 32-bit arch (#18375) We're now correctly computing allocated bytes on 32-bit arch, so we get huge increases. Metric Increase: haddock.Cabal haddock.base haddock.compiler space_leak_001 - - - - - a3d69dc6 by Sebastian Graf at 2020-06-25T23:06:18-04:00 GHC.Core.Unify: Make UM actions one-shot by default This MR makes the UM monad in GHC.Core.Unify into a one-shot monad. See the long Note [The one-shot state monad trick]. See also #18202 and !3309, which applies this to all Reader/State-like monads in GHC for compile-time perf improvements. The pattern used here enables something similar to the state-hack, but is applicable to user-defined monads, not just `IO`. Metric Decrease 'runtime/bytes allocated' (test_env='i386-linux-deb9'): haddock.Cabal - - - - - 9ee58f8d by Matthias Pall Gissurarson at 2020-06-26T17:12:45+00:00 Implement the proposed -XQualifiedDo extension Co-authored-by: Facundo Domínguez <facundo.dominguez at tweag.io> QualifiedDo is implemented using the same placeholders for operation names in the AST that were devised for RebindableSyntax. Whenever the renamer checks which names to use for do syntax, it first checks if the do block is qualified (e.g. M.do { stmts }), in which case it searches for qualified names in the module M. This allows users to write {-# LANGUAGE QualifiedDo #-} import qualified SomeModule as M f x = M.do -- desugars to: y <- M.return x -- M.return x M.>>= \y -> M.return y -- M.return y M.>> M.return y -- M.return y See Note [QualifiedDo] and the users' guide for more details. Issue #18214 Proposal: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0216-qualified-do.rst Since we change the constructors `ITdo` and `ITmdo` to carry the new module name, we need to bump the haddock submodule to account or the new shape of these constructors. - - - - - ce987865 by Ryan Scott at 2020-06-27T11:55:21-04:00 Revamp the treatment of auxiliary bindings for derived instances This started as a simple fix for #18321 that organically grew into a much more sweeping refactor of how auxiliary bindings for derived instances are handled. I have rewritten `Note [Auxiliary binders]` in `GHC.Tc.Deriv.Generate` to explain all of the moving parts, but the highlights are: * Previously, the OccName of each auxiliary binding would be given a suffix containing a hash of its package name, module name, and parent data type to avoid name clashes. This was needlessly complicated, so we take the more direct approach of generating `Exact` `RdrName`s for each auxiliary binding with the same `OccName`, but using an underlying `System` `Name` with a fresh `Unique` for each binding. Unlike hashes, allocating new `Unique`s does not require any cleverness and avoid name clashes all the same... * ...speaking of which, in order to convince the renamer that multiple auxiliary bindings with the same `OccName` (but different `Unique`s) are kosher, we now use `rnLocalValBindsLHS` instead of `rnTopBindsLHS` to rename auxiliary bindings. Again, see `Note [Auxiliary binders]` for the full story. * I have removed the `DerivHsBind` constructor for `DerivStuff`—which was only used for `Data.Data`-related auxiliary bindings—and refactored `gen_Data_binds` to use `DerivAuxBind` instead. This brings the treatment of `Data.Data`-related auxiliary bindings in line with every other form of auxiliary binding. Fixes #18321. - - - - - a403eb91 by Sylvain Henry at 2020-06-27T11:55:59-04:00 ghc-bignum: fix division by zero (#18359) - - - - - 1b3d13b6 by Sylvain Henry at 2020-06-27T11:55:59-04:00 Fix ghc-bignum exceptions We must ensure that exceptions are not simplified. Previously we used: case raiseDivZero of _ -> 0## -- dummyValue But it was wrong because the evaluation of `raiseDivZero` was removed and the dummy value was directly returned. See new Note [ghc-bignum exceptions]. I've also removed the exception triggering primops which were fragile. We don't need them to be primops, we can have them exported by ghc-prim. I've also added a test for #18359 which triggered this patch. - - - - - a74ec37c by Simon Peyton Jones at 2020-06-27T11:56:34-04:00 Better loop detection in findTypeShape Andreas pointed out, in !3466, that my fix for #18304 was not quite right. This patch fixes it properly, by having just one RecTcChecker rather than (implicitly) two nested ones, in findTypeShape. - - - - - a04020b8 by Sylvain Henry at 2020-06-27T11:57:11-04:00 DynFlags: don't store buildTag `DynFlags.buildTag` was a field created from the set of Ways in `DynFlags.ways`. It had to be kept in sync with `DynFlags.ways` which was fragile. We want to avoid global state like this (#17957). Moreover in #14335 we also want to support loading units with different ways: target units would still use `DynFlags.ways` but plugins would use `GHC.Driver.Ways.hostFullWays`. To avoid having to deal both with build tag and with ways, we recompute the buildTag on-the-fly (should be pretty cheap) and we remove `DynFlags.buildTag` field. - - - - - 0e83efa2 by Krzysztof Gogolewski at 2020-06-27T11:57:49-04:00 Don't generalize when typechecking a tuple section The code is simpler and cleaner. - - - - - d8ba9e6f by Peter Trommler at 2020-06-28T09:19:11-04:00 RTS: Refactor Haskell-C glue for PPC 64-bit Make sure the stack is 16 byte aligned even when reserved stack bytes are not a multiple of 16 bytes. Avoid saving r2 (TOC). On ELF v1 the function descriptor of StgReturn has the same TOC as StgRun, on ELF v2 the TOC is recomputed in the function prologue. Use the ABI provided functions to save clobbered GPRs and FPRs. Improve comments. Describe what the stack looks like and how it relates to the respective ABIs. - - - - - 42f797b0 by Ryan Scott at 2020-06-28T09:19:46-04:00 Use NHsCoreTy to embed types into GND-generated code `GeneralizedNewtypeDeriving` is in the unique situation where it must produce an `LHsType GhcPs` from a Core `Type`. Historically, this was done with the `typeToLHsType` function, which walked over the entire `Type` and attempted to construct an `LHsType` with the same overall structure. `typeToLHsType` is quite complicated, however, and has been the subject of numerous bugs over the years (e.g., #14579). Luckily, there is an easier way to accomplish the same thing: the `XHsType` constructor of `HsType`. `XHsType` bundles an `NHsCoreTy`, which allows embedding a Core `Type` directly into an `HsType`, avoiding the need to laboriously convert from one to another (as `typeToLHsType` did). Moreover, renaming and typechecking an `XHsType` is simple, since one doesn't need to do anything to a Core `Type`... ...well, almost. For the reasons described in `Note [Typechecking NHsCoreTys]` in `GHC.Tc.Gen.HsType`, we must apply a substitution that we build from the local `tcl_env` type environment. But that's a relatively modest price to pay. Now that `GeneralizedNewtypeDeriving` uses `NHsCoreTy`, the `typeToLHsType` function no longer has any uses in GHC, so this patch rips it out. Some additional tweaks to `hsTypeNeedsParens` were necessary to make the new `-ddump-deriv` output correctly parenthesized, but other than that, this patch is quite straightforward. This is a mostly internal refactoring, although it is likely that `GeneralizedNewtypeDeriving`-generated code will now need fewer language extensions in certain situations than it did before. - - - - - 68530b1c by Jan Hrček at 2020-06-28T09:20:22-04:00 Fix duplicated words and typos in comments and user guide - - - - - 15b79bef by Ryan Scott at 2020-06-28T09:20:57-04:00 Add integer-gmp's ghc.mk and GNUmakefile to .gitignore - - - - - bfa5698b by Simon Peyton Jones at 2020-06-28T09:21:32-04:00 Fix a typo in Lint This simple error in GHC.Core.Litn.lintJoinLams meant that Lint reported bogus errors. Fixes #18399 - - - - - 71006532 by Ryan Scott at 2020-06-30T07:10:42-04:00 Reject nested foralls/contexts in instance types more consistently GHC is very wishy-washy about rejecting instance declarations with nested `forall`s or contexts that are surrounded by outermost parentheses. This can even lead to some strange interactions with `ScopedTypeVariables`, as demonstrated in #18240. This patch makes GHC more consistently reject instance types with nested `forall`s/contexts so as to prevent these strange interactions. On the implementation side, this patch tweaks `splitLHsInstDeclTy` and `getLHsInstDeclHead` to not look through parentheses, which can be semantically significant. I've added a `Note [No nested foralls or contexts in instance types]` in `GHC.Hs.Type` to explain why. This also introduces a `no_nested_foralls_contexts_err` function in `GHC.Rename.HsType` to catch nested `forall`s/contexts in instance types. This function is now used in `rnClsInstDecl` (for ordinary instance declarations) and `rnSrcDerivDecl` (for standalone `deriving` declarations), the latter of which fixes #18271. On the documentation side, this adds a new "Formal syntax for instance declaration types" section to the GHC User's Guide that presents a BNF-style grammar for what is and isn't allowed in instance types. Fixes #18240. Fixes #18271. - - - - - bccf3351 by Sylvain Henry at 2020-06-30T07:10:46-04:00 Add ghc-bignum to 8.12 release notes - - - - - 81704a6f by David Eichmann at 2020-06-30T07:10:48-04:00 Update ssh keys in CI performance metrics upload script - - - - - 85310fb8 by Joshua Price at 2020-06-30T07:10:49-04:00 Add missing Ix instances for tuples of size 6 through 15 (#16643) - - - - - cbb6b62f by Vladislav Zavialov at 2020-07-01T15:41:38-04:00 Implement -XLexicalNegation (GHC Proposal #229) This patch introduces a new extension, -XLexicalNegation, which detects whether the minus sign stands for negation or subtraction using the whitespace-based rules described in GHC Proposal #229. Updates haddock submodule. - - - - - fb5a0d01 by Martin Handley at 2020-07-01T15:42:14-04:00 #17169: Clarify Fixed's Enum instance. - - - - - b316804d by Simon Peyton Jones at 2020-07-01T15:42:49-04:00 Improve debug tracing for substitution This patch improves debug tracing a bit (#18395) * Remove the ancient SDoc argument to substitution, replacing it with a HasDebugCallStack constraint. The latter does the same job (indicate the call site) but much better. * Add HasDebugCallStack to simpleOptExpr, exprIsConApp_maybe I needed this to help nail the lookupIdSubst panic in #18326, #17784 - - - - - 5c9fabb8 by Hécate at 2020-07-01T15:43:25-04:00 Add most common return values for `os` and `arch` - - - - - 76d8cc74 by Ryan Scott at 2020-07-01T15:44:01-04:00 Desugar quoted uses of DerivingVia and expression type signatures properly The way that `GHC.HsToCore.Quote` desugared quoted `via` types (e.g., `deriving via forall a. [a] instance Eq a => Eq (List a)`) and explicit type annotations in signatures (e.g., `f = id @a :: forall a. a -> a`) was completely wrong, as it did not implement the scoping guidelines laid out in `Note [Scoped type variables in bindings]`. This is easily fixed. While I was in town, I did some minor cleanup of related Notes: * `Note [Scoped type variables in bindings]` and `Note [Scoped type variables in class and instance declarations]` say very nearly the same thing. I decided to just consolidate the two Notes into `Note [Scoped type variables in quotes]`. * `Note [Don't quantify implicit type variables in quotes]` is somewhat outdated, as it predates GHC 8.10, where the `forall`-or-nothing rule requires kind variables to be explicitly quantified in the presence of an explicit `forall`. As a result, the running example in that Note doesn't even compile. I have changed the example to something simpler that illustrates the same point that the original Note was making. Fixes #18388. - - - - - 44d6a335 by Andreas Klebinger at 2020-07-02T02:54:54-04:00 T16012: Be verbose on failure. - - - - - f9853330 by Ryan Scott at 2020-07-02T02:55:29-04:00 Bump ghc-prim version to 0.7.0 Fixes #18279. Bumps the `text` submodule. - - - - - 23e4e047 by Sylvain Henry at 2020-07-02T10:46:31-04:00 Hadrian: fix PowerPC64le support (#17601) [ci skip] - - - - - 3cdd8d69 by Sylvain Henry at 2020-07-02T10:47:08-04:00 NCG: correctly handle addresses with huge offsets (#15570) Before this patch we could generate addresses of this form: movzbl cP0_str+-9223372036854775808,%eax The linker can't handle them because the offset is too large: ld.lld: error: Main.o:(.text+0xB3): relocation R_X86_64_32S out of range: -9223372036852653050 is not in [-2147483648, 2147483647] With this patch we detect those cases and generate: movq $-9223372036854775808,%rax addq $cP0_str,%rax movzbl (%rax),%eax I've also refactored `getAmode` a little bit to make it easier to understand and to trace. - - - - - 4d90b3ff by Gabor Greif at 2020-07-02T20:07:59-04:00 No need for CURSES_INCLUDE_DIRS This is a leftover from ef63ff27251a20ff11e58c9303677fa31e609a88 - - - - - f08d6316 by Sylvain Henry at 2020-07-02T20:08:36-04:00 Replace Opt_SccProfilingOn flag with sccProfilingEnabled helper function SCC profiling was enabled in a convoluted way: if WayProf was enabled, Opt_SccProfilingOn general flag was set (in `GHC.Driver.Ways.wayGeneralFlags`), and then this flag was queried in various places. There is no need to go via general flags, so this patch defines a `sccProfilingEnabled :: DynFlags -> Bool` helper function that just checks whether WayProf is enabled. - - - - - 8cc7274b by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Only allocate the Censuses that we need When not LDV profiling there is no reason to allocate 32 Censuses; one will do. This is a very small memory footprint optimisation, but it comes for free. - - - - - b835112c by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Free old allocations when reinitialising Censuses Previously when not LDV profiling we would repeatedly reinitialise `censuses[0]` with `initEra`. This failed to free the `Arena` and `HashTable` from the old census, resulting in a memory leak. Fixes #18348. - - - - - 34be6523 by Valery Tolstov at 2020-07-03T02:50:03-04:00 Mention flags that are not enabled by -Wall (#18372) * Mention missing flags that are not actually enabled by -Wall (docs/users_guide/using-warnings.rst) * Additionally remove -Wmissing-monadfail-instances from the list of flags enabled by -Wcompat, as it is not the case since 8.8 - - - - - edc8d22b by Sylvain Henry at 2020-07-03T02:50:40-04:00 LLVM: support R9 and R10 registers d535ef006d85dbdb7cda2b09c5bc35cb80108909 allowed the use of up to 10 vanilla registers but didn't update LLVM backend to support them. This patch fixes it. - - - - - 4bf18646 by Simon Peyton Jones at 2020-07-03T08:37:42+01:00 Improve handling of data type return kinds Following a long conversation with Richard, this patch tidies up the handling of return kinds for data/newtype declarations (vanilla, family, and instance). I have substantially edited the Notes in TyCl, so they would bear careful reading. Fixes #18300, #18357 In GHC.Tc.Instance.Family.newFamInst we were checking some Lint-like properties with ASSSERT. Instead Richard and I have added a proper linter for axioms, and called it from lintGblEnv, which in turn is called in tcRnModuleTcRnM New tests (T18300, T18357) cause an ASSERT failure in HEAD. - - - - - 41d26492 by Sylvain Henry at 2020-07-03T17:33:59-04:00 DynFlags: avoid the use of sdocWithDynFlags in GHC.Core.Rules (#17957) - - - - - 7aa6ef11 by Hécate at 2020-07-03T17:34:36-04:00 Add the __GHC_FULL_VERSION__ CPP macro to expose the full GHC version - - - - - e61d5395 by Chaitanya Koparkar at 2020-07-07T13:55:59-04:00 ghc-prim: Turn some comments into haddocks [ci skip] - - - - - 37743f91 by John Ericson at 2020-07-07T13:56:00-04:00 Support `timesInt2#` in LLVM backend - - - - - 46397e53 by John Ericson at 2020-07-07T13:56:00-04:00 `genericIntMul2Op`: Call `genericWordMul2Op` directly This unblocks a refactor, and removes partiality. It might be a PowerPC regression but that should be fixable. - - - - - 8a1c0584 by John Ericson at 2020-07-07T13:56:00-04:00 Simplify `PrimopCmmEmit` Follow @simonpj's suggestion of pushing the "into regs" logic into `emitPrimOp`. With the previous commit getting rid of the recursion in `genericIntMul2Op`, this is now an easy refactor. - - - - - 6607f203 by John Ericson at 2020-07-07T13:56:00-04:00 `opAllDone` -> `opIntoRegs` The old name was and terrible and became worse after the previous commit's refactor moved non-trivial funcationlity into its body. - - - - - fdcc53ba by Sylvain Henry at 2020-07-07T13:56:00-04:00 Optimise genericIntMul2Op We shouldn't directly call 'genericWordMul2Op' in genericIntMul2Op because a target may provide a faster primop for 'WordMul2Op': we'd better use it! - - - - - 686e7225 by Moritz Angermann at 2020-07-07T13:56:01-04:00 [linker/rtsSymbols] More linker symbols Mostly symbols needed for aarch64/armv7l and in combination with musl, where we have to rely on loading *all* objects/archives - __stack_chk_* only when not DYNAMIC - - - - - 3f60b94d by Moritz Angermann at 2020-07-07T13:56:01-04:00 better if guards. - - - - - 7abffced by Moritz Angermann at 2020-07-07T13:56:01-04:00 Fix (1) - - - - - cdfeb3f2 by Moritz Angermann at 2020-07-07T13:56:01-04:00 AArch32 symbols only on aarch32. - - - - - f496c955 by Adam Sandberg Ericsson at 2020-07-07T13:56:02-04:00 add -flink-rts flag to link the rts when linking a shared or static library #18072 By default we don't link the RTS when linking shared libraries because in the most usual mode a shared library is an intermediary product, for example a Haskell library, that will be linked into some executable in the end. So we wish to defer the RTS flavour to link to the final link. However sometimes the final product is the shared library, for example when writing a plugin for some other system, so we do wish the shared library to link the RTS. For consistency we also make -staticlib honor this flag and its inversion. -staticlib currently implies -flink-shared. - - - - - c59faf67 by Stefan Schulze Frielinghaus at 2020-07-07T13:56:04-04:00 hadrian: link check-ppr against debugging RTS if ghcDebugged - - - - - 0effc57d by Adam Sandberg Ericsson at 2020-07-07T13:56:05-04:00 rts linker: teach the linker about GLIBC's special handling of *stat, mknod and atexit functions #7072 - - - - - 96153433 by Adam Sandberg Ericsson at 2020-07-07T13:56:06-04:00 hadrian: make hadrian/ghci use the bootstrap compiler from configure #18190 - - - - - 4d24f886 by Adam Sandberg Ericsson at 2020-07-07T13:56:07-04:00 hadrian: ignore cabal configure verbosity related flags #18131 - - - - - 7332bbff by Ben Gamari at 2020-07-07T13:56:08-04:00 testsuite: Widen T12234 acceptance window to 2% Previously it wasn't uncommon to see +/-1% fluctuations in compiler allocations on this test. - - - - - 180b6313 by Gabor Greif at 2020-07-07T13:56:08-04:00 When running libtool, report it as such - - - - - d3bd6897 by Sylvain Henry at 2020-07-07T13:56:11-04:00 BigNum: rename BigNat types Before this patch BigNat names were confusing because we had: * GHC.Num.BigNat.BigNat: unlifted type used everywhere else * GHC.Num.BigNat.BigNatW: lifted type only used to share static constants * GHC.Natural.BigNat: lifted type only used for backward compatibility After this patch we have: * GHC.Num.BigNat.BigNat#: unlifted type * GHC.Num.BigNat.BigNat: lifted type (reexported from GHC.Natural) Thanks to @RyanGlScott for spotting this. - - - - - 929d26db by Sylvain Henry at 2020-07-07T13:56:12-04:00 Bignum: don't build ghc-bignum with stage0 Noticed by @Ericson2314 - - - - - d25b6851 by Sylvain Henry at 2020-07-07T13:56:12-04:00 Hadrian: ghc-gmp.h shouldn't be a compiler dependency - - - - - 0ddae2ba by Sylvain Henry at 2020-07-07T13:56:14-04:00 DynFlags: factor out pprUnitId from "Outputable UnitId" instance - - - - - 204f3f5d by Krzysztof Gogolewski at 2020-07-07T13:56:18-04:00 Remove unused function pprHsForAllExtra (#18423) The function `pprHsForAllExtra` was called only on `Nothing` since 2015 (1e041b7382b6aa). - - - - - 3033e0e4 by Adam Sandberg Ericsson at 2020-07-08T20:36:49-04:00 hadrian: add flag to skip rebuilding dependency information #17636 - - - - - b7de4b96 by Stefan Schulze Frielinghaus at 2020-07-09T09:49:22-04:00 Fix GHCi :print on big-endian platforms On big-endian platforms executing import GHC.Exts data Foo = Foo Float# deriving Show foo = Foo 42.0# foo :print foo results in an arithmetic overflow exception which is caused by function index where moveBytes equals word_size - (r + item_size_b) * 8 Here we have a mixture of units. Both, word_size and item_size_b have unit bytes whereas r has unit bits. On 64-bit platforms moveBytes equals then 8 - (0 + 4) * 8 which results in a negative and therefore invalid second parameter for a shiftL operation. In order to make things more clear the expression (word .&. (mask `shiftL` moveBytes)) `shiftR` moveBytes is equivalent to (word `shiftR` moveBytes) .&. mask On big-endian platforms the shift must be a left shift instead of a right shift. For symmetry reasons not a mask is used but two shifts in order to zero out bits. Thus the fixed version equals case endian of BigEndian -> (word `shiftL` moveBits) `shiftR` zeroOutBits `shiftL` zeroOutBits LittleEndian -> (word `shiftR` moveBits) `shiftL` zeroOutBits `shiftR` zeroOutBits Fixes #16548 and #14455 - - - - - 3656dff8 by Sylvain Henry at 2020-07-09T09:50:01-04:00 LLVM: fix MO_S_Mul2 support (#18434) The value indicating if the carry is useful wasn't taken into account. - - - - - d9f09506 by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Define multiShotIO and use it in mkSplitUniqueSupply This patch is part of the ongoing eta-expansion saga; see #18238. It implements a neat trick (suggested by Sebastian Graf) that allows the programmer to disable the default one-shot behaviour of IO (the "state hack"). The trick is to use a new multiShotIO function; see Note [multiShotIO]. For now, multiShotIO is defined here in Unique.Supply; but it should ultimately be moved to the IO library. The change is necessary to get good code for GHC's unique supply; see Note [Optimising the unique supply]. However it makes no difference to GHC as-is. Rather, it makes a difference when a subsequent commit Improve eta-expansion using ArityType lands. - - - - - bce695cc by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Make arityType deal with join points As Note [Eta-expansion and join points] describes, this patch makes arityType deal correctly with join points. What was there before was not wrong, but yielded lower arities than it could. Fixes #18328 In base GHC this makes no difference to nofib. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- n-body -0.1% -0.1% -1.2% -1.1% 0.0% -------------------------------------------------------------------------------- Min -0.1% -0.1% -55.0% -56.5% 0.0% Max -0.0% 0.0% +16.1% +13.4% 0.0% Geometric Mean -0.0% -0.0% -30.1% -31.0% -0.0% But it starts to make real difference when we land the change to the way mkDupableAlts handles StrictArg, in fixing #13253 and friends. I think this is because we then get more non-inlined join points. - - - - - 2b7c71cb by Simon Peyton Jones at 2020-07-11T12:17:02-04:00 Improve eta-expansion using ArityType As #18355 shows, we were failing to preserve one-shot info when eta-expanding. It's rather easy to fix, by using ArityType more, rather than just Arity. This patch is important to suport the one-shot monad trick; see #18202. But the extra tracking of one-shot-ness requires the patch Define multiShotIO and use it in mkSplitUniqueSupply If that patch is missing, ths patch makes things worse in GHC.Types.Uniq.Supply. With it, however, we see these improvements T3064 compiler bytes allocated -2.2% T3294 compiler bytes allocated -1.3% T12707 compiler bytes allocated -1.3% T13056 compiler bytes allocated -2.2% Metric Decrease: T3064 T3294 T12707 T13056 - - - - - de139cc4 by Artem Pelenitsyn at 2020-07-12T02:53:20-04:00 add reproducer for #15630 - - - - - c4de6a7a by Andreas Klebinger at 2020-07-12T02:53:55-04:00 Give Uniq[D]FM a phantom type for its key. This fixes #17667 and should help to avoid such issues going forward. The changes are mostly mechanical in nature. With two notable exceptions. * The register allocator. The register allocator references registers by distinct uniques. However they come from the types of VirtualReg, Reg or Unique in various places. As a result we sometimes cast the key type of the map and use functions which operate on the now typed map but take a raw Unique as actual key. The logic itself has not changed it just becomes obvious where we do so now. * <Type>Env Modules. As an example a ClassEnv is currently queried using the types `Class`, `Name`, and `TyCon`. This is safe since for a distinct class value all these expressions give the same unique. getUnique cls getUnique (classTyCon cls) getUnique (className cls) getUnique (tcName $ classTyCon cls) This is for the most part contained within the modules defining the interface. However it requires us to play dirty when we are given a `Name` to lookup in a `UniqFM Class a` map. But again the logic did not change and it's for the most part hidden behind the Env Module. Some of these cases could be avoided by refactoring but this is left for future work. We also bump the haddock submodule as it uses UniqFM. - - - - - c2cfdfde by Aaron Allen at 2020-07-13T09:00:33-04:00 Warn about empty Char enumerations (#18402) Currently the "Enumeration is empty" warning (-Wempty-enumerations) only fires for numeric literals. This patch adds support for `Char` literals so that enumerating an empty list of `Char`s will also trigger the warning. - - - - - c3ac87ec by Stefan Schulze Frielinghaus at 2020-07-13T09:01:10-04:00 hadrian: build check-ppr dynamic if GHC is build dynamic Fixes #18361 - - - - - 9ad072b4 by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Use dumpStyle when printing inlinings This just makes debug-printing consistent, and more informative. - - - - - e78c4efb by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Comments only - - - - - 7ccb760b by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Reduce result discount in conSize Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c - - - - - 7f0b671e by Ben Gamari at 2020-07-13T14:52:49-04:00 testsuite: Widen acceptance threshold on T5837 This test is positively tiny and consequently the bytes allocated measurement will be relatively noisy. Consequently I have seen this fail spuriously quite often. - - - - - 118e1c3d by Alp Mestanogullari at 2020-07-14T21:30:52-04:00 compiler: re-engineer the treatment of rebindable if Executing on the plan described in #17582, this patch changes the way if expressions are handled in the compiler in the presence of rebindable syntax. We get rid of the SyntaxExpr field of HsIf and instead, when rebindable syntax is on, we rewrite the HsIf node to the appropriate sequence of applications of the local `ifThenElse` function. In order to be able to report good error messages, with expressions as they were written by the user (and not as desugared by the renamer), we make use of TTG extensions to extend GhcRn expression ASTs with an `HsExpansion` construct, which keeps track of a source (GhcPs) expression and the desugared (GhcRn) expression that it gives rise to. This way, we can typecheck the latter while reporting the former in error messages. In order to discard the error context lines that arise from typechecking the desugared expressions (because they talk about expressions that the user has not written), we carefully give a special treatment to the nodes fabricated by this new renaming-time transformation when typechecking them. See Note [Rebindable syntax and HsExpansion] for more details. The note also includes a recipe to apply the same treatment to other rebindable constructs. Tests 'rebindable11' and 'rebindable12' have been added to make sure we report identical error messages as before this patch under various circumstances. We also now disable rebindable syntax when processing untyped TH quotes, as per the discussion in #18102 and document the interaction of rebindable syntax and Template Haskell, both in Note [Template Haskell quotes and Rebindable Syntax] and in the user guide, adding a test to make sure that we do not regress in that regard. - - - - - 64c774b0 by Andreas Klebinger at 2020-07-14T21:31:27-04:00 Explain why keeping DynFlags in AnalEnv saves allocation. - - - - - 254245d0 by Ben Gamari at 2020-07-14T21:32:03-04:00 docs/users-guide: Update default -funfolding-use-threshold value This was changed in 3d2991f8 but I neglected to update the documentation. Fixes #18419. - - - - - 4c259f86 by Andreas Klebinger at 2020-07-14T21:32:41-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. - - - - - 23797224 by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 .gitlab: re-enable integer-simple substitute (BIGNUM_BACKEND) Recently build system migrated from INTEGER_LIBRARY to BIGNUM_BACKEND. But gitlab CI was never updated. Let's enable BIGNUM_BACKEND=native. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - e0db878a by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 ghc-bignum: bring in sync .hs-boot files with module declarations Before this change `BIGNUM_BACKEND=native` build was failing as: ``` libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs:708:16: error: * Variable not in scope: naturalFromBigNat# :: WordArray# -> t * Perhaps you meant one of these: `naturalFromBigNat' (imported from GHC.Num.Natural), `naturalToBigNat' (imported from GHC.Num.Natural) | 708 | m' = naturalFromBigNat# m | ``` This happens because `.hs-boot` files are slightly out of date. This change brings in data and function types in sync. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - c9f65c36 by Stefan Schulze Frielinghaus at 2020-07-14T21:33:57-04:00 rts/Disassembler.c: Use FMT_HexWord for printing values in hex format - - - - - 58ae62eb by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 macOS: Load frameworks without stating them first. macOS Big Sur makes the following change to how frameworks are shipped with the OS: > New in macOS Big Sur 11 beta, the system ships with a built-in > dynamic linker cache of all system-provided libraries. As part of > this change, copies of dynamic libraries are no longer present on > the filesystem. Code that attempts to check for dynamic library > presence by looking for a file at a path or enumerating a directory > will fail. Instead, check for library presence by attempting to > dlopen() the path, which will correctly check for the library in the > cache. (62986286) https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/ Therefore, the previous method of checking whether a library exists before attempting to load it makes GHC.Runtime.Linker.loadFramework fail to find frameworks installed at /System/Library/Frameworks. GHC.Runtime.Linker.loadFramework now opportunistically loads the framework libraries without checking for their existence first, failing only if all attempts to load a given framework from any of the various possible locations fail. - - - - - cdc4a6b0 by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 loadFramework: Output the errors collected in all loading attempts. With the recent change away from first finding and then loading a framework, loadFramework had no way of communicating the real reason why loadDLL failed if it was any reason other than the framework missing from the file system. It now collects all loading attempt errors into a list and concatenates them into a string to return to the caller. - - - - - 51dbfa52 by Ben Gamari at 2020-07-15T04:05:34-04:00 StgToCmm: Use CmmRegOff smart constructor Previously we would generate expressions of the form `CmmRegOff BaseReg 0`. This should do no harm (and really should be handled by the NCG anyways) but it's better to just generate a plain `CmmReg`. - - - - - ae11bdfd by Ben Gamari at 2020-07-15T04:06:08-04:00 testsuite: Add regression test for #17744 Test due to @monoidal. - - - - - 0e3c277a by Ben Gamari at 2020-07-15T16:41:01-04:00 Bump Cabal submodule Updates a variety of tests as Cabal is now more strict about Cabal file form. - - - - - ceed994a by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Drop Windows Vista support, require Windows 7 - - - - - 00a23bfd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Update Windows FileSystem wrapper utilities. - - - - - 459e1c5f by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Use SlimReaderLocks and ConditonalVariables provided by the OS instead of emulated ones - - - - - 763088fc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Small linker comment and ifdef cleanups - - - - - 1a228ff9 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Flush event logs eagerly. - - - - - e9e04dda by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Refactor Buffer structures to be able to track async operations - - - - - 356dc3fe by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Implement new Console API - - - - - 90e69f77 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add IOPort synchronization primitive - - - - - 71245fcc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add new io-manager cmdline options - - - - - d548a3b3 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Init Windows console Codepage to UTF-8. - - - - - 58ef6366 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add unsafeSplat to GHC.Event.Array - - - - - d660725e by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add size and iterate to GHC.Event.IntTable. - - - - - 050da6dd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Switch Testsuite to test winio by default - - - - - 4bf542bf by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Multiple refactorings and support changes. - - - - - 4489af6b by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core threaded I/O manager - - - - - 64d8f2fe by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core non-threaded I/O manager - - - - - 8da15a09 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix a scheduler bug with the threaded-runtime. - - - - - 84ea3d14 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Relaxing some constraints in io-manager. - - - - - ccf0d107 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix issues with non-threaded I/O manager after split. - - - - - b492fe6e by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Remove some barf statements that are a bit strict. - - - - - 01423fd2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Expand comments describing non-threaded loop - - - - - 4b69004f by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: fix FileSize unstat-able handles - - - - - 9b384270 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Implement new tempfile routines for winio - - - - - f1e0be82 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix input truncation when reading from handle. This was caused by not upholding the read buffer invariant that bufR == bufL == 0 for empty read buffers. - - - - - e176b625 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix output truncation for writes larger than buffer size - - - - - a831ce0e by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Rewrite bufWrite. I think it's far easier to follow the code now. It's also correct now as I had still missed a spot where we didn't update the offset. - - - - - 6aefdf62 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix offset set by bufReadEmpty. bufReadEmpty returns the bytes read *including* content that was already buffered, But for calculating the offset we only care about the number of bytes read into the new buffer. - - - - - 750ebaee by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Clean up code surrounding IOPort primitives. According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc. - - - - - ffd31db9 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix multi threaded threadDelay and a few other small changes. Multithreaded threadDelay suffered from a race condition based on the ioManagerStatus. Since the status isn't needed for WIO I removed it completely. This resulted in a light refactoring, as consequence we will always wake up the IO manager using interruptSystemManager, which uses `postQueuedCompletionStatus` internally. I also added a few comments which hopefully makes the code easier to dive into for the next person diving in. - - - - - 6ec26df2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 wionio: Make IO subsystem check a no-op on non-windows platforms. - - - - - 29bcd936 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Set handle offset when opening files in Append mode. Otherwise we would truncate the file. - - - - - 55c29700 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Remove debug event log trace - - - - - 9acb9f40 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix sqrt and openFile009 test cases - - - - - 57017cb7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Allow hp2ps to build with -DDEBUG - - - - - b8cd9995 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update output of T9681 since we now actually run it. - - - - - 10af5b14 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: A few more improvements to the IOPort primitives. - - - - - 39afc4a7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix expected tempfiles output. Tempfiles now works properly on windows, as such we can delete the win32 specific output. - - - - - 99db46e0 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Assign thread labels to IOManager threads. - - - - - be6af732 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Properly check for the tso of an incall to be zero. - - - - - e2c6dac7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark FD instances as unsupported under WINIO. - - - - - fd02ceed by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix threadDelay maxBound invocations. Instead of letting the ns timer overflow now clamp it at (maxBound :: Word64) ns. That still gives a few hundred years. - - - - - bc79f9f1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comments/cleanup an import in base - - - - - 1d197f4b by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark outstanding_service_requests volatile. As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration. - - - - - dc438186 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Make last_event a local variable - - - - - 2fc957c5 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comment about thread safety of processCompletion. - - - - - 4c026b6c by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: nonthreaded: Create io processing threads in main thread. We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread. - - - - - f47c7208 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add an exported isHeapAlloced function to the RTS - - - - - cc5d7bb1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Queue IO processing threads at the front of the queue. This will unblock the IO thread sooner hopefully leading to higher throughput in some situations. - - - - - e7630115 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: ThreadDelay001: Use higher resolution timer. - - - - - 451b5f96 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update T9681 output, disable T4808 on windows. T4808 tests functionality of the FD interface which won't be supported under WINIO. T9681 just has it's expected output tweaked. - - - - - dd06f930 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Wake io manager once per registerTimeout. Which is implicitly done in editTimeouts, so need to wake it up twice. - - - - - e87d0bf9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update placeholder comment with actual function name. - - - - - fc9025db by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Always lock win32 event queue - - - - - c24c9a1f by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Display thread labels when tracing scheduler events. - - - - - 06542b03 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Refactor non-threaded runner thread and scheduler interface. Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event. - - - - - 256299b1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove outstanding_requests from runner. We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port. - - - - - 3ebd8ad9 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Various fixes related to rebase and testdriver - - - - - 6be6bcba by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Fix rebase artifacts - - - - - 2c649dc3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename unsafeSplat to unsafeCopyFromBuffer - - - - - a18b73f3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove unused size/iterate operations from IntTable - - - - - 16bab48e by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Detect running IO Backend via peeking at RtsConfig - - - - - 8b8405a0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update temp path so GCC etc can handle it. Also fix PIPE support, clean up error casting, fix memory leaks - - - - - 2092bc54 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Minor comments/renamings - - - - - a5b5b6c0 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Checking if an error code indicates completion is now a function. - - - - - 362176fd by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Small refactor in withOverlappedEx - - - - - 32e20597 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: A few comments and commented out dbxIO - - - - - a4bfc1d9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't drop buffer offset in byteView/cwcharView - - - - - b3ad2a54 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: revert BHandle changes. - - - - - 3dcd87e2 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Fix imports - - - - - 5a371890 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update ghc-cabal to handle new Cabal submodule bump - - - - - d07ebe0d by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Only compile sources on Windows - - - - - dcb42393 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Actually return Nothing on EOF for non-blocking read - - - - - 895a3beb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate logic in encodeMultiByte[Raw]IO. - - - - - e06e6734 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate openFile logic - - - - - b59430c0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: fix -werror issue in encoding file - - - - - f8d39a51 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't mention windows specific functions when building on Linux. - - - - - 6a533d2a by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add a note about file locking in the RTS. - - - - - cf37ce34 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Add version to @since annotation - - - - - 0fafa2eb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename GHC.Conc.IOCP -> GHC.Conc.WinIO - - - - - 1854fc23 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Expand GHC.Conc.POSIX description It now explains users may not use these functions when using the old IO manager. - - - - - fcc7ba41 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Fix potential spaceleak in __createUUIDTempFileErrNo - - - - - 6b3fd9fa by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant -Wno-missing-signatures pragmas - - - - - 916fc861 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Make it explicit that we only create one IO manager - - - - - f260a721 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Note why we don't use blocking waits. - - - - - aa0a4bbf by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove commented out pragma - - - - - d679b544 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant buffer write in Handle/Text.hs:bufReadEmpty - - - - - d3f94368 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename SmartHandles to StdHandles - - - - - bd6b8ec1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add comment stating failure behaviour for getUniqueFileInfo. - - - - - 12846b85 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update IOPort haddocks. - - - - - 9f39fb14 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Add a note cross reference - - - - - 62dd5a73 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Name Haskell/OS I/O Manager explicitly in Note - - - - - fa807828 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Expand BlockedOnIOCompletion description. - - - - - f0880a1d by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove historical todos - - - - - 8e58e714 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Update note, remove debugging pragma. - - - - - aa4d84d5 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: flushCharReadBuffer shouldn't need to adjust offsets. - - - - - e580893a by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove obsolete comment about cond. variables - - - - - d54e9d79 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix initial linux validate build - - - - - 3cd4de46 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix ThreadDelay001 CPP - - - - - c88b1b9f by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix openFile009 merge conflict leftover - - - - - 849e8889 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept T9681 output. GHC now reports String instead of [Char]. - - - - - e7701818 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix cabal006 after upgrading cabal submodule Demand cabal 2.0 syntax instead of >= 1.20 as required by newer cabal versions. - - - - - a44f0373 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix stderr output for ghci/linking/dyn tests. We used to filter rtsopts, i opted to instead just accept the warning of it having no effect. This works both for -rtsopts, as well as -with-rtsopts which winio adds. - - - - - 515d9896 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T15261b stdout for --io-manager flag. - - - - - 949aaacc by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T5435_dyn_asm stderr The warning about rtsopts having no consequences is expected. So accept new stderr. - - - - - 7d424e1e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Also accept T7037 stderr - - - - - 1f009768 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal04 by filtering rts args - - - - - 981a9f2e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal01 by accepting expected stderr - - - - - b7b0464e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix safePkg01 by accepting expected stderr - - - - - 32734b29 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix T5435_dyn_gcc by accepting expected stderr - - - - - acc5cebf by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix tempfiles test on linux - - - - - c577b789 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for T3807 - - - - - c108c527 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload - - - - - 2b0b9a08 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload_multiple_objs - - - - - 67afb03c by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify wording on conditional variables. - - - - - 3bd41572 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify comment on cooked mode. - - - - - ded58a03 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: update lockfile signature and remove mistaken symbol in rts. - - - - - 2143c492 by Ben Gamari at 2020-07-15T16:41:04-04:00 testsuite: Add winio and winio_threaded ways Reverts many of the testsuite changes - - - - - c0979cc5 by Ben Gamari at 2020-07-16T10:56:54-04:00 Merge remote-tracking branch 'origin/wip/winio' - - - - - 750a1595 by Ben Gamari at 2020-07-18T07:26:41-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. - - - - - 6ba6a881 by Hécate at 2020-07-18T07:26:42-04:00 Implement `fullCompilerVersion` Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403 This MR adds `fullCompilerVersion`, a function that shares the same backend as the `--numeric-version` GHC flag, exposing a full, three-digit version datatype. - - - - - e6cf27df by Hécate at 2020-07-18T07:26:43-04:00 Add a Lint hadrian rule and an .hlint.yaml file in base/ - - - - - bcb177dd by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Allow multiple case branches to have a higher rank type As #18412 points out, it should be OK for multiple case alternatives to have a higher rank type, provided they are all the same. This patch implements that change. It sweeps away GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it with an enhanced version of fillInferResult. The basic change to fillInferResult is to permit the case in which another case alternative has already filled in the result; and in that case simply unify. It's very simple actually. See the new Note [fillInferResult] in TcMType Other refactoring: - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType (previously some of it was in Unify) - Move tcInstType and friends from TcMType to Instantiate, where it more properly belongs. (TCMType was getting very long.) - - - - - e5525a51 by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Improve typechecking of NPlusK patterns This patch (due to Richard Eisenberg) improves documentation of the wrapper returned by tcSubMult (see Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify). And, more substantially, it cleans up the multiplicity handling in the typechecking of NPlusKPat - - - - - 12f90352 by Krzysztof Gogolewski at 2020-07-18T07:26:45-04:00 Remove {-# CORE #-} pragma (part of #18048) This pragma has no effect since 2011. It was introduced for External Core, which no longer exists. Updates haddock submodule. - - - - - e504c913 by Simon Peyton Jones at 2020-07-18T07:26:45-04:00 Refactor the simplification of join binders This MR (for #18449) refactors the Simplifier's treatment of join-point binders. Specifically, it puts together, into GHC.Core.Opt.Simplify.Env.adjustJoinPointType two currently-separate ways in which we adjust the type of a join point. As the comment says: -- (adjustJoinPointType mult new_res_ty join_id) does two things: -- -- 1. Set the return type of the join_id to new_res_ty -- See Note [Return type for join points] -- -- 2. Adjust the multiplicity of arrows in join_id's type, as -- directed by 'mult'. See Note [Scaling join point arguments] I think this actually fixes a latent bug, by ensuring that the seIdSubst and seInScope have the right multiplicity on the type of join points. I did some tidying up while I was at it. No more setJoinResTy, or modifyJoinResTy: instead it's done locally in Simplify.Env.adjustJoinPointType - - - - - 49b265f0 by Chaitanya Koparkar at 2020-07-18T07:26:46-04:00 Fix minor typos in a Core.hs note - - - - - 8d59aed6 by Stefan Schulze Frielinghaus at 2020-07-18T07:26:47-04:00 GHCi: Fix isLittleEndian - - - - - c26e81d1 by Ben Gamari at 2020-07-18T07:26:47-04:00 testsuite: Mark ghci tests as fragile under unreg compiler In particular I have seen T16012 fail repeatedly under the unregisterised compiler. - - - - - 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - b1a56cc7 by Ben Gamari at 2020-08-18T11:47:49-04:00 configure: Work around Raspbian's silly packaging decisions See #17856. - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/test-metrics.sh - CODEOWNERS - Makefile - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - + compiler/GHC/Builtin/RebindableNames.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/ByteCode/Types.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/Dataflow/Block.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Graph.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Lint.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2c70a1e3f98a06321b066613eb8dccfd7ac420c7...b1a56cc7135a295eb3deb26715a0df93dcf6b907 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2c70a1e3f98a06321b066613eb8dccfd7ac420c7...b1a56cc7135a295eb3deb26715a0df93dcf6b907 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 19:39:02 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 18 Aug 2020 15:39:02 -0400 Subject: [Git][ghc/ghc][master] 2 commits: Allow unsaturated runRW# applications Message-ID: <5f3c2e5698825_80b1075951c85650b6@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - 6 changed files: - compiler/GHC/Core/Lint.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/CoreToStg/Prep.hs - libraries/ghc-prim/GHC/Magic.hs - + testsuite/tests/codeGen/should_compile/T18291.hs - testsuite/tests/codeGen/should_compile/all.T Changes: ===================================== compiler/GHC/Core/Lint.hs ===================================== @@ -731,8 +731,6 @@ lintJoinLams join_arity enforce rhs where go 0 expr = lintCoreExpr expr go n (Lam var body) = lintLambda var $ go (n-1) body - -- N.B. join points can be cast. e.g. we consider ((\x -> ...) `cast` ...) - -- to be a join point at join arity 1. go n expr | Just bndr <- enforce -- Join point with too few RHS lambdas = failWithL $ mkBadJoinArityMsg bndr join_arity n rhs | otherwise -- Future join point, not yet eta-expanded @@ -781,36 +779,26 @@ hurts us here. Note [Linting of runRW#] ~~~~~~~~~~~~~~~~~~~~~~~~ -runRW# has some very peculiar behavior (see Note [runRW magic] in -GHC.CoreToStg.Prep) which CoreLint must accommodate. +runRW# has some very special behavior (see Note [runRW magic] in +GHC.CoreToStg.Prep) which CoreLint must accommodate, by allowing +join points in its argument. For example, this is fine: -As described in Note [Casts and lambdas] in -GHC.Core.Opt.Simplify.Utils, the simplifier pushes casts out of -lambdas. Concretely, the simplifier will transform + join j x = ... + in runRW# (\s. case v of + A -> j 3 + B -> j 4) - runRW# @r @ty (\s -> expr `cast` co) +Usually those calls to the join point 'j' would not be valid tail calls, +because they occur in a function argument. But in the case of runRW# +they are fine, because runRW# (\s.e) behaves operationally just like e. +(runRW# is ultimately inlined in GHC.CoreToStg.Prep.) -into - - runRW# @r @ty ((\s -> expr) `cast` co) - -Consequently we need to handle the case that the continuation is a -cast of a lambda. See Note [Casts and lambdas] in -GHC.Core.Opt.Simplify.Utils. - -In the event that the continuation is headed by a lambda (which -will bind the State# token) we can safely allow calls to join -points since CorePrep is going to apply the continuation to -RealWorld. - -In the case that the continuation is not a lambda we lint the -continuation disallowing join points, to rule out things like, +In the case that the continuation is /not/ a lambda we simply disable this +special behaviour. For example, this is /not/ fine: join j = ... - in runRW# @r @ty ( - let x = jump j - in x - ) + in runRW# @r @ty (jump j) + ************************************************************************ @@ -931,10 +919,6 @@ lintCoreExpr e@(App _ _) ; (fun_ty2, ue2) <- lintCoreArg fun_pair1 arg_ty2 -- See Note [Linting of runRW#] ; let lintRunRWCont :: CoreArg -> LintM (LintedType, UsageEnv) - lintRunRWCont (Cast expr co) = do - (ty, ue) <- lintRunRWCont expr - new_ty <- lintCastExpr expr ty co - return (new_ty, ue) lintRunRWCont expr@(Lam _ _) = do lintJoinLams 1 (Just fun) expr lintRunRWCont other = markAllJoinsBad $ lintCoreExpr other @@ -943,10 +927,6 @@ lintCoreExpr e@(App _ _) ; app_ty <- lintValApp arg3 fun_ty2 arg3_ty ue2 ue3 ; lintCoreArgs app_ty rest } - | Var fun <- fun - , fun `hasKey` runRWKey - = failWithL (text "Invalid runRW# application") - | otherwise = do { pair <- lintCoreFun fun (length args) ; lintCoreArgs pair args } ===================================== compiler/GHC/Core/Opt/Simplify.hs ===================================== @@ -1972,8 +1972,10 @@ rebuildCall env info (ApplyToTy { sc_arg_ty = arg_ty, sc_hole_ty = hole_ty, sc_c = rebuildCall env (addTyArgTo info arg_ty hole_ty) cont ---------- The runRW# rule. Do this after absorbing all arguments ------ +-- See Note [Simplification of runRW#] in GHC.CoreToSTG.Prep. +-- -- runRW# :: forall (r :: RuntimeRep) (o :: TYPE r). (State# RealWorld -> o) -> o --- K[ runRW# rr ty body ] --> runRW rr' ty' (\s. K[ body s ]) +-- K[ runRW# rr ty body ] --> runRW rr' ty' (\s. K[ body s ]) rebuildCall env (ArgInfo { ai_fun = fun_id, ai_args = rev_args }) (ApplyToVal { sc_arg = arg, sc_env = arg_se , sc_cont = cont, sc_hole_ty = fun_ty }) ===================================== compiler/GHC/CoreToStg/Prep.hs ===================================== @@ -723,18 +723,6 @@ instance Outputable ArgInfo where ppr (CpeCast co) = text "cast" <+> ppr co ppr (CpeTick tick) = text "tick" <+> ppr tick -{- - Note [runRW arg] -~~~~~~~~~~~~~~~~~~~ -If we got, say - runRW# (case bot of {}) -which happened in #11291, we do /not/ want to turn it into - (case bot of {}) realWorldPrimId# -because that gives a panic in CoreToStg.myCollectArgs, which expects -only variables in function position. But if we are sure to make -runRW# strict (which we do in GHC.Types.Id.Make), this can't happen --} - cpeApp :: CorePrepEnv -> CoreExpr -> UniqSM (Floats, CpeRhs) -- May return a CpeRhs because of saturating primops cpeApp top_env expr @@ -800,10 +788,6 @@ cpeApp top_env expr _ -> cpe_app env arg (CpeApp (Var realWorldPrimId) : rest) (n-1) -- TODO: What about casts? - cpe_app _env (Var f) args n - | f `hasKey` runRWKey - = pprPanic "cpe_app(runRW#)" (ppr args $$ ppr n) - cpe_app env (Var v) args depth = do { v1 <- fiddleCCall v ; let e2 = lookupCorePrepEnv env v1 @@ -925,34 +909,96 @@ optimization (right before lowering to STG, in CorePrep), we can ensure that no further floating will occur. This allows us to safely inline things like @runST@, which are otherwise needlessly expensive (see #10678 and #5916). -'runRW' is defined (for historical reasons) in GHC.Magic, with a NOINLINE -pragma. It is levity-polymorphic. +'runRW' has a variety of quirks: + + * 'runRW' is known-key with a NOINLINE definition in + GHC.Magic. This definition is used in cases where runRW is curried. + + * In addition to its normal Haskell definition in GHC.Magic, we give it + a special late inlining here in CorePrep and GHC.CoreToByteCode, avoiding + the incorrect sharing due to float-out noted above. + + * It is levity-polymorphic: runRW# :: forall (r1 :: RuntimeRep). (o :: TYPE r) => (State# RealWorld -> (# State# RealWorld, o #)) - -> (# State# RealWorld, o #) + -> (# State# RealWorld, o #) + + * It has some special simplification logic to allow unboxing of results when + runRW# appears in a strict context. See Note [Simplification of runRW#] + below. + + * Since its body is inlined, we allow runRW#'s argument to contain jumps to + join points. That is, the following is allowed: + + join j x = ... + in runRW# @_ @_ (\s -> ... jump j 42 ...) + + The Core Linter knows about this. See Note [Linting of runRW#] in + GHC.Core.Lint for details. + + The occurrence analyser and SetLevels also know about this, as described in + Note [Simplification of runRW#]. + +Other relevant Notes: -It's correctness needs no special treatment in GHC except this special inlining -here in CorePrep (and in GHC.CoreToByteCode). + * Note [Simplification of runRW#] below, describing a transformation of runRW + applications in strict contexts performed by the simplifier. + * Note [Linting of runRW#] in GHC.Core.Lint + * Note [runRW arg] below, describing a non-obvious case where the + late-inlining could go wrong. -However, there are a variety of optimisation opportunities that the simplifier -takes advantage of. See Note [Simplification of runRW#]. + + Note [runRW arg] +~~~~~~~~~~~~~~~~~~~ +Consider the Core program (from #11291), + + runRW# (case bot of {}) + +The late inlining logic in cpe_app would transform this into: + + (case bot of {}) realWorldPrimId# + +Which would rise to a panic in CoreToStg.myCollectArgs, which expects only +variables in function position. + +However, as runRW#'s strictness signature captures the fact that it will call +its argument this can't happen: the simplifier will transform the bottoming +application into simply (case bot of {}). + +Note that this reasoning does *not* apply to non-bottoming continuations like: + + hello :: Bool -> Int + hello n = + runRW# ( + case n of + True -> \s -> 23 + _ -> \s -> 10) + +Why? The difference is that (case bot of {}) is considered by okCpeArg to be +trivial, consequently cpeArg (which the catch-all case of cpe_app calls on both +the function and the arguments) will forgo binding it to a variable. By +contrast, in the non-bottoming case of `hello` above the function will be +deemed non-trivial and consequently will be case-bound. Note [Simplification of runRW#] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Consider the program, - case runRW# (\s -> let n = I# 42# in n) of + case runRW# (\s -> I# 42#) of I# n# -> f n# There is no reason why we should allocate an I# constructor given that we -immediately destructure it. To avoid this the simplifier will push strict -contexts into runRW's continuation. That is, it transforms +immediately destructure it. + +To avoid this the simplifier has a special transformation rule, specific to +runRW#, that pushes a strict context into runRW#'s continuation. See the +`runRW#` guard in `GHC.Core.Opt.Simplify.rebuildCall`. That is, it transforms K[ runRW# @r @ty cont ] ~> - runRW# @r @ty K[cont] + runRW# @r @ty (\s -> K[cont s]) This has a few interesting implications. Consider, for instance, this program: @@ -971,15 +1017,29 @@ Performing the transform described above would result in: If runRW# were a "normal" function this call to join point j would not be allowed in its continuation argument. However, since runRW# is inlined (as described in Note [runRW magic] above), such join point occurences are -completely fine. Both occurrence analysis and Core Lint have special treatment -for runRW# applications. See Note [Linting of runRW#] for details on the latter. +completely fine. Both occurrence analysis (see the runRW guard in occAnalApp) +and Core Lint (see the App case of lintCoreExpr) have special treatment for +runRW# applications. See Note [Linting of runRW#] for details on the latter. Moreover, it's helpful to ensure that runRW's continuation isn't floated out -(since doing so would then require a call, whereas we would otherwise end up -with straight-line). Consequently, GHC.Core.Opt.SetLevels.lvlApp has special -treatment for runRW# applications, ensure the arguments are not floated if +For instance, if we have + + runRW# (\s -> do_something) + +where do_something contains only top-level free variables, we may be tempted to +float the argument to the top-level. However, we must resist this urge as since +doing so would then require that runRW# produce an allocation and call, e.g.: + + let lvl = \s -> do_somethign + in + ....(runRW# lvl).... + +whereas without floating the inlining of the definition of runRW would result +in straight-line code. Consequently, GHC.Core.Opt.SetLevels.lvlApp has special +treatment for runRW# applications, ensure the arguments are not floated as MFEs. + Other considered designs ------------------------ ===================================== libraries/ghc-prim/GHC/Magic.hs ===================================== @@ -122,7 +122,7 @@ oneShot f = f runRW# :: forall (r :: RuntimeRep) (o :: TYPE r). (State# RealWorld -> o) -> o --- See Note [runRW magic] in CorePrep +-- See Note [runRW magic] in GHC.CoreToStg.Prep. {-# NOINLINE runRW# #-} -- runRW# is inlined manually in CorePrep #if !defined(__HADDOCK_VERSION__) runRW# m = m realWorld# ===================================== testsuite/tests/codeGen/should_compile/T18291.hs ===================================== @@ -0,0 +1,7 @@ +{-# LANGUAGE MagicHash #-} +module T18291 where + +import GHC.Magic + +hi :: Int +hi = runRW# $ \_ -> 42 ===================================== testsuite/tests/codeGen/should_compile/all.T ===================================== @@ -91,6 +91,7 @@ test('T17648', normal, makefile_test, []) test('T17904', normal, compile, ['-O']) test('T18227A', normal, compile, ['']) test('T18227B', normal, compile, ['']) +test('T18291', normal, compile, ['-O0']) test('T15570', when(unregisterised(), skip), compile, ['-Wno-overflowed-literals']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/55fd1dc55990623dcf3b2e6143e766242315d757...3ac6ae7c8d5a66bfe36973d1e92f3feef482d589 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/55fd1dc55990623dcf3b2e6143e766242315d757...3ac6ae7c8d5a66bfe36973d1e92f3feef482d589 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 19:39:37 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 18 Aug 2020 15:39:37 -0400 Subject: [Git][ghc/ghc][master] install: do not install sphinx doctrees Message-ID: <5f3c2e79244cf_80b3f8468e8ce9485679ae@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 1 changed file: - ghc.mk Changes: ===================================== ghc.mk ===================================== @@ -934,6 +934,11 @@ ifneq "$(INSTALL_HTML_DOC_DIRS)" "" for i in $(INSTALL_HTML_DOC_DIRS); do \ $(CP) -Rp $$i "$(DESTDIR)$(docdir)/html"; \ done + for i in "$(DESTDIR)$(docdir)/html"/*/.doctrees; do \ + if [ -d "$$i" ]; then \ + rm -r "$$i"; \ + fi \ + done endif INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a87a0b498f4c93c33e3db8d7f68fbaa5d812b408 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a87a0b498f4c93c33e3db8d7f68fbaa5d812b408 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 19:40:09 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 18 Aug 2020 15:40:09 -0400 Subject: [Git][ghc/ghc][master] 2 commits: testsuite: Allow baseline commit to be set explicitly Message-ID: <5f3c2e996afa1_80b3f8468e8ce948568171@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 8 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - hadrian/src/Settings/Builders/RunTest.hs - testsuite/driver/perf_notes.py - testsuite/driver/runtests.py - testsuite/driver/testglobals.py - testsuite/driver/testlib.py - testsuite/mk/test.mk Changes: ===================================== .gitlab-ci.yml ===================================== @@ -26,12 +26,28 @@ stages: - testing # head.hackage correctness and compiler performance testing - deploy # push documentation +# Note [The CI Story] +# ~~~~~~~~~~~~~~~~~~~ +# +# There are two different types of pipelines: +# +# - marge-bot merges to `master`. Here we perform an exhaustive validation +# across all of the platforms which we support. In addition, we push +# performance metric notes upstream, providing a persistent record of the +# performance characteristics of the compiler. +# +# - merge requests. Here we perform a slightly less exhaustive battery of +# testing. Namely we omit some configurations (e.g. the unregisterised job). +# These use the merge request's base commit for performance metric +# comparisons. +# + workflow: - # N.B.Don't run on wip/ branches, instead on run on merge requests. + # N.B. Don't run on wip/ branches, instead on run on merge requests. rules: - if: $CI_MERGE_REQUEST_ID - if: $CI_COMMIT_TAG - - if: '$CI_COMMIT_BRANCH == "master"' + - if: '$CI_COMMIT_BRANCH == "wip/marge_bot_batch_merge_job"' - if: '$CI_COMMIT_BRANCH =~ /ghc-[0.9]+\.[0-9]+/' - if: '$CI_PIPELINE_SOURCE == "web"' ===================================== .gitlab/ci.sh ===================================== @@ -363,6 +363,13 @@ function push_perf_notes() { "$TOP/.gitlab/test-metrics.sh" push } +# Figure out which commit should be used by the testsuite driver as a +# performance baseline. See Note [The CI Story]. +function determine_metric_baseline() { + export PERF_BASELINE_COMMIT="$(git merge-base $CI_MERGE_REQUEST_TARGET_BRANCH_NAME HEAD)" + info "Using $PERF_BASELINE_COMMIT for performance metric baseline..." +} + function test_make() { run "$MAKE" test_bindist TEST_PREP=YES run "$MAKE" V=0 test \ ===================================== hadrian/src/Settings/Builders/RunTest.hs ===================================== @@ -78,6 +78,7 @@ runTestBuilderArgs = builder RunTest ? do <*> (maybe False (=="YES") <$> lookupEnv "OS") (testEnv, testMetricsFile) <- expr . liftIO $ (,) <$> lookupEnv "TEST_ENV" <*> lookupEnv "METRICS_FILE" + perfBaseline <- expr . liftIO $ lookupEnv "PERF_BASELINE_COMMIT" threads <- shakeThreads <$> expr getShakeOptions os <- getTestSetting TestHostOS @@ -141,6 +142,9 @@ runTestBuilderArgs = builder RunTest ? do , arg "--config", arg $ "timeout_prog=" ++ show (top -/- timeoutProg) , arg "--config", arg $ "stats_files_dir=" ++ statsFilesDir , arg $ "--threads=" ++ show threads + , case perfBaseline of + Just commit | not (null commit) -> arg ("--perf-baseline=" ++ show commit) + _ -> mempty , emitWhenSet testEnv $ \env -> arg ("--test-env=" ++ show env) , emitWhenSet testMetricsFile $ \file -> arg ("--metrics-file=" ++ file) , getTestArgs -- User-provided arguments from command line. ===================================== testsuite/driver/perf_notes.py ===================================== @@ -76,8 +76,7 @@ PerfStat = NamedTuple('PerfStat', [('test_env', TestEnv), # A baseline recovered form stored metrics. Baseline = NamedTuple('Baseline', [('perfStat', PerfStat), - ('commit', GitHash), - ('commitDepth', int)]) + ('commit', GitHash)]) class MetricChange(Enum): # The metric appears to have no baseline and is presumably a new test. @@ -402,7 +401,8 @@ def baseline_metric(commit: GitHash, name: TestName, test_env: TestEnv, metric: MetricName, - way: WayName + way: WayName, + baseline_ref: Optional[GitRef] ) -> Optional[Baseline]: # For performance reasons (in order to avoid calling commit_hash), we assert # commit is already a commit hash. @@ -411,6 +411,8 @@ def baseline_metric(commit: GitHash, # Get all recent commit hashes. commit_hashes = baseline_commit_log(commit) + baseline_commit = commit_hash(baseline_ref) if baseline_ref else None + def has_expected_change(commit: GitHash) -> bool: return get_allowed_perf_changes(commit).get(name) is not None @@ -418,11 +420,18 @@ def baseline_metric(commit: GitHash, def find_baseline(namespace: NoteNamespace, test_env: TestEnv ) -> Optional[Baseline]: + if baseline_commit is not None: + current_metric = get_commit_metric(namespace, baseline_commit, test_env, name, metric, way) + if current_metric is not None: + return Baseline(current_metric, baseline_commit) + else: + return None + for depth, current_commit in list(enumerate(commit_hashes))[1:]: # Check for a metric on this commit. current_metric = get_commit_metric(namespace, current_commit, test_env, name, metric, way) if current_metric is not None: - return Baseline(current_metric, current_commit, depth) + return Baseline(current_metric, current_commit) # Stop if there is an expected change at this commit. In that case # metrics on ancestor commits will not be a valid baseline. @@ -552,7 +561,7 @@ def check_stats_change(actual: PerfStat, result = passed() if not change_allowed: error = str(change) + ' from ' + baseline.perfStat.test_env + \ - ' baseline @ HEAD~' + str(baseline.commitDepth) + ' baseline @ %s' % baseline.commit print(actual.metric, error + ':') result = failBecause('stat ' + error, tag='stat') ===================================== testsuite/driver/runtests.py ===================================== @@ -27,7 +27,7 @@ from testutil import getStdout, Watcher, str_warn, str_info from testglobals import getConfig, ghc_env, getTestRun, TestConfig, \ TestOptions, brokens, PerfMetric from my_typing import TestName -from perf_notes import MetricChange, inside_git_repo, is_worktree_dirty, format_perf_stat +from perf_notes import MetricChange, GitRef, inside_git_repo, is_worktree_dirty, format_perf_stat from junit import junit import term_color from term_color import Color, colored @@ -70,6 +70,7 @@ parser.add_argument("--verbose", type=int, choices=[0,1,2,3,4,5], help="verbose parser.add_argument("--junit", type=argparse.FileType('wb'), help="output testsuite summary in JUnit format") parser.add_argument("--broken-test", action="append", default=[], help="a test name to mark as broken for this run") parser.add_argument("--test-env", default='local', help="Override default chosen test-env.") +parser.add_argument("--perf-baseline", type=GitRef, metavar='COMMIT', help="Baseline commit for performance comparsons.") perf_group.add_argument("--skip-perf-tests", action="store_true", help="skip performance tests") perf_group.add_argument("--only-perf-tests", action="store_true", help="Only do performance tests") @@ -101,6 +102,7 @@ config.metrics_file = args.metrics_file hasMetricsFile = config.metrics_file is not None config.summary_file = args.summary_file config.no_print_summary = args.no_print_summary +config.baseline_commit = args.perf_baseline if args.only: config.only = args.only @@ -351,8 +353,8 @@ def tabulate_metrics(metrics: List[PerfMetric]) -> None: rel = 100 * (val1 - val0) / val0 print("{space:24} {herald:40} {value:15.3f} [{direction}, {rel:2.1f}%]".format( space = "", - herald = "(baseline @ HEAD~{depth})".format( - depth = metric.baseline.commitDepth), + herald = "(baseline @ {commit})".format( + commit = metric.baseline.commit), value = val0, direction = metric.change, rel = rel @@ -422,6 +424,8 @@ else: # Dump metrics data. print("\nPerformance Metrics (test environment: {}):\n".format(config.test_env)) + if config.baseline_commit: + print('Performance baseline: %s\n' % config.baseline_commit) if any(t.metrics): tabulate_metrics(t.metrics) else: @@ -477,19 +481,19 @@ else: summary(t, sys.stdout, config.no_print_summary, config.supports_colors) # Write perf stats if any exist or if a metrics file is specified. - stats = [stat for (_, stat, __) in t.metrics] + stats_metrics = [stat for (_, stat, __) in t.metrics] # type: List[PerfStat] if hasMetricsFile: - print('Appending ' + str(len(stats)) + ' stats to file: ' + config.metrics_file) + print('Appending ' + str(len(stats_metrics)) + ' stats to file: ' + config.metrics_file) with open(config.metrics_file, 'a') as f: - f.write("\n" + Perf.format_perf_stat(stats)) - elif inside_git_repo() and any(stats): + f.write("\n" + Perf.format_perf_stat(stats_metrics)) + elif inside_git_repo() and any(stats_metrics): if is_worktree_dirty(): print() print(str_warn('Performance Metrics NOT Saved') + \ ' working tree is dirty. Commit changes or use ' + \ '--metrics-file to save metrics to a file.') else: - Perf.append_perf_stat(stats) + Perf.append_perf_stat(stats_metrics) # Write summary if config.summary_file: ===================================== testsuite/driver/testglobals.py ===================================== @@ -4,7 +4,7 @@ from my_typing import * from pathlib import Path -from perf_notes import MetricChange, PerfStat, Baseline, MetricOracles +from perf_notes import MetricChange, PerfStat, Baseline, MetricOracles, GitRef from datetime import datetime # ----------------------------------------------------------------------------- @@ -163,6 +163,9 @@ class TestConfig: # run. self.broken_tests = set() # type: Set[TestName] + # Baseline commit for performane metric comparisons. + self.baseline_commit = None # type: Optional[GitRef] + # Should we skip performance tests self.skip_perf_tests = False ===================================== testsuite/driver/testlib.py ===================================== @@ -477,7 +477,8 @@ def _collect_stats(name: TestName, opts, metrics, deviation, is_compiler_stats_t metric = '{}/{}'.format(tag, metric_name) def baselineByWay(way, target_commit, metric=metric): return Perf.baseline_metric( \ - target_commit, name, config.test_env, metric, way) + target_commit, name, config.test_env, metric, way, \ + config.baseline_commit ) opts.stats_range_fields[metric] = MetricOracles(baseline=baselineByWay, deviation=deviation) ===================================== testsuite/mk/test.mk ===================================== @@ -232,6 +232,10 @@ ifneq "$(VERBOSE)" "" RUNTEST_OPTS += --verbose=$(VERBOSE) endif +ifneq "$(PERF_TEST_BASELINE_COMMIT)" "" +RUNTEST_OPTS += --perf-baseline=$(PERF_TEST_BASELINE_COMMIT) +endif + ifeq "$(SKIP_PERF_TESTS)" "YES" RUNTEST_OPTS += --skip-perf-tests endif View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a87a0b498f4c93c33e3db8d7f68fbaa5d812b408...fdcf76450348d0554b7fd1768331f9efaf691e13 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a87a0b498f4c93c33e3db8d7f68fbaa5d812b408...fdcf76450348d0554b7fd1768331f9efaf691e13 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 19:40:45 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 18 Aug 2020 15:40:45 -0400 Subject: [Git][ghc/ghc][master] Expose UnitInfoMap as it is part of the public API Message-ID: <5f3c2ebd21cf6_80b3f84693c1eb48571242@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - 1 changed file: - compiler/GHC/Unit/State.hs Changes: ===================================== compiler/GHC/Unit/State.hs ===================================== @@ -18,6 +18,7 @@ module GHC.Unit.State ( listUnitInfo, -- * Querying the package config + UnitInfoMap, lookupUnit, lookupUnit', unsafeLookupUnit, View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9ad5cab33b8b78a346896cc6de555365c73e6298 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9ad5cab33b8b78a346896cc6de555365c73e6298 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 20:11:37 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 18 Aug 2020 16:11:37 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 8 commits: Allow unsaturated runRW# applications Message-ID: <5f3c35f9b7a80_80b3f848629827885812f6@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - 87746a36 by Ben Gamari at 2020-08-18T16:11:28-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 583ec18d by Sylvain Henry at 2020-08-18T16:11:31-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - compiler/GHC/Cmm.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/Instr.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs - + compiler/GHC/CmmToAsm/PPC.hs - compiler/GHC/CmmToAsm/PPC/CodeGen.hs - compiler/GHC/CmmToAsm/PPC/Instr.hs - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/Reg/Graph.hs - compiler/GHC/CmmToAsm/Reg/Graph/SpillCost.hs - compiler/GHC/CmmToAsm/Reg/Graph/Stats.hs - compiler/GHC/CmmToAsm/Reg/Linear.hs - compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs - compiler/GHC/CmmToAsm/Reg/Linear/Stats.hs - compiler/GHC/CmmToAsm/Reg/Liveness.hs - + compiler/GHC/CmmToAsm/SPARC.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen/Expand.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen/Gen64.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen/Sanity.hs - compiler/GHC/CmmToAsm/SPARC/Instr.hs - compiler/GHC/CmmToAsm/SPARC/Ppr.hs - + compiler/GHC/CmmToAsm/Types.hs - + compiler/GHC/CmmToAsm/Utils.hs - + compiler/GHC/CmmToAsm/X86.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2330b4b9709ca4f20cb029bc39a0c7c6a33d73b0...583ec18d44e75b47376e1cab5585e5dbc055b16c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2330b4b9709ca4f20cb029bc39a0c7c6a33d73b0...583ec18d44e75b47376e1cab5585e5dbc055b16c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 18 20:21:02 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Tue, 18 Aug 2020 16:21:02 -0400 Subject: [Git][ghc/ghc][wip/az/exactprint] 128 commits: Revert "AArch32 symbols only on aarch32." Message-ID: <5f3c382e2496f_80b3f8468e8ce9485814b2@gitlab.haskell.org.mail> Alan Zimmerman pushed to branch wip/az/exactprint at Glasgow Haskell Compiler / GHC Commits: 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - 09417957 by Alan Zimmerman at 2020-08-11T23:54:36+01:00 Proof of Concept implementation of in-tree API Annotations This MR introduces a possible machinery to introduce API Annotations into the TTG extension points. It is intended to be a concrete example for discussion. It still needs to process comments. ---- Work in progress, adding more TTG extensions for annotations. And fixing ppr round-trip tests by being able to blank out in-tree annotations, as done with SrcSpans. This is needed for the case of class Foo a where for which current ppr does not print the "where". Rename AA to AddApiAnn and AA to AddAnn Add XConPatIn and XConPatOut Rebase ---- First pass at bringing in LocatedA for API anns in locations Treatment of ECP in parsing is provisional at this stage, leads to some horribly stuff in Parser.y and RdrHsSyn. It is an extensive but not invasive change. I think (AZ). Locally it reports some parsing tests using less memory. Add ApiAnns to the HsExpr data structure. rebase. Change HsMatchContext and HsStmtContext to use an id, not a GhcPass parameter. Add ApiAnns to Hs/Types Rebase Rebased 2020-03-25 WIP on in-tree annotations Includes updating HsModule Imports LocateA ImportDecl so we can hang AnnSemi off it A whole bunch of stuff more InjectivityAnn and FamEqn now have annotations in them Add annotations to context srcspan ---- In-tree annotations: LHsDecl and LHsBind LocatedA ---- WIP on in-tree annotations ---- in-tree annotations: LHsType is now LocatedA ---- FunDeps is now also a HS data type ---- WIP. Added LocatedA to Pat, Expr, Decl And worked some more through Parser.y ---- LStmt now Located ---- Finished working through Parser.y, tests seem ok failures relate to annotations. Adding test infrastructure for check-exact Like check-ppr, but checking for an exact reproduction of the parsed source file. Starting to work on actual exact printer Bring in ApiAnnName As an alternative for LocatedA, to be used for names only. Carrying extra name adornments, such as locations of backticks, parens, etc. Working on changing ApiAnnName to accurately reflect actual usage Get rid of AnnApiName in favour of LocatedN Working on check-exact. Making progress Working on the ghc-exact bit Progress, can reproduce the first Test.hs file. Move API Annotations out of the extensions to annotations - - - - - 6ed01596 by Alan Zimmerman at 2020-08-12T00:01:18+01:00 Remove LHsLocalBinds - - - - - 45bd07cb by Alan Zimmerman at 2020-08-18T21:19:15+01:00 Fix up after rebasing to bring in XRec Main thing is to make type instance XRec (GhcPass p) a = GenLocated (Anno a) a type family Anno a = b But this has massive implications. - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/test-metrics.sh - .gitmodules - CODEOWNERS - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/Graph.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Monad.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Pipeline.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Switch/Implement.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e676cc0e16137042103b83a5440726d1eb9ebb6e...45bd07cb195cac1f41dbff13a109cb4326e1f09a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e676cc0e16137042103b83a5440726d1eb9ebb6e...45bd07cb195cac1f41dbff13a109cb4326e1f09a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 19 02:11:39 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 18 Aug 2020 22:11:39 -0400 Subject: [Git][ghc/ghc][master] testsuite: Only run llvm ways if llc is available Message-ID: <5f3c8a5ba9d10_80b3f8468e8ce948587161@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 4 changed files: - hadrian/src/Settings/Builders/RunTest.hs - testsuite/config/ghc - testsuite/driver/testglobals.py - testsuite/mk/test.mk Changes: ===================================== hadrian/src/Settings/Builders/RunTest.hs ===================================== @@ -70,7 +70,6 @@ runTestBuilderArgs = builder RunTest ? do withSMP <- getBooleanSetting TestGhcWithSMP debugged <- getBooleanSetting TestGhcDebugged keepFiles <- expr (testKeepFiles <$> userSetting defaultTestArgs) - withLlvm <- expr (not . null <$> settingsFileSetting SettingsFileSetting_LlcCommand) accept <- expr (testAccept <$> userSetting defaultTestArgs) (acceptPlatform, acceptOS) <- expr . liftIO $ @@ -126,8 +125,6 @@ runTestBuilderArgs = builder RunTest ? do , arg "-e", arg $ asBool "config.have_profiling=" (hasLibWay profiling) , arg "-e", arg $ asBool "config.have_fast_bignum=" (bignumBackend /= "native" && not bignumCheck) , arg "-e", arg $ asBool "ghc_with_smp=" withSMP - , arg "-e", arg $ asBool "ghc_with_llvm=" withLlvm - , arg "-e", arg $ "config.ghc_dynamic_by_default=" ++ show hasDynamicByDefault , arg "-e", arg $ "config.ghc_dynamic=" ++ show hasDynamic ===================================== testsuite/config/ghc ===================================== @@ -64,10 +64,6 @@ else: if (config.have_profiling and ghc_with_threaded_rts): config.run_ways.append('profthreaded') -if (ghc_with_llvm and not config.unregisterised): - config.compile_ways.append('optllvm') - config.run_ways.append('optllvm') - # WinIO I/O manager for Windows if windows: winio_ways = ['winio', 'winio_threaded'] @@ -195,6 +191,17 @@ def get_compiler_info(): config.have_ncg = compilerInfoDict.get("Have native code generator", "NO") == "YES" + # Detect whether an LLVM toolhain is available + llc_path = compilerInfoDict.get("LLVM llc command") + config.have_llvm = shutil.which(llc_path) is not None + if config.unregisterised: + print("Unregisterised build; skipping LLVM ways...") + elif config.have_llvm: + config.compile_ways.append('optllvm') + config.run_ways.append('optllvm') + else: + print("Failed to find `llc` command; skipping LLVM ways...") + # Whether GHC itself was built using the LLVM backend. We need to know this # since some tests in ext-interp fail when stage2 ghc is built using # LLVM. See #16087. ===================================== testsuite/driver/testglobals.py ===================================== @@ -115,6 +115,9 @@ class TestConfig: self.way_flags = {} # type: Dict[WayName, List[str]] self.way_rts_flags = {} # type: Dict[WayName, List[str]] + # Do we have a functional LLVM toolchain? + self.have_llvm = False + # Do we have vanilla libraries? self.have_vanilla = False ===================================== testsuite/mk/test.mk ===================================== @@ -194,18 +194,6 @@ else RUNTEST_OPTS += -e ghc_with_smp=False endif -# Does the LLVM backend work? -ifeq "$(LLC)" "" -RUNTEST_OPTS += -e ghc_with_llvm=False -else ifeq "$(TargetARCH_CPP)" "powerpc" -RUNTEST_OPTS += -e ghc_with_llvm=False -else ifneq "$(LLC)" "llc" -# If we have a real detected value for LLVM, then it really ought to work -RUNTEST_OPTS += -e ghc_with_llvm=True -else -RUNTEST_OPTS += -e ghc_with_llvm=False -endif - ifeq "$(WINDOWS)" "YES" RUNTEST_OPTS += -e windows=True else View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/aa4b744d51aa6bdb46064f981ea8e001627921d6 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/aa4b744d51aa6bdb46064f981ea8e001627921d6 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 19 02:12:16 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 18 Aug 2020 22:12:16 -0400 Subject: [Git][ghc/ghc][master] DynFlags: refactor GHC.CmmToAsm (#17957, #10143) Message-ID: <5f3c8a80a16a_80b40e7e108591341@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 30 changed files: - compiler/GHC/Cmm.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/Instr.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs - + compiler/GHC/CmmToAsm/PPC.hs - compiler/GHC/CmmToAsm/PPC/CodeGen.hs - compiler/GHC/CmmToAsm/PPC/Instr.hs - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/Reg/Graph.hs - compiler/GHC/CmmToAsm/Reg/Graph/SpillCost.hs - compiler/GHC/CmmToAsm/Reg/Graph/Stats.hs - compiler/GHC/CmmToAsm/Reg/Linear.hs - compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs - compiler/GHC/CmmToAsm/Reg/Linear/Stats.hs - compiler/GHC/CmmToAsm/Reg/Liveness.hs - + compiler/GHC/CmmToAsm/SPARC.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen/Expand.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen/Gen64.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen/Sanity.hs - compiler/GHC/CmmToAsm/SPARC/Instr.hs - compiler/GHC/CmmToAsm/SPARC/Ppr.hs - + compiler/GHC/CmmToAsm/Types.hs - + compiler/GHC/CmmToAsm/Utils.hs - + compiler/GHC/CmmToAsm/X86.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/CmmToAsm/X86/Instr.hs - compiler/GHC/CmmToAsm/X86/Ppr.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0c5ed5c7eb30bc5462b67ff097c3388597265a4b -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0c5ed5c7eb30bc5462b67ff097c3388597265a4b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 19 10:10:09 2020 From: gitlab at gitlab.haskell.org (Peter Trommler) Date: Wed, 19 Aug 2020 06:10:09 -0400 Subject: [Git][ghc/ghc][wip/cross-ppr-floats] 9 commits: Allow unsaturated runRW# applications Message-ID: <5f3cfa81adf04_80b3f84862982788602020@gitlab.haskell.org.mail> Peter Trommler pushed to branch wip/cross-ppr-floats at Glasgow Haskell Compiler / GHC Commits: f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 5fe1ecb2 by Peter Trommler at 2020-08-19T12:09:03+02:00 PPC and X86: Portable printing of IEEE floats GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness. This was brought up in #18431 by @hsyl20. - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - compiler/GHC/Cmm.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/Instr.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs - + compiler/GHC/CmmToAsm/PPC.hs - compiler/GHC/CmmToAsm/PPC/CodeGen.hs - compiler/GHC/CmmToAsm/PPC/Instr.hs - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/Ppr.hs - compiler/GHC/CmmToAsm/Reg/Graph.hs - compiler/GHC/CmmToAsm/Reg/Graph/SpillCost.hs - compiler/GHC/CmmToAsm/Reg/Graph/Stats.hs - compiler/GHC/CmmToAsm/Reg/Linear.hs - compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs - compiler/GHC/CmmToAsm/Reg/Linear/Stats.hs - compiler/GHC/CmmToAsm/Reg/Liveness.hs - + compiler/GHC/CmmToAsm/SPARC.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen/Expand.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen/Gen64.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen/Sanity.hs - compiler/GHC/CmmToAsm/SPARC/Instr.hs - compiler/GHC/CmmToAsm/SPARC/Ppr.hs - + compiler/GHC/CmmToAsm/Types.hs - + compiler/GHC/CmmToAsm/Utils.hs - + compiler/GHC/CmmToAsm/X86.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d914ea7ab6d4ab3e26b31e558156bd6aec268a90...5fe1ecb271156e8a90c30dfcf5c3e2586fbfa43c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d914ea7ab6d4ab3e26b31e558156bd6aec268a90...5fe1ecb271156e8a90c30dfcf5c3e2586fbfa43c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 19 11:22:35 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Wed, 19 Aug 2020 07:22:35 -0400 Subject: [Git][ghc/ghc][wip/T18126] 28 commits: Correct a typo in ghc.mk Message-ID: <5f3d0b7b8f3c2_80b3f84693c1eb4860901f@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18126 at Glasgow Haskell Compiler / GHC Commits: 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 8a7d504b by Simon Peyton Jones at 2020-08-19T12:22:06+01:00 Implement Quick Look impredicativity This patch implements Quick Look impredicativity (#18126), sticking very closely to the design in A quick look at impredicativity, Serrano et al, ICFP 2020 The main change is that a big chunk of GHC.Tc.Gen.Expr has been extracted to two new modules GHC.Tc.Gen.App GHC.Tc.Gen.Head which deal with typechecking n-ary applications, and the head of such applications, respectively. Both contain a good deal of documentation. Three other loosely-related changes are in this patch: * I implemented (partly by accident) point (2) of the accepted GHC proposal "Clean up printing of foralls", namely https://github.com/ghc-proposals/ghc-proposals/blob/ master/proposals/0179-printing-foralls.rst In particular, see Note [TcRnExprMode] in GHC.Tc.Module - :type instantiates /inferred/, but not /specified/, quantifiers - :type +d instantiates /all/ quantifiers - :type +v is killed off * HsRecFld (which the renamer introduces for record field selectors), is now preserved by the typechecker, rather than being rewritten back to HsVar. This is more uniform, and turned out to be more convenient in the new scheme of things. * The GHCi debugger uses a non-standard unification that allows the unification variables to unify with polytypes. We used to hack this by using ImpredicativeTypes, but that doesn't work anymore so I introduces RuntimeUnkTv. See Note [RuntimeUnkTv] in GHC.Runtime.Heap.Inspect WARNING: this patch won't validate on its own. It was too hard to fully disentangle it from the following patch, on type errors and kind generalisation. Changes to tests * Fixes #9730 (test added) * Fixes #7026 (test added) * Fixes most of #8808, except function `g2'` which uses a section (which doesn't play with QL yet -- see #18126) Test added * Fixes #1330. NB Church1.hs subsumes Church2.hs, which is now deleted * Fixes #17332 (test added) * Fixes #4295 * This patch makes typecheck/should_run/T7861 fail. But that turns out to be a pre-existing bug: #18467. So I have just made T7861 into expect_broken(18467) - - - - - 862cb017 by Simon Peyton Jones at 2020-08-19T12:22:07+01:00 Improve kind generalisation, error messages This patch does two things: * It refactors GHC.Tc.Errors a bit. In debugging Quick Look I was forced to look in detail at error messages, and ended up doing a bit of refactoring, esp in mkTyVarEqErr'. It's still quite a mess, but a bit better, I think. * It makes a significant improvement to the kind checking of type and class declarations. Specifically, we now ensure that if kind checking fails with an unsolved constraint, all the skolems are in scope. That wasn't the case before, which led to some obscure error messages; and occasional failures with "no skolem info" (eg #16245). Both of these, and the main Quick Look patch itself, affect a /lot/ of error messages, as you can see from the number of files changed. I've checked them all; I think they are as good or better than before. Smaller things * I documented the various instances of VarBndr better. See Note [The VarBndr tyep and its uses] in GHC.Types.Var * Renamed GHC.Tc.Solver.simpl_top to simplifyTopWanteds * A bit of refactoring in bindExplicitTKTele, to avoid the footwork with Either. Simpler now. * Move promoteTyVar from GHC.Tc.Solver to GHC.Tc.Utils.TcMType Fixes #16245 (comment 211369), memorialised as typeecheck/polykinds/T16245a - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - compiler/GHC.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Switch.hs - compiler/GHC/Cmm/Type.hs - compiler/GHC/Cmm/Utils.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - compiler/GHC/CmmToAsm/CPrim.hs - compiler/GHC/CmmToAsm/Dwarf.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/53904905fc1bf26a1834f344bbd52eeb9be6937f...862cb0171d716dc96f9786d35881d0c437a6de4e -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/53904905fc1bf26a1834f344bbd52eeb9be6937f...862cb0171d716dc96f9786d35881d0c437a6de4e You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 19 13:11:06 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Wed, 19 Aug 2020 09:11:06 -0400 Subject: [Git][ghc/ghc][wip/T18126] 2 commits: Implement Quick Look impredicativity Message-ID: <5f3d24eaa2c1c_80b3f8486b5b7c08619278@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18126 at Glasgow Haskell Compiler / GHC Commits: ab84e960 by Simon Peyton Jones at 2020-08-19T14:10:46+01:00 Implement Quick Look impredicativity This patch implements Quick Look impredicativity (#18126), sticking very closely to the design in A quick look at impredicativity, Serrano et al, ICFP 2020 The main change is that a big chunk of GHC.Tc.Gen.Expr has been extracted to two new modules GHC.Tc.Gen.App GHC.Tc.Gen.Head which deal with typechecking n-ary applications, and the head of such applications, respectively. Both contain a good deal of documentation. Three other loosely-related changes are in this patch: * I implemented (partly by accident) point (2) of the accepted GHC proposal "Clean up printing of foralls", namely https://github.com/ghc-proposals/ghc-proposals/blob/ master/proposals/0179-printing-foralls.rst In particular, see Note [TcRnExprMode] in GHC.Tc.Module - :type instantiates /inferred/, but not /specified/, quantifiers - :type +d instantiates /all/ quantifiers - :type +v is killed off * HsRecFld (which the renamer introduces for record field selectors), is now preserved by the typechecker, rather than being rewritten back to HsVar. This is more uniform, and turned out to be more convenient in the new scheme of things. * The GHCi debugger uses a non-standard unification that allows the unification variables to unify with polytypes. We used to hack this by using ImpredicativeTypes, but that doesn't work anymore so I introduces RuntimeUnkTv. See Note [RuntimeUnkTv] in GHC.Runtime.Heap.Inspect WARNING: this patch won't validate on its own. It was too hard to fully disentangle it from the following patch, on type errors and kind generalisation. Changes to tests * Fixes #9730 (test added) * Fixes #7026 (test added) * Fixes most of #8808, except function `g2'` which uses a section (which doesn't play with QL yet -- see #18126) Test added * Fixes #1330. NB Church1.hs subsumes Church2.hs, which is now deleted * Fixes #17332 (test added) * Fixes #4295 * This patch makes typecheck/should_run/T7861 fail. But that turns out to be a pre-existing bug: #18467. So I have just made T7861 into expect_broken(18467) - - - - - b544bb03 by Simon Peyton Jones at 2020-08-19T14:10:46+01:00 Improve kind generalisation, error messages This patch does two things: * It refactors GHC.Tc.Errors a bit. In debugging Quick Look I was forced to look in detail at error messages, and ended up doing a bit of refactoring, esp in mkTyVarEqErr'. It's still quite a mess, but a bit better, I think. * It makes a significant improvement to the kind checking of type and class declarations. Specifically, we now ensure that if kind checking fails with an unsolved constraint, all the skolems are in scope. That wasn't the case before, which led to some obscure error messages; and occasional failures with "no skolem info" (eg #16245). Both of these, and the main Quick Look patch itself, affect a /lot/ of error messages, as you can see from the number of files changed. I've checked them all; I think they are as good or better than before. Smaller things * I documented the various instances of VarBndr better. See Note [The VarBndr tyep and its uses] in GHC.Types.Var * Renamed GHC.Tc.Solver.simpl_top to simplifyTopWanteds * A bit of refactoring in bindExplicitTKTele, to avoid the footwork with Either. Simpler now. * Move promoteTyVar from GHC.Tc.Solver to GHC.Tc.Utils.TcMType Fixes #16245 (comment 211369), memorialised as typeecheck/polykinds/T16245a - - - - - 19 changed files: - compiler/GHC/Core/TyCon.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/HsToCore/Coverage.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/Iface/Ext/Ast.hs - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Rename/Pat.hs - compiler/GHC/Runtime/Eval.hs - compiler/GHC/Runtime/Heap/Inspect.hs - compiler/GHC/Tc/Deriv/Generate.hs - compiler/GHC/Tc/Errors.hs - compiler/GHC/Tc/Errors/Hole.hs - + compiler/GHC/Tc/Gen/App.hs - compiler/GHC/Tc/Gen/Arrow.hs - compiler/GHC/Tc/Gen/Default.hs - compiler/GHC/Tc/Gen/Expr.hs - compiler/GHC/Tc/Gen/Expr.hs-boot The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/862cb0171d716dc96f9786d35881d0c437a6de4e...b544bb035171e0ce2966d37c5cea1feecba60907 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/862cb0171d716dc96f9786d35881d0c437a6de4e...b544bb035171e0ce2966d37c5cea1feecba60907 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 19 16:22:43 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Wed, 19 Aug 2020 12:22:43 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18223 Message-ID: <5f3d51d372aef_80b1075951c86401c5@gitlab.haskell.org.mail> Simon Peyton Jones pushed new branch wip/T18223 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18223 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 19 16:47:39 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 19 Aug 2020 12:47:39 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: testsuite: Only run llvm ways if llc is available Message-ID: <5f3d57ab8027a_80b3f8468e8ce948650267@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 97337774 by nineonine at 2020-08-19T12:47:30-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - 74e57004 by Simon Peyton Jones at 2020-08-19T12:47:32-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 30 changed files: - compiler/GHC/Cmm.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/Instr.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs - + compiler/GHC/CmmToAsm/PPC.hs - compiler/GHC/CmmToAsm/PPC/CodeGen.hs - compiler/GHC/CmmToAsm/PPC/Instr.hs - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/Reg/Graph.hs - compiler/GHC/CmmToAsm/Reg/Graph/SpillCost.hs - compiler/GHC/CmmToAsm/Reg/Graph/Stats.hs - compiler/GHC/CmmToAsm/Reg/Linear.hs - compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs - compiler/GHC/CmmToAsm/Reg/Linear/Stats.hs - compiler/GHC/CmmToAsm/Reg/Liveness.hs - + compiler/GHC/CmmToAsm/SPARC.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen/Expand.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen/Gen64.hs - compiler/GHC/CmmToAsm/SPARC/CodeGen/Sanity.hs - compiler/GHC/CmmToAsm/SPARC/Instr.hs - compiler/GHC/CmmToAsm/SPARC/Ppr.hs - + compiler/GHC/CmmToAsm/Types.hs - + compiler/GHC/CmmToAsm/Utils.hs - + compiler/GHC/CmmToAsm/X86.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/CmmToAsm/X86/Instr.hs - compiler/GHC/CmmToAsm/X86/Ppr.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/583ec18d44e75b47376e1cab5585e5dbc055b16c...74e57004c54728ad9e9f1e6af8ebb92365e8ed95 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/583ec18d44e75b47376e1cab5585e5dbc055b16c...74e57004c54728ad9e9f1e6af8ebb92365e8ed95 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 19 22:47:44 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 19 Aug 2020 18:47:44 -0400 Subject: [Git][ghc/ghc][master] Implement -Wredundant-bang-patterns (#17340) Message-ID: <5f3dac1035467_80b1075951c866822a@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - 9 changed files: - compiler/GHC/Driver/Flags.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/PmCheck.hs - + docs/users_guide/9.2.1-notes.rst - docs/users_guide/using-warnings.rst - + testsuite/tests/pmcheck/should_compile/T17340.hs - + testsuite/tests/pmcheck/should_compile/T17340.stderr - testsuite/tests/pmcheck/should_compile/all.T Changes: ===================================== compiler/GHC/Driver/Flags.hs ===================================== @@ -442,6 +442,7 @@ data WarningFlag = | Opt_WarnUnusedTypePatterns | Opt_WarnUnusedForalls | Opt_WarnUnusedRecordWildcards + | Opt_WarnRedundantBangPatterns | Opt_WarnRedundantRecordWildcards | Opt_WarnWarningsDeprecations | Opt_WarnDeprecatedFlags ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -3387,6 +3387,7 @@ wWarningFlagsDeps = [ flagSpec "unused-top-binds" Opt_WarnUnusedTopBinds, flagSpec "unused-type-patterns" Opt_WarnUnusedTypePatterns, flagSpec "unused-record-wildcards" Opt_WarnUnusedRecordWildcards, + flagSpec "redundant-bang-patterns" Opt_WarnRedundantBangPatterns, flagSpec "redundant-record-wildcards" Opt_WarnRedundantRecordWildcards, flagSpec "warnings-deprecations" Opt_WarnWarningsDeprecations, flagSpec "wrong-do-bind" Opt_WarnWrongDoBind, ===================================== compiler/GHC/Hs/Utils.hs ===================================== @@ -885,14 +885,14 @@ BUT we have a special case when abs_sig is true; -- | Should we treat this as an unlifted bind? This will be true for any -- bind that binds an unlifted variable, but we must be careful around -- AbsBinds. See Note [Unlifted id check in isUnliftedHsBind]. For usage --- information, see Note [Strict binds check] is "GHC.HsToCore.Binds". +-- information, see Note [Strict binds checks] is GHC.HsToCore.Binds. isUnliftedHsBind :: HsBind GhcTc -> Bool -- works only over typechecked binds isUnliftedHsBind bind | AbsBinds { abs_exports = exports, abs_sig = has_sig } <- bind = if has_sig then any (is_unlifted_id . abe_poly) exports else any (is_unlifted_id . abe_mono) exports - -- If has_sig is True we wil never generate a binding for abe_mono, + -- If has_sig is True we will never generate a binding for abe_mono, -- so we don't need to worry about it being unlifted. The abe_poly -- binding might not be: e.g. forall a. Num a => (# a, a #) ===================================== compiler/GHC/HsToCore/PmCheck.hs ===================================== @@ -10,6 +10,7 @@ Pattern Matching Coverage Checking. {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE MultiWayIf #-} {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} module GHC.HsToCore.PmCheck ( -- Checking and printing @@ -105,8 +106,12 @@ data PmGrd } -- | @PmBang x@ corresponds to a @seq x True@ guard. + -- If the extra SrcInfo is present, the bang guard came from a source + -- bang pattern, in which case we might want to report it as redundant, + -- see Note [Dead bang patterns]. | PmBang { - pm_id :: !Id + pm_id :: !Id, + pm_loc :: !(Maybe SrcInfo) } -- | @PmLet x expr@ corresponds to a @let x = expr@ guard. This actually @@ -120,7 +125,7 @@ data PmGrd instance Outputable PmGrd where ppr (PmCon x alt _tvs _con_dicts con_args) = hsep [ppr alt, hsep (map ppr con_args), text "<-", ppr x] - ppr (PmBang x) = char '!' <> ppr x + ppr (PmBang x _loc) = char '!' <> ppr x ppr (PmLet x expr) = hsep [text "let", ppr x, text "=", ppr expr] type GrdVec = [PmGrd] @@ -139,14 +144,15 @@ instance Monoid Precision where mempty = Precise mappend = (Semi.<>) --- | Means by which we identify a RHS for later pretty-printing in a warning --- message. 'SDoc' for the equation to show, 'Located' for the location. -type RhsInfo = Located SDoc +-- | Means by which we identify source location for later pretty-printing +-- in a warning message. 'SDoc' for the equation to show, 'Located' for +-- the location. +type SrcInfo = Located SDoc -- | A representation of the desugaring to 'PmGrd's of all clauses of a -- function definition/pattern match/etc. data GrdTree - = Rhs !RhsInfo + = Rhs !SrcInfo | Guard !PmGrd !GrdTree -- ^ @Guard grd t@ will try to match @grd@ and on success continue to match -- @t at . Falls through if either match fails. Models left-to-right semantics @@ -157,14 +163,48 @@ data GrdTree -- of pattern matching. -- @Sequence []@ always fails; it is useful for Note [Checking EmptyCase]. +{- Note [Dead bang patterns] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider + + f :: Bool -> Int + f True = 1 + f !x = 2 + +Whenever we fall through to the second equation, we will already have evaluated +the argument. Thus, the bang pattern serves no purpose and should be warned +about. We call this kind of bang patterns "dead". Dead bangs are the ones +that under no circumstances can force a thunk that wasn't already forced. +Dead bangs are a form of redundant bangs; see below. + +We can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable +where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is +dead. Such a dead bang is then indicated in the annotated pattern-match tree by +a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect +all dead bangs to warn about. + +Note that we don't want to warn for a dead bang that appears on a redundant +clause. That is because in that case, we recommend to delete the clause wholly, +including its leading pattern match. + +Dead bang patterns are redundant. But there are bang patterns which are +redundant that aren't dead, for example + + f !() = 0 + +the bang still forces the match variable, before we attempt to match on (). But +it is redundant with the forcing done by the () match. We currently don't +detect redundant bangs that aren't dead. +-} + -- | The digest of 'checkGrdTree', representing the annotated pattern-match --- tree. 'redundantAndInaccessibleRhss' can figure out redundant and proper --- inaccessible RHSs from this. +-- tree. 'extractRedundancyInfo' can figure out redundant and proper +-- inaccessible RHSs from this, as well as dead bangs. data AnnotatedTree - = AccessibleRhs !Deltas !RhsInfo + = AccessibleRhs !Deltas !SrcInfo -- ^ A RHS deemed accessible. The 'Deltas' is the (non-empty) set of covered -- values. - | InaccessibleRhs !RhsInfo + | InaccessibleRhs !SrcInfo -- ^ A RHS deemed inaccessible; it covers no value. | MayDiverge !AnnotatedTree -- ^ Asserts that the tree may force diverging values, so not all of its @@ -173,13 +213,15 @@ data AnnotatedTree -- ^ @SequenceAnn inc ts@ mirrors @'Sequence' ts@ for preserving the -- skeleton of a 'GrdTree's @ts at . It also carries the set of incoming values -- @inc at . + | RedundantSrcBang !SrcInfo !AnnotatedTree + -- ^ For tracking redundant bangs. See Note [Dead bang patterns] -pprRhsInfo :: RhsInfo -> SDoc -pprRhsInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) -pprRhsInfo (L s _) = ppr s +pprSrcInfo :: SrcInfo -> SDoc +pprSrcInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) +pprSrcInfo (L s _) = ppr s instance Outputable GrdTree where - ppr (Rhs info) = text "->" <+> pprRhsInfo info + ppr (Rhs info) = text "->" <+> pprSrcInfo info -- Format guards as "| True <- x, let x = 42, !z" ppr g at Guard{} = fsep (prefix (map ppr grds)) <+> ppr t where @@ -192,11 +234,12 @@ instance Outputable GrdTree where ppr (Sequence ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) instance Outputable AnnotatedTree where - ppr (AccessibleRhs _delta info) = parens (ppr _delta) <+> pprRhsInfo info - ppr (InaccessibleRhs info) = text "inaccessible" <+> pprRhsInfo info + ppr (AccessibleRhs _delta info) = parens (ppr _delta) <+> pprSrcInfo info + ppr (InaccessibleRhs info) = text "inaccessible" <+> pprSrcInfo info ppr (MayDiverge t) = text "div" <+> ppr t ppr (SequenceAnn _ []) = text "" ppr (SequenceAnn _ ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) + ppr (RedundantSrcBang l t) = text "redundant bang" <+> pprSrcInfo l <+> ppr t -- | Lift 'addPmCts' over 'Deltas'. addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas @@ -336,8 +379,9 @@ extractRhsDeltas = go_matches go_match :: Deltas -> AnnotatedTree -> (Deltas, NonEmpty Deltas) -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ -- is non-empty! - go_match def (SequenceAnn pat ts) = (pat, foldMap1 (text "go_match: empty SequenceAnn") (go_grhss def) ts) - go_match def (MayDiverge t) = go_match def t + go_match def (SequenceAnn pat ts) = (pat, foldMap1 (text "go_match: empty SequenceAnn") (go_grhss def) ts) + go_match def (MayDiverge t) = go_match def t + go_match def (RedundantSrcBang _ t) = go_match def t -- Even if there's only a single GRHS, we wrap it in a SequenceAnn for the -- Deltas covered by the pattern. So the remaining cases are impossible! go_match _ t = pprPanic "extractRhsDeltas.go_match" (text "Single GRHS must be wrapped in SequenceAnn. But got " $$ ppr t) @@ -347,6 +391,7 @@ extractRhsDeltas = go_matches -- is non-empty! go_grhss def (SequenceAnn _ ts) = foldMap1 (text "go_grhss: empty SequenceAnn") (go_grhss def) ts go_grhss def (MayDiverge t) = go_grhss def t + go_grhss def (RedundantSrcBang _ t) = go_grhss def t go_grhss _ (AccessibleRhs deltas _) = deltas :| [] go_grhss def (InaccessibleRhs _) = def :| [] @@ -442,10 +487,11 @@ translatePat fam_insts x pat = case pat of VarPat _ y -> pure (mkPmLetVar (unLoc y) x) ParPat _ p -> translateLPat fam_insts x p LazyPat _ _ -> pure [] -- like a wildcard - BangPat _ p -> + BangPat _ p@(L l p') -> -- Add the bang in front of the list, because it will happen before any -- nested stuff. - (PmBang x :) <$> translateLPat fam_insts x p + (PmBang x pm_loc :) <$> translateLPat fam_insts x p + where pm_loc = Just (L l (ppr p')) -- (x at pat) ==> Translate pat with x as match var and handle impedance -- mismatch with incoming match var @@ -629,7 +675,8 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- 2. bang strict fields let arg_is_banged = map isBanged $ conLikeImplBangs con - bang_grds = map PmBang $ filterByList arg_is_banged arg_ids + noSrcPmBang i = PmBang {pm_id = i, pm_loc = Nothing} + bang_grds = map noSrcPmBang (filterByList arg_is_banged arg_ids) -- 3. guards from field selector patterns let arg_grds = concat arg_grdss @@ -958,8 +1005,9 @@ mayDiverge a = MayDiverge a -- 'GrdTree'. Note that 'PmCon' guards are the only way in which values -- fall through from one 'Many' branch to the next. -- * An 'AnnotatedTree' that contains divergence and inaccessibility info --- for all clauses. Will be fed to 'redundantAndInaccessibleRhss' for --- presenting redundant and proper innaccessible RHSs to the user. +-- for all clauses. Will be fed to 'extractRedundancyInfo' for +-- presenting redundant and proper innaccessible RHSs, as well as dead +-- bangs to the user. checkGrdTree' :: GrdTree -> Deltas -> DsM CheckResult -- RHS: Check that it covers something and wrap Inaccessible if not checkGrdTree' (Rhs sdoc) deltas = do @@ -976,11 +1024,21 @@ checkGrdTree' (Guard (PmLet x e) tree) deltas = do deltas' <- addPmCtDeltas deltas (PmCoreCt x e) checkGrdTree' tree deltas' -- Bang x: Diverge on x ~ ⊥, refine with x /~ ⊥ -checkGrdTree' (Guard (PmBang x) tree) deltas = do +checkGrdTree' (Guard (PmBang x src_bang_info) tree) deltas = do has_diverged <- addPmCtDeltas deltas (PmBotCt x) >>= isInhabited deltas' <- addPmCtDeltas deltas (PmNotBotCt x) res <- checkGrdTree' tree deltas' - pure res{ cr_clauses = applyWhen has_diverged mayDiverge (cr_clauses res) } + let clauses + | not has_diverged + , Just info <- src_bang_info + = RedundantSrcBang info (cr_clauses res) + | has_diverged + = mayDiverge (cr_clauses res) + | otherwise -- won't diverge and it wasn't a source bang + = cr_clauses res + + pure res{ cr_clauses = clauses } + -- Con: Diverge on x ~ ⊥, fall through on x /~ K and refine with x ~ K ys -- and type info checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do @@ -1122,25 +1180,43 @@ needToRunPmCheck dflags origin | otherwise = notNull (filter (`wopt` dflags) allPmCheckWarnings) -redundantAndInaccessibleRhss :: AnnotatedTree -> ([RhsInfo], [RhsInfo]) -redundantAndInaccessibleRhss tree = (fromOL ol_red, fromOL ol_inacc) +-- | A type for organising information to be used in warnings. +data RedundancyInfo + = RedundancyInfo + { redundant_rhss :: ![SrcInfo] + , inaccessible_rhss :: ![SrcInfo] + , redundant_bangs :: ![Located SDoc] + } + +extractRedundancyInfo :: AnnotatedTree -> RedundancyInfo +extractRedundancyInfo tree = + RedundancyInfo { redundant_rhss = fromOL ol_red + , inaccessible_rhss = fromOL ol_inacc + , redundant_bangs = fromOL ol_bangs } where - (_ol_acc, ol_inacc, ol_red) = go tree - -- | Collects RHSs which are - -- 1. accessible - -- 2. proper inaccessible (so we can't delete them) - -- 3. hypothetically redundant (so not only inaccessible RHS, but we can + (_ol_acc, ol_inacc, ol_red, ol_bangs) = go tree + -- | Collects + -- 1. accessible RHSs + -- 2. proper inaccessible RHSs (so we can't delete them) + -- 3. hypothetically redundant RHSs (so not only inaccessible, but we can -- even safely delete the equation without altering semantics) + -- 4. 'Dead' bangs from the source, collected to be warned about -- See Note [Determining inaccessible clauses] - go :: AnnotatedTree -> (OrdList RhsInfo, OrdList RhsInfo, OrdList RhsInfo) - go (AccessibleRhs _ info) = (unitOL info, nilOL, nilOL) - go (InaccessibleRhs info) = (nilOL, nilOL, unitOL info) -- presumably redundant + -- See Note [Dead bang patterns] + go :: AnnotatedTree -> (OrdList SrcInfo, OrdList SrcInfo, OrdList SrcInfo, OrdList SrcInfo) + go (AccessibleRhs _ info) = (unitOL info, nilOL, nilOL , nilOL) + go (InaccessibleRhs info) = (nilOL, nilOL, unitOL info, nilOL) -- presumably redundant go (MayDiverge t) = case go t of -- See Note [Determining inaccessible clauses] - (acc, inacc, red) - | isNilOL acc && isNilOL inacc -> (nilOL, red, nilOL) + (acc, inacc, red, bs) + | isNilOL acc && isNilOL inacc -> (nilOL, red, nilOL, bs) res -> res go (SequenceAnn _ ts) = foldMap go ts + go (RedundantSrcBang l t) = case go t of + -- See Note [Dead bang patterns] + res@(acc, inacc, _, _) + | isNilOL acc, isNilOL inacc -> res + | otherwise -> (nilOL, nilOL, nilOL, unitOL l) Semi.<> res {- Note [Determining inaccessible clauses] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1169,26 +1245,31 @@ inaccessible ones, we report the first clause as inaccessible. Clearly, it is enough if we say that we only degrade if *not all* of the child clauses are redundant. As long as there is at least one clause which we announce not to be redundant, the guard prefix responsible for the 'MayDiverge' will -survive. Hence we check for that in 'redundantAndInaccessibleRhss'. +survive. Hence we check for that in 'extractRedundancyInfo'. -} -- | Issue all the warnings (coverage, exhaustiveness, inaccessibility) dsPmWarn :: DynFlags -> DsMatchContext -> [Id] -> CheckResult -> DsM () dsPmWarn dflags ctx@(DsMatchContext kind loc) vars result - = when (flag_i || flag_u) $ do + = when (flag_i || flag_u || flag_b) $ do unc_examples <- getNFirstUncovered vars (maxPatterns + 1) uncovered - let exists_r = flag_i && notNull redundant - exists_i = flag_i && notNull inaccessible + let exists_r = flag_i && notNull redundant_rhss + exists_i = flag_i && notNull inaccessible_rhss exists_u = flag_u && notNull unc_examples + exists_b = flag_b && notNull redundant_bangs approx = precision == Approximate when (approx && (exists_u || exists_i)) $ putSrcSpanDs loc (warnDs NoReason approx_msg) - when exists_r $ forM_ redundant $ \(L l q) -> do + when exists_b $ forM_ redundant_bangs $ \(L l q) -> do + putSrcSpanDs l (warnDs (Reason Opt_WarnRedundantBangPatterns) + (pprEqn q "has redundant bang")) + + when exists_r $ forM_ redundant_rhss $ \(L l q) -> do putSrcSpanDs l (warnDs (Reason Opt_WarnOverlappingPatterns) (pprEqn q "is redundant")) - when exists_i $ forM_ inaccessible $ \(L l q) -> do + when exists_i $ forM_ inaccessible_rhss $ \(L l q) -> do putSrcSpanDs l (warnDs (Reason Opt_WarnOverlappingPatterns) (pprEqn q "has inaccessible right hand side")) @@ -1199,10 +1280,12 @@ dsPmWarn dflags ctx@(DsMatchContext kind loc) vars result { cr_clauses = clauses , cr_uncov = uncovered , cr_approx = precision } = result - (redundant, inaccessible) = redundantAndInaccessibleRhss clauses + RedundancyInfo{redundant_rhss, inaccessible_rhss, redundant_bangs} + = extractRedundancyInfo clauses flag_i = overlapping dflags kind flag_u = exhaustive dflags kind + flag_b = redundant_bang dflags flag_u_reason = maybe NoReason Reason (exhaustiveWarningFlag kind) maxPatterns = maxUncoveredPatterns dflags @@ -1297,6 +1380,10 @@ overlapping dflags _ = wopt Opt_WarnOverlappingPatterns dflags exhaustive :: DynFlags -> HsMatchContext id -> Bool exhaustive dflags = maybe False (`wopt` dflags) . exhaustiveWarningFlag +-- | Check whether unnecessary bangs should be warned about +redundant_bang :: DynFlags -> Bool +redundant_bang dflags = wopt Opt_WarnRedundantBangPatterns dflags + -- | Denotes whether an exhaustiveness check is supported, and if so, -- via which 'WarningFlag' it's controlled. -- Returns 'Nothing' if check is not supported. ===================================== docs/users_guide/9.2.1-notes.rst ===================================== @@ -0,0 +1,18 @@ +.. _release-9-2-1: + +Version 9.2.1 +============== + +Compiler +~~~~~~~~ + +- New '-Wredundant-bang-patterns' flag that enables checks for "dead" bangs. + For instance, given this program: :: + + f :: Bool -> Bool + f True = False + f !x = x + + GHC would report that the bang on ``x`` is redundant and can be removed + since the argument was already forced in the first equation. For more + details see :ghc-flag:`-Wredundant-bang-patterns` ===================================== docs/users_guide/using-warnings.rst ===================================== @@ -1627,6 +1627,47 @@ of ``-W(no-)*``. would report that the ``P{..}`` match is unused. +.. ghc-flag:: -Wredundant-bang-patterns + :shortdesc: Warn about redundant bang patterns. + :type: dynamic + :reverse: -Wno-redundant-bang-patterns + :category: + + :since: 9.2.1 + + .. index:: + single: redundant, warning, bang patterns + + Report dead bang patterns, where dead bangs are bang patterns that under no + circumstances can force a thunk that wasn't already forced. Dead bangs are a + form of redundant bangs. The new check is performed in pattern-match coverage + checker along with other checks (namely, redundant and inaccessible RHSs). + Given :: + + + f :: Bool -> Int + f True = 1 + f !x = 2 + + The bang pattern on ``!x`` is dead. By the time the ``x`` in the second equation + is reached, ``x`` will already have been forced due to the first equation + (``f True = 1``). Moreover, there is no way to reach the second equation without + going through the first one. + + Note that ``-Wredundant-bang-patterns`` will not warn about dead bangs that appear + on a redundant clause. That is because in that case, it is recommended to delete + the clause wholly, including its leading pattern match. + + Dead bang patterns are redundant. But there are bang patterns which are + redundant that aren't dead, for example: :: + + + f !() = 0 + + the bang still forces the argument, before we attempt to match on ``()``. But it is + redundant with the forcing done by the ``()`` match. Currently such redundant bangs + are not considered dead, and ``-Wredundant-bang-patterns`` will not warn about them. + .. ghc-flag:: -Wredundant-record-wildcards :shortdesc: Warn about record wildcard matches when the wildcard binds no patterns. :type: dynamic ===================================== testsuite/tests/pmcheck/should_compile/T17340.hs ===================================== @@ -0,0 +1,54 @@ +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE PatternSynonyms #-} +module T17340 where + +data A = A { a :: () } +data B = B +newtype C = C Int +pattern P = B + +f_nowarn :: Bool -> Bool +f_nowarn !x = x + +f :: Bool -> Bool +f True = False +f !x = x + +g :: (Int, Int) -> Bool -> () +g (a,b) True = () +g !x False = () + +data T = MkT !Int +h :: T -> () +h (MkT !x) = () + +k :: Bool -> Int +k True = 1 +k !_ = 2 -- clause is accessible, so warn for the bang + +t :: () -> Bool -> Int +t _ True = 1 +t !() True = 2 -- the clause has inaccessible RHS, warn for the bang +t _ False = 3 + +q :: Bool -> Int +q True = 1 +q !True = 2 -- clause is redundant, don't warn for the bang +q False = 3 + +i :: Bool -> Int +i True = 1 +i !x | x = 2 -- redundant + | not x = 3 -- accessible. This one will stay alive, so warn for the bang + +newtype T2 a = T2 a +w :: T2 a -> Bool -> () +w _ True = () +w (T2 _) True = () -- redundant +w !_ True = () -- inaccessible +w _ _ = () + +z :: T2 a -> Bool -> () +z _ True = () +z t2 !x | T2 _ <- t2, x = () -- redundant + | !_ <- t2, x = () -- inaccessable ===================================== testsuite/tests/pmcheck/should_compile/T17340.stderr ===================================== @@ -0,0 +1,48 @@ + +T17340.hs:15:4: warning: [-Wredundant-bang-patterns] + Pattern match has redundant bang + In an equation for ‘f’: f x = ... + +T17340.hs:19:4: warning: [-Wredundant-bang-patterns] + Pattern match has redundant bang + In an equation for ‘g’: g x = ... + +T17340.hs:27:4: warning: [-Wredundant-bang-patterns] + Pattern match has redundant bang + In an equation for ‘k’: k _ = ... + +T17340.hs:31:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match has inaccessible right hand side + In an equation for ‘t’: t !() True = ... + +T17340.hs:36:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In an equation for ‘q’: q !True = ... + +T17340.hs:41:4: warning: [-Wredundant-bang-patterns] + Pattern match has redundant bang + In an equation for ‘i’: i x = ... + +T17340.hs:41:8: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In an equation for ‘i’: i !x | x = ... + +T17340.hs:47:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In an equation for ‘w’: w (T2 _) True = ... + +T17340.hs:48:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match has inaccessible right hand side + In an equation for ‘w’: w !_ True = ... + +T17340.hs:53:7: warning: [-Wredundant-bang-patterns] + Pattern match has redundant bang + In an equation for ‘z’: z x = ... + +T17340.hs:53:11: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In an equation for ‘z’: z t2 !x | T2 _ <- t2, x = ... + +T17340.hs:54:11: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match has inaccessible right hand side + In an equation for ‘z’: z t2 !x | !_ <- t2, x = ... ===================================== testsuite/tests/pmcheck/should_compile/all.T ===================================== @@ -124,6 +124,8 @@ test('T18478', collect_compiler_stats('bytes allocated',10), compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T18533', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) +test('T17340', normal, compile, + ['-Wredundant-bang-patterns']) # Other tests test('pmc001', [], compile, View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/731c8d3bc5a84515793e5dadb26adf52f9280e13 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/731c8d3bc5a84515793e5dadb26adf52f9280e13 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 19 22:48:18 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 19 Aug 2020 18:48:18 -0400 Subject: [Git][ghc/ghc][master] Add right-to-left rule for pattern bindings Message-ID: <5f3dac32defb1_80b3f84693c1eb48671591@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 14 changed files: - compiler/GHC/Hs/Binds.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/Tc/Gen/Bind.hs - compiler/GHC/Tc/Gen/Match.hs - compiler/GHC/Tc/Gen/Match.hs-boot - compiler/GHC/Tc/Utils/Zonk.hs - + testsuite/tests/typecheck/should_compile/T18323.hs - testsuite/tests/typecheck/should_compile/all.T - testsuite/tests/typecheck/should_fail/T8570.stderr - testsuite/tests/typecheck/should_fail/tcfail004.stderr - testsuite/tests/typecheck/should_fail/tcfail005.stderr - testsuite/tests/typecheck/should_fail/tcfail012.stderr - testsuite/tests/warnings/should_fail/CaretDiagnostics1.stderr Changes: ===================================== compiler/GHC/Hs/Binds.hs ===================================== @@ -317,18 +317,13 @@ data HsBindLR idL idR | XHsBindsLR !(XXHsBindsLR idL idR) -data NPatBindTc = NPatBindTc { - pat_fvs :: NameSet, -- ^ Free variables - pat_rhs_ty :: Type -- ^ Type of the GRHSs - } deriving Data - type instance XFunBind (GhcPass pL) GhcPs = NoExtField type instance XFunBind (GhcPass pL) GhcRn = NameSet -- Free variables type instance XFunBind (GhcPass pL) GhcTc = HsWrapper -- See comments on FunBind.fun_ext type instance XPatBind GhcPs (GhcPass pR) = NoExtField type instance XPatBind GhcRn (GhcPass pR) = NameSet -- Free variables -type instance XPatBind GhcTc (GhcPass pR) = NPatBindTc +type instance XPatBind GhcTc (GhcPass pR) = Type -- Type of the GRHSs type instance XVarBind (GhcPass pL) (GhcPass pR) = NoExtField type instance XAbsBinds (GhcPass pL) (GhcPass pR) = NoExtField ===================================== compiler/GHC/HsToCore/Binds.hs ===================================== @@ -182,7 +182,7 @@ dsHsBind dflags b@(FunBind { fun_id = L loc fun return (force_var, [core_binds]) } dsHsBind dflags (PatBind { pat_lhs = pat, pat_rhs = grhss - , pat_ext = NPatBindTc _ ty + , pat_ext = ty , pat_ticks = (rhs_tick, var_ticks) }) = do { rhss_deltas <- checkGRHSs PatBindGuards grhss ; body_expr <- dsGuarded grhss ty rhss_deltas ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -212,7 +212,7 @@ dsUnliftedBind (FunBind { fun_id = L l fun ; return (bindNonRec fun rhs' body) } dsUnliftedBind (PatBind {pat_lhs = pat, pat_rhs = grhss - , pat_ext = NPatBindTc _ ty }) body + , pat_ext = ty }) body = -- let C x# y# = rhs in body -- ==> case rhs of C x# y# -> body do { match_deltas <- checkGRHSs PatBindGuards grhss ===================================== compiler/GHC/Tc/Gen/Bind.hs ===================================== @@ -1274,20 +1274,15 @@ tcMonoBinds :: RecFlag -- Whether the binding is recursive for typechecking pur -> TcSigFun -> LetBndrSpec -> [LHsBind GhcRn] -> TcM (LHsBinds GhcTc, [MonoBindInfo]) + +-- SPECIAL CASE 1: see Note [Inference for non-recursive function bindings] tcMonoBinds is_rec sig_fn no_gen [ L b_loc (FunBind { fun_id = L nm_loc name , fun_matches = matches })] -- Single function binding, | NonRecursive <- is_rec -- ...binder isn't mentioned in RHS , Nothing <- sig_fn name -- ...with no type signature - = -- Note [Single function non-recursive binding special-case] - -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -- In this very special case we infer the type of the - -- right hand side first (it may have a higher-rank type) - -- and *then* make the monomorphic Id for the LHS - -- e.g. f = \(x::forall a. a->a) -> - -- We want to infer a higher-rank type for f - setSrcSpan b_loc $ + = setSrcSpan b_loc $ do { ((co_fn, matches'), rhs_ty) <- tcInfer $ \ exp_ty -> tcExtendBinderStack [TcIdBndr_ExpType name exp_ty NotTopLevel] $ @@ -1305,6 +1300,29 @@ tcMonoBinds is_rec sig_fn no_gen , mbi_sig = Nothing , mbi_mono_id = mono_id }]) } +-- SPECIAL CASE 2: see Note [Inference for non-recursive pattern bindings] +tcMonoBinds is_rec sig_fn no_gen + [L b_loc (PatBind { pat_lhs = pat, pat_rhs = grhss })] + | NonRecursive <- is_rec -- ...binder isn't mentioned in RHS + , all (isNothing . sig_fn) bndrs + = addErrCtxt (patMonoBindsCtxt pat grhss) $ + do { (grhss', pat_ty) <- tcInfer $ \ exp_ty -> + tcGRHSsPat grhss exp_ty + + ; let exp_pat_ty :: Scaled ExpSigmaType + exp_pat_ty = unrestricted (mkCheckExpType pat_ty) + ; (pat', mbis) <- tcLetPat (const Nothing) no_gen pat exp_pat_ty $ + mapM lookupMBI bndrs + + ; return ( unitBag $ L b_loc $ + PatBind { pat_lhs = pat', pat_rhs = grhss' + , pat_ext = pat_ty, pat_ticks = ([],[]) } + + , mbis ) } + where + bndrs = collectPatBinders pat + +-- GENERAL CASE tcMonoBinds _ sig_fn no_gen binds = do { tc_binds <- mapM (wrapLocM (tcLhs sig_fn no_gen)) binds @@ -1327,6 +1345,66 @@ tcMonoBinds _ sig_fn no_gen binds ; return (listToBag binds', mono_infos) } +{- Note [Special case for non-recursive function bindings] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +In the special case of +* A non-recursive FunBind +* With no type signature +we infer the type of the right hand side first (it may have a +higher-rank type) and *then* make the monomorphic Id for the LHS e.g. + f = \(x::forall a. a->a) -> + +We want to infer a higher-rank type for f + +Note [Special case for non-recursive pattern bindings] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +In the special case of +* A pattern binding +* With no type signature for any of the binders +we can /infer/ the type of the RHS, and /check/ the pattern +against that type. For example (#18323) + + ids :: [forall a. a -> a] + combine :: (forall a . [a] -> a) -> [forall a. a -> a] + -> ((forall a . [a] -> a), [forall a. a -> a]) + + (x,y) = combine head ids + +with -XImpredicativeTypes we can infer a good type for +(combine head ids), and use that to tell us the polymorphic +types of x and y. + +We don't need to check -XImpredicativeTypes beucase without it +these types like [forall a. a->a] are illegal anyway, so this +special case code only really has an effect if -XImpredicativeTypes +is on. Small exception: + (x) = e +is currently treated as a pattern binding so, even absent +-XImpredicativeTypes, we will get a small improvement in behaviour. +But I don't think it's worth an extension flag. + +Why do we require no type signatures on /any/ of the binders? +Consider + x :: forall a. a->a + y :: forall a. a->a + (x,y) = (id,id) + +Here we should /check/ the RHS with expected type + (forall a. a->a, forall a. a->a). + +If we have no signatures, we can the approach of this Note +to /infer/ the type of the RHS. + +But what if we have some signatures, but not all? Say this: + p :: forall a. a->a + (p,q) = (id, (\(x::forall b. b->b). x True)) + +Here we want to push p's signature inwards, i.e. /checking/, to +correctly elaborate 'id'. But we want to /infer/ q's higher rank +type. There seems to be no way to do this. So currently we only +switch to inference when we have no signature for any of the binders. +-} + ------------------------ -- tcLhs typechecks the LHS of the bindings, to construct the environment in which @@ -1394,7 +1472,7 @@ tcLhs sig_fn no_gen (PatBind { pat_lhs = pat, pat_rhs = grhss }) -- The above inferred type get an unrestricted multiplicity. It may be -- worth it to try and find a finer-grained multiplicity here -- if examples warrant it. - mapM lookup_info nosig_names + mapM lookupMBI nosig_names ; let mbis = sig_mbis ++ nosig_mbis @@ -1412,19 +1490,19 @@ tcLhs sig_fn no_gen (PatBind { pat_lhs = pat, pat_rhs = grhss }) Just (TcIdSig sig) -> Right (name, sig) _ -> Left name - -- After typechecking the pattern, look up the binder - -- names that lack a signature, which the pattern has brought - -- into scope. - lookup_info :: Name -> TcM MonoBindInfo - lookup_info name - = do { mono_id <- tcLookupId name - ; return (MBI { mbi_poly_name = name - , mbi_sig = Nothing - , mbi_mono_id = mono_id }) } - tcLhs _ _ other_bind = pprPanic "tcLhs" (ppr other_bind) -- AbsBind, VarBind impossible +lookupMBI :: Name -> TcM MonoBindInfo +-- After typechecking the pattern, look up the binder +-- names that lack a signature, which the pattern has brought +-- into scope. +lookupMBI name + = do { mono_id <- tcLookupId name + ; return (MBI { mbi_poly_name = name + , mbi_sig = Nothing + , mbi_mono_id = mono_id }) } + ------------------- tcLhsSigId :: LetBndrSpec -> (Name, TcIdSigInfo) -> TcM MonoBindInfo tcLhsSigId no_gen (name, sig) @@ -1467,15 +1545,9 @@ tcRhs (TcPatBind infos pat' grhss pat_ty) tcExtendIdBinderStackForRhs infos $ do { traceTc "tcRhs: pat bind" (ppr pat' $$ ppr pat_ty) ; grhss' <- addErrCtxt (patMonoBindsCtxt pat' grhss) $ - tcScalingUsage Many $ - -- Like in tcMatchesFun, this scaling happens because all - -- let bindings are unrestricted. A difference, here, is - -- that when this is not the case, any more, we will have to - -- make sure that the pattern is strict, otherwise this will - -- be desugar to incorrect code. - tcGRHSsPat grhss pat_ty + tcGRHSsPat grhss (mkCheckExpType pat_ty) ; return ( PatBind { pat_lhs = pat', pat_rhs = grhss' - , pat_ext = NPatBindTc emptyNameSet pat_ty + , pat_ext = pat_ty , pat_ticks = ([],[]) } )} tcExtendTyVarEnvForRhs :: Maybe TcIdSigInst -> TcM a -> TcM a ===================================== compiler/GHC/Tc/Gen/Match.hs ===================================== @@ -157,10 +157,17 @@ tcMatchLambda herald match_ctxt match res_ty -- @tcGRHSsPat@ typechecks @[GRHSs]@ that occur in a @PatMonoBind at . -tcGRHSsPat :: GRHSs GhcRn (LHsExpr GhcRn) -> TcRhoType +tcGRHSsPat :: GRHSs GhcRn (LHsExpr GhcRn) -> ExpRhoType -> TcM (GRHSs GhcTc (LHsExpr GhcTc)) -- Used for pattern bindings -tcGRHSsPat grhss res_ty = tcGRHSs match_ctxt grhss (mkCheckExpType res_ty) +tcGRHSsPat grhss res_ty + = tcScalingUsage Many $ + -- Like in tcMatchesFun, this scaling happens because all + -- let bindings are unrestricted. A difference, here, is + -- that when this is not the case, any more, we will have to + -- make sure that the pattern is strict, otherwise this will + -- desugar to incorrect code. + tcGRHSs match_ctxt grhss res_ty where match_ctxt = MC { mc_what = PatBindRhs, mc_body = tcBody } ===================================== compiler/GHC/Tc/Gen/Match.hs-boot ===================================== @@ -2,13 +2,13 @@ module GHC.Tc.Gen.Match where import GHC.Hs ( GRHSs, MatchGroup, LHsExpr ) import GHC.Tc.Types.Evidence ( HsWrapper ) import GHC.Types.Name ( Name ) -import GHC.Tc.Utils.TcType( ExpSigmaType, TcRhoType ) +import GHC.Tc.Utils.TcType( ExpSigmaType, ExpRhoType ) import GHC.Tc.Types ( TcM ) import GHC.Types.SrcLoc ( Located ) import GHC.Hs.Extension ( GhcRn, GhcTc ) tcGRHSsPat :: GRHSs GhcRn (LHsExpr GhcRn) - -> TcRhoType + -> ExpRhoType -> TcM (GRHSs GhcTc (LHsExpr GhcTc)) tcMatchesFun :: Located Name ===================================== compiler/GHC/Tc/Utils/Zonk.hs ===================================== @@ -533,12 +533,12 @@ zonk_lbind env = wrapLocM (zonk_bind env) zonk_bind :: ZonkEnv -> HsBind GhcTc -> TcM (HsBind GhcTc) zonk_bind env bind@(PatBind { pat_lhs = pat, pat_rhs = grhss - , pat_ext = NPatBindTc fvs ty}) + , pat_ext = ty}) = do { (_env, new_pat) <- zonkPat env pat -- Env already extended ; new_grhss <- zonkGRHSs env zonkLExpr grhss ; new_ty <- zonkTcTypeToTypeX env ty ; return (bind { pat_lhs = new_pat, pat_rhs = new_grhss - , pat_ext = NPatBindTc fvs new_ty }) } + , pat_ext = new_ty }) } zonk_bind env (VarBind { var_ext = x , var_id = var, var_rhs = expr }) ===================================== testsuite/tests/typecheck/should_compile/T18323.hs ===================================== @@ -0,0 +1,29 @@ +{-# LANGUAGE ImpredicativeTypes #-} + +-- Tests SPECIAL CASE 2 in GHC.Tc.Gen.Bind.tcMonoBinds +-- See Note [Special case for non-recursive pattern bindings] +-- +-- Doesn't have any useful effect until we have +-- ImpredicativeTypes, but does no harm either + +module T18323 where + +ids :: [forall a. a -> a] +ids = [id] + +combine :: (forall a . [a] -> a) + -> [forall a. a -> a] + -> ((forall a . [a] -> a), [forall a. a -> a]) +combine x y = (x,y) + +-- This works +works = let t = combine head ids + in (fst t) (snd t) True + +-- But this does not typecheck, and it could +breaks = let (x,y) = combine head ids + in x y True + +-- And nor does this, but it could too +breaks2 = let (t) = combine head ids + in (fst t) (snd t) True ===================================== testsuite/tests/typecheck/should_compile/all.T ===================================== @@ -720,3 +720,5 @@ test('T17775-viewpats-d', normal, compile_fail, ['']) test('T18118', normal, multimod_compile, ['T18118', '-v0']) test('T18412', normal, compile, ['']) test('T18470', normal, compile, ['']) +test('T18323', normal, compile, ['']) + ===================================== testsuite/tests/typecheck/should_fail/T8570.stderr ===================================== @@ -1,6 +1,12 @@ -T8570.hs:6:18: - Constructor ‘Image’ does not have field ‘filepath’ - In the pattern: Image {filepath = x} - In a pattern binding: Image {filepath = x} = logo - In the expression: let Image {filepath = x} = logo in x +T8570.hs:6:11: error: + • Couldn't match expected type ‘Image’ with actual type ‘Field’ + • In the pattern: Image {filepath = x} + In a pattern binding: Image {filepath = x} = logo + In the expression: let Image {filepath = x} = logo in x + +T8570.hs:6:18: error: + • Constructor ‘Image’ does not have field ‘filepath’ + • In the pattern: Image {filepath = x} + In a pattern binding: Image {filepath = x} = logo + In the expression: let Image {filepath = x} = logo in x ===================================== testsuite/tests/typecheck/should_fail/tcfail004.stderr ===================================== @@ -1,9 +1,6 @@ -tcfail004.hs:3:9: error: - • Couldn't match expected type: (a, b) - with actual type: (a0, b0, c0) - • In the expression: (1, 2, 3) +tcfail004.hs:3:1: error: + • Couldn't match expected type: (a0, b0, c0) + with actual type: (a, b) + • In the pattern: (f, g) In a pattern binding: (f, g) = (1, 2, 3) - • Relevant bindings include - f :: a (bound at tcfail004.hs:3:2) - g :: b (bound at tcfail004.hs:3:4) ===================================== testsuite/tests/typecheck/should_fail/tcfail005.stderr ===================================== @@ -1,9 +1,6 @@ -tcfail005.hs:3:9: error: - • Couldn't match expected type: [a] - with actual type: (a0, Char) - • In the expression: (1, 'a') +tcfail005.hs:3:2: error: + • Couldn't match expected type: (a0, Char) + with actual type: [a] + • In the pattern: h : i In a pattern binding: (h : i) = (1, 'a') - • Relevant bindings include - h :: a (bound at tcfail005.hs:3:2) - i :: [a] (bound at tcfail005.hs:3:4) ===================================== testsuite/tests/typecheck/should_fail/tcfail012.stderr ===================================== @@ -1,5 +1,5 @@ -tcfail012.hs:3:8: error: - • Couldn't match expected type ‘Bool’ with actual type ‘[a0]’ - • In the expression: [] +tcfail012.hs:3:1: error: + • Couldn't match expected type ‘[a0]’ with actual type ‘Bool’ + • In the pattern: True In a pattern binding: True = [] ===================================== testsuite/tests/warnings/should_fail/CaretDiagnostics1.stderr ===================================== @@ -59,7 +59,7 @@ CaretDiagnostics1.hs:13:7-11: error: | ^^^^^ CaretDiagnostics1.hs:(13,16)-(14,13): error: - • Couldn't match expected type ‘Char -> p0’ with actual type ‘()’ + • Couldn't match expected type ‘Char -> t0’ with actual type ‘()’ • The function ‘()’ is applied to one value argument, but its type ‘()’ has none In the expression: () '0' View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/eb9bdaef6024558696e1e50b12d7fefb70483a9f -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/eb9bdaef6024558696e1e50b12d7fefb70483a9f You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 19 22:59:32 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Wed, 19 Aug 2020 18:59:32 -0400 Subject: [Git][ghc/ghc][wip/az/exactprint] Fix up after rebasing to bring in XRec Message-ID: <5f3daed4d36b0_80b40e7e108677352@gitlab.haskell.org.mail> Alan Zimmerman pushed to branch wip/az/exactprint at Glasgow Haskell Compiler / GHC Commits: ac2c120c by Alan Zimmerman at 2020-08-19T23:58:38+01:00 Fix up after rebasing to bring in XRec Main thing is to make type instance XRec (GhcPass p) a = GenLocated (Anno a) a type family Anno a = b But this has massive implications. - - - - - 24 changed files: - compiler/GHC.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Hs.hs - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Expr.hs-boot - compiler/GHC/Hs/Extension.hs - compiler/GHC/Hs/ImpExp.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Pat.hs-boot - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/Arrows.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Docs.hs - compiler/GHC/HsToCore/Foreign/Decl.hs - compiler/GHC/HsToCore/ListComp.hs - compiler/GHC/HsToCore/Quote.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Iface/Ext/Ast.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Annotation.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ac2c120c925af7adaf150abf54463a8f20143c20 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ac2c120c925af7adaf150abf54463a8f20143c20 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 20 02:13:14 2020 From: gitlab at gitlab.haskell.org (Moritz Angermann) Date: Wed, 19 Aug 2020 22:13:14 -0400 Subject: [Git][ghc/ghc][wip/angerman/aarch64-ncg] 3 commits: Disable trivial deadlock detection Message-ID: <5f3ddc3ad8daf_80b1075951c868456d@gitlab.haskell.org.mail> Moritz Angermann pushed to branch wip/angerman/aarch64-ncg at Glasgow Haskell Compiler / GHC Commits: e5059384 by Moritz Angermann at 2020-08-20T02:11:26+00:00 Disable trivial deadlock detection - - - - - 34c6c6d7 by Moritz Angermann at 2020-08-20T02:12:43+00:00 Adds some annotations - - - - - 3dbc6ac6 by Moritz Angermann at 2020-08-20T02:13:02+00:00 Trying to get PIC right. - - - - - 4 changed files: - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/CmmToAsm/AArch64/CodeGen.hs - compiler/GHC/CmmToAsm/AArch64/Ppr.hs - compiler/GHC/CmmToAsm/PIC.hs Changes: ===================================== compiler/GHC/Cmm/CLabel.hs ===================================== @@ -1436,6 +1436,10 @@ pprDynamicLinkerAsmLabel platform dllInfo lbl = SymbolPtr -> text ".LC_" <> ppr lbl _ -> panic "pprDynamicLinkerAsmLabel" + | platformArch platform == ArchAArch64 + = ppr lbl + + | platformArch platform == ArchX86_64 = case dllInfo of CodeStub -> ppr lbl <> text "@plt" ===================================== compiler/GHC/CmmToAsm/AArch64/CodeGen.hs ===================================== @@ -522,7 +522,7 @@ getRegister' config plat expr (op, imm_code) <- litToImm' lit let rep = cmmLitType plat lit format = cmmTypeFormat rep - return (Any format (\dst -> imm_code `snocOL` LDR format (OpReg (formatToWidth format) dst) op)) + return (Any format (\dst -> imm_code `snocOL` (ANN (text $ show expr) $ LDR format (OpReg (formatToWidth format) dst) op))) CmmLabelOff lbl off | is12bit (fromIntegral off) -> do (op, imm_code) <- litToImm' lit @@ -904,13 +904,19 @@ assignReg_FltCode = assignReg_IntCode -- ----------------------------------------------------------------------------- -- Jumps genJump :: CmmExpr{-the branch target-} -> [Reg] -> NatM InstrBlock -genJump (CmmLit (CmmLabel lbl)) regs - = return $ unitOL (J (TLabel lbl)) +genJump expr@(CmmLit (CmmLabel lbl)) regs + = return $ unitOL (ANN (text $ show expr) (J (TLabel lbl))) -- = return (toOL [ PUSH_STACK_FRAME -- , DELTA (-16) -- , B (TLabel lbl) -- , POP_STACK_FRAME -- , DELTA 0] ) + +-- no reason to load label into register just to +-- do a register jump. +genJump expr@(CmmLoad (CmmLit (CmmLabel lbl)) _rep) regs + = return $ unitOL (ANN (text $ show expr) (J (TLabel lbl))) + genJump expr regs = do (target, _format, code) <- getSomeReg expr return (code `appOL` unitOL (ANN (text $ show expr) (J (TReg target))) ===================================== compiler/GHC/CmmToAsm/AArch64/Ppr.hs ===================================== @@ -120,7 +120,7 @@ pprBasicBlock :: NCGConfig -> LabelMap RawCmmStatics -> NatBasicBlock Instr pprBasicBlock config info_env (BasicBlock blockid instrs) = maybe_infotable $ pprLabel platform asmLbl $$ - vcat (map (pprInstr platform) (detectTrivialDeadlock optInstrs)) $$ + vcat (map (pprInstr platform) (id {-detectTrivialDeadlock-} optInstrs)) $$ (if ncgDebugLevel config > 0 then ppr (mkAsmTempEndLabel asmLbl) <> char ':' else empty @@ -483,22 +483,23 @@ pprInstr platform instr = case instr of text "\tstrh" <+> pprOp o1 <> comma <+> pprOp o2 STR f o1 o2 -> text "\tstr" <+> pprOp o1 <> comma <+> pprOp o2 + LDR f o1 (OpImm (ImmIndex lbl' off)) | Just (_info, lbl) <- dynamicLinkerLabelInfo lbl' -> + text "\tadrp" <+> pprOp o1 <> comma <+> text ":got:" <> ppr lbl $$ + text "\tldr" <+> pprOp o1 <> comma <+> text "[" <> pprOp o1 <> comma <+> text ":got_lo12:" <> ppr lbl <> text "]" $$ + text "\tadd" <+> pprOp o1 <> comma <+> pprOp o1 <> comma <+> char '#' <> int off -- XXX: check that off is in 12bits. + LDR f o1 (OpImm (ImmIndex lbl off)) -> text "\tadrp" <+> pprOp o1 <> comma <+> ppr lbl $$ text "\tadd" <+> pprOp o1 <> comma <+> pprOp o1 <> comma <+> text ":lo12:" <> ppr lbl $$ text "\tadd" <+> pprOp o1 <> comma <+> pprOp o1 <> comma <+> char '#' <> int off -- XXX: check that off is in 12bits. - -- always GOT loads - -- LDR f o1 (OpImm (ImmIndex lbl off)) -> - -- text "\tadrp" <+> pprOp o1 <> comma <+> text ":got:" <> ppr lbl $$ - -- text "\tldr" <+> pprOp o1 <> comma <+> text "[" <> pprOp o1 <> comma <+> text":got_lo12:" <> ppr lbl <> text "]" $$ - -- text "\tadd" <+> pprOp o1 <> comma <+> pprOp o1 <> comma <+> char '#' <> int off -- XXX: check that off is in 12bits. + + LDR f o1 (OpImm (ImmCLbl lbl')) | Just (_info, lbl) <- dynamicLinkerLabelInfo lbl' -> + text "\tadrp" <+> pprOp o1 <> comma <+> text ":got:" <> ppr lbl $$ + text "\tldr" <+> pprOp o1 <> comma <+> text "[" <> pprOp o1 <> comma <+> text ":got_lo12:" <> ppr lbl <> text "]" LDR f o1 (OpImm (ImmCLbl lbl)) -> text "\tadrp" <+> pprOp o1 <> comma <+> ppr lbl $$ text "\tadd" <+> pprOp o1 <> comma <+> pprOp o1 <> comma <+> text ":lo12:" <> ppr lbl - -- LDR f o1 (OpImm (ImmCLbl lbl)) -> - -- text "\tadrp" <+> pprOp o1 <> comma <+> text ":got:" <> ppr lbl $$ - -- text "\tldr" <+> pprOp o1 <> comma <+> text "[" <> pprOp o1 <> comma <+> text":got_lo12:" <> ppr lbl <> text "]" LDR f o1@(OpReg W8 (RegReal (RealRegSingle i))) o2 | i < 32 -> text "\tldrsb" <+> pprOp o1 <> comma <+> pprOp o2 ===================================== compiler/GHC/CmmToAsm/PIC.hs ===================================== @@ -133,6 +133,14 @@ cmmMakeDynamicReference config referenceKind lbl addImport stub return $ CmmLit $ CmmLabel stub + -- GOT relative loads work differently on AArch64. We don't + -- the got symbol is loaded directly, and not through an additional + -- load. + AccessViaSymbolPtr | ArchAArch64 <- platformArch platform -> do + let symbolPtr = mkDynamicLinkerLabel SymbolPtr lbl + addImport symbolPtr + return $ cmmMakePicReference config symbolPtr + AccessViaSymbolPtr -> do let symbolPtr = mkDynamicLinkerLabel SymbolPtr lbl addImport symbolPtr @@ -146,7 +154,6 @@ cmmMakeDynamicReference config referenceKind lbl -- so just jump there if it's a call or a jump _ -> return $ CmmLit $ CmmLabel lbl - -- ----------------------------------------------------------------------------- -- Create a position independent reference to a label. -- (but do not bother with dynamic linking). @@ -261,11 +268,11 @@ howToAccessLabel config _ OSMinGW32 this_mod _ lbl -- is enough for ~64MB of range. Anything else will need to go through a veneer, -- which is the job of the linker to build. We might only want to lookup -- Data References through the GOT. -howToAccessLabel _config ArchAArch64 _os _this_mod kind _lbl - = case kind of - DataReference -> AccessDirectly -- AccessViaSymbolPtr - CallReference -> AccessDirectly - JumpReference -> AccessDirectly +-- howToAccessLabel _config ArchAArch64 _os _this_mod kind _lbl +-- = case kind of +-- DataReference -> AccessDirectly -- AccessViaSymbolPtr +-- CallReference -> AccessDirectly +-- JumpReference -> AccessDirectly -- Mach-O (Darwin, Mac OS X) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/cf52b0a164ea3a0406d6aa4e581a24818da03786...3dbc6ac67a0efac9eaabb5ea4623247fa717d189 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/cf52b0a164ea3a0406d6aa4e581a24818da03786...3dbc6ac67a0efac9eaabb5ea4623247fa717d189 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 20 11:41:17 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Thu, 20 Aug 2020 07:41:17 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/parser-qualified-prelude Message-ID: <5f3e615da67f5_80b3f846a4244a08698374@gitlab.haskell.org.mail> Vladislav Zavialov pushed new branch wip/parser-qualified-prelude at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/parser-qualified-prelude You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 20 13:55:16 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Thu, 20 Aug 2020 09:55:16 -0400 Subject: [Git][ghc/ghc][wip/az/exactprint] Fix up after rebasing to bring in XRec Message-ID: <5f3e80c42fd41_80b3f842731681c87124a0@gitlab.haskell.org.mail> Alan Zimmerman pushed to branch wip/az/exactprint at Glasgow Haskell Compiler / GHC Commits: c37d34f1 by Alan Zimmerman at 2020-08-20T14:54:44+01:00 Fix up after rebasing to bring in XRec Main thing is to make type instance XRec (GhcPass p) a = GenLocated (Anno a) a type family Anno a = b But this has massive implications. - - - - - 24 changed files: - compiler/GHC.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Hs.hs - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Expr.hs-boot - compiler/GHC/Hs/Extension.hs - compiler/GHC/Hs/ImpExp.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Pat.hs-boot - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/Arrows.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Docs.hs - compiler/GHC/HsToCore/Foreign/Decl.hs - compiler/GHC/HsToCore/ListComp.hs - compiler/GHC/HsToCore/Quote.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Iface/Ext/Ast.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Annotation.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c37d34f1b32aef43c26b55fe6bd699bde9115069 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c37d34f1b32aef43c26b55fe6bd699bde9115069 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 20 15:21:51 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Thu, 20 Aug 2020 11:21:51 -0400 Subject: [Git][ghc/ghc][wip/T18223] 3 commits: Implement -Wredundant-bang-patterns (#17340) Message-ID: <5f3e950fdf341_80b3f846a4244a08717945@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18223 at Glasgow Haskell Compiler / GHC Commits: 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 7137e3da by Simon Peyton Jones at 2020-08-20T16:21:33+01:00 Work in progress on #18223 There are two main changes in here 1. Stop Specialise specalising DFuns. This cases a huge (and utterly unnecessary) blowup in program size in #18223. I also refactored the Specialise monad a bit... it was silly. 2. Re-engineer eta-expansion (again). The eta-expander was generating lots of intermediate stuff, which could be optimised away, but which choked the simplifier meanwhile. Relatively easy to kill it off at source. Needs some Notes etc, and perhaps two separate patches, but I want to get this into CI and perf testing. - - - - - 30 changed files: - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Env.hs - compiler/GHC/Core/Opt/Specialise.hs - compiler/GHC/Core/Ppr.hs - compiler/GHC/Core/SimpleOpt.hs - compiler/GHC/Core/Subst.hs - compiler/GHC/Driver/Flags.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/Tc/Gen/Bind.hs - compiler/GHC/Tc/Gen/Match.hs - compiler/GHC/Tc/Gen/Match.hs-boot - compiler/GHC/Tc/Utils/Zonk.hs - + docs/users_guide/9.2.1-notes.rst - docs/users_guide/using-warnings.rst - + testsuite/tests/pmcheck/should_compile/T17340.hs - + testsuite/tests/pmcheck/should_compile/T17340.stderr - testsuite/tests/pmcheck/should_compile/all.T - + testsuite/tests/typecheck/should_compile/T18323.hs - testsuite/tests/typecheck/should_compile/all.T - testsuite/tests/typecheck/should_fail/T8570.stderr - testsuite/tests/typecheck/should_fail/tcfail004.stderr - testsuite/tests/typecheck/should_fail/tcfail005.stderr - testsuite/tests/typecheck/should_fail/tcfail012.stderr The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/940268367d30058bb27b69110705a51120f872e1...7137e3da1b91d46882881435b5cab9bc8eb66fa5 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/940268367d30058bb27b69110705a51120f872e1...7137e3da1b91d46882881435b5cab9bc8eb66fa5 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 20 15:30:46 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Thu, 20 Aug 2020 11:30:46 -0400 Subject: [Git][ghc/ghc][wip/az/ghc-9.0-anns] 72 commits: Bignum: add support for negative shifts (fix #18499) Message-ID: <5f3e97261b4b5_80b3f8468db919887188ba@gitlab.haskell.org.mail> Alan Zimmerman pushed to branch wip/az/ghc-9.0-anns at Glasgow Haskell Compiler / GHC Commits: 32496789 by Sylvain Henry at 2020-08-11T17:43:13+02:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - b4cccab3 by Sylvain Henry at 2020-08-11T17:48:05+02:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - 817f94f5 by Sylvain Henry at 2020-08-11T17:48:22+02:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - eab2511e by Sylvain Henry at 2020-08-12T11:43:42+02:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3745bdb6 by Sylvain Henry at 2020-08-12T11:43:42+02:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 7cf007cc by David Binder at 2020-08-13T18:22:38-04:00 Fix dead link to haskell prime discussion - - - - - 205f168c by BinderDavid at 2020-08-13T18:22:38-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 29794212 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Remove length field from FastString - - - - - f8804cd8 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 5acdf506 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - a9b46ec3 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - fcb9e94d by Daniel Gröber at 2020-08-13T18:22:38-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 44b28e97 by Daniel Gröber at 2020-08-13T18:22:38-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - f0fe989d by Daniel Gröber at 2020-08-13T18:22:38-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 59cd5cd4 by Daniel Gröber at 2020-08-13T18:22:38-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - 0f66e49e by Ben Gamari at 2020-08-13T18:22:38-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 3ecac53c by Andreas Klebinger at 2020-08-13T18:22:39-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - dbf77b79 by Sylvain Henry at 2020-08-13T18:22:39-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - 4e22de2a by Sylvain Henry at 2020-08-13T18:22:39-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - e27698ce by Sylvain Henry at 2020-08-13T18:22:39-04:00 Remove unused sGhcWithNativeCodeGen - - - - - 666acbd4 by Sylvain Henry at 2020-08-13T18:22:39-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - ce5408c0 by Sylvain Henry at 2020-08-13T18:22:39-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - 9751d499 by Tamar Christina at 2020-08-13T18:22:39-04:00 winio: restore console cp on exit (cherry picked from commit cdd0ff16f20ce920c74f9128a1067cbe1bd378c2) - - - - - 5438dcec by Tamar Christina at 2020-08-13T18:22:39-04:00 winio: change memory allocation strategy and fix double free errors. (cherry picked from commit c1f4f81d3a439cd1a8128e4ab11c7caac7cc0ad8) - - - - - 5544d17a by Stefan Schulze Frielinghaus at 2020-08-13T18:22:39-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 (cherry picked from commit fc0f6fbcd95f2dc69a8efabbee2d8a485c34cc47) - - - - - e66e281d by Matthias Andreas Benkard at 2020-08-13T18:22:39-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. (cherry picked from commit a7c4439a407ad85b76aab9301fda61e7c10183ff) - - - - - 986063cf by Ben Gamari at 2020-08-13T18:22:39-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. (cherry picked from commit da7269a4472856ba701d956a247599f721e9915e) - - - - - b2f8c6a7 by Ben Gamari at 2020-08-13T18:22:39-04:00 testsuite: Update win32 output for parseTree (cherry picked from commit f153a1d0a3351ad4d94cef4cef8e63bab5b47008) - - - - - 83a0649c by Ben Gamari at 2020-08-13T18:22:39-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. (cherry picked from commit e91672f0b7185bbafbe8ed1f2ae2cb775111f950) - - - - - 97ac5b2a by Ben Gamari at 2020-08-13T18:22:39-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. (cherry picked from commit 9cbfe0868418a531da0872b0c477a15aa67f8861) - - - - - 8f1154d3 by Tamar Christina at 2020-08-13T18:22:39-04:00 winio: remove dead argument to stg_newIOPortzh (cherry picked from commit 8236925fc8cc2e6e3fed61a0676fa65270a4a538) - - - - - 39c6fbae by Tamar Christina at 2020-08-13T18:22:39-04:00 winio: fix detection of tty terminals (cherry picked from commit ce0a1d678fbc8efa5fd384fd0227b7b3dc97cadd) - - - - - b784c75a by Tamar Christina at 2020-08-13T18:22:40-04:00 winio: update codeowners (cherry picked from commit 52685cf7c077c51e3719e3c4dd5ca8257a99c4ea) - - - - - 8388567e by Ben Gamari at 2020-08-13T18:22:40-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. (cherry picked from commit aa054d32a8ff69c334293a0d6c9d11b83a236a96) - - - - - 353521ab by Simon Peyton Jones at 2020-08-13T18:22:40-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 (cherry picked from commit 3d345c9680ab3d766ef43dd8389ccc1eaeca066c) - - - - - c0a3283a by Ben Gamari at 2020-08-13T18:22:40-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. (cherry picked from commit 57aca6bba1c000f8542ce94e8b724b0334ff96d4) - - - - - e14ee26b by Ben Gamari at 2020-08-13T18:22:40-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. (cherry picked from commit 0a815cea9fa11ce6ef22aec3525dd7a0df541daf) - - - - - cf9a6c17 by Simon Peyton Jones at 2020-08-13T18:22:40-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 (cherry picked from commit 0bd60059b0edfee9e8f66c6817257bbb946656cd) - - - - - 6ba13945 by Sergei Trofimovich at 2020-08-13T18:22:40-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> (cherry picked from commit 39c89862161bf488a6aca9372cbb67690f436ce7) - - - - - 59226e20 by Felix Wiemuth at 2020-08-13T18:22:40-04:00 Fix typo (cherry picked from commit b9a880fce484d0a87bb794b9d2d8a73e54819011) - - - - - 9166d4d6 by Simon Peyton Jones at 2020-08-13T18:22:40-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 (cherry picked from commit bbc5191640761ca9773abc898c077363b7beb4e7) - - - - - 505a9d68 by John Ericson at 2020-08-13T18:22:40-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. (cherry picked from commit 6c68a84254d70280e2dc73485f361787a3503850) - - - - - bd365c1d by Simon Peyton Jones at 2020-08-13T18:22:40-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d (cherry picked from commit 9f71f69714255165d0fdc2790a588487ff9439dc) - - - - - 6653e139 by Sylvain Henry at 2020-08-13T18:22:40-04:00 Fix minimal imports dump for boot files (fix #18497) (cherry picked from commit 7c274cd530cc42a26028050b75d56b3437e06ec1) - - - - - 2c86713b by Leon Schoorl at 2020-08-13T18:22:41-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 (cherry picked from commit f2d1accf67cb6e1dab6b2c78fef4b64526c31a4a) - - - - - 36d8cd6f by Niklas Hambüchen at 2020-08-13T18:22:41-04:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. (cherry picked from commit 947206f478d4eef641dfc58cb4c13471a23260c3) - - - - - 01534bf9 by Krzysztof Gogolewski at 2020-08-13T18:22:48-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. (cherry picked from commit 5e12cd1733b581f48a5873b12971b6974778eabb) - - - - - 20a45d0c by Ben Gamari at 2020-08-13T18:22:48-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. (cherry picked from commit 2bff2f87e43985e02bdde8c6fa39279df86cb617) - - - - - 2911d640 by Ben Gamari at 2020-08-13T18:22:48-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. (cherry picked from commit 53ce0db5a06598c88c6b8cb32043b878e7083dd4) - - - - - cb3e202a by Ryan Scott at 2020-08-13T18:22:48-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. (cherry picked from commit fbcb886d503dd7aaebc4c40e59615068b3fd0bd7) - - - - - bd506bd6 by Vladislav Zavialov at 2020-08-13T18:22:48-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. (cherry picked from commit aee45d9ea8c6cf4ebad4d5c732748923c7865cbe) - - - - - bc186461 by Takenobu Tani at 2020-08-13T18:22:48-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] (cherry picked from commit 9570c21295a2b4a1d1e40939869124f0b9b9bf91) - - - - - 77653d5c by Ben Gamari at 2020-08-13T18:22:48-04:00 cmm: Clean up Notes a bit (cherry picked from commit 5f03606319f745b10e9918c76a47426b293f0bf9) - - - - - 47de152f by Ben Gamari at 2020-08-13T18:22:48-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. (cherry picked from commit 6402c1240d5bd768b8fe8b4368413932bedbe107) - - - - - e64ac078 by Ben Gamari at 2020-08-13T18:22:48-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. (cherry picked from commit 15b36de030ecdd60897bc7a6a02bdeabd0825be4) - - - - - 24c230ce by Ben Gamari at 2020-08-13T18:22:48-04:00 testsuite: Add test for #18527 (cherry picked from commit 3847ae0ccf67bddf73304a39f5320c3ba285aa48) - - - - - ee2ed876 by Ben Gamari at 2020-08-13T18:22:48-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. (cherry picked from commit dd51d53be42114c105b5ab15fcbdb387526b1c17) - - - - - b4c33250 by Alan Zimmerman at 2020-08-13T18:22:48-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. (cherry picked from commit e4f1b73ad9f292a6bbeb21fee44b0ba1a7f3c33b) - - - - - cb39cfdc by Ben Gamari at 2020-08-13T18:22:48-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. (cherry picked from commit 8a665db6174eaedbbae925c0ccb4c22b3f29bcaf) - - - - - b221b571 by Alex Biehl at 2020-08-13T18:22:48-04:00 Hardcode RTS includes to cope with unregistered builds (cherry picked from commit ef2ae81a394df573510b12b7e11bba0c931249d8) - - - - - c15fb71b by Ben Gamari at 2020-08-13T18:22:48-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". (cherry picked from commit f1088b3f31ceddf918a319c97557fb1f08a9a387) - - - - - 3bda53ad by Ben Gamari at 2020-08-13T20:44:39-04:00 testsuite: Allow baseline commit to be set explicitly (cherry picked from commit bbde6ea0ce80a154735f1302251d073a56606c20) - - - - - ce32390c by Ben Gamari at 2020-08-15T12:19:32-04:00 gitlab-ci: Use MR base commit as performance baseline (cherry picked from commit 4b91e5edf64363eff7d087731c2806464033447c) Metric Decrease: T13056 T18304 T1969 T9233 - - - - - 57fd3ff0 by Ben Gamari at 2020-08-16T12:18:11-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. (cherry picked from commit 2f0bae734e2dc8737fbbb8465de7ded89c1121b6) - - - - - 0af2db18 by Ben Gamari at 2020-08-16T12:18:19-04:00 testsuite: Add test for #18291 (cherry picked from commit 6c7785f8e17a43a2578366134f74fd1989077b73) - - - - - 614ac76d by Ben Gamari at 2020-08-17T15:14:35-04:00 Clean up TBDs in changelog (cherry picked from commit 4f334120c8e9cc4aefcbf11d99f169f648af9fde) - - - - - 1a54d708 by Ben Gamari at 2020-08-17T15:14:35-04:00 Bump bytestring submodule - - - - - 20e19811 by Ben Gamari at 2020-08-17T15:14:35-04:00 Bump binary submodule - - - - - 8c7e8e1c by Ben Gamari at 2020-08-17T20:09:30+00:00 Bump Cabal submodule - - - - - 93cfed07 by Alan Zimmerman at 2020-08-20T15:48:16+01:00 Include API Annotations for trailing comma in export list - - - - - 3ccc80ee by Alan Zimmerman at 2020-08-20T15:48:16+01:00 Api Annotations : Adjust SrsSpans for prefix bang (!). And prefix ~ - - - - - f4ad068c by Alan Zimmerman at 2020-08-20T15:48:16+01:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/test-metrics.sh - CODEOWNERS - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Sink.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/Lint.hs - compiler/GHC/Core/Opt/OccurAnal.hs - compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/SetLevels.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Monad.hs - compiler/GHC/Core/Opt/Simplify/Utils.hs - compiler/GHC/Core/SimpleOpt.hs - compiler/GHC/CoreToStg/Prep.hs - compiler/GHC/Data/FastString.hs - compiler/GHC/Data/StringBuffer.hs - + compiler/GHC/Driver/Backend.hs - compiler/GHC/Driver/CodeOutput.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Make.hs - compiler/GHC/Driver/Pipeline.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d88bc94affafe24c3af7cb5f1fe095d1b9e676bf...f4ad068cf5784bcbb3eebe65d5fdcd81b9ea6540 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d88bc94affafe24c3af7cb5f1fe095d1b9e676bf...f4ad068cf5784bcbb3eebe65d5fdcd81b9ea6540 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 06:56:33 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 21 Aug 2020 02:56:33 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 7 commits: Implement -Wredundant-bang-patterns (#17340) Message-ID: <5f3f7021bfa86_80b3f8468e8ce9487665e5@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - de201efc by Sylvain Henry at 2020-08-21T02:56:25-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - b3ca4d70 by Sylvain Henry at 2020-08-21T02:56:25-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 0f17d2a2 by Sylvain Henry at 2020-08-21T02:56:25-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 1c0bf320 by Sylvain Henry at 2020-08-21T02:56:26-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - 2773b144 by Vladislav Zavialov at 2020-08-21T02:56:27-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - 30 changed files: - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - + compiler/GHC/CmmToAsm/CFG/Weight.hs - compiler/GHC/CmmToAsm/Config.hs - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/CmmToAsm/X86/Ppr.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/CmmToLlvm/CodeGen.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Driver/Flags.hs - compiler/GHC/Driver/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/Parser.y - compiler/GHC/Stg/Pipeline.hs - compiler/GHC/Tc/Gen/Bind.hs - compiler/GHC/Tc/Gen/Match.hs - compiler/GHC/Tc/Gen/Match.hs-boot - compiler/GHC/Tc/Utils/Zonk.hs - compiler/GHC/Unit/State.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/74e57004c54728ad9e9f1e6af8ebb92365e8ed95...2773b14489540e729bc6fe1744dc6f817ec1a559 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/74e57004c54728ad9e9f1e6af8ebb92365e8ed95...2773b14489540e729bc6fe1744dc6f817ec1a559 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 10:56:10 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Fri, 21 Aug 2020 06:56:10 -0400 Subject: [Git][ghc/ghc][wip/T18223] Work in progress on #18223 Message-ID: <5f3fa84ae9b84_80b3f8468db919887778cf@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18223 at Glasgow Haskell Compiler / GHC Commits: 716b67d9 by Simon Peyton Jones at 2020-08-20T17:29:09+01:00 Work in progress on #18223 There are two main changes in here 1. Stop Specialise specalising DFuns. This cases a huge (and utterly unnecessary) blowup in program size in #18223. I also refactored the Specialise monad a bit... it was silly. 2. Re-engineer eta-expansion (again). The eta-expander was generating lots of intermediate stuff, which could be optimised away, but which choked the simplifier meanwhile. Relatively easy to kill it off at source. Needs some Notes etc, and perhaps two separate patches, but I want to get this into CI and perf testing. - - - - - 8 changed files: - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Env.hs - compiler/GHC/Core/Opt/Specialise.hs - compiler/GHC/Core/Ppr.hs - compiler/GHC/Core/SimpleOpt.hs - compiler/GHC/Core/Subst.hs Changes: ===================================== compiler/GHC/Core/Coercion.hs ===================================== @@ -31,7 +31,7 @@ module GHC.Core.Coercion ( mkAxInstRHS, mkUnbranchedAxInstRHS, mkAxInstLHS, mkUnbranchedAxInstLHS, mkPiCo, mkPiCos, mkCoCast, - mkSymCo, mkTransCo, mkTransMCo, + mkSymCo, mkTransCo, mkNthCo, nthCoRole, mkLRCo, mkInstCo, mkAppCo, mkAppCos, mkTyConAppCo, mkFunCo, mkForAllCo, mkForAllCos, mkHomoForAllCos, @@ -65,7 +65,8 @@ module GHC.Core.Coercion ( pickLR, isGReflCo, isReflCo, isReflCo_maybe, isGReflCo_maybe, isReflexiveCo, isReflexiveCo_maybe, - isReflCoVar_maybe, isGReflMCo, coToMCo, + isReflCoVar_maybe, isGReflMCo, + coToMCo, mkTransMCo, mkTransMCoL, -- ** Coercion variables mkCoVar, isCoVar, coVarName, setCoVarName, setCoVarUnique, @@ -288,6 +289,44 @@ tidyCoAxBndrsForUser init_env tcvs ('_' : rest) -> all isDigit rest _ -> False + +{- ********************************************************************* +* * + MCoercion +* * +********************************************************************* -} + +coToMCo :: Coercion -> MCoercion +-- Convert a coercion to a MCoercion, +-- checking aggressively for reflexivity +coToMCo co | isReflexiveCo co = MRefl + | otherwise = MCo co + +-- | Tests if this MCoercion is obviously generalized reflexive +-- Guaranteed to work very quickly. +isGReflMCo :: MCoercion -> Bool +isGReflMCo MRefl = True +isGReflMCo (MCo co) | isGReflCo co = True +isGReflMCo _ = False + +-- | Make a generalized reflexive coercion +mkGReflCo :: Role -> Type -> MCoercionN -> Coercion +mkGReflCo r ty mco + | isGReflMCo mco = if r == Nominal then Refl ty + else GRefl r ty MRefl + | otherwise = GRefl r ty mco + +-- | Compose two MCoercions via transitivity +mkTransMCo :: MCoercion -> MCoercion -> MCoercion +mkTransMCo MRefl co2 = co2 +mkTransMCo co1 MRefl = co1 +mkTransMCo (MCo co1) (MCo co2) = MCo (mkTransCo co1 co2) + +mkTransMCoL :: MCoercion -> Coercion -> MCoercion +mkTransMCoL MRefl co2 = MCo co2 +mkTransMCoL (MCo co1) co2 = MCo (mkTransCo co1 co2) + + {- %************************************************************************ %* * @@ -556,13 +595,6 @@ isGReflCo (GRefl{}) = True isGReflCo (Refl{}) = True -- Refl ty == GRefl N ty MRefl isGReflCo _ = False --- | Tests if this MCoercion is obviously generalized reflexive --- Guaranteed to work very quickly. -isGReflMCo :: MCoercion -> Bool -isGReflMCo MRefl = True -isGReflMCo (MCo co) | isGReflCo co = True -isGReflMCo _ = False - -- | Tests if this coercion is obviously reflexive. Guaranteed to work -- very quickly. Sometimes a coercion can be reflexive, but not obviously -- so. c.f. 'isReflexiveCo' @@ -603,10 +635,6 @@ isReflexiveCo_maybe co = Nothing where (Pair ty1 ty2, r) = coercionKindRole co -coToMCo :: Coercion -> MCoercion -coToMCo c = if isReflCo c - then MRefl - else MCo c {- %************************************************************************ @@ -669,13 +697,6 @@ role is bizarre and a caller should have to ask for this behavior explicitly. -} --- | Make a generalized reflexive coercion -mkGReflCo :: Role -> Type -> MCoercionN -> Coercion -mkGReflCo r ty mco - | isGReflMCo mco = if r == Nominal then Refl ty - else GRefl r ty MRefl - | otherwise = GRefl r ty mco - -- | Make a reflexive coercion mkReflCo :: Role -> Type -> Coercion mkReflCo Nominal ty = Refl ty @@ -990,12 +1011,6 @@ mkTransCo (GRefl r t1 (MCo co1)) (GRefl _ _ (MCo co2)) = GRefl r t1 (MCo $ mkTransCo co1 co2) mkTransCo co1 co2 = TransCo co1 co2 --- | Compose two MCoercions via transitivity -mkTransMCo :: MCoercion -> MCoercion -> MCoercion -mkTransMCo MRefl co2 = co2 -mkTransMCo co1 MRefl = co1 -mkTransMCo (MCo co1) (MCo co2) = MCo (mkTransCo co1 co2) - mkNthCo :: HasDebugCallStack => Role -- The role of the coercion you're creating -> Int -- Zero-indexed ===================================== compiler/GHC/Core/Opt/Arity.hs ===================================== @@ -15,10 +15,18 @@ module GHC.Core.Opt.Arity ( manifestArity, joinRhsArity, exprArity, typeArity , exprEtaExpandArity, findRhsArity , etaExpand, etaExpandAT - , etaExpandToJoinPoint, etaExpandToJoinPointRule , exprBotStrictness_maybe + + -- ** ArityType , ArityType(..), expandableArityType, arityTypeArity , maxWithArity, isBotArityType, idArityType + + -- ** Join points + , etaExpandToJoinPoint, etaExpandToJoinPointRule + + -- ** Coercions and casts + , pushCoArg, pushCoArgs, pushCoValArg, pushCoTyArg + , pushCoercionIntoLambda, pushCoDataCon, collectBindersPushingCo ) where @@ -31,15 +39,21 @@ import GHC.Driver.Ppr import GHC.Core import GHC.Core.FVs import GHC.Core.Utils -import GHC.Core.Subst import GHC.Types.Demand import GHC.Types.Var import GHC.Types.Var.Env import GHC.Types.Id -import GHC.Core.Type as Type -import GHC.Core.TyCon ( initRecTc, checkRecTc ) + +-- We have two sorts of substitution: +-- GHC.Core.Subst.Subst, and GHC.Core.TyCo.TCvSubst +-- Both have substTy, substCo Hence need for qualification +import GHC.Core.Subst as Core +import GHC.Core.Type as Type +import GHC.Core.Coercion as Type + +import GHC.Core.DataCon +import GHC.Core.TyCon ( initRecTc, checkRecTc, tyConArity ) import GHC.Core.Predicate ( isDictTy ) -import GHC.Core.Coercion as Coercion import GHC.Core.Multiplicity import GHC.Types.Var.Set import GHC.Types.Basic @@ -48,7 +62,8 @@ import GHC.Driver.Session ( DynFlags, GeneralFlag(..), gopt ) import GHC.Utils.Outputable import GHC.Utils.Panic import GHC.Data.FastString -import GHC.Utils.Misc ( lengthAtLeast ) +import GHC.Data.Pair +import GHC.Utils.Misc {- ************************************************************************ @@ -1076,12 +1091,11 @@ eta_expand one_shots orig_expr go oss (Cast expr co) = Cast (go oss expr) co go oss expr - = -- pprTrace "ee" (vcat [ppr orig_expr, ppr expr, ppr etas]) $ - retick $ etaInfoAbs etas (etaInfoApp subst' sexpr etas) + = -- pprTrace "ee" (vcat [ppr orig_expr, ppr expr, pprEtaInfos etas]) $ + retick $ etaInfoAbs etas (etaInfoApp in_scope' sexpr etas) where in_scope = mkInScopeSet (exprFreeVars expr) (in_scope', etas) = mkEtaWW oss (ppr orig_expr) in_scope (exprType expr) - subst' = mkEmptySubst in_scope' -- Find ticks behind type apps. -- See Note [Eta expansion and source notes] @@ -1090,76 +1104,190 @@ eta_expand one_shots orig_expr sexpr = foldl' App expr'' args retick expr = foldr mkTick expr ticks - -- Abstraction Application +{- ********************************************************************* +* * + The EtaInfo mechanism +* * +************************************************************************ + +{- Note [The EtaInfo mechanism] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Suppose we have (e :: ty) and we want to eta-expand it to arity N. +This what eta_expand does. We do it in two steps: + +1. From 'ty' and 'N' build a [EtaInfo] which describes the shape + of the expansion. + +2. Build the term + \ v1..vn. e v1 .. vn + where those abstractions and applications are described by + the same [EtaInfo]. Specifically we build the term + + etaInfoAbs etas (etaInfoApp in_scope e etas) + + where etas :: [EtaInfo]# + etaInfoAbs builds the lambdas + etaInfoApp builds the applictions + + Note that the /same/ [EtaInfo] drives both etaInfoAbs and etaInfoApp + +To a first approximation [EtaInfo] is just [Var]. But +casts complicate the question. If we have + newtype N a = MkN (S -> a) +and + ty = N (N Int) +then the eta-expansion must look like + (\x (\y. ((e |> co1) x) |> co2) y) + |> sym co2) + |> sym co1 +where + co1 :: N (N Int) ~ S -> N Int + co2 :: N Int ~ S -> Int + +Blimey! Look at all those casts. Moreover, if the type +is very deeply nested (as happens in #18223), the repetition +of types can make the overall term very large. So there is a big +payoff in cancelling out casts aggressively wherever possible. +(See also Note [No crap in eta-expanded code].) + +This matters a lot in etaEInfoApp, where we +* Do beta-reduction on the fly +* Use getARg_mabye to get a cast out of the way, + so that we can do beta reduction +Together this makes a big difference. Consider when e is + case x of + True -> (\x -> e1) |> c1 + False -> (\p -> e2) |> c2 + +When we eta-expand this to arity 1, say, etaInfoAbs will wrap +a (\eta) around the outside and use etaInfoApp to apply each +alternative to 'eta'. We want to beta-reduce all that junk +away. + +#18223 was a dramtic example in which the intermediate term was +grotesquely huge, even though the next Simplifier iteration squashed +it. Better to kill it at birth. +-} + -------------- -data EtaInfo = EtaVar Var -- /\a. [] [] a - -- \x. [] [] x - | EtaCo Coercion -- [] |> sym co [] |> co +data EtaInfo -- Abstraction Application + = EtaVar Var -- /\a. [] [] a + -- (\x. []) [] x + | EtaCo CoercionR -- [] |> sym co [] |> co instance Outputable EtaInfo where - ppr (EtaVar v) = text "EtaVar" <+> ppr v - ppr (EtaCo co) = text "EtaCo" <+> ppr co + ppr (EtaVar v) = text "EtaVar" <+> ppr v <+> dcolon <+> ppr (idType v) + ppr (EtaCo co) = text "EtaCo" <+> hang (ppr co) 2 (dcolon <+> ppr (coercionType co)) + +-- Used in debug-printing +-- pprEtaInfos :: [EtaInfo] -> SDoc +-- pprEtaInfos eis = brackets $ vcat $ punctuate comma $ map ppr eis pushCoercion :: Coercion -> [EtaInfo] -> [EtaInfo] +-- Puts a EtaCo on the front of a [EtaInfo], but combining +-- with an existing EtaCo if possible +-- A minor improvement pushCoercion co1 (EtaCo co2 : eis) | isReflCo co = eis | otherwise = EtaCo co : eis where co = co1 `mkTransCo` co2 -pushCoercion co eis = EtaCo co : eis +pushCoercion co eis + = EtaCo co : eis + +getArg_maybe :: [EtaInfo] -> Maybe (CoreArg, [EtaInfo]) +-- Get an argument to the front of the [EtaInfo], if possible, +-- by pushing any EtaCo through the argument +getArg_maybe eis = go MRefl eis + where + go :: MCoercion -> [EtaInfo] -> Maybe (CoreArg, [EtaInfo]) + go _ [] = Nothing + go mco (EtaCo co2 : eis) = go (mkTransMCoL mco co2) eis + go MRefl (EtaVar v : eis) = Just (varToCoreExpr v, eis) + go (MCo co) (EtaVar v : eis) + | Just (arg, mco) <- pushCoArg co (varToCoreExpr v) + = case mco of + MRefl -> Just (arg, eis) + MCo co -> Just (arg, pushCoercion co eis) + | otherwise + = Nothing + +mkCastMCo :: CoreExpr -> MCoercionR -> CoreExpr +mkCastMCo e MRefl = e +mkCastMCo e (MCo co) = Cast e co + +mkPiMCo :: Var -> MCoercionR -> MCoercionR +mkPiMCo _ MRefl = MRefl +mkPiMCo v (MCo co) = MCo (mkPiCo Representational v co) -------------- etaInfoAbs :: [EtaInfo] -> CoreExpr -> CoreExpr -etaInfoAbs [] expr = expr -etaInfoAbs (EtaVar v : eis) expr = Lam v (etaInfoAbs eis expr) -etaInfoAbs (EtaCo co : eis) expr = Cast (etaInfoAbs eis expr) (mkSymCo co) +etaInfoAbs eis expr + | null eis = expr + | otherwise = case final_mco of + MRefl -> expr' + MCo co -> mkCast expr' co + where + (expr', final_mco) = foldr do_one (split_cast expr) eis + + do_one :: EtaInfo -> (CoreExpr, MCoercion) -> (CoreExpr, MCoercion) + do_one (EtaVar v) (expr, mco) = (Lam v expr, mkPiMCo v mco) + do_one (EtaCo co) (expr, mco) = (expr, mco `mkTransMCoL` mkSymCo co) + + split_cast :: CoreExpr -> (CoreExpr, MCoercion) + split_cast (Cast e co) = (e, MCo co) + split_cast e = (e, MRefl) + -- We could look in the body of lets, and the branches of a case + -- But then we would have to worry about whether the cast mentioned + -- any of the bound variables, which is tiresome. Later maybe. + -- Result: we may end up with + -- (\(x::Int). case x of { DEFAULT -> e1 |> co }) |> sym (->co) + -- and fail to optimise it away -------------- -etaInfoApp :: Subst -> CoreExpr -> [EtaInfo] -> CoreExpr +etaInfoApp :: InScopeSet -> CoreExpr -> [EtaInfo] -> CoreExpr -- (etaInfoApp s e eis) returns something equivalent to --- ((substExpr s e) `appliedto` eis) +-- (substExpr s e `appliedto` eis) -etaInfoApp subst (Lam v1 e) (EtaVar v2 : eis) - = etaInfoApp (GHC.Core.Subst.extendSubstWithVar subst v1 v2) e eis - -etaInfoApp subst (Cast e co1) eis - = etaInfoApp subst e (pushCoercion co' eis) +etaInfoApp in_scope expr eis + = go (mkEmptySubst in_scope) expr eis where - co' = GHC.Core.Subst.substCo subst co1 + go :: Subst -> CoreExpr -> [EtaInfo] -> CoreExpr + -- 'go' pushed down the eta-infos into the branch of a case + -- and the body of a let; and does beta-reduction if possible + go subst (Tick t e) eis + = Tick (substTickish subst t) (go subst e eis) + go subst (Cast e co) eis + = go subst e (pushCoercion (Core.substCo subst co) eis) + go subst (Case e b ty alts) eis + = Case (Core.substExprSC subst e) b1 ty' alts' + where + (subst1, b1) = Core.substBndr subst b + alts' = map subst_alt alts + ty' = etaInfoAppTy (Core.substTy subst ty) eis + subst_alt (con, bs, rhs) = (con, bs', go subst2 rhs eis) + where + (subst2,bs') = Core.substBndrs subst1 bs + go subst (Let b e) eis + | not (isJoinBind b) -- See Note [Eta expansion for join points] + = Let b' (go subst' e eis) + where + (subst', b') = Core.substBindSC subst b -etaInfoApp subst (Case e b ty alts) eis - = Case (subst_expr subst e) b1 ty' alts' - where - (subst1, b1) = substBndr subst b - alts' = map subst_alt alts - ty' = etaInfoAppTy (GHC.Core.Subst.substTy subst ty) eis - subst_alt (con, bs, rhs) = (con, bs', etaInfoApp subst2 rhs eis) - where - (subst2,bs') = substBndrs subst1 bs - -etaInfoApp subst (Let b e) eis - | not (isJoinBind b) - -- See Note [Eta expansion for join points] - = Let b' (etaInfoApp subst' e eis) - where - (subst', b') = substBindSC subst b + -- Beta-reduction if possible, using getArg_maybe to push + -- any intervening casts past the argument + -- See Note [The EtaInfo mechansim] + go subst (Lam v e) eis + | Just (arg, eis') <- getArg_maybe eis + = go (Core.extendSubst subst v arg) e eis' -etaInfoApp subst (Tick t e) eis - = Tick (substTickish subst t) (etaInfoApp subst e eis) + -- Stop pushing down; just wrap the expression up + go subst e eis = wrap (Core.substExprSC subst e) eis -etaInfoApp subst expr _ - | (Var fun, _) <- collectArgs expr - , Var fun' <- lookupIdSubst subst fun - , isJoinId fun' - = subst_expr subst expr - -etaInfoApp subst e eis - = go (subst_expr subst e) eis - where - go e [] = e - go e (EtaVar v : eis) = go (App e (varToCoreExpr v)) eis - go e (EtaCo co : eis) = go (Cast e co) eis + wrap e [] = e + wrap e (EtaVar v : eis) = wrap (App e (varToCoreExpr v)) eis + wrap e (EtaCo co : eis) = wrap (Cast e co) eis -------------- @@ -1235,7 +1363,7 @@ mkEtaWW orig_oss ppr_orig_expr in_scope orig_ty -- We want to get -- coerce T (\x::[T] -> (coerce ([T]->Int) e) x) | Just (co, ty') <- topNormaliseNewType_maybe ty - , let co' = Coercion.substCo subst co + , let co' = Type.substCo subst co -- Remember to apply the substitution to co (#16979) -- (or we could have applied to ty, but then -- we'd have had to zap it for the recursive call) @@ -1253,21 +1381,288 @@ mkEtaWW orig_oss ppr_orig_expr in_scope orig_ty -- with an explicit lambda having a non-function type +{- ********************************************************************* +* * + The "push rules" +* * +************************************************************************ + +Here we implement the "push rules" from FC papers: + +* The push-argument rules, where we can move a coercion past an argument. + We have + (fun |> co) arg + and we want to transform it to + (fun arg') |> co' + for some suitable co' and transformed arg'. + +* The PushK rule for data constructors. We have + (K e1 .. en) |> co + and we want to transform to + (K e1' .. en') + by pushing the coercion into the arguments +-} + +pushCoArgs :: CoercionR -> [CoreArg] -> Maybe ([CoreArg], MCoercion) +pushCoArgs co [] = return ([], MCo co) +pushCoArgs co (arg:args) = do { (arg', m_co1) <- pushCoArg co arg + ; case m_co1 of + MCo co1 -> do { (args', m_co2) <- pushCoArgs co1 args + ; return (arg':args', m_co2) } + MRefl -> return (arg':args, MRefl) } + +pushCoArg :: CoercionR -> CoreArg -> Maybe (CoreArg, MCoercion) +-- We have (fun |> co) arg, and we want to transform it to +-- (fun arg) |> co +-- This may fail, e.g. if (fun :: N) where N is a newtype +-- C.f. simplCast in GHC.Core.Opt.Simplify +-- 'co' is always Representational +-- If the returned coercion is Nothing, then it would have been reflexive +pushCoArg co (Type ty) = do { (ty', m_co') <- pushCoTyArg co ty + ; return (Type ty', m_co') } +pushCoArg co val_arg = do { (arg_co, m_co') <- pushCoValArg co + ; return (val_arg `mkCastMCo` arg_co, m_co') } + +pushCoTyArg :: CoercionR -> Type -> Maybe (Type, MCoercionR) +-- We have (fun |> co) @ty +-- Push the coercion through to return +-- (fun @ty') |> co' +-- 'co' is always Representational +-- If the returned coercion is Nothing, then it would have been reflexive; +-- it's faster not to compute it, though. +pushCoTyArg co ty + -- The following is inefficient - don't do `eqType` here, the coercion + -- optimizer will take care of it. See #14737. + -- -- | tyL `eqType` tyR + -- -- = Just (ty, Nothing) + + | isReflCo co + = Just (ty, MRefl) + + | isForAllTy_ty tyL + = ASSERT2( isForAllTy_ty tyR, ppr co $$ ppr ty ) + Just (ty `mkCastTy` co1, MCo co2) + + | otherwise + = Nothing + where + Pair tyL tyR = coercionKind co + -- co :: tyL ~ tyR + -- tyL = forall (a1 :: k1). ty1 + -- tyR = forall (a2 :: k2). ty2 + + co1 = mkSymCo (mkNthCo Nominal 0 co) + -- co1 :: k2 ~N k1 + -- Note that NthCo can extract a Nominal equality between the + -- kinds of the types related by a coercion between forall-types. + -- See the NthCo case in GHC.Core.Lint. + + co2 = mkInstCo co (mkGReflLeftCo Nominal ty co1) + -- co2 :: ty1[ (ty|>co1)/a1 ] ~ ty2[ ty/a2 ] + -- Arg of mkInstCo is always nominal, hence mkNomReflCo + +pushCoValArg :: CoercionR -> Maybe (MCoercionR, MCoercionR) +-- We have (fun |> co) arg +-- Push the coercion through to return +-- (fun (arg |> co_arg)) |> co_res +-- 'co' is always Representational +-- If the second returned Coercion is actually Nothing, then no cast is necessary; +-- the returned coercion would have been reflexive. +pushCoValArg co + -- The following is inefficient - don't do `eqType` here, the coercion + -- optimizer will take care of it. See #14737. + -- -- | tyL `eqType` tyR + -- -- = Just (mkRepReflCo arg, Nothing) + + | isReflCo co + = Just (MRefl, MRefl) + + | isFunTy tyL + , (co_mult, co1, co2) <- decomposeFunCo Representational co + , isReflexiveCo co_mult + -- We can't push the coercion in the case where co_mult isn't reflexivity: + -- it could be an unsafe axiom, and losing this information could yield + -- ill-typed terms. For instance (fun x ::(1) Int -> (fun _ -> () |> co) x) + -- with co :: (Int -> ()) ~ (Int #-> ()), would reduce to (fun x ::(1) Int + -- -> (fun _ ::(Many) Int -> ()) x) which is ill-typed + + -- If co :: (tyL1 -> tyL2) ~ (tyR1 -> tyR2) + -- then co1 :: tyL1 ~ tyR1 + -- co2 :: tyL2 ~ tyR2 + = ASSERT2( isFunTy tyR, ppr co $$ ppr arg ) + Just (coToMCo (mkSymCo co1), coToMCo co2) + -- Use coToMCo to check for reflexivity; the whole coercion may not + -- be reflexive, but either of its components might be + + | otherwise + = Nothing + where + arg = funArgTy tyR + Pair tyL tyR = coercionKind co + +pushCoercionIntoLambda + :: InScopeSet -> Var -> CoreExpr -> CoercionR -> Maybe (Var, CoreExpr) +-- This implements the Push rule from the paper on coercions +-- (\x. e) |> co +-- ===> +-- (\x'. e |> co') +pushCoercionIntoLambda in_scope x e co + | ASSERT(not (isTyVar x) && not (isCoVar x)) True + , Pair s1s2 t1t2 <- coercionKind co + , Just (_, _s1,_s2) <- splitFunTy_maybe s1s2 + , Just (w1, t1,_t2) <- splitFunTy_maybe t1t2 + , (co_mult, co1, co2) <- decomposeFunCo Representational co + , isReflexiveCo co_mult + -- We can't push the coercion in the case where co_mult isn't + -- reflexivity. See pushCoValArg for more details. + = let + -- Should we optimize the coercions here? + -- Otherwise they might not match too well + x' = x `setIdType` t1 `setIdMult` w1 + in_scope' = in_scope `extendInScopeSet` x' + subst = extendIdSubst (mkEmptySubst in_scope') + x + (mkCast (Var x') co1) + in Just (x', substExpr subst e `mkCast` co2) + | otherwise + = pprTrace "exprIsLambda_maybe: Unexpected lambda in case" (ppr (Lam x e)) + Nothing + +pushCoDataCon :: DataCon -> [CoreExpr] -> Coercion + -> Maybe (DataCon + , [Type] -- Universal type args + , [CoreExpr]) -- All other args incl existentials +-- Implement the KPush reduction rule as described in "Down with kinds" +-- The transformation applies iff we have +-- (C e1 ... en) `cast` co +-- where co :: (T t1 .. tn) ~ to_ty +-- The left-hand one must be a T, because exprIsConApp returned True +-- but the right-hand one might not be. (Though it usually will.) +pushCoDataCon dc dc_args co + | isReflCo co || from_ty `eqType` to_ty -- try cheap test first + , let (univ_ty_args, rest_args) = splitAtList (dataConUnivTyVars dc) dc_args + = Just (dc, map exprToType univ_ty_args, rest_args) + + | Just (to_tc, to_tc_arg_tys) <- splitTyConApp_maybe to_ty + , to_tc == dataConTyCon dc + -- These two tests can fail; we might see + -- (C x y) `cast` (g :: T a ~ S [a]), + -- where S is a type function. In fact, exprIsConApp + -- will probably not be called in such circumstances, + -- but there's nothing wrong with it + + = let + tc_arity = tyConArity to_tc + dc_univ_tyvars = dataConUnivTyVars dc + dc_ex_tcvars = dataConExTyCoVars dc + arg_tys = dataConRepArgTys dc + + non_univ_args = dropList dc_univ_tyvars dc_args + (ex_args, val_args) = splitAtList dc_ex_tcvars non_univ_args + + -- Make the "Psi" from the paper + omegas = decomposeCo tc_arity co (tyConRolesRepresentational to_tc) + (psi_subst, to_ex_arg_tys) + = liftCoSubstWithEx Representational + dc_univ_tyvars + omegas + dc_ex_tcvars + (map exprToType ex_args) + + -- Cast the value arguments (which include dictionaries) + new_val_args = zipWith cast_arg (map scaledThing arg_tys) val_args + cast_arg arg_ty arg = mkCast arg (psi_subst arg_ty) + + to_ex_args = map Type to_ex_arg_tys + + dump_doc = vcat [ppr dc, ppr dc_univ_tyvars, ppr dc_ex_tcvars, + ppr arg_tys, ppr dc_args, + ppr ex_args, ppr val_args, ppr co, ppr from_ty, ppr to_ty, ppr to_tc + , ppr $ mkTyConApp to_tc (map exprToType $ takeList dc_univ_tyvars dc_args) ] + in + ASSERT2( eqType from_ty (mkTyConApp to_tc (map exprToType $ takeList dc_univ_tyvars dc_args)), dump_doc ) + ASSERT2( equalLength val_args arg_tys, dump_doc ) + Just (dc, to_tc_arg_tys, to_ex_args ++ new_val_args) + + | otherwise + = Nothing + + where + Pair from_ty to_ty = coercionKind co ------------- -subst_expr :: Subst -> CoreExpr -> CoreExpr --- Apply a substitution to an expression. We use substExpr --- not substExprSC (short-cutting substitution) because --- we may be changing the types of join points, so applying --- the in-scope set is necessary. +collectBindersPushingCo :: CoreExpr -> ([Var], CoreExpr) +-- Collect lambda binders, pushing coercions inside if possible +-- E.g. (\x.e) |> g g :: -> blah +-- = (\x. e |> Nth 1 g) +-- +-- That is, -- --- ToDo: we could instead check if we actually *are* --- changing any join points' types, and if not use substExprSC. -subst_expr = substExpr +-- collectBindersPushingCo ((\x.e) |> g) === ([x], e |> Nth 1 g) +collectBindersPushingCo e + = go [] e + where + -- Peel off lambdas until we hit a cast. + go :: [Var] -> CoreExpr -> ([Var], CoreExpr) + -- The accumulator is in reverse order + go bs (Lam b e) = go (b:bs) e + go bs (Cast e co) = go_c bs e co + go bs e = (reverse bs, e) + + -- We are in a cast; peel off casts until we hit a lambda. + go_c :: [Var] -> CoreExpr -> CoercionR -> ([Var], CoreExpr) + -- (go_c bs e c) is same as (go bs e (e |> c)) + go_c bs (Cast e co1) co2 = go_c bs e (co1 `mkTransCo` co2) + go_c bs (Lam b e) co = go_lam bs b e co + go_c bs e co = (reverse bs, mkCast e co) + + -- We are in a lambda under a cast; peel off lambdas and build a + -- new coercion for the body. + go_lam :: [Var] -> Var -> CoreExpr -> CoercionR -> ([Var], CoreExpr) + -- (go_lam bs b e c) is same as (go_c bs (\b.e) c) + go_lam bs b e co + | isTyVar b + , let Pair tyL tyR = coercionKind co + , ASSERT( isForAllTy_ty tyL ) + isForAllTy_ty tyR + , isReflCo (mkNthCo Nominal 0 co) -- See Note [collectBindersPushingCo] + = go_c (b:bs) e (mkInstCo co (mkNomReflCo (mkTyVarTy b))) + + | isCoVar b + , let Pair tyL tyR = coercionKind co + , ASSERT( isForAllTy_co tyL ) + isForAllTy_co tyR + , isReflCo (mkNthCo Nominal 0 co) -- See Note [collectBindersPushingCo] + , let cov = mkCoVarCo b + = go_c (b:bs) e (mkInstCo co (mkNomReflCo (mkCoercionTy cov))) + + | isId b + , let Pair tyL tyR = coercionKind co + , ASSERT( isFunTy tyL) isFunTy tyR + , (co_mult, co_arg, co_res) <- decomposeFunCo Representational co + , isReflCo co_mult -- See Note [collectBindersPushingCo] + , isReflCo co_arg -- See Note [collectBindersPushingCo] + = go_c (b:bs) e co_res + + | otherwise = (reverse bs, mkCast (Lam b e) co) +{- --------------- +Note [collectBindersPushingCo] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +We just look for coercions of form + # w -> blah +(and similarly for foralls) to keep this function simple. We could do +more elaborate stuff, but it'd involve substitution etc. +-} + +{- ********************************************************************* +* * + Join points +* * +********************************************************************* -} + +------------------- -- | Split an expression into the given number of binders and a body, -- eta-expanding if necessary. Counts value *and* type binders. etaExpandToJoinPoint :: JoinArity -> CoreExpr -> ([CoreBndr], CoreExpr) @@ -1307,7 +1702,7 @@ etaBodyForJoinPoint need_args body = (reverse rev_bs, e) go n ty subst rev_bs e | Just (tv, res_ty) <- splitForAllTy_maybe ty - , let (subst', tv') = Type.substVarBndr subst tv + , let (subst', tv') = substVarBndr subst tv = go (n-1) res_ty subst' (tv' : rev_bs) (e `App` varToCoreExpr tv') | Just (mult, arg_ty, res_ty) <- splitFunTy_maybe ty , let (subst', b) = freshEtaId n subst (Scaled mult arg_ty) @@ -1318,6 +1713,8 @@ etaBodyForJoinPoint need_args body init_subst e = mkEmptyTCvSubst (mkInScopeSet (exprFreeVars e)) + + -------------- freshEtaId :: Int -> TCvSubst -> Scaled Type -> (TCvSubst, Id) -- Make a fresh Id, with specified type (after applying substitution) @@ -1336,3 +1733,4 @@ freshEtaId n subst ty -- "OrCoVar" since this can be used to eta-expand -- coercion abstractions subst' = extendTCvInScope subst eta_id' + ===================================== compiler/GHC/Core/Opt/Simplify.hs ===================================== @@ -48,9 +48,9 @@ import GHC.Types.Unique ( hasKey ) import GHC.Core.Unfold import GHC.Core.Utils import GHC.Core.Opt.Arity ( ArityType(..), arityTypeArity, isBotArityType + , pushCoTyArg, pushCoValArg , idArityType, etaExpandAT ) -import GHC.Core.SimpleOpt ( pushCoTyArg, pushCoValArg - , joinPointBinding_maybe, joinPointBindings_maybe ) +import GHC.Core.SimpleOpt ( joinPointBinding_maybe, joinPointBindings_maybe ) import GHC.Core.FVs ( mkRuleInfo ) import GHC.Core.Rules ( lookupRule, getRules, initRuleOpts ) import GHC.Types.Basic @@ -315,7 +315,7 @@ simplLazyBind env top_lvl is_rec bndr bndr1 rhs rhs_se ; let rhs_cont = mkRhsStop (substTy body_env (exprType body)) ; (body_floats0, body0) <- {-#SCC "simplExprF" #-} simplExprF body_env body rhs_cont - -- Never float join-floats out of a non-join let-binding + -- Never float join-floats out of a non-join let-binding (which this is) -- So wrap the body in the join-floats right now -- Hence: body_floats1 consists only of let-floats ; let (body_floats1, body1) = wrapJoinFloatsX body_floats0 body0 @@ -385,7 +385,8 @@ simplNonRecX env bndr new_rhs | otherwise = do { (env', bndr') <- simplBinder env bndr - ; completeNonRecX NotTopLevel env' (isStrictId bndr) bndr bndr' new_rhs } + ; -- pprTrace "simplNonRecX" (ppr bndr <+> ppr bndr' $$ ppr (idOccInfo bndr) $$ ppr new_rhs) $ + completeNonRecX NotTopLevel env' (isStrictId bndr) bndr bndr' new_rhs } -- simplNonRecX is only used for NotTopLevel things -------------------------- @@ -600,7 +601,8 @@ prepareRhs mode top_lvl occ rhs0 = do { (is_exp, floats1, fun') <- go (n_val_args+1) fun ; case is_exp of False -> return (False, emptyLetFloats, App fun arg) - True -> do { (floats2, arg') <- makeTrivial mode top_lvl topDmd occ arg + True -> do { (floats2, arg') <- -- pprTrace "prepareRhs" (ppr occ <+> ppr rhs0) $ + makeTrivial mode top_lvl topDmd occ arg ; return (True, floats1 `addLetFlts` floats2, App fun' arg') } } go n_val_args (Var fun) = return (is_exp, emptyLetFloats, Var fun) @@ -680,7 +682,8 @@ makeTrivialBinding mode top_lvl occ_fs info expr expr_ty ; let final_id = addLetBndrInfo var arity_type unf bind = NonRec final_id expr2 - ; return ( floats `addLetFlts` unitLetFloat bind, final_id ) } + ; -- pprTrace "makeTrivial" (ppr bind) $ + return ( floats `addLetFlts` unitLetFloat bind, final_id ) } bindingOk :: TopLevelFlag -> CoreExpr -> Type -> Bool -- True iff we can have a binding of this expression at this level @@ -1411,25 +1414,23 @@ simplCast env body co0 cont0 -- type of the hole changes (#16312) -- (f |> co) e ===> (f (e |> co1)) |> co2 - -- where co :: (s1->s2) ~ (t1~t2) + -- where co :: (s1->s2) ~ (t1->t2) -- co1 :: t1 ~ s1 -- co2 :: s2 ~ t2 addCoerce co cont@(ApplyToVal { sc_arg = arg, sc_env = arg_se , sc_dup = dup, sc_cont = tail }) - | Just (co1, m_co2) <- pushCoValArg co - , let new_ty = coercionRKind co1 - , not (isTypeLevPoly new_ty) -- Without this check, we get a lev-poly arg - -- See Note [Levity polymorphism invariants] in GHC.Core - -- test: typecheck/should_run/EtaExpandLevPoly + | Just (m_co1, m_co2) <- pushCoValArg co + , levity_ok m_co1 = {-#SCC "addCoerce-pushCoValArg" #-} do { tail' <- addCoerceM m_co2 tail - ; if isReflCo co1 - then return (cont { sc_cont = tail' - , sc_hole_ty = coercionLKind co }) + ; case m_co1 of { + MRefl -> return (cont { sc_cont = tail' + , sc_hole_ty = coercionLKind co }) ; -- Avoid simplifying if possible; -- See Note [Avoiding exponential behaviour] - else do - { (dup', arg_se', arg') <- simplArg env dup arg_se arg + + MCo co1 -> + do { (dup', arg_se', arg') <- simplArg env dup arg_se arg -- When we build the ApplyTo we can't mix the OutCoercion -- 'co' with the InExpr 'arg', so we simplify -- to make it all consistent. It's a bit messy. @@ -1439,7 +1440,7 @@ simplCast env body co0 cont0 , sc_env = arg_se' , sc_dup = dup' , sc_cont = tail' - , sc_hole_ty = coercionLKind co }) } } + , sc_hole_ty = coercionLKind co }) } } } addCoerce co cont | isReflexiveCo co = return cont -- Having this at the end makes a huge @@ -1447,6 +1448,13 @@ simplCast env body co0 cont0 -- See Note [Optimising reflexivity] | otherwise = return (CastIt co cont) + levity_ok :: MCoercionR -> Bool + levity_ok MRefl = True + levity_ok (MCo co) = not $ isTypeLevPoly $ coercionRKind co + -- Without this check, we get a lev-poly arg + -- See Note [Levity polymorphism invariants] in GHC.Core + -- test: typecheck/should_run/EtaExpandLevPoly + simplArg :: SimplEnv -> DupFlag -> StaticEnv -> CoreExpr -> SimplM (DupFlag, StaticEnv, OutExpr) simplArg env dup_flag arg_env arg @@ -3111,7 +3119,7 @@ knownCon :: SimplEnv knownCon env scrut dc_floats dc dc_ty_args dc_args bndr bs rhs cont = do { (floats1, env1) <- bind_args env bs dc_args - ; (floats2, env2) <- bind_case_bndr env1 + ; (floats2, env2) <- bind_case_bndr env1 ; (floats3, expr') <- simplExprF env2 rhs cont ; case dc_floats of [] -> @@ -3143,8 +3151,9 @@ knownCon env scrut dc_floats dc dc_ty_args dc_args bndr bs rhs cont -- it via postInlineUnconditionally. -- Nevertheless we must keep it if the case-binder is alive, -- because it may be used in the con_app. See Note [knownCon occ info] - ; (floats1, env2) <- simplNonRecX env' b' arg -- arg satisfies let/app invariant - ; (floats2, env3) <- bind_args env2 bs' args + ; (floats1, env2) <- -- pprTrace "knownCon" (vcat [ pprBndr CasePatBind b, pprBndr CasePatBind b', ppr arg ]) $ + simplNonRecX env' b' arg -- arg satisfies let/app invariant + ; (floats2, env3) <- bind_args env2 bs' args ; return (floats1 `addFloats` floats2, env3) } bind_args _ _ _ = @@ -3237,6 +3246,7 @@ altsWouldDup [_] = False altsWouldDup (alt:alts) | is_bot_alt alt = altsWouldDup alts | otherwise = not (all is_bot_alt alts) + -- otherwise case: first alt is non-bot, so all the rest must be bot where is_bot_alt (_,_,rhs) = exprIsDeadEnd rhs @@ -3824,7 +3834,8 @@ simplStableUnfolding env top_lvl mb_cont id rhs_ty id_arity unf simplJoinRhs unf_env id expr cont Nothing -> -- Binder is not a join point do { expr' <- simplExprC unf_env expr (mkBoringStop rhs_ty) - ; return (eta_expand expr') } + ; -- pprTrace "ssu" (ppr expr $$ ppr expr' $$ ppr (eta_expand expr')) $ + return (eta_expand expr') } ; case guide of UnfWhen { ug_arity = arity , ug_unsat_ok = sat_ok ===================================== compiler/GHC/Core/Opt/Simplify/Env.hs ===================================== @@ -591,7 +591,7 @@ addJoinFlts :: JoinFloats -> JoinFloats -> JoinFloats addJoinFlts = appOL mkRecFloats :: SimplFloats -> SimplFloats --- Flattens the floats from env2 into a single Rec group, +-- Flattens the floats into a single Rec group, -- They must either all be lifted LetFloats or all JoinFloats mkRecFloats floats@(SimplFloats { sfLetFloats = LetFloats bs ff , sfJoinFloats = jbs ===================================== compiler/GHC/Core/Opt/Specialise.hs ===================================== @@ -21,7 +21,7 @@ import GHC.Tc.Utils.TcType hiding( substTy ) import GHC.Core.Type hiding( substTy, extendTvSubstList ) import GHC.Core.Multiplicity import GHC.Core.Predicate -import GHC.Unit.Module( Module, HasModule(..) ) +import GHC.Unit.Module( Module ) import GHC.Core.Coercion( Coercion ) import GHC.Core.Opt.Monad import qualified GHC.Core.Subst as Core @@ -31,11 +31,11 @@ import GHC.Types.Var.Set import GHC.Types.Var.Env import GHC.Core import GHC.Core.Rules -import GHC.Core.SimpleOpt ( collectBindersPushingCo ) import GHC.Core.Utils ( exprIsTrivial, getIdFromTrivialExpr_maybe , mkCast, exprType ) import GHC.Core.FVs -import GHC.Core.Opt.Arity ( etaExpandToJoinPointRule ) +import GHC.Core.Opt.Arity ( collectBindersPushingCo + , etaExpandToJoinPointRule ) import GHC.Types.Unique.Supply import GHC.Types.Name import GHC.Types.Id.Make ( voidArgId, voidPrimId ) @@ -51,12 +51,9 @@ import GHC.Utils.Misc import GHC.Utils.Outputable import GHC.Utils.Panic import GHC.Data.FastString -import GHC.Utils.Monad.State import GHC.Types.Unique.DFM import GHC.Core.TyCo.Rep (TyCoBinder (..)) -import Control.Monad - {- ************************************************************************ * * @@ -590,28 +587,29 @@ specProgram guts@(ModGuts { mg_module = this_mod , mg_binds = binds }) = do { dflags <- getDynFlags + -- We need to start with a Subst that knows all the things + -- that are in scope, so that the substitution engine doesn't + -- accidentally re-use a unique that's already in use + -- Easiest thing is to do it all at once, as if all the top-level + -- decls were mutually recursive + ; let top_env = SE { se_subst = Core.mkEmptySubst $ mkInScopeSet $ mkVarSet $ + bindersOfBinds binds + , se_interesting = emptyVarSet + , se_module = this_mod + , se_dflags = dflags } + + go [] = return ([], emptyUDs) + go (bind:binds) = do (binds', uds) <- go binds + (bind', uds') <- specBind top_env bind uds + return (bind' ++ binds', uds') + -- Specialise the bindings of this module - ; (binds', uds) <- runSpecM dflags this_mod (go binds) + ; (binds', uds) <- runSpecM (go binds) - ; (spec_rules, spec_binds) <- specImports dflags this_mod top_env - local_rules uds + ; (spec_rules, spec_binds) <- specImports top_env local_rules uds ; return (guts { mg_binds = spec_binds ++ binds' , mg_rules = spec_rules ++ local_rules }) } - where - -- We need to start with a Subst that knows all the things - -- that are in scope, so that the substitution engine doesn't - -- accidentally re-use a unique that's already in use - -- Easiest thing is to do it all at once, as if all the top-level - -- decls were mutually recursive - top_env = SE { se_subst = Core.mkEmptySubst $ mkInScopeSet $ mkVarSet $ - bindersOfBinds binds - , se_interesting = emptyVarSet } - - go [] = return ([], emptyUDs) - go (bind:binds) = do (binds', uds) <- go binds - (bind', uds') <- specBind top_env bind uds - return (bind' ++ binds', uds') {- Note [Wrap bindings returned by specImports] @@ -641,13 +639,13 @@ See #10491 * * ********************************************************************* -} -specImports :: DynFlags -> Module -> SpecEnv +specImports :: SpecEnv -> [CoreRule] -> UsageDetails -> CoreM ([CoreRule], [CoreBind]) -specImports dflags this_mod top_env local_rules +specImports top_env local_rules (MkUD { ud_binds = dict_binds, ud_calls = calls }) - | not $ gopt Opt_CrossModuleSpecialise dflags + | not $ gopt Opt_CrossModuleSpecialise (se_dflags top_env) -- See Note [Disabling cross-module specialisation] = return ([], wrapDictBinds dict_binds []) @@ -655,8 +653,7 @@ specImports dflags this_mod top_env local_rules = do { hpt_rules <- getRuleBase ; let rule_base = extendRuleBaseList hpt_rules local_rules - ; (spec_rules, spec_binds) <- spec_imports dflags this_mod top_env - [] rule_base + ; (spec_rules, spec_binds) <- spec_imports top_env [] rule_base dict_binds calls -- Don't forget to wrap the specialized bindings with @@ -672,9 +669,7 @@ specImports dflags this_mod top_env local_rules } -- | Specialise a set of calls to imported bindings -spec_imports :: DynFlags - -> Module - -> SpecEnv -- Passed in so that all top-level Ids are in scope +spec_imports :: SpecEnv -- Passed in so that all top-level Ids are in scope -> [Id] -- Stack of imported functions being specialised -- See Note [specImport call stack] -> RuleBase -- Rules from this module and the home package @@ -684,8 +679,7 @@ spec_imports :: DynFlags -> CallDetails -- Calls for imported things -> CoreM ( [CoreRule] -- New rules , [CoreBind] ) -- Specialised bindings -spec_imports dflags this_mod top_env - callers rule_base dict_binds calls +spec_imports top_env callers rule_base dict_binds calls = do { let import_calls = dVarEnvElts calls -- ; debugTraceMsg (text "specImports {" <+> -- vcat [ text "calls:" <+> ppr import_calls @@ -699,16 +693,13 @@ spec_imports dflags this_mod top_env go _ [] = return ([], []) go rb (cis : other_calls) = do { -- debugTraceMsg (text "specImport {" <+> ppr cis) - ; (rules1, spec_binds1) <- spec_import dflags this_mod top_env - callers rb dict_binds cis + ; (rules1, spec_binds1) <- spec_import top_env callers rb dict_binds cis -- ; debugTraceMsg (text "specImport }" <+> ppr cis) ; (rules2, spec_binds2) <- go (extendRuleBaseList rb rules1) other_calls ; return (rules1 ++ rules2, spec_binds1 ++ spec_binds2) } -spec_import :: DynFlags - -> Module - -> SpecEnv -- Passed in so that all top-level Ids are in scope +spec_import :: SpecEnv -- Passed in so that all top-level Ids are in scope -> [Id] -- Stack of imported functions being specialised -- See Note [specImport call stack] -> RuleBase -- Rules from this module @@ -717,8 +708,7 @@ spec_import :: DynFlags -> CallInfoSet -- Imported function and calls for it -> CoreM ( [CoreRule] -- New rules , [CoreBind] ) -- Specialised bindings -spec_import dflags this_mod top_env callers - rb dict_binds cis@(CIS fn _) +spec_import top_env callers rb dict_binds cis@(CIS fn _) | isIn "specImport" fn callers = return ([], []) -- No warning. This actually happens all the time -- when specialising a recursive function, because @@ -729,8 +719,7 @@ spec_import dflags this_mod top_env callers = do { -- debugTraceMsg (text "specImport:no valid calls") ; return ([], []) } - | wantSpecImport dflags unfolding - , Just rhs <- maybeUnfoldingTemplate unfolding + | Just rhs <- maybeUnfoldingTemplate unfolding = do { -- Get rules from the external package state -- We keep doing this in case we "page-fault in" -- more rules as we go along @@ -742,8 +731,8 @@ spec_import dflags this_mod top_env callers ; (rules1, spec_pairs, MkUD { ud_binds = dict_binds1, ud_calls = new_calls }) <- do { -- debugTraceMsg (text "specImport1" <+> vcat [ppr fn, ppr good_calls, ppr rhs]) - ; runSpecM dflags this_mod $ - specCalls (Just this_mod) top_env rules_for_fn good_calls fn rhs } + ; runSpecM $ + specCalls True top_env rules_for_fn good_calls fn rhs } ; let spec_binds1 = [NonRec b r | (b,r) <- spec_pairs] -- After the rules kick in we may get recursion, but -- we rely on a global GlomBinds to sort that out later @@ -751,7 +740,7 @@ spec_import dflags this_mod top_env callers -- Now specialise any cascaded calls -- ; debugTraceMsg (text "specImport 2" <+> (ppr fn $$ ppr rules1 $$ ppr spec_binds1)) - ; (rules2, spec_binds2) <- spec_imports dflags this_mod top_env + ; (rules2, spec_binds2) <- spec_imports top_env (fn:callers) (extendRuleBaseList rb rules1) (dict_binds `unionBags` dict_binds1) @@ -767,6 +756,7 @@ spec_import dflags this_mod top_env callers ; return ([], [])} where + dflags = se_dflags top_env unfolding = realIdUnfolding fn -- We want to see the unfolding even for loop breakers good_calls = filterCalls cis dict_binds -- SUPER IMPORTANT! Drop calls that (directly or indirectly) refer to fn @@ -796,22 +786,6 @@ tryWarnMissingSpecs dflags callers fn calls_for_fn , whenPprDebug (text "calls:" <+> vcat (map (pprCallInfo fn) calls_for_fn)) , text "Probable fix: add INLINABLE pragma on" <+> quotes (ppr fn) ]) -wantSpecImport :: DynFlags -> Unfolding -> Bool --- See Note [Specialise imported INLINABLE things] -wantSpecImport dflags unf - = case unf of - NoUnfolding -> False - BootUnfolding -> False - OtherCon {} -> False - DFunUnfolding {} -> True - CoreUnfolding { uf_src = src, uf_guidance = _guidance } - | gopt Opt_SpecialiseAggressively dflags -> True - | isStableSource src -> True - -- Specialise even INLINE things; it hasn't inlined yet, - -- so perhaps it never will. Moreover it may have calls - -- inside it that we want to specialise - | otherwise -> False -- Stable, not INLINE, hence INLINABLE - {- Note [Avoiding loops in specImports] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We must take great care when specialising instance declarations @@ -1001,6 +975,9 @@ data SpecEnv -- Dict Ids that we know something about -- and hence may be worth specialising against -- See Note [Interesting dictionary arguments] + + , se_module :: Module + , se_dflags :: DynFlags } instance Outputable SpecEnv where @@ -1308,7 +1285,7 @@ specDefn :: SpecEnv specDefn env body_uds fn rhs = do { let (body_uds_without_me, calls_for_me) = callsForMe fn body_uds rules_for_me = idCoreRules fn - ; (rules, spec_defns, spec_uds) <- specCalls Nothing env rules_for_me + ; (rules, spec_defns, spec_uds) <- specCalls False env rules_for_me calls_for_me fn rhs ; return ( fn `addIdSpecialisations` rules , spec_defns @@ -1321,8 +1298,8 @@ specDefn env body_uds fn rhs -- body_uds_without_me --------------------------- -specCalls :: Maybe Module -- Just this_mod => specialising imported fn - -- Nothing => specialising local fn +specCalls :: Bool -- True => specialising imported fn + -- False => specialising local fn -> SpecEnv -> [CoreRule] -- Existing RULES for the fn -> [CallInfo] @@ -1337,7 +1314,7 @@ type SpecInfo = ( [CoreRule] -- Specialisation rules , [(Id,CoreExpr)] -- Specialised definition , UsageDetails ) -- Usage details from specialised RHSs -specCalls mb_mod env existing_rules calls_for_me fn rhs +specCalls spec_imp env existing_rules calls_for_me fn rhs -- The first case is the interesting one | notNull calls_for_me -- And there are some calls to specialise && not (isNeverActive (idInlineActivation fn)) @@ -1368,7 +1345,9 @@ specCalls mb_mod env existing_rules calls_for_me fn rhs inl_act = inlinePragmaActivation inl_prag is_local = isLocalId fn is_dfun = isDFunId fn - + dflags = se_dflags env + ropts = initRuleOpts dflags + this_mod = se_module env -- Figure out whether the function has an INLINE pragma -- See Note [Inline specialisations] @@ -1410,8 +1389,6 @@ specCalls mb_mod env existing_rules calls_for_me fn rhs -- , ppr dx_binds ]) $ -- return () - ; dflags <- getDynFlags - ; let ropts = initRuleOpts dflags ; if not useful -- No useful specialisation || already_covered ropts rules_acc rule_lhs_args then return spec_acc @@ -1439,17 +1416,15 @@ specCalls mb_mod env existing_rules calls_for_me fn rhs = Nothing ; spec_fn <- newSpecIdSM fn spec_fn_ty spec_join_arity - ; this_mod <- getModule ; let -- The rule to put in the function's specialisation is: -- forall x @b d1' d2'. -- f x @T1 @b @T2 d1' d2' = f1 x @b -- See Note [Specialising Calls] - herald = case mb_mod of - Nothing -- Specialising local fn - -> text "SPEC" - Just this_mod -- Specialising imported fn - -> text "SPEC/" <> ppr this_mod + herald | spec_imp = -- Specialising imported fn + text "SPEC/" <> ppr this_mod + | otherwise = -- Specialising local fn + text "SPEC" rule_name = mkFastString $ showSDoc dflags $ herald <+> ftext (occNameFS (getOccName fn)) @@ -2476,15 +2451,15 @@ mkCallUDs env f args res = mkCallUDs' env f args mkCallUDs' env f args - | not (want_calls_for f) -- Imported from elsewhere - || null ci_key -- No useful specialisation - -- See also Note [Specialisations already covered] + | wantCallsFor env f -- We want it, and... + , not (null ci_key) -- this call site has a useful specialisation + = -- pprTrace "mkCallUDs: keeping" _trace_doc + singleCall f ci_key + + | otherwise -- See also Note [Specialisations already covered] = -- pprTrace "mkCallUDs: discarding" _trace_doc emptyUDs - | otherwise - = -- pprTrace "mkCallUDs: keeping" _trace_doc - singleCall f ci_key where _trace_doc = vcat [ppr f, ppr args, ppr ci_key] pis = fst $ splitPiTys $ idType f @@ -2518,13 +2493,6 @@ mkCallUDs' env f args mk_spec_arg _ (Anon VisArg _) = UnspecArg - want_calls_for f = isLocalId f || isJust (maybeUnfoldingTemplate (realIdUnfolding f)) - -- For imported things, we gather call instances if - -- there is an unfolding that we could in principle specialise - -- We might still decide not to use it (consulting dflags) - -- in specImports - -- Use 'realIdUnfolding' to ignore the loop-breaker flag! - type_determines_value pred -- See Note [Type determines value] = case classifyPredType pred of ClassPred cls _ -> not (isIPClass cls) -- Superclasses can't be IPs @@ -2533,7 +2501,68 @@ mkCallUDs' env f args -- Constraint-ranged family; #7785 ForAllPred {} -> True -{- +wantCallsFor :: SpecEnv -> Id -> Bool +wantCallsFor env f + | isLocalId f -- Local function; don't look at the unfolding, because + = True -- unfoldings for local functions are discarded by cloneBind + -- ToDo: we could keep a candidate set of let-binders to + -- reduce the size of the UsageDetails + + | otherwise -- Imported function + = case unf of + NoUnfolding -> False + BootUnfolding -> False + OtherCon {} -> False + CoreUnfolding { uf_src = src } + | isStableSource src -> True -- INLINEABLE/INLINE + -- See Note [Specialise imported INLINABLE things] + -- Specialise even INLINE things; it hasn't inlined yet, + -- so perhaps it never will. Moreover it may have calls + -- inside it that we want to specialise + | otherwise -> aggressive_only -- Imported, no INLINABLE + DFunUnfolding {} -> aggressive_only -- See Note [Do not specialise DFuns] + where + aggressive_only = gopt Opt_SpecialiseAggressively (se_dflags env) + unf = realIdUnfolding f + -- 'realIdUnfolding' to ignore the loop-breaker flag! + +{- Note [Do not specialise DFuns] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Ticket #18223 shows that specialising calls of DFuns is can cause a huge +and entirely unnecessary blowup in program size. Consider a call to + f @[[[[[[[[T]]]]]]]] d1 x +where df :: C a => C [a] + d1 :: C [[[[[[[[T]]]]]]]] = dfC[] @[[[[[[[T]]]]]]] d1 + d2 :: C [[[[[[[T]]]]]]] = dfC[] @[[[[[[T]]]]]] d3 + ... +Now we'll specialise f's RHS, which may give rise to calls to 'g', +also overloaded, which we will specialise, and so on. However, if +we specialise the calls to dfC[], we'll generate specialised copies of +all methods of C, at all types; and the same for C's superclasses. + +And many of these specialised functions will never be called. We are +going to call the specialised 'f', and the specialised 'g', but DFuns +group functions into a tuple, many of whose elements may never be used. + +With deeply-nested types this can lead to a simply overwhelming number +of specialisations: see #18223 for a simple example (from the wild). +I measured the number of specialisations for various numbers of calls +of `flip evalStateT ()`, and got this + + Size after one simplification + #calls #SPEC rules Terms Types + 5 56 3100 10600 + 9 108 13660 77206 + +The real tests case has 60+ calls, which blew GHC out of the water. + +Solution: don't specialise DFuns. The downside is that if we end +up with (h (dfun d)), /and/ we don't specialise 'h', then we won't +pass to 'h' a tuple of specialised functions. + +However, the flag -fspecialise-aggressively (experimental, off by default) +allows DFuns to specialise as well. + Note [Type determines value] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Only specialise on non-IP *class* params, because these are the ones @@ -2796,55 +2825,12 @@ deleteCallsFor bs calls = delDVarEnvList calls bs ************************************************************************ -} -newtype SpecM a = SpecM (State SpecState a) deriving (Functor) - -data SpecState = SpecState { - spec_uniq_supply :: UniqSupply, - spec_module :: Module, - spec_dflags :: DynFlags - } - -instance Applicative SpecM where - pure x = SpecM $ return x - (<*>) = ap - -instance Monad SpecM where - SpecM x >>= f = SpecM $ do y <- x - case f y of - SpecM z -> - z - -instance MonadFail SpecM where - fail str = SpecM $ error str - -instance MonadUnique SpecM where - getUniqueSupplyM - = SpecM $ do st <- get - let (us1, us2) = splitUniqSupply $ spec_uniq_supply st - put $ st { spec_uniq_supply = us2 } - return us1 - - getUniqueM - = SpecM $ do st <- get - let (u,us') = takeUniqFromSupply $ spec_uniq_supply st - put $ st { spec_uniq_supply = us' } - return u - -instance HasDynFlags SpecM where - getDynFlags = SpecM $ liftM spec_dflags get - -instance HasModule SpecM where - getModule = SpecM $ liftM spec_module get - -runSpecM :: DynFlags -> Module -> SpecM a -> CoreM a -runSpecM dflags this_mod (SpecM spec) - = do us <- getUniqueSupplyM - let initialState = SpecState { - spec_uniq_supply = us, - spec_module = this_mod, - spec_dflags = dflags - } - return $ evalState spec initialState +type SpecM a = UniqSM a + +runSpecM :: SpecM a -> CoreM a +runSpecM thing_inside + = do { us <- getUniqueSupplyM + ; return (initUs_ us thing_inside) } mapAndCombineSM :: (a -> SpecM (b, UsageDetails)) -> [a] -> SpecM ([b], UsageDetails) mapAndCombineSM _ [] = return ([], emptyUDs) ===================================== compiler/GHC/Core/Ppr.hs ===================================== @@ -161,15 +161,18 @@ pprOptCo co = sdocOption sdocSuppressCoercions $ \case True -> angleBrackets (text "Co:" <> int (coercionSize co)) False -> parens $ sep [ppr co, dcolon <+> ppr (coercionType co)] +ppr_id_occ :: (SDoc -> SDoc) -> Id -> SDoc +ppr_id_occ add_par id + | isJoinId id = add_par ((text "jump") <+> pp_id) + | otherwise = pp_id + where + pp_id = pprPrefixOcc id + ppr_expr :: OutputableBndr b => (SDoc -> SDoc) -> Expr b -> SDoc -- The function adds parens in context that need -- an atomic value (e.g. function args) -ppr_expr add_par (Var name) - | isJoinId name = add_par ((text "jump") <+> pp_name) - | otherwise = pp_name - where - pp_name = pprPrefixOcc name +ppr_expr add_par (Var id) = ppr_id_occ add_par id ppr_expr add_par (Type ty) = add_par (text "TYPE:" <+> ppr ty) -- Weird ppr_expr add_par (Coercion co) = add_par (text "CO:" <+> ppr co) ppr_expr add_par (Lit lit) = pprLiteral add_par lit @@ -212,8 +215,7 @@ ppr_expr add_par expr@(App {}) _ -> parens (hang fun_doc 2 pp_args) where - fun_doc | isJoinId f = text "jump" <+> ppr f - | otherwise = ppr f + fun_doc = ppr_id_occ noParens f _ -> parens (hang (pprParendExpr fun) 2 pp_args) } ===================================== compiler/GHC/Core/SimpleOpt.hs ===================================== @@ -16,17 +16,14 @@ module GHC.Core.SimpleOpt ( -- ** Predicates on expressions exprIsConApp_maybe, exprIsLiteral_maybe, exprIsLambda_maybe, - -- ** Coercions and casts - pushCoArg, pushCoValArg, pushCoTyArg, collectBindersPushingCo ) where #include "HsVersions.h" import GHC.Prelude -import GHC.Core.Opt.Arity( etaExpandToJoinPoint ) - import GHC.Core +import GHC.Core.Opt.Arity import GHC.Core.Subst import GHC.Core.Utils import GHC.Core.FVs @@ -46,18 +43,14 @@ import GHC.Core.Coercion.Opt ( optCoercion ) import GHC.Core.Type hiding ( substTy, extendTvSubst, extendCvSubst, extendTvSubstList , isInScope, substTyVarBndr, cloneTyVarBndr ) import GHC.Core.Coercion hiding ( substCo, substCoVarBndr ) -import GHC.Core.TyCon ( tyConArity ) -import GHC.Core.Multiplicity import GHC.Builtin.Types import GHC.Builtin.Names import GHC.Types.Basic import GHC.Unit.Module ( Module ) import GHC.Utils.Error import GHC.Driver.Session -import GHC.Driver.Ppr import GHC.Utils.Outputable import GHC.Utils.Panic -import GHC.Data.Pair import GHC.Utils.Misc import GHC.Data.Maybe ( orElse ) import GHC.Data.FastString @@ -756,6 +749,28 @@ a good cause. And it won't hurt other RULES and such that it comes across. ************************************************************************ -} +{- Note [Strictness and join points] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Suppose we have + + let f = \x. if x>200 then e1 else e1 + +and we know that f is strict in x. Then if we subsequently +discover that f is an arity-2 join point, we'll eta-expand it to + + let f = \x y. if x>200 then e1 else e1 + +and now it's only strict if applied to two arguments. So we should +adjust the strictness info. + +A more common case is when + + f = \x. error ".." + +and again its arity increases (#15517) +-} + + -- | Returns Just (bndr,rhs) if the binding is a join point: -- If it's a JoinId, just return it -- If it's not yet a JoinId but is always tail-called, @@ -789,27 +804,6 @@ joinPointBindings_maybe bndrs = mapM (uncurry joinPointBinding_maybe) bndrs -{- Note [Strictness and join points] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Suppose we have - - let f = \x. if x>200 then e1 else e1 - -and we know that f is strict in x. Then if we subsequently -discover that f is an arity-2 join point, we'll eta-expand it to - - let f = \x y. if x>200 then e1 else e1 - -and now it's only strict if applied to two arguments. So we should -adjust the strictness info. - -A more common case is when - - f = \x. error ".." - -and again its arity increases (#15517) --} - {- ********************************************************************* * * exprIsConApp_maybe @@ -1324,275 +1318,3 @@ exprIsLambda_maybe _ _e Nothing -{- ********************************************************************* -* * - The "push rules" -* * -************************************************************************ - -Here we implement the "push rules" from FC papers: - -* The push-argument rules, where we can move a coercion past an argument. - We have - (fun |> co) arg - and we want to transform it to - (fun arg') |> co' - for some suitable co' and transformed arg'. - -* The PushK rule for data constructors. We have - (K e1 .. en) |> co - and we want to transform to - (K e1' .. en') - by pushing the coercion into the arguments --} - -pushCoArgs :: CoercionR -> [CoreArg] -> Maybe ([CoreArg], MCoercion) -pushCoArgs co [] = return ([], MCo co) -pushCoArgs co (arg:args) = do { (arg', m_co1) <- pushCoArg co arg - ; case m_co1 of - MCo co1 -> do { (args', m_co2) <- pushCoArgs co1 args - ; return (arg':args', m_co2) } - MRefl -> return (arg':args, MRefl) } - -pushCoArg :: CoercionR -> CoreArg -> Maybe (CoreArg, MCoercion) --- We have (fun |> co) arg, and we want to transform it to --- (fun arg) |> co --- This may fail, e.g. if (fun :: N) where N is a newtype --- C.f. simplCast in GHC.Core.Opt.Simplify --- 'co' is always Representational --- If the returned coercion is Nothing, then it would have been reflexive -pushCoArg co (Type ty) = do { (ty', m_co') <- pushCoTyArg co ty - ; return (Type ty', m_co') } -pushCoArg co val_arg = do { (arg_co, m_co') <- pushCoValArg co - ; return (val_arg `mkCast` arg_co, m_co') } - -pushCoTyArg :: CoercionR -> Type -> Maybe (Type, MCoercionR) --- We have (fun |> co) @ty --- Push the coercion through to return --- (fun @ty') |> co' --- 'co' is always Representational --- If the returned coercion is Nothing, then it would have been reflexive; --- it's faster not to compute it, though. -pushCoTyArg co ty - -- The following is inefficient - don't do `eqType` here, the coercion - -- optimizer will take care of it. See #14737. - -- -- | tyL `eqType` tyR - -- -- = Just (ty, Nothing) - - | isReflCo co - = Just (ty, MRefl) - - | isForAllTy_ty tyL - = ASSERT2( isForAllTy_ty tyR, ppr co $$ ppr ty ) - Just (ty `mkCastTy` co1, MCo co2) - - | otherwise - = Nothing - where - Pair tyL tyR = coercionKind co - -- co :: tyL ~ tyR - -- tyL = forall (a1 :: k1). ty1 - -- tyR = forall (a2 :: k2). ty2 - - co1 = mkSymCo (mkNthCo Nominal 0 co) - -- co1 :: k2 ~N k1 - -- Note that NthCo can extract a Nominal equality between the - -- kinds of the types related by a coercion between forall-types. - -- See the NthCo case in GHC.Core.Lint. - - co2 = mkInstCo co (mkGReflLeftCo Nominal ty co1) - -- co2 :: ty1[ (ty|>co1)/a1 ] ~ ty2[ ty/a2 ] - -- Arg of mkInstCo is always nominal, hence mkNomReflCo - -pushCoValArg :: CoercionR -> Maybe (Coercion, MCoercion) --- We have (fun |> co) arg --- Push the coercion through to return --- (fun (arg |> co_arg)) |> co_res --- 'co' is always Representational --- If the second returned Coercion is actually Nothing, then no cast is necessary; --- the returned coercion would have been reflexive. -pushCoValArg co - -- The following is inefficient - don't do `eqType` here, the coercion - -- optimizer will take care of it. See #14737. - -- -- | tyL `eqType` tyR - -- -- = Just (mkRepReflCo arg, Nothing) - - | isReflCo co - = Just (mkRepReflCo arg, MRefl) - - | isFunTy tyL - , (co_mult, co1, co2) <- decomposeFunCo Representational co - , isReflexiveCo co_mult - -- We can't push the coercion in the case where co_mult isn't reflexivity: - -- it could be an unsafe axiom, and losing this information could yield - -- ill-typed terms. For instance (fun x ::(1) Int -> (fun _ -> () |> co) x) - -- with co :: (Int -> ()) ~ (Int #-> ()), would reduce to (fun x ::(1) Int - -- -> (fun _ ::(Many) Int -> ()) x) which is ill-typed - - -- If co :: (tyL1 -> tyL2) ~ (tyR1 -> tyR2) - -- then co1 :: tyL1 ~ tyR1 - -- co2 :: tyL2 ~ tyR2 - = ASSERT2( isFunTy tyR, ppr co $$ ppr arg ) - Just (mkSymCo co1, MCo co2) - - | otherwise - = Nothing - where - arg = funArgTy tyR - Pair tyL tyR = coercionKind co - -pushCoercionIntoLambda - :: InScopeSet -> Var -> CoreExpr -> CoercionR -> Maybe (Var, CoreExpr) --- This implements the Push rule from the paper on coercions --- (\x. e) |> co --- ===> --- (\x'. e |> co') -pushCoercionIntoLambda in_scope x e co - | ASSERT(not (isTyVar x) && not (isCoVar x)) True - , Pair s1s2 t1t2 <- coercionKind co - , Just (_, _s1,_s2) <- splitFunTy_maybe s1s2 - , Just (w1, t1,_t2) <- splitFunTy_maybe t1t2 - , (co_mult, co1, co2) <- decomposeFunCo Representational co - , isReflexiveCo co_mult - -- We can't push the coercion in the case where co_mult isn't - -- reflexivity. See pushCoValArg for more details. - = let - -- Should we optimize the coercions here? - -- Otherwise they might not match too well - x' = x `setIdType` t1 `setIdMult` w1 - in_scope' = in_scope `extendInScopeSet` x' - subst = extendIdSubst (mkEmptySubst in_scope') - x - (mkCast (Var x') co1) - in Just (x', substExpr subst e `mkCast` co2) - | otherwise - = pprTrace "exprIsLambda_maybe: Unexpected lambda in case" (ppr (Lam x e)) - Nothing - -pushCoDataCon :: DataCon -> [CoreExpr] -> Coercion - -> Maybe (DataCon - , [Type] -- Universal type args - , [CoreExpr]) -- All other args incl existentials --- Implement the KPush reduction rule as described in "Down with kinds" --- The transformation applies iff we have --- (C e1 ... en) `cast` co --- where co :: (T t1 .. tn) ~ to_ty --- The left-hand one must be a T, because exprIsConApp returned True --- but the right-hand one might not be. (Though it usually will.) -pushCoDataCon dc dc_args co - | isReflCo co || from_ty `eqType` to_ty -- try cheap test first - , let (univ_ty_args, rest_args) = splitAtList (dataConUnivTyVars dc) dc_args - = Just (dc, map exprToType univ_ty_args, rest_args) - - | Just (to_tc, to_tc_arg_tys) <- splitTyConApp_maybe to_ty - , to_tc == dataConTyCon dc - -- These two tests can fail; we might see - -- (C x y) `cast` (g :: T a ~ S [a]), - -- where S is a type function. In fact, exprIsConApp - -- will probably not be called in such circumstances, - -- but there's nothing wrong with it - - = let - tc_arity = tyConArity to_tc - dc_univ_tyvars = dataConUnivTyVars dc - dc_ex_tcvars = dataConExTyCoVars dc - arg_tys = dataConRepArgTys dc - - non_univ_args = dropList dc_univ_tyvars dc_args - (ex_args, val_args) = splitAtList dc_ex_tcvars non_univ_args - - -- Make the "Psi" from the paper - omegas = decomposeCo tc_arity co (tyConRolesRepresentational to_tc) - (psi_subst, to_ex_arg_tys) - = liftCoSubstWithEx Representational - dc_univ_tyvars - omegas - dc_ex_tcvars - (map exprToType ex_args) - - -- Cast the value arguments (which include dictionaries) - new_val_args = zipWith cast_arg (map scaledThing arg_tys) val_args - cast_arg arg_ty arg = mkCast arg (psi_subst arg_ty) - - to_ex_args = map Type to_ex_arg_tys - - dump_doc = vcat [ppr dc, ppr dc_univ_tyvars, ppr dc_ex_tcvars, - ppr arg_tys, ppr dc_args, - ppr ex_args, ppr val_args, ppr co, ppr from_ty, ppr to_ty, ppr to_tc - , ppr $ mkTyConApp to_tc (map exprToType $ takeList dc_univ_tyvars dc_args) ] - in - ASSERT2( eqType from_ty (mkTyConApp to_tc (map exprToType $ takeList dc_univ_tyvars dc_args)), dump_doc ) - ASSERT2( equalLength val_args arg_tys, dump_doc ) - Just (dc, to_tc_arg_tys, to_ex_args ++ new_val_args) - - | otherwise - = Nothing - - where - Pair from_ty to_ty = coercionKind co - -collectBindersPushingCo :: CoreExpr -> ([Var], CoreExpr) --- Collect lambda binders, pushing coercions inside if possible --- E.g. (\x.e) |> g g :: -> blah --- = (\x. e |> Nth 1 g) --- --- That is, --- --- collectBindersPushingCo ((\x.e) |> g) === ([x], e |> Nth 1 g) -collectBindersPushingCo e - = go [] e - where - -- Peel off lambdas until we hit a cast. - go :: [Var] -> CoreExpr -> ([Var], CoreExpr) - -- The accumulator is in reverse order - go bs (Lam b e) = go (b:bs) e - go bs (Cast e co) = go_c bs e co - go bs e = (reverse bs, e) - - -- We are in a cast; peel off casts until we hit a lambda. - go_c :: [Var] -> CoreExpr -> CoercionR -> ([Var], CoreExpr) - -- (go_c bs e c) is same as (go bs e (e |> c)) - go_c bs (Cast e co1) co2 = go_c bs e (co1 `mkTransCo` co2) - go_c bs (Lam b e) co = go_lam bs b e co - go_c bs e co = (reverse bs, mkCast e co) - - -- We are in a lambda under a cast; peel off lambdas and build a - -- new coercion for the body. - go_lam :: [Var] -> Var -> CoreExpr -> CoercionR -> ([Var], CoreExpr) - -- (go_lam bs b e c) is same as (go_c bs (\b.e) c) - go_lam bs b e co - | isTyVar b - , let Pair tyL tyR = coercionKind co - , ASSERT( isForAllTy_ty tyL ) - isForAllTy_ty tyR - , isReflCo (mkNthCo Nominal 0 co) -- See Note [collectBindersPushingCo] - = go_c (b:bs) e (mkInstCo co (mkNomReflCo (mkTyVarTy b))) - - | isCoVar b - , let Pair tyL tyR = coercionKind co - , ASSERT( isForAllTy_co tyL ) - isForAllTy_co tyR - , isReflCo (mkNthCo Nominal 0 co) -- See Note [collectBindersPushingCo] - , let cov = mkCoVarCo b - = go_c (b:bs) e (mkInstCo co (mkNomReflCo (mkCoercionTy cov))) - - | isId b - , let Pair tyL tyR = coercionKind co - , ASSERT( isFunTy tyL) isFunTy tyR - , (co_mult, co_arg, co_res) <- decomposeFunCo Representational co - , isReflCo co_mult -- See Note [collectBindersPushingCo] - , isReflCo co_arg -- See Note [collectBindersPushingCo] - = go_c (b:bs) e co_res - - | otherwise = (reverse bs, mkCast (Lam b e) co) - -{- - -Note [collectBindersPushingCo] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -We just look for coercions of form - # w -> blah -(and similarly for foralls) to keep this function simple. We could do -more elaborate stuff, but it'd involve substitution etc. - --} ===================================== compiler/GHC/Core/Subst.hs ===================================== @@ -343,6 +343,8 @@ instance Outputable Subst where substExprSC :: HasDebugCallStack => Subst -> CoreExpr -> CoreExpr -- Just like substExpr, but a no-op if the substitution is empty +-- Note that this does /not/ replace occurrences of free vars with +-- their canonical representatives in the in-scope set substExprSC subst orig_expr | isEmptySubst subst = orig_expr | otherwise = -- pprTrace "enter subst-expr" (doc $$ ppr orig_expr) $ @@ -628,6 +630,9 @@ substIdInfo subst new_id info ------------------ -- | Substitutes for the 'Id's within an unfolding +-- NB: substUnfolding /discards/ any unfolding without +-- without a Stable source. This is usually what we want, +-- but it may be a bit unexpected substUnfolding, substUnfoldingSC :: Subst -> Unfolding -> Unfolding -- Seq'ing on the returned Unfolding is enough to cause -- all the substitutions to happen completely View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/716b67d9b0ce485e2bfb6951b5f0586af642cad8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/716b67d9b0ce485e2bfb6951b5f0586af642cad8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 13:36:46 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 21 Aug 2020 09:36:46 -0400 Subject: [Git][ghc/ghc][master] 3 commits: Put CFG weights into their own module (#17957) Message-ID: <5f3fcdee51aa7_80b3f845293a31c878848d@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 293c7fba by Sylvain Henry at 2020-08-21T09:36:38-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - 50eb4460 by Sylvain Henry at 2020-08-21T09:36:38-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 659eb31b by Sylvain Henry at 2020-08-21T09:36:38-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 22 changed files: - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - + compiler/GHC/CmmToAsm/CFG/Weight.hs - compiler/GHC/CmmToAsm/Config.hs - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/CmmToAsm/X86/Ppr.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/CmmToLlvm/CodeGen.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Driver/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Unit/State.hs - compiler/GHC/Utils/Outputable.hs - compiler/ghc.cabal.in - testsuite/tests/hiefile/should_run/HieQueries.hs - testsuite/tests/parser/should_run/CountParserDeps.hs - testsuite/tests/regalloc/regalloc_unit_tests.hs Changes: ===================================== compiler/GHC/Cmm/Info/Build.hs ===================================== @@ -34,7 +34,7 @@ import GHC.Runtime.Heap.Layout import GHC.Types.Unique.Supply import GHC.Types.CostCentre import GHC.StgToCmm.Heap -import GHC.CmmToAsm.Monad +import GHC.CmmToAsm import Control.Monad import Data.Map.Strict (Map) @@ -933,7 +933,7 @@ oneSRT dflags staticFuns lbls caf_lbls isCAF cafs static_data = do topSRT <- get let - config = initConfig dflags + config = initNCGConfig dflags profile = targetProfile dflags platform = profilePlatform profile srtMap = moduleSRTMap topSRT ===================================== compiler/GHC/CmmToAsm.hs ===================================== @@ -72,6 +72,7 @@ module GHC.CmmToAsm -- cmmNativeGen emits , cmmNativeGen , NcgImpl(..) + , initNCGConfig ) where @@ -147,11 +148,11 @@ nativeCodeGen :: forall a . DynFlags -> Module -> ModLocation -> Handle -> UniqS -> Stream IO RawCmmGroup a -> IO a nativeCodeGen dflags this_mod modLoc h us cmms - = let config = initConfig dflags + = let config = initNCGConfig dflags platform = ncgPlatform config nCG' :: ( Outputable statics, Outputable jumpDest, Instruction instr) => NcgImpl statics instr jumpDest -> IO a - nCG' ncgImpl = nativeCodeGen' dflags this_mod modLoc ncgImpl h us cmms + nCG' ncgImpl = nativeCodeGen' dflags config this_mod modLoc ncgImpl h us cmms in case platformArch platform of ArchX86 -> nCG' (X86.ncgX86 config) ArchX86_64 -> nCG' (X86.ncgX86_64 config) @@ -215,39 +216,42 @@ See also Note [What is this unwinding business?] in "GHC.Cmm.DebugBlock". nativeCodeGen' :: (Outputable statics, Outputable jumpDest, Instruction instr) => DynFlags + -> NCGConfig -> Module -> ModLocation -> NcgImpl statics instr jumpDest -> Handle -> UniqSupply -> Stream IO RawCmmGroup a -> IO a -nativeCodeGen' dflags this_mod modLoc ncgImpl h us cmms +nativeCodeGen' dflags config this_mod modLoc ncgImpl h us cmms = do -- BufHandle is a performance hack. We could hide it inside -- Pretty if it weren't for the fact that we do lots of little -- printDocs here (in order to do codegen in constant space). bufh <- newBufHandle h let ngs0 = NGS [] [] [] [] [] [] emptyUFM mapEmpty - (ngs, us', a) <- cmmNativeGenStream dflags this_mod modLoc ncgImpl bufh us + (ngs, us', a) <- cmmNativeGenStream dflags config this_mod modLoc ncgImpl bufh us cmms ngs0 - _ <- finishNativeGen dflags modLoc bufh us' ngs + _ <- finishNativeGen dflags config modLoc bufh us' ngs return a finishNativeGen :: Instruction instr => DynFlags + -> NCGConfig -> ModLocation -> BufHandle -> UniqSupply -> NativeGenAcc statics instr -> IO UniqSupply -finishNativeGen dflags modLoc bufh@(BufHandle _ _ h) us ngs +finishNativeGen dflags config modLoc bufh@(BufHandle _ _ h) us ngs = withTimingSilent dflags (text "NCG") (`seq` ()) $ do -- Write debug data and finish - let emitDw = debugLevel dflags > 0 - us' <- if not emitDw then return us else do - (dwarf, us') <- dwarfGen dflags modLoc us (ngs_debug ngs) - emitNativeCode dflags bufh dwarf - return us' + us' <- if not (ncgDwarfEnabled config) + then return us + else do + (dwarf, us') <- dwarfGen config modLoc us (ngs_debug ngs) + emitNativeCode dflags config bufh dwarf + return us' bFlush bufh -- dump global NCG stats for graph coloring allocator @@ -262,7 +266,7 @@ finishNativeGen dflags modLoc bufh@(BufHandle _ _ h) us ngs dump_stats (Color.pprStats stats graphGlobal) - let platform = targetPlatform dflags + let platform = ncgPlatform config dumpIfSet_dyn dflags Opt_D_dump_asm_conflicts "Register conflict graph" FormatText @@ -280,7 +284,7 @@ finishNativeGen dflags modLoc bufh@(BufHandle _ _ h) us ngs dump_stats (Linear.pprStats (concat (ngs_natives ngs)) linearStats) -- write out the imports - let ctx = initSDocContext dflags (mkCodeStyle AsmStyle) + let ctx = ncgAsmContext config printSDocLn ctx Pretty.LeftMode h $ makeImportsDoc dflags (concat (ngs_imports ngs)) return us' @@ -291,6 +295,7 @@ finishNativeGen dflags modLoc bufh@(BufHandle _ _ h) us ngs cmmNativeGenStream :: (Outputable statics, Outputable jumpDest, Instruction instr) => DynFlags + -> NCGConfig -> Module -> ModLocation -> NcgImpl statics instr jumpDest -> BufHandle @@ -299,7 +304,7 @@ cmmNativeGenStream :: (Outputable statics, Outputable jumpDest, Instruction inst -> NativeGenAcc statics instr -> IO (NativeGenAcc statics instr, UniqSupply, a) -cmmNativeGenStream dflags this_mod modLoc ncgImpl h us cmm_stream ngs +cmmNativeGenStream dflags config this_mod modLoc ncgImpl h us cmm_stream ngs = do r <- Stream.runStream cmm_stream case r of Left a -> @@ -316,13 +321,12 @@ cmmNativeGenStream dflags this_mod modLoc ncgImpl h us cmm_stream ngs dflags ncglabel (\(a, b) -> a `seq` b `seq` ()) $ do -- Generate debug information - let debugFlag = debugLevel dflags > 0 - !ndbgs | debugFlag = cmmDebugGen modLoc cmms - | otherwise = [] + let !ndbgs | ncgDwarfEnabled config = cmmDebugGen modLoc cmms + | otherwise = [] dbgMap = debugToMap ndbgs -- Generate native code - (ngs',us') <- cmmNativeGens dflags this_mod modLoc ncgImpl h + (ngs',us') <- cmmNativeGens dflags config this_mod modLoc ncgImpl h dbgMap us cmms ngs 0 -- Link native code information into debug blocks @@ -336,7 +340,7 @@ cmmNativeGenStream dflags this_mod modLoc ncgImpl h us cmm_stream ngs let ngs'' = ngs' { ngs_debug = ngs_debug ngs' ++ ldbgs, ngs_labels = [] } return (us', ngs'') - cmmNativeGenStream dflags this_mod modLoc ncgImpl h us' + cmmNativeGenStream dflags config this_mod modLoc ncgImpl h us' cmm_stream' ngs'' where ncglabel = text "NCG" @@ -346,6 +350,7 @@ cmmNativeGenStream dflags this_mod modLoc ncgImpl h us cmm_stream ngs cmmNativeGens :: forall statics instr jumpDest. (Outputable statics, Outputable jumpDest, Instruction instr) => DynFlags + -> NCGConfig -> Module -> ModLocation -> NcgImpl statics instr jumpDest -> BufHandle @@ -356,7 +361,7 @@ cmmNativeGens :: forall statics instr jumpDest. -> Int -> IO (NativeGenAcc statics instr, UniqSupply) -cmmNativeGens dflags this_mod modLoc ncgImpl h dbgMap = go +cmmNativeGens dflags config this_mod modLoc ncgImpl h dbgMap = go where go :: UniqSupply -> [RawCmmDecl] -> NativeGenAcc statics instr -> Int @@ -381,14 +386,14 @@ cmmNativeGens dflags this_mod modLoc ncgImpl h dbgMap = go pprDecl (f,n) = text "\t.file " <> ppr n <+> pprFilePathString (unpackFS f) - emitNativeCode dflags h $ vcat $ + emitNativeCode dflags config h $ vcat $ map pprDecl newFileIds ++ map (pprNatCmmDecl ncgImpl) native -- force evaluation all this stuff to avoid space leaks {-# SCC "seqString" #-} evaluate $ seqList (showSDoc dflags $ vcat $ map ppr imports) () - let !labels' = if debugLevel dflags > 0 + let !labels' = if ncgDwarfEnabled config then cmmDebugLabels isMetaInstr native else [] !natives' = if dopt Opt_D_dump_asm_stats dflags then native : ngs_natives ngs else [] @@ -405,10 +410,10 @@ cmmNativeGens dflags this_mod modLoc ncgImpl h dbgMap = go go us' cmms ngs' (count + 1) -emitNativeCode :: DynFlags -> BufHandle -> SDoc -> IO () -emitNativeCode dflags h sdoc = do +emitNativeCode :: DynFlags -> NCGConfig -> BufHandle -> SDoc -> IO () +emitNativeCode dflags config h sdoc = do - let ctx = initSDocContext dflags (mkCodeStyle AsmStyle) + let ctx = ncgAsmContext config {-# SCC "pprNativeCode" #-} bufLeftRenderSDoc ctx h sdoc -- dump native code @@ -442,6 +447,7 @@ cmmNativeGen dflags this_mod modLoc ncgImpl us fileIds dbgMap cmm count = do let config = ncgConfig ncgImpl let platform = ncgPlatform config + let weights = ncgCfgWeights config let proc_name = case cmm of (CmmProc _ entry_label _ _) -> ppr entry_label @@ -462,12 +468,12 @@ cmmNativeGen dflags this_mod modLoc ncgImpl us fileIds dbgMap cmm count (pprCmmGroup [opt_cmm]) let cmmCfg = {-# SCC "getCFG" #-} - getCfgProc (cfgWeightInfo dflags) opt_cmm + getCfgProc weights opt_cmm -- generate native code from cmm let ((native, lastMinuteImports, fileIds', nativeCfgWeights), usGen) = {-# SCC "genMachCode" #-} - initUs us $ genMachCode dflags this_mod modLoc + initUs us $ genMachCode config this_mod modLoc (cmmTopCodeGen ncgImpl) fileIds dbgMap opt_cmm cmmCfg @@ -594,11 +600,11 @@ cmmNativeGen dflags this_mod modLoc ncgImpl us fileIds dbgMap cmm count cfgRegAllocUpdates = (concatMap Linear.ra_fixupList raStats) let cfgWithFixupBlks = - (\cfg -> addNodesBetween dflags cfg cfgRegAllocUpdates) <$> livenessCfg + (\cfg -> addNodesBetween weights cfg cfgRegAllocUpdates) <$> livenessCfg -- Insert stack update blocks let postRegCFG = - pure (foldl' (\m (from,to) -> addImmediateSuccessor dflags from to m )) + pure (foldl' (\m (from,to) -> addImmediateSuccessor weights from to m )) <*> cfgWithFixupBlks <*> pure stack_updt_blks @@ -620,7 +626,7 @@ cmmNativeGen dflags this_mod modLoc ncgImpl us fileIds dbgMap cmm count let optimizedCFG :: Maybe CFG optimizedCFG = - optimizeCFG (gopt Opt_CmmStaticPred dflags) (cfgWeightInfo dflags) cmm <$!> postShortCFG + optimizeCFG (gopt Opt_CmmStaticPred dflags) weights cmm <$!> postShortCFG maybeDumpCfg dflags optimizedCFG "CFG Weights - Final" proc_name @@ -642,7 +648,6 @@ cmmNativeGen dflags this_mod modLoc ncgImpl us fileIds dbgMap cmm count checkLayout shorted $ {-# SCC "sequenceBlocks" #-} map (BlockLayout.sequenceTop - dflags ncgImpl optimizedCFG) shorted @@ -768,7 +773,7 @@ makeImportsDoc dflags imports else Outputable.empty) where - config = initConfig dflags + config = initNCGConfig dflags platform = ncgPlatform config -- Generate "symbol stubs" for all external symbols that might @@ -790,10 +795,9 @@ makeImportsDoc dflags imports | otherwise = Outputable.empty - doPpr lbl = (lbl, renderWithStyle - (initSDocContext dflags astyle) + doPpr lbl = (lbl, renderWithContext + (ncgAsmContext config) (pprCLabel_NCG platform lbl)) - astyle = mkCodeStyle AsmStyle -- ----------------------------------------------------------------------------- -- Generate jump tables @@ -904,7 +908,7 @@ apply_mapping ncgImpl ufm (CmmProc info lbl live (ListGraph blocks)) -- Unique supply breaks abstraction. Is that bad? genMachCode - :: DynFlags + :: NCGConfig -> Module -> ModLocation -> (RawCmmDecl -> NatM [NatCmmDecl statics instr]) -> DwarfFiles @@ -918,9 +922,9 @@ genMachCode , CFG ) -genMachCode dflags this_mod modLoc cmmTopCodeGen fileIds dbgMap cmm_top cmm_cfg +genMachCode config this_mod modLoc cmmTopCodeGen fileIds dbgMap cmm_top cmm_cfg = do { initial_us <- getUniqueSupplyM - ; let initial_st = mkNatM_State initial_us 0 dflags this_mod + ; let initial_st = mkNatM_State initial_us 0 config this_mod modLoc fileIds dbgMap cmm_cfg (new_tops, final_st) = initNat initial_st (cmmTopCodeGen cmm_top) final_delta = natm_delta final_st @@ -1134,3 +1138,54 @@ cmmExprNative referenceKind expr = do other -> return other + +-- | Initialize the native code generator configuration from the DynFlags +initNCGConfig :: DynFlags -> NCGConfig +initNCGConfig dflags = NCGConfig + { ncgPlatform = targetPlatform dflags + , ncgAsmContext = initSDocContext dflags (mkCodeStyle AsmStyle) + , ncgProcAlignment = cmmProcAlignment dflags + , ncgExternalDynamicRefs = gopt Opt_ExternalDynamicRefs dflags + , ncgPIC = positionIndependent dflags + , ncgInlineThresholdMemcpy = fromIntegral $ maxInlineMemcpyInsns dflags + , ncgInlineThresholdMemset = fromIntegral $ maxInlineMemsetInsns dflags + , ncgSplitSections = gopt Opt_SplitSections dflags + , ncgRegsIterative = gopt Opt_RegsIterative dflags + , ncgAsmLinting = gopt Opt_DoAsmLinting dflags + , ncgCfgWeights = cfgWeights dflags + , ncgCfgBlockLayout = gopt Opt_CfgBlocklayout dflags + , ncgCfgWeightlessLayout = gopt Opt_WeightlessBlocklayout dflags + + -- With -O1 and greater, the cmmSink pass does constant-folding, so + -- we don't need to do it again in the native code generator. + , ncgDoConstantFolding = optLevel dflags < 1 + + , ncgDumpRegAllocStages = dopt Opt_D_dump_asm_regalloc_stages dflags + , ncgDumpAsmStats = dopt Opt_D_dump_asm_stats dflags + , ncgDumpAsmConflicts = dopt Opt_D_dump_asm_conflicts dflags + , ncgBmiVersion = case platformArch (targetPlatform dflags) of + ArchX86_64 -> bmiVersion dflags + ArchX86 -> bmiVersion dflags + _ -> Nothing + + -- We Assume SSE1 and SSE2 operations are available on both + -- x86 and x86_64. Historically we didn't default to SSE2 and + -- SSE1 on x86, which results in defacto nondeterminism for how + -- rounding behaves in the associated x87 floating point instructions + -- because variations in the spill/fpu stack placement of arguments for + -- operations would change the precision and final result of what + -- would otherwise be the same expressions with respect to single or + -- double precision IEEE floating point computations. + , ncgSseVersion = + let v | sseVersion dflags < Just SSE2 = Just SSE2 + | otherwise = sseVersion dflags + in case platformArch (targetPlatform dflags) of + ArchX86_64 -> v + ArchX86 -> v + _ -> Nothing + + , ncgDwarfEnabled = debugLevel dflags > 0 + , ncgDwarfUnwindings = debugLevel dflags >= 1 + , ncgDwarfStripBlockInfo = debugLevel dflags < 2 -- We strip out block information when running with -g0 or -g1. + } + ===================================== compiler/GHC/CmmToAsm/BlockLayout.hs ===================================== @@ -8,6 +8,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE MultiWayIf #-} module GHC.CmmToAsm.BlockLayout ( sequenceTop, backendMaintainsCfg) @@ -16,13 +17,13 @@ where #include "HsVersions.h" import GHC.Prelude -import GHC.Driver.Session (gopt, GeneralFlag(..), DynFlags, targetPlatform) import GHC.Driver.Ppr (pprTrace) import GHC.CmmToAsm.Instr import GHC.CmmToAsm.Monad import GHC.CmmToAsm.CFG import GHC.CmmToAsm.Types +import GHC.CmmToAsm.Config import GHC.Cmm.BlockId import GHC.Cmm @@ -817,30 +818,32 @@ dropJumps info ((BasicBlock lbl ins):todo) sequenceTop :: Instruction instr - => DynFlags -- Determine which layout algo to use - -> NcgImpl statics instr jumpDest + => NcgImpl statics instr jumpDest -> Maybe CFG -- ^ CFG if we have one. -> NatCmmDecl statics instr -- ^ Function to serialize -> NatCmmDecl statics instr -sequenceTop _ _ _ top@(CmmData _ _) = top -sequenceTop dflags ncgImpl edgeWeights - (CmmProc info lbl live (ListGraph blocks)) - | (gopt Opt_CfgBlocklayout dflags) && backendMaintainsCfg (targetPlatform dflags) - --Use chain based algorithm - , Just cfg <- edgeWeights - = CmmProc info lbl live ( ListGraph $ ncgMakeFarBranches ncgImpl info $ - {-# SCC layoutBlocks #-} - sequenceChain info cfg blocks ) - | otherwise - --Use old algorithm - = let cfg = if dontUseCfg then Nothing else edgeWeights - in CmmProc info lbl live ( ListGraph $ ncgMakeFarBranches ncgImpl info $ - {-# SCC layoutBlocks #-} - sequenceBlocks cfg info blocks) - where - dontUseCfg = gopt Opt_WeightlessBlocklayout dflags || - (not $ backendMaintainsCfg (targetPlatform dflags)) +sequenceTop _ _ top@(CmmData _ _) = top +sequenceTop ncgImpl edgeWeights (CmmProc info lbl live (ListGraph blocks)) + = let + config = ncgConfig ncgImpl + platform = ncgPlatform config + + in CmmProc info lbl live $ ListGraph $ ncgMakeFarBranches ncgImpl info $ + if -- Chain based algorithm + | ncgCfgBlockLayout config + , backendMaintainsCfg platform + , Just cfg <- edgeWeights + -> {-# SCC layoutBlocks #-} sequenceChain info cfg blocks + + -- Old algorithm without edge weights + | ncgCfgWeightlessLayout config + || not (backendMaintainsCfg platform) + -> {-# SCC layoutBlocks #-} sequenceBlocks Nothing info blocks + + -- Old algorithm with edge weights (if any) + | otherwise + -> {-# SCC layoutBlocks #-} sequenceBlocks edgeWeights info blocks -- The old algorithm: -- It is very simple (and stupid): We make a graph out of ===================================== compiler/GHC/CmmToAsm/CFG.hs ===================================== @@ -62,6 +62,7 @@ import GHC.Data.Maybe import GHC.Types.Unique import qualified GHC.CmmToAsm.CFG.Dominators as Dom +import GHC.CmmToAsm.CFG.Weight import Data.IntMap.Strict (IntMap) import Data.IntSet (IntSet) @@ -79,7 +80,6 @@ import GHC.Utils.Panic --import GHC.Data.OrdList --import GHC.Cmm.DebugBlock.Trace import GHC.Cmm.Ppr () -- For Outputable instances -import qualified GHC.Driver.Session as D import Data.List (sort, nub, partition) import Data.STRef.Strict @@ -329,12 +329,11 @@ shortcutWeightMap cuts cfg = -- \ \ -- -> C => -> C -- -addImmediateSuccessor :: D.DynFlags -> BlockId -> BlockId -> CFG -> CFG -addImmediateSuccessor dflags node follower cfg - = updateEdges . addWeightEdge node follower uncondWeight $ cfg +addImmediateSuccessor :: Weights -> BlockId -> BlockId -> CFG -> CFG +addImmediateSuccessor weights node follower cfg + = updateEdges . addWeightEdge node follower weight $ cfg where - uncondWeight = fromIntegral . D.uncondWeight . - D.cfgWeightInfo $ dflags + weight = fromIntegral (uncondWeight weights) targets = getSuccessorEdges cfg node successors = map fst targets :: [BlockId] updateEdges = addNewSuccs . remOldSuccs @@ -509,13 +508,12 @@ mapWeights f cfg = -- these cases. -- We assign the old edge info to the edge A -> B and assign B -> C the -- weight of an unconditional jump. -addNodesBetween :: D.DynFlags -> CFG -> [(BlockId,BlockId,BlockId)] -> CFG -addNodesBetween dflags m updates = +addNodesBetween :: Weights -> CFG -> [(BlockId,BlockId,BlockId)] -> CFG +addNodesBetween weights m updates = foldl' updateWeight m . weightUpdates $ updates where - weight = fromIntegral . D.uncondWeight . - D.cfgWeightInfo $ dflags + weight = fromIntegral (uncondWeight weights) -- We might add two blocks for different jumps along a single -- edge. So we end up with edges: A -> B -> C , A -> D -> C -- in this case after applying the first update the weight for A -> C @@ -585,24 +583,24 @@ addNodesBetween dflags m updates = -} -- | Generate weights for a Cmm proc based on some simple heuristics. -getCfgProc :: D.CfgWeights -> RawCmmDecl -> CFG +getCfgProc :: Weights -> RawCmmDecl -> CFG getCfgProc _ (CmmData {}) = mapEmpty getCfgProc weights (CmmProc _info _lab _live graph) = getCfg weights graph -getCfg :: D.CfgWeights -> CmmGraph -> CFG +getCfg :: Weights -> CmmGraph -> CFG getCfg weights graph = foldl' insertEdge edgelessCfg $ concatMap getBlockEdges blocks where - D.CFGWeights - { D.uncondWeight = uncondWeight - , D.condBranchWeight = condBranchWeight - , D.switchWeight = switchWeight - , D.callWeight = callWeight - , D.likelyCondWeight = likelyCondWeight - , D.unlikelyCondWeight = unlikelyCondWeight + Weights + { uncondWeight = uncondWeight + , condBranchWeight = condBranchWeight + , switchWeight = switchWeight + , callWeight = callWeight + , likelyCondWeight = likelyCondWeight + , unlikelyCondWeight = unlikelyCondWeight -- Last two are used in other places - --, D.infoTablePenalty = infoTablePenalty - --, D.backEdgeBonus = backEdgeBonus + --, infoTablePenalty = infoTablePenalty + --, backEdgeBonus = backEdgeBonus } = weights -- Explicitly add all nodes to the cfg to ensure they are part of the -- CFG. @@ -631,7 +629,7 @@ getCfg weights graph = mkEdge target weight = ((bid,target), mkEdgeInfo weight) branchInfo = foldRegsUsed - (panic "foldRegsDynFlags") + (panic "GHC.CmmToAsm.CFG.getCfg: foldRegsUsed") (\info r -> if r == SpLim || r == HpLim || r == BaseReg then HeapStackCheck else info) NoInfo cond @@ -671,7 +669,7 @@ findBackEdges root cfg = typedEdges = classifyEdges root getSuccs edges :: [((BlockId,BlockId),EdgeType)] -optimizeCFG :: Bool -> D.CfgWeights -> RawCmmDecl -> CFG -> CFG +optimizeCFG :: Bool -> Weights -> RawCmmDecl -> CFG -> CFG optimizeCFG _ _ (CmmData {}) cfg = cfg optimizeCFG doStaticPred weights proc@(CmmProc _info _lab _live graph) cfg = (if doStaticPred then staticPredCfg (g_entry graph) else id) $ @@ -682,7 +680,7 @@ optimizeCFG doStaticPred weights proc@(CmmProc _info _lab _live graph) cfg = -- performance. -- -- Most importantly we penalize jumps across info tables. -optHsPatterns :: D.CfgWeights -> RawCmmDecl -> CFG -> CFG +optHsPatterns :: Weights -> RawCmmDecl -> CFG -> CFG optHsPatterns _ (CmmData {}) cfg = cfg optHsPatterns weights (CmmProc info _lab _live graph) cfg = {-# SCC optHsPatterns #-} @@ -704,7 +702,7 @@ optHsPatterns weights (CmmProc info _lab _live graph) cfg = --Keep irrelevant edges irrelevant | weight <= 0 = 0 | otherwise - = weight + fromIntegral (D.backEdgeBonus weights) + = weight + fromIntegral (backEdgeBonus weights) in foldl' (\cfg edge -> updateEdgeWeight update edge cfg) cfg backedges @@ -716,7 +714,7 @@ optHsPatterns weights (CmmProc info _lab _live graph) cfg = fupdate :: BlockId -> BlockId -> EdgeWeight -> EdgeWeight fupdate _ to weight | mapMember to info - = weight - (fromIntegral $ D.infoTablePenalty weights) + = weight - (fromIntegral $ infoTablePenalty weights) | otherwise = weight -- | If a block has two successors, favour the one with fewer ===================================== compiler/GHC/CmmToAsm/CFG/Weight.hs ===================================== @@ -0,0 +1,78 @@ +module GHC.CmmToAsm.CFG.Weight + ( Weights (..) + , defaultWeights + , parseWeights + ) +where + +import GHC.Prelude +import GHC.Utils.Panic + +-- | Edge weights to use when generating a CFG from CMM +data Weights = Weights + { uncondWeight :: Int + , condBranchWeight :: Int + , switchWeight :: Int + , callWeight :: Int + , likelyCondWeight :: Int + , unlikelyCondWeight :: Int + , infoTablePenalty :: Int + , backEdgeBonus :: Int + } + +-- | Default edge weights +defaultWeights :: Weights +defaultWeights = Weights + { uncondWeight = 1000 + , condBranchWeight = 800 + , switchWeight = 1 + , callWeight = -10 + , likelyCondWeight = 900 + , unlikelyCondWeight = 300 + , infoTablePenalty = 300 + , backEdgeBonus = 400 + } + +parseWeights :: String -> Weights -> Weights +parseWeights s oldWeights = + foldl' (\cfg (n,v) -> update n v cfg) oldWeights assignments + where + assignments = map assignment $ settings s + update "uncondWeight" n w = + w {uncondWeight = n} + update "condBranchWeight" n w = + w {condBranchWeight = n} + update "switchWeight" n w = + w {switchWeight = n} + update "callWeight" n w = + w {callWeight = n} + update "likelyCondWeight" n w = + w {likelyCondWeight = n} + update "unlikelyCondWeight" n w = + w {unlikelyCondWeight = n} + update "infoTablePenalty" n w = + w {infoTablePenalty = n} + update "backEdgeBonus" n w = + w {backEdgeBonus = n} + update other _ _ + = panic $ other ++ + " is not a CFG weight parameter. " ++ + exampleString + settings s + | (s1,rest) <- break (== ',') s + , null rest + = [s1] + | (s1,rest) <- break (== ',') s + = s1 : settings (drop 1 rest) + + assignment as + | (name, _:val) <- break (== '=') as + = (name,read val) + | otherwise + = panic $ "Invalid CFG weight parameters." ++ exampleString + + exampleString = "Example parameters: uncondWeight=1000," ++ + "condBranchWeight=800,switchWeight=0,callWeight=300" ++ + ",likelyCondWeight=900,unlikelyCondWeight=300" ++ + ",infoTablePenalty=300,backEdgeBonus=400" + ===================================== compiler/GHC/CmmToAsm/Config.hs ===================================== @@ -10,12 +10,14 @@ where import GHC.Prelude import GHC.Platform import GHC.Cmm.Type (Width(..)) +import GHC.CmmToAsm.CFG.Weight +import GHC.Utils.Outputable -- | Native code generator configuration data NCGConfig = NCGConfig { ncgPlatform :: !Platform -- ^ Target platform + , ncgAsmContext :: !SDocContext -- ^ Context for ASM code generation , ncgProcAlignment :: !(Maybe Int) -- ^ Mandatory proc alignment - , ncgDebugLevel :: !Int -- ^ Debug level , ncgExternalDynamicRefs :: !Bool -- ^ Generate code to link against dynamic libraries , ncgPIC :: !Bool -- ^ Enable Position-Independent Code , ncgInlineThresholdMemcpy :: !Word -- ^ If inlining `memcpy` produces less than this threshold (in pseudo-instruction unit), do it @@ -29,6 +31,12 @@ data NCGConfig = NCGConfig , ncgDumpRegAllocStages :: !Bool , ncgDumpAsmStats :: !Bool , ncgDumpAsmConflicts :: !Bool + , ncgCfgWeights :: !Weights -- ^ CFG edge weights + , ncgCfgBlockLayout :: !Bool -- ^ Use CFG based block layout algorithm + , ncgCfgWeightlessLayout :: !Bool -- ^ Layout based on last instruction per block. + , ncgDwarfEnabled :: !Bool -- ^ Enable Dwarf generation + , ncgDwarfUnwindings :: !Bool -- ^ Enable unwindings + , ncgDwarfStripBlockInfo :: !Bool -- ^ Strip out block information from generated Dwarf } -- | Return Word size ===================================== compiler/GHC/CmmToAsm/Dwarf.hs ===================================== @@ -4,9 +4,6 @@ module GHC.CmmToAsm.Dwarf ( import GHC.Prelude -import GHC.Driver.Session -import GHC.Driver.Ppr - import GHC.Cmm.CLabel import GHC.Cmm.Expr ( GlobalReg(..) ) import GHC.Settings.Config ( cProjectName, cProjectVersion ) @@ -20,6 +17,7 @@ import GHC.Types.Unique.Supply import GHC.CmmToAsm.Dwarf.Constants import GHC.CmmToAsm.Dwarf.Types +import GHC.CmmToAsm.Config import Control.Arrow ( first ) import Control.Monad ( mfilter ) @@ -34,23 +32,22 @@ import qualified GHC.Cmm.Dataflow.Label as H import qualified GHC.Cmm.Dataflow.Collections as H -- | Generate DWARF/debug information -dwarfGen :: DynFlags -> ModLocation -> UniqSupply -> [DebugBlock] +dwarfGen :: NCGConfig -> ModLocation -> UniqSupply -> [DebugBlock] -> IO (SDoc, UniqSupply) -dwarfGen _ _ us [] = return (empty, us) -dwarfGen df modLoc us blocks = do - let platform = targetPlatform df +dwarfGen _ _ us [] = return (empty, us) +dwarfGen config modLoc us blocks = do + let platform = ncgPlatform config -- Convert debug data structures to DWARF info records - -- We strip out block information when running with -g0 or -g1. let procs = debugSplitProcs blocks stripBlocks dbg - | debugLevel df < 2 = dbg { dblBlocks = [] } - | otherwise = dbg + | ncgDwarfStripBlockInfo config = dbg { dblBlocks = [] } + | otherwise = dbg compPath <- getCurrentDirectory let lowLabel = dblCLabel $ head procs highLabel = mkAsmTempEndLabel $ dblCLabel $ last procs dwarfUnit = DwarfCompileUnit - { dwChildren = map (procToDwarf df) (map stripBlocks procs) + { dwChildren = map (procToDwarf config) (map stripBlocks procs) , dwName = fromMaybe "" (ml_hs_file modLoc) , dwCompDir = addTrailingPathSeparator compPath , dwProducer = cProjectName ++ " " ++ cProjectVersion @@ -91,8 +88,8 @@ dwarfGen df modLoc us blocks = do pprDwarfFrame platform (debugFrame framesU procs) -- .aranges section: Information about the bounds of compilation units - let aranges' | gopt Opt_SplitSections df = map mkDwarfARange procs - | otherwise = [DwarfARange lowLabel highLabel] + let aranges' | ncgSplitSections config = map mkDwarfARange procs + | otherwise = [DwarfARange lowLabel highLabel] let aranges = dwarfARangesSection platform $$ pprDwarfARanges platform aranges' unitU return (infoSct $$ abbrevSct $$ lineSct $$ frameSct $$ aranges, us'') @@ -177,12 +174,14 @@ parent, B. -} -- | Generate DWARF info for a procedure debug block -procToDwarf :: DynFlags -> DebugBlock -> DwarfInfo -procToDwarf df prc +procToDwarf :: NCGConfig -> DebugBlock -> DwarfInfo +procToDwarf config prc = DwarfSubprogram { dwChildren = map blockToDwarf (dblBlocks prc) , dwName = case dblSourceTick prc of Just s at SourceNote{} -> sourceName s - _otherwise -> showSDocDump df $ ppr $ dblLabel prc + _otherwise -> renderWithContext defaultSDocContext + $ withPprStyle defaultDumpStyle + $ ppr (dblLabel prc) , dwLabel = dblCLabel prc , dwParent = fmap mkAsmTempDieLabel $ mfilter goodParent @@ -192,9 +191,9 @@ procToDwarf df prc goodParent a | a == dblCLabel prc = False -- Omit parent if it would be self-referential goodParent a | not (externallyVisibleCLabel a) - , debugLevel df < 2 = False - -- We strip block information when running -g0 or -g1, don't - -- refer to blocks in that case. Fixes #14894. + , ncgDwarfStripBlockInfo config = False + -- If we strip block information, don't refer to blocks. + -- Fixes #14894. goodParent _ = True -- | Generate DWARF info for a block ===================================== compiler/GHC/CmmToAsm/Monad.hs ===================================== @@ -16,7 +16,6 @@ module GHC.CmmToAsm.Monad ( NatM, -- instance Monad initNat, - initConfig, addImportNat, addNodeBetweenNat, addImmediateSuccessorNat, @@ -34,7 +33,7 @@ module GHC.CmmToAsm.Monad ( getNewRegPairNat, getPicBaseMaybeNat, getPicBaseNat, - getDynFlags, + getCfgWeights, getModLoc, getFileId, getDebugBlock, @@ -64,7 +63,6 @@ import GHC.Data.FastString ( FastString ) import GHC.Types.Unique.FM import GHC.Types.Unique.Supply import GHC.Types.Unique ( Unique ) -import GHC.Driver.Session import GHC.Unit.Module import Control.Monad ( ap ) @@ -72,6 +70,7 @@ import Control.Monad ( ap ) import GHC.Utils.Outputable (SDoc, ppr) import GHC.Utils.Panic (pprPanic) import GHC.CmmToAsm.CFG +import GHC.CmmToAsm.CFG.Weight data NcgImpl statics instr jumpDest = NcgImpl { ncgConfig :: !NCGConfig, @@ -107,7 +106,6 @@ data NatM_State natm_delta :: Int, natm_imports :: [(CLabel)], natm_pic :: Maybe Reg, - natm_dflags :: DynFlags, natm_config :: NCGConfig, natm_this_module :: Module, natm_modloc :: ModLocation, @@ -127,17 +125,16 @@ newtype NatM result = NatM (NatM_State -> (result, NatM_State)) unNat :: NatM a -> NatM_State -> (a, NatM_State) unNat (NatM a) = a -mkNatM_State :: UniqSupply -> Int -> DynFlags -> Module -> ModLocation -> +mkNatM_State :: UniqSupply -> Int -> NCGConfig -> Module -> ModLocation -> DwarfFiles -> LabelMap DebugBlock -> CFG -> NatM_State -mkNatM_State us delta dflags this_mod +mkNatM_State us delta config this_mod = \loc dwf dbg cfg -> NatM_State { natm_us = us , natm_delta = delta , natm_imports = [] , natm_pic = Nothing - , natm_dflags = dflags - , natm_config = initConfig dflags + , natm_config = config , natm_this_module = this_mod , natm_modloc = loc , natm_fileid = dwf @@ -145,49 +142,6 @@ mkNatM_State us delta dflags this_mod , natm_cfg = cfg } --- | Initialize the native code generator configuration from the DynFlags -initConfig :: DynFlags -> NCGConfig -initConfig dflags = NCGConfig - { ncgPlatform = targetPlatform dflags - , ncgProcAlignment = cmmProcAlignment dflags - , ncgDebugLevel = debugLevel dflags - , ncgExternalDynamicRefs = gopt Opt_ExternalDynamicRefs dflags - , ncgPIC = positionIndependent dflags - , ncgInlineThresholdMemcpy = fromIntegral $ maxInlineMemcpyInsns dflags - , ncgInlineThresholdMemset = fromIntegral $ maxInlineMemsetInsns dflags - , ncgSplitSections = gopt Opt_SplitSections dflags - , ncgRegsIterative = gopt Opt_RegsIterative dflags - , ncgAsmLinting = gopt Opt_DoAsmLinting dflags - - -- With -O1 and greater, the cmmSink pass does constant-folding, so - -- we don't need to do it again in the native code generator. - , ncgDoConstantFolding = optLevel dflags < 1 - - , ncgDumpRegAllocStages = dopt Opt_D_dump_asm_regalloc_stages dflags - , ncgDumpAsmStats = dopt Opt_D_dump_asm_stats dflags - , ncgDumpAsmConflicts = dopt Opt_D_dump_asm_conflicts dflags - , ncgBmiVersion = case platformArch (targetPlatform dflags) of - ArchX86_64 -> bmiVersion dflags - ArchX86 -> bmiVersion dflags - _ -> Nothing - - -- We Assume SSE1 and SSE2 operations are available on both - -- x86 and x86_64. Historically we didn't default to SSE2 and - -- SSE1 on x86, which results in defacto nondeterminism for how - -- rounding behaves in the associated x87 floating point instructions - -- because variations in the spill/fpu stack placement of arguments for - -- operations would change the precision and final result of what - -- would otherwise be the same expressions with respect to single or - -- double precision IEEE floating point computations. - , ncgSseVersion = - let v | sseVersion dflags < Just SSE2 = Just SSE2 - | otherwise = sseVersion dflags - in case platformArch (targetPlatform dflags) of - ArchX86_64 -> v - ArchX86 -> v - _ -> Nothing - } - initNat :: NatM_State -> NatM a -> (a, NatM_State) initNat init_st m = case unNat m init_st of { (r,st) -> (r,st) } @@ -234,13 +188,12 @@ getUniqueNat = NatM $ \ st -> case takeUniqFromSupply $ natm_us st of (uniq, us') -> (uniq, st {natm_us = us'}) -instance HasDynFlags NatM where - getDynFlags = NatM $ \ st -> (natm_dflags st, st) - - getDeltaNat :: NatM Int getDeltaNat = NatM $ \ st -> (natm_delta st, st) +-- | Get CFG edge weights +getCfgWeights :: NatM Weights +getCfgWeights = NatM $ \ st -> (ncgCfgWeights (natm_config st), st) setDeltaNat :: Int -> NatM () setDeltaNat delta = NatM $ \ st -> ((), st {natm_delta = delta}) @@ -262,9 +215,8 @@ updateCfgNat f -- | Record that we added a block between `from` and `old`. addNodeBetweenNat :: BlockId -> BlockId -> BlockId -> NatM () addNodeBetweenNat from between to - = do df <- getDynFlags - let jmpWeight = fromIntegral . uncondWeight . - cfgWeightInfo $ df + = do weights <- getCfgWeights + let jmpWeight = fromIntegral (uncondWeight weights) updateCfgNat (updateCfg jmpWeight from between to) where -- When transforming A -> B to A -> A' -> B @@ -284,8 +236,8 @@ addNodeBetweenNat from between to -- block -> X to `succ` -> X addImmediateSuccessorNat :: BlockId -> BlockId -> NatM () addImmediateSuccessorNat block succ = do - dflags <- getDynFlags - updateCfgNat (addImmediateSuccessor dflags block succ) + weights <- getCfgWeights + updateCfgNat (addImmediateSuccessor weights block succ) getBlockIdNat :: NatM BlockId getBlockIdNat ===================================== compiler/GHC/CmmToAsm/PPC/Ppr.hs ===================================== @@ -64,7 +64,7 @@ pprNatCmmDecl config proc@(CmmProc top_info lbl _ (ListGraph blocks)) = _ -> pprLabel platform lbl) $$ -- blocks guaranteed not null, -- so label needed vcat (map (pprBasicBlock config top_info) blocks) $$ - (if ncgDebugLevel config > 0 + (if ncgDwarfEnabled config then ppr (mkAsmTempEndLabel lbl) <> char ':' else empty) $$ pprSizeDecl platform lbl @@ -131,7 +131,7 @@ pprBasicBlock config info_env (BasicBlock blockid instrs) = maybe_infotable $$ pprLabel platform asmLbl $$ vcat (map (pprInstr platform) instrs) $$ - (if ncgDebugLevel config > 0 + (if ncgDwarfEnabled config then ppr (mkAsmTempEndLabel asmLbl) <> char ':' else empty ) ===================================== compiler/GHC/CmmToAsm/X86/CodeGen.hs ===================================== @@ -57,6 +57,7 @@ import GHC.CmmToAsm.Monad , getDeltaNat, getBlockIdNat, getPicBaseNat, getNewRegPairNat , getPicBaseMaybeNat, getDebugBlock, getFileId , addImmediateSuccessorNat, updateCfgNat, getConfig, getPlatform + , getCfgWeights ) import GHC.CmmToAsm.CFG import GHC.CmmToAsm.Format @@ -228,7 +229,7 @@ basicBlockCodeGen block = do addSpUnwindings :: Instr -> NatM (OrdList Instr) addSpUnwindings instr@(DELTA d) = do config <- getConfig - if ncgDebugLevel config >= 1 + if ncgDwarfUnwindings config then do lbl <- mkAsmTempLabel <$> getUniqueM let unwind = M.singleton MachSp (Just $ UwReg MachSp $ negate d) return $ toOL [ instr, UNWIND lbl unwind ] @@ -2106,10 +2107,10 @@ genCCall is32Bit (PrimTarget (MO_Ctz width)) [dst] [src] bid -- bid -> lbl2 -- bid -> lbl1 -> lbl2 -- We also changes edges originating at bid to start at lbl2 instead. - dflags <- getDynFlags + weights <- getCfgWeights updateCfgNat (addWeightEdge bid lbl1 110 . addWeightEdge lbl1 lbl2 110 . - addImmediateSuccessor dflags bid lbl2) + addImmediateSuccessor weights bid lbl2) -- The following instruction sequence corresponds to the pseudo-code -- ===================================== compiler/GHC/CmmToAsm/X86/Ppr.hs ===================================== @@ -91,7 +91,7 @@ pprNatCmmDecl config proc@(CmmProc top_info lbl _ (ListGraph blocks)) = pprProcAlignment config $$ pprLabel platform lbl $$ -- blocks guaranteed not null, so label needed vcat (map (pprBasicBlock config top_info) blocks) $$ - (if ncgDebugLevel config > 0 + (if ncgDwarfEnabled config then ppr (mkAsmTempEndLabel lbl) <> char ':' else empty) $$ pprSizeDecl platform lbl @@ -125,7 +125,7 @@ pprBasicBlock config info_env (BasicBlock blockid instrs) = maybe_infotable $ pprLabel platform asmLbl $$ vcat (map (pprInstr platform) instrs) $$ - (if ncgDebugLevel config > 0 + (if ncgDwarfEnabled config then ppr (mkAsmTempEndLabel asmLbl) <> char ':' else empty ) @@ -140,7 +140,7 @@ pprBasicBlock config info_env (BasicBlock blockid instrs) vcat (map (pprData config) info) $$ pprLabel platform infoLbl $$ c $$ - (if ncgDebugLevel config > 0 + (if ncgDwarfEnabled config then ppr (mkAsmTempEndLabel infoLbl) <> char ':' else empty ) ===================================== compiler/GHC/CmmToLlvm/Base.hs ===================================== @@ -498,7 +498,7 @@ strCLabel_llvm lbl = do dflags <- getDynFlags platform <- getPlatform let sdoc = pprCLabel_LLVM platform lbl - str = Outp.renderWithStyle + str = Outp.renderWithContext (initSDocContext dflags (Outp.mkCodeStyle Outp.CStyle)) sdoc return (fsLit str) ===================================== compiler/GHC/CmmToLlvm/CodeGen.hs ===================================== @@ -1566,7 +1566,7 @@ genMachOp_slow opt op [x, y] = case op of -- Error. Continue anyway so we can debug the generated ll file. dflags <- getDynFlags let style = mkCodeStyle CStyle - toString doc = renderWithStyle (initSDocContext dflags style) doc + toString doc = renderWithContext (initSDocContext dflags style) doc cmmToStr = (lines . toString . PprCmm.pprExpr platform) statement $ Comment $ map fsLit $ cmmToStr x statement $ Comment $ map fsLit $ cmmToStr y ===================================== compiler/GHC/Driver/Backpack.hs ===================================== @@ -539,7 +539,7 @@ msgUnitId pk = do dflags <- getDynFlags level <- getBkpLevel liftIO . backpackProgressMsg level dflags - $ "Instantiating " ++ renderWithStyle + $ "Instantiating " ++ renderWithContext (initSDocContext dflags backpackStyle) (ppr pk) @@ -550,7 +550,7 @@ msgInclude (i,n) uid = do level <- getBkpLevel liftIO . backpackProgressMsg level dflags $ showModuleIndex (i, n) ++ "Including " ++ - renderWithStyle (initSDocContext dflags backpackStyle) + renderWithContext (initSDocContext dflags backpackStyle) (ppr uid) -- ---------------------------------------------------------------------------- ===================================== compiler/GHC/Driver/Ppr.hs ===================================== @@ -36,7 +36,7 @@ import Control.Monad.IO.Class -- | Show a SDoc as a String with the default user style showSDoc :: DynFlags -> SDoc -> String -showSDoc dflags sdoc = renderWithStyle (initSDocContext dflags defaultUserStyle) sdoc +showSDoc dflags sdoc = renderWithContext (initSDocContext dflags defaultUserStyle) sdoc showPpr :: Outputable a => DynFlags -> a -> String showPpr dflags thing = showSDoc dflags (ppr thing) @@ -46,13 +46,13 @@ showPprUnsafe a = showPpr unsafeGlobalDynFlags a -- | Allows caller to specify the PrintUnqualified to use showSDocForUser :: DynFlags -> PrintUnqualified -> SDoc -> String -showSDocForUser dflags unqual doc = renderWithStyle (initSDocContext dflags (mkUserStyle unqual AllTheWay)) doc +showSDocForUser dflags unqual doc = renderWithContext (initSDocContext dflags (mkUserStyle unqual AllTheWay)) doc showSDocDump :: DynFlags -> SDoc -> String -showSDocDump dflags d = renderWithStyle (initSDocContext dflags defaultDumpStyle) d +showSDocDump dflags d = renderWithContext (initSDocContext dflags defaultDumpStyle) d showSDocDebug :: DynFlags -> SDoc -> String -showSDocDebug dflags d = renderWithStyle ctx d +showSDocDebug dflags d = renderWithContext ctx d where ctx = (initSDocContext dflags defaultDumpStyle) { sdocPprDebug = True ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -226,9 +226,6 @@ module GHC.Driver.Session ( -- * SDoc initSDocContext, initDefaultSDocContext, - - -- * Make use of the Cmm CFG - CfgWeights(..) ) where #include "HsVersions.h" @@ -268,6 +265,7 @@ import GHC.Data.FastString import GHC.Utils.Fingerprint import GHC.Utils.Outputable import GHC.Settings +import GHC.CmmToAsm.CFG.Weight import {-# SOURCE #-} GHC.Utils.Error ( Severity(..), MsgDoc, mkLocMessageAnn @@ -777,78 +775,9 @@ data DynFlags = DynFlags { uniqueIncrement :: Int, -- | Temporary: CFG Edge weights for fast iterations - cfgWeightInfo :: CfgWeights + cfgWeights :: Weights } --- | Edge weights to use when generating a CFG from CMM -data CfgWeights - = CFGWeights - { uncondWeight :: Int - , condBranchWeight :: Int - , switchWeight :: Int - , callWeight :: Int - , likelyCondWeight :: Int - , unlikelyCondWeight :: Int - , infoTablePenalty :: Int - , backEdgeBonus :: Int - } - -defaultCfgWeights :: CfgWeights -defaultCfgWeights - = CFGWeights - { uncondWeight = 1000 - , condBranchWeight = 800 - , switchWeight = 1 - , callWeight = -10 - , likelyCondWeight = 900 - , unlikelyCondWeight = 300 - , infoTablePenalty = 300 - , backEdgeBonus = 400 - } - -parseCfgWeights :: String -> CfgWeights -> CfgWeights -parseCfgWeights s oldWeights = - foldl' (\cfg (n,v) -> update n v cfg) oldWeights assignments - where - assignments = map assignment $ settings s - update "uncondWeight" n w = - w {uncondWeight = n} - update "condBranchWeight" n w = - w {condBranchWeight = n} - update "switchWeight" n w = - w {switchWeight = n} - update "callWeight" n w = - w {callWeight = n} - update "likelyCondWeight" n w = - w {likelyCondWeight = n} - update "unlikelyCondWeight" n w = - w {unlikelyCondWeight = n} - update "infoTablePenalty" n w = - w {infoTablePenalty = n} - update "backEdgeBonus" n w = - w {backEdgeBonus = n} - update other _ _ - = panic $ other ++ - " is not a cfg weight parameter. " ++ - exampleString - settings s - | (s1,rest) <- break (== ',') s - , null rest - = [s1] - | (s1,rest) <- break (== ',') s - = s1 : settings (drop 1 rest) - - assignment as - | (name, _:val) <- break (== '=') as - = (name,read val) - | otherwise - = panic $ "Invalid cfg parameters." ++ exampleString - - exampleString = "Example parameters: uncondWeight=1000," ++ - "condBranchWeight=800,switchWeight=0,callWeight=300" ++ - ",likelyCondWeight=900,unlikelyCondWeight=300" ++ - ",infoTablePenalty=300,backEdgeBonus=400" - class HasDynFlags m where getDynFlags :: m DynFlags @@ -1430,7 +1359,7 @@ defaultDynFlags mySettings llvmConfig = reverseErrors = False, maxErrors = Nothing, - cfgWeightInfo = defaultCfgWeights + cfgWeights = defaultWeights } defaultWays :: Settings -> Ways @@ -2949,8 +2878,8 @@ dynamic_flags_deps = [ (intSuffix (\n d -> d { cmmProcAlignment = Just n })) , make_ord_flag defFlag "fblock-layout-weights" (HasArg (\s -> - upd (\d -> d { cfgWeightInfo = - parseCfgWeights s (cfgWeightInfo d)}))) + upd (\d -> d { cfgWeights = + parseWeights s (cfgWeights d)}))) , make_ord_flag defFlag "fhistory-size" (intSuffix (\n d -> d { historySize = n })) , make_ord_flag defFlag "funfolding-creation-threshold" ===================================== compiler/GHC/Unit/State.hs ===================================== @@ -980,7 +980,7 @@ packageFlagErr' :: SDocContext -> [(UnitInfo, UnusableUnitReason)] -> IO a packageFlagErr' ctx flag_doc reasons - = throwGhcExceptionIO (CmdLineError (renderWithStyle ctx $ err)) + = throwGhcExceptionIO (CmdLineError (renderWithContext ctx $ err)) where err = text "cannot satisfy " <> flag_doc <> (if null reasons then Outputable.empty else text ": ") $$ nest 4 (ppr_reasons $$ @@ -1712,7 +1712,7 @@ mkModuleNameProvidersMap ctx cfg pkg_map closure vis_map = rnBinding (orig, new) = (new, setOrigins origEntry fromFlag) where origEntry = case lookupUFM esmap orig of Just r -> r - Nothing -> throwGhcException (CmdLineError (renderWithStyle ctx + Nothing -> throwGhcException (CmdLineError (renderWithContext ctx (text "package flag: could not find module name" <+> ppr orig <+> text "in package" <+> ppr pk))) @@ -2058,7 +2058,7 @@ getPreloadUnitsAnd ctx unit_state home_unit ids0 = throwErr :: SDocContext -> MaybeErr MsgDoc a -> IO a throwErr ctx m = case m of - Failed e -> throwGhcExceptionIO (CmdLineError (renderWithStyle ctx e)) + Failed e -> throwGhcExceptionIO (CmdLineError (renderWithContext ctx e)) Succeeded r -> return r -- | Takes a list of UnitIds (and their "parent" dependency, used for error ===================================== compiler/GHC/Utils/Outputable.hs ===================================== @@ -47,7 +47,7 @@ module GHC.Utils.Outputable ( bufLeftRenderSDoc, pprCode, mkCodeStyle, showSDocOneLine, - renderWithStyle, + renderWithContext, pprInfixVar, pprPrefixVar, pprHsChar, pprHsString, pprHsBytes, @@ -71,7 +71,7 @@ module GHC.Utils.Outputable ( QualifyName(..), queryQual, sdocWithDynFlags, sdocOption, updSDocContext, - SDocContext (..), sdocWithContext, + SDocContext (..), sdocWithContext, defaultSDocContext, getPprStyle, withPprStyle, setStyleColoured, pprDeeper, pprDeeperList, pprSetDepth, codeStyle, userStyle, dumpStyle, asmStyle, @@ -302,7 +302,7 @@ code (either C or assembly), or generating interface files. -- | Represents a pretty-printable document. -- -- To display an 'SDoc', use 'printSDoc', 'printSDocLn', 'bufLeftRenderSDoc', --- or 'renderWithStyle'. Avoid calling 'runSDoc' directly as it breaks the +-- or 'renderWithContext'. Avoid calling 'runSDoc' directly as it breaks the -- abstraction layer. newtype SDoc = SDoc { runSDoc :: SDocContext -> Doc } @@ -354,6 +354,44 @@ instance IsString SDoc where instance Outputable SDoc where ppr = id +-- | Default pretty-printing options +defaultSDocContext :: SDocContext +defaultSDocContext = SDC + { sdocStyle = defaultDumpStyle + , sdocColScheme = Col.defaultScheme + , sdocLastColour = Col.colReset + , sdocShouldUseColor = False + , sdocDefaultDepth = 5 + , sdocLineLength = 100 + , sdocCanUseUnicode = False + , sdocHexWordLiterals = False + , sdocPprDebug = False + , sdocPrintUnicodeSyntax = False + , sdocPrintCaseAsLet = False + , sdocPrintTypecheckerElaboration = False + , sdocPrintAxiomIncomps = False + , sdocPrintExplicitKinds = False + , sdocPrintExplicitCoercions = False + , sdocPrintExplicitRuntimeReps = False + , sdocPrintExplicitForalls = False + , sdocPrintPotentialInstances = False + , sdocPrintEqualityRelations = False + , sdocSuppressTicks = False + , sdocSuppressTypeSignatures = False + , sdocSuppressTypeApplications = False + , sdocSuppressIdInfo = False + , sdocSuppressCoercions = False + , sdocSuppressUnfoldings = False + , sdocSuppressVarKinds = False + , sdocSuppressUniques = False + , sdocSuppressModulePrefixes = False + , sdocSuppressStgExts = False + , sdocErrorSpans = False + , sdocStarIsType = False + , sdocImpredicativeTypes = False + , sdocLinearTypes = False + , sdocDynFlags = error "defaultSDocContext: DynFlags not available" + } withPprStyle :: PprStyle -> SDoc -> SDoc withPprStyle sty d = SDoc $ \ctxt -> runSDoc d ctxt{sdocStyle=sty} @@ -490,8 +528,8 @@ pprCode cs d = withPprStyle (PprCode cs) d mkCodeStyle :: CodeStyle -> PprStyle mkCodeStyle = PprCode -renderWithStyle :: SDocContext -> SDoc -> String -renderWithStyle ctx sdoc +renderWithContext :: SDocContext -> SDoc -> String +renderWithContext ctx sdoc = let s = Pretty.style{ Pretty.mode = PageMode, Pretty.lineLength = sdocLineLength ctx } in Pretty.renderStyle s $ runSDoc sdoc ctx ===================================== compiler/ghc.cabal.in ===================================== @@ -581,6 +581,7 @@ Library GHC.CmmToAsm.Instr GHC.CmmToAsm.BlockLayout GHC.CmmToAsm.CFG + GHC.CmmToAsm.CFG.Weight GHC.CmmToAsm.CFG.Dominators GHC.CmmToAsm.Format GHC.Platform.Reg ===================================== testsuite/tests/hiefile/should_run/HieQueries.hs ===================================== @@ -14,7 +14,7 @@ import GHC.Iface.Ext.Utils import Data.Maybe (fromJust) import GHC.Driver.Session import GHC.SysTools -import GHC.Utils.Outputable ( Outputable, renderWithStyle, ppr, defaultUserStyle, text) +import GHC.Utils.Outputable ( Outputable, renderWithContext, ppr, defaultUserStyle, text) import qualified Data.Map as M import Data.Foldable @@ -78,5 +78,5 @@ explainEv df hf refmap point = do pretty = unlines . (++["└"]) . ("┌":) . map ("│ "++) . lines - pprint = pretty . renderWithStyle (initSDocContext df sty) . ppr + pprint = pretty . renderWithContext (initSDocContext df sty) . ppr sty = defaultUserStyle ===================================== testsuite/tests/parser/should_run/CountParserDeps.hs ===================================== @@ -30,7 +30,7 @@ main = do let num = sizeUniqSet modules -- print num -- print (map moduleNameString $ nonDetEltsUniqSet modules) - unless (num < 200) $ exitWith (ExitFailure num) + unless (num <= 200) $ exitWith (ExitFailure num) parserDeps :: FilePath -> IO (UniqSet ModuleName) parserDeps libdir = ===================================== testsuite/tests/regalloc/regalloc_unit_tests.hs ===================================== @@ -28,7 +28,6 @@ import GHC.Driver.Main import GHC.StgToCmm.CgUtils import GHC.CmmToAsm import GHC.CmmToAsm.Config -import GHC.CmmToAsm.Monad as NCGConfig import GHC.Cmm.Info.Build import GHC.Cmm.Pipeline import GHC.Cmm.Parser @@ -106,7 +105,7 @@ compileCmmForRegAllocStats :: IO [( Maybe [Color.RegAllocStats (Alignment, RawCmmStatics) X86.Instr.Instr] , Maybe [Linear.RegAllocStats])] compileCmmForRegAllocStats dflags' cmmFile ncgImplF us = do - let ncgImpl = ncgImplF (NCGConfig.initConfig dflags) + let ncgImpl = ncgImplF (initNCGConfig dflags) hscEnv <- newHscEnv dflags -- parse the cmm file and output any warnings or errors View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/eb9bdaef6024558696e1e50b12d7fefb70483a9f...659eb31b7a40f0aa2ba43c3454b5d9006fde837d -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/eb9bdaef6024558696e1e50b12d7fefb70483a9f...659eb31b7a40f0aa2ba43c3454b5d9006fde837d You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 13:37:18 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 21 Aug 2020 09:37:18 -0400 Subject: [Git][ghc/ghc][master] Fix -ddump-stg flag Message-ID: <5f3fce0ebb5ce_80b1075951c87909d9@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 2d8ca917 by Sylvain Henry at 2020-08-21T09:37:15-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - 6 changed files: - compiler/GHC/Driver/Flags.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Stg/Pipeline.hs - docs/users_guide/debugging.rst - testsuite/tests/simplCore/should_compile/all.T - testsuite/tests/simplCore/should_compile/noinline01.stderr Changes: ===================================== compiler/GHC/Driver/Flags.hs ===================================== @@ -68,9 +68,9 @@ data DumpFlag | Opt_D_dump_simpl_iterations | Opt_D_dump_spec | Opt_D_dump_prep - | Opt_D_dump_stg -- CoreToStg output - | Opt_D_dump_stg_unarised -- STG after unarise - | Opt_D_dump_stg_final -- STG after stg2stg + | Opt_D_dump_stg_from_core -- ^ Initial STG (CoreToStg output) + | Opt_D_dump_stg_unarised -- ^ STG after unarise + | Opt_D_dump_stg_final -- ^ Final STG (after stg2stg) | Opt_D_dump_call_arity | Opt_D_dump_exitify | Opt_D_dump_stranal ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -2586,12 +2586,15 @@ dynamic_flags_deps = [ (setDumpFlag Opt_D_dump_spec) , make_ord_flag defGhcFlag "ddump-prep" (setDumpFlag Opt_D_dump_prep) - , make_ord_flag defGhcFlag "ddump-stg" - (setDumpFlag Opt_D_dump_stg) + , make_ord_flag defGhcFlag "ddump-stg-from-core" + (setDumpFlag Opt_D_dump_stg_from_core) , make_ord_flag defGhcFlag "ddump-stg-unarised" (setDumpFlag Opt_D_dump_stg_unarised) , make_ord_flag defGhcFlag "ddump-stg-final" (setDumpFlag Opt_D_dump_stg_final) + , make_dep_flag defGhcFlag "ddump-stg" + (setDumpFlag Opt_D_dump_stg_from_core) + "Use `-ddump-stg-from-core` or `-ddump-stg-final` instead" , make_ord_flag defGhcFlag "ddump-call-arity" (setDumpFlag Opt_D_dump_call_arity) , make_ord_flag defGhcFlag "ddump-exitify" ===================================== compiler/GHC/Stg/Pipeline.hs ===================================== @@ -52,7 +52,7 @@ stg2stg :: DynFlags -- includes spec of what stg-to-stg passes -> IO [StgTopBinding] -- output program stg2stg dflags this_mod binds - = do { dump_when Opt_D_dump_stg "STG:" binds + = do { dump_when Opt_D_dump_stg_from_core "Initial STG:" binds ; showPass dflags "Stg2Stg" -- Do the main business! ; binds' <- runStgM 'g' $ ===================================== docs/users_guide/debugging.rst ===================================== @@ -387,7 +387,7 @@ STG representation These flags dump various phases of GHC's STG pipeline. -.. ghc-flag:: -ddump-stg +.. ghc-flag:: -ddump-stg-from-core :shortdesc: Show CoreToStg output :type: dynamic @@ -411,6 +411,14 @@ These flags dump various phases of GHC's STG pipeline. Show the output of the last STG pass before we generate Cmm. +.. ghc-flag:: -ddump-stg + :shortdesc: *(deprecated)* Alias for :ghc-flag:`-ddump-stg-from-core` + :type: dynamic + + Alias for :ghc-flag:`-ddump-stg-from-core`. Deprecated in favor of more explicit + flags: :ghc-flag:`-ddump-stg-from-core`, :ghc-flag:`-ddump-stg-final`, etc. + + C-\\- representation ~~~~~~~~~~~~~~~~~~~~ ===================================== testsuite/tests/simplCore/should_compile/all.T ===================================== @@ -210,7 +210,7 @@ test('T12076lit', normal, compile, ['-O']) test('T12076sat', normal, compile, ['-O']) test('T12212', normal, compile, ['-O']) -test('noinline01', only_ways(['optasm']), compile, ['-ddump-stg -dsuppress-uniques -dsuppress-ticks -O']) +test('noinline01', only_ways(['optasm']), compile, ['-ddump-stg-from-core -dsuppress-uniques -dsuppress-ticks -O']) test('par01', only_ways(['optasm']), compile, ['-ddump-prep -dsuppress-uniques -dsuppress-ticks -O2']) test('T12776', normal, compile, ['-O2']) test('T9509', ===================================== testsuite/tests/simplCore/should_compile/noinline01.stderr ===================================== @@ -1,5 +1,5 @@ -==================== STG: ==================== +==================== Initial STG: ==================== Noinline01.f [InlPrag=INLINE (sat-args=1)] :: forall {p}. p -> GHC.Types.Bool [GblId, Arity=1, Str=, Unf=OtherCon []] = View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2d8ca9170328249a436c3b5647b8e548d32b11c8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2d8ca9170328249a436c3b5647b8e548d32b11c8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 13:37:53 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 21 Aug 2020 09:37:53 -0400 Subject: [Git][ghc/ghc][master] Import qualified Prelude in Cmm/Parser.y Message-ID: <5f3fce312acf3_80b3f8468cb3dc0879383d@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: fddddbf4 by Vladislav Zavialov at 2020-08-21T09:37:49-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - 2 changed files: - compiler/GHC/Cmm/Parser.y - compiler/GHC/Parser.y Changes: ===================================== compiler/GHC/Cmm/Parser.y ===================================== @@ -203,6 +203,7 @@ necessary to the stack to accommodate it (e.g. 2). module GHC.Cmm.Parser ( parseCmmFile ) where import GHC.Prelude +import qualified Prelude -- for happy-generated code import GHC.Platform import GHC.Platform.Profile ===================================== compiler/GHC/Parser.y ===================================== @@ -46,7 +46,7 @@ import Data.Char import Data.Maybe ( maybeToList ) import Control.Monad ( mplus ) import Control.Applicative ((<$)) -import qualified Prelude +import qualified Prelude -- for happy-generated code -- compiler import GHC.Hs View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fddddbf47d6ba2b1b3b6ec89bd40c8fa020e6606 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fddddbf47d6ba2b1b3b6ec89bd40c8fa020e6606 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 14:08:40 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 21 Aug 2020 10:08:40 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 7 commits: Put CFG weights into their own module (#17957) Message-ID: <5f3fd5686b999_80b3f842731681c8817098@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 293c7fba by Sylvain Henry at 2020-08-21T09:36:38-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - 50eb4460 by Sylvain Henry at 2020-08-21T09:36:38-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 659eb31b by Sylvain Henry at 2020-08-21T09:36:38-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 2d8ca917 by Sylvain Henry at 2020-08-21T09:37:15-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - fddddbf4 by Vladislav Zavialov at 2020-08-21T09:37:49-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - 145765e5 by Aditya Gupta at 2020-08-21T10:08:32-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - f1ef981c by Wander Hillen at 2020-08-21T10:08:34-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 30 changed files: - .gitlab-ci.yml - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - + compiler/GHC/CmmToAsm/CFG/Weight.hs - compiler/GHC/CmmToAsm/Config.hs - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/Reg/Graph/Base.hs - compiler/GHC/CmmToAsm/Reg/Graph/SpillClean.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/CmmToAsm/X86/Ppr.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/CmmToLlvm/CodeGen.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/DataCon.hs-boot - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/Exitify.hs - compiler/GHC/Core/Opt/Monad.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2773b14489540e729bc6fe1744dc6f817ec1a559...f1ef981c78ff0c11961057e4ca316ce23b1d8965 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2773b14489540e729bc6fe1744dc6f817ec1a559...f1ef981c78ff0c11961057e4ca316ce23b1d8965 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 15:10:52 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Fri, 21 Aug 2020 11:10:52 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/stgMalloc Message-ID: <5f3fe3fc38fe1_80b3f84902b125088240ca@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/stgMalloc at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/stgMalloc You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 15:27:57 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Fri, 21 Aug 2020 11:27:57 -0400 Subject: [Git][ghc/ghc][master] gitlab-ci: Test master branch as well Message-ID: <5f3fe7fda84ab_80b3f8495bc8b04883153c@gitlab.haskell.org.mail> Ben Gamari pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 989c1c27 by Ben Gamari at 2020-08-21T11:27:53-04:00 gitlab-ci: Test master branch as well While these builds are strictly speaking redundant (since every commit is tested by @marge-bot before making it into `master`), they are nevertheless useful as they are displayed in the branch's commit list in GitLab's web interface. Fixes #18595. - - - - - 1 changed file: - .gitlab-ci.yml Changes: ===================================== .gitlab-ci.yml ===================================== @@ -47,6 +47,7 @@ workflow: rules: - if: $CI_MERGE_REQUEST_ID - if: $CI_COMMIT_TAG + - if: '$CI_COMMIT_BRANCH == "master"' - if: '$CI_COMMIT_BRANCH == "wip/marge_bot_batch_merge_job"' - if: '$CI_COMMIT_BRANCH =~ /ghc-[0.9]+\.[0-9]+/' - if: '$CI_PIPELINE_SOURCE == "web"' View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/989c1c27b1ec69d8cf56b438f0173d92c3547ab5 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/989c1c27b1ec69d8cf56b438f0173d92c3547ab5 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 15:31:50 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Fri, 21 Aug 2020 11:31:50 -0400 Subject: [Git][ghc/ghc][wip/bump-text] 148 commits: Fix #17724 by having occAnal preserve used bindings. Message-ID: <5f3fe8e6fab7_80b3f8468db91988840043@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/bump-text at Glasgow Haskell Compiler / GHC Commits: 7fc34aed by Andreas Klebinger at 2020-02-22T18:43:59-05:00 Fix #17724 by having occAnal preserve used bindings. It sometimes happened that occAnal would remove bindings as dead code by relying on bindings to be in dependency order. The fix was contributed by SPJ. (cherry picked from commit 6de966f1369740d00193e64ec82d11e934256616) - - - - - 19565411 by Ben Gamari at 2020-02-22T18:44:33-05:00 Set RELEASE=YES - - - - - 5ccd851f by Alexis King at 2020-02-22T18:49:33-05:00 Treat coercions as arguments for floating and inlining This reverts commit 8924224ecfa065ebc67b96a90d01cf9d2edd0e77 and fixes #17787. (cherry picked from commit 54c8641df70961fd57ff89ec52596a2898a048d7) - - - - - ff95136b by Ben Gamari at 2020-02-22T18:58:35-05:00 fs: Port fixes from ghc-jailbreak repository * Override rename, unlink, and remove * Factor out wchar conversion (cherry picked from commit bdb2e37550fed13ad1d5cf1d76c8cc90b4d823fb) - - - - - 05969579 by Ben Gamari at 2020-02-23T10:21:06-05:00 testsuite: Skip T17787 in profiled ways - - - - - 58481788 by Krzysztof Gogolewski at 2020-02-25T01:37:00-05:00 Fix order of arguments in specializer (#17801) See https://gitlab.haskell.org/ghc/ghc/issues/17801#note_253330 No regression test, as it's hard to trigger. (cherry picked from commit f0c0ee7d9a942a19361e72553cd08f42cc12b04a) - - - - - fe488bbe by Sylvain Henry at 2020-02-25T18:29:03+01:00 Document module renaming - - - - - ea7ff702 by Ben Gamari at 2020-03-04T12:33:25-05:00 nonmoving: Fix marking in compact regions Previously we were tracing the object we were asked to mark, even if it lives in a compact region. However, there is no need to do this; we need only to mark the region itself as live. I have seen a segfault due to this due to the concurrent mark seeing a an object in the process of being compacted by the mutator. (cherry picked from commit e4e9a7ba3abc991d3583371da4681560a7b67bd2) - - - - - a9dcac04 by Ben Gamari at 2020-03-04T12:33:25-05:00 nonmoving: Clear segment bitmaps during sweep Previously we would clear the bitmaps of segments which we are going to sweep during the preparatory pause. However, this is unnecessary: the existence of the mark epoch ensures that the sweep will correctly identify non-reachable objects, even if we do not clear the bitmap. We now defer clearing the bitmap to sweep, which happens concurrently with mutation. (cherry picked from commit 69001f54279a55bc4e5e5883c675e5ba6fe49a22) - - - - - 2bf7b5b5 by Ben Gamari at 2020-03-04T12:33:25-05:00 nonmoving: Don't traverse filled segment list in pause The non-moving collector would previously walk the entire filled segment list during the preparatory pause. However, this is far more work than is strictly necessary. We can rather get away with merely collecting the allocators' filled segment list heads and process the lists themselves during the concurrent phase. This can significantly reduce the maximum gen1 GC pause time in programs with high rates of long-lived allocations. (cherry picked from commit 927b7a3de710d53fb11ccea35b807b64b4afc700) - - - - - 92bc3688 by Ben Gamari at 2020-03-04T12:56:40-05:00 nonmoving: Fix collection of sparks Previously sparks living in the non-moving heap would be promptly GC'd by the minor collector since pruneSparkQueue uses the BF_EVACUATED flag, which non-moving heap blocks do not have set. Fix this by implementing proper support in pruneSparkQueue for determining reachability in the non-moving heap. The story is told in Note [Spark management in the nonmoving heap]. - - - - - 7daea656 by Josef Svenningsson at 2020-03-09T11:55:24-04:00 Fix ApplicativeDo regression #17835 A previous fix for #15344 made sure that monadic 'fail' is used properly when translating ApplicativeDo. However, it didn't properly account for when a 'fail' will be inserted which resulted in some programs failing with a type error. (cherry picked from commit 7537d273b3082ef15693c78ac38d3020d4add4c9) - - - - - a4d102d2 by Ben Gamari at 2020-03-09T19:07:33-04:00 Revert "Solve constraints from top-level groups sooner" This reverts commit 9612e91c793830b3049d2bc9a9ee28d9d82b928d. - - - - - a20022fc by Tamar Christina at 2020-03-10T17:52:13-04:00 Fs: Fix UNC remapping code. (cherry picked from commit 5670881d7779ecd7eee8c969dab66ee343298532) - - - - - fb3542a5 by Ben Gamari at 2020-03-11T19:59:32-04:00 gitlab-ci: Rework triggering of release builds Use a push option instead of tagging. - - - - - 84439cb0 by Ben Gamari at 2020-03-12T19:00:23-04:00 Bump hpc submodule Fixes typo in changelog. - - - - - e6ccab35 by Ben Gamari at 2020-03-12T19:32:37-04:00 gitlab-ci: Disable utimensat support in Darwin builds Works around #17895. - - - - - dbc5e8c8 by Ben Gamari at 2020-03-13T10:44:54-04:00 gitlab-ci: Add integer-simple release build for Windows Closes #16144. - - - - - e03bae3c by Ben Gamari at 2020-03-14T15:41:40-04:00 Bump process submodule Avoid unreachable case alternative warning on Windows. - - - - - 05cc8b19 by Ben Gamari at 2020-03-14T15:42:16-04:00 gitlab-ci: Use integer-simple to built Alpine bindists - - - - - 91d1f25c by Ömer Sinan Ağacan at 2020-03-14T16:13:39-04:00 Fix global_link of TSOs for threads reachable via dead weaks Fixes #17785 Here's how the problem occurs: - In generation 0 we have a TSO that is finished (i.e. it has no more work to do or it is killed). - The TSO only becomes reachable after collectDeadWeakPtrs(). - After collectDeadWeakPtrs() we switch to WeakDone phase where we don't move TSOs to different lists anymore (like the next gen's thread list or the resurrected_threads list). - So the TSO will never be moved to a generation's thread list, but it will be promoted to generation 1. - Generation 1 collected via mark-compact, and because the TSO is reachable it is marked, and its `global_link` field, which is bogus at this point (because the TSO is not in a list), will be threaded. - Chaos ensues. In other words, when these conditions hold: - A TSO is reachable only after collectDeadWeakPtrs() - It's finished (what_next is ThreadComplete or ThreadKilled) - It's retained by mark-compact collector (moving collector doesn't evacuate the global_list field) We end up doing random mutations on the heap because the TSO's global_list field is not valid, but it still looks like a heap pointer so we thread it during compacting GC. The fix is simple: when we traverse old_threads lists to resurrect unreachable threads the threads that won't be resurrected currently stays on the old_threads lists. Those threads will never be visited again by MarkWeak so we now reset the global_list fields. This way compacting GC does not thread pointers to nowhere. Testing ------- The reproducer in #17785 is quite large and hard to build, because of the dependencies, so I'm not adding a regression test. In my testing the reproducer would take a less than 5 seconds to run, and once in every ~5 runs would fail with a segfault or an assertion error. In other cases it also fails with a test failure. Because the tests never fail with the bug fix, assuming the code is correct, this also means that this bug can sometimes lead to incorrect runtime results. After the fix I was able to run the reproducer repeatedly for about an hour, with no runtime crashes or test failures. To run the reproducer clone the git repo: $ git clone https://github.com/osa1/streamly --branch ghc-segfault Then clone primitive and atomic-primops from their git repos and point to the clones in cabal.project.local. The project should then be buildable using GHC HEAD. Run the executable `properties` with `+RTS -c -DZ`. In addition to the reproducer above I run the test suite using: $ make slowtest EXTRA_HC_OPTS="-debug -with-rtsopts=-DS \ -with-rtsopts=-c +RTS -c -RTS" SKIPWAY='nonmoving nonmoving_thr' This enables compacting GC always in both GHC when building the test programs and when running the test programs, and also enables sanity checking when running the test programs. These set of flags are not compatible for all tests so there are some failures, but I got the same set of failures with this patch compared to GHC HEAD. (cherry picked from commit 2e4d572e0a869e38253574cb8f383d6ded0b7e32) - - - - - 35aab0f9 by Ben Gamari at 2020-03-14T16:40:50-04:00 fs.h: Add missing declarations on Windows - - - - - 2cf76e2b by Adam Sandberg Ericsson at 2020-03-14T21:14:25-04:00 configure: correctly generate LIBRARY_template_haskell_VERSION (backport for 8.10) - - - - - 14ec315f by Ben Gamari at 2020-03-15T00:20:55-04:00 base: Fix unqualified import of Data.List In System.Environment.ExecutablePath that was only compiled on Windows. - - - - - 02f393fb by Ben Gamari at 2020-03-15T00:21:50-04:00 Bump process submodule again - - - - - 5c1c4022 by Richard Eisenberg at 2020-03-16T16:47:14+00:00 Warning about SAKs in release notes - - - - - af9eea15 by Ben Gamari at 2020-03-16T22:34:17-04:00 Bump process submodule again - - - - - 3368f4f7 by Ben Gamari at 2020-03-16T22:34:17-04:00 gitlab-ci: Fix integer-simple job - - - - - 90e28e61 by Ben Gamari at 2020-03-16T22:41:53-04:00 Bump hsc2hs to 0.68.7 - - - - - 036133af by Ben Gamari at 2020-03-17T09:46:27-04:00 gitlab-ci: Bootstrap Darwin/Windows with 8.8.3 To ensure we have a new enough process version. - - - - - 848cc69b by Ben Gamari at 2020-03-17T09:46:48-04:00 gitlab-ci: Drop old build.mk logic on Windows - - - - - 4c0a45d1 by Ben Gamari at 2020-03-17T20:16:58-04:00 Bump hsc2hs submodule Fixes Darwin build failure due to CPP whitespace. - - - - - de890c82 by Ben Gamari at 2020-03-18T09:53:53-04:00 gitlab-ci: Backport CI rework from master - - - - - 671ac3f6 by Ben Gamari at 2020-03-18T11:57:52-04:00 users-guide: Fix :default: fields - - - - - 00d25137 by Ben Gamari at 2020-03-18T13:42:15-04:00 release notes: Fix undefined references - - - - - a5caf1a2 by Ben Gamari at 2020-03-18T13:43:11-04:00 rts: Expose interface for configuring EventLogWriters This exposes a set of interfaces from the GHC API for configuring EventLogWriters. These can be used by consumers like [ghc-eventlog-socket](https://github.com/bgamari/ghc-eventlog-socket). (cherry picked from commit e43e6ece1418f84e50d572772394ab639a083e79) - - - - - 5295fd5a by Ben Gamari at 2020-03-18T13:46:52-04:00 users-guide: Fix unknown link targets - - - - - 544e24e1 by Ben Gamari at 2020-03-18T15:35:34-04:00 docs/compare-flags: Don't use python f-strings - - - - - 24966161 by Ben Gamari at 2020-03-18T15:35:38-04:00 compare-flags: Don't rely on encoding flag of subprocess.check_output Apparently it isn't supported by some slightly older Python versions. - - - - - 0fd7e009 by Ben Gamari at 2020-03-18T15:35:42-04:00 compare-flags: Fix output - - - - - cd4990ca by Ben Gamari at 2020-03-18T18:15:45-04:00 Drop compare-flags - - - - - 06ee06fb by Ben Gamari at 2020-03-18T21:32:17-04:00 Add test-metrics.sh from master - - - - - b9fb1ac4 by Ben Gamari at 2020-03-19T09:36:05-04:00 Backport get-win32-tarballs configure changes - - - - - 8eb82c89 by Ben Gamari at 2020-03-19T23:45:02-04:00 Bump process submodule - - - - - 06889a6f by Ben Gamari at 2020-03-19T23:45:28-04:00 gitlab-ci: Allow armv7 to fail - - - - - 5c3cadf5 by Alec Theriault at 2020-03-22T20:26:41-04:00 Bump Haddock submodule for 2.24 release - - - - - 07c0d148 by Sylvain Henry at 2020-04-13T17:57:19-04:00 Force -fPIC for intree GMP (fix #17799) Configure intree GMP with `--with-pic` instead of patching it. Moreover the correct patching was only done for x86_64/darwin (see #17799). (cherry picked from commit e1e329448f3742b2024ca6bc2c78f36fe282b606) - - - - - 64fb49c9 by Ben Gamari at 2020-04-13T17:57:19-04:00 gitlab-ci: Add FreeBSD release job - - - - - d1464459 by Ben Gamari at 2020-04-13T17:57:19-04:00 Mention -Wunused-packages in release notes - - - - - 9ba0cd3e by Ben Gamari at 2020-04-13T17:57:19-04:00 testsuite: Don't ask sed to operate in-place on symlinks Some sed implementations (e.g. FreeBSD) refuse to operate in-place on symlinks. (cherry picked from commit e5ee07ab565c1bf7a33d3bd4bcd3fb6c7b100d1c) - - - - - c0b4e2cc by Ben Gamari at 2020-04-13T17:57:19-04:00 testsuite/T16930: Don't rely on gnu grep specific --include In BSD grep this flag only affects directory recursion. - - - - - 2daee665 by Ben Gamari at 2020-04-13T17:57:19-04:00 testsuite: Mark T6132 as broken on FreeBSD - - - - - 12bb9912 by Ben Gamari at 2020-04-13T17:57:20-04:00 Pass -Wno-unused-command-line-arguments during link on FreeBSD FreeBSD cc throws a warning if we pass -pthread without actually using any pthread symbols. - - - - - 3717c610 by Ben Gamari at 2020-04-13T17:57:20-04:00 base: Always clamp reads/writes to 2GB in length Previously we did this only on Darwin due to #17414. However, even on other platforms >2GB writes are on shaky ground. POSIX explicitly says that the result is implementation-specified and Linux will write at most 0x7ffff000, even on 64-bit platforms. Moreover, getting the sign of the syscall result correct is tricky, as demonstrated by the fact that T17414 currently fails on FreeBSD. For simplicity we now just uniformly clamp to 0x7ffff000 on all platforms. - - - - - 9ff90fd8 by Ben Gamari at 2020-04-13T17:57:20-04:00 configure: Fix sphinx version test The check for the "v" prefix is redundant. - - - - - 584c3b05 by Ben Gamari at 2020-05-12T12:42:34-04:00 configure.ac: Reset RELEASE to NO - - - - - 37956be4 by Viktor Dukhovni at 2020-05-21T17:42:48-04:00 Note platform-specific Foreign.C.Types in context Also fix the markup in the general note at the top of the module. Haddock (usability trade-off), does not support multi-line emphasised text. - - - - - a16c24b7 by Ben Gamari at 2020-05-24T20:42:31-04:00 rts: Add getCurrentThreadCPUTime helper (cherry picked from commit cedd6f3041de6abe64dfa3257bec7730a9dced9f) - - - - - d1f9d711 by Ben Gamari at 2020-05-24T20:42:31-04:00 rts: Prefer darwin-specific getCurrentThreadCPUTime macOS Catalina now supports a non-POSIX-compliant version of clock_gettime which cannot use the clock_gettime codepath. Fixes #17906. (cherry picked from commit bb586f894532baf1bcb822afd0df7f9fea198671) - - - - - 39f3b172 by Ben Gamari at 2020-05-24T20:42:31-04:00 nonmoving-gc: Track time usage of nonmoving marking (cherry picked from commit ace618cd2294989e783bd453cee88e0e1c0dad77) - - - - - 35f50728 by Ben Gamari at 2020-05-24T20:42:31-04:00 nonmoving: Eagerly flush all capabilities' update remembered sets (cherry picked from commit 2fa79119570b358a4db61446396889b8260d7957) - - - - - dc26ba87 by Ben Gamari at 2020-05-24T20:42:31-04:00 nonmoving: Explicitly memoize block count A profile cast doubt on whether the compiler hoisted the bound out the loop as I would have expected here. It turns out it did but nevertheless it seems clearer to just do this manually. - - - - - ce49860d by Ben Gamari at 2020-05-24T20:42:32-04:00 nonmoving: Clear bitmap after initializing block size Previously nonmovingInitSegment would clear the bitmap before initializing the segment's block size. This is broken since nonmovingClearBitmap looks at the segment's block size to determine how much bitmap to clear. - - - - - 1101739a by Ben Gamari at 2020-05-24T20:42:32-04:00 hadrian: Allow libnuma library path to be specified - - - - - 6e8ede7e by Ben Gamari at 2020-05-24T20:42:32-04:00 rts: Zero block flags with -DZ Block flags are very useful for determining the state of a block. However, some block allocator users don't touch them, leading to misleading values. Ensure that we zero then when zero-on-gc is set. This is safe and makes the flags more useful during debugging. - - - - - 185a870e by Ben Gamari at 2020-05-24T20:42:32-04:00 nonmoving: Fix incorrect failed_to_evac value during deadlock gc Previously we would incorrectly set the failed_to_evac flag if we evacuated a value due to a deadlock GC. This would cause us to mark more things as dirty than strictly necessary. It also turned up a nasty but which I will fix next. - - - - - 124a40cc by Ben Gamari at 2020-05-24T20:42:32-04:00 nonmoving: Fix handling of dirty objects Previously we (incorrectly) relied on failed_to_evac to be "precise". That is, we expected it to only be true if *all* of an object's fields lived outside of the non-moving heap. However, does not match the behavior of failed_to_evac, which is true if *any* of the object's fields weren't promoted (meaning that some others *may* live in the non-moving heap). This is problematic as we skip the non-moving write barrier for dirty objects (which we can only safely do if *all* fields point outside of the non-moving heap). Clearly this arises due to a fundamental difference in the behavior expected of failed_to_evac in the moving and non-moving collector. e.g., in the moving collector it is always safe to conservatively say failed_to_evac=true whereas in the non-moving collector the safe value is false. This issue went unnoticed as I never wrote down the dirtiness invariant enforced by the non-moving collector. We now define this invariant as An object being marked as dirty implies that all of its fields are on the mark queue (or, equivalently, update remembered set). To maintain this invariant we teach nonmovingScavengeOne to push the fields of objects which we fail to evacuate to the update remembered set. This is a simple and reasonably cheap solution and avoids the complexity and fragility that other, more strict alternative invariants would require. All of this is described in a new Note, Note [Dirty flags in the non-moving collector] in NonMoving.c. - - - - - b23f16d0 by Ben Gamari at 2020-05-24T20:42:32-04:00 nonmoving: Optimise the write barrier (cherry picked from commit a636eadac1f30bae37aeb6526f94893293f098b8) - - - - - d2581e98 by Ömer Sinan Ağacan at 2020-05-24T20:42:32-04:00 FastString: fix eager reading of string ptr in hashStr This read causes NULL dereferencing when len is 0. Fixes #17909 In the reproducer in #17909 this bug is triggered as follows: - SimplOpt.dealWithStringLiteral is called with a single-char string ("=" in #17909) - tailFS gets called on the FastString of the single-char string. - tailFS checks the length of the string, which is 1, and calls mkFastStringByteString on the tail of the ByteString, which is an empty ByteString as the original ByteString has only one char. - ByteString's unsafeUseAsCStringLen returns (NULL, 0) for the empty ByteString, which is passed to mkFastStringWith. - mkFastStringWith gets hash of the NULL pointer via hashStr, which fails on empty strings because of this bug. (cherry picked from commit d15b61608a542f6349b42224140b7d227b88ef4e) - - - - - 76059e3e by Simon Peyton Jones at 2020-05-24T20:42:32-04:00 Improve error handling for VTA + deferred type errors This fixes #17792 See Note [VTA for out-of-scope functions] in TcExpr (cherry picked from commit 335b18bac3c361d243f427b66e67c2c94f5c6494) - - - - - a7dd83db by Simon Peyton Jones at 2020-05-24T20:42:32-04:00 Add a missing zonk in tcHsPartialType I omitted a vital zonk when refactoring tcHsPartialType in commit 48fb3482f8cbc8a4b37161021e846105f980eed4 Author: Simon Peyton Jones <simonpj at microsoft.com> Date: Wed Jun 5 08:55:17 2019 +0100 Fix typechecking of partial type signatures This patch fixes it and adds commentary to explain why. Fixes #18008 (cherry picked from commit 658bda511237593bb80389280d0364180648058d) - - - - - e3fcf26d by Sylvain Henry at 2020-05-24T20:42:32-04:00 Rts: show errno on failure (#18033) (cherry picked from commit 4875d419ba066e479f7ac07f8b39ebe10c855859) - - - - - ba788d22 by Ryan Scott at 2020-05-24T20:42:32-04:00 Fix two ASSERT buglets in reifyDataCon Two `ASSERT`s in `reifyDataCon` were always using `arg_tys`, but `arg_tys` is not meaningful for GADT constructors. In fact, it's worse than non-meaningful, since using `arg_tys` when reifying a GADT constructor can lead to failed `ASSERT`ions, as #17305 demonstrates. This patch applies the simplest possible fix to the immediate problem. The `ASSERT`s now use `r_arg_tys` instead of `arg_tys`, as the former makes sure to give something meaningful for GADT constructors. This makes the panic go away at the very least. There is still an underlying issue with the way the internals of `reifyDataCon` work, as described in https://gitlab.haskell.org/ghc/ghc/issues/17305#note_227023, but we leave that as future work, since fixing the underlying issue is much trickier (see https://gitlab.haskell.org/ghc/ghc/issues/17305#note_227087). (cherry picked from commit cfb66d181ac45ce3d934bda3521b94277e6eb683) - - - - - 25d84fa2 by Adam Gundry at 2020-05-24T20:42:32-04:00 Reject all duplicate declarations involving DuplicateRecordFields (fixes #17965) This fixes a bug that resulted in some programs being accepted that used the same identifier as a field label and another declaration, depending on the order they appeared in the source code. (cherry picked from commit 0d8c7a6c7c3513089668f49efb0a2dd8b4bbe74a) - - - - - 646648a9 by Ben Gamari at 2020-05-24T20:42:32-04:00 Ensure that printMinimalImports closes handle Fixes #18166. (cherry picked from commit 5afc160dee7142c96a842037fb64bee1429ad9ec) - - - - - 123c386b by Ben Gamari at 2020-05-24T20:42:32-04:00 rts: Make non-existent linker search path merely a warning As noted in #18105, previously this resulted in a rather intrusive error message. This is in contrast to the general expectation that search paths are merely places to look, not places that must exist. Fixes #18105. (cherry picked from commit 24af9f30681444380c25465f555599da563713cb) - - - - - 06f05573 by Ben Gamari at 2020-05-24T20:42:32-04:00 nonmoving: Optimise log2_ceil (cherry picked from commit 5f69016115414d0dd921e72f3edcd0b365966141) - - - - - dae01c10 by Ben Gamari at 2020-05-24T20:42:32-04:00 rts: Enable tracing of nonmoving heap census with -ln Previously this was not easily available to the user. Fix this. Non-moving collection lifecycle events are now reported with -lg. (cherry picked from commit 7bfe9ac514e18c0b0e24ff55230fe98ec9db894c) - - - - - 72218602 by Ben Gamari at 2020-05-24T20:42:32-04:00 users guide: Move eventlog documentation users guide (cherry picked from commit c560dd07f506810eaabae2f582491138aa224819) - - - - - 79da3ca2 by Ben Gamari at 2020-05-24T20:42:33-04:00 users guide: Add documentation for non-moving GC events (cherry picked from commit 02543d5ef9bd7a910fc9fece895780583ab9635a) - - - - - 10f80ca8 by Ben Gamari at 2020-05-30T09:56:23-04:00 iserv: Don't pass --export-dynamic on FreeBSD This is definitely a hack but it's probably the best we can do for now. Hadrian does the right thing here by passing --export-dynamic only to the linker. (cherry picked from commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9) - - - - - 94562bbf by Ben Gamari at 2020-05-30T09:56:30-04:00 hadrian: Use --export-dynamic when linking iserv As noticed in #17962, the make build system currently does this (see 3ce0e0ba) but the change was never ported to Hadrian. (cherry picked from commit eba58110538686d8fe57d5dd372624b50f1fa2b7) - - - - - b3330c2d by Ben Gamari at 2020-05-30T09:58:52-04:00 Coverage: Don't produce ModBreaks if not HscInterpreted emptyModBreaks contains a bottom and consequently it's important that we don't use it unless necessary. (cherry picked from commit f684a7d505f19bd78f178e01bbd8e4467aaa00ea) - - - - - 295735ae by Ben Gamari at 2020-05-30T10:00:15-04:00 Bump process submodule Fixes #17926. - - - - - 285f92bb by Sylvain Henry at 2020-05-30T10:03:03-04:00 RTS: workaround a Linux kernel bug in timerfd Reading a timerfd may return 0: https://lkml.org/lkml/2019/8/16/335. This is currently undocumented behavior and documentation "won't happen anytime soon" (https://lkml.org/lkml/2020/2/13/295). With this patch, we just ignore the result instead of crashing. It may fix #18033 but we can't be sure because we don't have enough information. See also this discussion about the kernel bug: https://github.com/Azure/sonic-swss-common/pull/302/files/1f070e7920c2e5d63316c0105bf4481e73d72dc9 (cherry picked from commit 8ea37b01b6ab16937f7b528b6bbae9fade9f1361) - - - - - 88fd4829 by Ryan Scott at 2020-05-31T18:03:38-04:00 Add orderingTyCon to wiredInTyCons (#18185) `Ordering` needs to be wired in for use in the built-in `CmpNat` and `CmpSymbol` type families, but somehow it was never added to the list of `wiredInTyCons`, leading to the various oddities observed in #18185. Easily fixed by moving `orderingTyCon` from `basicKnownKeyNames` to `wiredInTyCons`. Fixes #18185. (cherry picked from commit 6ca3d6a6c19dcd885f3b0beeda192cd90e83e0bd) - - - - - a6befeb3 by Ben Gamari at 2020-05-31T18:03:38-04:00 simplCore: Ignore ticks in rule templates This fixes #17619, where a tick snuck in to the template of a rule, resulting in a panic during rule matching. The tick in question was introduced via post-inlining, as discussed in `Note [Simplifying rules]`. The solution we decided upon was to simply ignore ticks in the rule template, as discussed in `Note [Tick annotations in RULE matching]`. Fixes #18162. Fixes #17619. (cherry picked from commit dcd6bdcce57430d08b335014625722c487ea08e4) - - - - - fa36474d by Tuan Le at 2020-05-31T18:03:38-04:00 llvmGen: Consider Relocatable read-only data as not constantReferences: #18137 (cherry picked from commit 0004ccb885e534c386ceae21580fc59ec7ad0ede) - - - - - 4a73e707 by Ben Gamari at 2020-05-31T18:03:38-04:00 rts/CNF: Fix fixup comparison function Previously we would implicitly convert the difference between two words to an int, resulting in an integer overflow on 64-bit machines. Fixes #16992 (cherry picked from commit cf4f1e2f78840d25b132de55bce1e02256334ace) - - - - - 4219e9c1 by Ryan Scott at 2020-05-31T18:03:38-04:00 Make boxed 1-tuples have known keys Unlike other tuples, which use special syntax and are "known" by way of a special `isBuiltInOcc_maybe` code path, boxed 1-tuples do not use special syntax. Therefore, in order to make sure that the internals of GHC are aware of the `data Unit a = Unit a` definition in `GHC.Tuple`, we give `Unit` known keys. For the full details, see `Note [One-tuples] (Wrinkle: Make boxed one-tuple names have known keys)` in `GHC.Builtin.Types`. Fixes #18097. (cherry picked from commit 518a63d4d7e31e49a81ad66d5e5ccb1f790f6de9) - - - - - 761909b9 by Ryan Scott at 2020-05-31T18:03:38-04:00 Create di_scoped_tvs for associated data family instances properly See `Note [Associated data family instances and di_scoped_tvs]` in `GHC.Tc.TyCl.Instance`, which explains all of the moving parts. Fixes #18055. (cherry picked from commit cd8409c26d4370bf2cdcd76801974e99a9adf7b0) - - - - - 30037e6d by Sebastian Graf at 2020-05-31T18:03:38-04:00 PmCheck: Adjust recursion depth for inhabitation test In #17977, we ran into the reduction depth limit of the typechecker. That was only a symptom of a much broader issue: The recursion depth of the coverage checker for trying to instantiate strict fields in the `nonVoid` test was far too high (100, the `defaultMaxTcBound`). As a result, we were performing quite poorly on `T17977`. Short of a proper termination analysis to prove emptyness of a type, we just arbitrarily default to a much lower recursion limit of 3. Fixes #17977. (cherry picked from commit ed58d4fdcbc7b4fa8fbdf3d638a8d53c444ef4f2) - - - - - 1666baa6 by Simon Peyton Jones at 2020-05-31T18:03:38-04:00 Improve skolemisation This patch avoids skolemiseUnboundMetaTyVar making up a fresh Name when it doesn't need to. See Note [Skolemising and identity] Improves error messsages for partial type signatures. (cherry picked from commit d7002bccd7d131f8ee9b1ddcd83d62262622294d) - - - - - 84ba6d2c by Simon Peyton Jones at 2020-05-31T18:03:38-04:00 Improve pretty-printing for TyConBinders In particular, show their kinds. (cherry picked from commit fa37940cd72f82abc460f5c0a5de64dd75cee6ae) - - - - - 35277140 by Simon Peyton Jones at 2020-05-31T18:03:38-04:00 Fix scoping of TyCon binders in TcTyClsDecls This patch fixes #17566 by refactoring the way we decide the final identity of the tyvars in the TyCons of a possibly-recursive nest of type and class decls, possibly with associated types. It's all laid out in Note [Swizzling the tyvars before generaliseTcTyCon] Main changes: * We have to generalise each decl (with its associated types) all at once: TcTyClsDecls.generaliseTyClDecl * The main new work is done in TcTyClsDecls.swizzleTcTyConBndrs * The mysterious TcHsSyn.zonkRecTyVarBndrs dies altogether Other smaller things: * A little refactoring, moving bindTyClTyVars from tcTyClDecl1 to tcDataDefn, tcSynRhs, etc. Clearer, reduces the number of parameters * Reduce the amount of swizzling required. Specifically, bindExplicitTKBndrs_Q_Tv doesn't need to clone a new Name for the TyVarTv, and not cloning means that in the vasly common case, swizzleTyConBndrs is a no-op In detail: Rename newTyVarTyVar --> cloneTyVarTyVar Add newTyVarTyTyVar that doesn't clone Use the non-cloning newTyVarTyVar in bindExplicitTKBndrs_Q_Tv Rename newFlexiKindedTyVarTyVar --> cloneFlexiKindedTyVarTyVar * Define new utility function and use it HsDecls.familyDeclName :: FamilyDecl (GhcPass p) -> IdP (GhcPass p) Updates haddock submodule. (cherry picked from commit b9605396f1f1560aea94792646b835cadcb49f45) - - - - - 540d5562 by Ben Gamari at 2020-06-02T10:07:07-04:00 CorePrep: Print type if we fail to split - - - - - 26386f0c by Ben Gamari at 2020-06-20T15:26:31-04:00 gitlab-ci: Introduce DWARF release jobs for Deb10 and Fedora 27 (cherry picked from commit 481e31740672a37c5b3a8924bba7e15c4080bc2e) - - - - - 408b6714 by Ben Gamari at 2020-07-15T11:26:48-04:00 gitlab-ci: Bump Docker images - - - - - 410f53a9 by Ben Gamari at 2020-07-15T11:26:48-04:00 hadrian: Eliminate some redundant imports - - - - - e2bed3ee by GHC GitLab CI at 2020-07-15T11:26:48-04:00 Accept testsuite changes - - - - - 5018cad4 by Kevin Buhr at 2020-07-15T11:26:48-04:00 Add "-Iw" RTS flag for minimum wait between idle GCs (#11134) This wasn't originally slated for 8.10 but the documentation part of this patch snuck into the ghc-8.10 branch via a backport. Instead of backing out the documentation and causing further user confusion I've opted just to backport this functional change as well. (cherry picked from commit 859ebdd446eda446d38708a587503c255b58c4c6) - - - - - edc36a91 by Ben Gamari at 2020-07-15T11:26:48-04:00 user-guide: Add release notes for 8.10.2 - - - - - 46e3ceca by Ben Gamari at 2020-07-15T11:27:30-04:00 rts/ProfHeap: Only allocate the Censuses that we need When not LDV profiling there is no reason to allocate 32 Censuses; one will do. This is a very small memory footprint optimisation, but it comes for free. (cherry picked from commit 8cc7274b8de254c7266b61fadbc6795dc37bd1e9) - - - - - ca146208 by Ben Gamari at 2020-07-15T11:27:40-04:00 rts/ProfHeap: Free old allocations when reinitialising Censuses Previously when not LDV profiling we would repeatedly reinitialise `censuses[0]` with `initEra`. This failed to free the `Arena` and `HashTable` from the old census, resulting in a memory leak. Fixes #18348. (cherry picked from commit b835112cbeaa6e34a8bae7b7697bdf2826edaa9a) - - - - - c9770ef3 by Andreas Klebinger at 2020-07-15T23:39:35-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. (cherry picked from commit fecafac8065d951c14a23de2395e078328f856cd) - - - - - aa2e5863 by Moritz Angermann at 2020-07-15T23:42:39-04:00 [linker/rtsSymbols] More linker symbols Mostly symbols needed for aarch64/armv7l and in combination with musl, where we have to rely on loading *all* objects/archives - __stack_chk_* only when not DYNAMIC (cherry picked from commit 5bc6082fdcb278be878f01a2eeb9741d7d82bb49) - - - - - dfffd9eb by Artem Pelenitsyn at 2020-07-15T23:50:11-04:00 base: fix sign confusion in log1mexp implementation (fix #17125) author: claude (https://gitlab.haskell.org/trac-claude) The correct threshold for log1mexp is -(log 2) with the current specification of log1mexp. This change improves accuracy for large negative inputs. To avoid code duplication, a small helper function is added; it isn't the default implementation in Floating because it needs Ord. This patch does nothing to address that the Haskell specification is different from that in common use in other languages. (cherry picked from commit af5e3a885ddd09dd5f550552c535af3661ff3dbf) - - - - - 93c06518 by Moritz Angermann at 2020-07-15T23:51:27-04:00 ghc-prim needs to depend on libc and libm libm is just an empty shell on musl, and all the math functions are contained in libc. (cherry picked from commit b455074875d3c8fd3a5787e01dc6f922f3a97bc2) - - - - - b33a20c5 by Moritz Angermann at 2020-07-15T23:51:39-04:00 Load .lo as well. Some archives contain so called linker objects, with the affectionate .lo suffic. For example the musl libc.a will come in that form. We still want to load those objects, hence we should not discard them and look for .lo as well. Ultimately we might want to fix this proerly by looking at the file magic. (cherry picked from commit 3fd12af1eaafe304e5916bc1fcfdf31709d360b8) - - - - - 6560fa8f by Moritz Angermann at 2020-07-15T23:52:20-04:00 Range is actually +/-2^32, not +/-2^31 See also: https://static.docs.arm.com/ihi0056/g/aaelf64.pdf (cherry picked from commit f2446ff1578a37822488e0e3968694f66712b969) - - - - - 820d9ed2 by Ben Gamari at 2020-07-15T23:55:55-04:00 testsuite: Add test for #18151 (cherry picked from commit bd9f558924755f965f5136b5e3d4fa88d34c9778) - - - - - be443156 by Ben Gamari at 2020-07-15T23:56:02-04:00 testsuite: Add test for desugaring of PostfixOperators (cherry picked from commit 95a9eb7396912314f6cfd971fb4523e4062acec6) - - - - - cc8800f9 by Ben Gamari at 2020-07-15T23:56:42-04:00 HsToCore: Eta expand left sections Strangely, the comment next to this code already alluded to the fact that even simply eta-expanding will sacrifice laziness. It's quite unclear how we regressed so far. See #18151. (cherry picked from commit b1dbd625493ae1bf984cf51177011baf9c677c0a) - - - - - 96a16275 by Ben Gamari at 2020-07-22T19:56:38-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. (cherry picked from commit 750a1595ef31cdc335f3bab045b2f19a9c43ff93) - - - - - 29d24d10 by Moritz Angermann at 2020-07-22T19:59:40-04:00 Disable DLL loading if without system linker Some platforms (musl, aarch64) do not have a working dynamic linker implemented in the libc, even though we might see dlopen. It will ultimately just return that this is not supported. Hence we'll add a flag to the compiler to flat our disable loading dlls. This is needed as we will otherwise try to load the shared library even if this will subsequently fail. At that point we have given up looking for static options though. (cherry picked from commit aef523ea1254e8bb9e4143ad8f5994ca89ea9d2d) - - - - - 9ab76ca5 by Sylvain Henry at 2020-07-22T20:47:38-04:00 Cmm: introduce SAVE_REGS/RESTORE_REGS We don't want to save both Fn and Dn register sets on x86-64 as they are aliased to the same arch register (XMMn). Moreover, when SAVE_STGREGS was used in conjunction with `jump foo [*]` which makes a set of Cmm registers alive so that they cover all arch registers used to pass parameter, we could have Fn, Dn and XMMn alive at the same time. It made the LLVM code generator choke (see #17920). Now `SAVE_REGS/RESTORE_REGS` and `jump foo [*]` use the same set of registers. (cherry picked from commit 54b595c1b91ad9e686b5baf7640177becb372336) - - - - - e447bd2c by Sylvain Henry at 2020-07-22T22:57:09-04:00 CmmToC: don't add extern decl to parsed Cmm data Previously, if a .cmm file *not in the RTS* contained something like: ```cmm section "rodata" { msg : bits8[] "Test\n"; } ``` It would get compiled by CmmToC into: ```c ERW_(msg); const char msg[] = "Test\012"; ``` and fail with: ``` /tmp/ghc32129_0/ghc_4.hc:5:12: error: error: conflicting types for \u2018msg\u2019 const char msg[] = "Test\012"; ^~~ In file included from /tmp/ghc32129_0/ghc_4.hc:3:0: error: /tmp/ghc32129_0/ghc_4.hc:4:6: error: note: previous declaration of \u2018msg\u2019 was here ERW_(msg); ^ /builds/hsyl20/ghc/_build/install/lib/ghc-8.11.0.20200605/lib/../lib/x86_64-linux-ghc-8.11.0.20200605/rts-1.0/include/Stg.h:253:46: error: note: in definition of macro \u2018ERW_\u2019 #define ERW_(X) extern StgWordArray (X) ^ ``` See the rationale for this on https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/backends/ppr-c#prototypes Now we don't generate these extern declarations (ERW_, etc.) for top-level data. It shouldn't change anything for the RTS (the only place we use .cmm files) as it is already special cased in `GHC.Cmm.CLabel.needsCDecl`. And hand-written Cmm can use explicit extern declarations when needed. Note that it allows `cgrun069` test to pass with CmmToC (cf #15467). (cherry picked from commit 499f3a2829d7c5a047c2ee87377d71ab2ea8c6d9) - - - - - f96a4b2c by Sylvain Henry at 2020-07-22T22:57:09-04:00 LLVM: refactor and comment register padding code (#17920) (cherry picked from commit 9bdc2a056f459b0e05ddbc49d978dfed547ecc13) - - - - - 36656d70 by Sylvain Henry at 2020-07-22T22:57:10-04:00 Add tests for #17920 Metric Decrease: T12150 T12234 (cherry picked from commit aa54d1a2b2d2c89107cfa77d8c14a50d6ee9c140) - - - - - b7c216cb by Ben Gamari at 2020-07-22T22:57:10-04:00 Fix GhcThreaded setting This adopts a patch from NetBSD's packaging fixing the `GhcThreaded` option of the make build system. In addition we introduce a `ghcThreaded` option in hadrian's `Flavour` type. Also fix Hadrian's treatment of the `Use Threaded` entry in `settings`. Previously it would incorrectly claim `Use Threaded = True` if we were building the `threaded` runtime way. However, this is inconsistent with the `make` build system, which defines it to be whether the `ghc` executable is linked against the threaded runtime. Fixes #17692. - - - - - 55fac768 by Travis Whitaker at 2020-07-22T22:57:10-04:00 Build a threaded stage 1 if the bootstrapping GHC supports it. (cherry picked from commit 67738db10010fd28a8e997b5c8f83ea591b88a0e) (cherry picked from commit a228d0a83db06fbe81b1c74fe3b1aea3133cee50) - - - - - 83bcf37d by Joshua Price at 2020-07-26T15:05:52-04:00 Make `identifier` parse unparenthesized `->` (#18060) (cherry picked from commit d6203f24cf421749616a247c047a9b44192f963a) - - - - - 50f25994 by Simon Peyton Jones at 2020-07-26T15:05:52-04:00 Wrap an implication around class-sig kind errors Ticket #17841 showed that we can get a kind error in a class signature, but lack an enclosing implication that binds its skolems. This patch * Adds the wrapping implication: the new call to checkTvConstraints in tcClassDecl1 * Simplifies the API to checkTvConstraints, which was not otherwise called at all. * Simplifies TcErrors.report_unsolved by *not* initialising the TidyEnv from the typechecker lexical envt. It's enough to do so from the free vars of the unsolved constraints; and we get silly renamings if we add variables twice: once from the lexical scope and once from the implication constraint. (cherry picked from commit 3f431587c2db712136a3b5a353758ca63e1a5fd8) - - - - - a063768e by Simon Peyton Jones at 2020-07-26T15:05:52-04:00 Refactoring in TcSMonad This patch is just refactoring: no change in behaviour. I removed the rather complicated checkConstraintsTcS checkTvConstraintsTcS in favour of simpler functions emitImplicationTcS emitTvImplicationTcS pushLevelNoWorkList The last of these is a little strange, but overall it's much better I think. (cherry picked from commit 9d87ced6832e75fce1e01b67bc6b7d9d1cf31efb) - - - - - 05be81e8 by Simon Peyton Jones at 2020-07-26T15:05:52-04:00 Major improvements to the specialiser This patch is joint work of Alexis King and Simon PJ. It does some significant refactoring of the type-class specialiser. Main highlights: * We can specialise functions with types like f :: Eq a => a -> Ord b => b => blah where the classes aren't all at the front (#16473). Here we can correctly specialise 'f' based on a call like f @Int @Bool dEqInt x dOrdBool This change really happened in an earlier patch commit 2d0cf6252957b8980d89481ecd0b79891da4b14b Author: Sandy Maguire <sandy at sandymaguire.me> Date: Thu May 16 12:12:10 2019 -0400 work that this new patch builds directly on that work, and refactors it a bit. * We can specialise functions with implicit parameters (#17930) g :: (?foo :: Bool, Show a) => a -> String Previously we could not, but now they behave just like a non-class argument as in 'f' above. * We can specialise under-saturated calls, where some (but not all of the dictionary arguments are provided (#17966). For example, we can specialise the above 'f' based on a call map (f @Int dEqInt) xs even though we don't (and can't) give Ord dictionary. This may sound exotic, but #17966 is a program from the wild, and showed significant perf loss for functions like f, if you need saturation of all dictionaries. * We fix a buglet in which a floated dictionary had a bogus demand (#17810), by using zapIdDemandInfo in the NonRec case of specBind. * A tiny side benefit: we can drop dead arguments to specialised functions; see Note [Drop dead args from specialisations] * Fixed a bug in deciding what dictionaries are "interesting"; see Note [Keep the old dictionaries interesting] This is all achieved by by building on Sandy Macguire's work in defining SpecArg, which mkCallUDs uses to describe the arguments of the call. Main changes: * Main work is in specHeader, which marched down the [InBndr] from the function definition and the [SpecArg] from the call site, together. * specCalls no longer has an arity check; the entire mechanism now handles unders-saturated calls fine. * mkCallUDs decides on an argument-by-argument basis whether to specialise a particular dictionary argument; this is new. See mk_spec_arg in mkCallUDs. It looks as if there are many more lines of code, but I think that all the extra lines are comments! (cherry picked from commit 7052d7c7ce3418db9e66ad6ff31e80b2a2c724bb) - - - - - a10c6ddf by Simon Peyton Jones at 2020-07-26T15:05:52-04:00 Fix specialisation for DFuns When specialising a DFun we must take care to saturate the unfolding. See Note [Specialising DFuns] in Specialise. Fixes #18120 (cherry picked from commit 88e3c8150d2b2d96c3ebc0b2942c9af44071c511) - - - - - 5015d3ac by Ben Gamari at 2020-07-26T15:05:52-04:00 testsuite: Accept wibbles in specialiser test output - - - - - 6471cc6a by Moritz Angermann at 2020-07-26T15:05:52-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. (cherry picked from commit aedfeb0b2b22172a0dfca0fe0c020ac80539d6ae) - - - - - 2e4fe920 by Stefan Schulze Frielinghaus at 2020-07-28T12:58:12-04:00 Require SMP support in order to build a threaded stage1 Fixes #18266 (cherry picked from commit fc0f6fbcd95f2dc69a8efabbee2d8a485c34cc47) - - - - - 4672b93e by Ben Gamari at 2020-07-29T22:59:54-04:00 base: Bump version for log1mexp fix - - - - - 9aa91006 by Ben Gamari at 2020-07-29T22:59:54-04:00 users-guide: Release notes for 8.10.2 - - - - - 7b82011a by Ben Gamari at 2020-07-29T22:59:54-04:00 Bump Cabal submodule - - - - - 750c51ba by Ben Gamari at 2020-07-29T22:59:54-04:00 Bump hsc2hs submodule to 0.68.7 - - - - - f34695e9 by Ben Gamari at 2020-07-30T10:48:10-04:00 Restore haskeline submodule to v0.8.0.0 It appears that this was incorrectly reverted in 4186c713e65dc5041d0b7a0e1d77f48edc763c3a. - - - - - 274989ff by Ben Gamari at 2020-07-30T10:48:10-04:00 users-guide: Mention LLVM version requirement - - - - - 484c4d89 by Ben Gamari at 2020-07-30T10:48:10-04:00 Use ld.gold to link on deb10 Otherwise we use ld.lld, which fails with ld.lld: error: -r and --export-dynamic may not be used together - - - - - bb0dae83 by Ben Gamari at 2020-07-30T10:48:10-04:00 Release GHC 8.10.2 - - - - - 81134748 by Ben Gamari at 2020-07-31T16:47:01-04:00 gitlab-ci: Build ARMv7 and AArch64 on Debian 10, not Debian 9 - - - - - fec2abb8 by Leon Schoorl at 2020-08-01T14:43:48-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 (cherry picked from commit a481afef354ca0383477fd20891c2e8eb9ef4449) - - - - - 428320a9 by Ben Gamari at 2020-08-03T17:51:43-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. (cherry picked from commit f9b7497d30d98a054d4ec5a8df2dfaf4a2b0bb30) - - - - - e69b0d42 by Ben Gamari at 2020-08-04T23:37:46-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - b260f31f by Ben Gamari at 2020-08-06T17:10:00-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. (cherry picked from commit a647bae8518e96156eb7775c4cede52b69f711d7) - - - - - 44f958c8 by Ben Gamari at 2020-08-06T17:10:00-04:00 testsuite: Add test for #18527 - - - - - 29204b1c by Ben Gamari at 2020-08-07T10:53:04-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. (cherry picked from commit d589ef25f54862968976bc279eb6748509794566) - - - - - 430e69ec by Ben Gamari at 2020-08-09T14:26:14-04:00 Set RELEASE=NO - - - - - fac083e7 by Ben Gamari at 2020-08-09T14:26:14-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit aa2e5863699306920513b216f337de09e29b5bb8. - - - - - 82f15edc by Ben Gamari at 2020-08-09T16:27:21-04:00 rts: Fix unused variable warning on Darwin - - - - - f43a255a by Ben Gamari at 2020-08-21T11:31:14-04:00 Bump text submodule to 1.2.4.0 Fixes #18588 and #17956. - - - - - 30 changed files: - .gitlab-ci.yml - + .gitlab/ci.sh - − .gitlab/prepare-system.sh - + .gitlab/test-metrics.sh - − .gitlab/win32-init.sh - aclocal.m4 - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - compiler/GHC/StgToCmm/Foreign.hs - compiler/GHC/StgToCmm/Prof.hs - compiler/GHC/StgToCmm/Ticky.hs - compiler/GHC/StgToCmm/Utils.hs - compiler/basicTypes/MkId.hs - compiler/basicTypes/RdrName.hs - compiler/cmm/CLabel.hs - compiler/cmm/Cmm.hs - compiler/cmm/CmmCallConv.hs - compiler/cmm/CmmMachOp.hs - compiler/cmm/CmmParse.y - compiler/cmm/PprC.hs - compiler/coreSyn/CorePrep.hs - compiler/coreSyn/CoreSubst.hs - compiler/coreSyn/CoreUnfold.hs - compiler/deSugar/Coverage.hs - compiler/deSugar/DsBinds.hs - compiler/deSugar/DsExpr.hs - compiler/deSugar/DsMeta.hs - compiler/ghc.cabal.in - compiler/ghc.mk The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/722cc2294120b297c9c824ee960c390f7d62e1ed...f43a255a660ce3f5571f84d5d608b150f57d4821 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/722cc2294120b297c9c824ee960c390f7d62e1ed...f43a255a660ce3f5571f84d5d608b150f57d4821 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 15:34:26 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Fri, 21 Aug 2020 11:34:26 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/backports Message-ID: <5f3fe9823296e_80bac4156c884168@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/backports at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/backports You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 15:35:09 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Fri, 21 Aug 2020 11:35:09 -0400 Subject: [Git][ghc/ghc][ghc-9.0] Accept spurious performance shift Message-ID: <5f3fe9adb1232_80b3f8469dd34488841855@gitlab.haskell.org.mail> Ben Gamari pushed to branch ghc-9.0 at Glasgow Haskell Compiler / GHC Commits: 1f6824a1 by Ben Gamari at 2020-08-21T11:35:00-04:00 Accept spurious performance shift Metric Decrease: T13035 - - - - - 0 changed files: Changes: View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1f6824a168c5ffebb9ef44b7933a667b7b813893 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1f6824a168c5ffebb9ef44b7933a667b7b813893 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 15:44:07 2020 From: gitlab at gitlab.haskell.org (Krzysztof Gogolewski) Date: Fri, 21 Aug 2020 11:44:07 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18594 Message-ID: <5f3febc76684f_80b3f8468db91988842033@gitlab.haskell.org.mail> Krzysztof Gogolewski pushed new branch wip/T18594 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18594 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 15:44:36 2020 From: gitlab at gitlab.haskell.org (Krzysztof Gogolewski) Date: Fri, 21 Aug 2020 11:44:36 -0400 Subject: [Git][ghc/ghc] Deleted branch wip/T18594 Message-ID: <5f3febe47b60f_80bac4156c88426aa@gitlab.haskell.org.mail> Krzysztof Gogolewski deleted branch wip/T18594 at Glasgow Haskell Compiler / GHC -- You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 15:59:20 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Fri, 21 Aug 2020 11:59:20 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18587 Message-ID: <5f3fef58a4c6d_80b3f8469dd344888460bf@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/T18587 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18587 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 18:26:07 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Fri, 21 Aug 2020 14:26:07 -0400 Subject: [Git][ghc/ghc][wip/T18126] Bump haddock submodule Message-ID: <5f4011bf123e5_80b3f84868578948870911@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T18126 at Glasgow Haskell Compiler / GHC Commits: e074f1bd by GHC GitLab CI at 2020-08-21T18:25:38+00:00 Bump haddock submodule Accounts for spurious changes in the output of hypsrc-test. - - - - - 1 changed file: - utils/haddock Changes: ===================================== utils/haddock ===================================== @@ -1 +1 @@ -Subproject commit 323aa89cbb4a3e8c8f32295e42a42635f05c849d +Subproject commit fc80404ca02553a92bc034bd37df730e835843c4 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e074f1bd5cab5796a093d1861fcbdf1974195f6e -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e074f1bd5cab5796a093d1861fcbdf1974195f6e You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 22:07:12 2020 From: gitlab at gitlab.haskell.org (Adam Gundry) Date: Fri, 21 Aug 2020 18:07:12 -0400 Subject: [Git][ghc/ghc][wip/amg/hasfield-2020] 657 commits: Fix unboxed-sums GC ptr-slot rubbish value (#17791) Message-ID: <5f404590981e8_80b3f84693c1eb488889b2@gitlab.haskell.org.mail> Adam Gundry pushed to branch wip/amg/hasfield-2020 at Glasgow Haskell Compiler / GHC Commits: 951c1fb0 by Sylvain Henry at 2020-05-09T21:46:38-04:00 Fix unboxed-sums GC ptr-slot rubbish value (#17791) This patch allows boot libraries to use unboxed sums without implicitly depending on `base` package because of `absentSumFieldError`. See updated Note [aBSENT_SUM_FIELD_ERROR_ID] in GHC.Core.Make - - - - - b352d63c by Ben Gamari at 2020-05-09T21:47:14-04:00 rts: Make non-existent linker search path merely a warning As noted in #18105, previously this resulted in a rather intrusive error message. This is in contrast to the general expectation that search paths are merely places to look, not places that must exist. Fixes #18105. - - - - - cf4f1e2f by Ben Gamari at 2020-05-13T02:02:33-04:00 rts/CNF: Fix fixup comparison function Previously we would implicitly convert the difference between two words to an int, resulting in an integer overflow on 64-bit machines. Fixes #16992 - - - - - a03da9bf by Ömer Sinan Ağacan at 2020-05-13T02:03:16-04:00 Pack some of IdInfo fields into a bit field This reduces residency of compiler quite a bit on some programs. Example stats when building T10370: Before: 2,871,242,832 bytes allocated in the heap 4,693,328,008 bytes copied during GC 33,941,448 bytes maximum residency (276 sample(s)) 375,976 bytes maximum slop 83 MiB total memory in use (0 MB lost due to fragmentation) After: 2,858,897,344 bytes allocated in the heap 4,629,255,440 bytes copied during GC 32,616,624 bytes maximum residency (278 sample(s)) 314,400 bytes maximum slop 80 MiB total memory in use (0 MB lost due to fragmentation) So -3.9% residency, -1.3% bytes copied and -0.4% allocations. Fixes #17497 Metric Decrease: T9233 T9675 - - - - - 670c3e5c by Ben Gamari at 2020-05-13T02:03:54-04:00 get-win32-tarballs: Fix base URL Revert a change previously made for testing purposes. - - - - - 8ad8dc41 by Ben Gamari at 2020-05-13T02:03:54-04:00 get-win32-tarballs: Improve diagnostics output - - - - - 8c0740b7 by Simon Jakobi at 2020-05-13T02:04:33-04:00 docs: Add examples for Data.Semigroup.Arg{Min,Max} Context: #17153 - - - - - cb22348f by Ben Gamari at 2020-05-13T02:05:11-04:00 Add few cleanups of the CAF logic Give the NameSet of non-CAFfy names a proper newtype to distinguish it from all of the other NameSets floating about. - - - - - 90e38b81 by Emeka Nkurumeh at 2020-05-13T02:05:51-04:00 fix printf warning when using with ghc with clang on mingw - - - - - 86d8ac22 by Sebastian Graf at 2020-05-13T02:06:29-04:00 CprAnal: Don't attach CPR sigs to expandable bindings (#18154) Instead, look through expandable unfoldings in `cprTransform`. See the new Note [CPR for expandable unfoldings]: ``` Long static data structures (whether top-level or not) like xs = x1 : xs1 xs1 = x2 : xs2 xs2 = x3 : xs3 should not get CPR signatures, because they * Never get WW'd, so their CPR signature should be irrelevant after analysis (in fact the signature might even be harmful for that reason) * Would need to be inlined/expanded to see their constructed product * Recording CPR on them blows up interface file sizes and is redundant with their unfolding. In case of Nested CPR, this blow-up can be quadratic! But we can't just stop giving DataCon application bindings the CPR property, for example fac 0 = 1 fac n = n * fac (n-1) fac certainly has the CPR property and should be WW'd! But FloatOut will transform the first clause to lvl = 1 fac 0 = lvl If lvl doesn't have the CPR property, fac won't either. But lvl doesn't have a CPR signature to extrapolate into a CPR transformer ('cprTransform'). So instead we keep on cprAnal'ing through *expandable* unfoldings for these arity 0 bindings via 'cprExpandUnfolding_maybe'. In practice, GHC generates a lot of (nested) TyCon and KindRep bindings, one for each data declaration. It's wasteful to attach CPR signatures to each of them (and intractable in case of Nested CPR). ``` Fixes #18154. - - - - - e34bf656 by Ben Gamari at 2020-05-13T02:07:08-04:00 users-guide: Add discussion of shared object naming Fixes #18074. - - - - - 5d0f2445 by Ben Gamari at 2020-05-13T02:07:47-04:00 testsuite: Print sign of performance changes Executes the minor formatting change in the tabulated performance changes suggested in #18135. - - - - - 9e4b981f by Ben Gamari at 2020-05-13T02:08:24-04:00 testsuite: Add testcase for #18129 - - - - - 266310c3 by Ivan-Yudin at 2020-05-13T02:09:03-04:00 doc: Reformulate the opening paragraph of Ch. 4 in User's guide Removes mentioning of Hugs (it is not helpful for new users anymore). Changes the wording for the rest of the paragraph. Fixes #18132. - - - - - 55e35c0b by Baldur Blöndal at 2020-05-13T20:02:48-04:00 Predicate, Equivalence derive via `.. -> a -> All' - - - - - d7e0b57f by Alp Mestanogullari at 2020-05-13T20:03:30-04:00 hadrian: add a --freeze2 option to freeze stage 1 and 2 - - - - - d880d6b2 by Artem Pelenitsyn at 2020-05-13T20:04:11-04:00 Don't reload environment files on every setSessionDynFlags Makes `interpretPackageEnv` (which loads envirinment files) a part of `parseDynamicFlags` (parsing command-line arguments, which is typically done once) instead of `setSessionDynFlags` (which is typically called several times). Making several (transitive) calls to `interpretPackageEnv`, as before, caused #18125 #16318, which should be fixed now. - - - - - 102cfd67 by Ryan Scott at 2020-05-13T20:04:46-04:00 Factor out HsPatSigType for pat sigs/RULE term sigs (#16762) This implements chunks (2) and (3) of https://gitlab.haskell.org/ghc/ghc/issues/16762#note_270170. Namely, it introduces a dedicated `HsPatSigType` AST type, which represents the types that can appear in pattern signatures and term-level `RULE` binders. Previously, these were represented with `LHsSigWcType`. Although `LHsSigWcType` is isomorphic to `HsPatSigType`, the intended semantics of the two types are slightly different, as evidenced by the fact that they have different code paths in the renamer and typechecker. See also the new `Note [Pattern signature binders and scoping]` in `GHC.Hs.Types`. - - - - - b17574f7 by Hécate at 2020-05-13T20:05:28-04:00 fix(documentation): Fix the RST links to GHC.Prim - - - - - df021fb1 by Baldur Blöndal at 2020-05-13T20:06:06-04:00 Document (->) using inferred quantification for its runtime representations. Fixes #18142. - - - - - 1a93ea57 by Takenobu Tani at 2020-05-13T20:06:54-04:00 Tweak man page for ghc command This commit updates the ghc command's man page as followings: * Enable `man_show_urls` to show URL addresses in the `DESCRIPTION` section of ghc.rst, because sphinx currently removes hyperlinks for man pages. * Add a `SEE ALSO` section to point to the GHC homepage - - - - - a951e1ba by Takenobu Tani at 2020-05-13T20:07:37-04:00 GHCi: Add link to the user's guide in help message This commit adds a link to the user's guide in ghci's `:help` message. Newcomers could easily reach to details of ghci. - - - - - 404581ea by Jeff Happily at 2020-05-13T20:08:15-04:00 Handle single unused import - - - - - 1c999e5d by Ben Gamari at 2020-05-13T20:09:07-04:00 Ensure that printMinimalImports closes handle Fixes #18166. - - - - - c9f5a8f4 by Ben Gamari at 2020-05-13T20:09:51-04:00 hadrian: Tell testsuite driver about LLVM availability This reflects the logic present in the Make build system into Hadrian. Fixes #18167. - - - - - c05c0659 by Simon Jakobi at 2020-05-14T03:31:21-04:00 Improve some folds over Uniq[D]FM * Replace some non-deterministic lazy folds with strict folds. * Replace some O(n log n) folds in deterministic order with O(n) non-deterministic folds. * Replace some folds with set-operations on the underlying IntMaps. This reduces max residency when compiling `nofib/spectral/simple/Main.hs` with -O0 by about 1%. Maximum residency when compiling Cabal also seems reduced on the order of 3-9%. - - - - - 477f13bb by Simon Jakobi at 2020-05-14T03:31:58-04:00 Use Data.IntMap.disjoint Data.IntMap gained a dedicated `disjoint` function in containers-0.6.2.1. This patch applies this function where appropriate in hopes of modest compiler performance improvements. Closes #16806. - - - - - e9c0110c by Ben Gamari at 2020-05-14T12:25:53-04:00 IdInfo: Add reference to bitfield-packing ticket - - - - - 9bd20e83 by Sebastian Graf at 2020-05-15T10:42:09-04:00 DmdAnal: Improve handling of precise exceptions This patch does two things: Fix possible unsoundness in what was called the "IO hack" and implement part 2.1 of the "fixing precise exceptions" plan in https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions, which, in combination with !2956, supersedes !3014 and !2525. **IO hack** The "IO hack" (which is a fallback to preserve precise exceptions semantics and thus soundness, rather than some smart thing that increases precision) is called `exprMayThrowPreciseException` now. I came up with two testcases exemplifying possible unsoundness (if twisted enough) in the old approach: - `T13380d`: Demonstrating unsoundness of the "IO hack" when resorting to manual state token threading and direct use of primops. More details below. - `T13380e`: Demonstrating unsoundness of the "IO hack" when we have Nested CPR. Not currently relevant, as we don't have Nested CPR yet. - `T13380f`: Demonstrating unsoundness of the "IO hack" for safe FFI calls. Basically, the IO hack assumed that precise exceptions can only be thrown from a case scrutinee of type `(# State# RealWorld, _ #)`. I couldn't come up with a program using the `IO` abstraction that violates this assumption. But it's easy to do so via manual state token threading and direct use of primops, see `T13380d`. Also similar code might be generated by Nested CPR in the (hopefully not too) distant future, see `T13380e`. Hence, we now have a more careful test in `forcesRealWorld` that passes `T13380{d,e}` (and will hopefully be robust to Nested CPR). **Precise exceptions** In #13380 and #17676 we saw that we didn't preserve precise exception semantics in demand analysis. We fixed that with minimal changes in !2956, but that was terribly unprincipled. That unprincipledness resulted in a loss of precision, which is tracked by these new test cases: - `T13380b`: Regression in dead code elimination, because !2956 was too syntactic about `raiseIO#` - `T13380c`: No need to apply the "IO hack" when the IO action may not throw a precise exception (and the existing IO hack doesn't detect that) Fixing both issues in !3014 turned out to be too complicated and had the potential to regress in the future. Hence we decided to only fix `T13380b` and augment the `Divergence` lattice with a new middle-layer element, `ExnOrDiv`, which means either `Diverges` (, throws an imprecise exception) or throws a *precise* exception. See the wiki page on Step 2.1 for more implementational details: https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions#dead-code-elimination-for-raiseio-with-isdeadenddiv-introducing-exnordiv-step-21 - - - - - 568d7279 by Ben Gamari at 2020-05-15T10:42:46-04:00 GHC.Cmm.Opt: Handle MO_XX_Conv This MachOp was introduced by 2c959a1894311e59cd2fd469c1967491c1e488f3 but a wildcard match in cmmMachOpFoldM hid the fact that it wasn't handled. Ideally we would eliminate the match but this appears to be a larger task. Fixes #18141. - - - - - 5bcf8606 by Ryan Scott at 2020-05-17T08:46:38-04:00 Remove duplicate Note [When to print foralls] in GHC.Core.TyCo.Ppr There are two different Notes named `[When to print foralls]`. The most up-to-date one is in `GHC.Iface.Type`, but there is a second one in `GHC.Core.TyCo.Ppr`. The latter is less up-to-date, as it was written before GHC switched over to using ifaces to pretty-print types. I decided to just remove the latter and replace it with a reference to the former. [ci skip] - - - - - 55f0e783 by Fumiaki Kinoshita at 2020-05-21T12:10:44-04:00 base: Add Generic instances to various datatypes under GHC.* * GHC.Fingerprint.Types: Fingerprint * GHC.RTS.Flags: GiveGCStats, GCFlags, ConcFlags, DebugFlags, CCFlags, DoHeapProfile, ProfFlags, DoTrace, TraceFlags, TickyFlags, ParFlags and RTSFlags * GHC.Stats: RTSStats and GCStats * GHC.ByteOrder: ByteOrder * GHC.Unicode: GeneralCategory * GHC.Stack.Types: SrcLoc Metric Increase: haddock.base - - - - - a9311cd5 by Gert-Jan Bottu at 2020-05-21T12:11:31-04:00 Explicit Specificity Implementation for Ticket #16393. Explicit specificity allows users to manually create inferred type variables, by marking them with braces. This way, the user determines which variables can be instantiated through visible type application. The additional syntax is included in the parser, allowing users to write braces in type variable binders (type signatures, data constructors etc). This information is passed along through the renamer and verified in the type checker. The AST for type variable binders, data constructors, pattern synonyms, partial signatures and Template Haskell has been updated to include the specificity of type variables. Minor notes: - Bumps haddock submodule - Disables pattern match checking in GHC.Iface.Type with GHC 8.8 - - - - - 24e61aad by Ben Price at 2020-05-21T12:12:17-04:00 Lint should say when it is checking a rule It is rather confusing that when lint finds an error in a rule attached to a binder, it reports the error as in the RHS, not the rule: ... In the RHS of foo We add a clarifying line: ... In the RHS of foo In a rule attached to foo The implication that the rule lives inside the RHS is a bit odd, but this niggle is already present for unfoldings, whose pattern we are following. - - - - - 78c6523c by Ben Gamari at 2020-05-21T12:13:01-04:00 nonmoving: Optimise the write barrier - - - - - 13f6c9d0 by Andreas Klebinger at 2020-05-21T12:13:45-04:00 Refactor linear reg alloc to remember past assignments. When assigning registers we now first try registers we assigned to in the past, instead of picking the "first" one. This is in extremely helpful when dealing with loops for which variables are dead for part of the loop. This is important for patterns like this: foo = arg1 loop: use(foo) ... foo = getVal() goto loop; There we: * assign foo to the register of arg1. * use foo, it's dead after this use as it's overwritten after. * do other things. * look for a register to put foo in. If we pick an arbitrary one it might differ from the register the start of the loop expect's foo to be in. To fix this we simply look for past register assignments for the given variable. If we find one and the register is free we use that register. This reduces the need for fixup blocks which match the register assignment between blocks. In the example above between the end and the head of the loop. This patch also moves branch weight estimation ahead of register allocation and adds a flag to control it (cmm-static-pred). * It means the linear allocator is more likely to assign the hotter code paths first. * If it assign these first we are: + Less likely to spill on the hot path. + Less likely to introduce fixup blocks on the hot path. These two measure combined are surprisingly effective. Based on nofib we get in the mean: * -0.9% instructions executed * -0.1% reads/writes * -0.2% code size. * -0.1% compiler allocations. * -0.9% compile time. * -0.8% runtime. Most of the benefits are simply a result of removing redundant moves and spills. Reduced compiler allocations likely are the result of less code being generated. (The added lookup is mostly non-allocating). - - - - - edc2cc58 by Andreas Klebinger at 2020-05-21T12:14:25-04:00 NCG: Codelayout: Distinguish conditional and other branches. In #18053 we ended up with a suboptimal code layout because the code layout algorithm didn't distinguish between conditional and unconditional control flow. We can completely eliminate unconditional control flow instructions by placing blocks next to each other, not so much for conditionals. In terms of implementation we simply give conditional branches less weight before computing the layout. Fixes #18053 - - - - - b7a6b2f4 by Gleb Popov at 2020-05-21T12:15:26-04:00 gitlab-ci: Set locale to C.UTF-8. - - - - - a8c27cf6 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Allow spaces in GHCi :script file names This patch updates the user interface of GHCi so that file names passed to the ':script' command may contain spaces escaped with a backslash. For example: :script foo\ bar.script The implementation uses a modified version of 'words' that does not break on escaped spaces. Fixes #18027. - - - - - 82663959 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Add extra tests for GHCi :script syntax checks The syntax for GHCi's ":script" command allows for only a single file name to be passed as an argument. This patch adds a test for the cases in which a file name is missing or multiple file names are passed. Related to #T18027. - - - - - a0b79e1b by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Allow GHCi :script file names in double quotes This patch updates the user interface of GHCi so that file names passed to the ':script' command can be wrapped in double quotes. For example: :script "foo bar.script" The implementation uses a modified version of 'words' that treats character sequences enclosed in double quotes as single words. Fixes #18027. - - - - - cf566330 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Update documentation for GHCi :script This patch adds the fixes that allow for file names containing spaces to be passed to GHCi's ':script' command to the release notes for 8.12 and expands the user-guide documentation for ':script' by mentioning how such file names can be passed. Related to #18027. - - - - - 0004ccb8 by Tuan Le at 2020-05-21T12:16:46-04:00 llvmGen: Consider Relocatable read-only data as not constantReferences: #18137 - - - - - 964d3ea2 by John Ericson at 2020-05-21T12:17:30-04:00 Use `Checker` for `tc_pat` - - - - - b797aa42 by John Ericson at 2020-05-21T12:17:30-04:00 Use `Checker` for `tc_lpat` and `tc_lpats` - - - - - 5108e84a by John Ericson at 2020-05-21T12:17:30-04:00 More judiciously panic in `ts_pat` - - - - - 510e0451 by John Ericson at 2020-05-21T12:17:30-04:00 Put `PatEnv` first in `GHC.Tc.Gen.Pat.Checker` - - - - - cb4231db by John Ericson at 2020-05-21T12:17:30-04:00 Tiny cleaup eta-reduce away a function argument In GHC, not in the code being compiled! - - - - - 6890c38d by John Ericson at 2020-05-21T12:17:30-04:00 Use braces with do in `SplicePat` case for consistency - - - - - 3451584f by buggymcbugfix at 2020-05-21T12:18:06-04:00 Fix spelling mistakes and typos - - - - - b552e531 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Add INLINABLE pragmas to Enum list producers The INLINABLE pragmas ensure that we export stable (unoptimised) unfoldings in the interface file so we can do list fusion at usage sites. Related tickets: #15185, #8763, #18178. - - - - - e7480063 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Piggyback on Enum Word methods for Word64 If we are on a 64 bit platform, we can use the efficient Enum Word methods for the Enum Word64 instance. - - - - - 892b0c41 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Document INLINE(ABLE) pragmas that enable fusion - - - - - 2b363ebb by Richard Eisenberg at 2020-05-21T12:18:45-04:00 MR template should ask for key part - - - - - a95bbd0b by Sebastian Graf at 2020-05-21T12:19:37-04:00 Make `Int`'s `mod` and `rem` strict in their first arguments They used to be strict until 4d2ac2d (9 years ago). It's obviously better to be strict for performance reasons. It also blocks #18067. NoFib results: ``` -------------------------------------------------------------------------------- Program Allocs Instrs -------------------------------------------------------------------------------- integer -1.1% +0.4% wheel-sieve2 +21.2% +20.7% -------------------------------------------------------------------------------- Min -1.1% -0.0% Max +21.2% +20.7% Geometric Mean +0.2% +0.2% ``` The regression in `wheel-sieve2` is due to reboxing that likely will go away with the resolution of #18067. See !3282 for details. Fixes #18187. - - - - - d3d055b8 by Galen Huntington at 2020-05-21T12:20:18-04:00 Clarify pitfalls of NegativeLiterals; see #18022. - - - - - 1b508a9e by Alexey Kuleshevich at 2020-05-21T12:21:02-04:00 Fix wording in primops documentation to reflect the correct reasoning: * Besides resizing functions, shrinking ones also mutate the size of a mutable array and because of those two `sizeofMutabeByteArray` and `sizeofSmallMutableArray` are now deprecated * Change reference in documentation to the newer functions `getSizeof*` instead of `sizeof*` for shrinking functions * Fix incorrect mention of "byte" instead of "small" - - - - - 4ca0c8a1 by Andreas Klebinger at 2020-05-21T12:21:53-04:00 Don't variable-length encode magic iface constant. We changed to use variable length encodings for many types by default, including Word32. This makes sense for numbers but not when Word32 is meant to represent four bytes. I added a FixedLengthEncoding newtype to Binary who's instances interpret their argument as a collection of bytes instead of a number. We then use this when writing/reading magic numbers to the iface file. I also took the libery to remove the dummy iface field. This fixes #18180. - - - - - a1275081 by Krzysztof Gogolewski at 2020-05-21T12:22:35-04:00 Add a regression test for #11506 The testcase works now. See explanation in https://gitlab.haskell.org/ghc/ghc/issues/11506#note_273202 - - - - - 8a816e5f by Krzysztof Gogolewski at 2020-05-21T12:23:55-04:00 Sort deterministically metric output Previously, we sorted according to the test name and way, but the metrics (max_bytes_used/peak_megabytes_allocated etc.) were appearing in nondeterministic order. - - - - - 566cc73f by Sylvain Henry at 2020-05-21T12:24:45-04:00 Move isDynLinkName into GHC.Types.Name It doesn't belong into GHC.Unit.State - - - - - d830bbc9 by Adam Sandberg Ericsson at 2020-05-23T13:36:20-04:00 docs: fix formatting and add some links [skip ci] - - - - - 49301ad6 by Andrew Martin at 2020-05-23T13:37:01-04:00 Implement cstringLength# and FinalPtr This function and its accompanying rule resolve issue #5218. A future PR to the bytestring library will make the internal Data.ByteString.Internal.unsafePackAddress compute string length with cstringLength#. This will improve the status quo because it is eligible for constant folding. Additionally, introduce a new data constructor to ForeignPtrContents named FinalPtr. This additional data constructor, when used in the IsString instance for ByteString, leads to more Core-to-Core optimization opportunities, fewer runtime allocations, and smaller binaries. Also, this commit re-exports all the functions from GHC.CString (including cstringLength#) in GHC.Exts. It also adds a new test driver. This test driver is used to perform substring matches on Core that is dumped after all the simplifier passes. In this commit, it is used to check that constant folding of cstringLength# works. - - - - - dcd6bdcc by Ben Gamari at 2020-05-23T13:37:48-04:00 simplCore: Ignore ticks in rule templates This fixes #17619, where a tick snuck in to the template of a rule, resulting in a panic during rule matching. The tick in question was introduced via post-inlining, as discussed in `Note [Simplifying rules]`. The solution we decided upon was to simply ignore ticks in the rule template, as discussed in `Note [Tick annotations in RULE matching]`. Fixes #18162. Fixes #17619. - - - - - 82cb8913 by John Ericson at 2020-05-23T13:38:32-04:00 Fix #18145 and also avoid needless work with implicit vars - `forAllOrNothing` now is monadic, so we can trace whether we bind an explicit `forall` or not. - #18145 arose because the free vars calculation was needlessly complex. It is now greatly simplified. - Replaced some other implicit var code with `filterFreeVarsToBind`. Co-authored-by: Ryan Scott <ryan.gl.scott at gmail.com> - - - - - a60dc835 by Ben Gamari at 2020-05-23T13:39:12-04:00 Bump process submodule Fixes #17926. - - - - - 856adf54 by Ben Gamari at 2020-05-23T13:40:21-04:00 users-guide: Clarify meaning of -haddock flag Fixes #18206. - - - - - 7ae57afd by Ben Gamari at 2020-05-23T13:41:03-04:00 git: Add ignored commits file This can be used to tell git to ignore bulk renaming commits like the recently-finished module hierarchy refactoring. Configured with, git config blame.ignoreRevsFile .git-ignore-revs - - - - - 63d30e60 by jneira at 2020-05-24T01:54:42-04:00 Add hie-bios script for windows systems It is a direct translation of the sh script - - - - - 59182b88 by jneira at 2020-05-24T01:54:42-04:00 Honour previous values for CABAL and CABFLAGS The immediate goal is let the hie-bios.bat script set CABFLAGS with `-v0` and remove all cabal output except the compiler arguments - - - - - 932dc54e by jneira at 2020-05-24T01:54:42-04:00 Add specific configuration for windows in hie.yaml - - - - - e0eda070 by jneira at 2020-05-24T01:54:42-04:00 Remove not needed hie-bios output - - - - - a0ea59d6 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Move Config module into GHC.Settings - - - - - 37430251 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Rename GHC.Core.Arity into GHC.Core.Opt.Arity - - - - - a426abb9 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Rename GHC.Hs.Types into GHC.Hs.Type See discussion in https://gitlab.haskell.org/ghc/ghc/issues/13009#note_268610 - - - - - 1c91a7a0 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Bump haddock submodule - - - - - 66bd24d1 by Ryan Scott at 2020-05-24T01:56:03-04:00 Add orderingTyCon to wiredInTyCons (#18185) `Ordering` needs to be wired in for use in the built-in `CmpNat` and `CmpSymbol` type families, but somehow it was never added to the list of `wiredInTyCons`, leading to the various oddities observed in #18185. Easily fixed by moving `orderingTyCon` from `basicKnownKeyNames` to `wiredInTyCons`. Fixes #18185. - - - - - 01c43634 by Matthew Pickering at 2020-05-24T01:56:42-04:00 Remove unused hs-boot file - - - - - 7a07aa71 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix cross-compiler build (#16051) - - - - - 15ccca16 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix distDir per stage - - - - - b420fb24 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix hp2ps error during cross-compilation Fixed by @alp (see https://gitlab.haskell.org/ghc/ghc/issues/16051#note_274265) - - - - - cd339ef0 by Joshua Price at 2020-05-24T15:22:56-04:00 Make Unicode brackets opening/closing tokens (#18225) The tokens `[|`, `|]`, `(|`, and `|)` are opening/closing tokens as described in GHC Proposal #229. This commit makes the unicode variants (`⟦`, `⟧`, `⦇`, and `⦈`) act the same as their ASCII counterparts. - - - - - 013d7120 by Ben Gamari at 2020-05-25T09:48:17-04:00 Revert "Specify kind variables for inferred kinds in base." As noted in !3132, this has rather severe knock-on consequences in user-code. We'll need to revisit this before merging something along these lines. This reverts commit 9749fe1223d182b1f8e7e4f7378df661c509f396. - - - - - 4c4312ed by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Drop redundant ad-hoc boot module check To determine whether the module is a boot module Coverage.addTicksToBinds was checking for a `boot` suffix in the module source filename. This is quite ad-hoc and shouldn't be necessary; the callsite in `deSugar` already checks that the module isn't a boot module. - - - - - 1abf3c84 by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Make tickBoxCount strict This could otherwise easily cause a leak of (+) thunks. - - - - - b2813750 by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Make ccIndices strict This just seems like a good idea. - - - - - 02e278eb by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Don't produce ModBreaks if not HscInterpreted emptyModBreaks contains a bottom and consequently it's important that we don't use it unless necessary. - - - - - b8c014ce by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Factor out addMixEntry - - - - - 53814a64 by Zubin Duggal at 2020-05-26T03:03:24-04:00 Add info about typeclass evidence to .hie files See `testsuite/tests/hiefile/should_run/HieQueries.hs` and `testsuite/tests/hiefile/should_run/HieQueries.stdout` for an example of this We add two new fields, `EvidenceVarBind` and `EvidenceVarUse` to the `ContextInfo` associated with an Identifier. These are associated with the appropriate identifiers for the evidence variables collected when we come across `HsWrappers`, `TcEvBinds` and `IPBinds` while traversing the AST. Instance dictionary and superclass selector dictionaries from `tcg_insts` and classes defined in `tcg_tcs` are also recorded in the AST as originating from their definition span This allows us to save a complete picture of the evidence constructed by the constraint solver, and will let us report this to the user, enabling features like going to the instance definition from the invocation of a class method(or any other method taking a constraint) and finding all usages of a particular instance. Additionally, - Mark NodeInfo with an origin so we can differentiate between bindings origininating in the source vs those in ghc - Along with typeclass evidence info, also include information on Implicit Parameters - Add a few utility functions to HieUtils in order to query the new info Updates haddock submodule - - - - - 6604906c by Sebastian Graf at 2020-05-26T03:04:04-04:00 Make WorkWrap.Lib.isWorkerSmallEnough aware of the old arity We should allow a wrapper with up to 82 parameters when the original function had 82 parameters to begin with. I verified that this made no difference on NoFib, but then again it doesn't use huge records... Fixes #18122. - - - - - cf772f19 by Sylvain Henry at 2020-05-26T03:04:45-04:00 Enhance Note [About units] for Backpack - - - - - ede24126 by Takenobu Tani at 2020-05-27T00:13:55-04:00 core-spec: Modify file paths according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * GHC/Core.hs <= coreSyn/CoreSyn.hs * GHC/Core/Coercion.hs <= types/Coercion.hs * GHC/Core/Coercion/Axiom.hs <= types/CoAxiom.hs * GHC/Core/Coercion/Opt.hs <= types/OptCoercion.hs * GHC/Core/DataCon.hs <= basicTypes/DataCon.hs * GHC/Core/FamInstEnv.hs <= types/FamInstEnv.hs * GHC/Core/Lint.hs <= coreSyn/CoreLint.hs * GHC/Core/Subst.hs <= coreSyn/CoreSubst.hs * GHC/Core/TyCo/Rep.hs <= types/TyCoRep.hs * GHC/Core/TyCon.hs <= types/TyCon.hs * GHC/Core/Type.hs <= types/Type.hs * GHC/Core/Unify.hs <= types/Unify.hs * GHC/Types/Literal.hs <= basicTypes/Literal.hs * GHC/Types/Var.hs <= basicTypes/Var.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [skip ci] - - - - - 04750304 by Ben Gamari at 2020-05-27T00:14:33-04:00 eventlog: Fix racy flushing Previously no attempt was made to avoid multiple threads writing their capability-local eventlog buffers to the eventlog writer simultaneously. This could result in multiple eventlog streams being interleaved. Fix this by documenting that the EventLogWriter's write() and flush() functions may be called reentrantly and fix the default writer to protect its FILE* by a mutex. Fixes #18210. - - - - - d6203f24 by Joshua Price at 2020-05-27T00:15:17-04:00 Make `identifier` parse unparenthesized `->` (#18060) - - - - - 28deee28 by Ben Gamari at 2020-05-28T16:23:21-04:00 GHC.Core.Unfold: Refactor traceInline This reduces duplication as well as fixes a bug wherein -dinlining-check would override -ddump-inlinings. Moreover, the new variant - - - - - 1f393e1e by Ben Gamari at 2020-05-28T16:23:21-04:00 Avoid unnecessary allocations due to tracing utilities While ticky-profiling the typechecker I noticed that hundreds of millions of SDocs are being allocated just in case -ddump-*-trace is enabled. This is awful. We avoid this by ensuring that the dump flag check is inlined into the call site, ensuring that the tracing document needn't be allocated unless it's actually needed. See Note [INLINE conditional tracing utilities] for details. Fixes #18168. Metric Decrease: T9961 haddock.Cabal haddock.base haddock.compiler - - - - - 5f621a78 by Vladislav Zavialov at 2020-05-28T16:23:58-04:00 Add Semigroup/Monoid for Q (#18123) - - - - - dc5f004c by Xavier Denis at 2020-05-28T16:24:37-04:00 Fix #18071 Run the core linter on candidate instances to ensure they are well-kinded. Better handle quantified constraints by using a CtWanted to avoid having unsolved constraints thrown away at the end by the solver. - - - - - 10e6982c by Sebastian Graf at 2020-05-28T16:25:14-04:00 FloatOut: Only eta-expand dead-end RHS if arity will increase (#18231) Otherwise we risk turning trivial RHS into non-trivial RHS, introducing unnecessary bindings in the next Simplifier run, resulting in more churn. Fixes #18231. - - - - - 08dab5f7 by Sebastian Graf at 2020-05-28T16:25:14-04:00 DmdAnal: Recognise precise exceptions from case alternatives (#18086) Consider ```hs m :: IO () m = do putStrLn "foo" error "bar" ``` `m` (from #18086) always throws a (precise or imprecise) exception or diverges. Yet demand analysis infers `<L,A>` as demand signature instead of `<L,A>x` for it. That's because the demand analyser sees `putStrLn` occuring in a case scrutinee and decides that it has to `deferAfterPreciseException`, because `putStrLn` throws a precise exception on some control flow paths. This will mask the `botDiv` `Divergence`of the single case alt containing `error` to `topDiv`. Since `putStrLn` has `topDiv` itself, the final `Divergence` is `topDiv`. This is easily fixed: `deferAfterPreciseException` works by `lub`ing with the demand type of a virtual case branch denoting the precise exceptional control flow. We used `nopDmdType` before, but we can be more precise and use `exnDmdType`, which is `nopDmdType` with `exnDiv`. Now the `Divergence` from the case alt will degrade `botDiv` to `exnDiv` instead of `topDiv`, which combines with the result from the scrutinee to `exnDiv`, and all is well. Fixes #18086. - - - - - aef95f11 by Ben Gamari at 2020-05-28T16:25:53-04:00 Ticky-ticky: Record DataCon name in ticker name This makes it significantly easier to spot the nature of allocations regressions and comes at a reasonably low cost. - - - - - 8f021b8c by Ben Gamari at 2020-05-28T16:26:34-04:00 hadrian: Don't track GHC's verbosity argument Teach hadrian to ignore GHC's -v argument in its recompilation check, thus fixing #18131. - - - - - 13d9380b by Ben Gamari at 2020-05-28T16:27:20-04:00 Rip out CmmStackInfo(updfr_space) As noted in #18232, this field is currently completely unused and moreover doesn't have a clear meaning. - - - - - f10d11fa by Andreas Klebinger at 2020-05-29T01:38:42-04:00 Fix "build/elem" RULE. An redundant constraint prevented the rule from matching. Fixing this allows a call to elem on a known list to be translated into a series of equality checks, and eventually a simple case expression. Surprisingly this seems to regress elem for strings. To avoid this we now also allow foldrCString to inline and add an UTF8 variant. This results in elem being compiled to a tight non-allocating loop over the primitive string literal which performs a linear search. In the process this commit adds UTF8 variants for some of the functions in GHC.CString. This is required to make this work for both ASCII and UTF8 strings. There are also small tweaks to the CString related rules. We now allow ourselfes the luxury to compare the folding function via eqExpr, which helps to ensure the rule fires before we inline foldrCString*. Together with a few changes to allow matching on both the UTF8 and ASCII variants of the CString functions. - - - - - bbeb2389 by Ben Gamari at 2020-05-29T01:39:19-04:00 CoreToStg: Add Outputable ArgInfo instance - - - - - 0e3361ca by Simon Peyton Jones at 2020-05-29T01:39:19-04:00 Make Lint check return type of a join point Consider join x = rhs in body It's important that the type of 'rhs' is the same as the type of 'body', but Lint wasn't checking that invariant. Now it does! This was exposed by investigation into !3113. - - - - - c49f7df0 by Simon Peyton Jones at 2020-05-29T01:39:19-04:00 Do not float join points in exprIsConApp_maybe We hvae been making exprIsConApp_maybe cleverer in recent times: commit b78cc64e923716ac0512c299f42d4d0012306c05 Date: Thu Nov 15 17:14:31 2018 +0100 Make constructor wrappers inline only during the final phase commit 7833cf407d1f608bebb1d38bb99d3035d8d735e6 Date: Thu Jan 24 17:58:50 2019 +0100 Look through newtype wrappers (Trac #16254) commit c25b135ff5b9c69a90df0ccf51b04952c2dc6ee1 Date: Thu Feb 21 12:03:22 2019 +0000 Fix exprIsConApp_maybe But alas there was still a bug, now immortalised in Note [Don't float join points] in SimpleOpt. It's quite hard to trigger because it requires a dead join point, but it came up when compiling Cabal Cabal.Distribution.Fields.Lexer.hs, when working on !3113. Happily, the fix is extremly easy. Finding the bug was not so easy. - - - - - 46720997 by Ben Gamari at 2020-05-29T01:39:19-04:00 Allow simplification through runRW# Because runRW# inlines so late, we were previously able to do very little simplification across it. For instance, given even a simple program like case runRW# (\s -> let n = I# 42# in n) of I# n# -> f n# we previously had no way to avoid the allocation of the I#. This patch allows the simplifier to push strict contexts into the continuation of a runRW# application, as explained in in Note [Simplification of runRW#] in GHC.CoreToStg.Prep. Fixes #15127. Metric Increase: T9961 Metric Decrease: ManyConstructors Co-Authored-By: Simon Peyton-Jone <simonpj at microsoft.com> - - - - - 277c2f26 by Ben Gamari at 2020-05-29T01:39:55-04:00 Eta expand un-saturated primops Now since we no longer try to predict CAFfyness we have no need for the solution to #16846. Eta expanding unsaturated primop applications is conceptually simpler, especially in the presence of levity polymorphism. This essentially reverts cac8dc9f51e31e4c0a6cd9bc302f7e1bc7c03beb, as suggested in #18079. Closes #18079. - - - - - f44d7ae0 by Simon Jakobi at 2020-05-29T01:40:34-04:00 base: Scrap deprecation plan for Data.Monoid.{First,Last} See the discussion on the libraries mailing list for context: https://mail.haskell.org/pipermail/libraries/2020-April/030357.html - - - - - 8b494895 by Jeremy Schlatter at 2020-05-29T01:41:12-04:00 Fix typo in documentation - - - - - 998450f4 by Gleb Popov at 2020-05-29T01:41:53-04:00 Always define USE_PTHREAD_FOR_ITIMER for FreeBSD. - - - - - f9a513e0 by Alp Mestanogullari at 2020-05-29T01:42:36-04:00 hadrian: introduce 'install' target Its logic is very simple. It `need`s the `binary-dist-dir` target and runs suitable `configure` and `make install` commands for the user. A new `--prefix` command line argument is introduced to specify where GHC should be installed. - - - - - 67738db1 by Travis Whitaker at 2020-05-29T13:34:48-04:00 Build a threaded stage 1 if the bootstrapping GHC supports it. - - - - - aac19e6c by Peter Trommler at 2020-05-29T13:35:24-04:00 PPC NCG: No per-symbol .section ".toc" directives All position independent symbols are collected during code generation and emitted in one go. Prepending each symbol with a .section ".toc" directive is redundant. This patch drops the per-symbol directives leading to smaller assembler files. Fixes #18250 - - - - - 4413828b by Ben Gamari at 2020-05-30T06:07:31-04:00 rts: Teach getNumProcessors to return available processors Previously we would report the number of physical processors, which can be quite wrong in a containerized setting. Now we rather return how many processors are in our affinity mask when possible. I also refactored the code to prefer platform-specific since this will report logical CPUs instead of physical (using `machdep.cpu.thread_count` on Darwin and `cpuset_getaffinity` on FreeBSD). Fixes #14781. - - - - - 1449435c by Ben Gamari at 2020-05-30T06:07:31-04:00 users-guide: Note change in getNumProcessors in users guide - - - - - 3d960169 by Ben Gamari at 2020-05-30T06:07:31-04:00 rts: Drop compatibility shims for Windows Vista We can now assume that the thread and processor group interfaces are available. - - - - - 7f8f948c by Peter Trommler at 2020-05-30T06:08:07-04:00 PPC NCG: Fix .size directive on powerpc64 ELF v1 Thanks to Sergei Trofimovich for pointing out the issue. Fixes #18237 - - - - - 7c555b05 by Andreas Klebinger at 2020-05-30T06:08:43-04:00 Optimize GHC.Utils.Monad. Many functions in this module are recursive and as such are marked loop breakers. Which means they are unlikely to get an unfolding. This is *bad*. We always want to specialize them to specific Monads. Which requires a visible unfolding at the use site. I rewrote the recursive ones from: foo f x = ... foo x' ... to foo f x = go x where go x = ... As well as giving some pragmas to make all of them available for specialization. The end result is a reduction of allocations of about -1.4% for nofib/spectral/simple/Main.hs when compiled with `-O`. ------------------------- Metric Decrease: T12425 T14683 T5631 T9233 T9675 T9961 WWRec ------------------------- - - - - - 8b1cb5df by Ben Gamari at 2020-05-30T06:09:20-04:00 Windows: Bump Windows toolchain to 0.2 - - - - - 6947231a by Zubin Duggal at 2020-05-30T06:10:02-04:00 Simplify contexts in GHC.Iface.Ext.Ast - - - - - 2ee4f36c by Daniel Gröber at 2020-06-01T06:32:56-04:00 Cleanup OVERWRITING_CLOSURE logic The code is just more confusing than it needs to be. We don't need to mix the threaded check with the ldv profiling check since ldv's init already checks for this. Hence they can be two separate checks. Taking the sanity checking into account is also cleaner via DebugFlags.sanity. No need for checking the DEBUG define. The ZERO_SLOP_FOR_LDV_PROF and ZERO_SLOP_FOR_SANITY_CHECK definitions the old code had also make things a lot more opaque IMO so I removed those. - - - - - 6159559b by Daniel Gröber at 2020-06-01T06:32:56-04:00 Fix OVERWRITING_CLOSURE assuming closures are not inherently used The new ASSERT in LDV_recordDead() was being tripped up by MVars when removeFromMVarBlockedQueue() calls OVERWRITING_CLOSURE() via OVERWRITE_INFO(). - - - - - 38992085 by Daniel Gröber at 2020-06-01T06:32:56-04:00 Always zero shrunk mutable array slop when profiling When shrinking arrays in the profiling way we currently don't always zero the leftover slop. This means we can't traverse such closures in the heap profiler. The old Note [zeroing slop] and #8402 have some rationale for why this is so but I belive the reasoning doesn't apply to mutable closures. There users already have to ensure multiple threads don't step on each other's toes so zeroing should be safe. - - - - - b0c1f2a6 by Ben Gamari at 2020-06-01T06:33:37-04:00 testsuite: Add test for #18151 - - - - - 9a99a178 by Ben Gamari at 2020-06-01T06:33:37-04:00 testsuite: Add test for desugaring of PostfixOperators - - - - - 2b89ca5b by Ben Gamari at 2020-06-01T06:33:37-04:00 HsToCore: Eta expand left sections Strangely, the comment next to this code already alluded to the fact that even simply eta-expanding will sacrifice laziness. It's quite unclear how we regressed so far. See #18151. - - - - - d412d7a3 by Kirill Elagin at 2020-06-01T06:34:21-04:00 Winferred-safe-imports: Do not exit with error Currently, when -Winferred-safe-imports is enabled, even when it is not turned into an error, the compiler will still exit with exit code 1 if this warning was emitted. Make sure it is really treated as a warning. - - - - - f945eea5 by Ben Gamari at 2020-06-01T06:34:58-04:00 nonmoving: Optimise log2_ceil - - - - - aab606e4 by Bodigrim at 2020-06-01T06:35:36-04:00 Clarify description of fromListN - - - - - 7e5220e2 by Bodigrim at 2020-06-01T06:35:36-04:00 Apply suggestion to libraries/base/GHC/Exts.hs - - - - - f3fb1ce9 by fendor at 2020-06-01T06:36:18-04:00 Add `isInScope` check to `lintCoercion` Mirrors the behaviour of `lintType`. - - - - - 5ac4d946 by fendor at 2020-06-01T06:36:18-04:00 Lint rhs of IfaceRule - - - - - 1cef6126 by Jeremy Schlatter at 2020-06-01T06:37:00-04:00 Fix wording in documentation The duplicate "orphan instance" phrase here doesn't make sense, and was probably an accident. - - - - - 5aaf08f2 by Takenobu Tani at 2020-06-01T06:37:43-04:00 configure: Modify aclocal.m4 according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * Rename: * compiler/GHC/Parser.hs <= compiler/parser/Parser.hs * compiler/GHC/Parser/Lexer.hs <= compiler/Parser/Lexer.hs * Add: * compiler/GHC/Cmm/Lexer.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular - - - - - 15857ad8 by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Don't fail if we can't unlink __symlink_test Afterall, it's possible we were unable to create it due to lack of symlink permission. - - - - - 4a7229ef by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Refactor ghostscript detection Tamar reported that he saw crashes due to unhandled exceptions. - - - - - 2ab37eaf by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite/perf_notes: Fix ill-typed assignments - - - - - e45d5b66 by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite/testutil: Fix bytes/str mismatch - - - - - 7002d0cb by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Work around spurious mypy failure - - - - - 11390e3a by Takenobu Tani at 2020-06-01T06:39:05-04:00 Clean up file paths for new module hierarchy This updates comments only. This patch replaces file references according to new module hierarchy. See also: * https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular * https://gitlab.haskell.org/ghc/ghc/issues/13009 - - - - - 8f2e5732 by Takenobu Tani at 2020-06-01T06:39:05-04:00 Modify file paths to module paths for new module hierarchy This updates comments only. This patch replaces module references according to new module hierarchy [1][2]. For files under the `compiler/` directory, I replace them as module paths instead of file paths. For instance, `GHC.Unit.State` instead of `compiler/GHC/Unit/State.hs` [3]. For current and future haddock's markup, this patch encloses the module name with "" [4]. [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: https://gitlab.haskell.org/ghc/ghc/issues/13009 [3]: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3375#note_276613 [4]: https://haskell-haddock.readthedocs.io/en/latest/markup.html#linking-to-modules - - - - - 68b71c4a by Tom Ellis at 2020-06-01T06:39:55-04:00 Rename the singleton tuple GHC.Tuple.Unit to GHC.Tuple.Solo - - - - - 95da76c2 by Sylvain Henry at 2020-06-01T06:40:41-04:00 Hadrian: fix binary-dist target for cross-compilation - - - - - 730fcd54 by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for the @-operator Since GHC diverges from the Haskell Report by allowing the user to define (@) as an infix operator, we better give a good error message when the user does so unintentionally. In general, this is rather hard to do, as some failures will be discovered only in the renamer or the type checker: x :: (Integer, Integer) x @ (a, b) = (1, 2) This patch does *not* address this general case. However, it gives much better error messages when the binding is not syntactically valid: pairs xs @ (_:xs') = zip xs xs' Before this patch, the error message was rather puzzling: <interactive>:1:1: error: Parse error in pattern: pairs After this patch, the error message includes a hint: <interactive>:1:1: error: Parse error in pattern: pairs In a function binding for the ‘@’ operator. Perhaps you meant an as-pattern, which must not be surrounded by whitespace - - - - - 0fde5377 by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for TypeApplications With this patch, we always parse f @t as a type application, thereby producing better error messages. This steals two syntactic forms: * Prefix form of the @-operator in expressions. Since the @-operator is a divergence from the Haskell Report anyway, this is not a major loss. * Prefix form of @-patterns. Since we are stealing loose infix form anyway, might as well sacrifice the prefix form for the sake of much better error messages. - - - - - c68e7e1e by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for TemplateHaskellQuotes While [e| |], [t| |], [d| |], and so on, steal syntax from list comprehensions, [| |] and [|| ||] do not steal any syntax. Thus we can improve error messages by always accepting them in the lexer. Turns out the renamer already performs necessary validation. - - - - - 120aedbd by Ben Gamari at 2020-06-01T16:07:02-04:00 gitlab-ci: Disable use of ld.lld on ARMv7 It turns out that lld non-deterministically fails on ARMv7. I suspect this may be due to the a kernel regression as this only started happening when we upgraded to 5.4. Nevertheless, easily avoided by simply sticking with gold. Works around #18280. - - - - - d6279ff0 by Ben Gamari at 2020-06-02T13:03:30-04:00 gitlab-ci: Ensure that workaround for #18280 applies to bindisttest We need to ensure that the `configure` flags working around #18280 are propagated to the bindisttest `configure` as well. - - - - - cb5c31b5 by Ben Gamari at 2020-06-03T17:55:04-04:00 gitlab-ci: Allow ARMv7 job to fail Due to #18298. - - - - - 32a4ae90 by John Ericson at 2020-06-04T04:34:42-04:00 Clean up boot vs non-boot disambiguating types We often have (ModuleName, Bool) or (Module, Bool) pairs for "extended" module names (without or with a unit id) disambiguating boot and normal modules. We think this is important enough across the compiler that it deserves a new nominal product type. We do this with synnoyms and a functor named with a `Gen` prefix, matching other newly created definitions. It was also requested that we keep custom `IsBoot` / `NotBoot` sum type. So we have it too. This means changing many the many bools to use that instead. Updates `haddock` submodule. - - - - - c05756cd by Niklas Hambüchen at 2020-06-04T04:35:24-04:00 docs: Add more details on InterruptibleFFI. Details from https://gitlab.haskell.org/ghc/ghc/issues/8684 and https://github.com/takano-akio/filelock/pull/7#discussion_r280332430 - - - - - 1b975aed by Andrew Martin at 2020-06-04T04:36:03-04:00 Allow finalizeForeignPtr to be called on FinalPtr/PlainPtr. MR 2165 (commit 49301ad6226d9a83d110bee8c419615dd94f5ded) regressed finalizeForeignPtr by throwing exceptions when PlainPtr was encounterd. This regression did not make it into a release of GHC. Here, the original behavior is restored, and FinalPtr is given the same treatment as PlainPtr. - - - - - 2bd3929a by Luke Lau at 2020-06-04T04:36:41-04:00 Fix documentation on type families not being extracted It looks like the location of the Names used for CoAxioms on type families are now located at their type constructors. Previously, Docs.hs thought the Names were located in the RHS, so the RealSrcSpan in the instanceMap and getInstLoc didn't match up. Fixes #18241 - - - - - 6735b9d9 by Ben Gamari at 2020-06-04T04:37:21-04:00 GHC.Hs.Instances: Compile with -O0 This module contains exclusively Data instances, which are going to be slow no matter what we do. Furthermore, they are incredibly slow to compile with optimisation (see #9557). Consequently we compile this with -O0. See #18254. - - - - - c330331a by nineonine at 2020-06-04T04:37:59-04:00 Add test for #17669 - - - - - cab684f0 by Ben Gamari at 2020-06-04T04:38:36-04:00 rts: Add Windows-specific implementation of rtsSleep Previously we would use the POSIX path, which uses `nanosleep`. However, it turns out that `nanosleep` is provided by `libpthread` on Windows. In general we don't want to incur such a dependency. Avoid this by simply using `Sleep` on Windows. Fixes #18272. - - - - - ad44b504 by Ben Gamari at 2020-06-04T04:38:36-04:00 compiler: Disable use of process jobs with process < 1.6.9 Due to #17926. - - - - - 6a4098a4 by Moritz Angermann at 2020-06-04T04:55:51-04:00 [linker] Adds void printLoadedObjects(void); This allows us to dump in-memory object code locations for debugging. Fixup printLoadedObjects prototype - - - - - af5e3a88 by Artem Pelenitsyn at 2020-06-05T03:18:49-04:00 base: fix sign confusion in log1mexp implementation (fix #17125) author: claude (https://gitlab.haskell.org/trac-claude) The correct threshold for log1mexp is -(log 2) with the current specification of log1mexp. This change improves accuracy for large negative inputs. To avoid code duplication, a small helper function is added; it isn't the default implementation in Floating because it needs Ord. This patch does nothing to address that the Haskell specification is different from that in common use in other languages. - - - - - 2b792fac by Simon Peyton Jones at 2020-06-05T09:27:50-04:00 Simple subsumption This patch simplifies GHC to use simple subsumption. Ticket #17775 Implements GHC proposal #287 https://github.com/ghc-proposals/ghc-proposals/blob/master/ proposals/0287-simplify-subsumption.rst All the motivation is described there; I will not repeat it here. The implementation payload: * tcSubType and friends become noticably simpler, because it no longer uses eta-expansion when checking subsumption. * No deeplyInstantiate or deeplySkolemise That in turn means that some tests fail, by design; they can all be fixed by eta expansion. There is a list of such changes below. Implementing the patch led me into a variety of sticky corners, so the patch includes several othe changes, some quite significant: * I made String wired-in, so that "foo" :: String rather than "foo" :: [Char] This improves error messages, and fixes #15679 * The pattern match checker relies on knowing about in-scope equality constraints, andd adds them to the desugarer's environment using addTyCsDs. But the co_fn in a FunBind was missed, and for some reason simple-subsumption ends up with dictionaries there. So I added a call to addTyCsDs. This is really part of #18049. * I moved the ic_telescope field out of Implication and into ForAllSkol instead. This is a nice win; just expresses the code much better. * There was a bug in GHC.Tc.TyCl.Instance.tcDataFamInstHeader. We called checkDataKindSig inside tc_kind_sig, /before/ solveEqualities and zonking. Obviously wrong, easily fixed. * solveLocalEqualitiesX: there was a whole mess in here, around failing fast enough. I discovered a bad latent bug where we could successfully kind-check a type signature, and use it, but have unsolved constraints that could fill in coercion holes in that signature -- aargh. It's all explained in Note [Failure in local type signatures] in GHC.Tc.Solver. Much better now. * I fixed a serious bug in anonymous type holes. IN f :: Int -> (forall a. a -> _) -> Int that "_" should be a unification variable at the /outer/ level; it cannot be instantiated to 'a'. This was plain wrong. New fields mode_lvl and mode_holes in TcTyMode, and auxiliary data type GHC.Tc.Gen.HsType.HoleMode. This fixes #16292, but makes no progress towards the more ambitious #16082 * I got sucked into an enormous refactoring of the reporting of equality errors in GHC.Tc.Errors, especially in mkEqErr1 mkTyVarEqErr misMatchMsg misMatchMsgOrCND In particular, the very tricky mkExpectedActualMsg function is gone. It took me a full day. But the result is far easier to understand. (Still not easy!) This led to various minor improvements in error output, and an enormous number of test-case error wibbles. One particular point: for occurs-check errors I now just say Can't match 'a' against '[a]' rather than using the intimidating language of "occurs check". * Pretty-printing AbsBinds Tests review * Eta expansions T11305: one eta expansion T12082: one eta expansion (undefined) T13585a: one eta expansion T3102: one eta expansion T3692: two eta expansions (tricky) T2239: two eta expansions T16473: one eta determ004: two eta expansions (undefined) annfail06: two eta (undefined) T17923: four eta expansions (a strange program indeed!) tcrun035: one eta expansion * Ambiguity check at higher rank. Now that we have simple subsumption, a type like f :: (forall a. Eq a => Int) -> Int is no longer ambiguous, because we could write g :: (forall a. Eq a => Int) -> Int g = f and it'd typecheck just fine. But f's type is a bit suspicious, and we might want to consider making the ambiguity check do a check on each sub-term. Meanwhile, these tests are accepted, whereas they were previously rejected as ambiguous: T7220a T15438 T10503 T9222 * Some more interesting error message wibbles T13381: Fine: one error (Int ~ Exp Int) rather than two (Int ~ Exp Int, Exp Int ~ Int) T9834: Small change in error (improvement) T10619: Improved T2414: Small change, due to order of unification, fine T2534: A very simple case in which a change of unification order means we get tow unsolved constraints instead of one tc211: bizarre impredicative tests; just accept this for now Updates Cabal and haddock submodules. Metric Increase: T12150 T12234 T5837 haddock.base Metric Decrease: haddock.compiler haddock.Cabal haddock.base Merge note: This appears to break the `UnliftedNewtypesDifficultUnification` test. It has been marked as broken in the interest of merging. (cherry picked from commit 66b7b195cb3dce93ed5078b80bf568efae904cc5) - - - - - 2dff8141 by Ryan Scott at 2020-06-05T14:21:24-04:00 Simplify bindLHsTyVarBndrs and bindHsQTyVars Both `bindLHsTyVarBndrs` and `bindHsQTyVars` take two separate `Maybe` arguments, which I find terribly confusing. Thankfully, it's possible to remove one `Maybe` argument from each of these functions, which this patch accomplishes: * `bindHsQTyVars` takes a `Maybe SDoc` argument, which is `Just` if GHC should warn about any of the quantified type variables going unused. However, every call site uses `Nothing` in practice. This makes sense, since it doesn't really make sense to warn about unused type variables bound by an `LHsQTyVars`. For instance, you wouldn't warn about the `a` in `data Proxy a = Proxy` going unused. As a result, I simply remove this `Maybe SDoc` argument altogether. * `bindLHsTyVarBndrs` also takes a `Maybe SDoc` argument for the same reasons that `bindHsQTyVars` took one. To make things more confusing, however, `bindLHsTyVarBndrs` also takes a separate `HsDocContext` argument, which is pretty-printed (to an `SDoc`) in warnings and error messages. In practice, the `Maybe SDoc` and the `HsDocContext` often contain the same text. See the call sites for `bindLHsTyVarBndrs` in `rnFamInstEqn` and `rnConDecl`, for instance. There are only a handful of call sites where the text differs between the `Maybe SDoc` and `HsDocContext` arguments: * In `rnHsRuleDecl`, where the `Maybe SDoc` says "`In the rule`" and the `HsDocContext` says "`In the transformation rule`". * In `rnHsTyKi`/`rn_ty`, where the `Maybe SDoc` says "`In the type`" but the `HsDocContext` is inhereted from the surrounding context (e.g., if `rnHsTyKi` were called on a top-level type signature, the `HsDocContext` would be "`In the type signature`" instead) In both cases, warnings/error messages arguably _improve_ by unifying making the `Maybe SDoc`'s text match that of the `HsDocContext`. As a result, I decided to remove the `Maybe SDoc` argument to `bindLHsTyVarBndrs` entirely and simply reuse the text from the `HsDocContext`. (I decided to change the phrase "transformation rule" to "rewrite rule" while I was in the area.) The `Maybe SDoc` argument has one other purpose: signaling when to emit "`Unused quantified type variable`" warnings. To recover this functionality, I replaced the `Maybe SDoc` argument with a boolean-like `WarnUnusedForalls` argument. The only `bindLHsTyVarBndrs` call site that chooses _not_ to emit these warnings in `bindHsQTyVars`. - - - - - e372331b by Ben Gamari at 2020-06-07T08:46:41-04:00 hadrian: Add missing deriveConstants dependency on ghcplatform.h deriveConstants wants to compile C sources which #include PosixSource.h, which itself #includes ghcplatform.h. Make sure that Hadrian knows about this dependency. Fixes #18290. - - - - - b022051a by Moritz Angermann at 2020-06-07T08:46:42-04:00 ghc-prim needs to depend on libc and libm libm is just an empty shell on musl, and all the math functions are contained in libc. - - - - - 6dae6548 by Moritz Angermann at 2020-06-07T08:46:42-04:00 Disable DLL loading if without system linker Some platforms (musl, aarch64) do not have a working dynamic linker implemented in the libc, even though we might see dlopen. It will ultimately just return that this is not supported. Hence we'll add a flag to the compiler to flat our disable loading dlls. This is needed as we will otherwise try to load the shared library even if this will subsequently fail. At that point we have given up looking for static options though. - - - - - 4a158ffc by Moritz Angermann at 2020-06-07T08:46:43-04:00 Range is actually +/-2^32, not +/-2^31 See also: https://static.docs.arm.com/ihi0056/g/aaelf64.pdf - - - - - f1bfb806 by Ben Gamari at 2020-06-07T10:49:30-04:00 OccurAnal: Avoid exponential behavior due to where clauses Previously the `Var` case of `occAnalApp` could in some cases (namely in the case of `runRW#` applications) call `occAnalRhs` two. In the case of nested `runRW#`s this results in exponential complexity. In some cases the compilation time that resulted would be very long indeed (see #18296). Fixes #18296. Metric Decrease: T9961 T12150 T12234 - - - - - 9b607671 by Takenobu Tani at 2020-06-09T08:05:46-04:00 Add link to GHC's wiki in the GHC API header This adds a URL to point to GHC's wiki in the GHC API header. Newcomers could easily find more information from the GHC API's web like [1]. [1]: Current version, https://ghc.gitlab.haskell.org/ghc/doc/libraries/ghc-8.11.0.20200604/index.html [skip ci] - - - - - 72c7fe9a by Ryan Scott at 2020-06-09T08:06:24-04:00 Make GADT constructors adhere to the forall-or-nothing rule properly Issue #18191 revealed that the types of GADT constructors don't quite adhere to the `forall`-or-nothing rule. This patch serves to clean up this sad state of affairs somewhat. The main change is not in the code itself, but in the documentation, as this patch introduces two sections to the GHC User's Guide: * A "Formal syntax for GADTs" section that presents a BNF-style grammar for what is and isn't allowed in GADT constructor types. This mostly exists to codify GHC's existing behavior, but it also imposes a new restriction that addresses #18191: the outermost `forall` and/or context in a GADT constructor is not allowed to be surrounded by parentheses. Doing so would make these `forall`s/contexts nested, and GADTs do not support nested `forall`s/contexts at present. * A "`forall`-or-nothing rule" section that describes exactly what the `forall`-or-nothing rule is all about. Surprisingly, there was no mention of this anywhere in the User's Guide up until now! To adhere the new specification in the "Formal syntax for GADTs" section of the User's Guide, the following code changes were made: * A new function, `GHC.Hs.Type.splitLHsGADTPrefixTy`, was introduced. This is very much like `splitLHsSigmaTy`, except that it avoids splitting apart any parentheses, which can be syntactically significant for GADT types. See `Note [No nested foralls or contexts in GADT constructors]` in `GHC.Hs.Type`. * `ConDeclGADTPrefixPs`, an extension constructor for `XConDecl`, was introduced so that `GHC.Parser.PostProcess.mkGadtDecl` can return it when given a prefix GADT constructor. Unlike `ConDeclGADT`, `ConDeclGADTPrefixPs` does not split the GADT type into its argument and result types, as this cannot be done until after the type is renamed (see `Note [GADT abstract syntax]` in `GHC.Hs.Decls` for why this is the case). * `GHC.Renamer.Module.rnConDecl` now has an additional case for `ConDeclGADTPrefixPs` that (1) splits apart the full `LHsType` into its `forall`s, context, argument types, and result type, and (2) checks for nested `forall`s/contexts. Step (2) used to be performed the typechecker (in `GHC.Tc.TyCl.badDataConTyCon`) rather than the renamer, but now the relevant code from the typechecker can simply be deleted. One nice side effect of this change is that we are able to give a more accurate error message for GADT constructors that use visible dependent quantification (e.g., `MkFoo :: forall a -> a -> Foo a`), which improves the stderr in the `T16326_Fail6` test case. Fixes #18191. Bumps the Haddock submodule. - - - - - a47e6442 by Ryan Scott at 2020-06-10T03:39:12-04:00 Always use rnImplicitBndrs to bring implicit tyvars into scope This implements a first step towards #16762 by changing the renamer to always use `rnImplicitBndrs` to bring implicitly bound type variables into scope. The main change is in `rnFamInstEqn` and `bindHsQTyVars`, which previously used _ad hoc_ methods of binding their implicit tyvars. There are a number of knock-on consequences: * One of the reasons that `rnFamInstEqn` used an _ad hoc_ binding mechanism was to give more precise source locations in `-Wunused-type-patterns` warnings. (See https://gitlab.haskell.org/ghc/ghc/issues/16762#note_273343 for an example of this.) However, these warnings are actually a little _too_ precise, since implicitly bound type variables don't have exact binding sites like explicitly bound type variables do. A similar problem existed for "`Different names for the same type variable`" errors involving implicit tyvars bound by `bindHsQTyVars`. Therefore, we simply accept the less precise (but more accurate) source locations from `rnImplicitBndrs` in `rnFamInstEqn` and `bindHsQTyVars`. See `Note [Source locations for implicitly bound type variables]` in `GHC.Rename.HsType` for the full story. * In order for `rnImplicitBndrs` to work in `rnFamInstEqn`, it needs to be able to look up names from the parent class (in the event that we are renaming an associated type family instance). As a result, `rnImplicitBndrs` now takes an argument of type `Maybe assoc`, which is `Just` in the event that a type family instance is associated with a class. * Previously, GHC kept track of three type synonyms for free type variables in the renamer: `FreeKiTyVars`, `FreeKiTyVarsDups` (which are allowed to contain duplicates), and `FreeKiTyVarsNoDups` (which contain no duplicates). However, making is a distinction between `-Dups` and `-NoDups` is now pointless, as all code that returns `FreeKiTyVars{,Dups,NoDups}` will eventually end up being passed to `rnImplicitBndrs`, which removes duplicates. As a result, I decided to just get rid of `FreeKiTyVarsDups` and `FreeKiTyVarsNoDups`, leaving only `FreeKiTyVars`. * The `bindLRdrNames` and `deleteBys` functions are now dead code, so I took the liberty of removing them. - - - - - 24879129 by Takenobu Tani at 2020-06-10T03:39:59-04:00 Clarify leaf module names for new module hierarchy This updates comments only. This patch replaces leaf module names according to new module hierarchy [1][2] as followings: * Expand leaf names to easily find the module path: for instance, `Id.hs` to `GHC.Types.Id`. * Modify leaf names according to new module hierarchy: for instance, `Convert.hs` to `GHC.ThToHs`. * Fix typo: for instance, `GHC.Core.TyCo.Rep.hs` to `GHC.Core.TyCo.Rep` See also !3375 [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: https://gitlab.haskell.org/ghc/ghc/issues/13009 - - - - - 92de9e25 by Ömer Sinan Ağacan at 2020-06-10T03:41:07-04:00 rts: Remove unused GET_ENTRY closure macro This macro is not used and got broken in the meantime, as ENTRY_CODE was deleted. - - - - - 87102928 by Ömer Sinan Ağacan at 2020-06-10T03:41:50-04:00 Fix -fkeep-cafs flag name in users guide - - - - - ccd6843d by Shayne Fletcher at 2020-06-10T04:14:57-04:00 Expose impliedGFlags, impledOffGFlags, impliedXFlags - - - - - 7a737e89 by Ömer Sinan Ağacan at 2020-06-10T04:14:58-04:00 Cross-module LambdaFormInfo passing - Store LambdaFormInfos of exported Ids in interface files - Use them in importing modules This is for optimization purposes: if we know LambdaFormInfo of imported Ids we can generate more efficient calling code, see `getCallMethod`. Exporting (putting them in interface files or in ModDetails) and importing (reading them from interface files) are both optional. We don't assume known LambdaFormInfos anywhere and do not change how we call Ids with unknown LambdaFormInfos. Runtime, allocation, and residency numbers when building Cabal-the-library (commit 0d4ee7ba3): (Log and .hp files are in the MR: !2842) | | GHC HEAD | This patch | Diff | |-----|----------|------------|----------------| | -O0 | 0:35.89 | 0:34.10 | -1.78s, -4.98% | | -O1 | 2:24.01 | 2:23.62 | -0.39s, -0.27% | | -O2 | 2:52.23 | 2:51.35 | -0.88s, -0.51% | | | GHC HEAD | This patch | Diff | |-----|-----------------|-----------------|----------------------------| | -O0 | 54,843,608,416 | 54,878,769,544 | +35,161,128 bytes, +0.06% | | -O1 | 227,136,076,400 | 227,569,045,168 | +432,968,768 bytes, +0.19% | | -O2 | 266,147,063,296 | 266,749,643,440 | +602,580,144 bytes, +0.22% | NOTE: Residency is measured with extra runtime args: `-i0 -h` which effectively turn all GCs into major GCs, and do GC more often. | | GHC HEAD | This patch | Diff | |-----|----------------------------|------------------------------|----------------------------| | -O0 | 410,284,000 (910 samples) | 411,745,008 (906 samples) | +1,461,008 bytes, +0.35% | | -O1 | 928,580,856 (2109 samples) | 943,506,552 (2103 samples) | +14,925,696 bytes, +1.60% | | -O2 | 993,951,352 (2549 samples) | 1,010,156,328 (2545 samples) | +16,204,9760 bytes, +1.63% | NoFib results: -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS 0.0% 0.0% +0.0% +0.0% +0.0% CSD 0.0% 0.0% 0.0% +0.0% +0.0% FS 0.0% 0.0% +0.0% +0.0% +0.0% S 0.0% 0.0% +0.0% +0.0% +0.0% VS 0.0% 0.0% +0.0% +0.0% +0.0% VSD 0.0% 0.0% +0.0% +0.0% +0.1% VSM 0.0% 0.0% +0.0% +0.0% +0.0% anna 0.0% 0.0% -0.3% -0.8% -0.0% ansi 0.0% 0.0% -0.0% -0.0% 0.0% atom 0.0% 0.0% -0.0% -0.0% 0.0% awards 0.0% 0.0% -0.1% -0.3% 0.0% banner 0.0% 0.0% -0.0% -0.0% -0.0% bernouilli 0.0% 0.0% -0.0% -0.0% -0.0% binary-trees 0.0% 0.0% -0.0% -0.0% +0.0% boyer 0.0% 0.0% -0.0% -0.0% 0.0% boyer2 0.0% 0.0% -0.0% -0.0% 0.0% bspt 0.0% 0.0% -0.0% -0.2% 0.0% cacheprof 0.0% 0.0% -0.1% -0.4% +0.0% calendar 0.0% 0.0% -0.0% -0.0% 0.0% cichelli 0.0% 0.0% -0.9% -2.4% 0.0% circsim 0.0% 0.0% -0.0% -0.0% 0.0% clausify 0.0% 0.0% -0.1% -0.3% 0.0% comp_lab_zift 0.0% 0.0% -0.0% -0.0% +0.0% compress 0.0% 0.0% -0.0% -0.0% -0.0% compress2 0.0% 0.0% -0.0% -0.0% 0.0% constraints 0.0% 0.0% -0.1% -0.2% -0.0% cryptarithm1 0.0% 0.0% -0.0% -0.0% 0.0% cryptarithm2 0.0% 0.0% -1.4% -4.1% -0.0% cse 0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e1 0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e2 0.0% 0.0% -0.0% -0.0% -0.0% dom-lt 0.0% 0.0% -0.1% -0.2% 0.0% eliza 0.0% 0.0% -0.5% -1.5% 0.0% event 0.0% 0.0% -0.0% -0.0% -0.0% exact-reals 0.0% 0.0% -0.1% -0.3% +0.0% exp3_8 0.0% 0.0% -0.0% -0.0% -0.0% expert 0.0% 0.0% -0.3% -1.0% -0.0% fannkuch-redux 0.0% 0.0% +0.0% +0.0% +0.0% fasta 0.0% 0.0% -0.0% -0.0% +0.0% fem 0.0% 0.0% -0.0% -0.0% 0.0% fft 0.0% 0.0% -0.0% -0.0% 0.0% fft2 0.0% 0.0% -0.0% -0.0% 0.0% fibheaps 0.0% 0.0% -0.0% -0.0% +0.0% fish 0.0% 0.0% 0.0% -0.0% +0.0% fluid 0.0% 0.0% -0.4% -1.2% +0.0% fulsom 0.0% 0.0% -0.0% -0.0% 0.0% gamteb 0.0% 0.0% -0.1% -0.3% 0.0% gcd 0.0% 0.0% -0.0% -0.0% 0.0% gen_regexps 0.0% 0.0% -0.0% -0.0% -0.0% genfft 0.0% 0.0% -0.0% -0.0% 0.0% gg 0.0% 0.0% -0.0% -0.0% +0.0% grep 0.0% 0.0% -0.0% -0.0% -0.0% hidden 0.0% 0.0% -0.1% -0.4% -0.0% hpg 0.0% 0.0% -0.2% -0.5% +0.0% ida 0.0% 0.0% -0.0% -0.0% +0.0% infer 0.0% 0.0% -0.3% -0.8% -0.0% integer 0.0% 0.0% -0.0% -0.0% +0.0% integrate 0.0% 0.0% -0.0% -0.0% 0.0% k-nucleotide 0.0% 0.0% -0.0% -0.0% +0.0% kahan 0.0% 0.0% -0.0% -0.0% +0.0% knights 0.0% 0.0% -2.2% -5.4% 0.0% lambda 0.0% 0.0% -0.6% -1.8% 0.0% last-piece 0.0% 0.0% -0.0% -0.0% 0.0% lcss 0.0% 0.0% -0.0% -0.1% 0.0% life 0.0% 0.0% -0.0% -0.1% 0.0% lift 0.0% 0.0% -0.2% -0.6% +0.0% linear 0.0% 0.0% -0.0% -0.0% -0.0% listcompr 0.0% 0.0% -0.0% -0.0% 0.0% listcopy 0.0% 0.0% -0.0% -0.0% 0.0% maillist 0.0% 0.0% -0.1% -0.3% +0.0% mandel 0.0% 0.0% -0.0% -0.0% 0.0% mandel2 0.0% 0.0% -0.0% -0.0% -0.0% mate +0.0% 0.0% -0.0% -0.0% -0.0% minimax 0.0% 0.0% -0.2% -1.0% 0.0% mkhprog 0.0% 0.0% -0.1% -0.2% -0.0% multiplier 0.0% 0.0% -0.0% -0.0% -0.0% n-body 0.0% 0.0% -0.0% -0.0% +0.0% nucleic2 0.0% 0.0% -0.1% -0.2% 0.0% para 0.0% 0.0% -0.0% -0.0% -0.0% paraffins 0.0% 0.0% -0.0% -0.0% 0.0% parser 0.0% 0.0% -0.2% -0.7% 0.0% parstof 0.0% 0.0% -0.0% -0.0% +0.0% pic 0.0% 0.0% -0.0% -0.0% 0.0% pidigits 0.0% 0.0% +0.0% +0.0% +0.0% power 0.0% 0.0% -0.2% -0.6% +0.0% pretty 0.0% 0.0% -0.0% -0.0% -0.0% primes 0.0% 0.0% -0.0% -0.0% 0.0% primetest 0.0% 0.0% -0.0% -0.0% -0.0% prolog 0.0% 0.0% -0.3% -1.1% 0.0% puzzle 0.0% 0.0% -0.0% -0.0% 0.0% queens 0.0% 0.0% -0.0% -0.0% +0.0% reptile 0.0% 0.0% -0.0% -0.0% 0.0% reverse-complem 0.0% 0.0% -0.0% -0.0% +0.0% rewrite 0.0% 0.0% -0.7% -2.5% -0.0% rfib 0.0% 0.0% -0.0% -0.0% 0.0% rsa 0.0% 0.0% -0.0% -0.0% 0.0% scc 0.0% 0.0% -0.1% -0.2% -0.0% sched 0.0% 0.0% -0.0% -0.0% -0.0% scs 0.0% 0.0% -1.0% -2.6% +0.0% simple 0.0% 0.0% +0.0% -0.0% +0.0% solid 0.0% 0.0% -0.0% -0.0% 0.0% sorting 0.0% 0.0% -0.6% -1.6% 0.0% spectral-norm 0.0% 0.0% +0.0% 0.0% +0.0% sphere 0.0% 0.0% -0.0% -0.0% -0.0% symalg 0.0% 0.0% -0.0% -0.0% +0.0% tak 0.0% 0.0% -0.0% -0.0% 0.0% transform 0.0% 0.0% -0.0% -0.0% 0.0% treejoin 0.0% 0.0% -0.0% -0.0% 0.0% typecheck 0.0% 0.0% -0.0% -0.0% +0.0% veritas +0.0% 0.0% -0.2% -0.4% +0.0% wang 0.0% 0.0% -0.0% -0.0% 0.0% wave4main 0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve1 0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve2 0.0% 0.0% -0.0% -0.0% +0.0% x2n1 0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min 0.0% 0.0% -2.2% -5.4% -0.0% Max +0.0% 0.0% +0.0% +0.0% +0.1% Geometric Mean -0.0% -0.0% -0.1% -0.3% +0.0% Metric increases micro benchmarks tracked in #17686: Metric Increase: T12150 T12234 T12425 T13035 T5837 T6048 T9233 Co-authored-by: Andreas Klebinger <klebinger.andreas at gmx.at> - - - - - 3b22b14a by Shayne Fletcher at 2020-06-10T04:15:01-04:00 Give Language a Bounded instance - - - - - 9454511b by Simon Peyton Jones at 2020-06-10T04:17:06-04:00 Optimisation in Unique.Supply This patch switches on -fno-state-hack in GHC.Types.Unique.Supply. It turned out that my fixes for #18078 (coercion floating) changed the optimisation pathway for mkSplitUniqSupply in such a way that we had an extra allocation inside the inner loop. Adding -fno-state-hack fixed that -- and indeed the loop in mkSplitUniqSupply is a classic example of the way in which -fno-state-hack can be bad; see #18238. Moreover, the new code is better than the old. They allocate the same, but the old code ends up with a partial application. The net effect is that the test perf/should_run/UniqLoop runs 20% faster! From 2.5s down to 2.0s. The allocation numbers are the same -- but elapsed time falls. Good! The bad thing about this is that it's terribly delicate. But at least it's a good example of such delicacy in action. There is a long Note [Optimising the unique supply] which now explains all this. - - - - - 6d49d5be by Simon Peyton Jones at 2020-06-10T04:17:06-04:00 Implement cast worker/wrapper properly The cast worker/wrapper transformation transforms x = e |> co into y = e x = y |> co This is done by the simplifier, but we were being careless about transferring IdInfo from x to y, and about what to do if x is a NOINLNE function. This resulted in a series of bugs: #17673, #18093, #18078. This patch fixes all that: * Main change is in GHC.Core.Opt.Simplify, and the new prepareBinding function, which does this cast worker/wrapper transform. See Note [Cast worker/wrappers]. * There is quite a bit of refactoring around prepareRhs, makeTrivial etc. It's nicer now. * Some wrappers from strictness and cast w/w, notably those for a function with a NOINLINE, should inline very late. There wasn't really a mechanism for that, which was an existing bug really; so I invented a new finalPhase = Phase (-1). It's used for all simplifier runs after the user-visible phase 2,1,0 have run. (No new runs of the simplifier are introduced thereby.) See new Note [Compiler phases] in GHC.Types.Basic; the main changes are in GHC.Core.Opt.Driver * Doing this made me trip over two places where the AnonArgFlag on a FunTy was being lost so we could end up with (Num a -> ty) rather than (Num a => ty) - In coercionLKind/coercionRKind - In contHoleType in the Simplifier I fixed the former by defining mkFunctionType and using it in coercionLKind/RKind. I could have done the same for the latter, but the information is almost to hand. So I fixed the latter by - adding sc_hole_ty to ApplyToVal (like ApplyToTy), - adding as_hole_ty to ValArg (like TyArg) - adding sc_fun_ty to StrictArg Turned out I could then remove ai_type from ArgInfo. This is just moving the deck chairs around, but it worked out nicely. See the new Note [AnonArgFlag] in GHC.Types.Var * When looking at the 'arity decrease' thing (#18093) I discovered that stable unfoldings had a much lower arity than the actual optimised function. That's what led to the arity-decrease message. Simple solution: eta-expand. It's described in Note [Eta-expand stable unfoldings] in GHC.Core.Opt.Simplify * I also discovered that unsafeCoerce wasn't being inlined if the context was boring. So (\x. f (unsafeCoerce x)) would create a thunk -- yikes! I fixed that by making inlineBoringOK a bit cleverer: see Note [Inline unsafeCoerce] in GHC.Core.Unfold. I also found that unsafeCoerceName was unused, so I removed it. I made a test case for #18078, and a very similar one for #17673. The net effect of all this on nofib is very modest, but positive: -------------------------------------------------------------------------------- Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- anna -0.4% -0.1% -3.1% -3.1% 0.0% fannkuch-redux -0.4% -0.3% -0.1% -0.1% 0.0% maillist -0.4% -0.1% -7.8% -1.0% -14.3% primetest -0.4% -15.6% -7.1% -6.6% 0.0% -------------------------------------------------------------------------------- Min -0.9% -15.6% -13.3% -14.2% -14.3% Max -0.3% 0.0% +12.1% +12.4% 0.0% Geometric Mean -0.4% -0.2% -2.3% -2.2% -0.1% All following metric decreases are compile-time allocation decreases between -1% and -3%: Metric Decrease: T5631 T13701 T14697 T15164 - - - - - 32fd37f5 by Luke Lau at 2020-06-10T04:17:22-04:00 Fix lookupGlobalOccRn_maybe sometimes reporting an error In some cases it was possible for lookupGlobalOccRn_maybe to return an error, when it should be returning a Nothing. If it called lookupExactOcc_either when there were no matching GlobalRdrElts in the otherwise case, it would return an error message. This could be caused when lookupThName_maybe in Template Haskell was looking in different namespaces (thRdrNameGuesses), guessing different namespaces that the name wasn't guaranteed to be found in. However, by addressing this some more accurate errors were being lost in the conversion to Maybes. So some of the lookup* functions have been shuffled about so that errors should always be ignored in lookup*_maybes, and propagated otherwise. This fixes #18263 - - - - - 9b283e1b by Roland Senn at 2020-06-10T04:17:34-04:00 Initialize the allocation counter in GHCi to 0 (Fixes #16012) According to the documentation for the function `getAllocationCounter` in [System.Mem](http://hackage.haskell.org/package/base-4.14.0.0/docs/System-Mem.html) initialize the allocationCounter also in GHCi to 0. - - - - - 8d07c48c by Sylvain Henry at 2020-06-10T04:17:36-04:00 test: fix conc038 We had spurious failures of conc038 test on CI with stdout: ``` newThread started -mainThread -Haskell: 2 newThread back again +mainThread 1 sec later shutting down +Haskell: 2 ``` - - - - - 4c7e9689 by Sebastian Graf at 2020-06-11T10:37:38+02:00 Release Notes: Add news from the pattern-match checker [skip ci] - - - - - 3445b965 by Sylvain Henry at 2020-06-13T02:13:01-04:00 Only test T16190 with the NCG T16190 is meant to test a NCG feature. It has already caused spurious failures in other MRs (e.g. !2165) when LLVM is used. - - - - - 2517a51c by Sylvain Henry at 2020-06-13T02:13:01-04:00 DynFlags refactoring VIII (#17957) * Remove several uses of `sdocWithDynFlags`, especially in GHC.Llvm.* * Add LlvmOpts datatype to store Llvm backend options * Remove Outputable instances (for LlvmVar, LlvmLit, LlvmStatic and Llvm.MetaExpr) which require LlvmOpts. * Rename ppMetaExpr into ppMetaAnnotExpr (pprMetaExpr is now used in place of `ppr :: MetaExpr -> SDoc`) - - - - - 7a02599a by Sylvain Henry at 2020-06-13T02:13:02-04:00 Remove unused code - - - - - 72d08610 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Refactor homeUnit * rename thisPackage into homeUnit * document and refactor several Backpack things - - - - - 8dc71f55 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Rename unsafeGetUnitInfo into unsafeLookupUnit - - - - - f6be6e43 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Add allowVirtualUnits field in PackageState Instead of always querying DynFlags to know whether we are allowed to use virtual units (i.e. instantiated on-the-fly, cf Note [About units] in GHC.Unit), we store it once for all in `PackageState.allowVirtualUnits`. This avoids using DynFlags too much (cf #17957) and is preliminary work for #14335. - - - - - e7272d53 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Enhance UnitId use * use UnitId instead of String to identify wired-in units * use UnitId instead of Unit in the backend (Unit are only use by Backpack to produce type-checked interfaces, not real code) * rename lookup functions for consistency * documentation - - - - - 9c5572cd by Sylvain Henry at 2020-06-13T02:13:02-04:00 Remove LinkerUnitId type alias - - - - - d345edfe by Sylvain Henry at 2020-06-13T02:13:02-04:00 Refactor WiredMap * Remove WiredInUnitId and WiredUnitId type aliases - - - - - 3d171cd6 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Document and refactor `mkUnit` and `mkUnitInfoMap` - - - - - d2109b4f by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove PreloadUnitId type alias - - - - - f50c19b8 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename listUnitInfoMap into listUnitInfo There is no Map involved - - - - - ed533ec2 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename Package into Unit The terminology changed over time and now package databases contain "units" (there can be several units compiled from a single Cabal package: one per-component, one for each option set, one per instantiation, etc.). We should try to be consistent internally and use "units": that's what this renaming does. Maybe one day we'll fix the UI too (e.g. replace -package-id with -unit-id, we already have -this-unit-id and ghc-pkg has -unit-id...) but it's not done in this patch. * rename getPkgFrameworkOpts into getUnitFrameworkOpts * rename UnitInfoMap into ClosureUnitInfoMap * rename InstalledPackageIndex into UnitInfoMap * rename UnusablePackages into UnusableUnits * rename PackagePrecedenceIndex into UnitPrecedenceMap * rename PackageDatabase into UnitDatabase * rename pkgDatabase into unitDatabases * rename pkgState into unitState * rename initPackages into initUnits * rename renamePackage into renameUnitInfo * rename UnusablePackageReason into UnusableUnitReason * rename getPackage* into getUnit* * etc. - - - - - 202728e5 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Make ClosureUnitInfoMap uses UnitInfoMap - - - - - 55b4263e by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove ClosureUnitInfoMap - - - - - 653d17bd by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename Package into Unit (2) * rename PackageState into UnitState * rename findWiredInPackages into findWiredInUnits * rename lookupModuleInAll[Packages,Units] * etc. - - - - - ae900605 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move dump_mod_map into initUnits - - - - - 598cc1dd by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move wiring of homeUnitInstantiations outside of mkUnitState - - - - - 437265eb by Sylvain Henry at 2020-06-13T02:13:03-04:00 Avoid timing module map dump in initUnits - - - - - 9400aa93 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove preload parameter of mkUnitState * Remove preload parameter (unused) * Don't explicitly return preloaded units: redundant because already returned as "preloadUnits" field of UnitState - - - - - 266bc3d9 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: refactor unwireUnit - - - - - 9e715c1b by Sylvain Henry at 2020-06-13T02:13:03-04:00 Document getPreloadUnitsAnd - - - - - bd5810dc by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: remove useless add_package parameter - - - - - 36e1daf0 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: make listVisibleModuleNames take a UnitState - - - - - 5226da37 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Refactor and document add_package - - - - - 4b53aac1 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Refactor and document closeUnitDeps - - - - - 42c054f6 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: findWiredInUnits - - - - - a444d01b by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: reportCycles, reportUnusable - - - - - 8408d521 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: merge_databases - - - - - fca2d25f by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: add UnitConfig datatype Avoid directly querying flags from DynFlags to build the UnitState. Instead go via UnitConfig so that we could reuse this to make another UnitState for plugins. - - - - - 4274688a by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move distrustAll into mkUnitState - - - - - 28d804e1 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Create helper upd_wired_in_home_instantiations - - - - - ac964c83 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Put database cache in UnitConfig - - - - - bfd0a78c by Sylvain Henry at 2020-06-13T02:13:03-04:00 Don't return preload units when we set DyNFlags Preload units can be retrieved in UnitState when needed (i.e. in GHCi) - - - - - 1fbb4bf5 by Sylvain Henry at 2020-06-13T02:13:03-04:00 NCGConfig: remove useless ncgUnitId field - - - - - c10ff7e7 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Doc: fix some comments - - - - - 456e17f0 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Bump haddock submodule and allow metric decrease Metric Decrease: T12150 T12234 T5837 Metric Increase: T16190 - - - - - 42953902 by Simon Peyton Jones at 2020-06-13T02:13:03-04:00 Trim the demand for recursive product types Ticket #18304 showed that we need to be very careful when exploring the demand (esp usage demand) on recursive product types. This patch solves the problem by trimming the demand on such types -- in effect, a form of "widening". See the Note [Trimming a demand to a type] in DmdAnal, which explains how I did this by piggy-backing on an existing mechansim for trimming demands becuase of GADTs. The significant payload of this patch is very small indeed: * Make GHC.Core.Opt.WorkWrap.Utils.typeShape use RecTcChecker to avoid looking through recursive types. But on the way * I found that ae_rec_tc was entirely inoperative and did nothing. So I removed it altogether from DmdAnal. * I moved some code around in DmdAnal and Demand. (There are no actual changes in dmdFix.) * I changed the API of DmsAnal.dmdAnalRhsLetDown to return a StrictSig rather than a decorated Id * I removed the dead function peelTsFuns from Demand Performance effects: Nofib: 0.0% changes. Not surprising, because they don't use recursive products Perf tests T12227: 1% increase in compiler allocation, becuase $cto gets w/w'd. It did not w/w before because it takes a deeply nested argument, so the worker gets too many args, so we abandon w/w altogether (see GHC.Core.Opt.WorkWrap.Utils.isWorkerSmallEnough) With this patch we trim the demands. That is not strictly necessary (since these Generic type constructors are like tuples -- they can't cause a loop) but the net result is that we now w/w $cto which is fine. UniqLoop: 16% decrease in /runtime/ allocation. The UniqSupply is a recursive product, so currently we abandon all strictness on 'churn'. With this patch 'churn' gets useful strictness, and we w/w it. Hooray Metric Decrease: UniqLoop Metric Increase: T12227 - - - - - 87d504f4 by Viktor Dukhovni at 2020-06-13T02:13:05-04:00 Add introductory prose for Data.Traversable - - - - - 9f09b608 by Oleg Grenrus at 2020-06-13T02:13:07-04:00 Fix #12073: Add MonadFix Q instance - - - - - 220c2d34 by Ben Gamari at 2020-06-13T02:13:07-04:00 testsuite: Increase size of T12150 As noted in #18319, this test was previously very fragile. Increase its size to make it more likely that its fails with its newly-increased acceptance threshold. Metric Increase: T12150 - - - - - 8bba1c26 by Ben Gamari at 2020-06-13T04:59:06-04:00 gitlab-ci: Always push perf notes Previously we ci.sh would run with `set -e` implying that we wouldn't push perf notes if the testsuite were to fail, even if it *only* failed due to perf notes. This rendered the whole performance testing story quite fragile as a single regressing commit would cause every successive commit to fail since a new baseline would not be uploaded. Fix this by ensuring that we always push performance notes. - - - - - 7a773f16 by Ben Gamari at 2020-06-13T15:10:55-04:00 gitlab-ci: Eliminate redundant push of CI metrics - - - - - a31218f7 by Ryan Scott at 2020-06-13T15:58:37-04:00 Use HsForAllTelescope to avoid inferred, visible foralls Currently, `HsForAllTy` permits the combination of `ForallVis` and `Inferred`, but you can't actually typecheck code that uses it (e.g., `forall {a} ->`). This patch refactors `HsForAllTy` to use a new `HsForAllTelescope` data type that makes a type-level distinction between visible and invisible `forall`s such that visible `forall`s do not track `Specificity`. That part of the patch is actually quite small; the rest is simply changing consumers of `HsType` to accommodate this new type. Fixes #18235. Bumps the `haddock` submodule. - - - - - c0e6dee9 by Tamar Christina at 2020-06-14T09:07:44-04:00 winio: Add Atomic Exchange PrimOp and implement Atomic Ptr exchanges. The initial version was rewritten by Tamar Christina. It was rewritten in large parts by Andreas Klebinger. Co-authored-by: Andreas Klebinger <klebinger.andreas at gmx.at> - - - - - 9a7462fb by Ben Gamari at 2020-06-14T15:35:23-04:00 codeGen: Don't discard live case binders in unsafeEqualityProof logic Previously CoreToStg would unconditionally discard cases of the form: case unsafeEqualityProof of wild { _ -> rhs } and rather replace the whole thing with `rhs`. However, in some cases (see #18227) the case binder is still live, resulting in unbound occurrences in `rhs`. Fix this by only discarding the case if the case binder is dead. Fixes #18227. - - - - - e4137c48 by Ben Gamari at 2020-06-14T15:35:23-04:00 testsuite: Add tests for #18227 T18227A is the original issue which gave rise to the ticket and depends upon bytestring. T18227B is a minimized reproducer. - - - - - 8bab9ff1 by Ben Gamari at 2020-06-14T15:35:59-04:00 hadrian: Fix rts include and library paths Fixes two bugs: * (?) and (<>) associated in a surprising way * We neglected to include libdw paths in the rts configure flags - - - - - bd761185 by Ben Gamari at 2020-06-14T15:35:59-04:00 hadrian: Drop redundant GHC arguments Cabal should already be passing this arguments to GHC. - - - - - 01f7052c by Peter Trommler at 2020-06-14T15:36:38-04:00 FFI: Fix pass small ints in foreign call wrappers The Haskell calling convention requires integer parameters smaller than wordsize to be promoted to wordsize (where the upper bits are don't care). To access such small integer parameter read a word from the parameter array and then cast that word to the small integer target type. Fixes #15933 - - - - - 502647f7 by Krzysztof Gogolewski at 2020-06-14T15:37:14-04:00 Fix "ndecreasingIndentation" in manual (#18116) - - - - - 9a9cc089 by Simon Jakobi at 2020-06-15T13:10:00-04:00 Use foldl' in unionManyUniqDSets - - - - - 761dcb84 by Moritz Angermann at 2020-06-15T13:10:36-04:00 Load .lo as well. Some archives contain so called linker objects, with the affectionate .lo suffic. For example the musl libc.a will come in that form. We still want to load those objects, hence we should not discard them and look for .lo as well. Ultimately we might want to fix this proerly by looking at the file magic. - - - - - cf01477f by Vladislav Zavialov at 2020-06-15T13:11:20-04:00 User's Guide: KnownNat evidence is Natural This bit of documentation got outdated after commit 1fcede43d2b30f33b7505e25eb6b1f321be0407f - - - - - d0dcbfe6 by Jan Hrček at 2020-06-16T20:36:38+02:00 Fix typos and formatting in user guide - - - - - 56a9e95f by Jan Hrček at 2020-06-16T20:36:38+02:00 Resolve TODO - - - - - 3e884d14 by Jan Hrček at 2020-06-16T20:36:38+02:00 Rename TcHoleErrors to GHC.Tc.Errors.Hole - - - - - d23fc678 by Stefan Schulze Frielinghaus at 2020-06-17T15:31:09-04:00 hadrian: Build with threaded runtime if available See #16873. - - - - - 0639dc10 by Sylvain Henry at 2020-06-17T15:31:53-04:00 T16190: only measure bytes_allocated Just adding `{-# LANGUAGE BangPatterns #-}` makes the two other metrics fluctuate by 13%. - - - - - 4cab6897 by Adam Sandberg Ericsson at 2020-06-17T15:32:44-04:00 docs: fix formatting in users guide - - - - - eb8115a8 by Sylvain Henry at 2020-06-17T15:33:23-04:00 Move CLabel assertions into smart constructors (#17957) It avoids using DynFlags in the Outputable instance of Clabel to check assertions at pretty-printing time. - - - - - 7faa4509 by Ben Gamari at 2020-06-17T15:43:31-04:00 base: Bump to 4.15.0.0 - - - - - 20616959 by Ben Gamari at 2020-06-17T15:43:31-04:00 configure: Use grep -q instead of --quiet The latter is apparently not supported by busybox. - - - - - 40fa237e by Krzysztof Gogolewski at 2020-06-17T16:21:58-04:00 Linear types (#15981) This is the first step towards implementation of the linear types proposal (https://github.com/ghc-proposals/ghc-proposals/pull/111). It features * A language extension -XLinearTypes * Syntax for linear functions in the surface language * Linearity checking in Core Lint, enabled with -dlinear-core-lint * Core-to-core passes are mostly compatible with linearity * Fields in a data type can be linear or unrestricted; linear fields have multiplicity-polymorphic constructors. If -XLinearTypes is disabled, the GADT syntax defaults to linear fields The following items are not yet supported: * a # m -> b syntax (only prefix FUN is supported for now) * Full multiplicity inference (multiplicities are really only checked) * Decent linearity error messages * Linear let, where, and case expressions in the surface language (each of these currently introduce the unrestricted variant) * Multiplicity-parametric fields * Syntax for annotating lambda-bound or let-bound with a multiplicity * Syntax for non-linear/multiple-field-multiplicity records * Linear projections for records with a single linear field * Linear pattern synonyms * Multiplicity coercions (test LinearPolyType) A high-level description can be found at https://ghc.haskell.org/trac/ghc/wiki/LinearTypes/Implementation Following the link above you will find a description of the changes made to Core. This commit has been authored by * Richard Eisenberg * Krzysztof Gogolewski * Matthew Pickering * Arnaud Spiwack With contributions from: * Mark Barbone * Alexander Vershilov Updates haddock submodule. - - - - - 6cb84c46 by Krzysztof Gogolewski at 2020-06-17T16:22:03-04:00 Various performance improvements This implements several general performance improvements to GHC, to offset the effect of the linear types change. General optimisations: - Add a `coreFullView` function which iterates `coreView` on the head. This avoids making function recursive solely because the iterate `coreView` themselves. As a consequence, this functions can be inlined, and trigger case-of-known constructor (_e.g._ `kindRep_maybe`, `isLiftedRuntimeRep`, `isMultiplicityTy`, `getTyVar_maybe`, `splitAppTy_maybe`, `splitFunType_maybe`, `tyConAppTyCon_maybe`). The common pattern about all these functions is that they are almost always used as views, and immediately consumed by a case expression. This commit also mark them asx `INLINE`. - In `subst_ty` add a special case for nullary `TyConApp`, which avoid allocations altogether. - Use `mkTyConApp` in `subst_ty` for the general `TyConApp`. This required quite a bit of module shuffling. case. `myTyConApp` enforces crucial sharing, which was lost during substitution. See also !2952 . - Make `subst_ty` stricter. - In `eqType` (specifically, in `nonDetCmpType`), add a special case, tested first, for the very common case of nullary `TyConApp`. `nonDetCmpType` has been made `INLINE` otherwise it is actually a regression. This is similar to the optimisations in !2952. Linear-type specific optimisations: - Use `tyConAppTyCon_maybe` instead of the more complex `eqType` in the definition of the pattern synonyms `One` and `Many`. - Break the `hs-boot` cycles between `Multiplicity.hs` and `Type.hs`: `Multiplicity` now import `Type` normally, rather than from the `hs-boot`. This way `tyConAppTyCon_maybe` can inline properly in the `One` and `Many` pattern synonyms. - Make `updateIdTypeAndMult` strict in its type and multiplicity - The `scaleIdBy` gets a specialised definition rather than being an alias to `scaleVarBy` - `splitFunTy_maybe` is given the type `Type -> Maybe (Mult, Type, Type)` instead of `Type -> Maybe (Scaled Type, Type)` - Remove the `MultMul` pattern synonym in favour of a view `isMultMul` because pattern synonyms appear not to inline well. - in `eqType`, in a `FunTy`, compare multiplicities last: they are almost always both `Many`, so it helps failing faster. - Cache `manyDataConTy` in `mkTyConApp`, to make sure that all the instances of `TyConApp ManyDataConTy []` are physically the same. This commit has been authored by * Richard Eisenberg * Krzysztof Gogolewski * Arnaud Spiwack Metric Decrease: haddock.base T12227 T12545 T12990 T1969 T3064 T5030 T9872b Metric Increase: haddock.base haddock.Cabal haddock.compiler T12150 T12234 T12425 T12707 T13035 T13056 T15164 T16190 T18304 T1969 T3064 T3294 T5631 T5642 T5837 T6048 T9020 T9233 T9675 T9872a T9961 WWRec - - - - - 57db91d8 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Remove integer-simple integer-simple uses lists of words (`[Word]`) to represent big numbers instead of ByteArray#: * it is less efficient than the newer ghc-bignum native backend * it isn't compatible with the big number representation that is now shared by all the ghc-bignum backends (based on the one that was used only in integer-gmp before). As a consequence, we simply drop integer-simple - - - - - 9f96bc12 by Sylvain Henry at 2020-06-17T16:22:03-04:00 ghc-bignum library ghc-bignum is a newer package that aims to replace the legacy integer-simple and integer-gmp packages. * it supports several backends. In particular GMP is still supported and most of the code from integer-gmp has been merged in the "gmp" backend. * the pure Haskell "native" backend is new and is much faster than the previous pure Haskell implementation provided by integer-simple * new backends are easier to write because they only have to provide a few well defined functions. All the other code is common to all backends. In particular they all share the efficient small/big number distinction previously used only in integer-gmp. * backends can all be tested against the "native" backend with a simple Cabal flag. Backends are only allowed to differ in performance, their results should be the same. * Add `integer-gmp` compat package: provide some pattern synonyms and function aliases for those in `ghc-bignum`. It is intended to avoid breaking packages that depend on `integer-gmp` internals. Update submodules: text, bytestring Metric Decrease: Conversions ManyAlternatives ManyConstructors Naperian T10359 T10547 T10678 T12150 T12227 T12234 T12425 T13035 T13719 T14936 T1969 T4801 T4830 T5237 T5549 T5837 T8766 T9020 parsing001 space_leak_001 T16190 haddock.base On ARM and i386, T17499 regresses (+6% > 5%). On x86_64 unregistered, T13701 sometimes regresses (+2.2% > 2%). Metric Increase: T17499 T13701 - - - - - 96aa5787 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update compiler Thanks to ghc-bignum, the compiler can be simplified: * Types and constructors of Integer and Natural can be wired-in. It means that we don't have to query them from interfaces. It also means that numeric literals don't have to carry their type with them. * The same code is used whatever ghc-bignum backend is enabled. In particular, conversion of bignum literals into final Core expressions is now much more straightforward. Bignum closure inspection too. * GHC itself doesn't depend on any integer-* package anymore * The `integerLibrary` setting is gone. - - - - - 0f67e344 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update `base` package * GHC.Natural isn't implemented in `base` anymore. It is provided by ghc-bignum in GHC.Num.Natural. It means that we can safely use Natural primitives in `base` without fearing issues with built-in rewrite rules (cf #15286) * `base` doesn't conditionally depend on an integer-* package anymore, it depends on ghc-bignum * Some duplicated code in integer-* can now be factored in GHC.Float * ghc-bignum tries to use a uniform naming convention so most of the other changes are renaming - - - - - aa9e7b71 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update `make` based build system * replace integer-* package selection with ghc-bignum backend selection - - - - - f817d816 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Update testsuite * support detection of slow ghc-bignum backend (to replace the detection of integer-simple use). There are still some test cases that the native backend doesn't handle efficiently enough. * remove tests for GMP only functions that have been removed from ghc-bignum * fix test results showing dependent packages (e.g. integer-gmp) or showing suggested instances * fix test using Integer/Natural API or showing internal names - - - - - dceecb09 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Update Hadrian * support ghc-bignum backend selection in flavours and command-line * support ghc-bignum "--check" flag (compare results of selected backend against results of the native one) in flavours and command-line (e.g. pass --bignum=check-gmp" to check the "gmp" backend) * remove the hack to workaround #15286 * build GMP only when the gmp backend is used * remove hacks to workaround `text` package flags about integer-*. We fix `text` to use ghc-bignum unconditionally in another patch - - - - - fa4281d6 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Bump bytestring and text submodules - - - - - 1a3f6f34 by Adam Sandberg Ericsson at 2020-06-18T23:03:36-04:00 docs: mention -hiedir in docs for -outputdir [skip ci] - - - - - 729bcb02 by Sylvain Henry at 2020-06-18T23:04:17-04:00 Hadrian: fix build on Mac OS Catalina (#17798) - - - - - 95e18292 by Andreas Klebinger at 2020-06-18T23:04:58-04:00 Relax allocation threshold for T12150. This test performs little work, so the most minor allocation changes often cause the test to fail. Increasing the threshold to 2% should help with this. - - - - - 8ce6c393 by Sebastian Graf at 2020-06-18T23:05:36-04:00 hadrian: Bump pinned cabal.project to an existent index-state - - - - - 08c1cb0f by Ömer Sinan Ağacan at 2020-06-18T23:06:21-04:00 Fix uninitialized field read in Linker.c Valgrind report of the bug when running the test `linker_unload`: ==29666== Conditional jump or move depends on uninitialised value(s) ==29666== at 0x369C5B4: setOcInitialStatus (Linker.c:1305) ==29666== by 0x369C6C5: mkOc (Linker.c:1347) ==29666== by 0x36C027A: loadArchive_ (LoadArchive.c:522) ==29666== by 0x36C0600: loadArchive (LoadArchive.c:626) ==29666== by 0x2C144CD: ??? (in /home/omer/haskell/ghc_2/testsuite/tests/rts/linker/linker_unload.run/linker_unload) ==29666== ==29666== Conditional jump or move depends on uninitialised value(s) ==29666== at 0x369C5B4: setOcInitialStatus (Linker.c:1305) ==29666== by 0x369C6C5: mkOc (Linker.c:1347) ==29666== by 0x369C9F6: preloadObjectFile (Linker.c:1507) ==29666== by 0x369CA8D: loadObj_ (Linker.c:1536) ==29666== by 0x369CB17: loadObj (Linker.c:1557) ==29666== by 0x3866BC: main (linker_unload.c:33) The problem is `mkOc` allocates a new `ObjectCode` and calls `setOcInitialStatus` without initializing the `status` field. `setOcInitialStatus` reads the field as first thing: static void setOcInitialStatus(ObjectCode* oc) { if (oc->status == OBJECT_DONT_RESOLVE) return; if (oc->archiveMemberName == NULL) { oc->status = OBJECT_NEEDED; } else { oc->status = OBJECT_LOADED; } } `setOcInitialStatus` is unsed in two places for two different purposes: in `mkOc` where we don't have the `status` field initialized yet (`mkOc` is supposed to initialize it), and `loadOc` where we do have `status` field initialized and we want to update it. Instead of splitting the function into two functions which are both called just once I inline the functions in the use sites and remove it. Fixes #18342 - - - - - da18ff99 by Tamar Christina at 2020-06-18T23:07:03-04:00 fix windows bootstrap due to linker changes - - - - - 2af0ec90 by Sylvain Henry at 2020-06-18T23:07:47-04:00 DynFlags: store default depth in SDocContext (#17957) It avoids having to use DynFlags to reach for pprUserLength. - - - - - d4a0be75 by Sylvain Henry at 2020-06-18T23:08:35-04:00 Move tablesNextToCode field into Platform tablesNextToCode is a platform setting and doesn't belong into DynFlags (#17957). Doing this is also a prerequisite to fix #14335 where we deal with two platforms (target and host) that may have different platform settings. - - - - - 809caedf by John Ericson at 2020-06-23T22:47:37-04:00 Switch from HscSource to IsBootInterface for module lookup in GhcMake We look up modules by their name, and not their contents. There is no way to separately reference a signature vs regular module; you get what you get. Only boot files can be referenced indepenently with `import {-# SOURCE #-}`. - - - - - 7750bd45 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Cmm: introduce SAVE_REGS/RESTORE_REGS We don't want to save both Fn and Dn register sets on x86-64 as they are aliased to the same arch register (XMMn). Moreover, when SAVE_STGREGS was used in conjunction with `jump foo [*]` which makes a set of Cmm registers alive so that they cover all arch registers used to pass parameter, we could have Fn, Dn and XMMn alive at the same time. It made the LLVM code generator choke (see #17920). Now `SAVE_REGS/RESTORE_REGS` and `jump foo [*]` use the same set of registers. - - - - - 2636794d by Sylvain Henry at 2020-06-23T22:48:18-04:00 CmmToC: don't add extern decl to parsed Cmm data Previously, if a .cmm file *not in the RTS* contained something like: ```cmm section "rodata" { msg : bits8[] "Test\n"; } ``` It would get compiled by CmmToC into: ```c ERW_(msg); const char msg[] = "Test\012"; ``` and fail with: ``` /tmp/ghc32129_0/ghc_4.hc:5:12: error: error: conflicting types for \u2018msg\u2019 const char msg[] = "Test\012"; ^~~ In file included from /tmp/ghc32129_0/ghc_4.hc:3:0: error: /tmp/ghc32129_0/ghc_4.hc:4:6: error: note: previous declaration of \u2018msg\u2019 was here ERW_(msg); ^ /builds/hsyl20/ghc/_build/install/lib/ghc-8.11.0.20200605/lib/../lib/x86_64-linux-ghc-8.11.0.20200605/rts-1.0/include/Stg.h:253:46: error: note: in definition of macro \u2018ERW_\u2019 #define ERW_(X) extern StgWordArray (X) ^ ``` See the rationale for this on https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/backends/ppr-c#prototypes Now we don't generate these extern declarations (ERW_, etc.) for top-level data. It shouldn't change anything for the RTS (the only place we use .cmm files) as it is already special cased in `GHC.Cmm.CLabel.needsCDecl`. And hand-written Cmm can use explicit extern declarations when needed. Note that it allows `cgrun069` test to pass with CmmToC (cf #15467). - - - - - 5f6a0665 by Sylvain Henry at 2020-06-23T22:48:18-04:00 LLVM: refactor and comment register padding code (#17920) - - - - - cad62ef1 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Add tests for #17920 Metric Decrease: T12150 T12234 - - - - - a2a9006b by Xavier Denis at 2020-06-23T22:48:56-04:00 Fix issue #18262 by zonking constraints after solving Zonk residual constraints in checkForExistence to reveal user type errors. Previously when `:instances` was used with instances that have TypeError constraints the result would look something like: instance [safe] s0 => Err 'A -- Defined at ../Bug2.hs:8:10 whereas after zonking, `:instances` now sees the `TypeError` and properly eliminates the constraint from the results. - - - - - 181516bc by Simon Peyton Jones at 2020-06-23T22:49:33-04:00 Fix a buglet in Simplify.simplCast This bug, revealed by #18347, is just a missing update to sc_hole_ty in simplCast. I'd missed a code path when I made the recentchanges in commit 6d49d5be904c0c01788fa7aae1b112d5b4dfaf1c Author: Simon Peyton Jones <simonpj at microsoft.com> Date: Thu May 21 12:53:35 2020 +0100 Implement cast worker/wrapper properly The fix is very easy. Two other minor changes * Tidy up in SimpleOpt.simple_opt_expr. In fact I think this is an outright bug, introduced in the fix to #18112: we were simplifying the same coercion twice *with the same substitution*, which is just wrong. It'd be a hard bug to trigger, so I just fixed it; less code too. * Better debug printing of ApplyToVal - - - - - 625a7f54 by Simon Peyton Jones at 2020-06-23T22:50:11-04:00 Two small tweaks to Coercion.simplifyArgsWorker These tweaks affect the inner loop of simplifyArgsWorker, which in turn is called from the flattener in Flatten.hs. This is a key perf bottleneck to T9872{a,b,c,d}. These two small changes have a modest but useful benefit. No change in functionality whatsoever. Relates to #18354 - - - - - b5768cce by Sylvain Henry at 2020-06-23T22:50:49-04:00 Don't use timesInt2# with GHC < 8.11 (fix #18358) - - - - - 7ad4085c by Sylvain Henry at 2020-06-23T22:51:27-04:00 Fix invalid printf format - - - - - a1f34d37 by Krzysztof Gogolewski at 2020-06-23T22:52:09-04:00 Add missing entry to freeNamesItem (#18369) - - - - - 03a708ba by Andreas Klebinger at 2020-06-25T03:54:37-04:00 Enable large address space optimization on windows. Starting with Win 8.1/Server 2012 windows no longer preallocates page tables for reserverd memory eagerly, which prevented us from using this approach in the past. We also try to allocate the heap high in the memory space. Hopefully this makes it easier to allocate things in the low 4GB of memory that need to be there. Like jump islands for the linker. - - - - - 7e6d3d09 by Roland Senn at 2020-06-25T03:54:38-04:00 In `:break ident` allow out of scope and nested identifiers (Fix #3000) This patch fixes the bug and implements the feature request of #3000. 1. If `Module` is a real module name and `identifier` a name of a top-level function in `Module` then `:break Module.identifer` works also for an `identifier` that is out of scope. 2. Extend the syntax for `:break identifier` to: :break [ModQual.]topLevelIdent[.nestedIdent]...[.nestedIdent] `ModQual` is optional and is either the effective name of a module or the local alias of a qualified import statement. `topLevelIdent` is the name of a top level function in the module referenced by `ModQual`. `nestedIdent` is optional and the name of a function nested in a let or where clause inside the previously mentioned function `nestedIdent` or `topLevelIdent`. If `ModQual` is a module name, then `topLevelIdent` can be any top level identifier in this module. If `ModQual` is missing or a local alias of a qualified import, then `topLevelIdent` must be in scope. Breakpoints can be set on arbitrarily deeply nested functions, but the whole chain of nested function names must be specified. 3. To support the new functionality rewrite the code to tab complete `:break`. - - - - - 30e42652 by Ben Gamari at 2020-06-25T03:54:39-04:00 make: Respect XELATEX variable Previously we simply ignored the XELATEX variable when building PDF documentation. - - - - - 4acc2934 by Ben Gamari at 2020-06-25T03:54:39-04:00 hadrian/make: Detect makeindex Previously we would simply assume that makeindex was available. Now we correctly detect it in `configure` and respect this conclusion in hadrian and make. - - - - - 0d61f866 by Simon Peyton Jones at 2020-06-25T03:54:40-04:00 Expunge GhcTcId GHC.Hs.Extension had type GhcPs = GhcPass 'Parsed type GhcRn = GhcPass 'Renamed type GhcTc = GhcPass 'Typechecked type GhcTcId = GhcTc The last of these, GhcTcId, is a vestige of the past. This patch expunges it from GHC. - - - - - 8ddbed4a by Adam Wespiser at 2020-06-25T03:54:40-04:00 add examples to Data.Traversable - - - - - 284001d0 by Oleg Grenrus at 2020-06-25T03:54:42-04:00 Export readBinIface_ - - - - - 90f43872 by Zubin Duggal at 2020-06-25T03:54:43-04:00 Export everything from HsToCore. This lets us reuse these functions in haddock, avoiding synchronization bugs. Also fixed some divergences with haddock in that file Updates haddock submodule - - - - - c7dd6da7 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part1) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Hs.* - GHC.Core.* - GHC.Stg.* - GHC.Cmm.* - GHC.Types.* - GHC.Data.* - GHC.Builtin.* - GHC.Parser.* - GHC.Driver.* - GHC top - - - - - 1eb997a8 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part2) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Iface.* - GHC.Llvm.* - GHC.Rename.* - GHC.Tc.* - GHC.HsToCore.* - GHC.StgToCmm.* - GHC.CmmToAsm.* - GHC.Runtime.* - GHC.Unit.* - GHC.Utils.* - GHC.SysTools.* - - - - - 67a86b4d by Oleg Grenrus at 2020-06-25T03:54:46-04:00 Add MonadZip and MonadFix instances for Complex These instances are taken from https://hackage.haskell.org/package/linear-1.21/docs/Linear-Instances.html They are the unique possible, so let they be in `base`. - - - - - c50ef26e by Artem Pelenitsyn at 2020-06-25T03:54:47-04:00 test suite: add reproducer for #17516 - - - - - fe281b27 by Roland Senn at 2020-06-25T03:54:48-04:00 Enable maxBound checks for OverloadedLists (Fixes #18172) Consider the Literal `[256] :: [Data.Word.Word8]` When the `OverloadedLists` extension is not active, then the `ol_ext` field in the `OverLitTc` record that is passed to the function `getIntegralLit` contains the type `Word8`. This is a simple type, and we can use its type constructor immediately for the `warnAboutOverflowedLiterals` function. When the `OverloadedLists` extension is active, then the `ol_ext` field contains the type family `Item [Word8]`. The function `nomaliseType` is used to convert it to the needed type `Word8`. - - - - - a788d4d1 by Ben Gamari at 2020-06-25T03:54:52-04:00 rts/Hash: Simplify freeing of HashListChunks While looking at #18348 I noticed that the treatment of HashLists are a bit more complex than necessary (which lead to some initial confusion on my part). Specifically, we allocate HashLists in chunks. Each chunk allocation makes two allocations: one for the chunk itself and one for a HashListChunk to link together the chunks for the purposes of freeing. Simplify this (and hopefully make the relationship between these clearer) but allocating the HashLists and HashListChunk in a single malloc. This will both make the implementation easier to follow and reduce C heap fragmentation. Note that even after this patch we fail to bound the size of the free HashList pool. However, this is a separate bug. - - - - - d3c2d59b by Sylvain Henry at 2020-06-25T03:54:55-04:00 RTS: avoid overflow on 32-bit arch (#18375) We're now correctly computing allocated bytes on 32-bit arch, so we get huge increases. Metric Increase: haddock.Cabal haddock.base haddock.compiler space_leak_001 - - - - - a3d69dc6 by Sebastian Graf at 2020-06-25T23:06:18-04:00 GHC.Core.Unify: Make UM actions one-shot by default This MR makes the UM monad in GHC.Core.Unify into a one-shot monad. See the long Note [The one-shot state monad trick]. See also #18202 and !3309, which applies this to all Reader/State-like monads in GHC for compile-time perf improvements. The pattern used here enables something similar to the state-hack, but is applicable to user-defined monads, not just `IO`. Metric Decrease 'runtime/bytes allocated' (test_env='i386-linux-deb9'): haddock.Cabal - - - - - 9ee58f8d by Matthias Pall Gissurarson at 2020-06-26T17:12:45+00:00 Implement the proposed -XQualifiedDo extension Co-authored-by: Facundo Domínguez <facundo.dominguez at tweag.io> QualifiedDo is implemented using the same placeholders for operation names in the AST that were devised for RebindableSyntax. Whenever the renamer checks which names to use for do syntax, it first checks if the do block is qualified (e.g. M.do { stmts }), in which case it searches for qualified names in the module M. This allows users to write {-# LANGUAGE QualifiedDo #-} import qualified SomeModule as M f x = M.do -- desugars to: y <- M.return x -- M.return x M.>>= \y -> M.return y -- M.return y M.>> M.return y -- M.return y See Note [QualifiedDo] and the users' guide for more details. Issue #18214 Proposal: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0216-qualified-do.rst Since we change the constructors `ITdo` and `ITmdo` to carry the new module name, we need to bump the haddock submodule to account or the new shape of these constructors. - - - - - ce987865 by Ryan Scott at 2020-06-27T11:55:21-04:00 Revamp the treatment of auxiliary bindings for derived instances This started as a simple fix for #18321 that organically grew into a much more sweeping refactor of how auxiliary bindings for derived instances are handled. I have rewritten `Note [Auxiliary binders]` in `GHC.Tc.Deriv.Generate` to explain all of the moving parts, but the highlights are: * Previously, the OccName of each auxiliary binding would be given a suffix containing a hash of its package name, module name, and parent data type to avoid name clashes. This was needlessly complicated, so we take the more direct approach of generating `Exact` `RdrName`s for each auxiliary binding with the same `OccName`, but using an underlying `System` `Name` with a fresh `Unique` for each binding. Unlike hashes, allocating new `Unique`s does not require any cleverness and avoid name clashes all the same... * ...speaking of which, in order to convince the renamer that multiple auxiliary bindings with the same `OccName` (but different `Unique`s) are kosher, we now use `rnLocalValBindsLHS` instead of `rnTopBindsLHS` to rename auxiliary bindings. Again, see `Note [Auxiliary binders]` for the full story. * I have removed the `DerivHsBind` constructor for `DerivStuff`—which was only used for `Data.Data`-related auxiliary bindings—and refactored `gen_Data_binds` to use `DerivAuxBind` instead. This brings the treatment of `Data.Data`-related auxiliary bindings in line with every other form of auxiliary binding. Fixes #18321. - - - - - a403eb91 by Sylvain Henry at 2020-06-27T11:55:59-04:00 ghc-bignum: fix division by zero (#18359) - - - - - 1b3d13b6 by Sylvain Henry at 2020-06-27T11:55:59-04:00 Fix ghc-bignum exceptions We must ensure that exceptions are not simplified. Previously we used: case raiseDivZero of _ -> 0## -- dummyValue But it was wrong because the evaluation of `raiseDivZero` was removed and the dummy value was directly returned. See new Note [ghc-bignum exceptions]. I've also removed the exception triggering primops which were fragile. We don't need them to be primops, we can have them exported by ghc-prim. I've also added a test for #18359 which triggered this patch. - - - - - a74ec37c by Simon Peyton Jones at 2020-06-27T11:56:34-04:00 Better loop detection in findTypeShape Andreas pointed out, in !3466, that my fix for #18304 was not quite right. This patch fixes it properly, by having just one RecTcChecker rather than (implicitly) two nested ones, in findTypeShape. - - - - - a04020b8 by Sylvain Henry at 2020-06-27T11:57:11-04:00 DynFlags: don't store buildTag `DynFlags.buildTag` was a field created from the set of Ways in `DynFlags.ways`. It had to be kept in sync with `DynFlags.ways` which was fragile. We want to avoid global state like this (#17957). Moreover in #14335 we also want to support loading units with different ways: target units would still use `DynFlags.ways` but plugins would use `GHC.Driver.Ways.hostFullWays`. To avoid having to deal both with build tag and with ways, we recompute the buildTag on-the-fly (should be pretty cheap) and we remove `DynFlags.buildTag` field. - - - - - 0e83efa2 by Krzysztof Gogolewski at 2020-06-27T11:57:49-04:00 Don't generalize when typechecking a tuple section The code is simpler and cleaner. - - - - - d8ba9e6f by Peter Trommler at 2020-06-28T09:19:11-04:00 RTS: Refactor Haskell-C glue for PPC 64-bit Make sure the stack is 16 byte aligned even when reserved stack bytes are not a multiple of 16 bytes. Avoid saving r2 (TOC). On ELF v1 the function descriptor of StgReturn has the same TOC as StgRun, on ELF v2 the TOC is recomputed in the function prologue. Use the ABI provided functions to save clobbered GPRs and FPRs. Improve comments. Describe what the stack looks like and how it relates to the respective ABIs. - - - - - 42f797b0 by Ryan Scott at 2020-06-28T09:19:46-04:00 Use NHsCoreTy to embed types into GND-generated code `GeneralizedNewtypeDeriving` is in the unique situation where it must produce an `LHsType GhcPs` from a Core `Type`. Historically, this was done with the `typeToLHsType` function, which walked over the entire `Type` and attempted to construct an `LHsType` with the same overall structure. `typeToLHsType` is quite complicated, however, and has been the subject of numerous bugs over the years (e.g., #14579). Luckily, there is an easier way to accomplish the same thing: the `XHsType` constructor of `HsType`. `XHsType` bundles an `NHsCoreTy`, which allows embedding a Core `Type` directly into an `HsType`, avoiding the need to laboriously convert from one to another (as `typeToLHsType` did). Moreover, renaming and typechecking an `XHsType` is simple, since one doesn't need to do anything to a Core `Type`... ...well, almost. For the reasons described in `Note [Typechecking NHsCoreTys]` in `GHC.Tc.Gen.HsType`, we must apply a substitution that we build from the local `tcl_env` type environment. But that's a relatively modest price to pay. Now that `GeneralizedNewtypeDeriving` uses `NHsCoreTy`, the `typeToLHsType` function no longer has any uses in GHC, so this patch rips it out. Some additional tweaks to `hsTypeNeedsParens` were necessary to make the new `-ddump-deriv` output correctly parenthesized, but other than that, this patch is quite straightforward. This is a mostly internal refactoring, although it is likely that `GeneralizedNewtypeDeriving`-generated code will now need fewer language extensions in certain situations than it did before. - - - - - 68530b1c by Jan Hrček at 2020-06-28T09:20:22-04:00 Fix duplicated words and typos in comments and user guide - - - - - 15b79bef by Ryan Scott at 2020-06-28T09:20:57-04:00 Add integer-gmp's ghc.mk and GNUmakefile to .gitignore - - - - - bfa5698b by Simon Peyton Jones at 2020-06-28T09:21:32-04:00 Fix a typo in Lint This simple error in GHC.Core.Litn.lintJoinLams meant that Lint reported bogus errors. Fixes #18399 - - - - - 71006532 by Ryan Scott at 2020-06-30T07:10:42-04:00 Reject nested foralls/contexts in instance types more consistently GHC is very wishy-washy about rejecting instance declarations with nested `forall`s or contexts that are surrounded by outermost parentheses. This can even lead to some strange interactions with `ScopedTypeVariables`, as demonstrated in #18240. This patch makes GHC more consistently reject instance types with nested `forall`s/contexts so as to prevent these strange interactions. On the implementation side, this patch tweaks `splitLHsInstDeclTy` and `getLHsInstDeclHead` to not look through parentheses, which can be semantically significant. I've added a `Note [No nested foralls or contexts in instance types]` in `GHC.Hs.Type` to explain why. This also introduces a `no_nested_foralls_contexts_err` function in `GHC.Rename.HsType` to catch nested `forall`s/contexts in instance types. This function is now used in `rnClsInstDecl` (for ordinary instance declarations) and `rnSrcDerivDecl` (for standalone `deriving` declarations), the latter of which fixes #18271. On the documentation side, this adds a new "Formal syntax for instance declaration types" section to the GHC User's Guide that presents a BNF-style grammar for what is and isn't allowed in instance types. Fixes #18240. Fixes #18271. - - - - - bccf3351 by Sylvain Henry at 2020-06-30T07:10:46-04:00 Add ghc-bignum to 8.12 release notes - - - - - 81704a6f by David Eichmann at 2020-06-30T07:10:48-04:00 Update ssh keys in CI performance metrics upload script - - - - - 85310fb8 by Joshua Price at 2020-06-30T07:10:49-04:00 Add missing Ix instances for tuples of size 6 through 15 (#16643) - - - - - cbb6b62f by Vladislav Zavialov at 2020-07-01T15:41:38-04:00 Implement -XLexicalNegation (GHC Proposal #229) This patch introduces a new extension, -XLexicalNegation, which detects whether the minus sign stands for negation or subtraction using the whitespace-based rules described in GHC Proposal #229. Updates haddock submodule. - - - - - fb5a0d01 by Martin Handley at 2020-07-01T15:42:14-04:00 #17169: Clarify Fixed's Enum instance. - - - - - b316804d by Simon Peyton Jones at 2020-07-01T15:42:49-04:00 Improve debug tracing for substitution This patch improves debug tracing a bit (#18395) * Remove the ancient SDoc argument to substitution, replacing it with a HasDebugCallStack constraint. The latter does the same job (indicate the call site) but much better. * Add HasDebugCallStack to simpleOptExpr, exprIsConApp_maybe I needed this to help nail the lookupIdSubst panic in #18326, #17784 - - - - - 5c9fabb8 by Hécate at 2020-07-01T15:43:25-04:00 Add most common return values for `os` and `arch` - - - - - 76d8cc74 by Ryan Scott at 2020-07-01T15:44:01-04:00 Desugar quoted uses of DerivingVia and expression type signatures properly The way that `GHC.HsToCore.Quote` desugared quoted `via` types (e.g., `deriving via forall a. [a] instance Eq a => Eq (List a)`) and explicit type annotations in signatures (e.g., `f = id @a :: forall a. a -> a`) was completely wrong, as it did not implement the scoping guidelines laid out in `Note [Scoped type variables in bindings]`. This is easily fixed. While I was in town, I did some minor cleanup of related Notes: * `Note [Scoped type variables in bindings]` and `Note [Scoped type variables in class and instance declarations]` say very nearly the same thing. I decided to just consolidate the two Notes into `Note [Scoped type variables in quotes]`. * `Note [Don't quantify implicit type variables in quotes]` is somewhat outdated, as it predates GHC 8.10, where the `forall`-or-nothing rule requires kind variables to be explicitly quantified in the presence of an explicit `forall`. As a result, the running example in that Note doesn't even compile. I have changed the example to something simpler that illustrates the same point that the original Note was making. Fixes #18388. - - - - - 44d6a335 by Andreas Klebinger at 2020-07-02T02:54:54-04:00 T16012: Be verbose on failure. - - - - - f9853330 by Ryan Scott at 2020-07-02T02:55:29-04:00 Bump ghc-prim version to 0.7.0 Fixes #18279. Bumps the `text` submodule. - - - - - 23e4e047 by Sylvain Henry at 2020-07-02T10:46:31-04:00 Hadrian: fix PowerPC64le support (#17601) [ci skip] - - - - - 3cdd8d69 by Sylvain Henry at 2020-07-02T10:47:08-04:00 NCG: correctly handle addresses with huge offsets (#15570) Before this patch we could generate addresses of this form: movzbl cP0_str+-9223372036854775808,%eax The linker can't handle them because the offset is too large: ld.lld: error: Main.o:(.text+0xB3): relocation R_X86_64_32S out of range: -9223372036852653050 is not in [-2147483648, 2147483647] With this patch we detect those cases and generate: movq $-9223372036854775808,%rax addq $cP0_str,%rax movzbl (%rax),%eax I've also refactored `getAmode` a little bit to make it easier to understand and to trace. - - - - - 4d90b3ff by Gabor Greif at 2020-07-02T20:07:59-04:00 No need for CURSES_INCLUDE_DIRS This is a leftover from ef63ff27251a20ff11e58c9303677fa31e609a88 - - - - - f08d6316 by Sylvain Henry at 2020-07-02T20:08:36-04:00 Replace Opt_SccProfilingOn flag with sccProfilingEnabled helper function SCC profiling was enabled in a convoluted way: if WayProf was enabled, Opt_SccProfilingOn general flag was set (in `GHC.Driver.Ways.wayGeneralFlags`), and then this flag was queried in various places. There is no need to go via general flags, so this patch defines a `sccProfilingEnabled :: DynFlags -> Bool` helper function that just checks whether WayProf is enabled. - - - - - 8cc7274b by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Only allocate the Censuses that we need When not LDV profiling there is no reason to allocate 32 Censuses; one will do. This is a very small memory footprint optimisation, but it comes for free. - - - - - b835112c by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Free old allocations when reinitialising Censuses Previously when not LDV profiling we would repeatedly reinitialise `censuses[0]` with `initEra`. This failed to free the `Arena` and `HashTable` from the old census, resulting in a memory leak. Fixes #18348. - - - - - 34be6523 by Valery Tolstov at 2020-07-03T02:50:03-04:00 Mention flags that are not enabled by -Wall (#18372) * Mention missing flags that are not actually enabled by -Wall (docs/users_guide/using-warnings.rst) * Additionally remove -Wmissing-monadfail-instances from the list of flags enabled by -Wcompat, as it is not the case since 8.8 - - - - - edc8d22b by Sylvain Henry at 2020-07-03T02:50:40-04:00 LLVM: support R9 and R10 registers d535ef006d85dbdb7cda2b09c5bc35cb80108909 allowed the use of up to 10 vanilla registers but didn't update LLVM backend to support them. This patch fixes it. - - - - - 4bf18646 by Simon Peyton Jones at 2020-07-03T08:37:42+01:00 Improve handling of data type return kinds Following a long conversation with Richard, this patch tidies up the handling of return kinds for data/newtype declarations (vanilla, family, and instance). I have substantially edited the Notes in TyCl, so they would bear careful reading. Fixes #18300, #18357 In GHC.Tc.Instance.Family.newFamInst we were checking some Lint-like properties with ASSSERT. Instead Richard and I have added a proper linter for axioms, and called it from lintGblEnv, which in turn is called in tcRnModuleTcRnM New tests (T18300, T18357) cause an ASSERT failure in HEAD. - - - - - 41d26492 by Sylvain Henry at 2020-07-03T17:33:59-04:00 DynFlags: avoid the use of sdocWithDynFlags in GHC.Core.Rules (#17957) - - - - - 7aa6ef11 by Hécate at 2020-07-03T17:34:36-04:00 Add the __GHC_FULL_VERSION__ CPP macro to expose the full GHC version - - - - - e61d5395 by Chaitanya Koparkar at 2020-07-07T13:55:59-04:00 ghc-prim: Turn some comments into haddocks [ci skip] - - - - - 37743f91 by John Ericson at 2020-07-07T13:56:00-04:00 Support `timesInt2#` in LLVM backend - - - - - 46397e53 by John Ericson at 2020-07-07T13:56:00-04:00 `genericIntMul2Op`: Call `genericWordMul2Op` directly This unblocks a refactor, and removes partiality. It might be a PowerPC regression but that should be fixable. - - - - - 8a1c0584 by John Ericson at 2020-07-07T13:56:00-04:00 Simplify `PrimopCmmEmit` Follow @simonpj's suggestion of pushing the "into regs" logic into `emitPrimOp`. With the previous commit getting rid of the recursion in `genericIntMul2Op`, this is now an easy refactor. - - - - - 6607f203 by John Ericson at 2020-07-07T13:56:00-04:00 `opAllDone` -> `opIntoRegs` The old name was and terrible and became worse after the previous commit's refactor moved non-trivial funcationlity into its body. - - - - - fdcc53ba by Sylvain Henry at 2020-07-07T13:56:00-04:00 Optimise genericIntMul2Op We shouldn't directly call 'genericWordMul2Op' in genericIntMul2Op because a target may provide a faster primop for 'WordMul2Op': we'd better use it! - - - - - 686e7225 by Moritz Angermann at 2020-07-07T13:56:01-04:00 [linker/rtsSymbols] More linker symbols Mostly symbols needed for aarch64/armv7l and in combination with musl, where we have to rely on loading *all* objects/archives - __stack_chk_* only when not DYNAMIC - - - - - 3f60b94d by Moritz Angermann at 2020-07-07T13:56:01-04:00 better if guards. - - - - - 7abffced by Moritz Angermann at 2020-07-07T13:56:01-04:00 Fix (1) - - - - - cdfeb3f2 by Moritz Angermann at 2020-07-07T13:56:01-04:00 AArch32 symbols only on aarch32. - - - - - f496c955 by Adam Sandberg Ericsson at 2020-07-07T13:56:02-04:00 add -flink-rts flag to link the rts when linking a shared or static library #18072 By default we don't link the RTS when linking shared libraries because in the most usual mode a shared library is an intermediary product, for example a Haskell library, that will be linked into some executable in the end. So we wish to defer the RTS flavour to link to the final link. However sometimes the final product is the shared library, for example when writing a plugin for some other system, so we do wish the shared library to link the RTS. For consistency we also make -staticlib honor this flag and its inversion. -staticlib currently implies -flink-shared. - - - - - c59faf67 by Stefan Schulze Frielinghaus at 2020-07-07T13:56:04-04:00 hadrian: link check-ppr against debugging RTS if ghcDebugged - - - - - 0effc57d by Adam Sandberg Ericsson at 2020-07-07T13:56:05-04:00 rts linker: teach the linker about GLIBC's special handling of *stat, mknod and atexit functions #7072 - - - - - 96153433 by Adam Sandberg Ericsson at 2020-07-07T13:56:06-04:00 hadrian: make hadrian/ghci use the bootstrap compiler from configure #18190 - - - - - 4d24f886 by Adam Sandberg Ericsson at 2020-07-07T13:56:07-04:00 hadrian: ignore cabal configure verbosity related flags #18131 - - - - - 7332bbff by Ben Gamari at 2020-07-07T13:56:08-04:00 testsuite: Widen T12234 acceptance window to 2% Previously it wasn't uncommon to see +/-1% fluctuations in compiler allocations on this test. - - - - - 180b6313 by Gabor Greif at 2020-07-07T13:56:08-04:00 When running libtool, report it as such - - - - - d3bd6897 by Sylvain Henry at 2020-07-07T13:56:11-04:00 BigNum: rename BigNat types Before this patch BigNat names were confusing because we had: * GHC.Num.BigNat.BigNat: unlifted type used everywhere else * GHC.Num.BigNat.BigNatW: lifted type only used to share static constants * GHC.Natural.BigNat: lifted type only used for backward compatibility After this patch we have: * GHC.Num.BigNat.BigNat#: unlifted type * GHC.Num.BigNat.BigNat: lifted type (reexported from GHC.Natural) Thanks to @RyanGlScott for spotting this. - - - - - 929d26db by Sylvain Henry at 2020-07-07T13:56:12-04:00 Bignum: don't build ghc-bignum with stage0 Noticed by @Ericson2314 - - - - - d25b6851 by Sylvain Henry at 2020-07-07T13:56:12-04:00 Hadrian: ghc-gmp.h shouldn't be a compiler dependency - - - - - 0ddae2ba by Sylvain Henry at 2020-07-07T13:56:14-04:00 DynFlags: factor out pprUnitId from "Outputable UnitId" instance - - - - - 204f3f5d by Krzysztof Gogolewski at 2020-07-07T13:56:18-04:00 Remove unused function pprHsForAllExtra (#18423) The function `pprHsForAllExtra` was called only on `Nothing` since 2015 (1e041b7382b6aa). - - - - - 3033e0e4 by Adam Sandberg Ericsson at 2020-07-08T20:36:49-04:00 hadrian: add flag to skip rebuilding dependency information #17636 - - - - - b7de4b96 by Stefan Schulze Frielinghaus at 2020-07-09T09:49:22-04:00 Fix GHCi :print on big-endian platforms On big-endian platforms executing import GHC.Exts data Foo = Foo Float# deriving Show foo = Foo 42.0# foo :print foo results in an arithmetic overflow exception which is caused by function index where moveBytes equals word_size - (r + item_size_b) * 8 Here we have a mixture of units. Both, word_size and item_size_b have unit bytes whereas r has unit bits. On 64-bit platforms moveBytes equals then 8 - (0 + 4) * 8 which results in a negative and therefore invalid second parameter for a shiftL operation. In order to make things more clear the expression (word .&. (mask `shiftL` moveBytes)) `shiftR` moveBytes is equivalent to (word `shiftR` moveBytes) .&. mask On big-endian platforms the shift must be a left shift instead of a right shift. For symmetry reasons not a mask is used but two shifts in order to zero out bits. Thus the fixed version equals case endian of BigEndian -> (word `shiftL` moveBits) `shiftR` zeroOutBits `shiftL` zeroOutBits LittleEndian -> (word `shiftR` moveBits) `shiftL` zeroOutBits `shiftR` zeroOutBits Fixes #16548 and #14455 - - - - - 3656dff8 by Sylvain Henry at 2020-07-09T09:50:01-04:00 LLVM: fix MO_S_Mul2 support (#18434) The value indicating if the carry is useful wasn't taken into account. - - - - - d9f09506 by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Define multiShotIO and use it in mkSplitUniqueSupply This patch is part of the ongoing eta-expansion saga; see #18238. It implements a neat trick (suggested by Sebastian Graf) that allows the programmer to disable the default one-shot behaviour of IO (the "state hack"). The trick is to use a new multiShotIO function; see Note [multiShotIO]. For now, multiShotIO is defined here in Unique.Supply; but it should ultimately be moved to the IO library. The change is necessary to get good code for GHC's unique supply; see Note [Optimising the unique supply]. However it makes no difference to GHC as-is. Rather, it makes a difference when a subsequent commit Improve eta-expansion using ArityType lands. - - - - - bce695cc by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Make arityType deal with join points As Note [Eta-expansion and join points] describes, this patch makes arityType deal correctly with join points. What was there before was not wrong, but yielded lower arities than it could. Fixes #18328 In base GHC this makes no difference to nofib. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- n-body -0.1% -0.1% -1.2% -1.1% 0.0% -------------------------------------------------------------------------------- Min -0.1% -0.1% -55.0% -56.5% 0.0% Max -0.0% 0.0% +16.1% +13.4% 0.0% Geometric Mean -0.0% -0.0% -30.1% -31.0% -0.0% But it starts to make real difference when we land the change to the way mkDupableAlts handles StrictArg, in fixing #13253 and friends. I think this is because we then get more non-inlined join points. - - - - - 2b7c71cb by Simon Peyton Jones at 2020-07-11T12:17:02-04:00 Improve eta-expansion using ArityType As #18355 shows, we were failing to preserve one-shot info when eta-expanding. It's rather easy to fix, by using ArityType more, rather than just Arity. This patch is important to suport the one-shot monad trick; see #18202. But the extra tracking of one-shot-ness requires the patch Define multiShotIO and use it in mkSplitUniqueSupply If that patch is missing, ths patch makes things worse in GHC.Types.Uniq.Supply. With it, however, we see these improvements T3064 compiler bytes allocated -2.2% T3294 compiler bytes allocated -1.3% T12707 compiler bytes allocated -1.3% T13056 compiler bytes allocated -2.2% Metric Decrease: T3064 T3294 T12707 T13056 - - - - - de139cc4 by Artem Pelenitsyn at 2020-07-12T02:53:20-04:00 add reproducer for #15630 - - - - - c4de6a7a by Andreas Klebinger at 2020-07-12T02:53:55-04:00 Give Uniq[D]FM a phantom type for its key. This fixes #17667 and should help to avoid such issues going forward. The changes are mostly mechanical in nature. With two notable exceptions. * The register allocator. The register allocator references registers by distinct uniques. However they come from the types of VirtualReg, Reg or Unique in various places. As a result we sometimes cast the key type of the map and use functions which operate on the now typed map but take a raw Unique as actual key. The logic itself has not changed it just becomes obvious where we do so now. * <Type>Env Modules. As an example a ClassEnv is currently queried using the types `Class`, `Name`, and `TyCon`. This is safe since for a distinct class value all these expressions give the same unique. getUnique cls getUnique (classTyCon cls) getUnique (className cls) getUnique (tcName $ classTyCon cls) This is for the most part contained within the modules defining the interface. However it requires us to play dirty when we are given a `Name` to lookup in a `UniqFM Class a` map. But again the logic did not change and it's for the most part hidden behind the Env Module. Some of these cases could be avoided by refactoring but this is left for future work. We also bump the haddock submodule as it uses UniqFM. - - - - - c2cfdfde by Aaron Allen at 2020-07-13T09:00:33-04:00 Warn about empty Char enumerations (#18402) Currently the "Enumeration is empty" warning (-Wempty-enumerations) only fires for numeric literals. This patch adds support for `Char` literals so that enumerating an empty list of `Char`s will also trigger the warning. - - - - - c3ac87ec by Stefan Schulze Frielinghaus at 2020-07-13T09:01:10-04:00 hadrian: build check-ppr dynamic if GHC is build dynamic Fixes #18361 - - - - - 9ad072b4 by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Use dumpStyle when printing inlinings This just makes debug-printing consistent, and more informative. - - - - - e78c4efb by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Comments only - - - - - 7ccb760b by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Reduce result discount in conSize Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c - - - - - 7f0b671e by Ben Gamari at 2020-07-13T14:52:49-04:00 testsuite: Widen acceptance threshold on T5837 This test is positively tiny and consequently the bytes allocated measurement will be relatively noisy. Consequently I have seen this fail spuriously quite often. - - - - - 118e1c3d by Alp Mestanogullari at 2020-07-14T21:30:52-04:00 compiler: re-engineer the treatment of rebindable if Executing on the plan described in #17582, this patch changes the way if expressions are handled in the compiler in the presence of rebindable syntax. We get rid of the SyntaxExpr field of HsIf and instead, when rebindable syntax is on, we rewrite the HsIf node to the appropriate sequence of applications of the local `ifThenElse` function. In order to be able to report good error messages, with expressions as they were written by the user (and not as desugared by the renamer), we make use of TTG extensions to extend GhcRn expression ASTs with an `HsExpansion` construct, which keeps track of a source (GhcPs) expression and the desugared (GhcRn) expression that it gives rise to. This way, we can typecheck the latter while reporting the former in error messages. In order to discard the error context lines that arise from typechecking the desugared expressions (because they talk about expressions that the user has not written), we carefully give a special treatment to the nodes fabricated by this new renaming-time transformation when typechecking them. See Note [Rebindable syntax and HsExpansion] for more details. The note also includes a recipe to apply the same treatment to other rebindable constructs. Tests 'rebindable11' and 'rebindable12' have been added to make sure we report identical error messages as before this patch under various circumstances. We also now disable rebindable syntax when processing untyped TH quotes, as per the discussion in #18102 and document the interaction of rebindable syntax and Template Haskell, both in Note [Template Haskell quotes and Rebindable Syntax] and in the user guide, adding a test to make sure that we do not regress in that regard. - - - - - 64c774b0 by Andreas Klebinger at 2020-07-14T21:31:27-04:00 Explain why keeping DynFlags in AnalEnv saves allocation. - - - - - 254245d0 by Ben Gamari at 2020-07-14T21:32:03-04:00 docs/users-guide: Update default -funfolding-use-threshold value This was changed in 3d2991f8 but I neglected to update the documentation. Fixes #18419. - - - - - 4c259f86 by Andreas Klebinger at 2020-07-14T21:32:41-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. - - - - - 23797224 by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 .gitlab: re-enable integer-simple substitute (BIGNUM_BACKEND) Recently build system migrated from INTEGER_LIBRARY to BIGNUM_BACKEND. But gitlab CI was never updated. Let's enable BIGNUM_BACKEND=native. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - e0db878a by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 ghc-bignum: bring in sync .hs-boot files with module declarations Before this change `BIGNUM_BACKEND=native` build was failing as: ``` libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs:708:16: error: * Variable not in scope: naturalFromBigNat# :: WordArray# -> t * Perhaps you meant one of these: `naturalFromBigNat' (imported from GHC.Num.Natural), `naturalToBigNat' (imported from GHC.Num.Natural) | 708 | m' = naturalFromBigNat# m | ``` This happens because `.hs-boot` files are slightly out of date. This change brings in data and function types in sync. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - c9f65c36 by Stefan Schulze Frielinghaus at 2020-07-14T21:33:57-04:00 rts/Disassembler.c: Use FMT_HexWord for printing values in hex format - - - - - 58ae62eb by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 macOS: Load frameworks without stating them first. macOS Big Sur makes the following change to how frameworks are shipped with the OS: > New in macOS Big Sur 11 beta, the system ships with a built-in > dynamic linker cache of all system-provided libraries. As part of > this change, copies of dynamic libraries are no longer present on > the filesystem. Code that attempts to check for dynamic library > presence by looking for a file at a path or enumerating a directory > will fail. Instead, check for library presence by attempting to > dlopen() the path, which will correctly check for the library in the > cache. (62986286) https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/ Therefore, the previous method of checking whether a library exists before attempting to load it makes GHC.Runtime.Linker.loadFramework fail to find frameworks installed at /System/Library/Frameworks. GHC.Runtime.Linker.loadFramework now opportunistically loads the framework libraries without checking for their existence first, failing only if all attempts to load a given framework from any of the various possible locations fail. - - - - - cdc4a6b0 by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 loadFramework: Output the errors collected in all loading attempts. With the recent change away from first finding and then loading a framework, loadFramework had no way of communicating the real reason why loadDLL failed if it was any reason other than the framework missing from the file system. It now collects all loading attempt errors into a list and concatenates them into a string to return to the caller. - - - - - 51dbfa52 by Ben Gamari at 2020-07-15T04:05:34-04:00 StgToCmm: Use CmmRegOff smart constructor Previously we would generate expressions of the form `CmmRegOff BaseReg 0`. This should do no harm (and really should be handled by the NCG anyways) but it's better to just generate a plain `CmmReg`. - - - - - ae11bdfd by Ben Gamari at 2020-07-15T04:06:08-04:00 testsuite: Add regression test for #17744 Test due to @monoidal. - - - - - 0e3c277a by Ben Gamari at 2020-07-15T16:41:01-04:00 Bump Cabal submodule Updates a variety of tests as Cabal is now more strict about Cabal file form. - - - - - ceed994a by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Drop Windows Vista support, require Windows 7 - - - - - 00a23bfd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Update Windows FileSystem wrapper utilities. - - - - - 459e1c5f by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Use SlimReaderLocks and ConditonalVariables provided by the OS instead of emulated ones - - - - - 763088fc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Small linker comment and ifdef cleanups - - - - - 1a228ff9 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Flush event logs eagerly. - - - - - e9e04dda by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Refactor Buffer structures to be able to track async operations - - - - - 356dc3fe by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Implement new Console API - - - - - 90e69f77 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add IOPort synchronization primitive - - - - - 71245fcc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add new io-manager cmdline options - - - - - d548a3b3 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Init Windows console Codepage to UTF-8. - - - - - 58ef6366 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add unsafeSplat to GHC.Event.Array - - - - - d660725e by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add size and iterate to GHC.Event.IntTable. - - - - - 050da6dd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Switch Testsuite to test winio by default - - - - - 4bf542bf by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Multiple refactorings and support changes. - - - - - 4489af6b by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core threaded I/O manager - - - - - 64d8f2fe by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core non-threaded I/O manager - - - - - 8da15a09 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix a scheduler bug with the threaded-runtime. - - - - - 84ea3d14 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Relaxing some constraints in io-manager. - - - - - ccf0d107 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix issues with non-threaded I/O manager after split. - - - - - b492fe6e by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Remove some barf statements that are a bit strict. - - - - - 01423fd2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Expand comments describing non-threaded loop - - - - - 4b69004f by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: fix FileSize unstat-able handles - - - - - 9b384270 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Implement new tempfile routines for winio - - - - - f1e0be82 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix input truncation when reading from handle. This was caused by not upholding the read buffer invariant that bufR == bufL == 0 for empty read buffers. - - - - - e176b625 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix output truncation for writes larger than buffer size - - - - - a831ce0e by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Rewrite bufWrite. I think it's far easier to follow the code now. It's also correct now as I had still missed a spot where we didn't update the offset. - - - - - 6aefdf62 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix offset set by bufReadEmpty. bufReadEmpty returns the bytes read *including* content that was already buffered, But for calculating the offset we only care about the number of bytes read into the new buffer. - - - - - 750ebaee by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Clean up code surrounding IOPort primitives. According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc. - - - - - ffd31db9 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix multi threaded threadDelay and a few other small changes. Multithreaded threadDelay suffered from a race condition based on the ioManagerStatus. Since the status isn't needed for WIO I removed it completely. This resulted in a light refactoring, as consequence we will always wake up the IO manager using interruptSystemManager, which uses `postQueuedCompletionStatus` internally. I also added a few comments which hopefully makes the code easier to dive into for the next person diving in. - - - - - 6ec26df2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 wionio: Make IO subsystem check a no-op on non-windows platforms. - - - - - 29bcd936 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Set handle offset when opening files in Append mode. Otherwise we would truncate the file. - - - - - 55c29700 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Remove debug event log trace - - - - - 9acb9f40 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix sqrt and openFile009 test cases - - - - - 57017cb7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Allow hp2ps to build with -DDEBUG - - - - - b8cd9995 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update output of T9681 since we now actually run it. - - - - - 10af5b14 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: A few more improvements to the IOPort primitives. - - - - - 39afc4a7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix expected tempfiles output. Tempfiles now works properly on windows, as such we can delete the win32 specific output. - - - - - 99db46e0 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Assign thread labels to IOManager threads. - - - - - be6af732 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Properly check for the tso of an incall to be zero. - - - - - e2c6dac7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark FD instances as unsupported under WINIO. - - - - - fd02ceed by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix threadDelay maxBound invocations. Instead of letting the ns timer overflow now clamp it at (maxBound :: Word64) ns. That still gives a few hundred years. - - - - - bc79f9f1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comments/cleanup an import in base - - - - - 1d197f4b by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark outstanding_service_requests volatile. As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration. - - - - - dc438186 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Make last_event a local variable - - - - - 2fc957c5 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comment about thread safety of processCompletion. - - - - - 4c026b6c by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: nonthreaded: Create io processing threads in main thread. We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread. - - - - - f47c7208 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add an exported isHeapAlloced function to the RTS - - - - - cc5d7bb1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Queue IO processing threads at the front of the queue. This will unblock the IO thread sooner hopefully leading to higher throughput in some situations. - - - - - e7630115 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: ThreadDelay001: Use higher resolution timer. - - - - - 451b5f96 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update T9681 output, disable T4808 on windows. T4808 tests functionality of the FD interface which won't be supported under WINIO. T9681 just has it's expected output tweaked. - - - - - dd06f930 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Wake io manager once per registerTimeout. Which is implicitly done in editTimeouts, so need to wake it up twice. - - - - - e87d0bf9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update placeholder comment with actual function name. - - - - - fc9025db by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Always lock win32 event queue - - - - - c24c9a1f by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Display thread labels when tracing scheduler events. - - - - - 06542b03 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Refactor non-threaded runner thread and scheduler interface. Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event. - - - - - 256299b1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove outstanding_requests from runner. We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port. - - - - - 3ebd8ad9 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Various fixes related to rebase and testdriver - - - - - 6be6bcba by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Fix rebase artifacts - - - - - 2c649dc3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename unsafeSplat to unsafeCopyFromBuffer - - - - - a18b73f3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove unused size/iterate operations from IntTable - - - - - 16bab48e by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Detect running IO Backend via peeking at RtsConfig - - - - - 8b8405a0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update temp path so GCC etc can handle it. Also fix PIPE support, clean up error casting, fix memory leaks - - - - - 2092bc54 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Minor comments/renamings - - - - - a5b5b6c0 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Checking if an error code indicates completion is now a function. - - - - - 362176fd by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Small refactor in withOverlappedEx - - - - - 32e20597 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: A few comments and commented out dbxIO - - - - - a4bfc1d9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't drop buffer offset in byteView/cwcharView - - - - - b3ad2a54 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: revert BHandle changes. - - - - - 3dcd87e2 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Fix imports - - - - - 5a371890 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update ghc-cabal to handle new Cabal submodule bump - - - - - d07ebe0d by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Only compile sources on Windows - - - - - dcb42393 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Actually return Nothing on EOF for non-blocking read - - - - - 895a3beb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate logic in encodeMultiByte[Raw]IO. - - - - - e06e6734 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate openFile logic - - - - - b59430c0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: fix -werror issue in encoding file - - - - - f8d39a51 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't mention windows specific functions when building on Linux. - - - - - 6a533d2a by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add a note about file locking in the RTS. - - - - - cf37ce34 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Add version to @since annotation - - - - - 0fafa2eb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename GHC.Conc.IOCP -> GHC.Conc.WinIO - - - - - 1854fc23 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Expand GHC.Conc.POSIX description It now explains users may not use these functions when using the old IO manager. - - - - - fcc7ba41 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Fix potential spaceleak in __createUUIDTempFileErrNo - - - - - 6b3fd9fa by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant -Wno-missing-signatures pragmas - - - - - 916fc861 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Make it explicit that we only create one IO manager - - - - - f260a721 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Note why we don't use blocking waits. - - - - - aa0a4bbf by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove commented out pragma - - - - - d679b544 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant buffer write in Handle/Text.hs:bufReadEmpty - - - - - d3f94368 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename SmartHandles to StdHandles - - - - - bd6b8ec1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add comment stating failure behaviour for getUniqueFileInfo. - - - - - 12846b85 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update IOPort haddocks. - - - - - 9f39fb14 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Add a note cross reference - - - - - 62dd5a73 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Name Haskell/OS I/O Manager explicitly in Note - - - - - fa807828 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Expand BlockedOnIOCompletion description. - - - - - f0880a1d by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove historical todos - - - - - 8e58e714 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Update note, remove debugging pragma. - - - - - aa4d84d5 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: flushCharReadBuffer shouldn't need to adjust offsets. - - - - - e580893a by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove obsolete comment about cond. variables - - - - - d54e9d79 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix initial linux validate build - - - - - 3cd4de46 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix ThreadDelay001 CPP - - - - - c88b1b9f by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix openFile009 merge conflict leftover - - - - - 849e8889 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept T9681 output. GHC now reports String instead of [Char]. - - - - - e7701818 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix cabal006 after upgrading cabal submodule Demand cabal 2.0 syntax instead of >= 1.20 as required by newer cabal versions. - - - - - a44f0373 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix stderr output for ghci/linking/dyn tests. We used to filter rtsopts, i opted to instead just accept the warning of it having no effect. This works both for -rtsopts, as well as -with-rtsopts which winio adds. - - - - - 515d9896 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T15261b stdout for --io-manager flag. - - - - - 949aaacc by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T5435_dyn_asm stderr The warning about rtsopts having no consequences is expected. So accept new stderr. - - - - - 7d424e1e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Also accept T7037 stderr - - - - - 1f009768 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal04 by filtering rts args - - - - - 981a9f2e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal01 by accepting expected stderr - - - - - b7b0464e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix safePkg01 by accepting expected stderr - - - - - 32734b29 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix T5435_dyn_gcc by accepting expected stderr - - - - - acc5cebf by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix tempfiles test on linux - - - - - c577b789 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for T3807 - - - - - c108c527 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload - - - - - 2b0b9a08 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload_multiple_objs - - - - - 67afb03c by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify wording on conditional variables. - - - - - 3bd41572 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify comment on cooked mode. - - - - - ded58a03 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: update lockfile signature and remove mistaken symbol in rts. - - - - - 2143c492 by Ben Gamari at 2020-07-15T16:41:04-04:00 testsuite: Add winio and winio_threaded ways Reverts many of the testsuite changes - - - - - c0979cc5 by Ben Gamari at 2020-07-16T10:56:54-04:00 Merge remote-tracking branch 'origin/wip/winio' - - - - - 750a1595 by Ben Gamari at 2020-07-18T07:26:41-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. - - - - - 6ba6a881 by Hécate at 2020-07-18T07:26:42-04:00 Implement `fullCompilerVersion` Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403 This MR adds `fullCompilerVersion`, a function that shares the same backend as the `--numeric-version` GHC flag, exposing a full, three-digit version datatype. - - - - - e6cf27df by Hécate at 2020-07-18T07:26:43-04:00 Add a Lint hadrian rule and an .hlint.yaml file in base/ - - - - - bcb177dd by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Allow multiple case branches to have a higher rank type As #18412 points out, it should be OK for multiple case alternatives to have a higher rank type, provided they are all the same. This patch implements that change. It sweeps away GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it with an enhanced version of fillInferResult. The basic change to fillInferResult is to permit the case in which another case alternative has already filled in the result; and in that case simply unify. It's very simple actually. See the new Note [fillInferResult] in TcMType Other refactoring: - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType (previously some of it was in Unify) - Move tcInstType and friends from TcMType to Instantiate, where it more properly belongs. (TCMType was getting very long.) - - - - - e5525a51 by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Improve typechecking of NPlusK patterns This patch (due to Richard Eisenberg) improves documentation of the wrapper returned by tcSubMult (see Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify). And, more substantially, it cleans up the multiplicity handling in the typechecking of NPlusKPat - - - - - 12f90352 by Krzysztof Gogolewski at 2020-07-18T07:26:45-04:00 Remove {-# CORE #-} pragma (part of #18048) This pragma has no effect since 2011. It was introduced for External Core, which no longer exists. Updates haddock submodule. - - - - - e504c913 by Simon Peyton Jones at 2020-07-18T07:26:45-04:00 Refactor the simplification of join binders This MR (for #18449) refactors the Simplifier's treatment of join-point binders. Specifically, it puts together, into GHC.Core.Opt.Simplify.Env.adjustJoinPointType two currently-separate ways in which we adjust the type of a join point. As the comment says: -- (adjustJoinPointType mult new_res_ty join_id) does two things: -- -- 1. Set the return type of the join_id to new_res_ty -- See Note [Return type for join points] -- -- 2. Adjust the multiplicity of arrows in join_id's type, as -- directed by 'mult'. See Note [Scaling join point arguments] I think this actually fixes a latent bug, by ensuring that the seIdSubst and seInScope have the right multiplicity on the type of join points. I did some tidying up while I was at it. No more setJoinResTy, or modifyJoinResTy: instead it's done locally in Simplify.Env.adjustJoinPointType - - - - - 49b265f0 by Chaitanya Koparkar at 2020-07-18T07:26:46-04:00 Fix minor typos in a Core.hs note - - - - - 8d59aed6 by Stefan Schulze Frielinghaus at 2020-07-18T07:26:47-04:00 GHCi: Fix isLittleEndian - - - - - c26e81d1 by Ben Gamari at 2020-07-18T07:26:47-04:00 testsuite: Mark ghci tests as fragile under unreg compiler In particular I have seen T16012 fail repeatedly under the unregisterised compiler. - - - - - 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - ce9f4e64 by Adam Gundry at 2020-08-21T22:59:23+01:00 Attach update function names to FieldLabels in DataCons - - - - - 56aa345f by Adam Gundry at 2020-08-21T22:59:23+01:00 Use rnIfaceNeverExported for updaters - - - - - 58bb5483 by Adam Gundry at 2020-08-21T22:59:23+01:00 Update GHC.Records to use hasField instead of getField - - - - - 7dfaf7e9 by Adam Gundry at 2020-08-21T22:59:23+01:00 Update HasField tests Adapt overloadedrecflds tests and T17355 to new definition of HasField Extend hasfieldrun01 test with partial record field test Update hasfieldfail02 test to check unlifted type case Accept changed T14189 output due to FieldLabel additional field - - - - - 11f80857 by Adam Gundry at 2020-08-21T22:59:23+01:00 Generate record updaters and use in HasField - - - - - ca5801f1 by Adam Gundry at 2020-08-21T23:04:36+01:00 Adjust expected output from dynamic-paper - - - - - 26 changed files: - + .git-ignore-revs - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/merge_request_templates/merge-request.md - .gitlab/test-metrics.sh - .gitmodules - CODEOWNERS - Makefile - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - − compiler/GHC/Builtin/Names.hs-boot - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - + compiler/GHC/Builtin/RebindableNames.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/ByteCode/Linker.hs - compiler/GHC/ByteCode/Types.hs - compiler/GHC/Cmm.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f83e9a6a13ea388e94e226cd23b7ef0da4d9be81...ca5801f1157f0732e8b5656bc4bc636b4c08e06f -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f83e9a6a13ea388e94e226cd23b7ef0da4d9be81...ca5801f1157f0732e8b5656bc4bc636b4c08e06f You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 21 23:18:59 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 21 Aug 2020 19:18:59 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: gitlab-ci: Test master branch as well Message-ID: <5f4056631dd68_80b3f8468db919888972b8@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 989c1c27 by Ben Gamari at 2020-08-21T11:27:53-04:00 gitlab-ci: Test master branch as well While these builds are strictly speaking redundant (since every commit is tested by @marge-bot before making it into `master`), they are nevertheless useful as they are displayed in the branch's commit list in GitLab's web interface. Fixes #18595. - - - - - c5694c4d by Aditya Gupta at 2020-08-21T19:18:50-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - f0488f18 by Wander Hillen at 2020-08-21T19:18:51-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 32c60ff4 by Craig Ferguson at 2020-08-21T19:18:52-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 30 changed files: - .gitlab-ci.yml - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/CmmToAsm/Reg/Graph/Base.hs - compiler/GHC/CmmToAsm/Reg/Graph/SpillClean.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/DataCon.hs-boot - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/Exitify.hs - compiler/GHC/Core/Opt/Monad.hs - compiler/GHC/Core/TyCon.hs - compiler/GHC/Core/TyCon.hs-boot - compiler/GHC/CoreToByteCode.hs - compiler/GHC/Iface/Ext/Ast.hs - compiler/GHC/Platform/Reg.hs - compiler/GHC/Platform/Reg/Class.hs - compiler/GHC/Stg/Pipeline.hs - compiler/GHC/Tc/TyCl/Utils.hs - compiler/GHC/Tc/Utils/Monad.hs - compiler/GHC/Tc/Validity.hs - compiler/GHC/Types/FieldLabel.hs - compiler/GHC/Types/Id.hs - + compiler/GHC/Types/Id.hs-boot - compiler/GHC/Types/Id/Make.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f1ef981c78ff0c11961057e4ca316ce23b1d8965...32c60ff475435d94f1a3fb3f089b738c897b724d -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f1ef981c78ff0c11961057e4ca316ce23b1d8965...32c60ff475435d94f1a3fb3f089b738c897b724d You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 22 07:29:05 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sat, 22 Aug 2020 03:29:05 -0400 Subject: [Git][ghc/ghc][master] mkUnique refactoring (#18362) Message-ID: <5f40c941f3f60_80b3f842731681c891101a@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: e67ae884 by Aditya Gupta at 2020-08-22T03:29:00-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - 30 changed files: - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/CmmToAsm/Reg/Graph/Base.hs - compiler/GHC/CmmToAsm/Reg/Graph/SpillClean.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/DataCon.hs-boot - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/Exitify.hs - compiler/GHC/Core/Opt/Monad.hs - compiler/GHC/Core/TyCon.hs - compiler/GHC/Core/TyCon.hs-boot - compiler/GHC/CoreToByteCode.hs - compiler/GHC/Iface/Ext/Ast.hs - compiler/GHC/Platform/Reg.hs - compiler/GHC/Platform/Reg/Class.hs - compiler/GHC/Stg/Pipeline.hs - compiler/GHC/Tc/TyCl/Utils.hs - compiler/GHC/Tc/Utils/Monad.hs - compiler/GHC/Tc/Validity.hs - compiler/GHC/Types/FieldLabel.hs - compiler/GHC/Types/Id.hs - + compiler/GHC/Types/Id.hs-boot - compiler/GHC/Types/Id/Make.hs - compiler/GHC/Types/Name.hs-boot The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e67ae884ebe42cb31fc4230301a5f555ae23cce8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e67ae884ebe42cb31fc4230301a5f555ae23cce8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 22 07:29:42 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sat, 22 Aug 2020 03:29:42 -0400 Subject: [Git][ghc/ghc][master] Add ubuntu 20.04 jobs for nightly and release Message-ID: <5f40c9664abd9_80b3f8495bc8b04891415a@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 03cfcfd4 by Wander Hillen at 2020-08-22T03:29:36-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 1 changed file: - .gitlab-ci.yml Changes: ===================================== .gitlab-ci.yml ===================================== @@ -2,7 +2,7 @@ variables: GIT_SSL_NO_VERIFY: "1" # Commit of ghc/ci-images repository from which to pull Docker images - DOCKER_REV: 6223fe0b5942f4fa35bdec92c74566cf195bfb42 + DOCKER_REV: b65e1145d7c0a62c3533904a88dac14f56fb371b # Sequential version number capturing the versions of all tools fetched by # .gitlab/ci.sh. @@ -672,6 +672,35 @@ release-x86_64-linux-deb10: <<: *release extends: .build-x86_64-linux-deb10 +################################# +# x86_64-linux-ubuntu 20.04 +################################# + +.build-x86_64-linux-ubuntu2004: + extends: .validate-linux + stage: full-build + image: "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-ubuntu2004:$DOCKER_REV" + variables: + TEST_ENV: "x86_64-linux-ubuntu2004" + BIN_DIST_PREP_TAR_COMP: "./ghc-x86_64-ubuntu2004-linux.tar.xz" + cache: + key: linux-x86_64-ubuntu2004 + +# Disabled to alleviate CI load +.validate-x86_64-linux-ubuntu2004: + extends: .build-x86_64-linux-ubuntu2004 + stage: full-build + +nightly-x86_64-linux-ubuntu2004: + <<: *nightly + extends: .build-x86_64-linux-ubuntu2004 + variables: + TEST_TYPE: slowtest + +release-x86_64-linux-ubuntu2004: + <<: *release + extends: .build-x86_64-linux-ubuntu2004 + ################################# # x86_64-linux-deb8 ################################# View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/03cfcfd450335d5ecb63fec1f55d9feafabb2b4c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/03cfcfd450335d5ecb63fec1f55d9feafabb2b4c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 22 07:30:18 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sat, 22 Aug 2020 03:30:18 -0400 Subject: [Git][ghc/ghc][master] Utils: clarify docs slightly Message-ID: <5f40c98a4d526_80b3f8468db919889155d7@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 3f501545 by Craig Ferguson at 2020-08-22T03:30:13-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 1 changed file: - compiler/GHC/Utils/Misc.hs Changes: ===================================== compiler/GHC/Utils/Misc.hs ===================================== @@ -236,7 +236,7 @@ applyWhen :: Bool -> (a -> a) -> a -> a applyWhen True f x = f x applyWhen _ _ x = x --- | A for loop: Compose a function with itself n times. (nth rather than twice) +-- | Apply a function @n@ times to a given value. nTimes :: Int -> (a -> a) -> (a -> a) nTimes 0 _ = id nTimes 1 f = f View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3f50154591ada9064351ccec4adfe6df53ca2439 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3f50154591ada9064351ccec4adfe6df53ca2439 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 22 11:26:56 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Sat, 22 Aug 2020 07:26:56 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] 8 commits: Decode CostCentreStacks, CostCentres and InfoTables (#18405) Message-ID: <5f410100892ba_80bac4156c89249d@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: 9aa7aef9 by Sven Tennie at 2020-08-22T12:10:02+02:00 Decode CostCentreStacks, CostCentres and InfoTables (#18405) Use cache and loop breakers for CostCentre, CostCentreStack and IndexTable decoding (#18405) Cleanup Query caches once, not twice Fix Haddock for EndTSOQueue Run prof_info test only in prof_ways (#18405) That's the required way for collecting PROFILING data (e.g. CostCentres). Add missing module to ghc-heap.cabal Rearrange #ifdef with GHC version This prevents some "unused" warnings. Fix cpp redefinition warnings With --Werror this made the build fail. Add dummy import for PeekProfInfo_ProfilingEnabled for non-profiled builds This circumvents #15197. Otherwise PeekProfInfo_ProfilingEnabled wouldn't be available for make-based builds. Add assertions to prof_info test (#18405) Cache only CostCentres during ProfInfo decoding Looks like caches for CostCentreStacks and IndexTables are not needed. Fix warning - - - - - 96f56aab by Sven Tennie at 2020-08-22T12:13:22+02:00 Fix types in tests Use `Ptr ()` instead of `Word` to communicate that addresses/pointers are meant. Cleanup - - - - - 19a4b3b4 by Sven Tennie at 2020-08-22T12:13:25+02:00 Introduce LiftedClosure This is a representation for closures that do not have a represantation in the Haskell language. I.e. things like TSOs. Fix prof_info test Line number of self defined cost centre changed. - - - - - a95d99cf by Sven Tennie at 2020-08-22T12:13:25+02:00 Expect stack_marking starting from GHC 8.10 This field was introduced with GHC 8.10. - - - - - c6f86b1d by Sven Tennie at 2020-08-22T12:13:25+02:00 Add WhatNext, WhyBlocked and TsoFlags Additionally extract TestUtils with common test functions. Parse TSO flags - - - - - eef76d26 by Sven Tennie at 2020-08-22T12:13:25+02:00 END_TSO_QUEUE is not a closure type on it's own Indeed it's a CONSTR_NOCAF. Delete unused function - - - - - 2731382e by Sven Tennie at 2020-08-22T12:13:25+02:00 Rename boundTaskExiting and getTask (#18405) Both are directly related to myTask, which the new names now reflect. - - - - - d92c67f0 by Sven Tennie at 2020-08-22T12:18:29+02:00 Mark unsafe accesses (#18405) StgTSO and StgStack are very dynamic by nature. Accesses to outdated pointers lead to segmentation faults or absolutely wrong results. So, make sure (by naming) that the users nows about these facts. - - - - - 24 changed files: - compiler/GHC/ByteCode/Types.hs - compiler/GHC/Runtime/Interpreter.hs - includes/rts/Task.h - libraries/ghc-heap/GHC/Exts/Heap.hs - libraries/ghc-heap/GHC/Exts/Heap/Closures.hs - libraries/ghc-heap/GHC/Exts/Heap/FFIClosures.hsc - + libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingDisabled.hsc - + libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc - + libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/Types.hs - + libraries/ghc-heap/GHC/Exts/Heap/Ptr/Utils.hs - libraries/ghc-heap/ghc-heap.cabal.in - + libraries/ghc-heap/tests/TestUtils.hs - libraries/ghc-heap/tests/all.T - libraries/ghc-heap/tests/list_threads_and_misc_roots.hs - + libraries/ghc-heap/tests/parse_tso_flags.hs - + libraries/ghc-heap/tests/prof_info.hs - libraries/ghc-heap/tests/tso_and_stack_closures.hs - libraries/ghci/GHCi/Message.hs - libraries/ghci/GHCi/Run.hs - rts/RtsAPI.c - rts/Schedule.c - rts/Task.c - rts/Task.h - rts/sm/NonMoving.c Changes: ===================================== compiler/GHC/ByteCode/Types.hs ===================================== @@ -36,7 +36,7 @@ import Data.ByteString (ByteString) import Data.IntMap (IntMap) import qualified Data.IntMap as IntMap import Data.Maybe (catMaybes) -import GHC.Exts.Heap +import qualified GHC.Exts.Heap as Heap import GHC.Stack.CCS -- ----------------------------------------------------------------------------- @@ -71,7 +71,7 @@ type ItblEnv = NameEnv (Name, ItblPtr) -- We need the Name in the range so we know which -- elements to filter out when unloading a module -newtype ItblPtr = ItblPtr (RemotePtr StgInfoTable) +newtype ItblPtr = ItblPtr (RemotePtr Heap.StgInfoTable) deriving (Show, NFData) data UnlinkedBCO ===================================== compiler/GHC/Runtime/Interpreter.hs ===================================== @@ -94,7 +94,7 @@ import qualified Data.ByteString.Lazy as LB import Data.Array ((!)) import Data.IORef import Foreign hiding (void) -import GHC.Exts.Heap +import qualified GHC.Exts.Heap as Heap import GHC.Stack.CCS (CostCentre,CostCentreStack) import System.Exit import GHC.IO.Handle.Types (Handle) @@ -386,7 +386,7 @@ getBreakpointVar hsc_env ref ix = mb <- iservCmd hsc_env (GetBreakpointVar apStack ix) mapM (mkFinalizedHValue hsc_env) mb -getClosure :: HscEnv -> ForeignHValue -> IO (GenClosure ForeignHValue) +getClosure :: HscEnv -> ForeignHValue -> IO (Heap.GenClosure ForeignHValue) getClosure hsc_env ref = withForeignRef ref $ \hval -> do mb <- iservCmd hsc_env (GetClosure hval) ===================================== includes/rts/Task.h ===================================== @@ -15,9 +15,9 @@ typedef struct Task_ Task; -// Create a new Task for a bound thread. This Task must be released -// by calling boundTaskExiting. The Task is cached in -// thread-local storage and will remain even after boundTaskExiting() +// Create a new Task for a bound thread. This Task must be released +// by calling exitMyTask(). The Task is cached in +// thread-local storage and will remain even after exitMyTask() // has been called; to free the memory, see freeMyTask(). // Task* newBoundTask (void); @@ -25,11 +25,10 @@ Task* newBoundTask (void); // Return the current OS thread's Task, which is created if it doesn't already // exist. After you have finished using RTS APIs, you should call freeMyTask() // to release this thread's Task. -Task* getTask (void); +Task* getMyTask (void); -// The current task is a bound task that is exiting. -// -void boundTaskExiting (Task *task); +// Exit myTask - This is the counterpart of newBoundTask(). +void exitMyTask (void); // Free a Task if one was previously allocated by newBoundTask(). // This is not necessary unless the thread that called newBoundTask() @@ -37,4 +36,3 @@ void boundTaskExiting (Task *task); // functions. // void freeMyTask(void); - ===================================== libraries/ghc-heap/GHC/Exts/Heap.hs ===================================== @@ -9,6 +9,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE ExplicitForAll #-} {-# LANGUAGE RankNTypes #-} +{-# LANGUAGE UnliftedFFITypes #-} {-| Module : GHC.Exts.Heap @@ -23,9 +24,13 @@ values, i.e. to investigate sharing and lazy evaluation. module GHC.Exts.Heap ( -- * Closure types Closure + , LiftedClosure , GenClosure(..) , ClosureType(..) , PrimType(..) + , WhatNext(..) + , WhyBlocked(..) + , TsoFlags(..) , HasHeapRep(getClosureDataX) , getClosureData @@ -38,6 +43,12 @@ module GHC.Exts.Heap ( , peekItbl , pokeItbl + -- * Cost Centre (profiling) types + , StgTSOProfInfo(..) + , IndexTable(..) + , CostCentre(..) + , CostCentreStack(..) + -- * Closure inspection , getBoxedClosureData , allClosures @@ -52,9 +63,19 @@ import Prelude import GHC.Exts.Heap.Closures import GHC.Exts.Heap.ClosureTypes import GHC.Exts.Heap.Constants +import GHC.Exts.Heap.ProfInfo.Types #if defined(PROFILING) +import GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingEnabled import GHC.Exts.Heap.InfoTableProf #else +-- This import makes PeekProfInfo_ProfilingEnabled available in make-based +-- builds. See #15197 for details (even though the related patch didn't +-- seem to fix the issue). +-- GHC.Exts.Heap.Closures uses the same trick to include +-- GHC.Exts.Heap.InfoTableProf into make-based builds. +import GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingEnabled () + +import GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingDisabled import GHC.Exts.Heap.InfoTable #endif import GHC.Exts.Heap.Utils @@ -71,12 +92,19 @@ import Foreign #include "ghcconfig.h" +-- | Some closures (e.g.TSOs) don't have corresponding types to represent them in Haskell. +-- So when we have a pointer to such closure that we want to inspect, we `unsafeCoerce` it +-- into the following `LiftedClosure` lifted type (could be any lifted type) so that the +-- appropriate `instance HasHeapRep (a :: TYPE 'LiftedRep)` is used to decode the closure. +data LiftedClosure + class HasHeapRep (a :: TYPE rep) where -- | Decode a closure to it's heap representation ('GenClosure'). -- Inside a GHC context 'b' is usually a 'GHC.Exts.Heap.Closures.Box' -- containing a thunk or an evaluated heap object. Outside it can be a -- 'Word' for "raw" usage of pointers. + getClosureDataX :: (forall c . c -> IO (Ptr StgInfoTable, [Word], [b])) -- ^ Helper function to get info table, memory and pointers of the @@ -166,6 +194,7 @@ getClosureData = getClosureDataX getClosureRaw -- @collect_pointers()@ in @rts/Heap.c at . -- -- For most use cases 'getClosureData' is an easier to use alternative. + getClosureX :: forall a b. (forall c . c -> IO (Ptr StgInfoTable, [Word], [b])) -- ^ Helper function to get info table, memory and pointers of the @@ -325,16 +354,15 @@ getClosureX get_closure_raw x = do allocaArray (length wds) (\ptr -> do pokeArray ptr wds - fields <- FFIClosures.peekTSOFields ptr - + fields <- FFIClosures.peekTSOFields peekStgTSOProfInfo ptr pure $ TSOClosure { info = itbl - , _link = (pts !! 0) - , global_link = (pts !! 1) + , unsafe_link = (pts !! 0) + , unsafe_global_link = (pts !! 1) , tsoStack = (pts !! 2) - , trec = (pts !! 3) - , blocked_exceptions = (pts !! 4) - , bq = (pts !! 5) + , unsafe_trec = (pts !! 3) + , unsafe_blocked_exceptions = (pts !! 4) + , unsafe_bq = (pts !! 5) , what_next = FFIClosures.tso_what_next fields , why_blocked = FFIClosures.tso_why_blocked fields , flags = FFIClosures.tso_flags fields @@ -343,6 +371,7 @@ getClosureX get_closure_raw x = do , tso_dirty = FFIClosures.tso_dirty fields , alloc_limit = FFIClosures.tso_alloc_limit fields , tot_stack_size = FFIClosures.tso_tot_stack_size fields + , prof = FFIClosures.tso_prof fields } ) STACK -> do @@ -359,8 +388,8 @@ getClosureX get_closure_raw x = do { info = itbl , stack_size = FFIClosures.stack_size fields , stack_dirty = FFIClosures.stack_dirty fields - , stackPointer = (pts !! 0) - , stack = FFIClosures.stack fields + , unsafeStackPointer = (pts !! 0) + , unsafeStack = FFIClosures.stack fields #if __GLASGOW_HASKELL__ >= 811 , stack_marking = FFIClosures.stack_marking fields #endif ===================================== libraries/ghc-heap/GHC/Exts/Heap/Closures.hs ===================================== @@ -12,6 +12,9 @@ module GHC.Exts.Heap.Closures ( Closure , GenClosure(..) , PrimType(..) + , WhatNext(..) + , WhyBlocked(..) + , TsoFlags(..) , allClosures #if __GLASGOW_HASKELL__ >= 809 -- The closureSize# primop is unsupported on earlier GHC releases but we @@ -40,6 +43,8 @@ import GHC.Exts.Heap.InfoTable import GHC.Exts.Heap.InfoTableProf () #endif +import GHC.Exts.Heap.ProfInfo.Types + import Data.Bits import Data.Int import Data.Word @@ -271,35 +276,42 @@ data GenClosure b -- | Representation of StgTSO: A Thread State Object. -- The values for 'what_next', 'why_blocked' and 'flags' are defined in -- @Constants.h at . + -- Fields marked as @unsafe@ are backed by dynamic pointers and should only + -- be accessed when the garbage collector is stopped. Otherwise segmentation + -- faults may happen when an invalidated pointer is accessed. | TSOClosure { info :: !StgInfoTable -- pointers - , _link :: !b - , global_link :: !b + , unsafe_link :: !b + , unsafe_global_link :: !b , tsoStack :: !b -- ^ stackobj from StgTSO - , trec :: !b - , blocked_exceptions :: !b - , bq :: !b + , unsafe_trec :: !b + , unsafe_blocked_exceptions :: !b + , unsafe_bq :: !b -- values - , what_next :: Word16 - , why_blocked :: Word16 - , flags :: Word32 + , what_next :: WhatNext + , why_blocked :: WhyBlocked + , flags :: [TsoFlags] , threadId :: Word64 , saved_errno :: Word32 , tso_dirty:: Word32 -- ^ non-zero => dirty , alloc_limit :: Int64 , tot_stack_size :: Word32 + , prof :: Maybe StgTSOProfInfo } - -- Representation of StgStack: The 'tsoStack' of a 'TSOClosure'. + -- | Representation of StgStack: The 'tsoStack' of a 'TSOClosure'. + -- Fields marked as @unsafe@ are backed by dynamic pointers and should only + -- be accessed when the garbage collector is stopped. Otherwise segmentation + -- faults may happen when an invalidated pointer is accessed. | StackClosure { info :: !StgInfoTable , stack_size :: !Word32 -- ^ stack size in *words* , stack_dirty :: !Word8 -- ^ non-zero => dirty -#if __GLASGOW_HASKELL__ >= 811 +#if __GLASGOW_HASKELL__ >= 810 , stack_marking :: Word8 #endif - , stackPointer :: !b -- ^ current stack pointer - , stack :: [Word] + , unsafeStackPointer :: !b -- ^ current stack pointer + , unsafeStack :: [Word] } ------------------------------------------------------------ @@ -366,6 +378,43 @@ data PrimType | PDouble deriving (Eq, Show, Generic) +data WhatNext + = ThreadRunGHC + | ThreadInterpret + | ThreadKilled + | ThreadComplete + | WhatNextUnknownValue -- ^ Please report this as a bug + deriving (Eq, Show, Generic) + +data WhyBlocked + = NotBlocked + | BlockedOnMVar + | BlockedOnMVarRead + | BlockedOnBlackHole + | BlockedOnRead + | BlockedOnWrite + | BlockedOnDelay + | BlockedOnSTM + | BlockedOnDoProc + | BlockedOnCCall + | BlockedOnCCall_Interruptible + | BlockedOnMsgThrowTo + | ThreadMigrating + | BlockedOnIOCompletion + | WhyBlockedUnknownValue -- ^ Please report this as a bug + deriving (Eq, Show, Generic) + +data TsoFlags + = TsoLocked + | TsoBlockx + | TsoInterruptible + | TsoStoppedOnBreakpoint + | TsoMarked + | TsoSqueezed + | TsoAllocLimit + | TsoFlagsUnknownValue -- ^ Please report this as a bug + deriving (Eq, Show, Generic) + -- | For generic code, this function returns all referenced closures. allClosures :: GenClosure b -> [b] allClosures (ConstrClosure {..}) = ptrArgs ===================================== libraries/ghc-heap/GHC/Exts/Heap/FFIClosures.hsc ===================================== @@ -5,26 +5,28 @@ module GHC.Exts.Heap.FFIClosures where import Prelude import Foreign - --- TODO use sum type for what_next, why_blocked, flags? +import GHC.Exts.Heap.ProfInfo.Types +import GHC.Exts.Heap.Closures(WhatNext(..), WhyBlocked(..), TsoFlags(..)) data TSOFields = TSOFields { - tso_what_next :: Word16, - tso_why_blocked :: Word16, - tso_flags :: Word32, + tso_what_next :: WhatNext, + tso_why_blocked :: WhyBlocked, + tso_flags :: [TsoFlags], -- Unfortunately block_info is a union without clear discriminator. -- block_info :: TDB, tso_threadId :: Word64, tso_saved_errno :: Word32, tso_dirty:: Word32, tso_alloc_limit :: Int64, - tso_tot_stack_size :: Word32 --- TODO StgTSOProfInfo prof is optionally included, but looks very interesting. + tso_tot_stack_size :: Word32, + tso_prof :: Maybe StgTSOProfInfo } -- | Get non-pointer fields from @StgTSO_@ (@TSO.h@) -peekTSOFields :: Ptr a -> IO TSOFields -peekTSOFields ptr = do +peekTSOFields :: (Ptr tsoPtr -> IO (Maybe StgTSOProfInfo)) + -> Ptr tsoPtr + -> IO TSOFields +peekTSOFields peekProfInfo ptr = do what_next' <- (#peek struct StgTSO_, what_next) ptr why_blocked' <- (#peek struct StgTSO_, why_blocked) ptr flags' <- (#peek struct StgTSO_, flags) ptr @@ -33,22 +35,69 @@ peekTSOFields ptr = do dirty' <- (#peek struct StgTSO_, dirty) ptr alloc_limit' <- (#peek struct StgTSO_, alloc_limit) ptr tot_stack_size' <- (#peek struct StgTSO_, tot_stack_size) ptr + tso_prof' <- peekProfInfo ptr return TSOFields { - tso_what_next = what_next', - tso_why_blocked = why_blocked', - tso_flags = flags', + tso_what_next = parseWhatNext what_next', + tso_why_blocked = parseWhyBlocked why_blocked', + tso_flags = parseTsoFlags flags', tso_threadId = threadId', tso_saved_errno = saved_errno', - tso_dirty= dirty', + tso_dirty = dirty', tso_alloc_limit = alloc_limit', - tso_tot_stack_size = tot_stack_size' + tso_tot_stack_size = tot_stack_size', + tso_prof = tso_prof' } +parseWhatNext :: Word16 -> WhatNext +parseWhatNext w = case w of + (#const ThreadRunGHC) -> ThreadRunGHC + (#const ThreadInterpret) -> ThreadInterpret + (#const ThreadKilled) -> ThreadKilled + (#const ThreadComplete) -> ThreadComplete + _ -> WhatNextUnknownValue + +parseWhyBlocked :: Word16 -> WhyBlocked +parseWhyBlocked w = case w of + (#const NotBlocked) -> NotBlocked + (#const BlockedOnMVar) -> BlockedOnMVar + (#const BlockedOnMVarRead) -> BlockedOnMVarRead + (#const BlockedOnBlackHole) -> BlockedOnBlackHole + (#const BlockedOnRead) -> BlockedOnRead + (#const BlockedOnWrite) -> BlockedOnWrite + (#const BlockedOnDelay) -> BlockedOnDelay + (#const BlockedOnSTM) -> BlockedOnSTM + (#const BlockedOnDoProc) -> BlockedOnDoProc + (#const BlockedOnCCall) -> BlockedOnCCall + (#const BlockedOnCCall_Interruptible) -> BlockedOnCCall_Interruptible + (#const BlockedOnMsgThrowTo) -> BlockedOnMsgThrowTo + (#const ThreadMigrating) -> ThreadMigrating +#if __GLASGOW_HASKELL__ >= 810 + (#const BlockedOnIOCompletion) -> BlockedOnIOCompletion +#endif + _ -> WhyBlockedUnknownValue + +parseTsoFlags :: Word32 -> [TsoFlags] +parseTsoFlags w | isSet (#const TSO_LOCKED) w = TsoLocked : parseTsoFlags (unset (#const TSO_LOCKED) w) + | isSet (#const TSO_BLOCKEX) w = TsoBlockx : parseTsoFlags (unset (#const TSO_BLOCKEX) w) + | isSet (#const TSO_INTERRUPTIBLE) w = TsoInterruptible : parseTsoFlags (unset (#const TSO_INTERRUPTIBLE) w) + | isSet (#const TSO_STOPPED_ON_BREAKPOINT) w = TsoStoppedOnBreakpoint : parseTsoFlags (unset (#const TSO_STOPPED_ON_BREAKPOINT) w) + | isSet (#const TSO_MARKED) w = TsoMarked : parseTsoFlags (unset (#const TSO_MARKED) w) + | isSet (#const TSO_SQUEEZED) w = TsoSqueezed : parseTsoFlags (unset (#const TSO_SQUEEZED) w) + | isSet (#const TSO_ALLOC_LIMIT) w = TsoAllocLimit : parseTsoFlags (unset (#const TSO_ALLOC_LIMIT) w) +parseTsoFlags 0 = [] +parseTsoFlags _ = [TsoFlagsUnknownValue] + +isSet :: Word32 -> Word32 -> Bool +isSet bitMask w = w .&. bitMask /= 0 + +unset :: Word32 -> Word32 -> Word32 +unset bitMask w = w `xor` bitMask + data StackFields = StackFields { stack_size :: Word32, stack_dirty :: Word8, -#if __GLASGOW_HASKELL__ >= 811 +#if __GLASGOW_HASKELL__ >= 810 stack_marking :: Word8, #endif stack :: [Word] @@ -59,7 +108,7 @@ peekStackFields :: Ptr a -> IO StackFields peekStackFields ptr = do stack_size' <- (#peek struct StgStack_, stack_size) ptr ::IO Word32 dirty' <- (#peek struct StgStack_, dirty) ptr -#if __GLASGOW_HASKELL__ >= 811 +#if __GLASGOW_HASKELL__ >= 810 marking' <- (#peek struct StgStack_, marking) ptr #endif @@ -69,7 +118,7 @@ peekStackFields ptr = do return StackFields { stack_size = stack_size', stack_dirty = dirty', -#if __GLASGOW_HASKELL__ >= 811 +#if __GLASGOW_HASKELL__ >= 810 stack_marking = marking', #endif stack = stack' ===================================== libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingDisabled.hsc ===================================== @@ -0,0 +1,13 @@ +{-# LANGUAGE CPP, DeriveGeneric #-} +module GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingDisabled( + peekStgTSOProfInfo +) where + +import Prelude +import Foreign +import GHC.Exts.Heap.ProfInfo.Types + +-- | This implementation is used when PROFILING is undefined. +-- It always returns 'Nothing', because there is no profiling info available. +peekStgTSOProfInfo :: Ptr tsoPtr -> IO (Maybe StgTSOProfInfo) +peekStgTSOProfInfo _ = return Nothing ===================================== libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc ===================================== @@ -0,0 +1,168 @@ +{-# LANGUAGE CPP, DeriveGeneric #-} +module GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingEnabled( + peekStgTSOProfInfo +) where + +#if __GLASGOW_HASKELL__ >= 811 + +-- Manually defining PROFILING gives the #peek and #poke macros an accurate +-- representation of the C structures when hsc2hs runs. This is valid because +-- a non-profiling build would use +-- GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingDisabled. +#define PROFILING + +#include "Rts.h" +#undef BLOCK_SIZE +#undef MBLOCK_SIZE +#undef BLOCKS_PER_MBLOCK +#include "DerivedConstants.h" + +import Prelude +import Foreign + +import Foreign.C.String +import GHC.Exts.Heap.ProfInfo.Types + +import Data.IntMap.Strict (IntMap) +import qualified Data.IntMap.Strict as IntMap + +import Data.IntSet (IntSet) +import qualified Data.IntSet as IntSet + +import Control.Monad.Trans.State +import Control.Monad.IO.Class + +import GHC.Exts.Heap.Ptr.Utils + +-- Use Int based containers for pointers (addresses) for better performance. +-- These will be queried a lot! +type AddressSet = IntSet +type AddressMap = IntMap + +data Cache = Cache { + ccCache :: AddressMap CostCentre +} +type DecoderMonad a = StateT Cache IO a + +peekStgTSOProfInfo :: Ptr a -> IO (Maybe StgTSOProfInfo) +peekStgTSOProfInfo tsoPtr = do + cccs_ptr <- peekByteOff tsoPtr cccsOffset + cccs' <- evalStateT (peekCostCentreStack IntSet.empty cccs_ptr) $ Cache IntMap.empty + + return $ Just StgTSOProfInfo { + cccs = cccs' + } + +cccsOffset :: Int +cccsOffset = (#const OFFSET_StgTSO_cccs) + (#size StgHeader) + +peekCostCentreStack :: AddressSet -> Ptr costCentreStack -> DecoderMonad (Maybe CostCentreStack) +peekCostCentreStack _ ptr | ptr == nullPtr = return Nothing +peekCostCentreStack loopBreakers ptr | IntSet.member (ptrToInt ptr) loopBreakers = return Nothing +peekCostCentreStack loopBreakers ptr = do + ccs_ccsID' <- liftIO $ (#peek struct CostCentreStack_, ccsID) ptr + ccs_cc_ptr <- liftIO $ (#peek struct CostCentreStack_, cc) ptr + ccs_cc' <- peekCostCentre ccs_cc_ptr + ccs_prevStack_ptr <- liftIO $ (#peek struct CostCentreStack_, prevStack) ptr + let loopBreakers' = (IntSet.insert ptrAsInt loopBreakers) + ccs_prevStack' <- peekCostCentreStack loopBreakers' ccs_prevStack_ptr + ccs_indexTable_ptr <- liftIO $ (#peek struct CostCentreStack_, indexTable) ptr + ccs_indexTable' <- peekIndexTable loopBreakers' ccs_indexTable_ptr + ccs_root_ptr <- liftIO $ (#peek struct CostCentreStack_, root) ptr + ccs_root' <- peekCostCentreStack loopBreakers' ccs_root_ptr + ccs_depth' <- liftIO $ (#peek struct CostCentreStack_, depth) ptr + ccs_scc_count' <- liftIO $ (#peek struct CostCentreStack_, scc_count) ptr + ccs_selected' <- liftIO $ (#peek struct CostCentreStack_, selected) ptr + ccs_time_ticks' <- liftIO $ (#peek struct CostCentreStack_, time_ticks) ptr + ccs_mem_alloc' <- liftIO $ (#peek struct CostCentreStack_, mem_alloc) ptr + ccs_inherited_alloc' <- liftIO $ (#peek struct CostCentreStack_, inherited_alloc) ptr + ccs_inherited_ticks' <- liftIO $ (#peek struct CostCentreStack_, inherited_ticks) ptr + + return $ Just CostCentreStack { + ccs_ccsID = ccs_ccsID', + ccs_cc = ccs_cc', + ccs_prevStack = ccs_prevStack', + ccs_indexTable = ccs_indexTable', + ccs_root = ccs_root', + ccs_depth = ccs_depth', + ccs_scc_count = ccs_scc_count', + ccs_selected = ccs_selected', + ccs_time_ticks = ccs_time_ticks', + ccs_mem_alloc = ccs_mem_alloc', + ccs_inherited_alloc = ccs_inherited_alloc', + ccs_inherited_ticks = ccs_inherited_ticks' + } + where + ptrAsInt = ptrToInt ptr + +peekCostCentre :: Ptr costCentre -> DecoderMonad CostCentre +peekCostCentre ptr = do + cache <- get + case IntMap.lookup ptrAsInt (ccCache cache) of + (Just a) -> return a + Nothing -> do + cc_ccID' <- liftIO $ (#peek struct CostCentre_, ccID) ptr + cc_label_ptr <- liftIO $ (#peek struct CostCentre_, label) ptr + cc_label' <- liftIO $ peekCString cc_label_ptr + cc_module_ptr <- liftIO $ (#peek struct CostCentre_, module) ptr + cc_module' <- liftIO $ peekCString cc_module_ptr + cc_srcloc_ptr <- liftIO $ (#peek struct CostCentre_, srcloc) ptr + cc_srcloc' <- liftIO $ do + if cc_srcloc_ptr == nullPtr then + return Nothing + else + fmap Just (peekCString cc_srcloc_ptr) + cc_mem_alloc' <- liftIO $ (#peek struct CostCentre_, mem_alloc) ptr + cc_time_ticks' <- liftIO $ (#peek struct CostCentre_, time_ticks) ptr + cc_is_caf' <- liftIO $ (#peek struct CostCentre_, is_caf) ptr + cc_link_ptr <- liftIO $ (#peek struct CostCentre_, link) ptr + cc_link' <- if cc_link_ptr == nullPtr then + return Nothing + else + fmap Just (peekCostCentre cc_link_ptr) + + let result = CostCentre { + cc_ccID = cc_ccID', + cc_label = cc_label', + cc_module = cc_module', + cc_srcloc = cc_srcloc', + cc_mem_alloc = cc_mem_alloc', + cc_time_ticks = cc_time_ticks', + cc_is_caf = cc_is_caf', + cc_link = cc_link' + } + + let updatedCCCache = IntMap.insert ptrAsInt result (ccCache cache) + put $ cache { ccCache = updatedCCCache } + + return result + where + ptrAsInt = ptrToInt ptr + +peekIndexTable :: AddressSet -> Ptr indexTable -> DecoderMonad (Maybe IndexTable) +peekIndexTable _ ptr | ptr == nullPtr = return Nothing +peekIndexTable loopBreakers ptr = do + it_cc_ptr <- liftIO $ (#peek struct IndexTable_, cc) ptr + it_cc' <- peekCostCentre it_cc_ptr + it_ccs_ptr <- liftIO $ (#peek struct IndexTable_, ccs) ptr + it_ccs' <- peekCostCentreStack loopBreakers it_ccs_ptr + it_next_ptr <- liftIO $ (#peek struct IndexTable_, next) ptr + it_next' <- peekIndexTable loopBreakers it_next_ptr + it_back_edge' <- liftIO $ (#peek struct IndexTable_, back_edge) ptr + + return $ Just IndexTable { + it_cc = it_cc', + it_ccs = it_ccs', + it_next = it_next', + it_back_edge = it_back_edge' + } + +#else +import Prelude +import Foreign + +import GHC.Exts.Heap.ProfInfo.Types + +peekStgTSOProfInfo :: Ptr a -> IO (Maybe StgTSOProfInfo) +peekStgTSOProfInfo _ = return Nothing +#endif ===================================== libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/Types.hs ===================================== @@ -0,0 +1,44 @@ +{-# LANGUAGE DeriveGeneric #-} + +module GHC.Exts.Heap.ProfInfo.Types where + +import Prelude +import Data.Word +import GHC.Generics + +data StgTSOProfInfo = StgTSOProfInfo { + cccs :: Maybe CostCentreStack +} deriving (Show, Generic) + +data CostCentreStack = CostCentreStack { + ccs_ccsID :: Int, + ccs_cc :: CostCentre, + ccs_prevStack :: Maybe CostCentreStack, + ccs_indexTable :: Maybe IndexTable, + ccs_root :: Maybe CostCentreStack, + ccs_depth :: Word, + ccs_scc_count :: Word64, + ccs_selected :: Word, + ccs_time_ticks :: Word, + ccs_mem_alloc :: Word64, + ccs_inherited_alloc :: Word64, + ccs_inherited_ticks :: Word +} deriving (Show, Generic, Eq) + +data CostCentre = CostCentre { + cc_ccID :: Int, + cc_label :: String, + cc_module :: String, + cc_srcloc :: Maybe String, + cc_mem_alloc :: Word64, + cc_time_ticks :: Word, + cc_is_caf :: Bool, + cc_link :: Maybe CostCentre +} deriving (Show, Generic, Eq) + +data IndexTable = IndexTable { + it_cc :: CostCentre, + it_ccs :: Maybe CostCentreStack, + it_next :: Maybe IndexTable, + it_back_edge :: Bool +} deriving (Show, Generic, Eq) ===================================== libraries/ghc-heap/GHC/Exts/Heap/Ptr/Utils.hs ===================================== @@ -0,0 +1,11 @@ +{-# LANGUAGE CPP, DeriveGeneric, MagicHash #-} + +module GHC.Exts.Heap.Ptr.Utils where + +import Prelude +import GHC.Ptr +import GHC.Exts + +-- | casts a @Ptr@ to an @Int@ +ptrToInt :: Ptr a -> Int +ptrToInt (Ptr a#) = I# (addr2Int# a#) ===================================== libraries/ghc-heap/ghc-heap.cabal.in ===================================== @@ -25,6 +25,8 @@ library build-depends: base >= 4.9.0 && < 5.0 , ghc-prim > 0.2 && < 0.8 , rts == 1.0.* + , containers >= 0.6.2.1 && < 0.7 + , transformers == 0.5.* ghc-options: -Wall cmm-sources: cbits/HeapPrim.cmm @@ -40,3 +42,7 @@ library GHC.Exts.Heap.InfoTableProf GHC.Exts.Heap.Utils GHC.Exts.Heap.FFIClosures + GHC.Exts.Heap.ProfInfo.Types + GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingEnabled + GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingDisabled + GHC.Exts.Heap.Ptr.Utils ===================================== libraries/ghc-heap/tests/TestUtils.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE MagicHash #-} +module TestUtils where + +import GHC.Exts.Heap (getClosureData, LiftedClosure, Box, GenClosure) +import Foreign (Ptr) +import GHC.Exts (Ptr, Addr#, unsafeCoerce#) +import GHC.Ptr (Ptr(Ptr)) + +assertEqual :: (Show a, Eq a) => a -> a -> IO () +assertEqual a b + | a /= b = error (show a ++ " /= " ++ show b) + | otherwise = return () + +createClosure :: Ptr () -> IO (GenClosure Box) +createClosure tsoPtr = do + let addr = unpackAddr# tsoPtr + getClosureData ((unsafeCoerce# addr) :: LiftedClosure) + +unpackAddr# :: Ptr () -> Addr# +unpackAddr# (Ptr addr) = addr ===================================== libraries/ghc-heap/tests/all.T ===================================== @@ -37,15 +37,32 @@ test('closure_size_noopt', compile_and_run, ['']) test('tso_and_stack_closures', - [extra_files(['create_tso.c','create_tso.h']), + [extra_files(['create_tso.c','create_tso.h', 'TestUtils.hs']), ignore_stdout, ignore_stderr ], multi_compile_and_run, ['tso_and_stack_closures', [('create_tso.c','')], '']) test('list_threads_and_misc_roots', - [extra_files(['list_threads_and_misc_roots_c.c','list_threads_and_misc_roots_c.h']), + [extra_files(['list_threads_and_misc_roots_c.c','list_threads_and_misc_roots_c.h','TestUtils.hs']), ignore_stdout, ignore_stderr ], multi_compile_and_run, ['list_threads_and_misc_roots', [('list_threads_and_misc_roots_c.c','')], '-threaded']) + +test('prof_info', + [extra_files(['create_tso.c','create_tso.h','TestUtils.hs']), + ignore_stdout, + ignore_stderr, + when(have_profiling(), extra_ways(['prof'])), + only_ways(prof_ways) + ], + multi_compile_and_run, ['prof_info', [('create_tso.c','')], '-prof']) + +test('parse_tso_flags', + [extra_files(['TestUtils.hs']), + only_ways(['normal']), + ignore_stdout, + ignore_stderr + ], + compile_and_run, ['']) ===================================== libraries/ghc-heap/tests/list_threads_and_misc_roots.hs ===================================== @@ -7,11 +7,7 @@ import Control.Concurrent import GHC.Exts.Heap import GHC.Exts - --- Invent a type to bypass the type constraints of getClosureData. --- Infact this will be a Word#, that is directly given to unpackClosure# --- (which is a primop that expects a pointer to a closure). -data FoolClosure +import TestUtils foreign import ccall safe "list_threads_and_misc_roots_c.h listThreadsAndMiscRoots" listThreadsAndMiscRoots_c :: IO () @@ -20,13 +16,13 @@ foreign import ccall safe "list_threads_and_misc_roots_c.h getTSOCount" getTSOCount_c :: IO Int foreign import ccall safe "list_threads_and_misc_roots_c.h getTSOs" - getTSOs_c :: IO (Ptr Word) + getTSOs_c :: IO (Ptr (Ptr ())) foreign import ccall safe "list_threads_and_misc_roots_c.h getMiscRootsCount" getMiscRootsCount_c :: IO Int foreign import ccall safe "list_threads_and_misc_roots_c.h getMiscRoots" - getMiscRoots_c :: IO (Ptr Word) + getMiscRoots_c :: IO (Ptr (Ptr ())) main :: IO () main = do @@ -50,19 +46,6 @@ main = do return () -createClosure :: Word -> IO (GenClosure Box) -createClosure tsoPtr = do - let wPtr = unpackWord# tsoPtr - getClosureData ((unsafeCoerce# wPtr) :: FoolClosure) - -unpackWord# :: Word -> Word# -unpackWord# (W# w#) = w# - -assertEqual :: (Show a, Eq a) => a -> a -> IO () -assertEqual a b - | a /= b = error (show a ++ " /= " ++ show b) - | otherwise = return () - assertIsClosureType :: ClosureType -> IO () assertIsClosureType t | t `elem` enumerate = return () ===================================== libraries/ghc-heap/tests/parse_tso_flags.hs ===================================== @@ -0,0 +1,17 @@ +import GHC.Exts.Heap.Closures +import GHC.Exts.Heap.FFIClosures +import TestUtils + +main :: IO() +main = do + assertEqual (parseTsoFlags 0) [] + assertEqual (parseTsoFlags 1) [TsoFlagsUnknownValue] + assertEqual (parseTsoFlags 2) [TsoLocked] + assertEqual (parseTsoFlags 4) [TsoBlockx] + assertEqual (parseTsoFlags 8) [TsoInterruptible] + assertEqual (parseTsoFlags 16) [TsoStoppedOnBreakpoint] + assertEqual (parseTsoFlags 64) [TsoMarked] + assertEqual (parseTsoFlags 128) [TsoSqueezed] + assertEqual (parseTsoFlags 256) [TsoAllocLimit] + + assertEqual (parseTsoFlags 6) [TsoLocked, TsoBlockx] ===================================== libraries/ghc-heap/tests/prof_info.hs ===================================== @@ -0,0 +1,53 @@ +{-# LANGUAGE ForeignFunctionInterface, MagicHash, CPP, BangPatterns #-} + +import Prelude +import Foreign +import Foreign.C.Types +import GHC.Exts.Heap +import GHC.Exts +import Data.Functor + +import GHC.Word +import Data.List (find) + +import TestUtils + +#include "ghcconfig.h" +#include "rts/Constants.h" + +foreign import ccall unsafe "create_tso.h create_tso" + c_create_tso:: IO (Ptr ()) + +createTSOClosure :: IO (GenClosure Box) +createTSOClosure = do + ptr <- {-# SCC "MyCostCentre" #-} c_create_tso + let addr = unpackAddr# ptr + getClosureData ((unsafeCoerce# addr) :: LiftedClosure) + +-- We can make some assumptions about the - otherwise dynamic - properties of +-- StgTSO and StgStack, because a new, non-running TSO is created with +-- create_tso() (create_tso.c).create_tso +main :: IO () +main = do + tso <- createTSOClosure + + let costCentre = prof tso >>= cccs <&> ccs_cc + + case costCentre of + Nothing -> error $ "No CostCentre found in TSO: " ++ show tso + Just _ -> case findMyCostCentre (linkedCostCentres costCentre) of + Just myCostCentre -> do + assertEqual (cc_label myCostCentre) "MyCostCentre" + assertEqual (cc_module myCostCentre) "Main" + assertEqual (cc_srcloc myCostCentre) (Just "prof_info.hs:23:39-50") + assertEqual (cc_mem_alloc myCostCentre) 0 + assertEqual (cc_time_ticks myCostCentre) 0 + assertEqual (cc_is_caf myCostCentre) False + Nothing -> error "MyCostCentre not found!" + +linkedCostCentres :: Maybe CostCentre -> [CostCentre] +linkedCostCentres Nothing = [] +linkedCostCentres (Just cc) = cc : linkedCostCentres (cc_link cc) + +findMyCostCentre:: [CostCentre] -> Maybe CostCentre +findMyCostCentre ccs = find (\cc -> cc_label cc == "MyCostCentre") ccs ===================================== libraries/ghc-heap/tests/tso_and_stack_closures.hs ===================================== @@ -1,4 +1,4 @@ -{-# LANGUAGE ForeignFunctionInterface, MagicHash, CPP, BangPatterns #-} +{-# LANGUAGE ForeignFunctionInterface, MagicHash, BangPatterns #-} import Foreign import Foreign.C.Types @@ -7,16 +7,10 @@ import GHC.Exts import GHC.Word -#include "ghcconfig.h" -#include "rts/Constants.h" +import TestUtils foreign import ccall unsafe "create_tso.h create_tso" - c_create_tso:: IO Word - --- Invent a type to bypass the type constraints of getClosureData. --- Infact this will be a Word#, that is directly given to unpackClosure# --- (which is a primop that expects a pointer to a closure). -data FoolStgTSO + c_create_tso:: IO (Ptr ()) -- We can make some assumptions about the - otherwise dynamic - properties of -- StgTSO and StgStack, because a new, non-running TSO is created with @@ -28,14 +22,13 @@ main = do assertEqual (why_blocked tso) NotBlocked assertEqual (saved_errno tso) 0 - print $ "tso : "++ show tso - -- The newly created TSO should be on the end of the run queue. - let !_linkBox = _link tso + let !_linkBox = unsafe_link tso _linkClosure <- getBoxedClosureData _linkBox assertEqual (name _linkClosure) "END_TSO_QUEUE" + assertEqual (getClosureType _linkClosure) CONSTR_NOCAF - let !global_linkBox = global_link tso + let !global_linkBox = unsafe_global_link tso globalLinkClosure <- getBoxedClosureData global_linkBox assertEqual (getClosureType globalLinkClosure) TSO @@ -43,35 +36,26 @@ main = do stackClosure <- getBoxedClosureData stackBox assertEqual (getClosureType stackClosure) STACK - let !stackPointerBox = stackPointer stackClosure + let !stackPointerBox = unsafeStackPointer stackClosure stackPointerClosure <- getBoxedClosureData stackPointerBox assertEqual (getClosureType stackPointerClosure) RET_SMALL - let !trecBox = trec tso + let !trecBox = unsafe_trec tso trecClosure <- getBoxedClosureData trecBox assertEqual (name trecClosure) "NO_TREC" - let !blockedExceptionsBox = blocked_exceptions tso + let !blockedExceptionsBox = unsafe_blocked_exceptions tso blockedExceptionsClosure <- getBoxedClosureData blockedExceptionsBox assertEqual (name blockedExceptionsClosure) "END_TSO_QUEUE" - let !bqBox = bq tso + let !bqBox = unsafe_bq tso bqClosure <- getBoxedClosureData bqBox assertEqual (name bqClosure) "END_TSO_QUEUE" createTSOClosure :: IO (GenClosure Box) createTSOClosure = do ptr <- c_create_tso - let wPtr = unpackWord# ptr - getClosureData ((unsafeCoerce# wPtr) :: FoolStgTSO) - -unpackWord# :: Word -> Word# -unpackWord# (W# w#) = w# - -assertEqual :: (Show a, Eq a) => a -> a -> IO () -assertEqual a b - | a /= b = error (show a ++ " /= " ++ show b) - | otherwise = return () + createClosure ptr getClosureType :: GenClosure b -> ClosureType getClosureType = tipe . info ===================================== libraries/ghci/GHCi/Message.hs ===================================== @@ -1,5 +1,6 @@ {-# LANGUAGE GADTs, DeriveGeneric, StandaloneDeriving, ScopedTypeVariables, - GeneralizedNewtypeDeriving, ExistentialQuantification, RecordWildCards #-} + GeneralizedNewtypeDeriving, ExistentialQuantification, RecordWildCards, + CPP #-} {-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-orphans #-} -- | @@ -29,7 +30,7 @@ import GHCi.TH.Binary () -- For Binary instances import GHCi.BreakArray import GHC.LanguageExtensions -import GHC.Exts.Heap +import qualified GHC.Exts.Heap as Heap import GHC.ForeignSrcLang import GHC.Fingerprint import Control.Concurrent @@ -110,7 +111,7 @@ data Message a where -> Int -- constr tag -> Int -- pointer tag -> ByteString -- constructor desccription - -> Message (RemotePtr StgInfoTable) + -> Message (RemotePtr Heap.StgInfoTable) -- | Evaluate a statement EvalStmt @@ -211,7 +212,7 @@ data Message a where -- type reconstruction. GetClosure :: HValueRef - -> Message (GenClosure HValueRef) + -> Message (Heap.GenClosure HValueRef) -- | Evaluate something. This is used to support :force in GHCi. Seq @@ -449,10 +450,20 @@ instance Binary (FunPtr a) where get = castPtrToFunPtr <$> get -- Binary instances to support the GetClosure message -instance Binary StgInfoTable -instance Binary ClosureType -instance Binary PrimType -instance Binary a => Binary (GenClosure a) +#if MIN_VERSION_ghc_heap(8,11,0) +instance Binary Heap.StgTSOProfInfo +instance Binary Heap.CostCentreStack +instance Binary Heap.CostCentre +instance Binary Heap.IndexTable +instance Binary Heap.WhatNext +instance Binary Heap.WhyBlocked +instance Binary Heap.TsoFlags +#endif + +instance Binary Heap.StgInfoTable +instance Binary Heap.ClosureType +instance Binary Heap.PrimType +instance Binary a => Binary (Heap.GenClosure a) data Msg = forall a . (Binary a, Show a) => Msg (Message a) ===================================== libraries/ghci/GHCi/Run.hs ===================================== @@ -32,7 +32,7 @@ import Data.Binary.Get import Data.ByteString (ByteString) import qualified Data.ByteString.Unsafe as B import GHC.Exts -import GHC.Exts.Heap +import qualified GHC.Exts.Heap as Heap import GHC.Stack import Foreign hiding (void) import Foreign.C @@ -93,8 +93,8 @@ run m = case m of toRemotePtr <$> mkConInfoTable tc ptrs nptrs tag ptrtag desc StartTH -> startTH GetClosure ref -> do - clos <- getClosureData =<< localRef ref - mapM (\(Box x) -> mkRemoteRef (HValue x)) clos + clos <- Heap.getClosureData =<< localRef ref + mapM (\(Heap.Box x) -> mkRemoteRef (HValue x)) clos Seq ref -> doSeq ref ResumeSeq ref -> resumeSeq ref _other -> error "GHCi.Run.run" ===================================== rts/RtsAPI.c ===================================== @@ -621,21 +621,21 @@ rts_unlock (Capability *cap) task = cap->running_task; ASSERT_FULL_CAPABILITY_INVARIANTS(cap,task); - // Now release the Capability. With the capability released, GC - // may happen. NB. does not try to put the current Task on the + // Now release the Capability. With the capability released, GC + // may happen. NB. does not try to put the current Task on the // worker queue. - // NB. keep cap->lock held while we call boundTaskExiting(). This + // NB. keep cap->lock held while we call exitMyTask(). This // is necessary during shutdown, where we want the invariant that // after shutdownCapability(), all the Tasks associated with the - // Capability have completed their shutdown too. Otherwise we - // could have boundTaskExiting()/workerTaskStop() running at some + // Capability have completed their shutdown too. Otherwise we + // could have exitMyTask()/workerTaskStop() running at some // random point in the future, which causes problems for // freeTaskManager(). ACQUIRE_LOCK(&cap->lock); releaseCapability_(cap,false); // Finally, we can release the Task to the free list. - boundTaskExiting(task); + exitMyTask(); RELEASE_LOCK(&cap->lock); if (task->incall == NULL) { @@ -794,7 +794,7 @@ void rts_done (void) void hs_try_putmvar (/* in */ int capability, /* in */ HsStablePtr mvar) { - Task *task = getTask(); + Task *task = getMyTask(); Capability *cap; Capability *task_old_cap USED_IF_THREADS; ===================================== rts/Schedule.c ===================================== @@ -2082,7 +2082,7 @@ forkProcess(HsStablePtr *entry RELEASE_LOCK(&capabilities[i]->lock); } - boundTaskExiting(task); + exitMyTask(); // just return the pid return pid; @@ -2762,7 +2762,7 @@ exitScheduler (bool wait_foreign USED_IF_THREADS) // debugBelch("n_failed_trygrab_idles = %d, n_idle_caps = %d\n", // n_failed_trygrab_idles, n_idle_caps); - boundTaskExiting(task); + exitMyTask(); } void @@ -2821,7 +2821,7 @@ performGC_(bool force_major) waitForCapability(&cap,task); scheduleDoGC(&cap,task,force_major,false); releaseCapability(cap); - boundTaskExiting(task); + exitMyTask(); } void ===================================== rts/Task.c ===================================== @@ -116,7 +116,7 @@ freeTaskManager (void) return tasksRunning; } -Task* getTask (void) +Task* getMyTask (void) { Task *task; @@ -304,7 +304,7 @@ newBoundTask (void) stg_exit(EXIT_FAILURE); } - task = getTask(); + task = getMyTask(); task->stopped = false; @@ -315,13 +315,12 @@ newBoundTask (void) } void -boundTaskExiting (Task *task) +exitMyTask (void) { + Task* task = myTask(); #if defined(THREADED_RTS) ASSERT(osThreadId() == task->id); #endif - ASSERT(myTask() == task); - endInCall(task); // Set task->stopped, but only if this is the last call (#4850). @@ -522,7 +521,7 @@ void rts_setInCallCapability ( int preferred_capability, int affinity USED_IF_THREADS) { - Task *task = getTask(); + Task *task = getMyTask(); task->preferred_capability = preferred_capability; #if defined(THREADED_RTS) @@ -539,7 +538,7 @@ void rts_pinThreadToNumaNode ( { #if defined(THREADED_RTS) if (RtsFlags.GcFlags.numa) { - Task *task = getTask(); + Task *task = getMyTask(); task->node = capNoToNumaNode(node); if (!DEBUG_IS_ON || !RtsFlags.DebugFlags.numa) { // faking NUMA setThreadNode(numa_map[task->node]); ===================================== rts/Task.h ===================================== @@ -150,7 +150,7 @@ typedef struct Task_ { bool worker; // == true if this is a worker Task bool stopped; // == true between newBoundTask and - // boundTaskExiting, or in a worker Task. + // exitMyTask, or in a worker Task. // So that we can detect when a finalizer illegally calls back into Haskell bool running_finalizers; ===================================== rts/sm/NonMoving.c ===================================== @@ -1215,7 +1215,7 @@ static void nonmovingMark_(MarkQueue *mark_queue, StgWeak **dead_weaks, StgTSO * #if defined(THREADED_RTS) finish: - boundTaskExiting(task); + exitMyTask(); // We are done... mark_thread = 0; View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/26f2302e80c4d92f344997b120af5dba0c2fa4f9...d92c67f01bdd1da6f6f8ecebd5365aed3d62dab5 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/26f2302e80c4d92f344997b120af5dba0c2fa4f9...d92c67f01bdd1da6f6f8ecebd5365aed3d62dab5 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 22 12:26:52 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Sat, 22 Aug 2020 08:26:52 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] 8 commits: Decode CostCentreStacks, CostCentres and InfoTables (#18405) Message-ID: <5f410f0cbba9a_80b3f84693c1eb48928139@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: 43194225 by Sven Tennie at 2020-08-22T13:48:33+02:00 Decode CostCentreStacks, CostCentres and InfoTables (#18405) These are the data structures used by profiling, i.e. they are only available when the RTS is used with `-prof`. Otherwise fetching them results into `Nothing`. To reduce unnecessary decoding, a state monad transformer is used to provide caching for CostCentres. Because the three types form a circular data structure, loop-breakers are applied to prevent endless decoding loops. - - - - - e944ff9b by Sven Tennie at 2020-08-22T14:05:46+02:00 Use more precise types in tests (#18405) Use `Ptr ()` instead of `Word` to communicate that addresses/pointers are meant. - - - - - 06e0567f by Sven Tennie at 2020-08-22T14:05:46+02:00 Introduce LiftedClosure (#18405) This is a representation for closures that do not have a representation in the Haskell language. I.e. things like StgTSOs. - - - - - 80ade003 by Sven Tennie at 2020-08-22T14:05:46+02:00 Expect stack_marking starting from GHC 8.10 (#18405) This field was introduced with GHC 8.10. - - - - - b8e3c5c8 by Sven Tennie at 2020-08-22T14:05:46+02:00 Add WhatNext, WhyBlocked and TsoFlags to TSO closure (#18405) These constants can easily be decoded to sum types. Additionally extract TestUtils with common test functions. - - - - - e30edec6 by Sven Tennie at 2020-08-22T14:05:46+02:00 END_TSO_QUEUE is not a closure type on it's own (#18405) Indeed it's a CONSTR_NOCAF. - - - - - 5ee63586 by Sven Tennie at 2020-08-22T14:05:46+02:00 Rename boundTaskExiting and getTask (#18405) Both are directly related to myTask, which the new names now reflect. - - - - - 929c5c33 by Sven Tennie at 2020-08-22T14:05:46+02:00 Mark unsafe accesses (#18405) StgTSO and StgStack are very dynamic by nature. Accesses to outdated pointers lead to segmentation faults or absolutely wrong results. So, make sure (by naming) that the users nows about these facts. The safe way to access these fields it to stop the RTS via RTS API. - - - - - 24 changed files: - compiler/GHC/ByteCode/Types.hs - compiler/GHC/Runtime/Interpreter.hs - includes/rts/Task.h - libraries/ghc-heap/GHC/Exts/Heap.hs - libraries/ghc-heap/GHC/Exts/Heap/Closures.hs - libraries/ghc-heap/GHC/Exts/Heap/FFIClosures.hsc - + libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingDisabled.hsc - + libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc - + libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/Types.hs - + libraries/ghc-heap/GHC/Exts/Heap/Ptr/Utils.hs - libraries/ghc-heap/ghc-heap.cabal.in - + libraries/ghc-heap/tests/TestUtils.hs - libraries/ghc-heap/tests/all.T - libraries/ghc-heap/tests/list_threads_and_misc_roots.hs - + libraries/ghc-heap/tests/parse_tso_flags.hs - + libraries/ghc-heap/tests/prof_info.hs - libraries/ghc-heap/tests/tso_and_stack_closures.hs - libraries/ghci/GHCi/Message.hs - libraries/ghci/GHCi/Run.hs - rts/RtsAPI.c - rts/Schedule.c - rts/Task.c - rts/Task.h - rts/sm/NonMoving.c Changes: ===================================== compiler/GHC/ByteCode/Types.hs ===================================== @@ -36,7 +36,7 @@ import Data.ByteString (ByteString) import Data.IntMap (IntMap) import qualified Data.IntMap as IntMap import Data.Maybe (catMaybes) -import GHC.Exts.Heap +import qualified GHC.Exts.Heap as Heap import GHC.Stack.CCS -- ----------------------------------------------------------------------------- @@ -71,7 +71,7 @@ type ItblEnv = NameEnv (Name, ItblPtr) -- We need the Name in the range so we know which -- elements to filter out when unloading a module -newtype ItblPtr = ItblPtr (RemotePtr StgInfoTable) +newtype ItblPtr = ItblPtr (RemotePtr Heap.StgInfoTable) deriving (Show, NFData) data UnlinkedBCO ===================================== compiler/GHC/Runtime/Interpreter.hs ===================================== @@ -94,7 +94,7 @@ import qualified Data.ByteString.Lazy as LB import Data.Array ((!)) import Data.IORef import Foreign hiding (void) -import GHC.Exts.Heap +import qualified GHC.Exts.Heap as Heap import GHC.Stack.CCS (CostCentre,CostCentreStack) import System.Exit import GHC.IO.Handle.Types (Handle) @@ -386,7 +386,7 @@ getBreakpointVar hsc_env ref ix = mb <- iservCmd hsc_env (GetBreakpointVar apStack ix) mapM (mkFinalizedHValue hsc_env) mb -getClosure :: HscEnv -> ForeignHValue -> IO (GenClosure ForeignHValue) +getClosure :: HscEnv -> ForeignHValue -> IO (Heap.GenClosure ForeignHValue) getClosure hsc_env ref = withForeignRef ref $ \hval -> do mb <- iservCmd hsc_env (GetClosure hval) ===================================== includes/rts/Task.h ===================================== @@ -15,9 +15,9 @@ typedef struct Task_ Task; -// Create a new Task for a bound thread. This Task must be released -// by calling boundTaskExiting. The Task is cached in -// thread-local storage and will remain even after boundTaskExiting() +// Create a new Task for a bound thread. This Task must be released +// by calling exitMyTask(). The Task is cached in +// thread-local storage and will remain even after exitMyTask() // has been called; to free the memory, see freeMyTask(). // Task* newBoundTask (void); @@ -25,11 +25,10 @@ Task* newBoundTask (void); // Return the current OS thread's Task, which is created if it doesn't already // exist. After you have finished using RTS APIs, you should call freeMyTask() // to release this thread's Task. -Task* getTask (void); +Task* getMyTask (void); -// The current task is a bound task that is exiting. -// -void boundTaskExiting (Task *task); +// Exit myTask - This is the counterpart of newBoundTask(). +void exitMyTask (void); // Free a Task if one was previously allocated by newBoundTask(). // This is not necessary unless the thread that called newBoundTask() @@ -37,4 +36,3 @@ void boundTaskExiting (Task *task); // functions. // void freeMyTask(void); - ===================================== libraries/ghc-heap/GHC/Exts/Heap.hs ===================================== @@ -9,6 +9,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE ExplicitForAll #-} {-# LANGUAGE RankNTypes #-} +{-# LANGUAGE UnliftedFFITypes #-} {-| Module : GHC.Exts.Heap @@ -23,9 +24,13 @@ values, i.e. to investigate sharing and lazy evaluation. module GHC.Exts.Heap ( -- * Closure types Closure + , LiftedClosure , GenClosure(..) , ClosureType(..) , PrimType(..) + , WhatNext(..) + , WhyBlocked(..) + , TsoFlags(..) , HasHeapRep(getClosureDataX) , getClosureData @@ -38,6 +43,12 @@ module GHC.Exts.Heap ( , peekItbl , pokeItbl + -- * Cost Centre (profiling) types + , StgTSOProfInfo(..) + , IndexTable(..) + , CostCentre(..) + , CostCentreStack(..) + -- * Closure inspection , getBoxedClosureData , allClosures @@ -52,9 +63,19 @@ import Prelude import GHC.Exts.Heap.Closures import GHC.Exts.Heap.ClosureTypes import GHC.Exts.Heap.Constants +import GHC.Exts.Heap.ProfInfo.Types #if defined(PROFILING) +import GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingEnabled import GHC.Exts.Heap.InfoTableProf #else +-- This import makes PeekProfInfo_ProfilingEnabled available in make-based +-- builds. See #15197 for details (even though the related patch didn't +-- seem to fix the issue). +-- GHC.Exts.Heap.Closures uses the same trick to include +-- GHC.Exts.Heap.InfoTableProf into make-based builds. +import GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingEnabled () + +import GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingDisabled import GHC.Exts.Heap.InfoTable #endif import GHC.Exts.Heap.Utils @@ -71,12 +92,19 @@ import Foreign #include "ghcconfig.h" +-- | Some closures (e.g.TSOs) don't have corresponding types to represent them in Haskell. +-- So when we have a pointer to such closure that we want to inspect, we `unsafeCoerce` it +-- into the following `LiftedClosure` lifted type (could be any lifted type) so that the +-- appropriate `instance HasHeapRep (a :: TYPE 'LiftedRep)` is used to decode the closure. +data LiftedClosure + class HasHeapRep (a :: TYPE rep) where -- | Decode a closure to it's heap representation ('GenClosure'). -- Inside a GHC context 'b' is usually a 'GHC.Exts.Heap.Closures.Box' -- containing a thunk or an evaluated heap object. Outside it can be a -- 'Word' for "raw" usage of pointers. + getClosureDataX :: (forall c . c -> IO (Ptr StgInfoTable, [Word], [b])) -- ^ Helper function to get info table, memory and pointers of the @@ -166,6 +194,7 @@ getClosureData = getClosureDataX getClosureRaw -- @collect_pointers()@ in @rts/Heap.c at . -- -- For most use cases 'getClosureData' is an easier to use alternative. + getClosureX :: forall a b. (forall c . c -> IO (Ptr StgInfoTable, [Word], [b])) -- ^ Helper function to get info table, memory and pointers of the @@ -325,16 +354,15 @@ getClosureX get_closure_raw x = do allocaArray (length wds) (\ptr -> do pokeArray ptr wds - fields <- FFIClosures.peekTSOFields ptr - + fields <- FFIClosures.peekTSOFields peekStgTSOProfInfo ptr pure $ TSOClosure { info = itbl - , _link = (pts !! 0) - , global_link = (pts !! 1) + , unsafe_link = (pts !! 0) + , unsafe_global_link = (pts !! 1) , tsoStack = (pts !! 2) - , trec = (pts !! 3) - , blocked_exceptions = (pts !! 4) - , bq = (pts !! 5) + , unsafe_trec = (pts !! 3) + , unsafe_blocked_exceptions = (pts !! 4) + , unsafe_bq = (pts !! 5) , what_next = FFIClosures.tso_what_next fields , why_blocked = FFIClosures.tso_why_blocked fields , flags = FFIClosures.tso_flags fields @@ -343,6 +371,7 @@ getClosureX get_closure_raw x = do , tso_dirty = FFIClosures.tso_dirty fields , alloc_limit = FFIClosures.tso_alloc_limit fields , tot_stack_size = FFIClosures.tso_tot_stack_size fields + , prof = FFIClosures.tso_prof fields } ) STACK -> do @@ -359,8 +388,8 @@ getClosureX get_closure_raw x = do { info = itbl , stack_size = FFIClosures.stack_size fields , stack_dirty = FFIClosures.stack_dirty fields - , stackPointer = (pts !! 0) - , stack = FFIClosures.stack fields + , unsafeStackPointer = (pts !! 0) + , unsafeStack = FFIClosures.stack fields #if __GLASGOW_HASKELL__ >= 811 , stack_marking = FFIClosures.stack_marking fields #endif ===================================== libraries/ghc-heap/GHC/Exts/Heap/Closures.hs ===================================== @@ -12,6 +12,9 @@ module GHC.Exts.Heap.Closures ( Closure , GenClosure(..) , PrimType(..) + , WhatNext(..) + , WhyBlocked(..) + , TsoFlags(..) , allClosures #if __GLASGOW_HASKELL__ >= 809 -- The closureSize# primop is unsupported on earlier GHC releases but we @@ -40,6 +43,8 @@ import GHC.Exts.Heap.InfoTable import GHC.Exts.Heap.InfoTableProf () #endif +import GHC.Exts.Heap.ProfInfo.Types + import Data.Bits import Data.Int import Data.Word @@ -271,35 +276,42 @@ data GenClosure b -- | Representation of StgTSO: A Thread State Object. -- The values for 'what_next', 'why_blocked' and 'flags' are defined in -- @Constants.h at . + -- Fields marked as @unsafe@ are backed by dynamic pointers and should only + -- be accessed when the garbage collector is stopped. Otherwise segmentation + -- faults may happen when an invalidated pointer is accessed. | TSOClosure { info :: !StgInfoTable -- pointers - , _link :: !b - , global_link :: !b + , unsafe_link :: !b + , unsafe_global_link :: !b , tsoStack :: !b -- ^ stackobj from StgTSO - , trec :: !b - , blocked_exceptions :: !b - , bq :: !b + , unsafe_trec :: !b + , unsafe_blocked_exceptions :: !b + , unsafe_bq :: !b -- values - , what_next :: Word16 - , why_blocked :: Word16 - , flags :: Word32 + , what_next :: WhatNext + , why_blocked :: WhyBlocked + , flags :: [TsoFlags] , threadId :: Word64 , saved_errno :: Word32 , tso_dirty:: Word32 -- ^ non-zero => dirty , alloc_limit :: Int64 , tot_stack_size :: Word32 + , prof :: Maybe StgTSOProfInfo } - -- Representation of StgStack: The 'tsoStack' of a 'TSOClosure'. + -- | Representation of StgStack: The 'tsoStack' of a 'TSOClosure'. + -- Fields marked as @unsafe@ are backed by dynamic pointers and should only + -- be accessed when the garbage collector is stopped. Otherwise segmentation + -- faults may happen when an invalidated pointer is accessed. | StackClosure { info :: !StgInfoTable , stack_size :: !Word32 -- ^ stack size in *words* , stack_dirty :: !Word8 -- ^ non-zero => dirty -#if __GLASGOW_HASKELL__ >= 811 +#if __GLASGOW_HASKELL__ >= 810 , stack_marking :: Word8 #endif - , stackPointer :: !b -- ^ current stack pointer - , stack :: [Word] + , unsafeStackPointer :: !b -- ^ current stack pointer + , unsafeStack :: [Word] } ------------------------------------------------------------ @@ -366,6 +378,43 @@ data PrimType | PDouble deriving (Eq, Show, Generic) +data WhatNext + = ThreadRunGHC + | ThreadInterpret + | ThreadKilled + | ThreadComplete + | WhatNextUnknownValue -- ^ Please report this as a bug + deriving (Eq, Show, Generic) + +data WhyBlocked + = NotBlocked + | BlockedOnMVar + | BlockedOnMVarRead + | BlockedOnBlackHole + | BlockedOnRead + | BlockedOnWrite + | BlockedOnDelay + | BlockedOnSTM + | BlockedOnDoProc + | BlockedOnCCall + | BlockedOnCCall_Interruptible + | BlockedOnMsgThrowTo + | ThreadMigrating + | BlockedOnIOCompletion + | WhyBlockedUnknownValue -- ^ Please report this as a bug + deriving (Eq, Show, Generic) + +data TsoFlags + = TsoLocked + | TsoBlockx + | TsoInterruptible + | TsoStoppedOnBreakpoint + | TsoMarked + | TsoSqueezed + | TsoAllocLimit + | TsoFlagsUnknownValue -- ^ Please report this as a bug + deriving (Eq, Show, Generic) + -- | For generic code, this function returns all referenced closures. allClosures :: GenClosure b -> [b] allClosures (ConstrClosure {..}) = ptrArgs ===================================== libraries/ghc-heap/GHC/Exts/Heap/FFIClosures.hsc ===================================== @@ -5,26 +5,28 @@ module GHC.Exts.Heap.FFIClosures where import Prelude import Foreign - --- TODO use sum type for what_next, why_blocked, flags? +import GHC.Exts.Heap.ProfInfo.Types +import GHC.Exts.Heap.Closures(WhatNext(..), WhyBlocked(..), TsoFlags(..)) data TSOFields = TSOFields { - tso_what_next :: Word16, - tso_why_blocked :: Word16, - tso_flags :: Word32, + tso_what_next :: WhatNext, + tso_why_blocked :: WhyBlocked, + tso_flags :: [TsoFlags], -- Unfortunately block_info is a union without clear discriminator. -- block_info :: TDB, tso_threadId :: Word64, tso_saved_errno :: Word32, tso_dirty:: Word32, tso_alloc_limit :: Int64, - tso_tot_stack_size :: Word32 --- TODO StgTSOProfInfo prof is optionally included, but looks very interesting. + tso_tot_stack_size :: Word32, + tso_prof :: Maybe StgTSOProfInfo } -- | Get non-pointer fields from @StgTSO_@ (@TSO.h@) -peekTSOFields :: Ptr a -> IO TSOFields -peekTSOFields ptr = do +peekTSOFields :: (Ptr tsoPtr -> IO (Maybe StgTSOProfInfo)) + -> Ptr tsoPtr + -> IO TSOFields +peekTSOFields peekProfInfo ptr = do what_next' <- (#peek struct StgTSO_, what_next) ptr why_blocked' <- (#peek struct StgTSO_, why_blocked) ptr flags' <- (#peek struct StgTSO_, flags) ptr @@ -33,22 +35,69 @@ peekTSOFields ptr = do dirty' <- (#peek struct StgTSO_, dirty) ptr alloc_limit' <- (#peek struct StgTSO_, alloc_limit) ptr tot_stack_size' <- (#peek struct StgTSO_, tot_stack_size) ptr + tso_prof' <- peekProfInfo ptr return TSOFields { - tso_what_next = what_next', - tso_why_blocked = why_blocked', - tso_flags = flags', + tso_what_next = parseWhatNext what_next', + tso_why_blocked = parseWhyBlocked why_blocked', + tso_flags = parseTsoFlags flags', tso_threadId = threadId', tso_saved_errno = saved_errno', - tso_dirty= dirty', + tso_dirty = dirty', tso_alloc_limit = alloc_limit', - tso_tot_stack_size = tot_stack_size' + tso_tot_stack_size = tot_stack_size', + tso_prof = tso_prof' } +parseWhatNext :: Word16 -> WhatNext +parseWhatNext w = case w of + (#const ThreadRunGHC) -> ThreadRunGHC + (#const ThreadInterpret) -> ThreadInterpret + (#const ThreadKilled) -> ThreadKilled + (#const ThreadComplete) -> ThreadComplete + _ -> WhatNextUnknownValue + +parseWhyBlocked :: Word16 -> WhyBlocked +parseWhyBlocked w = case w of + (#const NotBlocked) -> NotBlocked + (#const BlockedOnMVar) -> BlockedOnMVar + (#const BlockedOnMVarRead) -> BlockedOnMVarRead + (#const BlockedOnBlackHole) -> BlockedOnBlackHole + (#const BlockedOnRead) -> BlockedOnRead + (#const BlockedOnWrite) -> BlockedOnWrite + (#const BlockedOnDelay) -> BlockedOnDelay + (#const BlockedOnSTM) -> BlockedOnSTM + (#const BlockedOnDoProc) -> BlockedOnDoProc + (#const BlockedOnCCall) -> BlockedOnCCall + (#const BlockedOnCCall_Interruptible) -> BlockedOnCCall_Interruptible + (#const BlockedOnMsgThrowTo) -> BlockedOnMsgThrowTo + (#const ThreadMigrating) -> ThreadMigrating +#if __GLASGOW_HASKELL__ >= 810 + (#const BlockedOnIOCompletion) -> BlockedOnIOCompletion +#endif + _ -> WhyBlockedUnknownValue + +parseTsoFlags :: Word32 -> [TsoFlags] +parseTsoFlags w | isSet (#const TSO_LOCKED) w = TsoLocked : parseTsoFlags (unset (#const TSO_LOCKED) w) + | isSet (#const TSO_BLOCKEX) w = TsoBlockx : parseTsoFlags (unset (#const TSO_BLOCKEX) w) + | isSet (#const TSO_INTERRUPTIBLE) w = TsoInterruptible : parseTsoFlags (unset (#const TSO_INTERRUPTIBLE) w) + | isSet (#const TSO_STOPPED_ON_BREAKPOINT) w = TsoStoppedOnBreakpoint : parseTsoFlags (unset (#const TSO_STOPPED_ON_BREAKPOINT) w) + | isSet (#const TSO_MARKED) w = TsoMarked : parseTsoFlags (unset (#const TSO_MARKED) w) + | isSet (#const TSO_SQUEEZED) w = TsoSqueezed : parseTsoFlags (unset (#const TSO_SQUEEZED) w) + | isSet (#const TSO_ALLOC_LIMIT) w = TsoAllocLimit : parseTsoFlags (unset (#const TSO_ALLOC_LIMIT) w) +parseTsoFlags 0 = [] +parseTsoFlags _ = [TsoFlagsUnknownValue] + +isSet :: Word32 -> Word32 -> Bool +isSet bitMask w = w .&. bitMask /= 0 + +unset :: Word32 -> Word32 -> Word32 +unset bitMask w = w `xor` bitMask + data StackFields = StackFields { stack_size :: Word32, stack_dirty :: Word8, -#if __GLASGOW_HASKELL__ >= 811 +#if __GLASGOW_HASKELL__ >= 810 stack_marking :: Word8, #endif stack :: [Word] @@ -59,7 +108,7 @@ peekStackFields :: Ptr a -> IO StackFields peekStackFields ptr = do stack_size' <- (#peek struct StgStack_, stack_size) ptr ::IO Word32 dirty' <- (#peek struct StgStack_, dirty) ptr -#if __GLASGOW_HASKELL__ >= 811 +#if __GLASGOW_HASKELL__ >= 810 marking' <- (#peek struct StgStack_, marking) ptr #endif @@ -69,7 +118,7 @@ peekStackFields ptr = do return StackFields { stack_size = stack_size', stack_dirty = dirty', -#if __GLASGOW_HASKELL__ >= 811 +#if __GLASGOW_HASKELL__ >= 810 stack_marking = marking', #endif stack = stack' ===================================== libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingDisabled.hsc ===================================== @@ -0,0 +1,13 @@ +{-# LANGUAGE CPP, DeriveGeneric #-} +module GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingDisabled( + peekStgTSOProfInfo +) where + +import Prelude +import Foreign +import GHC.Exts.Heap.ProfInfo.Types + +-- | This implementation is used when PROFILING is undefined. +-- It always returns 'Nothing', because there is no profiling info available. +peekStgTSOProfInfo :: Ptr tsoPtr -> IO (Maybe StgTSOProfInfo) +peekStgTSOProfInfo _ = return Nothing ===================================== libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc ===================================== @@ -0,0 +1,168 @@ +{-# LANGUAGE CPP, DeriveGeneric #-} +module GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingEnabled( + peekStgTSOProfInfo +) where + +#if __GLASGOW_HASKELL__ >= 811 + +-- Manually defining PROFILING gives the #peek and #poke macros an accurate +-- representation of the C structures when hsc2hs runs. This is valid because +-- a non-profiling build would use +-- GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingDisabled. +#define PROFILING + +#include "Rts.h" +#undef BLOCK_SIZE +#undef MBLOCK_SIZE +#undef BLOCKS_PER_MBLOCK +#include "DerivedConstants.h" + +import Prelude +import Foreign + +import Foreign.C.String +import GHC.Exts.Heap.ProfInfo.Types + +import Data.IntMap.Strict (IntMap) +import qualified Data.IntMap.Strict as IntMap + +import Data.IntSet (IntSet) +import qualified Data.IntSet as IntSet + +import Control.Monad.Trans.State +import Control.Monad.IO.Class + +import GHC.Exts.Heap.Ptr.Utils + +-- Use Int based containers for pointers (addresses) for better performance. +-- These will be queried a lot! +type AddressSet = IntSet +type AddressMap = IntMap + +data Cache = Cache { + ccCache :: AddressMap CostCentre +} +type DecoderMonad a = StateT Cache IO a + +peekStgTSOProfInfo :: Ptr a -> IO (Maybe StgTSOProfInfo) +peekStgTSOProfInfo tsoPtr = do + cccs_ptr <- peekByteOff tsoPtr cccsOffset + cccs' <- evalStateT (peekCostCentreStack IntSet.empty cccs_ptr) $ Cache IntMap.empty + + return $ Just StgTSOProfInfo { + cccs = cccs' + } + +cccsOffset :: Int +cccsOffset = (#const OFFSET_StgTSO_cccs) + (#size StgHeader) + +peekCostCentreStack :: AddressSet -> Ptr costCentreStack -> DecoderMonad (Maybe CostCentreStack) +peekCostCentreStack _ ptr | ptr == nullPtr = return Nothing +peekCostCentreStack loopBreakers ptr | IntSet.member (ptrToInt ptr) loopBreakers = return Nothing +peekCostCentreStack loopBreakers ptr = do + ccs_ccsID' <- liftIO $ (#peek struct CostCentreStack_, ccsID) ptr + ccs_cc_ptr <- liftIO $ (#peek struct CostCentreStack_, cc) ptr + ccs_cc' <- peekCostCentre ccs_cc_ptr + ccs_prevStack_ptr <- liftIO $ (#peek struct CostCentreStack_, prevStack) ptr + let loopBreakers' = (IntSet.insert ptrAsInt loopBreakers) + ccs_prevStack' <- peekCostCentreStack loopBreakers' ccs_prevStack_ptr + ccs_indexTable_ptr <- liftIO $ (#peek struct CostCentreStack_, indexTable) ptr + ccs_indexTable' <- peekIndexTable loopBreakers' ccs_indexTable_ptr + ccs_root_ptr <- liftIO $ (#peek struct CostCentreStack_, root) ptr + ccs_root' <- peekCostCentreStack loopBreakers' ccs_root_ptr + ccs_depth' <- liftIO $ (#peek struct CostCentreStack_, depth) ptr + ccs_scc_count' <- liftIO $ (#peek struct CostCentreStack_, scc_count) ptr + ccs_selected' <- liftIO $ (#peek struct CostCentreStack_, selected) ptr + ccs_time_ticks' <- liftIO $ (#peek struct CostCentreStack_, time_ticks) ptr + ccs_mem_alloc' <- liftIO $ (#peek struct CostCentreStack_, mem_alloc) ptr + ccs_inherited_alloc' <- liftIO $ (#peek struct CostCentreStack_, inherited_alloc) ptr + ccs_inherited_ticks' <- liftIO $ (#peek struct CostCentreStack_, inherited_ticks) ptr + + return $ Just CostCentreStack { + ccs_ccsID = ccs_ccsID', + ccs_cc = ccs_cc', + ccs_prevStack = ccs_prevStack', + ccs_indexTable = ccs_indexTable', + ccs_root = ccs_root', + ccs_depth = ccs_depth', + ccs_scc_count = ccs_scc_count', + ccs_selected = ccs_selected', + ccs_time_ticks = ccs_time_ticks', + ccs_mem_alloc = ccs_mem_alloc', + ccs_inherited_alloc = ccs_inherited_alloc', + ccs_inherited_ticks = ccs_inherited_ticks' + } + where + ptrAsInt = ptrToInt ptr + +peekCostCentre :: Ptr costCentre -> DecoderMonad CostCentre +peekCostCentre ptr = do + cache <- get + case IntMap.lookup ptrAsInt (ccCache cache) of + (Just a) -> return a + Nothing -> do + cc_ccID' <- liftIO $ (#peek struct CostCentre_, ccID) ptr + cc_label_ptr <- liftIO $ (#peek struct CostCentre_, label) ptr + cc_label' <- liftIO $ peekCString cc_label_ptr + cc_module_ptr <- liftIO $ (#peek struct CostCentre_, module) ptr + cc_module' <- liftIO $ peekCString cc_module_ptr + cc_srcloc_ptr <- liftIO $ (#peek struct CostCentre_, srcloc) ptr + cc_srcloc' <- liftIO $ do + if cc_srcloc_ptr == nullPtr then + return Nothing + else + fmap Just (peekCString cc_srcloc_ptr) + cc_mem_alloc' <- liftIO $ (#peek struct CostCentre_, mem_alloc) ptr + cc_time_ticks' <- liftIO $ (#peek struct CostCentre_, time_ticks) ptr + cc_is_caf' <- liftIO $ (#peek struct CostCentre_, is_caf) ptr + cc_link_ptr <- liftIO $ (#peek struct CostCentre_, link) ptr + cc_link' <- if cc_link_ptr == nullPtr then + return Nothing + else + fmap Just (peekCostCentre cc_link_ptr) + + let result = CostCentre { + cc_ccID = cc_ccID', + cc_label = cc_label', + cc_module = cc_module', + cc_srcloc = cc_srcloc', + cc_mem_alloc = cc_mem_alloc', + cc_time_ticks = cc_time_ticks', + cc_is_caf = cc_is_caf', + cc_link = cc_link' + } + + let updatedCCCache = IntMap.insert ptrAsInt result (ccCache cache) + put $ cache { ccCache = updatedCCCache } + + return result + where + ptrAsInt = ptrToInt ptr + +peekIndexTable :: AddressSet -> Ptr indexTable -> DecoderMonad (Maybe IndexTable) +peekIndexTable _ ptr | ptr == nullPtr = return Nothing +peekIndexTable loopBreakers ptr = do + it_cc_ptr <- liftIO $ (#peek struct IndexTable_, cc) ptr + it_cc' <- peekCostCentre it_cc_ptr + it_ccs_ptr <- liftIO $ (#peek struct IndexTable_, ccs) ptr + it_ccs' <- peekCostCentreStack loopBreakers it_ccs_ptr + it_next_ptr <- liftIO $ (#peek struct IndexTable_, next) ptr + it_next' <- peekIndexTable loopBreakers it_next_ptr + it_back_edge' <- liftIO $ (#peek struct IndexTable_, back_edge) ptr + + return $ Just IndexTable { + it_cc = it_cc', + it_ccs = it_ccs', + it_next = it_next', + it_back_edge = it_back_edge' + } + +#else +import Prelude +import Foreign + +import GHC.Exts.Heap.ProfInfo.Types + +peekStgTSOProfInfo :: Ptr a -> IO (Maybe StgTSOProfInfo) +peekStgTSOProfInfo _ = return Nothing +#endif ===================================== libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/Types.hs ===================================== @@ -0,0 +1,44 @@ +{-# LANGUAGE DeriveGeneric #-} + +module GHC.Exts.Heap.ProfInfo.Types where + +import Prelude +import Data.Word +import GHC.Generics + +data StgTSOProfInfo = StgTSOProfInfo { + cccs :: Maybe CostCentreStack +} deriving (Show, Generic) + +data CostCentreStack = CostCentreStack { + ccs_ccsID :: Int, + ccs_cc :: CostCentre, + ccs_prevStack :: Maybe CostCentreStack, + ccs_indexTable :: Maybe IndexTable, + ccs_root :: Maybe CostCentreStack, + ccs_depth :: Word, + ccs_scc_count :: Word64, + ccs_selected :: Word, + ccs_time_ticks :: Word, + ccs_mem_alloc :: Word64, + ccs_inherited_alloc :: Word64, + ccs_inherited_ticks :: Word +} deriving (Show, Generic, Eq) + +data CostCentre = CostCentre { + cc_ccID :: Int, + cc_label :: String, + cc_module :: String, + cc_srcloc :: Maybe String, + cc_mem_alloc :: Word64, + cc_time_ticks :: Word, + cc_is_caf :: Bool, + cc_link :: Maybe CostCentre +} deriving (Show, Generic, Eq) + +data IndexTable = IndexTable { + it_cc :: CostCentre, + it_ccs :: Maybe CostCentreStack, + it_next :: Maybe IndexTable, + it_back_edge :: Bool +} deriving (Show, Generic, Eq) ===================================== libraries/ghc-heap/GHC/Exts/Heap/Ptr/Utils.hs ===================================== @@ -0,0 +1,11 @@ +{-# LANGUAGE CPP, DeriveGeneric, MagicHash #-} + +module GHC.Exts.Heap.Ptr.Utils where + +import Prelude +import GHC.Ptr +import GHC.Exts + +-- | casts a @Ptr@ to an @Int@ +ptrToInt :: Ptr a -> Int +ptrToInt (Ptr a#) = I# (addr2Int# a#) ===================================== libraries/ghc-heap/ghc-heap.cabal.in ===================================== @@ -25,6 +25,8 @@ library build-depends: base >= 4.9.0 && < 5.0 , ghc-prim > 0.2 && < 0.8 , rts == 1.0.* + , containers >= 0.6.2.1 && < 0.7 + , transformers == 0.5.* ghc-options: -Wall cmm-sources: cbits/HeapPrim.cmm @@ -40,3 +42,7 @@ library GHC.Exts.Heap.InfoTableProf GHC.Exts.Heap.Utils GHC.Exts.Heap.FFIClosures + GHC.Exts.Heap.ProfInfo.Types + GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingEnabled + GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingDisabled + GHC.Exts.Heap.Ptr.Utils ===================================== libraries/ghc-heap/tests/TestUtils.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE MagicHash #-} +module TestUtils where + +import GHC.Exts.Heap (getClosureData, LiftedClosure, Box, GenClosure) +import Foreign (Ptr) +import GHC.Exts (Ptr, Addr#, unsafeCoerce#) +import GHC.Ptr (Ptr(Ptr)) + +assertEqual :: (Show a, Eq a) => a -> a -> IO () +assertEqual a b + | a /= b = error (show a ++ " /= " ++ show b) + | otherwise = return () + +createClosure :: Ptr () -> IO (GenClosure Box) +createClosure tsoPtr = do + let addr = unpackAddr# tsoPtr + getClosureData ((unsafeCoerce# addr) :: LiftedClosure) + +unpackAddr# :: Ptr () -> Addr# +unpackAddr# (Ptr addr) = addr ===================================== libraries/ghc-heap/tests/all.T ===================================== @@ -37,15 +37,32 @@ test('closure_size_noopt', compile_and_run, ['']) test('tso_and_stack_closures', - [extra_files(['create_tso.c','create_tso.h']), + [extra_files(['create_tso.c','create_tso.h', 'TestUtils.hs']), ignore_stdout, ignore_stderr ], multi_compile_and_run, ['tso_and_stack_closures', [('create_tso.c','')], '']) test('list_threads_and_misc_roots', - [extra_files(['list_threads_and_misc_roots_c.c','list_threads_and_misc_roots_c.h']), + [extra_files(['list_threads_and_misc_roots_c.c','list_threads_and_misc_roots_c.h','TestUtils.hs']), ignore_stdout, ignore_stderr ], multi_compile_and_run, ['list_threads_and_misc_roots', [('list_threads_and_misc_roots_c.c','')], '-threaded']) + +test('prof_info', + [extra_files(['create_tso.c','create_tso.h','TestUtils.hs']), + ignore_stdout, + ignore_stderr, + when(have_profiling(), extra_ways(['prof'])), + only_ways(prof_ways) + ], + multi_compile_and_run, ['prof_info', [('create_tso.c','')], '-prof']) + +test('parse_tso_flags', + [extra_files(['TestUtils.hs']), + only_ways(['normal']), + ignore_stdout, + ignore_stderr + ], + compile_and_run, ['']) ===================================== libraries/ghc-heap/tests/list_threads_and_misc_roots.hs ===================================== @@ -7,11 +7,7 @@ import Control.Concurrent import GHC.Exts.Heap import GHC.Exts - --- Invent a type to bypass the type constraints of getClosureData. --- Infact this will be a Word#, that is directly given to unpackClosure# --- (which is a primop that expects a pointer to a closure). -data FoolClosure +import TestUtils foreign import ccall safe "list_threads_and_misc_roots_c.h listThreadsAndMiscRoots" listThreadsAndMiscRoots_c :: IO () @@ -20,13 +16,13 @@ foreign import ccall safe "list_threads_and_misc_roots_c.h getTSOCount" getTSOCount_c :: IO Int foreign import ccall safe "list_threads_and_misc_roots_c.h getTSOs" - getTSOs_c :: IO (Ptr Word) + getTSOs_c :: IO (Ptr (Ptr ())) foreign import ccall safe "list_threads_and_misc_roots_c.h getMiscRootsCount" getMiscRootsCount_c :: IO Int foreign import ccall safe "list_threads_and_misc_roots_c.h getMiscRoots" - getMiscRoots_c :: IO (Ptr Word) + getMiscRoots_c :: IO (Ptr (Ptr ())) main :: IO () main = do @@ -50,19 +46,6 @@ main = do return () -createClosure :: Word -> IO (GenClosure Box) -createClosure tsoPtr = do - let wPtr = unpackWord# tsoPtr - getClosureData ((unsafeCoerce# wPtr) :: FoolClosure) - -unpackWord# :: Word -> Word# -unpackWord# (W# w#) = w# - -assertEqual :: (Show a, Eq a) => a -> a -> IO () -assertEqual a b - | a /= b = error (show a ++ " /= " ++ show b) - | otherwise = return () - assertIsClosureType :: ClosureType -> IO () assertIsClosureType t | t `elem` enumerate = return () ===================================== libraries/ghc-heap/tests/parse_tso_flags.hs ===================================== @@ -0,0 +1,17 @@ +import GHC.Exts.Heap.Closures +import GHC.Exts.Heap.FFIClosures +import TestUtils + +main :: IO() +main = do + assertEqual (parseTsoFlags 0) [] + assertEqual (parseTsoFlags 1) [TsoFlagsUnknownValue] + assertEqual (parseTsoFlags 2) [TsoLocked] + assertEqual (parseTsoFlags 4) [TsoBlockx] + assertEqual (parseTsoFlags 8) [TsoInterruptible] + assertEqual (parseTsoFlags 16) [TsoStoppedOnBreakpoint] + assertEqual (parseTsoFlags 64) [TsoMarked] + assertEqual (parseTsoFlags 128) [TsoSqueezed] + assertEqual (parseTsoFlags 256) [TsoAllocLimit] + + assertEqual (parseTsoFlags 6) [TsoLocked, TsoBlockx] ===================================== libraries/ghc-heap/tests/prof_info.hs ===================================== @@ -0,0 +1,53 @@ +{-# LANGUAGE ForeignFunctionInterface, MagicHash, CPP, BangPatterns #-} + +import Prelude +import Foreign +import Foreign.C.Types +import GHC.Exts.Heap +import GHC.Exts +import Data.Functor + +import GHC.Word +import Data.List (find) + +import TestUtils + +#include "ghcconfig.h" +#include "rts/Constants.h" + +foreign import ccall unsafe "create_tso.h create_tso" + c_create_tso:: IO (Ptr ()) + +createTSOClosure :: IO (GenClosure Box) +createTSOClosure = do + ptr <- {-# SCC "MyCostCentre" #-} c_create_tso + let addr = unpackAddr# ptr + getClosureData ((unsafeCoerce# addr) :: LiftedClosure) + +-- We can make some assumptions about the - otherwise dynamic - properties of +-- StgTSO and StgStack, because a new, non-running TSO is created with +-- create_tso() (create_tso.c).create_tso +main :: IO () +main = do + tso <- createTSOClosure + + let costCentre = prof tso >>= cccs <&> ccs_cc + + case costCentre of + Nothing -> error $ "No CostCentre found in TSO: " ++ show tso + Just _ -> case findMyCostCentre (linkedCostCentres costCentre) of + Just myCostCentre -> do + assertEqual (cc_label myCostCentre) "MyCostCentre" + assertEqual (cc_module myCostCentre) "Main" + assertEqual (cc_srcloc myCostCentre) (Just "prof_info.hs:23:39-50") + assertEqual (cc_mem_alloc myCostCentre) 0 + assertEqual (cc_time_ticks myCostCentre) 0 + assertEqual (cc_is_caf myCostCentre) False + Nothing -> error "MyCostCentre not found!" + +linkedCostCentres :: Maybe CostCentre -> [CostCentre] +linkedCostCentres Nothing = [] +linkedCostCentres (Just cc) = cc : linkedCostCentres (cc_link cc) + +findMyCostCentre:: [CostCentre] -> Maybe CostCentre +findMyCostCentre ccs = find (\cc -> cc_label cc == "MyCostCentre") ccs ===================================== libraries/ghc-heap/tests/tso_and_stack_closures.hs ===================================== @@ -1,4 +1,4 @@ -{-# LANGUAGE ForeignFunctionInterface, MagicHash, CPP, BangPatterns #-} +{-# LANGUAGE ForeignFunctionInterface, MagicHash, BangPatterns #-} import Foreign import Foreign.C.Types @@ -7,16 +7,10 @@ import GHC.Exts import GHC.Word -#include "ghcconfig.h" -#include "rts/Constants.h" +import TestUtils foreign import ccall unsafe "create_tso.h create_tso" - c_create_tso:: IO Word - --- Invent a type to bypass the type constraints of getClosureData. --- Infact this will be a Word#, that is directly given to unpackClosure# --- (which is a primop that expects a pointer to a closure). -data FoolStgTSO + c_create_tso:: IO (Ptr ()) -- We can make some assumptions about the - otherwise dynamic - properties of -- StgTSO and StgStack, because a new, non-running TSO is created with @@ -28,14 +22,13 @@ main = do assertEqual (why_blocked tso) NotBlocked assertEqual (saved_errno tso) 0 - print $ "tso : "++ show tso - -- The newly created TSO should be on the end of the run queue. - let !_linkBox = _link tso + let !_linkBox = unsafe_link tso _linkClosure <- getBoxedClosureData _linkBox assertEqual (name _linkClosure) "END_TSO_QUEUE" + assertEqual (getClosureType _linkClosure) CONSTR_NOCAF - let !global_linkBox = global_link tso + let !global_linkBox = unsafe_global_link tso globalLinkClosure <- getBoxedClosureData global_linkBox assertEqual (getClosureType globalLinkClosure) TSO @@ -43,35 +36,26 @@ main = do stackClosure <- getBoxedClosureData stackBox assertEqual (getClosureType stackClosure) STACK - let !stackPointerBox = stackPointer stackClosure + let !stackPointerBox = unsafeStackPointer stackClosure stackPointerClosure <- getBoxedClosureData stackPointerBox assertEqual (getClosureType stackPointerClosure) RET_SMALL - let !trecBox = trec tso + let !trecBox = unsafe_trec tso trecClosure <- getBoxedClosureData trecBox assertEqual (name trecClosure) "NO_TREC" - let !blockedExceptionsBox = blocked_exceptions tso + let !blockedExceptionsBox = unsafe_blocked_exceptions tso blockedExceptionsClosure <- getBoxedClosureData blockedExceptionsBox assertEqual (name blockedExceptionsClosure) "END_TSO_QUEUE" - let !bqBox = bq tso + let !bqBox = unsafe_bq tso bqClosure <- getBoxedClosureData bqBox assertEqual (name bqClosure) "END_TSO_QUEUE" createTSOClosure :: IO (GenClosure Box) createTSOClosure = do ptr <- c_create_tso - let wPtr = unpackWord# ptr - getClosureData ((unsafeCoerce# wPtr) :: FoolStgTSO) - -unpackWord# :: Word -> Word# -unpackWord# (W# w#) = w# - -assertEqual :: (Show a, Eq a) => a -> a -> IO () -assertEqual a b - | a /= b = error (show a ++ " /= " ++ show b) - | otherwise = return () + createClosure ptr getClosureType :: GenClosure b -> ClosureType getClosureType = tipe . info ===================================== libraries/ghci/GHCi/Message.hs ===================================== @@ -1,5 +1,6 @@ {-# LANGUAGE GADTs, DeriveGeneric, StandaloneDeriving, ScopedTypeVariables, - GeneralizedNewtypeDeriving, ExistentialQuantification, RecordWildCards #-} + GeneralizedNewtypeDeriving, ExistentialQuantification, RecordWildCards, + CPP #-} {-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-orphans #-} -- | @@ -29,7 +30,7 @@ import GHCi.TH.Binary () -- For Binary instances import GHCi.BreakArray import GHC.LanguageExtensions -import GHC.Exts.Heap +import qualified GHC.Exts.Heap as Heap import GHC.ForeignSrcLang import GHC.Fingerprint import Control.Concurrent @@ -110,7 +111,7 @@ data Message a where -> Int -- constr tag -> Int -- pointer tag -> ByteString -- constructor desccription - -> Message (RemotePtr StgInfoTable) + -> Message (RemotePtr Heap.StgInfoTable) -- | Evaluate a statement EvalStmt @@ -211,7 +212,7 @@ data Message a where -- type reconstruction. GetClosure :: HValueRef - -> Message (GenClosure HValueRef) + -> Message (Heap.GenClosure HValueRef) -- | Evaluate something. This is used to support :force in GHCi. Seq @@ -449,10 +450,20 @@ instance Binary (FunPtr a) where get = castPtrToFunPtr <$> get -- Binary instances to support the GetClosure message -instance Binary StgInfoTable -instance Binary ClosureType -instance Binary PrimType -instance Binary a => Binary (GenClosure a) +#if MIN_VERSION_ghc_heap(8,11,0) +instance Binary Heap.StgTSOProfInfo +instance Binary Heap.CostCentreStack +instance Binary Heap.CostCentre +instance Binary Heap.IndexTable +instance Binary Heap.WhatNext +instance Binary Heap.WhyBlocked +instance Binary Heap.TsoFlags +#endif + +instance Binary Heap.StgInfoTable +instance Binary Heap.ClosureType +instance Binary Heap.PrimType +instance Binary a => Binary (Heap.GenClosure a) data Msg = forall a . (Binary a, Show a) => Msg (Message a) ===================================== libraries/ghci/GHCi/Run.hs ===================================== @@ -32,7 +32,7 @@ import Data.Binary.Get import Data.ByteString (ByteString) import qualified Data.ByteString.Unsafe as B import GHC.Exts -import GHC.Exts.Heap +import qualified GHC.Exts.Heap as Heap import GHC.Stack import Foreign hiding (void) import Foreign.C @@ -93,8 +93,8 @@ run m = case m of toRemotePtr <$> mkConInfoTable tc ptrs nptrs tag ptrtag desc StartTH -> startTH GetClosure ref -> do - clos <- getClosureData =<< localRef ref - mapM (\(Box x) -> mkRemoteRef (HValue x)) clos + clos <- Heap.getClosureData =<< localRef ref + mapM (\(Heap.Box x) -> mkRemoteRef (HValue x)) clos Seq ref -> doSeq ref ResumeSeq ref -> resumeSeq ref _other -> error "GHCi.Run.run" ===================================== rts/RtsAPI.c ===================================== @@ -621,21 +621,21 @@ rts_unlock (Capability *cap) task = cap->running_task; ASSERT_FULL_CAPABILITY_INVARIANTS(cap,task); - // Now release the Capability. With the capability released, GC - // may happen. NB. does not try to put the current Task on the + // Now release the Capability. With the capability released, GC + // may happen. NB. does not try to put the current Task on the // worker queue. - // NB. keep cap->lock held while we call boundTaskExiting(). This + // NB. keep cap->lock held while we call exitMyTask(). This // is necessary during shutdown, where we want the invariant that // after shutdownCapability(), all the Tasks associated with the - // Capability have completed their shutdown too. Otherwise we - // could have boundTaskExiting()/workerTaskStop() running at some + // Capability have completed their shutdown too. Otherwise we + // could have exitMyTask()/workerTaskStop() running at some // random point in the future, which causes problems for // freeTaskManager(). ACQUIRE_LOCK(&cap->lock); releaseCapability_(cap,false); // Finally, we can release the Task to the free list. - boundTaskExiting(task); + exitMyTask(); RELEASE_LOCK(&cap->lock); if (task->incall == NULL) { @@ -794,7 +794,7 @@ void rts_done (void) void hs_try_putmvar (/* in */ int capability, /* in */ HsStablePtr mvar) { - Task *task = getTask(); + Task *task = getMyTask(); Capability *cap; Capability *task_old_cap USED_IF_THREADS; ===================================== rts/Schedule.c ===================================== @@ -2082,7 +2082,7 @@ forkProcess(HsStablePtr *entry RELEASE_LOCK(&capabilities[i]->lock); } - boundTaskExiting(task); + exitMyTask(); // just return the pid return pid; @@ -2762,7 +2762,7 @@ exitScheduler (bool wait_foreign USED_IF_THREADS) // debugBelch("n_failed_trygrab_idles = %d, n_idle_caps = %d\n", // n_failed_trygrab_idles, n_idle_caps); - boundTaskExiting(task); + exitMyTask(); } void @@ -2821,7 +2821,7 @@ performGC_(bool force_major) waitForCapability(&cap,task); scheduleDoGC(&cap,task,force_major,false); releaseCapability(cap); - boundTaskExiting(task); + exitMyTask(); } void ===================================== rts/Task.c ===================================== @@ -116,7 +116,7 @@ freeTaskManager (void) return tasksRunning; } -Task* getTask (void) +Task* getMyTask (void) { Task *task; @@ -304,7 +304,7 @@ newBoundTask (void) stg_exit(EXIT_FAILURE); } - task = getTask(); + task = getMyTask(); task->stopped = false; @@ -315,13 +315,12 @@ newBoundTask (void) } void -boundTaskExiting (Task *task) +exitMyTask (void) { + Task* task = myTask(); #if defined(THREADED_RTS) ASSERT(osThreadId() == task->id); #endif - ASSERT(myTask() == task); - endInCall(task); // Set task->stopped, but only if this is the last call (#4850). @@ -522,7 +521,7 @@ void rts_setInCallCapability ( int preferred_capability, int affinity USED_IF_THREADS) { - Task *task = getTask(); + Task *task = getMyTask(); task->preferred_capability = preferred_capability; #if defined(THREADED_RTS) @@ -539,7 +538,7 @@ void rts_pinThreadToNumaNode ( { #if defined(THREADED_RTS) if (RtsFlags.GcFlags.numa) { - Task *task = getTask(); + Task *task = getMyTask(); task->node = capNoToNumaNode(node); if (!DEBUG_IS_ON || !RtsFlags.DebugFlags.numa) { // faking NUMA setThreadNode(numa_map[task->node]); ===================================== rts/Task.h ===================================== @@ -150,7 +150,7 @@ typedef struct Task_ { bool worker; // == true if this is a worker Task bool stopped; // == true between newBoundTask and - // boundTaskExiting, or in a worker Task. + // exitMyTask, or in a worker Task. // So that we can detect when a finalizer illegally calls back into Haskell bool running_finalizers; ===================================== rts/sm/NonMoving.c ===================================== @@ -1215,7 +1215,7 @@ static void nonmovingMark_(MarkQueue *mark_queue, StgWeak **dead_weaks, StgTSO * #if defined(THREADED_RTS) finish: - boundTaskExiting(task); + exitMyTask(); // We are done... mark_thread = 0; View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d92c67f01bdd1da6f6f8ecebd5365aed3d62dab5...929c5c33f842a96a75fac7779730c920c139276c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d92c67f01bdd1da6f6f8ecebd5365aed3d62dab5...929c5c33f842a96a75fac7779730c920c139276c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 23 15:41:27 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sun, 23 Aug 2020 11:41:27 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 6 commits: mkUnique refactoring (#18362) Message-ID: <5f428e27386e5_80b1161a4848997415@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: e67ae884 by Aditya Gupta at 2020-08-22T03:29:00-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - 03cfcfd4 by Wander Hillen at 2020-08-22T03:29:36-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 3f501545 by Craig Ferguson at 2020-08-22T03:30:13-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 895d5c6b by Krzysztof Gogolewski at 2020-08-23T11:41:17-04:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - 8a77ec11 by Krzysztof Gogolewski at 2020-08-23T11:41:17-04:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - bcf959e3 by Sylvain Henry at 2020-08-23T11:41:20-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - 30 changed files: - .gitlab-ci.yml - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/CmmToAsm/Reg/Graph/Base.hs - compiler/GHC/CmmToAsm/Reg/Graph/SpillClean.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/DataCon.hs-boot - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/Exitify.hs - compiler/GHC/Core/Opt/Monad.hs - compiler/GHC/Core/TyCon.hs - compiler/GHC/Core/TyCon.hs-boot - compiler/GHC/CoreToByteCode.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Iface/Ext/Ast.hs - compiler/GHC/Iface/Syntax.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Platform/Reg.hs - compiler/GHC/Platform/Reg/Class.hs - compiler/GHC/Stg/Pipeline.hs - compiler/GHC/Tc/TyCl/Utils.hs - compiler/GHC/Tc/Utils/Monad.hs - compiler/GHC/Tc/Validity.hs - compiler/GHC/Types/FieldLabel.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/32c60ff475435d94f1a3fb3f089b738c897b724d...bcf959e3f25d948aa48dc26440932ebd8dfbfdf1 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/32c60ff475435d94f1a3fb3f089b738c897b724d...bcf959e3f25d948aa48dc26440932ebd8dfbfdf1 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 23 19:44:55 2020 From: gitlab at gitlab.haskell.org (Shayne Fletcher) Date: Sun, 23 Aug 2020 15:44:55 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/sf/test Message-ID: <5f42c7375a5b_80b1075951c902184d@gitlab.haskell.org.mail> Shayne Fletcher pushed new branch wip/sf/test at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/sf/test You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 23 19:45:26 2020 From: gitlab at gitlab.haskell.org (Shayne Fletcher) Date: Sun, 23 Aug 2020 15:45:26 -0400 Subject: [Git][ghc/ghc] Deleted branch wip/sf/test Message-ID: <5f42c75617391_80b3f848685789490220c7@gitlab.haskell.org.mail> Shayne Fletcher deleted branch wip/sf/test at Glasgow Haskell Compiler / GHC -- You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 23 19:57:37 2020 From: gitlab at gitlab.haskell.org (Shayne Fletcher) Date: Sun, 23 Aug 2020 15:57:37 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18599 Message-ID: <5f42ca31df789_80b1161a4849026261@gitlab.haskell.org.mail> Shayne Fletcher pushed new branch wip/T18599 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18599 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 23 21:00:26 2020 From: gitlab at gitlab.haskell.org (Shayne Fletcher) Date: Sun, 23 Aug 2020 17:00:26 -0400 Subject: [Git][ghc/ghc][wip/T18599] First steps towards T18599 Message-ID: <5f42d8ea16f7f_80b3f84a401c3dc9041776@gitlab.haskell.org.mail> Shayne Fletcher pushed to branch wip/T18599 at Glasgow Haskell Compiler / GHC Commits: 44010729 by Shayne Fletcher at 2020-08-23T16:59:14-04:00 First steps towards T18599 - - - - - 7 changed files: - compiler/GHC/Driver/Session.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Lexer.x - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/ThToHs.hs - libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs - + record-dot-syntax-tests/Test.hs Changes: ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -3727,6 +3727,7 @@ xFlagsDeps = [ flagSpec "Rank2Types" LangExt.RankNTypes, flagSpec "RankNTypes" LangExt.RankNTypes, flagSpec "RebindableSyntax" LangExt.RebindableSyntax, + flagSpec "RecordDotSyntax" LangExt.RecordDotSyntax, depFlagSpec' "RecordPuns" LangExt.RecordPuns (deprecatedForExtension "NamedFieldPuns"), flagSpec "RecordWildCards" LangExt.RecordWildCards, ===================================== compiler/GHC/Parser.y ===================================== @@ -39,6 +39,9 @@ module GHC.Parser ) where +import Debug.Trace +import Data.Proxy + -- base import Control.Monad ( unless, liftM, when, (<=<) ) import GHC.Exts @@ -68,7 +71,7 @@ import GHC.Prelude -- compiler/basicTypes import GHC.Types.Name.Reader -import GHC.Types.Name.Occurrence ( varName, dataName, tcClsName, tvName, startsWithUnderscore ) +import GHC.Types.Name.Occurrence ( varName, dataName, tcClsName, tvName, startsWithUnderscore, mkVarOcc, occNameString, occNameFS ) import GHC.Core.DataCon ( DataCon, dataConName ) import GHC.Types.SrcLoc import GHC.Unit.Module @@ -95,7 +98,7 @@ import GHC.Builtin.Types ( unitTyCon, unitDataCon, tupleTyCon, tupleDataCon, nil manyDataConTyCon) } -%expect 232 -- shift/reduce conflicts +%expect 234 -- shift/reduce conflicts {- Last updated: 08 June 2020 @@ -551,6 +554,8 @@ are the most common patterns, rewritten as regular expressions for clarity: '-<<' { L _ (ITLarrowtail _) } -- for arrow notation '>>-' { L _ (ITRarrowtail _) } -- for arrow notation '.' { L _ ITdot } + PREFIX_PROJ { L _ (ITproj True) } -- RecordDotSyntax + TIGHT_INFIX_PROJ { L _ (ITproj False) } -- RecordDotSyntax PREFIX_AT { L _ ITtypeApp } '{' { L _ ITocurly } -- special symbols @@ -2610,6 +2615,20 @@ fexp :: { ECP } fmap ecpFromExp $ ams (sLL $1 $> $ HsStatic noExtField $2) [mj AnnStatic $1] } + + -- See Note [Whitespace-sensitive operator parsing] in Lexer.x + | fexp TIGHT_INFIX_PROJ field + {% do { ; $1 <- runPV (unECP $1) + -- Suppose lhs is an application term e.g. 'f a' and + -- rhs is '.b'. Usually we want the parse 'f + -- (a.b)' rather than '(f a).b.'. However, if lhs is + -- a projection 'r.a' (say) then we want the parse + -- '(r.a).b'. + ; return . ecpFromExp $ case $1 of + L _ (HsApp _ f arg) | not $ isGet f -> f `mkApp` mkGet arg $3 + _ -> mkGet $1 $3 + }} + | aexp { $1 } aexp :: { ECP } @@ -2699,10 +2718,12 @@ aexp :: { ECP } aexp1 :: { ECP } : aexp1 '{' fbinds '}' { ECP $ + getBit RecordDotSyntaxBit >>= \ dot -> unECP $1 >>= \ $1 -> $3 >>= \ $3 -> - amms (mkHsRecordPV (comb2 $1 $>) (comb2 $2 $4) $1 (snd $3)) + amms (mkHsRecordPV dot (comb2 $1 $>) (comb2 $2 $4) $1 (snd $3)) (moc $2:mcc $4:(fst $3)) } + | aexp1 '{' pbinds '}' {% runPV (unECP $1) >>= \ $1 -> fmap ecpFromExp $ applyFieldUpdates $1 $3 } | aexp2 { $1 } aexp2 :: { ECP } @@ -2730,6 +2751,9 @@ aexp2 :: { ECP } amms (mkSumOrTuplePV (comb2 $1 $>) Boxed (snd $2)) ((mop $1:fst $2) ++ [mcp $3]) } + -- This case is only possible when 'RecordDotSyntax' is enabled. + | '(' projection ')' { ecpFromExp $2 } + | '(#' texp '#)' { ECP $ unECP $2 >>= \ $2 -> amms (mkSumOrTuplePV (comb2 $1 $>) Unboxed (Tuple [L (gl $2) (Just $2)])) @@ -2778,6 +2802,12 @@ aexp2 :: { ECP } Nothing (reverse $3)) [mu AnnOpenB $1,mu AnnCloseB $4] } +projection :: { LHsExpr GhcPs } +projection + -- See Note [Whitespace-sensitive operator parsing] in Lexer.x + : projection TIGHT_INFIX_PROJ field { mkProj (Just $1) $3 } + | PREFIX_PROJ field { mkProj Nothing $2 } + splice_exp :: { LHsExpr GhcPs } : splice_untyped { mapLoc (HsSpliceE noExtField) $1 } | splice_typed { mapLoc (HsSpliceE noExtField) $1 } @@ -3191,7 +3221,7 @@ qual :: { forall b. DisambECP b => PV (LStmt GhcPs (Located b)) } (mj AnnLet $1:(fst $ unLoc $2)) } ----------------------------------------------------------------------------- --- Record Field Update/Construction +-- Record construction (expressions & patterns), top-level updates. fbinds :: { forall b. DisambECP b => PV ([AddAnn],([LHsRecField GhcPs (Located b)], Maybe SrcSpan)) } : fbinds1 { $1 } @@ -3220,6 +3250,49 @@ fbind :: { forall b. DisambECP b => PV (LHsRecField GhcPs (Located b)) } -- In the punning case, use a place-holder -- The renamer fills in the final value +----------------------------------------------------------------------------- +-- Nested updates (strictly expressions; patterns do not participate in updates). + +pbinds :: { [LHsExpr GhcPs -> LHsExpr GhcPs] } + : pbinds1 { $1 } + +pbinds1 :: { [LHsExpr GhcPs -> LHsExpr GhcPs] } + : pbind ',' pbinds1 { $1 : $3 } + | pbind { [$1] } + +pbind :: { LHsExpr GhcPs -> LHsExpr GhcPs } + -- See Note [Whitespace-sensitive operator parsing] in Lexer.x + : field TIGHT_INFIX_PROJ fieldToUpdate '=' texp + {%do { ; let { top = $1 -- foo + ; fields = top : reverse $3 -- [foo, bar, baz, quux] + } + ; arg <- runPV (unECP $5) + ; return $ mkFieldUpdater fields arg + }} + -- See Note [Whitespace-sensitive operator parsing] in Lexer.x + | field TIGHT_INFIX_PROJ fieldToUpdate + {%do { ; recordPuns <- getBit RecordPunsBit + ; if not recordPuns + then do { + ; addFatalError noSrcSpan $ + text "For this to work, enable NamedFieldPuns." + } + else do { + ; let { ; top = $1 -- foo + ; fields = top : reverse $3 -- [foo, bar, baz, quux] + ; final = last fields -- quux + ; arg = mkVar $ unpackFS final + } + ; return $ mkFieldUpdater fields arg + } + }} + +fieldToUpdate :: { [FastString] } +fieldToUpdate + -- See Note [Whitespace-sensitive operator parsing] in Lexer.x + : fieldToUpdate TIGHT_INFIX_PROJ field { $3 : $1 } + | field { [$1] } + ----------------------------------------------------------------------------- -- Implicit Parameter Bindings @@ -3512,6 +3585,10 @@ qvar :: { Located RdrName } -- whether it's a qvar or a var can be postponed until -- *after* we see the close paren. +field :: { FastString } + : VARID { getVARID $1 } + | QVARID { snd $ getQVARID $1 } + qvarid :: { Located RdrName } : varid { $1 } | QVARID { sL1 $1 $! mkQual varName (getQVARID $1) } ===================================== compiler/GHC/Parser/Lexer.x ===================================== @@ -618,6 +618,19 @@ $tab { warnTab } -- | | ordinary operator or type operator, -- | | e.g. xs ~ 3, (~ x), Int ~ Bool -- ----------+---------------+------------------------------------------ +-- . | prefix | ITproj True +-- | | field projection, +-- | | e.g. .x +-- | tight infix | ITproj False +-- | | field projection, +-- | | e.g. r.x +-- | suffix | ITdot +-- | | function composition, +-- | | e.g. f. g +-- | loose infix | ITdot +-- | | function composition, +-- | | e.g. f . g +-- ----------+---------------+------------------------------------------ -- $ $$ | prefix | ITdollar, ITdollardollar -- | | untyped or typed Template Haskell splice, -- | | e.g. $(f x), $$(f x), $$"str" @@ -779,6 +792,7 @@ data Token | ITtypeApp -- Prefix (@) only, e.g. f @t | ITstar IsUnicodeSyntax | ITdot + | ITproj Bool -- RecordDotSyntax | ITbiglam -- GHC-extension symbols @@ -1585,6 +1599,9 @@ varsym_prefix = sym $ \exts s -> | s == fsLit "-" -- Only when LexicalNegation is on, otherwise we get ITminus and -- don't hit this code path. See Note [Minus tokens] -> return ITprefixminus + | RecordDotSyntaxBit `xtest` exts, s == fsLit "." + -> return (ITproj True) -- e.g. '(.x)' + | s == fsLit "." -> return ITdot | s == fsLit "!" -> return ITbang | s == fsLit "~" -> return ITtilde | otherwise -> return (ITvarsym s) @@ -1594,17 +1611,28 @@ varsym_suffix :: Action varsym_suffix = sym $ \_ s -> if | s == fsLit "@" -> failMsgP "Suffix occurrence of @. For an as-pattern, remove the leading whitespace." + | s == fsLit "." + -> return ITdot | otherwise -> return (ITvarsym s) -- See Note [Whitespace-sensitive operator parsing] varsym_tight_infix :: Action -varsym_tight_infix = sym $ \_ s -> - if | s == fsLit "@" -> return ITat +varsym_tight_infix = sym $ \exts s -> + if | s == fsLit "@" + -> return ITat + | RecordDotSyntaxBit `xtest` exts, s == fsLit "." + -> return (ITproj False) + | s == fsLit "." + -> return ITdot | otherwise -> return (ITvarsym s) -- See Note [Whitespace-sensitive operator parsing] varsym_loose_infix :: Action -varsym_loose_infix = sym (\_ s -> return $ ITvarsym s) +varsym_loose_infix = sym $ \_ s -> + if | s == fsLit "." + -> return ITdot + | otherwise + -> return $ ITvarsym s consym :: Action consym = sym (\_exts s -> return $ ITconsym s) @@ -1612,8 +1640,13 @@ consym = sym (\_exts s -> return $ ITconsym s) sym :: (ExtsBitmap -> FastString -> P Token) -> Action sym con span buf len = case lookupUFM reservedSymsFM fs of - Just (keyword, NormalSyntax, 0) -> - return $ L span keyword + Just (keyword, NormalSyntax, 0) -> do + exts <- getExts + if fs == fsLit "." && + exts .&. (xbit RecordDotSyntaxBit) /= 0 && + xtest RecordDotSyntaxBit exts + then L span <$!> con exts fs -- Process by varsym_*. + else return $ L span keyword Just (keyword, NormalSyntax, i) -> do exts <- getExts if exts .&. i /= 0 @@ -2619,6 +2652,8 @@ data ExtBits | ImportQualifiedPostBit | LinearTypesBit | NoLexicalNegationBit -- See Note [Why not LexicalNegationBit] + | RecordPunsBit + | RecordDotSyntaxBit -- Flags that are updated once parsing starts | InRulePragBit @@ -2709,6 +2744,8 @@ mkParserFlags' warningFlags extensionFlags homeUnitId .|. ImportQualifiedPostBit `xoptBit` LangExt.ImportQualifiedPost .|. LinearTypesBit `xoptBit` LangExt.LinearTypes .|. NoLexicalNegationBit `xoptNotBit` LangExt.LexicalNegation -- See Note [Why not LexicalNegationBit] + .|. RecordPunsBit `xoptBit` LangExt.RecordPuns + .|. RecordDotSyntaxBit `xoptBit` LangExt.RecordDotSyntax optBits = HaddockBit `setBitIf` isHaddock .|. RawTokenStreamBit `setBitIf` rawTokStream ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -19,6 +19,7 @@ {-# OPTIONS_GHC -Wno-incomplete-record-updates #-} module GHC.Parser.PostProcess ( + mkApp, mkGet, mkVar, mkFieldUpdater, mkProj, isGet, applyFieldUpdates, -- RecordDot mkHsOpApp, mkHsIntegral, mkHsFractional, mkHsIsString, mkHsDo, mkSpliceDecl, @@ -31,7 +32,7 @@ module GHC.Parser.PostProcess ( mkFamDecl, mkLHsSigType, mkInlinePragma, mkPatSynMatchGroup, - mkRecConstrOrUpdate, -- HsExp -> [HsFieldUpdate] -> P HsExp + mkRecConstrOrUpdate, mkTyClD, mkInstD, mkRdrRecordCon, mkRdrRecordUpd, setRdrNameSpace, @@ -1441,6 +1442,7 @@ class b ~ (Body b) GhcPs => DisambECP b where mkHsSplicePV :: Located (HsSplice GhcPs) -> PV (Located b) -- | Disambiguate "f { a = b, ... }" syntax (record construction and record updates) mkHsRecordPV :: + Bool -> -- Is RecordDotSyntax in effect? SrcSpan -> SrcSpan -> Located b -> @@ -1463,7 +1465,6 @@ class b ~ (Body b) GhcPs => DisambECP b where -- | Validate infixexp LHS to reject unwanted {-# SCC ... #-} pragmas rejectPragmaPV :: Located b -> PV () - {- Note [UndecidableSuperClasses for associated types] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (This Note is about the code in GHC, not about the user code that we are parsing) @@ -1545,7 +1546,7 @@ instance DisambECP (HsCmd GhcPs) where mkHsExplicitListPV l xs = cmdFail l $ brackets (fsep (punctuate comma (map ppr xs))) mkHsSplicePV (L l sp) = cmdFail l (ppr sp) - mkHsRecordPV l _ a (fbinds, ddLoc) = cmdFail l $ + mkHsRecordPV _ l _ a (fbinds, ddLoc) = cmdFail l $ ppr a <+> ppr (mk_rec_fields fbinds ddLoc) mkHsNegAppPV l a = cmdFail l (text "-" <> ppr a) mkHsSectionR_PV l op c = cmdFail l $ @@ -1604,8 +1605,8 @@ instance DisambECP (HsExpr GhcPs) where mkHsTySigPV l a sig = return $ L l (ExprWithTySig noExtField a (mkLHsSigWcType sig)) mkHsExplicitListPV l xs = return $ L l (ExplicitList noExtField Nothing xs) mkHsSplicePV sp = return $ mapLoc (HsSpliceE noExtField) sp - mkHsRecordPV l lrec a (fbinds, ddLoc) = do - r <- mkRecConstrOrUpdate a lrec (fbinds, ddLoc) + mkHsRecordPV dot l lrec a (fbinds, ddLoc) = do + r <- mkRecConstrOrUpdate dot a lrec (fbinds, ddLoc) checkRecordSyntax (L l r) mkHsNegAppPV l a = return $ L l (NegApp noExtField a noSyntaxExpr) mkHsSectionR_PV l op e = return $ L l (SectionR noExtField op e) @@ -1692,7 +1693,7 @@ instance DisambECP (PatBuilder GhcPs) where ps <- traverse checkLPat xs return (L l (PatBuilderPat (ListPat noExtField ps))) mkHsSplicePV (L l sp) = return $ L l (PatBuilderPat (SplicePat noExtField sp)) - mkHsRecordPV l _ a (fbinds, ddLoc) = do + mkHsRecordPV _ l _ a (fbinds, ddLoc) = do r <- mkPatRec a (mk_rec_fields fbinds ddLoc) checkRecordSyntax (L l r) mkHsNegAppPV l (L lp p) = do @@ -2331,23 +2332,26 @@ checkPrecP (L l (_,i)) (L _ ol) , getRdrName unrestrictedFunTyCon ] mkRecConstrOrUpdate - :: LHsExpr GhcPs + :: Bool + -> LHsExpr GhcPs -> SrcSpan -> ([LHsRecField GhcPs (LHsExpr GhcPs)], Maybe SrcSpan) -> PV (HsExpr GhcPs) -mkRecConstrOrUpdate (L l (HsVar _ (L _ c))) _ (fs,dd) +mkRecConstrOrUpdate _ (L l (HsVar _ (L _ c))) _ (fs,dd) | isRdrDataCon c = return (mkRdrRecordCon (L l c) (mk_rec_fields fs dd)) -mkRecConstrOrUpdate exp _ (fs,dd) +mkRecConstrOrUpdate dot exp _ (fs,dd) | Just dd_loc <- dd = addFatalError dd_loc (text "You cannot use `..' in a record update") - | otherwise = return (mkRdrRecordUpd exp (map (fmap mk_rec_upd_field) fs)) + | otherwise = return (mkRdrRecordUpd dot exp (map (fmap mk_rec_upd_field) fs)) -mkRdrRecordUpd :: LHsExpr GhcPs -> [LHsRecUpdField GhcPs] -> HsExpr GhcPs -mkRdrRecordUpd exp flds - = RecordUpd { rupd_ext = noExtField - , rupd_expr = exp - , rupd_flds = flds } +mkRdrRecordUpd :: Bool -> LHsExpr GhcPs -> [LHsRecUpdField GhcPs] -> HsExpr GhcPs +mkRdrRecordUpd dot exp flds + -- If RecordDotSyntax is in effect produce a set_field expression. + | dot = unLoc $ foldl' mkSetField exp flds + | otherwise = RecordUpd { rupd_ext = noExtField + , rupd_expr = exp + , rupd_flds = flds } mkRdrRecordCon :: Located RdrName -> HsRecordBinds GhcPs -> HsExpr GhcPs mkRdrRecordCon con flds @@ -2885,3 +2889,105 @@ starSym False = "*" forallSym :: Bool -> String forallSym True = "∀" forallSym False = "forall" + +----------------------------------------- +-- Bits and pieces for RecordDotSyntax. + +mkParen :: LHsExpr GhcPs -> LHsExpr GhcPs +mkParen = noLoc . HsPar noExtField + +mkVar :: String -> LHsExpr GhcPs +mkVar = noLoc . HsVar noExtField . noLoc . mkRdrUnqual . mkVarOcc + +mkApp :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs +mkApp x = noLoc . HsApp noExtField x + +mkOpApp :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs +mkOpApp x op = noLoc . OpApp noExtField x op + +mkAppType :: LHsExpr GhcPs -> GenLocated SrcSpan (HsType (NoGhcTc GhcPs)) -> LHsExpr GhcPs +mkAppType expr = noLoc . HsAppType noExtField expr . HsWC noExtField + +mkSelector :: FastString -> LHsType GhcPs +mkSelector = noLoc . HsTyLit noExtField . HsStrTy NoSourceText + +get_field, set_field :: LHsExpr GhcPs +get_field = mkVar "getField" +set_field = mkVar "setField" + +-- Test if the expression is a 'getField @"..."' expression. +isGet :: LHsExpr GhcPs -> Bool +isGet (L _ (HsAppType _ (L _ (HsVar _ (L _ name))) _)) = occNameString (rdrNameOcc name) == "getField" +isGet _ = False + +zPat :: LPat GhcPs +zVar, circ :: LHsExpr GhcPs +zPat = noLoc $ VarPat noExtField (noLoc $ mkRdrUnqual (mkVarOcc "z")) +zVar = noLoc $ HsVar noExtField (noLoc $ mkRdrUnqual (mkVarOcc "z")) +circ = noLoc $ HsVar noExtField (noLoc $ mkRdrUnqual (mkVarOcc ".")) + +-- mkProj rhs fIELD calculates a projection. +-- e.g. .x = mkProj Nothing x = \z -> z.x = \z -> (getField @fIELD x) +-- .x.y = mkProj Just(.x) y = (.y) . (.x) = (\z -> z.y) . (\z -> z.x) +mkProj :: Maybe (LHsExpr GhcPs) -> FastString -> LHsExpr GhcPs +mkProj rhs fIELD = + let body = mkGet zVar fIELD + grhs = noLoc $ GRHS noExtField [] body + ghrss = GRHSs noExtField [grhs] (noLoc (EmptyLocalBinds noExtField)) + m = noLoc $ Match {m_ext=noExtField, m_ctxt=LambdaExpr, m_pats=[zPat], m_grhss=ghrss} + lhs = mkParen (noLoc $ HsLam noExtField MG {mg_ext=noExtField, mg_alts=noLoc [m], mg_origin=Generated}) in + maybe lhs (mkParen . mkOpApp lhs circ) rhs + +-- mkGet arg fIELD calcuates a get_field @fIELD arg expression. +-- e.g. z.x = mkGet z x = get_field @x z +mkGet :: LHsExpr GhcPs -> FastString -> LHsExpr GhcPs +mkGet arg fIELD = head $ mkGet' [arg] fIELD +mkGet' :: [LHsExpr GhcPs] -> FastString -> [LHsExpr GhcPs] +mkGet' l@(r : _) fIELD = get_field `mkAppType` mkSelector fIELD `mkApp` mkParen r : l +mkGet' [] _ = panic "mkGet' : The impossible has happened!" + +-- mkSet a fIELD b calculates a set_field @fIELD expression. +-- e.g mkSet a fIELD b = set_field @"fIELD" a b (read as "set field 'fIELD' on a to b"). +mkSet :: LHsExpr GhcPs -> FastString -> LHsExpr GhcPs -> LHsExpr GhcPs +mkSet a fIELD b = set_field `mkAppType` mkSelector fIELD `mkApp` a `mkApp` b + +-- mkFieldUpdater calculates functions representing dot notation record updates. +mkFieldUpdater :: [FastString] -> LHsExpr GhcPs -> (LHsExpr GhcPs -> LHsExpr GhcPs) +mkFieldUpdater -- e.g {foo.bar.baz.quux = 43} + fIELDS -- [foo, bar, baz, quux] + arg -- This is 'texp' (43 in the example). + = let { + ; final = last fIELDS -- quux + ; fields = init fIELDS -- [foo, bar, baz] + ; getters = \a -> foldl' mkGet' [a] fields -- Ordered from deep to shallow. + -- [getField@"baz"(getField@"bar"(getField@"foo" a), getField@"bar"(getField@"foo" a), getField@"foo" a, a] + ; zips = \a -> (final, head (getters a)) : zip (reverse fields) (tail (getters a)) -- Ordered from deep to shallow. + -- [("quux", getField@"baz"(getField@"bar"(getField@"foo" a)), ("baz", getField@"bar"(getField@"foo" a)), ("bar", getField@"foo" a), ("foo", a)] + } + in \a -> foldl' mkSet' arg (zips a) + -- setField@"foo" (a) (setField@"bar" (getField @"foo" (a))(setField@"baz" (getField @"bar" (getField @"foo" (a)))(setField@"quux" (getField @"baz" (getField @"bar" (getField @"foo" (a))))(quux)))) + where + mkSet' :: LHsExpr GhcPs -> (FastString, LHsExpr GhcPs) -> LHsExpr GhcPs + mkSet' acc (fIELD, g) = mkSet (mkParen g) fIELD (mkParen acc) + +-- Called from mkRdrRecordUpd. +mkSetField :: LHsExpr GhcPs -> LHsRecUpdField GhcPs -> LHsExpr GhcPs +mkSetField e (L _ (HsRecField occ arg _)) = mkSet e (fsLit $ field occ) (val arg) + where + val :: LHsExpr GhcPs -> LHsExpr GhcPs + val arg = if isPun arg then mkVar $ field occ else arg + + isPun :: LHsExpr GhcPs -> Bool + isPun = \case + L _ (HsVar _ (L _ p)) -> p == pun_RDR + _ -> False + + field :: Located (AmbiguousFieldOcc GhcPs) -> String + field = \case + L _ (Ambiguous _ (L _ lbl)) -> occNameString . rdrNameOcc $ lbl + L _ (Unambiguous _ (L _ lbl)) -> occNameString . rdrNameOcc $ lbl + _ -> "" -- Extension ctor. + +applyFieldUpdates :: LHsExpr GhcPs -> [LHsExpr GhcPs -> LHsExpr GhcPs] -> P (LHsExpr GhcPs) +applyFieldUpdates a updates = return $ foldl' apply a updates + where apply r update = update r ===================================== compiler/GHC/ThToHs.hs ===================================== @@ -1009,7 +1009,7 @@ cvtl e = wrapL (cvt e) ; flds' <- mapM (cvtFld (mkAmbiguousFieldOcc . noLoc)) flds - ; return $ mkRdrRecordUpd e' flds' } + ; return $ mkRdrRecordUpd False e' flds' } cvt (StaticE e) = fmap (HsStatic noExtField) $ cvtl e cvt (UnboundVarE s) = do -- Use of 'vcName' here instead of 'vName' is -- important, because UnboundVarE may contain ===================================== libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs ===================================== @@ -147,6 +147,7 @@ data Extension | CUSKs | StandaloneKindSignatures | LexicalNegation + | RecordDotSyntax deriving (Eq, Enum, Show, Generic, Bounded) -- 'Ord' and 'Bounded' are provided for GHC API users (see discussions -- in https://gitlab.haskell.org/ghc/ghc/merge_requests/2707 and ===================================== record-dot-syntax-tests/Test.hs ===================================== @@ -0,0 +1,116 @@ +{-# LANGUAGE AllowAmbiguousTypes, FunctionalDependencies, ScopedTypeVariables, PolyKinds, TypeApplications, DataKinds #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE RecordDotSyntax #-} + +-- Choice (C2a). + +import Data.Function -- for & + +class HasField x r a | x r -> a where + hasField :: r -> (a -> r, a) + +getField :: forall x r a . HasField x r a => r -> a +getField = snd . hasField @x -- Note: a.x = is getField @"x" a. + +setField :: forall x r a . HasField x r a => r -> a -> r +setField = fst . hasField @x -- Note : a{x = b} is setField @"x" a b. + +-- 'Foo' has 'foo' field of type 'Bar' +data Foo = Foo {foo :: Bar} deriving (Show, Eq) +instance HasField "foo" Foo Bar where + hasField r = (\x -> case r of Foo{..} -> Foo {foo = x, ..}, foo r) + +-- 'Bar' has a 'bar' field of type 'Baz' +data Bar = Bar {bar :: Baz} deriving (Show, Eq) +instance HasField "bar" Bar Baz where + hasField r = (\x -> case r of Bar{..} -> Bar {bar = x, ..}, bar r) + +-- 'Baz' has a 'baz' field of type 'Quux' +data Baz = Baz {baz :: Quux} deriving (Show, Eq) +instance HasField "baz" Baz Quux where + hasField r = (\x -> case r of Baz{..} -> Baz {baz = x, ..}, baz r) + +-- 'Quux' has a 'quux' field of type 'Int' +data Quux = Quux {quux :: Int} deriving (Show, Eq) +instance HasField "quux" Quux Int where + hasField r = (\x -> case r of Quux{..} -> Quux {quux = x, ..}, quux r) + +-- 'Corge' has a '&&&' field of type 'Int' +data Corge = Corge {(&&&) :: Int} deriving (Show, Eq) +instance HasField "&&&" Corge Int where + hasField r = (\x -> case r of Corge{..} -> Corge {(&&&) = x, ..}, (&&&) r) +-- Note : Dot notation is not available for fields with operator +-- names. + +-- 'Grault' has two fields 'f' and 'g' of type 'Foo'. +data Grault = Grault {f :: Foo, g :: Foo} deriving (Show, Eq) +instance HasField "f" Grault Foo where + hasField r = (\x -> case r of Grault{..} -> Grault {f = x, ..}, f r) +instance HasField "g" Grault Foo where + hasField r = (\x -> case r of Grault{..} -> Grault {g = x, ..}, g r) + +main = do + let a = Foo {foo = Bar{bar = Baz {baz = Quux {quux = 42}}}} + let b = Corge{(&&&) = 12}; + let c = Grault { + f = Foo {foo = Bar{bar = Baz {baz = Quux {quux = 1}}}} + , g = Foo {foo = Bar{bar = Baz {baz = Quux {quux = 1}}}} + } + + -- A "selector" is an expression like '(.a)' or '(.a.b)'. + putStrLn "-- selectors:" + print $ (.foo) a -- Bar {bar = Baz {baz = Quux {quux = 42}}} + print $ (.foo.bar) a -- Baz {baz = Quux {quux = 42}} + print $ (.foo.bar.baz) a -- Quux {quux = 42} + print $ (.foo.bar.baz.quux) a -- 42 + print $ ((&&&) b) -- 12 + -- print $ (b.(&&&)) -- illegal : parse error on input ‘(’ + print $ getField @"&&&" b -- 12 + + -- A "selection" is an expression like 'r.a' or '(f r).a.b'. + putStrLn "-- selections:" + print $ a.foo.bar.baz.quux -- 42 + print $ a.foo.bar.baz -- Quux {quux = 42} + print $ a.foo.bar -- Baz {baz = Quux {quux = 42}} + print $ a.foo -- Bar {bar = Baz {baz = Quux {quux = 42}}} + print $ (const "hello") a.foo -- f r.x means f (r.x) + -- print $ f a .foo -- f r .x is illegal + print $ (const "hello") (id a).foo -- f (g r).x means f ((g r).x) + -- print $ f (g a) .foo -- f (g r) .x is illegal + print $ a.foo + & (.bar.baz.quux) -- 42 + print $ (a.foo + ).bar.baz.quux -- 42 + print $ (+) a.foo.bar.baz.quux 1 -- 43 + print $ (+) (id a).foo.bar.baz.quux 1 -- 43 + print $ (+) ((id a).foo.bar & (.baz.quux)) 1 -- 43 + + -- An "update" is an expression like 'r{a.b = 12}'. + putStrLn "-- updates:" + print $ (a.foo.bar.baz) {quux = 2} -- Quux {quux = 2} + print $ (\b -> b{bar=Baz{baz=Quux{quux=1}}}) a.foo -- Bar {bar = Baz {baz = Quux {quux = 1}}} + let bar = Bar {bar = Baz {baz = Quux {quux = 44}}} + print $ a{foo.bar = Baz {baz = Quux {quux = 44}}} -- Foo {foo = Bar {bar = Baz {baz = Quux {quux = 44}}}} + print $ a{foo.bar.baz = Quux {quux = 45}} -- Foo {foo = Bar {bar = Baz {baz = Quux {quux = 45}}}} + print $ a{foo.bar.baz.quux = 46} -- Foo {foo = Bar {bar = Baz {baz = Quux {quux = 46}}}} + print $ c{f.foo.bar.baz.quux = 3, g.foo.bar.baz.quux = 4} -- Grault {f = Foo {foo = Bar {bar = Baz {baz = Quux {quux = 3}}}}, g = Foo {foo = Bar {bar = Baz {baz = Quux {quux = 4}}}}} + + -- A "punned update" is an expression like 'r{a.b}' (where it is + -- understood that 'b' is a variable binding in the environment of + -- the field update - enabled only when the extension + -- 'NamedFieldPuns' is in effect). + putStrLn "-- punned updates:" + let quux = 102; baz = Quux {quux}; bar = Baz {baz}; foo = Bar {bar} -- Foo {foo = Bar {bar = Baz {baz = Quux {quux = 102}}}} + print $ a{foo.bar.baz.quux} -- Foo {foo = Bar {bar = Baz {baz = Quux {quux = 102}}}} + print $ a{foo.bar.baz} -- Foo {foo = Bar {bar = Baz {baz = Quux {quux = 102}}}} + print $ a{foo.bar} -- Foo {foo = Bar {bar = Baz {baz = Quux {quux = 102}}}} + print $ a{foo} -- Foo {foo = Bar {bar = Baz {baz = Quux {quux = 102}}}} + print $ a -- Foo {foo = Bar {bar = Baz {baz = Quux {quux = 42}}}} + print $ c{f.foo, g.foo.bar.baz.quux = 4} -- Mix punned and explicit; 102, 4 + f <- pure a + g <- pure a + print $ c{f} -- 42, 1 + print $ c{f, g} -- 42, 42 + -- print $ c{f, g.foo.bar.baz.quux = 4} -- Can't mix top-level and nested updates (limitation of this prototype). + print $ c{f}{g.foo.bar.baz.quux = 4} -- Workaround; 42, 4 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4401072933a2098c67a4dd96960ea813213d58bf -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4401072933a2098c67a4dd96960ea813213d58bf You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 23 21:11:52 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Sun, 23 Aug 2020 17:11:52 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: Do not print synonyms in :i (->), :i Type (#18594) Message-ID: <5f42db985cc98_80b3f84693c1eb490481f8@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 8b865092 by Krzysztof Gogolewski at 2020-08-23T14:12:53+02:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - d8f61182 by Krzysztof Gogolewski at 2020-08-23T14:12:56+02:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - d7d36d3c by Krzysztof Gogolewski at 2020-08-23T17:11:39-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - eecaa756 by Sylvain Henry at 2020-08-23T17:11:43-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - 14 changed files: - compiler/GHC/Core/Opt/ConstantFold.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Iface/Syntax.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Utils/Outputable.hs - testsuite/tests/ghci/T18060/T18060.stdout - testsuite/tests/ghci/scripts/T8535.stdout - testsuite/tests/ghci/scripts/ghci020.stdout - testsuite/tests/ghci/should_run/T10145.stdout - + testsuite/tests/ghci/should_run/T18594.script - + testsuite/tests/ghci/should_run/T18594.stdout - testsuite/tests/ghci/should_run/all.T - + testsuite/tests/simplCore/should_compile/T18589.hs - testsuite/tests/simplCore/should_compile/all.T Changes: ===================================== compiler/GHC/Core/Opt/ConstantFold.hs ===================================== @@ -143,11 +143,11 @@ primOpRules nm = \case , inversePrimOp NotIOp ] IntNegOp -> mkPrimOpRule nm 1 [ unaryLit negOp , inversePrimOp IntNegOp ] - ISllOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftL) + ISllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const Bits.shiftL) , rightIdentityPlatform zeroi ] - ISraOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftR) + ISraOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const Bits.shiftR) , rightIdentityPlatform zeroi ] - ISrlOp -> mkPrimOpRule nm 2 [ shiftRule shiftRightLogical + ISrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt shiftRightLogical , rightIdentityPlatform zeroi ] -- Word operations @@ -189,8 +189,8 @@ primOpRules nm = \case , equalArgs >> retLit zerow ] NotOp -> mkPrimOpRule nm 1 [ unaryLit complementOp , inversePrimOp NotOp ] - SllOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftL) ] - SrlOp -> mkPrimOpRule nm 2 [ shiftRule shiftRightLogical ] + SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord (const Bits.shiftL) ] + SrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord shiftRightLogical ] -- coercions Word2IntOp -> mkPrimOpRule nm 1 [ liftLitPlatform word2IntLit @@ -477,12 +477,14 @@ wordOpC2 op env (LitNumber LitNumWord w1) (LitNumber LitNumWord w2) = wordCResult (roPlatform env) (fromInteger w1 `op` fromInteger w2) wordOpC2 _ _ _ _ = Nothing -shiftRule :: (Platform -> Integer -> Int -> Integer) -> RuleM CoreExpr +shiftRule :: LitNumType -- Type of the result, either LitNumInt or LitNumWord + -> (Platform -> Integer -> Int -> Integer) + -> RuleM CoreExpr -- Shifts take an Int; hence third arg of op is Int -- Used for shift primops --- ISllOp, ISraOp, ISrlOp :: Word# -> Int# -> Word# +-- ISllOp, ISraOp, ISrlOp :: Int# -> Int# -> Int# -- SllOp, SrlOp :: Word# -> Int# -> Word# -shiftRule shift_op +shiftRule lit_num_ty shift_op = do { platform <- getPlatform ; [e1, Lit (LitNumber LitNumInt shift_len)] <- getArgs ; case e1 of @@ -490,7 +492,9 @@ shiftRule shift_op -> return e1 -- See Note [Guarding against silly shifts] | shift_len < 0 || shift_len > toInteger (platformWordSizeInBits platform) - -> return $ Lit $ mkLitNumberWrap platform LitNumInt 0 + -> return $ Lit $ mkLitNumberWrap platform lit_num_ty 0 + -- Be sure to use lit_num_ty here, so we get a correctly typed zero + -- of type Int# or Word# resp. See #18589 -- Do the shift at type Integer, but shift length is Int Lit (LitNumber nt x) ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -5079,6 +5079,7 @@ initSDocContext dflags style = SDC , sdocStarIsType = xopt LangExt.StarIsType dflags , sdocImpredicativeTypes = xopt LangExt.ImpredicativeTypes dflags , sdocLinearTypes = xopt LangExt.LinearTypes dflags + , sdocPrintTypeAbbreviations = True , sdocDynFlags = dflags } ===================================== compiler/GHC/Iface/Syntax.hs ===================================== @@ -45,6 +45,8 @@ module GHC.Iface.Syntax ( import GHC.Prelude +import GHC.Builtin.Names ( unrestrictedFunTyConKey, liftedTypeKindTyConKey ) +import GHC.Types.Unique ( hasKey ) import GHC.Iface.Type import GHC.Iface.Recomp.Binary import GHC.Core( IsOrphan, isOrphan ) @@ -947,13 +949,19 @@ pprIfaceDecl ss (IfaceSynonym { ifName = tc , ifResKind = res_kind}) = vcat [ pprStandaloneKindSig name_doc (mkIfaceTyConKind binders res_kind) , hang (text "type" <+> pprIfaceDeclHead suppress_bndr_sig [] ss tc binders <+> equals) - 2 (sep [ pprIfaceForAll tvs, pprIfaceContextArr theta, ppr tau + 2 (sep [ pprIfaceForAll tvs, pprIfaceContextArr theta, ppr_tau , ppUnless (isIfaceLiftedTypeKind res_kind) (dcolon <+> ppr res_kind) ]) ] where (tvs, theta, tau) = splitIfaceSigmaTy mono_ty name_doc = pprPrefixIfDeclBndr (ss_how_much ss) (occName tc) + -- See Note [Printing type abbreviations] in GHC.Iface.Type + ppr_tau | tc `hasKey` liftedTypeKindTyConKey || + tc `hasKey` unrestrictedFunTyConKey + = updSDocContext (\ctx -> ctx { sdocPrintTypeAbbreviations = False }) $ ppr tau + | otherwise = ppr tau + -- See Note [Suppressing binder signatures] in GHC.Iface.Type suppress_bndr_sig = SuppressBndrSig True ===================================== compiler/GHC/Iface/Type.hs ===================================== @@ -783,6 +783,22 @@ Here we'd like to omit the kind annotation: type F :: Symbol -> Type type F s = blah + +Note [Printing type abbreviations] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Normally, we pretty-print `TYPE 'LiftedRep` as `Type` (or `*`) and +`FUN 'Many` as `(->)`. +This way, error messages don't refer to levity polymorphism or linearity +if it is not necessary. + +However, when printing the definition of Type or (->) with :info, +this would give confusing output: `type (->) = (->)` (#18594). +Solution: detect when we are in :info and disable displaying the synonym +with the SDoc option sdocPrintTypeAbbreviations. + +If there will be a need, in the future we could expose it as a flag +-fprint-type-abbreviations or even two separate flags controlling +TYPE 'LiftedRep and FUN 'Many. -} -- | Do we want to suppress kind annotations on binders? @@ -1364,56 +1380,55 @@ pprIfaceTypeApp prec tc args = pprTyTcApp prec tc args pprTyTcApp :: PprPrec -> IfaceTyCon -> IfaceAppArgs -> SDoc pprTyTcApp ctxt_prec tc tys = sdocOption sdocPrintExplicitKinds $ \print_kinds -> + sdocOption sdocPrintTypeAbbreviations $ \print_type_abbreviations -> getPprDebug $ \debug -> - pprTyTcApp' ctxt_prec tc tys (PrintExplicitKinds print_kinds) debug - -pprTyTcApp' :: PprPrec -> IfaceTyCon -> IfaceAppArgs - -> PrintExplicitKinds -> Bool -> SDoc -pprTyTcApp' ctxt_prec tc tys printExplicitKinds debug - | ifaceTyConName tc `hasKey` ipClassKey - , IA_Arg (IfaceLitTy (IfaceStrTyLit n)) - Required (IA_Arg ty Required IA_Nil) <- tys - = maybeParen ctxt_prec funPrec - $ char '?' <> ftext n <> text "::" <> ppr_ty topPrec ty - - | IfaceTupleTyCon arity sort <- ifaceTyConSort info - , not debug - , arity == ifaceVisAppArgsLength tys - = pprTuple ctxt_prec sort (ifaceTyConIsPromoted info) tys - - | IfaceSumTyCon arity <- ifaceTyConSort info - = pprSum arity (ifaceTyConIsPromoted info) tys - - | tc `ifaceTyConHasKey` consDataConKey - , PrintExplicitKinds False <- printExplicitKinds - , IA_Arg _ argf (IA_Arg ty1 Required (IA_Arg ty2 Required IA_Nil)) <- tys - , isInvisibleArgFlag argf - = pprIfaceTyList ctxt_prec ty1 ty2 - - | tc `ifaceTyConHasKey` tYPETyConKey - , IA_Arg (IfaceTyConApp rep IA_Nil) Required IA_Nil <- tys - , rep `ifaceTyConHasKey` liftedRepDataConKey - = ppr_kind_type ctxt_prec - | tc `ifaceTyConHasKey` funTyConKey - , IA_Arg (IfaceTyConApp rep IA_Nil) Required args <- tys - , rep `ifaceTyConHasKey` manyDataConKey - = pprIfacePrefixApp ctxt_prec (parens arrow) (map (ppr_ty appPrec) (appArgsIfaceTypes $ stripInvisArgs printExplicitKinds args)) - - | otherwise - = getPprDebug $ \dbg -> - if | not dbg && tc `ifaceTyConHasKey` errorMessageTypeErrorFamKey + if | ifaceTyConName tc `hasKey` ipClassKey + , IA_Arg (IfaceLitTy (IfaceStrTyLit n)) + Required (IA_Arg ty Required IA_Nil) <- tys + -> maybeParen ctxt_prec funPrec + $ char '?' <> ftext n <> text "::" <> ppr_ty topPrec ty + + | IfaceTupleTyCon arity sort <- ifaceTyConSort info + , not debug + , arity == ifaceVisAppArgsLength tys + -> pprTuple ctxt_prec sort (ifaceTyConIsPromoted info) tys + + | IfaceSumTyCon arity <- ifaceTyConSort info + -> pprSum arity (ifaceTyConIsPromoted info) tys + + | tc `ifaceTyConHasKey` consDataConKey + , False <- print_kinds + , IA_Arg _ argf (IA_Arg ty1 Required (IA_Arg ty2 Required IA_Nil)) <- tys + , isInvisibleArgFlag argf + -> pprIfaceTyList ctxt_prec ty1 ty2 + + | tc `ifaceTyConHasKey` tYPETyConKey + , IA_Arg (IfaceTyConApp rep IA_Nil) Required IA_Nil <- tys + , rep `ifaceTyConHasKey` liftedRepDataConKey + , print_type_abbreviations -- See Note [Printing type abbreviations] + -> ppr_kind_type ctxt_prec + + | tc `ifaceTyConHasKey` funTyConKey + , IA_Arg (IfaceTyConApp rep IA_Nil) Required args <- tys + , rep `ifaceTyConHasKey` manyDataConKey + , print_type_abbreviations -- See Note [Printing type abbreviations] + -> pprIfacePrefixApp ctxt_prec (parens arrow) (map (ppr_ty appPrec) $ + appArgsIfaceTypes $ stripInvisArgs (PrintExplicitKinds print_kinds) args) + + | tc `ifaceTyConHasKey` errorMessageTypeErrorFamKey + , not debug -- Suppress detail unless you _really_ want to see - -> text "(TypeError ...)" + -> text "(TypeError ...)" | Just doc <- ppr_equality ctxt_prec tc (appArgsIfaceTypes tys) - -> doc + -> doc | otherwise - -> ppr_iface_tc_app ppr_app_arg ctxt_prec tc tys_wo_kinds + -> ppr_iface_tc_app ppr_app_arg ctxt_prec tc $ + appArgsIfaceTypesArgFlags $ stripInvisArgs (PrintExplicitKinds print_kinds) tys where info = ifaceTyConInfo tc - tys_wo_kinds = appArgsIfaceTypesArgFlags $ stripInvisArgs printExplicitKinds tys ppr_kind_type :: PprPrec -> SDoc ppr_kind_type ctxt_prec = sdocOption sdocStarIsType $ \case ===================================== compiler/GHC/Utils/Outputable.hs ===================================== @@ -1,4 +1,5 @@ {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE PatternSynonyms #-} {- (c) The University of Glasgow 2006-2012 @@ -121,6 +122,7 @@ import qualified Data.List.NonEmpty as NEL import GHC.Fingerprint import GHC.Show ( showMultiLineString ) import GHC.Utils.Exception +import GHC.Exts (oneShot) {- ************************************************************************ @@ -304,7 +306,17 @@ code (either C or assembly), or generating interface files. -- To display an 'SDoc', use 'printSDoc', 'printSDocLn', 'bufLeftRenderSDoc', -- or 'renderWithContext'. Avoid calling 'runSDoc' directly as it breaks the -- abstraction layer. -newtype SDoc = SDoc { runSDoc :: SDocContext -> Doc } +newtype SDoc = SDoc' (SDocContext -> Doc) + +-- See Note [The one-shot state monad trick] in GHC.Utils.Monad +{-# COMPLETE SDoc #-} +pattern SDoc :: (SDocContext -> Doc) -> SDoc +pattern SDoc m <- SDoc' m + where + SDoc m = SDoc' (oneShot m) + +runSDoc :: SDoc -> (SDocContext -> Doc) +runSDoc (SDoc m) = m data SDocContext = SDC { sdocStyle :: !PprStyle @@ -344,6 +356,7 @@ data SDocContext = SDC , sdocStarIsType :: !Bool , sdocLinearTypes :: !Bool , sdocImpredicativeTypes :: !Bool + , sdocPrintTypeAbbreviations :: !Bool , sdocDynFlags :: DynFlags -- TODO: remove } @@ -390,6 +403,7 @@ defaultSDocContext = SDC , sdocStarIsType = False , sdocImpredicativeTypes = False , sdocLinearTypes = False + , sdocPrintTypeAbbreviations = True , sdocDynFlags = error "defaultSDocContext: DynFlags not available" } ===================================== testsuite/tests/ghci/T18060/T18060.stdout ===================================== @@ -1,5 +1,5 @@ type (->) :: * -> * -> * -type (->) = (->) :: * -> * -> * +type (->) = FUN 'Many :: * -> * -> * -- Defined in ‘GHC.Types’ infixr -1 -> instance Applicative ((->) r) -- Defined in ‘GHC.Base’ ===================================== testsuite/tests/ghci/scripts/T8535.stdout ===================================== @@ -1,5 +1,5 @@ type (->) :: * -> * -> * -type (->) = (->) :: * -> * -> * +type (->) = FUN 'Many :: * -> * -> * -- Defined in ‘GHC.Types’ infixr -1 -> instance Applicative ((->) r) -- Defined in ‘GHC.Base’ ===================================== testsuite/tests/ghci/scripts/ghci020.stdout ===================================== @@ -1,5 +1,5 @@ type (->) :: * -> * -> * -type (->) = (->) :: * -> * -> * +type (->) = FUN 'Many :: * -> * -> * -- Defined in ‘GHC.Types’ infixr -1 -> instance Applicative ((->) r) -- Defined in ‘GHC.Base’ ===================================== testsuite/tests/ghci/should_run/T10145.stdout ===================================== @@ -1,5 +1,5 @@ type (->) :: * -> * -> * -type (->) = (->) :: * -> * -> * +type (->) = FUN 'Many :: * -> * -> * -- Defined in ‘GHC.Types’ infixr -1 -> instance Applicative ((->) r) -- Defined in ‘GHC.Base’ ===================================== testsuite/tests/ghci/should_run/T18594.script ===================================== @@ -0,0 +1,6 @@ +:m GHC.Types +:i (->) +:set -XStarIsType +:i Type +:set -XNoStarIsType +:i Type ===================================== testsuite/tests/ghci/should_run/T18594.stdout ===================================== @@ -0,0 +1,15 @@ +type (->) :: * -> * -> * +type (->) = FUN 'Many :: * -> * -> * + -- Defined in ‘GHC.Types’ +infixr -1 -> +instance Applicative ((->) r) -- Defined in ‘GHC.Base’ +instance Functor ((->) r) -- Defined in ‘GHC.Base’ +instance Monad ((->) r) -- Defined in ‘GHC.Base’ +instance Monoid b => Monoid (a -> b) -- Defined in ‘GHC.Base’ +instance Semigroup b => Semigroup (a -> b) -- Defined in ‘GHC.Base’ +type Type :: * +type Type = TYPE 'LiftedRep + -- Defined in ‘GHC.Types’ +type Type :: Type +type Type = TYPE 'LiftedRep + -- Defined in ‘GHC.Types’ ===================================== testsuite/tests/ghci/should_run/all.T ===================================== @@ -75,3 +75,4 @@ test('T18064', ], ghci_script, ['T18064.script']) +test('T18594', just_ghci, ghci_script, ['T18594.script']) ===================================== testsuite/tests/simplCore/should_compile/T18589.hs ===================================== @@ -0,0 +1,12 @@ +{-# LANGUAGE MagicHash #-} +module T18589 where + +import GHC.Prim + +-- See Note [Guarding against silly shifts] +-- Make sure that a silly shift is optimized correctly +f1 x = uncheckedIShiftL# x -1# +f2 x = uncheckedIShiftRA# x -1# +f3 x = uncheckedIShiftRL# x -1# +f4 x = uncheckedShiftL# x -1# +f5 x = uncheckedShiftRL# x -1# ===================================== testsuite/tests/simplCore/should_compile/all.T ===================================== @@ -332,3 +332,4 @@ test('T18328', [ only_ways(['optasm']), grep_errmsg(r'Arity=') ], compile, ['-dd test('T18347', normal, compile, ['-dcore-lint -O']) test('T18355', [ grep_errmsg(r'OneShot') ], compile, ['-O -ddump-simpl -dsuppress-uniques']) test('T18399', normal, compile, ['-dcore-lint -O']) +test('T18589', normal, compile, ['-dcore-lint -O']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/bcf959e3f25d948aa48dc26440932ebd8dfbfdf1...eecaa756bb60f151a94a633d20c99993f5e7595a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/bcf959e3f25d948aa48dc26440932ebd8dfbfdf1...eecaa756bb60f151a94a633d20c99993f5e7595a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 04:31:59 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Mon, 24 Aug 2020 00:31:59 -0400 Subject: [Git][ghc/ghc][master] 2 commits: Do not print synonyms in :i (->), :i Type (#18594) Message-ID: <5f4342bf8e3dd_80b3f8495bc8b049074413@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 8b865092 by Krzysztof Gogolewski at 2020-08-23T14:12:53+02:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - d8f61182 by Krzysztof Gogolewski at 2020-08-23T14:12:56+02:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - 11 changed files: - compiler/GHC/Driver/Session.hs - compiler/GHC/Iface/Syntax.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Utils/Outputable.hs - testsuite/tests/ghci/T18060/T18060.stdout - testsuite/tests/ghci/scripts/T8535.stdout - testsuite/tests/ghci/scripts/ghci020.stdout - testsuite/tests/ghci/should_run/T10145.stdout - + testsuite/tests/ghci/should_run/T18594.script - + testsuite/tests/ghci/should_run/T18594.stdout - testsuite/tests/ghci/should_run/all.T Changes: ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -5079,6 +5079,7 @@ initSDocContext dflags style = SDC , sdocStarIsType = xopt LangExt.StarIsType dflags , sdocImpredicativeTypes = xopt LangExt.ImpredicativeTypes dflags , sdocLinearTypes = xopt LangExt.LinearTypes dflags + , sdocPrintTypeAbbreviations = True , sdocDynFlags = dflags } ===================================== compiler/GHC/Iface/Syntax.hs ===================================== @@ -45,6 +45,8 @@ module GHC.Iface.Syntax ( import GHC.Prelude +import GHC.Builtin.Names ( unrestrictedFunTyConKey, liftedTypeKindTyConKey ) +import GHC.Types.Unique ( hasKey ) import GHC.Iface.Type import GHC.Iface.Recomp.Binary import GHC.Core( IsOrphan, isOrphan ) @@ -947,13 +949,19 @@ pprIfaceDecl ss (IfaceSynonym { ifName = tc , ifResKind = res_kind}) = vcat [ pprStandaloneKindSig name_doc (mkIfaceTyConKind binders res_kind) , hang (text "type" <+> pprIfaceDeclHead suppress_bndr_sig [] ss tc binders <+> equals) - 2 (sep [ pprIfaceForAll tvs, pprIfaceContextArr theta, ppr tau + 2 (sep [ pprIfaceForAll tvs, pprIfaceContextArr theta, ppr_tau , ppUnless (isIfaceLiftedTypeKind res_kind) (dcolon <+> ppr res_kind) ]) ] where (tvs, theta, tau) = splitIfaceSigmaTy mono_ty name_doc = pprPrefixIfDeclBndr (ss_how_much ss) (occName tc) + -- See Note [Printing type abbreviations] in GHC.Iface.Type + ppr_tau | tc `hasKey` liftedTypeKindTyConKey || + tc `hasKey` unrestrictedFunTyConKey + = updSDocContext (\ctx -> ctx { sdocPrintTypeAbbreviations = False }) $ ppr tau + | otherwise = ppr tau + -- See Note [Suppressing binder signatures] in GHC.Iface.Type suppress_bndr_sig = SuppressBndrSig True ===================================== compiler/GHC/Iface/Type.hs ===================================== @@ -783,6 +783,22 @@ Here we'd like to omit the kind annotation: type F :: Symbol -> Type type F s = blah + +Note [Printing type abbreviations] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Normally, we pretty-print `TYPE 'LiftedRep` as `Type` (or `*`) and +`FUN 'Many` as `(->)`. +This way, error messages don't refer to levity polymorphism or linearity +if it is not necessary. + +However, when printing the definition of Type or (->) with :info, +this would give confusing output: `type (->) = (->)` (#18594). +Solution: detect when we are in :info and disable displaying the synonym +with the SDoc option sdocPrintTypeAbbreviations. + +If there will be a need, in the future we could expose it as a flag +-fprint-type-abbreviations or even two separate flags controlling +TYPE 'LiftedRep and FUN 'Many. -} -- | Do we want to suppress kind annotations on binders? @@ -1364,56 +1380,55 @@ pprIfaceTypeApp prec tc args = pprTyTcApp prec tc args pprTyTcApp :: PprPrec -> IfaceTyCon -> IfaceAppArgs -> SDoc pprTyTcApp ctxt_prec tc tys = sdocOption sdocPrintExplicitKinds $ \print_kinds -> + sdocOption sdocPrintTypeAbbreviations $ \print_type_abbreviations -> getPprDebug $ \debug -> - pprTyTcApp' ctxt_prec tc tys (PrintExplicitKinds print_kinds) debug - -pprTyTcApp' :: PprPrec -> IfaceTyCon -> IfaceAppArgs - -> PrintExplicitKinds -> Bool -> SDoc -pprTyTcApp' ctxt_prec tc tys printExplicitKinds debug - | ifaceTyConName tc `hasKey` ipClassKey - , IA_Arg (IfaceLitTy (IfaceStrTyLit n)) - Required (IA_Arg ty Required IA_Nil) <- tys - = maybeParen ctxt_prec funPrec - $ char '?' <> ftext n <> text "::" <> ppr_ty topPrec ty - - | IfaceTupleTyCon arity sort <- ifaceTyConSort info - , not debug - , arity == ifaceVisAppArgsLength tys - = pprTuple ctxt_prec sort (ifaceTyConIsPromoted info) tys - - | IfaceSumTyCon arity <- ifaceTyConSort info - = pprSum arity (ifaceTyConIsPromoted info) tys - - | tc `ifaceTyConHasKey` consDataConKey - , PrintExplicitKinds False <- printExplicitKinds - , IA_Arg _ argf (IA_Arg ty1 Required (IA_Arg ty2 Required IA_Nil)) <- tys - , isInvisibleArgFlag argf - = pprIfaceTyList ctxt_prec ty1 ty2 - - | tc `ifaceTyConHasKey` tYPETyConKey - , IA_Arg (IfaceTyConApp rep IA_Nil) Required IA_Nil <- tys - , rep `ifaceTyConHasKey` liftedRepDataConKey - = ppr_kind_type ctxt_prec - | tc `ifaceTyConHasKey` funTyConKey - , IA_Arg (IfaceTyConApp rep IA_Nil) Required args <- tys - , rep `ifaceTyConHasKey` manyDataConKey - = pprIfacePrefixApp ctxt_prec (parens arrow) (map (ppr_ty appPrec) (appArgsIfaceTypes $ stripInvisArgs printExplicitKinds args)) - - | otherwise - = getPprDebug $ \dbg -> - if | not dbg && tc `ifaceTyConHasKey` errorMessageTypeErrorFamKey + if | ifaceTyConName tc `hasKey` ipClassKey + , IA_Arg (IfaceLitTy (IfaceStrTyLit n)) + Required (IA_Arg ty Required IA_Nil) <- tys + -> maybeParen ctxt_prec funPrec + $ char '?' <> ftext n <> text "::" <> ppr_ty topPrec ty + + | IfaceTupleTyCon arity sort <- ifaceTyConSort info + , not debug + , arity == ifaceVisAppArgsLength tys + -> pprTuple ctxt_prec sort (ifaceTyConIsPromoted info) tys + + | IfaceSumTyCon arity <- ifaceTyConSort info + -> pprSum arity (ifaceTyConIsPromoted info) tys + + | tc `ifaceTyConHasKey` consDataConKey + , False <- print_kinds + , IA_Arg _ argf (IA_Arg ty1 Required (IA_Arg ty2 Required IA_Nil)) <- tys + , isInvisibleArgFlag argf + -> pprIfaceTyList ctxt_prec ty1 ty2 + + | tc `ifaceTyConHasKey` tYPETyConKey + , IA_Arg (IfaceTyConApp rep IA_Nil) Required IA_Nil <- tys + , rep `ifaceTyConHasKey` liftedRepDataConKey + , print_type_abbreviations -- See Note [Printing type abbreviations] + -> ppr_kind_type ctxt_prec + + | tc `ifaceTyConHasKey` funTyConKey + , IA_Arg (IfaceTyConApp rep IA_Nil) Required args <- tys + , rep `ifaceTyConHasKey` manyDataConKey + , print_type_abbreviations -- See Note [Printing type abbreviations] + -> pprIfacePrefixApp ctxt_prec (parens arrow) (map (ppr_ty appPrec) $ + appArgsIfaceTypes $ stripInvisArgs (PrintExplicitKinds print_kinds) args) + + | tc `ifaceTyConHasKey` errorMessageTypeErrorFamKey + , not debug -- Suppress detail unless you _really_ want to see - -> text "(TypeError ...)" + -> text "(TypeError ...)" | Just doc <- ppr_equality ctxt_prec tc (appArgsIfaceTypes tys) - -> doc + -> doc | otherwise - -> ppr_iface_tc_app ppr_app_arg ctxt_prec tc tys_wo_kinds + -> ppr_iface_tc_app ppr_app_arg ctxt_prec tc $ + appArgsIfaceTypesArgFlags $ stripInvisArgs (PrintExplicitKinds print_kinds) tys where info = ifaceTyConInfo tc - tys_wo_kinds = appArgsIfaceTypesArgFlags $ stripInvisArgs printExplicitKinds tys ppr_kind_type :: PprPrec -> SDoc ppr_kind_type ctxt_prec = sdocOption sdocStarIsType $ \case ===================================== compiler/GHC/Utils/Outputable.hs ===================================== @@ -344,6 +344,7 @@ data SDocContext = SDC , sdocStarIsType :: !Bool , sdocLinearTypes :: !Bool , sdocImpredicativeTypes :: !Bool + , sdocPrintTypeAbbreviations :: !Bool , sdocDynFlags :: DynFlags -- TODO: remove } @@ -390,6 +391,7 @@ defaultSDocContext = SDC , sdocStarIsType = False , sdocImpredicativeTypes = False , sdocLinearTypes = False + , sdocPrintTypeAbbreviations = True , sdocDynFlags = error "defaultSDocContext: DynFlags not available" } ===================================== testsuite/tests/ghci/T18060/T18060.stdout ===================================== @@ -1,5 +1,5 @@ type (->) :: * -> * -> * -type (->) = (->) :: * -> * -> * +type (->) = FUN 'Many :: * -> * -> * -- Defined in ‘GHC.Types’ infixr -1 -> instance Applicative ((->) r) -- Defined in ‘GHC.Base’ ===================================== testsuite/tests/ghci/scripts/T8535.stdout ===================================== @@ -1,5 +1,5 @@ type (->) :: * -> * -> * -type (->) = (->) :: * -> * -> * +type (->) = FUN 'Many :: * -> * -> * -- Defined in ‘GHC.Types’ infixr -1 -> instance Applicative ((->) r) -- Defined in ‘GHC.Base’ ===================================== testsuite/tests/ghci/scripts/ghci020.stdout ===================================== @@ -1,5 +1,5 @@ type (->) :: * -> * -> * -type (->) = (->) :: * -> * -> * +type (->) = FUN 'Many :: * -> * -> * -- Defined in ‘GHC.Types’ infixr -1 -> instance Applicative ((->) r) -- Defined in ‘GHC.Base’ ===================================== testsuite/tests/ghci/should_run/T10145.stdout ===================================== @@ -1,5 +1,5 @@ type (->) :: * -> * -> * -type (->) = (->) :: * -> * -> * +type (->) = FUN 'Many :: * -> * -> * -- Defined in ‘GHC.Types’ infixr -1 -> instance Applicative ((->) r) -- Defined in ‘GHC.Base’ ===================================== testsuite/tests/ghci/should_run/T18594.script ===================================== @@ -0,0 +1,6 @@ +:m GHC.Types +:i (->) +:set -XStarIsType +:i Type +:set -XNoStarIsType +:i Type ===================================== testsuite/tests/ghci/should_run/T18594.stdout ===================================== @@ -0,0 +1,15 @@ +type (->) :: * -> * -> * +type (->) = FUN 'Many :: * -> * -> * + -- Defined in ‘GHC.Types’ +infixr -1 -> +instance Applicative ((->) r) -- Defined in ‘GHC.Base’ +instance Functor ((->) r) -- Defined in ‘GHC.Base’ +instance Monad ((->) r) -- Defined in ‘GHC.Base’ +instance Monoid b => Monoid (a -> b) -- Defined in ‘GHC.Base’ +instance Semigroup b => Semigroup (a -> b) -- Defined in ‘GHC.Base’ +type Type :: * +type Type = TYPE 'LiftedRep + -- Defined in ‘GHC.Types’ +type Type :: Type +type Type = TYPE 'LiftedRep + -- Defined in ‘GHC.Types’ ===================================== testsuite/tests/ghci/should_run/all.T ===================================== @@ -75,3 +75,4 @@ test('T18064', ], ghci_script, ['T18064.script']) +test('T18594', just_ghci, ghci_script, ['T18594.script']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/3f50154591ada9064351ccec4adfe6df53ca2439...d8f61182c3bdd1b6121c83be632b4941b907de88 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/3f50154591ada9064351ccec4adfe6df53ca2439...d8f61182c3bdd1b6121c83be632b4941b907de88 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 04:32:38 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Mon, 24 Aug 2020 00:32:38 -0400 Subject: [Git][ghc/ghc][master] Fix types in silly shifts (#18589) Message-ID: <5f4342e6cc552_80b3f84693c1eb4907555e@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 364258e0 by Krzysztof Gogolewski at 2020-08-24T00:32:31-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - 3 changed files: - compiler/GHC/Core/Opt/ConstantFold.hs - + testsuite/tests/simplCore/should_compile/T18589.hs - testsuite/tests/simplCore/should_compile/all.T Changes: ===================================== compiler/GHC/Core/Opt/ConstantFold.hs ===================================== @@ -143,11 +143,11 @@ primOpRules nm = \case , inversePrimOp NotIOp ] IntNegOp -> mkPrimOpRule nm 1 [ unaryLit negOp , inversePrimOp IntNegOp ] - ISllOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftL) + ISllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const Bits.shiftL) , rightIdentityPlatform zeroi ] - ISraOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftR) + ISraOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const Bits.shiftR) , rightIdentityPlatform zeroi ] - ISrlOp -> mkPrimOpRule nm 2 [ shiftRule shiftRightLogical + ISrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt shiftRightLogical , rightIdentityPlatform zeroi ] -- Word operations @@ -189,8 +189,8 @@ primOpRules nm = \case , equalArgs >> retLit zerow ] NotOp -> mkPrimOpRule nm 1 [ unaryLit complementOp , inversePrimOp NotOp ] - SllOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftL) ] - SrlOp -> mkPrimOpRule nm 2 [ shiftRule shiftRightLogical ] + SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord (const Bits.shiftL) ] + SrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord shiftRightLogical ] -- coercions Word2IntOp -> mkPrimOpRule nm 1 [ liftLitPlatform word2IntLit @@ -477,12 +477,14 @@ wordOpC2 op env (LitNumber LitNumWord w1) (LitNumber LitNumWord w2) = wordCResult (roPlatform env) (fromInteger w1 `op` fromInteger w2) wordOpC2 _ _ _ _ = Nothing -shiftRule :: (Platform -> Integer -> Int -> Integer) -> RuleM CoreExpr +shiftRule :: LitNumType -- Type of the result, either LitNumInt or LitNumWord + -> (Platform -> Integer -> Int -> Integer) + -> RuleM CoreExpr -- Shifts take an Int; hence third arg of op is Int -- Used for shift primops --- ISllOp, ISraOp, ISrlOp :: Word# -> Int# -> Word# +-- ISllOp, ISraOp, ISrlOp :: Int# -> Int# -> Int# -- SllOp, SrlOp :: Word# -> Int# -> Word# -shiftRule shift_op +shiftRule lit_num_ty shift_op = do { platform <- getPlatform ; [e1, Lit (LitNumber LitNumInt shift_len)] <- getArgs ; case e1 of @@ -490,7 +492,9 @@ shiftRule shift_op -> return e1 -- See Note [Guarding against silly shifts] | shift_len < 0 || shift_len > toInteger (platformWordSizeInBits platform) - -> return $ Lit $ mkLitNumberWrap platform LitNumInt 0 + -> return $ Lit $ mkLitNumberWrap platform lit_num_ty 0 + -- Be sure to use lit_num_ty here, so we get a correctly typed zero + -- of type Int# or Word# resp. See #18589 -- Do the shift at type Integer, but shift length is Int Lit (LitNumber nt x) ===================================== testsuite/tests/simplCore/should_compile/T18589.hs ===================================== @@ -0,0 +1,12 @@ +{-# LANGUAGE MagicHash #-} +module T18589 where + +import GHC.Prim + +-- See Note [Guarding against silly shifts] +-- Make sure that a silly shift is optimized correctly +f1 x = uncheckedIShiftL# x -1# +f2 x = uncheckedIShiftRA# x -1# +f3 x = uncheckedIShiftRL# x -1# +f4 x = uncheckedShiftL# x -1# +f5 x = uncheckedShiftRL# x -1# ===================================== testsuite/tests/simplCore/should_compile/all.T ===================================== @@ -332,3 +332,4 @@ test('T18328', [ only_ways(['optasm']), grep_errmsg(r'Arity=') ], compile, ['-dd test('T18347', normal, compile, ['-dcore-lint -O']) test('T18355', [ grep_errmsg(r'OneShot') ], compile, ['-O -ddump-simpl -dsuppress-uniques']) test('T18399', normal, compile, ['-dcore-lint -O']) +test('T18589', normal, compile, ['-dcore-lint -O']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/364258e0ad25bc95e69745554f5ca831ce80baf8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/364258e0ad25bc95e69745554f5ca831ce80baf8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 04:33:20 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Mon, 24 Aug 2020 00:33:20 -0400 Subject: [Git][ghc/ghc][master] Perf: make SDoc monad one-shot (#18202) Message-ID: <5f434310c81d2_80b3f84902b1250908000@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: b1eb38a0 by Sylvain Henry at 2020-08-24T00:33:13-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - 1 changed file: - compiler/GHC/Utils/Outputable.hs Changes: ===================================== compiler/GHC/Utils/Outputable.hs ===================================== @@ -1,4 +1,5 @@ {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE PatternSynonyms #-} {- (c) The University of Glasgow 2006-2012 @@ -121,6 +122,7 @@ import qualified Data.List.NonEmpty as NEL import GHC.Fingerprint import GHC.Show ( showMultiLineString ) import GHC.Utils.Exception +import GHC.Exts (oneShot) {- ************************************************************************ @@ -304,7 +306,17 @@ code (either C or assembly), or generating interface files. -- To display an 'SDoc', use 'printSDoc', 'printSDocLn', 'bufLeftRenderSDoc', -- or 'renderWithContext'. Avoid calling 'runSDoc' directly as it breaks the -- abstraction layer. -newtype SDoc = SDoc { runSDoc :: SDocContext -> Doc } +newtype SDoc = SDoc' (SDocContext -> Doc) + +-- See Note [The one-shot state monad trick] in GHC.Utils.Monad +{-# COMPLETE SDoc #-} +pattern SDoc :: (SDocContext -> Doc) -> SDoc +pattern SDoc m <- SDoc' m + where + SDoc m = SDoc' (oneShot m) + +runSDoc :: SDoc -> (SDocContext -> Doc) +runSDoc (SDoc m) = m data SDocContext = SDC { sdocStyle :: !PprStyle View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b1eb38a0a7168d7612c791c4289cc02d900d402f -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b1eb38a0a7168d7612c791c4289cc02d900d402f You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 05:34:18 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Mon, 24 Aug 2020 01:34:18 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: Fix types in silly shifts (#18589) Message-ID: <5f43515a51123_80b3f84693c1eb4908762@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 364258e0 by Krzysztof Gogolewski at 2020-08-24T00:32:31-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - b1eb38a0 by Sylvain Henry at 2020-08-24T00:33:13-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - 71b2eacb by Krzysztof Gogolewski at 2020-08-24T01:34:09-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - fe9ab297 by Sylvain Henry at 2020-08-24T01:34:11-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 7 changed files: - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/Core/Opt/ConstantFold.hs - compiler/GHC/Utils/Outputable.hs - + testsuite/tests/codeGen/should_compile/T18397.hs - testsuite/tests/codeGen/should_compile/all.T - + testsuite/tests/simplCore/should_compile/T18589.hs - testsuite/tests/simplCore/should_compile/all.T Changes: ===================================== compiler/GHC/CmmToAsm/Dwarf.hs ===================================== @@ -179,9 +179,7 @@ procToDwarf config prc = DwarfSubprogram { dwChildren = map blockToDwarf (dblBlocks prc) , dwName = case dblSourceTick prc of Just s at SourceNote{} -> sourceName s - _otherwise -> renderWithContext defaultSDocContext - $ withPprStyle defaultDumpStyle - $ ppr (dblLabel prc) + _otherwise -> show (dblLabel prc) , dwLabel = dblCLabel prc , dwParent = fmap mkAsmTempDieLabel $ mfilter goodParent ===================================== compiler/GHC/Core/Opt/ConstantFold.hs ===================================== @@ -143,11 +143,11 @@ primOpRules nm = \case , inversePrimOp NotIOp ] IntNegOp -> mkPrimOpRule nm 1 [ unaryLit negOp , inversePrimOp IntNegOp ] - ISllOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftL) + ISllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const Bits.shiftL) , rightIdentityPlatform zeroi ] - ISraOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftR) + ISraOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const Bits.shiftR) , rightIdentityPlatform zeroi ] - ISrlOp -> mkPrimOpRule nm 2 [ shiftRule shiftRightLogical + ISrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt shiftRightLogical , rightIdentityPlatform zeroi ] -- Word operations @@ -189,8 +189,8 @@ primOpRules nm = \case , equalArgs >> retLit zerow ] NotOp -> mkPrimOpRule nm 1 [ unaryLit complementOp , inversePrimOp NotOp ] - SllOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftL) ] - SrlOp -> mkPrimOpRule nm 2 [ shiftRule shiftRightLogical ] + SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord (const Bits.shiftL) ] + SrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord shiftRightLogical ] -- coercions Word2IntOp -> mkPrimOpRule nm 1 [ liftLitPlatform word2IntLit @@ -477,12 +477,14 @@ wordOpC2 op env (LitNumber LitNumWord w1) (LitNumber LitNumWord w2) = wordCResult (roPlatform env) (fromInteger w1 `op` fromInteger w2) wordOpC2 _ _ _ _ = Nothing -shiftRule :: (Platform -> Integer -> Int -> Integer) -> RuleM CoreExpr +shiftRule :: LitNumType -- Type of the result, either LitNumInt or LitNumWord + -> (Platform -> Integer -> Int -> Integer) + -> RuleM CoreExpr -- Shifts take an Int; hence third arg of op is Int -- Used for shift primops --- ISllOp, ISraOp, ISrlOp :: Word# -> Int# -> Word# +-- ISllOp, ISraOp, ISrlOp :: Int# -> Int# -> Int# -- SllOp, SrlOp :: Word# -> Int# -> Word# -shiftRule shift_op +shiftRule lit_num_ty shift_op = do { platform <- getPlatform ; [e1, Lit (LitNumber LitNumInt shift_len)] <- getArgs ; case e1 of @@ -490,7 +492,9 @@ shiftRule shift_op -> return e1 -- See Note [Guarding against silly shifts] | shift_len < 0 || shift_len > toInteger (platformWordSizeInBits platform) - -> return $ Lit $ mkLitNumberWrap platform LitNumInt 0 + -> return $ Lit $ mkLitNumberWrap platform lit_num_ty 0 + -- Be sure to use lit_num_ty here, so we get a correctly typed zero + -- of type Int# or Word# resp. See #18589 -- Do the shift at type Integer, but shift length is Int Lit (LitNumber nt x) ===================================== compiler/GHC/Utils/Outputable.hs ===================================== @@ -1,4 +1,5 @@ {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE PatternSynonyms #-} {- (c) The University of Glasgow 2006-2012 @@ -121,6 +122,7 @@ import qualified Data.List.NonEmpty as NEL import GHC.Fingerprint import GHC.Show ( showMultiLineString ) import GHC.Utils.Exception +import GHC.Exts (oneShot) {- ************************************************************************ @@ -304,7 +306,17 @@ code (either C or assembly), or generating interface files. -- To display an 'SDoc', use 'printSDoc', 'printSDocLn', 'bufLeftRenderSDoc', -- or 'renderWithContext'. Avoid calling 'runSDoc' directly as it breaks the -- abstraction layer. -newtype SDoc = SDoc { runSDoc :: SDocContext -> Doc } +newtype SDoc = SDoc' (SDocContext -> Doc) + +-- See Note [The one-shot state monad trick] in GHC.Utils.Monad +{-# COMPLETE SDoc #-} +pattern SDoc :: (SDocContext -> Doc) -> SDoc +pattern SDoc m <- SDoc' m + where + SDoc m = SDoc' (oneShot m) + +runSDoc :: SDoc -> (SDocContext -> Doc) +runSDoc (SDoc m) = m data SDocContext = SDC { sdocStyle :: !PprStyle ===================================== testsuite/tests/codeGen/should_compile/T18397.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE UnboxedTuples #-} +module T18397 where + +import GHC.Exts +import GHC.ST + +data MutableArray s a = MutableArray (MutableArray# s a) + +runArray# + :: (forall s. ST s (MutableArray s a)) + -> Array# a +runArray# m = case runRW# $ \s -> + case unST m s of { (# s', MutableArray mary# #) -> + unsafeFreezeArray# mary# s'} of (# _, ary# #) -> ary# + +unST :: ST s a -> State# s -> (# State# s, a #) +unST (ST f) = f + ===================================== testsuite/tests/codeGen/should_compile/all.T ===================================== @@ -91,7 +91,11 @@ test('T17648', normal, makefile_test, []) test('T17904', normal, compile, ['-O']) test('T18227A', normal, compile, ['']) test('T18227B', normal, compile, ['']) + +# runRW#-related test('T18291', normal, compile, ['-O0']) +test('T18397', normal, compile, ['-O0']) + test('T15570', when(unregisterised(), skip), compile, ['-Wno-overflowed-literals']) ===================================== testsuite/tests/simplCore/should_compile/T18589.hs ===================================== @@ -0,0 +1,12 @@ +{-# LANGUAGE MagicHash #-} +module T18589 where + +import GHC.Prim + +-- See Note [Guarding against silly shifts] +-- Make sure that a silly shift is optimized correctly +f1 x = uncheckedIShiftL# x -1# +f2 x = uncheckedIShiftRA# x -1# +f3 x = uncheckedIShiftRL# x -1# +f4 x = uncheckedShiftL# x -1# +f5 x = uncheckedShiftRL# x -1# ===================================== testsuite/tests/simplCore/should_compile/all.T ===================================== @@ -332,3 +332,4 @@ test('T18328', [ only_ways(['optasm']), grep_errmsg(r'Arity=') ], compile, ['-dd test('T18347', normal, compile, ['-dcore-lint -O']) test('T18355', [ grep_errmsg(r'OneShot') ], compile, ['-O -ddump-simpl -dsuppress-uniques']) test('T18399', normal, compile, ['-dcore-lint -O']) +test('T18589', normal, compile, ['-dcore-lint -O']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/eecaa756bb60f151a94a633d20c99993f5e7595a...fe9ab297d215d12fc467786e538ac1cd89c4a8a1 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/eecaa756bb60f151a94a633d20c99993f5e7595a...fe9ab297d215d12fc467786e538ac1cd89c4a8a1 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 07:16:16 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Mon, 24 Aug 2020 03:16:16 -0400 Subject: [Git][ghc/ghc][wip/buggymcbugfix/arrayOf-static] fiddling in RTS (segfaults) Message-ID: <5f436940c83bb_80b1161a4849088239@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed to branch wip/buggymcbugfix/arrayOf-static at Glasgow Haskell Compiler / GHC Commits: f24cd69e by buggymcbugfix at 2020-08-24T09:03:00+02:00 fiddling in RTS (segfaults) - - - - - 3 changed files: - compiler/GHC/StgToCmm/Heap.hs - rts/sm/Evac.c - rts/sm/Scav.c Changes: ===================================== compiler/GHC/StgToCmm/Heap.hs ===================================== @@ -197,7 +197,7 @@ mkStaticClosureFields dflags info_tbl ccs caf_refs payload is_caf = isThunkRep (cit_rep info_tbl) padding - | is_caf && null payload = [mkIntCLit platform 0] + | is_caf && null payload = [mkIntCLit platform 0] -- TODO empty array case? | otherwise = [] static_link_field @@ -205,7 +205,11 @@ mkStaticClosureFields dflags info_tbl ccs caf_refs payload = [mkIntCLit platform 0] | staticClosureNeedsLink (mayHaveCafRefs caf_refs) info_tbl = [static_link_value] - | otherwise + | SmallArrayPtrsRep 0 <- cit_rep info_tbl + = [mkIntCLit platform 3] + | SmallArrayPtrsRep _ <- cit_rep info_tbl + = [mkIntCLit platform 0] + | otherwise -- CONSTR_0_1, CONSTR_0_2, CONSTR_NOCAF cases in rts/sm/Evac.c = [] saved_info_field ===================================== rts/sm/Evac.c ===================================== @@ -627,10 +627,17 @@ loop: case CONSTR_0_2: case CONSTR_NOCAF: /* no need to put these on the static linked list, they don't need - * to be scavenged. + * to be scavenged. See static_link_field in GHC.StgToCmm.Heap */ return; + case SMALL_MUT_ARR_PTRS_CLEAN: // todo: do we even need to evac this case? + case SMALL_MUT_ARR_PTRS_FROZEN_CLEAN: // todo: do we even need to evac this case? + case SMALL_MUT_ARR_PTRS_DIRTY: + case SMALL_MUT_ARR_PTRS_FROZEN_DIRTY: + evacuate_static_object(STATIC_LINK(info,(StgSmallMutArrPtrs*)q), q); + return; + default: barf("evacuate(static): strange closure type %d", (int)(info->type)); } ===================================== rts/sm/Scav.c ===================================== @@ -1791,6 +1791,20 @@ scavenge_static(void) } break; } + case SMALL_MUT_ARR_PTRS_CLEAN: + case SMALL_MUT_ARR_PTRS_FROZEN_CLEAN: + case SMALL_MUT_ARR_PTRS_DIRTY: + case SMALL_MUT_ARR_PTRS_FROZEN_DIRTY: + { + StgPtr q, next; + StgSmallMutArrPtrs* arr = (StgSmallMutArrPtrs*)p; + next = (P_)arr->payload + arr->ptrs; + // evacuate the pointers + for (q = (P_)arr->payload; q < next; q++) { // todo: does the payload come last, even when profiling? + evacuate((StgClosure **)q); + } + break; + } default: barf("scavenge_static: strange closure %d", (int)(info->type)); View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f24cd69ee27ec66331b06a016fba674b8e5f0d42 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f24cd69ee27ec66331b06a016fba674b8e5f0d42 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 07:20:58 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Mon, 24 Aug 2020 03:20:58 -0400 Subject: [Git][ghc/ghc][wip/buggymcbugfix/arrayOf-static] fiddling in RTS (segfaults) Message-ID: <5f436a5a8644f_80b1161a4849088468@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed to branch wip/buggymcbugfix/arrayOf-static at Glasgow Haskell Compiler / GHC Commits: 985aa804 by buggymcbugfix at 2020-08-24T09:20:43+02:00 fiddling in RTS (segfaults) - - - - - 3 changed files: - compiler/GHC/StgToCmm/Heap.hs - rts/sm/Evac.c - rts/sm/Scav.c Changes: ===================================== compiler/GHC/StgToCmm/Heap.hs ===================================== @@ -197,7 +197,7 @@ mkStaticClosureFields dflags info_tbl ccs caf_refs payload is_caf = isThunkRep (cit_rep info_tbl) padding - | is_caf && null payload = [mkIntCLit platform 0] + | is_caf && null payload = [mkIntCLit platform 0] -- TODO empty array case? | otherwise = [] static_link_field @@ -205,7 +205,11 @@ mkStaticClosureFields dflags info_tbl ccs caf_refs payload = [mkIntCLit platform 0] | staticClosureNeedsLink (mayHaveCafRefs caf_refs) info_tbl = [static_link_value] - | otherwise + | SmallArrayPtrsRep 0 <- cit_rep info_tbl -- todo: This is a hack. + = [mkIntCLit platform 3] + | SmallArrayPtrsRep _ <- cit_rep info_tbl -- todo: This is a hack. + = [mkIntCLit platform 0] + | otherwise -- CONSTR_0_1, CONSTR_0_2, CONSTR_NOCAF cases in evacuate (rts/sm/Evac.c). = [] saved_info_field ===================================== rts/sm/Evac.c ===================================== @@ -627,10 +627,17 @@ loop: case CONSTR_0_2: case CONSTR_NOCAF: /* no need to put these on the static linked list, they don't need - * to be scavenged. + * to be scavenged. See static_link_field in GHC.StgToCmm.Heap */ return; + case SMALL_MUT_ARR_PTRS_CLEAN: // todo: do we even need to evac this case? + case SMALL_MUT_ARR_PTRS_FROZEN_CLEAN: // todo: do we even need to evac this case? + case SMALL_MUT_ARR_PTRS_DIRTY: + case SMALL_MUT_ARR_PTRS_FROZEN_DIRTY: + evacuate_static_object(STATIC_LINK(info,(StgSmallMutArrPtrs*)q), q); + return; + default: barf("evacuate(static): strange closure type %d", (int)(info->type)); } ===================================== rts/sm/Scav.c ===================================== @@ -1791,6 +1791,20 @@ scavenge_static(void) } break; } + case SMALL_MUT_ARR_PTRS_CLEAN: + case SMALL_MUT_ARR_PTRS_FROZEN_CLEAN: + case SMALL_MUT_ARR_PTRS_DIRTY: + case SMALL_MUT_ARR_PTRS_FROZEN_DIRTY: + { + StgPtr q, next; + StgSmallMutArrPtrs* arr = (StgSmallMutArrPtrs*)p; + next = (P_)arr->payload + arr->ptrs; + // evacuate the pointers + for (q = (P_)arr->payload; q < next; q++) { // todo: does the payload come last, even when profiling? + evacuate((StgClosure **)q); + } + break; + } default: barf("scavenge_static: strange closure %d", (int)(info->type)); View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/985aa80423910beb93b15ee1958f2147e99698b4 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/985aa80423910beb93b15ee1958f2147e99698b4 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 08:56:00 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Mon, 24 Aug 2020 04:56:00 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18602 Message-ID: <5f4380a0a1707_80b3f8486857894909895@gitlab.haskell.org.mail> Simon Peyton Jones pushed new branch wip/T18602 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18602 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 09:04:33 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Mon, 24 Aug 2020 05:04:33 -0400 Subject: [Git][ghc/ghc][wip/T18223] Wibbles Message-ID: <5f4382a1779e6_80bac4156c91010ae@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18223 at Glasgow Haskell Compiler / GHC Commits: 71342296 by Simon Peyton Jones at 2020-08-24T10:04:03+01:00 Wibbles - - - - - 3 changed files: - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Ppr.hs Changes: ===================================== compiler/GHC/Core/Coercion.hs ===================================== @@ -299,8 +299,8 @@ tidyCoAxBndrsForUser init_env tcvs coToMCo :: Coercion -> MCoercion -- Convert a coercion to a MCoercion, -- checking aggressively for reflexivity -coToMCo co | isReflexiveCo co = MRefl - | otherwise = MCo co +coToMCo co | isReflCo co = MRefl + | otherwise = MCo co -- | Tests if this MCoercion is obviously generalized reflexive -- Guaranteed to work very quickly. ===================================== compiler/GHC/Core/Opt/Arity.hs ===================================== @@ -1108,7 +1108,7 @@ eta_expand one_shots orig_expr * * The EtaInfo mechanism * * -************************************************************************ +********************************************************************* -} {- Note [The EtaInfo mechanism] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/Core/Ppr.hs ===================================== @@ -166,7 +166,9 @@ ppr_id_occ add_par id | isJoinId id = add_par ((text "jump") <+> pp_id) | otherwise = pp_id where - pp_id = pprPrefixOcc id + pp_id = ppr id -- We could use pprPrefixOcc to print (+) etc, but this is + -- Core where we don't print things infix anyway, so doing + -- so just adds extra redundant parens ppr_expr :: OutputableBndr b => (SDoc -> SDoc) -> Expr b -> SDoc -- The function adds parens in context that need View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/71342296e7d426786bee4466249802cd630ec292 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/71342296e7d426786bee4466249802cd630ec292 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 09:29:16 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Mon, 24 Aug 2020 05:29:16 -0400 Subject: [Git][ghc/ghc][wip/buggymcbugfix/arrayOf-primop] Implement `arrayOf#` Message-ID: <5f43886cd403d_80b3f848685789491015bc@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed to branch wip/buggymcbugfix/arrayOf-primop at Glasgow Haskell Compiler / GHC Commits: 9995769c by buggymcbugfix at 2020-08-20T17:54:44+02:00 Implement `arrayOf#` - - - - - 3 changed files: - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/StgToCmm/Closure.hs - compiler/GHC/StgToCmm/Prim.hs Changes: ===================================== compiler/GHC/Builtin/primops.txt.pp ===================================== @@ -1247,9 +1247,15 @@ primop NewSmallArrayOp "newSmallArray#" GenPrimOp out_of_line = True has_side_effects = True +primop ArrayOfOp "arrayOf#" GenPrimOp + o -> Array# b + {arrayOf# :: (# a, .., a #) -> Array# a} + with + has_side_effects = True + primop SmallArrayOfOp "smallArrayOf#" GenPrimOp o -> SmallArray# b - {smallArrayOf# :: (# a, .., a #) -> Array# a} + {smallArrayOf# :: (# a, .., a #) -> SmallArray# a} with has_side_effects = True ===================================== compiler/GHC/StgToCmm/Closure.hs ===================================== @@ -60,7 +60,6 @@ module GHC.StgToCmm.Closure ( cafBlackHoleInfoTable, indStaticInfoTable, staticClosureNeedsLink, - smallArrayStaticInfoTable, ) where #include "HsVersions.h" @@ -987,14 +986,6 @@ indStaticInfoTable , cit_srt = Nothing , cit_clo = Nothing } -smallArrayStaticInfoTable :: WordOff -> CmmInfoTable -smallArrayStaticInfoTable n - = CmmInfoTable { cit_lbl = mkSMAP_FROZEN_DIRTY_infoLabel - , cit_rep = smallArrPtrsRep (fromIntegral n) - , cit_prof = NoProfilingInfo - , cit_srt = Nothing - , cit_clo = Nothing } - staticClosureNeedsLink :: Bool -> CmmInfoTable -> Bool -- A static closure needs a link field to aid the GC when traversing -- the static closure graph. But it only needs such a field if either ===================================== compiler/GHC/StgToCmm/Prim.hs ===================================== @@ -1,5 +1,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE ScopedTypeVariables #-} #if __GLASGOW_HASKELL__ <= 808 -- GHC 8.10 deprecates this flag, but GHC 8.8 needs it @@ -58,7 +59,6 @@ import Data.Bits ((.&.), bit) import Control.Monad (liftM, when, unless) import GHC.Types.CostCentre (dontCareCCS) -import GHC.StgToCmm.Closure ------------------------------------------------------------------------ -- Primitive operations and foreign calls @@ -244,27 +244,9 @@ emitPrimOp dflags = \case (replicate (fromIntegral n) init) _ -> PrimopCmmEmit_External - op at SmallArrayOfOp -> \elems -> PrimopCmmEmit_IntoRegs $ \[res] -> do - let n = length elems - case allStatic elems of - Just known -> do - u <- newUnique - let lbl = mkUnliftedDataLabel u op - emitDataCon lbl (smallArrayStaticInfoTable n) dontCareCCS known - emit $ mkAssign (CmmLocal res) (CmmLit $ CmmLabel lbl) - Nothing -> doNewArrayOp - res - (smallArrPtrsRep (fromIntegral n)) - mkSMAP_FROZEN_DIRTY_infoLabel - [ ( mkIntExpr platform n - , fixedHdrSize dflags + oFFSET_StgSmallMutArrPtrs_ptrs dflags ) ] - elems - where - -- todo: comment - allStatic = foldr step (Just []) + op at ArrayOfOp -> doArrayOfOp dflags op - step (CmmLit l) (Just acc) = Just (l : acc) -- c.f. XXX getLit - step _ _ = Nothing + op at SmallArrayOfOp -> doArrayOfOp dflags op CopySmallArrayOp -> \case [src, src_off, dst, dst_off, (CmmLit (CmmInt n _))] -> @@ -2577,6 +2559,61 @@ doNewArrayOp res_r rep info payload inits = do emit $ mkAssign (CmmLocal res_r) (CmmReg arr) +doArrayOfOp :: DynFlags -> PrimOp -> [CmmExpr] -> PrimopCmmEmit +doArrayOfOp dflags op = \elems -> PrimopCmmEmit_IntoRegs $ \[res] -> do + let + n :: Int + n = length elems + + platform :: Platform + platform = targetPlatform dflags + + infoTbl :: CmmInfoTable + infoTbl = CmmInfoTable + { cit_lbl = lbl + , cit_rep = rep + , cit_prof = NoProfilingInfo + , cit_srt = Nothing + , cit_clo = Nothing } + + lbl :: CLabel + rep :: SMRep + hdr :: [(CmmExpr, ByteOff)] + (lbl, rep, hdr) = case op of + ArrayOfOp -> + ( mkMAP_FROZEN_DIRTY_infoLabel + , arrPtrsRep dflags (fromIntegral n) + , [ ( mkIntExpr platform n + , fixedHdrSize dflags + oFFSET_StgMutArrPtrs_ptrs dflags ) + , ( mkIntExpr platform (nonHdrSizeW (arrPtrsRep dflags n)) + , fixedHdrSize dflags + oFFSET_StgMutArrPtrs_size dflags ) + ] + ) + SmallArrayOfOp -> + ( mkSMAP_FROZEN_DIRTY_infoLabel + , smallArrPtrsRep (fromIntegral n) + , [ ( mkIntExpr platform n + , fixedHdrSize dflags + oFFSET_StgSmallMutArrPtrs_ptrs dflags + ) + ] + ) + _ -> error "Expected one of: ArrayOfOp, SmallArrayOfOp" + + if all isStatic elems + then do + u <- newUnique + let staticLbl = mkUnliftedDataLabel u op + emitDataCon staticLbl infoTbl dontCareCCS (map unsafeUnwrapLit elems) + emit $ mkAssign (CmmLocal res) (CmmLit $ CmmLabel staticLbl) + else doNewArrayOp res rep lbl hdr elems + +isStatic :: CmmExpr -> Bool +isStatic = \case CmmLit{} -> True; _ -> False + +unsafeUnwrapLit :: CmmExpr -> CmmLit +unsafeUnwrapLit (CmmLit i) = i +unsafeUnwrapLit _ = error "Expected CmmLit" + -- ---------------------------------------------------------------------------- -- Copying pointer arrays View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9995769c61751476e33a6f17ee307045cd9cb9bc -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9995769c61751476e33a6f17ee307045cd9cb9bc You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 10:13:08 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Mon, 24 Aug 2020 06:13:08 -0400 Subject: [Git][ghc/ghc][wip/buggymcbugfix/arrayOf-static] blerg Message-ID: <5f4392b4cf010_80b3f84902b125091026cc@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed to branch wip/buggymcbugfix/arrayOf-static at Glasgow Haskell Compiler / GHC Commits: 0401d1a5 by buggymcbugfix at 2020-08-24T12:12:40+02:00 blerg - - - - - 1 changed file: - includes/rts/storage/ClosureMacros.h Changes: ===================================== includes/rts/storage/ClosureMacros.h ===================================== @@ -167,8 +167,16 @@ STATIC_LINK(const StgInfoTable *info, StgClosure *p) switch (info->type) { case THUNK_STATIC: return THUNK_STATIC_LINK(p); + case IND_STATIC: return IND_STATIC_LINK(p); + + case SMALL_MUT_ARR_PTRS_CLEAN: + case SMALL_MUT_ARR_PTRS_FROZEN_CLEAN: + case SMALL_MUT_ARR_PTRS_DIRTY: + case SMALL_MUT_ARR_PTRS_FROZEN_DIRTY: + return (StgSmallMutArrPtrs*)p->payload[(StgSmallMutArrPtrs*)p->size]; + default: return &p->payload[info->layout.payload.ptrs + info->layout.payload.nptrs]; View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0401d1a52a1d11bda5852f14e9730e38ac4c368c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0401d1a52a1d11bda5852f14e9730e38ac4c368c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 11:37:28 2020 From: gitlab at gitlab.haskell.org (Andreas Klebinger) Date: Mon, 24 Aug 2020 07:37:28 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/andreask/dom-lt-fixes Message-ID: <5f43a678b6f1a_80bac4156c911328@gitlab.haskell.org.mail> Andreas Klebinger pushed new branch wip/andreask/dom-lt-fixes at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/andreask/dom-lt-fixes You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 13:01:10 2020 From: gitlab at gitlab.haskell.org (Andreas Klebinger) Date: Mon, 24 Aug 2020 09:01:10 -0400 Subject: [Git][ghc/ghc][wip/andreask/dom-lt-fixes] Update dominator code with fixes from the dom-lt package. Message-ID: <5f43ba16bd408_80b3f8486857894913451d@gitlab.haskell.org.mail> Andreas Klebinger pushed to branch wip/andreask/dom-lt-fixes at Glasgow Haskell Compiler / GHC Commits: 3c795856 by Andreas Klebinger at 2020-08-24T15:00:59+02:00 Update dominator code with fixes from the dom-lt package. Two bugs turned out in the package that have been fixed since. This MR includes this fixes in the GHC port of the code. - - - - - 1 changed file: - compiler/GHC/CmmToAsm/CFG/Dominators.hs Changes: ===================================== compiler/GHC/CmmToAsm/CFG/Dominators.hs ===================================== @@ -1,15 +1,13 @@ {-# LANGUAGE RankNTypes, BangPatterns, FlexibleContexts, Strict #-} {- | - Module : Dominators + Module : Data.Graph.Dom Copyright : (c) Matt Morrow 2009 License : BSD3 - Maintainer : - Stability : experimental + Maintainer : + Stability : stable Portability : portable - Taken from the dom-lt package. - The Lengauer-Tarjan graph dominators algorithm. \[1\] Lengauer, Tarjan, @@ -22,7 +20,11 @@ /Interference Graphs for Procedures in Static Single/ /Information Form are Interval Graphs/, 2007. - Originally taken from the dom-lt package. + * Strictness + + Unless stated otherwise all exposed functions might fully evaluate their input + but are not guaranteed to do so. + -} module GHC.CmmToAsm.CFG.Dominators ( @@ -39,11 +41,12 @@ module GHC.CmmToAsm.CFG.Dominators ( ) where import GHC.Prelude - +import Data.Monoid(Monoid(..)) import Data.Bifunctor import Data.Tuple (swap) import Data.Tree +import Data.List import Data.IntMap(IntMap) import Data.IntSet(IntSet) import qualified Data.IntMap.Strict as IM @@ -53,12 +56,9 @@ import Control.Monad import Control.Monad.ST.Strict import Data.Array.ST -import Data.Array.Base hiding ((!)) - -- (unsafeNewArray_ - -- ,unsafeWrite,unsafeRead - -- ,readArray,writeArray) - -import GHC.Utils.Misc (debugIsOn) +import Data.Array.Base + (unsafeNewArray_ + ,unsafeWrite,unsafeRead) ----------------------------------------------------------------------------- @@ -152,9 +152,9 @@ idomM = do n <- gets dfsE forM_ [n,n-1..1] (\i-> do w <- ndfsM i - sw <- sdnoM w ps <- predsM w forM_ ps (\v-> do + sw <- sdnoM w u <- eval v su <- sdnoM u when (su < sw) @@ -291,9 +291,10 @@ dfsDom i = do initEnv :: Rooted -> ST s (Env s) initEnv (r0,g0) = do + -- Graph renumbered to indices from 1 to |V| let (g,rnmap) = renum 1 g0 - pred = predG g - r = rnmap IM.! r0 + pred = predG g -- reverse graph + root = rnmap IM.! r0 -- renamed root n = IM.size g ns = [0..n] m = n+1 @@ -315,13 +316,14 @@ initEnv (r0,g0) = do ndfs <- newI m dfn <- newI m + -- Initialize all arrays forM_ [0..n] (doms.=0) forM_ [0..n] (sdno.=0) forM_ [1..n] (size.=1) forM_ [0..n] (ancestor.=0) forM_ [0..n] (child.=0) - (doms.=r) r + (doms.=root) root (size.=0) 0 (label.=0) 0 @@ -329,7 +331,7 @@ initEnv (r0,g0) = do {rnE = rna ,dfsE = 0 ,zeroE = 0 - ,rootE = r + ,rootE = root ,labelE = label ,parentE = parent ,ancestorE = ancestor @@ -364,11 +366,11 @@ domM = fetch domE rootM :: Dom s Node rootM = gets rootE succsM :: Node -> Dom s [Node] -succsM i = gets (IS.toList . (! i) . succE) +succsM i = gets (IS.toList . (!i) . succE) predsM :: Node -> Dom s [Node] -predsM i = gets (IS.toList . (! i) . predE) +predsM i = gets (IS.toList . (!i) . predE) bucketM :: Node -> Dom s [Node] -bucketM i = gets (IS.toList . (! i) . bucketE) +bucketM i = gets (IS.toList . (!i) . bucketE) sizeM :: Node -> Dom s Int sizeM = fetch sizeE sdnoM :: Node -> Dom s Int @@ -400,21 +402,16 @@ type Arr s a = A s Int a infixl 9 !: infixr 2 .= +-- | arr .= x idx => write x to index (.=) :: (MArray (A s) a (ST s)) => Arr s a -> a -> Int -> ST s () -(v .= x) i - | debugIsOn = writeArray v i x - | otherwise = unsafeWrite v i x +(v .= x) i = unsafeWrite v i x (!:) :: (MArray (A s) a (ST s)) => A s Int a -> Int -> ST s a -a !: i - | debugIsOn = do - o <- readArray a i - return $! o - | otherwise = do - o <- unsafeRead a i - return $! o +a !: i = do + o <- unsafeRead a i + return $! o new :: (MArray (A s) a (ST s)) => Int -> ST s (Arr s a) @@ -423,30 +420,10 @@ new n = unsafeNewArray_ (0,n-1) newI :: Int -> ST s (Arr s Int) newI = new --- newD :: Int -> ST s (Arr s Double) --- newD = new - --- dump :: (MArray (A s) a (ST s)) => Arr s a -> ST s [a] --- dump a = do --- (m,n) <- getBounds a --- forM [m..n] (\i -> a!:i) - writes :: (MArray (A s) a (ST s)) => Arr s a -> [(Int,a)] -> ST s () writes a xs = forM_ xs (\(i,x) -> (a.=x) i) --- arr :: (MArray (A s) a (ST s)) => [a] -> ST s (Arr s a) --- arr xs = do --- let n = length xs --- a <- new n --- go a n 0 xs --- return a --- where go _ _ _ [] = return () --- go a n i (x:xs) --- | i <= n = (a.=x) i >> go a n (i+1) xs --- | otherwise = return () - ------------------------------------------------------------------------------ (!) :: Monoid a => IntMap a -> Int -> a (!) g n = maybe mempty id (IM.lookup n g) @@ -466,13 +443,11 @@ toEdges = concatMap (uncurry (fmap . (,))) . toAdj predG :: Graph -> Graph predG g = IM.unionWith IS.union (go g) g0 where g0 = fmap (const mempty) g - f :: IntMap IntSet -> Int -> IntSet -> IntMap IntSet - f m i a = foldl' (\m p -> IM.insertWith mappend p + go = flip IM.foldrWithKey mempty (\i a m -> + foldl' (\m p -> IM.insertWith mappend p (IS.singleton i) m) m - (IS.toList a) - go :: IntMap IntSet -> IntMap IntSet - go = flip IM.foldlWithKey' mempty f + (IS.toList a)) pruneReach :: Rooted -> Rooted pruneReach (r,g) = (r,g2) @@ -522,41 +497,35 @@ collectI (<>) f g (f a) (g a) m) mempty --- collect :: (Ord b) => (c -> c -> c) --- -> (a -> b) -> (a -> c) -> [a] -> Map b c --- collect (<>) f g --- = foldl' (\m a -> SM.insertWith (<>) --- (f a) --- (g a) m) mempty - +-- | renum n g: Rename all nodes +-- +-- Gives nodes sequential names starting at n. +-- Returns the new graph and a mapping. -- (renamed, old -> new) renum :: Int -> Graph -> (Graph, NodeMap Node) renum from = (\(_,m,g)->(g,m)) - . IM.foldlWithKey' - f (from,mempty,mempty) - where - f :: (Int, NodeMap Node, IntMap IntSet) -> Node -> IntSet - -> (Int, NodeMap Node, IntMap IntSet) - f (!n,!env,!new) i ss = - let (j,n2,env2) = go n env i - (n3,env3,ss2) = IS.fold - (\k (!n,!env,!new)-> - case go n env k of - (l,n2,env2)-> (n2,env2,l `IS.insert` new)) - (n2,env2,mempty) ss - new2 = IM.insertWith IS.union j ss2 new - in (n3,env3,new2) - go :: Int - -> NodeMap Node - -> Node - -> (Node,Int,NodeMap Node) - go !n !env i = - case IM.lookup i env of - Just j -> (j,n,env) - Nothing -> (n,n+1,IM.insert i n env) + . IM.foldrWithKey + (\i ss (!n,!env,!new)-> + let (j,n2,env2) = go n env i + (n3,env3,ss2) = IS.fold + (\k (!n,!env,!new)-> + case go n env k of + (l,n2,env2)-> (n2,env2,l `IS.insert` new)) + (n2,env2,mempty) ss + new2 = IM.insertWith IS.union j ss2 new + in (n3,env3,new2)) (from,mempty,mempty) + where go :: Int + -> NodeMap Node + -> Node + -> (Node,Int,NodeMap Node) + go !n !env i = + case IM.lookup i env of + Just j -> (j,n,env) + Nothing -> (n,n+1,IM.insert i n env) ----------------------------------------------------------------------------- +-- Nothing better than reinvinting the state monad. newtype S z s a = S {unS :: forall o. (a -> s -> ST z o) -> s -> ST z o} instance Functor (S z s) where fmap f (S g) = S (\k -> g (k . f)) @@ -594,4 +563,3 @@ fetch :: (MArray (A z) a (ST z)) fetch f i = do a <- gets f st (a!:i) - View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3c79585608738906aa44bfb8b4260a0c111e062f -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3c79585608738906aa44bfb8b4260a0c111e062f You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 13:38:16 2020 From: gitlab at gitlab.haskell.org (Andreas Klebinger) Date: Mon, 24 Aug 2020 09:38:16 -0400 Subject: [Git][ghc/ghc][wip/andreask/dom-lt-fixes] Remove redundant import Message-ID: <5f43c2c8d171d_80b3f842731681c913567f@gitlab.haskell.org.mail> Andreas Klebinger pushed to branch wip/andreask/dom-lt-fixes at Glasgow Haskell Compiler / GHC Commits: fc2f97c3 by Andreas Klebinger at 2020-08-24T15:38:06+02:00 Remove redundant import - - - - - 1 changed file: - compiler/GHC/CmmToAsm/CFG/Dominators.hs Changes: ===================================== compiler/GHC/CmmToAsm/CFG/Dominators.hs ===================================== @@ -1,7 +1,7 @@ {-# LANGUAGE RankNTypes, BangPatterns, FlexibleContexts, Strict #-} {- | - Module : Data.Graph.Dom + Module : GHC.CmmToAsm.CFG.Dominators Copyright : (c) Matt Morrow 2009 License : BSD3 Maintainer : @@ -41,7 +41,6 @@ module GHC.CmmToAsm.CFG.Dominators ( ) where import GHC.Prelude -import Data.Monoid(Monoid(..)) import Data.Bifunctor import Data.Tuple (swap) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fc2f97c3038972c902fa140786c1ed192f5f882c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fc2f97c3038972c902fa140786c1ed192f5f882c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 13:43:06 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Mon, 24 Aug 2020 09:43:06 -0400 Subject: [Git][ghc/ghc][wip/T18223] 14 commits: Put CFG weights into their own module (#17957) Message-ID: <5f43c3ea81b0e_80b3f8495bc8b04913597c@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18223 at Glasgow Haskell Compiler / GHC Commits: 293c7fba by Sylvain Henry at 2020-08-21T09:36:38-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - 50eb4460 by Sylvain Henry at 2020-08-21T09:36:38-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 659eb31b by Sylvain Henry at 2020-08-21T09:36:38-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 2d8ca917 by Sylvain Henry at 2020-08-21T09:37:15-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - fddddbf4 by Vladislav Zavialov at 2020-08-21T09:37:49-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - 989c1c27 by Ben Gamari at 2020-08-21T11:27:53-04:00 gitlab-ci: Test master branch as well While these builds are strictly speaking redundant (since every commit is tested by @marge-bot before making it into `master`), they are nevertheless useful as they are displayed in the branch's commit list in GitLab's web interface. Fixes #18595. - - - - - e67ae884 by Aditya Gupta at 2020-08-22T03:29:00-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - 03cfcfd4 by Wander Hillen at 2020-08-22T03:29:36-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 3f501545 by Craig Ferguson at 2020-08-22T03:30:13-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 8b865092 by Krzysztof Gogolewski at 2020-08-23T14:12:53+02:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - d8f61182 by Krzysztof Gogolewski at 2020-08-23T14:12:56+02:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - 364258e0 by Krzysztof Gogolewski at 2020-08-24T00:32:31-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - b1eb38a0 by Sylvain Henry at 2020-08-24T00:33:13-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - 3d7d1253 by Simon Peyton Jones at 2020-08-24T14:39:21+01:00 Better eta-expansion (again) and don't specilise DFuns This patch fixes #18223, which made GHC generate an exponential amount of code. There are two quite separate changes in here 1. Stop Specialise specalising DFuns. This is the cause of a huge (and utterly unnecessary) blowup in program size in #18223. See Note [Do not specialise DFuns] in GHC.Core.Opt.Specialise. I also refactored the Specialise monad a bit... it was silly, because it passed on unchanging values as if they were mutable state. 2. Re-engineer eta-expansion (again). The eta-expander was generating lots of intermediate stuff, which could be optimised away, but which choked the simplifier meanwhile. Relatively easy to kill it off at source. See Note [The EtaInfo mechanism] in GHC.Core.Opt.Arity. The main new thing is the use of pushCoArg in getArg_maybe. Some smaller consequences * I moved pushCoercion, pushCoArg and friends from SimpleOpt to Arity, because it was needed by the new etaInfoApp. And pushCoValArg now returns a MCoercion rather than Coercion for the argument Coercion. * A minor, incidental improvement to Core pretty-printing This does fix #18223, (which was otherwise uncompilable. Hooray. But there is still a big intermediate because there are some very deeply nested types in that program. Modest reductions in compile-time allocation on a couple of benchmarks 12425 -2.5% 13253 -10.4% MultiLayerModules -0.6% Metric Decrease: T12425 T13253 - - - - - 30 changed files: - .gitlab-ci.yml - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - + compiler/GHC/CmmToAsm/CFG/Weight.hs - compiler/GHC/CmmToAsm/Config.hs - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/Reg/Graph/Base.hs - compiler/GHC/CmmToAsm/Reg/Graph/SpillClean.hs - compiler/GHC/CmmToAsm/X86/CodeGen.hs - compiler/GHC/CmmToAsm/X86/Ppr.hs - compiler/GHC/CmmToLlvm/Base.hs - compiler/GHC/CmmToLlvm/CodeGen.hs - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/DataCon.hs-boot - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/ConstantFold.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/71342296e7d426786bee4466249802cd630ec292...3d7d125322ee4901285871f32317abcb992ce7b3 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/71342296e7d426786bee4466249802cd630ec292...3d7d125322ee4901285871f32317abcb992ce7b3 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 14:04:24 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Mon, 24 Aug 2020 10:04:24 -0400 Subject: [Git][ghc/ghc][master] Add a test for #18397 Message-ID: <5f43c8e8da769_80b3f84693c1eb49138877@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 2 changed files: - + testsuite/tests/codeGen/should_compile/T18397.hs - testsuite/tests/codeGen/should_compile/all.T Changes: ===================================== testsuite/tests/codeGen/should_compile/T18397.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE UnboxedTuples #-} +module T18397 where + +import GHC.Exts +import GHC.ST + +data MutableArray s a = MutableArray (MutableArray# s a) + +runArray# + :: (forall s. ST s (MutableArray s a)) + -> Array# a +runArray# m = case runRW# $ \s -> + case unST m s of { (# s', MutableArray mary# #) -> + unsafeFreezeArray# mary# s'} of (# _, ary# #) -> ary# + +unST :: ST s a -> State# s -> (# State# s, a #) +unST (ST f) = f + ===================================== testsuite/tests/codeGen/should_compile/all.T ===================================== @@ -91,7 +91,11 @@ test('T17648', normal, makefile_test, []) test('T17904', normal, compile, ['-O']) test('T18227A', normal, compile, ['']) test('T18227B', normal, compile, ['']) + +# runRW#-related test('T18291', normal, compile, ['-O0']) +test('T18397', normal, compile, ['-O0']) + test('T15570', when(unregisterised(), skip), compile, ['-Wno-overflowed-literals']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a77b9ec2a6153065565bca7bb154fff35b830b82 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a77b9ec2a6153065565bca7bb154fff35b830b82 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 14:05:04 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Mon, 24 Aug 2020 10:05:04 -0400 Subject: [Git][ghc/ghc][wip/buggymcbugfix/arrayOf-static] rts Message-ID: <5f43c910cc5c8_80b3f84693c1eb49142445@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed to branch wip/buggymcbugfix/arrayOf-static at Glasgow Haskell Compiler / GHC Commits: 6f57a31e by buggymcbugfix at 2020-08-24T16:04:50+02:00 rts - - - - - 2 changed files: - includes/rts/storage/ClosureMacros.h - rts/sm/Evac.c Changes: ===================================== includes/rts/storage/ClosureMacros.h ===================================== @@ -159,27 +159,35 @@ INLINE_HEADER StgHalfWord GET_TAG(const StgClosure *con) /* These are hard-coded. */ #define THUNK_STATIC_LINK(p) (&(p)->payload[1]) -#define IND_STATIC_LINK(p) (&(p)->payload[1]) +#define IND_STATIC_LINK(p) (&(p)->payload[1]) +#define SMALL_MUT_ARR_STATIC_LINK(p) (&((StgSmallMutArrPtrs*)p)->payload[((StgSmallMutArrPtrs*)p)->ptrs]) +#define CONSTR_AND_FUN_STATIC_LINK(info,p) (&(p)->payload[info->layout.payload.ptrs + info->layout.payload.nptrs]) INLINE_HEADER StgClosure ** STATIC_LINK(const StgInfoTable *info, StgClosure *p) { switch (info->type) { + case FUN_STATIC: + case CONSTR: + case CONSTR_1_0: + case CONSTR_2_0: + case CONSTR_1_1: + return CONSTR_AND_FUN_STATIC_LINK(info,p); + case THUNK_STATIC: return THUNK_STATIC_LINK(p); case IND_STATIC: return IND_STATIC_LINK(p); - case SMALL_MUT_ARR_PTRS_CLEAN: - case SMALL_MUT_ARR_PTRS_FROZEN_CLEAN: + // case SMALL_MUT_ARR_PTRS_CLEAN: // TODO: do we really need this case? + // case SMALL_MUT_ARR_PTRS_FROZEN_CLEAN: // TODO: do we really need this case? case SMALL_MUT_ARR_PTRS_DIRTY: case SMALL_MUT_ARR_PTRS_FROZEN_DIRTY: - return (StgSmallMutArrPtrs*)p->payload[(StgSmallMutArrPtrs*)p->size]; + return SMALL_MUT_ARR_STATIC_LINK(p); default: - return &p->payload[info->layout.payload.ptrs + - info->layout.payload.nptrs]; + barf("STATIC_LINK: strange closure type %d", (int)(info->type)); } } ===================================== rts/sm/Evac.c ===================================== @@ -604,7 +604,7 @@ loop: case FUN_STATIC: if (info->srt != 0 || info->layout.payload.ptrs != 0) { - evacuate_static_object(STATIC_LINK(info,(StgClosure *)q), q); + evacuate_static_object(CONSTR_AND_FUN_STATIC_LINK(info,(StgClosure *)q), q); } return; @@ -620,7 +620,7 @@ loop: case CONSTR_1_0: case CONSTR_2_0: case CONSTR_1_1: - evacuate_static_object(STATIC_LINK(info,(StgClosure *)q), q); + evacuate_static_object(CONSTR_AND_FUN_STATIC_LINK(info,(StgClosure *)q), q); return; case CONSTR_0_1: @@ -635,7 +635,7 @@ loop: case SMALL_MUT_ARR_PTRS_FROZEN_CLEAN: // todo: do we even need to evac this case? case SMALL_MUT_ARR_PTRS_DIRTY: case SMALL_MUT_ARR_PTRS_FROZEN_DIRTY: - evacuate_static_object(STATIC_LINK(info,(StgSmallMutArrPtrs*)q), q); + evacuate_static_object(SMALL_MUT_ARR_STATIC_LINK((StgSmallMutArrPtrs*)q), q); return; default: View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6f57a31e4928d6942cc179488b3bb4a6824409b8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6f57a31e4928d6942cc179488b3bb4a6824409b8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 14:05:07 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Mon, 24 Aug 2020 10:05:07 -0400 Subject: [Git][ghc/ghc][master] Avoid roundtrip through SDoc Message-ID: <5f43c913c1367_80b3f846a81b61c9145490@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 1 changed file: - compiler/GHC/CmmToAsm/Dwarf.hs Changes: ===================================== compiler/GHC/CmmToAsm/Dwarf.hs ===================================== @@ -179,9 +179,7 @@ procToDwarf config prc = DwarfSubprogram { dwChildren = map blockToDwarf (dblBlocks prc) , dwName = case dblSourceTick prc of Just s at SourceNote{} -> sourceName s - _otherwise -> renderWithContext defaultSDocContext - $ withPprStyle defaultDumpStyle - $ ppr (dblLabel prc) + _otherwise -> show (dblLabel prc) , dwLabel = dblCLabel prc , dwParent = fmap mkAsmTempDieLabel $ mfilter goodParent View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/05550a5abc369e1cc4fc48def532ca9ba9adcad7 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/05550a5abc369e1cc4fc48def532ca9ba9adcad7 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 15:25:20 2020 From: gitlab at gitlab.haskell.org (David Eichmann) Date: Mon, 24 Aug 2020 11:25:20 -0400 Subject: [Git][ghc/ghc][wip/T17747] 2 commits: Improve primop documentation Message-ID: <5f43dbe0947a5_80b10128008916006b@gitlab.haskell.org.mail> David Eichmann pushed to branch wip/T17747 at Glasgow Haskell Compiler / GHC Commits: fb2fca8f by David Eichmann at 2020-08-24T16:24:01+01:00 Improve primop documentation - - - - - 139d2f44 by David Eichmann at 2020-08-24T16:24:30+01:00 Add test addresses around the start of the heap for test T17747 - - - - - 4 changed files: - compiler/GHC/Builtin/primops.txt.pp - docs/users_guide/exts/ffi.rst - rts/PrimOps.cmm - testsuite/tests/rts/T17747.hs Changes: ===================================== compiler/GHC/Builtin/primops.txt.pp ===================================== @@ -1410,7 +1410,7 @@ section "Byte Arrays" -- It is useful to be able to allocate byte arrays outside of the heap, -- i.e. outside of the memory space covered by the HEAP_ALLOCED() test. -- --- There are two major use cases: +-- There are two major use cases (see issue #17747): -- -- 1. Having foreign memory appear as a normal GHC byte array. This -- are use cases similar to the use of a ForeignPtr, but where it @@ -1422,10 +1422,13 @@ section "Byte Arrays" -- The second is not yet available as it requires additional support -- from the code gen. -- --- A concrete use-case in the first category is to memory map a file +-- An example of the first category can be seen in GHC test T17747. +-- A concrete use-case is to memory map a file -- but have it appear as a ByteArray# rather than a ForeignPtr. Doing --- so of course requires that space is reserved immediatly before the --- file data for the byte array heap object header. +-- so of course requires that space is reserved immediately before the +-- file data for the byte array heap object header. See the +-- placeByteArray# primop documentation below and the FFI section of +-- the user guide for more details. -- -- To have the first use-case work requires a few things: -- @@ -1433,31 +1436,35 @@ section "Byte Arrays" -- the HEAP_ALLOCED space. This is straightforward because the GC -- has support for a number of different closure types to appear -- outside the heap (primarily for statically allocated values), and --- byte arrays are easy because they contain no heap pointers. +-- byte arrays are easy because they contain no heap pointers. See +-- the reference back to this note in `evacuate(StgClosure **p)` in +-- `rts/sm/Evac.c` -- --- * For other primops to not fail when encountering byte arrays --- outside of the heap. Specifically isByteArrayPinned# requires --- special support. This is currently the only primop that needs --- special support. +-- * For all other byte array primops (e.g. shrinkMutableByteArray#, +-- sameMutableByteArray#, isByteArrayPinned#, etc.) to not fail when +-- encountering byte arrays outside of the heap. Specifically +-- isByteArrayPinned# requires special support. This is currently the +-- only primop that needs special support. +-- See Note [isByteArrayPinned# support for off heap byte arrays]. -- -- * A mechanism to set up the heap object header for a byte array at -- an address outside of the HEAP_ALLOCED space. This is needed to -- make the foreign allocated memory look like a byte array. This is -- provided by the placeByteArray# primop. -- --- A concrete use case is to memory map a file but have it appear as a --- ByteArray# rather than a ForeignPtr. Doing so of course requires --- that space is reserved immediatly before the file data for the byte --- array heap object header. --- --- The special support in the isByteArrayPinned# primop is that it --- needs to be able to test if the byte array is HEAP_ALLOCED or not --- and if not then it is certainly pinned. This requires CMM support --- for the HEAP_ALLOCED test, which is otherwise only called from C + +-- Note [isByteArrayPinned# support for off heap byte arrays] +-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-- The isByteArrayPinned# primop is implemented by reading block descriptor +-- flags. Since off heap byte arrays don't have block descriptors, +-- isByteArrayPinned# must explicitly check if the byte array is HEAP_ALLOCED +-- or not. If not HEAP_ALLOCED then it is certainly pinned. This requires CMM +-- support for the HEAP_ALLOCED test, which is otherwise only called from C -- code in the RTS. The current design is to provide full CMM --- implementations of the code to implement HEAP_ALLOCED. This is fast --- but essentially duplicates what is already a complex implementation. --- An alternative would be to use a CMM C call to a C function that use +-- implementations of HEAP_ALLOCED enabled in `rts/sm/HeapAlloc.h` with the +-- CMINUSMINUS cpp flag. This includes HEAP_ALLOCED_CALLISH which essentially +-- duplicates what is already a complex C implementation. This is fast +-- but an alternative would be to use a CMM C call to a C function that use -- the existing C implementation of HEAP_ALLOCED. @@ -1475,8 +1482,14 @@ primop NewByteArrayOp_Char "newByteArray#" GenPrimOp -- See [Byte arrays outside of the HEAP_ALLOCED space] primop PlaceByteArrayOp_Char "placeByteArray#" GenPrimOp Addr# -> Int# -> State# s -> (# State# s, MutableByteArray# s #) - {Place a new byte array header for the specified size (in bytes), at the - specified address outside of the heap, in the specified state thread.} + {Place a new byte array header at the specified address outside of the heap, + for the specified payload size (in bytes), in the specified state thread. In + C code with `#include "Rts.h"`, use `sizeOf(StgArrBytes)` or + `sizeOfW(StgArrBytes)` to get the size of a byte array header in bytes or + words respectively. The caller must ensure `sizeof(StgArrBytes) + n` bytes of + space is allocated at the give address for the heap object header followed by + n bytes of payload. See the FFI section of the user guide for more details + on how to use this primop.} with out_of_line = True has_side_effects = True ===================================== docs/users_guide/exts/ffi.rst ===================================== @@ -788,7 +788,7 @@ Note that the object header size is different for normal and profiling builds. When allocating in foreign memory, space must be made available for this in the memory layout immediately before the data payload. -In C code, ``#include "rts.h"`` and use ``sizeOf(StgArrBytes)`` or +In C code, ``#include "Rts.h"`` and use ``sizeOf(StgArrBytes)`` or ``sizeOfW(StgArrBytes)`` to get the size of a byte array heap object header in bytes or words respectively. This is the space that must be reserved at the memory location immediately before the intended payload. ===================================== rts/PrimOps.cmm ===================================== @@ -74,6 +74,7 @@ stg_newByteArrayzh ( W_ n ) } stg_placeByteArrayzh ( W_ addr, W_ n ) +// Addr# -> Int# -> MutableByteArray# { { /* Place an ARR_WORDS object header at the given address outside the heap. The caller must arrange for space for the heap object header. */ ===================================== testsuite/tests/rts/T17747.hs ===================================== @@ -55,9 +55,12 @@ heapallocedTest = do putStrLn ("HEAP_ALLOCED = " ++ show same ++ "\t(c_HEAP_ALLOCED ptr == cmm_HEAP_ALLOCED ptr)") where - addrs = + heapStart = 0x4200000000 + addrs + -- Addresses around the start of the heap + = [heapStart + offset | offset <- [-1000..1000]] -- 2k address probes, appropriate to the address space - case sizeOf (nullPtr :: Ptr ()) of + ++ case sizeOf (nullPtr :: Ptr ()) of 4 -> [0, 2^21 .. 2^32-1] -- 0 to 4Gb-1 in 2Mb jumps 8 -> [0, 2^30 .. 2^41-1] -- 0 to 2Tb-1 in 1Gb jumps _ -> error "sizeOf ptr not 4 or 8" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6c085a637d1985d92fb70b157986cb5f8401f7ae...139d2f44f3339ff3bee9d5a77aa9be72bf677a9b -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6c085a637d1985d92fb70b157986cb5f8401f7ae...139d2f44f3339ff3bee9d5a77aa9be72bf677a9b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 16:36:28 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Mon, 24 Aug 2020 12:36:28 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: Add a test for #18397 Message-ID: <5f43ec8c3dd67_80b3f8495bc8b04918517b@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 6d2017a9 by Richard Eisenberg at 2020-08-24T12:36:16-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - 569ed083 by Simon Peyton Jones at 2020-08-24T12:36:16-04:00 Use LIdP rather than (XRec p (IdP p)) This patch mainly just replaces use of XRec p (IdP p) with LIdP p One slightly more significant change is to parameterise HsPatSynDetails over the pass rather than the argument type, so that it's uniform with HsConDeclDetails and HsConPatDetails. I also got rid of the dead code GHC.Hs.type.conDetailsArgs But this is all just minor refactoring. No change in functionality. - - - - - 18 changed files: - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/Core/Type.hs - compiler/GHC/Core/Unify.hs - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Extension.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/Match/Constructor.hs - compiler/GHC/HsToCore/Quote.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Parser.y - compiler/GHC/Tc/TyCl/PatSyn.hs - compiler/GHC/Tc/Utils/Zonk.hs - + testsuite/tests/codeGen/should_compile/T18397.hs - testsuite/tests/codeGen/should_compile/all.T Changes: ===================================== compiler/GHC/CmmToAsm/Dwarf.hs ===================================== @@ -179,9 +179,7 @@ procToDwarf config prc = DwarfSubprogram { dwChildren = map blockToDwarf (dblBlocks prc) , dwName = case dblSourceTick prc of Just s at SourceNote{} -> sourceName s - _otherwise -> renderWithContext defaultSDocContext - $ withPprStyle defaultDumpStyle - $ ppr (dblLabel prc) + _otherwise -> show (dblLabel prc) , dwLabel = dblCLabel prc , dwParent = fmap mkAsmTempDieLabel $ mfilter goodParent ===================================== compiler/GHC/Core/Type.hs ===================================== @@ -358,10 +358,28 @@ But in Core these two are treated as identical. We implement this by making 'coreView' convert 'Constraint' to 'TYPE LiftedRep' on the fly. The function tcView (used in the type checker) -does not do this. +does not do this. Accordingly, tcView is used in type-checker-oriented +functions (including the pure unifier, used in instance resolution), +while coreView is used during e.g. optimisation passes. See also #11715, which tracks removing this inconsistency. +The inconsistency actually leads to a potential soundness bug, in that +Constraint and Type are considered *apart* by the type family engine. +To wit, we can write + + type family F a + type instance F Type = Bool + type instance F Constraint = Int + +and (because Type ~# Constraint in Core), thus build a coercion between +Int and Bool. I (Richard E) conjecture that this never happens in practice, +but it's very uncomfortable. This, essentially, is the root problem +underneath #11715, which is quite resistant to an easy fix. The best +idea is to have roles in kind coercions, but that has yet to be implemented. +See also "A Role for Dependent Types in Haskell", ICFP 2019, which describes +how roles in kinds might work out. + -} -- | Gives the typechecker view of a type. This unwraps synonyms but ===================================== compiler/GHC/Core/Unify.hs ===================================== @@ -957,7 +957,7 @@ unify_ty :: UMEnv -- Respects newtypes, PredTypes unify_ty env ty1 ty2 kco - -- TODO: More commentary needed here + -- Use tcView, not coreView. See Note [coreView vs tcView] in GHC.Core.Type. | Just ty1' <- tcView ty1 = unify_ty env ty1' ty2 kco | Just ty2' <- tcView ty2 = unify_ty env ty1 ty2' kco | CastTy ty1' co <- ty1 = if um_unif env @@ -1121,7 +1121,8 @@ uUnrefined :: UMEnv -- We know that tv1 isn't refined uUnrefined env tv1' ty2 ty2' kco - | Just ty2'' <- coreView ty2' + -- Use tcView, not coreView. See Note [coreView vs tcView] in GHC.Core.Type. + | Just ty2'' <- tcView ty2' = uUnrefined env tv1' ty2 ty2'' kco -- Unwrap synonyms -- This is essential, in case we have -- type Foo a = a @@ -1412,6 +1413,8 @@ ty_co_match :: MatchEnv -- ^ ambient helpful info -> Maybe LiftCoEnv ty_co_match menv subst ty co lkco rkco | Just ty' <- coreView ty = ty_co_match menv subst ty' co lkco rkco + -- why coreView here, not tcView? Because we're firmly after type-checking. + -- This function is used only during coercion optimisation. -- handle Refl case: | tyCoVarsOfType ty `isNotInDomainOf` subst ===================================== compiler/GHC/Hs/Binds.hs ===================================== @@ -243,7 +243,7 @@ data HsBindLR idL idR -- type Int -> forall a'. a' -> a' -- Notice that the coercion captures the free a'. - fun_id :: XRec idL (IdP idL), -- Note [fun_id in Match] in GHC.Hs.Expr + fun_id :: LIdP idL, -- Note [fun_id in Match] in GHC.Hs.Expr fun_matches :: MatchGroup idR (LHsExpr idR), -- ^ The payload @@ -369,9 +369,8 @@ type instance XXABExport (GhcPass p) = NoExtCon data PatSynBind idL idR = PSB { psb_ext :: XPSB idL idR, -- ^ Post renaming, FVs. -- See Note [Bind free vars] - psb_id :: XRec idL (IdP idL), -- ^ Name of the pattern synonym - psb_args :: HsPatSynDetails (XRec idR (IdP idR)), - -- ^ Formal parameter names + psb_id :: LIdP idL, -- ^ Name of the pattern synonym + psb_args :: HsPatSynDetails idR, -- ^ Formal parameter names psb_def :: LPat idR, -- ^ Right-hand side psb_dir :: HsPatSynDir idR -- ^ Directionality } @@ -893,7 +892,7 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation TypeSig (XTypeSig pass) - [XRec pass (IdP pass)] -- LHS of the signature; e.g. f,g,h :: blah + [LIdP pass] -- LHS of the signature; e.g. f,g,h :: blah (LHsSigWcType pass) -- RHS of the signature; can have wildcards -- | A pattern synonym type signature @@ -905,7 +904,7 @@ data Sig pass -- 'GHC.Parser.Annotation.AnnDot','GHC.Parser.Annotation.AnnDarrow' -- For details on above see note [Api annotations] in GHC.Parser.Annotation - | PatSynSig (XPatSynSig pass) [XRec pass (IdP pass)] (LHsSigType pass) + | PatSynSig (XPatSynSig pass) [LIdP pass] (LHsSigType pass) -- P :: forall a b. Req => Prov => ty -- | A signature for a class method @@ -918,7 +917,7 @@ data Sig pass -- -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnDefault', -- 'GHC.Parser.Annotation.AnnDcolon' - | ClassOpSig (XClassOpSig pass) Bool [XRec pass (IdP pass)] (LHsSigType pass) + | ClassOpSig (XClassOpSig pass) Bool [LIdP pass] (LHsSigType pass) -- | A type signature in generated code, notably the code -- generated for record selectors. We simply record @@ -950,8 +949,8 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | InlineSig (XInlineSig pass) - (XRec pass (IdP pass)) -- Function name - InlinePragma -- Never defaultInlinePragma + (LIdP pass) -- Function name + InlinePragma -- Never defaultInlinePragma -- | A specialisation pragma -- @@ -966,7 +965,7 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | SpecSig (XSpecSig pass) - (XRec pass (IdP pass)) -- Specialise a function or datatype ... + (LIdP pass) -- Specialise a function or datatype ... [LHsSigType pass] -- ... to these types InlinePragma -- The pragma on SPECIALISE_INLINE form. -- If it's just defaultInlinePragma, then we said @@ -996,7 +995,7 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | MinimalSig (XMinimalSig pass) - SourceText (LBooleanFormula (XRec pass (IdP pass))) + SourceText (LBooleanFormula (LIdP pass)) -- Note [Pragma source text] in GHC.Types.Basic -- | A "set cost centre" pragma for declarations @@ -1008,8 +1007,8 @@ data Sig pass -- > {-# SCC funName "cost_centre_name" #-} | SCCFunSig (XSCCFunSig pass) - SourceText -- Note [Pragma source text] in GHC.Types.Basic - (XRec pass (IdP pass)) -- Function name + SourceText -- Note [Pragma source text] in GHC.Types.Basic + (LIdP pass) -- Function name (Maybe (XRec pass StringLiteral)) -- | A complete match pragma -- @@ -1020,8 +1019,8 @@ data Sig pass -- synonym definitions. | CompleteMatchSig (XCompleteMatchSig pass) SourceText - (XRec pass [XRec pass (IdP pass)]) - (Maybe (XRec pass (IdP pass))) + (XRec pass [LIdP pass]) + (Maybe (LIdP pass)) | XSig !(XXSig pass) type instance XTypeSig (GhcPass p) = NoExtField @@ -1041,7 +1040,7 @@ type instance XXSig (GhcPass p) = NoExtCon type LFixitySig pass = XRec pass (FixitySig pass) -- | Fixity Signature -data FixitySig pass = FixitySig (XFixitySig pass) [XRec pass (IdP pass)] Fixity +data FixitySig pass = FixitySig (XFixitySig pass) [LIdP pass] Fixity | XFixitySig !(XXFixitySig pass) type instance XFixitySig (GhcPass p) = NoExtField @@ -1229,14 +1228,14 @@ pprMinimalSig (L _ bf) = ppr (fmap unLoc bf) -} -- | Haskell Pattern Synonym Details -type HsPatSynDetails arg = HsConDetails arg [RecordPatSynField arg] +type HsPatSynDetails pass = HsConDetails (LIdP pass) [RecordPatSynField (LIdP pass)] -- See Note [Record PatSyn Fields] -- | Record Pattern Synonym Field -data RecordPatSynField a +data RecordPatSynField fld = RecordPatSynField { - recordPatSynSelectorId :: a -- Selector name visible in rest of the file - , recordPatSynPatVar :: a + recordPatSynSelectorId :: fld -- Selector name visible in rest of the file + , recordPatSynPatVar :: fld -- Filled in by renamer, the name used internally -- by the pattern } deriving (Data, Functor) ===================================== compiler/GHC/Hs/Decls.hs ===================================== @@ -592,7 +592,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation SynDecl { tcdSExt :: XSynDecl pass -- ^ Post renameer, FVs - , tcdLName :: XRec pass (IdP pass) -- ^ Type constructor + , tcdLName :: LIdP pass -- ^ Type constructor , tcdTyVars :: LHsQTyVars pass -- ^ Type variables; for an -- associated type these -- include outer binders @@ -609,7 +609,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation DataDecl { tcdDExt :: XDataDecl pass -- ^ Post renamer, CUSK flag, FVs - , tcdLName :: XRec pass (IdP pass) -- ^ Type constructor + , tcdLName :: LIdP pass -- ^ Type constructor , tcdTyVars :: LHsQTyVars pass -- ^ Type variables -- See Note [TyVar binders for associated declarations] , tcdFixity :: LexicalFixity -- ^ Fixity used in the declaration @@ -617,7 +617,7 @@ data TyClDecl pass | ClassDecl { tcdCExt :: XClassDecl pass, -- ^ Post renamer, FVs tcdCtxt :: LHsContext pass, -- ^ Context... - tcdLName :: XRec pass (IdP pass), -- ^ Name of the class + tcdLName :: LIdP pass, -- ^ Name of the class tcdTyVars :: LHsQTyVars pass, -- ^ Class type variables tcdFixity :: LexicalFixity, -- ^ Fixity used in the declaration tcdFDs :: [LHsFunDep pass], -- ^ Functional deps @@ -637,7 +637,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | XTyClDecl !(XXTyClDecl pass) -type LHsFunDep pass = XRec pass (FunDep (XRec pass (IdP pass))) +type LHsFunDep pass = XRec pass (FunDep (LIdP pass)) data DataDeclRn = DataDeclRn { tcdDataCusk :: Bool -- ^ does this have a CUSK? @@ -1135,7 +1135,7 @@ type LFamilyDecl pass = XRec pass (FamilyDecl pass) data FamilyDecl pass = FamilyDecl { fdExt :: XCFamilyDecl pass , fdInfo :: FamilyInfo pass -- type/data, closed/open - , fdLName :: XRec pass (IdP pass) -- type constructor + , fdLName :: LIdP pass -- type constructor , fdTyVars :: LHsQTyVars pass -- type variables -- See Note [TyVar binders for associated declarations] , fdFixity :: LexicalFixity -- Fixity used in the declaration @@ -1168,7 +1168,7 @@ type LInjectivityAnn pass = XRec pass (InjectivityAnn pass) -- -- This will be represented as "InjectivityAnn `r` [`a`, `c`]" data InjectivityAnn pass - = InjectivityAnn (XRec pass (IdP pass)) [XRec pass (IdP pass)] + = InjectivityAnn (LIdP pass) [LIdP pass] -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : -- 'GHC.Parser.Annotation.AnnRarrow', 'GHC.Parser.Annotation.AnnVbar' @@ -1364,7 +1364,7 @@ type LStandaloneKindSig pass = XRec pass (StandaloneKindSig pass) data StandaloneKindSig pass = StandaloneKindSig (XStandaloneKindSig pass) - (XRec pass (IdP pass)) -- Why a single binder? See #16754 + (LIdP pass) -- Why a single binder? See #16754 (LHsSigType pass) -- Why not LHsSigWcType? See Note [Wildcards in standalone kind signatures] | XStandaloneKindSig !(XXStandaloneKindSig pass) @@ -1435,7 +1435,7 @@ type LConDecl pass = XRec pass (ConDecl pass) data ConDecl pass = ConDeclGADT { con_g_ext :: XConDeclGADT pass - , con_names :: [XRec pass (IdP pass)] + , con_names :: [LIdP pass] -- The following fields describe the type after the '::' -- See Note [GADT abstract syntax] @@ -1458,7 +1458,7 @@ data ConDecl pass | ConDeclH98 { con_ext :: XConDeclH98 pass - , con_name :: XRec pass (IdP pass) + , con_name :: LIdP pass , con_forall :: XRec pass Bool -- ^ True <=> explicit user-written forall @@ -1849,7 +1849,7 @@ type FamInstEqn pass rhs = HsImplicitBndrs pass (FamEqn pass rhs) data FamEqn pass rhs = FamEqn { feqn_ext :: XCFamEqn pass rhs - , feqn_tycon :: XRec pass (IdP pass) + , feqn_tycon :: LIdP pass , feqn_bndrs :: Maybe [LHsTyVarBndr () pass] -- ^ Optional quantified type vars , feqn_pats :: HsTyPats pass , feqn_fixity :: LexicalFixity -- ^ Fixity used in the declaration @@ -2214,13 +2214,13 @@ type LForeignDecl pass = XRec pass (ForeignDecl pass) data ForeignDecl pass = ForeignImport { fd_i_ext :: XForeignImport pass -- Post typechecker, rep_ty ~ sig_ty - , fd_name :: XRec pass (IdP pass) -- defines this name + , fd_name :: LIdP pass -- defines this name , fd_sig_ty :: LHsSigType pass -- sig_ty , fd_fi :: ForeignImport } | ForeignExport { fd_e_ext :: XForeignExport pass -- Post typechecker, rep_ty ~ sig_ty - , fd_name :: XRec pass (IdP pass) -- uses this name + , fd_name :: LIdP pass -- uses this name , fd_sig_ty :: LHsSigType pass -- sig_ty , fd_fe :: ForeignExport } -- ^ @@ -2402,8 +2402,8 @@ type LRuleBndr pass = XRec pass (RuleBndr pass) -- | Rule Binder data RuleBndr pass - = RuleBndr (XCRuleBndr pass) (XRec pass (IdP pass)) - | RuleBndrSig (XRuleBndrSig pass) (XRec pass (IdP pass)) (HsPatSigType pass) + = RuleBndr (XCRuleBndr pass) (LIdP pass) + | RuleBndrSig (XRuleBndrSig pass) (LIdP pass) (HsPatSigType pass) | XRuleBndr !(XXRuleBndr pass) -- ^ -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen', @@ -2505,7 +2505,7 @@ type instance XXWarnDecls (GhcPass _) = NoExtCon type LWarnDecl pass = XRec pass (WarnDecl pass) -- | Warning pragma Declaration -data WarnDecl pass = Warning (XWarning pass) [XRec pass (IdP pass)] WarningTxt +data WarnDecl pass = Warning (XWarning pass) [LIdP pass] WarningTxt | XWarnDecl !(XXWarnDecl pass) type instance XWarning (GhcPass _) = NoExtField @@ -2592,7 +2592,7 @@ type LRoleAnnotDecl pass = XRec pass (RoleAnnotDecl pass) -- | Role Annotation Declaration data RoleAnnotDecl pass = RoleAnnotDecl (XCRoleAnnotDecl pass) - (XRec pass (IdP pass)) -- type constructor + (LIdP pass) -- type constructor [XRec pass (Maybe Role)] -- optional annotations -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnType', -- 'GHC.Parser.Annotation.AnnRole' ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -242,9 +242,8 @@ is Less Cool because -- | A Haskell expression. data HsExpr p = HsVar (XVar p) - (XRec p (IdP p)) -- ^ Variable - - -- See Note [Located RdrNames] + (LIdP p) -- ^ Variable + -- See Note [Located RdrNames] | HsUnboundVar (XUnboundVar p) OccName -- ^ Unbound variable; also used for "holes" @@ -439,7 +438,7 @@ data HsExpr p -- For details on above see note [Api annotations] in GHC.Parser.Annotation | RecordCon { rcon_ext :: XRecordCon p - , rcon_con_name :: XRec p (IdP p) -- The constructor name; + , rcon_con_name :: LIdP p -- The constructor name; -- not used after type checking , rcon_flds :: HsRecordBinds p } -- The fields @@ -2987,7 +2986,7 @@ matchSeparator ThPatSplice = panic "unused" matchSeparator ThPatQuote = panic "unused" matchSeparator PatSyn = panic "unused" -pprMatchContext :: Outputable (IdP p) +pprMatchContext :: (Outputable (IdP p), UnXRec p) => HsMatchContext p -> SDoc pprMatchContext ctxt | want_an ctxt = text "an" <+> pprMatchContextNoun ctxt @@ -2997,11 +2996,11 @@ pprMatchContext ctxt want_an ProcExpr = True want_an _ = False -pprMatchContextNoun :: Outputable (IdP id) - => HsMatchContext id -> SDoc -pprMatchContextNoun (FunRhs {mc_fun=L _ fun}) +pprMatchContextNoun :: forall p. (Outputable (IdP p), UnXRec p) + => HsMatchContext p -> SDoc +pprMatchContextNoun (FunRhs {mc_fun=fun}) = text "equation for" - <+> quotes (ppr fun) + <+> quotes (ppr (unXRec @p fun)) pprMatchContextNoun CaseAlt = text "case alternative" pprMatchContextNoun IfAlt = text "multi-way if alternative" pprMatchContextNoun RecUpd = text "record-update construct" @@ -3016,8 +3015,8 @@ pprMatchContextNoun (StmtCtxt ctxt) = text "pattern binding in" pprMatchContextNoun PatSyn = text "pattern synonym declaration" ----------------- -pprAStmtContext, pprStmtContext :: Outputable (IdP id) - => HsStmtContext id -> SDoc +pprAStmtContext, pprStmtContext :: (Outputable (IdP p), UnXRec p) + => HsStmtContext p -> SDoc pprAStmtContext ctxt = article <+> pprStmtContext ctxt where pp_an = text "an" ===================================== compiler/GHC/Hs/Extension.hs ===================================== @@ -307,7 +307,7 @@ type family IdGhcP pass where IdGhcP 'Renamed = Name IdGhcP 'Typechecked = Id -type LIdP p = Located (IdP p) +type LIdP p = XRec p (IdP p) -- | Marks that a field uses the GhcRn variant even when the pass -- parameter is GhcTc. Useful for storing HsTypes in GHC.Hs.Exprs, say, because ===================================== compiler/GHC/Hs/Pat.hs ===================================== @@ -93,7 +93,7 @@ data Pat p -- AZ:TODO above comment needs to be updated | VarPat (XVarPat p) - (XRec p (IdP p)) -- ^ Variable Pattern + (LIdP p) -- ^ Variable Pattern -- See Note [Located RdrNames] in GHC.Hs.Expr | LazyPat (XLazyPat p) @@ -103,7 +103,7 @@ data Pat p -- For details on above see note [Api annotations] in GHC.Parser.Annotation | AsPat (XAsPat p) - (XRec p (IdP p)) (LPat p) -- ^ As pattern + (LIdP p) (LPat p) -- ^ As pattern -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnAt' -- For details on above see note [Api annotations] in GHC.Parser.Annotation @@ -224,7 +224,7 @@ data Pat p -- For details on above see note [Api annotations] in GHC.Parser.Annotation | NPlusKPat (XNPlusKPat p) -- Type of overall pattern - (XRec p (IdP p)) -- n+k pattern + (LIdP p) -- n+k pattern (XRec p (HsOverLit p)) -- It'll always be an HsIntegral (HsOverLit p) -- See Note [NPlusK patterns] in GHC.Tc.Gen.Pat -- NB: This could be (PostTc ...), but that induced a @@ -313,7 +313,7 @@ type instance XXPat GhcTc = CoPat type family ConLikeP x type instance ConLikeP GhcPs = RdrName -- IdP GhcPs -type instance ConLikeP GhcRn = Name -- IdP GhcRn +type instance ConLikeP GhcRn = Name -- IdP GhcRn type instance ConLikeP GhcTc = ConLike -- --------------------------------------------------------------------- ===================================== compiler/GHC/Hs/Type.hs ===================================== @@ -73,7 +73,6 @@ module GHC.Hs.Type ( mkHsOpTy, mkHsAppTy, mkHsAppTys, mkHsAppKindTy, ignoreParens, hsSigType, hsSigWcType, hsPatSigType, hsTyKindSig, - hsConDetailsArgs, setHsTyVarBndrFlag, hsTyVarBndrFlag, -- Printing @@ -638,13 +637,13 @@ data HsTyVarBndr flag pass = UserTyVar -- no explicit kinding (XUserTyVar pass) flag - (XRec pass (IdP pass)) + (LIdP pass) -- See Note [Located RdrNames] in GHC.Hs.Expr | KindedTyVar (XKindedTyVar pass) flag - (XRec pass (IdP pass)) + (LIdP pass) (LHsKind pass) -- The user-supplied kind signature -- ^ -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen', @@ -705,7 +704,7 @@ data HsType pass | HsTyVar (XTyVar pass) PromotionFlag -- Whether explicitly promoted, -- for the pretty printer - (XRec pass (IdP pass)) + (LIdP pass) -- Type variable, type constructor, or data constructor -- see Note [Promotions (HsTyVar)] -- See Note [Located RdrNames] in GHC.Hs.Expr @@ -755,7 +754,7 @@ data HsType pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | HsOpTy (XOpTy pass) - (LHsType pass) (XRec pass (IdP pass)) (LHsType pass) + (LHsType pass) (LIdP pass) (LHsType pass) -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : None -- For details on above see note [Api annotations] in GHC.Parser.Annotation @@ -1116,14 +1115,6 @@ instance (Outputable arg, Outputable rec) ppr (RecCon rec) = text "RecCon:" <+> ppr rec ppr (InfixCon l r) = text "InfixCon:" <+> ppr [l, r] -hsConDetailsArgs :: - HsConDetails (LHsType (GhcPass p)) (Located [LConDeclField (GhcPass p)]) - -> [LHsType (GhcPass p)] -hsConDetailsArgs details = case details of - InfixCon a b -> [a,b] - PrefixCon xs -> xs - RecCon r -> map (cd_fld_type . unLoc) (unLoc r) - {- Note [ConDeclField passs] ~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/Hs/Utils.hs ===================================== @@ -777,7 +777,7 @@ mkVarBind var rhs = L (getLoc rhs) $ VarBind { var_ext = noExtField, var_id = var, var_rhs = rhs } -mkPatSynBind :: Located RdrName -> HsPatSynDetails (Located RdrName) +mkPatSynBind :: Located RdrName -> HsPatSynDetails GhcPs -> LPat GhcPs -> HsPatSynDir GhcPs -> HsBind GhcPs mkPatSynBind name details lpat dir = PatSynBind noExtField psb where @@ -990,7 +990,7 @@ collect_bind omitPatSyn (PatSynBind _ (PSB { psb_id = ps })) acc collect_bind _ (PatSynBind _ (XPatSynBind _)) acc = acc collect_bind _ (XHsBindsLR _) acc = acc -collectMethodBinders :: forall idL idR. UnXRec idL => LHsBindsLR idL idR -> [XRec idL (IdP idL)] +collectMethodBinders :: forall idL idR. UnXRec idL => LHsBindsLR idL idR -> [LIdP idL] -- ^ Used exclusively for the bindings of an instance decl which are all -- 'FunBinds' collectMethodBinders binds = foldr (get . unXRec @idL) [] binds @@ -1173,7 +1173,7 @@ hsLTyClDeclBinders (L loc (DataDecl { tcdLName = (L _ name) ------------------- -hsForeignDeclsBinders :: forall pass. (UnXRec pass, MapXRec pass) => [LForeignDecl pass] -> [XRec pass (IdP pass)] +hsForeignDeclsBinders :: forall pass. (UnXRec pass, MapXRec pass) => [LForeignDecl pass] -> [LIdP pass] -- ^ See Note [SrcSpan for binders] hsForeignDeclsBinders foreign_decls = [ mapXRec @pass (const $ unXRec @pass n) fi ===================================== compiler/GHC/HsToCore/Match/Constructor.hs ===================================== @@ -126,7 +126,7 @@ matchPatSyn (var :| vars) ty eqns PatSynCon psyn -> alt{ alt_pat = psyn } _ -> panic "matchPatSyn: not PatSynCon" -type ConArgPats = HsConDetails (LPat GhcTc) (HsRecFields GhcTc (LPat GhcTc)) +type ConArgPats = HsConPatDetails GhcTc matchOneConLike :: [Id] -> Type ===================================== compiler/GHC/HsToCore/Quote.hs ===================================== @@ -1840,7 +1840,7 @@ rep_bind (L loc (PatSynBind _ (PSB { psb_id = syn ; patSynD'' <- wrapGenArgSyms args ss patSynD' ; return (loc, patSynD'') } where - mkGenArgSyms :: HsPatSynDetails (Located Name) -> MetaM [GenSymBind] + mkGenArgSyms :: HsPatSynDetails GhcRn -> MetaM [GenSymBind] -- for Record Pattern Synonyms we want to conflate the selector -- and the pattern-only names in order to provide a nicer TH -- API. Whereas inside GHC, record pattern synonym selectors and @@ -1859,7 +1859,7 @@ rep_bind (L loc (PatSynBind _ (PSB { psb_id = syn = [ (pat, id) | (sel, id) <- genSyms, (sel', pat) <- selsPats , sel == sel' ] - wrapGenArgSyms :: HsPatSynDetails (Located Name) + wrapGenArgSyms :: HsPatSynDetails GhcRn -> [GenSymBind] -> Core (M TH.Dec) -> MetaM (Core (M TH.Dec)) wrapGenArgSyms (RecCon _) _ dec = return dec wrapGenArgSyms _ ss dec = wrapGenSyms ss dec @@ -1872,7 +1872,7 @@ repPatSynD :: Core TH.Name repPatSynD (MkC syn) (MkC args) (MkC dir) (MkC pat) = rep2 patSynDName [syn, args, dir, pat] -repPatSynArgs :: HsPatSynDetails (Located Name) -> MetaM (Core (M TH.PatSynArgs)) +repPatSynArgs :: HsPatSynDetails GhcRn -> MetaM (Core (M TH.PatSynArgs)) repPatSynArgs (PrefixCon args) = do { args' <- repList nameTyConName lookupLOcc args ; repPrefixPatSynArgs args' } ===================================== compiler/GHC/HsToCore/Utils.hs ===================================== @@ -900,7 +900,7 @@ CPR-friendly. This matters a lot: if you don't get it right, you lose the tail call property. For example, see #3403. -} -dsHandleMonadicFailure :: Outputable (IdP p) => HsStmtContext p -> LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr +dsHandleMonadicFailure :: HsStmtContext GhcRn -> LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr -- In a do expression, pattern-match failure just calls -- the monadic 'fail' rather than throwing an exception dsHandleMonadicFailure ctx pat match m_fail_op = @@ -921,8 +921,9 @@ dsHandleMonadicFailure ctx pat match m_fail_op = fail_expr <- dsSyntaxExpr fail_op [fail_msg] body fail_expr -mk_fail_msg :: Outputable (IdP p) => DynFlags -> HsStmtContext p -> Located e -> String -mk_fail_msg dflags ctx pat = showPpr dflags $ text "Pattern match failure in" <+> pprStmtContext ctx <+> text "at" <+> ppr (getLoc pat) +mk_fail_msg :: DynFlags -> HsStmtContext GhcRn -> Located e -> String +mk_fail_msg dflags ctx pat + = showPpr dflags $ text "Pattern match failure in" <+> pprStmtContext ctx <+> text "at" <+> ppr (getLoc pat) {- ********************************************************************* * * ===================================== compiler/GHC/Parser.y ===================================== @@ -1491,7 +1491,7 @@ pattern_synonym_decl :: { LHsDecl GhcPs } (as ++ ((mj AnnPattern $1:mu AnnLarrow $3:(fst $ unLoc $5))) ) }} -pattern_synonym_lhs :: { (Located RdrName, HsPatSynDetails (Located RdrName), [AddAnn]) } +pattern_synonym_lhs :: { (Located RdrName, HsPatSynDetails GhcPs, [AddAnn]) } : con vars0 { ($1, PrefixCon $2, []) } | varid conop varid { ($2, InfixCon $1 $3, []) } | con '{' cvars1 '}' { ($1, RecCon $3, [moc $2, mcc $4] ) } ===================================== compiler/GHC/Tc/TyCl/PatSyn.hs ===================================== @@ -558,7 +558,7 @@ a pattern synonym. What about the /building/ side? a bad idea. -} -collectPatSynArgInfo :: HsPatSynDetails (Located Name) +collectPatSynArgInfo :: HsPatSynDetails GhcRn -> ([Name], [Name], Bool) collectPatSynArgInfo details = case details of ===================================== compiler/GHC/Tc/Utils/Zonk.hs ===================================== @@ -626,8 +626,8 @@ zonk_bind env (PatSynBind x bind@(PSB { psb_id = L loc id , psb_dir = dir' } } zonkPatSynDetails :: ZonkEnv - -> HsPatSynDetails (Located TcId) - -> HsPatSynDetails (Located Id) + -> HsPatSynDetails GhcTc + -> HsPatSynDetails GhcTc zonkPatSynDetails env (PrefixCon as) = PrefixCon (map (zonkLIdOcc env) as) zonkPatSynDetails env (InfixCon a1 a2) @@ -1450,10 +1450,8 @@ zonk_pat env (XPat (CoPat co_fn pat ty)) zonk_pat _ pat = pprPanic "zonk_pat" (ppr pat) --------------------------- -zonkConStuff :: ZonkEnv - -> HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc)) - -> TcM (ZonkEnv, - HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc))) +zonkConStuff :: ZonkEnv -> HsConPatDetails GhcTc + -> TcM (ZonkEnv, HsConPatDetails GhcTc) zonkConStuff env (PrefixCon pats) = do { (env', pats') <- zonkPats env pats ; return (env', PrefixCon pats') } ===================================== testsuite/tests/codeGen/should_compile/T18397.hs ===================================== @@ -0,0 +1,20 @@ +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE UnboxedTuples #-} +module T18397 where + +import GHC.Exts +import GHC.ST + +data MutableArray s a = MutableArray (MutableArray# s a) + +runArray# + :: (forall s. ST s (MutableArray s a)) + -> Array# a +runArray# m = case runRW# $ \s -> + case unST m s of { (# s', MutableArray mary# #) -> + unsafeFreezeArray# mary# s'} of (# _, ary# #) -> ary# + +unST :: ST s a -> State# s -> (# State# s, a #) +unST (ST f) = f + ===================================== testsuite/tests/codeGen/should_compile/all.T ===================================== @@ -91,7 +91,11 @@ test('T17648', normal, makefile_test, []) test('T17904', normal, compile, ['-O']) test('T18227A', normal, compile, ['']) test('T18227B', normal, compile, ['']) + +# runRW#-related test('T18291', normal, compile, ['-O0']) +test('T18397', normal, compile, ['-O0']) + test('T15570', when(unregisterised(), skip), compile, ['-Wno-overflowed-literals']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fe9ab297d215d12fc467786e538ac1cd89c4a8a1...569ed08314d2f9e7ea36e0df1573f345a1720d18 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fe9ab297d215d12fc467786e538ac1cd89c4a8a1...569ed08314d2f9e7ea36e0df1573f345a1720d18 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 17:20:48 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 13:20:48 -0400 Subject: [Git][ghc/ghc][wip/bump-text] Bump text submodule to 1.2.4.0+ Message-ID: <5f43f6f0d4e96_80b101280089208174@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/bump-text at Glasgow Haskell Compiler / GHC Commits: b7a48700 by Ben Gamari at 2020-08-24T13:20:40-04:00 Bump text submodule to 1.2.4.0+ Fixes #18588 and #17956. - - - - - 1 changed file: - libraries/text Changes: ===================================== libraries/text ===================================== @@ -1 +1 @@ -Subproject commit c6768a2a07e94b8b26d0f0e53517773de1110ce2 +Subproject commit aeed085d8278882101fb43fdf6dc9cbc35f75641 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b7a48700b3cf01e3f4f0346beedd8f52e52fe67c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b7a48700b3cf01e3f4f0346beedd8f52e52fe67c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 17:52:23 2020 From: gitlab at gitlab.haskell.org (Andreas Klebinger) Date: Mon, 24 Aug 2020 13:52:23 -0400 Subject: [Git][ghc/ghc][wip/andreask/dom-lt-fixes] Change line endings, remove redundant import Message-ID: <5f43fe57ef713_80b3f84a401c3dc9212943@gitlab.haskell.org.mail> Andreas Klebinger pushed to branch wip/andreask/dom-lt-fixes at Glasgow Haskell Compiler / GHC Commits: 89a52ee3 by Andreas Klebinger at 2020-08-24T19:52:10+02:00 Change line endings, remove redundant import - - - - - 1 changed file: - compiler/GHC/CmmToAsm/CFG/Dominators.hs Changes: ===================================== compiler/GHC/CmmToAsm/CFG/Dominators.hs ===================================== @@ -1,564 +1,563 @@ -{-# LANGUAGE RankNTypes, BangPatterns, FlexibleContexts, Strict #-} - -{- | - Module : GHC.CmmToAsm.CFG.Dominators - Copyright : (c) Matt Morrow 2009 - License : BSD3 - Maintainer : - Stability : stable - Portability : portable - - The Lengauer-Tarjan graph dominators algorithm. - - \[1\] Lengauer, Tarjan, - /A Fast Algorithm for Finding Dominators in a Flowgraph/, 1979. - - \[2\] Muchnick, - /Advanced Compiler Design and Implementation/, 1997. - - \[3\] Brisk, Sarrafzadeh, - /Interference Graphs for Procedures in Static Single/ - /Information Form are Interval Graphs/, 2007. - - * Strictness - - Unless stated otherwise all exposed functions might fully evaluate their input - but are not guaranteed to do so. - --} - -module GHC.CmmToAsm.CFG.Dominators ( - Node,Path,Edge - ,Graph,Rooted - ,idom,ipdom - ,domTree,pdomTree - ,dom,pdom - ,pddfs,rpddfs - ,fromAdj,fromEdges - ,toAdj,toEdges - ,asTree,asGraph - ,parents,ancestors -) where - -import GHC.Prelude -import Data.Bifunctor -import Data.Tuple (swap) - -import Data.Tree -import Data.List -import Data.IntMap(IntMap) -import Data.IntSet(IntSet) -import qualified Data.IntMap.Strict as IM -import qualified Data.IntSet as IS - -import Control.Monad -import Control.Monad.ST.Strict - -import Data.Array.ST -import Data.Array.Base - (unsafeNewArray_ - ,unsafeWrite,unsafeRead) - ------------------------------------------------------------------------------ - -type Node = Int -type Path = [Node] -type Edge = (Node,Node) -type Graph = IntMap IntSet -type Rooted = (Node, Graph) - ------------------------------------------------------------------------------ - --- | /Dominators/. --- Complexity as for @idom@ -dom :: Rooted -> [(Node, Path)] -dom = ancestors . domTree - --- | /Post-dominators/. --- Complexity as for @idom at . -pdom :: Rooted -> [(Node, Path)] -pdom = ancestors . pdomTree - --- | /Dominator tree/. --- Complexity as for @idom at . -domTree :: Rooted -> Tree Node -domTree a@(r,_) = - let is = filter ((/=r).fst) (idom a) - tg = fromEdges (fmap swap is) - in asTree (r,tg) - --- | /Post-dominator tree/. --- Complexity as for @idom at . -pdomTree :: Rooted -> Tree Node -pdomTree a@(r,_) = - let is = filter ((/=r).fst) (ipdom a) - tg = fromEdges (fmap swap is) - in asTree (r,tg) - --- | /Immediate dominators/. --- /O(|E|*alpha(|E|,|V|))/, where /alpha(m,n)/ is --- \"a functional inverse of Ackermann's function\". --- --- This Complexity bound assumes /O(1)/ indexing. Since we're --- using @IntMap@, it has an additional /lg |V|/ factor --- somewhere in there. I'm not sure where. -idom :: Rooted -> [(Node,Node)] -idom rg = runST (evalS idomM =<< initEnv (pruneReach rg)) - --- | /Immediate post-dominators/. --- Complexity as for @idom at . -ipdom :: Rooted -> [(Node,Node)] -ipdom rg = runST (evalS idomM =<< initEnv (pruneReach (second predG rg))) - ------------------------------------------------------------------------------ - --- | /Post-dominated depth-first search/. -pddfs :: Rooted -> [Node] -pddfs = reverse . rpddfs - --- | /Reverse post-dominated depth-first search/. -rpddfs :: Rooted -> [Node] -rpddfs = concat . levels . pdomTree - ------------------------------------------------------------------------------ - -type Dom s a = S s (Env s) a -type NodeSet = IntSet -type NodeMap a = IntMap a -data Env s = Env - {succE :: !Graph - ,predE :: !Graph - ,bucketE :: !Graph - ,dfsE :: {-# UNPACK #-}!Int - ,zeroE :: {-# UNPACK #-}!Node - ,rootE :: {-# UNPACK #-}!Node - ,labelE :: {-# UNPACK #-}!(Arr s Node) - ,parentE :: {-# UNPACK #-}!(Arr s Node) - ,ancestorE :: {-# UNPACK #-}!(Arr s Node) - ,childE :: {-# UNPACK #-}!(Arr s Node) - ,ndfsE :: {-# UNPACK #-}!(Arr s Node) - ,dfnE :: {-# UNPACK #-}!(Arr s Int) - ,sdnoE :: {-# UNPACK #-}!(Arr s Int) - ,sizeE :: {-# UNPACK #-}!(Arr s Int) - ,domE :: {-# UNPACK #-}!(Arr s Node) - ,rnE :: {-# UNPACK #-}!(Arr s Node)} - ------------------------------------------------------------------------------ - -idomM :: Dom s [(Node,Node)] -idomM = do - dfsDom =<< rootM - n <- gets dfsE - forM_ [n,n-1..1] (\i-> do - w <- ndfsM i - ps <- predsM w - forM_ ps (\v-> do - sw <- sdnoM w - u <- eval v - su <- sdnoM u - when (su < sw) - (store sdnoE w su)) - z <- ndfsM =<< sdnoM w - modify(\e->e{bucketE=IM.adjust - (w`IS.insert`) - z (bucketE e)}) - pw <- parentM w - link pw w - bps <- bucketM pw - forM_ bps (\v-> do - u <- eval v - su <- sdnoM u - sv <- sdnoM v - let dv = case su < sv of - True-> u - False-> pw - store domE v dv)) - forM_ [1..n] (\i-> do - w <- ndfsM i - j <- sdnoM w - z <- ndfsM j - dw <- domM w - when (dw /= z) - (do ddw <- domM dw - store domE w ddw)) - fromEnv - ------------------------------------------------------------------------------ - -eval :: Node -> Dom s Node -eval v = do - n0 <- zeroM - a <- ancestorM v - case a==n0 of - True-> labelM v - False-> do - compress v - a <- ancestorM v - l <- labelM v - la <- labelM a - sl <- sdnoM l - sla <- sdnoM la - case sl <= sla of - True-> return l - False-> return la - -compress :: Node -> Dom s () -compress v = do - n0 <- zeroM - a <- ancestorM v - aa <- ancestorM a - when (aa /= n0) (do - compress a - a <- ancestorM v - aa <- ancestorM a - l <- labelM v - la <- labelM a - sl <- sdnoM l - sla <- sdnoM la - when (sla < sl) - (store labelE v la) - store ancestorE v aa) - ------------------------------------------------------------------------------ - -link :: Node -> Node -> Dom s () -link v w = do - n0 <- zeroM - lw <- labelM w - slw <- sdnoM lw - let balance s = do - c <- childM s - lc <- labelM c - slc <- sdnoM lc - case slw < slc of - False-> return s - True-> do - zs <- sizeM s - zc <- sizeM c - cc <- childM c - zcc <- sizeM cc - case 2*zc <= zs+zcc of - True-> do - store ancestorE c s - store childE s cc - balance s - False-> do - store sizeE c zs - store ancestorE s c - balance c - s <- balance w - lw <- labelM w - zw <- sizeM w - store labelE s lw - store sizeE v . (+zw) =<< sizeM v - let follow s = do - when (s /= n0) (do - store ancestorE s v - follow =<< childM s) - zv <- sizeM v - follow =<< case zv < 2*zw of - False-> return s - True-> do - cv <- childM v - store childE v s - return cv - ------------------------------------------------------------------------------ - -dfsDom :: Node -> Dom s () -dfsDom i = do - _ <- go i - n0 <- zeroM - r <- rootM - store parentE r n0 - where go i = do - n <- nextM - store dfnE i n - store sdnoE i n - store ndfsE n i - store labelE i i - ss <- succsM i - forM_ ss (\j-> do - s <- sdnoM j - case s==0 of - False-> return() - True-> do - store parentE j i - go j) - ------------------------------------------------------------------------------ - -initEnv :: Rooted -> ST s (Env s) -initEnv (r0,g0) = do - -- Graph renumbered to indices from 1 to |V| - let (g,rnmap) = renum 1 g0 - pred = predG g -- reverse graph - root = rnmap IM.! r0 -- renamed root - n = IM.size g - ns = [0..n] - m = n+1 - - let bucket = IM.fromList - (zip ns (repeat mempty)) - - rna <- newI m - writes rna (fmap swap - (IM.toList rnmap)) - - doms <- newI m - sdno <- newI m - size <- newI m - parent <- newI m - ancestor <- newI m - child <- newI m - label <- newI m - ndfs <- newI m - dfn <- newI m - - -- Initialize all arrays - forM_ [0..n] (doms.=0) - forM_ [0..n] (sdno.=0) - forM_ [1..n] (size.=1) - forM_ [0..n] (ancestor.=0) - forM_ [0..n] (child.=0) - - (doms.=root) root - (size.=0) 0 - (label.=0) 0 - - return (Env - {rnE = rna - ,dfsE = 0 - ,zeroE = 0 - ,rootE = root - ,labelE = label - ,parentE = parent - ,ancestorE = ancestor - ,childE = child - ,ndfsE = ndfs - ,dfnE = dfn - ,sdnoE = sdno - ,sizeE = size - ,succE = g - ,predE = pred - ,bucketE = bucket - ,domE = doms}) - -fromEnv :: Dom s [(Node,Node)] -fromEnv = do - dom <- gets domE - rn <- gets rnE - -- r <- gets rootE - (_,n) <- st (getBounds dom) - forM [1..n] (\i-> do - j <- st(rn!:i) - d <- st(dom!:i) - k <- st(rn!:d) - return (j,k)) - ------------------------------------------------------------------------------ - -zeroM :: Dom s Node -zeroM = gets zeroE -domM :: Node -> Dom s Node -domM = fetch domE -rootM :: Dom s Node -rootM = gets rootE -succsM :: Node -> Dom s [Node] -succsM i = gets (IS.toList . (!i) . succE) -predsM :: Node -> Dom s [Node] -predsM i = gets (IS.toList . (!i) . predE) -bucketM :: Node -> Dom s [Node] -bucketM i = gets (IS.toList . (!i) . bucketE) -sizeM :: Node -> Dom s Int -sizeM = fetch sizeE -sdnoM :: Node -> Dom s Int -sdnoM = fetch sdnoE --- dfnM :: Node -> Dom s Int --- dfnM = fetch dfnE -ndfsM :: Int -> Dom s Node -ndfsM = fetch ndfsE -childM :: Node -> Dom s Node -childM = fetch childE -ancestorM :: Node -> Dom s Node -ancestorM = fetch ancestorE -parentM :: Node -> Dom s Node -parentM = fetch parentE -labelM :: Node -> Dom s Node -labelM = fetch labelE -nextM :: Dom s Int -nextM = do - n <- gets dfsE - let n' = n+1 - modify(\e->e{dfsE=n'}) - return n' - ------------------------------------------------------------------------------ - -type A = STUArray -type Arr s a = A s Int a - -infixl 9 !: -infixr 2 .= - --- | arr .= x idx => write x to index -(.=) :: (MArray (A s) a (ST s)) - => Arr s a -> a -> Int -> ST s () -(v .= x) i = unsafeWrite v i x - -(!:) :: (MArray (A s) a (ST s)) - => A s Int a -> Int -> ST s a -a !: i = do - o <- unsafeRead a i - return $! o - -new :: (MArray (A s) a (ST s)) - => Int -> ST s (Arr s a) -new n = unsafeNewArray_ (0,n-1) - -newI :: Int -> ST s (Arr s Int) -newI = new - -writes :: (MArray (A s) a (ST s)) - => Arr s a -> [(Int,a)] -> ST s () -writes a xs = forM_ xs (\(i,x) -> (a.=x) i) - - -(!) :: Monoid a => IntMap a -> Int -> a -(!) g n = maybe mempty id (IM.lookup n g) - -fromAdj :: [(Node, [Node])] -> Graph -fromAdj = IM.fromList . fmap (second IS.fromList) - -fromEdges :: [Edge] -> Graph -fromEdges = collectI IS.union fst (IS.singleton . snd) - -toAdj :: Graph -> [(Node, [Node])] -toAdj = fmap (second IS.toList) . IM.toList - -toEdges :: Graph -> [Edge] -toEdges = concatMap (uncurry (fmap . (,))) . toAdj - -predG :: Graph -> Graph -predG g = IM.unionWith IS.union (go g) g0 - where g0 = fmap (const mempty) g - go = flip IM.foldrWithKey mempty (\i a m -> - foldl' (\m p -> IM.insertWith mappend p - (IS.singleton i) m) - m - (IS.toList a)) - -pruneReach :: Rooted -> Rooted -pruneReach (r,g) = (r,g2) - where is = reachable - (maybe mempty id - . flip IM.lookup g) $ r - g2 = IM.fromList - . fmap (second (IS.filter (`IS.member`is))) - . filter ((`IS.member`is) . fst) - . IM.toList $ g - -tip :: Tree a -> (a, [Tree a]) -tip (Node a ts) = (a, ts) - -parents :: Tree a -> [(a, a)] -parents (Node i xs) = p i xs - ++ concatMap parents xs - where p i = fmap (flip (,) i . rootLabel) - -ancestors :: Tree a -> [(a, [a])] -ancestors = go [] - where go acc (Node i xs) - = let acc' = i:acc - in p acc' xs ++ concatMap (go acc') xs - p is = fmap (flip (,) is . rootLabel) - -asGraph :: Tree Node -> Rooted -asGraph t@(Node a _) = let g = go t in (a, fromAdj g) - where go (Node a ts) = let as = (fst . unzip . fmap tip) ts - in (a, as) : concatMap go ts - -asTree :: Rooted -> Tree Node -asTree (r,g) = let go a = Node a (fmap go ((IS.toList . f) a)) - f = (g !) - in go r - -reachable :: (Node -> NodeSet) -> (Node -> NodeSet) -reachable f a = go (IS.singleton a) a - where go seen a = let s = f a - as = IS.toList (s `IS.difference` seen) - in foldl' go (s `IS.union` seen) as - -collectI :: (c -> c -> c) - -> (a -> Int) -> (a -> c) -> [a] -> IntMap c -collectI (<>) f g - = foldl' (\m a -> IM.insertWith (<>) - (f a) - (g a) m) mempty - --- | renum n g: Rename all nodes --- --- Gives nodes sequential names starting at n. --- Returns the new graph and a mapping. --- (renamed, old -> new) -renum :: Int -> Graph -> (Graph, NodeMap Node) -renum from = (\(_,m,g)->(g,m)) - . IM.foldrWithKey - (\i ss (!n,!env,!new)-> - let (j,n2,env2) = go n env i - (n3,env3,ss2) = IS.fold - (\k (!n,!env,!new)-> - case go n env k of - (l,n2,env2)-> (n2,env2,l `IS.insert` new)) - (n2,env2,mempty) ss - new2 = IM.insertWith IS.union j ss2 new - in (n3,env3,new2)) (from,mempty,mempty) - where go :: Int - -> NodeMap Node - -> Node - -> (Node,Int,NodeMap Node) - go !n !env i = - case IM.lookup i env of - Just j -> (j,n,env) - Nothing -> (n,n+1,IM.insert i n env) - ------------------------------------------------------------------------------ - --- Nothing better than reinvinting the state monad. -newtype S z s a = S {unS :: forall o. (a -> s -> ST z o) -> s -> ST z o} -instance Functor (S z s) where - fmap f (S g) = S (\k -> g (k . f)) -instance Monad (S z s) where - return = pure - S g >>= f = S (\k -> g (\a -> unS (f a) k)) -instance Applicative (S z s) where - pure a = S (\k -> k a) - (<*>) = ap --- get :: S z s s --- get = S (\k s -> k s s) -gets :: (s -> a) -> S z s a -gets f = S (\k s -> k (f s) s) --- set :: s -> S z s () --- set s = S (\k _ -> k () s) -modify :: (s -> s) -> S z s () -modify f = S (\k -> k () . f) --- runS :: S z s a -> s -> ST z (a, s) --- runS (S g) = g (\a s -> return (a,s)) -evalS :: S z s a -> s -> ST z a -evalS (S g) = g ((return .) . const) --- execS :: S z s a -> s -> ST z s --- execS (S g) = g ((return .) . flip const) -st :: ST z a -> S z s a -st m = S (\k s-> do - a <- m - k a s) -store :: (MArray (A z) a (ST z)) - => (s -> Arr z a) -> Int -> a -> S z s () -store f i x = do - a <- gets f - st ((a.=x) i) -fetch :: (MArray (A z) a (ST z)) - => (s -> Arr z a) -> Int -> S z s a -fetch f i = do - a <- gets f - st (a!:i) +{-# LANGUAGE RankNTypes, BangPatterns, FlexibleContexts, Strict #-} + +{- | + Module : GHC.CmmToAsm.CFG.Dominators + Copyright : (c) Matt Morrow 2009 + License : BSD3 + Maintainer : + Stability : stable + Portability : portable + + The Lengauer-Tarjan graph dominators algorithm. + + \[1\] Lengauer, Tarjan, + /A Fast Algorithm for Finding Dominators in a Flowgraph/, 1979. + + \[2\] Muchnick, + /Advanced Compiler Design and Implementation/, 1997. + + \[3\] Brisk, Sarrafzadeh, + /Interference Graphs for Procedures in Static Single/ + /Information Form are Interval Graphs/, 2007. + + * Strictness + + Unless stated otherwise all exposed functions might fully evaluate their input + but are not guaranteed to do so. + +-} + +module GHC.CmmToAsm.CFG.Dominators ( + Node,Path,Edge + ,Graph,Rooted + ,idom,ipdom + ,domTree,pdomTree + ,dom,pdom + ,pddfs,rpddfs + ,fromAdj,fromEdges + ,toAdj,toEdges + ,asTree,asGraph + ,parents,ancestors +) where + +import GHC.Prelude +import Data.Bifunctor +import Data.Tuple (swap) + +import Data.Tree +import Data.IntMap(IntMap) +import Data.IntSet(IntSet) +import qualified Data.IntMap.Strict as IM +import qualified Data.IntSet as IS + +import Control.Monad +import Control.Monad.ST.Strict + +import Data.Array.ST +import Data.Array.Base + (unsafeNewArray_ + ,unsafeWrite,unsafeRead) + +----------------------------------------------------------------------------- + +type Node = Int +type Path = [Node] +type Edge = (Node,Node) +type Graph = IntMap IntSet +type Rooted = (Node, Graph) + +----------------------------------------------------------------------------- + +-- | /Dominators/. +-- Complexity as for @idom@ +dom :: Rooted -> [(Node, Path)] +dom = ancestors . domTree + +-- | /Post-dominators/. +-- Complexity as for @idom at . +pdom :: Rooted -> [(Node, Path)] +pdom = ancestors . pdomTree + +-- | /Dominator tree/. +-- Complexity as for @idom at . +domTree :: Rooted -> Tree Node +domTree a@(r,_) = + let is = filter ((/=r).fst) (idom a) + tg = fromEdges (fmap swap is) + in asTree (r,tg) + +-- | /Post-dominator tree/. +-- Complexity as for @idom at . +pdomTree :: Rooted -> Tree Node +pdomTree a@(r,_) = + let is = filter ((/=r).fst) (ipdom a) + tg = fromEdges (fmap swap is) + in asTree (r,tg) + +-- | /Immediate dominators/. +-- /O(|E|*alpha(|E|,|V|))/, where /alpha(m,n)/ is +-- \"a functional inverse of Ackermann's function\". +-- +-- This Complexity bound assumes /O(1)/ indexing. Since we're +-- using @IntMap@, it has an additional /lg |V|/ factor +-- somewhere in there. I'm not sure where. +idom :: Rooted -> [(Node,Node)] +idom rg = runST (evalS idomM =<< initEnv (pruneReach rg)) + +-- | /Immediate post-dominators/. +-- Complexity as for @idom at . +ipdom :: Rooted -> [(Node,Node)] +ipdom rg = runST (evalS idomM =<< initEnv (pruneReach (second predG rg))) + +----------------------------------------------------------------------------- + +-- | /Post-dominated depth-first search/. +pddfs :: Rooted -> [Node] +pddfs = reverse . rpddfs + +-- | /Reverse post-dominated depth-first search/. +rpddfs :: Rooted -> [Node] +rpddfs = concat . levels . pdomTree + +----------------------------------------------------------------------------- + +type Dom s a = S s (Env s) a +type NodeSet = IntSet +type NodeMap a = IntMap a +data Env s = Env + {succE :: !Graph + ,predE :: !Graph + ,bucketE :: !Graph + ,dfsE :: {-# UNPACK #-}!Int + ,zeroE :: {-# UNPACK #-}!Node + ,rootE :: {-# UNPACK #-}!Node + ,labelE :: {-# UNPACK #-}!(Arr s Node) + ,parentE :: {-# UNPACK #-}!(Arr s Node) + ,ancestorE :: {-# UNPACK #-}!(Arr s Node) + ,childE :: {-# UNPACK #-}!(Arr s Node) + ,ndfsE :: {-# UNPACK #-}!(Arr s Node) + ,dfnE :: {-# UNPACK #-}!(Arr s Int) + ,sdnoE :: {-# UNPACK #-}!(Arr s Int) + ,sizeE :: {-# UNPACK #-}!(Arr s Int) + ,domE :: {-# UNPACK #-}!(Arr s Node) + ,rnE :: {-# UNPACK #-}!(Arr s Node)} + +----------------------------------------------------------------------------- + +idomM :: Dom s [(Node,Node)] +idomM = do + dfsDom =<< rootM + n <- gets dfsE + forM_ [n,n-1..1] (\i-> do + w <- ndfsM i + ps <- predsM w + forM_ ps (\v-> do + sw <- sdnoM w + u <- eval v + su <- sdnoM u + when (su < sw) + (store sdnoE w su)) + z <- ndfsM =<< sdnoM w + modify(\e->e{bucketE=IM.adjust + (w`IS.insert`) + z (bucketE e)}) + pw <- parentM w + link pw w + bps <- bucketM pw + forM_ bps (\v-> do + u <- eval v + su <- sdnoM u + sv <- sdnoM v + let dv = case su < sv of + True-> u + False-> pw + store domE v dv)) + forM_ [1..n] (\i-> do + w <- ndfsM i + j <- sdnoM w + z <- ndfsM j + dw <- domM w + when (dw /= z) + (do ddw <- domM dw + store domE w ddw)) + fromEnv + +----------------------------------------------------------------------------- + +eval :: Node -> Dom s Node +eval v = do + n0 <- zeroM + a <- ancestorM v + case a==n0 of + True-> labelM v + False-> do + compress v + a <- ancestorM v + l <- labelM v + la <- labelM a + sl <- sdnoM l + sla <- sdnoM la + case sl <= sla of + True-> return l + False-> return la + +compress :: Node -> Dom s () +compress v = do + n0 <- zeroM + a <- ancestorM v + aa <- ancestorM a + when (aa /= n0) (do + compress a + a <- ancestorM v + aa <- ancestorM a + l <- labelM v + la <- labelM a + sl <- sdnoM l + sla <- sdnoM la + when (sla < sl) + (store labelE v la) + store ancestorE v aa) + +----------------------------------------------------------------------------- + +link :: Node -> Node -> Dom s () +link v w = do + n0 <- zeroM + lw <- labelM w + slw <- sdnoM lw + let balance s = do + c <- childM s + lc <- labelM c + slc <- sdnoM lc + case slw < slc of + False-> return s + True-> do + zs <- sizeM s + zc <- sizeM c + cc <- childM c + zcc <- sizeM cc + case 2*zc <= zs+zcc of + True-> do + store ancestorE c s + store childE s cc + balance s + False-> do + store sizeE c zs + store ancestorE s c + balance c + s <- balance w + lw <- labelM w + zw <- sizeM w + store labelE s lw + store sizeE v . (+zw) =<< sizeM v + let follow s = do + when (s /= n0) (do + store ancestorE s v + follow =<< childM s) + zv <- sizeM v + follow =<< case zv < 2*zw of + False-> return s + True-> do + cv <- childM v + store childE v s + return cv + +----------------------------------------------------------------------------- + +dfsDom :: Node -> Dom s () +dfsDom i = do + _ <- go i + n0 <- zeroM + r <- rootM + store parentE r n0 + where go i = do + n <- nextM + store dfnE i n + store sdnoE i n + store ndfsE n i + store labelE i i + ss <- succsM i + forM_ ss (\j-> do + s <- sdnoM j + case s==0 of + False-> return() + True-> do + store parentE j i + go j) + +----------------------------------------------------------------------------- + +initEnv :: Rooted -> ST s (Env s) +initEnv (r0,g0) = do + -- Graph renumbered to indices from 1 to |V| + let (g,rnmap) = renum 1 g0 + pred = predG g -- reverse graph + root = rnmap IM.! r0 -- renamed root + n = IM.size g + ns = [0..n] + m = n+1 + + let bucket = IM.fromList + (zip ns (repeat mempty)) + + rna <- newI m + writes rna (fmap swap + (IM.toList rnmap)) + + doms <- newI m + sdno <- newI m + size <- newI m + parent <- newI m + ancestor <- newI m + child <- newI m + label <- newI m + ndfs <- newI m + dfn <- newI m + + -- Initialize all arrays + forM_ [0..n] (doms.=0) + forM_ [0..n] (sdno.=0) + forM_ [1..n] (size.=1) + forM_ [0..n] (ancestor.=0) + forM_ [0..n] (child.=0) + + (doms.=root) root + (size.=0) 0 + (label.=0) 0 + + return (Env + {rnE = rna + ,dfsE = 0 + ,zeroE = 0 + ,rootE = root + ,labelE = label + ,parentE = parent + ,ancestorE = ancestor + ,childE = child + ,ndfsE = ndfs + ,dfnE = dfn + ,sdnoE = sdno + ,sizeE = size + ,succE = g + ,predE = pred + ,bucketE = bucket + ,domE = doms}) + +fromEnv :: Dom s [(Node,Node)] +fromEnv = do + dom <- gets domE + rn <- gets rnE + -- r <- gets rootE + (_,n) <- st (getBounds dom) + forM [1..n] (\i-> do + j <- st(rn!:i) + d <- st(dom!:i) + k <- st(rn!:d) + return (j,k)) + +----------------------------------------------------------------------------- + +zeroM :: Dom s Node +zeroM = gets zeroE +domM :: Node -> Dom s Node +domM = fetch domE +rootM :: Dom s Node +rootM = gets rootE +succsM :: Node -> Dom s [Node] +succsM i = gets (IS.toList . (!i) . succE) +predsM :: Node -> Dom s [Node] +predsM i = gets (IS.toList . (!i) . predE) +bucketM :: Node -> Dom s [Node] +bucketM i = gets (IS.toList . (!i) . bucketE) +sizeM :: Node -> Dom s Int +sizeM = fetch sizeE +sdnoM :: Node -> Dom s Int +sdnoM = fetch sdnoE +-- dfnM :: Node -> Dom s Int +-- dfnM = fetch dfnE +ndfsM :: Int -> Dom s Node +ndfsM = fetch ndfsE +childM :: Node -> Dom s Node +childM = fetch childE +ancestorM :: Node -> Dom s Node +ancestorM = fetch ancestorE +parentM :: Node -> Dom s Node +parentM = fetch parentE +labelM :: Node -> Dom s Node +labelM = fetch labelE +nextM :: Dom s Int +nextM = do + n <- gets dfsE + let n' = n+1 + modify(\e->e{dfsE=n'}) + return n' + +----------------------------------------------------------------------------- + +type A = STUArray +type Arr s a = A s Int a + +infixl 9 !: +infixr 2 .= + +-- | arr .= x idx => write x to index +(.=) :: (MArray (A s) a (ST s)) + => Arr s a -> a -> Int -> ST s () +(v .= x) i = unsafeWrite v i x + +(!:) :: (MArray (A s) a (ST s)) + => A s Int a -> Int -> ST s a +a !: i = do + o <- unsafeRead a i + return $! o + +new :: (MArray (A s) a (ST s)) + => Int -> ST s (Arr s a) +new n = unsafeNewArray_ (0,n-1) + +newI :: Int -> ST s (Arr s Int) +newI = new + +writes :: (MArray (A s) a (ST s)) + => Arr s a -> [(Int,a)] -> ST s () +writes a xs = forM_ xs (\(i,x) -> (a.=x) i) + + +(!) :: Monoid a => IntMap a -> Int -> a +(!) g n = maybe mempty id (IM.lookup n g) + +fromAdj :: [(Node, [Node])] -> Graph +fromAdj = IM.fromList . fmap (second IS.fromList) + +fromEdges :: [Edge] -> Graph +fromEdges = collectI IS.union fst (IS.singleton . snd) + +toAdj :: Graph -> [(Node, [Node])] +toAdj = fmap (second IS.toList) . IM.toList + +toEdges :: Graph -> [Edge] +toEdges = concatMap (uncurry (fmap . (,))) . toAdj + +predG :: Graph -> Graph +predG g = IM.unionWith IS.union (go g) g0 + where g0 = fmap (const mempty) g + go = flip IM.foldrWithKey mempty (\i a m -> + foldl' (\m p -> IM.insertWith mappend p + (IS.singleton i) m) + m + (IS.toList a)) + +pruneReach :: Rooted -> Rooted +pruneReach (r,g) = (r,g2) + where is = reachable + (maybe mempty id + . flip IM.lookup g) $ r + g2 = IM.fromList + . fmap (second (IS.filter (`IS.member`is))) + . filter ((`IS.member`is) . fst) + . IM.toList $ g + +tip :: Tree a -> (a, [Tree a]) +tip (Node a ts) = (a, ts) + +parents :: Tree a -> [(a, a)] +parents (Node i xs) = p i xs + ++ concatMap parents xs + where p i = fmap (flip (,) i . rootLabel) + +ancestors :: Tree a -> [(a, [a])] +ancestors = go [] + where go acc (Node i xs) + = let acc' = i:acc + in p acc' xs ++ concatMap (go acc') xs + p is = fmap (flip (,) is . rootLabel) + +asGraph :: Tree Node -> Rooted +asGraph t@(Node a _) = let g = go t in (a, fromAdj g) + where go (Node a ts) = let as = (fst . unzip . fmap tip) ts + in (a, as) : concatMap go ts + +asTree :: Rooted -> Tree Node +asTree (r,g) = let go a = Node a (fmap go ((IS.toList . f) a)) + f = (g !) + in go r + +reachable :: (Node -> NodeSet) -> (Node -> NodeSet) +reachable f a = go (IS.singleton a) a + where go seen a = let s = f a + as = IS.toList (s `IS.difference` seen) + in foldl' go (s `IS.union` seen) as + +collectI :: (c -> c -> c) + -> (a -> Int) -> (a -> c) -> [a] -> IntMap c +collectI (<>) f g + = foldl' (\m a -> IM.insertWith (<>) + (f a) + (g a) m) mempty + +-- | renum n g: Rename all nodes +-- +-- Gives nodes sequential names starting at n. +-- Returns the new graph and a mapping. +-- (renamed, old -> new) +renum :: Int -> Graph -> (Graph, NodeMap Node) +renum from = (\(_,m,g)->(g,m)) + . IM.foldrWithKey + (\i ss (!n,!env,!new)-> + let (j,n2,env2) = go n env i + (n3,env3,ss2) = IS.fold + (\k (!n,!env,!new)-> + case go n env k of + (l,n2,env2)-> (n2,env2,l `IS.insert` new)) + (n2,env2,mempty) ss + new2 = IM.insertWith IS.union j ss2 new + in (n3,env3,new2)) (from,mempty,mempty) + where go :: Int + -> NodeMap Node + -> Node + -> (Node,Int,NodeMap Node) + go !n !env i = + case IM.lookup i env of + Just j -> (j,n,env) + Nothing -> (n,n+1,IM.insert i n env) + +----------------------------------------------------------------------------- + +-- Nothing better than reinvinting the state monad. +newtype S z s a = S {unS :: forall o. (a -> s -> ST z o) -> s -> ST z o} +instance Functor (S z s) where + fmap f (S g) = S (\k -> g (k . f)) +instance Monad (S z s) where + return = pure + S g >>= f = S (\k -> g (\a -> unS (f a) k)) +instance Applicative (S z s) where + pure a = S (\k -> k a) + (<*>) = ap +-- get :: S z s s +-- get = S (\k s -> k s s) +gets :: (s -> a) -> S z s a +gets f = S (\k s -> k (f s) s) +-- set :: s -> S z s () +-- set s = S (\k _ -> k () s) +modify :: (s -> s) -> S z s () +modify f = S (\k -> k () . f) +-- runS :: S z s a -> s -> ST z (a, s) +-- runS (S g) = g (\a s -> return (a,s)) +evalS :: S z s a -> s -> ST z a +evalS (S g) = g ((return .) . const) +-- execS :: S z s a -> s -> ST z s +-- execS (S g) = g ((return .) . flip const) +st :: ST z a -> S z s a +st m = S (\k s-> do + a <- m + k a s) +store :: (MArray (A z) a (ST z)) + => (s -> Arr z a) -> Int -> a -> S z s () +store f i x = do + a <- gets f + st ((a.=x) i) +fetch :: (MArray (A z) a (ST z)) + => (s -> Arr z a) -> Int -> S z s a +fetch f i = do + a <- gets f + st (a!:i) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/89a52ee3a9f7a215db71732cc590464b7929851d -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/89a52ee3a9f7a215db71732cc590464b7929851d You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 20:24:00 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 16:24:00 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/windows-fixes Message-ID: <5f4421e0793cc_80b3f84902b12509233768@gitlab.haskell.org.mail> Ben Gamari pushed new branch wip/windows-fixes at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/windows-fixes You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 20:27:24 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 16:27:24 -0400 Subject: [Git][ghc/ghc][wip/windows-fixes] gitlab-ci: Drop Windows make job Message-ID: <5f4422ace40bc_80b3f848685789492395f9@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/windows-fixes at Glasgow Haskell Compiler / GHC Commits: e05cc36b by Ben Gamari at 2020-08-24T16:27:16-04:00 gitlab-ci: Drop Windows make job These are a significant burden on our CI resources and end up failing quite often due to #18274. Here I drop the make jobs during validaion; it is now run only during the nightly builds. - - - - - 1 changed file: - .gitlab-ci.yml Changes: ===================================== .gitlab-ci.yml ===================================== @@ -866,9 +866,6 @@ validate-x86_64-windows-hadrian: cache: key: "x86_64-windows-$WINDOWS_TOOLCHAIN_VERSION" -validate-x86_64-windows: - extends: .build-x86_64-windows-make - nightly-x86_64-windows: <<: *nightly extends: .build-x86_64-windows-make @@ -879,13 +876,13 @@ nightly-x86_64-windows: # Normal Windows validate builds are profiled; that won't do for releases. release-x86_64-windows: <<: *release - extends: validate-x86_64-windows + extends: .build-x86t_64-windows-make variables: BUILD_FLAVOUR: "perf" # release-x86_64-windows-integer-simple: <<: *release - extends: validate-x86_64-windows + extends: .build-x86t_64-windows-make variables: BIGNUM_BACKEND: native BUILD_FLAVOUR: "perf" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e05cc36b123492c0b546bb95cf689fe87af08c5c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e05cc36b123492c0b546bb95cf689fe87af08c5c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 20:28:14 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 16:28:14 -0400 Subject: [Git][ghc/ghc][wip/windows-fixes] gitlab-ci: Drop Windows make job Message-ID: <5f4422de254b6_80b3f84693c1eb4924035@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/windows-fixes at Glasgow Haskell Compiler / GHC Commits: ff0d5a17 by Ben Gamari at 2020-08-24T16:28:08-04:00 gitlab-ci: Drop Windows make job These are a significant burden on our CI resources and end up failing quite often due to #18274. Here I drop the make jobs during validaion; it is now run only during the nightly builds. - - - - - 1 changed file: - .gitlab-ci.yml Changes: ===================================== .gitlab-ci.yml ===================================== @@ -866,9 +866,6 @@ validate-x86_64-windows-hadrian: cache: key: "x86_64-windows-$WINDOWS_TOOLCHAIN_VERSION" -validate-x86_64-windows: - extends: .build-x86_64-windows-make - nightly-x86_64-windows: <<: *nightly extends: .build-x86_64-windows-make @@ -879,13 +876,13 @@ nightly-x86_64-windows: # Normal Windows validate builds are profiled; that won't do for releases. release-x86_64-windows: <<: *release - extends: validate-x86_64-windows + extends: .build-x86_64-windows-make variables: BUILD_FLAVOUR: "perf" # release-x86_64-windows-integer-simple: <<: *release - extends: validate-x86_64-windows + extends: .build-x86_64-windows-make variables: BIGNUM_BACKEND: native BUILD_FLAVOUR: "perf" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ff0d5a17c4b2c86ce0ab90fce8a92ab8d16cf9e5 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ff0d5a17c4b2c86ce0ab90fce8a92ab8d16cf9e5 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 20:31:13 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 16:31:13 -0400 Subject: [Git][ghc/ghc][wip/bump-win32] 56 commits: A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure Message-ID: <5f4423912c8cd_80b3f842731681c9242131@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/bump-win32 at Glasgow Haskell Compiler / GHC Commits: 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 293c7fba by Sylvain Henry at 2020-08-21T09:36:38-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - 50eb4460 by Sylvain Henry at 2020-08-21T09:36:38-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 659eb31b by Sylvain Henry at 2020-08-21T09:36:38-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 2d8ca917 by Sylvain Henry at 2020-08-21T09:37:15-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - fddddbf4 by Vladislav Zavialov at 2020-08-21T09:37:49-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - 989c1c27 by Ben Gamari at 2020-08-21T11:27:53-04:00 gitlab-ci: Test master branch as well While these builds are strictly speaking redundant (since every commit is tested by @marge-bot before making it into `master`), they are nevertheless useful as they are displayed in the branch's commit list in GitLab's web interface. Fixes #18595. - - - - - e67ae884 by Aditya Gupta at 2020-08-22T03:29:00-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - 03cfcfd4 by Wander Hillen at 2020-08-22T03:29:36-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 3f501545 by Craig Ferguson at 2020-08-22T03:30:13-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 8b865092 by Krzysztof Gogolewski at 2020-08-23T14:12:53+02:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - d8f61182 by Krzysztof Gogolewski at 2020-08-23T14:12:56+02:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - 364258e0 by Krzysztof Gogolewski at 2020-08-24T00:32:31-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - b1eb38a0 by Sylvain Henry at 2020-08-24T00:33:13-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 45133301 by Ben Gamari at 2020-08-24T16:31:10-04:00 Bump Win32 and process submodules - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/Builtin/Utils.hs - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Lint.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/MachOp.hs - compiler/GHC/Cmm/Node.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c403006c13f161881e50ccbb9c6761fcbfc4ce03...45133301bb78e2eaaf5766f9c2f7c35068c3d0df -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c403006c13f161881e50ccbb9c6761fcbfc4ce03...45133301bb78e2eaaf5766f9c2f7c35068c3d0df You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 21:42:37 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 17:42:37 -0400 Subject: [Git][ghc/ghc][wip/ci-fixes] 1333 commits: rts: Specialize hashing at call site rather than in struct. Message-ID: <5f44344dc24aa_80b3f848685789492519f8@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/ci-fixes at Glasgow Haskell Compiler / GHC Commits: f80c4a66 by Crazycolorz5 at 2019-12-11T14:12:17-05:00 rts: Specialize hashing at call site rather than in struct. Separate word and string hash tables on the type level, and do not store the hashing function. Thus when a different hash function is desire it is provided upon accessing the table. This is worst case the same as before the change, and in the majority of cases is better. Also mark the functions for aggressive inlining to improve performance. {F1686506} Reviewers: bgamari, erikd, simonmar Subscribers: rwbarton, thomie, carter GHC Trac Issues: #13165 Differential Revision: https://phabricator.haskell.org/D4889 - - - - - 2d1b9619 by Richard Eisenberg at 2019-12-11T14:12:55-05:00 Warn on inferred polymorphic recursion Silly users sometimes try to use visible dependent quantification and polymorphic recursion without a CUSK or SAK. This causes unexpected errors. So we now adjust expectations with a bit of helpful messaging. Closes #17541 and closes #17131. test cases: dependent/should_fail/T{17541{,b},17131} - - - - - 4dde485e by Oleg Grenrus at 2019-12-12T02:24:46-05:00 Add --show-unit-ids flag to ghc-pkg I only added it into --simple-output and ghc-pkg check output; there are probably other places where it can be adopted. - - - - - e6e1ec08 by Ben Gamari at 2019-12-12T02:25:33-05:00 testsuite: Simplify and clarify performance test baseline search The previous implementation was extremely complicated, seemingly to allow the local and CI namespaces to be searched incrementally. However, it's quite unclear why this is needed and moreover the implementation seems to have had quadratic runtime cost in the search depth(!). - - - - - 29c4609c by Ben Gamari at 2019-12-12T02:26:19-05:00 testsuite: Add test for #17549 - - - - - 9f0ee253 by Ben Gamari at 2019-12-12T02:26:56-05:00 gitlab-ci: Move -dwarf and -debug jobs to full-build stage This sacrifices some precision in favor of improving parallelism. - - - - - 7179b968 by Ben Gamari at 2019-12-12T02:27:34-05:00 Revert "rts: Drop redundant flags for libffi" This seems to have regressed builds using `--with-system-libffi` (#17520). This reverts commit 3ce18700f80a12c48a029b49c6201ad2410071bb. - - - - - cc7d5650 by Oleg Grenrus at 2019-12-16T10:20:56+02:00 Having no shake upper bound is irresposible Given that shake is far from "done" API wise, and is central component to the build system. - - - - - 9431f905 by Oleg Grenrus at 2019-12-16T10:55:50+02:00 Add index-state to hadrian/cabal.project Then one is freer to omit upper bounds, as we won't pick any new entries on Hackage while building hadrian itself. - - - - - 3e17a866 by Krzysztof Gogolewski at 2019-12-16T19:31:44-05:00 Remove dataConSig As suggested in #17291 - - - - - 75355fde by Krzysztof Gogolewski at 2019-12-16T19:31:44-05:00 Use "OrCoVar" functions less As described in #17291, we'd like to separate coercions and expressions in a more robust fashion. This is a small step in this direction. - `mkLocalId` now panicks on a covar. Calls where this was not the case were changed to `mkLocalIdOrCoVar`. - Don't use "OrCoVar" functions in places where we know the type is not a coercion. - - - - - f9686e13 by Richard Eisenberg at 2019-12-16T19:32:21-05:00 Do more validity checks for quantified constraints Close #17583. Test case: typecheck/should_fail/T17563 - - - - - af763765 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Fix Windows artifact collection Variable interpolation in gitlab-ci.yml apparently doesn't work. Sigh. - - - - - e6d4b902 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Use xz --threads on Debian 10 - - - - - 8ba650e9 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Allow debian 8 build to fail The python release shipped with deb8 (3.3) is too old for our testsuite driver. - - - - - ac25a3f6 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Use xz --threads on Alpine - - - - - cc628088 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Another approach for xz detection - - - - - 37d788ab by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Re-add release-x86_64-deb9 job Also eliminate some redundancy. - - - - - f8279138 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Drop redundant release-x86_64-linux-deb9 job - - - - - 8148ff06 by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark cgrun057 as broken on ARMv7 Due to #17554. It's very surprising that this only occurs on ARMv7 but this is the only place I've seen this failure thusfar. - - - - - 85e5696d by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark prog001 as fragile on ARMv7 Due to #17555. - - - - - a5f0aab0 by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark T10272 as broken on ARMv7 Due to #17556. - - - - - 1e6827c6 by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark T13825-debugger as broken on ARMv7 Due to #17557. - - - - - 7cef0b7d by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark T14028 as broken on ARMv7 Due to #17558. - - - - - 6ea4eb4b by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Make ghc_built_by_llvm check more precise Previously it would hackily look at the flavour name to determine whether LLVM was used to build stage2 ghc. However, this didn't work at all with Hadrian and would miss cases like ARM where we use the LLVM backend by default. See #16087 for the motivation for why ghc_built_by_llvm is needed at all. This should catch one of the ARMv7 failures described in #17555. - - - - - c3e82bf7 by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark T5435_* tests as broken on ARM `T5435_v_asm_a`, `T5435_v_asm_b`, and `T5435_v_gcc` all fail on ARMv7. See #17559. - - - - - eb2aa851 by Ben Gamari at 2019-12-17T07:24:40-05:00 gitlab-ci: Don't allow armv7 jobs to fail - - - - - efc92216 by Ben Gamari at 2019-12-17T07:24:40-05:00 Revert "testsuite: Mark cgrun057 as broken on ARMv7" This reverts commit 6cfc47ec8a478e1751cb3e7338954da1853c3996. - - - - - 1d2bb9eb by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark print002 as fragile on ARM Due to #17557. Also accepting spurious performance change. Metric Decrease: T1969 - - - - - 41f4e4fb by Josh Meredith at 2019-12-17T07:25:17-05:00 Fix ambiguous occurence error when building Hadrian - - - - - 4374983a by Josh Meredith at 2019-12-17T07:25:17-05:00 Rename SphinxMode constructors - - - - - a8f7ecd5 by Josh Meredith at 2019-12-17T07:25:17-05:00 Use *Mode suffix instead of *M - - - - - 58655b9d by Sylvain Henry at 2019-12-18T13:43:37+01:00 Add GHC-API logging hooks * Add 'dumpAction' hook to DynFlags. It allows GHC API users to catch dumped intermediate codes and information. The format of the dump (Core, Stg, raw text, etc.) is now reported allowing easier automatic handling. * Add 'traceAction' hook to DynFlags. Some dumps go through the trace mechanism (for instance unfoldings that have been considered for inlining). This is problematic because: 1) dumps aren't written into files even with -ddump-to-file on 2) dumps are written on stdout even with GHC API 3) in this specific case, dumping depends on unsafe globally stored DynFlags which is bad for GHC API users We introduce 'traceAction' hook which allows GHC API to catch those traces and to avoid using globally stored DynFlags. * Avoid dumping empty logs via dumpAction/traceAction (but still write empty files to keep the existing behavior) - - - - - fad866e0 by Moritz Kiefer at 2019-12-19T11:15:39-05:00 Avoid race condition in hDuplicateTo In our codebase we have some code along the lines of ``` newStdout <- hDuplicate stdout stderr `hDuplicateTo` stdout ``` to avoid stray `putStrLn`s from corrupting a protocol (LSP) that is run over stdout. On CI we have seen a bunch of issues where `dup2` returned `EBUSY` so this fails with `ResourceExhausted` in Haskell. I’ve spent some time looking at the docs for `dup2` and the code in `base` and afaict the following race condition is being triggered here: 1. The user calls `hDuplicateTo stderr stdout`. 2. `hDuplicateTo` calls `hClose_help stdout_`, this closes the file handle for stdout. 3. The file handle for stdout is now free, so another thread allocating a file might get stdout. 4. If `dup2` is called while `stdout` (now pointing to something else) is half-open, it returns EBUSY. I think there might actually be an even worse case where `dup2` is run after FD 1 is fully open again. In that case, you will end up not just redirecting the original stdout to stderr but also the whatever resulted in that file handle being allocated. As far as I can tell, `dup2` takes care of closing the file handle itself so there is no reason to do this in `hDuplicateTo`. So this PR replaces the call to `hClose_help` by the only part of `hClose_help` that we actually care about, namely, `flushWriteBuffer`. I tested this on our codebase fairly extensively and haven’t been able to reproduce the issue with this patch. - - - - - 0c114c65 by Sylvain Henry at 2019-12-19T11:16:17-05:00 Handle large ARR_WORDS in heap census (fix #17572) We can do a heap census with a non-profiling RTS. With a non-profiling RTS we don't zero superfluous bytes of shrunk arrays hence a need to handle the case specifically to avoid a crash. Revert part of a586b33f8e8ad60b5c5ef3501c89e9b71794bbed - - - - - 1a0d1a65 by John Ericson at 2019-12-20T10:50:22-05:00 Deduplicate copied monad failure handler code - - - - - 70e56b27 by Ryan Scott at 2019-12-20T10:50:57-05:00 lookupBindGroupOcc: recommend names in the same namespace (#17593) Previously, `lookupBindGroupOcc`'s error message would recommend all similar names in scope, regardless of whether they were type constructors, data constructors, or functions, leading to the confusion witnessed in #17593. This is easily fixed by only recommending names in the same namespace, using the `nameSpacesRelated` function. Fixes #17593. - - - - - 3c12355e by Stefan Schulze Frielinghaus at 2019-12-24T01:03:44-05:00 Fix endian handling w.r.t. CPP macro WORDS_BIGENDIAN Include header file `ghcautoconf.h` where the CPP macro `WORDS_BIGENDIAN` is defined. This finally fixes #17337 (in conjunction with commit 6c59cc71dc). - - - - - 11f8eef5 by Stefan Schulze Frielinghaus at 2019-12-24T01:03:44-05:00 fixup! Fix endian handling w.r.t. CPP macro WORDS_BIGENDIAN - - - - - 40327b03 by Sylvain Henry at 2019-12-24T01:04:24-05:00 Remove outdated comment - - - - - aeea92ef by Sylvain Henry at 2019-12-25T19:23:54-05:00 Switch to ReadTheDocs theme for the user-guide - - - - - 26493eab by Gabor Greif at 2019-12-25T19:24:32-05:00 Fix copy-paste error in comment - - - - - 776df719 by Gabor Greif at 2019-12-25T19:24:32-05:00 Fix comment about minimal gcc version to be consistent what FP_GCC_VERSION requires - - - - - 3b17114d by Ömer Sinan Ağacan at 2019-12-26T14:09:11-05:00 Minor refactor in ghc.cabal.in: - Remove outdated comments - Move cutils.c from parser to cbits - Remove unused cutils.h - - - - - 334290b6 by Ryan Scott at 2019-12-26T14:09:48-05:00 Replace panic/notHandled with noExtCon in DsMeta There are many spots in `DsMeta` where `panic` or `notHandled` is used after pattern-matching on a TTG extension constructor. This is overkill, however, as using `noExtCon` would work just as well. This patch switches out these panics for `noExtCon`. - - - - - 68252aa3 by Ben Gamari at 2019-12-27T15:11:38-05:00 testsuite: Skip T17499 when built against integer-simple Since it routinely times out in CI. - - - - - 0c51aeeb by Gabor Greif at 2019-12-27T15:12:17-05:00 suppress popup dialog about missing Xcode at configure tested with `bash` and `zsh`. - - - - - 8d76bcc2 by Gabor Greif at 2019-12-27T15:12:17-05:00 while at it rename XCode to the official Xcode - - - - - 47a68205 by Ben Gamari at 2019-12-27T15:12:55-05:00 testsuite: Mark cgrun057 as fragile on ARM As reported in #17554. Only marking on ARM for now although there is evidence to suggest that the issue may occur on other platforms as well. - - - - - d03dec8f by Gabor Greif at 2019-12-27T15:13:32-05:00 use shell variable CcLlvmBackend for test Previously we used `AC_DEFINE`d variable `CC_LLVM_BACKEND` which has an empty shell expansion. - - - - - 2528e684 by Ben Gamari at 2019-12-30T06:51:32-05:00 driver: Include debug level in the recompilation check hash Fixes #17586. - - - - - f14bb50b by Ben Gamari at 2019-12-30T06:52:09-05:00 rts: Ensure that nonmoving gc isn't used with profiling - - - - - b426de37 by Ben Gamari at 2019-12-30T06:52:45-05:00 llvmGen: Ensure that entry labels don't have predecessors The LLVM IR forbids the entry label of a procedure from having any predecessors. In the case of a simple looping function the LLVM code generator broke this invariant, as noted in #17589. Fix this by moving the function prologue to its own basic block, as suggested by @kavon in #11649. Fixes #11649 and #17589. - - - - - 613f7265 by Ben Gamari at 2019-12-30T06:52:45-05:00 llvmGen: Drop old fix for #11649 This was a hack which is no longer necessary now since we introduce a dedicated entry block for each procedure. - - - - - fdeffa5e by Ben Gamari at 2019-12-30T06:53:23-05:00 rts: Error on invalid --numa flags Previously things like `+RTS --numa-debug` would enable NUMA support, despite being an invalid flag. - - - - - 9ce3ba68 by Ben Gamari at 2019-12-30T06:53:23-05:00 rts: Fix --debug-numa mode under Docker As noted in #17606, Docker disallows the get_mempolicy syscall by default. This caused numerous tests to fail under CI in the `debug_numa` way. Avoid this by disabling the NUMA probing logic when --debug-numa is in use, instead setting n_numa_nodes in RtsFlags.c. Fixes #17606. - - - - - 5baa2a43 by Ben Gamari at 2019-12-30T06:54:01-05:00 testsuite: Disable derefnull when built with LLVM LLVM does not guarantee any particular semantics when dereferencing null pointers. Consequently, this test actually passes when built with the LLVM backend. - - - - - bd544d3d by Ben Gamari at 2019-12-30T06:54:38-05:00 hadrian: Track hash of Cabal Setup builder arguments Lest we fail to rebuild when they change. Fixes #17611. - - - - - 6e2c495e by Ben Gamari at 2019-12-30T06:55:19-05:00 TcIface: Fix inverted logic in typechecking of source ticks Previously we would throw away source ticks when the debug level was non-zero. This is precisely the opposite of what was intended. Fixes #17616. Metric Decrease: T13056 T9020 T9961 T12425 - - - - - 7fad387d by Ben Gamari at 2019-12-30T06:55:55-05:00 perf_notes: Add --zero-y argument This makes it easier to see the true magnitude of fluctuations. Also do some house-keeping in the argument parsing department. - - - - - 0d42b287 by Ben Gamari at 2019-12-30T06:55:55-05:00 testsuite: Enlarge acceptance window for T1969 As noted in #17624, it's quite unstable, especially, for some reason, on i386 and armv7 (something about 32-bit platforms perhaps?). Metric Increase: T1969 - - - - - eb608235 by Sylvain Henry at 2019-12-31T14:22:32-05:00 Module hierarchy (#13009): Stg - - - - - d710fd66 by Vladislav Zavialov at 2019-12-31T14:23:10-05:00 Testsuite: update some Haddock tests Fixed tests: * haddockA039: added to all.T * haddockE004: replaced with T17561 (marked as expect_broken) New tests: * haddockA040: deriving clause for a data instance * haddockA041: haddock and CPP #include - - - - - 859ebdd4 by Kevin Buhr at 2019-12-31T23:44:39-05:00 Add "-Iw" RTS flag for minimum wait between idle GCs (#11134) - - - - - dd4b6551 by Kevin Buhr at 2019-12-31T23:44:39-05:00 Add additional Note explaining the -Iw flag - - - - - c4279ff1 by Kevin Buhr at 2019-12-31T23:44:39-05:00 Fix some sloppy indentation - - - - - b84c09d5 by Ömer Sinan Ağacan at 2019-12-31T23:45:19-05:00 Tweak Cmm dumps to avoid generating sections for empty groups When dumping Cmm groups check if the group is empty, to avoid generating empty sections in dump files like ==================== Output Cmm ==================== [] Also fixes a few bad indentation in the code around changes. - - - - - b2e0323f by Gabor Greif at 2020-01-03T21:22:36-05:00 Simplify mrStr - - - - - 3c9dc06b by Brian Wignall at 2020-01-04T15:55:06-05:00 Fix typos, via a Levenshtein-style corrector - - - - - d561c8f6 by Sylvain Henry at 2020-01-04T15:55:46-05:00 Add Cmm related hooks * stgToCmm hook * cmmToRawCmm hook These hooks are used by Asterius and could be useful to other clients of the GHC API. It increases the Parser dependencies (test CountParserDeps) to 184. It's still less than 200 which was the initial request (cf https://mail.haskell.org/pipermail/ghc-devs/2019-September/018122.html) so I think it's ok to merge this. - - - - - ae6b6276 by Oleg Grenrus at 2020-01-04T15:56:22-05:00 Update to Cabal submodule to v3.2.0.0-alpha3 Metric Increase: haddock.Cabal - - - - - 073f7cfd by Vladislav Zavialov at 2020-01-04T15:56:59-05:00 Add lexerDbg to dump the tokens fed to the parser This a small utility function that comes in handy when debugging the lexer and the parser. - - - - - 558d4d4a by Sylvain Henry at 2020-01-04T15:57:38-05:00 Split integerGmpInternals test in several parts This is to prepare for ghc-bignum which implements some but not all of gmp functions. - - - - - 4056b966 by Ben Gamari at 2020-01-04T15:58:15-05:00 testsuite: Mark cgrun057 as fragile on all platforms I have seen this fail both on x86-64/Debian 9 and armv7/Debian 9 See #17554. - - - - - 5ffea0c6 by Tamar Christina at 2020-01-06T18:38:37-05:00 Fix overflow. - - - - - 99a9f51b by Sylvain Henry at 2020-01-06T18:39:22-05:00 Module hierarchy: Iface (cf #13009) - - - - - 7aa4a061 by Ben Gamari at 2020-01-07T13:11:48-05:00 configure: Only check GCC version if CC is GCC Also refactor FP_GCC_EXTRA_FLAGS in a few ways: * We no longer support compilers which lack support for -fno-builtin and -fwrapv so remove the condition on GccVersion * These flags are only necessary when using the via-C backend so make them conditional on Unregisterised. Fixes #15742. - - - - - 0805ed7e by John Ericson at 2020-01-07T13:12:25-05:00 Use non-empty lists to remove partiality in matching code - - - - - 7844f3a8 by Ben Gamari at 2020-01-07T13:13:02-05:00 testsuite: Mark T17073 as broken on Windows Due to #17607. - - - - - acf40cae by Ben Gamari at 2020-01-07T13:13:02-05:00 gitlab-ci: Disallow Windows from failing - - - - - 34bc02c7 by Ben Gamari at 2020-01-07T13:13:02-05:00 configure: Find Python3 for testsuite In addition, we prefer the Mingw64 Python distribution on Windows due to #17483. - - - - - e35fe8d5 by Ben Gamari at 2020-01-07T13:13:02-05:00 testsuite: Fix Windows platform test Previously we used platform.system() and while this worked fine (e.g. returned `Windows`, as expected) locally under both msys and MingW64 Python distributions, it inexplicably returned `MINGW64_NT-10.0` under MingW64 Python on CI. It seems os.name is more reliable so we now use that instead.. - - - - - 48ef6217 by Ben Gamari at 2020-01-07T13:13:39-05:00 gitlab-ci: Rename push-test-metrics.sh to test-metrics.sh Refactoring to follow. - - - - - 2234fa92 by Ben Gamari at 2020-01-07T13:13:39-05:00 gitlab-ci: Pull test metrics before running testsuite Otherwise the testsuite driver may not have an up-to-date baseline. - - - - - 1ca9adbc by Sylvain Henry at 2020-01-07T13:14:18-05:00 Remove `parallel` check from configure.ac `parallel` is no longer a submodule since 3cb063c805ec841ca33b8371ef8aba9329221b6c - - - - - b69a3460 by Ryan Scott at 2020-01-07T13:14:57-05:00 Monomorphize HsModule to GhcPs (#17642) Analyzing the call sites for `HsModule` reveals that it is only ever used with parsed code (i.e., `GhcPs`). This simplifies `HsModule` by concretizing its `pass` parameter to always be `GhcPs`. Fixes #17642. - - - - - d491a679 by Sylvain Henry at 2020-01-08T06:16:31-05:00 Module hierarchy: Renamer (cf #13009) - - - - - d589410f by Ben Gamari at 2020-01-08T06:17:09-05:00 Bump haskeline submodule to 0.8.0.1 (cherry picked from commit feb3b955402d53c3875dd7a9a39f322827e5bd69) - - - - - 923a1272 by Ryan Scott at 2020-01-08T06:17:47-05:00 Print Core type applications with no whitespace after @ (#17643) This brings the pretty-printer for Core in line with how visible type applications are normally printed: namely, with no whitespace after the `@` character (i.e., `f @a` instead of `f @ a`). While I'm in town, I also give the same treatment to type abstractions (i.e., `\(@a)` instead of `\(@ a)`) and coercion applications (i.e., `f @~x` instead of `f @~ x`). Fixes #17643. - - - - - 49f83a0d by Adam Sandberg Eriksson at 2020-01-12T21:28:09-05:00 improve docs for HeaderInfo.getImports [skip ci] - - - - - 9129210f by Matthew Pickering at 2020-01-12T21:28:47-05:00 Overloaded Quotation Brackets (#246) This patch implements overloaded quotation brackets which generalise the desugaring of all quotation forms in terms of a new minimal interface. The main change is that a quotation, for example, [e| 5 |], will now have type `Quote m => m Exp` rather than `Q Exp`. The `Quote` typeclass contains a single method for generating new names which is used when desugaring binding structures. The return type of functions from the `Lift` type class, `lift` and `liftTyped` have been restricted to `forall m . Quote m => m Exp` rather than returning a result in a Q monad. More details about the feature can be read in the GHC proposal. https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0246-overloaded-bracket.rst - - - - - 350e2b78 by Richard Eisenberg at 2020-01-12T21:29:27-05:00 Don't zap to Any; error instead This changes GHC's treatment of so-called Naughty Quantification Candidates to issue errors, instead of zapping to Any. Close #16775. No new test cases, because existing ones cover this well. - - - - - 0b5ddc7f by Brian Wignall at 2020-01-12T21:30:08-05:00 Fix more typos, via an improved Levenshtein-style corrector - - - - - f732dbec by Ben Gamari at 2020-01-12T21:30:49-05:00 gitlab-ci: Retain bindists used by head.hackage for longer Previously we would keep them for two weeks. However, on the stable branches two weeks can easily elapse with no pushes. - - - - - c8636da5 by Sylvain Henry at 2020-01-12T21:31:30-05:00 Fix LANG=C for readelf invocation in T14999 The test fails when used with LANG=fr_FR.UTF-8 - - - - - 077a88de by Jean-Baptiste Mazon at 2020-01-12T21:32:08-05:00 users-guide/debug-info: typo “behivior” - - - - - 61916c5d by Simon Peyton Jones at 2020-01-12T21:32:44-05:00 Add comments about TH levels - - - - - 1fd766ca by Simon Peyton Jones at 2020-01-12T21:32:44-05:00 Comments about constraint floating - - - - - de01427e by Simon Peyton Jones at 2020-01-12T21:32:45-05:00 Minor refactor around quantified constraints This patch clarifies a dark corner of quantified constraints. * See Note [Yukky eq_sel for a HoleDest] in TcSMonad * Minor refactor, breaking out new function TcInteract.doTopReactEqPred - - - - - 30be3bf1 by Simon Peyton Jones at 2020-01-12T21:32:45-05:00 Comments in TcHsType - - - - - c5977d4d by Sebastian Graf at 2020-01-16T05:58:58-05:00 Better documentation for mkEtaWW [skip ci] So that hopefully I understand it faster next time. Also got rid of the confusing `orig_expr`, which makes the call site in `etaExpand` look out of sync with the passed `n` (which is not the original `n`). - - - - - 22c0bdc3 by John Ericson at 2020-01-16T05:59:37-05:00 Handle TagToEnum in the same big case as the other primops Before, it was a panic because it was handled above. But there must have been an error in my reasoning (another caller?) because #17442 reported the panic was hit. But, rather than figuring out what happened, I can just make it impossible by construction. By adding just a bit more bureaucracy in the return types, I can handle TagToEnum in the same case as all the others, so the big case is is now total, and the panic is removed. Fixes #17442 - - - - - ee5d63f4 by John Ericson at 2020-01-16T05:59:37-05:00 Get rid of OpDest `OpDest` was basically a defunctionalization. Just turn the code that cased on it into those functions, and call them directly. - - - - - 1ff55226 by John Ericson at 2020-01-16T06:00:16-05:00 Remove special case case of bool during STG -> C-- Allow removing the no longer needed cgPrimOp, getting rid of a small a small layer violation too. Change which made the special case no longer needed was #6135 / 6579a6c73082387f82b994305011f011d9d8382b, which dates back to 2013, making me feel better. - - - - - f416fe64 by Adam Wespiser at 2020-01-16T06:00:53-05:00 replace dead html link (fixes #17661) - - - - - f6bf2ce8 by Sebastian Graf at 2020-01-16T06:01:32-05:00 Revert "`exprOkForSpeculation` for Note [IO hack in the demand analyser]" This reverts commit ce64b397777408731c6dd3f5c55ea8415f9f565b on the grounds of the regression it would introduce in a couple of packages. Fixes #17653. Also undoes a slight metric increase in #13701 introduced by that commit that we didn't see prior to !1983. Metric Decrease: T13701 - - - - - a71323ff by Ben Gamari at 2020-01-17T08:43:16-05:00 gitlab-ci: Don't FORCE_SYMLINKS on Windows Not all runners have symlink permissions enabled. - - - - - 0499e3bc by Ömer Sinan Ağacan at 2020-01-20T15:31:33-05:00 Fix +RTS -Z flag documentation Stack squeezing is done on context switch, not on GC or stack overflow. Fix the documentation. Fixes #17685 [ci skip] - - - - - a661df91 by Ömer Sinan Ağacan at 2020-01-20T15:32:13-05:00 Document Stg.FVs module Fixes #17662 [ci skip] - - - - - db24e480 by Ben Gamari at 2020-01-20T15:32:52-05:00 llvmGen: Don't trash STG registers Fixes #13904. - - - - - f3d7fdb3 by Ben Gamari at 2020-01-20T15:32:52-05:00 llvmGen: Fix typo in readnone attribute - - - - - 442751c6 by Ben Gamari at 2020-01-20T15:32:52-05:00 llvmGen: Add lower-expect to the -O0 optimisation set @kavon says that this will improve block layout for stack checks. - - - - - e90ecc93 by Ben Gamari at 2020-01-20T15:32:52-05:00 llvmGen: Fix #14251 Fixes the calling convention for functions passing raw SSE-register values by adding padding as needed to get the values in the right registers. This problem cropped up when some args were unused an dropped from the live list. This folds together 2e23e1c7de01c92b038e55ce53d11bf9db993dd4 and 73273be476a8cc6c13368660b042b3b0614fd928 previously from @kavon. Metric Increase: T12707 ManyConstructors - - - - - 66e511a4 by Ben Gamari at 2020-01-20T15:33:28-05:00 testsuite: Preserve more information in framework failures Namely print the entire exception in hopes that this will help track down #17649. - - - - - b62b8cea by Ömer Sinan Ağacan at 2020-01-20T15:34:06-05:00 Remove deprecated -smp flag It was deprecated in 2012 with 46258b40 - - - - - 0c04a86a by Ben Gamari at 2020-01-20T15:34:43-05:00 gitlab-ci: Reenable submodule linter - - - - - 2bfabd22 by Ben Gamari at 2020-01-20T15:34:43-05:00 gitlab-ci: Allow submodule cleaning to fail on Windows Currently CI is inexplicably failing with ``` $ git submodule foreach git clean -xdf fatal: not a git repository: libffi-tarballs/../.git/modules/libffi-tarballs ``` I have no idea how this working tree got into such a state but we do need to fail more gracefully when it happens. Consequently, we allow the cleaning step to fail. - - - - - 14bced99 by Xavier Denis at 2020-01-20T15:35:21-05:00 Put the docs for :instances in alphabetical position - - - - - 7e0bb82b by Ben Gamari at 2020-01-20T15:35:57-05:00 Add missing Note [Improvement from Ground Wanteds] Closes #17659. - - - - - 17e43a7c by Ben Gamari at 2020-01-20T15:36:32-05:00 unregisterised: Fix declaration for stg_NO_FINALIZER Previously it had a redundant _entry suffix. We never noticed this previously presumably because we never generated references to it (however hard to believe this may be). However, it did start failing in !1304. - - - - - 3dae006f by PHO at 2020-01-20T15:37:08-05:00 Avoid ./configure failure on NetBSD - - - - - 738e2912 by Ben Gamari at 2020-01-24T13:42:56-05:00 testsuite: Widen acceptance window of T1969 I have seen >20% fluctuations in this number, leading to spurious failures. - - - - - ad4eb7a7 by Gabor Greif at 2020-01-25T05:19:07-05:00 Document the fact, that openFileBlocking can consume an OS thread indefinitely. Also state that a deadlock can happen with the non-threaded runtime. [ci skip] - - - - - be910728 by Sebastian Graf at 2020-01-25T05:19:46-05:00 `-ddump-str-signatures` dumps Text, not STG [skip ci] - - - - - 0e57d8a1 by Ömer Sinan Ağacan at 2020-01-25T05:20:27-05:00 Fix chaining tagged and untagged ptrs in compacting GC Currently compacting GC has the invariant that in a chain all fields are tagged the same. However this does not really hold: root pointers are not tagged, so when we thread a root we initialize a chain without a tag. When the pointed objects is evaluated and we have more pointers to it from the heap, we then add *tagged* fields to the chain (because pointers to it from the heap are tagged), ending up chaining fields with different tags (pointers from roots are NOT tagged, pointers from heap are). This breaks the invariant and as a result compacting GC turns tagged pointers into non-tagged. This later causes problem in the generated code where we do reads assuming that the pointer is aligned, e.g. 0x7(%rax) -- assumes that pointer is tagged 1 which causes misaligned reads. This caused #17088. We fix this using the "pointer tagging for large families" patch (#14373, !1742): - With the pointer tagging patch the GC can know what the tagged pointer to a CONSTR should be (previously we'd need to know the family size -- large families are always tagged 1, small families are tagged depending on the constructor). - Since we now know what the tags should be we no longer need to store the pointer tag in the info table pointers when forming chains in the compacting GC. As a result we no longer need to tag pointers in chains with 1/2 depending on whether the field points to an info table pointer, or to another field: an info table pointer is always tagged 0, everything else in the chain is tagged 1. The lost tags in pointers can be retrieved by looking at the info table. Finally, instead of using tag 1 for fields and tag 0 for info table pointers, we use two different tags for fields: - 1 for fields that have untagged pointers - 2 for fields that have tagged pointers When unchaining we then look at the pointer to a field, and depending on its tag we either leave a tagged pointer or an untagged pointer in the field. This allows chaining untagged and tagged fields together in compacting GC. Fixes #17088 Nofib results ------------- Binaries are smaller because of smaller `Compact.c` code. make mode=fast EXTRA_RUNTEST_OPTS="-cachegrind" EXTRA_HC_OPTS="-with-rtsopts=-c" NoFibRuns=1 -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS -0.3% 0.0% +0.0% +0.0% +0.0% CSD -0.3% 0.0% +0.0% +0.0% +0.0% FS -0.3% 0.0% +0.0% -0.0% -0.0% S -0.3% 0.0% +5.4% +0.8% +3.9% VS -0.3% 0.0% +0.0% -0.0% -0.0% VSD -0.3% 0.0% -0.0% -0.0% -0.2% VSM -0.3% 0.0% +0.0% +0.0% +0.0% anna -0.1% 0.0% +0.0% +0.0% +0.0% ansi -0.3% 0.0% +0.1% +0.0% +0.0% atom -0.2% 0.0% +0.0% +0.0% +0.0% awards -0.2% 0.0% +0.0% 0.0% -0.0% banner -0.3% 0.0% +0.0% +0.0% +0.0% bernouilli -0.3% 0.0% +0.1% +0.0% +0.0% binary-trees -0.2% 0.0% +0.0% 0.0% +0.0% boyer -0.3% 0.0% +0.2% +0.0% +0.0% boyer2 -0.2% 0.0% +0.2% +0.1% +0.0% bspt -0.2% 0.0% +0.0% +0.0% +0.0% cacheprof -0.2% 0.0% +0.0% +0.0% +0.0% calendar -0.3% 0.0% +0.0% +0.0% +0.0% cichelli -0.3% 0.0% +1.1% +0.2% +0.5% circsim -0.2% 0.0% +0.0% -0.0% -0.0% clausify -0.3% 0.0% +0.0% -0.0% -0.0% comp_lab_zift -0.2% 0.0% +0.0% +0.0% +0.0% compress -0.3% 0.0% +0.0% +0.0% +0.0% compress2 -0.3% 0.0% +0.0% -0.0% -0.0% constraints -0.3% 0.0% +0.2% +0.1% +0.1% cryptarithm1 -0.3% 0.0% +0.0% -0.0% 0.0% cryptarithm2 -0.3% 0.0% +0.0% +0.0% +0.0% cse -0.3% 0.0% +0.0% +0.0% +0.0% digits-of-e1 -0.3% 0.0% +0.0% +0.0% +0.0% digits-of-e2 -0.3% 0.0% +0.0% +0.0% -0.0% dom-lt -0.2% 0.0% +0.0% +0.0% +0.0% eliza -0.2% 0.0% +0.0% +0.0% +0.0% event -0.3% 0.0% +0.1% +0.0% -0.0% exact-reals -0.2% 0.0% +0.0% +0.0% +0.0% exp3_8 -0.3% 0.0% +0.0% +0.0% +0.0% expert -0.2% 0.0% +0.0% +0.0% +0.0% fannkuch-redux -0.3% 0.0% -0.0% -0.0% -0.0% fasta -0.3% 0.0% +0.0% +0.0% +0.0% fem -0.2% 0.0% +0.1% +0.0% +0.0% fft -0.2% 0.0% +0.0% -0.0% -0.0% fft2 -0.2% 0.0% +0.0% -0.0% +0.0% fibheaps -0.3% 0.0% +0.0% -0.0% -0.0% fish -0.3% 0.0% +0.0% +0.0% +0.0% fluid -0.2% 0.0% +0.4% +0.1% +0.1% fulsom -0.2% 0.0% +0.0% +0.0% +0.0% gamteb -0.2% 0.0% +0.1% +0.0% +0.0% gcd -0.3% 0.0% +0.0% +0.0% +0.0% gen_regexps -0.3% 0.0% +0.0% -0.0% -0.0% genfft -0.3% 0.0% +0.0% +0.0% +0.0% gg -0.2% 0.0% +0.7% +0.3% +0.2% grep -0.2% 0.0% +0.0% +0.0% +0.0% hidden -0.2% 0.0% +0.0% +0.0% +0.0% hpg -0.2% 0.0% +0.1% +0.0% +0.0% ida -0.3% 0.0% +0.0% +0.0% +0.0% infer -0.2% 0.0% +0.0% -0.0% -0.0% integer -0.3% 0.0% +0.0% +0.0% +0.0% integrate -0.2% 0.0% +0.0% +0.0% +0.0% k-nucleotide -0.2% 0.0% +0.0% +0.0% -0.0% kahan -0.3% 0.0% -0.0% -0.0% -0.0% knights -0.3% 0.0% +0.0% -0.0% -0.0% lambda -0.3% 0.0% +0.0% -0.0% -0.0% last-piece -0.3% 0.0% +0.0% +0.0% +0.0% lcss -0.3% 0.0% +0.0% +0.0% 0.0% life -0.3% 0.0% +0.0% -0.0% -0.0% lift -0.2% 0.0% +0.0% +0.0% +0.0% linear -0.2% 0.0% +0.0% +0.0% +0.0% listcompr -0.3% 0.0% +0.0% +0.0% +0.0% listcopy -0.3% 0.0% +0.0% +0.0% +0.0% maillist -0.3% 0.0% +0.0% -0.0% -0.0% mandel -0.2% 0.0% +0.0% +0.0% +0.0% mandel2 -0.3% 0.0% +0.0% +0.0% +0.0% mate -0.2% 0.0% +0.0% +0.0% +0.0% minimax -0.3% 0.0% +0.0% +0.0% +0.0% mkhprog -0.2% 0.0% +0.0% +0.0% +0.0% multiplier -0.3% 0.0% +0.0% -0.0% -0.0% n-body -0.2% 0.0% -0.0% -0.0% -0.0% nucleic2 -0.2% 0.0% +0.0% +0.0% +0.0% para -0.2% 0.0% +0.0% -0.0% -0.0% paraffins -0.3% 0.0% +0.0% -0.0% -0.0% parser -0.2% 0.0% +0.0% +0.0% +0.0% parstof -0.2% 0.0% +0.8% +0.2% +0.2% pic -0.2% 0.0% +0.1% -0.1% -0.1% pidigits -0.3% 0.0% +0.0% +0.0% +0.0% power -0.2% 0.0% +0.0% -0.0% -0.0% pretty -0.3% 0.0% -0.0% -0.0% -0.1% primes -0.3% 0.0% +0.0% +0.0% -0.0% primetest -0.2% 0.0% +0.0% -0.0% -0.0% prolog -0.3% 0.0% +0.0% -0.0% -0.0% puzzle -0.3% 0.0% +0.0% +0.0% +0.0% queens -0.3% 0.0% +0.0% +0.0% +0.0% reptile -0.2% 0.0% +0.2% +0.1% +0.0% reverse-complem -0.3% 0.0% +0.0% +0.0% +0.0% rewrite -0.3% 0.0% +0.0% -0.0% -0.0% rfib -0.2% 0.0% +0.0% +0.0% -0.0% rsa -0.2% 0.0% +0.0% +0.0% +0.0% scc -0.3% 0.0% -0.0% -0.0% -0.1% sched -0.3% 0.0% +0.0% +0.0% +0.0% scs -0.2% 0.0% +0.1% +0.0% +0.0% simple -0.2% 0.0% +3.4% +1.0% +1.8% solid -0.2% 0.0% +0.0% +0.0% +0.0% sorting -0.3% 0.0% +0.0% +0.0% +0.0% spectral-norm -0.2% 0.0% -0.0% -0.0% -0.0% sphere -0.2% 0.0% +0.0% +0.0% +0.0% symalg -0.2% 0.0% +0.0% +0.0% +0.0% tak -0.3% 0.0% +0.0% +0.0% -0.0% transform -0.2% 0.0% +0.2% +0.1% +0.1% treejoin -0.3% 0.0% +0.2% -0.0% -0.1% typecheck -0.3% 0.0% +0.0% +0.0% +0.0% veritas -0.1% 0.0% +0.0% +0.0% +0.0% wang -0.2% 0.0% +0.0% -0.0% -0.0% wave4main -0.3% 0.0% +0.0% -0.0% -0.0% wheel-sieve1 -0.3% 0.0% +0.0% -0.0% -0.0% wheel-sieve2 -0.3% 0.0% +0.0% -0.0% -0.0% x2n1 -0.3% 0.0% +0.0% +0.0% +0.0% -------------------------------------------------------------------------------- Min -0.3% 0.0% -0.0% -0.1% -0.2% Max -0.1% 0.0% +5.4% +1.0% +3.9% Geometric Mean -0.3% -0.0% +0.1% +0.0% +0.1% -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- circsim -0.2% 0.0% +1.6% +0.4% +0.7% constraints -0.3% 0.0% +4.3% +1.5% +2.3% fibheaps -0.3% 0.0% +3.5% +1.2% +1.3% fulsom -0.2% 0.0% +3.6% +1.2% +1.8% gc_bench -0.3% 0.0% +4.1% +1.3% +2.3% hash -0.3% 0.0% +6.6% +2.2% +3.6% lcss -0.3% 0.0% +0.7% +0.2% +0.7% mutstore1 -0.3% 0.0% +4.8% +1.4% +2.8% mutstore2 -0.3% 0.0% +3.4% +1.0% +1.7% power -0.2% 0.0% +2.7% +0.6% +1.9% spellcheck -0.3% 0.0% +1.1% +0.4% +0.4% -------------------------------------------------------------------------------- Min -0.3% 0.0% +0.7% +0.2% +0.4% Max -0.2% 0.0% +6.6% +2.2% +3.6% Geometric Mean -0.3% +0.0% +3.3% +1.0% +1.8% Metric changes -------------- While it sounds ridiculous, this change causes increased allocations in the following tests. We concluded that this change can't cause a difference in allocations and decided to land this patch. Fluctuations in "bytes allocated" metric is tracked in #17686. Metric Increase: Naperian T10547 T12150 T12234 T12425 T13035 T5837 T6048 - - - - - 8038cbd9 by Sebastian Graf at 2020-01-25T05:21:05-05:00 PmCheck: Formulate as translation between Clause Trees We used to check `GrdVec`s arising from multiple clauses and guards in isolation. That resulted in a split between `pmCheck` and `pmCheckGuards`, the implementations of which were similar, but subtly different in detail. Also the throttling mechanism described in `Note [Countering exponential blowup]` ultimately got quite complicated because it had to cater for both checking functions. This patch realises that pattern match checking doesn't just consider single guarded RHSs, but that it's always a whole set of clauses, each of which can have multiple guarded RHSs in turn. We do so by translating a list of `Match`es to a `GrdTree`: ```haskell data GrdTree = Rhs !RhsInfo | Guard !PmGrd !GrdTree -- captures lef-to-right match semantics | Sequence !GrdTree !GrdTree -- captures top-to-bottom match semantics | Empty -- For -XEmptyCase, neutral element of Sequence ``` Then we have a function `checkGrdTree` that matches a given `GrdTree` against an incoming set of values, represented by `Deltas`: ```haskell checkGrdTree :: GrdTree -> Deltas -> CheckResult ... ``` Throttling is isolated to the `Sequence` case and becomes as easy as one would expect: When the union of uncovered values becomes too big, just return the original incoming `Deltas` instead (which is always a superset of the union, thus a sound approximation). The returned `CheckResult` contains two things: 1. The set of values that were not covered by any of the clauses, for exhaustivity warnings. 2. The `AnnotatedTree` that enriches the syntactic structure of the input program with divergence and inaccessibility information. This is `AnnotatedTree`: ```haskell data AnnotatedTree = AccessibleRhs !RhsInfo | InaccessibleRhs !RhsInfo | MayDiverge !AnnotatedTree | SequenceAnn !AnnotatedTree !AnnotatedTree | EmptyAnn ``` Crucially, `MayDiverge` asserts that the tree may force diverging values, so not all of its wrapped clauses can be redundant. While the set of uncovered values can be used to generate the missing equations for warning messages, redundant and proper inaccessible equations can be extracted from `AnnotatedTree` by `redundantAndInaccessibleRhss`. For this to work properly, the interface to the Oracle had to change. There's only `addPmCts` now, which takes a bag of `PmCt`s. There's a whole bunch of `PmCt` variants to replace the different oracle functions from before. The new `AnnotatedTree` structure allows for more accurate warning reporting (as evidenced by a number of changes spread throughout GHC's code base), thus we fix #17465. Fixes #17646 on the go. Metric Decrease: T11822 T9233 PmSeriesS haddock.compiler - - - - - 86966d48 by Sebastian Graf at 2020-01-25T05:21:05-05:00 PmCheck: Properly handle constructor-bound type variables In https://gitlab.haskell.org/ghc/ghc/merge_requests/2192#note_246551 Simon convinced me that ignoring type variables existentially bound by data constructors have to be the same way as value binders. Sadly I couldn't think of a regression test, but I'm confident that this change strictly improves on the status quo. - - - - - c3fde723 by Ryan Scott at 2020-01-25T05:21:40-05:00 Handle local fixity declarations in DsMeta properly `DsMeta.rep_sig` used to skip over `FixSig` entirely, which had the effect of causing local fixity declarations to be dropped when quoted in Template Haskell. But there is no good reason for this state of affairs, as the code in `DsMeta.repFixD` (which handles top-level fixity declarations) handles local fixity declarations just fine. This patch factors out the necessary parts of `repFixD` so that they can be used in `rep_sig` as well. There was one minor complication: the fixity signatures for class methods in each `HsGroup` were stored both in `FixSig`s _and_ the list of `LFixitySig`s for top-level fixity signatures, so I needed to take action to prevent fixity signatures for class methods being converted to `Dec`s twice. I tweaked `RnSource.add` to avoid putting these fixity signatures in two places and added `Note [Top-level fixity signatures in an HsGroup]` in `GHC.Hs.Decls` to explain the new design. Fixes #17608. Bumps the Haddock submodule. - - - - - 6e2d9ee2 by Sylvain Henry at 2020-01-25T05:22:20-05:00 Module hierarchy: Cmm (cf #13009) - - - - - 8b726534 by PHO at 2020-01-25T05:23:01-05:00 Fix rts allocateExec() on NetBSD Similar to SELinux, NetBSD "PaX mprotect" prohibits marking a page mapping both writable and executable at the same time. Use libffi which knows how to work around it. - - - - - 6eb566a0 by Xavier Denis at 2020-01-25T05:23:39-05:00 Add ghc-in-ghci for stack based builds - - - - - b1a32170 by Xavier Denis at 2020-01-25T05:23:39-05:00 Create ghci.cabal.sh - - - - - 0a5e4f5f by Sylvain Henry at 2020-01-25T05:24:19-05:00 Split glasgow_exts into several files (#17316) - - - - - b3e5c678 by Ben Gamari at 2020-01-25T05:24:57-05:00 hadrian: Throw error on duplicate-named flavours Throw an error if the user requests a flavour for which there is more than one match. Fixes #17156. - - - - - 0940b59a by Ryan Scott at 2020-01-25T08:15:05-05:00 Do not bring visible foralls into scope in hsScopedTvs Previously, `hsScopedTvs` (and its cousin `hsWcScopedTvs`) pretended that visible dependent quantification could not possibly happen at the term level, and cemented that assumption with an `ASSERT`: ```hs hsScopedTvs (HsForAllTy { hst_fvf = vis_flag, ... }) = ASSERT( vis_flag == ForallInvis ) ... ``` It turns out that this assumption is wrong. You can end up tripping this `ASSERT` if you stick it to the man and write a type for a term that uses visible dependent quantification anyway, like in this example: ```hs {-# LANGUAGE ScopedTypeVariables #-} x :: forall a -> a -> a x = x ``` That won't typecheck, but that's not the point. Before the typechecker has a chance to reject this, the renamer will try to use `hsScopedTvs` to bring `a` into scope over the body of `x`, since `a` is quantified by a `forall`. This, in turn, causes the `ASSERT` to fail. Bummer. Instead of walking on this dangerous ground, this patch makes GHC adopt a more hardline stance by pattern-matching directly on `ForallInvis` in `hsScopedTvs`: ```hs hsScopedTvs (HsForAllTy { hst_fvf = ForallInvis, ... }) = ... ``` Now `a` will not be brought over the body of `x` at all (which is how it should be), there's no chance of the `ASSERT` failing anymore (as it's gone), and best of all, the behavior of `hsScopedTvs` does not change. Everyone wins! Fixes #17687. - - - - - 1132602f by Ryan Scott at 2020-01-27T10:03:42-05:00 Use splitLHs{ForAll,Sigma}TyInvis throughout the codebase Richard points out in #17688 that we use `splitLHsForAllTy` and `splitLHsSigmaTy` in places that we ought to be using the corresponding `-Invis` variants instead, identifying two bugs that are caused by this oversight: * Certain TH-quoted type signatures, such as those that appear in quoted `SPECIALISE` pragmas, silently turn visible `forall`s into invisible `forall`s. * When quoted, the type `forall a -> (a ~ a) => a` will turn into `forall a -> a` due to a bug in `DsMeta.repForall` that drops contexts that follow visible `forall`s. These are both ultimately caused by the fact that `splitLHsForAllTy` and `splitLHsSigmaTy` split apart visible `forall`s in addition to invisible ones. This patch cleans things up: * We now use `splitLHsForAllTyInvis` and `splitLHsSigmaTyInvis` throughout the codebase. Relatedly, the `splitLHsForAllTy` and `splitLHsSigmaTy` have been removed, as they are easy to misuse. * `DsMeta.repForall` now only handles invisible `forall`s to reduce the chance for confusion with visible `forall`s, which need to be handled differently. I also renamed it from `repForall` to `repForallT` to emphasize that its distinguishing characteristic is the fact that it desugars down to `L.H.TH.Syntax.ForallT`. Fixes #17688. - - - - - 97d0b0a3 by Matthew Pickering at 2020-01-27T10:04:19-05:00 Make Block.h compile with c++ compilers - - - - - 4bada77d by Tom Ellis at 2020-01-27T12:30:46-05:00 Disable two warnings for files that trigger them incomplete-uni-patterns and incomplete-record-updates will be in -Wall at a future date, so prepare for that by disabling those warnings on files that trigger them. - - - - - 0188404a by Tom Ellis at 2020-01-27T12:30:46-05:00 Add two warnings to stage 2 build - - - - - acae02c1 by Tom Ellis at 2020-01-27T12:30:46-05:00 Add two warnings to Hadrian - - - - - bf38a20e by Sylvain Henry at 2020-01-31T02:46:15-05:00 Call `interpretPackageEnv` from `setSessionDynFlags` interpretPackageEnv modifies the flags by reading the dreaded package environments. It is much less surprising to call it from `setSessionDynFlags` instead of reading package environments as a side-effect of `initPackages`. - - - - - 29c701c1 by Sylvain Henry at 2020-01-31T02:46:15-05:00 Refactor package related code The package terminology is a bit of a mess. Cabal packages contain components. Instances of these components when built with some flags/options/dependencies are called units. Units are registered into package databases and their metadata are called PackageConfig. GHC only knows about package databases containing units. It is a sad mismatch not fixed by this patch (we would have to rename parameters such as `package-id <unit-id>` which would affect users). This patch however fixes the following internal names: - Renames PackageConfig into UnitInfo. - Rename systemPackageConfig into globalPackageDatabase[Path] - Rename PkgConfXX into PkgDbXX - Rename pkgIdMap into unitIdMap - Rename ModuleToPkgDbAll into ModuleNameProvidersMap - Rename lookupPackage into lookupUnit - Add comments on DynFlags package related fields It also introduces a new `PackageDatabase` datatype instead of explicitly passing the following tuple: `(FilePath,[PackageConfig])`. The `pkgDatabase` field in `DynFlags` now contains the unit info for each unit of each package database exactly as they have been read from disk. Previously the command-line flag `-distrust-all-packages` would modify these unit info. Now this flag only affects the "dynamic" consolidated package state found in `pkgState` field. It makes sense because `initPackages` could be called first with this `distrust-all-packages` flag set and then again (using ghc-api) without and it should work (package databases are not read again from disk when `initPackages` is called the second time). Bump haddock submodule - - - - - 942c7148 by Ben Gamari at 2020-01-31T02:46:54-05:00 rename: Eliminate usage of mkVarOccUnique Replacing it with `newSysName`. Fixes #17061. - - - - - 41117d71 by Ben Gamari at 2020-01-31T02:47:31-05:00 base: Use one-shot kqueue on macOS The underlying reason requiring that one-shot usage be disabled (#13903) has been fixed. Closes #15768. - - - - - 01b15b83 by Ben Gamari at 2020-01-31T02:48:08-05:00 testsuite: Don't crash on encoding failure in print If the user doesn't use a Unicode locale then the testsuite driver would previously throw framework failures due to encoding failures. We now rather use the `replace` error-handling strategy. - - - - - c846618a by Ömer Sinan Ağacan at 2020-01-31T12:21:10+03:00 Do CafInfo/SRT analysis in Cmm This patch removes all CafInfo predictions and various hacks to preserve predicted CafInfos from the compiler and assigns final CafInfos to interface Ids after code generation. SRT analysis is extended to support static data, and Cmm generator is modified to allow generating static_link fields after SRT analysis. This also fixes `-fcatch-bottoms`, which introduces error calls in case expressions in CorePrep, which runs *after* CoreTidy (which is where we decide on CafInfos) and turns previously non-CAFFY things into CAFFY. Fixes #17648 Fixes #9718 Evaluation ========== NoFib ----- Boot with: `make boot mode=fast` Run: `make mode=fast EXTRA_RUNTEST_OPTS="-cachegrind" NoFibRuns=1` -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS -0.0% 0.0% -0.0% -0.0% -0.0% CSD -0.0% 0.0% -0.0% -0.0% -0.0% FS -0.0% 0.0% -0.0% -0.0% -0.0% S -0.0% 0.0% -0.0% -0.0% -0.0% VS -0.0% 0.0% -0.0% -0.0% -0.0% VSD -0.0% 0.0% -0.0% -0.0% -0.5% VSM -0.0% 0.0% -0.0% -0.0% -0.0% anna -0.1% 0.0% -0.0% -0.0% -0.0% ansi -0.0% 0.0% -0.0% -0.0% -0.0% atom -0.0% 0.0% -0.0% -0.0% -0.0% awards -0.0% 0.0% -0.0% -0.0% -0.0% banner -0.0% 0.0% -0.0% -0.0% -0.0% bernouilli -0.0% 0.0% -0.0% -0.0% -0.0% binary-trees -0.0% 0.0% -0.0% -0.0% -0.0% boyer -0.0% 0.0% -0.0% -0.0% -0.0% boyer2 -0.0% 0.0% -0.0% -0.0% -0.0% bspt -0.0% 0.0% -0.0% -0.0% -0.0% cacheprof -0.0% 0.0% -0.0% -0.0% -0.0% calendar -0.0% 0.0% -0.0% -0.0% -0.0% cichelli -0.0% 0.0% -0.0% -0.0% -0.0% circsim -0.0% 0.0% -0.0% -0.0% -0.0% clausify -0.0% 0.0% -0.0% -0.0% -0.0% comp_lab_zift -0.0% 0.0% -0.0% -0.0% -0.0% compress -0.0% 0.0% -0.0% -0.0% -0.0% compress2 -0.0% 0.0% -0.0% -0.0% -0.0% constraints -0.0% 0.0% -0.0% -0.0% -0.0% cryptarithm1 -0.0% 0.0% -0.0% -0.0% -0.0% cryptarithm2 -0.0% 0.0% -0.0% -0.0% -0.0% cse -0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e1 -0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e2 -0.0% 0.0% -0.0% -0.0% -0.0% dom-lt -0.0% 0.0% -0.0% -0.0% -0.0% eliza -0.0% 0.0% -0.0% -0.0% -0.0% event -0.0% 0.0% -0.0% -0.0% -0.0% exact-reals -0.0% 0.0% -0.0% -0.0% -0.0% exp3_8 -0.0% 0.0% -0.0% -0.0% -0.0% expert -0.0% 0.0% -0.0% -0.0% -0.0% fannkuch-redux -0.0% 0.0% -0.0% -0.0% -0.0% fasta -0.0% 0.0% -0.0% -0.0% -0.0% fem -0.0% 0.0% -0.0% -0.0% -0.0% fft -0.0% 0.0% -0.0% -0.0% -0.0% fft2 -0.0% 0.0% -0.0% -0.0% -0.0% fibheaps -0.0% 0.0% -0.0% -0.0% -0.0% fish -0.0% 0.0% -0.0% -0.0% -0.0% fluid -0.1% 0.0% -0.0% -0.0% -0.0% fulsom -0.0% 0.0% -0.0% -0.0% -0.0% gamteb -0.0% 0.0% -0.0% -0.0% -0.0% gcd -0.0% 0.0% -0.0% -0.0% -0.0% gen_regexps -0.0% 0.0% -0.0% -0.0% -0.0% genfft -0.0% 0.0% -0.0% -0.0% -0.0% gg -0.0% 0.0% -0.0% -0.0% -0.0% grep -0.0% 0.0% -0.0% -0.0% -0.0% hidden -0.0% 0.0% -0.0% -0.0% -0.0% hpg -0.1% 0.0% -0.0% -0.0% -0.0% ida -0.0% 0.0% -0.0% -0.0% -0.0% infer -0.0% 0.0% -0.0% -0.0% -0.0% integer -0.0% 0.0% -0.0% -0.0% -0.0% integrate -0.0% 0.0% -0.0% -0.0% -0.0% k-nucleotide -0.0% 0.0% -0.0% -0.0% -0.0% kahan -0.0% 0.0% -0.0% -0.0% -0.0% knights -0.0% 0.0% -0.0% -0.0% -0.0% lambda -0.0% 0.0% -0.0% -0.0% -0.0% last-piece -0.0% 0.0% -0.0% -0.0% -0.0% lcss -0.0% 0.0% -0.0% -0.0% -0.0% life -0.0% 0.0% -0.0% -0.0% -0.0% lift -0.0% 0.0% -0.0% -0.0% -0.0% linear -0.1% 0.0% -0.0% -0.0% -0.0% listcompr -0.0% 0.0% -0.0% -0.0% -0.0% listcopy -0.0% 0.0% -0.0% -0.0% -0.0% maillist -0.0% 0.0% -0.0% -0.0% -0.0% mandel -0.0% 0.0% -0.0% -0.0% -0.0% mandel2 -0.0% 0.0% -0.0% -0.0% -0.0% mate -0.0% 0.0% -0.0% -0.0% -0.0% minimax -0.0% 0.0% -0.0% -0.0% -0.0% mkhprog -0.0% 0.0% -0.0% -0.0% -0.0% multiplier -0.0% 0.0% -0.0% -0.0% -0.0% n-body -0.0% 0.0% -0.0% -0.0% -0.0% nucleic2 -0.0% 0.0% -0.0% -0.0% -0.0% para -0.0% 0.0% -0.0% -0.0% -0.0% paraffins -0.0% 0.0% -0.0% -0.0% -0.0% parser -0.1% 0.0% -0.0% -0.0% -0.0% parstof -0.1% 0.0% -0.0% -0.0% -0.0% pic -0.0% 0.0% -0.0% -0.0% -0.0% pidigits -0.0% 0.0% -0.0% -0.0% -0.0% power -0.0% 0.0% -0.0% -0.0% -0.0% pretty -0.0% 0.0% -0.3% -0.4% -0.4% primes -0.0% 0.0% -0.0% -0.0% -0.0% primetest -0.0% 0.0% -0.0% -0.0% -0.0% prolog -0.0% 0.0% -0.0% -0.0% -0.0% puzzle -0.0% 0.0% -0.0% -0.0% -0.0% queens -0.0% 0.0% -0.0% -0.0% -0.0% reptile -0.0% 0.0% -0.0% -0.0% -0.0% reverse-complem -0.0% 0.0% -0.0% -0.0% -0.0% rewrite -0.0% 0.0% -0.0% -0.0% -0.0% rfib -0.0% 0.0% -0.0% -0.0% -0.0% rsa -0.0% 0.0% -0.0% -0.0% -0.0% scc -0.0% 0.0% -0.3% -0.5% -0.4% sched -0.0% 0.0% -0.0% -0.0% -0.0% scs -0.0% 0.0% -0.0% -0.0% -0.0% simple -0.1% 0.0% -0.0% -0.0% -0.0% solid -0.0% 0.0% -0.0% -0.0% -0.0% sorting -0.0% 0.0% -0.0% -0.0% -0.0% spectral-norm -0.0% 0.0% -0.0% -0.0% -0.0% sphere -0.0% 0.0% -0.0% -0.0% -0.0% symalg -0.0% 0.0% -0.0% -0.0% -0.0% tak -0.0% 0.0% -0.0% -0.0% -0.0% transform -0.0% 0.0% -0.0% -0.0% -0.0% treejoin -0.0% 0.0% -0.0% -0.0% -0.0% typecheck -0.0% 0.0% -0.0% -0.0% -0.0% veritas -0.0% 0.0% -0.0% -0.0% -0.0% wang -0.0% 0.0% -0.0% -0.0% -0.0% wave4main -0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve1 -0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve2 -0.0% 0.0% -0.0% -0.0% -0.0% x2n1 -0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min -0.1% 0.0% -0.3% -0.5% -0.5% Max -0.0% 0.0% -0.0% -0.0% -0.0% Geometric Mean -0.0% -0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- circsim -0.1% 0.0% -0.0% -0.0% -0.0% constraints -0.0% 0.0% -0.0% -0.0% -0.0% fibheaps -0.0% 0.0% -0.0% -0.0% -0.0% gc_bench -0.0% 0.0% -0.0% -0.0% -0.0% hash -0.0% 0.0% -0.0% -0.0% -0.0% lcss -0.0% 0.0% -0.0% -0.0% -0.0% power -0.0% 0.0% -0.0% -0.0% -0.0% spellcheck -0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min -0.1% 0.0% -0.0% -0.0% -0.0% Max -0.0% 0.0% -0.0% -0.0% -0.0% Geometric Mean -0.0% +0.0% -0.0% -0.0% -0.0% Manual inspection of programs in testsuite/tests/programs --------------------------------------------------------- I built these programs with a bunch of dump flags and `-O` and compared STG, Cmm, and Asm dumps and file sizes. (Below the numbers in parenthesis show number of modules in the program) These programs have identical compiler (same .hi and .o sizes, STG, and Cmm and Asm dumps): - Queens (1), andre_monad (1), cholewo-eval (2), cvh_unboxing (3), andy_cherry (7), fun_insts (1), hs-boot (4), fast2haskell (2), jl_defaults (1), jq_readsPrec (1), jules_xref (1), jtod_circint (4), jules_xref2 (1), lennart_range (1), lex (1), life_space_leak (1), bargon-mangler-bug (7), record_upd (1), rittri (1), sanders_array (1), strict_anns (1), thurston-module-arith (2), okeefe_neural (1), joao-circular (6), 10queens (1) Programs with different compiler outputs: - jl_defaults (1): For some reason GHC HEAD marks a lot of top-level `[Int]` closures as CAFFY for no reason. With this patch we no longer make them CAFFY and generate less SRT entries. For some reason Main.o is slightly larger with this patch (1.3%) and the executable sizes are the same. (I'd expect both to be smaller) - launchbury (1): Same as jl_defaults: top-level `[Int]` closures marked as CAFFY for no reason. Similarly `Main.o` is 1.4% larger but the executable sizes are the same. - galois_raytrace (13): Differences are in the Parse module. There are a lot, but some of the changes are caused by the fact that for some reason (I think a bug) GHC HEAD marks the dictionary for `Functor Identity` as CAFFY. Parse.o is 0.4% larger, the executable size is the same. - north_array: We now generate less SRT entries because some of array primops used in this program like `NewArrayOp` get eliminated during Stg-to-Cmm and turn some CAFFY things into non-CAFFY. Main.o gets 24% larger (9224 bytes from 9000 bytes), executable sizes are the same. - seward-space-leak: Difference in this program is better shown by this smaller example: module Lib where data CDS = Case [CDS] [(Int, CDS)] | Call CDS CDS instance Eq CDS where Case sels1 rets1 == Case sels2 rets2 = sels1 == sels2 && rets1 == rets2 Call a1 b1 == Call a2 b2 = a1 == a2 && b1 == b2 _ == _ = False In this program GHC HEAD builds a new SRT for the recursive group of `(==)`, `(/=)` and the dictionary closure. Then `/=` points to `==` in its SRT field, and `==` uses the SRT object as its SRT. With this patch we use the closure for `/=` as the SRT and add `==` there. Then `/=` gets an empty SRT field and `==` points to `/=` in its SRT field. This change looks fine to me. Main.o gets 0.07% larger, executable sizes are identical. head.hackage ------------ head.hackage's CI script builds 428 packages from Hackage using this patch with no failures. Compiler performance -------------------- The compiler perf tests report that the compiler allocates slightly more (worst case observed so far is 4%). However most programs in the test suite are small, single file programs. To benchmark compiler performance on something more realistic I build Cabal (the library, 236 modules) with different optimisation levels. For the "max residency" row I run GHC with `+RTS -s -A100k -i0 -h` for more accurate numbers. Other rows are generated with just `-s`. (This is because `-i0` causes running GC much more frequently and as a result "bytes copied" gets inflated by more than 25x in some cases) * -O0 | | GHC HEAD | This MR | Diff | | --------------- | -------------- | -------------- | ------ | | Bytes allocated | 54,413,350,872 | 54,701,099,464 | +0.52% | | Bytes copied | 4,926,037,184 | 4,990,638,760 | +1.31% | | Max residency | 421,225,624 | 424,324,264 | +0.73% | * -O1 | | GHC HEAD | This MR | Diff | | --------------- | --------------- | --------------- | ------ | | Bytes allocated | 245,849,209,992 | 246,562,088,672 | +0.28% | | Bytes copied | 26,943,452,560 | 27,089,972,296 | +0.54% | | Max residency | 982,643,440 | 991,663,432 | +0.91% | * -O2 | | GHC HEAD | This MR | Diff | | --------------- | --------------- | --------------- | ------ | | Bytes allocated | 291,044,511,408 | 291,863,910,912 | +0.28% | | Bytes copied | 37,044,237,616 | 36,121,690,472 | -2.49% | | Max residency | 1,071,600,328 | 1,086,396,256 | +1.38% | Extra compiler allocations -------------------------- Runtime allocations of programs are as reported above (NoFib section). The compiler now allocates more than before. Main source of allocation in this patch compared to base commit is the new SRT algorithm (GHC.Cmm.Info.Build). Below is some of the extra work we do with this patch, numbers generated by profiled stage 2 compiler when building a pathological case (the test 'ManyConstructors') with '-O2': - We now sort the final STG for a module, which means traversing the entire program, generating free variable set for each top-level binding, doing SCC analysis, and re-ordering the program. In ManyConstructors this step allocates 97,889,952 bytes. - We now do SRT analysis on static data, which in a program like ManyConstructors causes analysing 10,000 bindings that we would previously just skip. This step allocates 70,898,352 bytes. - We now maintain an SRT map for the entire module as we compile Cmm groups: data ModuleSRTInfo = ModuleSRTInfo { ... , moduleSRTMap :: SRTMap } (SRTMap is just a strict Map from the 'containers' library) This map gets an entry for most bindings in a module (exceptions are THUNKs and CAFFY static functions). For ManyConstructors this map gets 50015 entries. - Once we're done with code generation we generate a NameSet from SRTMap for the non-CAFFY names in the current module. This set gets the same number of entries as the SRTMap. - Finally we update CafInfos in ModDetails for the non-CAFFY Ids, using the NameSet generated in the previous step. This usually does the least amount of allocation among the work listed here. Only place with this patch where we do less work in the CAF analysis in the tidying pass (CoreTidy). However that doesn't save us much, as the pass still needs to traverse the whole program and update IdInfos for other reasons. Only thing we don't here do is the `hasCafRefs` pass over the RHS of bindings, which is a stateless pass that returns a boolean value, so it doesn't allocate much. (Metric changes blow are all increased allocations) Metric changes -------------- Metric Increase: ManyAlternatives ManyConstructors T13035 T14683 T1969 T9961 - - - - - 2a87a565 by Andreas Klebinger at 2020-01-31T12:21:10+03:00 A few optimizations in STG and Cmm parts: (Guided by the profiler output) - Add a few bang patterns, INLINABLE annotations, and a seqList in a few places in Cmm and STG parts. - Do not add external variables as dependencies in STG dependency analysis (GHC.Stg.DepAnal). - - - - - bef704b6 by Simon Peyton Jones at 2020-02-01T02:28:45-05:00 Improve skolemisation This patch avoids skolemiseUnboundMetaTyVar making up a fresh Name when it doesn't need to. See Note [Skolemising and identity] Improves error messsages for partial type signatures. - - - - - cd110423 by Simon Peyton Jones at 2020-02-01T02:28:45-05:00 Improve pretty-printing for TyConBinders In particular, show their kinds. - - - - - 913287a0 by Simon Peyton Jones at 2020-02-01T02:28:45-05:00 Fix scoping of TyCon binders in TcTyClsDecls This patch fixes #17566 by refactoring the way we decide the final identity of the tyvars in the TyCons of a possibly-recursive nest of type and class decls, possibly with associated types. It's all laid out in Note [Swizzling the tyvars before generaliseTcTyCon] Main changes: * We have to generalise each decl (with its associated types) all at once: TcTyClsDecls.generaliseTyClDecl * The main new work is done in TcTyClsDecls.swizzleTcTyConBndrs * The mysterious TcHsSyn.zonkRecTyVarBndrs dies altogether Other smaller things: * A little refactoring, moving bindTyClTyVars from tcTyClDecl1 to tcDataDefn, tcSynRhs, etc. Clearer, reduces the number of parameters * Reduce the amount of swizzling required. Specifically, bindExplicitTKBndrs_Q_Tv doesn't need to clone a new Name for the TyVarTv, and not cloning means that in the vasly common case, swizzleTyConBndrs is a no-op In detail: Rename newTyVarTyVar --> cloneTyVarTyVar Add newTyVarTyTyVar that doesn't clone Use the non-cloning newTyVarTyVar in bindExplicitTKBndrs_Q_Tv Rename newFlexiKindedTyVarTyVar --> cloneFlexiKindedTyVarTyVar * Define new utility function and use it HsDecls.familyDeclName :: FamilyDecl (GhcPass p) -> IdP (GhcPass p) Updates haddock submodule. - - - - - 58ed6c4a by Ben Gamari at 2020-02-01T02:29:23-05:00 rts/M32Alloc: Don't attempt to unmap non-existent pages The m32 allocator's `pages` list may contain NULLs in the case that the page was flushed. Some `munmap` implementations (e.g. FreeBSD's) don't like it if we pass them NULL. Don't do that. - - - - - 859db7d6 by Ömer Sinan Ağacan at 2020-02-01T14:18:49+03:00 Improve/fix -fcatch-bottoms documentation Old documentation suggests that -fcatch-bottoms only adds a default alternative to bottoming case expression, but that's not true. We use a very simplistic "is exhaustive" check and add default alternatives to any case expression that does not cover all constructors of the type. In case of GADTs this simple check assumes all constructors should be covered, even the ones ruled out by the type of the scrutinee. Update the documentation to reflect this. (Originally noticed in #17648) [ci skip] - - - - - 54dfa94a by John Ericson at 2020-02-03T21:14:24-05:00 Fix docs for FrontendResult Other variant was removed in ac1a379363618a6f2f17fff65ce9129164b6ef30 but docs were no changed. - - - - - 5e63d9c0 by John Ericson at 2020-02-03T21:15:02-05:00 Refactor HscMain.finish I found the old control flow a bit hard to follow; I rewrote it to first decide whether to desugar, and then use that choice when computing whether to simplify / what sort of interface file to write. I hope eventually we will always write post-tc interface files, which will make the logic of this function even simpler, and continue the thrust of this refactor. - - - - - e580e5b8 by Stefan Schulze Frielinghaus at 2020-02-04T09:29:00-05:00 Do not build StgCRunAsm.S for unregisterised builds For unregisterised builds StgRun/StgReturn are implemented via a mini interpreter in StgCRun.c and therefore would collide with the implementations in StgCRunAsm.S. - - - - - e3b0bd97 by Stefan Schulze Frielinghaus at 2020-02-04T09:29:00-05:00 fixup! fixup! Do not build StgCRunAsm.S for unregisterised builds - - - - - eb629fab by John Ericson at 2020-02-04T09:29:38-05:00 Delete some superfluous helper functions in HscMain The driver code is some of the nastiest in GHC, and I am worried about being able to untangle all the tech debt. In `HscMain` we have a number of helpers which are either not-used or little used. I delete them so we can reduce cognative load, distilling the essential complexity away from the cruft. - - - - - c90eca55 by Sebastian Graf at 2020-02-05T09:21:29-05:00 PmCheck: Record type constraints arising from existentials in `PmCoreCt`s In #17703 (a follow-up of !2192), we established that contrary to my belief, type constraints arising from existentials in code like ```hs data Ex where Ex :: a -> Ex f _ | let x = Ex @Int 15 = case x of Ex -> ... ``` are in fact useful. This commit makes a number of refactorings and improvements to comments, but fundamentally changes `addCoreCt.core_expr` to record the type constraint `a ~ Int` in addition to `x ~ Ex @a y` and `y ~ 15`. Fixes #17703. - - - - - 6d3b5d57 by Ömer Sinan Ağacan at 2020-02-05T09:22:10-05:00 testlib: Extend existing *_opts in extra_*_opts Previously we'd override the existing {run,hc} opts in extra_{run,hc}_opts, which caused flakiness in T1969, see #17712. extra_{run,hc}_opts now extends {run,hc} opts, instead of overriding. Also we shrank the allocation area for T1969 in order to increase residency sampling frequency. Fixes #17712 - - - - - 9c89a48d by Ömer Sinan Ağacan at 2020-02-05T09:22:52-05:00 Remove CafInfo-related code from STG lambda lift pass After c846618ae0 we don't have accurate CafInfos for Ids in the current module and we're free to introduce new CAFFY or non-CAFFY bindings or change CafInfos of existing binders; so no we no longer need to maintain CafInfos in Core or STG passes. - - - - - 70ddb8bf by Ryan Scott at 2020-02-05T09:23:30-05:00 Add regression test for #17773 - - - - - e8004e5d by Ben Gamari at 2020-02-05T13:55:19-05:00 gitlab-ci: Allow Windows builds to fail again Due to T7702 and the process issues described in #17777. - - - - - 29b72c00 by Ben Gamari at 2020-02-06T11:55:41-05:00 VarSet: Introduce nonDetFoldVarSet - - - - - c4e6b35d by Ben Gamari at 2020-02-06T11:55:41-05:00 Move closeOverKinds and friends to TyCoFVs - - - - - ed2f0e5c by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Reform the free variable finders for types This patch delivers on (much of) #17509. * Introduces the shallow vs deep free variable distinction * Introduce TyCoRep.foldType, foldType :: Monoid a => TyCoFolder env a -> env -> Type -> a and use it in the free variable finders. * Substitution in TyCoSubst * ASSERTs are on for checkValidSubst * checkValidSubst uses shallowTyCoVarsOfTypes etc Quite a few things still to do * We could use foldType in lots of other places * We could use mapType for substitution. (Check that we get good code!) * Some (but not yet all) clients of substitution can now save time by using shallowTyCoVarsOfTypes * All calls to tyCoVarsOfTypes should be inspected; most of them should be shallow. Maybe. * Currently shallowTyCoVarsOfTypes still returns unification variables, but not CoVarHoles. Reason: we need to return unification variables in some of the calls in TcSimplify, eg when promoting. * We should do the same thing for tyCoFVsOfTypes, which is currently unchanged. * tyCoFVsOfTypes returns CoVarHoles, because of the use in TcSimplify.mkResidualConstraints. See Note [Emitting the residual implication in simplifyInfer] * #17509 talks about "relevant" variables too. - - - - - 01a1f4fb by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Use foldTyCo for noFreeVarsOfType - - - - - 0e59afd6 by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Simplify closeOverKinds - - - - - 9ca5c88e by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Use foldTyCo for coVarsOfType - - - - - 5541b87c by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Use foldTyCo for exactTyCoVarsOfType This entailed * Adding a tcf_view field to TyCoFolder * Moving exactTyCoVarsOtType to TcType. It properly belongs there, since only the typechecker calls this function. But it also means that we can "see" and inline tcView. Metric Decrease: T14683 - - - - - 7c122851 by Simon Peyton Jones at 2020-02-06T11:56:02-05:00 Comments only - - - - - 588acb99 by Adam Sandberg Eriksson at 2020-02-08T10:15:38-05:00 slightly better named cost-centres for simple pattern bindings #17006 ``` main = do print $ g [1..100] a where g xs x = map (`mod` x) xs a :: Int = 324 ``` The above program previously attributed the cost of computing 324 to a cost centre named `(...)`, with this change the cost is attributed to `a` instead. This change only affects simple pattern bindings (decorated variables: type signatures, parens, ~ annotations and ! annotations). - - - - - 309f8cfd by Richard Eisenberg at 2020-02-08T10:16:33-05:00 Remove unnecessary parentheses - - - - - 7755ffc2 by Richard Eisenberg at 2020-02-08T10:16:33-05:00 Introduce IsPass; refactor wrappers. There are two main payloads of this patch: 1. This introduces IsPass, which allows e.g. printing code to ask what pass it is running in (Renamed vs Typechecked) and thus print extension fields. See Note [IsPass] in Hs.Extension 2. This moves the HsWrap constructor into an extension field, where it rightly belongs. This is done for HsExpr and HsCmd, but not for HsPat, which is left as an exercise for the reader. There is also some refactoring around SyntaxExprs, but this is really just incidental. This patch subsumes !1721 (sorry @chreekat). Along the way, there is a bit of refactoring in GHC.Hs.Extension, including the removal of NameOrRdrName in favor of NoGhcTc. This meant that we had no real need for GHC.Hs.PlaceHolder, so I got rid of it. Updates haddock submodule. ------------------------- Metric Decrease: haddock.compiler ------------------------- - - - - - 7d452be4 by Dylan Yudaken at 2020-02-08T10:17:17-05:00 Fix hs_try_putmvar losing track of running cap If hs_try_putmvar was called through an unsafe import, it would lose track of the running cap causing a deadlock - - - - - c2e301ae by Ben Gamari at 2020-02-08T10:17:55-05:00 compiler: Qualify imports of Data.List - - - - - aede171a by Ben Gamari at 2020-02-08T10:17:55-05:00 testsuite: Fix -Wcompat-unqualified-imports issues - - - - - 4435a8e0 by Ben Gamari at 2020-02-08T10:17:55-05:00 Introduce -Wcompat-unqualified-imports This implements the warning proposed in option (B) of the Data.List.singleton CLC [discussion][]. This warning, which is included in `-Wcompat` is intended to help users identify imports of modules that will change incompatibly in future GHC releases. This currently only includes `Data.List` due to the expected specialisation and addition of `Data.List.singleton`. Fixes #17244. [discussion]: https://groups.google.com/d/msg/haskell-core-libraries/q3zHLmzBa5E/PmlAs_kYAQAJ - - - - - 28b5349a by Ben Gamari at 2020-02-08T10:17:55-05:00 Bump stm and process submodules - - - - - 7d04b9f2 by Ben Gamari at 2020-02-08T10:18:31-05:00 hadrian: Allow override of Cabal configuration in hadrian.settings Fixes #17612 by adding a `cabal.configure.opts` key for `hadrian.settings`. - - - - - 88bf81aa by Andreas Klebinger at 2020-02-08T10:19:10-05:00 Optimize unpackCString# to allocate less. unpackCString# is a recursive function which for each iteration returns a Cons cell containing the current Char, and a thunk for unpacking the rest of the string. In this patch we change from storing addr + offset inside this thunk to storing only the addr, simply incrementing the address on each iteration. This saves one word of allocation per unpacked character. For a program like "main = print "<largishString>" this amounts to 2-3% fewer % in bytes allocated. I also removed the now redundant local unpack definitions. This removes one call per unpack operation. - - - - - bec76733 by Ben Gamari at 2020-02-08T10:19:57-05:00 Fix GhcThreaded setting This adopts a patch from NetBSD's packaging fixing the `GhcThreaded` option of the make build system. In addition we introduce a `ghcThreaded` option in hadrian's `Flavour` type. Also fix Hadrian's treatment of the `Use Threaded` entry in `settings`. Previously it would incorrectly claim `Use Threaded = True` if we were building the `threaded` runtime way. However, this is inconsistent with the `make` build system, which defines it to be whether the `ghc` executable is linked against the threaded runtime. Fixes #17692. - - - - - 545cf1e1 by Ben Gamari at 2020-02-08T10:20:37-05:00 hadrian: Depend upon libray dependencies when configuring packages This will hopefully fix #17631. - - - - - 047d3d75 by Ben Gamari at 2020-02-08T10:21:16-05:00 testsuite: Add test for #15316 This is the full testcase for T15316. - - - - - 768e5866 by Julien Debon at 2020-02-08T10:22:07-05:00 doc(Data.List): Add some examples to Data.List - - - - - 3900cb83 by Julien Debon at 2020-02-08T10:22:07-05:00 Apply suggestion to libraries/base/GHC/List.hs - - - - - bd666766 by Ben Gamari at 2020-02-08T10:22:45-05:00 users-guide: Clarify that bundled patsyns were introduced in GHC 8.0 Closes #17094. - - - - - 95741ea1 by Pepe Iborra at 2020-02-08T10:23:23-05:00 Update to hie-bios 0.3.2 style program cradle - - - - - fb5c1912 by Sylvain Henry at 2020-02-08T10:24:07-05:00 Remove redundant case This alternative is redundant and triggers no warning when building with 8.6.5 - - - - - 5d83d948 by Matthew Pickering at 2020-02-08T10:24:43-05:00 Add mkHieFileWithSource which doesn't read the source file from disk cc/ @pepeiborra - - - - - dfdae56d by Andreas Klebinger at 2020-02-08T10:25:20-05:00 Rename ghcAssert to stgAssert in hp2ps/Main.h. This fixes #17763 - - - - - 658f7ac6 by Ben Gamari at 2020-02-08T10:26:00-05:00 includes: Avoid using single-line comments in HsFFI.h While single-line comments are supported by C99, dtrace on SmartOS apparently doesn't support them yet. - - - - - c95920a6 by Ömer Sinan Ağacan at 2020-02-08T10:26:42-05:00 Import qualified Prelude in parser This is in preparation of backwards-incompatible changes in happy. See https://github.com/simonmar/happy/issues/166 - - - - - b6dc319a by Ömer Sinan Ağacan at 2020-02-08T10:27:23-05:00 Add regression test for #12760 The bug seems to be fixed in the meantime, make sure it stays fixed. Closes #12760 - - - - - b3857b62 by Ben Gamari at 2020-02-08T10:28:03-05:00 base: Drop out-of-date comment The comment in GHC.Base claimed that ($) couldn't be used in that module as it was wired-in. However, this is no longer true; ($) is merely known key and is defined in Haskell (with a RuntimeRep-polymorphic type) in GHC.Base. The one piece of magic that ($) retains is that it a special typing rule to allow type inference with higher-rank types (e.g. `runST $ blah`; see Note [Typing rule for ($)] in TcExpr). - - - - - 1183ae94 by Daniel Gröber at 2020-02-08T10:29:00-05:00 rts: Fix Arena blocks accounting for MBlock sized allocations When requesting more than BLOCKS_PER_MBLOCK blocks allocGroup can return a different number of blocks than requested. Here we use the number of requested blocks, however arenaFree will subtract the actual number of blocks we got from arena_blocks (possibly) resulting in a negative value and triggering ASSERT(arena_blocks >= 0). - - - - - 97d59db5 by Daniel Gröber at 2020-02-08T10:29:48-05:00 rts: Fix need_prealloc being reset when retainer profiling is on - - - - - 1f630025 by Krzysztof Gogolewski at 2020-02-09T02:52:27-05:00 Add a test for #15712 - - - - - 2ac784ab by Ben Gamari at 2020-02-09T02:53:05-05:00 hadrian: Add --test-metrics argument Allowing the test metric output to be captured to a file, a la the METRIC_FILE environment variable of the make build system. - - - - - f432d8c6 by Ben Gamari at 2020-02-09T02:53:05-05:00 hadrian: Fix --test-summary argument This appears to be a cut-and-paste error. - - - - - a906595f by Arnaud Spiwack at 2020-02-09T02:53:50-05:00 Fix an outdated note link This link appears to have been forgotten in 0dad81ca5fd1f63bf8a3b6ad09787559e8bd05c0 . - - - - - 3ae83da1 by Alp Mestanogullari at 2020-02-09T02:54:28-05:00 hadrian: Windows fixes (bindists, CI) This commit implements a few Windows-specific fixes which get us from a CI job that can't even get as far as starting the testsuite driver, to a state where we can run the entire testssuite (but have test failures to fix). - Don't forget about a potential extension for the haddock program, when preparing the bindist. - Build the timeout program, used by the testsuite driver on Windows in place of the Python script used elsewhere, using the boot compiler. We could alternatively build it with the compiler that we're going to test but this would be a lot more tedious to write. - Implement a wrapper-script less installation procedure for Windows, in `hadrian/bindist/Makefile. - Make dependencies a bit more accurate in the aforementioned Makefile. - Update Windows/Hadrian CI job accordingly. This patch fixes #17486. - - - - - 82f9be8c by Roland Senn at 2020-02-09T02:55:06-05:00 Fix #14628: Panic (No skolem Info) in GHCi This patch implements the [sugggestion from Simon (PJ)](https://gitlab.haskell.org/ghc/ghc/issues/14628#note_146559): - Make `TcErrors.getSkolemInfo` return a `SkolemInfo` rather than an `Implication`. - If `getSkolemInfo` gets `RuntimeUnk`s, just return a new data constructor in `SkolemInfo`, called `RuntimeUnkSkol`. - In `TcErrors.pprSkols` print something sensible for a `RuntimeUnkSkol`. The `getSkolemInfo` function paniced while formating suggestions to add type annotations (subfunction `suggestAddSig`) to a *"Couldn't match type ‘x’ with ‘y’"* error message. The `getSkolemInfo` function didn't find any Implication value and paniced. With this patch the `getSkolemInfo` function does no longer panic, if it finds `RuntimeUnkSkol`s. As the panic occured while processing an error message, we don't need to implement any new error message! - - - - - b2e18e26 by Andreas Klebinger at 2020-02-09T02:55:46-05:00 Fix -ddump-stg-final. Once again make sure this dumps the STG used for codegen. - - - - - 414e2f62 by Sylvain Henry at 2020-02-09T02:56:26-05:00 Force -fPIC for intree GMP (fix #17799) Configure intree GMP with `--with-pic` instead of patching it. Moreover the correct patching was only done for x86_64/darwin (see #17799). - - - - - f0fd72ee by Sebastian Graf at 2020-02-09T17:22:38-05:00 8.10 Release notes for improvements to the pattern-match checker [skip ci] A little late to the game, but better late than never. - - - - - 00dc0f7e by Ömer Sinan Ağacan at 2020-02-09T17:23:17-05:00 Add regression test for #13142 Closes #13142 - - - - - f3e737bb by Sebastian Graf at 2020-02-10T20:04:09-05:00 Fix long distance info for record updates For record updates where the `record_expr` is a variable, as in #17783: ```hs data PartialRec = No | Yes { a :: Int, b :: Bool } update No = No update r@(Yes {}) = r { b = False } ``` We should make use of long distance info in `-Wincomplete-record-updates` checking. But the call to `matchWrapper` in the `RecUpd` case didn't specify a scrutinee expression, which would correspond to the `record_expr` `r` here. That is fixed now. Fixes #17783. - - - - - 5670881d by Tamar Christina at 2020-02-10T20:05:04-05:00 Fs: Fix UNC remapping code. - - - - - 375b3c45 by Oleg Grenrus at 2020-02-11T05:07:30-05:00 Add singleton to Data.OldList - - - - - de32beff by Richard Eisenberg at 2020-02-11T05:08:10-05:00 Do not create nested quantified constraints Previously, we would accidentally make constraints like forall a. C a => forall b. D b => E a b c as we traversed superclasses. No longer! This patch also expands Note [Eagerly expand given superclasses] to work over quantified constraints; necessary for T16502b. Close #17202 and #16502. test cases: typecheck/should_compile/T{17202,16502{,b}} - - - - - e319570e by Ben Gamari at 2020-02-11T05:08:47-05:00 rts: Use nanosleep instead of usleep usleep was removed in POSIX.1-2008. - - - - - b75e7486 by Ben Gamari at 2020-02-11T05:09:24-05:00 rts: Remove incorrect assertions around MSG_THROWTO messages Previously we would assert that threads which are sending a `MSG_THROWTO` message must have their blocking status be blocked on the message. In the usual case of a thread throwing to another thread this is guaranteed by `stg_killThreadzh`. However, `throwToSelf`, used by the GC to kill threads which ran out of heap, failed to guarantee this. Noted while debugging #17785. - - - - - aba51b65 by Sylvain Henry at 2020-02-11T05:10:04-05:00 Add arithmetic exception primops (#14664) - - - - - b157399f by Ben Gamari at 2020-02-11T05:10:40-05:00 configure: Don't assume Gnu linker on Solaris Compl Yue noticed that the linker was dumping the link map on SmartOS. This is because Smartos uses the Solaris linker, which uses the `-64` flag, not `-m64` like Gnu ld, to indicate that it should link for 64-bits. Fix the configure script to handle the Solaris linker correctly. - - - - - d8d73d77 by Simon Peyton Jones at 2020-02-11T05:11:18-05:00 Notes only: telescopes This documentation-only patch fixes #17793 - - - - - 58a4ddef by Alp Mestanogullari at 2020-02-11T05:12:17-05:00 hadrian: build (and ship) iserv on Windows - - - - - 82023524 by Matthew Pickering at 2020-02-11T18:04:17-05:00 TemplateHaskellQuotes: Allow nested splices There is no issue with nested splices as they do not require any compile time code execution. All execution is delayed until the top-level splice. - - - - - 50e24edd by Ömer Sinan Ağacan at 2020-02-11T18:04:57-05:00 Remove Hadrian's copy of (Data.Functor.<&>) The function was added to base with base-4.11 (GHC 8.4) - - - - - f82a2f90 by Sylvain Henry at 2020-02-12T01:56:46-05:00 Document GMP build [skip ci] - - - - - da7f7479 by Sylvain Henry at 2020-02-12T01:57:27-05:00 Module hierarchy: ByteCode and Runtime (cf #13009) Update haddock submodule - - - - - 04f51297 by Ömer Sinan Ağacan at 2020-02-12T01:58:11-05:00 Fix naming of tests for #12923 - - - - - 31fc3321 by Ömer Sinan Ağacan at 2020-02-12T01:58:11-05:00 Add regression test for #12926 Closes #12926 - - - - - f0c0ee7d by Krzysztof Gogolewski at 2020-02-12T01:58:51-05:00 Fix order of arguments in specializer (#17801) See https://gitlab.haskell.org/ghc/ghc/issues/17801#note_253330 No regression test, as it's hard to trigger. - - - - - 059c3c9d by Sebastian Graf at 2020-02-12T11:00:58+01:00 Separate CPR analysis from the Demand analyser The reasons for that can be found in the wiki: https://gitlab.haskell.org/ghc/ghc/wikis/nested-cpr/split-off-cpr We now run CPR after demand analysis (except for after the final demand analysis run just before code gen). CPR got its own dump flags (`-ddump-cpr-anal`, `-ddump-cpr-signatures`), but not its own flag to activate/deactivate. It will run with `-fstrictness`/`-fworker-wrapper`. As explained on the wiki page, this step is necessary for a sane Nested CPR analysis. And it has quite positive impact on compiler performance: Metric Decrease: T9233 T9675 T9961 T15263 - - - - - f5ffd8d9 by Ben Gamari at 2020-02-12T17:22:37-05:00 base: Expose GHC.Unicode.unicodeVersion This exposes a Data.Version.Version representing the version of the Unicode database used by `base`. This should clear up some confusion I have seen in tickets regarding with which Unicode versions a given GHC can be expected to work. While in town I also regenerated (but did not update) the Unicode database with database 12.0.0. Strangely, the file cited in the README no longer existed. Consequently, I used https://www.unicode.org/Public/12.0.0/ucd/UnicodeData.txt and was slightly surprised to find that there were a few changes. - - - - - 6c2585e0 by Ben Gamari at 2020-02-12T17:22:37-05:00 base: Update Unicode database to 12.1.0 Using `curl https://www.unicode.org/Public/12.1.0/ucd/UnicodeData.txt | libraries/base/cbits/ubconfc 12.1.0`. - - - - - df084681 by Krzysztof Gogolewski at 2020-02-12T23:58:52+01:00 Always display inferred variables using braces We now always show "forall {a}. T" for inferred variables, previously this was controlled by -fprint-explicit-foralls. This implements part 1 of https://github.com/ghc-proposals/ghc-proposals/pull/179. Part of GHC ticket #16320. Furthermore, when printing a levity restriction error, we now display the HsWrap of the expression. This lets users see the full elaboration with -fprint-typechecker-elaboration (see also #17670) - - - - - 16d643cf by Sylvain Henry at 2020-02-13T09:16:04-05:00 Remove -ddump-srts flag This flag is deemed not useful. - - - - - fa28ae95 by Sylvain Henry at 2020-02-13T09:16:04-05:00 Fix flag documentation (#17826) - - - - - 1bfd8259 by Sylvain Henry at 2020-02-13T09:16:43-05:00 Ensure that Hadrian is built correctly before using it When Hadrian failed to build, the script would pick a previously built Hadrian (if available) instead of failing. - - - - - cd6e786a by Ömer Sinan Ağacan at 2020-02-14T05:29:56-05:00 Add test for #17648 - - - - - 9f2c3677 by Sylvain Henry at 2020-02-14T05:30:39-05:00 GMP expects the Target platform as --host parameter - - - - - aa6086fd by Oleg Grenrus at 2020-02-14T05:31:16-05:00 Add explicit LANGUAGE Safe to template-haskell (cherry picked from commit a5e0f376821ca882880b03b07b451aa574e289ec) - - - - - af6a0c36 by Ben Gamari at 2020-02-14T05:31:53-05:00 hadrian: Add execution and target architecture to stage-compilation figure - - - - - cf739945 by Sylvain Henry at 2020-02-14T05:32:37-05:00 Module hierarchy: HsToCore (cf #13009) - - - - - 719db318 by Simon Peyton Jones at 2020-02-14T05:33:16-05:00 De-duplicate overlapping Notes Documentation only. Fixes #17827 - - - - - 7550417a by Sylvain Henry at 2020-02-14T05:33:56-05:00 Hadrian: drop Sphinx flag checking for PDF documentation (#17825) It seems that Sphinx produces the ghc-flags.txt in doc/users_guide/_build rather than pdfRoot. We could copy ghc-flags.txt into pdfRoot (like happens naturally in the HTML case) but the benefit is pretty small. Let's just only check the HTML case. - - - - - 813842f4 by Ben Gamari at 2020-02-14T10:16:36-05:00 make: Be more selective in building windows-extra-src tarball - - - - - 0725f4bb by Ben Gamari at 2020-02-14T10:16:36-05:00 Rework handling of win32 toolchain tarballs - - - - - 565ce7ae by Ben Gamari at 2020-02-14T10:16:36-05:00 gitlab-ci: Consolidate CI logic This moves nearly all of the CI logic to .gitlab/ci.sh. This improves things in a number of ways: * it's harder for inconsistencies to arise between architectures * it's easier to share logic between architectures * on Windows, it's easier to ensure that all CI steps are executed from within a properly initialized mingw session. While in town I also add a FreeBSD build job and update the Windows job to use the gitlab-runner PowerShell executor, since cmd.exe will be deprecated soon (fixing #17699). - - - - - 9cbace74 by Ben Gamari at 2020-02-14T10:16:36-05:00 gitlab-ci: Deduplicate nightly job configuration - - - - - 6e837144 by Ben Gamari at 2020-02-14T10:16:36-05:00 integer-gmp: Fix unused command-line argument -L is only needed during linking. - - - - - e5ee07ab by Ben Gamari at 2020-02-14T10:16:36-05:00 testsuite: Don't ask sed to operate in-place on symlinks Some sed implementations (e.g. FreeBSD) refuse to operate in-place on symlinks. - - - - - 71e5e68f by Ben Gamari at 2020-02-14T10:16:36-05:00 testsuite: Disable tests that assume name of libstdc++ on FreeBSD - - - - - 7b2da0f4 by Ben Gamari at 2020-02-14T10:16:36-05:00 testsuite: Mark T6132 as broken on FreeBSD - - - - - 8ef7a15a by Ben Gamari at 2020-02-14T10:16:36-05:00 testsuite/T16930: Don't rely on gnu grep specific --include In BSD grep this flag only affects directory recursion. - - - - - 6060003e by Ben Gamari at 2020-02-14T10:16:36-05:00 Pass -Wno-unused-command-line-arguments during link on FreeBSD FreeBSD cc throws a warning if we pass -pthread without actually using any pthread symbols. - - - - - 97497bae by Ben Gamari at 2020-02-14T10:16:36-05:00 base: Always clamp reads/writes to 2GB in length Previously we did this only on Darwin due to #17414. However, even on other platforms >2GB writes are on shaky ground. POSIX explicitly says that the result is implementation-specified and Linux will write at most 0x7ffff000, even on 64-bit platforms. Moreover, getting the sign of the syscall result correct is tricky, as demonstrated by the fact that T17414 currently fails on FreeBSD. For simplicity we now just uniformly clamp to 0x7ffff000 on all platforms. - - - - - 49be2a3f by Ben Gamari at 2020-02-14T10:16:36-05:00 configure: Fix sphinx version test The check for the "v" prefix is redundant. - - - - - f7f7a556 by Ben Gamari at 2020-02-14T10:16:37-05:00 users-guide: Fix unknown link targets - - - - - a204102c by Ben Gamari at 2020-02-14T10:16:37-05:00 docs/compare-flags: Don't use python f-strings - - - - - 92e15a37 by Ben Gamari at 2020-02-14T10:16:37-05:00 gitlab-ci: Fix various shellcheck warnings - - - - - 459f7c6e by Ben Gamari at 2020-02-14T10:16:37-05:00 hadrian: Drop empty arguments from target list Fixes #17748. - - - - - c06df28d by Ben Gamari at 2020-02-14T10:16:37-05:00 users-guide: Fix "invalid file" failure I have no idea how this worked previously. Different Python version? - - - - - 3fe8444f by Ben Gamari at 2020-02-14T10:16:59-05:00 testsuite: Mark T7702 as fragile on Windows Due to #16799. There was previously an attempt to mark it as broken but the `opsys` name was incorrect. - - - - - fe02f781 by Ben Gamari at 2020-02-14T10:16:59-05:00 testsuite: Assert the opsys names are known Previously opsys would take any string. This meant it was very easy for a typo to silently render the predicate ineffective. Fix this by checking the given operating system name against a list of known values. - - - - - 149e2a3a by Ben Gamari at 2020-02-14T10:16:59-05:00 compare-flags: Don't rely on encoding flag of subprocess.check_output Apparently it isn't supported by some slightly older Python versions. - - - - - 798d59f6 by Ben Gamari at 2020-02-14T10:16:59-05:00 rts: Add more debug output to failed path in onIOComplete This will help track down #17035. - - - - - e35f3f98 by Ben Gamari at 2020-02-14T10:16:59-05:00 gitlab-ci: Allow i386 Windows builds to fail again Due to the resistance of #17736 to resolution. - - - - - 261a3cf8 by Ben Gamari at 2020-02-14T10:17:00-05:00 gitlab-ci: Build integer-simple job in the validate flavour - - - - - b613a961 by Ben Gamari at 2020-02-14T10:17:00-05:00 gitlab-ci: Always use mingw64 python on Windows - - - - - 1bc8c8cd by Ben Gamari at 2020-02-14T10:17:00-05:00 gitlab-ci: Allow Windows build to fail due to #17777 The fact that `exec` isn't POSIX compliant means that things can break in arbitrarily bad ways. Sometimes things happen to work correctly but sadly this isn't always the case. - - - - - ac63020d by Ben Gamari at 2020-02-14T10:17:00-05:00 gitlab-ci: Drop unnecessary GHC_VERSION check - - - - - 6926f369 by Ben Gamari at 2020-02-14T10:17:00-05:00 Bump process submodule Folds in the second part of Phyx's Windows process exit fixes [1], hopefully finally resolving issue #17480. [1] https://github.com/haskell/process/pull/160 - - - - - 584eee71 by Tamar Christina at 2020-02-14T10:17:00-05:00 SysTools: Use "process job" when spawning processes on Windows GHC should make calls using process jobs when calling out to GCC and LD. The reason is these use the exec () family of posix functions. Window's process model doesn't allow replacement of processes so this is emulated by creating a new process and immediately exiting the old one. Because of this when using normal Windows wait functions you would return even without the child process having finished. In this case if you are depending on data from the child you will enter a race condition. The usual fix for this is to use process jobs and wait for the termination of all children that have ever been spawn by the process you called. But also waiting for the freeing of all resources. - - - - - ecabfa28 by Tamar Christina at 2020-02-14T10:17:00-05:00 Revert "compiler: Disable atomic renaming on Windows" The original reason this was disabled should be fixed by the previous commit. This reverts commit 1c1b63d63efe8b0f789aa7d5b87cfac3edd213eb. - - - - - 06d60c66 by Ben Gamari at 2020-02-14T10:17:00-05:00 Bump Cabal submodule - - - - - 8cabb384 by Ben Gamari at 2020-02-14T10:17:00-05:00 compare-flags: Fix output - - - - - 8cf646d3 by Ben Gamari at 2020-02-14T10:17:00-05:00 users-guide: Document -ddump-srts - - - - - 932307a5 by Ben Gamari at 2020-02-14T10:17:00-05:00 users-guide: Fix broken reference - - - - - e77818de by Ben Gamari at 2020-02-15T09:26:55-05:00 Accept performance changes These manifested in the integer-simple job. Metric Decrease: T12227 T5549 T14936 T4830 Conversions T5237 T8766 T4801 T10359 Metric Increase: T12234 T6048 T3294 T14683 T3064 T9872b T9872c T783 T5837 T10678 T14697 T5631 T9203 T13719 T12707 T13056 T9630 T10547 T9872d T1969 WWRec T10370 T5321FD haddock.Cabal T5642 T9872a T15263 T12425 MultiLayerModules T5205 T9233 T13379 haddock.base T9020 T13035 T12150 T9961 - - - - - 785008c1 by Ben Gamari at 2020-02-15T09:30:13-05:00 testsuite: Sort test names in expected change output - - - - - 9e851472 by Ömer Sinan Ağacan at 2020-02-16T10:38:41+03:00 Revert "users-guide: Document -ddump-srts" This reverts commit 8cf646d36b02b8ea1c289cb52781c9171853b514. The flag was removed by 16d643cf. [ci skip] - - - - - 9792c816 by Ben Gamari at 2020-02-16T09:47:08-05:00 testsuite: Probe whether symlinks are usable on Windows Closes #17706. - - - - - ee1e5342 by Vladislav Zavialov at 2020-02-16T09:47:44-05:00 Fix the "unused terminals: 2" warning in Parser.y - - - - - b4a8ce52 by Roland Senn at 2020-02-18T20:14:42-05:00 If a :reload finds syntax errors in the module graph, remove the loaded modules. (Fixes #17549) The processing in `compiler/main/GhcMake.hs` computes the ModuleGraph. If it finds errors in the module header or in the import specifications, then the new module graph is incomplete and should not be used. The code before #17549 just reported the errors and left the old ModuleGraph in place. The new code of this MR replaces the old ModuleGraph with an empty one. - - - - - d7029cc0 by Sylvain Henry at 2020-02-18T20:15:30-05:00 Hadrian: refactor GMP in-tree build support (#17756) * Hadrian doesn't use integer-gmp/config.mk file anymore to determine if building GMP in-tree is required. "config.mk" is created by Cabal when the integer-gmp package is configured and this file is still untracked by Hadrian. This led to a tricky configure "race" because "config.mk" is built by the "setup-config" rule, but this rule is also used to find dependencies, in particular the "ghc-gmp.h" header, but the creation of this file was depending (without being tracked) on "config.mk". Now Hadrian only builds in-tree GMP if `--with-intree-gmp` is passed to the top-level configure script. * in-tree GMP isn't built once for all in a fixed stage (Stage1) anymore. It is built per stage which is required if we build a cross-compiler * switching between in-tree and external GMP is now supported without having to clean the build directory first. * "wrappers.c" now includes "ghc-gmp.h" instead of "ghc.h". It helps ensuring that the build system generates "ghc-gmp.h". * build in-tree GMP in "<root>/stageN/gmp/gmpbuild" and produce useful artefacts (libgmp.a, gmp.h, objs/*.o) in "<root>/stageN/gmp" - - - - - 40d917fb by Vladislav Zavialov at 2020-02-18T20:16:07-05:00 Remove the MonadFail P instance There were two issues with this instance: * its existence meant that a pattern match failure in the P monad would produce a user-visible parse error, but the error message would not be helpful to the user * due to the MFP migration strategy, we had to use CPP in Lexer.x, and that created issues for #17750 Updates haddock submodule. - - - - - 5a1ce45d by Joshua Price at 2020-02-18T20:16:47-05:00 Fix unboxed tuple size limit (#17837) - - - - - 192caf58 by Vladislav Zavialov at 2020-02-18T20:17:24-05:00 Fix testsuite driver output (#17847) - - - - - 1500f089 by Sylvain Henry at 2020-02-18T20:18:12-05:00 Modules: Llvm (#13009) - - - - - d53e81c0 by Niklas Hambüchen at 2020-02-20T10:36:22-05:00 8.10 Release notes for atomic .o writes [skip ci] - - - - - 19680ee5 by Niklas Hambüchen at 2020-02-20T10:37:53-05:00 8.10 Release notes for --disable-delayed-os-memory-return [skip ci] - - - - - 74ad75e8 by Simon Peyton Jones at 2020-02-20T21:17:57-05:00 Re-implement unsafe coercions in terms of unsafe equality proofs (Commit message written by Omer, most of the code is written by Simon and Richard) See Note [Implementing unsafeCoerce] for how unsafe equality proofs and the new unsafeCoerce# are implemented. New notes added: - [Checking for levity polymorphism] in CoreLint.hs - [Implementing unsafeCoerce] in base/Unsafe/Coerce.hs - [Patching magic definitions] in Desugar.hs - [Wiring in unsafeCoerce#] in Desugar.hs Only breaking change in this patch is unsafeCoerce# is not exported from GHC.Exts, instead of GHC.Prim. Fixes #17443 Fixes #16893 NoFib ----- -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS -0.1% 0.0% -0.0% -0.0% -0.0% CSD -0.1% 0.0% -0.0% -0.0% -0.0% FS -0.1% 0.0% -0.0% -0.0% -0.0% S -0.1% 0.0% -0.0% -0.0% -0.0% VS -0.1% 0.0% -0.0% -0.0% -0.0% VSD -0.1% 0.0% -0.0% -0.0% -0.1% VSM -0.1% 0.0% -0.0% -0.0% -0.0% anna -0.0% 0.0% -0.0% -0.0% -0.0% ansi -0.1% 0.0% -0.0% -0.0% -0.0% atom -0.1% 0.0% -0.0% -0.0% -0.0% awards -0.1% 0.0% -0.0% -0.0% -0.0% banner -0.1% 0.0% -0.0% -0.0% -0.0% bernouilli -0.1% 0.0% -0.0% -0.0% -0.0% binary-trees -0.1% 0.0% -0.0% -0.0% -0.0% boyer -0.1% 0.0% -0.0% -0.0% -0.0% boyer2 -0.1% 0.0% -0.0% -0.0% -0.0% bspt -0.1% 0.0% -0.0% -0.0% -0.0% cacheprof -0.1% 0.0% -0.0% -0.0% -0.0% calendar -0.1% 0.0% -0.0% -0.0% -0.0% cichelli -0.1% 0.0% -0.0% -0.0% -0.0% circsim -0.1% 0.0% -0.0% -0.0% -0.0% clausify -0.1% 0.0% -0.0% -0.0% -0.0% comp_lab_zift -0.1% 0.0% -0.0% -0.0% -0.0% compress -0.1% 0.0% -0.0% -0.0% -0.0% compress2 -0.1% 0.0% -0.0% -0.0% -0.0% constraints -0.1% 0.0% -0.0% -0.0% -0.0% cryptarithm1 -0.1% 0.0% -0.0% -0.0% -0.0% cryptarithm2 -0.1% 0.0% -0.0% -0.0% -0.0% cse -0.1% 0.0% -0.0% -0.0% -0.0% digits-of-e1 -0.1% 0.0% -0.0% -0.0% -0.0% digits-of-e2 -0.1% 0.0% -0.0% -0.0% -0.0% dom-lt -0.1% 0.0% -0.0% -0.0% -0.0% eliza -0.1% 0.0% -0.0% -0.0% -0.0% event -0.1% 0.0% -0.0% -0.0% -0.0% exact-reals -0.1% 0.0% -0.0% -0.0% -0.0% exp3_8 -0.1% 0.0% -0.0% -0.0% -0.0% expert -0.1% 0.0% -0.0% -0.0% -0.0% fannkuch-redux -0.1% 0.0% -0.0% -0.0% -0.0% fasta -0.1% 0.0% -0.5% -0.3% -0.4% fem -0.1% 0.0% -0.0% -0.0% -0.0% fft -0.1% 0.0% -0.0% -0.0% -0.0% fft2 -0.1% 0.0% -0.0% -0.0% -0.0% fibheaps -0.1% 0.0% -0.0% -0.0% -0.0% fish -0.1% 0.0% -0.0% -0.0% -0.0% fluid -0.1% 0.0% -0.0% -0.0% -0.0% fulsom -0.1% 0.0% +0.0% +0.0% +0.0% gamteb -0.1% 0.0% -0.0% -0.0% -0.0% gcd -0.1% 0.0% -0.0% -0.0% -0.0% gen_regexps -0.1% 0.0% -0.0% -0.0% -0.0% genfft -0.1% 0.0% -0.0% -0.0% -0.0% gg -0.1% 0.0% -0.0% -0.0% -0.0% grep -0.1% 0.0% -0.0% -0.0% -0.0% hidden -0.1% 0.0% -0.0% -0.0% -0.0% hpg -0.1% 0.0% -0.0% -0.0% -0.0% ida -0.1% 0.0% -0.0% -0.0% -0.0% infer -0.1% 0.0% -0.0% -0.0% -0.0% integer -0.1% 0.0% -0.0% -0.0% -0.0% integrate -0.1% 0.0% -0.0% -0.0% -0.0% k-nucleotide -0.1% 0.0% -0.0% -0.0% -0.0% kahan -0.1% 0.0% -0.0% -0.0% -0.0% knights -0.1% 0.0% -0.0% -0.0% -0.0% lambda -0.1% 0.0% -0.0% -0.0% -0.0% last-piece -0.1% 0.0% -0.0% -0.0% -0.0% lcss -0.1% 0.0% -0.0% -0.0% -0.0% life -0.1% 0.0% -0.0% -0.0% -0.0% lift -0.1% 0.0% -0.0% -0.0% -0.0% linear -0.1% 0.0% -0.0% -0.0% -0.0% listcompr -0.1% 0.0% -0.0% -0.0% -0.0% listcopy -0.1% 0.0% -0.0% -0.0% -0.0% maillist -0.1% 0.0% -0.0% -0.0% -0.0% mandel -0.1% 0.0% -0.0% -0.0% -0.0% mandel2 -0.1% 0.0% -0.0% -0.0% -0.0% mate -0.1% 0.0% -0.0% -0.0% -0.0% minimax -0.1% 0.0% -0.0% -0.0% -0.0% mkhprog -0.1% 0.0% -0.0% -0.0% -0.0% multiplier -0.1% 0.0% -0.0% -0.0% -0.0% n-body -0.1% 0.0% -0.0% -0.0% -0.0% nucleic2 -0.1% 0.0% -0.0% -0.0% -0.0% para -0.1% 0.0% -0.0% -0.0% -0.0% paraffins -0.1% 0.0% -0.0% -0.0% -0.0% parser -0.1% 0.0% -0.0% -0.0% -0.0% parstof -0.1% 0.0% -0.0% -0.0% -0.0% pic -0.1% 0.0% -0.0% -0.0% -0.0% pidigits -0.1% 0.0% -0.0% -0.0% -0.0% power -0.1% 0.0% -0.0% -0.0% -0.0% pretty -0.1% 0.0% -0.1% -0.1% -0.1% primes -0.1% 0.0% -0.0% -0.0% -0.0% primetest -0.1% 0.0% -0.0% -0.0% -0.0% prolog -0.1% 0.0% -0.0% -0.0% -0.0% puzzle -0.1% 0.0% -0.0% -0.0% -0.0% queens -0.1% 0.0% -0.0% -0.0% -0.0% reptile -0.1% 0.0% -0.0% -0.0% -0.0% reverse-complem -0.1% 0.0% -0.0% -0.0% -0.0% rewrite -0.1% 0.0% -0.0% -0.0% -0.0% rfib -0.1% 0.0% -0.0% -0.0% -0.0% rsa -0.1% 0.0% -0.0% -0.0% -0.0% scc -0.1% 0.0% -0.1% -0.1% -0.1% sched -0.1% 0.0% -0.0% -0.0% -0.0% scs -0.1% 0.0% -0.0% -0.0% -0.0% simple -0.1% 0.0% -0.0% -0.0% -0.0% solid -0.1% 0.0% -0.0% -0.0% -0.0% sorting -0.1% 0.0% -0.0% -0.0% -0.0% spectral-norm -0.1% 0.0% -0.0% -0.0% -0.0% sphere -0.1% 0.0% -0.0% -0.0% -0.0% symalg -0.1% 0.0% -0.0% -0.0% -0.0% tak -0.1% 0.0% -0.0% -0.0% -0.0% transform -0.1% 0.0% -0.0% -0.0% -0.0% treejoin -0.1% 0.0% -0.0% -0.0% -0.0% typecheck -0.1% 0.0% -0.0% -0.0% -0.0% veritas -0.0% 0.0% -0.0% -0.0% -0.0% wang -0.1% 0.0% -0.0% -0.0% -0.0% wave4main -0.1% 0.0% -0.0% -0.0% -0.0% wheel-sieve1 -0.1% 0.0% -0.0% -0.0% -0.0% wheel-sieve2 -0.1% 0.0% -0.0% -0.0% -0.0% x2n1 -0.1% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min -0.1% 0.0% -0.5% -0.3% -0.4% Max -0.0% 0.0% +0.0% +0.0% +0.0% Geometric Mean -0.1% -0.0% -0.0% -0.0% -0.0% Test changes ------------ - break006 is marked as broken, see #17833 - The compiler allocates less when building T14683 (an unsafeCoerce#- heavy happy-generated code) on 64-platforms. Allocates more on 32-bit platforms. - Rest of the increases are tiny amounts (still enough to pass the threshold) in micro-benchmarks. I briefly looked at each one in a profiling build: most of the increased allocations seem to be because of random changes in the generated code. Metric Decrease: T14683 Metric Increase: T12150 T12234 T12425 T13035 T14683 T5837 T6048 Co-Authored-By: Richard Eisenberg <rae at cs.brynmawr.edu> Co-Authored-By: Ömer Sinan Ağacan <omeragacan at gmail.com> - - - - - 6880d6aa by Sylvain Henry at 2020-02-20T21:18:48-05:00 Disentangle DynFlags and SDoc Remove several uses of `sdocWithDynFlags`. The remaining ones are mostly CodeGen related (e.g. depend on target platform constants) and will be fixed separately. Metric Decrease: T12425 T9961 WWRec T1969 T14683 - - - - - 70a90110 by Julien Debon at 2020-02-20T21:19:27-05:00 doc(List): Add examples to GHC.List * Add examples * Cleanup documentation * Clarify merge process and Marge bot - - - - - c8439fc7 by Peter Trommler at 2020-02-20T21:20:05-05:00 Fix testsuite on powerpc64le Remove expect broken on recomp tests, #11260 was closed by !2264 and #11323 most likely by !2264 as well. GHCi scripts tests work on GHCi but not the external interpreter, adjust test configuration accordingly. Fixes unexpected passes. Mark test requiring DWARF expect fail on powerpc64[le] for #11261. - - - - - 65b7256a by Ömer Sinan Ağacan at 2020-02-20T21:20:45-05:00 Use concatMap(M) instead of `concat . map` and the monadic variant - - - - - 8b76d457 by Roland Senn at 2020-02-20T21:21:28-05:00 Fix #17832: Weird handling of exports named main in 8.10-rc1 Switching from `lookupGlobalOccRn_maybe` to `lookupInfoOccRn` to check whether a `main` function is in scope. Unfortunately `lookupGlobalOccRn_maybe` complains if there are multiple `main` functions in scope. - - - - - 466e1ad5 by Krzysztof Gogolewski at 2020-02-20T21:22:11-05:00 Use TTG for HsSplicedT constructor The constructor HsSplicedT occurs only in the GhcTc pass. This enforces this fact statically via TTG. - - - - - 4e622fca by Alexis King at 2020-02-20T21:22:49-05:00 Normalize types when dropping absent arguments from workers fixes #17852 - - - - - a533e547 by Adam Sandberg Eriksson at 2020-02-20T21:23:31-05:00 Mention users guide and release notes in merge request template - - - - - 05251b17 by Ben Gamari at 2020-02-20T21:24:08-05:00 gitlab-ci: Fix typo in BIN_DIST_PREP_TAR_COMP variable name - - - - - f44c7e67 by Ben Gamari at 2020-02-20T21:24:46-05:00 gitlab-ci: Avoid duplicating ~/.cabal contents with every build Previously our attempt to cache the cabal store would `cp cabal-cache ~/.cabal`. However, if the latter already existed this meant that we would end up with ~/.cabal/cabal-cache. Not only would this not help caching but it would exponentially grow the size of ~/.cabal. Not good! - - - - - c5ec9965 by Ben Gamari at 2020-02-20T21:56:13-05:00 GHC.Hs.Extension: Use Type instead of * - - - - - 89cb4cc4 by Ben Gamari at 2020-02-20T21:56:13-05:00 Use Type instead of * in GHC - - - - - 04eb0d6c by Ben Gamari at 2020-02-20T21:56:13-05:00 Enable -Wstar-is-type in -Wall As noted in [proposal 0143][proposal] this is supposed to happen in 8.12. Also fix an incorrect claim in the users guide that -Wstar-is-type is enabled by default. [proposal]: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0143-remove-star-kind.rst - - - - - 6de966f1 by Andreas Klebinger at 2020-02-20T21:56:15-05:00 Fix #17724 by having occAnal preserve used bindings. It sometimes happened that occAnal would remove bindings as dead code by relying on bindings to be in dependency order. The fix was contributed by SPJ. - - - - - abd7f962 by Ben Gamari at 2020-02-20T21:56:15-05:00 users-guide: Mention dependency on `exceptions` in release notes Fixes #17845. - - - - - 58175379 by Sylvain Henry at 2020-02-20T21:56:20-05:00 Hadrian: minor GMP refactoring Somehow I forgot to totally remove `gmpContext` in d7029cc09edc052c2f97effe33233c53340fcce0. This patch fixes it and adds some additional comments. - - - - - 33fa8d94 by Ryan Scott at 2020-02-20T21:56:21-05:00 Generalize liftData to work over any Quote (#17857) The Overloaded Quotations proposal generalized the type of `lift` to work over any `Quote`, but not the type of `liftData`, leading to #17857. Thankfully, generalizing `liftData` is extremely straightforward. Fixes #17857. - - - - - 3cea6795 by Sylvain Henry at 2020-02-20T21:56:23-05:00 Make: fix sdist target (#17848) - - - - - e2cce997 by Sylvain Henry at 2020-02-20T21:56:23-05:00 Hadrian: fix source-dist target (#17849) - - - - - 0a4c89b2 by Matthew Pickering at 2020-02-21T20:44:45-05:00 Special case `mkTyConApp liftedTypeKind []` We really need to make sure that these are shared because otherwise GHC will allocate thousands of identical `TyConApp` nodes. See #17292 ------------------------- Metric Decrease: haddock.Cabal T14683 ------------------------- - - - - - 0482f58a by Matthew Pickering at 2020-02-21T20:45:21-05:00 TH: wrapGenSyns, don't split the element type too much The invariant which allowed the pervious method of splitting the type of the body to find the type of the elements didn't work in the new overloaded quotation world as the type can be something like `WriterT () m a` rather than `Q a` like before. Fixes #17839 - - - - - be7068a6 by Vladislav Zavialov at 2020-02-21T20:45:59-05:00 Parser API annotations: RealSrcLoc During parsing, GHC collects lexical information about AST nodes and stores it in a map. It is needed to faithfully restore original source code, e.g. compare these expressions: a = b a = b The position of the equality sign is not recorded in the AST, so it must be stored elsewhere. This system is described in Note [Api annotations]. Before this patch, the mapping was represented by: Map (SrcSpan, AnnKeywordId) SrcSpan After this patch, the mapping is represented by: Map (RealSrcSpan, AnnKeywordId) RealSrcSpan The motivation behind this change is to avoid using the Ord SrcSpan instance (required by Map here), as it interferes with #17632 (see the discussion there). SrcSpan is isomorphic to Either String RealSrcSpan, but we shouldn't use those strings as Map keys. Those strings are intended as hints to the user, e.g. "<interactive>" or "<compiler-generated code>", so they are not a valid way to identify nodes in the source code. - - - - - 240f5bf6 by Sylvain Henry at 2020-02-21T20:46:40-05:00 Modules: Driver (#13009) submodule updates: nofib, haddock - - - - - 9d094111 by Sylvain Henry at 2020-02-21T20:47:19-05:00 Hadrian: `docs` rule needs `configure` (#17840) - - - - - 1674353a by Ben Gamari at 2020-02-23T17:31:19-05:00 fs: Port fixes from ghc-jailbreak repository * Override rename, unlink, and remove * Factor out wchar conversion - - - - - 853210f2 by Adam Sandberg Ericsson at 2020-02-23T17:32:03-05:00 show gcc linker options in configure summary - - - - - 2831544a by Adam Sandberg Ericsson at 2020-02-23T17:32:44-05:00 hadrian: docs depend on stage1 ghc - - - - - 1d9df9e0 by Adam Sandberg Ericsson at 2020-02-23T17:33:23-05:00 ci: after 5ce63d52fed the linux bindist for doc-tarball has changed name - - - - - 26e8fff3 by Vladislav Zavialov at 2020-02-24T02:05:30-05:00 Remove Ord SrcLoc, Ord SrcSpan Before this patch, GHC relied on Ord SrcSpan to identify source elements, by using SrcSpan as Map keys: blackList :: Map SrcSpan () -- compiler/GHC/HsToCore/Coverage.hs instanceMap :: Map SrcSpan Name -- compiler/GHC/HsToCore/Docs.hs Firstly, this design is not valid in presence of UnhelpfulSpan, as it distinguishes between UnhelpfulSpan "X" and UnhelpfulSpan "Y", but those strings are messages for the user, unfit to serve as identifiers for source elements. Secondly, this design made it hard to extend SrcSpan with additional data. Recall that the definition of SrcSpan is: data SrcSpan = RealSrcSpan !RealSrcSpan | UnhelpfulSpan !FastString Say we want to extend the RealSrcSpan constructor with additional information: data SrcSpan = RealSrcSpan !RealSrcSpan !AdditionalInformation | UnhelpfulSpan !FastString getAdditionalInformation :: SrcSpan -> AdditionalInformation getAdditionalInformation (RealSrcSpan _ a) = a Now, in order for Map SrcSpan to keep working correctly, we must *ignore* additional information when comparing SrcSpan values: instance Ord SrcSpan where compare (RealSrcSpan r1 _) (RealSrcSpan r2 _) = compare r1 r2 ... However, this would violate an important law: a == b therefore f a == f b Ignoring AdditionalInformation in comparisons would mean that with f=getAdditionalInformation, the law above does not hold. A more robust design is to avoid Ord SrcSpan altogether, which is what this patch implements. The mappings are changed to use RealSrcSpan instead: blackList :: Set RealSrcSpan -- compiler/GHC/HsToCore/Coverage.hs instanceMap :: Map RealSrcSpan Name -- compiler/GHC/HsToCore/Docs.hs All SrcSpan comparisons are now done with explicit comparison strategies: SrcLoc.leftmost_smallest SrcLoc.leftmost_largest SrcLoc.rightmost_smallest These strategies are not subject to the law mentioned above and can easily discard both the string stored in UnhelpfulSpan and AdditionalInformation. Updates haddock submodule. - - - - - 5aa6c188 by Ben Gamari at 2020-02-24T02:06:09-05:00 users-guide: Shuffle text - - - - - e3f17413 by Ben Gamari at 2020-02-24T02:06:09-05:00 users-guide: Drop old release notes - - - - - 84dd9610 by Ben Gamari at 2020-02-24T02:06:09-05:00 Bump directory submodule to 1.3.6.0 - - - - - e295a024 by Stefan Pavikevik at 2020-02-24T20:53:44-05:00 check for safe arguments, raising error when invalid (fix #17720) - - - - - 354e2787 by Krzysztof Gogolewski at 2020-02-24T20:54:35-05:00 Comments, small refactor * Remove outdated Note [HsForAllTy tyvar binders] and [Context quantification]. Since the wildcard refactor 1e041b7382, HsForAllTy no longer has an flag controlling explicity. The field `hsq_implicit` is gone too. The current situation is covered by Note [HsType binders] which is already linked from LHsQTyVars. * Small refactor in CoreLint, extracting common code to a function * Remove "not so sure about WpFun" in TcEvidence, per Richard's comment https://gitlab.haskell.org/ghc/ghc/merge_requests/852#note_223226 * Use mkIfThenElse in Foreign/Call, as it does exactly what we need. - - - - - 1b1067d1 by Sylvain Henry at 2020-02-24T20:55:25-05:00 Modules: CmmToAsm (#13009) - - - - - 621468f6 by Alexis King at 2020-02-26T15:08:09-05:00 Treat coercions as arguments for floating and inlining This reverts commit 8924224ecfa065ebc67b96a90d01cf9d2edd0e77 and fixes #17787. - - - - - def486c9 by Ben Gamari at 2020-02-26T15:08:47-05:00 hadrian: Allow libnuma library path to be specified - - - - - ed03d4e7 by Ben Gamari at 2020-02-26T15:08:47-05:00 hadrian: Refactor gmp arguments Move the gmp configuration to its own binding. - - - - - 09b88384 by Ben Gamari at 2020-02-26T15:08:47-05:00 hadrian: Tell Cabal about integer-gmp library location - - - - - 161e08c5 by Krzysztof Gogolewski at 2020-02-26T15:09:30-05:00 Remove dead code * FailablePattern can no longer be created since ab51bee40c82 Therefore, Opt_WarnMissingMonadFailInstances has no effect anymore. * XWrap is no longer used, it was moved to an extension field - - - - - e0d09db3 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Use 8.8.3 to bootstrap on Windows This should fix #17861. - - - - - 972bcf3a by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Fix symlink test Needs to `write` bytes, not str. - - - - - 273e60de by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Add shell subcommand for debugging within CI environment - - - - - 43b13ed3 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Fix colors on Darwin Darwin sh doesn't support \e. - - - - - 217546a7 by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Flush stdout buffers in InitEventLogging Otherwise we are sensitive to libc's buffering strategy. Similar to the issue fixed in 543dfaab166c81f46ac4af76918ce32190aaab22. - - - - - c7d4fa55 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Add run_hadrian subcommand I've ruined two trees already by failing to pass --flavour to hadrian. Let's factor this out so it can be reused during troubleshooting. - - - - - 7dc54873 by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Allow tests to be marked as broken on the command line This allows us to work-around distribution-specific breakage easily. - - - - - 25e2458e by Ben Gamari at 2020-02-26T15:10:09-05:00 hadrian: Add --broken-test flag This exposes the flag of the same name supported by the testsuite driver. - - - - - 55769996 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Mark some tests as broken on Alpine - - - - - 9ee7f87d by Ben Gamari at 2020-02-26T15:10:09-05:00 SysTools: Don't use process jobs if they are broken - - - - - bfaa3961 by Ben Gamari at 2020-02-26T15:10:09-05:00 Bump hsc2hs submodule Fixes name of C compiler. - - - - - b2b49a0a by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Make hasMetricsFile RHS more descriptive - - - - - 817f93ea by Sylvain Henry at 2020-02-26T15:10:58-05:00 Modules: Core (#13009) Update haddock submodule - - - - - 74311e10 by Sebastian Graf at 2020-02-27T16:22:45-05:00 PmCheck: Implement Long-distance information with Covered sets Consider ```hs data T = A | B | C f :: T -> Int f A = 1 f x = case x of A -> 2 B -> 3 C -> 4 ``` Clearly, the RHS returning 2 is redundant. But we don't currently see that, because our approximation to the covered set of the inner case expression just picks up the positive information from surrounding pattern matches. It lacks the context sensivity that `x` can't be `A` anymore! Therefore, we adopt the conceptually and practically superior approach of reusing the covered set of a particular GRHS from an outer pattern match. In this case, we begin checking the `case` expression with the covered set of `f`s second clause, which encodes the information that `x` can't be `A` anymore. After this MR, we will successfully warn about the RHS returning 2 being redundant. Perhaps surprisingly, this was a great simplification to the code of both the coverage checker and the desugarer. Found a redundant case alternative in `unix` submodule, so we have to bump it with a fix. Metric Decrease: T12227 - - - - - 59c023ba by Adam Sandberg Ericsson at 2020-02-27T16:23:25-05:00 configure: correctly generate LIBRARY_template_haskell_VERSION - - - - - 9be82389 by Krzysztof Gogolewski at 2020-02-28T02:35:35-05:00 boot: Remove remote origin check Previously, we used relative paths in submodules. When cloning from GitHub, they had to be manually tweaked. Since a76b233d we use absolute paths, so this workaround can be removed. - - - - - f4b6b594 by Ben Gamari at 2020-02-28T02:36:12-05:00 nonmoving: Fix marking in compact regions Previously we were tracing the object we were asked to mark, even if it lives in a compact region. However, there is no need to do this; we need only to mark the region itself as live. I have seen a segfault due to this due to the concurrent mark seeing a an object in the process of being compacted by the mutator. - - - - - f97d1fb6 by Alp Mestanogullari at 2020-02-28T02:36:59-05:00 base: use an explicit import list in System.Environment.ExecutablePath This was making -Werror builds fail on Windows (at least with Hadrian). - - - - - 66f5d6d6 by Simon Peyton Jones at 2020-02-28T22:03:23-05:00 Improve error handling for VTA + deferred type errors This fixes #17792 See Note [VTA for out-of-scope functions] in TcExpr - - - - - 37f12603 by Ilias Tsitsimpis at 2020-02-28T22:04:04-05:00 llvm-targets: Add arm-unknown-linux-gnueabi Add arm-unknown-linux-gnueabi, which is used by Debian's ARM EABI port (armel), as an LLVM target. - - - - - 327b29e1 by Vladislav Zavialov at 2020-02-29T05:06:31-05:00 Monotonic locations (#17632) When GHC is parsing a file generated by a tool, e.g. by the C preprocessor, the tool may insert #line pragmas to adjust the locations reported to the user. As the result, the locations recorded in RealSrcLoc are not monotonic. Elements that appear later in the StringBuffer are not guaranteed to have a higher line/column number. In fact, there are no guarantees whatsoever, as #line pragmas can arbitrarily modify locations. This lack of guarantees makes ideas such as #17544 infeasible. This patch adds an additional bit of information to every SrcLoc: newtype BufPos = BufPos { bufPos :: Int } A BufPos represents the location in the StringBuffer, unaffected by any pragmas. Updates haddock submodule. Metric Increase: haddock.Cabal haddock.base haddock.compiler MultiLayerModules Naperian parsing001 T12150 - - - - - 99d2de86 by Ben Gamari at 2020-02-29T05:07:10-05:00 plugins: Ensure that loadInterface plugins can see annotations loadInterface replaces the `mi_decls`, `mi_insts`, `mi_fam_insts`, `mi_rules`, `mi_anns` fields of ModIface with `undefined` before inserting the interface into the EPS. However, we still want to give loadInterface plugins access to these fields. Consequently, we want to pass the unmodified `ModIface` the plugin. - - - - - a999ee96 by Xavier Denis at 2020-02-29T05:07:50-05:00 Rename ghci.sh and build.sh to ghci and build respectively Convert hadrian buildscripts to unsuffixed, dashed form final cleanups - - - - - b5fb58fd by Ömer Sinan Ağacan at 2020-02-29T05:08:36-05:00 Document and refactor a few things around bitmap scavenging - Added a few comments in StgPAP - Added a few comments and assertions in scavenge_small_bitmap and walk_large_bitmap - Did tiny refactor in GHC.Data.Bitmap: added some comments, deleted dead code, used PlatformWordSize type. - - - - - 18757cab by Sylvain Henry at 2020-02-29T05:09:25-05:00 Refactor runtime interpreter code In #14335 we want to be able to use both the internal interpreter (for the plugins) and the external interpreter (for TH and GHCi) at the same time. This patch performs some preliminary refactoring: the `hsc_interp` field of HscEnv replaces `hsc_iserv` and is now used to indicate which interpreter (internal, external) to use to execute TH and GHCi. Opt_ExternalInterpreter flag and iserv options in DynFlags are now queried only when we set the session DynFlags. It should help making GHC multi-target in the future by selecting an interpreter according to the selected target. - - - - - b86a6395 by Adam Sandberg Ericsson at 2020-02-29T05:10:06-05:00 docs: correct relative links to haddocks from users guide (fixes #17866) - - - - - 0f55df7f by Adam Sandberg Ericsson at 2020-02-29T05:10:06-05:00 docs: correct link to th haddocks from users guide - - - - - 252e5117 by Jean-Baptiste Mazon at 2020-02-29T05:10:46-05:00 rts: enforce POSIX numeric locale for heap profiles - - - - - 34c7d230 by Sylvain Henry at 2020-02-29T05:11:27-05:00 Fix Hadrian's ``--configure`` (fix #17883) - - - - - 04d30137 by Ömer Sinan Ağacan at 2020-02-29T05:12:06-05:00 Simplify IfaceIdInfo type IfaceIdInfo type is confusing: there's practically no difference between `NoInfo` and `HasInfo []`. The comments say NoInfo is used when -fomit-interface-pragmas is enabled, but we don't need to distinguish `NoInfo` from `HasInfo []` in when reading the interface so the distinction is not important. This patch simplifies the type by removing NoInfo. When we have no info we use an empty list. With this change we no longer read the info list lazily when reading an IfaceInfoItem, but when reading an IfaceId the ifIdInfo field is read lazily, so I doubt this is going to be a problem. - - - - - 3979485b by Roland Senn at 2020-02-29T17:36:59+01:00 Show breakpoint locations of breakpoints which were ignored during :force (#2950) GHCi is split up into 2 major parts: The user-interface (UI) and the byte-code interpreter. With `-fexternal-interpreter` they even run in different processes. Communication between the UI and the Interpreter (called `iserv`) is done using messages over a pipe. This is called `Remote GHCI` and explained in the Note [Remote GHCi] in `compiler/ghci/GHCi.hs`. To process a `:force` command the UI sends a `Seq` message to the `iserv` process. Then `iserv` does the effective evaluation of the value. When during this process a breakpoint is hit, the `iserv` process has no additional information to enhance the `Ignoring breakpoint` output with the breakpoint location. To be able to print additional breakpoint information, there are 2 possible implementation choices: 1. Store the needed information in the `iserv` process. 2. Print the `Ignoring breakpoint` from the UI process. For option 1 we need to store the breakpoint info redundantely in 2 places and this is bad. Therfore option 2 was implemented in this MR: - The user enters a `force` command - The UI sends a `Seq` message to the `iserv` process. - If processing of the `Seq` message hits a breakpoint, the `iserv` process returns control to the UI process. - The UI looks up the source location of the breakpoint, and prints the enhanced `Ignoring breakpoint` output. - The UI sends a `ResumeSeq` message to the `iserv` process, to continue forcing. - - - - - 3cf7303b by Krzysztof Gogolewski at 2020-03-02T01:18:33-05:00 Remove dead code * The names in PrelName and THNames are no longer used since TH merged types and kinds, Typeable is kind-polymorphic, .net support was removed * unqualQuasiQuote no longer used since 6f8ff0bbad3b9fa3 - - - - - dbea7e9d by Ilias Tsitsimpis at 2020-03-02T01:19:12-05:00 Do not define hs_atomic{read,write}64() on non-64bit Do not define hs_atomicread64() and hs_atomicwrite64() on machines where WORD_SIZE_IN_BITS is less than 64, just like we do with the rest of the atomic functions which work on 64-bit values. Without this, compilation fails on MIPSel and PowerPC with the following error: /usr/bin/ld: /<<PKGBUILDDIR>>/libraries/ghc-prim/dist-install/build/libHSghc-prim-0.5.3_p.a(atomic.p_o): in function `hs_atomicread64': atomic.c:(.text.hs_atomicread64+0x8): undefined reference to `__sync_add_and_fetch_8' /usr/bin/ld: /<<PKGBUILDDIR>>/libraries/ghc-prim/dist-install/build/libHSghc-prim-0.5.3_p.a(atomic.p_o): in function `hs_atomicwrite64': atomic.c:(.text.hs_atomicwrite64+0x38): undefined reference to `__sync_bool_compare_and_swap_8' Fixes #17886. - - - - - 7c0c76fb by Roland Senn at 2020-03-02T17:13:55-05:00 Set `ImpredicativeTypes` during :print command. (#14828) If ImpredicativeTypes is not enabled, then `:print <term>` will fail if the type of <term> has nested `forall`s or `=>`s. This is because the GHCi debugger's internals will attempt to unify a metavariable with the type of <term> and then display the result, but if the type has nested `forall`s or `=>`s, then unification will fail. As a result, `:print` will bail out and the unhelpful result will be `<term> = (_t1::t1)` (where `t1` is a metavariable). Beware: <term> can have nested `forall`s even if its definition doesn't use RankNTypes! Here is an example from #14828: class Functor f where fmap :: (a -> b) -> f a -> f b Somewhat surprisingly, `:print fmap` considers the type of fmap to have nested foralls. This is because the GHCi debugger sees the type `fmap :: forall f. Functor f => forall a b. (a -> b) -> f a -> f b`. We could envision deeply instantiating this type to get the type `forall f a b. Functor f => (a -> b) -> f a -> f b`, but this trick wouldn't work for higher-rank types. Instead, we adopt a simpler fix: enable `ImpredicativeTypes` when using `:print` and friends in the GHCi debugger. This is allows metavariables to unify with types that have nested (or higher-rank) `forall`s/`=>`s, which makes `:print fmap` display as `fmap = (_t1::forall a b. Functor f => (a -> b) -> f a -> f b)`, as expected. Although ImpredicativeTypes is a somewhat unpredictable from a type inference perspective, there is no danger in using it in the GHCi debugger, since all of the terms that the GHCi debugger deals with have already been typechecked. - - - - - 2a2f51d7 by Sylvain Henry at 2020-03-02T17:14:38-05:00 Use configure script to detect that we should use in-tree GMP on Windows - - - - - 8c663c2c by Andreas Klebinger at 2020-03-04T16:12:14+01:00 Be explicit about how stack usage of mvar primops are covered. This fixes #17893 [skip-ci] - - - - - cedd6f30 by Ben Gamari at 2020-03-05T14:53:12-05:00 rts: Add getCurrentThreadCPUTime helper - - - - - ace618cd by Ben Gamari at 2020-03-05T14:53:12-05:00 nonmoving-gc: Track time usage of nonmoving marking - - - - - 022b5ad5 by Ben Gamari at 2020-03-05T14:53:12-05:00 Stats: Add sync pauses to +RTS -S output - - - - - 06763234 by Ben Gamari at 2020-03-05T14:53:12-05:00 rts: Report nonmoving collector statistics in machine-readable output - - - - - 70d2b995 by Ben Gamari at 2020-03-09T06:10:52-04:00 nonmoving: Fix collection of sparks Previously sparks living in the non-moving heap would be promptly GC'd by the minor collector since pruneSparkQueue uses the BF_EVACUATED flag, which non-moving heap blocks do not have set. Fix this by implementing proper support in pruneSparkQueue for determining reachability in the non-moving heap. The story is told in Note [Spark management in the nonmoving heap]. - - - - - 9668781a by Ben Gamari at 2020-03-09T06:11:30-04:00 gitlab-ci: Disable Sphinx documentation in Alpine build - - - - - 8eb2c263 by Jean-Baptiste Mazon at 2020-03-09T16:33:37-04:00 Fix Windows breakage by not touching locales on Windows - - - - - b8dab057 by Jean-Baptiste Mazon at 2020-03-09T16:33:37-04:00 rts: ensure C numerics in heap profiles using Windows locales if needed - - - - - 7d95260f by Jean-Baptiste Mazon at 2020-03-09T16:33:37-04:00 rts: refactor and comment profile locales - - - - - 5b627813 by Ryan Scott at 2020-03-09T16:34:14-04:00 Use InstanceSigs in GND/DerivingVia-generated code (#17899) Aside from making the generated code easier to read when `-ddump-deriv` is enabled, this makes the error message in `T15073` substantially simpler (see the updated `T15073` expected stderr). Fixes #17899. - - - - - 70b50778 by Ben Gamari at 2020-03-10T02:05:42-04:00 SysTools: Ensure that error parser can handle absolute paths on Windows This fixes #17786, where the error parser fails to correctly handle the drive name in absolute Windows paths. Unfortunately I couldn't find a satisfactory way to test this. - - - - - 85b861d8 by Ben Gamari at 2020-03-10T02:05:42-04:00 testsuite: Add test for #17786 This isn't pretty but it's perhaps better than nothing. - - - - - ee2c50cb by Sylvain Henry at 2020-03-10T02:06:33-04:00 Hadrian: track missing configure results - - - - - ca8f51d4 by Ömer Sinan Ağacan at 2020-03-10T02:07:22-04:00 Add regression test for T17904 Closes #17904 - - - - - 5fa9cb82 by Richard Eisenberg at 2020-03-10T12:29:46-04:00 anyRewritableTyVar now looks in RuntimeReps Previously, anyRewritableTyVar looked only at the arg and res of `arg -> res`, but their RuntimeReps are also subject to rewriting. Easy to fix. Test case: typecheck/should_compile/T17024 Fixes #17024. - - - - - 5ba01d83 by Ben Price at 2020-03-10T12:30:27-04:00 Clarify a Lint message When developing a plugin I had a shadowing problem, where I generated code app = \f{v r7B} x{v r7B} -> f{v r7B} x{v r7B} This is obviously wrong, since the occurrence of `f` to the right of the arrow refers to the `x` binder (they share a Unique). However, it is rather confusing when Lint reports Mismatch in type between binder and occurrence Var: x{v rB7} since it is printing the binder, rather than the occurrence. It is rather easy to read this as claiming there is something wrong with the `x` occurrence! We change the report to explicitly print both the binder and the occurrence variables. - - - - - 7b2c827b by Simon Peyton Jones at 2020-03-10T12:31:15-04:00 Comments only Clarify code added in #17852 and MR !2724 - - - - - 3300eeac by Krzysztof Gogolewski at 2020-03-10T12:31:54-04:00 Misc cleanup - Remove Note [Existentials in shift_con_pat]. The function shift_con_pat has been removed 15 years ago in 23f40f0e9be6d4. - Remove kcLookupTcTyCon - it's the same as tcLookupTcTyCon - Remove ASSERT in tyConAppArgN. It's already done by getNth, and it's the only reason getNth exists. - Remove unused function nextRole - - - - - abf5736b by Krzysztof Gogolewski at 2020-03-10T18:05:01+01:00 Typos in comments [skip ci] - - - - - bb586f89 by Ben Gamari at 2020-03-11T00:14:59-04:00 rts: Prefer darwin-specific getCurrentThreadCPUTime macOS Catalina now supports a non-POSIX-compliant version of clock_gettime which cannot use the clock_gettime codepath. Fixes #17906. - - - - - 20800b9a by Sylvain Henry at 2020-03-11T08:17:19-04:00 Split GHC.Iface.Utils module * GHC.Iface.Recomp: recompilation avoidance stuff * GHC.Iface.Make: mkIface* Moved `writeIfaceFile` into GHC.Iface.Load alongside `readIface` and renamed it `writeIface` for consistency. - - - - - 1daa2029 by Greg Steuck at 2020-03-11T08:17:56-04:00 Fixed a minor typo in codegen.rst - - - - - 0bc23338 by Ryan Scott at 2020-03-11T08:18:32-04:00 Re-quantify when generalising over rewrite rule types Previously, `tcRules` would check for naughty quantification candidates (see `Note [Naughty quantification candidates]` in `TcMType`) when generalising over the type of a rewrite rule. This caused sensible-looking rewrite rules (like those in #17710) to be rejected. A more permissing (and easier-to-implement) approach is to do what is described in `Note [Generalising in tcTyFamInstEqnGuts]` in `TcTyClsDecls`: just re-quantify all the type variable binders, regardless of the order in which the user specified them. After all, the notion of type variable specificity has no real meaning in rewrite rules, since one cannot "visibly apply" a rewrite rule. I have written up this wisdom in `Note [Re-quantify type variables in rules]` in `TcRules`. As a result of this patch, compiling the `ExplicitForAllRules1` test case now generates one fewer warning than it used to. As far as I can tell, this is benign, since the thing that the disappearing warning talked about was also mentioned in an entirely separate warning. Fixes #17710. - - - - - 336eac7e by Ben Gamari at 2020-03-11T08:19:08-04:00 testsuite: Mark ghci056 and ghcilink004 as fragile in unreg As noted in #17018. Also fix fragile declaration of T13786, which only runs in the normal way. - - - - - c61b9b02 by Simon Peyton Jones at 2020-03-11T08:19:44-04:00 Deepen call stack for isIn I see quite a few warnings like: WARNING: file compiler/utils/Util.hs, line 593 Over-long elem in unionLists But the call stack is uninformative. Better to add HasDebugCallStack to isIn. Ditto isn'tIn. - - - - - 3aa9b35f by Ömer Sinan Ağacan at 2020-03-11T08:20:27-04:00 Zero any slop after compaction in compacting GC In copying GC, with the relevant debug flags enabled, we release the old blocks after a GC, and the block allocator zeroes the space before releasing a block. This effectively zeros the old heap. In compacting GC we reuse the blocks and previously we didn't zero the unused space in a compacting generation after compaction. With this patch we zero the slop between the free pointer and the end of the block when we're done with compaction and when switching to a new block (because the current block doesn't have enough space for the next object we're shifting). - - - - - 8e6febce by Sylvain Henry at 2020-03-11T20:33:37-04:00 Refactor GHC.Driver.Session (Ways and Flags) * extract flags and ways into their own modules (with some renaming) * remove one SOURCE import of GHC.Driver.Session from GHC.Driver.Phases * when GHC uses dynamic linking (WayDyn), `interpWays` was only reporting WayDyn even if the host was profiled (WayProf). Now it returns both as expected (might fix #16803). * `mkBuildTag :: [Way] -> String` wasn't reporting a canonical tag for differently ordered lists. Now we sort and nub the list to fix this. - - - - - bc41e471 by Sylvain Henry at 2020-03-11T20:33:37-04:00 Refactor interpreterDynamic and interpreterProfiled * `interpreterDynamic` and `interpreterProfiled` now take `Interp` parameters instead of DynFlags * slight refactoring of `ExternalInterp` so that we can read the iserv configuration (which is pure) without reading an MVar. - - - - - a6989971 by Sylvain Henry at 2020-03-11T20:33:37-04:00 Use a Set to represent Ways Should make `member` queries faster and avoid messing up with missing `nubSort`. Metric Increase: hie002 - - - - - cb93a1a4 by Ryan Scott at 2020-03-11T20:34:14-04:00 Make DeriveFunctor-generated code require fewer beta reductions Issue #17880 demonstrates that `DeriveFunctor`-generated code is surprisingly fragile when rank-_n_ types are involved. The culprit is that `$fmap` (the algorithm used to generate `fmap` implementations) was too keen on applying arguments with rank-_n_ types to lambdas, which fail to typecheck more often than not. In this patch, I change `$fmap` (both the specification and the implementation) to produce code that avoids creating as many lambdas, avoiding problems when rank-_n_ field types arise. See the comments titled "Functor instances" in `TcGenFunctor` for a more detailed description. Not only does this fix #17880, but it also ensures that the code that `DeriveFunctor` generates will continue to work after simplified subsumption is implemented (see #17775). What is truly amazing is that #17880 is actually a regression (introduced in GHC 7.6.3) caused by commit 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e, the fix #7436. Prior to that commit, the version of `$fmap` that was used was almost identical to the one used in this patch! Why did that commit change `$fmap` then? It was to avoid severe performance issues that would arise for recursive `fmap` implementations, such as in the example below: ```hs data List a = Nil | Cons a (List a) deriving Functor -- ===> instance Functor List where fmap f Nil = Nil fmap f (Cons x xs) = Cons (f x) (fmap (\y -> f y) xs) ``` The fact that `\y -> f y` was eta expanded caused significant performance overheads. Commit 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e fixed this performance issue, but it went too far. As a result, this patch partially reverts 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e. To ensure that the performance issues pre-#7436 do not resurface, I have taken some precautionary measures: * I have added a special case to `$fmap` for situations where the last type variable in an application of some type occurs directly. If this special case fires, we avoid creating a lambda expression. This ensures that we generate `fmap f (Cons x xs) = Cons (f x) (fmap f xs)` in the derived `Functor List` instance above. For more details, see `Note [Avoid unnecessary eta expansion in derived fmap implementations]` in `TcGenFunctor`. * I have added a `T7436b` test case to ensure that the performance of this derived `Functor List`-style code does not regress. When implementing this, I discovered that `$replace`, the algorithm which generates implementations of `(<$)`, has a special case that is very similar to the `$fmap` special case described above. `$replace` marked this special case with a custom `Replacer` data type, which was a bit overkill. In order to use the same machinery for both `Functor` methods, I ripped out `Replacer` and instead implemented a simple way to detect the special case. See the updated commentary in `Note [Deriving <$]` for more details. - - - - - 1f9db3e7 by Kirill Elagin at 2020-03-12T09:45:51-04:00 pretty-printer: Properly parenthesise LastStmt After ApplicatveDo strips the last `return` during renaming, the pretty printer has to restore it. However, if the return was followed by `$`, the dollar was stripped too and not restored. For example, the last stamement in: ``` foo = do x <- ... ... return $ f x ``` would be printed as: ``` return f x ``` This commit preserved the dolar, so it becomes: ``` return $ f x ``` - - - - - 5cb93af7 by Kirill Elagin at 2020-03-12T09:45:51-04:00 pretty-printer: Do not print ApplicativeDo join * Do not print `join` in ApplictiveStmt, unless ppr-debug * Print parens around multiple parallel binds When ApplicativeDo is enabled, the renamer analyses the statements of a `do` block and in certain cases marks them as needing to be rewritten using `join`. For example, if you have: ``` foo = do a <- e1 b <- e2 doSomething a b ``` it will be desugared into: ``` foo = join (doSomething <$> e1 <*> e2) ``` After renaming but before desugaring the expression is stored essentially as: ``` foo = do [will need join] (a <- e1 | b <- e2) [no return] doSomething a b ``` Before this change, the pretty printer would print a call to `join`, even though it is not needed at this stage at all. The expression will be actually rewritten into one using join only at desugaring, at which point a literal call to join will be inserted. - - - - - 3a259092 by Simon Peyton Jones at 2020-03-12T09:46:29-04:00 Expose compulsory unfoldings always The unsafeCoerce# patch requires that unsafeCoerce# has a compulsory unfolding that is always available. So we have to be careful to expose compulsory unfoldings unconditionally and consistently. We didn't get this quite right: #17871. This patch fixes it. No real surprises here. See Note [Always expose compulsory unfoldings] in GHC.Iface.Tidy - - - - - 6a65b8c2 by Alp Mestanogullari at 2020-03-13T02:29:20-04:00 hadrian: improve dependency tracking for the check-* programs The code in Rules.Register responsible for finding all the build artifacts that Cabal installs when registering a library (static/shared libs, .hi files, ...) was looking in the wrong place. This patch fixes that logic and makes sure we gather all those artifacts in a list to declare that the rule for a given `.conf` file, our proxy for "Hadrian, please install this package in the package db for this stage", also produces those artifacts under the said package database. We also were completely missing some logic to declare that the check-* programs have dependencies besides their source code, at least when testing an in-tree compiler. Finally, this patch also removes redundant packages from 'testsuitePackages', since they should already be covered by the stage<N>Packages lists from Settings.Default. With this patch, after a complete build and freezing stage 1, a change to `compiler/parser/Parser.y` results in rebuilding the ghc lib, reinstalling it, and rebuilding the few programs that depend on it, _including_ `check-ppr` and `check-api-annotations` (therefore fixing #17273). - - - - - 44fad4a9 by Sylvain Henry at 2020-03-13T02:30:22-04:00 Rename isDllName I wanted to fix the dangling comment in `isDllName` ("This is the cause of #", #8696 is already mentioned earlier). I took the opportunity to change the function name to better reflect what it does. - - - - - 2f292db8 by Paavo at 2020-03-13T02:31:03-04:00 Update documentation for closureSize - - - - - f124ff0d by Ben Gamari at 2020-03-13T02:31:40-04:00 gitlab-ci: Rework triggering of release builds Use a push option instead of tagging. - - - - - 7f25557a by Ben Gamari at 2020-03-13T10:38:09-04:00 gitlab-ci: Distinguish integer-simple test envs Previously two integer-simple jobs declared the same test environment. One (the nightly job) was built in the perf way, the other in the validate way. Consequently they had appreciably different performance characteristics, causing in the nightly job to spuriously fail with performance changes. - - - - - c12a2ec5 by Simon Peyton Jones at 2020-03-14T05:25:30-04:00 Fix Lint Ticket #17590 pointed out a bug in the way the linter dealt with type lets, exposed by the new uniqAway story. The fix is described in Note [Linting type lets]. I ended up putting the in-scope Ids in a different env field, le_ids, rather than (as before) sneaking them into the TCvSubst. Surprisingly tiresome, but done. Metric Decrease: hie002 - - - - - b989845e by Sylvain Henry at 2020-03-14T05:26:11-04:00 Hadrian: fix absolute buildroot support (#17822) Shake's "**" wildcard doesn't match absolute root. We must use "//" instead. - - - - - 4f117135 by Sylvain Henry at 2020-03-14T05:26:49-04:00 Make: refactor GMP rules Document and use simpler rules for the ghc-gmp.h header. - - - - - 7432b327 by Sylvain Henry at 2020-03-14T05:27:28-04:00 Use correct option name (-opti) (fix #17314) s/pgmo/opti - - - - - 8f7dd571 by Judah Jacobson at 2020-03-14T05:28:07-04:00 Allow overriding LD_STAGE0 and AR_STAGE0 in the configure script. Previously it was possible to override the stage0 C compiler via `CC_STAGE0`, but you couldn't override `ld` or `ar` in stage0. This change allows overriding them by setting `LD_STAGE0` or `AR_STAGE0`, respectively. Our team uses this feature internally to take more control of our GHC build and make it run more hermetically. - - - - - 7c3e39a9 by Judah Jacobson at 2020-03-14T05:28:07-04:00 Use AC_ARG_VAR for LD_STAGE0 and AR_STAGE0. - - - - - 20d4d676 by Ben Gamari at 2020-03-14T05:28:43-04:00 nonmoving: Don't traverse filled segment list in pause The non-moving collector would previously walk the entire filled segment list during the preparatory pause. However, this is far more work than is strictly necessary. We can rather get away with merely collecting the allocators' filled segment list heads and process the lists themselves during the concurrent phase. This can significantly reduce the maximum gen1 GC pause time in programs with high rates of long-lived allocations. - - - - - fdfa2d01 by Ben Gamari at 2020-03-14T05:29:18-04:00 nonmoving: Remove redundant bitmap clearing nonmovingSweep already clears the bitmap in the sweep loop. There is no reason to do so a second time. - - - - - 2f8c7767 by Simon Peyton Jones at 2020-03-14T05:29:55-04:00 Simple refactor of cheapEqExpr No change in functionality. Just seems tidier (and signficantly more efficient) to deal with ticks directly than to call stripTicksTopE. - - - - - 88f7a762 by Simon Peyton Jones at 2020-03-14T05:29:55-04:00 Improve CSE.combineAlts This patch improves the way that CSE combines identical alternatives. See #17901. I'm still not happy about the duplication between CSE.combineAlts and GHC.Core.Utils.combineIdenticalAlts; see the Notes with those functions. But this patch is a step forward. Metric Decrease: T12425 T5642 - - - - - 8b95ddd3 by Ben Gamari at 2020-03-14T05:30:31-04:00 gitlab-ci: Add integer-simple release build for Windows Closes #16144. - - - - - e3c374cc by Simon Peyton Jones at 2020-03-14T05:31:07-04:00 Wrap an implication around class-sig kind errors Ticket #17841 showed that we can get a kind error in a class signature, but lack an enclosing implication that binds its skolems. This patch * Adds the wrapping implication: the new call to checkTvConstraints in tcClassDecl1 * Simplifies the API to checkTvConstraints, which was not otherwise called at all. * Simplifies TcErrors.report_unsolved by *not* initialising the TidyEnv from the typechecker lexical envt. It's enough to do so from the free vars of the unsolved constraints; and we get silly renamings if we add variables twice: once from the lexical scope and once from the implication constraint. - - - - - 73133a3b by Simon Peyton Jones at 2020-03-14T05:31:07-04:00 Refactoring in TcSMonad This patch is just refactoring: no change in behaviour. I removed the rather complicated checkConstraintsTcS checkTvConstraintsTcS in favour of simpler functions emitImplicationTcS emitTvImplicationTcS pushLevelNoWorkList The last of these is a little strange, but overall it's much better I think. - - - - - 93c88c26 by Ben Gamari at 2020-03-14T05:31:42-04:00 base: Make `open` calls interruptible As noted in #17912, `open` system calls were `safe` rather than `interruptible`. Consequently, the program could not be interrupted with SIGINT if stuck in a slow open operation. Fix this by marking `c_safe_open` as interruptible. - - - - - bee4cdad by Vladislav Zavialov at 2020-03-14T05:32:18-04:00 Remove second tcLookupTcTyCon in tcDataDefn Before this patch, tcDataDefn used to call tcLookupTcTyCon twice in a row: 1. in bindTyClTyVars itself 2. in the continuation passed to it Now bindTyClTyVars passes the TcTyCon to the continuation, making the second lookup unnecessary. - - - - - 3f116d35 by Cale Gibbard at 2020-03-14T19:34:42-04:00 Enable stage1 build of haddock The submodule has already been bumped to contain the fix. - - - - - 49e9d739 by Ömer Sinan Ağacan at 2020-03-14T19:35:24-04:00 rts: Fix printClosure when printing fwd ptrs - - - - - 1de3ab4a by Krzysztof Gogolewski at 2020-03-14T19:36:04-04:00 Remove unused field var_inline (#17915) - - - - - d30aeb4b by Krzysztof Gogolewski at 2020-03-15T03:57:41-04:00 Document restriction on SCC pragma syntax Currently, the names of cost centres must be quoted or be lowercase identifiers. Fixes #17916. - - - - - b4774598 by Brian Foley at 2020-03-15T03:58:18-04:00 Remove some dead code >From the notes.ghc.drop list found using weeder in #17713 - - - - - dd6ffe6b by Viktor Dukhovni at 2020-03-15T03:58:55-04:00 Note platform-specific Foreign.C.Types in context Also fix the markup in the general note at the top of the module. Haddock (usability trade-off), does not support multi-line emphasised text. - - - - - 2e82465f by Sylvain Henry at 2020-03-15T10:57:10-04:00 Refactor CmmToAsm (disentangle DynFlags) This patch disentangles a bit more DynFlags from the native code generator (CmmToAsm). In more details: - add a new NCGConfig datatype in GHC.CmmToAsm.Config which contains the configuration of a native code generation session - explicitly pass NCGConfig/Platform arguments when necessary - as a consequence `sdocWithPlatform` is gone and there are only a few `sdocWithDynFlags` left - remove the use of `unsafeGlobalDynFlags` from GHC.CmmToAsm.CFG - remove `sdocDebugLevel` (now we pass the debug level via NCGConfig) There are still some places where DynFlags is used, especially because of pretty-printing (CLabel), because of Cmm helpers (such as `cmmExprType`) and because of `Outputable` instance for the instructions. These are left for future refactoring as this patch is already big. - - - - - c35c545d by Judah Jacobson at 2020-03-15T10:57:48-04:00 Add a -no-haddock flag. This flag undoes the effect of a previous "-haddock" flag. Having both flags makes it easier for build systems to enable Haddock parsing in a set of global flags, but then disable it locally for specific targets (e.g., third-party packages whose comments don't pass the validation in the latest GHC). I added the flag to expected-undocumented-flags.txt since `-haddock` was alreadyin that list. - - - - - cfcc3c9a by Ömer Sinan Ağacan at 2020-03-15T10:58:27-04:00 Fix global_link of TSOs for threads reachable via dead weaks Fixes #17785 Here's how the problem occurs: - In generation 0 we have a TSO that is finished (i.e. it has no more work to do or it is killed). - The TSO only becomes reachable after collectDeadWeakPtrs(). - After collectDeadWeakPtrs() we switch to WeakDone phase where we don't move TSOs to different lists anymore (like the next gen's thread list or the resurrected_threads list). - So the TSO will never be moved to a generation's thread list, but it will be promoted to generation 1. - Generation 1 collected via mark-compact, and because the TSO is reachable it is marked, and its `global_link` field, which is bogus at this point (because the TSO is not in a list), will be threaded. - Chaos ensues. In other words, when these conditions hold: - A TSO is reachable only after collectDeadWeakPtrs() - It's finished (what_next is ThreadComplete or ThreadKilled) - It's retained by mark-compact collector (moving collector doesn't evacuate the global_list field) We end up doing random mutations on the heap because the TSO's global_list field is not valid, but it still looks like a heap pointer so we thread it during compacting GC. The fix is simple: when we traverse old_threads lists to resurrect unreachable threads the threads that won't be resurrected currently stays on the old_threads lists. Those threads will never be visited again by MarkWeak so we now reset the global_list fields. This way compacting GC does not thread pointers to nowhere. Testing ------- The reproducer in #17785 is quite large and hard to build, because of the dependencies, so I'm not adding a regression test. In my testing the reproducer would take a less than 5 seconds to run, and once in every ~5 runs would fail with a segfault or an assertion error. In other cases it also fails with a test failure. Because the tests never fail with the bug fix, assuming the code is correct, this also means that this bug can sometimes lead to incorrect runtime results. After the fix I was able to run the reproducer repeatedly for about an hour, with no runtime crashes or test failures. To run the reproducer clone the git repo: $ git clone https://github.com/osa1/streamly --branch ghc-segfault Then clone primitive and atomic-primops from their git repos and point to the clones in cabal.project.local. The project should then be buildable using GHC HEAD. Run the executable `properties` with `+RTS -c -DZ`. In addition to the reproducer above I run the test suite using: $ make slowtest EXTRA_HC_OPTS="-debug -with-rtsopts=-DS \ -with-rtsopts=-c +RTS -c -RTS" SKIPWAY='nonmoving nonmoving_thr' This enables compacting GC always in both GHC when building the test programs and when running the test programs, and also enables sanity checking when running the test programs. These set of flags are not compatible for all tests so there are some failures, but I got the same set of failures with this patch compared to GHC HEAD. - - - - - 818b3c38 by Lysxia at 2020-03-16T23:52:42-04:00 base: add strict IO functions: readFile', getContents', hGetContents' - - - - - 18a346a4 by Sylvain Henry at 2020-03-16T23:53:24-04:00 Modules: Core (#13009) Update submodule: haddock - - - - - 92327e3a by Ömer Sinan Ağacan at 2020-03-16T23:54:04-04:00 Update sanity checking for TSOs: - Remove an invalid assumption about GC checking what_next field. The GC doesn't care about what_next at all, if a TSO is reachable then all its pointers are followed (other than global_tso, which is only followed by compacting GC). - Remove checkSTACK in checkTSO: TSO stacks will be visited in checkHeapChain, or checkLargeObjects etc. - Add an assertion in checkTSO to check that the global_link field is sane. - Did some refactor to remove forward decls in checkGlobalTSOList and added braces around single-statement if statements. - - - - - e1aa4052 by PHO at 2020-03-17T07:36:09-04:00 Don't use non-portable operator "==" in configure.ac The test operator "==" is a Bash extension and produces a wrong result if /bin/sh is not Bash. - - - - - 89f034dd by Maximilian Tagher at 2020-03-17T07:36:48-04:00 Document the units of -ddump-timings Right now, in the output of -ddump-timings to a file, you can't tell what the units are: ``` CodeGen [TemplateTestImports]: alloc=22454880 time=14.597 ``` I believe bytes/milliseconds are the correct units, but confirmation would be appreciated. I'm basing it off of this snippet from `withTiming'`: ``` when (verbosity dflags >= 2 && prtimings == PrintTimings) $ liftIO $ logInfo dflags (defaultUserStyle dflags) (text "!!!" <+> what <> colon <+> text "finished in" <+> doublePrec 2 time <+> text "milliseconds" <> comma <+> text "allocated" <+> doublePrec 3 (realToFrac alloc / 1024 / 1024) <+> text "megabytes") ``` which implies time is in milliseconds, and allocations in bytes (which divided by 1024 would be KB, and again would be MB) - - - - - beffa147 by Simon Peyton Jones at 2020-03-17T07:37:25-04:00 Implement mapTyCo like foldTyCo This patch makes mapType use the successful idiom described in TyCoRep Note [Specialising foldType] I have not yet changed any functions to use mapType, though there may be some suitable candidates. This patch should be a no-op in terms of functionality but, because it inlines the mapper itself, I'm hoping that there may be some modest perf improvements. Metric Decrease: T5631 T5642 T3064 T9020 T14683 hie002 haddock.Cabal haddock.base haddock.compiler - - - - - 5800ebfe by Ömer Sinan Ağacan at 2020-03-17T07:38:08-04:00 Don't update ModDetails with CafInfos when opts are disabled This is consistent with the interface file behavior where we omit HsNoCafRefs annotations with -fomit-interface-pragmas (implied by -O0). ModDetails and ModIface are just different representations of the same thing, so they really need to be in sync. This patch does the right thing and does not need too much explanation, but here's an example of a problem not doing this causes in !2842: -- MyInteger.hs module MyInteger ( MyInteger (MyInteger) , ToMyInteger (toMyInteger) ) where newtype MyInteger = MyInteger Integer class ToMyInteger a where toMyInteger :: a -> MyInteger instance ToMyInteger Integer where toMyInteger = MyInteger {- . succ -} -- Main.hs module Main ( main ) where import MyInteger (MyInteger (MyInteger), toMyInteger) main :: IO () main = do let (MyInteger i) = (id . toMyInteger) (41 :: Integer) print i If I build this with -O0, without this fix, we generate a ModDetails with accurate LFInfo for toMyInteger (MyInteger.$fToMyIntegerInteger) which says that it's a LFReEntrant with arity 1. This means in the use site (Main) we tag the value: R3 = MyInteger.$fToMyIntegerInteger_closure + 1; R2 = GHC.Base.id_closure; R1 = GHC.Base.._closure; Sp = Sp - 16; call stg_ap_ppp_fast(R4, R3, R2, R1) args: 24, res: 0, upd: 24; Now we change the definition by uncommenting the `succ` part and it becomes a thunk: MyInteger.$fToMyIntegerInteger [InlPrag=INLINE (sat-args=0)] :: MyInteger.ToMyInteger GHC.Integer.Type.Integer [GblId[DFunId(nt)]] = {} \u [] $ctoMyInteger_rEA; and its LFInfo is now LFThunk. This change in LFInfo makes a difference in the use site: we can no longer tag it. But becuase the interface fingerprint does not change (because ModIface does not change) we don't rebuild Main and tag the thunk. (1.2% increase in allocations when building T12545 on armv7 because we generate more code without CafInfos) Metric Increase: T12545 - - - - - 5b632dad by Paavo at 2020-03-17T07:38:48-04:00 Add example for Data.Semigroup.diff - - - - - 4d85d68b by Paavo at 2020-03-17T07:38:48-04:00 Clean up - - - - - 75168d07 by Paavo at 2020-03-17T07:38:48-04:00 Make example collapsible - - - - - 53ff2cd0 by Richard Eisenberg at 2020-03-17T13:46:57+00:00 Fix #17021 by checking more return kinds All the details are in new Note [Datatype return kinds] in TcTyClsDecls. Test case: typecheck/should_fail/T17021{,b} typecheck/should_compile/T17021a Updates haddock submodule - - - - - 528df8ec by Sylvain Henry at 2020-03-18T10:06:43-04:00 Modules: Core operations (#13009) - - - - - 4e8a71c1 by Richard Eisenberg at 2020-03-18T10:07:19-04:00 Add release note about fix to #16502. We thought we needed to update the manual, but the fix for #16502 actually brings the implementation in line with the manual. So we just alert users of how to update their code. - - - - - 5cbf9934 by Andreas Klebinger at 2020-03-19T00:39:27-04:00 Update "GHC differences to the FFI Chapter" in user guide. The old entry had a heavy focus on how things had been. Which is not what I generally look for in a user guide. I also added a small section on behaviour of nested safe ffi calls. [skip-ci] - - - - - b03fd3bc by Sebastian Graf at 2020-03-19T00:40:06-04:00 PmCheck: Use ConLikeSet to model negative info In #17911, Simon recognised many warnings stemming from over-long list unions while coverage checking Cabal's `LicenseId` module. This patch introduces a new `PmAltConSet` type which uses a `UniqDSet` instead of an association list for `ConLike`s. For `PmLit`s, it will still use an assocation list, though, because a similar map data structure would entail a lot of busy work. Fixes #17911. - - - - - 64f20756 by Sylvain Henry at 2020-03-19T12:16:49-04:00 Refactoring: use Platform instead of DynFlags when possible Metric Decrease: ManyConstructors T12707 T13035 T1969 - - - - - cb1785d9 by Ömer Sinan Ağacan at 2020-03-19T12:16:54-04:00 FastString: fix eager reading of string ptr in hashStr This read causes NULL dereferencing when len is 0. Fixes #17909 In the reproducer in #17909 this bug is triggered as follows: - SimplOpt.dealWithStringLiteral is called with a single-char string ("=" in #17909) - tailFS gets called on the FastString of the single-char string. - tailFS checks the length of the string, which is 1, and calls mkFastStringByteString on the tail of the ByteString, which is an empty ByteString as the original ByteString has only one char. - ByteString's unsafeUseAsCStringLen returns (NULL, 0) for the empty ByteString, which is passed to mkFastStringWith. - mkFastStringWith gets hash of the NULL pointer via hashStr, which fails on empty strings because of this bug. - - - - - 73a7383e by Richard Eisenberg at 2020-03-20T20:42:56-04:00 Simplify treatment of heterogeneous equality Previously, if we had a [W] (a :: k1) ~ (rhs :: k2), we would spit out a [D] k1 ~ k2 and part the W as irreducible, hoping for a unification. But we needn't do this. Instead, we now spit out a [W] co :: k2 ~ k1 and then use co to cast the rhs of the original Wanted. This means that we retain the connection between the spat-out constraint and the original. The problem with this new approach is that we cannot use the casted equality for substitution; it's too like wanteds-rewriting- wanteds. So, we forbid CTyEqCans that mention coercion holes. All the details are in Note [Equalities with incompatible kinds] in TcCanonical. There are a few knock-on effects, documented where they occur. While debugging an error in this patch, Simon and I ran into infelicities in how patterns and matches are printed; we made small improvements. This patch includes mitigations for #17828, which causes spurious pattern-match warnings. When #17828 is fixed, these lines should be removed. - - - - - faa36e5b by Sylvain Henry at 2020-03-20T20:43:41-04:00 Hadrian: ignore in-tree GMP objects with ``--lint`` - - - - - 9a96ff6b by Richard Eisenberg at 2020-03-20T20:44:17-04:00 Update core spec to reflect changes to Core. Key changes: * Adds a new rule for forall-coercions over coercion variables, which was implemented but conspicuously missing from the spec. * Adds treatment for FunCo. * Adds treatment for ForAllTy over coercion variables. * Improves commentary (including restoring a Note lost in 03d4852658e1b7407abb4da84b1b03bfa6f6db3b) in the source. No changes to running code. - - - - - 7e0451c6 by Sergej Jaskiewicz at 2020-03-20T20:44:55-04:00 Fix event message in withTiming' This typo caused generating 'end' events without the corresponding 'begin' events. - - - - - 1542a626 by Ben Gamari at 2020-03-22T22:37:47-04:00 fs.h: Add missing declarations on Windows - - - - - 3bcf2ccd by Ben Gamari at 2020-03-22T22:37:47-04:00 Bump process submodule Avoids redundant case alternative warning. - - - - - 3b363ef9 by Ben Gamari at 2020-03-22T22:37:47-04:00 testsuite: Normalize slashes in ghc-api annotations output Enable `normalise_slashes` on `annotations`, `listcomps`, and `parseTree` to fix Windows failures. - - - - - 25fc9429 by Ben Gamari at 2020-03-22T22:37:47-04:00 testsuite: Update expected output on Windows - - - - - 7f58ec6d by Ben Gamari at 2020-03-22T22:37:47-04:00 testsuite: Fix TOP of T17786 - - - - - aadcd909 by GHC GitLab CI at 2020-03-22T22:37:47-04:00 testsuite: Update expected output on Windows - - - - - dc1eb10d by GHC GitLab CI at 2020-03-22T22:37:47-04:00 hadrian: Fix executable extension passed to testsuite driver - - - - - 58f62e2c by GHC GitLab CI at 2020-03-22T22:37:47-04:00 gitlab-ci: Require that Windows-hadrian job passes - - - - - 8dd2415d by Ben Gamari at 2020-03-22T22:37:47-04:00 hadrian: Eliminate redundant .exe from GHC path Previously we were invoking: bash -c "c:/GitLabRunner/builds/eEQrxK4p/0/ghc/ghc/toolchain/bin/ghc.exe.exe testsuite/mk/ghc-config.hs -o _build/test/bin/ghc-config.exe" - - - - - 373621f6 by Ben Gamari at 2020-03-22T22:37:47-04:00 Bump hsc2hs submodule - - - - - abc02b40 by Hécate at 2020-03-22T22:38:33-04:00 Annotate the non-total function in Data.Foldable as such - - - - - 19f12557 by Josef Svenningsson at 2020-03-23T14:05:33-04:00 Fix ApplicativeDo regression #17835 A previous fix for #15344 made sure that monadic 'fail' is used properly when translating ApplicativeDo. However, it didn't properly account for when a 'fail' will be inserted which resulted in some programs failing with a type error. - - - - - 2643ba46 by Paavo at 2020-03-24T08:31:32-04:00 Add example and doc for Arg (Fixes #17153) - - - - - 703221f4 by Roland Senn at 2020-03-25T14:45:04-04:00 Use export list of Main module in function TcRnDriver.hs:check_main (Fix #16453) - Provide the export list of the `Main` module as parameter to the `compiler/typecheck/TcRnDriver.hs:check_main` function. - Instead of `lookupOccRn_maybe` call the function `lookupInfoOccRn`. It returns the list `mains_all` of all the main functions in scope. - Select from this list `mains_all` all `main` functions that are in the export list of the `Main` module. - If this new list contains exactly one single `main` function, then typechecking continues. - Otherwise issue an appropriate error message. - - - - - 3e27205a by Sebastian Graf at 2020-03-25T14:45:40-04:00 Remove -fkill-absence and -fkill-one-shot flags They seem to be a benchmarking vestige of the Cardinality paper and probably shouldn't have been merged to HEAD in the first place. - - - - - 262e42aa by Peter Trommler at 2020-03-25T22:41:39-04:00 Do not panic on linker errors - - - - - 0de03cd7 by Sylvain Henry at 2020-03-25T22:42:02-04:00 DynFlags refactoring III Use Platform instead of DynFlags when possible: * `tARGET_MIN_INT` et al. replaced with `platformMinInt` et al. * no more DynFlags in PreRules: added a new `RuleOpts` datatype * don't use `wORD_SIZE` in the compiler * make `wordAlignment` use `Platform` * make `dOUBLE_SIZE` a constant Metric Decrease: T13035 T1969 - - - - - 7a04920b by Tristan Cacqueray at 2020-03-25T22:42:06-04:00 Base: fix a typo in liftA doc This change removes an extra '|' that should not be rendered in the liftA documentation. Tracking: #17929 - - - - - 1c5a15f7 by Tristan Cacqueray at 2020-03-25T22:42:06-04:00 Base: add Control.Applicative optional example This change adds an optional example. Tracking: #17929 - - - - - 6d172e63 by Tristan Cacqueray at 2020-03-25T22:42:06-04:00 Base: add markup around Except - - - - - eb2162c8 by John Ericson at 2020-03-26T12:37:08-04:00 Remove unused `ghciTablesNextToCode` from compiler proper - - - - - f51efc4b by Joachim Breitner at 2020-03-26T12:37:09-04:00 Prepare to use run-time tablesNextToCode in compiler exclusively Factor out CPP as much as possible to prepare for runtime determinattion. Progress towards #15548 - - - - - 1c446220 by Joachim Breitner at 2020-03-26T12:37:09-04:00 Use run-time tablesNextToCode in compiler exclusively (#15548) Summary: - There is no more use of the TABLES_NEXT_TO_CODE CPP macro in `compiler/`. GHCI_TABLES_NEXT_TO_CODE is also removed entirely. The field within `PlatformMisc` within `DynFlags` is used instead. - The field is still not exposed as a CLI flag. We might consider some way to ensure the right RTS / libraries are used before doing that. Original reviewers: Original subscribers: TerrorJack, rwbarton, carter Original Differential Revision: https://phabricator.haskell.org/D5082 - - - - - 1941ef4f by Sylvain Henry at 2020-03-29T17:28:51-04:00 Modules: Types (#13009) Update Haddock submodule Metric Increase: haddock.compiler - - - - - 1c7c6f1a by Sylvain Henry at 2020-03-29T17:28:51-04:00 Remove GHC.Types.Unique.Map module This module isn't used anywhere in GHC. - - - - - f1a6c73d by Sylvain Henry at 2020-03-29T17:28:51-04:00 Merge GHC.Types.CostCentre.Init into GHC.Driver.CodeOutput - - - - - 54250f2d by Simon Peyton Jones at 2020-03-29T17:29:30-04:00 Demand analysis: simplify the demand for a RHS Ticket #17932 showed that we were using a stupid demand for the RHS of a let-binding, when the result is a product. This was the result of a "fix" in 2013, which (happily) turns out to no longer be necessary. So I just deleted the code, which simplifies the demand analyser, and fixes #17932. That in turn uncovered that the anticipation of worker/wrapper in CPR analysis was inaccurate, hence the logic that decides whether to unbox an argument in WW was extracted into a function `wantToUnbox`, now consulted by CPR analysis. I tried nofib, and got 0.0% perf changes. All this came up when messing about with !2873 (ticket #17917), but is idependent of it. Unfortunately, this patch regresses #4267 and realised that it is now blocked on #16335. - - - - - 03060b2f by Ben Gamari at 2020-03-29T17:30:05-04:00 testsuite: Fix T17786 on Windows Fixes line ending normalization issue. - - - - - 1f7995ba by Ben Gamari at 2020-03-29T17:30:05-04:00 testsuite: Fix T17786 Fix missing quoting and expected exit code. - - - - - ef9c608e by Ben Gamari at 2020-03-29T17:30:05-04:00 testsuite: Mark T12971 as broken on Windows Due to #17945. - - - - - e54500c1 by Sylvain Henry at 2020-03-29T17:30:47-04:00 Store ComponentId details As far as GHC is concerned, installed package components ("units") are identified by an opaque ComponentId string provided by Cabal. But we don't want to display it to users (as it contains a hash) so GHC queries the database to retrieve some infos about the original source package (name, version, component name). This patch caches these infos in the ComponentId itself so that we don't need to provide DynFlags (which contains installed package informations) to print a ComponentId. In the future we want GHC to support several independent package states (e.g. for plugins and for target code), hence we need to avoid implicitly querying a single global package state. - - - - - 7e7cb714 by Marius Bakke at 2020-03-29T17:31:27-04:00 testsuite: Remove test that dlopens a PIE object. glibc 2.30 disallowed dlopening PIE objects, so just remove the test. Fixes #17952. - - - - - 6c8f80d8 by Andreas Klebinger at 2020-03-29T17:32:04-04:00 Correct haddocks for testBit in Data.Bits It conflated the nth bit with the bit at offset n. Now we instead give the definition in terms of `bit and `.&.` on top of clearer phrasing. - - - - - c916f190 by Andreas Klebinger at 2020-03-29T17:32:04-04:00 Apply suggestion to libraries/base/Data/Bits.hs - - - - - 64bf7f51 by Ben Gamari at 2020-03-29T17:32:41-04:00 gitlab-ci: Add FreeBSD release job - - - - - a0d8e92e by Ryan Scott at 2020-03-29T17:33:20-04:00 Run checkNewDataCon before constraint-solving newtype constructors Within `checkValidDataCon`, we used to run `checkValidType` on the argument types of a newtype constructor before running `checkNewDataCon`, which ensures that the user does not attempt non-sensical things such as newtypes with multiple arguments or constraints. This works out in most situations, but this falls over on a corner case revealed in #17955: ```hs newtype T = Coercible () T => T () ``` `checkValidType`, among other things, peforms an ambiguity check on the context of a data constructor, and that it turn invokes the constraint solver. It turns out that there is a special case in the constraint solver for representational equalities (read: `Coercible` constraints) that causes newtypes to be unwrapped (see `Note [Unwrap newtypes first]` in `TcCanonical`). This special case does not know how to cope with an ill formed newtype like `T`, so it ends up panicking. The solution is surprisingly simple: just invoke `checkNewDataCon` before `checkValidType` to ensure that the illicit newtype constructor context is detected before the constraint solver can run amok with it. Fixes #17955. - - - - - 45eb9d8c by Krzysztof Gogolewski at 2020-03-29T17:33:59-04:00 Minor cleanup - Simplify mkBuildExpr, the function newTyVars was called only on a one-element list. - TTG: use noExtCon in more places. This is more future-proof. - In zonkExpr, panic instead of printing a warning. - - - - - f024b6e3 by Sylvain Henry at 2020-03-30T12:48:39+02:00 Expect T4267 to pass Since 54250f2d8de910b094070c1b48f086030df634b1 we expected T4267 to fail, but it passes on CI. - - - - - 57b888c0 by Ryan Scott at 2020-03-31T10:54:20-04:00 Require GHC 8.8 as the minimum compiler for bootstrapping This allows us to remove several bits of CPP that are either always true or no longer reachable. As an added bonus, we no longer need to worry about importing `Control.Monad.Fail.fail` qualified to avoid clashing with `Control.Monad.fail`, since the latter is now the same as the former. - - - - - 33f09551 by Ryan Scott at 2020-03-31T10:54:57-04:00 Add regression test for #17963 The panic in #17963 happened to be fixed by commit e3c374cc5bd7eb49649b9f507f9f7740697e3f70. This patch adds a regression test to ensure that it remains fixed. Fixes #17963. - - - - - 09a36e80 by Ömer Sinan Ağacan at 2020-03-31T10:55:37-04:00 Simplify stderrSupportsAnsiColors The combinator andM is used only once, and the code is shorter and simpler if you inline it. - - - - - 95bccdd0 by Ben Gamari at 2020-03-31T10:56:19-04:00 base: Ensure that encoding global variables aren't inlined As noted in #17970, these (e.g. `getFileSystemEncoding` and `setFileSystemEncoding`) previously had unfoldings, which would break their global-ness. While not strictly necessary, I also add a NOINLINE on `initLocaleEncoding` since it is used in `System.IO`, ensuring that we only system's query the locale encoding once. Fixes #17970. - - - - - 982aaa83 by Andreas Klebinger at 2020-03-31T10:56:55-04:00 Update hadrian index revision. Required in order to build hadrian using ghc-8.10 - - - - - 4b9c5864 by Ben Gamari at 2020-03-31T10:57:32-04:00 integer-gmp: Bump version and add changelog entry - - - - - 9b39f2e6 by Ryan Scott at 2020-04-01T01:20:00-04:00 Clean up "Eta reduction for data families" Notes Before, there were two distinct Notes named "Eta reduction for data families". This renames one of them to "Implementing eta reduction for data families" to disambiguate the two and fixes references in other parts of the codebase to ensure that they are pointing to the right place. Fixes #17313. [ci skip] - - - - - 7627eab5 by Ryan Scott at 2020-04-01T01:20:38-04:00 Fix the changelog/@since information for hGetContents'/getContents'/readFile' Fixes #17979. [ci skip] - - - - - 0002db1b by Sylvain Henry at 2020-04-01T01:21:27-04:00 Kill wORDS_BIGENDIAN and replace it with platformByteOrder (#17957) Metric Decrease: T13035 T1969 - - - - - 7b217179 by Sebastian Graf at 2020-04-01T15:03:24-04:00 PmCheck: Adjust recursion depth for inhabitation test In #17977, we ran into the reduction depth limit of the typechecker. That was only a symptom of a much broader issue: The recursion depth of the coverage checker for trying to instantiate strict fields in the `nonVoid` test was far too high (100, the `defaultMaxTcBound`). As a result, we were performing quite poorly on `T17977`. Short of a proper termination analysis to prove emptyness of a type, we just arbitrarily default to a much lower recursion limit of 3. Fixes #17977. - - - - - 3c09f636 by Andreas Klebinger at 2020-04-01T15:03:59-04:00 Make hadrian pass on the no-colour setting to GHC. Fixes #17983. - - - - - b943b25d by Simon Peyton Jones at 2020-04-02T01:45:58-04:00 Re-engineer the binder-swap transformation The binder-swap transformation is implemented by the occurrence analyser -- see Note [Binder swap] in OccurAnal. However it had a very nasty corner in it, for the case where the case scrutinee was a GlobalId. This led to trouble and hacks, and ultimately to #16296. This patch re-engineers how the occurrence analyser implements the binder-swap, by actually carrying out a substitution rather than by adding a let-binding. It's all described in Note [The binder-swap substitution]. I did a few other things along the way * Fix a bug in StgCse, which could allow a loop breaker to be CSE'd away. See Note [Care with loop breakers] in StgCse. I think it can only show up if occurrence analyser sets up bad loop breakers, but still. * Better commenting in SimplUtils.prepareAlts * A little refactoring in CoreUnfold; nothing significant e.g. rename CoreUnfold.mkTopUnfolding to mkFinalUnfolding * Renamed CoreSyn.isFragileUnfolding to hasCoreUnfolding * Move mkRuleInfo to CoreFVs We observed respectively 4.6% and 5.9% allocation decreases for the following tests: Metric Decrease: T9961 haddock.base - - - - - 42d68364 by Sebastian Graf at 2020-04-02T01:46:34-04:00 Preserve precise exceptions in strictness analysis Fix #13380 and #17676 by 1. Changing `raiseIO#` to have `topDiv` instead of `botDiv` 2. Give it special treatment in `Simplifier.Util.mkArgInfo`, treating it as if it still had `botDiv`, to recover dead code elimination. This is the first commit of the plan outlined in https://gitlab.haskell.org/ghc/ghc/-/merge_requests/2525#note_260886. - - - - - 0a88dd11 by Ömer Sinan Ağacan at 2020-04-02T01:47:25-04:00 Fix a pointer format string in RTS - - - - - 5beac042 by Ömer Sinan Ağacan at 2020-04-02T01:48:05-04:00 Remove unused closure stg_IND_direct - - - - - 88f38b03 by Ben Gamari at 2020-04-02T01:48:42-04:00 Session: Memoize stderrSupportsAnsiColors Not only is this a reasonable efficiency measure but it avoids making reentrant calls into ncurses, which is not thread-safe. See #17922. - - - - - 27740f24 by Ryan Scott at 2020-04-02T01:49:21-04:00 Make Hadrian build with Cabal-3.2 GHC 8.10 ships with `Cabal-3.2.0.0`, so it would be convenient to make Hadrian supporting building against 3.2.* instead of having to rebuild the entirety of `Cabal-3.0.0.0`. There is one API change in `Cabal-3.2.*` that affects Hadrian: the `synopsis` and `description` functions now return `ShortText` instead of `String`. Since Hadrian manipulates these `String`s in various places, I found that the simplest fix was to use CPP to convert `ShortText` to `String`s where appropriate. - - - - - 49802002 by Sylvain Henry at 2020-04-02T01:50:00-04:00 Update Stack resolver for hadrian/build-stack Broken by 57b888c0e90be7189285a6b078c30b26d0923809 - - - - - 30a63e79 by Ryan Scott at 2020-04-02T01:50:36-04:00 Fix two ASSERT buglets in reifyDataCon Two `ASSERT`s in `reifyDataCon` were always using `arg_tys`, but `arg_tys` is not meaningful for GADT constructors. In fact, it's worse than non-meaningful, since using `arg_tys` when reifying a GADT constructor can lead to failed `ASSERT`ions, as #17305 demonstrates. This patch applies the simplest possible fix to the immediate problem. The `ASSERT`s now use `r_arg_tys` instead of `arg_tys`, as the former makes sure to give something meaningful for GADT constructors. This makes the panic go away at the very least. There is still an underlying issue with the way the internals of `reifyDataCon` work, as described in https://gitlab.haskell.org/ghc/ghc/issues/17305#note_227023, but we leave that as future work, since fixing the underlying issue is much trickier (see https://gitlab.haskell.org/ghc/ghc/issues/17305#note_227087). - - - - - ef7576c4 by Zubin Duggal at 2020-04-03T06:24:56-04:00 Add outputable instances for the types in GHC.Iface.Ext.Types, add -ddump-hie flag to dump pretty printed contents of the .hie file Metric Increase: hie002 Because of the regression on i386: compile_time/bytes allocated increased from i386-linux-deb9 baseline @ HEAD~10: Expected hie002 (normal) compile_time/bytes allocated: 583014888.0 +/-10% Lower bound hie002 (normal) compile_time/bytes allocated: 524713399 Upper bound hie002 (normal) compile_time/bytes allocated: 641316377 Actual hie002 (normal) compile_time/bytes allocated: 877986292 Deviation hie002 (normal) compile_time/bytes allocated: 50.6 % *** unexpected stat test failure for hie002(normal) - - - - - 9462452a by Andreas Klebinger at 2020-04-03T06:25:33-04:00 Improve and refactor StgToCmm codegen for DataCons. We now differentiate three cases of constructor bindings: 1)Bindings which we can "replace" with a reference to an existing closure. Reference the replacement closure when accessing the binding. 2)Bindings which we can "replace" as above. But we still generate a closure which will be referenced by modules importing this binding. 3)For any other binding generate a closure. Then reference it. Before this patch 1) did only apply to local bindings and we didn't do 2) at all. - - - - - a214d214 by Moritz Bruder at 2020-04-03T06:26:11-04:00 Add singleton to NonEmpty in libraries/base This adds a definition to construct a singleton non-empty list (Data.List.NonEmpty) according to issue #17851. - - - - - f7597aa0 by Sylvain Henry at 2020-04-03T06:26:54-04:00 Testsuite: measure compiler stats for T16190 We were mistakenly measuring program stats - - - - - a485c3c4 by Sylvain Henry at 2020-04-03T06:26:54-04:00 Move blob handling into StgToCmm Move handling of big literal strings from CmmToAsm to StgToCmm. It avoids the use of `sdocWithDynFlags` (cf #10143). We might need to move this handling even higher in the pipeline in the future (cf #17960): this patch will make it easier. - - - - - cc2918a0 by Sylvain Henry at 2020-04-03T06:26:54-04:00 Refactor CmmStatics In !2959 we noticed that there was some redundant code (in GHC.Cmm.Utils and GHC.Cmm.StgToCmm.Utils) used to deal with `CmmStatics` datatype (before SRT generation) and `RawCmmStatics` datatype (after SRT generation). This patch removes this redundant code by using a single GADT for (Raw)CmmStatics. - - - - - 9e60273d by Maxim Koltsov at 2020-04-03T06:27:32-04:00 Fix haddock formatting in Control.Monad.ST.Lazy.Imp.hs - - - - - 1b7e8a94 by Andreas Klebinger at 2020-04-03T06:28:08-04:00 Turn newlines into spaces for hadrian/ghci. The newlines break the command on windows. - - - - - 4291bdda by Simon Peyton Jones at 2020-04-03T06:28:44-04:00 Major improvements to the specialiser This patch is joint work of Alexis King and Simon PJ. It does some significant refactoring of the type-class specialiser. Main highlights: * We can specialise functions with types like f :: Eq a => a -> Ord b => b => blah where the classes aren't all at the front (#16473). Here we can correctly specialise 'f' based on a call like f @Int @Bool dEqInt x dOrdBool This change really happened in an earlier patch commit 2d0cf6252957b8980d89481ecd0b79891da4b14b Author: Sandy Maguire <sandy at sandymaguire.me> Date: Thu May 16 12:12:10 2019 -0400 work that this new patch builds directly on that work, and refactors it a bit. * We can specialise functions with implicit parameters (#17930) g :: (?foo :: Bool, Show a) => a -> String Previously we could not, but now they behave just like a non-class argument as in 'f' above. * We can specialise under-saturated calls, where some (but not all of the dictionary arguments are provided (#17966). For example, we can specialise the above 'f' based on a call map (f @Int dEqInt) xs even though we don't (and can't) give Ord dictionary. This may sound exotic, but #17966 is a program from the wild, and showed significant perf loss for functions like f, if you need saturation of all dictionaries. * We fix a buglet in which a floated dictionary had a bogus demand (#17810), by using zapIdDemandInfo in the NonRec case of specBind. * A tiny side benefit: we can drop dead arguments to specialised functions; see Note [Drop dead args from specialisations] * Fixed a bug in deciding what dictionaries are "interesting"; see Note [Keep the old dictionaries interesting] This is all achieved by by building on Sandy Macguire's work in defining SpecArg, which mkCallUDs uses to describe the arguments of the call. Main changes: * Main work is in specHeader, which marched down the [InBndr] from the function definition and the [SpecArg] from the call site, together. * specCalls no longer has an arity check; the entire mechanism now handles unders-saturated calls fine. * mkCallUDs decides on an argument-by-argument basis whether to specialise a particular dictionary argument; this is new. See mk_spec_arg in mkCallUDs. It looks as if there are many more lines of code, but I think that all the extra lines are comments! - - - - - 40a85563 by Ömer Sinan Ağacan at 2020-04-03T18:26:19+03:00 Revert accidental change in 9462452 [ci skip] - - - - - bd75e5da by Ryan Scott at 2020-04-04T07:07:58-04:00 Enable ImpredicativeTypes internally when typechecking selector bindings This is necessary for certain record selectors with higher-rank types, such as the examples in #18005. See `Note [Impredicative record selectors]` in `TcTyDecls`. Fixes #18005. - - - - - dcfe29c8 by Ömer Sinan Ağacan at 2020-04-06T13:16:08-04:00 Don't override proc CafInfos in ticky builds Fixes #17947 When we have a ticky label for a proc, IdLabels for the ticky counter and proc entry share the same Name. This caused overriding proc CafInfos with the ticky CafInfos (i.e. NoCafRefs) during SRT analysis. We now ignore the ticky labels when building SRTMaps. This makes sense because: - When building the current module they don't need to be in SRTMaps as they're initialized as non-CAFFY (see mkRednCountsLabel), so they don't take part in the dependency analysis and they're never added to SRTs. (Reminder: a "dependency" in the SRT analysis is a CAFFY dependency, non-CAFFY uses are not considered as dependencies for the algorithm) - They don't appear in the interfaces as they're not exported, so it doesn't matter for cross-module concerns whether they're in the SRTMap or not. See also the new Note [Ticky labels in SRT analysis]. - - - - - cec2c71f by Simon Peyton Jones at 2020-04-06T13:16:44-04:00 Fix an tricky specialiser loop Issue #17151 was a very tricky example of a bug in which the specialiser accidentally constructs a recurive dictionary, so that everything turns into bottom. I have fixed variants of this bug at least twice before: see Note [Avoiding loops]. It was a bit of a struggle to isolate the problem, greatly aided by the work that Alexey Kuleshevich did in distilling a test case. Once I'd understood the problem, it was not difficult to fix, though it did lead me a bit of refactoring in specImports. - - - - - e850d14f by Simon Peyton Jones at 2020-04-06T13:16:44-04:00 Refactoring only This refactors DictBinds into a data type rather than a pair. No change in behaviour, just better code - - - - - f38e8d61 by Daniel Gröber at 2020-04-07T02:00:05-04:00 rts: ProfHeap: Fix memory leak when not compiled with profiling If we're doing heap profiling on an unprofiled executable we keep allocating new space in initEra via nextEra on each profiler run but we don't have a corresponding freeEra call. We do free the last era in endHeapProfiling but previous eras will have been overwritten by initEra and will never get free()ed. Metric Decrease: space_leak_001 - - - - - bcd66859 by Sebastian Graf at 2020-04-07T02:00:41-04:00 Re-export GHC.Magic.noinline from base - - - - - 3d2991f8 by Ben Gamari at 2020-04-07T18:36:09-04:00 simplifier: Kill off ufKeenessFactor We used to have another factor, ufKeenessFactor, which would scale the discounts before they were subtracted from the size. This was justified with the following comment: -- We multiple the raw discounts (args_discount and result_discount) -- ty opt_UnfoldingKeenessFactor because the former have to do with -- *size* whereas the discounts imply that there's some extra -- *efficiency* to be gained (e.g. beta reductions, case reductions) -- by inlining. However, this is highly suspect since it means that we subtract a *scaled* size from an absolute size, resulting in crazy (e.g. negative) scores in some cases (#15304). We consequently killed off ufKeenessFactor and bumped up the ufUseThreshold to compensate. Adjustment of unfolding use threshold ===================================== Since this removes a discount from our inlining heuristic, I revisited our default choice of -funfolding-use-threshold to minimize the change in overall inlining behavior. Specifically, I measured runtime allocations and executable size of nofib and the testsuite performance tests built using compilers (and core libraries) built with several values of -funfolding-use-threshold. This comes as a result of a quantitative comparison of testsuite performance and code size as a function of ufUseThreshold, comparing GHC trees using values of 50, 60, 70, 80, 90, and 100. The test set consisted of nofib and the testsuite performance tests. A full summary of these measurements are found in the description of !2608 Comparing executable sizes (relative to the base commit) across all nofib tests, we see that sizes are similar to the baseline: gmean min max median thresh 50 -6.36% -7.04% -4.82% -6.46% 60 -5.04% -5.97% -3.83% -5.11% 70 -2.90% -3.84% -2.31% -2.92% 80 -0.75% -2.16% -0.42% -0.73% 90 +0.24% -0.41% +0.55% +0.26% 100 +1.36% +0.80% +1.64% +1.37% baseline +0.00% +0.00% +0.00% +0.00% Likewise, looking at runtime allocations we see that 80 gives slightly better optimisation than the baseline: gmean min max median thresh 50 +0.16% -0.16% +4.43% +0.00% 60 +0.09% -0.00% +3.10% +0.00% 70 +0.04% -0.09% +2.29% +0.00% 80 +0.02% -1.17% +2.29% +0.00% 90 -0.02% -2.59% +1.86% +0.00% 100 +0.00% -2.59% +7.51% -0.00% baseline +0.00% +0.00% +0.00% +0.00% Finally, I had to add a NOINLINE in T4306 to ensure that `upd` is worker-wrappered as the test expects. This makes me wonder whether the inlining heuristic is now too liberal as `upd` is quite a large function. The same measure was taken in T12600. Wall clock time compiling Cabal with -O0 thresh 50 60 70 80 90 100 baseline build-Cabal 93.88 89.58 92.59 90.09 100.26 94.81 89.13 Also, this change happens to avoid the spurious test output in `plugin-recomp-change` and `plugin-recomp-change-prof` (see #17308). Metric Decrease: hie002 T12234 T13035 T13719 T14683 T4801 T5631 T5642 T9020 T9872d T9961 Metric Increase: T12150 T12425 T13701 T14697 T15426 T1969 T3064 T5837 T6048 T9203 T9872a T9872b T9872c T9872d haddock.Cabal haddock.base haddock.compiler - - - - - 255418da by Sylvain Henry at 2020-04-07T18:36:49-04:00 Modules: type-checker (#13009) Update Haddock submodule - - - - - 04b6cf94 by Ryan Scott at 2020-04-07T19:43:20-04:00 Make NoExtCon fields strict This changes every unused TTG extension constructor to be strict in its field so that the pattern-match coverage checker is smart enough any such constructors are unreachable in pattern matches. This lets us remove nearly every use of `noExtCon` in the GHC API. The only ones we cannot remove are ones underneath uses of `ghcPass`, but that is only because GHC 8.8's and 8.10's coverage checkers weren't smart enough to perform this kind of reasoning. GHC HEAD's coverage checker, on the other hand, _is_ smart enough, so we guard these uses of `noExtCon` with CPP for now. Bumps the `haddock` submodule. Fixes #17992. - - - - - 7802fa17 by Ryan Scott at 2020-04-08T16:43:44-04:00 Handle promoted data constructors in typeToLHsType correctly Instead of using `nlHsTyVar`, which hardcodes `NotPromoted`, have `typeToLHsType` pick between `Promoted` and `NotPromoted` by checking if a type constructor is promoted using `isPromotedDataCon`. Fixes #18020. - - - - - ce481361 by Ben Gamari at 2020-04-09T16:17:21-04:00 hadrian: Use --export-dynamic when linking iserv As noticed in #17962, the make build system currently does this (see 3ce0e0ba) but the change was never ported to Hadrian. - - - - - fa66f143 by Ben Gamari at 2020-04-09T16:17:21-04:00 iserv: Don't pass --export-dynamic on FreeBSD This is definitely a hack but it's probably the best we can do for now. Hadrian does the right thing here by passing --export-dynamic only to the linker. - - - - - 39075176 by Ömer Sinan Ağacan at 2020-04-09T16:18:00-04:00 Fix CNF handling in compacting GC Fixes #17937 Previously compacting GC simply ignored CNFs. This is mostly fine as most (see "What about small compacts?" below) CNF objects don't have outgoing pointers, and are "large" (allocated in large blocks) and large objects are not moved or compacted. However if we do GC *during* sharing-preserving compaction then the CNF will have a hash table mapping objects that have been moved to the CNF to their location in the CNF, to be able to preserve sharing. This case is handled in the copying collector, in `scavenge_compact`, where we evacuate hash table entries and then rehash the table. Compacting GC ignored this case. We now visit CNFs in all generations when threading pointers to the compacted heap and thread hash table keys. A visited CNF is added to the list `nfdata_chain`. After compaction is done, we re-visit the CNFs in that list and rehash the tables. The overhead is minimal: the list is static in `Compact.c`, and link field is added to `StgCompactNFData` closure. Programs that don't use CNFs should not be affected. To test this CNF tests are now also run in a new way 'compacting_gc', which just passes `-c` to the RTS, enabling compacting GC for the oldest generation. Before this patch the result would be: Unexpected failures: compact_gc.run compact_gc [bad exit code (139)] (compacting_gc) compact_huge_array.run compact_huge_array [bad exit code (1)] (compacting_gc) With this patch all tests pass. I can also pass `-c -DS` without any failures. What about small compacts? Small CNFs are still not handled by the compacting GC. However so far I'm unable to write a test that triggers a runtime panic ("update_fwd: unknown/strange object") by allocating a small CNF in a compated heap. It's possible that I'm missing something and it's not possible to have a small CNF. NoFib Results: -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS +0.1% 0.0% 0.0% +0.0% +0.0% CSD +0.1% 0.0% 0.0% 0.0% 0.0% FS +0.1% 0.0% 0.0% 0.0% 0.0% S +0.1% 0.0% 0.0% 0.0% 0.0% VS +0.1% 0.0% 0.0% 0.0% 0.0% VSD +0.1% 0.0% +0.0% +0.0% -0.0% VSM +0.1% 0.0% +0.0% -0.0% 0.0% anna +0.0% 0.0% -0.0% -0.0% -0.0% ansi +0.1% 0.0% +0.0% +0.0% +0.0% atom +0.1% 0.0% +0.0% +0.0% +0.0% awards +0.1% 0.0% +0.0% +0.0% +0.0% banner +0.1% 0.0% +0.0% +0.0% +0.0% bernouilli +0.1% 0.0% 0.0% -0.0% +0.0% binary-trees +0.1% 0.0% -0.0% -0.0% 0.0% boyer +0.1% 0.0% +0.0% +0.0% +0.0% boyer2 +0.1% 0.0% +0.0% +0.0% +0.0% bspt +0.1% 0.0% -0.0% -0.0% -0.0% cacheprof +0.1% 0.0% -0.0% -0.0% -0.0% calendar +0.1% 0.0% +0.0% +0.0% +0.0% cichelli +0.1% 0.0% +0.0% +0.0% +0.0% circsim +0.1% 0.0% +0.0% +0.0% +0.0% clausify +0.1% 0.0% -0.0% +0.0% +0.0% comp_lab_zift +0.1% 0.0% +0.0% +0.0% +0.0% compress +0.1% 0.0% +0.0% +0.0% 0.0% compress2 +0.1% 0.0% -0.0% 0.0% 0.0% constraints +0.1% 0.0% +0.0% +0.0% +0.0% cryptarithm1 +0.1% 0.0% +0.0% +0.0% +0.0% cryptarithm2 +0.1% 0.0% +0.0% +0.0% +0.0% cse +0.1% 0.0% +0.0% +0.0% +0.0% digits-of-e1 +0.1% 0.0% +0.0% -0.0% -0.0% digits-of-e2 +0.1% 0.0% -0.0% -0.0% -0.0% dom-lt +0.1% 0.0% +0.0% +0.0% +0.0% eliza +0.1% 0.0% +0.0% +0.0% +0.0% event +0.1% 0.0% +0.0% +0.0% +0.0% exact-reals +0.1% 0.0% +0.0% +0.0% +0.0% exp3_8 +0.1% 0.0% +0.0% -0.0% 0.0% expert +0.1% 0.0% +0.0% +0.0% +0.0% fannkuch-redux +0.1% 0.0% -0.0% 0.0% 0.0% fasta +0.1% 0.0% -0.0% +0.0% +0.0% fem +0.1% 0.0% -0.0% +0.0% 0.0% fft +0.1% 0.0% -0.0% +0.0% +0.0% fft2 +0.1% 0.0% +0.0% +0.0% +0.0% fibheaps +0.1% 0.0% +0.0% +0.0% +0.0% fish +0.1% 0.0% +0.0% +0.0% +0.0% fluid +0.0% 0.0% +0.0% +0.0% +0.0% fulsom +0.1% 0.0% -0.0% +0.0% 0.0% gamteb +0.1% 0.0% +0.0% +0.0% 0.0% gcd +0.1% 0.0% +0.0% +0.0% +0.0% gen_regexps +0.1% 0.0% -0.0% +0.0% 0.0% genfft +0.1% 0.0% +0.0% +0.0% +0.0% gg +0.1% 0.0% 0.0% +0.0% +0.0% grep +0.1% 0.0% -0.0% +0.0% +0.0% hidden +0.1% 0.0% +0.0% -0.0% 0.0% hpg +0.1% 0.0% -0.0% -0.0% -0.0% ida +0.1% 0.0% +0.0% +0.0% +0.0% infer +0.1% 0.0% +0.0% 0.0% -0.0% integer +0.1% 0.0% +0.0% +0.0% +0.0% integrate +0.1% 0.0% -0.0% -0.0% -0.0% k-nucleotide +0.1% 0.0% +0.0% +0.0% 0.0% kahan +0.1% 0.0% +0.0% +0.0% +0.0% knights +0.1% 0.0% -0.0% -0.0% -0.0% lambda +0.1% 0.0% +0.0% +0.0% -0.0% last-piece +0.1% 0.0% +0.0% 0.0% 0.0% lcss +0.1% 0.0% +0.0% +0.0% 0.0% life +0.1% 0.0% -0.0% +0.0% +0.0% lift +0.1% 0.0% +0.0% +0.0% +0.0% linear +0.1% 0.0% -0.0% +0.0% 0.0% listcompr +0.1% 0.0% +0.0% +0.0% +0.0% listcopy +0.1% 0.0% +0.0% +0.0% +0.0% maillist +0.1% 0.0% +0.0% -0.0% -0.0% mandel +0.1% 0.0% +0.0% +0.0% 0.0% mandel2 +0.1% 0.0% +0.0% +0.0% +0.0% mate +0.1% 0.0% +0.0% 0.0% +0.0% minimax +0.1% 0.0% -0.0% 0.0% -0.0% mkhprog +0.1% 0.0% +0.0% +0.0% +0.0% multiplier +0.1% 0.0% +0.0% 0.0% 0.0% n-body +0.1% 0.0% +0.0% +0.0% +0.0% nucleic2 +0.1% 0.0% +0.0% +0.0% +0.0% para +0.1% 0.0% 0.0% +0.0% +0.0% paraffins +0.1% 0.0% +0.0% -0.0% 0.0% parser +0.1% 0.0% -0.0% -0.0% -0.0% parstof +0.1% 0.0% +0.0% +0.0% +0.0% pic +0.1% 0.0% -0.0% -0.0% 0.0% pidigits +0.1% 0.0% +0.0% -0.0% -0.0% power +0.1% 0.0% +0.0% +0.0% +0.0% pretty +0.1% 0.0% -0.0% -0.0% -0.1% primes +0.1% 0.0% -0.0% -0.0% -0.0% primetest +0.1% 0.0% -0.0% -0.0% -0.0% prolog +0.1% 0.0% -0.0% -0.0% -0.0% puzzle +0.1% 0.0% -0.0% -0.0% -0.0% queens +0.1% 0.0% +0.0% +0.0% +0.0% reptile +0.1% 0.0% -0.0% -0.0% +0.0% reverse-complem +0.1% 0.0% +0.0% 0.0% -0.0% rewrite +0.1% 0.0% -0.0% -0.0% -0.0% rfib +0.1% 0.0% +0.0% +0.0% +0.0% rsa +0.1% 0.0% -0.0% +0.0% -0.0% scc +0.1% 0.0% -0.0% -0.0% -0.1% sched +0.1% 0.0% +0.0% +0.0% +0.0% scs +0.1% 0.0% +0.0% +0.0% +0.0% simple +0.1% 0.0% -0.0% -0.0% -0.0% solid +0.1% 0.0% +0.0% +0.0% +0.0% sorting +0.1% 0.0% -0.0% -0.0% -0.0% spectral-norm +0.1% 0.0% +0.0% +0.0% +0.0% sphere +0.1% 0.0% -0.0% -0.0% -0.0% symalg +0.1% 0.0% -0.0% -0.0% -0.0% tak +0.1% 0.0% +0.0% +0.0% +0.0% transform +0.1% 0.0% +0.0% +0.0% +0.0% treejoin +0.1% 0.0% +0.0% -0.0% -0.0% typecheck +0.1% 0.0% +0.0% +0.0% +0.0% veritas +0.0% 0.0% +0.0% +0.0% +0.0% wang +0.1% 0.0% 0.0% +0.0% +0.0% wave4main +0.1% 0.0% +0.0% +0.0% +0.0% wheel-sieve1 +0.1% 0.0% +0.0% +0.0% +0.0% wheel-sieve2 +0.1% 0.0% +0.0% +0.0% +0.0% x2n1 +0.1% 0.0% +0.0% +0.0% +0.0% -------------------------------------------------------------------------------- Min +0.0% 0.0% -0.0% -0.0% -0.1% Max +0.1% 0.0% +0.0% +0.0% +0.0% Geometric Mean +0.1% -0.0% -0.0% -0.0% -0.0% Bumping numbers of nonsensical perf tests: Metric Increase: T12150 T12234 T12425 T13035 T5837 T6048 It's simply not possible for this patch to increase allocations, and I've wasted enough time on these test in the past (see #17686). I think these tests should not be perf tests, but for now I'll bump the numbers. - - - - - dce50062 by Sylvain Henry at 2020-04-09T16:18:44-04:00 Rts: show errno on failure (#18033) - - - - - 045139f4 by Hécate at 2020-04-09T23:10:44-04:00 Add an example to liftIO and explain its purpose - - - - - 101fab6e by Sebastian Graf at 2020-04-09T23:11:21-04:00 Special case `isConstraintKindCon` on `AlgTyCon` Previously, the `tyConUnique` record selector would unfold into a huge case expression that would be inlined in all call sites, such as the `INLINE`-annotated `coreView`, see #18026. `constraintKindTyConKey` only occurs as the `Unique` of an `AlgTyCon` anyway, so we can make the code a lot more compact, but have to move it to GHC.Core.TyCon. Metric Decrease: T12150 T12234 - - - - - f5212dfc by Sebastian Graf at 2020-04-09T23:11:57-04:00 DmdAnal: No need to attach a StrictSig to DataCon workers In GHC.Types.Id.Make we were giving a strictness signature to every data constructor wrapper Id that we weren't looking at in demand analysis anyway. We used to use its CPR info, but that has its own CPR signature now. `Note [Data-con worker strictness]` then felt very out of place, so I moved it to GHC.Core.DataCon. - - - - - 75a185dc by Sylvain Henry at 2020-04-09T23:12:37-04:00 Hadrian: fix --summary - - - - - 723062ed by Ömer Sinan Ağacan at 2020-04-10T09:18:14+03:00 testsuite: Move no_lint to the top level, tweak hie002 - We don't want to benchmark linting so disable lints in hie002 perf test - Move no_lint to the top-level to be able to use it in tests other than those in `testsuite/tests/perf/compiler`. - Filter out -dstg-lint in no_lint. - hie002 allocation numbers on 32-bit are unstable, so skip it on 32-bit Metric Decrease: hie002 ManyConstructors T12150 T12234 T13035 T1969 T4801 T9233 T9961 - - - - - bcafaa82 by Peter Trommler at 2020-04-10T19:29:33-04:00 Testsuite: mark T11531 fragile The test depends on a link editor allowing undefined symbols in an ELF shared object. This is the standard but it seems some distributions patch their link editor. See the report by @hsyl20 in #11531. Fixes #11531 - - - - - 0889f5ee by Takenobu Tani at 2020-04-12T11:44:52+09:00 testsuite: Fix comment for a language extension [skip ci] - - - - - cd4f92b5 by Simon Peyton Jones at 2020-04-12T11:20:58-04:00 Significant refactor of Lint This refactoring of Lint was triggered by #17923, which is fixed by this patch. The main change is this. Instead of lintType :: Type -> LintM LintedKind we now have lintType :: Type -> LintM LintedType Previously, all of typeKind was effectively duplicate in lintType. Moreover, since we have an ambient substitution, we still had to apply the substition here and there, sometimes more than once. It was all very tricky, in the end, and made my head hurt. Now, lintType returns a fully linted type, with all substitutions performed on it. This is much simpler. The same thing is needed for Coercions. Instead of lintCoercion :: OutCoercion -> LintM (LintedKind, LintedKind, LintedType, LintedType, Role) we now have lintCoercion :: Coercion -> LintM LintedCoercion Much simpler! The code is shorter and less bug-prone. There are a lot of knock on effects. But life is now better. Metric Decrease: T1969 - - - - - 0efaf301 by Josh Meredith at 2020-04-12T11:21:34-04:00 Implement extensible interface files - - - - - 54ca66a7 by Ryan Scott at 2020-04-12T11:22:10-04:00 Use conLikeUserTyVarBinders to quantify field selector types This patch: 1. Writes up a specification for how the types of top-level field selectors should be determined in a new section of the GHC User's Guide, and 2. Makes GHC actually implement that specification by using `conLikeUserTyVarBinders` in `mkOneRecordSelector` to preserve the order and specificity of type variables written by the user. Fixes #18023. - - - - - 35799dda by Ben Gamari at 2020-04-12T11:22:50-04:00 hadrian: Don't --export-dynamic on Darwin When fixing #17962 I neglected to consider that --export-dynamic is only supported on ELF platforms. - - - - - e8029816 by Alexis King at 2020-04-12T11:23:27-04:00 Add an INLINE pragma to Control.Category.>>> This fixes #18013 by adding INLINE pragmas to both Control.Category.>>> and GHC.Desugar.>>>. The functional change in this patch is tiny (just two lines of pragmas!), but an accompanying Note explains in gory detail what’s going on. - - - - - 0da186c1 by Krzysztof Gogolewski at 2020-04-14T07:55:20-04:00 Change zipWith to zipWithEqual in a few places - - - - - 074c1ccd by Andreas Klebinger at 2020-04-14T07:55:55-04:00 Small change to the windows ticker. We already have a function to go from time to ms so use it. Also expand on the state of timer resolution. - - - - - b69cc884 by Alp Mestanogullari at 2020-04-14T07:56:38-04:00 hadrian: get rid of unnecessary levels of nesting in source-dist - - - - - d0c3b069 by Julien Debon at 2020-04-14T07:57:16-04:00 doc (Foldable): Add examples to Data.Foldable See #17929 - - - - - 5b08e0c0 by Ben Gamari at 2020-04-14T23:28:20-04:00 StgCRun: Enable unwinding only on Linux It's broken on macOS due and SmartOS due to assembler differences (#15207) so let's be conservative in enabling it. Also, refactor things to make the intent clearer. - - - - - 27cc2e7b by Ben Gamari at 2020-04-14T23:28:57-04:00 rts: Don't mark evacuate_large as inline This function has two callsites and is quite large. GCC consequently decides not to inline and warns instead. Given the situation, I can't blame it. Let's just remove the inline specifier. - - - - - 9853fc5e by Ben Gamari at 2020-04-14T23:29:48-04:00 base: Enable large file support for OFD locking impl. Not only is this a good idea in general but this should also avoid issue #17950 by ensuring that off_t is 64-bits. - - - - - 7b41f21b by Matthew Pickering at 2020-04-14T23:30:24-04:00 Hadrian: Make -i paths absolute The primary reason for this change is that ghcide does not work with relative paths. It also matches what cabal and stack do, they always pass absolute paths. - - - - - 41230e26 by Daniel Gröber at 2020-04-14T23:31:01-04:00 Zero out pinned block alignment slop when profiling The heap profiler currently cannot traverse pinned blocks because of alignment slop. This used to just be a minor annoyance as the whole block is accounted into a special cost center rather than the respective object's CCS, cf. #7275. However for the new root profiler we would like to be able to visit _every_ closure on the heap. We need to do this so we can get rid of the current 'flip' bit hack in the heap traversal code. Since info pointers are always non-zero we can in principle skip all the slop in the profiler if we can rely on it being zeroed. This assumption caused problems in the past though, commit a586b33f8e ("rts: Correct handling of LARGE ARR_WORDS in LDV profiler"), part of !1118, tried to use the same trick for BF_LARGE objects but neglected to take into account that shrink*Array# functions don't ensure that slop is zeroed when not compiling with profiling. Later, commit 0c114c6599 ("Handle large ARR_WORDS in heap census (fix as we will only be assuming slop is zeroed when profiling is on. This commit also reduces the ammount of slop we introduce in the first place by calculating the needed alignment before doing the allocation for small objects where we know the next available address. For large objects we don't know how much alignment we'll have to do yet since those details are hidden behind the allocateMightFail function so there we continue to allocate the maximum additional words we'll need to do the alignment. So we don't have to duplicate all this logic in the cmm code we pull it into the RTS allocatePinned function instead. Metric Decrease: T7257 haddock.Cabal haddock.base - - - - - 15fa9bd6 by Daniel Gröber at 2020-04-14T23:31:01-04:00 rts: Expand and add more notes regarding slop - - - - - caf3f444 by Daniel Gröber at 2020-04-14T23:31:01-04:00 rts: allocatePinned: Fix confusion about word/byte units - - - - - c3c0f662 by Daniel Gröber at 2020-04-14T23:31:01-04:00 rts: Underline some Notes as is conventional - - - - - e149dea9 by Daniel Gröber at 2020-04-14T23:31:38-04:00 rts: Fix nomenclature in OVERWRITING_CLOSURE macros The additional commentary introduced by commit 8916e64e5437 ("Implement shrinkSmallMutableArray# and resizeSmallMutableArray#.") unfortunately got this wrong. We set 'prim' to true in overwritingClosureOfs because we _don't_ want to call LDV_recordDead(). The reason is because of this "inherently used" distinction made in the LDV profiler so I rename the variable to be more appropriate. - - - - - 1dd3d18c by Daniel Gröber at 2020-04-14T23:31:38-04:00 Remove call to LDV_RECORD_CREATE for array resizing - - - - - 19de2fb0 by Daniel Gröber at 2020-04-14T23:31:38-04:00 rts: Assert LDV_recordDead is not called for inherently used closures The comments make it clear LDV_recordDead should not be called for inhererently used closures, so add an assertion to codify this fact. - - - - - 0b934e30 by Ryan Scott at 2020-04-14T23:32:14-04:00 Bump template-haskell version to 2.17.0.0 This requires bumping the `exceptions` and `text` submodules to bring in commits that bump their respective upper version bounds on `template-haskell`. Fixes #17645. Fixes #17696. Note that the new `text` commit includes a fair number of additions to the Haddocks in that library. As a result, Haddock has to do more work during the `haddock.Cabal` test case, increasing the number of allocations it requires. Therefore, ------------------------- Metric Increase: haddock.Cabal ------------------------- - - - - - 22cc8e51 by Ryan Scott at 2020-04-15T17:48:47-04:00 Fix #18052 by using pprPrefixOcc in more places This fixes several small oversights in the choice of pretty-printing function to use. Fixes #18052. - - - - - ec77b2f1 by Daniel Gröber at 2020-04-15T17:49:24-04:00 rts: ProfHeap: Fix wrong time in last heap profile sample We've had this longstanding issue in the heap profiler, where the time of the last sample in the profile is sometimes way off causing the rendered graph to be quite useless for long runs. It seems to me the problem is that we use mut_user_time() for the last sample as opposed to getRTSStats(), which we use when calling heapProfile() in GC.c. The former is equivalent to getProcessCPUTime() but the latter does some additional stuff: getProcessCPUTime() - end_init_cpu - stats.gc_cpu_ns - stats.nonmoving_gc_cpu_ns So to fix this just use getRTSStats() in both places. - - - - - 85fc32f0 by Sylvain Henry at 2020-04-17T12:45:25-04:00 Hadrian: fix dyn_o/dyn_hi rule (#17534) - - - - - bfde3b76 by Ryan Scott at 2020-04-17T12:46:02-04:00 Fix #18065 by fixing an InstCo oversight in Core Lint There was a small thinko in Core Lint's treatment of `InstCo` coercions that ultimately led to #18065. The fix: add an apostrophe. That's it! Fixes #18065. Co-authored-by: Simon Peyton Jones <simonpj at microsoft.com> - - - - - a05348eb by Cale Gibbard at 2020-04-17T13:08:47-04:00 Change the fail operator argument of BindStmt to be a Maybe Don't use noSyntaxExpr for it. There is no good way to defensively case on that, nor is it clear one ought to do so. - - - - - 79e27144 by John Ericson at 2020-04-17T13:08:47-04:00 Use trees that grow for rebindable operators for `<-` binds Also add more documentation. - - - - - 18bc16ed by Cale Gibbard at 2020-04-17T13:08:47-04:00 Use FailOperator in more places, define a couple datatypes (XBindStmtRn and XBindStmtTc) to help clarify the meaning of XBindStmt in the renamer and typechecker - - - - - 84cc8394 by Simon Peyton Jones at 2020-04-18T13:20:29-04:00 Add a missing zonk in tcHsPartialType I omitted a vital zonk when refactoring tcHsPartialType in commit 48fb3482f8cbc8a4b37161021e846105f980eed4 Author: Simon Peyton Jones <simonpj at microsoft.com> Date: Wed Jun 5 08:55:17 2019 +0100 Fix typechecking of partial type signatures This patch fixes it and adds commentary to explain why. Fixes #18008 - - - - - 2ee96ac1 by Ben Gamari at 2020-04-18T13:21:05-04:00 gitlab-ci: Bump FreeBSD bootstrap compiler to 8.10.1 - - - - - 434312e5 by Ben Gamari at 2020-04-18T13:21:05-04:00 gitlab-ci: Enable FreeBSD job for so-labelled MRs - - - - - ddffb227 by Ben Gamari at 2020-04-18T13:21:05-04:00 gitlab-ci: Use rules syntax for conditional jobs - - - - - e2586828 by Ben Gamari at 2020-04-18T13:21:05-04:00 Bump hsc2hs submodule - - - - - 15ab6cd5 by Ömer Sinan Ağacan at 2020-04-18T13:21:44-04:00 Improve prepForeignCall error reporting Show parameters and description of the error code when ffi_prep_cif fails. This may be helpful for debugging #17018. - - - - - 3ca52151 by Sylvain Henry at 2020-04-18T20:04:14+02:00 GHC.Core.Opt renaming * GHC.Core.Op => GHC.Core.Opt * GHC.Core.Opt.Simplify.Driver => GHC.Core.Opt.Driver * GHC.Core.Opt.Tidy => GHC.Core.Tidy * GHC.Core.Opt.WorkWrap.Lib => GHC.Core.Opt.WorkWrap.Utils As discussed in: * https://mail.haskell.org/pipermail/ghc-devs/2020-April/018758.html * https://gitlab.haskell.org/ghc/ghc/issues/13009#note_264650 - - - - - 15312bbb by Sylvain Henry at 2020-04-18T20:04:46+02:00 Modules (#13009) * SysTools * Parser * GHC.Builtin * GHC.Iface.Recomp * Settings Update Haddock submodule Metric Decrease: Naperian parsing001 - - - - - eaed0a32 by Alexis King at 2020-04-19T03:16:44-04:00 Add missing addInScope call for letrec binders in OccurAnal This fixes #18044, where a shadowed variable was incorrectly substituted by the binder swap on the RHS of a floated-in letrec. This can only happen when the uniques line up *just* right, so writing a regression test would be very difficult, but at least the fix is small and straightforward. - - - - - 36882493 by Shayne Fletcher at 2020-04-20T04:36:43-04:00 Derive Ord instance for Extension Metric Increase: T12150 T12234 - - - - - b43365ad by Simon Peyton Jones at 2020-04-20T04:37:20-04:00 Fix a buglet in redundant-constraint warnings Ticket #18036 pointed out that we were reporting a redundant constraint when it really really wasn't. Turned out to be a buglet in the SkolemInfo for the relevant implication constraint. Easily fixed! - - - - - d5fae7da by Ömer Sinan Ağacan at 2020-04-20T14:39:28-04:00 Mark T12010 fragile on 32-bit - - - - - bca02fca by Adam Sandberg Ericsson at 2020-04-21T06:38:45-04:00 docs: drop note about not supporting shared libraries on unix systems [skip ci] - - - - - 6655f933 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Use ParserFlags in GHC.Runtime.Eval (#17957) Instead of passing `DynFlags` to functions such as `isStmt` and `hasImport` in `GHC.Runtime.Eval` we pass `ParserFlags`. It's a much simpler structure that can be created purely with `mkParserFlags'`. - - - - - 70be0fbc by Sylvain Henry at 2020-04-21T06:39:32-04:00 GHC.Runtime: avoid DynFlags (#17957) * add `getPlatform :: TcM Platform` helper * remove unused `DynFlags` parameter from `emptyPLS` - - - - - 35e43d48 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Avoid DynFlags in Ppr code (#17957) * replace `DynFlags` parameters with `SDocContext` parameters for a few Ppr related functions: `bufLeftRenderSDoc`, `printSDoc`, `printSDocLn`, `showSDocOneLine`. * remove the use of `pprCols :: DynFlags -> Int` in Outputable. We already have the information via `sdocLineLength :: SDocContext -> Int` - - - - - ce5c2999 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Avoid using sdocWithDynFlags (#17957) Remove one use of `sdocWithDynFlags` from `GHC.CmmToLlvm.llvmCodeGen'` and from `GHC.Driver.CodeOutput.profilingInitCode` - - - - - f2a98996 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Avoid `sdocWithDynFlags` in `pprCLbl` (#17957) * add a `DynFlags` parameter to `pprCLbl` * put `maybe_underscore` and `pprAsmCLbl` in a `where` clause to avoid `DynFlags` parameters - - - - - 747093b7 by Sylvain Henry at 2020-04-21T06:39:32-04:00 CmmToAsm DynFlags refactoring (#17957) * Remove `DynFlags` parameter from `isDynLinkName`: `isDynLinkName` used to test the global `ExternalDynamicRefs` flag. Now we test it outside of `isDynLinkName` * Add new fields into `NCGConfig`: current unit id, sse/bmi versions, externalDynamicRefs, etc. * Replace many uses of `DynFlags` by `NCGConfig` * Moved `BMI/SSE` datatypes into `GHC.Platform` - - - - - ffd7eef2 by Takenobu Tani at 2020-04-22T23:09:50-04:00 stg-spec: Modify file paths according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * GHC/Stg/Syntax.hs <= stgSyn/StgSyn.hs * GHC/Types/Literal.hs <= basicTypes/Literal.hs * GHC/Types/CostCentre.hs <= profiling/CostCentre.hs This patch also updates old file path [2]: * utils/genapply/Main.hs <= utils/genapply/GenApply.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: commit 0cc4aad36f [skip ci] - - - - - e8a5d81b by Jonathan DK Gibbons at 2020-04-22T23:10:28-04:00 Refactor the `MatchResult` type in the desugarer This way, it does a better job of proving whether or not the fail operator is used. - - - - - dcb7fe5a by John Ericson at 2020-04-22T23:10:28-04:00 Remove panic in dsHandleMonadicFailure Rework dsHandleMonadicFailure to be correct by construction instead of using an unreachable panic. - - - - - cde23cd4 by John Ericson at 2020-04-22T23:10:28-04:00 Inline `adjustMatchResult` It is just `fmap` - - - - - 72cb6bcc by John Ericson at 2020-04-22T23:10:28-04:00 Generalize type of `matchCanFail` - - - - - 401f7bb3 by John Ericson at 2020-04-22T23:10:28-04:00 `MatchResult'` -> `MatchResult` Inline `MatchResult` alias accordingly. - - - - - 6c9fae23 by Alexis King at 2020-04-22T23:11:12-04:00 Mark DataCon wrappers CONLIKE Now that DataCon wrappers don’t inline until phase 0 (see commit b78cc64e923716ac0512c299f42d4d0012306c05), it’s important that case-of-known-constructor and RULE matching be able to see saturated applications of DataCon wrappers in unfoldings. Making them conlike is a natural way to do it, since they are, in fact, precisely the sort of thing the CONLIKE pragma exists to solve. Fixes #18012. This also bumps the version of the parsec submodule to incorporate a patch that avoids a metric increase on the haddock perf tests. The increase was not really a flaw in this patch, as parsec was implicitly relying on inlining heuristics. The patch to parsec just adds some INLINABLE pragmas, and we get a nice performance bump out of it (well beyond the performance we lost from this patch). Metric Decrease: T12234 WWRec haddock.Cabal haddock.base haddock.compiler - - - - - 48b8951e by Roland Senn at 2020-04-22T23:11:51-04:00 Fix tab-completion for :break (#17989) In tab-completion for the `:break` command, only those identifiers should be shown, that are accepted in the `:break` command. Hence these identifiers must be - defined in an interpreted module - top-level - currently in scope - listed in a `ModBreaks` value as a possible breakpoint. The identifiers my be qualified or unqualified. To get all possible top-level breakpoints for tab-completeion with the correct qualification do: 1. Build the list called `pifsBreaks` of all pairs of (Identifier, module-filename) from the `ModBreaks` values. Here all identifiers are unqualified. 2. Build the list called `pifInscope` of all pairs of (Identifiers, module-filename) with identifiers from the `GlobalRdrEnv`. Take only those identifiers that are in scope and have the correct prefix. Here the identifiers may be qualified. 3. From the `pifInscope` list seclect all pairs that can be found in the `pifsBreaks` list, by comparing only the unqualified part of the identifier. The remaining identifiers can be used for tab-completion. This ensures, that we show only identifiers, that can be used in a `:break` command. - - - - - 34a45ee6 by Peter Trommler at 2020-04-22T23:12:27-04:00 PPC NCG: Add DWARF constants and debug labels Fixes #11261 - - - - - ffde2348 by Simon Peyton Jones at 2020-04-22T23:13:06-04:00 Do eager instantation in terms This patch implements eager instantiation, a small but critical change to the type inference engine, #17173. The main change is this: When inferring types, always return an instantiated type (for now, deeply instantiated; in future shallowly instantiated) There is more discussion in https://www.tweag.io/posts/2020-04-02-lazy-eager-instantiation.html There is quite a bit of refactoring in this patch: * The ir_inst field of GHC.Tc.Utils.TcType.InferResultk has entirely gone. So tcInferInst and tcInferNoInst have collapsed into tcInfer. * Type inference of applications, via tcInferApp and tcInferAppHead, are substantially refactored, preparing the way for Quick Look impredicativity. * New pure function GHC.Tc.Gen.Expr.collectHsArgs and applyHsArgs are beatifully dual. We can see the zipper! * GHC.Tc.Gen.Expr.tcArgs is now much nicer; no longer needs to return a wrapper * In HsExpr, HsTypeApp now contains the the actual type argument, and is used in desugaring, rather than putting it in a mysterious wrapper. * I struggled a bit with good error reporting in Unify.matchActualFunTysPart. It's a little bit simpler than before, but still not great. Some smaller things * Rename tcPolyExpr --> tcCheckExpr tcMonoExpr --> tcLExpr * tcPatSig moves from GHC.Tc.Gen.HsType to GHC.Tc.Gen.Pat Metric Decrease: T9961 Reduction of 1.6% in comiler allocation on T9961, I think. - - - - - 6f84aca3 by Ben Gamari at 2020-04-22T23:13:43-04:00 rts: Ensure that sigaction structs are initialized I noticed these may have uninitialized fields when looking into #18037. The reporter says that zeroing them doesn't fix the MSAN failures they observe but zeroing them is the right thing to do regardless. - - - - - c29f0fa6 by Andreas Klebinger at 2020-04-22T23:14:21-04:00 Add "ddump-cmm-opt" as alias for "ddump-opt-cmm". - - - - - 4b4a8b60 by Ben Gamari at 2020-04-22T23:14:57-04:00 llvmGen: Remove -fast-llvm flag Issue #18076 drew my attention to the undocumented `-fast-llvm` flag for the LLVM code generator introduced in 22733532171330136d87533d523f565f2a4f102f. Speaking to Moritz about this, the motivation for this flag was to avoid potential incompatibilities between LLVM and the assembler/linker toolchain by making LLVM responsible for machine-code generation. Unfortunately, this cannot possibly work: the LLVM backend's mangler performs a number of transforms on the assembler generated by LLVM that are necessary for correctness. These are currently: * mangling Haskell functions' symbol types to be `object` instead of `function` on ELF platforms (necessary for tables-next-to-code) * mangling AVX instructions to ensure that we don't assume alignment (which LLVM otherwise does) * mangling Darwin's subsections-via-symbols directives Given that these are all necessary I don't believe that we can support `-fast-llvm`. Let's rather remove it. - - - - - 831b6642 by Moritz Angermann at 2020-04-22T23:15:33-04:00 Fix build warning; add more informative information to the linker; fix linker for empty sections - - - - - c409961a by Ryan Scott at 2020-04-22T23:16:12-04:00 Update commentary and slightly refactor GHC.Tc.Deriv.Infer There was some out-of-date commentary in `GHC.Tc.Deriv.Infer` that has been modernized. Along the way, I removed the `bad` constraints in `simplifyDeriv`, which did not serve any useful purpose (besides being printed in debugging output). Fixes #18073. - - - - - 125aa2b8 by Ömer Sinan Ağacan at 2020-04-22T23:16:51-04:00 Remove leftover comment in tcRnModule', redundant bind The code for the comment was moved in dc8c03b2a5c but the comment was forgotten. - - - - - 8ea37b01 by Sylvain Henry at 2020-04-22T23:17:34-04:00 RTS: workaround a Linux kernel bug in timerfd Reading a timerfd may return 0: https://lkml.org/lkml/2019/8/16/335. This is currently undocumented behavior and documentation "won't happen anytime soon" (https://lkml.org/lkml/2020/2/13/295). With this patch, we just ignore the result instead of crashing. It may fix #18033 but we can't be sure because we don't have enough information. See also this discussion about the kernel bug: https://github.com/Azure/sonic-swss-common/pull/302/files/1f070e7920c2e5d63316c0105bf4481e73d72dc9 - - - - - cd8409c2 by Ryan Scott at 2020-04-23T11:39:24-04:00 Create di_scoped_tvs for associated data family instances properly See `Note [Associated data family instances and di_scoped_tvs]` in `GHC.Tc.TyCl.Instance`, which explains all of the moving parts. Fixes #18055. - - - - - 339e8ece by Ben Gamari at 2020-04-23T11:40:02-04:00 hadrian/ghci: Allow arguments to be passed to GHCi Previously the arguments passed to hadrian/ghci were passed both to `hadrian` and GHCi. This is rather odd given that there are essentially not arguments in the intersection of the two. Let's just pass them to GHCi; this allows `hadrian/ghci -Werror`. - - - - - 5946c85a by Ben Gamari at 2020-04-23T11:40:38-04:00 testsuite: Don't attempt to read .std{err,out} files if they don't exist Simon reports that he was previously seeing framework failures due to an attempt to read the non-existing T13456.stderr. While I don't know exactly what this is due to, it does seem like a non-existing .std{out,err} file should be equivalent to an empty file. Teach the testsuite driver to treat it as such. - - - - - c42754d5 by John Ericson at 2020-04-23T18:32:43-04:00 Trees That Grow refactor for `ConPat` and `CoPat` - `ConPat{In,Out}` -> `ConPat` - `CoPat` -> `XPat (CoPat ..)` Note that `GHC.HS.*` still uses `HsWrap`, but only when `p ~ GhcTc`. After this change, moving the type family instances out of `GHC.HS.*` is sufficient to break the cycle. Add XCollectPat class to decide how binders are collected from XXPat based on the pass. Previously we did this with IsPass, but that doesn't work for Haddock's DocNameI, and the constraint doesn't express what actual distinction is being made. Perhaps a class for collecting binders more generally is in order, but we haven't attempted this yet. Pure refactor of code around ConPat - InPat/OutPat synonyms removed - rename several identifiers - redundant constraints removed - move extension field in ConPat to be first - make ConPat use record syntax more consistently Fix T6145 (ConPatIn became ConPat) Add comments from SPJ. Add comment about haddock's use of CollectPass. Updates haddock submodule. - - - - - 72da0c29 by mniip at 2020-04-23T18:33:21-04:00 Add :doc to GHC.Prim - - - - - 2c23e2e3 by mniip at 2020-04-23T18:33:21-04:00 Include docs for non-primop entries in primops.txt as well - - - - - 0ac29c88 by mniip at 2020-04-23T18:33:21-04:00 GHC.Prim docs: note and test - - - - - b0fbfc75 by John Ericson at 2020-04-24T12:07:14-04:00 Switch order on `GhcMake.IsBoot` In !1798 we were requested to replace many `Bool`s with this data type. But those bools had `False` meaning `NotBoot`, so the `Ord` instance would be flipped if we use this data-type as-is. Since the planned formally-`Bool` occurrences vastly outnumber the current occurrences, we figured it would be better to conform the `Ord` instance to how the `Bool` is used now, fixing any issues, rather than fix them currently with the bigger refactor later in !1798. That way, !1798 can be a "pure" refactor with no behavioral changes. - - - - - af332442 by Sylvain Henry at 2020-04-26T13:55:14-04:00 Modules: Utils and Data (#13009) Update Haddock submodule Metric Increase: haddock.compiler - - - - - cd4434c8 by Sylvain Henry at 2020-04-26T13:55:16-04:00 Fix misleading Ptr phantom type in SerializedCompact (#15653) - - - - - 22bf5c73 by Ömer Sinan Ağacan at 2020-04-26T13:55:22-04:00 Tweak includes in non-moving GC headers We don't use hash tables in non-moving GC so remove the includes. This breaks Compact.c as existing includes no longer include Hash.h, so include Hash.h explicitly in Compact.c. - - - - - 99823ed2 by Sylvain Henry at 2020-04-27T20:24:46-04:00 TH: fix Show/Eq/Ord instances for Bytes (#16457) We shouldn't compare pointer values but the actual bytes. - - - - - c62271a2 by Alp Mestanogullari at 2020-04-27T20:25:33-04:00 hadrian: always capture both stdout and stderr when running a builder fails The idea being that when a builder('s command) fails, we quite likely want to have all the information available to figure out why. Depending on the builder _and_ the particular problem, the useful bits of information can be printed on stdout or stderr. We accomplish this by defining a simple wrapper for Shake's `cmd` function, that just _always_ captures both streams in case the command returns a non-zero exit code, and by using this wrapper everywhere in `hadrian/src/Builder.hs`. Fixes #18089. - - - - - 4b9764db by Ryan Scott at 2020-04-28T15:40:04-04:00 Define a Quote IO instance Fixes #18103. - - - - - 518a63d4 by Ryan Scott at 2020-04-28T15:40:42-04:00 Make boxed 1-tuples have known keys Unlike other tuples, which use special syntax and are "known" by way of a special `isBuiltInOcc_maybe` code path, boxed 1-tuples do not use special syntax. Therefore, in order to make sure that the internals of GHC are aware of the `data Unit a = Unit a` definition in `GHC.Tuple`, we give `Unit` known keys. For the full details, see `Note [One-tuples] (Wrinkle: Make boxed one-tuple names have known keys)` in `GHC.Builtin.Types`. Fixes #18097. - - - - - 2cfc4ab9 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Document backpack fields in DynFlags - - - - - 10a2ba90 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Refactor UnitInfo * Rename InstalledPackageInfo into GenericUnitInfo The name InstalledPackageInfo is only kept for alleged backward compatibility reason in Cabal. ghc-boot has its own stripped down copy of this datatype but it doesn't need to keep the name. Internally we already use type aliases (UnitInfo in GHC, PackageCacheFormat in ghc-pkg). * Rename UnitInfo fields: add "unit" prefix and fix misleading names * Add comments on every UnitInfo field * Rename SourcePackageId into PackageId "Package" already indicates that it's a "source package". Installed package components are called units. Update Haddock submodule - - - - - 69562e34 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Remove unused `emptyGenericUnitInfo` - - - - - 9e2c8e0e by Sylvain Henry at 2020-04-30T01:56:56-04:00 Refactor UnitInfo load/store from databases Converting between UnitInfo stored in package databases and UnitInfo as they are used in ghc-pkg and ghc was done in a very convoluted way (via BinaryStringRep and DbUnitModuleRep type classes using fun deps, etc.). It was difficult to understand and even more to modify (I wanted to try to use a GADT for UnitId but fun deps got in the way). The new code uses much more straightforward functions to convert between the different representations. Much simpler. - - - - - ea717aa4 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Factorize mungePackagePaths code This patch factorizes the duplicated code used in ghc-pkg and in GHC to munge package paths/urls. It also fixes haddock-html munging in GHC (allowed to be either a file or a url) to mimic ghc-pkg behavior. - - - - - 10d15f1e by Sylvain Henry at 2020-04-30T01:56:56-04:00 Refactoring unit management code Over the years the unit management code has been modified a lot to keep up with changes in Cabal (e.g. support for several library components in the same package), to integrate BackPack, etc. I found it very hard to understand as the terminology wasn't consistent, was referring to past concepts, etc. The terminology is now explained as clearly as I could in the Note "About Units" and the code is refactored to reflect it. ------------------- Many names were misleading: UnitId is not an Id but could be a virtual unit (an indefinite one instantiated on the fly), IndefUnitId constructor may contain a definite instantiated unit, etc. * Rename IndefUnitId into InstantiatedUnit * Rename IndefModule into InstantiatedModule * Rename UnitId type into Unit * Rename IndefiniteUnitId constructor into VirtUnit * Rename DefiniteUnitId constructor into RealUnit * Rename packageConfigId into mkUnit * Rename getPackageDetails into unsafeGetUnitInfo * Rename InstalledUnitId into UnitId Remove references to misleading ComponentId: a ComponentId is just an indefinite unit-id to be instantiated. * Rename ComponentId into IndefUnitId * Rename ComponentDetails into UnitPprInfo * Fix display of UnitPprInfo with empty version: this is now used for units dynamically generated by BackPack Generalize several types (Module, Unit, etc.) so that they can be used with different unit identifier types: UnitKey, UnitId, Unit, etc. * GenModule: Module, InstantiatedModule and InstalledModule are now instances of this type * Generalize DefUnitId, IndefUnitId, Unit, InstantiatedUnit, PackageDatabase Replace BackPack fake "hole" UnitId by a proper HoleUnit constructor. Add basic support for UnitKey. They should be used more in the future to avoid mixing them up with UnitId as we do now. Add many comments. Update Haddock submodule - - - - - 8bfb0219 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Unit: split and rename modules Introduce GHC.Unit.* hierarchy for everything concerning units, packages and modules. Update Haddock submodule - - - - - 71484b09 by Alexis King at 2020-04-30T01:57:35-04:00 Allow block arguments in arrow control operators Arrow control operators have their own entries in the grammar, so they did not cooperate with BlockArguments. This was just a minor oversight, so this patch adjusts the grammar to add the desired behavior. fixes #18050 - - - - - a48cd2a0 by Alexis King at 2020-04-30T01:57:35-04:00 Allow LambdaCase to be used as a command in proc notation - - - - - f4d3773c by Alexis King at 2020-04-30T01:57:35-04:00 Document BlockArguments/LambdaCase support in arrow notation - - - - - 5bdfdd13 by Simon Peyton Jones at 2020-04-30T01:58:15-04:00 Add tests for #17873 - - - - - 19b701c2 by Simon Peyton Jones at 2020-04-30T07:30:13-04:00 Mark rule args as non-tail-called This was just an omission...b I'd failed to call markAllNonTailCall on rule args. I think this bug has been here a long time, but it's quite hard to trigger. Fixes #18098 - - - - - 014ef4a3 by Matthew Pickering at 2020-04-30T07:30:50-04:00 Hadrian: Improve tool-args command to support more components There is a new command to hadrian, tool:path/to/file.hs, which returns the options needed to compile that file in GHCi. This is now used in the ghci script with argument `ghc/Main.hs` but its main purpose is to support the new multi-component branch of ghcide. - - - - - 2aa67611 by Ben Gamari at 2020-04-30T21:34:44-04:00 nonmoving: Clear bitmap after initializing block size Previously nonmovingInitSegment would clear the bitmap before initializing the segment's block size. This is broken since nonmovingClearBitmap looks at the segment's block size to determine how much bitmap to clear. - - - - - 54dad3cf by Ben Gamari at 2020-04-30T21:34:44-04:00 nonmoving: Explicitly memoize block count A profile cast doubt on whether the compiler hoisted the bound out the loop as I would have expected here. It turns out it did but nevertheless it seems clearer to just do this manually. - - - - - 99ff8145 by Ben Gamari at 2020-04-30T21:34:44-04:00 nonmoving: Eagerly flush all capabilities' update remembered sets (cherry picked from commit 2fa79119570b358a4db61446396889b8260d7957) - - - - - 05b0a9fd by Ömer Sinan Ağacan at 2020-04-30T21:35:24-04:00 Remove OneShotInfo field of LFReEntrant, document OneShotInfo The field is only used in withNewTickyCounterFun and it's easier to directly pass a parameter for one-shot info to withNewTickyCounterFun instead of passing it via LFReEntrant. This also makes !2842 simpler. Other changes: - New Note (by SPJ) [OneShotInfo overview] added. - Arity argument of thunkCode removed as it's always 0. - - - - - a43620c6 by Ömer Sinan Ağacan at 2020-04-30T21:35:24-04:00 GHC.StgToCmm.Ticky: remove a few unused stuff - - - - - 780de9e1 by Sylvain Henry at 2020-05-01T10:37:39-04:00 Use platform in Iface Binary - - - - - f8386c7b by Sylvain Henry at 2020-05-01T10:37:39-04:00 Refactor PprDebug handling If `-dppr-debug` is set, then PprUser and PprDump styles are silently replaced with PprDebug style. This was done in `mkUserStyle` and `mkDumpStyle` smart constructors. As a consequence they needed a DynFlags parameter. Now we keep the original PprUser and PprDump styles until they are used to create an `SDocContext`. I.e. the substitution is only performed in `initSDocContext`. - - - - - b3df9e78 by Sylvain Henry at 2020-05-01T10:37:39-04:00 Remove PprStyle param of logging actions Use `withPprStyle` instead to apply a specific style to a SDoc. - - - - - de9fc995 by Sylvain Henry at 2020-05-01T10:37:39-04:00 Fully remove PprDebug PprDebug was a pain to deal with consistently as it is implied by `-dppr-debug` but it isn't really a PprStyle. We remove it completely and query the appropriate SDoc flag instead (`sdocPprDebug`) via helpers (`getPprDebug` and its friends). - - - - - 8b51fcbd by Sebastian Graf at 2020-05-01T10:38:16-04:00 PmCheck: Only call checkSingle if we would report warnings - - - - - fd7ea0fe by Sebastian Graf at 2020-05-01T10:38:16-04:00 PmCheck: Pick up `EvVar`s bound in `HsWrapper`s for long-distance info `HsWrapper`s introduce evidence bindings through `WpEvLam` which the pattern-match coverage checker should be made aware of. Failing to do so caused #18049, where the resulting impreciseness of imcompleteness warnings seemingly contradicted with `-Winaccessible-code`. The solution is simple: Collect all the evidence binders of an `HsWrapper` and add it to the ambient `Deltas` before desugaring the wrapped expression. But that means we pick up many more evidence bindings, even when they wrap around code without a single pattern match to check! That regressed `T3064` by over 300%, so now we are adding long-distance info lazily through judicious use of `unsafeInterleaveIO`. Fixes #18049. - - - - - 7bfe9ac5 by Ben Gamari at 2020-05-03T04:41:33-04:00 rts: Enable tracing of nonmoving heap census with -ln Previously this was not easily available to the user. Fix this. Non-moving collection lifecycle events are now reported with -lg. - - - - - c560dd07 by Ben Gamari at 2020-05-03T04:41:33-04:00 users guide: Move eventlog documentation users guide - - - - - 02543d5e by Ben Gamari at 2020-05-03T04:41:33-04:00 users guide: Add documentation for non-moving GC events - - - - - b465dd45 by Alexis King at 2020-05-03T04:42:12-04:00 Flatten nested casts in the simple optimizer Normally, we aren’t supposed to generated any nested casts, since mkCast takes care to flatten them, but the simple optimizer didn’t use mkCast, so they could show up after inlining. This isn’t really a problem, since the simplifier will clean them up immediately anyway, but it can clutter the -ddump-ds output, and it’s an extremely easy fix. closes #18112 - - - - - 8bdc03d6 by Simon Peyton Jones at 2020-05-04T01:56:59-04:00 Don't return a panic in tcNestedSplice In GHC.Tc.Gen.Splice.tcNestedSplice we were returning a typechecked expression of "panic". That is usually OK, because the result is discarded. But it happens that tcApp now looks at the typechecked expression, trivially, to ask if it is tagToEnum. So being bottom is bad. Moreover a debug-trace might print it out. So better to return a civilised expression, even though it is usually discarded. - - - - - 0bf640b1 by Baldur Blöndal at 2020-05-04T01:57:36-04:00 Don't require parentheses around via type (`-XDerivingVia'). Fixes #18130". - - - - - 30272412 by Artem Pelenitsyn at 2020-05-04T13:19:59-04:00 Remove custom ExceptionMonad class (#18075) (updating haddock submodule accordingly) - - - - - b9f7c08f by jneira at 2020-05-04T13:20:37-04:00 Remove unused hs-boot file - - - - - 1d8f80cd by Sylvain Henry at 2020-05-05T03:22:46-04:00 Remove references to -package-key * remove references to `-package-key` which has been removed in 2016 (240ddd7c39536776e955e881d709bbb039b48513) * remove support for `-this-package-key` which has been deprecated at the same time - - - - - 7bc3a65b by Sylvain Henry at 2020-05-05T03:23:31-04:00 Remove SpecConstrAnnotation (#13681) This has been deprecated since 2013. Use GHC.Types.SPEC instead. Make GHC.Exts "not-home" for haddock Metric Decrease: haddock.base - - - - - 3c862f63 by DenisFrezzato at 2020-05-05T03:24:15-04:00 Fix Haskell98 short description in documentation - - - - - 2420c555 by Ryan Scott at 2020-05-05T03:24:53-04:00 Add regression tests for #16244, #16245, #16758 Commit e3c374cc5bd7eb49649b9f507f9f7740697e3f70 ended up fixing quite a few bugs: * This commit fixes #16244 completely. A regression test has been added. * This commit fixes one program from #16245. (The program in https://gitlab.haskell.org/ghc/ghc/issues/16245#note_211369 still panics, and the program in https://gitlab.haskell.org/ghc/ghc/issues/16245#note_211400 still loops infinitely.) A regression test has been added for this program. * This commit fixes #16758. Accordingly, this patch removes the `expect_broken` label from the `T16758` test case, moves it from `should_compile` to `should_fail` (as it should produce an error message), and checks in the expected stderr. - - - - - 40c71c2c by Sylvain Henry at 2020-05-05T03:25:31-04:00 Fix colorized error messages (#18128) In b3df9e780fb2f5658412c644849cd0f1e6f50331 I broke colorized messages by using "dump" style instead of "user" style. This commits fixes it. - - - - - 7ab6ab09 by Richard Eisenberg at 2020-05-06T04:39:32-04:00 Refactor hole constraints. Previously, holes (both expression holes / out of scope variables and partial-type-signature wildcards) were emitted as *constraints* via the CHoleCan constructor. While this worked fine for error reporting, there was a fair amount of faff in keeping these constraints in line. In particular, and unlike other constraints, we could never change a CHoleCan to become CNonCanonical. In addition: * the "predicate" of a CHoleCan constraint was really the type of the hole, which is not a predicate at all * type-level holes (partial type signature wildcards) carried evidence, which was never used * tcNormalise (used in the pattern-match checker) had to create a hole constraint just to extract it again; it was quite messy The new approach is to record holes directly in WantedConstraints. It flows much more nicely now. Along the way, I did some cleaning up of commentary in GHC.Tc.Errors.Hole, which I had a hard time understanding. This was instigated by a future patch that will refactor the way predicates are handled. The fact that CHoleCan's "predicate" wasn't really a predicate is incompatible with that future patch. No test case, because this is meant to be purely internal. It turns out that this change improves the performance of the pattern-match checker, likely because fewer constraints are sloshing about in tcNormalise. I have not investigated deeply, but an improvement is not a surprise here: ------------------------- Metric Decrease: PmSeriesG ------------------------- - - - - - 420b957d by Ben Gamari at 2020-05-06T04:40:08-04:00 rts: Zero block flags with -DZ Block flags are very useful for determining the state of a block. However, some block allocator users don't touch them, leading to misleading values. Ensure that we zero then when zero-on-gc is set. This is safe and makes the flags more useful during debugging. - - - - - 740b3b8d by Ben Gamari at 2020-05-06T04:40:08-04:00 nonmoving: Fix incorrect failed_to_evac value during deadlock gc Previously we would incorrectly set the failed_to_evac flag if we evacuated a value due to a deadlock GC. This would cause us to mark more things as dirty than strictly necessary. It also turned up a nasty but which I will fix next. - - - - - b2d72c75 by Ben Gamari at 2020-05-06T04:40:08-04:00 nonmoving: Fix handling of dirty objects Previously we (incorrectly) relied on failed_to_evac to be "precise". That is, we expected it to only be true if *all* of an object's fields lived outside of the non-moving heap. However, does not match the behavior of failed_to_evac, which is true if *any* of the object's fields weren't promoted (meaning that some others *may* live in the non-moving heap). This is problematic as we skip the non-moving write barrier for dirty objects (which we can only safely do if *all* fields point outside of the non-moving heap). Clearly this arises due to a fundamental difference in the behavior expected of failed_to_evac in the moving and non-moving collector. e.g., in the moving collector it is always safe to conservatively say failed_to_evac=true whereas in the non-moving collector the safe value is false. This issue went unnoticed as I never wrote down the dirtiness invariant enforced by the non-moving collector. We now define this invariant as An object being marked as dirty implies that all of its fields are on the mark queue (or, equivalently, update remembered set). To maintain this invariant we teach nonmovingScavengeOne to push the fields of objects which we fail to evacuate to the update remembered set. This is a simple and reasonably cheap solution and avoids the complexity and fragility that other, more strict alternative invariants would require. All of this is described in a new Note, Note [Dirty flags in the non-moving collector] in NonMoving.c. - - - - - 9f3e6884 by Zubin Duggal at 2020-05-06T04:41:08-04:00 Allow atomic update of NameCache in readHieFile The situation arises in ghcide where multiple different threads may need to update the name cache, therefore with the older interface it could happen that you start reading a hie file with name cache A and produce name cache A + B, but another thread in the meantime updated the namecache to A + C. Therefore if you write the new namecache you will lose the A' updates from the second thread. Updates haddock submodule - - - - - edec6a6c by Ryan Scott at 2020-05-06T04:41:57-04:00 Make isTauTy detect higher-rank contexts Previously, `isTauTy` would only detect higher-rank `forall`s, not higher-rank contexts, which led to some minor bugs observed in #18127. Easily fixed by adding a case for `(FunTy InvisArg _ _)`. Fixes #18127. - - - - - a95e7fe0 by Ömer Sinan Ağacan at 2020-05-06T04:42:39-04:00 ELF linker: increment curSymbol after filling in fields of current entry The bug was introduced in a8b7cef4d45 which added a field to the `symbols` array elements and then updated this code incorrectly: - oc->symbols[curSymbol++] = nm; + oc->symbols[curSymbol++].name = nm; + oc->symbols[curSymbol].addr = symbol->addr; - - - - - cab1871a by Sylvain Henry at 2020-05-06T04:43:21-04:00 Move LeadingUnderscore into Platform (#17957) Avoid direct use of DynFlags to know if symbols must be prefixed by an underscore. - - - - - 94e7c563 by Sylvain Henry at 2020-05-06T04:43:21-04:00 Don't use DynFlags in showLinkerState (#17957) - - - - - 9afd9251 by Ryan Scott at 2020-05-06T04:43:58-04:00 Refactoring: Use bindSigTyVarsFV in rnMethodBinds `rnMethodBinds` was explicitly using `xoptM` to determine if `ScopedTypeVariables` is enabled before bringing type variables bound by the class/instance header into scope. However, this `xoptM` logic is already performed by the `bindSigTyVarsFV` function. This patch uses `bindSigTyVarsFV` in `rnMethodBinds` to reduce the number of places where we need to consult if `ScopedTypeVariables` is on. This is purely refactoring, and there should be no user-visible change in behavior. - - - - - 6f6d72b2 by Brian Foley at 2020-05-08T15:29:25-04:00 Remove further dead code found by a simple Python script. Avoid removing some functions that are part of an API even though they're not used in-tree at the moment. - - - - - 78bf8bf9 by Julien Debon at 2020-05-08T15:29:28-04:00 Add doc examples for Bifoldable See #17929 - - - - - 66f0a847 by Julien Debon at 2020-05-08T15:29:29-04:00 doc (Bitraversable): Add examples to Bitraversable * Add examples to Data.Bitraversable * Fix formatting for (,) in Bitraversable and Bifoldable * Fix mistake on bimapAccumR documentation See #17929 - - - - - 9749fe12 by Baldur Blöndal at 2020-05-08T15:29:32-04:00 Specify kind variables for inferred kinds in base. - - - - - 4e9aef9e by John Ericson at 2020-05-08T15:29:36-04:00 HsSigWcTypeScoping: Pull in documentation from stray location - - - - - f4d5c6df by John Ericson at 2020-05-08T15:29:36-04:00 Rename local `real_fvs` to `implicit_vs` It doesn't make sense to call the "free" variables we are about to implicitly bind the real ones. - - - - - 20570b4b by John Ericson at 2020-05-08T15:29:36-04:00 A few tiny style nits with renaming - Use case rather than guards that repeatedly scrutenize same thing. - No need for view pattern when `L` is fine. - Use type synnonym to convey the intent like elsewhere. - - - - - 09ac8de5 by John Ericson at 2020-05-08T15:29:36-04:00 Add `forAllOrNothing` function with note - - - - - bb35c0e5 by Joseph C. Sible at 2020-05-08T15:29:40-04:00 Document lawlessness of Ap's Num instance - - - - - cdd229ff by Joseph C. Sible at 2020-05-08T15:29:40-04:00 Apply suggestion to libraries/base/Data/Monoid.hs - - - - - 926d2aab by Joseph C. Sible at 2020-05-08T15:29:40-04:00 Apply more suggestions from Simon Jakobi - - - - - 7a763cff by Adam Gundry at 2020-05-08T15:29:41-04:00 Reject all duplicate declarations involving DuplicateRecordFields (fixes #17965) This fixes a bug that resulted in some programs being accepted that used the same identifier as a field label and another declaration, depending on the order they appeared in the source code. - - - - - 88e3c815 by Simon Peyton Jones at 2020-05-08T15:29:41-04:00 Fix specialisation for DFuns When specialising a DFun we must take care to saturate the unfolding. See Note [Specialising DFuns] in Specialise. Fixes #18120 - - - - - 86c77b36 by Greg Steuck at 2020-05-08T15:29:45-04:00 Remove unused SEGMENT_PROT_RWX It's been unused for a year and is problematic on any OS which requires W^X for security. - - - - - 9d97f4b5 by nineonine at 2020-05-08T15:30:03-04:00 Add test for #16167 - - - - - aa318338 by Ryan Scott at 2020-05-08T15:30:04-04:00 Bump exceptions submodule so that dist-boot is .gitignore'd `exceptions` is a stage-0 boot library as of commit 30272412fa437ab8e7a8035db94a278e10513413, which means that building `exceptions` in a GHC tree will generate a `dist-boot` directory. However, this directory was not specified in `exceptions`' `.gitignore` file, which causes it to dirty up the current `git` working directory. Accordingly, this bumps the `exceptions` submodule to commit ghc/packages/exceptions at 23c0b8a50d7592af37ca09beeec16b93080df98f, which adds `dist-boot` to the `.gitignore` file. - - - - - ea86360f by Ömer Sinan Ağacan at 2020-05-08T15:30:30-04:00 Linker.c: initialize n_symbols of ObjectCode with other fields - - - - - 951c1fb0 by Sylvain Henry at 2020-05-09T21:46:38-04:00 Fix unboxed-sums GC ptr-slot rubbish value (#17791) This patch allows boot libraries to use unboxed sums without implicitly depending on `base` package because of `absentSumFieldError`. See updated Note [aBSENT_SUM_FIELD_ERROR_ID] in GHC.Core.Make - - - - - b352d63c by Ben Gamari at 2020-05-09T21:47:14-04:00 rts: Make non-existent linker search path merely a warning As noted in #18105, previously this resulted in a rather intrusive error message. This is in contrast to the general expectation that search paths are merely places to look, not places that must exist. Fixes #18105. - - - - - cf4f1e2f by Ben Gamari at 2020-05-13T02:02:33-04:00 rts/CNF: Fix fixup comparison function Previously we would implicitly convert the difference between two words to an int, resulting in an integer overflow on 64-bit machines. Fixes #16992 - - - - - a03da9bf by Ömer Sinan Ağacan at 2020-05-13T02:03:16-04:00 Pack some of IdInfo fields into a bit field This reduces residency of compiler quite a bit on some programs. Example stats when building T10370: Before: 2,871,242,832 bytes allocated in the heap 4,693,328,008 bytes copied during GC 33,941,448 bytes maximum residency (276 sample(s)) 375,976 bytes maximum slop 83 MiB total memory in use (0 MB lost due to fragmentation) After: 2,858,897,344 bytes allocated in the heap 4,629,255,440 bytes copied during GC 32,616,624 bytes maximum residency (278 sample(s)) 314,400 bytes maximum slop 80 MiB total memory in use (0 MB lost due to fragmentation) So -3.9% residency, -1.3% bytes copied and -0.4% allocations. Fixes #17497 Metric Decrease: T9233 T9675 - - - - - 670c3e5c by Ben Gamari at 2020-05-13T02:03:54-04:00 get-win32-tarballs: Fix base URL Revert a change previously made for testing purposes. - - - - - 8ad8dc41 by Ben Gamari at 2020-05-13T02:03:54-04:00 get-win32-tarballs: Improve diagnostics output - - - - - 8c0740b7 by Simon Jakobi at 2020-05-13T02:04:33-04:00 docs: Add examples for Data.Semigroup.Arg{Min,Max} Context: #17153 - - - - - cb22348f by Ben Gamari at 2020-05-13T02:05:11-04:00 Add few cleanups of the CAF logic Give the NameSet of non-CAFfy names a proper newtype to distinguish it from all of the other NameSets floating about. - - - - - 90e38b81 by Emeka Nkurumeh at 2020-05-13T02:05:51-04:00 fix printf warning when using with ghc with clang on mingw - - - - - 86d8ac22 by Sebastian Graf at 2020-05-13T02:06:29-04:00 CprAnal: Don't attach CPR sigs to expandable bindings (#18154) Instead, look through expandable unfoldings in `cprTransform`. See the new Note [CPR for expandable unfoldings]: ``` Long static data structures (whether top-level or not) like xs = x1 : xs1 xs1 = x2 : xs2 xs2 = x3 : xs3 should not get CPR signatures, because they * Never get WW'd, so their CPR signature should be irrelevant after analysis (in fact the signature might even be harmful for that reason) * Would need to be inlined/expanded to see their constructed product * Recording CPR on them blows up interface file sizes and is redundant with their unfolding. In case of Nested CPR, this blow-up can be quadratic! But we can't just stop giving DataCon application bindings the CPR property, for example fac 0 = 1 fac n = n * fac (n-1) fac certainly has the CPR property and should be WW'd! But FloatOut will transform the first clause to lvl = 1 fac 0 = lvl If lvl doesn't have the CPR property, fac won't either. But lvl doesn't have a CPR signature to extrapolate into a CPR transformer ('cprTransform'). So instead we keep on cprAnal'ing through *expandable* unfoldings for these arity 0 bindings via 'cprExpandUnfolding_maybe'. In practice, GHC generates a lot of (nested) TyCon and KindRep bindings, one for each data declaration. It's wasteful to attach CPR signatures to each of them (and intractable in case of Nested CPR). ``` Fixes #18154. - - - - - e34bf656 by Ben Gamari at 2020-05-13T02:07:08-04:00 users-guide: Add discussion of shared object naming Fixes #18074. - - - - - 5d0f2445 by Ben Gamari at 2020-05-13T02:07:47-04:00 testsuite: Print sign of performance changes Executes the minor formatting change in the tabulated performance changes suggested in #18135. - - - - - 9e4b981f by Ben Gamari at 2020-05-13T02:08:24-04:00 testsuite: Add testcase for #18129 - - - - - 266310c3 by Ivan-Yudin at 2020-05-13T02:09:03-04:00 doc: Reformulate the opening paragraph of Ch. 4 in User's guide Removes mentioning of Hugs (it is not helpful for new users anymore). Changes the wording for the rest of the paragraph. Fixes #18132. - - - - - 55e35c0b by Baldur Blöndal at 2020-05-13T20:02:48-04:00 Predicate, Equivalence derive via `.. -> a -> All' - - - - - d7e0b57f by Alp Mestanogullari at 2020-05-13T20:03:30-04:00 hadrian: add a --freeze2 option to freeze stage 1 and 2 - - - - - d880d6b2 by Artem Pelenitsyn at 2020-05-13T20:04:11-04:00 Don't reload environment files on every setSessionDynFlags Makes `interpretPackageEnv` (which loads envirinment files) a part of `parseDynamicFlags` (parsing command-line arguments, which is typically done once) instead of `setSessionDynFlags` (which is typically called several times). Making several (transitive) calls to `interpretPackageEnv`, as before, caused #18125 #16318, which should be fixed now. - - - - - 102cfd67 by Ryan Scott at 2020-05-13T20:04:46-04:00 Factor out HsPatSigType for pat sigs/RULE term sigs (#16762) This implements chunks (2) and (3) of https://gitlab.haskell.org/ghc/ghc/issues/16762#note_270170. Namely, it introduces a dedicated `HsPatSigType` AST type, which represents the types that can appear in pattern signatures and term-level `RULE` binders. Previously, these were represented with `LHsSigWcType`. Although `LHsSigWcType` is isomorphic to `HsPatSigType`, the intended semantics of the two types are slightly different, as evidenced by the fact that they have different code paths in the renamer and typechecker. See also the new `Note [Pattern signature binders and scoping]` in `GHC.Hs.Types`. - - - - - b17574f7 by Hécate at 2020-05-13T20:05:28-04:00 fix(documentation): Fix the RST links to GHC.Prim - - - - - df021fb1 by Baldur Blöndal at 2020-05-13T20:06:06-04:00 Document (->) using inferred quantification for its runtime representations. Fixes #18142. - - - - - 1a93ea57 by Takenobu Tani at 2020-05-13T20:06:54-04:00 Tweak man page for ghc command This commit updates the ghc command's man page as followings: * Enable `man_show_urls` to show URL addresses in the `DESCRIPTION` section of ghc.rst, because sphinx currently removes hyperlinks for man pages. * Add a `SEE ALSO` section to point to the GHC homepage - - - - - a951e1ba by Takenobu Tani at 2020-05-13T20:07:37-04:00 GHCi: Add link to the user's guide in help message This commit adds a link to the user's guide in ghci's `:help` message. Newcomers could easily reach to details of ghci. - - - - - 404581ea by Jeff Happily at 2020-05-13T20:08:15-04:00 Handle single unused import - - - - - 1c999e5d by Ben Gamari at 2020-05-13T20:09:07-04:00 Ensure that printMinimalImports closes handle Fixes #18166. - - - - - c9f5a8f4 by Ben Gamari at 2020-05-13T20:09:51-04:00 hadrian: Tell testsuite driver about LLVM availability This reflects the logic present in the Make build system into Hadrian. Fixes #18167. - - - - - c05c0659 by Simon Jakobi at 2020-05-14T03:31:21-04:00 Improve some folds over Uniq[D]FM * Replace some non-deterministic lazy folds with strict folds. * Replace some O(n log n) folds in deterministic order with O(n) non-deterministic folds. * Replace some folds with set-operations on the underlying IntMaps. This reduces max residency when compiling `nofib/spectral/simple/Main.hs` with -O0 by about 1%. Maximum residency when compiling Cabal also seems reduced on the order of 3-9%. - - - - - 477f13bb by Simon Jakobi at 2020-05-14T03:31:58-04:00 Use Data.IntMap.disjoint Data.IntMap gained a dedicated `disjoint` function in containers-0.6.2.1. This patch applies this function where appropriate in hopes of modest compiler performance improvements. Closes #16806. - - - - - e9c0110c by Ben Gamari at 2020-05-14T12:25:53-04:00 IdInfo: Add reference to bitfield-packing ticket - - - - - 9bd20e83 by Sebastian Graf at 2020-05-15T10:42:09-04:00 DmdAnal: Improve handling of precise exceptions This patch does two things: Fix possible unsoundness in what was called the "IO hack" and implement part 2.1 of the "fixing precise exceptions" plan in https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions, which, in combination with !2956, supersedes !3014 and !2525. **IO hack** The "IO hack" (which is a fallback to preserve precise exceptions semantics and thus soundness, rather than some smart thing that increases precision) is called `exprMayThrowPreciseException` now. I came up with two testcases exemplifying possible unsoundness (if twisted enough) in the old approach: - `T13380d`: Demonstrating unsoundness of the "IO hack" when resorting to manual state token threading and direct use of primops. More details below. - `T13380e`: Demonstrating unsoundness of the "IO hack" when we have Nested CPR. Not currently relevant, as we don't have Nested CPR yet. - `T13380f`: Demonstrating unsoundness of the "IO hack" for safe FFI calls. Basically, the IO hack assumed that precise exceptions can only be thrown from a case scrutinee of type `(# State# RealWorld, _ #)`. I couldn't come up with a program using the `IO` abstraction that violates this assumption. But it's easy to do so via manual state token threading and direct use of primops, see `T13380d`. Also similar code might be generated by Nested CPR in the (hopefully not too) distant future, see `T13380e`. Hence, we now have a more careful test in `forcesRealWorld` that passes `T13380{d,e}` (and will hopefully be robust to Nested CPR). **Precise exceptions** In #13380 and #17676 we saw that we didn't preserve precise exception semantics in demand analysis. We fixed that with minimal changes in !2956, but that was terribly unprincipled. That unprincipledness resulted in a loss of precision, which is tracked by these new test cases: - `T13380b`: Regression in dead code elimination, because !2956 was too syntactic about `raiseIO#` - `T13380c`: No need to apply the "IO hack" when the IO action may not throw a precise exception (and the existing IO hack doesn't detect that) Fixing both issues in !3014 turned out to be too complicated and had the potential to regress in the future. Hence we decided to only fix `T13380b` and augment the `Divergence` lattice with a new middle-layer element, `ExnOrDiv`, which means either `Diverges` (, throws an imprecise exception) or throws a *precise* exception. See the wiki page on Step 2.1 for more implementational details: https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions#dead-code-elimination-for-raiseio-with-isdeadenddiv-introducing-exnordiv-step-21 - - - - - 568d7279 by Ben Gamari at 2020-05-15T10:42:46-04:00 GHC.Cmm.Opt: Handle MO_XX_Conv This MachOp was introduced by 2c959a1894311e59cd2fd469c1967491c1e488f3 but a wildcard match in cmmMachOpFoldM hid the fact that it wasn't handled. Ideally we would eliminate the match but this appears to be a larger task. Fixes #18141. - - - - - 5bcf8606 by Ryan Scott at 2020-05-17T08:46:38-04:00 Remove duplicate Note [When to print foralls] in GHC.Core.TyCo.Ppr There are two different Notes named `[When to print foralls]`. The most up-to-date one is in `GHC.Iface.Type`, but there is a second one in `GHC.Core.TyCo.Ppr`. The latter is less up-to-date, as it was written before GHC switched over to using ifaces to pretty-print types. I decided to just remove the latter and replace it with a reference to the former. [ci skip] - - - - - 55f0e783 by Fumiaki Kinoshita at 2020-05-21T12:10:44-04:00 base: Add Generic instances to various datatypes under GHC.* * GHC.Fingerprint.Types: Fingerprint * GHC.RTS.Flags: GiveGCStats, GCFlags, ConcFlags, DebugFlags, CCFlags, DoHeapProfile, ProfFlags, DoTrace, TraceFlags, TickyFlags, ParFlags and RTSFlags * GHC.Stats: RTSStats and GCStats * GHC.ByteOrder: ByteOrder * GHC.Unicode: GeneralCategory * GHC.Stack.Types: SrcLoc Metric Increase: haddock.base - - - - - a9311cd5 by Gert-Jan Bottu at 2020-05-21T12:11:31-04:00 Explicit Specificity Implementation for Ticket #16393. Explicit specificity allows users to manually create inferred type variables, by marking them with braces. This way, the user determines which variables can be instantiated through visible type application. The additional syntax is included in the parser, allowing users to write braces in type variable binders (type signatures, data constructors etc). This information is passed along through the renamer and verified in the type checker. The AST for type variable binders, data constructors, pattern synonyms, partial signatures and Template Haskell has been updated to include the specificity of type variables. Minor notes: - Bumps haddock submodule - Disables pattern match checking in GHC.Iface.Type with GHC 8.8 - - - - - 24e61aad by Ben Price at 2020-05-21T12:12:17-04:00 Lint should say when it is checking a rule It is rather confusing that when lint finds an error in a rule attached to a binder, it reports the error as in the RHS, not the rule: ... In the RHS of foo We add a clarifying line: ... In the RHS of foo In a rule attached to foo The implication that the rule lives inside the RHS is a bit odd, but this niggle is already present for unfoldings, whose pattern we are following. - - - - - 78c6523c by Ben Gamari at 2020-05-21T12:13:01-04:00 nonmoving: Optimise the write barrier - - - - - 13f6c9d0 by Andreas Klebinger at 2020-05-21T12:13:45-04:00 Refactor linear reg alloc to remember past assignments. When assigning registers we now first try registers we assigned to in the past, instead of picking the "first" one. This is in extremely helpful when dealing with loops for which variables are dead for part of the loop. This is important for patterns like this: foo = arg1 loop: use(foo) ... foo = getVal() goto loop; There we: * assign foo to the register of arg1. * use foo, it's dead after this use as it's overwritten after. * do other things. * look for a register to put foo in. If we pick an arbitrary one it might differ from the register the start of the loop expect's foo to be in. To fix this we simply look for past register assignments for the given variable. If we find one and the register is free we use that register. This reduces the need for fixup blocks which match the register assignment between blocks. In the example above between the end and the head of the loop. This patch also moves branch weight estimation ahead of register allocation and adds a flag to control it (cmm-static-pred). * It means the linear allocator is more likely to assign the hotter code paths first. * If it assign these first we are: + Less likely to spill on the hot path. + Less likely to introduce fixup blocks on the hot path. These two measure combined are surprisingly effective. Based on nofib we get in the mean: * -0.9% instructions executed * -0.1% reads/writes * -0.2% code size. * -0.1% compiler allocations. * -0.9% compile time. * -0.8% runtime. Most of the benefits are simply a result of removing redundant moves and spills. Reduced compiler allocations likely are the result of less code being generated. (The added lookup is mostly non-allocating). - - - - - edc2cc58 by Andreas Klebinger at 2020-05-21T12:14:25-04:00 NCG: Codelayout: Distinguish conditional and other branches. In #18053 we ended up with a suboptimal code layout because the code layout algorithm didn't distinguish between conditional and unconditional control flow. We can completely eliminate unconditional control flow instructions by placing blocks next to each other, not so much for conditionals. In terms of implementation we simply give conditional branches less weight before computing the layout. Fixes #18053 - - - - - b7a6b2f4 by Gleb Popov at 2020-05-21T12:15:26-04:00 gitlab-ci: Set locale to C.UTF-8. - - - - - a8c27cf6 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Allow spaces in GHCi :script file names This patch updates the user interface of GHCi so that file names passed to the ':script' command may contain spaces escaped with a backslash. For example: :script foo\ bar.script The implementation uses a modified version of 'words' that does not break on escaped spaces. Fixes #18027. - - - - - 82663959 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Add extra tests for GHCi :script syntax checks The syntax for GHCi's ":script" command allows for only a single file name to be passed as an argument. This patch adds a test for the cases in which a file name is missing or multiple file names are passed. Related to #T18027. - - - - - a0b79e1b by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Allow GHCi :script file names in double quotes This patch updates the user interface of GHCi so that file names passed to the ':script' command can be wrapped in double quotes. For example: :script "foo bar.script" The implementation uses a modified version of 'words' that treats character sequences enclosed in double quotes as single words. Fixes #18027. - - - - - cf566330 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Update documentation for GHCi :script This patch adds the fixes that allow for file names containing spaces to be passed to GHCi's ':script' command to the release notes for 8.12 and expands the user-guide documentation for ':script' by mentioning how such file names can be passed. Related to #18027. - - - - - 0004ccb8 by Tuan Le at 2020-05-21T12:16:46-04:00 llvmGen: Consider Relocatable read-only data as not constantReferences: #18137 - - - - - 964d3ea2 by John Ericson at 2020-05-21T12:17:30-04:00 Use `Checker` for `tc_pat` - - - - - b797aa42 by John Ericson at 2020-05-21T12:17:30-04:00 Use `Checker` for `tc_lpat` and `tc_lpats` - - - - - 5108e84a by John Ericson at 2020-05-21T12:17:30-04:00 More judiciously panic in `ts_pat` - - - - - 510e0451 by John Ericson at 2020-05-21T12:17:30-04:00 Put `PatEnv` first in `GHC.Tc.Gen.Pat.Checker` - - - - - cb4231db by John Ericson at 2020-05-21T12:17:30-04:00 Tiny cleaup eta-reduce away a function argument In GHC, not in the code being compiled! - - - - - 6890c38d by John Ericson at 2020-05-21T12:17:30-04:00 Use braces with do in `SplicePat` case for consistency - - - - - 3451584f by buggymcbugfix at 2020-05-21T12:18:06-04:00 Fix spelling mistakes and typos - - - - - b552e531 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Add INLINABLE pragmas to Enum list producers The INLINABLE pragmas ensure that we export stable (unoptimised) unfoldings in the interface file so we can do list fusion at usage sites. Related tickets: #15185, #8763, #18178. - - - - - e7480063 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Piggyback on Enum Word methods for Word64 If we are on a 64 bit platform, we can use the efficient Enum Word methods for the Enum Word64 instance. - - - - - 892b0c41 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Document INLINE(ABLE) pragmas that enable fusion - - - - - 2b363ebb by Richard Eisenberg at 2020-05-21T12:18:45-04:00 MR template should ask for key part - - - - - a95bbd0b by Sebastian Graf at 2020-05-21T12:19:37-04:00 Make `Int`'s `mod` and `rem` strict in their first arguments They used to be strict until 4d2ac2d (9 years ago). It's obviously better to be strict for performance reasons. It also blocks #18067. NoFib results: ``` -------------------------------------------------------------------------------- Program Allocs Instrs -------------------------------------------------------------------------------- integer -1.1% +0.4% wheel-sieve2 +21.2% +20.7% -------------------------------------------------------------------------------- Min -1.1% -0.0% Max +21.2% +20.7% Geometric Mean +0.2% +0.2% ``` The regression in `wheel-sieve2` is due to reboxing that likely will go away with the resolution of #18067. See !3282 for details. Fixes #18187. - - - - - d3d055b8 by Galen Huntington at 2020-05-21T12:20:18-04:00 Clarify pitfalls of NegativeLiterals; see #18022. - - - - - 1b508a9e by Alexey Kuleshevich at 2020-05-21T12:21:02-04:00 Fix wording in primops documentation to reflect the correct reasoning: * Besides resizing functions, shrinking ones also mutate the size of a mutable array and because of those two `sizeofMutabeByteArray` and `sizeofSmallMutableArray` are now deprecated * Change reference in documentation to the newer functions `getSizeof*` instead of `sizeof*` for shrinking functions * Fix incorrect mention of "byte" instead of "small" - - - - - 4ca0c8a1 by Andreas Klebinger at 2020-05-21T12:21:53-04:00 Don't variable-length encode magic iface constant. We changed to use variable length encodings for many types by default, including Word32. This makes sense for numbers but not when Word32 is meant to represent four bytes. I added a FixedLengthEncoding newtype to Binary who's instances interpret their argument as a collection of bytes instead of a number. We then use this when writing/reading magic numbers to the iface file. I also took the libery to remove the dummy iface field. This fixes #18180. - - - - - a1275081 by Krzysztof Gogolewski at 2020-05-21T12:22:35-04:00 Add a regression test for #11506 The testcase works now. See explanation in https://gitlab.haskell.org/ghc/ghc/issues/11506#note_273202 - - - - - 8a816e5f by Krzysztof Gogolewski at 2020-05-21T12:23:55-04:00 Sort deterministically metric output Previously, we sorted according to the test name and way, but the metrics (max_bytes_used/peak_megabytes_allocated etc.) were appearing in nondeterministic order. - - - - - 566cc73f by Sylvain Henry at 2020-05-21T12:24:45-04:00 Move isDynLinkName into GHC.Types.Name It doesn't belong into GHC.Unit.State - - - - - d830bbc9 by Adam Sandberg Ericsson at 2020-05-23T13:36:20-04:00 docs: fix formatting and add some links [skip ci] - - - - - 49301ad6 by Andrew Martin at 2020-05-23T13:37:01-04:00 Implement cstringLength# and FinalPtr This function and its accompanying rule resolve issue #5218. A future PR to the bytestring library will make the internal Data.ByteString.Internal.unsafePackAddress compute string length with cstringLength#. This will improve the status quo because it is eligible for constant folding. Additionally, introduce a new data constructor to ForeignPtrContents named FinalPtr. This additional data constructor, when used in the IsString instance for ByteString, leads to more Core-to-Core optimization opportunities, fewer runtime allocations, and smaller binaries. Also, this commit re-exports all the functions from GHC.CString (including cstringLength#) in GHC.Exts. It also adds a new test driver. This test driver is used to perform substring matches on Core that is dumped after all the simplifier passes. In this commit, it is used to check that constant folding of cstringLength# works. - - - - - dcd6bdcc by Ben Gamari at 2020-05-23T13:37:48-04:00 simplCore: Ignore ticks in rule templates This fixes #17619, where a tick snuck in to the template of a rule, resulting in a panic during rule matching. The tick in question was introduced via post-inlining, as discussed in `Note [Simplifying rules]`. The solution we decided upon was to simply ignore ticks in the rule template, as discussed in `Note [Tick annotations in RULE matching]`. Fixes #18162. Fixes #17619. - - - - - 82cb8913 by John Ericson at 2020-05-23T13:38:32-04:00 Fix #18145 and also avoid needless work with implicit vars - `forAllOrNothing` now is monadic, so we can trace whether we bind an explicit `forall` or not. - #18145 arose because the free vars calculation was needlessly complex. It is now greatly simplified. - Replaced some other implicit var code with `filterFreeVarsToBind`. Co-authored-by: Ryan Scott <ryan.gl.scott at gmail.com> - - - - - a60dc835 by Ben Gamari at 2020-05-23T13:39:12-04:00 Bump process submodule Fixes #17926. - - - - - 856adf54 by Ben Gamari at 2020-05-23T13:40:21-04:00 users-guide: Clarify meaning of -haddock flag Fixes #18206. - - - - - 7ae57afd by Ben Gamari at 2020-05-23T13:41:03-04:00 git: Add ignored commits file This can be used to tell git to ignore bulk renaming commits like the recently-finished module hierarchy refactoring. Configured with, git config blame.ignoreRevsFile .git-ignore-revs - - - - - 63d30e60 by jneira at 2020-05-24T01:54:42-04:00 Add hie-bios script for windows systems It is a direct translation of the sh script - - - - - 59182b88 by jneira at 2020-05-24T01:54:42-04:00 Honour previous values for CABAL and CABFLAGS The immediate goal is let the hie-bios.bat script set CABFLAGS with `-v0` and remove all cabal output except the compiler arguments - - - - - 932dc54e by jneira at 2020-05-24T01:54:42-04:00 Add specific configuration for windows in hie.yaml - - - - - e0eda070 by jneira at 2020-05-24T01:54:42-04:00 Remove not needed hie-bios output - - - - - a0ea59d6 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Move Config module into GHC.Settings - - - - - 37430251 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Rename GHC.Core.Arity into GHC.Core.Opt.Arity - - - - - a426abb9 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Rename GHC.Hs.Types into GHC.Hs.Type See discussion in https://gitlab.haskell.org/ghc/ghc/issues/13009#note_268610 - - - - - 1c91a7a0 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Bump haddock submodule - - - - - 66bd24d1 by Ryan Scott at 2020-05-24T01:56:03-04:00 Add orderingTyCon to wiredInTyCons (#18185) `Ordering` needs to be wired in for use in the built-in `CmpNat` and `CmpSymbol` type families, but somehow it was never added to the list of `wiredInTyCons`, leading to the various oddities observed in #18185. Easily fixed by moving `orderingTyCon` from `basicKnownKeyNames` to `wiredInTyCons`. Fixes #18185. - - - - - 01c43634 by Matthew Pickering at 2020-05-24T01:56:42-04:00 Remove unused hs-boot file - - - - - 7a07aa71 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix cross-compiler build (#16051) - - - - - 15ccca16 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix distDir per stage - - - - - b420fb24 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix hp2ps error during cross-compilation Fixed by @alp (see https://gitlab.haskell.org/ghc/ghc/issues/16051#note_274265) - - - - - cd339ef0 by Joshua Price at 2020-05-24T15:22:56-04:00 Make Unicode brackets opening/closing tokens (#18225) The tokens `[|`, `|]`, `(|`, and `|)` are opening/closing tokens as described in GHC Proposal #229. This commit makes the unicode variants (`⟦`, `⟧`, `⦇`, and `⦈`) act the same as their ASCII counterparts. - - - - - 013d7120 by Ben Gamari at 2020-05-25T09:48:17-04:00 Revert "Specify kind variables for inferred kinds in base." As noted in !3132, this has rather severe knock-on consequences in user-code. We'll need to revisit this before merging something along these lines. This reverts commit 9749fe1223d182b1f8e7e4f7378df661c509f396. - - - - - 4c4312ed by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Drop redundant ad-hoc boot module check To determine whether the module is a boot module Coverage.addTicksToBinds was checking for a `boot` suffix in the module source filename. This is quite ad-hoc and shouldn't be necessary; the callsite in `deSugar` already checks that the module isn't a boot module. - - - - - 1abf3c84 by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Make tickBoxCount strict This could otherwise easily cause a leak of (+) thunks. - - - - - b2813750 by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Make ccIndices strict This just seems like a good idea. - - - - - 02e278eb by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Don't produce ModBreaks if not HscInterpreted emptyModBreaks contains a bottom and consequently it's important that we don't use it unless necessary. - - - - - b8c014ce by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Factor out addMixEntry - - - - - 53814a64 by Zubin Duggal at 2020-05-26T03:03:24-04:00 Add info about typeclass evidence to .hie files See `testsuite/tests/hiefile/should_run/HieQueries.hs` and `testsuite/tests/hiefile/should_run/HieQueries.stdout` for an example of this We add two new fields, `EvidenceVarBind` and `EvidenceVarUse` to the `ContextInfo` associated with an Identifier. These are associated with the appropriate identifiers for the evidence variables collected when we come across `HsWrappers`, `TcEvBinds` and `IPBinds` while traversing the AST. Instance dictionary and superclass selector dictionaries from `tcg_insts` and classes defined in `tcg_tcs` are also recorded in the AST as originating from their definition span This allows us to save a complete picture of the evidence constructed by the constraint solver, and will let us report this to the user, enabling features like going to the instance definition from the invocation of a class method(or any other method taking a constraint) and finding all usages of a particular instance. Additionally, - Mark NodeInfo with an origin so we can differentiate between bindings origininating in the source vs those in ghc - Along with typeclass evidence info, also include information on Implicit Parameters - Add a few utility functions to HieUtils in order to query the new info Updates haddock submodule - - - - - 6604906c by Sebastian Graf at 2020-05-26T03:04:04-04:00 Make WorkWrap.Lib.isWorkerSmallEnough aware of the old arity We should allow a wrapper with up to 82 parameters when the original function had 82 parameters to begin with. I verified that this made no difference on NoFib, but then again it doesn't use huge records... Fixes #18122. - - - - - cf772f19 by Sylvain Henry at 2020-05-26T03:04:45-04:00 Enhance Note [About units] for Backpack - - - - - ede24126 by Takenobu Tani at 2020-05-27T00:13:55-04:00 core-spec: Modify file paths according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * GHC/Core.hs <= coreSyn/CoreSyn.hs * GHC/Core/Coercion.hs <= types/Coercion.hs * GHC/Core/Coercion/Axiom.hs <= types/CoAxiom.hs * GHC/Core/Coercion/Opt.hs <= types/OptCoercion.hs * GHC/Core/DataCon.hs <= basicTypes/DataCon.hs * GHC/Core/FamInstEnv.hs <= types/FamInstEnv.hs * GHC/Core/Lint.hs <= coreSyn/CoreLint.hs * GHC/Core/Subst.hs <= coreSyn/CoreSubst.hs * GHC/Core/TyCo/Rep.hs <= types/TyCoRep.hs * GHC/Core/TyCon.hs <= types/TyCon.hs * GHC/Core/Type.hs <= types/Type.hs * GHC/Core/Unify.hs <= types/Unify.hs * GHC/Types/Literal.hs <= basicTypes/Literal.hs * GHC/Types/Var.hs <= basicTypes/Var.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [skip ci] - - - - - 04750304 by Ben Gamari at 2020-05-27T00:14:33-04:00 eventlog: Fix racy flushing Previously no attempt was made to avoid multiple threads writing their capability-local eventlog buffers to the eventlog writer simultaneously. This could result in multiple eventlog streams being interleaved. Fix this by documenting that the EventLogWriter's write() and flush() functions may be called reentrantly and fix the default writer to protect its FILE* by a mutex. Fixes #18210. - - - - - d6203f24 by Joshua Price at 2020-05-27T00:15:17-04:00 Make `identifier` parse unparenthesized `->` (#18060) - - - - - 28deee28 by Ben Gamari at 2020-05-28T16:23:21-04:00 GHC.Core.Unfold: Refactor traceInline This reduces duplication as well as fixes a bug wherein -dinlining-check would override -ddump-inlinings. Moreover, the new variant - - - - - 1f393e1e by Ben Gamari at 2020-05-28T16:23:21-04:00 Avoid unnecessary allocations due to tracing utilities While ticky-profiling the typechecker I noticed that hundreds of millions of SDocs are being allocated just in case -ddump-*-trace is enabled. This is awful. We avoid this by ensuring that the dump flag check is inlined into the call site, ensuring that the tracing document needn't be allocated unless it's actually needed. See Note [INLINE conditional tracing utilities] for details. Fixes #18168. Metric Decrease: T9961 haddock.Cabal haddock.base haddock.compiler - - - - - 5f621a78 by Vladislav Zavialov at 2020-05-28T16:23:58-04:00 Add Semigroup/Monoid for Q (#18123) - - - - - dc5f004c by Xavier Denis at 2020-05-28T16:24:37-04:00 Fix #18071 Run the core linter on candidate instances to ensure they are well-kinded. Better handle quantified constraints by using a CtWanted to avoid having unsolved constraints thrown away at the end by the solver. - - - - - 10e6982c by Sebastian Graf at 2020-05-28T16:25:14-04:00 FloatOut: Only eta-expand dead-end RHS if arity will increase (#18231) Otherwise we risk turning trivial RHS into non-trivial RHS, introducing unnecessary bindings in the next Simplifier run, resulting in more churn. Fixes #18231. - - - - - 08dab5f7 by Sebastian Graf at 2020-05-28T16:25:14-04:00 DmdAnal: Recognise precise exceptions from case alternatives (#18086) Consider ```hs m :: IO () m = do putStrLn "foo" error "bar" ``` `m` (from #18086) always throws a (precise or imprecise) exception or diverges. Yet demand analysis infers `<L,A>` as demand signature instead of `<L,A>x` for it. That's because the demand analyser sees `putStrLn` occuring in a case scrutinee and decides that it has to `deferAfterPreciseException`, because `putStrLn` throws a precise exception on some control flow paths. This will mask the `botDiv` `Divergence`of the single case alt containing `error` to `topDiv`. Since `putStrLn` has `topDiv` itself, the final `Divergence` is `topDiv`. This is easily fixed: `deferAfterPreciseException` works by `lub`ing with the demand type of a virtual case branch denoting the precise exceptional control flow. We used `nopDmdType` before, but we can be more precise and use `exnDmdType`, which is `nopDmdType` with `exnDiv`. Now the `Divergence` from the case alt will degrade `botDiv` to `exnDiv` instead of `topDiv`, which combines with the result from the scrutinee to `exnDiv`, and all is well. Fixes #18086. - - - - - aef95f11 by Ben Gamari at 2020-05-28T16:25:53-04:00 Ticky-ticky: Record DataCon name in ticker name This makes it significantly easier to spot the nature of allocations regressions and comes at a reasonably low cost. - - - - - 8f021b8c by Ben Gamari at 2020-05-28T16:26:34-04:00 hadrian: Don't track GHC's verbosity argument Teach hadrian to ignore GHC's -v argument in its recompilation check, thus fixing #18131. - - - - - 13d9380b by Ben Gamari at 2020-05-28T16:27:20-04:00 Rip out CmmStackInfo(updfr_space) As noted in #18232, this field is currently completely unused and moreover doesn't have a clear meaning. - - - - - f10d11fa by Andreas Klebinger at 2020-05-29T01:38:42-04:00 Fix "build/elem" RULE. An redundant constraint prevented the rule from matching. Fixing this allows a call to elem on a known list to be translated into a series of equality checks, and eventually a simple case expression. Surprisingly this seems to regress elem for strings. To avoid this we now also allow foldrCString to inline and add an UTF8 variant. This results in elem being compiled to a tight non-allocating loop over the primitive string literal which performs a linear search. In the process this commit adds UTF8 variants for some of the functions in GHC.CString. This is required to make this work for both ASCII and UTF8 strings. There are also small tweaks to the CString related rules. We now allow ourselfes the luxury to compare the folding function via eqExpr, which helps to ensure the rule fires before we inline foldrCString*. Together with a few changes to allow matching on both the UTF8 and ASCII variants of the CString functions. - - - - - bbeb2389 by Ben Gamari at 2020-05-29T01:39:19-04:00 CoreToStg: Add Outputable ArgInfo instance - - - - - 0e3361ca by Simon Peyton Jones at 2020-05-29T01:39:19-04:00 Make Lint check return type of a join point Consider join x = rhs in body It's important that the type of 'rhs' is the same as the type of 'body', but Lint wasn't checking that invariant. Now it does! This was exposed by investigation into !3113. - - - - - c49f7df0 by Simon Peyton Jones at 2020-05-29T01:39:19-04:00 Do not float join points in exprIsConApp_maybe We hvae been making exprIsConApp_maybe cleverer in recent times: commit b78cc64e923716ac0512c299f42d4d0012306c05 Date: Thu Nov 15 17:14:31 2018 +0100 Make constructor wrappers inline only during the final phase commit 7833cf407d1f608bebb1d38bb99d3035d8d735e6 Date: Thu Jan 24 17:58:50 2019 +0100 Look through newtype wrappers (Trac #16254) commit c25b135ff5b9c69a90df0ccf51b04952c2dc6ee1 Date: Thu Feb 21 12:03:22 2019 +0000 Fix exprIsConApp_maybe But alas there was still a bug, now immortalised in Note [Don't float join points] in SimpleOpt. It's quite hard to trigger because it requires a dead join point, but it came up when compiling Cabal Cabal.Distribution.Fields.Lexer.hs, when working on !3113. Happily, the fix is extremly easy. Finding the bug was not so easy. - - - - - 46720997 by Ben Gamari at 2020-05-29T01:39:19-04:00 Allow simplification through runRW# Because runRW# inlines so late, we were previously able to do very little simplification across it. For instance, given even a simple program like case runRW# (\s -> let n = I# 42# in n) of I# n# -> f n# we previously had no way to avoid the allocation of the I#. This patch allows the simplifier to push strict contexts into the continuation of a runRW# application, as explained in in Note [Simplification of runRW#] in GHC.CoreToStg.Prep. Fixes #15127. Metric Increase: T9961 Metric Decrease: ManyConstructors Co-Authored-By: Simon Peyton-Jone <simonpj at microsoft.com> - - - - - 277c2f26 by Ben Gamari at 2020-05-29T01:39:55-04:00 Eta expand un-saturated primops Now since we no longer try to predict CAFfyness we have no need for the solution to #16846. Eta expanding unsaturated primop applications is conceptually simpler, especially in the presence of levity polymorphism. This essentially reverts cac8dc9f51e31e4c0a6cd9bc302f7e1bc7c03beb, as suggested in #18079. Closes #18079. - - - - - f44d7ae0 by Simon Jakobi at 2020-05-29T01:40:34-04:00 base: Scrap deprecation plan for Data.Monoid.{First,Last} See the discussion on the libraries mailing list for context: https://mail.haskell.org/pipermail/libraries/2020-April/030357.html - - - - - 8b494895 by Jeremy Schlatter at 2020-05-29T01:41:12-04:00 Fix typo in documentation - - - - - 998450f4 by Gleb Popov at 2020-05-29T01:41:53-04:00 Always define USE_PTHREAD_FOR_ITIMER for FreeBSD. - - - - - f9a513e0 by Alp Mestanogullari at 2020-05-29T01:42:36-04:00 hadrian: introduce 'install' target Its logic is very simple. It `need`s the `binary-dist-dir` target and runs suitable `configure` and `make install` commands for the user. A new `--prefix` command line argument is introduced to specify where GHC should be installed. - - - - - 67738db1 by Travis Whitaker at 2020-05-29T13:34:48-04:00 Build a threaded stage 1 if the bootstrapping GHC supports it. - - - - - aac19e6c by Peter Trommler at 2020-05-29T13:35:24-04:00 PPC NCG: No per-symbol .section ".toc" directives All position independent symbols are collected during code generation and emitted in one go. Prepending each symbol with a .section ".toc" directive is redundant. This patch drops the per-symbol directives leading to smaller assembler files. Fixes #18250 - - - - - 4413828b by Ben Gamari at 2020-05-30T06:07:31-04:00 rts: Teach getNumProcessors to return available processors Previously we would report the number of physical processors, which can be quite wrong in a containerized setting. Now we rather return how many processors are in our affinity mask when possible. I also refactored the code to prefer platform-specific since this will report logical CPUs instead of physical (using `machdep.cpu.thread_count` on Darwin and `cpuset_getaffinity` on FreeBSD). Fixes #14781. - - - - - 1449435c by Ben Gamari at 2020-05-30T06:07:31-04:00 users-guide: Note change in getNumProcessors in users guide - - - - - 3d960169 by Ben Gamari at 2020-05-30T06:07:31-04:00 rts: Drop compatibility shims for Windows Vista We can now assume that the thread and processor group interfaces are available. - - - - - 7f8f948c by Peter Trommler at 2020-05-30T06:08:07-04:00 PPC NCG: Fix .size directive on powerpc64 ELF v1 Thanks to Sergei Trofimovich for pointing out the issue. Fixes #18237 - - - - - 7c555b05 by Andreas Klebinger at 2020-05-30T06:08:43-04:00 Optimize GHC.Utils.Monad. Many functions in this module are recursive and as such are marked loop breakers. Which means they are unlikely to get an unfolding. This is *bad*. We always want to specialize them to specific Monads. Which requires a visible unfolding at the use site. I rewrote the recursive ones from: foo f x = ... foo x' ... to foo f x = go x where go x = ... As well as giving some pragmas to make all of them available for specialization. The end result is a reduction of allocations of about -1.4% for nofib/spectral/simple/Main.hs when compiled with `-O`. ------------------------- Metric Decrease: T12425 T14683 T5631 T9233 T9675 T9961 WWRec ------------------------- - - - - - 8b1cb5df by Ben Gamari at 2020-05-30T06:09:20-04:00 Windows: Bump Windows toolchain to 0.2 - - - - - 6947231a by Zubin Duggal at 2020-05-30T06:10:02-04:00 Simplify contexts in GHC.Iface.Ext.Ast - - - - - 2ee4f36c by Daniel Gröber at 2020-06-01T06:32:56-04:00 Cleanup OVERWRITING_CLOSURE logic The code is just more confusing than it needs to be. We don't need to mix the threaded check with the ldv profiling check since ldv's init already checks for this. Hence they can be two separate checks. Taking the sanity checking into account is also cleaner via DebugFlags.sanity. No need for checking the DEBUG define. The ZERO_SLOP_FOR_LDV_PROF and ZERO_SLOP_FOR_SANITY_CHECK definitions the old code had also make things a lot more opaque IMO so I removed those. - - - - - 6159559b by Daniel Gröber at 2020-06-01T06:32:56-04:00 Fix OVERWRITING_CLOSURE assuming closures are not inherently used The new ASSERT in LDV_recordDead() was being tripped up by MVars when removeFromMVarBlockedQueue() calls OVERWRITING_CLOSURE() via OVERWRITE_INFO(). - - - - - 38992085 by Daniel Gröber at 2020-06-01T06:32:56-04:00 Always zero shrunk mutable array slop when profiling When shrinking arrays in the profiling way we currently don't always zero the leftover slop. This means we can't traverse such closures in the heap profiler. The old Note [zeroing slop] and #8402 have some rationale for why this is so but I belive the reasoning doesn't apply to mutable closures. There users already have to ensure multiple threads don't step on each other's toes so zeroing should be safe. - - - - - b0c1f2a6 by Ben Gamari at 2020-06-01T06:33:37-04:00 testsuite: Add test for #18151 - - - - - 9a99a178 by Ben Gamari at 2020-06-01T06:33:37-04:00 testsuite: Add test for desugaring of PostfixOperators - - - - - 2b89ca5b by Ben Gamari at 2020-06-01T06:33:37-04:00 HsToCore: Eta expand left sections Strangely, the comment next to this code already alluded to the fact that even simply eta-expanding will sacrifice laziness. It's quite unclear how we regressed so far. See #18151. - - - - - d412d7a3 by Kirill Elagin at 2020-06-01T06:34:21-04:00 Winferred-safe-imports: Do not exit with error Currently, when -Winferred-safe-imports is enabled, even when it is not turned into an error, the compiler will still exit with exit code 1 if this warning was emitted. Make sure it is really treated as a warning. - - - - - f945eea5 by Ben Gamari at 2020-06-01T06:34:58-04:00 nonmoving: Optimise log2_ceil - - - - - aab606e4 by Bodigrim at 2020-06-01T06:35:36-04:00 Clarify description of fromListN - - - - - 7e5220e2 by Bodigrim at 2020-06-01T06:35:36-04:00 Apply suggestion to libraries/base/GHC/Exts.hs - - - - - f3fb1ce9 by fendor at 2020-06-01T06:36:18-04:00 Add `isInScope` check to `lintCoercion` Mirrors the behaviour of `lintType`. - - - - - 5ac4d946 by fendor at 2020-06-01T06:36:18-04:00 Lint rhs of IfaceRule - - - - - 1cef6126 by Jeremy Schlatter at 2020-06-01T06:37:00-04:00 Fix wording in documentation The duplicate "orphan instance" phrase here doesn't make sense, and was probably an accident. - - - - - 5aaf08f2 by Takenobu Tani at 2020-06-01T06:37:43-04:00 configure: Modify aclocal.m4 according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * Rename: * compiler/GHC/Parser.hs <= compiler/parser/Parser.hs * compiler/GHC/Parser/Lexer.hs <= compiler/Parser/Lexer.hs * Add: * compiler/GHC/Cmm/Lexer.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular - - - - - 15857ad8 by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Don't fail if we can't unlink __symlink_test Afterall, it's possible we were unable to create it due to lack of symlink permission. - - - - - 4a7229ef by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Refactor ghostscript detection Tamar reported that he saw crashes due to unhandled exceptions. - - - - - 2ab37eaf by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite/perf_notes: Fix ill-typed assignments - - - - - e45d5b66 by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite/testutil: Fix bytes/str mismatch - - - - - 7002d0cb by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Work around spurious mypy failure - - - - - 11390e3a by Takenobu Tani at 2020-06-01T06:39:05-04:00 Clean up file paths for new module hierarchy This updates comments only. This patch replaces file references according to new module hierarchy. See also: * https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular * https://gitlab.haskell.org/ghc/ghc/issues/13009 - - - - - 8f2e5732 by Takenobu Tani at 2020-06-01T06:39:05-04:00 Modify file paths to module paths for new module hierarchy This updates comments only. This patch replaces module references according to new module hierarchy [1][2]. For files under the `compiler/` directory, I replace them as module paths instead of file paths. For instance, `GHC.Unit.State` instead of `compiler/GHC/Unit/State.hs` [3]. For current and future haddock's markup, this patch encloses the module name with "" [4]. [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: https://gitlab.haskell.org/ghc/ghc/issues/13009 [3]: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3375#note_276613 [4]: https://haskell-haddock.readthedocs.io/en/latest/markup.html#linking-to-modules - - - - - 68b71c4a by Tom Ellis at 2020-06-01T06:39:55-04:00 Rename the singleton tuple GHC.Tuple.Unit to GHC.Tuple.Solo - - - - - 95da76c2 by Sylvain Henry at 2020-06-01T06:40:41-04:00 Hadrian: fix binary-dist target for cross-compilation - - - - - 730fcd54 by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for the @-operator Since GHC diverges from the Haskell Report by allowing the user to define (@) as an infix operator, we better give a good error message when the user does so unintentionally. In general, this is rather hard to do, as some failures will be discovered only in the renamer or the type checker: x :: (Integer, Integer) x @ (a, b) = (1, 2) This patch does *not* address this general case. However, it gives much better error messages when the binding is not syntactically valid: pairs xs @ (_:xs') = zip xs xs' Before this patch, the error message was rather puzzling: <interactive>:1:1: error: Parse error in pattern: pairs After this patch, the error message includes a hint: <interactive>:1:1: error: Parse error in pattern: pairs In a function binding for the ‘@’ operator. Perhaps you meant an as-pattern, which must not be surrounded by whitespace - - - - - 0fde5377 by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for TypeApplications With this patch, we always parse f @t as a type application, thereby producing better error messages. This steals two syntactic forms: * Prefix form of the @-operator in expressions. Since the @-operator is a divergence from the Haskell Report anyway, this is not a major loss. * Prefix form of @-patterns. Since we are stealing loose infix form anyway, might as well sacrifice the prefix form for the sake of much better error messages. - - - - - c68e7e1e by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for TemplateHaskellQuotes While [e| |], [t| |], [d| |], and so on, steal syntax from list comprehensions, [| |] and [|| ||] do not steal any syntax. Thus we can improve error messages by always accepting them in the lexer. Turns out the renamer already performs necessary validation. - - - - - 120aedbd by Ben Gamari at 2020-06-01T16:07:02-04:00 gitlab-ci: Disable use of ld.lld on ARMv7 It turns out that lld non-deterministically fails on ARMv7. I suspect this may be due to the a kernel regression as this only started happening when we upgraded to 5.4. Nevertheless, easily avoided by simply sticking with gold. Works around #18280. - - - - - d6279ff0 by Ben Gamari at 2020-06-02T13:03:30-04:00 gitlab-ci: Ensure that workaround for #18280 applies to bindisttest We need to ensure that the `configure` flags working around #18280 are propagated to the bindisttest `configure` as well. - - - - - cb5c31b5 by Ben Gamari at 2020-06-03T17:55:04-04:00 gitlab-ci: Allow ARMv7 job to fail Due to #18298. - - - - - 32a4ae90 by John Ericson at 2020-06-04T04:34:42-04:00 Clean up boot vs non-boot disambiguating types We often have (ModuleName, Bool) or (Module, Bool) pairs for "extended" module names (without or with a unit id) disambiguating boot and normal modules. We think this is important enough across the compiler that it deserves a new nominal product type. We do this with synnoyms and a functor named with a `Gen` prefix, matching other newly created definitions. It was also requested that we keep custom `IsBoot` / `NotBoot` sum type. So we have it too. This means changing many the many bools to use that instead. Updates `haddock` submodule. - - - - - c05756cd by Niklas Hambüchen at 2020-06-04T04:35:24-04:00 docs: Add more details on InterruptibleFFI. Details from https://gitlab.haskell.org/ghc/ghc/issues/8684 and https://github.com/takano-akio/filelock/pull/7#discussion_r280332430 - - - - - 1b975aed by Andrew Martin at 2020-06-04T04:36:03-04:00 Allow finalizeForeignPtr to be called on FinalPtr/PlainPtr. MR 2165 (commit 49301ad6226d9a83d110bee8c419615dd94f5ded) regressed finalizeForeignPtr by throwing exceptions when PlainPtr was encounterd. This regression did not make it into a release of GHC. Here, the original behavior is restored, and FinalPtr is given the same treatment as PlainPtr. - - - - - 2bd3929a by Luke Lau at 2020-06-04T04:36:41-04:00 Fix documentation on type families not being extracted It looks like the location of the Names used for CoAxioms on type families are now located at their type constructors. Previously, Docs.hs thought the Names were located in the RHS, so the RealSrcSpan in the instanceMap and getInstLoc didn't match up. Fixes #18241 - - - - - 6735b9d9 by Ben Gamari at 2020-06-04T04:37:21-04:00 GHC.Hs.Instances: Compile with -O0 This module contains exclusively Data instances, which are going to be slow no matter what we do. Furthermore, they are incredibly slow to compile with optimisation (see #9557). Consequently we compile this with -O0. See #18254. - - - - - c330331a by nineonine at 2020-06-04T04:37:59-04:00 Add test for #17669 - - - - - cab684f0 by Ben Gamari at 2020-06-04T04:38:36-04:00 rts: Add Windows-specific implementation of rtsSleep Previously we would use the POSIX path, which uses `nanosleep`. However, it turns out that `nanosleep` is provided by `libpthread` on Windows. In general we don't want to incur such a dependency. Avoid this by simply using `Sleep` on Windows. Fixes #18272. - - - - - ad44b504 by Ben Gamari at 2020-06-04T04:38:36-04:00 compiler: Disable use of process jobs with process < 1.6.9 Due to #17926. - - - - - 6a4098a4 by Moritz Angermann at 2020-06-04T04:55:51-04:00 [linker] Adds void printLoadedObjects(void); This allows us to dump in-memory object code locations for debugging. Fixup printLoadedObjects prototype - - - - - af5e3a88 by Artem Pelenitsyn at 2020-06-05T03:18:49-04:00 base: fix sign confusion in log1mexp implementation (fix #17125) author: claude (https://gitlab.haskell.org/trac-claude) The correct threshold for log1mexp is -(log 2) with the current specification of log1mexp. This change improves accuracy for large negative inputs. To avoid code duplication, a small helper function is added; it isn't the default implementation in Floating because it needs Ord. This patch does nothing to address that the Haskell specification is different from that in common use in other languages. - - - - - 2b792fac by Simon Peyton Jones at 2020-06-05T09:27:50-04:00 Simple subsumption This patch simplifies GHC to use simple subsumption. Ticket #17775 Implements GHC proposal #287 https://github.com/ghc-proposals/ghc-proposals/blob/master/ proposals/0287-simplify-subsumption.rst All the motivation is described there; I will not repeat it here. The implementation payload: * tcSubType and friends become noticably simpler, because it no longer uses eta-expansion when checking subsumption. * No deeplyInstantiate or deeplySkolemise That in turn means that some tests fail, by design; they can all be fixed by eta expansion. There is a list of such changes below. Implementing the patch led me into a variety of sticky corners, so the patch includes several othe changes, some quite significant: * I made String wired-in, so that "foo" :: String rather than "foo" :: [Char] This improves error messages, and fixes #15679 * The pattern match checker relies on knowing about in-scope equality constraints, andd adds them to the desugarer's environment using addTyCsDs. But the co_fn in a FunBind was missed, and for some reason simple-subsumption ends up with dictionaries there. So I added a call to addTyCsDs. This is really part of #18049. * I moved the ic_telescope field out of Implication and into ForAllSkol instead. This is a nice win; just expresses the code much better. * There was a bug in GHC.Tc.TyCl.Instance.tcDataFamInstHeader. We called checkDataKindSig inside tc_kind_sig, /before/ solveEqualities and zonking. Obviously wrong, easily fixed. * solveLocalEqualitiesX: there was a whole mess in here, around failing fast enough. I discovered a bad latent bug where we could successfully kind-check a type signature, and use it, but have unsolved constraints that could fill in coercion holes in that signature -- aargh. It's all explained in Note [Failure in local type signatures] in GHC.Tc.Solver. Much better now. * I fixed a serious bug in anonymous type holes. IN f :: Int -> (forall a. a -> _) -> Int that "_" should be a unification variable at the /outer/ level; it cannot be instantiated to 'a'. This was plain wrong. New fields mode_lvl and mode_holes in TcTyMode, and auxiliary data type GHC.Tc.Gen.HsType.HoleMode. This fixes #16292, but makes no progress towards the more ambitious #16082 * I got sucked into an enormous refactoring of the reporting of equality errors in GHC.Tc.Errors, especially in mkEqErr1 mkTyVarEqErr misMatchMsg misMatchMsgOrCND In particular, the very tricky mkExpectedActualMsg function is gone. It took me a full day. But the result is far easier to understand. (Still not easy!) This led to various minor improvements in error output, and an enormous number of test-case error wibbles. One particular point: for occurs-check errors I now just say Can't match 'a' against '[a]' rather than using the intimidating language of "occurs check". * Pretty-printing AbsBinds Tests review * Eta expansions T11305: one eta expansion T12082: one eta expansion (undefined) T13585a: one eta expansion T3102: one eta expansion T3692: two eta expansions (tricky) T2239: two eta expansions T16473: one eta determ004: two eta expansions (undefined) annfail06: two eta (undefined) T17923: four eta expansions (a strange program indeed!) tcrun035: one eta expansion * Ambiguity check at higher rank. Now that we have simple subsumption, a type like f :: (forall a. Eq a => Int) -> Int is no longer ambiguous, because we could write g :: (forall a. Eq a => Int) -> Int g = f and it'd typecheck just fine. But f's type is a bit suspicious, and we might want to consider making the ambiguity check do a check on each sub-term. Meanwhile, these tests are accepted, whereas they were previously rejected as ambiguous: T7220a T15438 T10503 T9222 * Some more interesting error message wibbles T13381: Fine: one error (Int ~ Exp Int) rather than two (Int ~ Exp Int, Exp Int ~ Int) T9834: Small change in error (improvement) T10619: Improved T2414: Small change, due to order of unification, fine T2534: A very simple case in which a change of unification order means we get tow unsolved constraints instead of one tc211: bizarre impredicative tests; just accept this for now Updates Cabal and haddock submodules. Metric Increase: T12150 T12234 T5837 haddock.base Metric Decrease: haddock.compiler haddock.Cabal haddock.base Merge note: This appears to break the `UnliftedNewtypesDifficultUnification` test. It has been marked as broken in the interest of merging. (cherry picked from commit 66b7b195cb3dce93ed5078b80bf568efae904cc5) - - - - - 2dff8141 by Ryan Scott at 2020-06-05T14:21:24-04:00 Simplify bindLHsTyVarBndrs and bindHsQTyVars Both `bindLHsTyVarBndrs` and `bindHsQTyVars` take two separate `Maybe` arguments, which I find terribly confusing. Thankfully, it's possible to remove one `Maybe` argument from each of these functions, which this patch accomplishes: * `bindHsQTyVars` takes a `Maybe SDoc` argument, which is `Just` if GHC should warn about any of the quantified type variables going unused. However, every call site uses `Nothing` in practice. This makes sense, since it doesn't really make sense to warn about unused type variables bound by an `LHsQTyVars`. For instance, you wouldn't warn about the `a` in `data Proxy a = Proxy` going unused. As a result, I simply remove this `Maybe SDoc` argument altogether. * `bindLHsTyVarBndrs` also takes a `Maybe SDoc` argument for the same reasons that `bindHsQTyVars` took one. To make things more confusing, however, `bindLHsTyVarBndrs` also takes a separate `HsDocContext` argument, which is pretty-printed (to an `SDoc`) in warnings and error messages. In practice, the `Maybe SDoc` and the `HsDocContext` often contain the same text. See the call sites for `bindLHsTyVarBndrs` in `rnFamInstEqn` and `rnConDecl`, for instance. There are only a handful of call sites where the text differs between the `Maybe SDoc` and `HsDocContext` arguments: * In `rnHsRuleDecl`, where the `Maybe SDoc` says "`In the rule`" and the `HsDocContext` says "`In the transformation rule`". * In `rnHsTyKi`/`rn_ty`, where the `Maybe SDoc` says "`In the type`" but the `HsDocContext` is inhereted from the surrounding context (e.g., if `rnHsTyKi` were called on a top-level type signature, the `HsDocContext` would be "`In the type signature`" instead) In both cases, warnings/error messages arguably _improve_ by unifying making the `Maybe SDoc`'s text match that of the `HsDocContext`. As a result, I decided to remove the `Maybe SDoc` argument to `bindLHsTyVarBndrs` entirely and simply reuse the text from the `HsDocContext`. (I decided to change the phrase "transformation rule" to "rewrite rule" while I was in the area.) The `Maybe SDoc` argument has one other purpose: signaling when to emit "`Unused quantified type variable`" warnings. To recover this functionality, I replaced the `Maybe SDoc` argument with a boolean-like `WarnUnusedForalls` argument. The only `bindLHsTyVarBndrs` call site that chooses _not_ to emit these warnings in `bindHsQTyVars`. - - - - - e372331b by Ben Gamari at 2020-06-07T08:46:41-04:00 hadrian: Add missing deriveConstants dependency on ghcplatform.h deriveConstants wants to compile C sources which #include PosixSource.h, which itself #includes ghcplatform.h. Make sure that Hadrian knows about this dependency. Fixes #18290. - - - - - b022051a by Moritz Angermann at 2020-06-07T08:46:42-04:00 ghc-prim needs to depend on libc and libm libm is just an empty shell on musl, and all the math functions are contained in libc. - - - - - 6dae6548 by Moritz Angermann at 2020-06-07T08:46:42-04:00 Disable DLL loading if without system linker Some platforms (musl, aarch64) do not have a working dynamic linker implemented in the libc, even though we might see dlopen. It will ultimately just return that this is not supported. Hence we'll add a flag to the compiler to flat our disable loading dlls. This is needed as we will otherwise try to load the shared library even if this will subsequently fail. At that point we have given up looking for static options though. - - - - - 4a158ffc by Moritz Angermann at 2020-06-07T08:46:43-04:00 Range is actually +/-2^32, not +/-2^31 See also: https://static.docs.arm.com/ihi0056/g/aaelf64.pdf - - - - - f1bfb806 by Ben Gamari at 2020-06-07T10:49:30-04:00 OccurAnal: Avoid exponential behavior due to where clauses Previously the `Var` case of `occAnalApp` could in some cases (namely in the case of `runRW#` applications) call `occAnalRhs` two. In the case of nested `runRW#`s this results in exponential complexity. In some cases the compilation time that resulted would be very long indeed (see #18296). Fixes #18296. Metric Decrease: T9961 T12150 T12234 - - - - - 9b607671 by Takenobu Tani at 2020-06-09T08:05:46-04:00 Add link to GHC's wiki in the GHC API header This adds a URL to point to GHC's wiki in the GHC API header. Newcomers could easily find more information from the GHC API's web like [1]. [1]: Current version, https://ghc.gitlab.haskell.org/ghc/doc/libraries/ghc-8.11.0.20200604/index.html [skip ci] - - - - - 72c7fe9a by Ryan Scott at 2020-06-09T08:06:24-04:00 Make GADT constructors adhere to the forall-or-nothing rule properly Issue #18191 revealed that the types of GADT constructors don't quite adhere to the `forall`-or-nothing rule. This patch serves to clean up this sad state of affairs somewhat. The main change is not in the code itself, but in the documentation, as this patch introduces two sections to the GHC User's Guide: * A "Formal syntax for GADTs" section that presents a BNF-style grammar for what is and isn't allowed in GADT constructor types. This mostly exists to codify GHC's existing behavior, but it also imposes a new restriction that addresses #18191: the outermost `forall` and/or context in a GADT constructor is not allowed to be surrounded by parentheses. Doing so would make these `forall`s/contexts nested, and GADTs do not support nested `forall`s/contexts at present. * A "`forall`-or-nothing rule" section that describes exactly what the `forall`-or-nothing rule is all about. Surprisingly, there was no mention of this anywhere in the User's Guide up until now! To adhere the new specification in the "Formal syntax for GADTs" section of the User's Guide, the following code changes were made: * A new function, `GHC.Hs.Type.splitLHsGADTPrefixTy`, was introduced. This is very much like `splitLHsSigmaTy`, except that it avoids splitting apart any parentheses, which can be syntactically significant for GADT types. See `Note [No nested foralls or contexts in GADT constructors]` in `GHC.Hs.Type`. * `ConDeclGADTPrefixPs`, an extension constructor for `XConDecl`, was introduced so that `GHC.Parser.PostProcess.mkGadtDecl` can return it when given a prefix GADT constructor. Unlike `ConDeclGADT`, `ConDeclGADTPrefixPs` does not split the GADT type into its argument and result types, as this cannot be done until after the type is renamed (see `Note [GADT abstract syntax]` in `GHC.Hs.Decls` for why this is the case). * `GHC.Renamer.Module.rnConDecl` now has an additional case for `ConDeclGADTPrefixPs` that (1) splits apart the full `LHsType` into its `forall`s, context, argument types, and result type, and (2) checks for nested `forall`s/contexts. Step (2) used to be performed the typechecker (in `GHC.Tc.TyCl.badDataConTyCon`) rather than the renamer, but now the relevant code from the typechecker can simply be deleted. One nice side effect of this change is that we are able to give a more accurate error message for GADT constructors that use visible dependent quantification (e.g., `MkFoo :: forall a -> a -> Foo a`), which improves the stderr in the `T16326_Fail6` test case. Fixes #18191. Bumps the Haddock submodule. - - - - - a47e6442 by Ryan Scott at 2020-06-10T03:39:12-04:00 Always use rnImplicitBndrs to bring implicit tyvars into scope This implements a first step towards #16762 by changing the renamer to always use `rnImplicitBndrs` to bring implicitly bound type variables into scope. The main change is in `rnFamInstEqn` and `bindHsQTyVars`, which previously used _ad hoc_ methods of binding their implicit tyvars. There are a number of knock-on consequences: * One of the reasons that `rnFamInstEqn` used an _ad hoc_ binding mechanism was to give more precise source locations in `-Wunused-type-patterns` warnings. (See https://gitlab.haskell.org/ghc/ghc/issues/16762#note_273343 for an example of this.) However, these warnings are actually a little _too_ precise, since implicitly bound type variables don't have exact binding sites like explicitly bound type variables do. A similar problem existed for "`Different names for the same type variable`" errors involving implicit tyvars bound by `bindHsQTyVars`. Therefore, we simply accept the less precise (but more accurate) source locations from `rnImplicitBndrs` in `rnFamInstEqn` and `bindHsQTyVars`. See `Note [Source locations for implicitly bound type variables]` in `GHC.Rename.HsType` for the full story. * In order for `rnImplicitBndrs` to work in `rnFamInstEqn`, it needs to be able to look up names from the parent class (in the event that we are renaming an associated type family instance). As a result, `rnImplicitBndrs` now takes an argument of type `Maybe assoc`, which is `Just` in the event that a type family instance is associated with a class. * Previously, GHC kept track of three type synonyms for free type variables in the renamer: `FreeKiTyVars`, `FreeKiTyVarsDups` (which are allowed to contain duplicates), and `FreeKiTyVarsNoDups` (which contain no duplicates). However, making is a distinction between `-Dups` and `-NoDups` is now pointless, as all code that returns `FreeKiTyVars{,Dups,NoDups}` will eventually end up being passed to `rnImplicitBndrs`, which removes duplicates. As a result, I decided to just get rid of `FreeKiTyVarsDups` and `FreeKiTyVarsNoDups`, leaving only `FreeKiTyVars`. * The `bindLRdrNames` and `deleteBys` functions are now dead code, so I took the liberty of removing them. - - - - - 24879129 by Takenobu Tani at 2020-06-10T03:39:59-04:00 Clarify leaf module names for new module hierarchy This updates comments only. This patch replaces leaf module names according to new module hierarchy [1][2] as followings: * Expand leaf names to easily find the module path: for instance, `Id.hs` to `GHC.Types.Id`. * Modify leaf names according to new module hierarchy: for instance, `Convert.hs` to `GHC.ThToHs`. * Fix typo: for instance, `GHC.Core.TyCo.Rep.hs` to `GHC.Core.TyCo.Rep` See also !3375 [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: https://gitlab.haskell.org/ghc/ghc/issues/13009 - - - - - 92de9e25 by Ömer Sinan Ağacan at 2020-06-10T03:41:07-04:00 rts: Remove unused GET_ENTRY closure macro This macro is not used and got broken in the meantime, as ENTRY_CODE was deleted. - - - - - 87102928 by Ömer Sinan Ağacan at 2020-06-10T03:41:50-04:00 Fix -fkeep-cafs flag name in users guide - - - - - ccd6843d by Shayne Fletcher at 2020-06-10T04:14:57-04:00 Expose impliedGFlags, impledOffGFlags, impliedXFlags - - - - - 7a737e89 by Ömer Sinan Ağacan at 2020-06-10T04:14:58-04:00 Cross-module LambdaFormInfo passing - Store LambdaFormInfos of exported Ids in interface files - Use them in importing modules This is for optimization purposes: if we know LambdaFormInfo of imported Ids we can generate more efficient calling code, see `getCallMethod`. Exporting (putting them in interface files or in ModDetails) and importing (reading them from interface files) are both optional. We don't assume known LambdaFormInfos anywhere and do not change how we call Ids with unknown LambdaFormInfos. Runtime, allocation, and residency numbers when building Cabal-the-library (commit 0d4ee7ba3): (Log and .hp files are in the MR: !2842) | | GHC HEAD | This patch | Diff | |-----|----------|------------|----------------| | -O0 | 0:35.89 | 0:34.10 | -1.78s, -4.98% | | -O1 | 2:24.01 | 2:23.62 | -0.39s, -0.27% | | -O2 | 2:52.23 | 2:51.35 | -0.88s, -0.51% | | | GHC HEAD | This patch | Diff | |-----|-----------------|-----------------|----------------------------| | -O0 | 54,843,608,416 | 54,878,769,544 | +35,161,128 bytes, +0.06% | | -O1 | 227,136,076,400 | 227,569,045,168 | +432,968,768 bytes, +0.19% | | -O2 | 266,147,063,296 | 266,749,643,440 | +602,580,144 bytes, +0.22% | NOTE: Residency is measured with extra runtime args: `-i0 -h` which effectively turn all GCs into major GCs, and do GC more often. | | GHC HEAD | This patch | Diff | |-----|----------------------------|------------------------------|----------------------------| | -O0 | 410,284,000 (910 samples) | 411,745,008 (906 samples) | +1,461,008 bytes, +0.35% | | -O1 | 928,580,856 (2109 samples) | 943,506,552 (2103 samples) | +14,925,696 bytes, +1.60% | | -O2 | 993,951,352 (2549 samples) | 1,010,156,328 (2545 samples) | +16,204,9760 bytes, +1.63% | NoFib results: -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS 0.0% 0.0% +0.0% +0.0% +0.0% CSD 0.0% 0.0% 0.0% +0.0% +0.0% FS 0.0% 0.0% +0.0% +0.0% +0.0% S 0.0% 0.0% +0.0% +0.0% +0.0% VS 0.0% 0.0% +0.0% +0.0% +0.0% VSD 0.0% 0.0% +0.0% +0.0% +0.1% VSM 0.0% 0.0% +0.0% +0.0% +0.0% anna 0.0% 0.0% -0.3% -0.8% -0.0% ansi 0.0% 0.0% -0.0% -0.0% 0.0% atom 0.0% 0.0% -0.0% -0.0% 0.0% awards 0.0% 0.0% -0.1% -0.3% 0.0% banner 0.0% 0.0% -0.0% -0.0% -0.0% bernouilli 0.0% 0.0% -0.0% -0.0% -0.0% binary-trees 0.0% 0.0% -0.0% -0.0% +0.0% boyer 0.0% 0.0% -0.0% -0.0% 0.0% boyer2 0.0% 0.0% -0.0% -0.0% 0.0% bspt 0.0% 0.0% -0.0% -0.2% 0.0% cacheprof 0.0% 0.0% -0.1% -0.4% +0.0% calendar 0.0% 0.0% -0.0% -0.0% 0.0% cichelli 0.0% 0.0% -0.9% -2.4% 0.0% circsim 0.0% 0.0% -0.0% -0.0% 0.0% clausify 0.0% 0.0% -0.1% -0.3% 0.0% comp_lab_zift 0.0% 0.0% -0.0% -0.0% +0.0% compress 0.0% 0.0% -0.0% -0.0% -0.0% compress2 0.0% 0.0% -0.0% -0.0% 0.0% constraints 0.0% 0.0% -0.1% -0.2% -0.0% cryptarithm1 0.0% 0.0% -0.0% -0.0% 0.0% cryptarithm2 0.0% 0.0% -1.4% -4.1% -0.0% cse 0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e1 0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e2 0.0% 0.0% -0.0% -0.0% -0.0% dom-lt 0.0% 0.0% -0.1% -0.2% 0.0% eliza 0.0% 0.0% -0.5% -1.5% 0.0% event 0.0% 0.0% -0.0% -0.0% -0.0% exact-reals 0.0% 0.0% -0.1% -0.3% +0.0% exp3_8 0.0% 0.0% -0.0% -0.0% -0.0% expert 0.0% 0.0% -0.3% -1.0% -0.0% fannkuch-redux 0.0% 0.0% +0.0% +0.0% +0.0% fasta 0.0% 0.0% -0.0% -0.0% +0.0% fem 0.0% 0.0% -0.0% -0.0% 0.0% fft 0.0% 0.0% -0.0% -0.0% 0.0% fft2 0.0% 0.0% -0.0% -0.0% 0.0% fibheaps 0.0% 0.0% -0.0% -0.0% +0.0% fish 0.0% 0.0% 0.0% -0.0% +0.0% fluid 0.0% 0.0% -0.4% -1.2% +0.0% fulsom 0.0% 0.0% -0.0% -0.0% 0.0% gamteb 0.0% 0.0% -0.1% -0.3% 0.0% gcd 0.0% 0.0% -0.0% -0.0% 0.0% gen_regexps 0.0% 0.0% -0.0% -0.0% -0.0% genfft 0.0% 0.0% -0.0% -0.0% 0.0% gg 0.0% 0.0% -0.0% -0.0% +0.0% grep 0.0% 0.0% -0.0% -0.0% -0.0% hidden 0.0% 0.0% -0.1% -0.4% -0.0% hpg 0.0% 0.0% -0.2% -0.5% +0.0% ida 0.0% 0.0% -0.0% -0.0% +0.0% infer 0.0% 0.0% -0.3% -0.8% -0.0% integer 0.0% 0.0% -0.0% -0.0% +0.0% integrate 0.0% 0.0% -0.0% -0.0% 0.0% k-nucleotide 0.0% 0.0% -0.0% -0.0% +0.0% kahan 0.0% 0.0% -0.0% -0.0% +0.0% knights 0.0% 0.0% -2.2% -5.4% 0.0% lambda 0.0% 0.0% -0.6% -1.8% 0.0% last-piece 0.0% 0.0% -0.0% -0.0% 0.0% lcss 0.0% 0.0% -0.0% -0.1% 0.0% life 0.0% 0.0% -0.0% -0.1% 0.0% lift 0.0% 0.0% -0.2% -0.6% +0.0% linear 0.0% 0.0% -0.0% -0.0% -0.0% listcompr 0.0% 0.0% -0.0% -0.0% 0.0% listcopy 0.0% 0.0% -0.0% -0.0% 0.0% maillist 0.0% 0.0% -0.1% -0.3% +0.0% mandel 0.0% 0.0% -0.0% -0.0% 0.0% mandel2 0.0% 0.0% -0.0% -0.0% -0.0% mate +0.0% 0.0% -0.0% -0.0% -0.0% minimax 0.0% 0.0% -0.2% -1.0% 0.0% mkhprog 0.0% 0.0% -0.1% -0.2% -0.0% multiplier 0.0% 0.0% -0.0% -0.0% -0.0% n-body 0.0% 0.0% -0.0% -0.0% +0.0% nucleic2 0.0% 0.0% -0.1% -0.2% 0.0% para 0.0% 0.0% -0.0% -0.0% -0.0% paraffins 0.0% 0.0% -0.0% -0.0% 0.0% parser 0.0% 0.0% -0.2% -0.7% 0.0% parstof 0.0% 0.0% -0.0% -0.0% +0.0% pic 0.0% 0.0% -0.0% -0.0% 0.0% pidigits 0.0% 0.0% +0.0% +0.0% +0.0% power 0.0% 0.0% -0.2% -0.6% +0.0% pretty 0.0% 0.0% -0.0% -0.0% -0.0% primes 0.0% 0.0% -0.0% -0.0% 0.0% primetest 0.0% 0.0% -0.0% -0.0% -0.0% prolog 0.0% 0.0% -0.3% -1.1% 0.0% puzzle 0.0% 0.0% -0.0% -0.0% 0.0% queens 0.0% 0.0% -0.0% -0.0% +0.0% reptile 0.0% 0.0% -0.0% -0.0% 0.0% reverse-complem 0.0% 0.0% -0.0% -0.0% +0.0% rewrite 0.0% 0.0% -0.7% -2.5% -0.0% rfib 0.0% 0.0% -0.0% -0.0% 0.0% rsa 0.0% 0.0% -0.0% -0.0% 0.0% scc 0.0% 0.0% -0.1% -0.2% -0.0% sched 0.0% 0.0% -0.0% -0.0% -0.0% scs 0.0% 0.0% -1.0% -2.6% +0.0% simple 0.0% 0.0% +0.0% -0.0% +0.0% solid 0.0% 0.0% -0.0% -0.0% 0.0% sorting 0.0% 0.0% -0.6% -1.6% 0.0% spectral-norm 0.0% 0.0% +0.0% 0.0% +0.0% sphere 0.0% 0.0% -0.0% -0.0% -0.0% symalg 0.0% 0.0% -0.0% -0.0% +0.0% tak 0.0% 0.0% -0.0% -0.0% 0.0% transform 0.0% 0.0% -0.0% -0.0% 0.0% treejoin 0.0% 0.0% -0.0% -0.0% 0.0% typecheck 0.0% 0.0% -0.0% -0.0% +0.0% veritas +0.0% 0.0% -0.2% -0.4% +0.0% wang 0.0% 0.0% -0.0% -0.0% 0.0% wave4main 0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve1 0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve2 0.0% 0.0% -0.0% -0.0% +0.0% x2n1 0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min 0.0% 0.0% -2.2% -5.4% -0.0% Max +0.0% 0.0% +0.0% +0.0% +0.1% Geometric Mean -0.0% -0.0% -0.1% -0.3% +0.0% Metric increases micro benchmarks tracked in #17686: Metric Increase: T12150 T12234 T12425 T13035 T5837 T6048 T9233 Co-authored-by: Andreas Klebinger <klebinger.andreas at gmx.at> - - - - - 3b22b14a by Shayne Fletcher at 2020-06-10T04:15:01-04:00 Give Language a Bounded instance - - - - - 9454511b by Simon Peyton Jones at 2020-06-10T04:17:06-04:00 Optimisation in Unique.Supply This patch switches on -fno-state-hack in GHC.Types.Unique.Supply. It turned out that my fixes for #18078 (coercion floating) changed the optimisation pathway for mkSplitUniqSupply in such a way that we had an extra allocation inside the inner loop. Adding -fno-state-hack fixed that -- and indeed the loop in mkSplitUniqSupply is a classic example of the way in which -fno-state-hack can be bad; see #18238. Moreover, the new code is better than the old. They allocate the same, but the old code ends up with a partial application. The net effect is that the test perf/should_run/UniqLoop runs 20% faster! From 2.5s down to 2.0s. The allocation numbers are the same -- but elapsed time falls. Good! The bad thing about this is that it's terribly delicate. But at least it's a good example of such delicacy in action. There is a long Note [Optimising the unique supply] which now explains all this. - - - - - 6d49d5be by Simon Peyton Jones at 2020-06-10T04:17:06-04:00 Implement cast worker/wrapper properly The cast worker/wrapper transformation transforms x = e |> co into y = e x = y |> co This is done by the simplifier, but we were being careless about transferring IdInfo from x to y, and about what to do if x is a NOINLNE function. This resulted in a series of bugs: #17673, #18093, #18078. This patch fixes all that: * Main change is in GHC.Core.Opt.Simplify, and the new prepareBinding function, which does this cast worker/wrapper transform. See Note [Cast worker/wrappers]. * There is quite a bit of refactoring around prepareRhs, makeTrivial etc. It's nicer now. * Some wrappers from strictness and cast w/w, notably those for a function with a NOINLINE, should inline very late. There wasn't really a mechanism for that, which was an existing bug really; so I invented a new finalPhase = Phase (-1). It's used for all simplifier runs after the user-visible phase 2,1,0 have run. (No new runs of the simplifier are introduced thereby.) See new Note [Compiler phases] in GHC.Types.Basic; the main changes are in GHC.Core.Opt.Driver * Doing this made me trip over two places where the AnonArgFlag on a FunTy was being lost so we could end up with (Num a -> ty) rather than (Num a => ty) - In coercionLKind/coercionRKind - In contHoleType in the Simplifier I fixed the former by defining mkFunctionType and using it in coercionLKind/RKind. I could have done the same for the latter, but the information is almost to hand. So I fixed the latter by - adding sc_hole_ty to ApplyToVal (like ApplyToTy), - adding as_hole_ty to ValArg (like TyArg) - adding sc_fun_ty to StrictArg Turned out I could then remove ai_type from ArgInfo. This is just moving the deck chairs around, but it worked out nicely. See the new Note [AnonArgFlag] in GHC.Types.Var * When looking at the 'arity decrease' thing (#18093) I discovered that stable unfoldings had a much lower arity than the actual optimised function. That's what led to the arity-decrease message. Simple solution: eta-expand. It's described in Note [Eta-expand stable unfoldings] in GHC.Core.Opt.Simplify * I also discovered that unsafeCoerce wasn't being inlined if the context was boring. So (\x. f (unsafeCoerce x)) would create a thunk -- yikes! I fixed that by making inlineBoringOK a bit cleverer: see Note [Inline unsafeCoerce] in GHC.Core.Unfold. I also found that unsafeCoerceName was unused, so I removed it. I made a test case for #18078, and a very similar one for #17673. The net effect of all this on nofib is very modest, but positive: -------------------------------------------------------------------------------- Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- anna -0.4% -0.1% -3.1% -3.1% 0.0% fannkuch-redux -0.4% -0.3% -0.1% -0.1% 0.0% maillist -0.4% -0.1% -7.8% -1.0% -14.3% primetest -0.4% -15.6% -7.1% -6.6% 0.0% -------------------------------------------------------------------------------- Min -0.9% -15.6% -13.3% -14.2% -14.3% Max -0.3% 0.0% +12.1% +12.4% 0.0% Geometric Mean -0.4% -0.2% -2.3% -2.2% -0.1% All following metric decreases are compile-time allocation decreases between -1% and -3%: Metric Decrease: T5631 T13701 T14697 T15164 - - - - - 32fd37f5 by Luke Lau at 2020-06-10T04:17:22-04:00 Fix lookupGlobalOccRn_maybe sometimes reporting an error In some cases it was possible for lookupGlobalOccRn_maybe to return an error, when it should be returning a Nothing. If it called lookupExactOcc_either when there were no matching GlobalRdrElts in the otherwise case, it would return an error message. This could be caused when lookupThName_maybe in Template Haskell was looking in different namespaces (thRdrNameGuesses), guessing different namespaces that the name wasn't guaranteed to be found in. However, by addressing this some more accurate errors were being lost in the conversion to Maybes. So some of the lookup* functions have been shuffled about so that errors should always be ignored in lookup*_maybes, and propagated otherwise. This fixes #18263 - - - - - 9b283e1b by Roland Senn at 2020-06-10T04:17:34-04:00 Initialize the allocation counter in GHCi to 0 (Fixes #16012) According to the documentation for the function `getAllocationCounter` in [System.Mem](http://hackage.haskell.org/package/base-4.14.0.0/docs/System-Mem.html) initialize the allocationCounter also in GHCi to 0. - - - - - 8d07c48c by Sylvain Henry at 2020-06-10T04:17:36-04:00 test: fix conc038 We had spurious failures of conc038 test on CI with stdout: ``` newThread started -mainThread -Haskell: 2 newThread back again +mainThread 1 sec later shutting down +Haskell: 2 ``` - - - - - 4c7e9689 by Sebastian Graf at 2020-06-11T10:37:38+02:00 Release Notes: Add news from the pattern-match checker [skip ci] - - - - - 3445b965 by Sylvain Henry at 2020-06-13T02:13:01-04:00 Only test T16190 with the NCG T16190 is meant to test a NCG feature. It has already caused spurious failures in other MRs (e.g. !2165) when LLVM is used. - - - - - 2517a51c by Sylvain Henry at 2020-06-13T02:13:01-04:00 DynFlags refactoring VIII (#17957) * Remove several uses of `sdocWithDynFlags`, especially in GHC.Llvm.* * Add LlvmOpts datatype to store Llvm backend options * Remove Outputable instances (for LlvmVar, LlvmLit, LlvmStatic and Llvm.MetaExpr) which require LlvmOpts. * Rename ppMetaExpr into ppMetaAnnotExpr (pprMetaExpr is now used in place of `ppr :: MetaExpr -> SDoc`) - - - - - 7a02599a by Sylvain Henry at 2020-06-13T02:13:02-04:00 Remove unused code - - - - - 72d08610 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Refactor homeUnit * rename thisPackage into homeUnit * document and refactor several Backpack things - - - - - 8dc71f55 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Rename unsafeGetUnitInfo into unsafeLookupUnit - - - - - f6be6e43 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Add allowVirtualUnits field in PackageState Instead of always querying DynFlags to know whether we are allowed to use virtual units (i.e. instantiated on-the-fly, cf Note [About units] in GHC.Unit), we store it once for all in `PackageState.allowVirtualUnits`. This avoids using DynFlags too much (cf #17957) and is preliminary work for #14335. - - - - - e7272d53 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Enhance UnitId use * use UnitId instead of String to identify wired-in units * use UnitId instead of Unit in the backend (Unit are only use by Backpack to produce type-checked interfaces, not real code) * rename lookup functions for consistency * documentation - - - - - 9c5572cd by Sylvain Henry at 2020-06-13T02:13:02-04:00 Remove LinkerUnitId type alias - - - - - d345edfe by Sylvain Henry at 2020-06-13T02:13:02-04:00 Refactor WiredMap * Remove WiredInUnitId and WiredUnitId type aliases - - - - - 3d171cd6 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Document and refactor `mkUnit` and `mkUnitInfoMap` - - - - - d2109b4f by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove PreloadUnitId type alias - - - - - f50c19b8 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename listUnitInfoMap into listUnitInfo There is no Map involved - - - - - ed533ec2 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename Package into Unit The terminology changed over time and now package databases contain "units" (there can be several units compiled from a single Cabal package: one per-component, one for each option set, one per instantiation, etc.). We should try to be consistent internally and use "units": that's what this renaming does. Maybe one day we'll fix the UI too (e.g. replace -package-id with -unit-id, we already have -this-unit-id and ghc-pkg has -unit-id...) but it's not done in this patch. * rename getPkgFrameworkOpts into getUnitFrameworkOpts * rename UnitInfoMap into ClosureUnitInfoMap * rename InstalledPackageIndex into UnitInfoMap * rename UnusablePackages into UnusableUnits * rename PackagePrecedenceIndex into UnitPrecedenceMap * rename PackageDatabase into UnitDatabase * rename pkgDatabase into unitDatabases * rename pkgState into unitState * rename initPackages into initUnits * rename renamePackage into renameUnitInfo * rename UnusablePackageReason into UnusableUnitReason * rename getPackage* into getUnit* * etc. - - - - - 202728e5 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Make ClosureUnitInfoMap uses UnitInfoMap - - - - - 55b4263e by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove ClosureUnitInfoMap - - - - - 653d17bd by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename Package into Unit (2) * rename PackageState into UnitState * rename findWiredInPackages into findWiredInUnits * rename lookupModuleInAll[Packages,Units] * etc. - - - - - ae900605 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move dump_mod_map into initUnits - - - - - 598cc1dd by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move wiring of homeUnitInstantiations outside of mkUnitState - - - - - 437265eb by Sylvain Henry at 2020-06-13T02:13:03-04:00 Avoid timing module map dump in initUnits - - - - - 9400aa93 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove preload parameter of mkUnitState * Remove preload parameter (unused) * Don't explicitly return preloaded units: redundant because already returned as "preloadUnits" field of UnitState - - - - - 266bc3d9 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: refactor unwireUnit - - - - - 9e715c1b by Sylvain Henry at 2020-06-13T02:13:03-04:00 Document getPreloadUnitsAnd - - - - - bd5810dc by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: remove useless add_package parameter - - - - - 36e1daf0 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: make listVisibleModuleNames take a UnitState - - - - - 5226da37 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Refactor and document add_package - - - - - 4b53aac1 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Refactor and document closeUnitDeps - - - - - 42c054f6 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: findWiredInUnits - - - - - a444d01b by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: reportCycles, reportUnusable - - - - - 8408d521 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: merge_databases - - - - - fca2d25f by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: add UnitConfig datatype Avoid directly querying flags from DynFlags to build the UnitState. Instead go via UnitConfig so that we could reuse this to make another UnitState for plugins. - - - - - 4274688a by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move distrustAll into mkUnitState - - - - - 28d804e1 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Create helper upd_wired_in_home_instantiations - - - - - ac964c83 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Put database cache in UnitConfig - - - - - bfd0a78c by Sylvain Henry at 2020-06-13T02:13:03-04:00 Don't return preload units when we set DyNFlags Preload units can be retrieved in UnitState when needed (i.e. in GHCi) - - - - - 1fbb4bf5 by Sylvain Henry at 2020-06-13T02:13:03-04:00 NCGConfig: remove useless ncgUnitId field - - - - - c10ff7e7 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Doc: fix some comments - - - - - 456e17f0 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Bump haddock submodule and allow metric decrease Metric Decrease: T12150 T12234 T5837 Metric Increase: T16190 - - - - - 42953902 by Simon Peyton Jones at 2020-06-13T02:13:03-04:00 Trim the demand for recursive product types Ticket #18304 showed that we need to be very careful when exploring the demand (esp usage demand) on recursive product types. This patch solves the problem by trimming the demand on such types -- in effect, a form of "widening". See the Note [Trimming a demand to a type] in DmdAnal, which explains how I did this by piggy-backing on an existing mechansim for trimming demands becuase of GADTs. The significant payload of this patch is very small indeed: * Make GHC.Core.Opt.WorkWrap.Utils.typeShape use RecTcChecker to avoid looking through recursive types. But on the way * I found that ae_rec_tc was entirely inoperative and did nothing. So I removed it altogether from DmdAnal. * I moved some code around in DmdAnal and Demand. (There are no actual changes in dmdFix.) * I changed the API of DmsAnal.dmdAnalRhsLetDown to return a StrictSig rather than a decorated Id * I removed the dead function peelTsFuns from Demand Performance effects: Nofib: 0.0% changes. Not surprising, because they don't use recursive products Perf tests T12227: 1% increase in compiler allocation, becuase $cto gets w/w'd. It did not w/w before because it takes a deeply nested argument, so the worker gets too many args, so we abandon w/w altogether (see GHC.Core.Opt.WorkWrap.Utils.isWorkerSmallEnough) With this patch we trim the demands. That is not strictly necessary (since these Generic type constructors are like tuples -- they can't cause a loop) but the net result is that we now w/w $cto which is fine. UniqLoop: 16% decrease in /runtime/ allocation. The UniqSupply is a recursive product, so currently we abandon all strictness on 'churn'. With this patch 'churn' gets useful strictness, and we w/w it. Hooray Metric Decrease: UniqLoop Metric Increase: T12227 - - - - - 87d504f4 by Viktor Dukhovni at 2020-06-13T02:13:05-04:00 Add introductory prose for Data.Traversable - - - - - 9f09b608 by Oleg Grenrus at 2020-06-13T02:13:07-04:00 Fix #12073: Add MonadFix Q instance - - - - - 220c2d34 by Ben Gamari at 2020-06-13T02:13:07-04:00 testsuite: Increase size of T12150 As noted in #18319, this test was previously very fragile. Increase its size to make it more likely that its fails with its newly-increased acceptance threshold. Metric Increase: T12150 - - - - - 8bba1c26 by Ben Gamari at 2020-06-13T04:59:06-04:00 gitlab-ci: Always push perf notes Previously we ci.sh would run with `set -e` implying that we wouldn't push perf notes if the testsuite were to fail, even if it *only* failed due to perf notes. This rendered the whole performance testing story quite fragile as a single regressing commit would cause every successive commit to fail since a new baseline would not be uploaded. Fix this by ensuring that we always push performance notes. - - - - - 7a773f16 by Ben Gamari at 2020-06-13T15:10:55-04:00 gitlab-ci: Eliminate redundant push of CI metrics - - - - - a31218f7 by Ryan Scott at 2020-06-13T15:58:37-04:00 Use HsForAllTelescope to avoid inferred, visible foralls Currently, `HsForAllTy` permits the combination of `ForallVis` and `Inferred`, but you can't actually typecheck code that uses it (e.g., `forall {a} ->`). This patch refactors `HsForAllTy` to use a new `HsForAllTelescope` data type that makes a type-level distinction between visible and invisible `forall`s such that visible `forall`s do not track `Specificity`. That part of the patch is actually quite small; the rest is simply changing consumers of `HsType` to accommodate this new type. Fixes #18235. Bumps the `haddock` submodule. - - - - - c0e6dee9 by Tamar Christina at 2020-06-14T09:07:44-04:00 winio: Add Atomic Exchange PrimOp and implement Atomic Ptr exchanges. The initial version was rewritten by Tamar Christina. It was rewritten in large parts by Andreas Klebinger. Co-authored-by: Andreas Klebinger <klebinger.andreas at gmx.at> - - - - - 9a7462fb by Ben Gamari at 2020-06-14T15:35:23-04:00 codeGen: Don't discard live case binders in unsafeEqualityProof logic Previously CoreToStg would unconditionally discard cases of the form: case unsafeEqualityProof of wild { _ -> rhs } and rather replace the whole thing with `rhs`. However, in some cases (see #18227) the case binder is still live, resulting in unbound occurrences in `rhs`. Fix this by only discarding the case if the case binder is dead. Fixes #18227. - - - - - e4137c48 by Ben Gamari at 2020-06-14T15:35:23-04:00 testsuite: Add tests for #18227 T18227A is the original issue which gave rise to the ticket and depends upon bytestring. T18227B is a minimized reproducer. - - - - - 8bab9ff1 by Ben Gamari at 2020-06-14T15:35:59-04:00 hadrian: Fix rts include and library paths Fixes two bugs: * (?) and (<>) associated in a surprising way * We neglected to include libdw paths in the rts configure flags - - - - - bd761185 by Ben Gamari at 2020-06-14T15:35:59-04:00 hadrian: Drop redundant GHC arguments Cabal should already be passing this arguments to GHC. - - - - - 01f7052c by Peter Trommler at 2020-06-14T15:36:38-04:00 FFI: Fix pass small ints in foreign call wrappers The Haskell calling convention requires integer parameters smaller than wordsize to be promoted to wordsize (where the upper bits are don't care). To access such small integer parameter read a word from the parameter array and then cast that word to the small integer target type. Fixes #15933 - - - - - 502647f7 by Krzysztof Gogolewski at 2020-06-14T15:37:14-04:00 Fix "ndecreasingIndentation" in manual (#18116) - - - - - 9a9cc089 by Simon Jakobi at 2020-06-15T13:10:00-04:00 Use foldl' in unionManyUniqDSets - - - - - 761dcb84 by Moritz Angermann at 2020-06-15T13:10:36-04:00 Load .lo as well. Some archives contain so called linker objects, with the affectionate .lo suffic. For example the musl libc.a will come in that form. We still want to load those objects, hence we should not discard them and look for .lo as well. Ultimately we might want to fix this proerly by looking at the file magic. - - - - - cf01477f by Vladislav Zavialov at 2020-06-15T13:11:20-04:00 User's Guide: KnownNat evidence is Natural This bit of documentation got outdated after commit 1fcede43d2b30f33b7505e25eb6b1f321be0407f - - - - - d0dcbfe6 by Jan Hrček at 2020-06-16T20:36:38+02:00 Fix typos and formatting in user guide - - - - - 56a9e95f by Jan Hrček at 2020-06-16T20:36:38+02:00 Resolve TODO - - - - - 3e884d14 by Jan Hrček at 2020-06-16T20:36:38+02:00 Rename TcHoleErrors to GHC.Tc.Errors.Hole - - - - - d23fc678 by Stefan Schulze Frielinghaus at 2020-06-17T15:31:09-04:00 hadrian: Build with threaded runtime if available See #16873. - - - - - 0639dc10 by Sylvain Henry at 2020-06-17T15:31:53-04:00 T16190: only measure bytes_allocated Just adding `{-# LANGUAGE BangPatterns #-}` makes the two other metrics fluctuate by 13%. - - - - - 4cab6897 by Adam Sandberg Ericsson at 2020-06-17T15:32:44-04:00 docs: fix formatting in users guide - - - - - eb8115a8 by Sylvain Henry at 2020-06-17T15:33:23-04:00 Move CLabel assertions into smart constructors (#17957) It avoids using DynFlags in the Outputable instance of Clabel to check assertions at pretty-printing time. - - - - - 7faa4509 by Ben Gamari at 2020-06-17T15:43:31-04:00 base: Bump to 4.15.0.0 - - - - - 20616959 by Ben Gamari at 2020-06-17T15:43:31-04:00 configure: Use grep -q instead of --quiet The latter is apparently not supported by busybox. - - - - - 40fa237e by Krzysztof Gogolewski at 2020-06-17T16:21:58-04:00 Linear types (#15981) This is the first step towards implementation of the linear types proposal (https://github.com/ghc-proposals/ghc-proposals/pull/111). It features * A language extension -XLinearTypes * Syntax for linear functions in the surface language * Linearity checking in Core Lint, enabled with -dlinear-core-lint * Core-to-core passes are mostly compatible with linearity * Fields in a data type can be linear or unrestricted; linear fields have multiplicity-polymorphic constructors. If -XLinearTypes is disabled, the GADT syntax defaults to linear fields The following items are not yet supported: * a # m -> b syntax (only prefix FUN is supported for now) * Full multiplicity inference (multiplicities are really only checked) * Decent linearity error messages * Linear let, where, and case expressions in the surface language (each of these currently introduce the unrestricted variant) * Multiplicity-parametric fields * Syntax for annotating lambda-bound or let-bound with a multiplicity * Syntax for non-linear/multiple-field-multiplicity records * Linear projections for records with a single linear field * Linear pattern synonyms * Multiplicity coercions (test LinearPolyType) A high-level description can be found at https://ghc.haskell.org/trac/ghc/wiki/LinearTypes/Implementation Following the link above you will find a description of the changes made to Core. This commit has been authored by * Richard Eisenberg * Krzysztof Gogolewski * Matthew Pickering * Arnaud Spiwack With contributions from: * Mark Barbone * Alexander Vershilov Updates haddock submodule. - - - - - 6cb84c46 by Krzysztof Gogolewski at 2020-06-17T16:22:03-04:00 Various performance improvements This implements several general performance improvements to GHC, to offset the effect of the linear types change. General optimisations: - Add a `coreFullView` function which iterates `coreView` on the head. This avoids making function recursive solely because the iterate `coreView` themselves. As a consequence, this functions can be inlined, and trigger case-of-known constructor (_e.g._ `kindRep_maybe`, `isLiftedRuntimeRep`, `isMultiplicityTy`, `getTyVar_maybe`, `splitAppTy_maybe`, `splitFunType_maybe`, `tyConAppTyCon_maybe`). The common pattern about all these functions is that they are almost always used as views, and immediately consumed by a case expression. This commit also mark them asx `INLINE`. - In `subst_ty` add a special case for nullary `TyConApp`, which avoid allocations altogether. - Use `mkTyConApp` in `subst_ty` for the general `TyConApp`. This required quite a bit of module shuffling. case. `myTyConApp` enforces crucial sharing, which was lost during substitution. See also !2952 . - Make `subst_ty` stricter. - In `eqType` (specifically, in `nonDetCmpType`), add a special case, tested first, for the very common case of nullary `TyConApp`. `nonDetCmpType` has been made `INLINE` otherwise it is actually a regression. This is similar to the optimisations in !2952. Linear-type specific optimisations: - Use `tyConAppTyCon_maybe` instead of the more complex `eqType` in the definition of the pattern synonyms `One` and `Many`. - Break the `hs-boot` cycles between `Multiplicity.hs` and `Type.hs`: `Multiplicity` now import `Type` normally, rather than from the `hs-boot`. This way `tyConAppTyCon_maybe` can inline properly in the `One` and `Many` pattern synonyms. - Make `updateIdTypeAndMult` strict in its type and multiplicity - The `scaleIdBy` gets a specialised definition rather than being an alias to `scaleVarBy` - `splitFunTy_maybe` is given the type `Type -> Maybe (Mult, Type, Type)` instead of `Type -> Maybe (Scaled Type, Type)` - Remove the `MultMul` pattern synonym in favour of a view `isMultMul` because pattern synonyms appear not to inline well. - in `eqType`, in a `FunTy`, compare multiplicities last: they are almost always both `Many`, so it helps failing faster. - Cache `manyDataConTy` in `mkTyConApp`, to make sure that all the instances of `TyConApp ManyDataConTy []` are physically the same. This commit has been authored by * Richard Eisenberg * Krzysztof Gogolewski * Arnaud Spiwack Metric Decrease: haddock.base T12227 T12545 T12990 T1969 T3064 T5030 T9872b Metric Increase: haddock.base haddock.Cabal haddock.compiler T12150 T12234 T12425 T12707 T13035 T13056 T15164 T16190 T18304 T1969 T3064 T3294 T5631 T5642 T5837 T6048 T9020 T9233 T9675 T9872a T9961 WWRec - - - - - 57db91d8 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Remove integer-simple integer-simple uses lists of words (`[Word]`) to represent big numbers instead of ByteArray#: * it is less efficient than the newer ghc-bignum native backend * it isn't compatible with the big number representation that is now shared by all the ghc-bignum backends (based on the one that was used only in integer-gmp before). As a consequence, we simply drop integer-simple - - - - - 9f96bc12 by Sylvain Henry at 2020-06-17T16:22:03-04:00 ghc-bignum library ghc-bignum is a newer package that aims to replace the legacy integer-simple and integer-gmp packages. * it supports several backends. In particular GMP is still supported and most of the code from integer-gmp has been merged in the "gmp" backend. * the pure Haskell "native" backend is new and is much faster than the previous pure Haskell implementation provided by integer-simple * new backends are easier to write because they only have to provide a few well defined functions. All the other code is common to all backends. In particular they all share the efficient small/big number distinction previously used only in integer-gmp. * backends can all be tested against the "native" backend with a simple Cabal flag. Backends are only allowed to differ in performance, their results should be the same. * Add `integer-gmp` compat package: provide some pattern synonyms and function aliases for those in `ghc-bignum`. It is intended to avoid breaking packages that depend on `integer-gmp` internals. Update submodules: text, bytestring Metric Decrease: Conversions ManyAlternatives ManyConstructors Naperian T10359 T10547 T10678 T12150 T12227 T12234 T12425 T13035 T13719 T14936 T1969 T4801 T4830 T5237 T5549 T5837 T8766 T9020 parsing001 space_leak_001 T16190 haddock.base On ARM and i386, T17499 regresses (+6% > 5%). On x86_64 unregistered, T13701 sometimes regresses (+2.2% > 2%). Metric Increase: T17499 T13701 - - - - - 96aa5787 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update compiler Thanks to ghc-bignum, the compiler can be simplified: * Types and constructors of Integer and Natural can be wired-in. It means that we don't have to query them from interfaces. It also means that numeric literals don't have to carry their type with them. * The same code is used whatever ghc-bignum backend is enabled. In particular, conversion of bignum literals into final Core expressions is now much more straightforward. Bignum closure inspection too. * GHC itself doesn't depend on any integer-* package anymore * The `integerLibrary` setting is gone. - - - - - 0f67e344 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update `base` package * GHC.Natural isn't implemented in `base` anymore. It is provided by ghc-bignum in GHC.Num.Natural. It means that we can safely use Natural primitives in `base` without fearing issues with built-in rewrite rules (cf #15286) * `base` doesn't conditionally depend on an integer-* package anymore, it depends on ghc-bignum * Some duplicated code in integer-* can now be factored in GHC.Float * ghc-bignum tries to use a uniform naming convention so most of the other changes are renaming - - - - - aa9e7b71 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update `make` based build system * replace integer-* package selection with ghc-bignum backend selection - - - - - f817d816 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Update testsuite * support detection of slow ghc-bignum backend (to replace the detection of integer-simple use). There are still some test cases that the native backend doesn't handle efficiently enough. * remove tests for GMP only functions that have been removed from ghc-bignum * fix test results showing dependent packages (e.g. integer-gmp) or showing suggested instances * fix test using Integer/Natural API or showing internal names - - - - - dceecb09 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Update Hadrian * support ghc-bignum backend selection in flavours and command-line * support ghc-bignum "--check" flag (compare results of selected backend against results of the native one) in flavours and command-line (e.g. pass --bignum=check-gmp" to check the "gmp" backend) * remove the hack to workaround #15286 * build GMP only when the gmp backend is used * remove hacks to workaround `text` package flags about integer-*. We fix `text` to use ghc-bignum unconditionally in another patch - - - - - fa4281d6 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Bump bytestring and text submodules - - - - - 1a3f6f34 by Adam Sandberg Ericsson at 2020-06-18T23:03:36-04:00 docs: mention -hiedir in docs for -outputdir [skip ci] - - - - - 729bcb02 by Sylvain Henry at 2020-06-18T23:04:17-04:00 Hadrian: fix build on Mac OS Catalina (#17798) - - - - - 95e18292 by Andreas Klebinger at 2020-06-18T23:04:58-04:00 Relax allocation threshold for T12150. This test performs little work, so the most minor allocation changes often cause the test to fail. Increasing the threshold to 2% should help with this. - - - - - 8ce6c393 by Sebastian Graf at 2020-06-18T23:05:36-04:00 hadrian: Bump pinned cabal.project to an existent index-state - - - - - 08c1cb0f by Ömer Sinan Ağacan at 2020-06-18T23:06:21-04:00 Fix uninitialized field read in Linker.c Valgrind report of the bug when running the test `linker_unload`: ==29666== Conditional jump or move depends on uninitialised value(s) ==29666== at 0x369C5B4: setOcInitialStatus (Linker.c:1305) ==29666== by 0x369C6C5: mkOc (Linker.c:1347) ==29666== by 0x36C027A: loadArchive_ (LoadArchive.c:522) ==29666== by 0x36C0600: loadArchive (LoadArchive.c:626) ==29666== by 0x2C144CD: ??? (in /home/omer/haskell/ghc_2/testsuite/tests/rts/linker/linker_unload.run/linker_unload) ==29666== ==29666== Conditional jump or move depends on uninitialised value(s) ==29666== at 0x369C5B4: setOcInitialStatus (Linker.c:1305) ==29666== by 0x369C6C5: mkOc (Linker.c:1347) ==29666== by 0x369C9F6: preloadObjectFile (Linker.c:1507) ==29666== by 0x369CA8D: loadObj_ (Linker.c:1536) ==29666== by 0x369CB17: loadObj (Linker.c:1557) ==29666== by 0x3866BC: main (linker_unload.c:33) The problem is `mkOc` allocates a new `ObjectCode` and calls `setOcInitialStatus` without initializing the `status` field. `setOcInitialStatus` reads the field as first thing: static void setOcInitialStatus(ObjectCode* oc) { if (oc->status == OBJECT_DONT_RESOLVE) return; if (oc->archiveMemberName == NULL) { oc->status = OBJECT_NEEDED; } else { oc->status = OBJECT_LOADED; } } `setOcInitialStatus` is unsed in two places for two different purposes: in `mkOc` where we don't have the `status` field initialized yet (`mkOc` is supposed to initialize it), and `loadOc` where we do have `status` field initialized and we want to update it. Instead of splitting the function into two functions which are both called just once I inline the functions in the use sites and remove it. Fixes #18342 - - - - - da18ff99 by Tamar Christina at 2020-06-18T23:07:03-04:00 fix windows bootstrap due to linker changes - - - - - 2af0ec90 by Sylvain Henry at 2020-06-18T23:07:47-04:00 DynFlags: store default depth in SDocContext (#17957) It avoids having to use DynFlags to reach for pprUserLength. - - - - - d4a0be75 by Sylvain Henry at 2020-06-18T23:08:35-04:00 Move tablesNextToCode field into Platform tablesNextToCode is a platform setting and doesn't belong into DynFlags (#17957). Doing this is also a prerequisite to fix #14335 where we deal with two platforms (target and host) that may have different platform settings. - - - - - 809caedf by John Ericson at 2020-06-23T22:47:37-04:00 Switch from HscSource to IsBootInterface for module lookup in GhcMake We look up modules by their name, and not their contents. There is no way to separately reference a signature vs regular module; you get what you get. Only boot files can be referenced indepenently with `import {-# SOURCE #-}`. - - - - - 7750bd45 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Cmm: introduce SAVE_REGS/RESTORE_REGS We don't want to save both Fn and Dn register sets on x86-64 as they are aliased to the same arch register (XMMn). Moreover, when SAVE_STGREGS was used in conjunction with `jump foo [*]` which makes a set of Cmm registers alive so that they cover all arch registers used to pass parameter, we could have Fn, Dn and XMMn alive at the same time. It made the LLVM code generator choke (see #17920). Now `SAVE_REGS/RESTORE_REGS` and `jump foo [*]` use the same set of registers. - - - - - 2636794d by Sylvain Henry at 2020-06-23T22:48:18-04:00 CmmToC: don't add extern decl to parsed Cmm data Previously, if a .cmm file *not in the RTS* contained something like: ```cmm section "rodata" { msg : bits8[] "Test\n"; } ``` It would get compiled by CmmToC into: ```c ERW_(msg); const char msg[] = "Test\012"; ``` and fail with: ``` /tmp/ghc32129_0/ghc_4.hc:5:12: error: error: conflicting types for \u2018msg\u2019 const char msg[] = "Test\012"; ^~~ In file included from /tmp/ghc32129_0/ghc_4.hc:3:0: error: /tmp/ghc32129_0/ghc_4.hc:4:6: error: note: previous declaration of \u2018msg\u2019 was here ERW_(msg); ^ /builds/hsyl20/ghc/_build/install/lib/ghc-8.11.0.20200605/lib/../lib/x86_64-linux-ghc-8.11.0.20200605/rts-1.0/include/Stg.h:253:46: error: note: in definition of macro \u2018ERW_\u2019 #define ERW_(X) extern StgWordArray (X) ^ ``` See the rationale for this on https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/backends/ppr-c#prototypes Now we don't generate these extern declarations (ERW_, etc.) for top-level data. It shouldn't change anything for the RTS (the only place we use .cmm files) as it is already special cased in `GHC.Cmm.CLabel.needsCDecl`. And hand-written Cmm can use explicit extern declarations when needed. Note that it allows `cgrun069` test to pass with CmmToC (cf #15467). - - - - - 5f6a0665 by Sylvain Henry at 2020-06-23T22:48:18-04:00 LLVM: refactor and comment register padding code (#17920) - - - - - cad62ef1 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Add tests for #17920 Metric Decrease: T12150 T12234 - - - - - a2a9006b by Xavier Denis at 2020-06-23T22:48:56-04:00 Fix issue #18262 by zonking constraints after solving Zonk residual constraints in checkForExistence to reveal user type errors. Previously when `:instances` was used with instances that have TypeError constraints the result would look something like: instance [safe] s0 => Err 'A -- Defined at ../Bug2.hs:8:10 whereas after zonking, `:instances` now sees the `TypeError` and properly eliminates the constraint from the results. - - - - - 181516bc by Simon Peyton Jones at 2020-06-23T22:49:33-04:00 Fix a buglet in Simplify.simplCast This bug, revealed by #18347, is just a missing update to sc_hole_ty in simplCast. I'd missed a code path when I made the recentchanges in commit 6d49d5be904c0c01788fa7aae1b112d5b4dfaf1c Author: Simon Peyton Jones <simonpj at microsoft.com> Date: Thu May 21 12:53:35 2020 +0100 Implement cast worker/wrapper properly The fix is very easy. Two other minor changes * Tidy up in SimpleOpt.simple_opt_expr. In fact I think this is an outright bug, introduced in the fix to #18112: we were simplifying the same coercion twice *with the same substitution*, which is just wrong. It'd be a hard bug to trigger, so I just fixed it; less code too. * Better debug printing of ApplyToVal - - - - - 625a7f54 by Simon Peyton Jones at 2020-06-23T22:50:11-04:00 Two small tweaks to Coercion.simplifyArgsWorker These tweaks affect the inner loop of simplifyArgsWorker, which in turn is called from the flattener in Flatten.hs. This is a key perf bottleneck to T9872{a,b,c,d}. These two small changes have a modest but useful benefit. No change in functionality whatsoever. Relates to #18354 - - - - - b5768cce by Sylvain Henry at 2020-06-23T22:50:49-04:00 Don't use timesInt2# with GHC < 8.11 (fix #18358) - - - - - 7ad4085c by Sylvain Henry at 2020-06-23T22:51:27-04:00 Fix invalid printf format - - - - - a1f34d37 by Krzysztof Gogolewski at 2020-06-23T22:52:09-04:00 Add missing entry to freeNamesItem (#18369) - - - - - 03a708ba by Andreas Klebinger at 2020-06-25T03:54:37-04:00 Enable large address space optimization on windows. Starting with Win 8.1/Server 2012 windows no longer preallocates page tables for reserverd memory eagerly, which prevented us from using this approach in the past. We also try to allocate the heap high in the memory space. Hopefully this makes it easier to allocate things in the low 4GB of memory that need to be there. Like jump islands for the linker. - - - - - 7e6d3d09 by Roland Senn at 2020-06-25T03:54:38-04:00 In `:break ident` allow out of scope and nested identifiers (Fix #3000) This patch fixes the bug and implements the feature request of #3000. 1. If `Module` is a real module name and `identifier` a name of a top-level function in `Module` then `:break Module.identifer` works also for an `identifier` that is out of scope. 2. Extend the syntax for `:break identifier` to: :break [ModQual.]topLevelIdent[.nestedIdent]...[.nestedIdent] `ModQual` is optional and is either the effective name of a module or the local alias of a qualified import statement. `topLevelIdent` is the name of a top level function in the module referenced by `ModQual`. `nestedIdent` is optional and the name of a function nested in a let or where clause inside the previously mentioned function `nestedIdent` or `topLevelIdent`. If `ModQual` is a module name, then `topLevelIdent` can be any top level identifier in this module. If `ModQual` is missing or a local alias of a qualified import, then `topLevelIdent` must be in scope. Breakpoints can be set on arbitrarily deeply nested functions, but the whole chain of nested function names must be specified. 3. To support the new functionality rewrite the code to tab complete `:break`. - - - - - 30e42652 by Ben Gamari at 2020-06-25T03:54:39-04:00 make: Respect XELATEX variable Previously we simply ignored the XELATEX variable when building PDF documentation. - - - - - 4acc2934 by Ben Gamari at 2020-06-25T03:54:39-04:00 hadrian/make: Detect makeindex Previously we would simply assume that makeindex was available. Now we correctly detect it in `configure` and respect this conclusion in hadrian and make. - - - - - 0d61f866 by Simon Peyton Jones at 2020-06-25T03:54:40-04:00 Expunge GhcTcId GHC.Hs.Extension had type GhcPs = GhcPass 'Parsed type GhcRn = GhcPass 'Renamed type GhcTc = GhcPass 'Typechecked type GhcTcId = GhcTc The last of these, GhcTcId, is a vestige of the past. This patch expunges it from GHC. - - - - - 8ddbed4a by Adam Wespiser at 2020-06-25T03:54:40-04:00 add examples to Data.Traversable - - - - - 284001d0 by Oleg Grenrus at 2020-06-25T03:54:42-04:00 Export readBinIface_ - - - - - 90f43872 by Zubin Duggal at 2020-06-25T03:54:43-04:00 Export everything from HsToCore. This lets us reuse these functions in haddock, avoiding synchronization bugs. Also fixed some divergences with haddock in that file Updates haddock submodule - - - - - c7dd6da7 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part1) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Hs.* - GHC.Core.* - GHC.Stg.* - GHC.Cmm.* - GHC.Types.* - GHC.Data.* - GHC.Builtin.* - GHC.Parser.* - GHC.Driver.* - GHC top - - - - - 1eb997a8 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part2) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Iface.* - GHC.Llvm.* - GHC.Rename.* - GHC.Tc.* - GHC.HsToCore.* - GHC.StgToCmm.* - GHC.CmmToAsm.* - GHC.Runtime.* - GHC.Unit.* - GHC.Utils.* - GHC.SysTools.* - - - - - 67a86b4d by Oleg Grenrus at 2020-06-25T03:54:46-04:00 Add MonadZip and MonadFix instances for Complex These instances are taken from https://hackage.haskell.org/package/linear-1.21/docs/Linear-Instances.html They are the unique possible, so let they be in `base`. - - - - - c50ef26e by Artem Pelenitsyn at 2020-06-25T03:54:47-04:00 test suite: add reproducer for #17516 - - - - - fe281b27 by Roland Senn at 2020-06-25T03:54:48-04:00 Enable maxBound checks for OverloadedLists (Fixes #18172) Consider the Literal `[256] :: [Data.Word.Word8]` When the `OverloadedLists` extension is not active, then the `ol_ext` field in the `OverLitTc` record that is passed to the function `getIntegralLit` contains the type `Word8`. This is a simple type, and we can use its type constructor immediately for the `warnAboutOverflowedLiterals` function. When the `OverloadedLists` extension is active, then the `ol_ext` field contains the type family `Item [Word8]`. The function `nomaliseType` is used to convert it to the needed type `Word8`. - - - - - a788d4d1 by Ben Gamari at 2020-06-25T03:54:52-04:00 rts/Hash: Simplify freeing of HashListChunks While looking at #18348 I noticed that the treatment of HashLists are a bit more complex than necessary (which lead to some initial confusion on my part). Specifically, we allocate HashLists in chunks. Each chunk allocation makes two allocations: one for the chunk itself and one for a HashListChunk to link together the chunks for the purposes of freeing. Simplify this (and hopefully make the relationship between these clearer) but allocating the HashLists and HashListChunk in a single malloc. This will both make the implementation easier to follow and reduce C heap fragmentation. Note that even after this patch we fail to bound the size of the free HashList pool. However, this is a separate bug. - - - - - d3c2d59b by Sylvain Henry at 2020-06-25T03:54:55-04:00 RTS: avoid overflow on 32-bit arch (#18375) We're now correctly computing allocated bytes on 32-bit arch, so we get huge increases. Metric Increase: haddock.Cabal haddock.base haddock.compiler space_leak_001 - - - - - a3d69dc6 by Sebastian Graf at 2020-06-25T23:06:18-04:00 GHC.Core.Unify: Make UM actions one-shot by default This MR makes the UM monad in GHC.Core.Unify into a one-shot monad. See the long Note [The one-shot state monad trick]. See also #18202 and !3309, which applies this to all Reader/State-like monads in GHC for compile-time perf improvements. The pattern used here enables something similar to the state-hack, but is applicable to user-defined monads, not just `IO`. Metric Decrease 'runtime/bytes allocated' (test_env='i386-linux-deb9'): haddock.Cabal - - - - - 9ee58f8d by Matthias Pall Gissurarson at 2020-06-26T17:12:45+00:00 Implement the proposed -XQualifiedDo extension Co-authored-by: Facundo Domínguez <facundo.dominguez at tweag.io> QualifiedDo is implemented using the same placeholders for operation names in the AST that were devised for RebindableSyntax. Whenever the renamer checks which names to use for do syntax, it first checks if the do block is qualified (e.g. M.do { stmts }), in which case it searches for qualified names in the module M. This allows users to write {-# LANGUAGE QualifiedDo #-} import qualified SomeModule as M f x = M.do -- desugars to: y <- M.return x -- M.return x M.>>= \y -> M.return y -- M.return y M.>> M.return y -- M.return y See Note [QualifiedDo] and the users' guide for more details. Issue #18214 Proposal: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0216-qualified-do.rst Since we change the constructors `ITdo` and `ITmdo` to carry the new module name, we need to bump the haddock submodule to account or the new shape of these constructors. - - - - - ce987865 by Ryan Scott at 2020-06-27T11:55:21-04:00 Revamp the treatment of auxiliary bindings for derived instances This started as a simple fix for #18321 that organically grew into a much more sweeping refactor of how auxiliary bindings for derived instances are handled. I have rewritten `Note [Auxiliary binders]` in `GHC.Tc.Deriv.Generate` to explain all of the moving parts, but the highlights are: * Previously, the OccName of each auxiliary binding would be given a suffix containing a hash of its package name, module name, and parent data type to avoid name clashes. This was needlessly complicated, so we take the more direct approach of generating `Exact` `RdrName`s for each auxiliary binding with the same `OccName`, but using an underlying `System` `Name` with a fresh `Unique` for each binding. Unlike hashes, allocating new `Unique`s does not require any cleverness and avoid name clashes all the same... * ...speaking of which, in order to convince the renamer that multiple auxiliary bindings with the same `OccName` (but different `Unique`s) are kosher, we now use `rnLocalValBindsLHS` instead of `rnTopBindsLHS` to rename auxiliary bindings. Again, see `Note [Auxiliary binders]` for the full story. * I have removed the `DerivHsBind` constructor for `DerivStuff`—which was only used for `Data.Data`-related auxiliary bindings—and refactored `gen_Data_binds` to use `DerivAuxBind` instead. This brings the treatment of `Data.Data`-related auxiliary bindings in line with every other form of auxiliary binding. Fixes #18321. - - - - - a403eb91 by Sylvain Henry at 2020-06-27T11:55:59-04:00 ghc-bignum: fix division by zero (#18359) - - - - - 1b3d13b6 by Sylvain Henry at 2020-06-27T11:55:59-04:00 Fix ghc-bignum exceptions We must ensure that exceptions are not simplified. Previously we used: case raiseDivZero of _ -> 0## -- dummyValue But it was wrong because the evaluation of `raiseDivZero` was removed and the dummy value was directly returned. See new Note [ghc-bignum exceptions]. I've also removed the exception triggering primops which were fragile. We don't need them to be primops, we can have them exported by ghc-prim. I've also added a test for #18359 which triggered this patch. - - - - - a74ec37c by Simon Peyton Jones at 2020-06-27T11:56:34-04:00 Better loop detection in findTypeShape Andreas pointed out, in !3466, that my fix for #18304 was not quite right. This patch fixes it properly, by having just one RecTcChecker rather than (implicitly) two nested ones, in findTypeShape. - - - - - a04020b8 by Sylvain Henry at 2020-06-27T11:57:11-04:00 DynFlags: don't store buildTag `DynFlags.buildTag` was a field created from the set of Ways in `DynFlags.ways`. It had to be kept in sync with `DynFlags.ways` which was fragile. We want to avoid global state like this (#17957). Moreover in #14335 we also want to support loading units with different ways: target units would still use `DynFlags.ways` but plugins would use `GHC.Driver.Ways.hostFullWays`. To avoid having to deal both with build tag and with ways, we recompute the buildTag on-the-fly (should be pretty cheap) and we remove `DynFlags.buildTag` field. - - - - - 0e83efa2 by Krzysztof Gogolewski at 2020-06-27T11:57:49-04:00 Don't generalize when typechecking a tuple section The code is simpler and cleaner. - - - - - d8ba9e6f by Peter Trommler at 2020-06-28T09:19:11-04:00 RTS: Refactor Haskell-C glue for PPC 64-bit Make sure the stack is 16 byte aligned even when reserved stack bytes are not a multiple of 16 bytes. Avoid saving r2 (TOC). On ELF v1 the function descriptor of StgReturn has the same TOC as StgRun, on ELF v2 the TOC is recomputed in the function prologue. Use the ABI provided functions to save clobbered GPRs and FPRs. Improve comments. Describe what the stack looks like and how it relates to the respective ABIs. - - - - - 42f797b0 by Ryan Scott at 2020-06-28T09:19:46-04:00 Use NHsCoreTy to embed types into GND-generated code `GeneralizedNewtypeDeriving` is in the unique situation where it must produce an `LHsType GhcPs` from a Core `Type`. Historically, this was done with the `typeToLHsType` function, which walked over the entire `Type` and attempted to construct an `LHsType` with the same overall structure. `typeToLHsType` is quite complicated, however, and has been the subject of numerous bugs over the years (e.g., #14579). Luckily, there is an easier way to accomplish the same thing: the `XHsType` constructor of `HsType`. `XHsType` bundles an `NHsCoreTy`, which allows embedding a Core `Type` directly into an `HsType`, avoiding the need to laboriously convert from one to another (as `typeToLHsType` did). Moreover, renaming and typechecking an `XHsType` is simple, since one doesn't need to do anything to a Core `Type`... ...well, almost. For the reasons described in `Note [Typechecking NHsCoreTys]` in `GHC.Tc.Gen.HsType`, we must apply a substitution that we build from the local `tcl_env` type environment. But that's a relatively modest price to pay. Now that `GeneralizedNewtypeDeriving` uses `NHsCoreTy`, the `typeToLHsType` function no longer has any uses in GHC, so this patch rips it out. Some additional tweaks to `hsTypeNeedsParens` were necessary to make the new `-ddump-deriv` output correctly parenthesized, but other than that, this patch is quite straightforward. This is a mostly internal refactoring, although it is likely that `GeneralizedNewtypeDeriving`-generated code will now need fewer language extensions in certain situations than it did before. - - - - - 68530b1c by Jan Hrček at 2020-06-28T09:20:22-04:00 Fix duplicated words and typos in comments and user guide - - - - - 15b79bef by Ryan Scott at 2020-06-28T09:20:57-04:00 Add integer-gmp's ghc.mk and GNUmakefile to .gitignore - - - - - bfa5698b by Simon Peyton Jones at 2020-06-28T09:21:32-04:00 Fix a typo in Lint This simple error in GHC.Core.Litn.lintJoinLams meant that Lint reported bogus errors. Fixes #18399 - - - - - 71006532 by Ryan Scott at 2020-06-30T07:10:42-04:00 Reject nested foralls/contexts in instance types more consistently GHC is very wishy-washy about rejecting instance declarations with nested `forall`s or contexts that are surrounded by outermost parentheses. This can even lead to some strange interactions with `ScopedTypeVariables`, as demonstrated in #18240. This patch makes GHC more consistently reject instance types with nested `forall`s/contexts so as to prevent these strange interactions. On the implementation side, this patch tweaks `splitLHsInstDeclTy` and `getLHsInstDeclHead` to not look through parentheses, which can be semantically significant. I've added a `Note [No nested foralls or contexts in instance types]` in `GHC.Hs.Type` to explain why. This also introduces a `no_nested_foralls_contexts_err` function in `GHC.Rename.HsType` to catch nested `forall`s/contexts in instance types. This function is now used in `rnClsInstDecl` (for ordinary instance declarations) and `rnSrcDerivDecl` (for standalone `deriving` declarations), the latter of which fixes #18271. On the documentation side, this adds a new "Formal syntax for instance declaration types" section to the GHC User's Guide that presents a BNF-style grammar for what is and isn't allowed in instance types. Fixes #18240. Fixes #18271. - - - - - bccf3351 by Sylvain Henry at 2020-06-30T07:10:46-04:00 Add ghc-bignum to 8.12 release notes - - - - - 81704a6f by David Eichmann at 2020-06-30T07:10:48-04:00 Update ssh keys in CI performance metrics upload script - - - - - 85310fb8 by Joshua Price at 2020-06-30T07:10:49-04:00 Add missing Ix instances for tuples of size 6 through 15 (#16643) - - - - - cbb6b62f by Vladislav Zavialov at 2020-07-01T15:41:38-04:00 Implement -XLexicalNegation (GHC Proposal #229) This patch introduces a new extension, -XLexicalNegation, which detects whether the minus sign stands for negation or subtraction using the whitespace-based rules described in GHC Proposal #229. Updates haddock submodule. - - - - - fb5a0d01 by Martin Handley at 2020-07-01T15:42:14-04:00 #17169: Clarify Fixed's Enum instance. - - - - - b316804d by Simon Peyton Jones at 2020-07-01T15:42:49-04:00 Improve debug tracing for substitution This patch improves debug tracing a bit (#18395) * Remove the ancient SDoc argument to substitution, replacing it with a HasDebugCallStack constraint. The latter does the same job (indicate the call site) but much better. * Add HasDebugCallStack to simpleOptExpr, exprIsConApp_maybe I needed this to help nail the lookupIdSubst panic in #18326, #17784 - - - - - 5c9fabb8 by Hécate at 2020-07-01T15:43:25-04:00 Add most common return values for `os` and `arch` - - - - - 76d8cc74 by Ryan Scott at 2020-07-01T15:44:01-04:00 Desugar quoted uses of DerivingVia and expression type signatures properly The way that `GHC.HsToCore.Quote` desugared quoted `via` types (e.g., `deriving via forall a. [a] instance Eq a => Eq (List a)`) and explicit type annotations in signatures (e.g., `f = id @a :: forall a. a -> a`) was completely wrong, as it did not implement the scoping guidelines laid out in `Note [Scoped type variables in bindings]`. This is easily fixed. While I was in town, I did some minor cleanup of related Notes: * `Note [Scoped type variables in bindings]` and `Note [Scoped type variables in class and instance declarations]` say very nearly the same thing. I decided to just consolidate the two Notes into `Note [Scoped type variables in quotes]`. * `Note [Don't quantify implicit type variables in quotes]` is somewhat outdated, as it predates GHC 8.10, where the `forall`-or-nothing rule requires kind variables to be explicitly quantified in the presence of an explicit `forall`. As a result, the running example in that Note doesn't even compile. I have changed the example to something simpler that illustrates the same point that the original Note was making. Fixes #18388. - - - - - 44d6a335 by Andreas Klebinger at 2020-07-02T02:54:54-04:00 T16012: Be verbose on failure. - - - - - f9853330 by Ryan Scott at 2020-07-02T02:55:29-04:00 Bump ghc-prim version to 0.7.0 Fixes #18279. Bumps the `text` submodule. - - - - - 23e4e047 by Sylvain Henry at 2020-07-02T10:46:31-04:00 Hadrian: fix PowerPC64le support (#17601) [ci skip] - - - - - 3cdd8d69 by Sylvain Henry at 2020-07-02T10:47:08-04:00 NCG: correctly handle addresses with huge offsets (#15570) Before this patch we could generate addresses of this form: movzbl cP0_str+-9223372036854775808,%eax The linker can't handle them because the offset is too large: ld.lld: error: Main.o:(.text+0xB3): relocation R_X86_64_32S out of range: -9223372036852653050 is not in [-2147483648, 2147483647] With this patch we detect those cases and generate: movq $-9223372036854775808,%rax addq $cP0_str,%rax movzbl (%rax),%eax I've also refactored `getAmode` a little bit to make it easier to understand and to trace. - - - - - 4d90b3ff by Gabor Greif at 2020-07-02T20:07:59-04:00 No need for CURSES_INCLUDE_DIRS This is a leftover from ef63ff27251a20ff11e58c9303677fa31e609a88 - - - - - f08d6316 by Sylvain Henry at 2020-07-02T20:08:36-04:00 Replace Opt_SccProfilingOn flag with sccProfilingEnabled helper function SCC profiling was enabled in a convoluted way: if WayProf was enabled, Opt_SccProfilingOn general flag was set (in `GHC.Driver.Ways.wayGeneralFlags`), and then this flag was queried in various places. There is no need to go via general flags, so this patch defines a `sccProfilingEnabled :: DynFlags -> Bool` helper function that just checks whether WayProf is enabled. - - - - - 8cc7274b by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Only allocate the Censuses that we need When not LDV profiling there is no reason to allocate 32 Censuses; one will do. This is a very small memory footprint optimisation, but it comes for free. - - - - - b835112c by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Free old allocations when reinitialising Censuses Previously when not LDV profiling we would repeatedly reinitialise `censuses[0]` with `initEra`. This failed to free the `Arena` and `HashTable` from the old census, resulting in a memory leak. Fixes #18348. - - - - - 34be6523 by Valery Tolstov at 2020-07-03T02:50:03-04:00 Mention flags that are not enabled by -Wall (#18372) * Mention missing flags that are not actually enabled by -Wall (docs/users_guide/using-warnings.rst) * Additionally remove -Wmissing-monadfail-instances from the list of flags enabled by -Wcompat, as it is not the case since 8.8 - - - - - edc8d22b by Sylvain Henry at 2020-07-03T02:50:40-04:00 LLVM: support R9 and R10 registers d535ef006d85dbdb7cda2b09c5bc35cb80108909 allowed the use of up to 10 vanilla registers but didn't update LLVM backend to support them. This patch fixes it. - - - - - 4bf18646 by Simon Peyton Jones at 2020-07-03T08:37:42+01:00 Improve handling of data type return kinds Following a long conversation with Richard, this patch tidies up the handling of return kinds for data/newtype declarations (vanilla, family, and instance). I have substantially edited the Notes in TyCl, so they would bear careful reading. Fixes #18300, #18357 In GHC.Tc.Instance.Family.newFamInst we were checking some Lint-like properties with ASSSERT. Instead Richard and I have added a proper linter for axioms, and called it from lintGblEnv, which in turn is called in tcRnModuleTcRnM New tests (T18300, T18357) cause an ASSERT failure in HEAD. - - - - - 41d26492 by Sylvain Henry at 2020-07-03T17:33:59-04:00 DynFlags: avoid the use of sdocWithDynFlags in GHC.Core.Rules (#17957) - - - - - 7aa6ef11 by Hécate at 2020-07-03T17:34:36-04:00 Add the __GHC_FULL_VERSION__ CPP macro to expose the full GHC version - - - - - e61d5395 by Chaitanya Koparkar at 2020-07-07T13:55:59-04:00 ghc-prim: Turn some comments into haddocks [ci skip] - - - - - 37743f91 by John Ericson at 2020-07-07T13:56:00-04:00 Support `timesInt2#` in LLVM backend - - - - - 46397e53 by John Ericson at 2020-07-07T13:56:00-04:00 `genericIntMul2Op`: Call `genericWordMul2Op` directly This unblocks a refactor, and removes partiality. It might be a PowerPC regression but that should be fixable. - - - - - 8a1c0584 by John Ericson at 2020-07-07T13:56:00-04:00 Simplify `PrimopCmmEmit` Follow @simonpj's suggestion of pushing the "into regs" logic into `emitPrimOp`. With the previous commit getting rid of the recursion in `genericIntMul2Op`, this is now an easy refactor. - - - - - 6607f203 by John Ericson at 2020-07-07T13:56:00-04:00 `opAllDone` -> `opIntoRegs` The old name was and terrible and became worse after the previous commit's refactor moved non-trivial funcationlity into its body. - - - - - fdcc53ba by Sylvain Henry at 2020-07-07T13:56:00-04:00 Optimise genericIntMul2Op We shouldn't directly call 'genericWordMul2Op' in genericIntMul2Op because a target may provide a faster primop for 'WordMul2Op': we'd better use it! - - - - - 686e7225 by Moritz Angermann at 2020-07-07T13:56:01-04:00 [linker/rtsSymbols] More linker symbols Mostly symbols needed for aarch64/armv7l and in combination with musl, where we have to rely on loading *all* objects/archives - __stack_chk_* only when not DYNAMIC - - - - - 3f60b94d by Moritz Angermann at 2020-07-07T13:56:01-04:00 better if guards. - - - - - 7abffced by Moritz Angermann at 2020-07-07T13:56:01-04:00 Fix (1) - - - - - cdfeb3f2 by Moritz Angermann at 2020-07-07T13:56:01-04:00 AArch32 symbols only on aarch32. - - - - - f496c955 by Adam Sandberg Ericsson at 2020-07-07T13:56:02-04:00 add -flink-rts flag to link the rts when linking a shared or static library #18072 By default we don't link the RTS when linking shared libraries because in the most usual mode a shared library is an intermediary product, for example a Haskell library, that will be linked into some executable in the end. So we wish to defer the RTS flavour to link to the final link. However sometimes the final product is the shared library, for example when writing a plugin for some other system, so we do wish the shared library to link the RTS. For consistency we also make -staticlib honor this flag and its inversion. -staticlib currently implies -flink-shared. - - - - - c59faf67 by Stefan Schulze Frielinghaus at 2020-07-07T13:56:04-04:00 hadrian: link check-ppr against debugging RTS if ghcDebugged - - - - - 0effc57d by Adam Sandberg Ericsson at 2020-07-07T13:56:05-04:00 rts linker: teach the linker about GLIBC's special handling of *stat, mknod and atexit functions #7072 - - - - - 96153433 by Adam Sandberg Ericsson at 2020-07-07T13:56:06-04:00 hadrian: make hadrian/ghci use the bootstrap compiler from configure #18190 - - - - - 4d24f886 by Adam Sandberg Ericsson at 2020-07-07T13:56:07-04:00 hadrian: ignore cabal configure verbosity related flags #18131 - - - - - 7332bbff by Ben Gamari at 2020-07-07T13:56:08-04:00 testsuite: Widen T12234 acceptance window to 2% Previously it wasn't uncommon to see +/-1% fluctuations in compiler allocations on this test. - - - - - 180b6313 by Gabor Greif at 2020-07-07T13:56:08-04:00 When running libtool, report it as such - - - - - d3bd6897 by Sylvain Henry at 2020-07-07T13:56:11-04:00 BigNum: rename BigNat types Before this patch BigNat names were confusing because we had: * GHC.Num.BigNat.BigNat: unlifted type used everywhere else * GHC.Num.BigNat.BigNatW: lifted type only used to share static constants * GHC.Natural.BigNat: lifted type only used for backward compatibility After this patch we have: * GHC.Num.BigNat.BigNat#: unlifted type * GHC.Num.BigNat.BigNat: lifted type (reexported from GHC.Natural) Thanks to @RyanGlScott for spotting this. - - - - - 929d26db by Sylvain Henry at 2020-07-07T13:56:12-04:00 Bignum: don't build ghc-bignum with stage0 Noticed by @Ericson2314 - - - - - d25b6851 by Sylvain Henry at 2020-07-07T13:56:12-04:00 Hadrian: ghc-gmp.h shouldn't be a compiler dependency - - - - - 0ddae2ba by Sylvain Henry at 2020-07-07T13:56:14-04:00 DynFlags: factor out pprUnitId from "Outputable UnitId" instance - - - - - 204f3f5d by Krzysztof Gogolewski at 2020-07-07T13:56:18-04:00 Remove unused function pprHsForAllExtra (#18423) The function `pprHsForAllExtra` was called only on `Nothing` since 2015 (1e041b7382b6aa). - - - - - 3033e0e4 by Adam Sandberg Ericsson at 2020-07-08T20:36:49-04:00 hadrian: add flag to skip rebuilding dependency information #17636 - - - - - b7de4b96 by Stefan Schulze Frielinghaus at 2020-07-09T09:49:22-04:00 Fix GHCi :print on big-endian platforms On big-endian platforms executing import GHC.Exts data Foo = Foo Float# deriving Show foo = Foo 42.0# foo :print foo results in an arithmetic overflow exception which is caused by function index where moveBytes equals word_size - (r + item_size_b) * 8 Here we have a mixture of units. Both, word_size and item_size_b have unit bytes whereas r has unit bits. On 64-bit platforms moveBytes equals then 8 - (0 + 4) * 8 which results in a negative and therefore invalid second parameter for a shiftL operation. In order to make things more clear the expression (word .&. (mask `shiftL` moveBytes)) `shiftR` moveBytes is equivalent to (word `shiftR` moveBytes) .&. mask On big-endian platforms the shift must be a left shift instead of a right shift. For symmetry reasons not a mask is used but two shifts in order to zero out bits. Thus the fixed version equals case endian of BigEndian -> (word `shiftL` moveBits) `shiftR` zeroOutBits `shiftL` zeroOutBits LittleEndian -> (word `shiftR` moveBits) `shiftL` zeroOutBits `shiftR` zeroOutBits Fixes #16548 and #14455 - - - - - 3656dff8 by Sylvain Henry at 2020-07-09T09:50:01-04:00 LLVM: fix MO_S_Mul2 support (#18434) The value indicating if the carry is useful wasn't taken into account. - - - - - d9f09506 by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Define multiShotIO and use it in mkSplitUniqueSupply This patch is part of the ongoing eta-expansion saga; see #18238. It implements a neat trick (suggested by Sebastian Graf) that allows the programmer to disable the default one-shot behaviour of IO (the "state hack"). The trick is to use a new multiShotIO function; see Note [multiShotIO]. For now, multiShotIO is defined here in Unique.Supply; but it should ultimately be moved to the IO library. The change is necessary to get good code for GHC's unique supply; see Note [Optimising the unique supply]. However it makes no difference to GHC as-is. Rather, it makes a difference when a subsequent commit Improve eta-expansion using ArityType lands. - - - - - bce695cc by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Make arityType deal with join points As Note [Eta-expansion and join points] describes, this patch makes arityType deal correctly with join points. What was there before was not wrong, but yielded lower arities than it could. Fixes #18328 In base GHC this makes no difference to nofib. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- n-body -0.1% -0.1% -1.2% -1.1% 0.0% -------------------------------------------------------------------------------- Min -0.1% -0.1% -55.0% -56.5% 0.0% Max -0.0% 0.0% +16.1% +13.4% 0.0% Geometric Mean -0.0% -0.0% -30.1% -31.0% -0.0% But it starts to make real difference when we land the change to the way mkDupableAlts handles StrictArg, in fixing #13253 and friends. I think this is because we then get more non-inlined join points. - - - - - 2b7c71cb by Simon Peyton Jones at 2020-07-11T12:17:02-04:00 Improve eta-expansion using ArityType As #18355 shows, we were failing to preserve one-shot info when eta-expanding. It's rather easy to fix, by using ArityType more, rather than just Arity. This patch is important to suport the one-shot monad trick; see #18202. But the extra tracking of one-shot-ness requires the patch Define multiShotIO and use it in mkSplitUniqueSupply If that patch is missing, ths patch makes things worse in GHC.Types.Uniq.Supply. With it, however, we see these improvements T3064 compiler bytes allocated -2.2% T3294 compiler bytes allocated -1.3% T12707 compiler bytes allocated -1.3% T13056 compiler bytes allocated -2.2% Metric Decrease: T3064 T3294 T12707 T13056 - - - - - de139cc4 by Artem Pelenitsyn at 2020-07-12T02:53:20-04:00 add reproducer for #15630 - - - - - c4de6a7a by Andreas Klebinger at 2020-07-12T02:53:55-04:00 Give Uniq[D]FM a phantom type for its key. This fixes #17667 and should help to avoid such issues going forward. The changes are mostly mechanical in nature. With two notable exceptions. * The register allocator. The register allocator references registers by distinct uniques. However they come from the types of VirtualReg, Reg or Unique in various places. As a result we sometimes cast the key type of the map and use functions which operate on the now typed map but take a raw Unique as actual key. The logic itself has not changed it just becomes obvious where we do so now. * <Type>Env Modules. As an example a ClassEnv is currently queried using the types `Class`, `Name`, and `TyCon`. This is safe since for a distinct class value all these expressions give the same unique. getUnique cls getUnique (classTyCon cls) getUnique (className cls) getUnique (tcName $ classTyCon cls) This is for the most part contained within the modules defining the interface. However it requires us to play dirty when we are given a `Name` to lookup in a `UniqFM Class a` map. But again the logic did not change and it's for the most part hidden behind the Env Module. Some of these cases could be avoided by refactoring but this is left for future work. We also bump the haddock submodule as it uses UniqFM. - - - - - c2cfdfde by Aaron Allen at 2020-07-13T09:00:33-04:00 Warn about empty Char enumerations (#18402) Currently the "Enumeration is empty" warning (-Wempty-enumerations) only fires for numeric literals. This patch adds support for `Char` literals so that enumerating an empty list of `Char`s will also trigger the warning. - - - - - c3ac87ec by Stefan Schulze Frielinghaus at 2020-07-13T09:01:10-04:00 hadrian: build check-ppr dynamic if GHC is build dynamic Fixes #18361 - - - - - 9ad072b4 by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Use dumpStyle when printing inlinings This just makes debug-printing consistent, and more informative. - - - - - e78c4efb by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Comments only - - - - - 7ccb760b by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Reduce result discount in conSize Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c - - - - - 7f0b671e by Ben Gamari at 2020-07-13T14:52:49-04:00 testsuite: Widen acceptance threshold on T5837 This test is positively tiny and consequently the bytes allocated measurement will be relatively noisy. Consequently I have seen this fail spuriously quite often. - - - - - 118e1c3d by Alp Mestanogullari at 2020-07-14T21:30:52-04:00 compiler: re-engineer the treatment of rebindable if Executing on the plan described in #17582, this patch changes the way if expressions are handled in the compiler in the presence of rebindable syntax. We get rid of the SyntaxExpr field of HsIf and instead, when rebindable syntax is on, we rewrite the HsIf node to the appropriate sequence of applications of the local `ifThenElse` function. In order to be able to report good error messages, with expressions as they were written by the user (and not as desugared by the renamer), we make use of TTG extensions to extend GhcRn expression ASTs with an `HsExpansion` construct, which keeps track of a source (GhcPs) expression and the desugared (GhcRn) expression that it gives rise to. This way, we can typecheck the latter while reporting the former in error messages. In order to discard the error context lines that arise from typechecking the desugared expressions (because they talk about expressions that the user has not written), we carefully give a special treatment to the nodes fabricated by this new renaming-time transformation when typechecking them. See Note [Rebindable syntax and HsExpansion] for more details. The note also includes a recipe to apply the same treatment to other rebindable constructs. Tests 'rebindable11' and 'rebindable12' have been added to make sure we report identical error messages as before this patch under various circumstances. We also now disable rebindable syntax when processing untyped TH quotes, as per the discussion in #18102 and document the interaction of rebindable syntax and Template Haskell, both in Note [Template Haskell quotes and Rebindable Syntax] and in the user guide, adding a test to make sure that we do not regress in that regard. - - - - - 64c774b0 by Andreas Klebinger at 2020-07-14T21:31:27-04:00 Explain why keeping DynFlags in AnalEnv saves allocation. - - - - - 254245d0 by Ben Gamari at 2020-07-14T21:32:03-04:00 docs/users-guide: Update default -funfolding-use-threshold value This was changed in 3d2991f8 but I neglected to update the documentation. Fixes #18419. - - - - - 4c259f86 by Andreas Klebinger at 2020-07-14T21:32:41-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. - - - - - 23797224 by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 .gitlab: re-enable integer-simple substitute (BIGNUM_BACKEND) Recently build system migrated from INTEGER_LIBRARY to BIGNUM_BACKEND. But gitlab CI was never updated. Let's enable BIGNUM_BACKEND=native. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - e0db878a by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 ghc-bignum: bring in sync .hs-boot files with module declarations Before this change `BIGNUM_BACKEND=native` build was failing as: ``` libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs:708:16: error: * Variable not in scope: naturalFromBigNat# :: WordArray# -> t * Perhaps you meant one of these: `naturalFromBigNat' (imported from GHC.Num.Natural), `naturalToBigNat' (imported from GHC.Num.Natural) | 708 | m' = naturalFromBigNat# m | ``` This happens because `.hs-boot` files are slightly out of date. This change brings in data and function types in sync. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - c9f65c36 by Stefan Schulze Frielinghaus at 2020-07-14T21:33:57-04:00 rts/Disassembler.c: Use FMT_HexWord for printing values in hex format - - - - - 58ae62eb by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 macOS: Load frameworks without stating them first. macOS Big Sur makes the following change to how frameworks are shipped with the OS: > New in macOS Big Sur 11 beta, the system ships with a built-in > dynamic linker cache of all system-provided libraries. As part of > this change, copies of dynamic libraries are no longer present on > the filesystem. Code that attempts to check for dynamic library > presence by looking for a file at a path or enumerating a directory > will fail. Instead, check for library presence by attempting to > dlopen() the path, which will correctly check for the library in the > cache. (62986286) https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/ Therefore, the previous method of checking whether a library exists before attempting to load it makes GHC.Runtime.Linker.loadFramework fail to find frameworks installed at /System/Library/Frameworks. GHC.Runtime.Linker.loadFramework now opportunistically loads the framework libraries without checking for their existence first, failing only if all attempts to load a given framework from any of the various possible locations fail. - - - - - cdc4a6b0 by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 loadFramework: Output the errors collected in all loading attempts. With the recent change away from first finding and then loading a framework, loadFramework had no way of communicating the real reason why loadDLL failed if it was any reason other than the framework missing from the file system. It now collects all loading attempt errors into a list and concatenates them into a string to return to the caller. - - - - - 51dbfa52 by Ben Gamari at 2020-07-15T04:05:34-04:00 StgToCmm: Use CmmRegOff smart constructor Previously we would generate expressions of the form `CmmRegOff BaseReg 0`. This should do no harm (and really should be handled by the NCG anyways) but it's better to just generate a plain `CmmReg`. - - - - - ae11bdfd by Ben Gamari at 2020-07-15T04:06:08-04:00 testsuite: Add regression test for #17744 Test due to @monoidal. - - - - - 0e3c277a by Ben Gamari at 2020-07-15T16:41:01-04:00 Bump Cabal submodule Updates a variety of tests as Cabal is now more strict about Cabal file form. - - - - - ceed994a by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Drop Windows Vista support, require Windows 7 - - - - - 00a23bfd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Update Windows FileSystem wrapper utilities. - - - - - 459e1c5f by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Use SlimReaderLocks and ConditonalVariables provided by the OS instead of emulated ones - - - - - 763088fc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Small linker comment and ifdef cleanups - - - - - 1a228ff9 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Flush event logs eagerly. - - - - - e9e04dda by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Refactor Buffer structures to be able to track async operations - - - - - 356dc3fe by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Implement new Console API - - - - - 90e69f77 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add IOPort synchronization primitive - - - - - 71245fcc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add new io-manager cmdline options - - - - - d548a3b3 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Init Windows console Codepage to UTF-8. - - - - - 58ef6366 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add unsafeSplat to GHC.Event.Array - - - - - d660725e by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add size and iterate to GHC.Event.IntTable. - - - - - 050da6dd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Switch Testsuite to test winio by default - - - - - 4bf542bf by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Multiple refactorings and support changes. - - - - - 4489af6b by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core threaded I/O manager - - - - - 64d8f2fe by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core non-threaded I/O manager - - - - - 8da15a09 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix a scheduler bug with the threaded-runtime. - - - - - 84ea3d14 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Relaxing some constraints in io-manager. - - - - - ccf0d107 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix issues with non-threaded I/O manager after split. - - - - - b492fe6e by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Remove some barf statements that are a bit strict. - - - - - 01423fd2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Expand comments describing non-threaded loop - - - - - 4b69004f by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: fix FileSize unstat-able handles - - - - - 9b384270 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Implement new tempfile routines for winio - - - - - f1e0be82 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix input truncation when reading from handle. This was caused by not upholding the read buffer invariant that bufR == bufL == 0 for empty read buffers. - - - - - e176b625 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix output truncation for writes larger than buffer size - - - - - a831ce0e by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Rewrite bufWrite. I think it's far easier to follow the code now. It's also correct now as I had still missed a spot where we didn't update the offset. - - - - - 6aefdf62 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix offset set by bufReadEmpty. bufReadEmpty returns the bytes read *including* content that was already buffered, But for calculating the offset we only care about the number of bytes read into the new buffer. - - - - - 750ebaee by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Clean up code surrounding IOPort primitives. According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc. - - - - - ffd31db9 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix multi threaded threadDelay and a few other small changes. Multithreaded threadDelay suffered from a race condition based on the ioManagerStatus. Since the status isn't needed for WIO I removed it completely. This resulted in a light refactoring, as consequence we will always wake up the IO manager using interruptSystemManager, which uses `postQueuedCompletionStatus` internally. I also added a few comments which hopefully makes the code easier to dive into for the next person diving in. - - - - - 6ec26df2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 wionio: Make IO subsystem check a no-op on non-windows platforms. - - - - - 29bcd936 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Set handle offset when opening files in Append mode. Otherwise we would truncate the file. - - - - - 55c29700 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Remove debug event log trace - - - - - 9acb9f40 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix sqrt and openFile009 test cases - - - - - 57017cb7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Allow hp2ps to build with -DDEBUG - - - - - b8cd9995 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update output of T9681 since we now actually run it. - - - - - 10af5b14 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: A few more improvements to the IOPort primitives. - - - - - 39afc4a7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix expected tempfiles output. Tempfiles now works properly on windows, as such we can delete the win32 specific output. - - - - - 99db46e0 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Assign thread labels to IOManager threads. - - - - - be6af732 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Properly check for the tso of an incall to be zero. - - - - - e2c6dac7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark FD instances as unsupported under WINIO. - - - - - fd02ceed by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix threadDelay maxBound invocations. Instead of letting the ns timer overflow now clamp it at (maxBound :: Word64) ns. That still gives a few hundred years. - - - - - bc79f9f1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comments/cleanup an import in base - - - - - 1d197f4b by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark outstanding_service_requests volatile. As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration. - - - - - dc438186 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Make last_event a local variable - - - - - 2fc957c5 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comment about thread safety of processCompletion. - - - - - 4c026b6c by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: nonthreaded: Create io processing threads in main thread. We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread. - - - - - f47c7208 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add an exported isHeapAlloced function to the RTS - - - - - cc5d7bb1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Queue IO processing threads at the front of the queue. This will unblock the IO thread sooner hopefully leading to higher throughput in some situations. - - - - - e7630115 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: ThreadDelay001: Use higher resolution timer. - - - - - 451b5f96 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update T9681 output, disable T4808 on windows. T4808 tests functionality of the FD interface which won't be supported under WINIO. T9681 just has it's expected output tweaked. - - - - - dd06f930 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Wake io manager once per registerTimeout. Which is implicitly done in editTimeouts, so need to wake it up twice. - - - - - e87d0bf9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update placeholder comment with actual function name. - - - - - fc9025db by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Always lock win32 event queue - - - - - c24c9a1f by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Display thread labels when tracing scheduler events. - - - - - 06542b03 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Refactor non-threaded runner thread and scheduler interface. Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event. - - - - - 256299b1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove outstanding_requests from runner. We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port. - - - - - 3ebd8ad9 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Various fixes related to rebase and testdriver - - - - - 6be6bcba by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Fix rebase artifacts - - - - - 2c649dc3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename unsafeSplat to unsafeCopyFromBuffer - - - - - a18b73f3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove unused size/iterate operations from IntTable - - - - - 16bab48e by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Detect running IO Backend via peeking at RtsConfig - - - - - 8b8405a0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update temp path so GCC etc can handle it. Also fix PIPE support, clean up error casting, fix memory leaks - - - - - 2092bc54 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Minor comments/renamings - - - - - a5b5b6c0 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Checking if an error code indicates completion is now a function. - - - - - 362176fd by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Small refactor in withOverlappedEx - - - - - 32e20597 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: A few comments and commented out dbxIO - - - - - a4bfc1d9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't drop buffer offset in byteView/cwcharView - - - - - b3ad2a54 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: revert BHandle changes. - - - - - 3dcd87e2 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Fix imports - - - - - 5a371890 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update ghc-cabal to handle new Cabal submodule bump - - - - - d07ebe0d by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Only compile sources on Windows - - - - - dcb42393 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Actually return Nothing on EOF for non-blocking read - - - - - 895a3beb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate logic in encodeMultiByte[Raw]IO. - - - - - e06e6734 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate openFile logic - - - - - b59430c0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: fix -werror issue in encoding file - - - - - f8d39a51 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't mention windows specific functions when building on Linux. - - - - - 6a533d2a by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add a note about file locking in the RTS. - - - - - cf37ce34 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Add version to @since annotation - - - - - 0fafa2eb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename GHC.Conc.IOCP -> GHC.Conc.WinIO - - - - - 1854fc23 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Expand GHC.Conc.POSIX description It now explains users may not use these functions when using the old IO manager. - - - - - fcc7ba41 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Fix potential spaceleak in __createUUIDTempFileErrNo - - - - - 6b3fd9fa by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant -Wno-missing-signatures pragmas - - - - - 916fc861 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Make it explicit that we only create one IO manager - - - - - f260a721 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Note why we don't use blocking waits. - - - - - aa0a4bbf by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove commented out pragma - - - - - d679b544 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant buffer write in Handle/Text.hs:bufReadEmpty - - - - - d3f94368 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename SmartHandles to StdHandles - - - - - bd6b8ec1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add comment stating failure behaviour for getUniqueFileInfo. - - - - - 12846b85 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update IOPort haddocks. - - - - - 9f39fb14 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Add a note cross reference - - - - - 62dd5a73 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Name Haskell/OS I/O Manager explicitly in Note - - - - - fa807828 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Expand BlockedOnIOCompletion description. - - - - - f0880a1d by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove historical todos - - - - - 8e58e714 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Update note, remove debugging pragma. - - - - - aa4d84d5 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: flushCharReadBuffer shouldn't need to adjust offsets. - - - - - e580893a by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove obsolete comment about cond. variables - - - - - d54e9d79 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix initial linux validate build - - - - - 3cd4de46 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix ThreadDelay001 CPP - - - - - c88b1b9f by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix openFile009 merge conflict leftover - - - - - 849e8889 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept T9681 output. GHC now reports String instead of [Char]. - - - - - e7701818 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix cabal006 after upgrading cabal submodule Demand cabal 2.0 syntax instead of >= 1.20 as required by newer cabal versions. - - - - - a44f0373 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix stderr output for ghci/linking/dyn tests. We used to filter rtsopts, i opted to instead just accept the warning of it having no effect. This works both for -rtsopts, as well as -with-rtsopts which winio adds. - - - - - 515d9896 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T15261b stdout for --io-manager flag. - - - - - 949aaacc by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T5435_dyn_asm stderr The warning about rtsopts having no consequences is expected. So accept new stderr. - - - - - 7d424e1e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Also accept T7037 stderr - - - - - 1f009768 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal04 by filtering rts args - - - - - 981a9f2e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal01 by accepting expected stderr - - - - - b7b0464e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix safePkg01 by accepting expected stderr - - - - - 32734b29 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix T5435_dyn_gcc by accepting expected stderr - - - - - acc5cebf by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix tempfiles test on linux - - - - - c577b789 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for T3807 - - - - - c108c527 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload - - - - - 2b0b9a08 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload_multiple_objs - - - - - 67afb03c by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify wording on conditional variables. - - - - - 3bd41572 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify comment on cooked mode. - - - - - ded58a03 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: update lockfile signature and remove mistaken symbol in rts. - - - - - 2143c492 by Ben Gamari at 2020-07-15T16:41:04-04:00 testsuite: Add winio and winio_threaded ways Reverts many of the testsuite changes - - - - - c0979cc5 by Ben Gamari at 2020-07-16T10:56:54-04:00 Merge remote-tracking branch 'origin/wip/winio' - - - - - 750a1595 by Ben Gamari at 2020-07-18T07:26:41-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. - - - - - 6ba6a881 by Hécate at 2020-07-18T07:26:42-04:00 Implement `fullCompilerVersion` Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403 This MR adds `fullCompilerVersion`, a function that shares the same backend as the `--numeric-version` GHC flag, exposing a full, three-digit version datatype. - - - - - e6cf27df by Hécate at 2020-07-18T07:26:43-04:00 Add a Lint hadrian rule and an .hlint.yaml file in base/ - - - - - bcb177dd by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Allow multiple case branches to have a higher rank type As #18412 points out, it should be OK for multiple case alternatives to have a higher rank type, provided they are all the same. This patch implements that change. It sweeps away GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it with an enhanced version of fillInferResult. The basic change to fillInferResult is to permit the case in which another case alternative has already filled in the result; and in that case simply unify. It's very simple actually. See the new Note [fillInferResult] in TcMType Other refactoring: - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType (previously some of it was in Unify) - Move tcInstType and friends from TcMType to Instantiate, where it more properly belongs. (TCMType was getting very long.) - - - - - e5525a51 by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Improve typechecking of NPlusK patterns This patch (due to Richard Eisenberg) improves documentation of the wrapper returned by tcSubMult (see Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify). And, more substantially, it cleans up the multiplicity handling in the typechecking of NPlusKPat - - - - - 12f90352 by Krzysztof Gogolewski at 2020-07-18T07:26:45-04:00 Remove {-# CORE #-} pragma (part of #18048) This pragma has no effect since 2011. It was introduced for External Core, which no longer exists. Updates haddock submodule. - - - - - e504c913 by Simon Peyton Jones at 2020-07-18T07:26:45-04:00 Refactor the simplification of join binders This MR (for #18449) refactors the Simplifier's treatment of join-point binders. Specifically, it puts together, into GHC.Core.Opt.Simplify.Env.adjustJoinPointType two currently-separate ways in which we adjust the type of a join point. As the comment says: -- (adjustJoinPointType mult new_res_ty join_id) does two things: -- -- 1. Set the return type of the join_id to new_res_ty -- See Note [Return type for join points] -- -- 2. Adjust the multiplicity of arrows in join_id's type, as -- directed by 'mult'. See Note [Scaling join point arguments] I think this actually fixes a latent bug, by ensuring that the seIdSubst and seInScope have the right multiplicity on the type of join points. I did some tidying up while I was at it. No more setJoinResTy, or modifyJoinResTy: instead it's done locally in Simplify.Env.adjustJoinPointType - - - - - 49b265f0 by Chaitanya Koparkar at 2020-07-18T07:26:46-04:00 Fix minor typos in a Core.hs note - - - - - 8d59aed6 by Stefan Schulze Frielinghaus at 2020-07-18T07:26:47-04:00 GHCi: Fix isLittleEndian - - - - - c26e81d1 by Ben Gamari at 2020-07-18T07:26:47-04:00 testsuite: Mark ghci tests as fragile under unreg compiler In particular I have seen T16012 fail repeatedly under the unregisterised compiler. - - - - - 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 293c7fba by Sylvain Henry at 2020-08-21T09:36:38-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - 50eb4460 by Sylvain Henry at 2020-08-21T09:36:38-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 659eb31b by Sylvain Henry at 2020-08-21T09:36:38-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 2d8ca917 by Sylvain Henry at 2020-08-21T09:37:15-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - fddddbf4 by Vladislav Zavialov at 2020-08-21T09:37:49-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - f4fa3969 by Ben Gamari at 2020-08-24T17:04:55-04:00 configure: Fix whitespace - - - - - b0755f8a by Ben Gamari at 2020-08-24T17:39:20-04:00 gitlab-ci: More intelligent detection of locale availability Previously ci.sh would unconditionally use C.UTF-8. However, this fails on Centos 7, which appears not to provide this locale. Now we first try C.UTF-8, then try en_US.UTF-8, then fail. Works around #18607. - - - - - c8e48545 by Ben Gamari at 2020-08-24T17:42:10-04:00 gitlab-ci: Rename RELEASE variable to RELEASE_JOB This interfered with the autoconf variable of the same name, breaking pre-release builds. - - - - - 17 changed files: - .ghcid - + .git-ignore-revs - .gitlab-ci.yml - + .gitlab/ci.sh - − .gitlab/darwin-init.sh - .gitlab/linters/check-cpp.py - .gitlab/merge_request_templates/merge-request.md - − .gitlab/prepare-system.sh - − .gitlab/push-test-metrics.sh - + .gitlab/test-metrics.sh - − .gitlab/win32-init.sh - .gitmodules - CODEOWNERS - HACKING.md - Makefile - aclocal.m4 - boot The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d5f7ad47caa57b4cdc81a141b6a150fb4b817a41...c8e48545b2cd434f42aec08ede46f4812623a59a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d5f7ad47caa57b4cdc81a141b6a150fb4b817a41...c8e48545b2cd434f42aec08ede46f4812623a59a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 21:48:52 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 17:48:52 -0400 Subject: [Git][ghc/ghc][wip/ci-fixes] 2 commits: gitlab-ci: Bump Windows toolchain version Message-ID: <5f4435c4407b5_80b3f8495bc8b0492561f@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/ci-fixes at Glasgow Haskell Compiler / GHC Commits: 91b1478c by Ben Gamari at 2020-08-24T17:48:03-04:00 gitlab-ci: Bump Windows toolchain version This should have been done when we bumped the bootstrap compiler to 8.8.4. - - - - - 0da276d6 by Ben Gamari at 2020-08-24T17:48:46-04:00 gitlab-ci: Drop Windows make job These are a significant burden on our CI resources and end up failing quite often due to #18274. Here I drop the make jobs during validaion; it is now run only during the nightly builds. - - - - - 1 changed file: - .gitlab-ci.yml Changes: ===================================== .gitlab-ci.yml ===================================== @@ -6,7 +6,7 @@ variables: # Sequential version number capturing the versions of all tools fetched by # .gitlab/ci.sh. - WINDOWS_TOOLCHAIN_VERSION: 1 + WINDOWS_TOOLCHAIN_VERSION: 2 # Disable shallow clones; they break our linting rules GIT_DEPTH: 0 @@ -866,9 +866,6 @@ validate-x86_64-windows-hadrian: cache: key: "x86_64-windows-$WINDOWS_TOOLCHAIN_VERSION" -validate-x86_64-windows: - extends: .build-x86_64-windows-make - nightly-x86_64-windows: <<: *nightly extends: .build-x86_64-windows-make @@ -879,13 +876,13 @@ nightly-x86_64-windows: # Normal Windows validate builds are profiled; that won't do for releases. release-x86_64-windows: <<: *release - extends: validate-x86_64-windows + extends: .build-x86_64-windows-make variables: BUILD_FLAVOUR: "perf" # release-x86_64-windows-integer-simple: <<: *release - extends: validate-x86_64-windows + extends: .build-x86_64-windows-make variables: BIGNUM_BACKEND: native BUILD_FLAVOUR: "perf" @@ -940,7 +937,7 @@ doc-tarball: image: "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb9:$DOCKER_REV" dependencies: - validate-x86_64-linux-deb9-debug - - validate-x86_64-windows + - validate-x86_64-windows-hadrian variables: LINUX_BINDIST: "ghc-x86_64-deb9-linux-debug.tar.xz" WINDOWS_BINDIST: "ghc-x86_64-mingw32.tar.xz" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c8e48545b2cd434f42aec08ede46f4812623a59a...0da276d60a56096a224b56e67786071c9e8b8b00 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c8e48545b2cd434f42aec08ede46f4812623a59a...0da276d60a56096a224b56e67786071c9e8b8b00 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 22:04:18 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 18:04:18 -0400 Subject: [Git][ghc/ghc][wip/T15616] 403 commits: Switch from HscSource to IsBootInterface for module lookup in GhcMake Message-ID: <5f44396213859_80b3f84693c1eb492683ae@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/T15616 at Glasgow Haskell Compiler / GHC Commits: 809caedf by John Ericson at 2020-06-23T22:47:37-04:00 Switch from HscSource to IsBootInterface for module lookup in GhcMake We look up modules by their name, and not their contents. There is no way to separately reference a signature vs regular module; you get what you get. Only boot files can be referenced indepenently with `import {-# SOURCE #-}`. - - - - - 7750bd45 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Cmm: introduce SAVE_REGS/RESTORE_REGS We don't want to save both Fn and Dn register sets on x86-64 as they are aliased to the same arch register (XMMn). Moreover, when SAVE_STGREGS was used in conjunction with `jump foo [*]` which makes a set of Cmm registers alive so that they cover all arch registers used to pass parameter, we could have Fn, Dn and XMMn alive at the same time. It made the LLVM code generator choke (see #17920). Now `SAVE_REGS/RESTORE_REGS` and `jump foo [*]` use the same set of registers. - - - - - 2636794d by Sylvain Henry at 2020-06-23T22:48:18-04:00 CmmToC: don't add extern decl to parsed Cmm data Previously, if a .cmm file *not in the RTS* contained something like: ```cmm section "rodata" { msg : bits8[] "Test\n"; } ``` It would get compiled by CmmToC into: ```c ERW_(msg); const char msg[] = "Test\012"; ``` and fail with: ``` /tmp/ghc32129_0/ghc_4.hc:5:12: error: error: conflicting types for \u2018msg\u2019 const char msg[] = "Test\012"; ^~~ In file included from /tmp/ghc32129_0/ghc_4.hc:3:0: error: /tmp/ghc32129_0/ghc_4.hc:4:6: error: note: previous declaration of \u2018msg\u2019 was here ERW_(msg); ^ /builds/hsyl20/ghc/_build/install/lib/ghc-8.11.0.20200605/lib/../lib/x86_64-linux-ghc-8.11.0.20200605/rts-1.0/include/Stg.h:253:46: error: note: in definition of macro \u2018ERW_\u2019 #define ERW_(X) extern StgWordArray (X) ^ ``` See the rationale for this on https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/backends/ppr-c#prototypes Now we don't generate these extern declarations (ERW_, etc.) for top-level data. It shouldn't change anything for the RTS (the only place we use .cmm files) as it is already special cased in `GHC.Cmm.CLabel.needsCDecl`. And hand-written Cmm can use explicit extern declarations when needed. Note that it allows `cgrun069` test to pass with CmmToC (cf #15467). - - - - - 5f6a0665 by Sylvain Henry at 2020-06-23T22:48:18-04:00 LLVM: refactor and comment register padding code (#17920) - - - - - cad62ef1 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Add tests for #17920 Metric Decrease: T12150 T12234 - - - - - a2a9006b by Xavier Denis at 2020-06-23T22:48:56-04:00 Fix issue #18262 by zonking constraints after solving Zonk residual constraints in checkForExistence to reveal user type errors. Previously when `:instances` was used with instances that have TypeError constraints the result would look something like: instance [safe] s0 => Err 'A -- Defined at ../Bug2.hs:8:10 whereas after zonking, `:instances` now sees the `TypeError` and properly eliminates the constraint from the results. - - - - - 181516bc by Simon Peyton Jones at 2020-06-23T22:49:33-04:00 Fix a buglet in Simplify.simplCast This bug, revealed by #18347, is just a missing update to sc_hole_ty in simplCast. I'd missed a code path when I made the recentchanges in commit 6d49d5be904c0c01788fa7aae1b112d5b4dfaf1c Author: Simon Peyton Jones <simonpj at microsoft.com> Date: Thu May 21 12:53:35 2020 +0100 Implement cast worker/wrapper properly The fix is very easy. Two other minor changes * Tidy up in SimpleOpt.simple_opt_expr. In fact I think this is an outright bug, introduced in the fix to #18112: we were simplifying the same coercion twice *with the same substitution*, which is just wrong. It'd be a hard bug to trigger, so I just fixed it; less code too. * Better debug printing of ApplyToVal - - - - - 625a7f54 by Simon Peyton Jones at 2020-06-23T22:50:11-04:00 Two small tweaks to Coercion.simplifyArgsWorker These tweaks affect the inner loop of simplifyArgsWorker, which in turn is called from the flattener in Flatten.hs. This is a key perf bottleneck to T9872{a,b,c,d}. These two small changes have a modest but useful benefit. No change in functionality whatsoever. Relates to #18354 - - - - - b5768cce by Sylvain Henry at 2020-06-23T22:50:49-04:00 Don't use timesInt2# with GHC < 8.11 (fix #18358) - - - - - 7ad4085c by Sylvain Henry at 2020-06-23T22:51:27-04:00 Fix invalid printf format - - - - - a1f34d37 by Krzysztof Gogolewski at 2020-06-23T22:52:09-04:00 Add missing entry to freeNamesItem (#18369) - - - - - 03a708ba by Andreas Klebinger at 2020-06-25T03:54:37-04:00 Enable large address space optimization on windows. Starting with Win 8.1/Server 2012 windows no longer preallocates page tables for reserverd memory eagerly, which prevented us from using this approach in the past. We also try to allocate the heap high in the memory space. Hopefully this makes it easier to allocate things in the low 4GB of memory that need to be there. Like jump islands for the linker. - - - - - 7e6d3d09 by Roland Senn at 2020-06-25T03:54:38-04:00 In `:break ident` allow out of scope and nested identifiers (Fix #3000) This patch fixes the bug and implements the feature request of #3000. 1. If `Module` is a real module name and `identifier` a name of a top-level function in `Module` then `:break Module.identifer` works also for an `identifier` that is out of scope. 2. Extend the syntax for `:break identifier` to: :break [ModQual.]topLevelIdent[.nestedIdent]...[.nestedIdent] `ModQual` is optional and is either the effective name of a module or the local alias of a qualified import statement. `topLevelIdent` is the name of a top level function in the module referenced by `ModQual`. `nestedIdent` is optional and the name of a function nested in a let or where clause inside the previously mentioned function `nestedIdent` or `topLevelIdent`. If `ModQual` is a module name, then `topLevelIdent` can be any top level identifier in this module. If `ModQual` is missing or a local alias of a qualified import, then `topLevelIdent` must be in scope. Breakpoints can be set on arbitrarily deeply nested functions, but the whole chain of nested function names must be specified. 3. To support the new functionality rewrite the code to tab complete `:break`. - - - - - 30e42652 by Ben Gamari at 2020-06-25T03:54:39-04:00 make: Respect XELATEX variable Previously we simply ignored the XELATEX variable when building PDF documentation. - - - - - 4acc2934 by Ben Gamari at 2020-06-25T03:54:39-04:00 hadrian/make: Detect makeindex Previously we would simply assume that makeindex was available. Now we correctly detect it in `configure` and respect this conclusion in hadrian and make. - - - - - 0d61f866 by Simon Peyton Jones at 2020-06-25T03:54:40-04:00 Expunge GhcTcId GHC.Hs.Extension had type GhcPs = GhcPass 'Parsed type GhcRn = GhcPass 'Renamed type GhcTc = GhcPass 'Typechecked type GhcTcId = GhcTc The last of these, GhcTcId, is a vestige of the past. This patch expunges it from GHC. - - - - - 8ddbed4a by Adam Wespiser at 2020-06-25T03:54:40-04:00 add examples to Data.Traversable - - - - - 284001d0 by Oleg Grenrus at 2020-06-25T03:54:42-04:00 Export readBinIface_ - - - - - 90f43872 by Zubin Duggal at 2020-06-25T03:54:43-04:00 Export everything from HsToCore. This lets us reuse these functions in haddock, avoiding synchronization bugs. Also fixed some divergences with haddock in that file Updates haddock submodule - - - - - c7dd6da7 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part1) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Hs.* - GHC.Core.* - GHC.Stg.* - GHC.Cmm.* - GHC.Types.* - GHC.Data.* - GHC.Builtin.* - GHC.Parser.* - GHC.Driver.* - GHC top - - - - - 1eb997a8 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part2) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Iface.* - GHC.Llvm.* - GHC.Rename.* - GHC.Tc.* - GHC.HsToCore.* - GHC.StgToCmm.* - GHC.CmmToAsm.* - GHC.Runtime.* - GHC.Unit.* - GHC.Utils.* - GHC.SysTools.* - - - - - 67a86b4d by Oleg Grenrus at 2020-06-25T03:54:46-04:00 Add MonadZip and MonadFix instances for Complex These instances are taken from https://hackage.haskell.org/package/linear-1.21/docs/Linear-Instances.html They are the unique possible, so let they be in `base`. - - - - - c50ef26e by Artem Pelenitsyn at 2020-06-25T03:54:47-04:00 test suite: add reproducer for #17516 - - - - - fe281b27 by Roland Senn at 2020-06-25T03:54:48-04:00 Enable maxBound checks for OverloadedLists (Fixes #18172) Consider the Literal `[256] :: [Data.Word.Word8]` When the `OverloadedLists` extension is not active, then the `ol_ext` field in the `OverLitTc` record that is passed to the function `getIntegralLit` contains the type `Word8`. This is a simple type, and we can use its type constructor immediately for the `warnAboutOverflowedLiterals` function. When the `OverloadedLists` extension is active, then the `ol_ext` field contains the type family `Item [Word8]`. The function `nomaliseType` is used to convert it to the needed type `Word8`. - - - - - a788d4d1 by Ben Gamari at 2020-06-25T03:54:52-04:00 rts/Hash: Simplify freeing of HashListChunks While looking at #18348 I noticed that the treatment of HashLists are a bit more complex than necessary (which lead to some initial confusion on my part). Specifically, we allocate HashLists in chunks. Each chunk allocation makes two allocations: one for the chunk itself and one for a HashListChunk to link together the chunks for the purposes of freeing. Simplify this (and hopefully make the relationship between these clearer) but allocating the HashLists and HashListChunk in a single malloc. This will both make the implementation easier to follow and reduce C heap fragmentation. Note that even after this patch we fail to bound the size of the free HashList pool. However, this is a separate bug. - - - - - d3c2d59b by Sylvain Henry at 2020-06-25T03:54:55-04:00 RTS: avoid overflow on 32-bit arch (#18375) We're now correctly computing allocated bytes on 32-bit arch, so we get huge increases. Metric Increase: haddock.Cabal haddock.base haddock.compiler space_leak_001 - - - - - a3d69dc6 by Sebastian Graf at 2020-06-25T23:06:18-04:00 GHC.Core.Unify: Make UM actions one-shot by default This MR makes the UM monad in GHC.Core.Unify into a one-shot monad. See the long Note [The one-shot state monad trick]. See also #18202 and !3309, which applies this to all Reader/State-like monads in GHC for compile-time perf improvements. The pattern used here enables something similar to the state-hack, but is applicable to user-defined monads, not just `IO`. Metric Decrease 'runtime/bytes allocated' (test_env='i386-linux-deb9'): haddock.Cabal - - - - - 9ee58f8d by Matthias Pall Gissurarson at 2020-06-26T17:12:45+00:00 Implement the proposed -XQualifiedDo extension Co-authored-by: Facundo Domínguez <facundo.dominguez at tweag.io> QualifiedDo is implemented using the same placeholders for operation names in the AST that were devised for RebindableSyntax. Whenever the renamer checks which names to use for do syntax, it first checks if the do block is qualified (e.g. M.do { stmts }), in which case it searches for qualified names in the module M. This allows users to write {-# LANGUAGE QualifiedDo #-} import qualified SomeModule as M f x = M.do -- desugars to: y <- M.return x -- M.return x M.>>= \y -> M.return y -- M.return y M.>> M.return y -- M.return y See Note [QualifiedDo] and the users' guide for more details. Issue #18214 Proposal: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0216-qualified-do.rst Since we change the constructors `ITdo` and `ITmdo` to carry the new module name, we need to bump the haddock submodule to account or the new shape of these constructors. - - - - - ce987865 by Ryan Scott at 2020-06-27T11:55:21-04:00 Revamp the treatment of auxiliary bindings for derived instances This started as a simple fix for #18321 that organically grew into a much more sweeping refactor of how auxiliary bindings for derived instances are handled. I have rewritten `Note [Auxiliary binders]` in `GHC.Tc.Deriv.Generate` to explain all of the moving parts, but the highlights are: * Previously, the OccName of each auxiliary binding would be given a suffix containing a hash of its package name, module name, and parent data type to avoid name clashes. This was needlessly complicated, so we take the more direct approach of generating `Exact` `RdrName`s for each auxiliary binding with the same `OccName`, but using an underlying `System` `Name` with a fresh `Unique` for each binding. Unlike hashes, allocating new `Unique`s does not require any cleverness and avoid name clashes all the same... * ...speaking of which, in order to convince the renamer that multiple auxiliary bindings with the same `OccName` (but different `Unique`s) are kosher, we now use `rnLocalValBindsLHS` instead of `rnTopBindsLHS` to rename auxiliary bindings. Again, see `Note [Auxiliary binders]` for the full story. * I have removed the `DerivHsBind` constructor for `DerivStuff`—which was only used for `Data.Data`-related auxiliary bindings—and refactored `gen_Data_binds` to use `DerivAuxBind` instead. This brings the treatment of `Data.Data`-related auxiliary bindings in line with every other form of auxiliary binding. Fixes #18321. - - - - - a403eb91 by Sylvain Henry at 2020-06-27T11:55:59-04:00 ghc-bignum: fix division by zero (#18359) - - - - - 1b3d13b6 by Sylvain Henry at 2020-06-27T11:55:59-04:00 Fix ghc-bignum exceptions We must ensure that exceptions are not simplified. Previously we used: case raiseDivZero of _ -> 0## -- dummyValue But it was wrong because the evaluation of `raiseDivZero` was removed and the dummy value was directly returned. See new Note [ghc-bignum exceptions]. I've also removed the exception triggering primops which were fragile. We don't need them to be primops, we can have them exported by ghc-prim. I've also added a test for #18359 which triggered this patch. - - - - - a74ec37c by Simon Peyton Jones at 2020-06-27T11:56:34-04:00 Better loop detection in findTypeShape Andreas pointed out, in !3466, that my fix for #18304 was not quite right. This patch fixes it properly, by having just one RecTcChecker rather than (implicitly) two nested ones, in findTypeShape. - - - - - a04020b8 by Sylvain Henry at 2020-06-27T11:57:11-04:00 DynFlags: don't store buildTag `DynFlags.buildTag` was a field created from the set of Ways in `DynFlags.ways`. It had to be kept in sync with `DynFlags.ways` which was fragile. We want to avoid global state like this (#17957). Moreover in #14335 we also want to support loading units with different ways: target units would still use `DynFlags.ways` but plugins would use `GHC.Driver.Ways.hostFullWays`. To avoid having to deal both with build tag and with ways, we recompute the buildTag on-the-fly (should be pretty cheap) and we remove `DynFlags.buildTag` field. - - - - - 0e83efa2 by Krzysztof Gogolewski at 2020-06-27T11:57:49-04:00 Don't generalize when typechecking a tuple section The code is simpler and cleaner. - - - - - d8ba9e6f by Peter Trommler at 2020-06-28T09:19:11-04:00 RTS: Refactor Haskell-C glue for PPC 64-bit Make sure the stack is 16 byte aligned even when reserved stack bytes are not a multiple of 16 bytes. Avoid saving r2 (TOC). On ELF v1 the function descriptor of StgReturn has the same TOC as StgRun, on ELF v2 the TOC is recomputed in the function prologue. Use the ABI provided functions to save clobbered GPRs and FPRs. Improve comments. Describe what the stack looks like and how it relates to the respective ABIs. - - - - - 42f797b0 by Ryan Scott at 2020-06-28T09:19:46-04:00 Use NHsCoreTy to embed types into GND-generated code `GeneralizedNewtypeDeriving` is in the unique situation where it must produce an `LHsType GhcPs` from a Core `Type`. Historically, this was done with the `typeToLHsType` function, which walked over the entire `Type` and attempted to construct an `LHsType` with the same overall structure. `typeToLHsType` is quite complicated, however, and has been the subject of numerous bugs over the years (e.g., #14579). Luckily, there is an easier way to accomplish the same thing: the `XHsType` constructor of `HsType`. `XHsType` bundles an `NHsCoreTy`, which allows embedding a Core `Type` directly into an `HsType`, avoiding the need to laboriously convert from one to another (as `typeToLHsType` did). Moreover, renaming and typechecking an `XHsType` is simple, since one doesn't need to do anything to a Core `Type`... ...well, almost. For the reasons described in `Note [Typechecking NHsCoreTys]` in `GHC.Tc.Gen.HsType`, we must apply a substitution that we build from the local `tcl_env` type environment. But that's a relatively modest price to pay. Now that `GeneralizedNewtypeDeriving` uses `NHsCoreTy`, the `typeToLHsType` function no longer has any uses in GHC, so this patch rips it out. Some additional tweaks to `hsTypeNeedsParens` were necessary to make the new `-ddump-deriv` output correctly parenthesized, but other than that, this patch is quite straightforward. This is a mostly internal refactoring, although it is likely that `GeneralizedNewtypeDeriving`-generated code will now need fewer language extensions in certain situations than it did before. - - - - - 68530b1c by Jan Hrček at 2020-06-28T09:20:22-04:00 Fix duplicated words and typos in comments and user guide - - - - - 15b79bef by Ryan Scott at 2020-06-28T09:20:57-04:00 Add integer-gmp's ghc.mk and GNUmakefile to .gitignore - - - - - bfa5698b by Simon Peyton Jones at 2020-06-28T09:21:32-04:00 Fix a typo in Lint This simple error in GHC.Core.Litn.lintJoinLams meant that Lint reported bogus errors. Fixes #18399 - - - - - 71006532 by Ryan Scott at 2020-06-30T07:10:42-04:00 Reject nested foralls/contexts in instance types more consistently GHC is very wishy-washy about rejecting instance declarations with nested `forall`s or contexts that are surrounded by outermost parentheses. This can even lead to some strange interactions with `ScopedTypeVariables`, as demonstrated in #18240. This patch makes GHC more consistently reject instance types with nested `forall`s/contexts so as to prevent these strange interactions. On the implementation side, this patch tweaks `splitLHsInstDeclTy` and `getLHsInstDeclHead` to not look through parentheses, which can be semantically significant. I've added a `Note [No nested foralls or contexts in instance types]` in `GHC.Hs.Type` to explain why. This also introduces a `no_nested_foralls_contexts_err` function in `GHC.Rename.HsType` to catch nested `forall`s/contexts in instance types. This function is now used in `rnClsInstDecl` (for ordinary instance declarations) and `rnSrcDerivDecl` (for standalone `deriving` declarations), the latter of which fixes #18271. On the documentation side, this adds a new "Formal syntax for instance declaration types" section to the GHC User's Guide that presents a BNF-style grammar for what is and isn't allowed in instance types. Fixes #18240. Fixes #18271. - - - - - bccf3351 by Sylvain Henry at 2020-06-30T07:10:46-04:00 Add ghc-bignum to 8.12 release notes - - - - - 81704a6f by David Eichmann at 2020-06-30T07:10:48-04:00 Update ssh keys in CI performance metrics upload script - - - - - 85310fb8 by Joshua Price at 2020-06-30T07:10:49-04:00 Add missing Ix instances for tuples of size 6 through 15 (#16643) - - - - - cbb6b62f by Vladislav Zavialov at 2020-07-01T15:41:38-04:00 Implement -XLexicalNegation (GHC Proposal #229) This patch introduces a new extension, -XLexicalNegation, which detects whether the minus sign stands for negation or subtraction using the whitespace-based rules described in GHC Proposal #229. Updates haddock submodule. - - - - - fb5a0d01 by Martin Handley at 2020-07-01T15:42:14-04:00 #17169: Clarify Fixed's Enum instance. - - - - - b316804d by Simon Peyton Jones at 2020-07-01T15:42:49-04:00 Improve debug tracing for substitution This patch improves debug tracing a bit (#18395) * Remove the ancient SDoc argument to substitution, replacing it with a HasDebugCallStack constraint. The latter does the same job (indicate the call site) but much better. * Add HasDebugCallStack to simpleOptExpr, exprIsConApp_maybe I needed this to help nail the lookupIdSubst panic in #18326, #17784 - - - - - 5c9fabb8 by Hécate at 2020-07-01T15:43:25-04:00 Add most common return values for `os` and `arch` - - - - - 76d8cc74 by Ryan Scott at 2020-07-01T15:44:01-04:00 Desugar quoted uses of DerivingVia and expression type signatures properly The way that `GHC.HsToCore.Quote` desugared quoted `via` types (e.g., `deriving via forall a. [a] instance Eq a => Eq (List a)`) and explicit type annotations in signatures (e.g., `f = id @a :: forall a. a -> a`) was completely wrong, as it did not implement the scoping guidelines laid out in `Note [Scoped type variables in bindings]`. This is easily fixed. While I was in town, I did some minor cleanup of related Notes: * `Note [Scoped type variables in bindings]` and `Note [Scoped type variables in class and instance declarations]` say very nearly the same thing. I decided to just consolidate the two Notes into `Note [Scoped type variables in quotes]`. * `Note [Don't quantify implicit type variables in quotes]` is somewhat outdated, as it predates GHC 8.10, where the `forall`-or-nothing rule requires kind variables to be explicitly quantified in the presence of an explicit `forall`. As a result, the running example in that Note doesn't even compile. I have changed the example to something simpler that illustrates the same point that the original Note was making. Fixes #18388. - - - - - 44d6a335 by Andreas Klebinger at 2020-07-02T02:54:54-04:00 T16012: Be verbose on failure. - - - - - f9853330 by Ryan Scott at 2020-07-02T02:55:29-04:00 Bump ghc-prim version to 0.7.0 Fixes #18279. Bumps the `text` submodule. - - - - - 23e4e047 by Sylvain Henry at 2020-07-02T10:46:31-04:00 Hadrian: fix PowerPC64le support (#17601) [ci skip] - - - - - 3cdd8d69 by Sylvain Henry at 2020-07-02T10:47:08-04:00 NCG: correctly handle addresses with huge offsets (#15570) Before this patch we could generate addresses of this form: movzbl cP0_str+-9223372036854775808,%eax The linker can't handle them because the offset is too large: ld.lld: error: Main.o:(.text+0xB3): relocation R_X86_64_32S out of range: -9223372036852653050 is not in [-2147483648, 2147483647] With this patch we detect those cases and generate: movq $-9223372036854775808,%rax addq $cP0_str,%rax movzbl (%rax),%eax I've also refactored `getAmode` a little bit to make it easier to understand and to trace. - - - - - 4d90b3ff by Gabor Greif at 2020-07-02T20:07:59-04:00 No need for CURSES_INCLUDE_DIRS This is a leftover from ef63ff27251a20ff11e58c9303677fa31e609a88 - - - - - f08d6316 by Sylvain Henry at 2020-07-02T20:08:36-04:00 Replace Opt_SccProfilingOn flag with sccProfilingEnabled helper function SCC profiling was enabled in a convoluted way: if WayProf was enabled, Opt_SccProfilingOn general flag was set (in `GHC.Driver.Ways.wayGeneralFlags`), and then this flag was queried in various places. There is no need to go via general flags, so this patch defines a `sccProfilingEnabled :: DynFlags -> Bool` helper function that just checks whether WayProf is enabled. - - - - - 8cc7274b by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Only allocate the Censuses that we need When not LDV profiling there is no reason to allocate 32 Censuses; one will do. This is a very small memory footprint optimisation, but it comes for free. - - - - - b835112c by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Free old allocations when reinitialising Censuses Previously when not LDV profiling we would repeatedly reinitialise `censuses[0]` with `initEra`. This failed to free the `Arena` and `HashTable` from the old census, resulting in a memory leak. Fixes #18348. - - - - - 34be6523 by Valery Tolstov at 2020-07-03T02:50:03-04:00 Mention flags that are not enabled by -Wall (#18372) * Mention missing flags that are not actually enabled by -Wall (docs/users_guide/using-warnings.rst) * Additionally remove -Wmissing-monadfail-instances from the list of flags enabled by -Wcompat, as it is not the case since 8.8 - - - - - edc8d22b by Sylvain Henry at 2020-07-03T02:50:40-04:00 LLVM: support R9 and R10 registers d535ef006d85dbdb7cda2b09c5bc35cb80108909 allowed the use of up to 10 vanilla registers but didn't update LLVM backend to support them. This patch fixes it. - - - - - 4bf18646 by Simon Peyton Jones at 2020-07-03T08:37:42+01:00 Improve handling of data type return kinds Following a long conversation with Richard, this patch tidies up the handling of return kinds for data/newtype declarations (vanilla, family, and instance). I have substantially edited the Notes in TyCl, so they would bear careful reading. Fixes #18300, #18357 In GHC.Tc.Instance.Family.newFamInst we were checking some Lint-like properties with ASSSERT. Instead Richard and I have added a proper linter for axioms, and called it from lintGblEnv, which in turn is called in tcRnModuleTcRnM New tests (T18300, T18357) cause an ASSERT failure in HEAD. - - - - - 41d26492 by Sylvain Henry at 2020-07-03T17:33:59-04:00 DynFlags: avoid the use of sdocWithDynFlags in GHC.Core.Rules (#17957) - - - - - 7aa6ef11 by Hécate at 2020-07-03T17:34:36-04:00 Add the __GHC_FULL_VERSION__ CPP macro to expose the full GHC version - - - - - e61d5395 by Chaitanya Koparkar at 2020-07-07T13:55:59-04:00 ghc-prim: Turn some comments into haddocks [ci skip] - - - - - 37743f91 by John Ericson at 2020-07-07T13:56:00-04:00 Support `timesInt2#` in LLVM backend - - - - - 46397e53 by John Ericson at 2020-07-07T13:56:00-04:00 `genericIntMul2Op`: Call `genericWordMul2Op` directly This unblocks a refactor, and removes partiality. It might be a PowerPC regression but that should be fixable. - - - - - 8a1c0584 by John Ericson at 2020-07-07T13:56:00-04:00 Simplify `PrimopCmmEmit` Follow @simonpj's suggestion of pushing the "into regs" logic into `emitPrimOp`. With the previous commit getting rid of the recursion in `genericIntMul2Op`, this is now an easy refactor. - - - - - 6607f203 by John Ericson at 2020-07-07T13:56:00-04:00 `opAllDone` -> `opIntoRegs` The old name was and terrible and became worse after the previous commit's refactor moved non-trivial funcationlity into its body. - - - - - fdcc53ba by Sylvain Henry at 2020-07-07T13:56:00-04:00 Optimise genericIntMul2Op We shouldn't directly call 'genericWordMul2Op' in genericIntMul2Op because a target may provide a faster primop for 'WordMul2Op': we'd better use it! - - - - - 686e7225 by Moritz Angermann at 2020-07-07T13:56:01-04:00 [linker/rtsSymbols] More linker symbols Mostly symbols needed for aarch64/armv7l and in combination with musl, where we have to rely on loading *all* objects/archives - __stack_chk_* only when not DYNAMIC - - - - - 3f60b94d by Moritz Angermann at 2020-07-07T13:56:01-04:00 better if guards. - - - - - 7abffced by Moritz Angermann at 2020-07-07T13:56:01-04:00 Fix (1) - - - - - cdfeb3f2 by Moritz Angermann at 2020-07-07T13:56:01-04:00 AArch32 symbols only on aarch32. - - - - - f496c955 by Adam Sandberg Ericsson at 2020-07-07T13:56:02-04:00 add -flink-rts flag to link the rts when linking a shared or static library #18072 By default we don't link the RTS when linking shared libraries because in the most usual mode a shared library is an intermediary product, for example a Haskell library, that will be linked into some executable in the end. So we wish to defer the RTS flavour to link to the final link. However sometimes the final product is the shared library, for example when writing a plugin for some other system, so we do wish the shared library to link the RTS. For consistency we also make -staticlib honor this flag and its inversion. -staticlib currently implies -flink-shared. - - - - - c59faf67 by Stefan Schulze Frielinghaus at 2020-07-07T13:56:04-04:00 hadrian: link check-ppr against debugging RTS if ghcDebugged - - - - - 0effc57d by Adam Sandberg Ericsson at 2020-07-07T13:56:05-04:00 rts linker: teach the linker about GLIBC's special handling of *stat, mknod and atexit functions #7072 - - - - - 96153433 by Adam Sandberg Ericsson at 2020-07-07T13:56:06-04:00 hadrian: make hadrian/ghci use the bootstrap compiler from configure #18190 - - - - - 4d24f886 by Adam Sandberg Ericsson at 2020-07-07T13:56:07-04:00 hadrian: ignore cabal configure verbosity related flags #18131 - - - - - 7332bbff by Ben Gamari at 2020-07-07T13:56:08-04:00 testsuite: Widen T12234 acceptance window to 2% Previously it wasn't uncommon to see +/-1% fluctuations in compiler allocations on this test. - - - - - 180b6313 by Gabor Greif at 2020-07-07T13:56:08-04:00 When running libtool, report it as such - - - - - d3bd6897 by Sylvain Henry at 2020-07-07T13:56:11-04:00 BigNum: rename BigNat types Before this patch BigNat names were confusing because we had: * GHC.Num.BigNat.BigNat: unlifted type used everywhere else * GHC.Num.BigNat.BigNatW: lifted type only used to share static constants * GHC.Natural.BigNat: lifted type only used for backward compatibility After this patch we have: * GHC.Num.BigNat.BigNat#: unlifted type * GHC.Num.BigNat.BigNat: lifted type (reexported from GHC.Natural) Thanks to @RyanGlScott for spotting this. - - - - - 929d26db by Sylvain Henry at 2020-07-07T13:56:12-04:00 Bignum: don't build ghc-bignum with stage0 Noticed by @Ericson2314 - - - - - d25b6851 by Sylvain Henry at 2020-07-07T13:56:12-04:00 Hadrian: ghc-gmp.h shouldn't be a compiler dependency - - - - - 0ddae2ba by Sylvain Henry at 2020-07-07T13:56:14-04:00 DynFlags: factor out pprUnitId from "Outputable UnitId" instance - - - - - 204f3f5d by Krzysztof Gogolewski at 2020-07-07T13:56:18-04:00 Remove unused function pprHsForAllExtra (#18423) The function `pprHsForAllExtra` was called only on `Nothing` since 2015 (1e041b7382b6aa). - - - - - 3033e0e4 by Adam Sandberg Ericsson at 2020-07-08T20:36:49-04:00 hadrian: add flag to skip rebuilding dependency information #17636 - - - - - b7de4b96 by Stefan Schulze Frielinghaus at 2020-07-09T09:49:22-04:00 Fix GHCi :print on big-endian platforms On big-endian platforms executing import GHC.Exts data Foo = Foo Float# deriving Show foo = Foo 42.0# foo :print foo results in an arithmetic overflow exception which is caused by function index where moveBytes equals word_size - (r + item_size_b) * 8 Here we have a mixture of units. Both, word_size and item_size_b have unit bytes whereas r has unit bits. On 64-bit platforms moveBytes equals then 8 - (0 + 4) * 8 which results in a negative and therefore invalid second parameter for a shiftL operation. In order to make things more clear the expression (word .&. (mask `shiftL` moveBytes)) `shiftR` moveBytes is equivalent to (word `shiftR` moveBytes) .&. mask On big-endian platforms the shift must be a left shift instead of a right shift. For symmetry reasons not a mask is used but two shifts in order to zero out bits. Thus the fixed version equals case endian of BigEndian -> (word `shiftL` moveBits) `shiftR` zeroOutBits `shiftL` zeroOutBits LittleEndian -> (word `shiftR` moveBits) `shiftL` zeroOutBits `shiftR` zeroOutBits Fixes #16548 and #14455 - - - - - 3656dff8 by Sylvain Henry at 2020-07-09T09:50:01-04:00 LLVM: fix MO_S_Mul2 support (#18434) The value indicating if the carry is useful wasn't taken into account. - - - - - d9f09506 by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Define multiShotIO and use it in mkSplitUniqueSupply This patch is part of the ongoing eta-expansion saga; see #18238. It implements a neat trick (suggested by Sebastian Graf) that allows the programmer to disable the default one-shot behaviour of IO (the "state hack"). The trick is to use a new multiShotIO function; see Note [multiShotIO]. For now, multiShotIO is defined here in Unique.Supply; but it should ultimately be moved to the IO library. The change is necessary to get good code for GHC's unique supply; see Note [Optimising the unique supply]. However it makes no difference to GHC as-is. Rather, it makes a difference when a subsequent commit Improve eta-expansion using ArityType lands. - - - - - bce695cc by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Make arityType deal with join points As Note [Eta-expansion and join points] describes, this patch makes arityType deal correctly with join points. What was there before was not wrong, but yielded lower arities than it could. Fixes #18328 In base GHC this makes no difference to nofib. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- n-body -0.1% -0.1% -1.2% -1.1% 0.0% -------------------------------------------------------------------------------- Min -0.1% -0.1% -55.0% -56.5% 0.0% Max -0.0% 0.0% +16.1% +13.4% 0.0% Geometric Mean -0.0% -0.0% -30.1% -31.0% -0.0% But it starts to make real difference when we land the change to the way mkDupableAlts handles StrictArg, in fixing #13253 and friends. I think this is because we then get more non-inlined join points. - - - - - 2b7c71cb by Simon Peyton Jones at 2020-07-11T12:17:02-04:00 Improve eta-expansion using ArityType As #18355 shows, we were failing to preserve one-shot info when eta-expanding. It's rather easy to fix, by using ArityType more, rather than just Arity. This patch is important to suport the one-shot monad trick; see #18202. But the extra tracking of one-shot-ness requires the patch Define multiShotIO and use it in mkSplitUniqueSupply If that patch is missing, ths patch makes things worse in GHC.Types.Uniq.Supply. With it, however, we see these improvements T3064 compiler bytes allocated -2.2% T3294 compiler bytes allocated -1.3% T12707 compiler bytes allocated -1.3% T13056 compiler bytes allocated -2.2% Metric Decrease: T3064 T3294 T12707 T13056 - - - - - de139cc4 by Artem Pelenitsyn at 2020-07-12T02:53:20-04:00 add reproducer for #15630 - - - - - c4de6a7a by Andreas Klebinger at 2020-07-12T02:53:55-04:00 Give Uniq[D]FM a phantom type for its key. This fixes #17667 and should help to avoid such issues going forward. The changes are mostly mechanical in nature. With two notable exceptions. * The register allocator. The register allocator references registers by distinct uniques. However they come from the types of VirtualReg, Reg or Unique in various places. As a result we sometimes cast the key type of the map and use functions which operate on the now typed map but take a raw Unique as actual key. The logic itself has not changed it just becomes obvious where we do so now. * <Type>Env Modules. As an example a ClassEnv is currently queried using the types `Class`, `Name`, and `TyCon`. This is safe since for a distinct class value all these expressions give the same unique. getUnique cls getUnique (classTyCon cls) getUnique (className cls) getUnique (tcName $ classTyCon cls) This is for the most part contained within the modules defining the interface. However it requires us to play dirty when we are given a `Name` to lookup in a `UniqFM Class a` map. But again the logic did not change and it's for the most part hidden behind the Env Module. Some of these cases could be avoided by refactoring but this is left for future work. We also bump the haddock submodule as it uses UniqFM. - - - - - c2cfdfde by Aaron Allen at 2020-07-13T09:00:33-04:00 Warn about empty Char enumerations (#18402) Currently the "Enumeration is empty" warning (-Wempty-enumerations) only fires for numeric literals. This patch adds support for `Char` literals so that enumerating an empty list of `Char`s will also trigger the warning. - - - - - c3ac87ec by Stefan Schulze Frielinghaus at 2020-07-13T09:01:10-04:00 hadrian: build check-ppr dynamic if GHC is build dynamic Fixes #18361 - - - - - 9ad072b4 by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Use dumpStyle when printing inlinings This just makes debug-printing consistent, and more informative. - - - - - e78c4efb by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Comments only - - - - - 7ccb760b by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Reduce result discount in conSize Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c - - - - - 7f0b671e by Ben Gamari at 2020-07-13T14:52:49-04:00 testsuite: Widen acceptance threshold on T5837 This test is positively tiny and consequently the bytes allocated measurement will be relatively noisy. Consequently I have seen this fail spuriously quite often. - - - - - 118e1c3d by Alp Mestanogullari at 2020-07-14T21:30:52-04:00 compiler: re-engineer the treatment of rebindable if Executing on the plan described in #17582, this patch changes the way if expressions are handled in the compiler in the presence of rebindable syntax. We get rid of the SyntaxExpr field of HsIf and instead, when rebindable syntax is on, we rewrite the HsIf node to the appropriate sequence of applications of the local `ifThenElse` function. In order to be able to report good error messages, with expressions as they were written by the user (and not as desugared by the renamer), we make use of TTG extensions to extend GhcRn expression ASTs with an `HsExpansion` construct, which keeps track of a source (GhcPs) expression and the desugared (GhcRn) expression that it gives rise to. This way, we can typecheck the latter while reporting the former in error messages. In order to discard the error context lines that arise from typechecking the desugared expressions (because they talk about expressions that the user has not written), we carefully give a special treatment to the nodes fabricated by this new renaming-time transformation when typechecking them. See Note [Rebindable syntax and HsExpansion] for more details. The note also includes a recipe to apply the same treatment to other rebindable constructs. Tests 'rebindable11' and 'rebindable12' have been added to make sure we report identical error messages as before this patch under various circumstances. We also now disable rebindable syntax when processing untyped TH quotes, as per the discussion in #18102 and document the interaction of rebindable syntax and Template Haskell, both in Note [Template Haskell quotes and Rebindable Syntax] and in the user guide, adding a test to make sure that we do not regress in that regard. - - - - - 64c774b0 by Andreas Klebinger at 2020-07-14T21:31:27-04:00 Explain why keeping DynFlags in AnalEnv saves allocation. - - - - - 254245d0 by Ben Gamari at 2020-07-14T21:32:03-04:00 docs/users-guide: Update default -funfolding-use-threshold value This was changed in 3d2991f8 but I neglected to update the documentation. Fixes #18419. - - - - - 4c259f86 by Andreas Klebinger at 2020-07-14T21:32:41-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. - - - - - 23797224 by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 .gitlab: re-enable integer-simple substitute (BIGNUM_BACKEND) Recently build system migrated from INTEGER_LIBRARY to BIGNUM_BACKEND. But gitlab CI was never updated. Let's enable BIGNUM_BACKEND=native. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - e0db878a by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 ghc-bignum: bring in sync .hs-boot files with module declarations Before this change `BIGNUM_BACKEND=native` build was failing as: ``` libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs:708:16: error: * Variable not in scope: naturalFromBigNat# :: WordArray# -> t * Perhaps you meant one of these: `naturalFromBigNat' (imported from GHC.Num.Natural), `naturalToBigNat' (imported from GHC.Num.Natural) | 708 | m' = naturalFromBigNat# m | ``` This happens because `.hs-boot` files are slightly out of date. This change brings in data and function types in sync. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - c9f65c36 by Stefan Schulze Frielinghaus at 2020-07-14T21:33:57-04:00 rts/Disassembler.c: Use FMT_HexWord for printing values in hex format - - - - - 58ae62eb by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 macOS: Load frameworks without stating them first. macOS Big Sur makes the following change to how frameworks are shipped with the OS: > New in macOS Big Sur 11 beta, the system ships with a built-in > dynamic linker cache of all system-provided libraries. As part of > this change, copies of dynamic libraries are no longer present on > the filesystem. Code that attempts to check for dynamic library > presence by looking for a file at a path or enumerating a directory > will fail. Instead, check for library presence by attempting to > dlopen() the path, which will correctly check for the library in the > cache. (62986286) https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/ Therefore, the previous method of checking whether a library exists before attempting to load it makes GHC.Runtime.Linker.loadFramework fail to find frameworks installed at /System/Library/Frameworks. GHC.Runtime.Linker.loadFramework now opportunistically loads the framework libraries without checking for their existence first, failing only if all attempts to load a given framework from any of the various possible locations fail. - - - - - cdc4a6b0 by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 loadFramework: Output the errors collected in all loading attempts. With the recent change away from first finding and then loading a framework, loadFramework had no way of communicating the real reason why loadDLL failed if it was any reason other than the framework missing from the file system. It now collects all loading attempt errors into a list and concatenates them into a string to return to the caller. - - - - - 51dbfa52 by Ben Gamari at 2020-07-15T04:05:34-04:00 StgToCmm: Use CmmRegOff smart constructor Previously we would generate expressions of the form `CmmRegOff BaseReg 0`. This should do no harm (and really should be handled by the NCG anyways) but it's better to just generate a plain `CmmReg`. - - - - - ae11bdfd by Ben Gamari at 2020-07-15T04:06:08-04:00 testsuite: Add regression test for #17744 Test due to @monoidal. - - - - - 0e3c277a by Ben Gamari at 2020-07-15T16:41:01-04:00 Bump Cabal submodule Updates a variety of tests as Cabal is now more strict about Cabal file form. - - - - - ceed994a by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Drop Windows Vista support, require Windows 7 - - - - - 00a23bfd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Update Windows FileSystem wrapper utilities. - - - - - 459e1c5f by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Use SlimReaderLocks and ConditonalVariables provided by the OS instead of emulated ones - - - - - 763088fc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Small linker comment and ifdef cleanups - - - - - 1a228ff9 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Flush event logs eagerly. - - - - - e9e04dda by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Refactor Buffer structures to be able to track async operations - - - - - 356dc3fe by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Implement new Console API - - - - - 90e69f77 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add IOPort synchronization primitive - - - - - 71245fcc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add new io-manager cmdline options - - - - - d548a3b3 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Init Windows console Codepage to UTF-8. - - - - - 58ef6366 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add unsafeSplat to GHC.Event.Array - - - - - d660725e by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add size and iterate to GHC.Event.IntTable. - - - - - 050da6dd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Switch Testsuite to test winio by default - - - - - 4bf542bf by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Multiple refactorings and support changes. - - - - - 4489af6b by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core threaded I/O manager - - - - - 64d8f2fe by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core non-threaded I/O manager - - - - - 8da15a09 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix a scheduler bug with the threaded-runtime. - - - - - 84ea3d14 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Relaxing some constraints in io-manager. - - - - - ccf0d107 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix issues with non-threaded I/O manager after split. - - - - - b492fe6e by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Remove some barf statements that are a bit strict. - - - - - 01423fd2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Expand comments describing non-threaded loop - - - - - 4b69004f by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: fix FileSize unstat-able handles - - - - - 9b384270 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Implement new tempfile routines for winio - - - - - f1e0be82 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix input truncation when reading from handle. This was caused by not upholding the read buffer invariant that bufR == bufL == 0 for empty read buffers. - - - - - e176b625 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix output truncation for writes larger than buffer size - - - - - a831ce0e by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Rewrite bufWrite. I think it's far easier to follow the code now. It's also correct now as I had still missed a spot where we didn't update the offset. - - - - - 6aefdf62 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix offset set by bufReadEmpty. bufReadEmpty returns the bytes read *including* content that was already buffered, But for calculating the offset we only care about the number of bytes read into the new buffer. - - - - - 750ebaee by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Clean up code surrounding IOPort primitives. According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc. - - - - - ffd31db9 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix multi threaded threadDelay and a few other small changes. Multithreaded threadDelay suffered from a race condition based on the ioManagerStatus. Since the status isn't needed for WIO I removed it completely. This resulted in a light refactoring, as consequence we will always wake up the IO manager using interruptSystemManager, which uses `postQueuedCompletionStatus` internally. I also added a few comments which hopefully makes the code easier to dive into for the next person diving in. - - - - - 6ec26df2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 wionio: Make IO subsystem check a no-op on non-windows platforms. - - - - - 29bcd936 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Set handle offset when opening files in Append mode. Otherwise we would truncate the file. - - - - - 55c29700 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Remove debug event log trace - - - - - 9acb9f40 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix sqrt and openFile009 test cases - - - - - 57017cb7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Allow hp2ps to build with -DDEBUG - - - - - b8cd9995 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update output of T9681 since we now actually run it. - - - - - 10af5b14 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: A few more improvements to the IOPort primitives. - - - - - 39afc4a7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix expected tempfiles output. Tempfiles now works properly on windows, as such we can delete the win32 specific output. - - - - - 99db46e0 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Assign thread labels to IOManager threads. - - - - - be6af732 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Properly check for the tso of an incall to be zero. - - - - - e2c6dac7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark FD instances as unsupported under WINIO. - - - - - fd02ceed by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix threadDelay maxBound invocations. Instead of letting the ns timer overflow now clamp it at (maxBound :: Word64) ns. That still gives a few hundred years. - - - - - bc79f9f1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comments/cleanup an import in base - - - - - 1d197f4b by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark outstanding_service_requests volatile. As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration. - - - - - dc438186 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Make last_event a local variable - - - - - 2fc957c5 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comment about thread safety of processCompletion. - - - - - 4c026b6c by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: nonthreaded: Create io processing threads in main thread. We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread. - - - - - f47c7208 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add an exported isHeapAlloced function to the RTS - - - - - cc5d7bb1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Queue IO processing threads at the front of the queue. This will unblock the IO thread sooner hopefully leading to higher throughput in some situations. - - - - - e7630115 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: ThreadDelay001: Use higher resolution timer. - - - - - 451b5f96 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update T9681 output, disable T4808 on windows. T4808 tests functionality of the FD interface which won't be supported under WINIO. T9681 just has it's expected output tweaked. - - - - - dd06f930 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Wake io manager once per registerTimeout. Which is implicitly done in editTimeouts, so need to wake it up twice. - - - - - e87d0bf9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update placeholder comment with actual function name. - - - - - fc9025db by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Always lock win32 event queue - - - - - c24c9a1f by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Display thread labels when tracing scheduler events. - - - - - 06542b03 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Refactor non-threaded runner thread and scheduler interface. Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event. - - - - - 256299b1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove outstanding_requests from runner. We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port. - - - - - 3ebd8ad9 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Various fixes related to rebase and testdriver - - - - - 6be6bcba by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Fix rebase artifacts - - - - - 2c649dc3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename unsafeSplat to unsafeCopyFromBuffer - - - - - a18b73f3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove unused size/iterate operations from IntTable - - - - - 16bab48e by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Detect running IO Backend via peeking at RtsConfig - - - - - 8b8405a0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update temp path so GCC etc can handle it. Also fix PIPE support, clean up error casting, fix memory leaks - - - - - 2092bc54 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Minor comments/renamings - - - - - a5b5b6c0 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Checking if an error code indicates completion is now a function. - - - - - 362176fd by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Small refactor in withOverlappedEx - - - - - 32e20597 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: A few comments and commented out dbxIO - - - - - a4bfc1d9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't drop buffer offset in byteView/cwcharView - - - - - b3ad2a54 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: revert BHandle changes. - - - - - 3dcd87e2 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Fix imports - - - - - 5a371890 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update ghc-cabal to handle new Cabal submodule bump - - - - - d07ebe0d by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Only compile sources on Windows - - - - - dcb42393 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Actually return Nothing on EOF for non-blocking read - - - - - 895a3beb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate logic in encodeMultiByte[Raw]IO. - - - - - e06e6734 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate openFile logic - - - - - b59430c0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: fix -werror issue in encoding file - - - - - f8d39a51 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't mention windows specific functions when building on Linux. - - - - - 6a533d2a by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add a note about file locking in the RTS. - - - - - cf37ce34 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Add version to @since annotation - - - - - 0fafa2eb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename GHC.Conc.IOCP -> GHC.Conc.WinIO - - - - - 1854fc23 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Expand GHC.Conc.POSIX description It now explains users may not use these functions when using the old IO manager. - - - - - fcc7ba41 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Fix potential spaceleak in __createUUIDTempFileErrNo - - - - - 6b3fd9fa by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant -Wno-missing-signatures pragmas - - - - - 916fc861 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Make it explicit that we only create one IO manager - - - - - f260a721 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Note why we don't use blocking waits. - - - - - aa0a4bbf by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove commented out pragma - - - - - d679b544 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant buffer write in Handle/Text.hs:bufReadEmpty - - - - - d3f94368 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename SmartHandles to StdHandles - - - - - bd6b8ec1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add comment stating failure behaviour for getUniqueFileInfo. - - - - - 12846b85 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update IOPort haddocks. - - - - - 9f39fb14 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Add a note cross reference - - - - - 62dd5a73 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Name Haskell/OS I/O Manager explicitly in Note - - - - - fa807828 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Expand BlockedOnIOCompletion description. - - - - - f0880a1d by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove historical todos - - - - - 8e58e714 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Update note, remove debugging pragma. - - - - - aa4d84d5 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: flushCharReadBuffer shouldn't need to adjust offsets. - - - - - e580893a by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove obsolete comment about cond. variables - - - - - d54e9d79 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix initial linux validate build - - - - - 3cd4de46 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix ThreadDelay001 CPP - - - - - c88b1b9f by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix openFile009 merge conflict leftover - - - - - 849e8889 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept T9681 output. GHC now reports String instead of [Char]. - - - - - e7701818 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix cabal006 after upgrading cabal submodule Demand cabal 2.0 syntax instead of >= 1.20 as required by newer cabal versions. - - - - - a44f0373 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix stderr output for ghci/linking/dyn tests. We used to filter rtsopts, i opted to instead just accept the warning of it having no effect. This works both for -rtsopts, as well as -with-rtsopts which winio adds. - - - - - 515d9896 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T15261b stdout for --io-manager flag. - - - - - 949aaacc by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T5435_dyn_asm stderr The warning about rtsopts having no consequences is expected. So accept new stderr. - - - - - 7d424e1e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Also accept T7037 stderr - - - - - 1f009768 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal04 by filtering rts args - - - - - 981a9f2e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal01 by accepting expected stderr - - - - - b7b0464e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix safePkg01 by accepting expected stderr - - - - - 32734b29 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix T5435_dyn_gcc by accepting expected stderr - - - - - acc5cebf by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix tempfiles test on linux - - - - - c577b789 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for T3807 - - - - - c108c527 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload - - - - - 2b0b9a08 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload_multiple_objs - - - - - 67afb03c by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify wording on conditional variables. - - - - - 3bd41572 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify comment on cooked mode. - - - - - ded58a03 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: update lockfile signature and remove mistaken symbol in rts. - - - - - 2143c492 by Ben Gamari at 2020-07-15T16:41:04-04:00 testsuite: Add winio and winio_threaded ways Reverts many of the testsuite changes - - - - - c0979cc5 by Ben Gamari at 2020-07-16T10:56:54-04:00 Merge remote-tracking branch 'origin/wip/winio' - - - - - 750a1595 by Ben Gamari at 2020-07-18T07:26:41-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. - - - - - 6ba6a881 by Hécate at 2020-07-18T07:26:42-04:00 Implement `fullCompilerVersion` Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403 This MR adds `fullCompilerVersion`, a function that shares the same backend as the `--numeric-version` GHC flag, exposing a full, three-digit version datatype. - - - - - e6cf27df by Hécate at 2020-07-18T07:26:43-04:00 Add a Lint hadrian rule and an .hlint.yaml file in base/ - - - - - bcb177dd by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Allow multiple case branches to have a higher rank type As #18412 points out, it should be OK for multiple case alternatives to have a higher rank type, provided they are all the same. This patch implements that change. It sweeps away GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it with an enhanced version of fillInferResult. The basic change to fillInferResult is to permit the case in which another case alternative has already filled in the result; and in that case simply unify. It's very simple actually. See the new Note [fillInferResult] in TcMType Other refactoring: - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType (previously some of it was in Unify) - Move tcInstType and friends from TcMType to Instantiate, where it more properly belongs. (TCMType was getting very long.) - - - - - e5525a51 by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Improve typechecking of NPlusK patterns This patch (due to Richard Eisenberg) improves documentation of the wrapper returned by tcSubMult (see Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify). And, more substantially, it cleans up the multiplicity handling in the typechecking of NPlusKPat - - - - - 12f90352 by Krzysztof Gogolewski at 2020-07-18T07:26:45-04:00 Remove {-# CORE #-} pragma (part of #18048) This pragma has no effect since 2011. It was introduced for External Core, which no longer exists. Updates haddock submodule. - - - - - e504c913 by Simon Peyton Jones at 2020-07-18T07:26:45-04:00 Refactor the simplification of join binders This MR (for #18449) refactors the Simplifier's treatment of join-point binders. Specifically, it puts together, into GHC.Core.Opt.Simplify.Env.adjustJoinPointType two currently-separate ways in which we adjust the type of a join point. As the comment says: -- (adjustJoinPointType mult new_res_ty join_id) does two things: -- -- 1. Set the return type of the join_id to new_res_ty -- See Note [Return type for join points] -- -- 2. Adjust the multiplicity of arrows in join_id's type, as -- directed by 'mult'. See Note [Scaling join point arguments] I think this actually fixes a latent bug, by ensuring that the seIdSubst and seInScope have the right multiplicity on the type of join points. I did some tidying up while I was at it. No more setJoinResTy, or modifyJoinResTy: instead it's done locally in Simplify.Env.adjustJoinPointType - - - - - 49b265f0 by Chaitanya Koparkar at 2020-07-18T07:26:46-04:00 Fix minor typos in a Core.hs note - - - - - 8d59aed6 by Stefan Schulze Frielinghaus at 2020-07-18T07:26:47-04:00 GHCi: Fix isLittleEndian - - - - - c26e81d1 by Ben Gamari at 2020-07-18T07:26:47-04:00 testsuite: Mark ghci tests as fragile under unreg compiler In particular I have seen T16012 fail repeatedly under the unregisterised compiler. - - - - - 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 293c7fba by Sylvain Henry at 2020-08-21T09:36:38-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - 50eb4460 by Sylvain Henry at 2020-08-21T09:36:38-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 659eb31b by Sylvain Henry at 2020-08-21T09:36:38-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 2d8ca917 by Sylvain Henry at 2020-08-21T09:37:15-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - fddddbf4 by Vladislav Zavialov at 2020-08-21T09:37:49-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - 989c1c27 by Ben Gamari at 2020-08-21T11:27:53-04:00 gitlab-ci: Test master branch as well While these builds are strictly speaking redundant (since every commit is tested by @marge-bot before making it into `master`), they are nevertheless useful as they are displayed in the branch's commit list in GitLab's web interface. Fixes #18595. - - - - - e67ae884 by Aditya Gupta at 2020-08-22T03:29:00-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - 03cfcfd4 by Wander Hillen at 2020-08-22T03:29:36-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 3f501545 by Craig Ferguson at 2020-08-22T03:30:13-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 8b865092 by Krzysztof Gogolewski at 2020-08-23T14:12:53+02:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - d8f61182 by Krzysztof Gogolewski at 2020-08-23T14:12:56+02:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - 364258e0 by Krzysztof Gogolewski at 2020-08-24T00:32:31-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - b1eb38a0 by Sylvain Henry at 2020-08-24T00:33:13-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 48a4f5dc by Ben Gamari at 2020-08-24T18:04:16-04:00 base: Better error message on invalid getSystemTimerManager call Previously we would produce a rather unhelpful pattern match failure error in the case where the user called `getSystemTimerManager` in a program which isn't built with `-threaded`. This understandably confused the user in #15616. Fixes #15616. - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/test-metrics.sh - CODEOWNERS - Makefile - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - + compiler/GHC/Builtin/RebindableNames.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/ByteCode/Types.hs - compiler/GHC/Cmm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/Dataflow/Block.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Graph.hs - compiler/GHC/Cmm/Info.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/353e1230538a9adeca25930d57190a6df88a4cdc...48a4f5dc6a0568a7fe4e24b2a3620a9d78f9ae58 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/353e1230538a9adeca25930d57190a6df88a4cdc...48a4f5dc6a0568a7fe4e24b2a3620a9d78f9ae58 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 22:21:02 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 18:21:02 -0400 Subject: [Git][ghc/ghc][wip/bump-text] Bump text submodule to 1.2.4.0+ Message-ID: <5f443d4ede833_80b1012800892739f0@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/bump-text at Glasgow Haskell Compiler / GHC Commits: 190c6c55 by Ben Gamari at 2020-08-24T18:20:56-04:00 Bump text submodule to 1.2.4.0+ Fixes #18588 and #17956. - - - - - 1 changed file: - libraries/text Changes: ===================================== libraries/text ===================================== @@ -1 +1 @@ -Subproject commit c6768a2a07e94b8b26d0f0e53517773de1110ce2 +Subproject commit 0b654f90c9af6461f10a0bb287da52a39393dd63 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/190c6c553a54d476dc55c9bb4275b5c096539b6e -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/190c6c553a54d476dc55c9bb4275b5c096539b6e You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 22:36:52 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Mon, 24 Aug 2020 18:36:52 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 5 commits: users-guide: Color the logo on the front page of the PDF Message-ID: <5f444104ca63e_80b3f84a401c3dc9279755@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 138c8083 by Takenobu Tani at 2020-08-24T18:36:30-04:00 users-guide: Color the logo on the front page of the PDF This patch updates the logo with a recent color scheme. This affects only the PDF version of the user's guide. See also: * https://mail.haskell.org/pipermail/ghc-devs/2020-August/019139.html * https://gitlab.haskell.org/ghc/ghc/-/wikis/logo [skip ci] - - - - - ba46d729 by Ben Gamari at 2020-08-24T18:36:31-04:00 SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' In #18069 we are observing MVar deadlocks from somewhere in ghc.exe. This use of MVar stood out as being one of the more likely culprits. Here we make sure that it is exception-safe. - - - - - 6cbab75d by Richard Eisenberg at 2020-08-24T18:36:33-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - 9c982a9d by Simon Peyton Jones at 2020-08-24T18:36:33-04:00 Use LIdP rather than (XRec p (IdP p)) This patch mainly just replaces use of XRec p (IdP p) with LIdP p One slightly more significant change is to parameterise HsPatSynDetails over the pass rather than the argument type, so that it's uniform with HsConDeclDetails and HsConPatDetails. I also got rid of the dead code GHC.Hs.type.conDetailsArgs But this is all just minor refactoring. No change in functionality. - - - - - faae584d by Krzysztof Gogolewski at 2020-08-24T18:36:39-04:00 Add a test for #18585 - - - - - 19 changed files: - compiler/GHC/Core/Type.hs - compiler/GHC/Core/Unify.hs - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Extension.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/Match/Constructor.hs - compiler/GHC/HsToCore/Quote.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Parser.y - compiler/GHC/SysTools/Process.hs - compiler/GHC/Tc/TyCl/PatSyn.hs - compiler/GHC/Tc/Utils/Zonk.hs - docs/users_guide/images/logo.pdf - + testsuite/tests/typecheck/should_compile/T18585.hs - testsuite/tests/typecheck/should_compile/all.T Changes: ===================================== compiler/GHC/Core/Type.hs ===================================== @@ -358,10 +358,28 @@ But in Core these two are treated as identical. We implement this by making 'coreView' convert 'Constraint' to 'TYPE LiftedRep' on the fly. The function tcView (used in the type checker) -does not do this. +does not do this. Accordingly, tcView is used in type-checker-oriented +functions (including the pure unifier, used in instance resolution), +while coreView is used during e.g. optimisation passes. See also #11715, which tracks removing this inconsistency. +The inconsistency actually leads to a potential soundness bug, in that +Constraint and Type are considered *apart* by the type family engine. +To wit, we can write + + type family F a + type instance F Type = Bool + type instance F Constraint = Int + +and (because Type ~# Constraint in Core), thus build a coercion between +Int and Bool. I (Richard E) conjecture that this never happens in practice, +but it's very uncomfortable. This, essentially, is the root problem +underneath #11715, which is quite resistant to an easy fix. The best +idea is to have roles in kind coercions, but that has yet to be implemented. +See also "A Role for Dependent Types in Haskell", ICFP 2019, which describes +how roles in kinds might work out. + -} -- | Gives the typechecker view of a type. This unwraps synonyms but ===================================== compiler/GHC/Core/Unify.hs ===================================== @@ -957,7 +957,7 @@ unify_ty :: UMEnv -- Respects newtypes, PredTypes unify_ty env ty1 ty2 kco - -- TODO: More commentary needed here + -- Use tcView, not coreView. See Note [coreView vs tcView] in GHC.Core.Type. | Just ty1' <- tcView ty1 = unify_ty env ty1' ty2 kco | Just ty2' <- tcView ty2 = unify_ty env ty1 ty2' kco | CastTy ty1' co <- ty1 = if um_unif env @@ -1121,7 +1121,8 @@ uUnrefined :: UMEnv -- We know that tv1 isn't refined uUnrefined env tv1' ty2 ty2' kco - | Just ty2'' <- coreView ty2' + -- Use tcView, not coreView. See Note [coreView vs tcView] in GHC.Core.Type. + | Just ty2'' <- tcView ty2' = uUnrefined env tv1' ty2 ty2'' kco -- Unwrap synonyms -- This is essential, in case we have -- type Foo a = a @@ -1412,6 +1413,8 @@ ty_co_match :: MatchEnv -- ^ ambient helpful info -> Maybe LiftCoEnv ty_co_match menv subst ty co lkco rkco | Just ty' <- coreView ty = ty_co_match menv subst ty' co lkco rkco + -- why coreView here, not tcView? Because we're firmly after type-checking. + -- This function is used only during coercion optimisation. -- handle Refl case: | tyCoVarsOfType ty `isNotInDomainOf` subst ===================================== compiler/GHC/Hs/Binds.hs ===================================== @@ -243,7 +243,7 @@ data HsBindLR idL idR -- type Int -> forall a'. a' -> a' -- Notice that the coercion captures the free a'. - fun_id :: XRec idL (IdP idL), -- Note [fun_id in Match] in GHC.Hs.Expr + fun_id :: LIdP idL, -- Note [fun_id in Match] in GHC.Hs.Expr fun_matches :: MatchGroup idR (LHsExpr idR), -- ^ The payload @@ -369,9 +369,8 @@ type instance XXABExport (GhcPass p) = NoExtCon data PatSynBind idL idR = PSB { psb_ext :: XPSB idL idR, -- ^ Post renaming, FVs. -- See Note [Bind free vars] - psb_id :: XRec idL (IdP idL), -- ^ Name of the pattern synonym - psb_args :: HsPatSynDetails (XRec idR (IdP idR)), - -- ^ Formal parameter names + psb_id :: LIdP idL, -- ^ Name of the pattern synonym + psb_args :: HsPatSynDetails idR, -- ^ Formal parameter names psb_def :: LPat idR, -- ^ Right-hand side psb_dir :: HsPatSynDir idR -- ^ Directionality } @@ -893,7 +892,7 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation TypeSig (XTypeSig pass) - [XRec pass (IdP pass)] -- LHS of the signature; e.g. f,g,h :: blah + [LIdP pass] -- LHS of the signature; e.g. f,g,h :: blah (LHsSigWcType pass) -- RHS of the signature; can have wildcards -- | A pattern synonym type signature @@ -905,7 +904,7 @@ data Sig pass -- 'GHC.Parser.Annotation.AnnDot','GHC.Parser.Annotation.AnnDarrow' -- For details on above see note [Api annotations] in GHC.Parser.Annotation - | PatSynSig (XPatSynSig pass) [XRec pass (IdP pass)] (LHsSigType pass) + | PatSynSig (XPatSynSig pass) [LIdP pass] (LHsSigType pass) -- P :: forall a b. Req => Prov => ty -- | A signature for a class method @@ -918,7 +917,7 @@ data Sig pass -- -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnDefault', -- 'GHC.Parser.Annotation.AnnDcolon' - | ClassOpSig (XClassOpSig pass) Bool [XRec pass (IdP pass)] (LHsSigType pass) + | ClassOpSig (XClassOpSig pass) Bool [LIdP pass] (LHsSigType pass) -- | A type signature in generated code, notably the code -- generated for record selectors. We simply record @@ -950,8 +949,8 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | InlineSig (XInlineSig pass) - (XRec pass (IdP pass)) -- Function name - InlinePragma -- Never defaultInlinePragma + (LIdP pass) -- Function name + InlinePragma -- Never defaultInlinePragma -- | A specialisation pragma -- @@ -966,7 +965,7 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | SpecSig (XSpecSig pass) - (XRec pass (IdP pass)) -- Specialise a function or datatype ... + (LIdP pass) -- Specialise a function or datatype ... [LHsSigType pass] -- ... to these types InlinePragma -- The pragma on SPECIALISE_INLINE form. -- If it's just defaultInlinePragma, then we said @@ -996,7 +995,7 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | MinimalSig (XMinimalSig pass) - SourceText (LBooleanFormula (XRec pass (IdP pass))) + SourceText (LBooleanFormula (LIdP pass)) -- Note [Pragma source text] in GHC.Types.Basic -- | A "set cost centre" pragma for declarations @@ -1008,8 +1007,8 @@ data Sig pass -- > {-# SCC funName "cost_centre_name" #-} | SCCFunSig (XSCCFunSig pass) - SourceText -- Note [Pragma source text] in GHC.Types.Basic - (XRec pass (IdP pass)) -- Function name + SourceText -- Note [Pragma source text] in GHC.Types.Basic + (LIdP pass) -- Function name (Maybe (XRec pass StringLiteral)) -- | A complete match pragma -- @@ -1020,8 +1019,8 @@ data Sig pass -- synonym definitions. | CompleteMatchSig (XCompleteMatchSig pass) SourceText - (XRec pass [XRec pass (IdP pass)]) - (Maybe (XRec pass (IdP pass))) + (XRec pass [LIdP pass]) + (Maybe (LIdP pass)) | XSig !(XXSig pass) type instance XTypeSig (GhcPass p) = NoExtField @@ -1041,7 +1040,7 @@ type instance XXSig (GhcPass p) = NoExtCon type LFixitySig pass = XRec pass (FixitySig pass) -- | Fixity Signature -data FixitySig pass = FixitySig (XFixitySig pass) [XRec pass (IdP pass)] Fixity +data FixitySig pass = FixitySig (XFixitySig pass) [LIdP pass] Fixity | XFixitySig !(XXFixitySig pass) type instance XFixitySig (GhcPass p) = NoExtField @@ -1229,14 +1228,14 @@ pprMinimalSig (L _ bf) = ppr (fmap unLoc bf) -} -- | Haskell Pattern Synonym Details -type HsPatSynDetails arg = HsConDetails arg [RecordPatSynField arg] +type HsPatSynDetails pass = HsConDetails (LIdP pass) [RecordPatSynField (LIdP pass)] -- See Note [Record PatSyn Fields] -- | Record Pattern Synonym Field -data RecordPatSynField a +data RecordPatSynField fld = RecordPatSynField { - recordPatSynSelectorId :: a -- Selector name visible in rest of the file - , recordPatSynPatVar :: a + recordPatSynSelectorId :: fld -- Selector name visible in rest of the file + , recordPatSynPatVar :: fld -- Filled in by renamer, the name used internally -- by the pattern } deriving (Data, Functor) ===================================== compiler/GHC/Hs/Decls.hs ===================================== @@ -592,7 +592,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation SynDecl { tcdSExt :: XSynDecl pass -- ^ Post renameer, FVs - , tcdLName :: XRec pass (IdP pass) -- ^ Type constructor + , tcdLName :: LIdP pass -- ^ Type constructor , tcdTyVars :: LHsQTyVars pass -- ^ Type variables; for an -- associated type these -- include outer binders @@ -609,7 +609,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation DataDecl { tcdDExt :: XDataDecl pass -- ^ Post renamer, CUSK flag, FVs - , tcdLName :: XRec pass (IdP pass) -- ^ Type constructor + , tcdLName :: LIdP pass -- ^ Type constructor , tcdTyVars :: LHsQTyVars pass -- ^ Type variables -- See Note [TyVar binders for associated declarations] , tcdFixity :: LexicalFixity -- ^ Fixity used in the declaration @@ -617,7 +617,7 @@ data TyClDecl pass | ClassDecl { tcdCExt :: XClassDecl pass, -- ^ Post renamer, FVs tcdCtxt :: LHsContext pass, -- ^ Context... - tcdLName :: XRec pass (IdP pass), -- ^ Name of the class + tcdLName :: LIdP pass, -- ^ Name of the class tcdTyVars :: LHsQTyVars pass, -- ^ Class type variables tcdFixity :: LexicalFixity, -- ^ Fixity used in the declaration tcdFDs :: [LHsFunDep pass], -- ^ Functional deps @@ -637,7 +637,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | XTyClDecl !(XXTyClDecl pass) -type LHsFunDep pass = XRec pass (FunDep (XRec pass (IdP pass))) +type LHsFunDep pass = XRec pass (FunDep (LIdP pass)) data DataDeclRn = DataDeclRn { tcdDataCusk :: Bool -- ^ does this have a CUSK? @@ -1135,7 +1135,7 @@ type LFamilyDecl pass = XRec pass (FamilyDecl pass) data FamilyDecl pass = FamilyDecl { fdExt :: XCFamilyDecl pass , fdInfo :: FamilyInfo pass -- type/data, closed/open - , fdLName :: XRec pass (IdP pass) -- type constructor + , fdLName :: LIdP pass -- type constructor , fdTyVars :: LHsQTyVars pass -- type variables -- See Note [TyVar binders for associated declarations] , fdFixity :: LexicalFixity -- Fixity used in the declaration @@ -1168,7 +1168,7 @@ type LInjectivityAnn pass = XRec pass (InjectivityAnn pass) -- -- This will be represented as "InjectivityAnn `r` [`a`, `c`]" data InjectivityAnn pass - = InjectivityAnn (XRec pass (IdP pass)) [XRec pass (IdP pass)] + = InjectivityAnn (LIdP pass) [LIdP pass] -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : -- 'GHC.Parser.Annotation.AnnRarrow', 'GHC.Parser.Annotation.AnnVbar' @@ -1364,7 +1364,7 @@ type LStandaloneKindSig pass = XRec pass (StandaloneKindSig pass) data StandaloneKindSig pass = StandaloneKindSig (XStandaloneKindSig pass) - (XRec pass (IdP pass)) -- Why a single binder? See #16754 + (LIdP pass) -- Why a single binder? See #16754 (LHsSigType pass) -- Why not LHsSigWcType? See Note [Wildcards in standalone kind signatures] | XStandaloneKindSig !(XXStandaloneKindSig pass) @@ -1435,7 +1435,7 @@ type LConDecl pass = XRec pass (ConDecl pass) data ConDecl pass = ConDeclGADT { con_g_ext :: XConDeclGADT pass - , con_names :: [XRec pass (IdP pass)] + , con_names :: [LIdP pass] -- The following fields describe the type after the '::' -- See Note [GADT abstract syntax] @@ -1458,7 +1458,7 @@ data ConDecl pass | ConDeclH98 { con_ext :: XConDeclH98 pass - , con_name :: XRec pass (IdP pass) + , con_name :: LIdP pass , con_forall :: XRec pass Bool -- ^ True <=> explicit user-written forall @@ -1849,7 +1849,7 @@ type FamInstEqn pass rhs = HsImplicitBndrs pass (FamEqn pass rhs) data FamEqn pass rhs = FamEqn { feqn_ext :: XCFamEqn pass rhs - , feqn_tycon :: XRec pass (IdP pass) + , feqn_tycon :: LIdP pass , feqn_bndrs :: Maybe [LHsTyVarBndr () pass] -- ^ Optional quantified type vars , feqn_pats :: HsTyPats pass , feqn_fixity :: LexicalFixity -- ^ Fixity used in the declaration @@ -2214,13 +2214,13 @@ type LForeignDecl pass = XRec pass (ForeignDecl pass) data ForeignDecl pass = ForeignImport { fd_i_ext :: XForeignImport pass -- Post typechecker, rep_ty ~ sig_ty - , fd_name :: XRec pass (IdP pass) -- defines this name + , fd_name :: LIdP pass -- defines this name , fd_sig_ty :: LHsSigType pass -- sig_ty , fd_fi :: ForeignImport } | ForeignExport { fd_e_ext :: XForeignExport pass -- Post typechecker, rep_ty ~ sig_ty - , fd_name :: XRec pass (IdP pass) -- uses this name + , fd_name :: LIdP pass -- uses this name , fd_sig_ty :: LHsSigType pass -- sig_ty , fd_fe :: ForeignExport } -- ^ @@ -2402,8 +2402,8 @@ type LRuleBndr pass = XRec pass (RuleBndr pass) -- | Rule Binder data RuleBndr pass - = RuleBndr (XCRuleBndr pass) (XRec pass (IdP pass)) - | RuleBndrSig (XRuleBndrSig pass) (XRec pass (IdP pass)) (HsPatSigType pass) + = RuleBndr (XCRuleBndr pass) (LIdP pass) + | RuleBndrSig (XRuleBndrSig pass) (LIdP pass) (HsPatSigType pass) | XRuleBndr !(XXRuleBndr pass) -- ^ -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen', @@ -2505,7 +2505,7 @@ type instance XXWarnDecls (GhcPass _) = NoExtCon type LWarnDecl pass = XRec pass (WarnDecl pass) -- | Warning pragma Declaration -data WarnDecl pass = Warning (XWarning pass) [XRec pass (IdP pass)] WarningTxt +data WarnDecl pass = Warning (XWarning pass) [LIdP pass] WarningTxt | XWarnDecl !(XXWarnDecl pass) type instance XWarning (GhcPass _) = NoExtField @@ -2592,7 +2592,7 @@ type LRoleAnnotDecl pass = XRec pass (RoleAnnotDecl pass) -- | Role Annotation Declaration data RoleAnnotDecl pass = RoleAnnotDecl (XCRoleAnnotDecl pass) - (XRec pass (IdP pass)) -- type constructor + (LIdP pass) -- type constructor [XRec pass (Maybe Role)] -- optional annotations -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnType', -- 'GHC.Parser.Annotation.AnnRole' ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -242,9 +242,8 @@ is Less Cool because -- | A Haskell expression. data HsExpr p = HsVar (XVar p) - (XRec p (IdP p)) -- ^ Variable - - -- See Note [Located RdrNames] + (LIdP p) -- ^ Variable + -- See Note [Located RdrNames] | HsUnboundVar (XUnboundVar p) OccName -- ^ Unbound variable; also used for "holes" @@ -439,7 +438,7 @@ data HsExpr p -- For details on above see note [Api annotations] in GHC.Parser.Annotation | RecordCon { rcon_ext :: XRecordCon p - , rcon_con_name :: XRec p (IdP p) -- The constructor name; + , rcon_con_name :: LIdP p -- The constructor name; -- not used after type checking , rcon_flds :: HsRecordBinds p } -- The fields @@ -2987,7 +2986,7 @@ matchSeparator ThPatSplice = panic "unused" matchSeparator ThPatQuote = panic "unused" matchSeparator PatSyn = panic "unused" -pprMatchContext :: Outputable (IdP p) +pprMatchContext :: (Outputable (IdP p), UnXRec p) => HsMatchContext p -> SDoc pprMatchContext ctxt | want_an ctxt = text "an" <+> pprMatchContextNoun ctxt @@ -2997,11 +2996,11 @@ pprMatchContext ctxt want_an ProcExpr = True want_an _ = False -pprMatchContextNoun :: Outputable (IdP id) - => HsMatchContext id -> SDoc -pprMatchContextNoun (FunRhs {mc_fun=L _ fun}) +pprMatchContextNoun :: forall p. (Outputable (IdP p), UnXRec p) + => HsMatchContext p -> SDoc +pprMatchContextNoun (FunRhs {mc_fun=fun}) = text "equation for" - <+> quotes (ppr fun) + <+> quotes (ppr (unXRec @p fun)) pprMatchContextNoun CaseAlt = text "case alternative" pprMatchContextNoun IfAlt = text "multi-way if alternative" pprMatchContextNoun RecUpd = text "record-update construct" @@ -3016,8 +3015,8 @@ pprMatchContextNoun (StmtCtxt ctxt) = text "pattern binding in" pprMatchContextNoun PatSyn = text "pattern synonym declaration" ----------------- -pprAStmtContext, pprStmtContext :: Outputable (IdP id) - => HsStmtContext id -> SDoc +pprAStmtContext, pprStmtContext :: (Outputable (IdP p), UnXRec p) + => HsStmtContext p -> SDoc pprAStmtContext ctxt = article <+> pprStmtContext ctxt where pp_an = text "an" ===================================== compiler/GHC/Hs/Extension.hs ===================================== @@ -307,7 +307,7 @@ type family IdGhcP pass where IdGhcP 'Renamed = Name IdGhcP 'Typechecked = Id -type LIdP p = Located (IdP p) +type LIdP p = XRec p (IdP p) -- | Marks that a field uses the GhcRn variant even when the pass -- parameter is GhcTc. Useful for storing HsTypes in GHC.Hs.Exprs, say, because ===================================== compiler/GHC/Hs/Pat.hs ===================================== @@ -93,7 +93,7 @@ data Pat p -- AZ:TODO above comment needs to be updated | VarPat (XVarPat p) - (XRec p (IdP p)) -- ^ Variable Pattern + (LIdP p) -- ^ Variable Pattern -- See Note [Located RdrNames] in GHC.Hs.Expr | LazyPat (XLazyPat p) @@ -103,7 +103,7 @@ data Pat p -- For details on above see note [Api annotations] in GHC.Parser.Annotation | AsPat (XAsPat p) - (XRec p (IdP p)) (LPat p) -- ^ As pattern + (LIdP p) (LPat p) -- ^ As pattern -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnAt' -- For details on above see note [Api annotations] in GHC.Parser.Annotation @@ -224,7 +224,7 @@ data Pat p -- For details on above see note [Api annotations] in GHC.Parser.Annotation | NPlusKPat (XNPlusKPat p) -- Type of overall pattern - (XRec p (IdP p)) -- n+k pattern + (LIdP p) -- n+k pattern (XRec p (HsOverLit p)) -- It'll always be an HsIntegral (HsOverLit p) -- See Note [NPlusK patterns] in GHC.Tc.Gen.Pat -- NB: This could be (PostTc ...), but that induced a @@ -313,7 +313,7 @@ type instance XXPat GhcTc = CoPat type family ConLikeP x type instance ConLikeP GhcPs = RdrName -- IdP GhcPs -type instance ConLikeP GhcRn = Name -- IdP GhcRn +type instance ConLikeP GhcRn = Name -- IdP GhcRn type instance ConLikeP GhcTc = ConLike -- --------------------------------------------------------------------- ===================================== compiler/GHC/Hs/Type.hs ===================================== @@ -73,7 +73,6 @@ module GHC.Hs.Type ( mkHsOpTy, mkHsAppTy, mkHsAppTys, mkHsAppKindTy, ignoreParens, hsSigType, hsSigWcType, hsPatSigType, hsTyKindSig, - hsConDetailsArgs, setHsTyVarBndrFlag, hsTyVarBndrFlag, -- Printing @@ -638,13 +637,13 @@ data HsTyVarBndr flag pass = UserTyVar -- no explicit kinding (XUserTyVar pass) flag - (XRec pass (IdP pass)) + (LIdP pass) -- See Note [Located RdrNames] in GHC.Hs.Expr | KindedTyVar (XKindedTyVar pass) flag - (XRec pass (IdP pass)) + (LIdP pass) (LHsKind pass) -- The user-supplied kind signature -- ^ -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen', @@ -705,7 +704,7 @@ data HsType pass | HsTyVar (XTyVar pass) PromotionFlag -- Whether explicitly promoted, -- for the pretty printer - (XRec pass (IdP pass)) + (LIdP pass) -- Type variable, type constructor, or data constructor -- see Note [Promotions (HsTyVar)] -- See Note [Located RdrNames] in GHC.Hs.Expr @@ -755,7 +754,7 @@ data HsType pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | HsOpTy (XOpTy pass) - (LHsType pass) (XRec pass (IdP pass)) (LHsType pass) + (LHsType pass) (LIdP pass) (LHsType pass) -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : None -- For details on above see note [Api annotations] in GHC.Parser.Annotation @@ -1116,14 +1115,6 @@ instance (Outputable arg, Outputable rec) ppr (RecCon rec) = text "RecCon:" <+> ppr rec ppr (InfixCon l r) = text "InfixCon:" <+> ppr [l, r] -hsConDetailsArgs :: - HsConDetails (LHsType (GhcPass p)) (Located [LConDeclField (GhcPass p)]) - -> [LHsType (GhcPass p)] -hsConDetailsArgs details = case details of - InfixCon a b -> [a,b] - PrefixCon xs -> xs - RecCon r -> map (cd_fld_type . unLoc) (unLoc r) - {- Note [ConDeclField passs] ~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/Hs/Utils.hs ===================================== @@ -777,7 +777,7 @@ mkVarBind var rhs = L (getLoc rhs) $ VarBind { var_ext = noExtField, var_id = var, var_rhs = rhs } -mkPatSynBind :: Located RdrName -> HsPatSynDetails (Located RdrName) +mkPatSynBind :: Located RdrName -> HsPatSynDetails GhcPs -> LPat GhcPs -> HsPatSynDir GhcPs -> HsBind GhcPs mkPatSynBind name details lpat dir = PatSynBind noExtField psb where @@ -990,7 +990,7 @@ collect_bind omitPatSyn (PatSynBind _ (PSB { psb_id = ps })) acc collect_bind _ (PatSynBind _ (XPatSynBind _)) acc = acc collect_bind _ (XHsBindsLR _) acc = acc -collectMethodBinders :: forall idL idR. UnXRec idL => LHsBindsLR idL idR -> [XRec idL (IdP idL)] +collectMethodBinders :: forall idL idR. UnXRec idL => LHsBindsLR idL idR -> [LIdP idL] -- ^ Used exclusively for the bindings of an instance decl which are all -- 'FunBinds' collectMethodBinders binds = foldr (get . unXRec @idL) [] binds @@ -1173,7 +1173,7 @@ hsLTyClDeclBinders (L loc (DataDecl { tcdLName = (L _ name) ------------------- -hsForeignDeclsBinders :: forall pass. (UnXRec pass, MapXRec pass) => [LForeignDecl pass] -> [XRec pass (IdP pass)] +hsForeignDeclsBinders :: forall pass. (UnXRec pass, MapXRec pass) => [LForeignDecl pass] -> [LIdP pass] -- ^ See Note [SrcSpan for binders] hsForeignDeclsBinders foreign_decls = [ mapXRec @pass (const $ unXRec @pass n) fi ===================================== compiler/GHC/HsToCore/Match/Constructor.hs ===================================== @@ -126,7 +126,7 @@ matchPatSyn (var :| vars) ty eqns PatSynCon psyn -> alt{ alt_pat = psyn } _ -> panic "matchPatSyn: not PatSynCon" -type ConArgPats = HsConDetails (LPat GhcTc) (HsRecFields GhcTc (LPat GhcTc)) +type ConArgPats = HsConPatDetails GhcTc matchOneConLike :: [Id] -> Type ===================================== compiler/GHC/HsToCore/Quote.hs ===================================== @@ -1840,7 +1840,7 @@ rep_bind (L loc (PatSynBind _ (PSB { psb_id = syn ; patSynD'' <- wrapGenArgSyms args ss patSynD' ; return (loc, patSynD'') } where - mkGenArgSyms :: HsPatSynDetails (Located Name) -> MetaM [GenSymBind] + mkGenArgSyms :: HsPatSynDetails GhcRn -> MetaM [GenSymBind] -- for Record Pattern Synonyms we want to conflate the selector -- and the pattern-only names in order to provide a nicer TH -- API. Whereas inside GHC, record pattern synonym selectors and @@ -1859,7 +1859,7 @@ rep_bind (L loc (PatSynBind _ (PSB { psb_id = syn = [ (pat, id) | (sel, id) <- genSyms, (sel', pat) <- selsPats , sel == sel' ] - wrapGenArgSyms :: HsPatSynDetails (Located Name) + wrapGenArgSyms :: HsPatSynDetails GhcRn -> [GenSymBind] -> Core (M TH.Dec) -> MetaM (Core (M TH.Dec)) wrapGenArgSyms (RecCon _) _ dec = return dec wrapGenArgSyms _ ss dec = wrapGenSyms ss dec @@ -1872,7 +1872,7 @@ repPatSynD :: Core TH.Name repPatSynD (MkC syn) (MkC args) (MkC dir) (MkC pat) = rep2 patSynDName [syn, args, dir, pat] -repPatSynArgs :: HsPatSynDetails (Located Name) -> MetaM (Core (M TH.PatSynArgs)) +repPatSynArgs :: HsPatSynDetails GhcRn -> MetaM (Core (M TH.PatSynArgs)) repPatSynArgs (PrefixCon args) = do { args' <- repList nameTyConName lookupLOcc args ; repPrefixPatSynArgs args' } ===================================== compiler/GHC/HsToCore/Utils.hs ===================================== @@ -900,7 +900,7 @@ CPR-friendly. This matters a lot: if you don't get it right, you lose the tail call property. For example, see #3403. -} -dsHandleMonadicFailure :: Outputable (IdP p) => HsStmtContext p -> LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr +dsHandleMonadicFailure :: HsStmtContext GhcRn -> LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr -- In a do expression, pattern-match failure just calls -- the monadic 'fail' rather than throwing an exception dsHandleMonadicFailure ctx pat match m_fail_op = @@ -921,8 +921,9 @@ dsHandleMonadicFailure ctx pat match m_fail_op = fail_expr <- dsSyntaxExpr fail_op [fail_msg] body fail_expr -mk_fail_msg :: Outputable (IdP p) => DynFlags -> HsStmtContext p -> Located e -> String -mk_fail_msg dflags ctx pat = showPpr dflags $ text "Pattern match failure in" <+> pprStmtContext ctx <+> text "at" <+> ppr (getLoc pat) +mk_fail_msg :: DynFlags -> HsStmtContext GhcRn -> Located e -> String +mk_fail_msg dflags ctx pat + = showPpr dflags $ text "Pattern match failure in" <+> pprStmtContext ctx <+> text "at" <+> ppr (getLoc pat) {- ********************************************************************* * * ===================================== compiler/GHC/Parser.y ===================================== @@ -1491,7 +1491,7 @@ pattern_synonym_decl :: { LHsDecl GhcPs } (as ++ ((mj AnnPattern $1:mu AnnLarrow $3:(fst $ unLoc $5))) ) }} -pattern_synonym_lhs :: { (Located RdrName, HsPatSynDetails (Located RdrName), [AddAnn]) } +pattern_synonym_lhs :: { (Located RdrName, HsPatSynDetails GhcPs, [AddAnn]) } : con vars0 { ($1, PrefixCon $2, []) } | varid conop varid { ($2, InfixCon $1 $3, []) } | con '{' cvars1 '}' { ($1, RecCon $3, [moc $2, mcc $4] ) } ===================================== compiler/GHC/SysTools/Process.hs ===================================== @@ -45,6 +45,15 @@ enableProcessJobs opts = opts enableProcessJobs opts = opts #endif +#if !MIN_VERSION_base(4,15,0) +-- TODO: This can be dropped with GHC 8.16 +hGetContents' :: Handle -> IO String +hGetContents' hdl = do + output <- hGetContents hdl + _ <- evaluate $ length output + return output +#endif + -- Similar to System.Process.readCreateProcessWithExitCode, but stderr is -- inherited from the parent process, and output to stderr is not captured. readCreateProcessWithExitCode' @@ -55,13 +64,19 @@ readCreateProcessWithExitCode' proc = do createProcess $ enableProcessJobs $ proc{ std_out = CreatePipe } -- fork off a thread to start consuming the output - output <- hGetContents outh outMVar <- newEmptyMVar - _ <- forkIO $ evaluate (length output) >> putMVar outMVar () + let onError :: SomeException -> IO () + onError exc = putMVar outMVar (Left exc) + _ <- forkIO $ handle onError $ do + output <- hGetContents' outh + putMVar outMVar $ Right output -- wait on the output - takeMVar outMVar + result <- takeMVar outMVar hClose outh + output <- case result of + Left exc -> throwIO exc + Right output -> return output -- wait on the process ex <- waitForProcess pid ===================================== compiler/GHC/Tc/TyCl/PatSyn.hs ===================================== @@ -558,7 +558,7 @@ a pattern synonym. What about the /building/ side? a bad idea. -} -collectPatSynArgInfo :: HsPatSynDetails (Located Name) +collectPatSynArgInfo :: HsPatSynDetails GhcRn -> ([Name], [Name], Bool) collectPatSynArgInfo details = case details of ===================================== compiler/GHC/Tc/Utils/Zonk.hs ===================================== @@ -626,8 +626,8 @@ zonk_bind env (PatSynBind x bind@(PSB { psb_id = L loc id , psb_dir = dir' } } zonkPatSynDetails :: ZonkEnv - -> HsPatSynDetails (Located TcId) - -> HsPatSynDetails (Located Id) + -> HsPatSynDetails GhcTc + -> HsPatSynDetails GhcTc zonkPatSynDetails env (PrefixCon as) = PrefixCon (map (zonkLIdOcc env) as) zonkPatSynDetails env (InfixCon a1 a2) @@ -1450,10 +1450,8 @@ zonk_pat env (XPat (CoPat co_fn pat ty)) zonk_pat _ pat = pprPanic "zonk_pat" (ppr pat) --------------------------- -zonkConStuff :: ZonkEnv - -> HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc)) - -> TcM (ZonkEnv, - HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc))) +zonkConStuff :: ZonkEnv -> HsConPatDetails GhcTc + -> TcM (ZonkEnv, HsConPatDetails GhcTc) zonkConStuff env (PrefixCon pats) = do { (env', pats') <- zonkPats env pats ; return (env', PrefixCon pats') } ===================================== docs/users_guide/images/logo.pdf ===================================== Binary files a/docs/users_guide/images/logo.pdf and b/docs/users_guide/images/logo.pdf differ ===================================== testsuite/tests/typecheck/should_compile/T18585.hs ===================================== @@ -0,0 +1,48 @@ +{-# Language DataKinds #-} +{-# Language FlexibleContexts #-} +{-# Language PolyKinds #-} +{-# Language StandaloneKindSignatures #-} +{-# Language TypeFamilyDependencies #-} +{-# Language UndecidableInstances #-} +{-# Language UndecidableSuperClasses #-} +module T18585 (Functor(..)) where + +import Data.Kind (Type) +import Prelude hiding (Functor(..)) + +type Cat i = i -> i -> Type + +class + ( Op (Op k) ~ k + , Category (Op k) + ) => Category (k :: Cat i) where + type Op k :: i -> i -> Type + type Op k = Y k + +newtype Y k a b = Y (k b a) + +instance (Category k, Op k ~ Y k) => Category (Y k) where + type Op (Y k) = k + +instance Category (->) + +type SelfDom :: (i -> j) -> Cat i -> Cat i +type family SelfDom (f :: i -> j) (k :: Cat i) :: Cat i where + SelfDom p p = Op p + SelfDom f p = p + +type family DefaultCat (i :: Type) = (res :: Cat i) | res -> i +type instance DefaultCat Type = (->) + +class + ( Category (Dom f) + , Category (Cod f) + ) => Functor (f :: i -> j) where + + type Dom f :: Cat i + type Dom (f :: i -> j) = SelfDom f (DefaultCat i) + + type Cod f :: Cat j + type Cod (f :: i -> j) = DefaultCat j + +instance Functor IO ===================================== testsuite/tests/typecheck/should_compile/all.T ===================================== @@ -721,4 +721,5 @@ test('T18118', normal, multimod_compile, ['T18118', '-v0']) test('T18412', normal, compile, ['']) test('T18470', normal, compile, ['']) test('T18323', normal, compile, ['']) +test('T18585', normal, compile, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/569ed08314d2f9e7ea36e0df1573f345a1720d18...faae584d4710f987df10243f0b39bf8b54b4b705 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/569ed08314d2f9e7ea36e0df1573f345a1720d18...faae584d4710f987df10243f0b39bf8b54b4b705 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 24 22:55:46 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 18:55:46 -0400 Subject: [Git][ghc/ghc][wip/ci-fixes] 3 commits: testsuite: Drop Windows-specific output for parseTree Message-ID: <5f44457231f58_80b3f8495bc8b049284054@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/ci-fixes at Glasgow Haskell Compiler / GHC Commits: fbe8252c by Ben Gamari at 2020-08-24T18:01:53-04:00 testsuite: Drop Windows-specific output for parseTree The normalise_slashes normaliser should handle this. - - - - - ed142d46 by Ben Gamari at 2020-08-24T18:02:03-04:00 testsuite: Mark T5975[ab] as broken on Windows Due to #7305. - - - - - af50e339 by Ben Gamari at 2020-08-24T18:03:35-04:00 gitlab-ci: Fix typo A small typo in a rule regular expression. - - - - - 3 changed files: - .gitlab-ci.yml - − testsuite/tests/ghc-api/annotations/parseTree.stdout-mingw32 - testsuite/tests/ghci/scripts/all.T Changes: ===================================== .gitlab-ci.yml ===================================== @@ -48,7 +48,7 @@ workflow: - if: $CI_MERGE_REQUEST_ID - if: $CI_COMMIT_TAG - if: '$CI_COMMIT_BRANCH == "wip/marge_bot_batch_merge_job"' - - if: '$CI_COMMIT_BRANCH =~ /ghc-[0.9]+\.[0-9]+/' + - if: '$CI_COMMIT_BRANCH =~ /ghc-[0-9]+\.[0-9]+/' - if: '$CI_PIPELINE_SOURCE == "web"' .nightly: &nightly ===================================== testsuite/tests/ghc-api/annotations/parseTree.stdout-mingw32 deleted ===================================== @@ -1,160 +0,0 @@ -[(AnnotationTuple.hs:14:20, [p], Solo 1), - (AnnotationTuple.hs:14:23-29, [p], Solo "hello"), - (AnnotationTuple.hs:14:35-37, [p], Solo 6.5), - (AnnotationTuple.hs:14:39, [m], ()), - (AnnotationTuple.hs:14:41-52, [p], Solo [5, 5, 6, 7]), - (AnnotationTuple.hs:16:8, [p], Solo 1), - (AnnotationTuple.hs:16:11-17, [p], Solo "hello"), - (AnnotationTuple.hs:16:20-22, [p], Solo 6.5), - (AnnotationTuple.hs:16:24, [m], ()), - (AnnotationTuple.hs:16:25, [m], ()), - (AnnotationTuple.hs:16:26, [m], ()), (, [m], ())] -[ -(AK AnnotationTuple.hs:1:1 AnnCloseC = [AnnotationTuple.hs:27:1]) - -(AK AnnotationTuple.hs:1:1 AnnModule = [AnnotationTuple.hs:3:1-6]) - -(AK AnnotationTuple.hs:1:1 AnnOpenC = [AnnotationTuple.hs:5:1]) - -(AK AnnotationTuple.hs:1:1 AnnWhere = [AnnotationTuple.hs:3:30-34]) - -(AK AnnotationTuple.hs:3:24-28 AnnCloseP = [AnnotationTuple.hs:3:28]) - -(AK AnnotationTuple.hs:3:24-28 AnnOpenP = [AnnotationTuple.hs:3:24]) - -(AK AnnotationTuple.hs:6:1-32 AnnAs = [AnnotationTuple.hs:6:28-29]) - -(AK AnnotationTuple.hs:6:1-32 AnnImport = [AnnotationTuple.hs:6:1-6]) - -(AK AnnotationTuple.hs:6:1-32 AnnQualified = [AnnotationTuple.hs:6:8-16]) - -(AK AnnotationTuple.hs:6:1-32 AnnSemi = [AnnotationTuple.hs:7:1]) - -(AK AnnotationTuple.hs:(8,1)-(11,14) AnnEqual = [AnnotationTuple.hs:8:5]) - -(AK AnnotationTuple.hs:(8,1)-(11,14) AnnFunId = [AnnotationTuple.hs:8:1-3]) - -(AK AnnotationTuple.hs:(8,1)-(11,14) AnnSemi = [AnnotationTuple.hs:13:1]) - -(AK AnnotationTuple.hs:(8,7)-(11,14) AnnIn = [AnnotationTuple.hs:11:7-8]) - -(AK AnnotationTuple.hs:(8,7)-(11,14) AnnLet = [AnnotationTuple.hs:8:7-9]) - -(AK AnnotationTuple.hs:9:9-13 AnnEqual = [AnnotationTuple.hs:9:11]) - -(AK AnnotationTuple.hs:9:9-13 AnnFunId = [AnnotationTuple.hs:9:9]) - -(AK AnnotationTuple.hs:9:9-13 AnnSemi = [AnnotationTuple.hs:10:9]) - -(AK AnnotationTuple.hs:10:9-13 AnnEqual = [AnnotationTuple.hs:10:11]) - -(AK AnnotationTuple.hs:10:9-13 AnnFunId = [AnnotationTuple.hs:10:9]) - -(AK AnnotationTuple.hs:11:10-14 AnnVal = [AnnotationTuple.hs:11:12]) - -(AK AnnotationTuple.hs:14:1-72 AnnEqual = [AnnotationTuple.hs:14:5]) - -(AK AnnotationTuple.hs:14:1-72 AnnFunId = [AnnotationTuple.hs:14:1-3]) - -(AK AnnotationTuple.hs:14:1-72 AnnSemi = [AnnotationTuple.hs:15:1]) - -(AK AnnotationTuple.hs:14:7-72 AnnVal = [AnnotationTuple.hs:14:13]) - -(AK AnnotationTuple.hs:14:19-53 AnnCloseP = [AnnotationTuple.hs:14:53]) - -(AK AnnotationTuple.hs:14:19-53 AnnOpenP = [AnnotationTuple.hs:14:19]) - -(AK AnnotationTuple.hs:14:20 AnnComma = [AnnotationTuple.hs:14:21]) - -(AK AnnotationTuple.hs:14:23-29 AnnComma = [AnnotationTuple.hs:14:33]) - -(AK AnnotationTuple.hs:14:35-37 AnnComma = [AnnotationTuple.hs:14:38]) - -(AK AnnotationTuple.hs:14:39 AnnComma = [AnnotationTuple.hs:14:39]) - -(AK AnnotationTuple.hs:14:41-52 AnnCloseS = [AnnotationTuple.hs:14:52]) - -(AK AnnotationTuple.hs:14:41-52 AnnOpenS = [AnnotationTuple.hs:14:41]) - -(AK AnnotationTuple.hs:14:42 AnnComma = [AnnotationTuple.hs:14:43]) - -(AK AnnotationTuple.hs:14:45 AnnComma = [AnnotationTuple.hs:14:46]) - -(AK AnnotationTuple.hs:14:48 AnnComma = [AnnotationTuple.hs:14:49]) - -(AK AnnotationTuple.hs:14:55-72 AnnCloseS = [AnnotationTuple.hs:14:72]) - -(AK AnnotationTuple.hs:14:55-72 AnnOpenS = [AnnotationTuple.hs:14:55]) - -(AK AnnotationTuple.hs:14:56-62 AnnComma = [AnnotationTuple.hs:14:63]) - -(AK AnnotationTuple.hs:14:61-62 AnnCloseP = [AnnotationTuple.hs:14:62]) - -(AK AnnotationTuple.hs:14:61-62 AnnOpenP = [AnnotationTuple.hs:14:61]) - -(AK AnnotationTuple.hs:16:1-41 AnnEqual = [AnnotationTuple.hs:16:5]) - -(AK AnnotationTuple.hs:16:1-41 AnnFunId = [AnnotationTuple.hs:16:1-3]) - -(AK AnnotationTuple.hs:16:1-41 AnnSemi = [AnnotationTuple.hs:17:1]) - -(AK AnnotationTuple.hs:16:7-27 AnnCloseP = [AnnotationTuple.hs:16:27]) - -(AK AnnotationTuple.hs:16:7-27 AnnOpenP = [AnnotationTuple.hs:16:7]) - -(AK AnnotationTuple.hs:16:8 AnnComma = [AnnotationTuple.hs:16:9]) - -(AK AnnotationTuple.hs:16:11-17 AnnComma = [AnnotationTuple.hs:16:18]) - -(AK AnnotationTuple.hs:16:20-22 AnnComma = [AnnotationTuple.hs:16:23]) - -(AK AnnotationTuple.hs:16:24 AnnComma = [AnnotationTuple.hs:16:24]) - -(AK AnnotationTuple.hs:16:25 AnnComma = [AnnotationTuple.hs:16:25]) - -(AK AnnotationTuple.hs:16:26 AnnComma = [AnnotationTuple.hs:16:26]) - -(AK AnnotationTuple.hs:16:33-41 AnnCloseP = [AnnotationTuple.hs:16:41]) - -(AK AnnotationTuple.hs:16:33-41 AnnOpenP = [AnnotationTuple.hs:16:33]) - -(AK AnnotationTuple.hs:16:39-40 AnnCloseP = [AnnotationTuple.hs:16:40]) - -(AK AnnotationTuple.hs:16:39-40 AnnOpenP = [AnnotationTuple.hs:16:39]) - -(AK AnnotationTuple.hs:18:1-28 AnnData = [AnnotationTuple.hs:18:1-4]) - -(AK AnnotationTuple.hs:18:1-28 AnnDcolon = [AnnotationTuple.hs:18:20-21]) - -(AK AnnotationTuple.hs:18:1-28 AnnFamily = [AnnotationTuple.hs:18:6-11]) - -(AK AnnotationTuple.hs:18:1-28 AnnSemi = [AnnotationTuple.hs:19:1]) - -(AK AnnotationTuple.hs:18:23 AnnRarrow = [AnnotationTuple.hs:18:25-26]) - -(AK AnnotationTuple.hs:18:23-28 AnnRarrow = [AnnotationTuple.hs:18:25-26]) - -(AK AnnotationTuple.hs:(20,1)-(24,14) AnnFunId = [AnnotationTuple.hs:20:1-5]) - -(AK AnnotationTuple.hs:(20,1)-(24,14) AnnSemi = [AnnotationTuple.hs:25:1]) - -(AK AnnotationTuple.hs:(21,7)-(24,14) AnnEqual = [AnnotationTuple.hs:24:7]) - -(AK AnnotationTuple.hs:(21,7)-(24,14) AnnVbar = [AnnotationTuple.hs:21:7]) - -(AK AnnotationTuple.hs:21:9-24 AnnComma = [AnnotationTuple.hs:22:7]) - -(AK AnnotationTuple.hs:21:9-24 AnnLarrow = [AnnotationTuple.hs:21:16-17]) - -(AK AnnotationTuple.hs:22:9-25 AnnComma = [AnnotationTuple.hs:23:7]) - -(AK AnnotationTuple.hs:22:9-25 AnnLarrow = [AnnotationTuple.hs:22:16-17]) - -(AK AnnotationTuple.hs:23:9-24 AnnLarrow = [AnnotationTuple.hs:23:16-17]) - -(AK AnnotationTuple.hs:26:1-10 AnnDcolon = [AnnotationTuple.hs:26:5-6]) - -(AK AnnotationTuple.hs:26:1-14 AnnEqual = [AnnotationTuple.hs:26:12]) -] - -EOF: Just SrcSpanPoint ".\\AnnotationTuple.hs" 32 1 ===================================== testsuite/tests/ghci/scripts/all.T ===================================== @@ -141,8 +141,11 @@ test('T5979', normalise_slashes, normalise_version("transformers")], ghci_script, ['T5979.script']) -test('T5975a', [pre_cmd('touch föøbàr1.hs')], ghci_script, ['T5975a.script']) -test('T5975b', [pre_cmd('touch föøbàr2.hs'), extra_hc_opts('föøbàr2.hs')], +test('T5975a', + [pre_cmd('touch föøbàr1.hs'), when(opsys('mingw32'), expect_broken(7305))], + ghci_script, ['T5975a.script']) +test('T5975b', + [pre_cmd('touch föøbàr2.hs'), extra_hc_opts('föøbàr2.hs'), when(opsys('mingw32'), expect_broken(7305))], ghci_script, ['T5975b.script']) test('T6027ghci', normal, ghci_script, ['T6027ghci.script']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0da276d60a56096a224b56e67786071c9e8b8b00...af50e339d67db1af40bc30164c3062d49ac47446 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0da276d60a56096a224b56e67786071c9e8b8b00...af50e339d67db1af40bc30164c3062d49ac47446 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 01:28:11 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 21:28:11 -0400 Subject: [Git][ghc/ghc][wip/stgMalloc] rts: Consistently use stgMallocBytes instead of malloc Message-ID: <5f44692bc734c_80b3f846a81b61c9302939@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/stgMalloc at Glasgow Haskell Compiler / GHC Commits: 1d1d21b2 by GHC GitLab CI at 2020-08-24T21:28:04-04:00 rts: Consistently use stgMallocBytes instead of malloc This can help in debugging RTS memory leaks since all allocations go through the same interface. - - - - - 5 changed files: - rts/linker/PEi386.c - rts/win32/IOManager.c - rts/win32/OSThreads.c - rts/win32/WorkQueue.c - rts/xxhash.c Changes: ===================================== rts/linker/PEi386.c ===================================== @@ -735,7 +735,7 @@ addDLL_PEi386( pathchar *dll_name, HINSTANCE *loaded ) error: stgFree(buf); - char* errormsg = malloc(sizeof(char) * 80); + char* errormsg = stgMallocBytes(sizeof(char) * 80, "addDLL_PEi386"); snprintf(errormsg, 80, "addDLL: %" PATH_FMT " or dependencies not loaded. (Win32 error %lu)", dll_name, GetLastError()); /* LoadLibrary failed; return a ptr to the error msg. */ return errormsg; @@ -745,7 +745,7 @@ pathchar* findSystemLibrary_PEi386( pathchar* dll_name ) { const unsigned int init_buf_size = 1024; unsigned int bufsize = init_buf_size; - wchar_t* result = malloc(sizeof(wchar_t) * bufsize); + wchar_t* result = stgMallocBytes(sizeof(wchar_t) * bufsize, "findSystemLibrary_PEi386"); DWORD wResult = SearchPathW(NULL, dll_name, NULL, bufsize, result, NULL); if (wResult > bufsize) { @@ -755,7 +755,7 @@ pathchar* findSystemLibrary_PEi386( pathchar* dll_name ) if (!wResult) { - free(result); + stgFree(result); return NULL; } @@ -773,7 +773,7 @@ HsPtr addLibrarySearchPath_PEi386(pathchar* dll_path) int bufsize = init_buf_size; // Make sure the path is an absolute path - WCHAR* abs_path = malloc(sizeof(WCHAR) * init_buf_size); + WCHAR* abs_path = stgMallocBytes(sizeof(WCHAR) * init_buf_size, "addLibrarySearchPath_PEi386(1)"); DWORD wResult = GetFullPathNameW(dll_path, bufsize, abs_path, NULL); if (!wResult){ IF_DEBUG(linker, debugBelch("addLibrarySearchPath[GetFullPathNameW]: %" PATH_FMT " (Win32 error %lu)", dll_path, GetLastError())); @@ -791,7 +791,7 @@ HsPtr addLibrarySearchPath_PEi386(pathchar* dll_path) else { warnMissingKBLibraryPaths(); - WCHAR* str = malloc(sizeof(WCHAR) * init_buf_size); + WCHAR* str = stgMallocBytes(sizeof(WCHAR) * init_buf_size, "addLibrarySearchPath_PEi386(2)"); wResult = GetEnvironmentVariableW(L"PATH", str, bufsize); if (wResult > init_buf_size) { @@ -804,7 +804,7 @@ HsPtr addLibrarySearchPath_PEi386(pathchar* dll_path) } bufsize = wResult + 2 + pathlen(abs_path); - wchar_t* newPath = malloc(sizeof(wchar_t) * bufsize); + wchar_t* newPath = stgMallocBytes(sizeof(wchar_t) * bufsize, "addLibrarySearchPath_PEi386(3)"); wcscpy(newPath, abs_path); wcscat(newPath, L";"); @@ -813,19 +813,19 @@ HsPtr addLibrarySearchPath_PEi386(pathchar* dll_path) sysErrorBelch("addLibrarySearchPath[SetEnvironmentVariableW]: %" PATH_FMT " (Win32 error %lu)", abs_path, GetLastError()); } - free(newPath); - free(abs_path); + stgFree(newPath); + stgFree(abs_path); return str; } if (!result) { sysErrorBelch("addLibrarySearchPath: %" PATH_FMT " (Win32 error %lu)", abs_path, GetLastError()); - free(abs_path); + stgFree(abs_path); return NULL; } - free(abs_path); + stgFree(abs_path); return result; } ===================================== rts/win32/IOManager.c ===================================== @@ -265,7 +265,7 @@ IOWorkerProc(PVOID param) } // Free the WorkItem DeregisterWorkItem(iom,work); - free(work); + stgFree(work); } else { fprintf(stderr, "unable to fetch work; fatal.\n"); fflush(stderr); @@ -321,7 +321,7 @@ StartIOManager(void) wq = NewWorkQueue(); if ( !wq ) return false; - ioMan = (IOManagerState*)malloc(sizeof(IOManagerState)); + ioMan = (IOManagerState*)stgMallocBytes(sizeof(IOManagerState), "StartIOManager"); if (!ioMan) { FreeWorkQueue(wq); @@ -332,7 +332,7 @@ StartIOManager(void) hExit = CreateEvent ( NULL, true, false, NULL ); if ( !hExit ) { FreeWorkQueue(wq); - free(ioMan); + stgFree(ioMan); return false; } @@ -440,8 +440,7 @@ AddIORequest ( int fd, { ASSERT(ioMan); - WorkItem* wItem = (WorkItem*)malloc(sizeof(WorkItem)); - if (!wItem) return 0; + WorkItem* wItem = (WorkItem*)stgMallocBytes(sizeof(WorkItem), "AddIORequest"); unsigned int reqID = ioMan->requestID++; @@ -471,8 +470,7 @@ AddDelayRequest ( HsInt usecs, { ASSERT(ioMan); - WorkItem* wItem = (WorkItem*)malloc(sizeof(WorkItem)); - if (!wItem) return false; + WorkItem* wItem = (WorkItem*)stgMallocBytes(sizeof(WorkItem), "AddDelayRequest"); unsigned int reqID = ioMan->requestID++; @@ -498,7 +496,7 @@ AddProcRequest ( void* proc, { ASSERT(ioMan); - WorkItem* wItem = (WorkItem*)malloc(sizeof(WorkItem)); + WorkItem* wItem = (WorkItem*)stgMallocBytes(sizeof(WorkItem), "AddProcRequest"); if (!wItem) return false; unsigned int reqID = ioMan->requestID++; @@ -542,7 +540,7 @@ void ShutdownIOManager ( bool wait_threads ) barf("timeEndPeriod failed"); } - free(ioMan); + stgFree(ioMan); ioMan = NULL; } } ===================================== rts/win32/OSThreads.c ===================================== @@ -171,19 +171,19 @@ void freeThreadingResources (void) { if (cpuGroupCache) { - free(cpuGroupCache); + stgFree(cpuGroupCache); cpuGroupCache = NULL; } if (cpuGroupCumulativeCache) { - free(cpuGroupCumulativeCache); + stgFree(cpuGroupCumulativeCache); cpuGroupCumulativeCache = NULL; } if (cpuGroupDistCache) { - free(cpuGroupDistCache); + stgFree(cpuGroupDistCache); cpuGroupDistCache = NULL; } } @@ -240,7 +240,7 @@ getProcessorsDistribution (void) if (!cpuGroupDistCache) { uint8_t n_groups = getNumberOfProcessorsGroups(); - cpuGroupDistCache = malloc(n_groups * sizeof(uint8_t)); + cpuGroupDistCache = stgMallocBytes(n_groups * sizeof(uint8_t), "getProcessorsDistribution"); memset(cpuGroupDistCache, MAXIMUM_PROCESSORS, n_groups * sizeof(uint8_t)); for (int i = 0; i < n_groups; i++) @@ -265,7 +265,7 @@ getProcessorsCumulativeSum(void) if (!cpuGroupCumulativeCache) { uint8_t n_groups = getNumberOfProcessorsGroups(); - cpuGroupCumulativeCache = malloc(n_groups * sizeof(uint32_t)); + cpuGroupCumulativeCache = stgMallocBytes(n_groups * sizeof(uint32_t), "getProcessorsCumulativeSum"); memset(cpuGroupCumulativeCache, 0, n_groups * sizeof(uint32_t)); #if defined(x86_64_HOST_ARCH) @@ -306,7 +306,7 @@ createProcessorGroupMap (void) uint32_t numProcs = getNumberOfProcessors(); - cpuGroupCache = malloc(numProcs * sizeof(uint8_t)); + cpuGroupCache = stgMallocBytes(numProcs * sizeof(uint8_t), "createProcessorGroupMap"); /* For 32bit Windows and 64bit older than Windows 7, create a default mapping. */ memset(cpuGroupCache, 0, numProcs * sizeof(uint8_t)); @@ -386,7 +386,7 @@ setThreadAffinity (uint32_t n, uint32_t m) // cap N of M ASSERT(n_groups > 0); ASSERT(n_proc > 0); - mask = malloc(n_groups * sizeof(DWORD_PTR)); + mask = stgMallocBytes(n_groups * sizeof(DWORD_PTR), "setThreadAffinity"); memset(mask, 0, n_groups * sizeof(DWORD_PTR)); /* The mask for the individual groups are all 0 based @@ -422,14 +422,14 @@ setThreadAffinity (uint32_t n, uint32_t m) // cap N of M { r = SetThreadAffinityMask(hThread, mask[i]); if (r == 0) { - free(mask); + stgFree(mask); sysErrorBelch("SetThreadAffinity"); stg_exit(EXIT_FAILURE); } } } - free(mask); + stgFree(mask); } void ===================================== rts/win32/WorkQueue.c ===================================== @@ -41,12 +41,7 @@ newSemaphore(int initCount, int max) WorkQueue* NewWorkQueue() { - WorkQueue* wq = (WorkQueue*)malloc(sizeof(WorkQueue)); - - if (!wq) { - queue_error("NewWorkQueue", "malloc() failed"); - return wq; - } + WorkQueue* wq = (WorkQueue*)stgMallocBytes(sizeof(WorkQueue), "NewWorkQueue"); memset(wq, 0, sizeof *wq); ===================================== rts/xxhash.c ===================================== @@ -98,9 +98,9 @@ ***************************************/ /*! Modify the local functions below should you wish to use some other memory routines * for malloc(), free() */ -#include -static void* XXH_malloc(size_t s) { return malloc(s); } -static void XXH_free (void* p) { free(p); } +#include "Rts.h" +static void* XXH_malloc(size_t s) { return stgMallocBytes(s, "XXH_malloc"); } +static void XXH_free (void* p) { stgFree(p); } /*! and for memcpy() */ #include static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1d1d21b2f05c342e5ad0e2acfaf12219a278513b -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1d1d21b2f05c342e5ad0e2acfaf12219a278513b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 01:36:43 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 21:36:43 -0400 Subject: [Git][ghc/ghc][wip/backports] 3 commits: Bump Cabal submodule Message-ID: <5f446b2be0009_80b1012800893047e8@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/backports at Glasgow Haskell Compiler / GHC Commits: 8c7e8e1c by Ben Gamari at 2020-08-17T20:09:30+00:00 Bump Cabal submodule - - - - - 1f6824a1 by Ben Gamari at 2020-08-21T11:35:00-04:00 Accept spurious performance shift Metric Decrease: T13035 - - - - - 5ccf44c6 by Krzysztof Gogolewski at 2020-08-24T21:35:48-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. (cherry picked from commit 364258e0ad25bc95e69745554f5ca831ce80baf8) - - - - - 8 changed files: - compiler/GHC/Core/Opt/ConstantFold.hs - libraries/Cabal - + testsuite/tests/simplCore/should_compile/T18589.hs - testsuite/tests/simplCore/should_compile/all.T - utils/check-api-annotations/check-api-annotations.cabal - utils/check-ppr/check-ppr.cabal - utils/ghc-cabal/ghc-cabal.cabal - utils/ghc-cabal/ghc.mk Changes: ===================================== compiler/GHC/Core/Opt/ConstantFold.hs ===================================== @@ -140,11 +140,11 @@ primOpRules nm = \case , inversePrimOp NotIOp ] IntNegOp -> mkPrimOpRule nm 1 [ unaryLit negOp , inversePrimOp IntNegOp ] - ISllOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftL) + ISllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const Bits.shiftL) , rightIdentityPlatform zeroi ] - ISraOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftR) + ISraOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const Bits.shiftR) , rightIdentityPlatform zeroi ] - ISrlOp -> mkPrimOpRule nm 2 [ shiftRule shiftRightLogical + ISrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt shiftRightLogical , rightIdentityPlatform zeroi ] -- Word operations @@ -186,8 +186,8 @@ primOpRules nm = \case , equalArgs >> retLit zerow ] NotOp -> mkPrimOpRule nm 1 [ unaryLit complementOp , inversePrimOp NotOp ] - SllOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftL) ] - SrlOp -> mkPrimOpRule nm 2 [ shiftRule shiftRightLogical ] + SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord (const Bits.shiftL) ] + SrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord shiftRightLogical ] -- coercions Word2IntOp -> mkPrimOpRule nm 1 [ liftLitPlatform word2IntLit @@ -474,12 +474,14 @@ wordOpC2 op env (LitNumber LitNumWord w1) (LitNumber LitNumWord w2) = wordCResult (roPlatform env) (fromInteger w1 `op` fromInteger w2) wordOpC2 _ _ _ _ = Nothing -shiftRule :: (Platform -> Integer -> Int -> Integer) -> RuleM CoreExpr +shiftRule :: LitNumType -- Type of the result, either LitNumInt or LitNumWord + -> (Platform -> Integer -> Int -> Integer) + -> RuleM CoreExpr -- Shifts take an Int; hence third arg of op is Int -- Used for shift primops --- ISllOp, ISraOp, ISrlOp :: Word# -> Int# -> Word# +-- ISllOp, ISraOp, ISrlOp :: Int# -> Int# -> Int# -- SllOp, SrlOp :: Word# -> Int# -> Word# -shiftRule shift_op +shiftRule lit_num_ty shift_op = do { platform <- getPlatform ; [e1, Lit (LitNumber LitNumInt shift_len)] <- getArgs ; case e1 of @@ -487,7 +489,9 @@ shiftRule shift_op -> return e1 -- See Note [Guarding against silly shifts] | shift_len < 0 || shift_len > toInteger (platformWordSizeInBits platform) - -> return $ Lit $ mkLitNumberWrap platform LitNumInt 0 + -> return $ Lit $ mkLitNumberWrap platform lit_num_ty 0 + -- Be sure to use lit_num_ty here, so we get a correctly typed zero + -- of type Int# or Word# resp. See #18589 -- Do the shift at type Integer, but shift length is Int Lit (LitNumber nt x) ===================================== libraries/Cabal ===================================== @@ -1 +1 @@ -Subproject commit 32dad5c1cf70d65ecb93b0ec214445cf9c9f6615 +Subproject commit 1d886476c443b227bf93eba62781a6cad5012d9e ===================================== testsuite/tests/simplCore/should_compile/T18589.hs ===================================== @@ -0,0 +1,12 @@ +{-# LANGUAGE MagicHash #-} +module T18589 where + +import GHC.Prim + +-- See Note [Guarding against silly shifts] +-- Make sure that a silly shift is optimized correctly +f1 x = uncheckedIShiftL# x -1# +f2 x = uncheckedIShiftRA# x -1# +f3 x = uncheckedIShiftRL# x -1# +f4 x = uncheckedShiftL# x -1# +f5 x = uncheckedShiftRL# x -1# ===================================== testsuite/tests/simplCore/should_compile/all.T ===================================== @@ -332,3 +332,4 @@ test('T18328', [ only_ways(['optasm']), grep_errmsg(r'Arity=') ], compile, ['-dd test('T18347', normal, compile, ['-dcore-lint -O']) test('T18355', [ grep_errmsg(r'OneShot') ], compile, ['-O -ddump-simpl -dsuppress-uniques']) test('T18399', normal, compile, ['-dcore-lint -O']) +test('T18589', normal, compile, ['-dcore-lint -O']) ===================================== utils/check-api-annotations/check-api-annotations.cabal ===================================== @@ -24,6 +24,6 @@ Executable check-api-annotations Build-Depends: base >= 4 && < 5, containers, - Cabal >= 3.0 && < 3.4, + Cabal >= 3.0 && < 3.6, directory, ghc ===================================== utils/check-ppr/check-ppr.cabal ===================================== @@ -25,7 +25,7 @@ Executable check-ppr Build-Depends: base >= 4 && < 5, bytestring, containers, - Cabal >= 3.0 && < 3.4, + Cabal >= 3.0 && < 3.6, directory, filepath, ghc ===================================== utils/ghc-cabal/ghc-cabal.cabal ===================================== @@ -21,6 +21,6 @@ Executable ghc-cabal Build-Depends: base >= 3 && < 5, bytestring >= 0.10 && < 0.11, - Cabal >= 3.0 && < 3.4, + Cabal >= 3.2 && < 3.6, directory >= 1.1 && < 1.4, filepath >= 1.2 && < 1.5 ===================================== utils/ghc-cabal/ghc.mk ===================================== @@ -37,25 +37,13 @@ ifneq "$(BINDIST)" "YES" $(ghc-cabal_INPLACE) : $(ghc-cabal_DIST_BINARY) | $$(dir $$@)/. "$(CP)" $< $@ -# Minor hack, since we can't reuse the `hs-suffix-rules-srcdir` macro -ifneq ($(wildcard libraries/Cabal/Cabal/Distribution/Fields/Lexer.x),) -# Lexer.x exists so we have to call Alex ourselves -CABAL_LEXER_DEP := bootstrapping/Cabal/Distribution/Fields/Lexer.hs - -bootstrapping/Cabal/Distribution/Fields/Lexer.hs: libraries/Cabal/Cabal/Distribution/Fields/Lexer.x - mkdir -p bootstrapping/Cabal/Distribution/Fields - $(call cmd,ALEX) $< -o $@ -else -CABAL_LEXER_DEP := libraries/Cabal/Cabal/Distribution/Fields/Lexer.hs -endif - -$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*/*/*.hs) -$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*/*.hs) -$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*.hs) +$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/src/Distribution/*/*/*.hs) +$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/src/Distribution/*/*.hs) +$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/src/Distribution/*.hs) # N.B. Compile with -O0 since this is not a performance-critical executable # and the Cabal takes nearly twice as long to build with -O1. See #16817. -$(ghc-cabal_DIST_BINARY): $(CABAL_LEXER_DEP) utils/ghc-cabal/Main.hs $(TOUCH_DEP) | $$(dir $$@)/. bootstrapping/. +$(ghc-cabal_DIST_BINARY): utils/ghc-cabal/Main.hs $(TOUCH_DEP) | $$(dir $$@)/. bootstrapping/. "$(GHC)" $(SRC_HC_OPTS) \ $(addprefix -optc, $(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE0)) \ $(addprefix -optl, $(SRC_LD_OPTS) $(CONF_GCC_LINKER_OPTS_STAGE0)) \ @@ -69,8 +57,7 @@ $(ghc-cabal_DIST_BINARY): $(CABAL_LEXER_DEP) utils/ghc-cabal/Main.hs $(TOUCH_DEP -DBOOTSTRAPPING \ -odir bootstrapping \ -hidir bootstrapping \ - $(CABAL_LEXER_DEP) \ - -ilibraries/Cabal/Cabal \ + -ilibraries/Cabal/Cabal/src \ -ilibraries/binary/src \ -ilibraries/filepath \ -ilibraries/hpc \ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e5db922952e7fcd2a4f2562112769f352c60d30e...5ccf44c6f0e27e83bf2828f0834bb790b1834929 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e5db922952e7fcd2a4f2562112769f352c60d30e...5ccf44c6f0e27e83bf2828f0834bb790b1834929 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 01:51:33 2020 From: gitlab at gitlab.haskell.org (Moritz Angermann) Date: Mon, 24 Aug 2020 21:51:33 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/angerman/fixup-3433 Message-ID: <5f446ea5414d2_80b10128008931341@gitlab.haskell.org.mail> Moritz Angermann pushed new branch wip/angerman/fixup-3433 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/angerman/fixup-3433 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 02:20:05 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 22:20:05 -0400 Subject: [Git][ghc/ghc][ghc-8.10] 2 commits: Fix typos in Runtime system section of 8.10.1 notes Message-ID: <5f447555d85f4_80b3f842731681c93241f9@gitlab.haskell.org.mail> Ben Gamari pushed to branch ghc-8.10 at Glasgow Haskell Compiler / GHC Commits: f8f59515 by toonn at 2020-08-22T14:14:22+02:00 Fix typos in Runtime system section of 8.10.1 notes - - - - - 1f8e9831 by toonn at 2020-08-22T15:53:38+02:00 Fix typos in Template Haskell section of ghc 8.10.1 notes - - - - - 1 changed file: - docs/users_guide/8.10.1-notes.rst Changes: ===================================== docs/users_guide/8.10.1-notes.rst ===================================== @@ -281,13 +281,13 @@ Runtime system ~~~~~~~~~~~~~~ - The runtime system linker now marks loaded code as non-writable (see - :ghc-ticket:`14069`) on all tier-1 platforms. This is necesaary for + :ghc-ticket:`14069`) on all tier-1 platforms. This is necessary for out-of-the-box compatibility with OpenBSD and macOS Catalina (see :ghc-ticket:`17353`) - The RTS API now exposes :ref:`an interface ` to - configure ``EventLogWriters``, allowing eventlog data to fed to sinks other - than ``.eventlog`` files. + configure ``EventLogWriters``, allowing eventlog data to be fed to sinks + other than ``.eventlog`` files. - A new ``+RTS`` flag ``--disable-delayed-os-memory-return`` was added to make for accurate resident memory usage of the program as shown in memory @@ -298,9 +298,9 @@ Runtime system Using this new flag is expected to make the program slightly slower. Without this flag, the (Linux) RTS returns unused memory "lazily" to the OS. - This has making the memory available to other processes while also allowing - the RTS to re-use the memory very efficiently (without zeroing pages) in case - it needs it again, but common tools will incorrectly show such memory as + This makes the memory available to other processes while also allowing the + RTS to re-use the memory very efficiently (without zeroing pages) in case it + needs it again, but common tools will incorrectly show such memory as occupied by the RTS (because they do not process the ``LazyFree`` field in ``/proc/PID/smaps``). @@ -308,7 +308,7 @@ Template Haskell ~~~~~~~~~~~~~~~~ - The ``Lift`` typeclass is now levity-polymorphic and has a ``liftTyped`` - method. Previously disallowed instances for unboxed tuples, unboxed sums, an + method. Previously disallowed instances for unboxed tuples, unboxed sums, and primitive unboxed types have also been added. Finally, the code generated by :extension:`DeriveLift` has been simplified to take advantage of expression quotations. @@ -316,7 +316,7 @@ Template Haskell - Using ``TupleT 1``, ``TupE [exp]``, or ``TupP [pat]`` will now produce unary tuples (i.e., involving the ``Unit`` type from ``GHC.Tuple``) instead of silently dropping the parentheses. This brings Template Haskell's treatment - of boxed tuples in line with that of unboxed tuples, as ``UnboxedTupleT`, + of boxed tuples in line with that of unboxed tuples, as ``UnboxedTupleT``, ``UnboxedTupE``, and ``UnboxedTupP`` also produce unary unboxed tuples (i.e., ``Unit#``) when applied to only one argument. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/82f15edc506cdf91c63c2351603c8f0fb0379914...1f8e98313f46414987c88d6cc8f8fe7e34fba1ff -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/82f15edc506cdf91c63c2351603c8f0fb0379914...1f8e98313f46414987c88d6cc8f8fe7e34fba1ff You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 02:26:54 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 24 Aug 2020 22:26:54 -0400 Subject: [Git][ghc/ghc][wip/andreask/exprSizeBangs] 317 commits: Define multiShotIO and use it in mkSplitUniqueSupply Message-ID: <5f4476ee70543_80bac4156c932577f@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/andreask/exprSizeBangs at Glasgow Haskell Compiler / GHC Commits: d9f09506 by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Define multiShotIO and use it in mkSplitUniqueSupply This patch is part of the ongoing eta-expansion saga; see #18238. It implements a neat trick (suggested by Sebastian Graf) that allows the programmer to disable the default one-shot behaviour of IO (the "state hack"). The trick is to use a new multiShotIO function; see Note [multiShotIO]. For now, multiShotIO is defined here in Unique.Supply; but it should ultimately be moved to the IO library. The change is necessary to get good code for GHC's unique supply; see Note [Optimising the unique supply]. However it makes no difference to GHC as-is. Rather, it makes a difference when a subsequent commit Improve eta-expansion using ArityType lands. - - - - - bce695cc by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Make arityType deal with join points As Note [Eta-expansion and join points] describes, this patch makes arityType deal correctly with join points. What was there before was not wrong, but yielded lower arities than it could. Fixes #18328 In base GHC this makes no difference to nofib. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- n-body -0.1% -0.1% -1.2% -1.1% 0.0% -------------------------------------------------------------------------------- Min -0.1% -0.1% -55.0% -56.5% 0.0% Max -0.0% 0.0% +16.1% +13.4% 0.0% Geometric Mean -0.0% -0.0% -30.1% -31.0% -0.0% But it starts to make real difference when we land the change to the way mkDupableAlts handles StrictArg, in fixing #13253 and friends. I think this is because we then get more non-inlined join points. - - - - - 2b7c71cb by Simon Peyton Jones at 2020-07-11T12:17:02-04:00 Improve eta-expansion using ArityType As #18355 shows, we were failing to preserve one-shot info when eta-expanding. It's rather easy to fix, by using ArityType more, rather than just Arity. This patch is important to suport the one-shot monad trick; see #18202. But the extra tracking of one-shot-ness requires the patch Define multiShotIO and use it in mkSplitUniqueSupply If that patch is missing, ths patch makes things worse in GHC.Types.Uniq.Supply. With it, however, we see these improvements T3064 compiler bytes allocated -2.2% T3294 compiler bytes allocated -1.3% T12707 compiler bytes allocated -1.3% T13056 compiler bytes allocated -2.2% Metric Decrease: T3064 T3294 T12707 T13056 - - - - - de139cc4 by Artem Pelenitsyn at 2020-07-12T02:53:20-04:00 add reproducer for #15630 - - - - - c4de6a7a by Andreas Klebinger at 2020-07-12T02:53:55-04:00 Give Uniq[D]FM a phantom type for its key. This fixes #17667 and should help to avoid such issues going forward. The changes are mostly mechanical in nature. With two notable exceptions. * The register allocator. The register allocator references registers by distinct uniques. However they come from the types of VirtualReg, Reg or Unique in various places. As a result we sometimes cast the key type of the map and use functions which operate on the now typed map but take a raw Unique as actual key. The logic itself has not changed it just becomes obvious where we do so now. * <Type>Env Modules. As an example a ClassEnv is currently queried using the types `Class`, `Name`, and `TyCon`. This is safe since for a distinct class value all these expressions give the same unique. getUnique cls getUnique (classTyCon cls) getUnique (className cls) getUnique (tcName $ classTyCon cls) This is for the most part contained within the modules defining the interface. However it requires us to play dirty when we are given a `Name` to lookup in a `UniqFM Class a` map. But again the logic did not change and it's for the most part hidden behind the Env Module. Some of these cases could be avoided by refactoring but this is left for future work. We also bump the haddock submodule as it uses UniqFM. - - - - - c2cfdfde by Aaron Allen at 2020-07-13T09:00:33-04:00 Warn about empty Char enumerations (#18402) Currently the "Enumeration is empty" warning (-Wempty-enumerations) only fires for numeric literals. This patch adds support for `Char` literals so that enumerating an empty list of `Char`s will also trigger the warning. - - - - - c3ac87ec by Stefan Schulze Frielinghaus at 2020-07-13T09:01:10-04:00 hadrian: build check-ppr dynamic if GHC is build dynamic Fixes #18361 - - - - - 9ad072b4 by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Use dumpStyle when printing inlinings This just makes debug-printing consistent, and more informative. - - - - - e78c4efb by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Comments only - - - - - 7ccb760b by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Reduce result discount in conSize Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c - - - - - 7f0b671e by Ben Gamari at 2020-07-13T14:52:49-04:00 testsuite: Widen acceptance threshold on T5837 This test is positively tiny and consequently the bytes allocated measurement will be relatively noisy. Consequently I have seen this fail spuriously quite often. - - - - - 118e1c3d by Alp Mestanogullari at 2020-07-14T21:30:52-04:00 compiler: re-engineer the treatment of rebindable if Executing on the plan described in #17582, this patch changes the way if expressions are handled in the compiler in the presence of rebindable syntax. We get rid of the SyntaxExpr field of HsIf and instead, when rebindable syntax is on, we rewrite the HsIf node to the appropriate sequence of applications of the local `ifThenElse` function. In order to be able to report good error messages, with expressions as they were written by the user (and not as desugared by the renamer), we make use of TTG extensions to extend GhcRn expression ASTs with an `HsExpansion` construct, which keeps track of a source (GhcPs) expression and the desugared (GhcRn) expression that it gives rise to. This way, we can typecheck the latter while reporting the former in error messages. In order to discard the error context lines that arise from typechecking the desugared expressions (because they talk about expressions that the user has not written), we carefully give a special treatment to the nodes fabricated by this new renaming-time transformation when typechecking them. See Note [Rebindable syntax and HsExpansion] for more details. The note also includes a recipe to apply the same treatment to other rebindable constructs. Tests 'rebindable11' and 'rebindable12' have been added to make sure we report identical error messages as before this patch under various circumstances. We also now disable rebindable syntax when processing untyped TH quotes, as per the discussion in #18102 and document the interaction of rebindable syntax and Template Haskell, both in Note [Template Haskell quotes and Rebindable Syntax] and in the user guide, adding a test to make sure that we do not regress in that regard. - - - - - 64c774b0 by Andreas Klebinger at 2020-07-14T21:31:27-04:00 Explain why keeping DynFlags in AnalEnv saves allocation. - - - - - 254245d0 by Ben Gamari at 2020-07-14T21:32:03-04:00 docs/users-guide: Update default -funfolding-use-threshold value This was changed in 3d2991f8 but I neglected to update the documentation. Fixes #18419. - - - - - 4c259f86 by Andreas Klebinger at 2020-07-14T21:32:41-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. - - - - - 23797224 by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 .gitlab: re-enable integer-simple substitute (BIGNUM_BACKEND) Recently build system migrated from INTEGER_LIBRARY to BIGNUM_BACKEND. But gitlab CI was never updated. Let's enable BIGNUM_BACKEND=native. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - e0db878a by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 ghc-bignum: bring in sync .hs-boot files with module declarations Before this change `BIGNUM_BACKEND=native` build was failing as: ``` libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs:708:16: error: * Variable not in scope: naturalFromBigNat# :: WordArray# -> t * Perhaps you meant one of these: `naturalFromBigNat' (imported from GHC.Num.Natural), `naturalToBigNat' (imported from GHC.Num.Natural) | 708 | m' = naturalFromBigNat# m | ``` This happens because `.hs-boot` files are slightly out of date. This change brings in data and function types in sync. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - c9f65c36 by Stefan Schulze Frielinghaus at 2020-07-14T21:33:57-04:00 rts/Disassembler.c: Use FMT_HexWord for printing values in hex format - - - - - 58ae62eb by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 macOS: Load frameworks without stating them first. macOS Big Sur makes the following change to how frameworks are shipped with the OS: > New in macOS Big Sur 11 beta, the system ships with a built-in > dynamic linker cache of all system-provided libraries. As part of > this change, copies of dynamic libraries are no longer present on > the filesystem. Code that attempts to check for dynamic library > presence by looking for a file at a path or enumerating a directory > will fail. Instead, check for library presence by attempting to > dlopen() the path, which will correctly check for the library in the > cache. (62986286) https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/ Therefore, the previous method of checking whether a library exists before attempting to load it makes GHC.Runtime.Linker.loadFramework fail to find frameworks installed at /System/Library/Frameworks. GHC.Runtime.Linker.loadFramework now opportunistically loads the framework libraries without checking for their existence first, failing only if all attempts to load a given framework from any of the various possible locations fail. - - - - - cdc4a6b0 by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 loadFramework: Output the errors collected in all loading attempts. With the recent change away from first finding and then loading a framework, loadFramework had no way of communicating the real reason why loadDLL failed if it was any reason other than the framework missing from the file system. It now collects all loading attempt errors into a list and concatenates them into a string to return to the caller. - - - - - 51dbfa52 by Ben Gamari at 2020-07-15T04:05:34-04:00 StgToCmm: Use CmmRegOff smart constructor Previously we would generate expressions of the form `CmmRegOff BaseReg 0`. This should do no harm (and really should be handled by the NCG anyways) but it's better to just generate a plain `CmmReg`. - - - - - ae11bdfd by Ben Gamari at 2020-07-15T04:06:08-04:00 testsuite: Add regression test for #17744 Test due to @monoidal. - - - - - 0e3c277a by Ben Gamari at 2020-07-15T16:41:01-04:00 Bump Cabal submodule Updates a variety of tests as Cabal is now more strict about Cabal file form. - - - - - ceed994a by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Drop Windows Vista support, require Windows 7 - - - - - 00a23bfd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Update Windows FileSystem wrapper utilities. - - - - - 459e1c5f by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Use SlimReaderLocks and ConditonalVariables provided by the OS instead of emulated ones - - - - - 763088fc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Small linker comment and ifdef cleanups - - - - - 1a228ff9 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Flush event logs eagerly. - - - - - e9e04dda by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Refactor Buffer structures to be able to track async operations - - - - - 356dc3fe by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Implement new Console API - - - - - 90e69f77 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add IOPort synchronization primitive - - - - - 71245fcc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add new io-manager cmdline options - - - - - d548a3b3 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Init Windows console Codepage to UTF-8. - - - - - 58ef6366 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add unsafeSplat to GHC.Event.Array - - - - - d660725e by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add size and iterate to GHC.Event.IntTable. - - - - - 050da6dd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Switch Testsuite to test winio by default - - - - - 4bf542bf by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Multiple refactorings and support changes. - - - - - 4489af6b by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core threaded I/O manager - - - - - 64d8f2fe by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core non-threaded I/O manager - - - - - 8da15a09 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix a scheduler bug with the threaded-runtime. - - - - - 84ea3d14 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Relaxing some constraints in io-manager. - - - - - ccf0d107 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix issues with non-threaded I/O manager after split. - - - - - b492fe6e by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Remove some barf statements that are a bit strict. - - - - - 01423fd2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Expand comments describing non-threaded loop - - - - - 4b69004f by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: fix FileSize unstat-able handles - - - - - 9b384270 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Implement new tempfile routines for winio - - - - - f1e0be82 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix input truncation when reading from handle. This was caused by not upholding the read buffer invariant that bufR == bufL == 0 for empty read buffers. - - - - - e176b625 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix output truncation for writes larger than buffer size - - - - - a831ce0e by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Rewrite bufWrite. I think it's far easier to follow the code now. It's also correct now as I had still missed a spot where we didn't update the offset. - - - - - 6aefdf62 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix offset set by bufReadEmpty. bufReadEmpty returns the bytes read *including* content that was already buffered, But for calculating the offset we only care about the number of bytes read into the new buffer. - - - - - 750ebaee by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Clean up code surrounding IOPort primitives. According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc. - - - - - ffd31db9 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix multi threaded threadDelay and a few other small changes. Multithreaded threadDelay suffered from a race condition based on the ioManagerStatus. Since the status isn't needed for WIO I removed it completely. This resulted in a light refactoring, as consequence we will always wake up the IO manager using interruptSystemManager, which uses `postQueuedCompletionStatus` internally. I also added a few comments which hopefully makes the code easier to dive into for the next person diving in. - - - - - 6ec26df2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 wionio: Make IO subsystem check a no-op on non-windows platforms. - - - - - 29bcd936 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Set handle offset when opening files in Append mode. Otherwise we would truncate the file. - - - - - 55c29700 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Remove debug event log trace - - - - - 9acb9f40 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix sqrt and openFile009 test cases - - - - - 57017cb7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Allow hp2ps to build with -DDEBUG - - - - - b8cd9995 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update output of T9681 since we now actually run it. - - - - - 10af5b14 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: A few more improvements to the IOPort primitives. - - - - - 39afc4a7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix expected tempfiles output. Tempfiles now works properly on windows, as such we can delete the win32 specific output. - - - - - 99db46e0 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Assign thread labels to IOManager threads. - - - - - be6af732 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Properly check for the tso of an incall to be zero. - - - - - e2c6dac7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark FD instances as unsupported under WINIO. - - - - - fd02ceed by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix threadDelay maxBound invocations. Instead of letting the ns timer overflow now clamp it at (maxBound :: Word64) ns. That still gives a few hundred years. - - - - - bc79f9f1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comments/cleanup an import in base - - - - - 1d197f4b by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark outstanding_service_requests volatile. As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration. - - - - - dc438186 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Make last_event a local variable - - - - - 2fc957c5 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comment about thread safety of processCompletion. - - - - - 4c026b6c by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: nonthreaded: Create io processing threads in main thread. We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread. - - - - - f47c7208 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add an exported isHeapAlloced function to the RTS - - - - - cc5d7bb1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Queue IO processing threads at the front of the queue. This will unblock the IO thread sooner hopefully leading to higher throughput in some situations. - - - - - e7630115 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: ThreadDelay001: Use higher resolution timer. - - - - - 451b5f96 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update T9681 output, disable T4808 on windows. T4808 tests functionality of the FD interface which won't be supported under WINIO. T9681 just has it's expected output tweaked. - - - - - dd06f930 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Wake io manager once per registerTimeout. Which is implicitly done in editTimeouts, so need to wake it up twice. - - - - - e87d0bf9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update placeholder comment with actual function name. - - - - - fc9025db by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Always lock win32 event queue - - - - - c24c9a1f by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Display thread labels when tracing scheduler events. - - - - - 06542b03 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Refactor non-threaded runner thread and scheduler interface. Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event. - - - - - 256299b1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove outstanding_requests from runner. We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port. - - - - - 3ebd8ad9 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Various fixes related to rebase and testdriver - - - - - 6be6bcba by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Fix rebase artifacts - - - - - 2c649dc3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename unsafeSplat to unsafeCopyFromBuffer - - - - - a18b73f3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove unused size/iterate operations from IntTable - - - - - 16bab48e by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Detect running IO Backend via peeking at RtsConfig - - - - - 8b8405a0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update temp path so GCC etc can handle it. Also fix PIPE support, clean up error casting, fix memory leaks - - - - - 2092bc54 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Minor comments/renamings - - - - - a5b5b6c0 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Checking if an error code indicates completion is now a function. - - - - - 362176fd by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Small refactor in withOverlappedEx - - - - - 32e20597 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: A few comments and commented out dbxIO - - - - - a4bfc1d9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't drop buffer offset in byteView/cwcharView - - - - - b3ad2a54 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: revert BHandle changes. - - - - - 3dcd87e2 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Fix imports - - - - - 5a371890 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update ghc-cabal to handle new Cabal submodule bump - - - - - d07ebe0d by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Only compile sources on Windows - - - - - dcb42393 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Actually return Nothing on EOF for non-blocking read - - - - - 895a3beb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate logic in encodeMultiByte[Raw]IO. - - - - - e06e6734 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate openFile logic - - - - - b59430c0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: fix -werror issue in encoding file - - - - - f8d39a51 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't mention windows specific functions when building on Linux. - - - - - 6a533d2a by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add a note about file locking in the RTS. - - - - - cf37ce34 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Add version to @since annotation - - - - - 0fafa2eb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename GHC.Conc.IOCP -> GHC.Conc.WinIO - - - - - 1854fc23 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Expand GHC.Conc.POSIX description It now explains users may not use these functions when using the old IO manager. - - - - - fcc7ba41 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Fix potential spaceleak in __createUUIDTempFileErrNo - - - - - 6b3fd9fa by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant -Wno-missing-signatures pragmas - - - - - 916fc861 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Make it explicit that we only create one IO manager - - - - - f260a721 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Note why we don't use blocking waits. - - - - - aa0a4bbf by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove commented out pragma - - - - - d679b544 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant buffer write in Handle/Text.hs:bufReadEmpty - - - - - d3f94368 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename SmartHandles to StdHandles - - - - - bd6b8ec1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add comment stating failure behaviour for getUniqueFileInfo. - - - - - 12846b85 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update IOPort haddocks. - - - - - 9f39fb14 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Add a note cross reference - - - - - 62dd5a73 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Name Haskell/OS I/O Manager explicitly in Note - - - - - fa807828 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Expand BlockedOnIOCompletion description. - - - - - f0880a1d by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove historical todos - - - - - 8e58e714 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Update note, remove debugging pragma. - - - - - aa4d84d5 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: flushCharReadBuffer shouldn't need to adjust offsets. - - - - - e580893a by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove obsolete comment about cond. variables - - - - - d54e9d79 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix initial linux validate build - - - - - 3cd4de46 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix ThreadDelay001 CPP - - - - - c88b1b9f by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix openFile009 merge conflict leftover - - - - - 849e8889 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept T9681 output. GHC now reports String instead of [Char]. - - - - - e7701818 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix cabal006 after upgrading cabal submodule Demand cabal 2.0 syntax instead of >= 1.20 as required by newer cabal versions. - - - - - a44f0373 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix stderr output for ghci/linking/dyn tests. We used to filter rtsopts, i opted to instead just accept the warning of it having no effect. This works both for -rtsopts, as well as -with-rtsopts which winio adds. - - - - - 515d9896 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T15261b stdout for --io-manager flag. - - - - - 949aaacc by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T5435_dyn_asm stderr The warning about rtsopts having no consequences is expected. So accept new stderr. - - - - - 7d424e1e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Also accept T7037 stderr - - - - - 1f009768 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal04 by filtering rts args - - - - - 981a9f2e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal01 by accepting expected stderr - - - - - b7b0464e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix safePkg01 by accepting expected stderr - - - - - 32734b29 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix T5435_dyn_gcc by accepting expected stderr - - - - - acc5cebf by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix tempfiles test on linux - - - - - c577b789 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for T3807 - - - - - c108c527 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload - - - - - 2b0b9a08 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload_multiple_objs - - - - - 67afb03c by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify wording on conditional variables. - - - - - 3bd41572 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify comment on cooked mode. - - - - - ded58a03 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: update lockfile signature and remove mistaken symbol in rts. - - - - - 2143c492 by Ben Gamari at 2020-07-15T16:41:04-04:00 testsuite: Add winio and winio_threaded ways Reverts many of the testsuite changes - - - - - c0979cc5 by Ben Gamari at 2020-07-16T10:56:54-04:00 Merge remote-tracking branch 'origin/wip/winio' - - - - - 750a1595 by Ben Gamari at 2020-07-18T07:26:41-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. - - - - - 6ba6a881 by Hécate at 2020-07-18T07:26:42-04:00 Implement `fullCompilerVersion` Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403 This MR adds `fullCompilerVersion`, a function that shares the same backend as the `--numeric-version` GHC flag, exposing a full, three-digit version datatype. - - - - - e6cf27df by Hécate at 2020-07-18T07:26:43-04:00 Add a Lint hadrian rule and an .hlint.yaml file in base/ - - - - - bcb177dd by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Allow multiple case branches to have a higher rank type As #18412 points out, it should be OK for multiple case alternatives to have a higher rank type, provided they are all the same. This patch implements that change. It sweeps away GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it with an enhanced version of fillInferResult. The basic change to fillInferResult is to permit the case in which another case alternative has already filled in the result; and in that case simply unify. It's very simple actually. See the new Note [fillInferResult] in TcMType Other refactoring: - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType (previously some of it was in Unify) - Move tcInstType and friends from TcMType to Instantiate, where it more properly belongs. (TCMType was getting very long.) - - - - - e5525a51 by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Improve typechecking of NPlusK patterns This patch (due to Richard Eisenberg) improves documentation of the wrapper returned by tcSubMult (see Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify). And, more substantially, it cleans up the multiplicity handling in the typechecking of NPlusKPat - - - - - 12f90352 by Krzysztof Gogolewski at 2020-07-18T07:26:45-04:00 Remove {-# CORE #-} pragma (part of #18048) This pragma has no effect since 2011. It was introduced for External Core, which no longer exists. Updates haddock submodule. - - - - - e504c913 by Simon Peyton Jones at 2020-07-18T07:26:45-04:00 Refactor the simplification of join binders This MR (for #18449) refactors the Simplifier's treatment of join-point binders. Specifically, it puts together, into GHC.Core.Opt.Simplify.Env.adjustJoinPointType two currently-separate ways in which we adjust the type of a join point. As the comment says: -- (adjustJoinPointType mult new_res_ty join_id) does two things: -- -- 1. Set the return type of the join_id to new_res_ty -- See Note [Return type for join points] -- -- 2. Adjust the multiplicity of arrows in join_id's type, as -- directed by 'mult'. See Note [Scaling join point arguments] I think this actually fixes a latent bug, by ensuring that the seIdSubst and seInScope have the right multiplicity on the type of join points. I did some tidying up while I was at it. No more setJoinResTy, or modifyJoinResTy: instead it's done locally in Simplify.Env.adjustJoinPointType - - - - - 49b265f0 by Chaitanya Koparkar at 2020-07-18T07:26:46-04:00 Fix minor typos in a Core.hs note - - - - - 8d59aed6 by Stefan Schulze Frielinghaus at 2020-07-18T07:26:47-04:00 GHCi: Fix isLittleEndian - - - - - c26e81d1 by Ben Gamari at 2020-07-18T07:26:47-04:00 testsuite: Mark ghci tests as fragile under unreg compiler In particular I have seen T16012 fail repeatedly under the unregisterised compiler. - - - - - 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 293c7fba by Sylvain Henry at 2020-08-21T09:36:38-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - 50eb4460 by Sylvain Henry at 2020-08-21T09:36:38-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 659eb31b by Sylvain Henry at 2020-08-21T09:36:38-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 2d8ca917 by Sylvain Henry at 2020-08-21T09:37:15-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - fddddbf4 by Vladislav Zavialov at 2020-08-21T09:37:49-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - 989c1c27 by Ben Gamari at 2020-08-21T11:27:53-04:00 gitlab-ci: Test master branch as well While these builds are strictly speaking redundant (since every commit is tested by @marge-bot before making it into `master`), they are nevertheless useful as they are displayed in the branch's commit list in GitLab's web interface. Fixes #18595. - - - - - e67ae884 by Aditya Gupta at 2020-08-22T03:29:00-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - 03cfcfd4 by Wander Hillen at 2020-08-22T03:29:36-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 3f501545 by Craig Ferguson at 2020-08-22T03:30:13-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 8b865092 by Krzysztof Gogolewski at 2020-08-23T14:12:53+02:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - d8f61182 by Krzysztof Gogolewski at 2020-08-23T14:12:56+02:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - 364258e0 by Krzysztof Gogolewski at 2020-08-24T00:32:31-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - b1eb38a0 by Sylvain Henry at 2020-08-24T00:33:13-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 8dbaa68a by Andreas Klebinger at 2020-08-24T22:26:52-04:00 Make sizeExpr strict in the size threshold to facilitate WW. - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/test-metrics.sh - CODEOWNERS - Makefile - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - + compiler/GHC/Builtin/RebindableNames.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/Cmm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Graph.hs - compiler/GHC/Cmm/Info.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d1dae72ee1b62054d8056d32578d222550f047b7...8dbaa68a2d1944199ba206eaa77fd43fdea69f55 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d1dae72ee1b62054d8056d32578d222550f047b7...8dbaa68a2d1944199ba206eaa77fd43fdea69f55 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 04:07:08 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 25 Aug 2020 00:07:08 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' Message-ID: <5f448e6cb1528_80b3f842731681c9349767@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: e06ba67d by Ben Gamari at 2020-08-25T00:06:53-04:00 SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' In #18069 we are observing MVar deadlocks from somewhere in ghc.exe. This use of MVar stood out as being one of the more likely culprits. Here we make sure that it is exception-safe. - - - - - 7053cfc0 by Richard Eisenberg at 2020-08-25T00:06:55-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - ff5ea233 by Simon Peyton Jones at 2020-08-25T00:06:56-04:00 Use LIdP rather than (XRec p (IdP p)) This patch mainly just replaces use of XRec p (IdP p) with LIdP p One slightly more significant change is to parameterise HsPatSynDetails over the pass rather than the argument type, so that it's uniform with HsConDeclDetails and HsConPatDetails. I also got rid of the dead code GHC.Hs.type.conDetailsArgs But this is all just minor refactoring. No change in functionality. - - - - - b3711405 by Krzysztof Gogolewski at 2020-08-25T00:06:57-04:00 Add a test for #18585 - - - - - 18 changed files: - compiler/GHC/Core/Type.hs - compiler/GHC/Core/Unify.hs - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Extension.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/Match/Constructor.hs - compiler/GHC/HsToCore/Quote.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Parser.y - compiler/GHC/SysTools/Process.hs - compiler/GHC/Tc/TyCl/PatSyn.hs - compiler/GHC/Tc/Utils/Zonk.hs - + testsuite/tests/typecheck/should_compile/T18585.hs - testsuite/tests/typecheck/should_compile/all.T Changes: ===================================== compiler/GHC/Core/Type.hs ===================================== @@ -358,10 +358,28 @@ But in Core these two are treated as identical. We implement this by making 'coreView' convert 'Constraint' to 'TYPE LiftedRep' on the fly. The function tcView (used in the type checker) -does not do this. +does not do this. Accordingly, tcView is used in type-checker-oriented +functions (including the pure unifier, used in instance resolution), +while coreView is used during e.g. optimisation passes. See also #11715, which tracks removing this inconsistency. +The inconsistency actually leads to a potential soundness bug, in that +Constraint and Type are considered *apart* by the type family engine. +To wit, we can write + + type family F a + type instance F Type = Bool + type instance F Constraint = Int + +and (because Type ~# Constraint in Core), thus build a coercion between +Int and Bool. I (Richard E) conjecture that this never happens in practice, +but it's very uncomfortable. This, essentially, is the root problem +underneath #11715, which is quite resistant to an easy fix. The best +idea is to have roles in kind coercions, but that has yet to be implemented. +See also "A Role for Dependent Types in Haskell", ICFP 2019, which describes +how roles in kinds might work out. + -} -- | Gives the typechecker view of a type. This unwraps synonyms but ===================================== compiler/GHC/Core/Unify.hs ===================================== @@ -957,7 +957,7 @@ unify_ty :: UMEnv -- Respects newtypes, PredTypes unify_ty env ty1 ty2 kco - -- TODO: More commentary needed here + -- Use tcView, not coreView. See Note [coreView vs tcView] in GHC.Core.Type. | Just ty1' <- tcView ty1 = unify_ty env ty1' ty2 kco | Just ty2' <- tcView ty2 = unify_ty env ty1 ty2' kco | CastTy ty1' co <- ty1 = if um_unif env @@ -1121,7 +1121,8 @@ uUnrefined :: UMEnv -- We know that tv1 isn't refined uUnrefined env tv1' ty2 ty2' kco - | Just ty2'' <- coreView ty2' + -- Use tcView, not coreView. See Note [coreView vs tcView] in GHC.Core.Type. + | Just ty2'' <- tcView ty2' = uUnrefined env tv1' ty2 ty2'' kco -- Unwrap synonyms -- This is essential, in case we have -- type Foo a = a @@ -1412,6 +1413,8 @@ ty_co_match :: MatchEnv -- ^ ambient helpful info -> Maybe LiftCoEnv ty_co_match menv subst ty co lkco rkco | Just ty' <- coreView ty = ty_co_match menv subst ty' co lkco rkco + -- why coreView here, not tcView? Because we're firmly after type-checking. + -- This function is used only during coercion optimisation. -- handle Refl case: | tyCoVarsOfType ty `isNotInDomainOf` subst ===================================== compiler/GHC/Hs/Binds.hs ===================================== @@ -243,7 +243,7 @@ data HsBindLR idL idR -- type Int -> forall a'. a' -> a' -- Notice that the coercion captures the free a'. - fun_id :: XRec idL (IdP idL), -- Note [fun_id in Match] in GHC.Hs.Expr + fun_id :: LIdP idL, -- Note [fun_id in Match] in GHC.Hs.Expr fun_matches :: MatchGroup idR (LHsExpr idR), -- ^ The payload @@ -369,9 +369,8 @@ type instance XXABExport (GhcPass p) = NoExtCon data PatSynBind idL idR = PSB { psb_ext :: XPSB idL idR, -- ^ Post renaming, FVs. -- See Note [Bind free vars] - psb_id :: XRec idL (IdP idL), -- ^ Name of the pattern synonym - psb_args :: HsPatSynDetails (XRec idR (IdP idR)), - -- ^ Formal parameter names + psb_id :: LIdP idL, -- ^ Name of the pattern synonym + psb_args :: HsPatSynDetails idR, -- ^ Formal parameter names psb_def :: LPat idR, -- ^ Right-hand side psb_dir :: HsPatSynDir idR -- ^ Directionality } @@ -893,7 +892,7 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation TypeSig (XTypeSig pass) - [XRec pass (IdP pass)] -- LHS of the signature; e.g. f,g,h :: blah + [LIdP pass] -- LHS of the signature; e.g. f,g,h :: blah (LHsSigWcType pass) -- RHS of the signature; can have wildcards -- | A pattern synonym type signature @@ -905,7 +904,7 @@ data Sig pass -- 'GHC.Parser.Annotation.AnnDot','GHC.Parser.Annotation.AnnDarrow' -- For details on above see note [Api annotations] in GHC.Parser.Annotation - | PatSynSig (XPatSynSig pass) [XRec pass (IdP pass)] (LHsSigType pass) + | PatSynSig (XPatSynSig pass) [LIdP pass] (LHsSigType pass) -- P :: forall a b. Req => Prov => ty -- | A signature for a class method @@ -918,7 +917,7 @@ data Sig pass -- -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnDefault', -- 'GHC.Parser.Annotation.AnnDcolon' - | ClassOpSig (XClassOpSig pass) Bool [XRec pass (IdP pass)] (LHsSigType pass) + | ClassOpSig (XClassOpSig pass) Bool [LIdP pass] (LHsSigType pass) -- | A type signature in generated code, notably the code -- generated for record selectors. We simply record @@ -950,8 +949,8 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | InlineSig (XInlineSig pass) - (XRec pass (IdP pass)) -- Function name - InlinePragma -- Never defaultInlinePragma + (LIdP pass) -- Function name + InlinePragma -- Never defaultInlinePragma -- | A specialisation pragma -- @@ -966,7 +965,7 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | SpecSig (XSpecSig pass) - (XRec pass (IdP pass)) -- Specialise a function or datatype ... + (LIdP pass) -- Specialise a function or datatype ... [LHsSigType pass] -- ... to these types InlinePragma -- The pragma on SPECIALISE_INLINE form. -- If it's just defaultInlinePragma, then we said @@ -996,7 +995,7 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | MinimalSig (XMinimalSig pass) - SourceText (LBooleanFormula (XRec pass (IdP pass))) + SourceText (LBooleanFormula (LIdP pass)) -- Note [Pragma source text] in GHC.Types.Basic -- | A "set cost centre" pragma for declarations @@ -1008,8 +1007,8 @@ data Sig pass -- > {-# SCC funName "cost_centre_name" #-} | SCCFunSig (XSCCFunSig pass) - SourceText -- Note [Pragma source text] in GHC.Types.Basic - (XRec pass (IdP pass)) -- Function name + SourceText -- Note [Pragma source text] in GHC.Types.Basic + (LIdP pass) -- Function name (Maybe (XRec pass StringLiteral)) -- | A complete match pragma -- @@ -1020,8 +1019,8 @@ data Sig pass -- synonym definitions. | CompleteMatchSig (XCompleteMatchSig pass) SourceText - (XRec pass [XRec pass (IdP pass)]) - (Maybe (XRec pass (IdP pass))) + (XRec pass [LIdP pass]) + (Maybe (LIdP pass)) | XSig !(XXSig pass) type instance XTypeSig (GhcPass p) = NoExtField @@ -1041,7 +1040,7 @@ type instance XXSig (GhcPass p) = NoExtCon type LFixitySig pass = XRec pass (FixitySig pass) -- | Fixity Signature -data FixitySig pass = FixitySig (XFixitySig pass) [XRec pass (IdP pass)] Fixity +data FixitySig pass = FixitySig (XFixitySig pass) [LIdP pass] Fixity | XFixitySig !(XXFixitySig pass) type instance XFixitySig (GhcPass p) = NoExtField @@ -1229,14 +1228,14 @@ pprMinimalSig (L _ bf) = ppr (fmap unLoc bf) -} -- | Haskell Pattern Synonym Details -type HsPatSynDetails arg = HsConDetails arg [RecordPatSynField arg] +type HsPatSynDetails pass = HsConDetails (LIdP pass) [RecordPatSynField (LIdP pass)] -- See Note [Record PatSyn Fields] -- | Record Pattern Synonym Field -data RecordPatSynField a +data RecordPatSynField fld = RecordPatSynField { - recordPatSynSelectorId :: a -- Selector name visible in rest of the file - , recordPatSynPatVar :: a + recordPatSynSelectorId :: fld -- Selector name visible in rest of the file + , recordPatSynPatVar :: fld -- Filled in by renamer, the name used internally -- by the pattern } deriving (Data, Functor) ===================================== compiler/GHC/Hs/Decls.hs ===================================== @@ -592,7 +592,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation SynDecl { tcdSExt :: XSynDecl pass -- ^ Post renameer, FVs - , tcdLName :: XRec pass (IdP pass) -- ^ Type constructor + , tcdLName :: LIdP pass -- ^ Type constructor , tcdTyVars :: LHsQTyVars pass -- ^ Type variables; for an -- associated type these -- include outer binders @@ -609,7 +609,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation DataDecl { tcdDExt :: XDataDecl pass -- ^ Post renamer, CUSK flag, FVs - , tcdLName :: XRec pass (IdP pass) -- ^ Type constructor + , tcdLName :: LIdP pass -- ^ Type constructor , tcdTyVars :: LHsQTyVars pass -- ^ Type variables -- See Note [TyVar binders for associated declarations] , tcdFixity :: LexicalFixity -- ^ Fixity used in the declaration @@ -617,7 +617,7 @@ data TyClDecl pass | ClassDecl { tcdCExt :: XClassDecl pass, -- ^ Post renamer, FVs tcdCtxt :: LHsContext pass, -- ^ Context... - tcdLName :: XRec pass (IdP pass), -- ^ Name of the class + tcdLName :: LIdP pass, -- ^ Name of the class tcdTyVars :: LHsQTyVars pass, -- ^ Class type variables tcdFixity :: LexicalFixity, -- ^ Fixity used in the declaration tcdFDs :: [LHsFunDep pass], -- ^ Functional deps @@ -637,7 +637,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | XTyClDecl !(XXTyClDecl pass) -type LHsFunDep pass = XRec pass (FunDep (XRec pass (IdP pass))) +type LHsFunDep pass = XRec pass (FunDep (LIdP pass)) data DataDeclRn = DataDeclRn { tcdDataCusk :: Bool -- ^ does this have a CUSK? @@ -1135,7 +1135,7 @@ type LFamilyDecl pass = XRec pass (FamilyDecl pass) data FamilyDecl pass = FamilyDecl { fdExt :: XCFamilyDecl pass , fdInfo :: FamilyInfo pass -- type/data, closed/open - , fdLName :: XRec pass (IdP pass) -- type constructor + , fdLName :: LIdP pass -- type constructor , fdTyVars :: LHsQTyVars pass -- type variables -- See Note [TyVar binders for associated declarations] , fdFixity :: LexicalFixity -- Fixity used in the declaration @@ -1168,7 +1168,7 @@ type LInjectivityAnn pass = XRec pass (InjectivityAnn pass) -- -- This will be represented as "InjectivityAnn `r` [`a`, `c`]" data InjectivityAnn pass - = InjectivityAnn (XRec pass (IdP pass)) [XRec pass (IdP pass)] + = InjectivityAnn (LIdP pass) [LIdP pass] -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : -- 'GHC.Parser.Annotation.AnnRarrow', 'GHC.Parser.Annotation.AnnVbar' @@ -1364,7 +1364,7 @@ type LStandaloneKindSig pass = XRec pass (StandaloneKindSig pass) data StandaloneKindSig pass = StandaloneKindSig (XStandaloneKindSig pass) - (XRec pass (IdP pass)) -- Why a single binder? See #16754 + (LIdP pass) -- Why a single binder? See #16754 (LHsSigType pass) -- Why not LHsSigWcType? See Note [Wildcards in standalone kind signatures] | XStandaloneKindSig !(XXStandaloneKindSig pass) @@ -1435,7 +1435,7 @@ type LConDecl pass = XRec pass (ConDecl pass) data ConDecl pass = ConDeclGADT { con_g_ext :: XConDeclGADT pass - , con_names :: [XRec pass (IdP pass)] + , con_names :: [LIdP pass] -- The following fields describe the type after the '::' -- See Note [GADT abstract syntax] @@ -1458,7 +1458,7 @@ data ConDecl pass | ConDeclH98 { con_ext :: XConDeclH98 pass - , con_name :: XRec pass (IdP pass) + , con_name :: LIdP pass , con_forall :: XRec pass Bool -- ^ True <=> explicit user-written forall @@ -1849,7 +1849,7 @@ type FamInstEqn pass rhs = HsImplicitBndrs pass (FamEqn pass rhs) data FamEqn pass rhs = FamEqn { feqn_ext :: XCFamEqn pass rhs - , feqn_tycon :: XRec pass (IdP pass) + , feqn_tycon :: LIdP pass , feqn_bndrs :: Maybe [LHsTyVarBndr () pass] -- ^ Optional quantified type vars , feqn_pats :: HsTyPats pass , feqn_fixity :: LexicalFixity -- ^ Fixity used in the declaration @@ -2214,13 +2214,13 @@ type LForeignDecl pass = XRec pass (ForeignDecl pass) data ForeignDecl pass = ForeignImport { fd_i_ext :: XForeignImport pass -- Post typechecker, rep_ty ~ sig_ty - , fd_name :: XRec pass (IdP pass) -- defines this name + , fd_name :: LIdP pass -- defines this name , fd_sig_ty :: LHsSigType pass -- sig_ty , fd_fi :: ForeignImport } | ForeignExport { fd_e_ext :: XForeignExport pass -- Post typechecker, rep_ty ~ sig_ty - , fd_name :: XRec pass (IdP pass) -- uses this name + , fd_name :: LIdP pass -- uses this name , fd_sig_ty :: LHsSigType pass -- sig_ty , fd_fe :: ForeignExport } -- ^ @@ -2402,8 +2402,8 @@ type LRuleBndr pass = XRec pass (RuleBndr pass) -- | Rule Binder data RuleBndr pass - = RuleBndr (XCRuleBndr pass) (XRec pass (IdP pass)) - | RuleBndrSig (XRuleBndrSig pass) (XRec pass (IdP pass)) (HsPatSigType pass) + = RuleBndr (XCRuleBndr pass) (LIdP pass) + | RuleBndrSig (XRuleBndrSig pass) (LIdP pass) (HsPatSigType pass) | XRuleBndr !(XXRuleBndr pass) -- ^ -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen', @@ -2505,7 +2505,7 @@ type instance XXWarnDecls (GhcPass _) = NoExtCon type LWarnDecl pass = XRec pass (WarnDecl pass) -- | Warning pragma Declaration -data WarnDecl pass = Warning (XWarning pass) [XRec pass (IdP pass)] WarningTxt +data WarnDecl pass = Warning (XWarning pass) [LIdP pass] WarningTxt | XWarnDecl !(XXWarnDecl pass) type instance XWarning (GhcPass _) = NoExtField @@ -2592,7 +2592,7 @@ type LRoleAnnotDecl pass = XRec pass (RoleAnnotDecl pass) -- | Role Annotation Declaration data RoleAnnotDecl pass = RoleAnnotDecl (XCRoleAnnotDecl pass) - (XRec pass (IdP pass)) -- type constructor + (LIdP pass) -- type constructor [XRec pass (Maybe Role)] -- optional annotations -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnType', -- 'GHC.Parser.Annotation.AnnRole' ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -242,9 +242,8 @@ is Less Cool because -- | A Haskell expression. data HsExpr p = HsVar (XVar p) - (XRec p (IdP p)) -- ^ Variable - - -- See Note [Located RdrNames] + (LIdP p) -- ^ Variable + -- See Note [Located RdrNames] | HsUnboundVar (XUnboundVar p) OccName -- ^ Unbound variable; also used for "holes" @@ -439,7 +438,7 @@ data HsExpr p -- For details on above see note [Api annotations] in GHC.Parser.Annotation | RecordCon { rcon_ext :: XRecordCon p - , rcon_con_name :: XRec p (IdP p) -- The constructor name; + , rcon_con_name :: LIdP p -- The constructor name; -- not used after type checking , rcon_flds :: HsRecordBinds p } -- The fields @@ -2987,7 +2986,7 @@ matchSeparator ThPatSplice = panic "unused" matchSeparator ThPatQuote = panic "unused" matchSeparator PatSyn = panic "unused" -pprMatchContext :: Outputable (IdP p) +pprMatchContext :: (Outputable (IdP p), UnXRec p) => HsMatchContext p -> SDoc pprMatchContext ctxt | want_an ctxt = text "an" <+> pprMatchContextNoun ctxt @@ -2997,11 +2996,11 @@ pprMatchContext ctxt want_an ProcExpr = True want_an _ = False -pprMatchContextNoun :: Outputable (IdP id) - => HsMatchContext id -> SDoc -pprMatchContextNoun (FunRhs {mc_fun=L _ fun}) +pprMatchContextNoun :: forall p. (Outputable (IdP p), UnXRec p) + => HsMatchContext p -> SDoc +pprMatchContextNoun (FunRhs {mc_fun=fun}) = text "equation for" - <+> quotes (ppr fun) + <+> quotes (ppr (unXRec @p fun)) pprMatchContextNoun CaseAlt = text "case alternative" pprMatchContextNoun IfAlt = text "multi-way if alternative" pprMatchContextNoun RecUpd = text "record-update construct" @@ -3016,8 +3015,8 @@ pprMatchContextNoun (StmtCtxt ctxt) = text "pattern binding in" pprMatchContextNoun PatSyn = text "pattern synonym declaration" ----------------- -pprAStmtContext, pprStmtContext :: Outputable (IdP id) - => HsStmtContext id -> SDoc +pprAStmtContext, pprStmtContext :: (Outputable (IdP p), UnXRec p) + => HsStmtContext p -> SDoc pprAStmtContext ctxt = article <+> pprStmtContext ctxt where pp_an = text "an" ===================================== compiler/GHC/Hs/Extension.hs ===================================== @@ -307,7 +307,7 @@ type family IdGhcP pass where IdGhcP 'Renamed = Name IdGhcP 'Typechecked = Id -type LIdP p = Located (IdP p) +type LIdP p = XRec p (IdP p) -- | Marks that a field uses the GhcRn variant even when the pass -- parameter is GhcTc. Useful for storing HsTypes in GHC.Hs.Exprs, say, because ===================================== compiler/GHC/Hs/Pat.hs ===================================== @@ -93,7 +93,7 @@ data Pat p -- AZ:TODO above comment needs to be updated | VarPat (XVarPat p) - (XRec p (IdP p)) -- ^ Variable Pattern + (LIdP p) -- ^ Variable Pattern -- See Note [Located RdrNames] in GHC.Hs.Expr | LazyPat (XLazyPat p) @@ -103,7 +103,7 @@ data Pat p -- For details on above see note [Api annotations] in GHC.Parser.Annotation | AsPat (XAsPat p) - (XRec p (IdP p)) (LPat p) -- ^ As pattern + (LIdP p) (LPat p) -- ^ As pattern -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnAt' -- For details on above see note [Api annotations] in GHC.Parser.Annotation @@ -224,7 +224,7 @@ data Pat p -- For details on above see note [Api annotations] in GHC.Parser.Annotation | NPlusKPat (XNPlusKPat p) -- Type of overall pattern - (XRec p (IdP p)) -- n+k pattern + (LIdP p) -- n+k pattern (XRec p (HsOverLit p)) -- It'll always be an HsIntegral (HsOverLit p) -- See Note [NPlusK patterns] in GHC.Tc.Gen.Pat -- NB: This could be (PostTc ...), but that induced a @@ -313,7 +313,7 @@ type instance XXPat GhcTc = CoPat type family ConLikeP x type instance ConLikeP GhcPs = RdrName -- IdP GhcPs -type instance ConLikeP GhcRn = Name -- IdP GhcRn +type instance ConLikeP GhcRn = Name -- IdP GhcRn type instance ConLikeP GhcTc = ConLike -- --------------------------------------------------------------------- ===================================== compiler/GHC/Hs/Type.hs ===================================== @@ -73,7 +73,6 @@ module GHC.Hs.Type ( mkHsOpTy, mkHsAppTy, mkHsAppTys, mkHsAppKindTy, ignoreParens, hsSigType, hsSigWcType, hsPatSigType, hsTyKindSig, - hsConDetailsArgs, setHsTyVarBndrFlag, hsTyVarBndrFlag, -- Printing @@ -638,13 +637,13 @@ data HsTyVarBndr flag pass = UserTyVar -- no explicit kinding (XUserTyVar pass) flag - (XRec pass (IdP pass)) + (LIdP pass) -- See Note [Located RdrNames] in GHC.Hs.Expr | KindedTyVar (XKindedTyVar pass) flag - (XRec pass (IdP pass)) + (LIdP pass) (LHsKind pass) -- The user-supplied kind signature -- ^ -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen', @@ -705,7 +704,7 @@ data HsType pass | HsTyVar (XTyVar pass) PromotionFlag -- Whether explicitly promoted, -- for the pretty printer - (XRec pass (IdP pass)) + (LIdP pass) -- Type variable, type constructor, or data constructor -- see Note [Promotions (HsTyVar)] -- See Note [Located RdrNames] in GHC.Hs.Expr @@ -755,7 +754,7 @@ data HsType pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | HsOpTy (XOpTy pass) - (LHsType pass) (XRec pass (IdP pass)) (LHsType pass) + (LHsType pass) (LIdP pass) (LHsType pass) -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : None -- For details on above see note [Api annotations] in GHC.Parser.Annotation @@ -1116,14 +1115,6 @@ instance (Outputable arg, Outputable rec) ppr (RecCon rec) = text "RecCon:" <+> ppr rec ppr (InfixCon l r) = text "InfixCon:" <+> ppr [l, r] -hsConDetailsArgs :: - HsConDetails (LHsType (GhcPass p)) (Located [LConDeclField (GhcPass p)]) - -> [LHsType (GhcPass p)] -hsConDetailsArgs details = case details of - InfixCon a b -> [a,b] - PrefixCon xs -> xs - RecCon r -> map (cd_fld_type . unLoc) (unLoc r) - {- Note [ConDeclField passs] ~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/Hs/Utils.hs ===================================== @@ -777,7 +777,7 @@ mkVarBind var rhs = L (getLoc rhs) $ VarBind { var_ext = noExtField, var_id = var, var_rhs = rhs } -mkPatSynBind :: Located RdrName -> HsPatSynDetails (Located RdrName) +mkPatSynBind :: Located RdrName -> HsPatSynDetails GhcPs -> LPat GhcPs -> HsPatSynDir GhcPs -> HsBind GhcPs mkPatSynBind name details lpat dir = PatSynBind noExtField psb where @@ -990,7 +990,7 @@ collect_bind omitPatSyn (PatSynBind _ (PSB { psb_id = ps })) acc collect_bind _ (PatSynBind _ (XPatSynBind _)) acc = acc collect_bind _ (XHsBindsLR _) acc = acc -collectMethodBinders :: forall idL idR. UnXRec idL => LHsBindsLR idL idR -> [XRec idL (IdP idL)] +collectMethodBinders :: forall idL idR. UnXRec idL => LHsBindsLR idL idR -> [LIdP idL] -- ^ Used exclusively for the bindings of an instance decl which are all -- 'FunBinds' collectMethodBinders binds = foldr (get . unXRec @idL) [] binds @@ -1173,7 +1173,7 @@ hsLTyClDeclBinders (L loc (DataDecl { tcdLName = (L _ name) ------------------- -hsForeignDeclsBinders :: forall pass. (UnXRec pass, MapXRec pass) => [LForeignDecl pass] -> [XRec pass (IdP pass)] +hsForeignDeclsBinders :: forall pass. (UnXRec pass, MapXRec pass) => [LForeignDecl pass] -> [LIdP pass] -- ^ See Note [SrcSpan for binders] hsForeignDeclsBinders foreign_decls = [ mapXRec @pass (const $ unXRec @pass n) fi ===================================== compiler/GHC/HsToCore/Match/Constructor.hs ===================================== @@ -126,7 +126,7 @@ matchPatSyn (var :| vars) ty eqns PatSynCon psyn -> alt{ alt_pat = psyn } _ -> panic "matchPatSyn: not PatSynCon" -type ConArgPats = HsConDetails (LPat GhcTc) (HsRecFields GhcTc (LPat GhcTc)) +type ConArgPats = HsConPatDetails GhcTc matchOneConLike :: [Id] -> Type ===================================== compiler/GHC/HsToCore/Quote.hs ===================================== @@ -1840,7 +1840,7 @@ rep_bind (L loc (PatSynBind _ (PSB { psb_id = syn ; patSynD'' <- wrapGenArgSyms args ss patSynD' ; return (loc, patSynD'') } where - mkGenArgSyms :: HsPatSynDetails (Located Name) -> MetaM [GenSymBind] + mkGenArgSyms :: HsPatSynDetails GhcRn -> MetaM [GenSymBind] -- for Record Pattern Synonyms we want to conflate the selector -- and the pattern-only names in order to provide a nicer TH -- API. Whereas inside GHC, record pattern synonym selectors and @@ -1859,7 +1859,7 @@ rep_bind (L loc (PatSynBind _ (PSB { psb_id = syn = [ (pat, id) | (sel, id) <- genSyms, (sel', pat) <- selsPats , sel == sel' ] - wrapGenArgSyms :: HsPatSynDetails (Located Name) + wrapGenArgSyms :: HsPatSynDetails GhcRn -> [GenSymBind] -> Core (M TH.Dec) -> MetaM (Core (M TH.Dec)) wrapGenArgSyms (RecCon _) _ dec = return dec wrapGenArgSyms _ ss dec = wrapGenSyms ss dec @@ -1872,7 +1872,7 @@ repPatSynD :: Core TH.Name repPatSynD (MkC syn) (MkC args) (MkC dir) (MkC pat) = rep2 patSynDName [syn, args, dir, pat] -repPatSynArgs :: HsPatSynDetails (Located Name) -> MetaM (Core (M TH.PatSynArgs)) +repPatSynArgs :: HsPatSynDetails GhcRn -> MetaM (Core (M TH.PatSynArgs)) repPatSynArgs (PrefixCon args) = do { args' <- repList nameTyConName lookupLOcc args ; repPrefixPatSynArgs args' } ===================================== compiler/GHC/HsToCore/Utils.hs ===================================== @@ -900,7 +900,7 @@ CPR-friendly. This matters a lot: if you don't get it right, you lose the tail call property. For example, see #3403. -} -dsHandleMonadicFailure :: Outputable (IdP p) => HsStmtContext p -> LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr +dsHandleMonadicFailure :: HsStmtContext GhcRn -> LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr -- In a do expression, pattern-match failure just calls -- the monadic 'fail' rather than throwing an exception dsHandleMonadicFailure ctx pat match m_fail_op = @@ -921,8 +921,9 @@ dsHandleMonadicFailure ctx pat match m_fail_op = fail_expr <- dsSyntaxExpr fail_op [fail_msg] body fail_expr -mk_fail_msg :: Outputable (IdP p) => DynFlags -> HsStmtContext p -> Located e -> String -mk_fail_msg dflags ctx pat = showPpr dflags $ text "Pattern match failure in" <+> pprStmtContext ctx <+> text "at" <+> ppr (getLoc pat) +mk_fail_msg :: DynFlags -> HsStmtContext GhcRn -> Located e -> String +mk_fail_msg dflags ctx pat + = showPpr dflags $ text "Pattern match failure in" <+> pprStmtContext ctx <+> text "at" <+> ppr (getLoc pat) {- ********************************************************************* * * ===================================== compiler/GHC/Parser.y ===================================== @@ -1491,7 +1491,7 @@ pattern_synonym_decl :: { LHsDecl GhcPs } (as ++ ((mj AnnPattern $1:mu AnnLarrow $3:(fst $ unLoc $5))) ) }} -pattern_synonym_lhs :: { (Located RdrName, HsPatSynDetails (Located RdrName), [AddAnn]) } +pattern_synonym_lhs :: { (Located RdrName, HsPatSynDetails GhcPs, [AddAnn]) } : con vars0 { ($1, PrefixCon $2, []) } | varid conop varid { ($2, InfixCon $1 $3, []) } | con '{' cvars1 '}' { ($1, RecCon $3, [moc $2, mcc $4] ) } ===================================== compiler/GHC/SysTools/Process.hs ===================================== @@ -45,6 +45,15 @@ enableProcessJobs opts = opts enableProcessJobs opts = opts #endif +#if !MIN_VERSION_base(4,15,0) +-- TODO: This can be dropped with GHC 8.16 +hGetContents' :: Handle -> IO String +hGetContents' hdl = do + output <- hGetContents hdl + _ <- evaluate $ length output + return output +#endif + -- Similar to System.Process.readCreateProcessWithExitCode, but stderr is -- inherited from the parent process, and output to stderr is not captured. readCreateProcessWithExitCode' @@ -55,13 +64,19 @@ readCreateProcessWithExitCode' proc = do createProcess $ enableProcessJobs $ proc{ std_out = CreatePipe } -- fork off a thread to start consuming the output - output <- hGetContents outh outMVar <- newEmptyMVar - _ <- forkIO $ evaluate (length output) >> putMVar outMVar () + let onError :: SomeException -> IO () + onError exc = putMVar outMVar (Left exc) + _ <- forkIO $ handle onError $ do + output <- hGetContents' outh + putMVar outMVar $ Right output -- wait on the output - takeMVar outMVar + result <- takeMVar outMVar hClose outh + output <- case result of + Left exc -> throwIO exc + Right output -> return output -- wait on the process ex <- waitForProcess pid ===================================== compiler/GHC/Tc/TyCl/PatSyn.hs ===================================== @@ -558,7 +558,7 @@ a pattern synonym. What about the /building/ side? a bad idea. -} -collectPatSynArgInfo :: HsPatSynDetails (Located Name) +collectPatSynArgInfo :: HsPatSynDetails GhcRn -> ([Name], [Name], Bool) collectPatSynArgInfo details = case details of ===================================== compiler/GHC/Tc/Utils/Zonk.hs ===================================== @@ -626,8 +626,8 @@ zonk_bind env (PatSynBind x bind@(PSB { psb_id = L loc id , psb_dir = dir' } } zonkPatSynDetails :: ZonkEnv - -> HsPatSynDetails (Located TcId) - -> HsPatSynDetails (Located Id) + -> HsPatSynDetails GhcTc + -> HsPatSynDetails GhcTc zonkPatSynDetails env (PrefixCon as) = PrefixCon (map (zonkLIdOcc env) as) zonkPatSynDetails env (InfixCon a1 a2) @@ -1450,10 +1450,8 @@ zonk_pat env (XPat (CoPat co_fn pat ty)) zonk_pat _ pat = pprPanic "zonk_pat" (ppr pat) --------------------------- -zonkConStuff :: ZonkEnv - -> HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc)) - -> TcM (ZonkEnv, - HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc))) +zonkConStuff :: ZonkEnv -> HsConPatDetails GhcTc + -> TcM (ZonkEnv, HsConPatDetails GhcTc) zonkConStuff env (PrefixCon pats) = do { (env', pats') <- zonkPats env pats ; return (env', PrefixCon pats') } ===================================== testsuite/tests/typecheck/should_compile/T18585.hs ===================================== @@ -0,0 +1,48 @@ +{-# Language DataKinds #-} +{-# Language FlexibleContexts #-} +{-# Language PolyKinds #-} +{-# Language StandaloneKindSignatures #-} +{-# Language TypeFamilyDependencies #-} +{-# Language UndecidableInstances #-} +{-# Language UndecidableSuperClasses #-} +module T18585 (Functor(..)) where + +import Data.Kind (Type) +import Prelude hiding (Functor(..)) + +type Cat i = i -> i -> Type + +class + ( Op (Op k) ~ k + , Category (Op k) + ) => Category (k :: Cat i) where + type Op k :: i -> i -> Type + type Op k = Y k + +newtype Y k a b = Y (k b a) + +instance (Category k, Op k ~ Y k) => Category (Y k) where + type Op (Y k) = k + +instance Category (->) + +type SelfDom :: (i -> j) -> Cat i -> Cat i +type family SelfDom (f :: i -> j) (k :: Cat i) :: Cat i where + SelfDom p p = Op p + SelfDom f p = p + +type family DefaultCat (i :: Type) = (res :: Cat i) | res -> i +type instance DefaultCat Type = (->) + +class + ( Category (Dom f) + , Category (Cod f) + ) => Functor (f :: i -> j) where + + type Dom f :: Cat i + type Dom (f :: i -> j) = SelfDom f (DefaultCat i) + + type Cod f :: Cat j + type Cod (f :: i -> j) = DefaultCat j + +instance Functor IO ===================================== testsuite/tests/typecheck/should_compile/all.T ===================================== @@ -721,4 +721,5 @@ test('T18118', normal, multimod_compile, ['T18118', '-v0']) test('T18412', normal, compile, ['']) test('T18470', normal, compile, ['']) test('T18323', normal, compile, ['']) +test('T18585', normal, compile, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/faae584d4710f987df10243f0b39bf8b54b4b705...b37114051fbc489d32cf7bc72b18950e30a676fb -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/faae584d4710f987df10243f0b39bf8b54b4b705...b37114051fbc489d32cf7bc72b18950e30a676fb You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 11:37:13 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 25 Aug 2020 07:37:13 -0400 Subject: [Git][ghc/ghc][master] SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' Message-ID: <5f44f7e97dbd4_80b3f848685789493821f3@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 0a1ecc5f by Ben Gamari at 2020-08-25T07:37:05-04:00 SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' In #18069 we are observing MVar deadlocks from somewhere in ghc.exe. This use of MVar stood out as being one of the more likely culprits. Here we make sure that it is exception-safe. - - - - - 1 changed file: - compiler/GHC/SysTools/Process.hs Changes: ===================================== compiler/GHC/SysTools/Process.hs ===================================== @@ -45,6 +45,15 @@ enableProcessJobs opts = opts enableProcessJobs opts = opts #endif +#if !MIN_VERSION_base(4,15,0) +-- TODO: This can be dropped with GHC 8.16 +hGetContents' :: Handle -> IO String +hGetContents' hdl = do + output <- hGetContents hdl + _ <- evaluate $ length output + return output +#endif + -- Similar to System.Process.readCreateProcessWithExitCode, but stderr is -- inherited from the parent process, and output to stderr is not captured. readCreateProcessWithExitCode' @@ -55,13 +64,19 @@ readCreateProcessWithExitCode' proc = do createProcess $ enableProcessJobs $ proc{ std_out = CreatePipe } -- fork off a thread to start consuming the output - output <- hGetContents outh outMVar <- newEmptyMVar - _ <- forkIO $ evaluate (length output) >> putMVar outMVar () + let onError :: SomeException -> IO () + onError exc = putMVar outMVar (Left exc) + _ <- forkIO $ handle onError $ do + output <- hGetContents' outh + putMVar outMVar $ Right output -- wait on the output - takeMVar outMVar + result <- takeMVar outMVar hClose outh + output <- case result of + Left exc -> throwIO exc + Right output -> return output -- wait on the process ex <- waitForProcess pid View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0a1ecc5fd45a46372c3935df596f05432db1b270 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0a1ecc5fd45a46372c3935df596f05432db1b270 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 11:37:46 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 25 Aug 2020 07:37:46 -0400 Subject: [Git][ghc/ghc][master] Use tcView, not coreView, in the pure unifier. Message-ID: <5f44f80a5d804_80b3f84693c1eb4938286a@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: db8793ad by Richard Eisenberg at 2020-08-25T07:37:40-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - 2 changed files: - compiler/GHC/Core/Type.hs - compiler/GHC/Core/Unify.hs Changes: ===================================== compiler/GHC/Core/Type.hs ===================================== @@ -358,10 +358,28 @@ But in Core these two are treated as identical. We implement this by making 'coreView' convert 'Constraint' to 'TYPE LiftedRep' on the fly. The function tcView (used in the type checker) -does not do this. +does not do this. Accordingly, tcView is used in type-checker-oriented +functions (including the pure unifier, used in instance resolution), +while coreView is used during e.g. optimisation passes. See also #11715, which tracks removing this inconsistency. +The inconsistency actually leads to a potential soundness bug, in that +Constraint and Type are considered *apart* by the type family engine. +To wit, we can write + + type family F a + type instance F Type = Bool + type instance F Constraint = Int + +and (because Type ~# Constraint in Core), thus build a coercion between +Int and Bool. I (Richard E) conjecture that this never happens in practice, +but it's very uncomfortable. This, essentially, is the root problem +underneath #11715, which is quite resistant to an easy fix. The best +idea is to have roles in kind coercions, but that has yet to be implemented. +See also "A Role for Dependent Types in Haskell", ICFP 2019, which describes +how roles in kinds might work out. + -} -- | Gives the typechecker view of a type. This unwraps synonyms but ===================================== compiler/GHC/Core/Unify.hs ===================================== @@ -957,7 +957,7 @@ unify_ty :: UMEnv -- Respects newtypes, PredTypes unify_ty env ty1 ty2 kco - -- TODO: More commentary needed here + -- Use tcView, not coreView. See Note [coreView vs tcView] in GHC.Core.Type. | Just ty1' <- tcView ty1 = unify_ty env ty1' ty2 kco | Just ty2' <- tcView ty2 = unify_ty env ty1 ty2' kco | CastTy ty1' co <- ty1 = if um_unif env @@ -1121,7 +1121,8 @@ uUnrefined :: UMEnv -- We know that tv1 isn't refined uUnrefined env tv1' ty2 ty2' kco - | Just ty2'' <- coreView ty2' + -- Use tcView, not coreView. See Note [coreView vs tcView] in GHC.Core.Type. + | Just ty2'' <- tcView ty2' = uUnrefined env tv1' ty2 ty2'' kco -- Unwrap synonyms -- This is essential, in case we have -- type Foo a = a @@ -1412,6 +1413,8 @@ ty_co_match :: MatchEnv -- ^ ambient helpful info -> Maybe LiftCoEnv ty_co_match menv subst ty co lkco rkco | Just ty' <- coreView ty = ty_co_match menv subst ty' co lkco rkco + -- why coreView here, not tcView? Because we're firmly after type-checking. + -- This function is used only during coercion optimisation. -- handle Refl case: | tyCoVarsOfType ty `isNotInDomainOf` subst View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/db8793ad417ebfcb57d42e8111674a90706a7918 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/db8793ad417ebfcb57d42e8111674a90706a7918 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 11:38:25 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 25 Aug 2020 07:38:25 -0400 Subject: [Git][ghc/ghc][master] Use LIdP rather than (XRec p (IdP p)) Message-ID: <5f44f8312ee43_80b3f84a401c3dc93862f9@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: fb77207a by Simon Peyton Jones at 2020-08-25T07:38:16-04:00 Use LIdP rather than (XRec p (IdP p)) This patch mainly just replaces use of XRec p (IdP p) with LIdP p One slightly more significant change is to parameterise HsPatSynDetails over the pass rather than the argument type, so that it's uniform with HsConDeclDetails and HsConPatDetails. I also got rid of the dead code GHC.Hs.type.conDetailsArgs But this is all just minor refactoring. No change in functionality. - - - - - 13 changed files: - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Extension.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/Match/Constructor.hs - compiler/GHC/HsToCore/Quote.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Parser.y - compiler/GHC/Tc/TyCl/PatSyn.hs - compiler/GHC/Tc/Utils/Zonk.hs Changes: ===================================== compiler/GHC/Hs/Binds.hs ===================================== @@ -243,7 +243,7 @@ data HsBindLR idL idR -- type Int -> forall a'. a' -> a' -- Notice that the coercion captures the free a'. - fun_id :: XRec idL (IdP idL), -- Note [fun_id in Match] in GHC.Hs.Expr + fun_id :: LIdP idL, -- Note [fun_id in Match] in GHC.Hs.Expr fun_matches :: MatchGroup idR (LHsExpr idR), -- ^ The payload @@ -369,9 +369,8 @@ type instance XXABExport (GhcPass p) = NoExtCon data PatSynBind idL idR = PSB { psb_ext :: XPSB idL idR, -- ^ Post renaming, FVs. -- See Note [Bind free vars] - psb_id :: XRec idL (IdP idL), -- ^ Name of the pattern synonym - psb_args :: HsPatSynDetails (XRec idR (IdP idR)), - -- ^ Formal parameter names + psb_id :: LIdP idL, -- ^ Name of the pattern synonym + psb_args :: HsPatSynDetails idR, -- ^ Formal parameter names psb_def :: LPat idR, -- ^ Right-hand side psb_dir :: HsPatSynDir idR -- ^ Directionality } @@ -893,7 +892,7 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation TypeSig (XTypeSig pass) - [XRec pass (IdP pass)] -- LHS of the signature; e.g. f,g,h :: blah + [LIdP pass] -- LHS of the signature; e.g. f,g,h :: blah (LHsSigWcType pass) -- RHS of the signature; can have wildcards -- | A pattern synonym type signature @@ -905,7 +904,7 @@ data Sig pass -- 'GHC.Parser.Annotation.AnnDot','GHC.Parser.Annotation.AnnDarrow' -- For details on above see note [Api annotations] in GHC.Parser.Annotation - | PatSynSig (XPatSynSig pass) [XRec pass (IdP pass)] (LHsSigType pass) + | PatSynSig (XPatSynSig pass) [LIdP pass] (LHsSigType pass) -- P :: forall a b. Req => Prov => ty -- | A signature for a class method @@ -918,7 +917,7 @@ data Sig pass -- -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnDefault', -- 'GHC.Parser.Annotation.AnnDcolon' - | ClassOpSig (XClassOpSig pass) Bool [XRec pass (IdP pass)] (LHsSigType pass) + | ClassOpSig (XClassOpSig pass) Bool [LIdP pass] (LHsSigType pass) -- | A type signature in generated code, notably the code -- generated for record selectors. We simply record @@ -950,8 +949,8 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | InlineSig (XInlineSig pass) - (XRec pass (IdP pass)) -- Function name - InlinePragma -- Never defaultInlinePragma + (LIdP pass) -- Function name + InlinePragma -- Never defaultInlinePragma -- | A specialisation pragma -- @@ -966,7 +965,7 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | SpecSig (XSpecSig pass) - (XRec pass (IdP pass)) -- Specialise a function or datatype ... + (LIdP pass) -- Specialise a function or datatype ... [LHsSigType pass] -- ... to these types InlinePragma -- The pragma on SPECIALISE_INLINE form. -- If it's just defaultInlinePragma, then we said @@ -996,7 +995,7 @@ data Sig pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | MinimalSig (XMinimalSig pass) - SourceText (LBooleanFormula (XRec pass (IdP pass))) + SourceText (LBooleanFormula (LIdP pass)) -- Note [Pragma source text] in GHC.Types.Basic -- | A "set cost centre" pragma for declarations @@ -1008,8 +1007,8 @@ data Sig pass -- > {-# SCC funName "cost_centre_name" #-} | SCCFunSig (XSCCFunSig pass) - SourceText -- Note [Pragma source text] in GHC.Types.Basic - (XRec pass (IdP pass)) -- Function name + SourceText -- Note [Pragma source text] in GHC.Types.Basic + (LIdP pass) -- Function name (Maybe (XRec pass StringLiteral)) -- | A complete match pragma -- @@ -1020,8 +1019,8 @@ data Sig pass -- synonym definitions. | CompleteMatchSig (XCompleteMatchSig pass) SourceText - (XRec pass [XRec pass (IdP pass)]) - (Maybe (XRec pass (IdP pass))) + (XRec pass [LIdP pass]) + (Maybe (LIdP pass)) | XSig !(XXSig pass) type instance XTypeSig (GhcPass p) = NoExtField @@ -1041,7 +1040,7 @@ type instance XXSig (GhcPass p) = NoExtCon type LFixitySig pass = XRec pass (FixitySig pass) -- | Fixity Signature -data FixitySig pass = FixitySig (XFixitySig pass) [XRec pass (IdP pass)] Fixity +data FixitySig pass = FixitySig (XFixitySig pass) [LIdP pass] Fixity | XFixitySig !(XXFixitySig pass) type instance XFixitySig (GhcPass p) = NoExtField @@ -1229,14 +1228,14 @@ pprMinimalSig (L _ bf) = ppr (fmap unLoc bf) -} -- | Haskell Pattern Synonym Details -type HsPatSynDetails arg = HsConDetails arg [RecordPatSynField arg] +type HsPatSynDetails pass = HsConDetails (LIdP pass) [RecordPatSynField (LIdP pass)] -- See Note [Record PatSyn Fields] -- | Record Pattern Synonym Field -data RecordPatSynField a +data RecordPatSynField fld = RecordPatSynField { - recordPatSynSelectorId :: a -- Selector name visible in rest of the file - , recordPatSynPatVar :: a + recordPatSynSelectorId :: fld -- Selector name visible in rest of the file + , recordPatSynPatVar :: fld -- Filled in by renamer, the name used internally -- by the pattern } deriving (Data, Functor) ===================================== compiler/GHC/Hs/Decls.hs ===================================== @@ -592,7 +592,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation SynDecl { tcdSExt :: XSynDecl pass -- ^ Post renameer, FVs - , tcdLName :: XRec pass (IdP pass) -- ^ Type constructor + , tcdLName :: LIdP pass -- ^ Type constructor , tcdTyVars :: LHsQTyVars pass -- ^ Type variables; for an -- associated type these -- include outer binders @@ -609,7 +609,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation DataDecl { tcdDExt :: XDataDecl pass -- ^ Post renamer, CUSK flag, FVs - , tcdLName :: XRec pass (IdP pass) -- ^ Type constructor + , tcdLName :: LIdP pass -- ^ Type constructor , tcdTyVars :: LHsQTyVars pass -- ^ Type variables -- See Note [TyVar binders for associated declarations] , tcdFixity :: LexicalFixity -- ^ Fixity used in the declaration @@ -617,7 +617,7 @@ data TyClDecl pass | ClassDecl { tcdCExt :: XClassDecl pass, -- ^ Post renamer, FVs tcdCtxt :: LHsContext pass, -- ^ Context... - tcdLName :: XRec pass (IdP pass), -- ^ Name of the class + tcdLName :: LIdP pass, -- ^ Name of the class tcdTyVars :: LHsQTyVars pass, -- ^ Class type variables tcdFixity :: LexicalFixity, -- ^ Fixity used in the declaration tcdFDs :: [LHsFunDep pass], -- ^ Functional deps @@ -637,7 +637,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | XTyClDecl !(XXTyClDecl pass) -type LHsFunDep pass = XRec pass (FunDep (XRec pass (IdP pass))) +type LHsFunDep pass = XRec pass (FunDep (LIdP pass)) data DataDeclRn = DataDeclRn { tcdDataCusk :: Bool -- ^ does this have a CUSK? @@ -1135,7 +1135,7 @@ type LFamilyDecl pass = XRec pass (FamilyDecl pass) data FamilyDecl pass = FamilyDecl { fdExt :: XCFamilyDecl pass , fdInfo :: FamilyInfo pass -- type/data, closed/open - , fdLName :: XRec pass (IdP pass) -- type constructor + , fdLName :: LIdP pass -- type constructor , fdTyVars :: LHsQTyVars pass -- type variables -- See Note [TyVar binders for associated declarations] , fdFixity :: LexicalFixity -- Fixity used in the declaration @@ -1168,7 +1168,7 @@ type LInjectivityAnn pass = XRec pass (InjectivityAnn pass) -- -- This will be represented as "InjectivityAnn `r` [`a`, `c`]" data InjectivityAnn pass - = InjectivityAnn (XRec pass (IdP pass)) [XRec pass (IdP pass)] + = InjectivityAnn (LIdP pass) [LIdP pass] -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : -- 'GHC.Parser.Annotation.AnnRarrow', 'GHC.Parser.Annotation.AnnVbar' @@ -1364,7 +1364,7 @@ type LStandaloneKindSig pass = XRec pass (StandaloneKindSig pass) data StandaloneKindSig pass = StandaloneKindSig (XStandaloneKindSig pass) - (XRec pass (IdP pass)) -- Why a single binder? See #16754 + (LIdP pass) -- Why a single binder? See #16754 (LHsSigType pass) -- Why not LHsSigWcType? See Note [Wildcards in standalone kind signatures] | XStandaloneKindSig !(XXStandaloneKindSig pass) @@ -1435,7 +1435,7 @@ type LConDecl pass = XRec pass (ConDecl pass) data ConDecl pass = ConDeclGADT { con_g_ext :: XConDeclGADT pass - , con_names :: [XRec pass (IdP pass)] + , con_names :: [LIdP pass] -- The following fields describe the type after the '::' -- See Note [GADT abstract syntax] @@ -1458,7 +1458,7 @@ data ConDecl pass | ConDeclH98 { con_ext :: XConDeclH98 pass - , con_name :: XRec pass (IdP pass) + , con_name :: LIdP pass , con_forall :: XRec pass Bool -- ^ True <=> explicit user-written forall @@ -1849,7 +1849,7 @@ type FamInstEqn pass rhs = HsImplicitBndrs pass (FamEqn pass rhs) data FamEqn pass rhs = FamEqn { feqn_ext :: XCFamEqn pass rhs - , feqn_tycon :: XRec pass (IdP pass) + , feqn_tycon :: LIdP pass , feqn_bndrs :: Maybe [LHsTyVarBndr () pass] -- ^ Optional quantified type vars , feqn_pats :: HsTyPats pass , feqn_fixity :: LexicalFixity -- ^ Fixity used in the declaration @@ -2214,13 +2214,13 @@ type LForeignDecl pass = XRec pass (ForeignDecl pass) data ForeignDecl pass = ForeignImport { fd_i_ext :: XForeignImport pass -- Post typechecker, rep_ty ~ sig_ty - , fd_name :: XRec pass (IdP pass) -- defines this name + , fd_name :: LIdP pass -- defines this name , fd_sig_ty :: LHsSigType pass -- sig_ty , fd_fi :: ForeignImport } | ForeignExport { fd_e_ext :: XForeignExport pass -- Post typechecker, rep_ty ~ sig_ty - , fd_name :: XRec pass (IdP pass) -- uses this name + , fd_name :: LIdP pass -- uses this name , fd_sig_ty :: LHsSigType pass -- sig_ty , fd_fe :: ForeignExport } -- ^ @@ -2402,8 +2402,8 @@ type LRuleBndr pass = XRec pass (RuleBndr pass) -- | Rule Binder data RuleBndr pass - = RuleBndr (XCRuleBndr pass) (XRec pass (IdP pass)) - | RuleBndrSig (XRuleBndrSig pass) (XRec pass (IdP pass)) (HsPatSigType pass) + = RuleBndr (XCRuleBndr pass) (LIdP pass) + | RuleBndrSig (XRuleBndrSig pass) (LIdP pass) (HsPatSigType pass) | XRuleBndr !(XXRuleBndr pass) -- ^ -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen', @@ -2505,7 +2505,7 @@ type instance XXWarnDecls (GhcPass _) = NoExtCon type LWarnDecl pass = XRec pass (WarnDecl pass) -- | Warning pragma Declaration -data WarnDecl pass = Warning (XWarning pass) [XRec pass (IdP pass)] WarningTxt +data WarnDecl pass = Warning (XWarning pass) [LIdP pass] WarningTxt | XWarnDecl !(XXWarnDecl pass) type instance XWarning (GhcPass _) = NoExtField @@ -2592,7 +2592,7 @@ type LRoleAnnotDecl pass = XRec pass (RoleAnnotDecl pass) -- | Role Annotation Declaration data RoleAnnotDecl pass = RoleAnnotDecl (XCRoleAnnotDecl pass) - (XRec pass (IdP pass)) -- type constructor + (LIdP pass) -- type constructor [XRec pass (Maybe Role)] -- optional annotations -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnType', -- 'GHC.Parser.Annotation.AnnRole' ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -242,9 +242,8 @@ is Less Cool because -- | A Haskell expression. data HsExpr p = HsVar (XVar p) - (XRec p (IdP p)) -- ^ Variable - - -- See Note [Located RdrNames] + (LIdP p) -- ^ Variable + -- See Note [Located RdrNames] | HsUnboundVar (XUnboundVar p) OccName -- ^ Unbound variable; also used for "holes" @@ -439,7 +438,7 @@ data HsExpr p -- For details on above see note [Api annotations] in GHC.Parser.Annotation | RecordCon { rcon_ext :: XRecordCon p - , rcon_con_name :: XRec p (IdP p) -- The constructor name; + , rcon_con_name :: LIdP p -- The constructor name; -- not used after type checking , rcon_flds :: HsRecordBinds p } -- The fields @@ -2987,7 +2986,7 @@ matchSeparator ThPatSplice = panic "unused" matchSeparator ThPatQuote = panic "unused" matchSeparator PatSyn = panic "unused" -pprMatchContext :: Outputable (IdP p) +pprMatchContext :: (Outputable (IdP p), UnXRec p) => HsMatchContext p -> SDoc pprMatchContext ctxt | want_an ctxt = text "an" <+> pprMatchContextNoun ctxt @@ -2997,11 +2996,11 @@ pprMatchContext ctxt want_an ProcExpr = True want_an _ = False -pprMatchContextNoun :: Outputable (IdP id) - => HsMatchContext id -> SDoc -pprMatchContextNoun (FunRhs {mc_fun=L _ fun}) +pprMatchContextNoun :: forall p. (Outputable (IdP p), UnXRec p) + => HsMatchContext p -> SDoc +pprMatchContextNoun (FunRhs {mc_fun=fun}) = text "equation for" - <+> quotes (ppr fun) + <+> quotes (ppr (unXRec @p fun)) pprMatchContextNoun CaseAlt = text "case alternative" pprMatchContextNoun IfAlt = text "multi-way if alternative" pprMatchContextNoun RecUpd = text "record-update construct" @@ -3016,8 +3015,8 @@ pprMatchContextNoun (StmtCtxt ctxt) = text "pattern binding in" pprMatchContextNoun PatSyn = text "pattern synonym declaration" ----------------- -pprAStmtContext, pprStmtContext :: Outputable (IdP id) - => HsStmtContext id -> SDoc +pprAStmtContext, pprStmtContext :: (Outputable (IdP p), UnXRec p) + => HsStmtContext p -> SDoc pprAStmtContext ctxt = article <+> pprStmtContext ctxt where pp_an = text "an" ===================================== compiler/GHC/Hs/Extension.hs ===================================== @@ -307,7 +307,7 @@ type family IdGhcP pass where IdGhcP 'Renamed = Name IdGhcP 'Typechecked = Id -type LIdP p = Located (IdP p) +type LIdP p = XRec p (IdP p) -- | Marks that a field uses the GhcRn variant even when the pass -- parameter is GhcTc. Useful for storing HsTypes in GHC.Hs.Exprs, say, because ===================================== compiler/GHC/Hs/Pat.hs ===================================== @@ -93,7 +93,7 @@ data Pat p -- AZ:TODO above comment needs to be updated | VarPat (XVarPat p) - (XRec p (IdP p)) -- ^ Variable Pattern + (LIdP p) -- ^ Variable Pattern -- See Note [Located RdrNames] in GHC.Hs.Expr | LazyPat (XLazyPat p) @@ -103,7 +103,7 @@ data Pat p -- For details on above see note [Api annotations] in GHC.Parser.Annotation | AsPat (XAsPat p) - (XRec p (IdP p)) (LPat p) -- ^ As pattern + (LIdP p) (LPat p) -- ^ As pattern -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnAt' -- For details on above see note [Api annotations] in GHC.Parser.Annotation @@ -224,7 +224,7 @@ data Pat p -- For details on above see note [Api annotations] in GHC.Parser.Annotation | NPlusKPat (XNPlusKPat p) -- Type of overall pattern - (XRec p (IdP p)) -- n+k pattern + (LIdP p) -- n+k pattern (XRec p (HsOverLit p)) -- It'll always be an HsIntegral (HsOverLit p) -- See Note [NPlusK patterns] in GHC.Tc.Gen.Pat -- NB: This could be (PostTc ...), but that induced a @@ -313,7 +313,7 @@ type instance XXPat GhcTc = CoPat type family ConLikeP x type instance ConLikeP GhcPs = RdrName -- IdP GhcPs -type instance ConLikeP GhcRn = Name -- IdP GhcRn +type instance ConLikeP GhcRn = Name -- IdP GhcRn type instance ConLikeP GhcTc = ConLike -- --------------------------------------------------------------------- ===================================== compiler/GHC/Hs/Type.hs ===================================== @@ -73,7 +73,6 @@ module GHC.Hs.Type ( mkHsOpTy, mkHsAppTy, mkHsAppTys, mkHsAppKindTy, ignoreParens, hsSigType, hsSigWcType, hsPatSigType, hsTyKindSig, - hsConDetailsArgs, setHsTyVarBndrFlag, hsTyVarBndrFlag, -- Printing @@ -638,13 +637,13 @@ data HsTyVarBndr flag pass = UserTyVar -- no explicit kinding (XUserTyVar pass) flag - (XRec pass (IdP pass)) + (LIdP pass) -- See Note [Located RdrNames] in GHC.Hs.Expr | KindedTyVar (XKindedTyVar pass) flag - (XRec pass (IdP pass)) + (LIdP pass) (LHsKind pass) -- The user-supplied kind signature -- ^ -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen', @@ -705,7 +704,7 @@ data HsType pass | HsTyVar (XTyVar pass) PromotionFlag -- Whether explicitly promoted, -- for the pretty printer - (XRec pass (IdP pass)) + (LIdP pass) -- Type variable, type constructor, or data constructor -- see Note [Promotions (HsTyVar)] -- See Note [Located RdrNames] in GHC.Hs.Expr @@ -755,7 +754,7 @@ data HsType pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | HsOpTy (XOpTy pass) - (LHsType pass) (XRec pass (IdP pass)) (LHsType pass) + (LHsType pass) (LIdP pass) (LHsType pass) -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : None -- For details on above see note [Api annotations] in GHC.Parser.Annotation @@ -1116,14 +1115,6 @@ instance (Outputable arg, Outputable rec) ppr (RecCon rec) = text "RecCon:" <+> ppr rec ppr (InfixCon l r) = text "InfixCon:" <+> ppr [l, r] -hsConDetailsArgs :: - HsConDetails (LHsType (GhcPass p)) (Located [LConDeclField (GhcPass p)]) - -> [LHsType (GhcPass p)] -hsConDetailsArgs details = case details of - InfixCon a b -> [a,b] - PrefixCon xs -> xs - RecCon r -> map (cd_fld_type . unLoc) (unLoc r) - {- Note [ConDeclField passs] ~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/Hs/Utils.hs ===================================== @@ -777,7 +777,7 @@ mkVarBind var rhs = L (getLoc rhs) $ VarBind { var_ext = noExtField, var_id = var, var_rhs = rhs } -mkPatSynBind :: Located RdrName -> HsPatSynDetails (Located RdrName) +mkPatSynBind :: Located RdrName -> HsPatSynDetails GhcPs -> LPat GhcPs -> HsPatSynDir GhcPs -> HsBind GhcPs mkPatSynBind name details lpat dir = PatSynBind noExtField psb where @@ -990,7 +990,7 @@ collect_bind omitPatSyn (PatSynBind _ (PSB { psb_id = ps })) acc collect_bind _ (PatSynBind _ (XPatSynBind _)) acc = acc collect_bind _ (XHsBindsLR _) acc = acc -collectMethodBinders :: forall idL idR. UnXRec idL => LHsBindsLR idL idR -> [XRec idL (IdP idL)] +collectMethodBinders :: forall idL idR. UnXRec idL => LHsBindsLR idL idR -> [LIdP idL] -- ^ Used exclusively for the bindings of an instance decl which are all -- 'FunBinds' collectMethodBinders binds = foldr (get . unXRec @idL) [] binds @@ -1173,7 +1173,7 @@ hsLTyClDeclBinders (L loc (DataDecl { tcdLName = (L _ name) ------------------- -hsForeignDeclsBinders :: forall pass. (UnXRec pass, MapXRec pass) => [LForeignDecl pass] -> [XRec pass (IdP pass)] +hsForeignDeclsBinders :: forall pass. (UnXRec pass, MapXRec pass) => [LForeignDecl pass] -> [LIdP pass] -- ^ See Note [SrcSpan for binders] hsForeignDeclsBinders foreign_decls = [ mapXRec @pass (const $ unXRec @pass n) fi ===================================== compiler/GHC/HsToCore/Match/Constructor.hs ===================================== @@ -126,7 +126,7 @@ matchPatSyn (var :| vars) ty eqns PatSynCon psyn -> alt{ alt_pat = psyn } _ -> panic "matchPatSyn: not PatSynCon" -type ConArgPats = HsConDetails (LPat GhcTc) (HsRecFields GhcTc (LPat GhcTc)) +type ConArgPats = HsConPatDetails GhcTc matchOneConLike :: [Id] -> Type ===================================== compiler/GHC/HsToCore/Quote.hs ===================================== @@ -1840,7 +1840,7 @@ rep_bind (L loc (PatSynBind _ (PSB { psb_id = syn ; patSynD'' <- wrapGenArgSyms args ss patSynD' ; return (loc, patSynD'') } where - mkGenArgSyms :: HsPatSynDetails (Located Name) -> MetaM [GenSymBind] + mkGenArgSyms :: HsPatSynDetails GhcRn -> MetaM [GenSymBind] -- for Record Pattern Synonyms we want to conflate the selector -- and the pattern-only names in order to provide a nicer TH -- API. Whereas inside GHC, record pattern synonym selectors and @@ -1859,7 +1859,7 @@ rep_bind (L loc (PatSynBind _ (PSB { psb_id = syn = [ (pat, id) | (sel, id) <- genSyms, (sel', pat) <- selsPats , sel == sel' ] - wrapGenArgSyms :: HsPatSynDetails (Located Name) + wrapGenArgSyms :: HsPatSynDetails GhcRn -> [GenSymBind] -> Core (M TH.Dec) -> MetaM (Core (M TH.Dec)) wrapGenArgSyms (RecCon _) _ dec = return dec wrapGenArgSyms _ ss dec = wrapGenSyms ss dec @@ -1872,7 +1872,7 @@ repPatSynD :: Core TH.Name repPatSynD (MkC syn) (MkC args) (MkC dir) (MkC pat) = rep2 patSynDName [syn, args, dir, pat] -repPatSynArgs :: HsPatSynDetails (Located Name) -> MetaM (Core (M TH.PatSynArgs)) +repPatSynArgs :: HsPatSynDetails GhcRn -> MetaM (Core (M TH.PatSynArgs)) repPatSynArgs (PrefixCon args) = do { args' <- repList nameTyConName lookupLOcc args ; repPrefixPatSynArgs args' } ===================================== compiler/GHC/HsToCore/Utils.hs ===================================== @@ -900,7 +900,7 @@ CPR-friendly. This matters a lot: if you don't get it right, you lose the tail call property. For example, see #3403. -} -dsHandleMonadicFailure :: Outputable (IdP p) => HsStmtContext p -> LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr +dsHandleMonadicFailure :: HsStmtContext GhcRn -> LPat GhcTc -> MatchResult CoreExpr -> FailOperator GhcTc -> DsM CoreExpr -- In a do expression, pattern-match failure just calls -- the monadic 'fail' rather than throwing an exception dsHandleMonadicFailure ctx pat match m_fail_op = @@ -921,8 +921,9 @@ dsHandleMonadicFailure ctx pat match m_fail_op = fail_expr <- dsSyntaxExpr fail_op [fail_msg] body fail_expr -mk_fail_msg :: Outputable (IdP p) => DynFlags -> HsStmtContext p -> Located e -> String -mk_fail_msg dflags ctx pat = showPpr dflags $ text "Pattern match failure in" <+> pprStmtContext ctx <+> text "at" <+> ppr (getLoc pat) +mk_fail_msg :: DynFlags -> HsStmtContext GhcRn -> Located e -> String +mk_fail_msg dflags ctx pat + = showPpr dflags $ text "Pattern match failure in" <+> pprStmtContext ctx <+> text "at" <+> ppr (getLoc pat) {- ********************************************************************* * * ===================================== compiler/GHC/Parser.y ===================================== @@ -1491,7 +1491,7 @@ pattern_synonym_decl :: { LHsDecl GhcPs } (as ++ ((mj AnnPattern $1:mu AnnLarrow $3:(fst $ unLoc $5))) ) }} -pattern_synonym_lhs :: { (Located RdrName, HsPatSynDetails (Located RdrName), [AddAnn]) } +pattern_synonym_lhs :: { (Located RdrName, HsPatSynDetails GhcPs, [AddAnn]) } : con vars0 { ($1, PrefixCon $2, []) } | varid conop varid { ($2, InfixCon $1 $3, []) } | con '{' cvars1 '}' { ($1, RecCon $3, [moc $2, mcc $4] ) } ===================================== compiler/GHC/Tc/TyCl/PatSyn.hs ===================================== @@ -558,7 +558,7 @@ a pattern synonym. What about the /building/ side? a bad idea. -} -collectPatSynArgInfo :: HsPatSynDetails (Located Name) +collectPatSynArgInfo :: HsPatSynDetails GhcRn -> ([Name], [Name], Bool) collectPatSynArgInfo details = case details of ===================================== compiler/GHC/Tc/Utils/Zonk.hs ===================================== @@ -626,8 +626,8 @@ zonk_bind env (PatSynBind x bind@(PSB { psb_id = L loc id , psb_dir = dir' } } zonkPatSynDetails :: ZonkEnv - -> HsPatSynDetails (Located TcId) - -> HsPatSynDetails (Located Id) + -> HsPatSynDetails GhcTc + -> HsPatSynDetails GhcTc zonkPatSynDetails env (PrefixCon as) = PrefixCon (map (zonkLIdOcc env) as) zonkPatSynDetails env (InfixCon a1 a2) @@ -1450,10 +1450,8 @@ zonk_pat env (XPat (CoPat co_fn pat ty)) zonk_pat _ pat = pprPanic "zonk_pat" (ppr pat) --------------------------- -zonkConStuff :: ZonkEnv - -> HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc)) - -> TcM (ZonkEnv, - HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc))) +zonkConStuff :: ZonkEnv -> HsConPatDetails GhcTc + -> TcM (ZonkEnv, HsConPatDetails GhcTc) zonkConStuff env (PrefixCon pats) = do { (env', pats') <- zonkPats env pats ; return (env', PrefixCon pats') } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fb77207a23deade8e3f8598c34598535711264cc -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fb77207a23deade8e3f8598c34598535711264cc You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 11:38:59 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 25 Aug 2020 07:38:59 -0400 Subject: [Git][ghc/ghc][master] Add a test for #18585 Message-ID: <5f44f853b14b3_80b3f848685789493882de@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 8426a136 by Krzysztof Gogolewski at 2020-08-25T07:38:54-04:00 Add a test for #18585 - - - - - 2 changed files: - + testsuite/tests/typecheck/should_compile/T18585.hs - testsuite/tests/typecheck/should_compile/all.T Changes: ===================================== testsuite/tests/typecheck/should_compile/T18585.hs ===================================== @@ -0,0 +1,48 @@ +{-# Language DataKinds #-} +{-# Language FlexibleContexts #-} +{-# Language PolyKinds #-} +{-# Language StandaloneKindSignatures #-} +{-# Language TypeFamilyDependencies #-} +{-# Language UndecidableInstances #-} +{-# Language UndecidableSuperClasses #-} +module T18585 (Functor(..)) where + +import Data.Kind (Type) +import Prelude hiding (Functor(..)) + +type Cat i = i -> i -> Type + +class + ( Op (Op k) ~ k + , Category (Op k) + ) => Category (k :: Cat i) where + type Op k :: i -> i -> Type + type Op k = Y k + +newtype Y k a b = Y (k b a) + +instance (Category k, Op k ~ Y k) => Category (Y k) where + type Op (Y k) = k + +instance Category (->) + +type SelfDom :: (i -> j) -> Cat i -> Cat i +type family SelfDom (f :: i -> j) (k :: Cat i) :: Cat i where + SelfDom p p = Op p + SelfDom f p = p + +type family DefaultCat (i :: Type) = (res :: Cat i) | res -> i +type instance DefaultCat Type = (->) + +class + ( Category (Dom f) + , Category (Cod f) + ) => Functor (f :: i -> j) where + + type Dom f :: Cat i + type Dom (f :: i -> j) = SelfDom f (DefaultCat i) + + type Cod f :: Cat j + type Cod (f :: i -> j) = DefaultCat j + +instance Functor IO ===================================== testsuite/tests/typecheck/should_compile/all.T ===================================== @@ -721,4 +721,5 @@ test('T18118', normal, multimod_compile, ['T18118', '-v0']) test('T18412', normal, compile, ['']) test('T18470', normal, compile, ['']) test('T18323', normal, compile, ['']) +test('T18585', normal, compile, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8426a1364ba450fe48fc41a95b2ba76c8d1bb7c8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8426a1364ba450fe48fc41a95b2ba76c8d1bb7c8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 11:51:12 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Tue, 25 Aug 2020 07:51:12 -0400 Subject: [Git][ghc/ghc][wip/T18223] Wibbles Message-ID: <5f44fb3096b31_80b3f8495bc8b04939207e@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18223 at Glasgow Haskell Compiler / GHC Commits: e3c76de3 by Simon Peyton Jones at 2020-08-25T12:50:30+01:00 Wibbles - - - - - 6 changed files: - compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Specialise.hs - testsuite/tests/perf/compiler/T16473.stdout - testsuite/tests/printer/T18052a.stderr - testsuite/tests/simplCore/should_compile/T17966.stdout - testsuite/tests/stranal/should_compile/T18122.stderr Changes: ===================================== compiler/GHC/Core/Opt/Pipeline.hs ===================================== @@ -311,33 +311,38 @@ getCoreToDo dflags runWhen do_float_in CoreDoFloatInwards, + simplify "final", -- Final tidy-up + maybe_rule_check FinalPhase, + -------- After this we have -O2 passes ----------------- + -- None of them run with -O + -- Case-liberation for -O2. This should be after -- strictness analysis and the simplification which follows it. - runWhen liberate_case (CoreDoPasses [ - CoreLiberateCase, - simplify "post-liberate-case" - ]), -- Run the simplifier after LiberateCase to vastly - -- reduce the possibility of shadowing - -- Reason: see Note [Shadowing] in GHC.Core.Opt.SpecConstr + runWhen liberate_case $ CoreDoPasses + [ CoreLiberateCase, simplify "post-liberate-case" ], + -- Run the simplifier after LiberateCase to vastly + -- reduce the possibility of shadowing + -- Reason: see Note [Shadowing] in GHC.Core.Opt.SpecConstr - runWhen spec_constr CoreDoSpecConstr, + runWhen spec_constr $ CoreDoPasses + [ CoreDoSpecConstr, simplify "post-spec-constr"], + -- See Note [Simplify after SpecConstr] maybe_rule_check FinalPhase, - runWhen late_specialise - (CoreDoPasses [ CoreDoSpecialising - , simplify "post-late-spec"]), + runWhen late_specialise $ CoreDoPasses + [ CoreDoSpecialising, simplify "post-late-spec"], -- LiberateCase can yield new CSE opportunities because it peels -- off one layer of a recursive function (concretely, I saw this -- in wheel-sieve1), and I'm guessing that SpecConstr can too -- And CSE is a very cheap pass. So it seems worth doing here. - runWhen ((liberate_case || spec_constr) && cse) CoreCSE, + runWhen ((liberate_case || spec_constr) && cse) $ CoreDoPasses + [ CoreCSE, simplify "post-final-cse" ], - -- Final clean-up simplification: - simplify "final", + --------- End of -O2 passes -------------- runWhen late_dmd_anal $ CoreDoPasses ( dmd_cpr_ww ++ [simplify "post-late-ww"] @@ -406,6 +411,10 @@ or with -O0. Two reasons: But watch out: list fusion can prevent floating. So use phase control to switch off those rules until after floating. +Note [Simplify after SpecConstr] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +We want to run the simplifier after SpecConstr, and + ************************************************************************ * * The CoreToDo interpreter ===================================== compiler/GHC/Core/Opt/Specialise.hs ===================================== @@ -719,7 +719,7 @@ spec_import top_env callers rb dict_binds cis@(CIS fn _) = do { -- debugTraceMsg (text "specImport:no valid calls") ; return ([], []) } - | Just rhs <- maybeUnfoldingTemplate unfolding + | Just rhs <- canSpecImport dflags fn = do { -- Get rules from the external package state -- We keep doing this in case we "page-fault in" -- more rules as we go along @@ -757,11 +757,33 @@ spec_import top_env callers rb dict_binds cis@(CIS fn _) where dflags = se_dflags top_env - unfolding = realIdUnfolding fn -- We want to see the unfolding even for loop breakers good_calls = filterCalls cis dict_binds -- SUPER IMPORTANT! Drop calls that (directly or indirectly) refer to fn -- See Note [Avoiding loops in specImports] +canSpecImport :: DynFlags -> Id -> Maybe CoreExpr +-- See Note [Specialise imported INLINABLE things] +canSpecImport dflags fn + | CoreUnfolding { uf_src = src, uf_tmpl = rhs } <- unf + , isStableSource src + = Just rhs -- By default, specialise only imported things that have a stable + -- unfolding; that is, have an INLINE or INLINABLE pragma + -- Specialise even INLINE things; it hasn't inlined yet, + -- so perhaps it never will. Moreover it may have calls + -- inside it that we want to specialise + + -- CoreUnfolding case does /not/ include DFunUnfoldings; + -- We only specialise DFunUnfoldings with -fspecialise-aggressively + -- See Note [Do not specialise imported DFuns] + + | gopt Opt_SpecialiseAggressively dflags + = maybeUnfoldingTemplate unf -- With -fspecialise-aggressively, specialise anything + -- with an unfolding, stable or not, DFun or not + + | otherwise = Nothing + where + unf = realIdUnfolding fn -- We want to see the unfolding even for loop breakers + -- | Returns whether or not to show a missed-spec warning. -- If -Wall-missed-specializations is on, show the warning. -- Otherwise, if -Wmissed-specializations is on, only show a warning @@ -786,8 +808,47 @@ tryWarnMissingSpecs dflags callers fn calls_for_fn , whenPprDebug (text "calls:" <+> vcat (map (pprCallInfo fn) calls_for_fn)) , text "Probable fix: add INLINABLE pragma on" <+> quotes (ppr fn) ]) -{- Note [Avoiding loops in specImports] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +{- Note [Do not specialise imported DFuns] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Ticket #18223 shows that specialising calls of DFuns is can cause a huge +and entirely unnecessary blowup in program size. Consider a call to + f @[[[[[[[[T]]]]]]]] d1 x +where df :: C a => C [a] + d1 :: C [[[[[[[[T]]]]]]]] = dfC[] @[[[[[[[T]]]]]]] d1 + d2 :: C [[[[[[[T]]]]]]] = dfC[] @[[[[[[T]]]]]] d3 + ... +Now we'll specialise f's RHS, which may give rise to calls to 'g', +also overloaded, which we will specialise, and so on. However, if +we specialise the calls to dfC[], we'll generate specialised copies of +all methods of C, at all types; and the same for C's superclasses. + +And many of these specialised functions will never be called. We are +going to call the specialised 'f', and the specialised 'g', but DFuns +group functions into a tuple, many of whose elements may never be used. + +With deeply-nested types this can lead to a simply overwhelming number +of specialisations: see #18223 for a simple example (from the wild). +I measured the number of specialisations for various numbers of calls +of `flip evalStateT ()`, and got this + + Size after one simplification + #calls #SPEC rules Terms Types + 5 56 3100 10600 + 9 108 13660 77206 + +The real tests case has 60+ calls, which blew GHC out of the water. + +Solution: don't specialise DFuns. The downside is that if we end +up with (h (dfun d)), /and/ we don't specialise 'h', then we won't +pass to 'h' a tuple of specialised functions. + +However, the flag -fspecialise-aggressively (experimental, off by default) +allows DFuns to specialise as well. + +Note [Avoiding loops in specImports] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We must take great care when specialising instance declarations (functions like $fOrdList) lest we accidentally build a recursive dictionary. See Note [Avoiding loops]. @@ -2502,69 +2563,16 @@ mkCallUDs' env f args ForAllPred {} -> True wantCallsFor :: SpecEnv -> Id -> Bool -wantCallsFor env f - | isLocalId f -- Local function; don't look at the unfolding, because - = True -- unfoldings for local functions are discarded by cloneBind - -- ToDo: we could keep a candidate set of let-binders to - -- reduce the size of the UsageDetails - - | otherwise -- Imported function - = case unf of - NoUnfolding -> False - BootUnfolding -> False - OtherCon {} -> False - CoreUnfolding { uf_src = src } - | isStableSource src -> True -- INLINEABLE/INLINE - -- See Note [Specialise imported INLINABLE things] - -- Specialise even INLINE things; it hasn't inlined yet, - -- so perhaps it never will. Moreover it may have calls - -- inside it that we want to specialise - | otherwise -> aggressive_only -- Imported, no INLINABLE - DFunUnfolding {} -> aggressive_only -- See Note [Do not specialise DFuns] - where - aggressive_only = gopt Opt_SpecialiseAggressively (se_dflags env) - unf = realIdUnfolding f - -- 'realIdUnfolding' to ignore the loop-breaker flag! - -{- Note [Do not specialise DFuns] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Ticket #18223 shows that specialising calls of DFuns is can cause a huge -and entirely unnecessary blowup in program size. Consider a call to - f @[[[[[[[[T]]]]]]]] d1 x -where df :: C a => C [a] - d1 :: C [[[[[[[[T]]]]]]]] = dfC[] @[[[[[[[T]]]]]]] d1 - d2 :: C [[[[[[[T]]]]]]] = dfC[] @[[[[[[T]]]]]] d3 - ... -Now we'll specialise f's RHS, which may give rise to calls to 'g', -also overloaded, which we will specialise, and so on. However, if -we specialise the calls to dfC[], we'll generate specialised copies of -all methods of C, at all types; and the same for C's superclasses. - -And many of these specialised functions will never be called. We are -going to call the specialised 'f', and the specialised 'g', but DFuns -group functions into a tuple, many of whose elements may never be used. - -With deeply-nested types this can lead to a simply overwhelming number -of specialisations: see #18223 for a simple example (from the wild). -I measured the number of specialisations for various numbers of calls -of `flip evalStateT ()`, and got this - - Size after one simplification - #calls #SPEC rules Terms Types - 5 56 3100 10600 - 9 108 13660 77206 - -The real tests case has 60+ calls, which blew GHC out of the water. +wantCallsFor _env _f = True + -- We could be less eager about collecting calls for LocalIds: there's + -- no point for ones that are lambda-bound. But we can't use the + -- unfolding, because unfoldings for local functions are discarded by + -- cloneBindSM. We could keep a candidate set of let-binders to + -- reduce the size of the UsageDetails -Solution: don't specialise DFuns. The downside is that if we end -up with (h (dfun d)), /and/ we don't specialise 'h', then we won't -pass to 'h' a tuple of specialised functions. -However, the flag -fspecialise-aggressively (experimental, off by default) -allows DFuns to specialise as well. - -Note [Type determines value] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +{- Note [Type determines value] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Only specialise on non-IP *class* params, because these are the ones whose *type* determines their *value*. In particular, with implicit params, the type args *don't* say what the value of the implicit param ===================================== testsuite/tests/perf/compiler/T16473.stdout ===================================== @@ -73,25 +73,15 @@ Rule fired: Class op $p1Monad (BUILTIN) Rule fired: Class op pure (BUILTIN) Rule fired: Class op $p1Monad (BUILTIN) Rule fired: Class op $p1Applicative (BUILTIN) -Rule fired: SPEC/Main $fMonadStateT_$c>>= @Identity _ (Main) -Rule fired: SPEC/Main $fApplicativeStateT_$c<*> @Identity _ (Main) -Rule fired: SPEC/Main $fApplicativeStateT_$cpure @Identity _ (Main) -Rule fired: SPEC/Main $fFunctorStateT @Identity _ (Main) -Rule fired: SPEC/Main $fFunctorStateT_$cfmap @Identity _ (Main) -Rule fired: Class op fmap (BUILTIN) -Rule fired: SPEC/Main $fFunctorStateT_$cfmap @Identity _ (Main) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) Rule fired: Class op >>= (BUILTIN) +Rule fired: SC:$wgo90 (Main) Rule fired: Class op return (BUILTIN) Rule fired: Class op >>= (BUILTIN) Rule fired: Class op >>= (BUILTIN) Rule fired: Class op return (BUILTIN) +Rule fired: SC:$wgo90 (Main) +Rule fired: Class op fmap (BUILTIN) +Rule fired: Class op fmap (BUILTIN) +Rule fired: SPEC $s$wgo9 (Main) +Rule fired: SPEC $s$wgo9 (Main) +Rule fired: SPEC $s$wgo9 (Main) ===================================== testsuite/tests/printer/T18052a.stderr ===================================== @@ -20,7 +20,7 @@ T18052a.$b:||: = \ (@a) (@b) (x :: a) (y :: b) -> (x, y) -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} (+++) :: forall {a}. [a] -> [a] -> [a] [GblId] -(+++) = (++) +(+++) = ++ -- RHS size: {terms: 13, types: 20, coercions: 0, joins: 0/0} T18052a.$m:||: ===================================== testsuite/tests/simplCore/should_compile/T17966.stdout ===================================== @@ -1,5 +1,2 @@ RULES: "SPEC $cm @()" [0] RULES: "SPEC f @Bool @() @(Maybe Integer)" [0] -"SPEC/T17966 $fShowMaybe_$cshow @Integer" -"SPEC/T17966 $fShowMaybe_$cshowList @Integer" -"SPEC/T17966 $fShowMaybe @Integer" ===================================== testsuite/tests/stranal/should_compile/T18122.stderr ===================================== @@ -13,9 +13,8 @@ Lib.$trModule4 = "main"# -- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} Lib.$trModule3 :: GHC.Types.TrName [GblId, - Cpr=m1, Unf=Unf{Src=, TopLvl=True, Value=True, ConLike=True, - WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 20}] + WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] Lib.$trModule3 = GHC.Types.TrNameS Lib.$trModule4 -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} @@ -28,27 +27,25 @@ Lib.$trModule2 = "Lib"# -- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} Lib.$trModule1 :: GHC.Types.TrName [GblId, - Cpr=m1, Unf=Unf{Src=, TopLvl=True, Value=True, ConLike=True, - WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 20}] + WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] Lib.$trModule1 = GHC.Types.TrNameS Lib.$trModule2 -- RHS size: {terms: 3, types: 0, coercions: 0, joins: 0/0} Lib.$trModule :: GHC.Types.Module [GblId, - Cpr=m1, Unf=Unf{Src=, TopLvl=True, Value=True, ConLike=True, - WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 30}] + WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] Lib.$trModule = GHC.Types.Module Lib.$trModule3 Lib.$trModule1 -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} Lib.$wfoo [InlPrag=NOINLINE] :: GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int# [GblId, Arity=2, Str=, Unf=OtherCon []] -Lib.$wfoo = (GHC.Prim.+#) +Lib.$wfoo = GHC.Prim.+# -- RHS size: {terms: 18, types: 14, coercions: 0, joins: 0/0} -foo [InlPrag=NOUSERINLINE[0]] :: (Int, Int) -> Int -> Int +foo [InlPrag=NOUSERINLINE[final]] :: (Int, Int) -> Int -> Int [GblId, Arity=2, Str=, @@ -56,24 +53,25 @@ foo [InlPrag=NOUSERINLINE[0]] :: (Int, Int) -> Int -> Int Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=2,unsat_ok=True,boring_ok=False) - Tmpl= \ (w_sHs [Occ=Once!] :: (Int, Int)) - (w1_sHt [Occ=Once!] :: Int) -> - case w_sHs of { (ww1_sHw [Occ=Once!], _ [Occ=Dead]) -> - case ww1_sHw of { GHC.Types.I# ww4_sHz [Occ=Once] -> - case w1_sHt of { GHC.Types.I# ww6_sHF [Occ=Once] -> - case Lib.$wfoo ww4_sHz ww6_sHF of ww7_sHJ [Occ=Once] { __DEFAULT -> - GHC.Types.I# ww7_sHJ + Tmpl= \ (w_sEf [Occ=Once1!] :: (Int, Int)) + (w1_sEg [Occ=Once1!] :: Int) -> + case w_sEf of { (ww1_sEj [Occ=Once1!], _ [Occ=Dead]) -> + case ww1_sEj of { GHC.Types.I# ww4_sEm [Occ=Once1] -> + case w1_sEg of { GHC.Types.I# ww6_sEs [Occ=Once1] -> + case Lib.$wfoo ww4_sEm ww6_sEs of ww7_sEw [Occ=Once1] + { __DEFAULT -> + GHC.Types.I# ww7_sEw } } } }}] foo - = \ (w_sHs :: (Int, Int)) (w1_sHt :: Int) -> - case w_sHs of { (ww1_sHw, ww2_sHB) -> - case ww1_sHw of { GHC.Types.I# ww4_sHz -> - case w1_sHt of { GHC.Types.I# ww6_sHF -> - case Lib.$wfoo ww4_sHz ww6_sHF of ww7_sHJ { __DEFAULT -> - GHC.Types.I# ww7_sHJ + = \ (w_sEf :: (Int, Int)) (w1_sEg :: Int) -> + case w_sEf of { (ww1_sEj, ww2_sEo) -> + case ww1_sEj of { GHC.Types.I# ww4_sEm -> + case w1_sEg of { GHC.Types.I# ww6_sEs -> + case Lib.$wfoo ww4_sEm ww6_sEs of ww7_sEw { __DEFAULT -> + GHC.Types.I# ww7_sEw } } } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e3c76de3eb2a09d78ebc14cc5c11b667b69c5807 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e3c76de3eb2a09d78ebc14cc5c11b667b69c5807 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 12:09:52 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 25 Aug 2020 08:09:52 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 6 commits: SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' Message-ID: <5f44ff90de02a_80b3f84693c1eb4940351@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 0a1ecc5f by Ben Gamari at 2020-08-25T07:37:05-04:00 SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' In #18069 we are observing MVar deadlocks from somewhere in ghc.exe. This use of MVar stood out as being one of the more likely culprits. Here we make sure that it is exception-safe. - - - - - db8793ad by Richard Eisenberg at 2020-08-25T07:37:40-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - fb77207a by Simon Peyton Jones at 2020-08-25T07:38:16-04:00 Use LIdP rather than (XRec p (IdP p)) This patch mainly just replaces use of XRec p (IdP p) with LIdP p One slightly more significant change is to parameterise HsPatSynDetails over the pass rather than the argument type, so that it's uniform with HsConDeclDetails and HsConPatDetails. I also got rid of the dead code GHC.Hs.type.conDetailsArgs But this is all just minor refactoring. No change in functionality. - - - - - 8426a136 by Krzysztof Gogolewski at 2020-08-25T07:38:54-04:00 Add a test for #18585 - - - - - 33638af3 by Sylvain Henry at 2020-08-25T08:09:42-04:00 Refactor UnitId pretty-printing When we pretty-print a UnitId for the user, we try to map it back to its origin package name, version and component to print "package-version:component" instead of some hash. The UnitId type doesn't carry these information, so we have to look into a UnitState to find them. This is why the Outputable instance of UnitId used `sdocWithDynFlags` in order to access the `unitState` field of DynFlags. This is wrong for several reasons: 1. The DynFlags are accessed when the message is printed, not when it is generated. So we could imagine that the unitState may have changed in-between. Especially if we want to allow unit unloading. 2. We want GHC to support several independent sessions at once, hence several UnitState. The current approach supposes there is a unique UnitState as a UnitId doesn't indicate which UnitState to use. See the Note [Pretty-printing UnitId] in GHC.Unit for the new approach implemented by this patch. One step closer to remove `sdocDynFlags` field from `SDocContext` (#10143). Fix #18124. Also fix some Backpack code to use SDoc instead of String. - - - - - cf4da265 by Sylvain Henry at 2020-08-25T08:09:44-04:00 Bignum: fix BigNat subtraction (#18604) There was a confusion between the boolean expected by withNewWordArrayTrimedMaybe and the boolean returned by subtracting functions. - - - - - 30 changed files: - compiler/GHC.hs - compiler/GHC/Core/Type.hs - compiler/GHC/Core/Unify.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Driver/Finder.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Extension.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/Match/Constructor.hs - compiler/GHC/HsToCore/Quote.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/Parser.y - compiler/GHC/Runtime/Eval.hs - compiler/GHC/SysTools/Process.hs - compiler/GHC/Tc/Module.hs - compiler/GHC/Tc/TyCl/PatSyn.hs - compiler/GHC/Tc/Utils/Backpack.hs - compiler/GHC/Tc/Utils/Instantiate.hs - compiler/GHC/Tc/Utils/Monad.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b37114051fbc489d32cf7bc72b18950e30a676fb...cf4da2653a68209e13d8efe39f6e644b8a4ddb89 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b37114051fbc489d32cf7bc72b18950e30a676fb...cf4da2653a68209e13d8efe39f6e644b8a4ddb89 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 12:48:02 2020 From: gitlab at gitlab.haskell.org (Andreas Klebinger) Date: Tue, 25 Aug 2020 08:48:02 -0400 Subject: [Git][ghc/ghc][wip/andreask/dom-lt-fixes] Whitespace in front of ! operator Message-ID: <5f4508821923f_80b3f846a81b61c9419729@gitlab.haskell.org.mail> Andreas Klebinger pushed to branch wip/andreask/dom-lt-fixes at Glasgow Haskell Compiler / GHC Commits: fa115f2a by Andreas Klebinger at 2020-08-25T14:47:51+02:00 Whitespace in front of ! operator - - - - - 1 changed file: - compiler/GHC/CmmToAsm/CFG/Dominators.hs Changes: ===================================== compiler/GHC/CmmToAsm/CFG/Dominators.hs ===================================== @@ -364,11 +364,11 @@ domM = fetch domE rootM :: Dom s Node rootM = gets rootE succsM :: Node -> Dom s [Node] -succsM i = gets (IS.toList . (!i) . succE) +succsM i = gets (IS.toList . (! i) . succE) predsM :: Node -> Dom s [Node] -predsM i = gets (IS.toList . (!i) . predE) +predsM i = gets (IS.toList . (! i) . predE) bucketM :: Node -> Dom s [Node] -bucketM i = gets (IS.toList . (!i) . bucketE) +bucketM i = gets (IS.toList . (! i) . bucketE) sizeM :: Node -> Dom s Int sizeM = fetch sizeE sdnoM :: Node -> Dom s Int View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fa115f2a88adfd16eddeda68ca08860d2bb4f343 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fa115f2a88adfd16eddeda68ca08860d2bb4f343 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 12:57:12 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Tue, 25 Aug 2020 08:57:12 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/happy-1.20 Message-ID: <5f450aa8d9a78_80b3f84868578949422363@gitlab.haskell.org.mail> Vladislav Zavialov pushed new branch wip/happy-1.20 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/happy-1.20 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 13:22:50 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Tue, 25 Aug 2020 09:22:50 -0400 Subject: [Git][ghc/ghc][wip/T18126] 3 commits: Implement Quick Look impredicativity Message-ID: <5f4510aade2d9_80b3f842731681c94287cc@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18126 at Glasgow Haskell Compiler / GHC Commits: 375a51c9 by Simon Peyton Jones at 2020-08-25T14:20:41+01:00 Implement Quick Look impredicativity This patch implements Quick Look impredicativity (#18126), sticking very closely to the design in A quick look at impredicativity, Serrano et al, ICFP 2020 The main change is that a big chunk of GHC.Tc.Gen.Expr has been extracted to two new modules GHC.Tc.Gen.App GHC.Tc.Gen.Head which deal with typechecking n-ary applications, and the head of such applications, respectively. Both contain a good deal of documentation. Three other loosely-related changes are in this patch: * I implemented (partly by accident) point (2) of the accepted GHC proposal "Clean up printing of foralls", namely https://github.com/ghc-proposals/ghc-proposals/blob/ master/proposals/0179-printing-foralls.rst In particular, see Note [TcRnExprMode] in GHC.Tc.Module - :type instantiates /inferred/, but not /specified/, quantifiers - :type +d instantiates /all/ quantifiers - :type +v is killed off * HsRecFld (which the renamer introduces for record field selectors), is now preserved by the typechecker, rather than being rewritten back to HsVar. This is more uniform, and turned out to be more convenient in the new scheme of things. * The GHCi debugger uses a non-standard unification that allows the unification variables to unify with polytypes. We used to hack this by using ImpredicativeTypes, but that doesn't work anymore so I introduces RuntimeUnkTv. See Note [RuntimeUnkTv] in GHC.Runtime.Heap.Inspect WARNING: this patch won't validate on its own. It was too hard to fully disentangle it from the following patch, on type errors and kind generalisation. Changes to tests * Fixes #9730 (test added) * Fixes #7026 (test added) * Fixes most of #8808, except function `g2'` which uses a section (which doesn't play with QL yet -- see #18126) Test added * Fixes #1330. NB Church1.hs subsumes Church2.hs, which is now deleted * Fixes #17332 (test added) * Fixes #4295 * This patch makes typecheck/should_run/T7861 fail. But that turns out to be a pre-existing bug: #18467. So I have just made T7861 into expect_broken(18467) - - - - - c87c7331 by Simon Peyton Jones at 2020-08-25T14:20:41+01:00 Improve kind generalisation, error messages This patch does two things: * It refactors GHC.Tc.Errors a bit. In debugging Quick Look I was forced to look in detail at error messages, and ended up doing a bit of refactoring, esp in mkTyVarEqErr'. It's still quite a mess, but a bit better, I think. * It makes a significant improvement to the kind checking of type and class declarations. Specifically, we now ensure that if kind checking fails with an unsolved constraint, all the skolems are in scope. That wasn't the case before, which led to some obscure error messages; and occasional failures with "no skolem info" (eg #16245). Both of these, and the main Quick Look patch itself, affect a /lot/ of error messages, as you can see from the number of files changed. I've checked them all; I think they are as good or better than before. Smaller things * I documented the various instances of VarBndr better. See Note [The VarBndr tyep and its uses] in GHC.Types.Var * Renamed GHC.Tc.Solver.simpl_top to simplifyTopWanteds * A bit of refactoring in bindExplicitTKTele, to avoid the footwork with Either. Simpler now. * Move promoteTyVar from GHC.Tc.Solver to GHC.Tc.Utils.TcMType Fixes #16245 (comment 211369), memorialised as typeecheck/polykinds/T16245a - - - - - f9f6ba7e by GHC GitLab CI at 2020-08-25T14:22:15+01:00 Bump haddock submodule Accounts for spurious changes in the output of hypsrc-test. - - - - - 19 changed files: - compiler/GHC/Core/TyCon.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/HsToCore/Coverage.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/Iface/Ext/Ast.hs - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Rename/Pat.hs - compiler/GHC/Runtime/Eval.hs - compiler/GHC/Runtime/Heap/Inspect.hs - compiler/GHC/Tc/Deriv/Generate.hs - compiler/GHC/Tc/Errors.hs - compiler/GHC/Tc/Errors/Hole.hs - + compiler/GHC/Tc/Gen/App.hs - compiler/GHC/Tc/Gen/Arrow.hs - compiler/GHC/Tc/Gen/Default.hs - compiler/GHC/Tc/Gen/Expr.hs - compiler/GHC/Tc/Gen/Expr.hs-boot The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e074f1bd5cab5796a093d1861fcbdf1974195f6e...f9f6ba7e02a5d8a0e5809eea2566df1e3943e8fa -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e074f1bd5cab5796a093d1861fcbdf1974195f6e...f9f6ba7e02a5d8a0e5809eea2566df1e3943e8fa You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 14:09:14 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 25 Aug 2020 10:09:14 -0400 Subject: [Git][ghc/ghc][wip/ci-fixes] 18 commits: gitlab-ci: Test master branch as well Message-ID: <5f451b8a573cf_80b3f8486857894943384e@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/ci-fixes at Glasgow Haskell Compiler / GHC Commits: 989c1c27 by Ben Gamari at 2020-08-21T11:27:53-04:00 gitlab-ci: Test master branch as well While these builds are strictly speaking redundant (since every commit is tested by @marge-bot before making it into `master`), they are nevertheless useful as they are displayed in the branch's commit list in GitLab's web interface. Fixes #18595. - - - - - e67ae884 by Aditya Gupta at 2020-08-22T03:29:00-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - 03cfcfd4 by Wander Hillen at 2020-08-22T03:29:36-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 3f501545 by Craig Ferguson at 2020-08-22T03:30:13-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 8b865092 by Krzysztof Gogolewski at 2020-08-23T14:12:53+02:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - d8f61182 by Krzysztof Gogolewski at 2020-08-23T14:12:56+02:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - 364258e0 by Krzysztof Gogolewski at 2020-08-24T00:32:31-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - b1eb38a0 by Sylvain Henry at 2020-08-24T00:33:13-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 1213fd87 by Ben Gamari at 2020-08-25T10:09:08-04:00 configure: Fix whitespace - - - - - bbad97c9 by Ben Gamari at 2020-08-25T10:09:08-04:00 gitlab-ci: More intelligent detection of locale availability Previously ci.sh would unconditionally use C.UTF-8. However, this fails on Centos 7, which appears not to provide this locale. Now we first try C.UTF-8, then try en_US.UTF-8, then fail. Works around #18607. - - - - - edacc510 by Ben Gamari at 2020-08-25T10:09:08-04:00 gitlab-ci: Rename RELEASE variable to RELEASE_JOB This interfered with the autoconf variable of the same name, breaking pre-release builds. - - - - - d92c6a5b by Ben Gamari at 2020-08-25T10:09:08-04:00 gitlab-ci: Bump Windows toolchain version This should have been done when we bumped the bootstrap compiler to 8.8.4. - - - - - 00493b29 by Ben Gamari at 2020-08-25T10:09:08-04:00 gitlab-ci: Drop Windows make job These are a significant burden on our CI resources and end up failing quite often due to #18274. Here I drop the make jobs during validaion; it is now run only during the nightly builds. - - - - - 6083e6a9 by Ben Gamari at 2020-08-25T10:09:08-04:00 testsuite: Drop Windows-specific output for parseTree The normalise_slashes normaliser should handle this. - - - - - 43c013d4 by Ben Gamari at 2020-08-25T10:09:08-04:00 testsuite: Mark T5975[ab] as broken on Windows Due to #7305. - - - - - 015afc46 by Ben Gamari at 2020-08-25T10:09:09-04:00 gitlab-ci: Fix typo A small typo in a rule regular expression. - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - aclocal.m4 - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Reg/Graph/Base.hs - compiler/GHC/CmmToAsm/Reg/Graph/SpillClean.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Core/DataCon.hs-boot - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/ConstantFold.hs - compiler/GHC/Core/Opt/Exitify.hs - compiler/GHC/Core/Opt/Monad.hs - compiler/GHC/Core/TyCon.hs - compiler/GHC/Core/TyCon.hs-boot - compiler/GHC/CoreToByteCode.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Iface/Ext/Ast.hs - compiler/GHC/Iface/Syntax.hs - compiler/GHC/Iface/Type.hs - compiler/GHC/Platform/Reg.hs - compiler/GHC/Platform/Reg/Class.hs - compiler/GHC/Stg/Pipeline.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/af50e339d67db1af40bc30164c3062d49ac47446...015afc46003f346502d65ecda44e84235bc98126 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/af50e339d67db1af40bc30164c3062d49ac47446...015afc46003f346502d65ecda44e84235bc98126 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 15:04:25 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Tue, 25 Aug 2020 11:04:25 -0400 Subject: [Git][ghc/ghc][wip/happy-1.20] Require happy >=1.20 Message-ID: <5f452879780e9_80b3f84a401c3dc94430fa@gitlab.haskell.org.mail> Vladislav Zavialov pushed to branch wip/happy-1.20 at Glasgow Haskell Compiler / GHC Commits: 253ee6c8 by Vladislav Zavialov at 2020-08-25T18:03:49+03:00 Require happy >=1.20 - - - - - 3 changed files: - aclocal.m4 - hadrian/cabal.project - hadrian/hadrian.cabal Changes: ===================================== aclocal.m4 ===================================== @@ -1021,8 +1021,8 @@ changequote([, ])dnl ]) if test ! -f compiler/GHC/Parser.hs || test ! -f compiler/GHC/Cmm/Parser.hs then - FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.19.10], - [AC_MSG_ERROR([Happy version 1.19.10 or later is required to compile GHC.])])[] + FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.20.0], + [AC_MSG_ERROR([Happy version 1.20.0 or later is required to compile GHC.])])[] fi HappyVersion=$fptools_cv_happy_version; AC_SUBST(HappyVersion) ===================================== hadrian/cabal.project ===================================== @@ -1,7 +1,7 @@ packages: ./ -- This essentially freezes the build plan for hadrian -index-state: 2020-06-16T03:59:14Z +index-state: 2020-08-25T12:30:13Z -- N.B. Compile with -O0 since this is not a performance-critical executable -- and the Cabal takes nearly twice as long to build with -O1. See #16817. ===================================== hadrian/hadrian.cabal ===================================== @@ -148,7 +148,7 @@ executable hadrian , transformers >= 0.4 && < 0.6 , unordered-containers >= 0.2.1 && < 0.3 build-tools: alex >= 3.1 - , happy >= 1.19.10 + , happy >= 1.20.0 ghc-options: -Wall -Wincomplete-record-updates -Wredundant-constraints View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/253ee6c8f9c26c423e782d7077821f37e4b6b42a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/253ee6c8f9c26c423e782d7077821f37e4b6b42a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 15:19:08 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Tue, 25 Aug 2020 11:19:08 -0400 Subject: [Git][ghc/ghc][wip/parsing-shift] 1838 commits: Hadrian: Libffi rule now `produces` dynamic library files. Message-ID: <5f452becd9b0d_80b3f84868578949443438@gitlab.haskell.org.mail> Vladislav Zavialov pushed to branch wip/parsing-shift at Glasgow Haskell Compiler / GHC Commits: 9a27a063 by David Eichmann at 2019-10-01T16:55:33-04:00 Hadrian: Libffi rule now `produces` dynamic library files. - - - - - 0956c194 by David Eichmann at 2019-10-01T16:55:33-04:00 Hadrian: do not cache GHC configure rule - - - - - 8924224e by Ömer Sinan Ağacan at 2019-10-01T16:55:37-04:00 Make small INLINE functions behave properly Simon writes: Currently we check for a type arg rather than isTyCoArg. This in turn makes INLINE things look bigger than they should be, and stops them being inlined into boring contexts when they perfectly well could be. E.g. f x = g <refl> x {-# INLINE g #-} ... (map (f x) xs) ... The context is boring, so don't inline unconditionally. But f's RHS is no bigger than its call, provided you realise that the coercion argument is ultimately cost-free. This happens in practice for $WHRefl. It's not a big deal: at most it means we have an extra function call overhead. But it's untidy, and actually worse than what happens without an INLINE pragma. Fixes #17182 This makes 0.0% change in nofib binary sizes. - - - - - 53b0c6e0 by Gabor Greif at 2019-10-03T08:15:50-04:00 Typo in comment [ci skip] - - - - - 60229e9e by Ryan Scott at 2019-10-03T12:17:10-04:00 Merge TcTypeableValidity into TcTypeable, document treatment of casts This patch: * Implements a refactoring (suggested in https://gitlab.haskell.org/ghc/ghc/merge_requests/1199#note_207345) that moves all functions from `TcTypeableValidity` back to `TcTypeable`, as the former module doesn't really need to live on its own. * Adds `Note [Typeable instances for casted types]` to `TcTypeable` explaining why the `Typeable` solver currently does not support types containing casts. Resolves #16835. - - - - - 3b9d4907 by Richard Eisenberg at 2019-10-03T12:17:13-04:00 Note [Don't flatten tuples from HsSyn] in MkCore Previously, we would sometimes flatten 1-tuples and sometimes not. This didn't cause damage because there is no way to generate HsSyn with 1-tuples. But, with the upcoming fix to #16881, there will be. Without this patch, obscure lint errors would have resulted. No test case, as there is not yet a way to tickle this. - - - - - 8a254d6b by Ömer Sinan Ağacan at 2019-10-03T12:17:19-04:00 Fix new compact block allocation in allocateForCompact allocateForCompact() is called when nursery of a compact region is full, to add new blocks to the compact. New blocks added to an existing region needs a StgCompactNFDataBlock header, not a StgCompactNFData. This fixes allocateForCompact() so that it now correctly allocates space for StgCompactNFDataBlock instead of StgCompactNFData as before. Fixes #17044. A regression test T17044 added. - - - - - 3c7b172b by James Brock at 2019-10-03T12:17:24-04:00 docs String, hyperlink to Data.List Add a reference to the documentation for Data.List in the description for String. On the generated Haddock for Data.String, http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-String.html there is curently no hyperlink to Data.List, which is where a reader will find most of the useful functions which can operate on Strings. I imagine this has confused beginners who came to this page looking for String operations. - - - - - 67bf734c by John Ericson at 2019-10-03T12:17:28-04:00 Add `module {-# SOURCE #-} Foo` syntax for hs-boot in bkp This is a good convenience for testing. - - - - - 6655ec73 by Richard Eisenberg at 2019-10-03T12:17:30-04:00 Improve documentation around empty tuples/lists This patch also changes the way we handle empty lists, simplifying them somewhat. See Note [Empty lists]. Previously, we had to special-case empty lists in the type-checker. Now no more! Finally, this patch improves some documentation around the ir_inst field used in the type-checker. This breaks a test case, but I really think the problem is #17251, not really related to this patch. Test case: typecheck/should_compile/T13680 - - - - - 9a4ff210 by John Ericson at 2019-10-03T12:17:31-04:00 Make Haddock submodule remote point to gitlab mirror This makes it match the others - - - - - cb364bc2 by Ben Gamari at 2019-10-03T12:17:32-04:00 testsuite: Mark print037 as fragile, not broken See #16205. - - - - - 259f4dff by Ben Gamari at 2019-10-03T12:17:32-04:00 Exclude rts.cabal from source distributions This modifies both the Hadrian and make build systems to avoid included the rts.cabal generated by autoconf in the source distribution. Fixes #17265. - - - - - e4c93896 by Ben Gamari at 2019-10-03T12:17:32-04:00 DynFlags: Only warn when split-sections is ignored Previously we would throw an error which seems a bit harsh. As reported in #17283. - - - - - ee6324ad by Tobias Guggenmos at 2019-10-03T12:17:33-04:00 Improve documentation for runtime debugging flags - - - - - 47386fe8 by Tobias Guggenmos at 2019-10-03T12:17:33-04:00 Add new debug flag -DZ Zeros heap memory after gc freed it. - - - - - d0924b15 by Stefan Schulze Frielinghaus at 2019-10-03T12:17:34-04:00 Extend argument of createIOThread to word size Function createIOThread expects its second argument to be of size word. The natural size of the second parameter is 32bits. Thus for some 64bit architectures, where a write of the lower half of a register does not clear the upper half, the value must be zero extended. - - - - - 1357d023 by Ben Gamari at 2019-10-03T12:17:34-04:00 rules/haddock: Ensure that RTS stats directory exists It may not exist if the source tarball was extracted yet not the testsuite tarball. - - - - - ec93d2a9 by Fumiaki Kinoshita at 2019-10-04T21:43:49-04:00 Add Monad instances to `(,,) a b` and `(,,,) a b c` - - - - - 05419e55 by John Ericson at 2019-10-04T21:44:29-04:00 Per stage headers, ghc_boot_platform.h -> stage 0 ghcplatform.h The generated headers are now generated per stage, which means we can skip hacks like `ghc_boot_platform.h` and just have that be the stage 0 header as proper. In general, stages are to be embraced: freely generate everything in each stage but then just build what you depend on, and everything is symmetrical and efficient. Trying to avoid stages because bootstrapping is a mind bender just creates tons of bespoke mini-mind-benders that add up to something far crazier. Hadrian was pretty close to this "stage-major" approach already, and so was fairly easy to fix. Make needed more work, however: it did know about stages so at least there was a scaffold, but few packages except for the compiler cared, and the compiler used its own counting system. That said, make and Hadrian now work more similarly, which is good for the transition to Hadrian. The merits of embracing stage aside, the change may be worthy for easing that transition alone. - - - - - 75a5dd8e by John Ericson at 2019-10-04T21:44:29-04:00 Remove {Build,Host}Platform_NAME from header They are only used in a file we construct directly, so just skip CPP. - - - - - b538476b by Daroc Alden at 2019-10-04T21:45:09-04:00 Deprecate -fwarn-hi-shadowing, because it was never implemented and is not used. This fixes #10913. - - - - - dd8f76b2 by John Ericson at 2019-10-04T21:45:48-04:00 Factor out a smaller part of Platform for host fallback - - - - - d15b44d6 by John Ericson at 2019-10-04T21:45:49-04:00 Pull out the settings file parsing code into it's own module. This has two benefits: 1. One less hunk of code dependent on DynFlags 2. Add a little bit of error granularity to distrinugish between missing data and bad data. This could someday be shared with ghc-pkg which aims to work even with a missing file. I also am about to to make --supported-extensions use this too. - - - - - eb892b28 by John Ericson at 2019-10-04T21:45:49-04:00 Add tryFindTopDir to look for the top dir without blowing up if it is not found. - - - - - 0dded5ec by John Ericson at 2019-10-04T21:45:49-04:00 Always enable the external interpreter You can always just not use or even build `iserv`. I don't think the maintenance cost of the CPP is worth...I can't even tell what the benefit is. - - - - - 0d31ccdd by Artem Pyanykh at 2019-10-04T21:46:28-04:00 [linker, macho] Don't map/allocate zero size sections and segments Zero size sections are common even during regular build on MacOS. For instance: ``` $ ar -xv libHSghc-prim-0.6.1.a longlong.o $ otool -l longlong.o longlong.o: Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags 0xfeedfacf 16777223 3 0x00 1 2 176 0x00002000 Load command 0 cmd LC_SEGMENT_64 cmdsize 152 segname vmaddr 0x0000000000000000 vmsize 0x0000000000000000 <-- segment size = 0 fileoff 208 filesize 0 maxprot 0x00000007 initprot 0x00000007 nsects 1 flags 0x0 Section sectname __text segname __TEXT addr 0x0000000000000000 size 0x0000000000000000 <-- section size = 0 offset 208 align 2^0 (1) reloff 0 nreloc 0 flags 0x80000000 reserved1 0 reserved2 0 cmd LC_BUILD_VERSION cmdsize 24 platform macos sdk 10.14 minos 10.14 ntools 0 ``` The issue of `mmap`ing 0 bytes was resolved in !1050, but the problem remained. These 0 size segments and sections were still allocated in object code, which lead to failed `ASSERT(size > 0)` in `addProddableBlock` further down the road. With this change zero size segments **and** sections are not mapped/allocated at all. Test plan: 1. Build statically linked GHC. 2. Run `ghc --interactive`. Observe that REPL loads successfully (which was not the case before). 3. Load several more compiled hs files into repl. No failures. - - - - - 93f02b62 by Roland Senn at 2019-10-04T21:47:07-04:00 New fix for #11647. Avoid side effects like #17171 If a main module doesn't contain a header, we omit the check whether the main module is exported. With this patch GHC, GHCi and runghc use the same code. - - - - - 8039b625 by Matthew Bauer at 2019-10-04T21:47:47-04:00 Add musl systems to llvm-targets This was done in Nixpkgs, but never upstreamed. Musl is pretty much the same as gnu, but with a different libc. I’ve used the same values for everything. - - - - - ee8118ca by John Ericson at 2019-10-05T00:11:58-04:00 Clean up `#include`s in the compiler - Remove unneeded ones - Use <..> for inter-package. Besides general clean up, helps distinguish between the RTS we link against vs the RTS we compile for. - - - - - 241921a0 by Ben Gamari at 2019-10-05T19:18:40-04:00 rts: Fix CNF dirtying logic Previously due to a silly implementation bug CNFs would never have their dirty flag set, resulting in their being added again and again to the `mut_list`. Fix this. Fixes #17297. - - - - - 825c108b by Ryan Scott at 2019-10-07T12:00:59-04:00 Only flatten up to type family arity in coreFlattenTyFamApp (#16995) Among other uses, `coreFlattenTyFamApp` is used by Core Lint as a part of its check to ensure that each type family axiom reduces according to the way it is defined in the source code. Unfortunately, the logic that `coreFlattenTyFamApp` uses to flatten type family applications disagreed with the logic in `TcFlatten`, which caused it to spuriously complain this program: ```hs type family Param :: Type -> Type type family LookupParam (a :: Type) :: Type where LookupParam (f Char) = Bool LookupParam x = Int foo :: LookupParam (Param ()) foo = 42 ``` This is because `coreFlattenTyFamApp` tries to flatten the `Param ()` in `LookupParam (Param ())` to `alpha` (where `alpha` is a flattening skolem), and GHC is unable to conclude that `alpha` is apart from `f Char`. This patch spruces up `coreFlattenTyFamApp` so that it instead flattens `Param ()` to `alpha ()`, which GHC _can_ know for sure is apart from `f Char`. See `Note [Flatten], wrinkle 3` in `FamInstEnv`. - - - - - b2577081 by Ben Gamari at 2019-10-07T12:01:46-04:00 Refactor, document, and optimize LLVM configuration loading As described in the new Note [LLVM Configuration] in SysTools, we now load llvm-targets and llvm-passes lazily to avoid the overhead of doing so when -fllvm isn't used (also known as "the common case"). Noticed in #17003. Metric Decrease: T12234 T12150 - - - - - 93c71ae6 by Ben Gamari at 2019-10-07T12:02:23-04:00 configure: Determine library versions of template-haskell, et al. These are needed by the user guide documentation. Fixes #17260. - - - - - b7890611 by Andrey Mokhov at 2019-10-07T12:03:13-04:00 Hadrian: Stop using in-tree Cabal - - - - - 0ceb98f6 by Andrey Mokhov at 2019-10-07T12:03:13-04:00 Switch to cabal-version=3.0 in ghc-heap.cabal - - - - - e3418e96 by Andrey Mokhov at 2019-10-07T12:03:13-04:00 Switch to cabal-version=3.0 in base.cabal and rts.cabal - - - - - 805653f6 by John Ericson at 2019-10-07T12:04:19-04:00 Get rid of wildcard patterns in prim Cmm emitting code This way, we can be sure we don't miss a case. - - - - - ab945819 by Ryan Scott at 2019-10-07T12:05:09-04:00 Refactor some cruft in TcGenGenerics * `foldBal` contains needless partiality that can easily be avoided. * `mkProd_E` and `mkProd_P` both contain unique supply arguments that are completely unused, which can be removed. - - - - - d0edba3a by John Ericson at 2019-10-07T12:05:47-04:00 Remove CONFIGURE_ARGS from configure.ac It looks like it's been unused since at least 34cc75e1a62638f2833815746ebce0a9114dc26b. - - - - - 9a6bfb0a by John Ericson at 2019-10-07T12:06:26-04:00 Keep OSTYPE local to configure.ac Unused outside it since b6be81b841e34ca45b3549c4c79e886a8761e59a. - - - - - 4df39fd0 by John Ericson at 2019-10-07T12:07:08-04:00 Get rid of GHC_PACKAGE_DB_FLAG We no longer support booting from older GHC since 527bcc41630918977c73584d99125ff164400695. - - - - - 31a29a7a by John Ericson at 2019-10-07T12:07:46-04:00 Remove GhcLibsWithUnix d679ca43e7477284d733b94ff542be5363be3353 meant to remove it but did not finish the job. - - - - - 77ca39e3 by Ben Gamari at 2019-10-08T05:11:03-04:00 gitlab-ci: Add missing TEST_ENV variables This should fix #16985. - - - - - 9a2798e1 by Ben Gamari at 2019-10-08T05:11:03-04:00 hadrian: Add `validate` and `slow validate` flavours - - - - - ab311696 by Ben Gamari at 2019-10-08T05:11:03-04:00 validate: Use Hadrian's validate flavour - - - - - 98179a77 by Ben Gamari at 2019-10-08T05:11:03-04:00 gitlab-ci: Use validate flavour in hadrian builds - - - - - 8af9eba8 by Ben Gamari at 2019-10-08T05:11:40-04:00 base: Document the fact that Typeable is automatically "derived" This fixes #17060. - - - - - 397c6ed5 by Sebastian Graf at 2019-10-08T05:12:15-04:00 PmCheck: Identify some semantically equivalent expressions By introducing a `CoreMap Id` to the term oracle, we can represent syntactically equivalent expressions by the same `Id`. Combine that with `CoreOpt.simpleCoreExpr` and it might even catch non-trivial semantic equalities. Unfortunately due to scoping issues, this will not solve #17208 for view patterns yet. - - - - - 8a2e8408 by Ben Gamari at 2019-10-08T05:12:58-04:00 users-guide: Refer to language extension flags via :extension: Previously several were referred to via :ghc-flag:`-X...`. - - - - - 7cd54538 by Ben Gamari at 2019-10-08T05:12:58-04:00 users-guide: Make reverse flags addressable via :ghc-flag: Previously one could not easily link to the :reverse: flag of a ghc-flag. - - - - - e9813afc by Ben Gamari at 2019-10-08T05:12:58-04:00 users-guide: Document -XHaskell98 and -XHaskell2010 - - - - - eaeb28a1 by Ben Gamari at 2019-10-08T05:12:58-04:00 users-guide: Fix various warnings - - - - - 180cf177 by Ben Gamari at 2019-10-08T05:12:58-04:00 users-guide: Document NondecreasingIndentation - - - - - 0a26f9e8 by Ben Gamari at 2019-10-08T05:12:58-04:00 users-guide: Document -fworker-wrapper - - - - - ca4791db by Ben Gamari at 2019-10-08T05:12:58-04:00 users-guide: Rework pragma key generation Previously we had a hack to handle the case of multi-token SPECIALISE pragmas. Now we use a slightly more general rule of using a prefix of tokens containing only alphabetical characters. - - - - - 98c09422 by Ben Gamari at 2019-10-08T05:12:58-04:00 users-guide: Run sphinx in nit-picky mode This ensure that it blurts an error on missing references. - - - - - a95f7185 by Ben Gamari at 2019-10-08T05:12:58-04:00 doc: Write out documented flag list - - - - - 9402608e by Ben Gamari at 2019-10-08T05:12:58-04:00 gitlab-ci: Check coverage of GHC flags in users guide This ensures that all GHC flags are documented during the documentation build. Fixes #17315. - - - - - 9ac3bcbb by Andrew Martin at 2019-10-08T13:24:52-04:00 Document the UnliftedFFITypes extension. - - - - - 77f3ba23 by Andrew Martin at 2019-10-08T13:24:52-04:00 Rephrase a bunch of things in the unlifted ffi types documentation. Add a section on pinned byte arrays. - - - - - a70db7bf by Andrew Martin at 2019-10-08T13:24:52-04:00 [skip ci] link to foreign cmm call - - - - - 0d413259 by Andrew Martin at 2019-10-08T13:24:52-04:00 [skip ci] make the table better - - - - - 0c7a5bcd by Andrew Martin at 2019-10-08T13:24:52-04:00 [skip ci] can not -> may not - - - - - 6a5c249d by Andrew Martin at 2019-10-08T13:24:52-04:00 [skip ci] clarify what unsound means - - - - - bf02c264 by Ryan Scott at 2019-10-08T13:25:37-04:00 Mark newtype constructors as used in the Coercible solver (#10347) Currently, newtype constructors are not marked as used when they are accessed under the hood by uses of `coerce`, as described in #10347. This fixes #10347 by co-opting the `tcg_keep` field of `TcGblEnv` to track uses of newtype constructors in the `Coercible` solver. See `Note [Tracking unused binding and imports]` in `TcRnTypes`. Since #10347 is fixed, I was able to simplify the code in `TcDeriv` slightly, as the hack described in `Note [Newtype deriving and unused constructors]` is no longer necessary. - - - - - 9612e91c by Richard Eisenberg at 2019-10-08T13:26:20-04:00 Solve constraints from top-level groups sooner Previously, all constraints from all top-level groups (as separated by top-level splices) were lumped together and solved at the end. This could leak metavariables to TH, though, and that's bad. This patch solves each group's constraints before running the next group's splice. Naturally, we now report fewer errors in some cases. One nice benefit is that this also fixes #11680, but in a much simpler way than the original fix for that ticket. Admittedly, the error messages degrade just a bit from the fix from #11680 (previously, we informed users about variables that will be brought into scope below a top-level splice, and now we just report an out-of-scope error), but the amount of complexity required throughout GHC to get that error was just not worth it. This patch thus reverts much of f93c9517a2c6e158e4a5c5bc7a3d3f88cb4ed119. Fixes #16980 Test cases: th/T16980{,a} - - - - - c2d4011c by Vladislav Zavialov at 2019-10-08T13:27:12-04:00 Bump array and haddock submodules - - - - - f691f0c2 by Sebastian Graf at 2019-10-08T13:27:49-04:00 PmCheck: Look up parent data family TyCon when populating `PossibleMatches` The vanilla COMPLETE set is attached to the representation TyCon of a data family instance, whereas the user-defined COMPLETE sets are attached to the parent data family TyCon itself. Previously, we weren't trying particularly hard to get back to the representation TyCon to the parent data family TyCon, resulting in bugs like #17207. Now we should do much better. Fixes the original issue in #17207, but I found another related bug that isn't so easy to fix. - - - - - 0c0a15a8 by Ben Gamari at 2019-10-09T16:21:14-04:00 Rename STAGE macro to GHC_STAGE To avoid polluting the macro namespace - - - - - 63a5371d by Ben Gamari at 2019-10-09T16:21:14-04:00 Relayout generated header body - - - - - 817c1a94 by Ben Gamari at 2019-10-09T16:21:14-04:00 Define GHC_STAGE in headers instead of command-line - - - - - 5f2c49d8 by Ben Gamari at 2019-10-09T16:21:14-04:00 Remove GHC_STAGE guards from MachDeps This allows the stage1 compiler (which needs to run on the build platform and produce code for the host) to depend upon properties of the target. This is wrong. However, it's no more wrong than it was previously and @Erichson2314 is working on fixing this so I'm going to remove the guard so we can finally bootstrap HEAD with ghc-8.8 (see issue #17146). - - - - - 35cc5eff by Ben Gamari at 2019-10-09T16:21:15-04:00 Test - - - - - d584e3f0 by Ryan Scott at 2019-10-09T16:21:50-04:00 Use addUsedDataCons more judiciously in TcDeriv (#17324) If you derive an instance like this: ```hs deriving <...> instance Foo C ``` And the data constructors for `C` aren't in scope, then `doDerivInstErrorChecks1` throws an error. Moreover, it will _only_ throw an error if `<...>` is either `stock` or `newtype`. This is because the code that the `anyclass` or `via` strategies would generate would not require the use of the data constructors for `C`. However, `doDerivInstErrorChecks1` has another purpose. If you write this: ```hs import M (C(MkC1, ..., MkCn)) deriving <...> instance Foo C ``` Then `doDerivInstErrorChecks1` will call `addUsedDataCons` on `MkC1` through `MkCn` to ensure that `-Wunused-imports` does not complain about them. However, `doDerivInstErrorChecks1` was doing this for _every_ deriving strategy, which mean that if `<...>` were `anyclass` or `via`, then the warning about `MkC1` through `MkCn` being unused would be suppressed! The fix is simple enough: only call `addUsedDataCons` when the strategy is `stock` or `newtype`, just like the other code paths in `doDerivInstErrorChecks1`. Fixes #17324. - - - - - 30f5ac07 by Sebastian Graf at 2019-10-11T22:10:12-04:00 Much simpler language for PmCheck Simon realised that the simple language composed of let bindings, bang patterns and flat constructor patterns is enough to capture the semantics of the source pattern language that are important for pattern-match checking. Well, given that the Oracle is smart enough to connect the dots in this less informationally dense form, which it is now. So we transform `translatePat` to return a list of `PmGrd`s relative to an incoming match variable. `pmCheck` then trivially translates each of the `PmGrd`s into constraints that the oracle understands. Since we pass in the match variable, we incidentally fix #15884 (coverage checks for view patterns) through an interaction with !1746. - - - - - 166e1c2a by Stefan Schulze Frielinghaus at 2019-10-11T22:10:51-04:00 Hadrian: Take care of assembler source files Fixes #17286. - - - - - c2290596 by John Ericson at 2019-10-12T06:32:18-04:00 Simplify Configure in a few ways - No need to distinguish between gcc-llvm and clang. First of all, gcc-llvm is quite old and surely unmaintained by now. Second of all, none of the code actually care about that distinction! Now, it does make sense to consider C multiple frontends for LLVMs in the form of clang vs clang-cl (same clang, yes, but tweaked interface). But this is better handled in terms of "gccish vs mvscish" and "is LLVM", yielding 4 combinations. Therefore, I don't think it is useful saving the existing code for that. - Get the remaining CC_LLVM_BACKEND, and also TABLES_NEXT_TO_CODE in mk/config.h the normal way, rather than hacking it post-hoc. No point keeping these special cases around for now reason. - Get rid of hand-rolled `die` function and just use `AC_MSG_ERROR`. - Abstract check + flag override for unregisterised and tables next to code. Oh, and as part of the above I also renamed/combined some variables where it felt appropriate. - GccIsClang -> CcLlvmBackend. This is for `AC_SUBST`, like the other Camal case ones. It was never about gcc-llvm, or Apple's renamed clang, to be clear. - llvm_CC_FLAVOR -> CC_LLVM_BACKEND. This is for `AC_DEFINE`, like the other all-caps snake case ones. llvm_CC_FLAVOR was just silly indirection *and* an odd name to boot. - - - - - f1ce3535 by Vladislav Zavialov at 2019-10-12T06:33:05-04:00 Escape stats file command (#13676) - - - - - cd1a8808 by Vladislav Zavialov at 2019-10-12T06:33:05-04:00 Skip T13767 on Darwin The CI job fails with: +++ rts/T13676.run/T13676.run.stderr.normalised 2019-10-09 12:27:56.000000000 -0700 @@ -0,0 +1,4 @@ +dyld: Library not loaded: @rpath/libHShaskeline-0.7.5.0-ghc8.9.0.20191009.dylib + Referenced from: /Users/builder/builds/ewzE5N2p/0/ghc/ghc/inplace/lib/bin/ghc + Reason: image not found +*** Exception: readCreateProcess: '/Users/builder/builds/ewzE5N2p/0/ghc/ghc/inplace/lib/bin/ghc' '-B/Users/builder/builds/ewzE5N2p/0/ghc/ghc/inplace/lib' '-e' ''/''$'/'' == '/''/x0024'/''' +RTS '-tT13676.t' (exit -6): failed Unable to reproduce locally. - - - - - 0a338264 by Ryan Scott at 2019-10-12T06:33:42-04:00 Use newDFunName for both manual and derived instances (#17339) Issue #17339 was caused by using a slightly different version of `newDFunName` for derived instances that, confusingly enough, did not take all arguments to the class into account when generating the `DFun` name. I cannot think of any good reason for doing this, so this patch uses `newDFunName` uniformly for both derived instances and manually written instances alike. Fixes #17339. - - - - - c50e4c92 by Simon Peyton Jones at 2019-10-12T13:35:24-04:00 Fix validity checking for inferred types GHC is suposed to uphold the principle that an /inferred/ type for a let-binding should obey the rules for that module. E.g. we should only accept an inferred higher rank type if we have RankNTypes on. But we were failing to check this: TcValidity.checkValidType allowed arbitrary rank for inferred types. This patch fixes the bug. It might in principle cause some breakage, but if so that's good: the user should add RankNTypes and/or a manual signature. (And almost every package has explicit user signatures for all top-level things anyway.) Let's see. Fixes #17213. Metric Decrease: T10370 - - - - - 226d86d2 by Simon Peyton Jones at 2019-10-12T13:36:02-04:00 Do not add a 'solved dict' for quantified constraints GHC has a wonderful-but-delicate mechanism for building recursive dictionaries by adding a goal to the "solved dictionaries" before solving the sub-goals. See Note [Solved dictionaries] in TcSMonad Ticket #17267 showed that if you use this mechanism for local /quantified/ constraints you can get a loop -- or even unsafe coerce. This patch fixes the bug. Specifically * Make TcSMonad.addSolvedDict be conditional on using a /top level/ instance, not a quantified one. * Moreover, we /also/ don't want to add a solved dict for equalities (a~b). * Add lots more comments to Note [Solved dictionaries] to explain the above cryptic stuff. * Extend InstanceWhat to identify those strange built-in equality instances. A couple of other things along the way * Delete the unused Type.isIPPred_maybe. * Stop making addSolvedDict conditional on not being an impolicit parameter. This comes from way back. But it's irrelevant now because IP dicts are never solved via an instance. - - - - - 5ab1a28d by nineonine at 2019-10-13T06:31:40-04:00 Template Haskell: make unary tuples legal (#16881) - - - - - c1bd07cd by Andreas Klebinger at 2019-10-13T06:32:19-04:00 Fix #17334 where NCG did not properly update the CFG. Statements can change the basic block in which instructions are placed during instruction selection. We have to keep track of this switch of the current basic block as we need this information in order to properly update the CFG. This commit implements this change and fixes #17334. We do so by having stmtToInstr return the new block id if a statement changed the basic block. - - - - - 1eda9f28 by Takenobu Tani at 2019-10-13T19:06:02-04:00 users-guide: Add GHCi's ::<builtin-command> form This commit explicitly adds description about double colon command of GHCi. [skip ci] - - - - - 27145351 by Takenobu Tani at 2019-10-13T19:06:40-04:00 Add GHCi help message for :def! and :: commands - - - - - 78463fc5 by Ryan Scott at 2019-10-14T08:38:36-04:00 Add docs/users_guide/.log to .gitignore When the users guide fails to build (as in #17346), a `docs/users_guide/.log` file will be generated with contents that look something like this: ``` WARNING: unknown config value 'latex_paper_size' in override, ignoring /home/rgscott/Software/ghc5/docs/users_guide/ghci.rst:3410: WARNING: u'ghc-flag' reference target not found: -pgmo ?option? /home/rgscott/Software/ghc5/docs/users_guide/ghci.rst:3410: WARNING: u'ghc-flag' reference target not found: -pgmo ?port? Encoding error: 'ascii' codec can't encode character u'\u27e8' in position 132: ordinal not in range(128) The full traceback has been saved in /tmp/sphinx-err-rDF2LX.log, if you want to report the issue to the developers. ``` This definitely should not be checked in to version control, so let's add this to `.gitignore`. - - - - - 4aba72d6 by Ryan Scott at 2019-10-14T08:39:12-04:00 Mention changes from #16980, #17213 in 8.10.1 release notes The fixes for these issues both have user-facing consequences, so it would be good to mention them in the release notes for GHC 8.10.1. While I'm in town, also mention `UnboxedSums` in the release notes entry related to `-fobject-code`. - - - - - 0ca044fd by Ben Gamari at 2019-10-14T08:39:48-04:00 gitlab-ci: Move hadrian-ghc-in-ghci job first This is a very cheap job and can catch a number of "easy" failure modes (e.g. missing imports in the compiler). Let's run it first. - - - - - a2d3594c by Ryan Scott at 2019-10-15T01:35:34-04:00 Refactor some cruft in TcDerivInfer.inferConstraints The latest installment in my quest to clean up the code in `TcDeriv*`. This time, my sights are set on `TcDerivInfer.inferConstraints`, which infers the context for derived instances. This function is a wee bit awkward at the moment: * It's not terribly obvious from a quick glance, but `inferConstraints` is only ever invoked when using the `stock` or `anyclass` deriving strategies, as the code for inferring the context for `newtype`- or `via`-derived instances is located separately in `mk_coerce_based_eqn`. But there's no good reason for things to be this way, so I moved this code from `mk_coerce_based_eqn` to `inferConstraints` so that everything related to inferring instance contexts is located in one place. * In this process, I discovered that the Haddocks for the auxiliary function `inferConstraintsDataConArgs` are completely wrong. It claims that it handles both `stock` and `newtype` deriving, but this is completely wrong, as discussed above—it only handles `stock`. To rectify this, I renamed this function to `inferConstraintsStock` to reflect its actual purpose and created a new `inferConstraintsCoerceBased` function to specifically handle `newtype` (and `via`) deriving. Doing this revealed some opportunities for further simplification: * Removing the context-inference–related code from `mk_coerce_based_eqn` made me realize that the overall structure of the function is basically identical to `mk_originative_eqn`. In fact, I was easily able to combine the two functions into a single `mk_eqn_from_mechanism` function. As part of this merger, I now invoke `atf_coerce_based_error_checks` from `doDerivInstErrorChecks1`. * I discovered that GHC defined this function: ```hs typeToTypeKind = liftedTypeKind `mkVisFunTy` liftedTypeKind ``` No fewer than four times in different modules. I consolidated all of these definitions in a single location in `TysWiredIn`. - - - - - 426b0ddc by Ryan Scott at 2019-10-15T01:36:14-04:00 Don't skip validity checks for built-in classes (#17355) Issue #17355 occurred because the control flow for `TcValidity.check_valid_inst_head` was structured in such a way that whenever it checked a special, built-in class (like `Generic` or `HasField`), it would skip the most important check of all: `checkValidTypePats`, which rejects nonsense like this: ```hs instance Generic (forall a. a) ``` This fixes the issue by carving out `checkValidTypePats` from `check_valid_inst_head` so that `checkValidTypePats` is always invoked. `check_valid_inst_head` has also been renamed to `check_special_inst_head` to reflect its new purpose of _only_ checking for instances headed by special classes. Fixes #17355. - - - - - a55b8a65 by Alp Mestanogullari at 2019-10-15T18:41:18-04:00 iface: export a few more functions from BinIface - - - - - 9c11f817 by Ben Gamari at 2019-10-15T18:41:54-04:00 hadrian: Add support for bindist compressors other than Xz Fixes #17351. - - - - - 535a88e1 by klebinger.andreas at gmx.at at 2019-10-16T07:04:21-04:00 Add loop level analysis to the NCG backend. For backends maintaining the CFG during codegen we can now find loops and their nesting level. This is based on the Cmm CFG and dominator analysis. As a result we can estimate edge frequencies a lot better for methods, resulting in far better code layout. Speedup on nofib: ~1.5% Increase in compile times: ~1.9% To make this feasible this commit adds: * Dominator analysis based on the Lengauer-Tarjan Algorithm. * An algorithm estimating global edge frequences from branch probabilities - In CFG.hs A few static branch prediction heuristics: * Expect to take the backedge in loops. * Expect to take the branch NOT exiting a loop. * Expect integer vs constant comparisons to be false. We also treat heap/stack checks special for branch prediction to avoid them being treated as loops. - - - - - cc2bda50 by adithyaov at 2019-10-16T07:05:01-04:00 Compiling with -S and -fno-code no longer panics (fixes #17143) - - - - - 19641957 by Takenobu Tani at 2019-10-16T07:05:41-04:00 testsuite: Add test for #8305 This is a test for the current algorithm of GHCi command name resolution. I add this test in preparation for updating GHCi command name resolution. For the current algorithm, see https://downloads.haskell.org/ghc/latest/docs/html/users_guide/ghci.html#the-ghci-files - - - - - 6ede3554 by Sebastian Graf at 2019-10-16T07:06:20-04:00 Infer rho-types instead of sigma-types in guard BindStmts and TransStmts In #17343 we saw that we didn't handle the pattern guard `!_ <- undefined` correctly: The `undefined` was never evaluated. Indeed, elaboration failed to insert the invisible type aruments to `undefined`. So `undefined` was trivially a normal-form and in turn never entered. The problem is that we used to infer a sigma-type for the RHS of the guard, the leading qualifiers of which will never be useful in a pattern match situation. Hence we infer a rho-type now. Fixes #17343. - - - - - 798037a1 by John Ericson at 2019-10-16T07:06:58-04:00 Delete ghctags cabal file It came back to life in 381c3ae31b68019177f1cd20cb4da2f9d3b7d6c6 by mistake. - - - - - 51fad9e6 by Richard Eisenberg at 2019-10-16T15:58:58-04:00 Break up TcRnTypes, among other modules. This introduces three new modules: - basicTypes/Predicate.hs describes predicates, moving this logic out of Type. Predicates don't really exist in Core, and so don't belong in Type. - typecheck/TcOrigin.hs describes the origin of constraints and types. It was easy to remove from other modules and can often be imported instead of other, scarier modules. - typecheck/Constraint.hs describes constraints as used in the solver. It is taken from TcRnTypes. No work other than module splitting is in this patch. This is the first step toward homogeneous equality, which will rely more strongly on predicates. And homogeneous equality is the next step toward a dependently typed core language. - - - - - 11d4fc50 by Ben Gamari at 2019-10-16T15:59:52-04:00 hadrian: Introduce enableDebugInfo flavour transformer Also refactor things a bit to eliminate repetition. - - - - - deb96399 by Ryan Scott at 2019-10-16T16:00:29-04:00 Make Coverage.TM a newtype - - - - - 42ebc3f6 by Brian Wignall at 2019-10-16T16:01:06-04:00 Add hyperlinks to PDF/HTML documentation; closes #17342 - - - - - b15a7fb8 by Ben Gamari at 2019-10-17T01:03:11-04:00 testsuite: Ensure that makefile tests get run Previously `makefile_test` and `run_command` tests could easily end up in a situation where they wouldn't be run if the user used the `only_ways` modifier. The reason is to build the set of a ways to run the test in we first start with a candidate set determined by the test type (e.g. `makefile_test`, `compile_run`, etc.) and then filter that set with the constraints given by the test's modifiers. `makefile_test` and `run_command` tests' candidate sets were simply `{normal}`, and consequently most uses of `only_ways` would result in the test being never run. To avoid this we rather use all ways as the candidate sets for these test types. This may result in a few more testcases than we would like (given that some `run_command` tests are insensitive to way) but this can be fixed by adding modifiers and we would much rather run too many tests than too few. This fixes #16042 and a number of other tests afflicted by the same issue. However, there were a few cases that required special attention: * `T14028` is currently failing and is therefore marked as broken due to #17300 * `T-signals-child` is fragile in the `threaded1` and `threaded2` ways (tracked in #17307) - - - - - 4efdda90 by Richard Eisenberg at 2019-10-17T01:03:51-04:00 Tiny fixes to comments around flattening. - - - - - c4c9904b by Ben Gamari at 2019-10-17T01:04:26-04:00 testsuite: Assert that testsuite ways are known This ensures that all testsuite way names given to `omit_ways`, `only_ways`, etc. are known ways. - - - - - 697be2b6 by Ömer Sinan Ağacan at 2019-10-18T15:26:53-04:00 rts/GC: Add an obvious assertion during block initialization Namely ensure that block descriptors are initialized with valid generation numbers. Co-Authored-By: Ben Gamari <ben at well-typed.com> - - - - - 61d2ed42 by Ben Gamari at 2019-10-18T15:26:53-04:00 rts: Add Note explaining applicability of selector optimisation depth limit This was slightly non-obvious so a note seems deserved. - - - - - 11395037 by Ben Gamari at 2019-10-18T15:26:53-04:00 rts/Capability: A few documentation comments - - - - - 206f782a by Ben Gamari at 2019-10-18T15:26:53-04:00 rts: Give stack flags proper macros This were previously quite unclear and will change a bit under the non-moving collector so let's clear this up now. - - - - - 81d4675e by Ben Gamari at 2019-10-18T15:26:53-04:00 rts/GC: Refactor gcCAFs - - - - - 4d674c4e by Ben Gamari at 2019-10-18T15:26:53-04:00 rts: Fix macro parenthesisation - - - - - bfcafd39 by Ben Gamari at 2019-10-18T15:27:42-04:00 rts/Schedule: Allow synchronization without holding a capability The concurrent mark-and-sweep will be performed by a GHC task which will not hold a capability. This is necessary to avoid a concurrent mark from interfering with minor generation collections. However, the major collector must synchronize with the mutators at the end of marking to flush their update remembered sets. This patch extends the `requestSync` mechanism used to synchronize garbage collectors to allow synchronization without holding a capability. This change is fairly straightforward as the capability was previously only required for two reasons: 1. to ensure that we don't try to re-acquire a capability that we the sync requestor already holds. 2. to provide a way to suspend and later resume the sync request if there is already a sync pending. When synchronizing without holding a capability we needn't worry about consideration (1) at all. (2) is slightly trickier and may happen, for instance, when a capability requests a minor collection and shortly thereafter the non-moving mark thread requests a post-mark synchronization. In this case we need to ensure that the non-moving mark thread suspends his request until after the minor GC has concluded to avoid dead-locking. For this we introduce a condition variable, `sync_finished_cond`, which a non-capability-bearing requestor will wait on and which is signalled after a synchronization or GC has finished. - - - - - 921e4e36 by Ömer Sinan Ağacan at 2019-10-18T15:27:56-04:00 rts/BlockAlloc: Allow aligned allocation requests This implements support for block group allocations which are aligned to an integral number of blocks. This will be used by the nonmoving garbage collector, which uses the block allocator to allocate the segments which back its heap. These segments are a fixed number of blocks in size, with each segment being aligned to the segment size boundary. This allows us to easily find the segment metadata stored at the beginning of the segment. - - - - - 4b431f33 by Tamar Christina at 2019-10-20T16:21:10+01:00 Windows: Update tarballs to GCC 9.2 and remove MAX_PATH limit. - - - - - 8057ac96 by Ben Gamari at 2019-10-20T21:15:14-04:00 Merge branches 'wip/gc/sync-without-capability' and 'wip/gc/aligned-block-allocation' into wip/gc/preparation - - - - - 32500f64 by Ömer Sinan Ağacan at 2019-10-20T21:15:37-04:00 rts/StableName: Expose FOR_EACH_STABLE_NAME, freeSnEntry, SNT_size These will be needed when we implement sweeping in the nonmoving collector. - - - - - 4be5152a by Ben Gamari at 2019-10-20T21:15:37-04:00 rts: Disable aggregate-return warnings from gcc This warning is a bit of a relic; there is little reason to avoid aggregate return values in 2019. - - - - - 04471c4f by Ömer Sinan Ağacan at 2019-10-20T21:15:37-04:00 rts/Scav: Expose scavenging functions To keep the non-moving collector nicely separated from the moving collector its scavenging phase will live in another file, `NonMovingScav.c`. However, it will need to use these functions so let's expose them. - - - - - 6ff29c06 by Ben Gamari at 2019-10-20T21:15:37-04:00 rts: Introduce flag to enable the nonmoving old generation This flag will enable the use of a non-moving oldest generation. - - - - - b3ef2d1a by Ben Gamari at 2019-10-20T21:15:37-04:00 rts: Introduce debug flag for non-moving GC - - - - - 68e0647f by Ömer Sinan Ağacan at 2019-10-20T21:15:37-04:00 rts: Non-concurrent mark and sweep This implements the core heap structure and a serial mark/sweep collector which can be used to manage the oldest-generation heap. This is the first step towards a concurrent mark-and-sweep collector aimed at low-latency applications. The full design of the collector implemented here is described in detail in a technical note B. Gamari. "A Concurrent Garbage Collector For the Glasgow Haskell Compiler" (2018) The basic heap structure used in this design is heavily inspired by K. Ueno & A. Ohori. "A fully concurrent garbage collector for functional programs on multicore processors." /ACM SIGPLAN Notices/ Vol. 51. No. 9 (presented by ICFP 2016) This design is intended to allow both marking and sweeping concurrent to execution of a multi-core mutator. Unlike the Ueno design, which requires no global synchronization pauses, the collector introduced here requires a stop-the-world pause at the beginning and end of the mark phase. To avoid heap fragmentation, the allocator consists of a number of fixed-size /sub-allocators/. Each of these sub-allocators allocators into its own set of /segments/, themselves allocated from the block allocator. Each segment is broken into a set of fixed-size allocation blocks (which back allocations) in addition to a bitmap (used to track the liveness of blocks) and some additional metadata (used also used to track liveness). This heap structure enables collection via mark-and-sweep, which can be performed concurrently via a snapshot-at-the-beginning scheme (although concurrent collection is not implemented in this patch). The mark queue is a fairly straightforward chunked-array structure. The representation is a bit more verbose than a typical mark queue to accomodate a combination of two features: * a mark FIFO, which improves the locality of marking, reducing one of the major overheads seen in mark/sweep allocators (see [1] for details) * the selector optimization and indirection shortcutting, which requires that we track where we found each reference to an object in case we need to update the reference at a later point (e.g. when we find that it is an indirection). See Note [Origin references in the nonmoving collector] (in `NonMovingMark.h`) for details. Beyond this the mark/sweep is fairly run-of-the-mill. [1] R. Garner, S.M. Blackburn, D. Frampton. "Effective Prefetch for Mark-Sweep Garbage Collection." ISMM 2007. Co-Authored-By: Ben Gamari <ben at well-typed.com> - - - - - c7e73d12 by Ben Gamari at 2019-10-20T21:15:37-04:00 testsuite: Add nonmoving WAY This simply runs the compile_and_run tests with `-xn`, enabling the nonmoving oldest generation. - - - - - f8f77a07 by Ben Gamari at 2019-10-20T21:15:37-04:00 rts: Mark binder as const - - - - - bd8e3ff4 by Ben Gamari at 2019-10-20T21:15:52-04:00 rts: Implement concurrent collection in the nonmoving collector This extends the non-moving collector to allow concurrent collection. The full design of the collector implemented here is described in detail in a technical note B. Gamari. "A Concurrent Garbage Collector For the Glasgow Haskell Compiler" (2018) This extension involves the introduction of a capability-local remembered set, known as the /update remembered set/, which tracks objects which may no longer be visible to the collector due to mutation. To maintain this remembered set we introduce a write barrier on mutations which is enabled while a concurrent mark is underway. The update remembered set representation is similar to that of the nonmoving mark queue, being a chunked array of `MarkEntry`s. Each `Capability` maintains a single accumulator chunk, which it flushed when it (a) is filled, or (b) when the nonmoving collector enters its post-mark synchronization phase. While the write barrier touches a significant amount of code it is conceptually straightforward: the mutator must ensure that the referee of any pointer it overwrites is added to the update remembered set. However, there are a few details: * In the case of objects with a dirty flag (e.g. `MVar`s) we can exploit the fact that only the *first* mutation requires a write barrier. * Weak references, as usual, complicate things. In particular, we must ensure that the referee of a weak object is marked if dereferenced by the mutator. For this we (unfortunately) must introduce a read barrier, as described in Note [Concurrent read barrier on deRefWeak#] (in `NonMovingMark.c`). * Stable names are also a bit tricky as described in Note [Sweeping stable names in the concurrent collector] (`NonMovingSweep.c`). We take quite some pains to ensure that the high thread count often seen in parallel Haskell applications doesn't affect pause times. To this end we allow thread stacks to be marked either by the thread itself (when it is executed or stack-underflows) or the concurrent mark thread (if the thread owning the stack is never scheduled). There is a non-trivial handshake to ensure that this happens without racing which is described in Note [StgStack dirtiness flags and concurrent marking]. Co-Authored-by: Ömer Sinan Ağacan <omer at well-typed.com> - - - - - dd1b4fdd by Ben Gamari at 2019-10-20T21:15:52-04:00 Nonmoving: Disable memory inventory with concurrent collection - - - - - 4a44ab33 by Ben Gamari at 2019-10-20T21:15:52-04:00 rts: Shrink size of STACK's dirty and marking fields - - - - - 10373416 by Ben Gamari at 2019-10-20T21:15:52-04:00 Don't cleanup until we've stopped the collector This requires that we break nonmovingExit into two pieces since we need to first stop the collector to relinquish any capabilities, then we need to shutdown the scheduler, then we need to free the nonmoving allocators. - - - - - 26c3827f by Ben Gamari at 2019-10-21T11:43:54-04:00 Nonmoving: Ensure write barrier vanishes in non-threaded RTS - - - - - 17e5a032 by Ben Gamari at 2019-10-21T11:43:54-04:00 ThreadPaused: Add barrer on updated thunk - - - - - 8ea316da by David Eichmann at 2019-10-22T02:07:48-04:00 CI: Always dump performance metrics. - - - - - aa31ceaf by Matthew Bauer at 2019-10-22T02:39:01-04:00 Replace freebsd-gnueabihf with freebsd FreeBSD does not support GNU libc, so it makes no sense to use this triple. Most likely previous builds were just using the FreeBSD libc instead of gnueabihf. To fix this, we should just use armv6-unknown-freebsd and armv7-unknown-freebsd triples. Note that both of these are actually "soft-float", not "hard-float". FreeBSD has never officially released hard-float arm32: https://wiki.freebsd.org/ARMTier1 - - - - - fd8b666a by Stefan Schulze Frielinghaus at 2019-10-22T02:39:03-04:00 Implement s390x LLVM backend. This patch adds support for the s390x architecture for the LLVM code generator. The patch includes a register mapping of STG registers onto s390x machine registers which enables a registerised build. - - - - - 2d2cc76f by Tilman Blumhagen at 2019-10-22T02:39:04-04:00 Documentation for (&&) and (&&) states that they are lazy in their second argument (fixes #17354) - - - - - 06d51c4e by Ben Gamari at 2019-10-22T12:13:36-04:00 Fix unregisterised build This required some fiddling around with the location of forward declarations since the C sources generated by GHC's C backend only includes Stg.h. - - - - - 912e440e by Ben Gamari at 2019-10-22T12:17:00-04:00 rts: Tracing support for nonmoving collection events This introduces a few events to mark key points in the nonmoving garbage collection cycle. These include: * `EVENT_CONC_MARK_BEGIN`, denoting the beginning of a round of marking. This may happen more than once in a single major collection since we the major collector iterates until it hits a fixed point. * `EVENT_CONC_MARK_END`, denoting the end of a round of marking. * `EVENT_CONC_SYNC_BEGIN`, denoting the beginning of the post-mark synchronization phase * `EVENT_CONC_UPD_REM_SET_FLUSH`, indicating that a capability has flushed its update remembered set. * `EVENT_CONC_SYNC_END`, denoting that all mutators have flushed their update remembered sets. * `EVENT_CONC_SWEEP_BEGIN`, denoting the beginning of the sweep portion of the major collection. * `EVENT_CONC_SWEEP_END`, denoting the end of the sweep portion of the major collection. - - - - - 9f42cd81 by Ben Gamari at 2019-10-22T12:17:00-04:00 rts: Introduce non-moving heap census This introduces a simple census of the non-moving heap (not to be confused with the heap census used by the heap profiler). This collects basic heap usage information (number of allocated and free blocks) which is useful when characterising fragmentation of the nonmoving heap. - - - - - 711837cc by Ben Gamari at 2019-10-22T12:17:00-04:00 rts/Eventlog: More descriptive error message - - - - - 0d31819e by Ben Gamari at 2019-10-22T12:17:00-04:00 Allow census without live word count Otherwise the census is unsafe when mutators are running due to concurrent mutation. - - - - - 6f173181 by Ben Gamari at 2019-10-22T12:17:00-04:00 NonmovingCensus: Emit samples to eventlog - - - - - 13dd78dd by Ben Gamari at 2019-10-22T12:18:33-04:00 Nonmoving: Allow aging and refactor static objects logic This commit does two things: * Allow aging of objects during the preparatory minor GC * Refactor handling of static objects to avoid the use of a hashtable - - - - - 7b79e8b4 by Ben Gamari at 2019-10-22T12:18:33-04:00 Disable aging when doing deadlock detection GC - - - - - 8fffe12b by Ben Gamari at 2019-10-22T12:18:33-04:00 More comments for aging - - - - - 039d2906 by Ben Gamari at 2019-10-22T12:18:39-04:00 NonMoving: Eliminate integer division in nonmovingBlockCount Perf showed that the this single div was capturing up to 10% of samples in nonmovingMark. However, the overwhelming majority of cases is looking at small block sizes. These cases we can easily compute explicitly, allowing the compiler to turn the division into a significantly more efficient division-by-constant. While the increase in source code looks scary, this all optimises down to very nice looking assembler. At this point the only remaining hotspots in nonmovingBlockCount are due to memory access. - - - - - d15ac82d by Ben Gamari at 2019-10-22T12:18:39-04:00 NonMoving: Allocate mark queues in larger block groups - - - - - 26d2d331 by Ben Gamari at 2019-10-22T12:18:39-04:00 NonMovingMark: Optimize representation of mark queue This shortens MarkQueueEntry by 30% (one word) - - - - - e5eda61e by Ben Gamari at 2019-10-22T12:18:39-04:00 NonMoving: Optimize bitmap search during allocation Use memchr instead of a open-coded loop. This is nearly twice as fast in a synthetic benchmark. - - - - - dacf4cae by Ben Gamari at 2019-10-22T12:18:39-04:00 rts: Add prefetch macros - - - - - 786c52d2 by Ben Gamari at 2019-10-22T12:18:39-04:00 NonMoving: Prefetch when clearing bitmaps Ensure that the bitmap of the segmentt that we will clear next is in cache by the time we reach it. - - - - - 0387df5b by Ben Gamari at 2019-10-22T12:18:39-04:00 NonMoving: Inline nonmovingClearAllBitmaps - - - - - e893877e by Ben Gamari at 2019-10-22T12:18:39-04:00 NonMoving: Fuse sweep preparation into mark prep - - - - - e6f6823f by Ben Gamari at 2019-10-22T12:18:39-04:00 NonMoving: Pre-fetch during mark This improved overall runtime on nofib's constraints test by nearly 10%. - - - - - 56c5ebdc by Ben Gamari at 2019-10-22T12:18:39-04:00 NonMoving: Prefetch segment header - - - - - 19bfe460 by Ben Gamari at 2019-10-22T12:18:39-04:00 NonMoving: Optimise allocator cache behavior Previously we would look at the segment header to determine the block size despite the fact that we already had the block size at hand. - - - - - 53a1a27e by Ben Gamari at 2019-10-22T12:18:39-04:00 NonMovingMark: Eliminate redundant check_in_nonmoving_heaps - - - - - b967e470 by Ben Gamari at 2019-10-22T12:18:39-04:00 NonMoving: Don't do major GC if one is already running Previously we would perform a preparatory moving collection, resulting in many things being added to the mark queue. When we finished with this we would realize in nonmovingCollect that there was already a collection running, in which case we would simply not run the nonmoving collector. However, it was very easy to end up in a "treadmilling" situation: all subsequent GC following the first failed major GC would be scheduled as major GCs. Consequently we would continuously feed the concurrent collector with more mark queue entries and it would never finish. This patch aborts the major collection far earlier, meaning that we avoid adding nonmoving objects to the mark queue and allowing the concurrent collector to finish. - - - - - 3bc172a4 by Ben Gamari at 2019-10-22T12:18:39-04:00 NonMoving: Clean mut_list - - - - - 8e79e2a9 by Ben Gamari at 2019-10-22T12:18:39-04:00 Unconditionally flush update remembered set during minor GC Flush the update remembered set. The goal here is to flush periodically to ensure that we don't end up with a thread who marks their stack on their local update remembered set and doesn't flush until the nonmoving sync period as this would result in a large fraction of the heap being marked during the sync pause. - - - - - b281e80b by Ben Gamari at 2019-10-22T12:18:44-04:00 testsuite: Add nonmoving_thr way - - - - - 07987957 by Ben Gamari at 2019-10-22T12:18:44-04:00 testsuite: Add nonmoving_thr_ghc way This uses the nonmoving collector when compiling the testcases. - - - - - 01fd0242 by Ben Gamari at 2019-10-22T12:18:44-04:00 testsuite: Don't run T15892 in nonmoving ways The nonmoving GC doesn't support `+RTS -G1`, which this test insists on. - - - - - 097f4fd0 by Ben Gamari at 2019-10-22T12:18:44-04:00 testsuite: Nonmoving collector doesn't support -G1 - - - - - 4b91dd25 by Ben Gamari at 2019-10-22T12:18:44-04:00 testsuite: Ensure that threaded tests are run in nonmoving_thr - - - - - 78ce35b9 by Ben Gamari at 2019-10-22T12:18:44-04:00 testsuite: bug1010 requires -c, which isn't supported by nonmoving - - - - - 6e97cc47 by Ben Gamari at 2019-10-22T12:18:44-04:00 testsuite: Skip T15892 in nonmoving_thr_ghc - - - - - 5ce853c8 by Ben Gamari at 2019-10-22T12:18:44-04:00 ghc-heap: Skip heap_all test with debugged RTS The debugged RTS initializes the heap with 0xaa, which breaks the (admittedly rather fragile) assumption that uninitialized fields are set to 0x00: ``` Wrong exit code for heap_all(nonmoving)(expected 0 , actual 1 ) Stderr ( heap_all ): heap_all: user error (assertClosuresEq: Closures do not match Expected: FunClosure {info = StgInfoTable {entry = Nothing, ptrs = 0, nptrs = 1, tipe = FUN_0_1, srtlen = 0, code = Nothing}, ptrArgs = [], dataArgs = [0]} Actual: FunClosure {info = StgInfoTable {entry = Nothing, ptrs = 0, nptrs = 1, tipe = FUN_0_1, srtlen = 1032832, code = Nothing}, ptrArgs = [], dataArgs = [12297829382473034410]} CallStack (from HasCallStack): assertClosuresEq, called at heap_all.hs:230:9 in main:Main ) ``` - - - - - 6abefce7 by Ben Gamari at 2019-10-22T12:18:44-04:00 Skip ghc_heap_all test in nonmoving ways - - - - - 99baff8c by Ben Gamari at 2019-10-22T12:18:44-04:00 testsuite: Don't run T9630 in nonmoving ways The nonmoving collector doesn't support -G1 - - - - - 25ae8f7d by Ben Gamari at 2019-10-22T12:18:44-04:00 testsuite: Don't run T7160 in nonmoving_thr ways The nonmoving way finalizes things in a different order. - - - - - 8cab149b by Ben Gamari at 2019-10-22T12:18:44-04:00 testsuite: Mark length001 as failing under nonmoving ways This is consistent with the other unoptimized ways. - - - - - 5b130b3d by Ben Gamari at 2019-10-22T12:18:46-04:00 Merge branches 'wip/gc/optimize' and 'wip/gc/test' into wip/gc/everything - - - - - 246ce2af by Ömer Sinan Ağacan at 2019-10-22T12:20:15-04:00 NonMoving: Implement indirection shortcutting This allows indirection chains residing in the non-moving heap to be shorted-out. - - - - - 875861ef by Ömer Sinan Ağacan at 2019-10-22T12:20:15-04:00 NonMoving: Implement selector optimisation - - - - - c72e84c6 by Ben Gamari at 2019-10-22T12:20:15-04:00 NonMovingMark: Handle INDs left by shortcutting - - - - - 0f8fd3c6 by Ömer Sinan Ağacan at 2019-10-22T12:20:15-04:00 NonMoving: Implement -xns to disable selector optimization - - - - - c936a245 by Ben Gamari at 2019-10-22T12:20:37-04:00 NonMoving: Introduce nonmovingSegmentLogBlockSize acccessor This will allow us to easily move the block size elsewhere. - - - - - 6dcef5ee by Ben Gamari at 2019-10-22T12:20:37-04:00 NonMoving: Move block size to block descriptor - - - - - dd8d1b49 by Ben Gamari at 2019-10-22T12:20:37-04:00 NonMoving: Move next_free_snap to block descriptor - - - - - 116e4646 by Ben Gamari at 2019-10-22T12:20:46-04:00 NonMoving: Add summarizing Note - - - - - 22eee2bc by Ben Gamari at 2019-10-22T12:20:48-04:00 Merge branches 'wip/gc/segment-header-to-bdescr' and 'wip/gc/docs' into wip/gc/everything2 - - - - - 3a862703 by Ömer Sinan Ağacan at 2019-10-22T18:56:32-04:00 rts: COMPACT_NFDATA support for the nonmoving collector This largely follows the model used for large objects, with appropriate adjustments made to account for references in the sharing deduplication hashtable. - - - - - 7c35d39b by Ben Gamari at 2019-10-22T18:56:32-04:00 rts: Mark nonmoving GC paths in moving collector as unlikely The expectation here is that the nonmoving GC is latency-centric, whereas the moving GC emphasizes throughput. Therefore we give the latter the benefit of better static branch prediction. - - - - - 91109404 by Ben Gamari at 2019-10-22T18:57:27-04:00 nonmoving: Trace GC preparation steps - - - - - a69b28f4 by Ben Gamari at 2019-10-22T18:57:27-04:00 nonmoving: Don't do two passes over large and compact object lists Previously we would first move the new objects to their appropriate non-moving GC list, then do another pass over that list to clear their mark bits. This is needlessly expensive. First clear the mark bits of the existing objects, then add the newly evacuated objects and, at the same time, clear their mark bits. This cuts the preparatory GC time in half for the Pusher benchmark with a large queue size. - - - - - 984745b0 by Ben Gamari at 2019-10-22T18:57:27-04:00 nonmoving: Upper-bound time we hold SM_MUTEX for during sweep - - - - - 96c5411a by David Feuer at 2019-10-23T05:58:37-04:00 Use an IORef for QSemN Replace the outer `MVar` in `QSemN` with an `IORef`. This should probably be lighter, and it removes the need for `uninterruptibleMask`. Previously Differential Revision https://phabricator.haskell.org/D4896 - - - - - faa30dcb by Andreas Klebinger at 2019-10-23T05:58:43-04:00 Warn about missing profiled libs when using the Interpreter. When GHC itself, or it's interpreter is profiled we need to load profiled libraries as well. This requirement is not always obvious, especially when TH implicilty uses the interpreter. When the libs were not found we fall back to assuming the are in a DLL. This is usually not the case so now we warn users when we do so. This makes it more obvious what is happening and gives users a way to fix the issue. This fixes #17121. - - - - - 1cd3fa29 by Richard Eisenberg at 2019-10-23T05:58:46-04:00 Implement a coverage checker for injectivity This fixes #16512. There are lots of parts of this patch: * The main payload is in FamInst. See Note [Coverage condition for injective type families] there for the overview. But it doesn't fix the bug. * We now bump the reduction depth every time we discharge a CFunEqCan. See Note [Flatten when discharging CFunEqCan] in TcInteract. * Exploration of this revealed a new, easy to maintain invariant for CTyEqCans. See Note [Almost function-free] in TcRnTypes. * We also realized that type inference for injectivity was a bit incomplete. This means we exchanged lookupFlattenTyVar for rewriteTyVar. See Note [rewriteTyVar] in TcFlatten. The new function is monadic while the previous one was pure, necessitating some faff in TcInteract. Nothing too bad. * zonkCt did not maintain invariants on CTyEqCan. It's not worth the bother doing so, so we just transmute CTyEqCans to CNonCanonicals. * The pure unifier was finding the fixpoint of the returned substitution, even when doing one-way matching (in tcUnifyTysWithTFs). Fixed now. Test cases: typecheck/should_fail/T16512{a,b} - - - - - 900cf195 by Alp Mestanogullari at 2019-10-23T05:58:48-04:00 compiler: introduce DynFlags plugins They have type '[CommandLineOpts] -> Maybe (DynFlags -> IO DynFlags)'. All plugins that supply a non-Nothing 'dynflagsPlugin' will see their updates applied to the current DynFlags right after the plugins are loaded. One use case for this is to superseede !1580 for registering hooks from a plugin. Frontend/parser plugins were considered to achieve this but they respectively conflict with how this plugin is going to be used and don't allow overriding/modifying the DynFlags, which is how hooks have to be registered. This commit comes with a test, 'test-hook-plugin', that registers a "fake" meta hook that replaces TH expressions with the 0 integer literal. - - - - - a19c7d17 by Ryan Scott at 2019-10-23T05:58:49-04:00 Reify oversaturated data family instances correctly (#17296) `TcSplice` was not properly handling oversaturated data family instances, such as the example in #17296, as it dropped arguments due to carelessly zipping data family instance arguments with `tyConTyVars`. For data families, the number of `tyConTyVars` can sometimes be less than the number of arguments it can accept in a data family instance due to the fact that data family instances can be oversaturated. To account for this, `TcSplice.mkIsPolyTvs` has now been renamed to `tyConArgsPolyKinded` and now factors in `tyConResKind` in addition to `tyConTyVars`. I've also added `Note [Reified instances and explicit kind signatures]` which explains the various subtleties in play here. Fixes #17296. - - - - - 9b2a5008 by Ben Gamari at 2019-10-23T05:58:50-04:00 testsuite: Don't run T7653 in ghci and profiled ways Currently this routinely fails in the i386 job. See #7653. - - - - - b521e8b6 by Ömer Sinan Ağacan at 2019-10-23T05:58:57-04:00 Refactor Compact.c: - Remove forward declarations - Introduce UNTAG_PTR and GET_PTR_TAG for dealing with pointer tags without having to cast arguments to StgClosure* - Remove dead code - Use W_ instead of StgWord - Use P_ instead of StgPtr - - - - - 17987a4b by Matthew Pickering at 2019-10-23T05:58:58-04:00 eventlog: Dump cost centre stack on each sample With this change it is possible to reconstruct the timing portion of a `.prof` file after the fact. By logging the stacks at each time point a more precise executation trace of the program can be observed rather than all identical cost centres being identified in the report. There are two new events: 1. `EVENT_PROF_BEGIN` - emitted at the start of profiling to communicate the tick interval 2. `EVENT_PROF_SAMPLE_COST_CENTRE` - emitted on each tick to communicate the current call stack. Fixes #17322 - - - - - 4798f3b9 by Takenobu Tani at 2019-10-23T05:59:00-04:00 Allow command name resolution for GHCi commands with option `!` #17345 This commit allows command name resolution for GHCi commands with option `!` as follows: ghci> :k! Int Int :: * = Int This commit changes implementation as follows: Before: * Prefix match with full string including the option `!` (e.g. `k!`) After (this patch): * Prefix match without option suffix `!` (e.g. `k`) * in addition, suffix match with option `!` See also #8305 and #8113 - - - - - aa778152 by Andreas Klebinger at 2019-10-23T05:59:01-04:00 Fix bug in the x86 backend involving the CFG. This is part two of fixing #17334. There are two parts to this commit: - A bugfix for computing loop levels - A bugfix of basic block invariants in the NCG. ----------------------------------------------------------- In the first bug we ended up with a CFG of the sort: [A -> B -> C] This was represented via maps as fromList [(A,B),(B,C)] and later transformed into a adjacency array. However the transformation did not include block C in the array (since we only looked at the keys of the map). This was still fine until we tried to look up successors for C and tried to read outside of the array bounds when accessing C. In order to prevent this in the future I refactored to code to include all nodes as keys in the map representation. And make this a invariant which is checked in a few places. Overall I expect this to make the code more robust as now any failed lookup will represent an error, versus failed lookups sometimes being expected and sometimes not. In terms of performance this makes some things cheaper (getting a list of all nodes) and others more expensive (adding a new edge). Overall this adds up to no noteable performance difference. ----------------------------------------------------------- Part 2: When the NCG generated a new basic block, it did not always insert a NEWBLOCK meta instruction in the stream which caused a quite subtle bug. During instruction selection a statement `s` in a block B with control of the sort: B -> C will sometimes result in control flow of the sort: ┌ < ┐ v ^ B -> B1 ┴ -> C as is the case for some atomic operations. Now to keep the CFG in sync when introducing B1 we clearly want to insert it between B and C. However there is a catch when we have to deal with self loops. We might start with code and a CFG of these forms: loop: stmt1 ┌ < ┐ .... v ^ stmtX loop ┘ stmtY .... goto loop: Now we introduce B1: ┌ ─ ─ ─ ─ ─┐ loop: │ ┌ < ┐ │ instrs v │ │ ^ .... loop ┴ B1 ┴ ┘ instrsFromX stmtY goto loop: This is simple, all outgoing edges from loop now simply start from B1 instead and the code generator knows which new edges it introduced for the self loop of B1. Disaster strikes if the statement Y follows the same pattern. If we apply the same rule that all outgoing edges change then we end up with: loop ─> B1 ─> B2 ┬─┐ │ │ └─<┤ │ │ └───<───┘ │ └───────<────────┘ This is problematic. The edge B1->B1 is modified as expected. However the modification is wrong! The assembly in this case looked like this: _loop: <instrs> _B1: ... cmpxchgq ... jne _B1 <instrs> <end _B1> _B2: ... cmpxchgq ... jne _B2 <instrs> jmp loop There is no edge _B2 -> _B1 here. It's still a self loop onto _B1. The problem here is that really B1 should be two basic blocks. Otherwise we have control flow in the *middle* of a basic block. A contradiction! So to account for this we add yet another basic block marker: _B: <instrs> _B1: ... cmpxchgq ... jne _B1 jmp _B1' _B1': <instrs> <end _B1> _B2: ... Now when inserting B2 we will only look at the outgoing edges of B1' and everything will work out nicely. You might also wonder why we don't insert jumps at the end of _B1'. There is no way another block ends up jumping to the labels _B1 or _B2 since they are essentially invisible to other blocks. View them as control flow labels local to the basic block if you'd like. Not doing this ultimately caused (part 2 of) #17334. - - - - - 1f40e68a by Ryan Yates at 2019-10-23T05:59:03-04:00 Full abort on validate failure merging `orElse`. Previously partial roll back of a branch of an `orElse` was attempted if validation failure was observed. Validation here, however, does not account for what part of the transaction observed inconsistent state. This commit fixes this by fully aborting and restarting the transaction. - - - - - 9c1f0f7c by Ben Gamari at 2019-10-23T05:59:03-04:00 Bump stm submodule - - - - - 6beea836 by Andreas Klebinger at 2019-10-23T05:59:04-04:00 Make dynflag argument for withTiming pure. 19 times out of 20 we already have dynflags in scope. We could just always use `return dflags`. But this is in fact not free. When looking at some STG code I noticed that we always allocate a closure for this expression in the heap. Clearly a waste in these cases. For the other cases we can either just modify the callsite to get dynflags or use the _D variants of withTiming I added which will use getDynFlags under the hood. - - - - - 8dd480cc by Matthew Pickering at 2019-10-23T05:59:06-04:00 Performance tests: Reduce acceptance threshold for bytes allocated tests The "new" performance testing infrastructure resets the baseline after every test so it's easy to miss gradual performance regressions over time. We should at least make these numbers smaller to catch patches which affect performance earlier. - - - - - 4af20bbc by Ben Gamari at 2019-10-23T05:59:06-04:00 users-guide: Fix :since: for -Wunused-packages Fixes #17382. - - - - - 21663693 by Ben Gamari at 2019-10-23T05:59:07-04:00 Drop duplicate -optl's from GHC invocations Previously the make build system would pass things like `-optl-optl-Wl,-x -optl-optl-Wl,noexecstack` to GHC. This would naturally result in mass confusion as GHC would pass `-optl-Wl,-x` to GCC. GCC would in turn interpret this as `-o ptl-Wl,-x`, setting the output pass of the invocation. The problem that `-optl` was added to the command-line in two places in the build system. Fix this. Fixes #17385. - - - - - bb0dc5a5 by Andreas Klebinger at 2019-10-23T05:59:07-04:00 Hadrian: Invoke ghc0 via bash when running tests to fix #17362. cmd uses RawCommand which uses Windows semantics to find the executable which sometimes seems to fail for unclear reasons. If we invoke ghc via bash then bash will find the ghc executable and the issue goes away. - - - - - 266435a7 by Ömer Sinan Ağacan at 2019-10-23T05:59:09-04:00 Add new flag for unarised STG dumps Previously -ddump-stg would dump pre and post-unarise STGs. Now we have a new flag for post-unarise STG and -ddump-stg only dumps coreToStg output. STG dump flags after this commit: - -ddump-stg: Dumps CoreToStg output - -ddump-stg-unarised: Unarise output - -ddump-stg-final: STG right before code gen (includes CSE and lambda lifting) - - - - - 8abddac8 by Ben Gamari at 2019-10-23T05:59:10-04:00 base: Add @since on GHC.IO.Handle.Lock.hUnlock Unfortunately this was introduced in base-4.11.0 (GHC 8.4.1) whereas the other locking primitives were added in base-4.10.0 (GHC 8.2.1). - - - - - 7f72b540 by Ben Gamari at 2019-10-23T14:56:46-04:00 Merge non-moving garbage collector This introduces a concurrent mark & sweep garbage collector to manage the old generation. The concurrent nature of this collector typically results in significantly reduced maximum and mean pause times in applications with large working sets. Due to the large and intricate nature of the change I have opted to preserve the fully-buildable history, including merge commits, which is described in the "Branch overview" section below. Collector design ================ The full design of the collector implemented here is described in detail in a technical note > B. Gamari. "A Concurrent Garbage Collector For the Glasgow Haskell > Compiler" (2018) This document can be requested from @bgamari. The basic heap structure used in this design is heavily inspired by > K. Ueno & A. Ohori. "A fully concurrent garbage collector for > functional programs on multicore processors." /ACM SIGPLAN Notices/ > Vol. 51. No. 9 (presented at ICFP 2016) This design is intended to allow both marking and sweeping concurrent to execution of a multi-core mutator. Unlike the Ueno design, which requires no global synchronization pauses, the collector introduced here requires a stop-the-world pause at the beginning and end of the mark phase. To avoid heap fragmentation, the allocator consists of a number of fixed-size /sub-allocators/. Each of these sub-allocators allocators into its own set of /segments/, themselves allocated from the block allocator. Each segment is broken into a set of fixed-size allocation blocks (which back allocations) in addition to a bitmap (used to track the liveness of blocks) and some additional metadata (used also used to track liveness). This heap structure enables collection via mark-and-sweep, which can be performed concurrently via a snapshot-at-the-beginning scheme (although concurrent collection is not implemented in this patch). Implementation structure ======================== The majority of the collector is implemented in a handful of files: * `rts/Nonmoving.c` is the heart of the beast. It implements the entry-point to the nonmoving collector (`nonmoving_collect`), as well as the allocator (`nonmoving_allocate`) and a number of utilities for manipulating the heap. * `rts/NonmovingMark.c` implements the mark queue functionality, update remembered set, and mark loop. * `rts/NonmovingSweep.c` implements the sweep loop. * `rts/NonmovingScav.c` implements the logic necessary to scavenge the nonmoving heap. Branch overview =============== ``` * wip/gc/opt-pause: | A variety of small optimisations to further reduce pause times. | * wip/gc/compact-nfdata: | Introduce support for compact regions into the non-moving |\ collector | \ | \ | | * wip/gc/segment-header-to-bdescr: | | | Another optimization that we are considering, pushing | | | some segment metadata into the segment descriptor for | | | the sake of locality during mark | | | | * | wip/gc/shortcutting: | | | Support for indirection shortcutting and the selector optimization | | | in the non-moving heap. | | | * | | wip/gc/docs: | |/ Work on implementation documentation. | / |/ * wip/gc/everything: | A roll-up of everything below. |\ | \ | |\ | | \ | | * wip/gc/optimize: | | | A variety of optimizations, primarily to the mark loop. | | | Some of these are microoptimizations but a few are quite | | | significant. In particular, the prefetch patches have | | | produced a nontrivial improvement in mark performance. | | | | | * wip/gc/aging: | | | Enable support for aging in major collections. | | | | * | wip/gc/test: | | | Fix up the testsuite to more or less pass. | | | * | | wip/gc/instrumentation: | | | A variety of runtime instrumentation including statistics | | / support, the nonmoving census, and eventlog support. | |/ | / |/ * wip/gc/nonmoving-concurrent: | The concurrent write barriers. | * wip/gc/nonmoving-nonconcurrent: | The nonmoving collector without the write barriers necessary | for concurrent collection. | * wip/gc/preparation: | A merge of the various preparatory patches that aren't directly | implementing the GC. | | * GHC HEAD . . . ``` - - - - - 83655b06 by Ben Gamari at 2019-10-24T08:45:41-04:00 hadrian: Warn user if hadrian build fails due to lack of threaded RTS See #16873. - - - - - 6824f29a by Ryan Scott at 2019-10-24T08:46:19-04:00 Parenthesize GADT return types in pprIfaceConDecl (#17384) We were using `pprIfaceAppArgs` instead of `pprParendIfaceAppArgs` in `pprIfaceConDecl`. Oops. Fixes #17384. - - - - - 9de3f8b1 by Ryan Scott at 2019-10-24T18:38:32-04:00 Make isTcLevPoly more conservative with newtypes (#17360) `isTcLevPoly` gives an approximate answer for when a type constructor is levity polymorphic when fully applied, where `True` means "possibly levity polymorphic" and `False` means "definitely not levity polymorphic". `isTcLevPoly` returned `False` for newtypes, which is incorrect in the presence of `UnliftedNewtypes`, leading to #17360. This patch tweaks `isTcLevPoly` to return `True` for newtypes instead. Fixes #17360. - - - - - 243c72eb by Ryan Scott at 2019-10-24T18:39:08-04:00 Mark promoted InfixT names as IsPromoted (#17394) We applied a similar fix for `ConT` in #15572 but forgot to apply the fix to `InfixT` as well. This patch fixes #17394 by doing just that. - - - - - 87175e78 by James Foster at 2019-10-25T09:01:08-04:00 Make Hadrian use -dynamic-too in the basic case This commit makes Hadrian use the `-dynamic-too` flag when the current Flavour's libraryWays contains both vanilla and dynamic, cutting down the amount of repeated work caused by separate compilation of dynamic and static files. It does this for the basic case where '.o' and '.dyn_o' files are built with one command, but does not generalise to cases like '.prof_o' and '.prof_dyn_o'. - - - - - ecd89062 by Alp Mestanogullari at 2019-10-25T09:01:47-04:00 hadrian/ci: run testsuite against a freshly produced and installed bindist - - - - - 2a16b555 by Ben Gamari at 2019-10-25T09:02:26-04:00 testsuite: Mark T13786 as fragile in unreg build Due to #17018. - - - - - 08298926 by Ben Gamari at 2019-10-25T09:02:26-04:00 testsuite: Use fragile modifier in TH_foreignInterruptible It looks like this use of `skip` snuck through my previous refactoring. - - - - - 4c7d45d1 by Brian Wignall at 2019-10-25T09:03:04-04:00 Make documentation for byteSwap16 consistent with byteSwap32 (impl is same, with s/16/32) - - - - - 02822d84 by Ben Gamari at 2019-10-25T09:03:40-04:00 aclocal: A bit of reformatting - - - - - 519f5162 by Ben Gamari at 2019-10-25T09:03:40-04:00 configure: Drop GccLT46 GCC 4.6 was released 7 years ago. I think we can finally assume that it's available. This is a simplification prompted by #15742. - - - - - acedfc8b by Ben Gamari at 2019-10-25T09:04:16-04:00 gitlab-ci: Run check-uniques during lint job - - - - - 8916e64e by Andrew Martin at 2019-10-26T05:19:38-04:00 Implement shrinkSmallMutableArray# and resizeSmallMutableArray#. This is a part of GHC Proposal #25: "Offer more array resizing primitives". Resources related to the proposal: - Discussion: https://github.com/ghc-proposals/ghc-proposals/pull/121 - Proposal: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0025-resize-boxed.rst Only shrinkSmallMutableArray# is implemented as a primop since a library-space implementation of resizeSmallMutableArray# (in GHC.Exts) is no less efficient than a primop would be. This may be replaced by a primop in the future if someone devises a strategy for growing arrays in-place. The library-space implementation always copies the array when growing it. This commit also tweaks the documentation of the deprecated sizeofMutableByteArray#, removing the mention of concurrency. That primop is unsound even in single-threaded applications. Additionally, the non-negativity assertion on the existing shrinkMutableByteArray# primop has been removed since this predicate is trivially always true. - - - - - 1be9c35c by Roland Senn at 2019-10-26T05:20:14-04:00 Fix #14690 - :steplocal panics after break-on-error `:steplocal` enables only breakpoints in the current top-level binding. When a normal breakpoint is hit, then the module name and the break id from the `BRK_FUN` byte code allow us to access the corresponding entry in a ModBreak table. From this entry we then get the SrcSpan (see compiler/main/InteractiveEval.hs:bindLocalsAtBreakpoint). With this source-span we can then determine the current top-level binding, needed for the steplocal command. However, if we break at an exception or at an error, we don't have an BRK_FUN byte-code, so we don't have any source information. The function `bindLocalsAtBreakpoint` creates an `UnhelpfulSpan`, which doesn't allow us to determine the current top-level binding. To avoid a `panic`, we have to check for `UnhelpfulSpan` in the function `ghc/GHCi/UI.hs:stepLocalCmd`. Hence a :steplocal command after a break-on-exception or a break-on-error is not possible. - - - - - 4820af10 by Adam Sandberg Eriksson at 2019-10-26T19:53:01-04:00 hadrian: point link to ghc gitlab [skip ci] - - - - - 609c7ee6 by Ben Gamari at 2019-10-26T19:53:36-04:00 gitlab-ci: Produce ARMv7 binary distributions - - - - - 8ac49411 by Ben Gamari at 2019-10-26T19:53:36-04:00 testsuite: Skip regalloc_unit_tests unless have_ncg This is a unit test for the native code generator's register allocator; naturally. the NCG is required. - - - - - 60575596 by Ben Gamari at 2019-10-26T19:53:36-04:00 Enable PDF documentation - - - - - 417f59d4 by Ben Gamari at 2019-10-26T19:53:36-04:00 rts: Fix ARM linker includes * Prefer #pragma once over guard macros * Drop redundant #includes * Fix order to ensure that necessary macros are defined when we condition on them - - - - - 4054f0e5 by Ömer Sinan Ağacan at 2019-10-26T19:54:16-04:00 Remove redundant -fno-cse options These were probably added with some GLOBAL_VARs, but those GLOBAL_VARs are now gone. - - - - - c62817f2 by Luke Lau at 2019-10-27T11:35:40-04:00 Fix RankNTypes :ghc-flag: in users guide This fixes a hadrian `build docs` failure - - - - - fc3a5205 by Luke Lau at 2019-10-27T11:35:40-04:00 Remove unused import - - - - - d2520bef by Luke Lau at 2019-10-27T11:35:40-04:00 Fix path to ghc-flags in users guide Hadrian rules It should point to the _build directory, not the source - - - - - 896d470a by Luke Lau at 2019-10-27T11:35:40-04:00 Add back documentation for deprecated -Whi-shadowing This was removed in b538476be3706264620c072e6e436debf9e0d3e4, but without it the compare-flags.py script fails. This adds it back and marks it as deprecated, with a notice that it is slated for removal. - - - - - 7d80f8b5 by Luke Lau at 2019-10-27T11:35:40-04:00 Remove documented flags from expected-undocumented-flags.txt - - - - - fa0d4809 by Ryan Scott at 2019-10-27T11:36:17-04:00 Parenthesize nullary constraint tuples using sigPrec (#17403) We were using `appPrec`, not `sigPrec`, as the precedence when determining whether or not to parenthesize `() :: Constraint`, which lead to the parentheses being omitted in function contexts like `(() :: Constraint) => String`. Easily fixed. Fixes #17403. - - - - - 90d06fd0 by Ben Gamari at 2019-10-27T17:27:17-04:00 hadrian: Silence output from Support SMP check Previously we would allow the output from the check of SMP support introduced by 83655b06e6d3e93b2d15bb0fa250fbb113d7fe68 leak to stdout. Silence this. See #16873. - - - - - 6635a3f6 by Josef Svenningsson at 2019-10-28T09:20:34-04:00 Fix #15344: use fail when desugaring applicative-do Applicative-do has a bug where it fails to use the monadic fail method when desugaring patternmatches which can fail. See #15344. This patch fixes that problem. It required more rewiring than I had expected. Applicative-do happens mostly in the renamer; that's where decisions about scheduling are made. This schedule is then carried through the typechecker and into the desugarer which performs the actual translation. Fixing this bug required sending information about the fail method from the renamer, through the type checker and into the desugarer. Previously, the desugarer didn't have enough information to actually desugar pattern matches correctly. As a side effect, we also fix #16628, where GHC wouldn't catch missing MonadFail instances with -XApplicativeDo. - - - - - cd9b9459 by Ryan Scott at 2019-10-28T09:21:13-04:00 Refactor TcDeriv to validity-check less in anyclass/via deriving (#13154) Due to the way `DerivEnv` is currently structured, there is an invariant that every derived instance must consist of a class applied to a non-empty list of argument types, where the last argument *must* be an application of a type constructor to some arguments. This works for many cases, but there are also some design patterns in standalone `anyclass`/`via` deriving that are made impossible due to enforcing this invariant, as documented in #13154. This fixes #13154 by refactoring `TcDeriv` and friends to perform fewer validity checks when using the `anyclass` or `via` strategies. The highlights are as followed: * Five fields of `DerivEnv` have been factored out into a new `DerivInstTys` data type. These fields only make sense for instances that satisfy the invariant mentioned above, so `DerivInstTys` is now only used in `stock` and `newtype` deriving, but not in other deriving strategies. * There is now a `Note [DerivEnv and DerivSpecMechanism]` describing the bullet point above in more detail, as well as explaining the exact requirements that each deriving strategy imposes. * I've refactored `mkEqnHelp`'s call graph to be slightly less complicated. Instead of the previous `mkDataTypeEqn`/`mkNewTypeEqn` dichotomy, there is now a single entrypoint `mk_eqn`. * Various bits of code were tweaked so as not to use fields that are specific to `DerivInstTys` so that they may be used by all deriving strategies, since not all deriving strategies use `DerivInstTys`. - - - - - e0e04856 by Alan Zimmerman at 2019-10-28T09:21:58-04:00 Attach API Annotations for {-# SOURCE #-} import pragma Attach the API annotations for the start and end locations of the {-# SOURCE #-} pragma in an ImportDecl. Closes #17388 - - - - - e951f219 by Sebastian Graf at 2019-10-28T09:22:35-04:00 Use FlexibleInstances for `Outputable (* p)` instead of match-all instances with equality constraints In #17304, Richard and Simon dicovered that using `-XFlexibleInstances` for `Outputable` instances of AST data types means users can provide orphan `Outputable` instances for passes other than `GhcPass`. Type inference doesn't currently to suffer, and Richard gave an example in #17304 that shows how rare a case would be where the slightly worse type inference would matter. So I went ahead with the refactoring, attempting to fix #17304. - - - - - ad1fe274 by Simon Peyton Jones at 2019-10-28T09:23:14-04:00 Better arity for join points A join point was getting too large an arity, leading to #17294. I've tightened up the invariant: see CoreSyn, Note [Invariants on join points], invariant 2b - - - - - fb4f245c by Takenobu Tani at 2019-10-29T03:45:02-04:00 users-guide: Fix :since: for -xn flag [skip ci] - - - - - 35abbfee by Takenobu Tani at 2019-10-29T03:45:41-04:00 users-guide: Add some new features and fix warnings for GHC 8.10 This updates the following: * Add description for ImportQualifiedPost extension * Add description for ghci command name resolution * Fix markdown warnings [skip ci] - - - - - 57dc1565 by Sylvain Henry at 2019-10-29T03:46:22-04:00 Use `not#` primitive to implement Word's complement - - - - - 28e52732 by Ben Gamari at 2019-10-29T03:46:59-04:00 linters: Add mode to lint given set of files This makes testing much easier. - - - - - db43b3b3 by Ben Gamari at 2019-10-29T03:46:59-04:00 linters: Add linter to catch unquoted use of $(TEST_HC) This is a common bug that creeps into Makefiles (e.g. see T12674). - - - - - ebee0d6b by Ben Gamari at 2019-10-29T03:46:59-04:00 testsuite: Fix quoting of $(TEST_HC) in T12674 I have no idea how this went unnoticed until now. - - - - - 3bd3456f by Ömer Sinan Ağacan at 2019-10-29T03:47:44-04:00 Refactor HscRecomp constructors: Make it evident in the constructors that the final interface is only available when HscStatus is not HscRecomp. (When HscStatus == HscRecomp we need to finish the compilation to get the final interface) `Maybe ModIface` return value of hscIncrementalCompile and the partial `expectIface` function are removed. - - - - - bbdd54aa by Ömer Sinan Ağacan at 2019-10-29T03:47:44-04:00 Return ModIface in compilation pipeline, remove IORef hack for generating ModIfaces The compilation phases now optionally return ModIface (for phases that generate an interface, currently only HscOut when (re)compiling a file). The value is then used by compileOne' to return the generated interface with HomeModInfo (which is then used by the batch mode compiler when building rest of the tree). hscIncrementalMode also returns a DynFlags with plugin info, to be used in the rest of the pipeline. Unfortunately this introduces a (perhaps less bad) hack in place of the previous IORef: we now record the DynFlags used to generate the partial infterface in HscRecomp and use the same DynFlags when generating the full interface. I spent almost three days trying to understand what's changing in DynFlags that causes a backpack test to fail, but I couldn't figure it out. There's a FIXME added next to the field so hopefully someone who understands this better than I do will fix it leter. - - - - - a56433a9 by Ömer Sinan Ağacan at 2019-10-29T03:47:44-04:00 Remove unused DynFlags arg of lookupIfaceByModule - - - - - dcd40c71 by Ömer Sinan Ağacan at 2019-10-29T03:47:44-04:00 HscMain: Move a comment closer to the relevant site - - - - - 593f6543 by Ömer Sinan Ağacan at 2019-10-29T03:47:44-04:00 MkIface: Remove redundant parameter and outdated comments from addFingerprints - - - - - f868e1fe by Ben Gamari at 2019-10-29T03:48:20-04:00 gitlab-ci: Use Hadrian for unregisterised job - - - - - 7b2ecbc0 by Ben Gamari at 2019-10-29T03:48:20-04:00 gitlab-ci: Factor out Linux Hadrian validation logic - - - - - 8e5de15d by Ben Gamari at 2019-10-29T03:48:20-04:00 hadrian: Define USE_LIBFFI_FOR_ADJUSTORS when necessary - - - - - 6a090270 by Ben Gamari at 2019-10-29T03:48:20-04:00 hadrian: Define NOSMP when building rts unregisterised It seems that NOSMP was previously only defined when compiling the compiler, not the RTS. Fix this. In addition do some spring-cleaning and make the logic match that of the Make build system. - - - - - b741d19d by Ben Gamari at 2019-10-29T03:48:20-04:00 hadrian: Shuffle around RTS build flags Some of these flags wanted to be passed to .cmm builds as well as C builds. - - - - - d7cedd9d by Ben Gamari at 2019-10-29T03:48:20-04:00 hadrian: Drop -Werror=unused-but-set-variable from GHC flags Previously `hadrian` would pass `-optc-Werror=unused-but-set-variable` to all GHC invocations. This was a difference from the make build system and cause the unregisterised build to fail as the C that GHC produces contains many unused functions. Drop it from the GHC flags. Note, however, that the flag is still present in `Settings.Builders.Common.cWarnings` and therefore will still be applied during compilation of C sources. - - - - - 7d3a15c7 by Ben Gamari at 2019-10-29T03:48:55-04:00 base: Fix open-file locking The OFD locking path introduced in 3b784d440d4b01b4c549df7c9a3ed2058edfc780 due to #13945 appears to have never actually worked but we never noticed due to an oversight in the autoconf check. Fix it. Thanks to Oleg Grenrus for noticing this. - - - - - 78b70e63 by Ben Gamari at 2019-10-29T03:48:55-04:00 base: Split up file locking implementation This makes the CPP significantly easier to follow. - - - - - 63977398 by Ben Gamari at 2019-10-29T03:49:31-04:00 Don't substitute GccVersion variable Not only is it now unused but we generally can't assume that we are compiling with GCC, so it really shouldn't be used. - - - - - 72f7ac9a by Ben Gamari at 2019-10-29T03:50:06-04:00 Revert "Replace freebsd-gnueabihf with freebsd" This reverts commit aa31ceaf7568802590f73a740ffbc8b800096342 as suggested in #17392. - - - - - 3c0372d6 by Ben Gamari at 2019-10-29T20:31:36-04:00 distrib: Fix binary distribution installation This had silently regressed due to 81860281 and the variable renaming performed in b55ee979, as noted in #17374. - - - - - a7f423ee by Ben Gamari at 2019-10-29T20:31:36-04:00 gitlab-ci: Use pxz to compress binary distributions - - - - - db602643 by Ben Gamari at 2019-10-29T20:31:36-04:00 Don't include settings file in binary distribution The configuration in the installation environment (as determined by `autoconf`) may differ from the build environment and therefore we need to be sure to rebuild the settings file. Fixes #17374. - - - - - 260e2379 by Ben Gamari at 2019-10-29T20:31:36-04:00 gitlab-ci: Fix binary distribution testing - - - - - 01ef3e1f by Ömer Sinan Ağacan at 2019-10-29T20:32:18-04:00 Interpreter: initialize arity fields of AP_NOUPDs AP_NOUPD entry code doesn't use the arity field, but not initializing this field confuses printers/debuggers, and also makes testing harder as the field's value changes randomly. - - - - - 93ff9197 by Ben Gamari at 2019-10-30T07:36:49-04:00 rts: More aarch64 header fixes - - - - - 3e7569bc by Vladislav Zavialov at 2019-10-30T07:36:50-04:00 Whitespace forward compatibility for proposal #229 GHC Proposal #229 changes the lexical rules of Haskell, which may require slight whitespace adjustments in certain cases. This patch changes formatting in a few places in GHC and its testsuite in a way that enables it to compile under the proposed rules. - - - - - 4898df1c by Ben Gamari at 2019-10-30T18:15:52-04:00 gitlab-ci: Fix the ARMv7 triple Previously we were configuring the ARMv7 builds with a host/target triple of arm-linux-gnueabihf, which caused us to target ARMv6 and consequently rely on the old CP15 memory barrier implementation. This barrier has to be emulated on ARMv8 machines which is glacially slow. Hopefully this should fix the ARMv7 builds which currently consistently time out. - - - - - 337e9b5a by Ömer Sinan Ağacan at 2019-10-31T19:01:54-04:00 Remove redundant 0s in ghc-heap pointer strings Before: 0x0000004200c86888 After: 0x42000224f8 This is more concise and consistent with the RTS's printer (which uses %p formatter, and at least on Linux gcc prints the short form) and gdb's pointer formatter. - - - - - 97b6f7a3 by Ben Gamari at 2019-10-31T19:02:32-04:00 base: Clamp IO operation size to 2GB on Darwin As reported in #17414, Darwin throws EINVAL in response to large writes. - - - - - a9743eb7 by Ben Gamari at 2019-10-31T19:02:32-04:00 testsuite: Add test for #17414 - - - - - 73d6e508 by Ben Gamari at 2019-10-31T19:03:10-04:00 base: Various haddock fixes Just a few things I found while looking at #17383. - - - - - dc487642 by taylorfausak at 2019-11-01T04:54:47-04:00 Implement `round` for `Ratio` that doesn't explode with `Natural`s - - - - - 3932fb97 by taylorfausak at 2019-11-01T04:54:47-04:00 Fix rounding around 0 - - - - - baf47ff8 by taylorfausak at 2019-11-01T04:54:47-04:00 Add tests for rounding ratios - - - - - 214d8122 by taylorfausak at 2019-11-01T04:54:47-04:00 Fix running of ratio test case - - - - - 70b62c97 by Ben Gamari at 2019-11-01T04:55:24-04:00 mmap: Factor out protection flags - - - - - c6759080 by Ben Gamari at 2019-11-01T04:55:24-04:00 rts: Make m32 allocator per-ObjectCode MacOS Catalina is finally going to force our hand in forbidden writable exeutable mappings. Unfortunately, this is quite incompatible with the current global m32 allocator, which mixes symbols from various objects in a single page. The problem here is that some of these symbols may not yet be resolved (e.g. had relocations performed) as this happens lazily (and therefore we can't yet make the section read-only and therefore executable). The easiest way around this is to simply create one m32 allocator per ObjectCode. This may slightly increase fragmentation for short-running programs but I suspect will actually improve fragmentation for programs doing lots of loading/unloading since we can always free all of the pages allocated to an object when it is unloaded (although this ability will only be implemented in a later patch). - - - - - 35c99e72 by Simon Peyton Jones at 2019-11-01T04:56:02-04:00 Makes Lint less chatty: I found in #17415 that Lint was printing out truly gigantic warnings, unmanageably huge, with repeated copies of the same thing. This patch makes Lint less chatty, especially for warnings: * For **warnings**, I don't print details of the location, unless you add `-dppr-debug`. * For **errors**, I still print all the info. They are fatal and stop exection, whereas warnings appear repeatedly. * I've made much less use of `AnExpr` in `LintLocInfo`; the expression can be gigantic. - - - - - d2471964 by Simon Peyton Jones at 2019-11-01T04:56:38-04:00 Add another test for #17267 This one came in a comment from James Payor - - - - - 1e2e82aa by Simon Peyton Jones at 2019-11-01T04:57:15-04:00 Fix a bad error in tcMatchTy This patch fixes #17395, a very subtle and hard-to-trigger bug in tcMatchTy. It's all explained in Note [Matching in the presence of casts (2)] I have not added a regression test because it is very hard to trigger it, until we have the upcoming mkAppTyM patch, after which lacking this patch means you can't even compile the libraries. - - - - - 51067194 by Ben Gamari at 2019-11-01T15:48:37-04:00 base: Ensure that failIO isn't SOURCE imported failIO has useful information in its demand signature (specifically that it bottoms) which is hidden if it is SOURCE imported, as noted in #16588. Rejigger things such that we don't SOURCE import it. Metric Increase: T13701 - - - - - c751082c by Ben Gamari at 2019-11-01T15:48:37-04:00 testsuite: Make ExplicitForAllRules1 more robust Previously the test relied on `id` not inlining. Fix this. - - - - - dab12c87 by Ben Gamari at 2019-11-01T15:48:37-04:00 Describe optimisation of demand analysis of noinline As described in #16588. - - - - - c9236384 by Adam Sandberg Eriksson at 2019-11-01T15:49:16-04:00 template-haskell: require at least 1 GADT constructor name (#17379) - - - - - a4ce26e0 by Ben Gamari at 2019-11-01T15:49:53-04:00 hadrian: Make runtest invocation consistency with Make Use True/False instead of 0/1. This shouldn't be a functional change but we should be consistent. - - - - - cabafe34 by Ben Gamari at 2019-11-01T15:50:29-04:00 testsuite: Add test for #17423 - - - - - 4a6d3d68 by Simon Peyton Jones at 2019-11-01T23:11:37-04:00 Make CSE delay inlining less CSE delays inlining a little bit, to avoid losing vital specialisations; see Note [Delay inlining after CSE] in CSE. But it was being over-enthusiastic. This patch makes the delay only apply to Ids with specialisation rules, which avoids unnecessary delay (#17409). - - - - - 01006bc7 by Niklas Hambüchen at 2019-11-01T23:12:17-04:00 doc: Fix backticks - - - - - 9980fb58 by Niklas Hambüchen at 2019-11-01T23:12:17-04:00 Add +RTS --disable-delayed-os-memory-return. Fixes #17411. Sets `MiscFlags.disableDelayedOsMemoryReturn`. See the added `Note [MADV_FREE and MADV_DONTNEED]` for details. - - - - - 182b1199 by Sebastian Graf at 2019-11-02T20:16:33-04:00 Separate `LPat` from `Pat` on the type-level Since the Trees That Grow effort started, we had `type LPat = Pat`. This is so that `SrcLoc`s would only be annotated in GHC's AST, which is the reason why all GHC passes use the extension constructor `XPat` to attach source locations. See #15495 for the design discussion behind that. But now suddenly there are `XPat`s everywhere! There are several functions which dont't cope with `XPat`s by either crashing (`hsPatType`) or simply returning incorrect results (`collectEvVarsPat`). This issue was raised in #17330. I also came up with a rather clean and type-safe solution to the problem: We define ```haskell type family XRec p (f :: * -> *) = r | r -> p f type instance XRec (GhcPass p) f = Located (f (GhcPass p)) type instance XRec TH f = f p type LPat p = XRec p Pat ``` This is a rather modular embedding of the old "ping-pong" style, while we only pay for the `Located` wrapper within GHC. No ping-ponging in a potential Template Haskell AST, for example. Yet, we miss no case where we should've handled a `SrcLoc`: `hsPatType` and `collectEvVarsPat` are not callable at an `LPat`. Also, this gets rid of one indirection in `Located` variants: Previously, we'd have to go through `XPat` and `Located` to get from `LPat` to the wrapped `Pat`. Now it's just `Located` again. Thus we fix #17330. - - - - - 3c916162 by Richard Eisenberg at 2019-11-02T20:17:13-04:00 Update Note references -- comments only Follow-on from !2041. - - - - - 3b65655c by Ben Gamari at 2019-11-04T03:40:31-05:00 SysTools: Only apply Windows-specific workaround on Windows Issue #1110 was apparently due to a bug in Vista which prevented GCC from finding its binaries unless we explicitly added it to PATH. However, this workaround was incorrectly applied on non-Windows platforms as well, resulting in ill-formed PATHs (#17266). Fixes #17266. - - - - - 5d4f16ee by Leif Metcalf at 2019-11-04T03:41:09-05:00 Rephrase note on full-laziness - - - - - 120f2e53 by Ben Gamari at 2019-11-04T03:41:44-05:00 rts/linker: Ensure that code isn't writable For many years the linker would simply map all of its memory with PROT_READ|PROT_WRITE|PROT_EXEC. However operating systems have been becoming increasingly reluctant to accept this practice (e.g. #17353 and #12657) and for good reason: writable code is ripe for exploitation. Consequently mmapForLinker now maps its memory with PROT_READ|PROT_WRITE. After the linker has finished filling/relocating the mapping it must then call mmapForLinkerMarkExecutable on the sections of the mapping which contain executable code. Moreover, to make all of this possible it was necessary to redesign the m32 allocator. First, we gave (in an earlier commit) each ObjectCode its own m32_allocator. This was necessary since code loading and symbol resolution/relocation are currently interleaved, meaning that it is not possible to enforce W^X when symbols from different objects reside in the same page. We then redesigned the m32 allocator to take advantage of the fact that all of the pages allocated with the allocator die at the same time (namely, when the owning ObjectCode is unloaded). This makes a number of things simpler (e.g. no more page reference counting; the interface provided by the allocator for freeing is simpler). See Note [M32 Allocator] for details. - - - - - 7c28087a by Takenobu Tani at 2019-11-05T02:45:31-05:00 users-guide: Improve documentaion of CPP extension Currently, the description of CPP extension is given in the section of command-line options. Therefore, it is a little difficult to understand that it is a language extension. This commit explicitly adds a description for it. [skip ci] - - - - - d57059f7 by Ben Gamari at 2019-11-05T02:46:10-05:00 rts: Add missing const in HEAP_ALLOCED_GC This was previously unnoticed as this code-path is hit on very few platforms (e.g. OpenBSD). - - - - - 487ede42 by Peter Trommler at 2019-11-05T02:46:48-05:00 testsuite: skip test requiring RTS linker on PowerPC The RTS linker is not available on 64-bit PowerPC. Instead of marking tests that require the RTS linker as broken on PowerPC 64-bit skip the respective tests on all platforms where the RTS linker or a statically linked external interpreter is not available. Fixes #11259 - - - - - 1593debf by Sebastian Graf at 2019-11-05T11:38:30-05:00 Check EmptyCase by simply adding a non-void constraint We can handle non-void constraints since !1733, so we can now express the strictness of `-XEmptyCase` just by adding a non-void constraint to the initial Uncovered set. For `case x of {}` we thus check that the Uncovered set `{ x | x /~ ⊥ }` is non-empty. This is conceptually simpler than the plan outlined in #17376, because it talks to the oracle directly. In order for this patch to pass the testsuite, I had to fix handling of newtypes in the pattern-match checker (#17248). Since we use a different code path (well, the main code path) for `-XEmptyCase` now, we apparently also handle #13717 correctly. There's also some dead code that we can get rid off now. `provideEvidence` has been updated to provide output more in line with the old logic, which used `inhabitationCandidates` under the hood. A consequence of the shift away from the `UncoveredPatterns` type is that we don't report reduced type families for empty case matches, because the pretty printer is pure and only knows the match variable's type. Fixes #13717, #17248, #17386 - - - - - e6ffe148 by Ömer Sinan Ağacan at 2019-11-05T11:39:13-05:00 TidyPgm: replace an explicit loop with mapAccumL - - - - - b7460492 by Ömer Sinan Ağacan at 2019-11-05T11:39:13-05:00 CoreTidy: hide tidyRule - - - - - f9978f53 by Stefan Schulze Frielinghaus at 2019-11-05T11:39:51-05:00 Hadrian: enable interpreter for s390x - - - - - 3ce18700 by Ben Gamari at 2019-11-06T08:05:57-05:00 rts: Drop redundant flags for libffi These are now handled in the cabal file's include-dirs field. - - - - - ce9e2a1a by Ben Gamari at 2019-11-06T08:05:57-05:00 configure: Add --with-libdw-{includes,libraries} flags Fixing #17255. - - - - - 97f9674b by Takenobu Tani at 2019-11-06T08:06:37-05:00 configure: Add checking python3-sphinx This checks the configuration about python3-sphinx. We need python3-sphinx instead of python2-sphinx to build documentation. The approach is as follows: * Check python3 version with custom `conf.py` invoked from sphinx-build` executable * Place custom `conf.py` into new `utils/check-sphinx` directory If sphinx is for python2 not python3, it's treated as config ERROR instead of WARN. See also #17346 and #17356. - - - - - b4fb2328 by Dan Brooks at 2019-11-06T08:07:15-05:00 Adding examples to Semigroup/monoid - - - - - 708c60aa by Ryan Scott at 2019-11-07T08:39:36-05:00 Clean up TH's treatment of unary tuples (or, #16881 part two) !1906 left some loose ends in regards to Template Haskell's treatment of unary tuples. This patch ends to tie up those loose ends: * In addition to having `TupleT 1` produce unary tuples, `TupE [exp]` and `TupP [pat]` also now produce unary tuples. * I have added various special cases in GHC's pretty-printers to ensure that explicit 1-tuples are printed using the `Unit` type. See `testsuite/tests/th/T17380`. * The GHC 8.10.1 release notes entry has been tidied up a little. Fixes #16881. Fixes #17371. Fixes #17380. - - - - - a424229d by Stefan Schulze Frielinghaus at 2019-11-07T08:40:13-05:00 For s390x issue a warning if LLVM 9 or older is used For s390x the GHC calling convention is only supported since LLVM version 10. Issue a warning in case an older version of LLVM is used. - - - - - 55bc3787 by Ben Gamari at 2019-11-07T08:40:50-05:00 FlagChecker: Add ticky flags to hashed flags These affect output and therefore should be part of the flag hash. - - - - - fa0b1b4b by Stefan Schulze Frielinghaus at 2019-11-07T08:41:33-05:00 Bump libffi-tarballs submodule - - - - - a9566632 by Takenobu Tani at 2019-11-07T08:42:15-05:00 configure: Modify ERROR to WARN for sphinx's python check If sphinx's python version check failed, many people prefer to build without documents instead of stopping on the error. So this commit fixes the following: * Modify AC_MSG_ERROR to AC_MSG_WARN * Add clearing of SPHINXBUILD variable when check fails See also !2016. - - - - - d0ef8312 by Alp Mestanogullari at 2019-11-07T21:24:59-05:00 hadrian: fix support for the recording of perf test results Before this patch, Hadrian didn't care about the TEST_ENV and METRICS_FILE environment variables, that the performance testing infrastructure uses to record perf tests results from CI jobs. It now looks them up right before running the testsuite driver, and passes suitable --test-env/--metrics-file arguments when these environment variables are set. - - - - - 601e554c by Ben Gamari at 2019-11-07T21:25:36-05:00 Bump the process submodule This should fix the #17108 and #17249 with the fix from https://github.com/haskell/process/pull/159. - - - - - 6b7d7e1c by Ben Gamari at 2019-11-07T21:25:36-05:00 Bump hsc2hs submodule - - - - - b1c158c9 by Ben Gamari at 2019-11-07T21:25:36-05:00 rts: Fix m32 allocator build on Windows An inconsistency in the name of m32_allocator_flush caused the build to fail with a missing prototype error. - - - - - ae431cf4 by Ben Gamari at 2019-11-07T21:25:36-05:00 rts: Ensure that Rts.h is always included first In general this is the convention that we use in the RTS. On Windows things actually fail if we break it. For instance, you see things like: includes\stg\Types.h:26:9: error: warning: #warning "Mismatch between __USE_MINGW_ANSI_STDIO definitions. If using Rts.h make sure it is the first header included." [-Wcpp] - - - - - 0d141d28 by Ben Gamari at 2019-11-07T21:25:36-05:00 rts: Remove undesireable inline specifier I have no idea why I marked this as inline originally but clearly it shouldn't be inlined. - - - - - 870376f9 by Ben Gamari at 2019-11-07T21:25:36-05:00 base: Add missing imports in Windows locking implementation - - - - - 23994738 by Ben Gamari at 2019-11-07T21:25:36-05:00 rts/NonMoving: Fix various Windows build issues The Windows build seems to be stricter about not providing threading primitives in the non-threaded RTS. - - - - - a3ce52fd by Ben Gamari at 2019-11-07T21:25:36-05:00 users_guide: Set flags list file encoding Otherwise this fails on Windows. - - - - - 9db2e905 by Stefan Schulze Frielinghaus at 2019-11-08T05:36:54-05:00 Testsuite: Introduce req_rts_linker Some tests depend on the RTS linker. Introduce a modifier to skip such tests, in case the RTS linker is not available. - - - - - a4631335 by Szymon Nowicki-Korgol at 2019-11-08T05:37:34-05:00 Set correct length of DWARF .debug_aranges section (fixes #17428) - - - - - 3db2ab30 by Ben Gamari at 2019-11-08T05:38:11-05:00 hadrian: Add enableTickyGhc helper This took a bit of trial-and-error to get working so it seems worth having in the tree. - - - - - 5c87ebd7 by Ben Gamari at 2019-11-08T12:09:22-05:00 SetLevels: Don't set context level when floating cases When floating a single-alternative case we previously would set the context level to the level where we were floating the case. However, this is wrong as we are only moving the case and its binders. This resulted in #16978, where the disrepancy caused us to unnecessarily abstract over some free variables of the case body, resulting in shadowing and consequently Core Lint failures. (cherry picked from commit a2a0e6f3bb2d02a9347dec4c7c4f6d4480bc2421) - - - - - 43623b09 by Ben Gamari at 2019-11-08T12:10:01-05:00 testsuite: Run tests in nonmoving_thr in speed==slow - - - - - 6e4656cc by Ben Gamari at 2019-11-08T12:10:01-05:00 rts/nonmoving: Catch failure of createOSThread - - - - - 2e4fc04b by Ben Gamari at 2019-11-08T12:10:01-05:00 Bump unix submodule Marks executeFile001 as broken in all concurrent ways. - - - - - 8a10f9fb by Ben Gamari at 2019-11-09T18:03:01-05:00 template-haskell: Document assembler foreign file support See #16180. - - - - - 5ad3cb53 by Ben Gamari at 2019-11-09T18:03:01-05:00 template-haskell: Fix TBAs in changelog - - - - - 4a75a832 by Ben Gamari at 2019-11-09T18:03:01-05:00 base: Fix TBA in changelog - - - - - d7de0d81 by Ryan Scott at 2019-11-09T18:03:02-05:00 template-haskell: Fix italics in changelog [ci-skip] - - - - - 0fb246c3 by Ben Gamari at 2019-11-09T18:03:37-05:00 testsuite: Fix Windows cleanup path This was a regression introduced with the Path refactoring. - - - - - 925fbdbb by Ben Gamari at 2019-11-09T18:03:37-05:00 testsuite: Skip T16916 on Windows The event manager is not supported on Windows. - - - - - 7c2ce0a0 by Ben Gamari at 2019-11-09T18:03:38-05:00 testsuite: Skip T14931 on Windows This test uses -dynamic-too, which is not supported on Windows. - - - - - 7c63edb4 by Ben Gamari at 2019-11-09T18:03:38-05:00 gitlab-ci: Don't allow Windows make job to fail While linking is still slow (#16084) all of the correctness issues which were preventing us from being able to enforce testsuite-green on Windows are now resolved. - - - - - a50ecda6 by Ben Gamari at 2019-11-09T18:03:38-05:00 testsuite: Fix header #include order on Windows <Rts.h> must always come first. - - - - - dcb23ec9 by Ben Gamari at 2019-11-09T18:03:38-05:00 testsuite: Mark T13676 as broken on Darwin and Windows Due to #17447. - - - - - 411ba7ba by Ben Gamari at 2019-11-09T18:03:38-05:00 testsuite: Mark T11627b as fragile It was previously marked as broken due to #12236 however it passes for me locally while failing on CI. - - - - - c1f1f3f9 by Ben Gamari at 2019-11-09T18:03:38-05:00 testsuite: Mark T16219 as unbroken This was previously broken due to #16386 yet it passes for me locally. - - - - - 1f871e70 by Ben Gamari at 2019-11-09T18:03:38-05:00 testsuite: Remove redundant cleaning logic from T16511 The GHCi script for T16511 had some `rm` commands to clean up output from previous runs. This should be harmless since stderr was redirected to /dev/null; however, it seems that this redirection doesn't work on Windows (perhaps because GHCi uses `cmd` to execute the command-line; I'm not sure). I tried to fix it but was unable to find a sensible solution. Regardless, the cleaning logic is quite redundant now that we run each test in a hermetic environment. Let's just remove it. - - - - - 4d523cb1 by Ben Gamari at 2019-11-09T18:03:38-05:00 testsuite: Mark T17414 as fragile on Windows This consistently times out on Windows as described in #17453. I have tried increasing the timeout multiplier to two yet it stills fails. Disabling until we have time to investigate. - - - - - f73fbd2d by Ben Gamari at 2019-11-09T18:03:38-05:00 testsuite: Ignore stderr in PartialDownsweep As described in #17449, PartialDownsweep is currently fragile due to its dependence on the error messages produced by the C preprocessor. To eliminate this dependence we simply ignore stderr output, instead relying on the fact that the test will exit with a non-zero exit code on failure. Fixes #17449. - - - - - a9b14790 by Ben Gamari at 2019-11-09T18:03:38-05:00 testsuite: Fix putStrLn in saks028 Bizarrely, `saks028` previously failed reliably, but only on Windows (#17450). The test would exit with a zero exit code but simply didn't emit the expected text to stderr. I believe this was due to the fact that the test used `putStrLn`, resulting in the output ending up on stdout. This worked on other platforms since (apparently) we redirect stdout to stderr when evaluating splices. However, on Windows it seems that the redirected output wasn't flushed as it was on other platforms. Anyways, it seems like the right thing to do here is to be explicit about our desire for the output to end up on stderr. Closes #17450. - - - - - b62ca659 by Ben Gamari at 2019-11-09T18:03:38-05:00 testsuite: Drop T7995 This test is quite sensitive to the build configuration as it requires that ghc have unfoldings, which isn't true in the quick build flavours. I considered various options to make the test more robust but none of them seemed particularly appealing. Moreover, Simon PJ was a bit skeptical of the value of the test to begin with and I strongly suspect that any regression in #7995 would be accompanied by failures in our other compiler performance tests. Closes #17399. - - - - - 011f3121 by Ben Gamari at 2019-11-09T18:03:38-05:00 testsuite: Mark T16219 as fragile on Windows As noted in #17452, this test produces very long file paths which exceed the Windows MAX_PATH limitation. Mark the test as fragile for not until we can come up with a better solution. - - - - - 1f98e47d by Simon Peyton Jones at 2019-11-09T18:04:14-05:00 Use the right type in :force A missing prime meant that we were considering the wrong type in the GHCi debugger, when doing :force on multiple arguments (issue #17431). The fix is trivial. - - - - - 1f911de4 by Brian Wignall at 2019-11-09T18:04:57-05:00 Add IsList instance for ZipList (closes #17433) - - - - - e3672f40 by Brian Wignall at 2019-11-09T18:04:57-05:00 Incorporate MR review suggestions; add change in changelog - - - - - 3957bdf2 by Brian Wignall at 2019-11-09T18:04:57-05:00 Fix incorrect plurals - - - - - 6f4c1250 by Alina Banerjee at 2019-11-10T01:06:12-05:00 Improve SPECIALIZE pragma error messages (Fixes #12126) - - - - - fa25c8c4 by Richard Eisenberg at 2019-11-10T01:06:48-05:00 Update release notes about #16512 / #17405. - - - - - 55ca1085 by Richard Eisenberg at 2019-11-10T01:06:48-05:00 Fix #17405 by not checking imported equations Previously, we checked all imported type family equations for injectivity. This is very silly. Now, we check only for conflicts. Before I could even imagine doing the fix, I needed to untangle several functions that were (in my opinion) overly complicated. It's still not quite as perfect as I'd like, but it's good enough for now. Test case: typecheck/should_compile/T17405 - - - - - a9467f4f by Ben Gamari at 2019-11-10T21:06:33-05:00 testsuite: Mark tests fragile in threaded2 as fragile in all concurrent ways - - - - - 3e07ea8d by Ben Gamari at 2019-11-10T21:10:30-05:00 testsuite: Use small allocation area when measuring residency As suggested in #17387; this helps reduce the variance in our residency sampling. Metric Increase: T10370 T3586 lazy-bs-alloc Metric Decrease 'compile_time/peak_megabytes_allocated': T1969 Metric Decrease 'runtime/bytes allocated': space_leak_001 Metric Increase 'compile_time/bytes allocated': T1969 Metric Increase 'runtime/peak_megabytes_allocated': space_leak_001 Metric Decrease: T3064 T9675 - - - - - 049d9ae0 by Ben Gamari at 2019-11-10T21:10:30-05:00 testsuite: Don't check_stats at runtime if not requested Previously we would call check_stats to check the runtime metrics even if the test definition hadn't requested it. This would result in an error since the .stats file doesn't exist. - - - - - 64433428 by Alp Mestanogullari at 2019-11-11T08:49:01-05:00 hadrian: export METRICS_FILE to make it accessible to perf notes script This addresses #17456 and also fixes the --metrics-file argument that Hadrian passes to the testsuite driver. - - - - - 06640394 by Ben Gamari at 2019-11-11T08:50:45-05:00 testsuite: Disable T4334 in nonmoving_thr way - - - - - f8ec32d7 by Alp Mestanogullari at 2019-11-11T11:36:44-05:00 ci: push perf test metrics even when the testsuite doesn't pass The corresponding commit might introduce a regression on a perf test, in which case we certainly want to record it. The testsuite might also fail because of a test unrelated to performance, in which case we want to record that the perf test results were good. Either way, we likely want to record them under all circumstances but we don't without this patch. Metric Decrease: T3586 Metric Increase: lazy-bs-alloc - - - - - 643d42fc by Alp Mestanogullari at 2019-11-12T18:40:19-05:00 testsuite: don't collect compiler stats in collect_runtime_residency We instead want to collect the runtime stats (with collect_stats, instead of collect_compiler_stats). This should fix a number of perf tests failures we have been seeing, where we suddenly started measuring metrics we didn't intend to measure, which tend to fall outside of the acceptance window. Metric Decrease: lazy-bs-alloc T3586 Metric Increase: space_leak_001 T4801 T5835 T12791 - - - - - 535d0edc by Ömer Sinan Ağacan at 2019-11-13T07:06:12-05:00 Document CmmTopInfo type [ci skip] - - - - - 2d4f9ad8 by Ben Gamari at 2019-11-13T07:06:49-05:00 Ensure that coreView/tcView are able to inline Previously an import cycle between Type and TyCoRep meant that several functions in TyCoRep ended up SOURCE import coreView. This is quite unfortunate as coreView is intended to be fused into a larger pattern match and not incur an extra call. Fix this with a bit of restructuring: * Move the functions in `TyCoRep` which depend upon things in `Type` into `Type` * Fold contents of `Kind` into `Type` and turn `Kind` into a simple wrapper re-exporting kind-ish things from `Type` * Clean up the redundant imports that popped up as a result Closes #17441. Metric Decrease: T4334 - - - - - b795637f by Alp Mestanogullari at 2019-11-13T07:07:28-05:00 hadrian: fix Windows CI script By only using 'export' from within bash commands. - - - - - 6885e22c by Ben Gamari at 2019-11-13T07:08:03-05:00 testsuite: Add test for #17458 As noted in #17458, QuantifiedConstraints and UndecideableInstances could previously be used to write programs which can loop at runtime. This was fixed in !1870. - - - - - b4b19d89 by Ben Gamari at 2019-11-13T07:08:03-05:00 users guide: Fix broken link - - - - - 9a939a6c by Ryan Scott at 2019-11-13T07:08:40-05:00 Print name prefixly in the Outputable instance for StandaloneKindSig Issue #17461 was occurring because the `Outputable` instance for standalone kind signatures was simply calling `ppr` on the name in the kind signature, which does not add parentheses to infix names. The solution is simple: use `pprPrefixOcc` instead. Fixes #17461. - - - - - a06cfb59 by Ömer Sinan Ağacan at 2019-11-13T07:09:18-05:00 Only pass mod_location with HscRecomp instead of the entire ModSummary HscRecomp users only need the ModLocation of the module being compiled, so only pass that to users instead of the entire ModSummary Metric Decrease: T4801 - - - - - dd49b3f0 by Ben Gamari at 2019-11-13T17:01:21-05:00 Bump Haskeline and add exceptions as boot library Haskeline now depends upon exceptions. See #16752. - - - - - b06b1858 by Ben Gamari at 2019-11-14T11:30:20-05:00 base: Bump version to 4.14.0.0 Metric Increase: T4801 - - - - - 6ab80439 by Ben Gamari at 2019-11-14T23:05:30-05:00 gitlab-ci: Allow Windows to fail again - - - - - 46afc380 by Ben Gamari at 2019-11-15T09:45:36-05:00 gitlab-ci: Install process to global pkgdb before starting build This is an attempt to mitigate #17480 by ensuring that a functional version of the process library is available before attempting the build. - - - - - 8c5cb806 by Ben Gamari at 2019-11-15T10:45:55-05:00 Bump supported LLVM version to 9.0 - - - - - 8e5851f0 by Ben Gamari at 2019-11-15T10:45:55-05:00 llvm-targets: Update with Clang 9 - - - - - f3ffec27 by Ben Gamari at 2019-11-15T11:54:26-05:00 testsuite: Increase acceptance window of T4801 This statistic is rather unstable. Hopefully fixes #17475. - - - - - c2991f16 by Ben Gamari at 2019-11-15T11:56:10-05:00 users-guide: Drop 8.6.1 release notes - - - - - e8da1354 by Ben Gamari at 2019-11-17T06:48:16-05:00 gitlab-ci: Fix submodule linter We ran it against the .git directory despite the fact that the linter wants to be run against the repository. - - - - - 13290f91 by Ben Gamari at 2019-11-17T06:48:16-05:00 Bump version to 8.10.0 Bumps haddock submodule. - - - - - fa98f823 by Ben Gamari at 2019-11-17T06:48:16-05:00 testsuite: Don't collect residency for T4801 I previously increased the size of the acceptance window from 2% to 5% but this still isn't enough. Regardless, measuring bytes allocated should be sufficient to catch any regressions. - - - - - 002b2842 by Ivan Kasatenko at 2019-11-17T06:49:22-05:00 Make test 16916 more stable across runs - - - - - ca89dd3b by Ben Gamari at 2019-11-17T06:58:17-05:00 users-guide: Address #17329 Adopts the language suggested by @JakobBruenker. - - - - - 2f5ed225 by Ben Gamari at 2019-11-17T07:16:32-05:00 exceptions: Bump submodule back to master The previous commit hasn't made it to master yet. - - - - - 34515e7c by nineonine at 2019-11-17T13:33:22-08:00 Fix random typos [skip ci] - - - - - 4a37a29b by Mario Blažević at 2019-11-17T17:26:24-05:00 Fixed issue #17435, missing Data instances - - - - - 97f1bcae by Andreas Klebinger at 2019-11-17T17:26:24-05:00 Turn some comments into GHC.Hs.Utils into haddocks - - - - - cf7f8e5b by Ben Gamari at 2019-11-17T17:26:26-05:00 testsuite: Skip T17414 on Linux It is typical for $TMP to be a small tmpfson Linux. This test will fail in such cases since we must create a file larger than the filesystem. See #17459. - - - - - 88013b78 by nineonine at 2019-11-19T11:53:16-05:00 Optimize MonadUnique instances based on IO (#16843) Metric Decrease: T14683 - - - - - a8adb5b4 by Ben Gamari at 2019-11-19T11:53:55-05:00 desugar: Drop stale Note [Matching seqId] The need for this note vanished in eae703aa60f41fd232be5478e196b661839ec3de. - - - - - 08d595c0 by Ben Gamari at 2019-11-19T11:53:55-05:00 Give seq a more precise type and remove magic `GHC.Prim.seq` previously had the rather plain type: seq :: forall a b. a -> b -> b However, it also had a special typing rule to applications where `b` is not of kind `Type`. Issue #17440 noted that levity polymorphism allows us to rather give it the more precise type: seq :: forall (r :: RuntimeRep) a (b :: TYPE r). a -> b -> b This allows us to remove the special typing rule that we previously required to allow applications on unlifted arguments. T9404 contains a non-Type application of `seq` which should verify that this works as expected. Closes #17440. - - - - - ec8a463d by Viktor Dukhovni at 2019-11-19T11:54:45-05:00 Enable USE_PTHREAD_FOR_ITIMER also on FreeBSD If using a pthread instead of a timer signal is more reliable, and has no known drawbacks, then FreeBSD is also capable of supporting this mode of operation (tested on FreeBSD 12 with GHC 8.8.1, but no reason why it would not also work on FreeBSD 11 or GHC 8.6). Proposed by Kevin Zhang in: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=241849 - - - - - cd40e12a by Ömer Sinan Ağacan at 2019-11-19T11:55:36-05:00 Packages.hs: use O(n*log(n)) ordNub instead of O(n*n) nub As reported in #8173 in some environments package lists can get quite long, so we use more efficient ordNub instead of nub on package lists. - - - - - 2b27cc16 by Ben Gamari at 2019-11-19T11:56:21-05:00 Properly account for libdw paths in make build system Should finally fix #17255. - - - - - 0418c38d by Ben Gamari at 2019-11-19T11:56:58-05:00 rts: Add missing include of SymbolExtras.h This broke the Windows build. - - - - - c819c0e4 by Ben Gamari at 2019-11-19T11:57:36-05:00 nonmoving: Use correct info table pointer accessor Previously we used INFO_PTR_TO_STRUCT instead of THUNK_INFO_PTR_TO_STRUCT when looking at a thunk. These two happen to be equivalent on 64-bit architectures due to alignment considerations however they are different on 32-bit platforms. This lead to #17487. To fix this we also employ a small optimization: there is only one thunk of type WHITEHOLE (namely stg_WHITEHOLE_info). Consequently, we can just use a plain pointer comparison instead of testing against info->type. - - - - - deed8e31 by Ben Gamari at 2019-11-19T11:57:36-05:00 nonmoving: Fix incorrect masking in mark queue type test We were using TAG_BITS instead of TAG_MASK. This happened to work on 64-bit platforms where TAG_BITS==3 since we only use tag values 0 and 3. However, this broken on 32-bit platforms where TAG_BITS==2. - - - - - 097f8072 by Ben Gamari at 2019-11-19T11:57:36-05:00 nonmoving: Rework mark queue representation The previous representation needlessly limited the array length to 16-bits on 32-bit platforms. - - - - - eb7b233a by Ben Gamari at 2019-11-19T11:57:36-05:00 nonmoving: Fix handling on large object marking on 32-bit Previously we would reset the pointer pointing to the object to be marked to the beginning of the block when marking a large object. This did no harm on 64-bit but on 32-bit it broke, e.g. `arr020`, since we align pinned ByteArray allocations such that the payload is 8 byte-aligned. This means that the object might not begin at the beginning of the block., - - - - - a7571a74 by Ben Gamari at 2019-11-19T11:57:36-05:00 testsuite: Increase width of stack003 test Previously the returned tuple seemed to fit in registers on amd64. This meant that non-moving collector bug would cause the test to fail on i386 yet not amd64. - - - - - 098d5017 by Ben Gamari at 2019-11-19T11:57:36-05:00 nonmoving: Drop redundant write barrier on stack underflow Previously we would push stack-carried return values to the new stack on a stack overflow. While the precise reasoning for this barrier is unfortunately lost to history, in hindsight I suspect it was prompted by a missing barrier elsewhere (that has been since fixed). Moreover, there the redundant barrier is actively harmful: the stack may contain non-pointer values; blindly pushing these to the mark queue will result in a crash. This is precisely what happened in the `stack003` test. However, because of a (now fixed) deficiency in the test this crash did not trigger on amd64. - - - - - e57b7cc6 by Roland Zumkeller at 2019-11-19T20:39:19-05:00 Changing Thread IDs from 32 bits to 64 bits. - - - - - d1f3c637 by Roland Zumkeller at 2019-11-19T20:39:19-05:00 Use pointer equality in Eq/Ord for ThreadId Changes (==) to use only pointer equality. This is safe because two threads are the same iff they have the same id. Changes `compare` to check pointer equality first and fall back on ids only in case of inequality. See discussion in #16761. - - - - - ef8a08e0 by Alexey Kuleshevich at 2019-11-19T20:39:20-05:00 hpc: Fix encoding issues. Add test for and fix #17073 * Make sure files are being read/written in UTF-8. Set encoding while writing HTML output. Also set encoding while writing and reading .tix files although we don't yet have a ticket complaining that this poses problems. * Set encoding in html header to utf8 * Upgrade to new version of 'hpc' library and reuse `readFileUtf8` and `writeFileUtf8` functions * Update git submodule for `hpc` * Bump up `hpc` executable version Co-authored-by: Ben Gamari <ben at smart-cactus.org> - - - - - b79e46d6 by Vladislav Zavialov at 2019-11-19T20:39:20-05:00 Strip parentheses in expressions contexts in error messages This makes error messages a tad less noisy. - - - - - 13bbde77 by Ben Gamari at 2019-11-21T13:56:56-05:00 Bump hsc2hs submodule Including Phyx's backport of the process changes fixing #17480. - - - - - d4d10501 by Ben Gamari at 2019-11-23T09:42:38-05:00 Bump hsc2hs submodule again This fixes the Darwin build. - - - - - 889d475b by nineonine at 2019-11-23T18:53:29-05:00 Fix typo in Note reference [skip ci] - - - - - 8a33abfc by Ryan Scott at 2019-11-23T18:54:05-05:00 Target the IsList instance for ZipList at base-4.14.0.0 (#17489) This moves the changelog entry about the instance from `base-4.15.0.0` to `base-4.14.0.0`. This accomplishes part (1) from #17489. [ci skip] - - - - - e43e6ece by Ben Gamari at 2019-11-23T18:54:41-05:00 rts: Expose interface for configuring EventLogWriters This exposes a set of interfaces from the GHC API for configuring EventLogWriters. These can be used by consumers like [ghc-eventlog-socket](https://github.com/bgamari/ghc-eventlog-socket). - - - - - de6bbdf2 by Matheus Magalhães de Alcantara at 2019-11-23T18:55:23-05:00 Take care to not eta-reduce jumps in CorePrep CorePrep already had a check to prevent it from eta-reducing Ids that respond true to hasNoBinding (foreign calls, constructors for unboxed sums and products, and Ids with compulsory unfoldings). It did not, however, consider join points as ids that 'must be saturated'. Checking whether the Id responds True to 'isJoinId' should prevent CorePrep from turning saturated jumps like the following (from #17429) into undersaturated ones: (\ eta_XP -> join { mapped_s1vo _ = lvl_s1vs } in jump mapped_s1vo eta_XP) - - - - - 4a1e7e47 by Matheus Magalhães de Alcantara at 2019-11-23T18:55:23-05:00 Make CorePrep.tryEtaReducePrep and CoreUtils.tryEtaReduce line up Simon PJ says he prefers this fix to #17429 over banning eta-reduction for jumps entirely. Sure enough, this also works. Test case: simplCore/should_compile/T17429.hs - - - - - 15f1dc33 by Ryan Scott at 2019-11-23T18:56:00-05:00 Prevent -optc arguments from being duplicated in reverse order (#17471) This reverts a part of commit 7bc5d6c6578ab9d60a83b81c7cc14819afef32ba that causes all arguments to `-optc` (and `-optcxx`) to be passed twice to the C/C++ compiler, once in reverse order and then again in the correct order. While passing duplicate arguments is usually harmless it can cause breakage in this pattern, which is employed by Hackage libraries in the wild: ``` ghc Foo.hs foo.c -optc-D -optcFOO ``` As `FOO -D -D FOO` will cause compilers to error. Fixes #17471. - - - - - e85c9b22 by Ben Gamari at 2019-11-23T18:56:36-05:00 Bump ghc version to 8.11 - - - - - 0e6c2045 by Ben Gamari at 2019-11-23T18:57:12-05:00 rts: Consolidate spinlock implementation Previously we had two distinct implementations: one with spinlock profiling and another without. This seems like needless duplication. - - - - - cb11fcb5 by Ben Gamari at 2019-11-23T18:57:49-05:00 Packages: Don't use expectJust Throw a slightly more informative error on failure. Motivated by the errors seen in !2160. - - - - - 5747ebe9 by Sebastian Graf at 2019-11-23T18:58:25-05:00 Stricten functions ins GHC.Natural This brings `Natural` on par with `Integer` and fixes #17499. Also does some manual CSE for 0 and 1 literals. - - - - - c14b723f by Ömer Sinan Ağacan at 2019-11-23T18:59:06-05:00 Bump exceptions submodule Adds a few files generated by GHC's configure script to .gitignore - - - - - 7b4c7b75 by Brian Wignall at 2019-11-23T19:04:52-05:00 Fix typos - - - - - 6008206a by Viktor Dukhovni at 2019-11-24T14:33:18-05:00 On FreeBSD 12 sys/sysctl.h requires sys/types.h Else build fails with: In file included from ExecutablePath.hsc:42: /usr/include/sys/sysctl.h:1062:25: error: unknown type name 'u_int'; did you mean 'int'? int sysctl(const int *, u_int, void *, size_t *, const void *, size_t); ^~~~~ int compiling libraries/base/dist-install/build/System/Environment/ExecutablePath_hsc_make.c failed (exit code 1) Perhaps also also other FreeBSD releases, but additional include will no harm even if not needed. - - - - - b694b566 by Ben Gamari at 2019-11-24T14:33:54-05:00 configure: Fix HAVE_C11_ATOMICS macro Previously we were using AC_DEFINE instead of AC_DEFINE_UNQUOTED, resulted in the variable not being interpolated. Fixes #17505. - - - - - 8b8dc366 by Krzysztof Gogolewski at 2019-11-25T14:37:38+01:00 Remove prefix arrow support for GADTs (#17211) This reverts the change in #9096. The specialcasing done for prefix (->) is brittle and does not support VTA, type families, type synonyms etc. - - - - - 5a08f7d4 by Sebastian Graf at 2019-11-27T00:14:59-05:00 Make warnings for TH splices opt-in In #17270 we have the pattern-match checker emit incorrect warnings. The reason for that behavior is ultimately an inconsistency in whether we treat TH splices as written by the user (`FromSource :: Origin`) or as generated code (`Generated`). This was first reported in #14838. The current solution is to TH splices as `Generated` by default and only treat them as `FromSource` when the user requests so (-fenable-th-splice-warnings). There are multiple reasons for opt-in rather than opt-out: * It's not clear that the user that compiles a splice is the author of the code that produces the warning. Think of the situation where she just splices in code from a third-party library that produces incomplete pattern matches. In this scenario, the user isn't even able to fix that warning. * Gathering information for producing the warnings (pattern-match check warnings in particular) is costly. There's no point in doing so if the user is not interested in those warnings. Fixes #17270, but not #14838, because the proper solution needs a GHC proposal extending the TH AST syntax. - - - - - 8168b42a by Vladislav Zavialov at 2019-11-27T11:32:18+03:00 Whitespace-sensitive bang patterns (#1087, #17162) This patch implements a part of GHC Proposal #229 that covers five operators: * the bang operator (!) * the tilde operator (~) * the at operator (@) * the dollar operator ($) * the double dollar operator ($$) Based on surrounding whitespace, these operators are disambiguated into bang patterns, lazy patterns, strictness annotations, type applications, splices, and typed splices. This patch doesn't cover the (-) operator or the -Woperator-whitespace warning, which are left as future work. - - - - - 9e5477c4 by Ryan Scott at 2019-11-27T20:01:50-05:00 Fix @since annotations for isResourceVanishedError and friends (#17488) - - - - - e122ba33 by Sergei Trofimovich at 2019-11-27T20:02:29-05:00 .gitmodules: tweak 'exception' URL to avoid redirection warnings Avoid initial close warning of form: ``` Cloning into 'exceptions'... warning: redirecting to https://gitlab.haskell.org/ghc/packages/exceptions.git/ ``` Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - 5f84b52a by Philipp Krüger at 2019-11-28T02:54:05-05:00 Reduce boolean blindness in OccInfo(OneOcc) #17482 * Transformed the type aliases `InterestingCxt`, `InsideLam` and `OneBranch` into data types. * Added Semigroup and Monoid instances for use in orOccInfo in OccurAnal.hs * Simplified some usage sites by using pattern matching instead of boolean algebra. Metric Increase: T12150 This increase was on a Mac-build of exactly 1%. This commit does *not* re-intruduce the asymptotic memory usage described in T12150. - - - - - 3748ba3a by Brian Wignall at 2019-11-28T02:54:52-05:00 Fix typos, using Wikipedia list of common typos - - - - - 6c59cc71 by Stefan Schulze Frielinghaus at 2019-11-28T02:55:33-05:00 Fix endian handling of LLVM backend Get rid of CPP macro WORDS_BIGENDIAN which is not defined anymore, and replace it by DynFlag. This fixes partially #17337. - - - - - 6985e0fc by Vladislav Zavialov at 2019-11-28T15:47:53+03:00 Factor out HsSCC/HsCoreAnn/HsTickPragma into HsPragE This is a refactoring with no user-visible changes (except for GHC API users). Consider the HsExpr constructors that correspond to user-written pragmas: HsSCC representing {-# SCC ... #-} HsCoreAnn representing {-# CORE ... #-} HsTickPragma representing {-# GENERATED ... #-} We can factor them out into a separate datatype, HsPragE. It makes the code a bit tidier, especially in the parser. Before this patch: hpc_annot :: { Located ( (([AddAnn],SourceText),(StringLiteral,(Int,Int),(Int,Int))), ((SourceText,SourceText),(SourceText,SourceText)) ) } After this patch: prag_hpc :: { Located ([AddAnn], HsPragE GhcPs) } - - - - - 7f695a20 by Ömer Sinan Ağacan at 2019-11-29T08:25:28-05:00 Pass ModDetails with (partial) ModIface in HscStatus (Partial) ModIface and ModDetails are generated at the same time, but they're passed differently: ModIface is passed in HscStatus consturctors while ModDetails is returned in a tuple. This refactors ModDetails passing so that it's passed around with ModIface in HscStatus constructors. This makes the code more consistent and hopefully easier to understand: ModIface and ModDetails are really very closely related. It makes sense to treat them the same way. - - - - - e921c90f by Ömer Sinan Ağacan at 2019-11-29T08:26:07-05:00 Improve few Foreign.Marshal.Utils docs In copyBytes and moveBytes mention which argument is source and which is destination. Also fixes some of the crazy indentation in the module and cleans trailing whitespace. - - - - - 316f2431 by Sebastian Graf at 2019-11-30T02:57:58-05:00 Hadrian docs: Rename the second "validate" entry to "slow-validate" [ci skip] That would be in line with the implementation. - - - - - 5aba5d32 by Vladislav Zavialov at 2019-11-30T02:58:34-05:00 Remove HasSrcSpan (#17494) Metric Decrease: haddock.compiler - - - - - d1de5c22 by Sylvain Henry at 2019-11-30T02:59:13-05:00 Use Hadrian by default in validate script (#17527) - - - - - 3a96a0b6 by Sebastian Graf at 2019-11-30T02:59:55-05:00 Simpler Semigroup instance for InsideLam and InterestingCtxt This mirrors the definition of `(&&)` and `(||)` now, relieving the Simplifier of a marginal amount of pressure. - - - - - f8cfe81a by Roland Senn at 2019-11-30T20:33:49+01:00 Improve tests for #17171 While backporting MR !1806 to 8.8.2 (!1885) I learnt the following: * Tests with `expect_fail` do not compare `*.stderr` output files. So a test using `expect_fail` will not detect future regressions on the `stderr` output. * To compare the `*.stderr` output files, I have to use the `exit_code(n)` function. * When a release is made, tests with `makefile_test` are converted to use `run_command`. * For the test `T17171a` the return code is `1` when running `makefile_test`, however it's `2` when running `run_command`. Therefore I decided: * To improve my tests for #17171 * To change test T17171a from `expect_fail` to `exit_code(2)` * To change both tests from `makefile_test` to `run_command` - - - - - 2b113fc9 by Vladislav Zavialov at 2019-12-01T08:17:05-05:00 Update DisambECP-related comments - - - - - beed7c3e by Ben Gamari at 2019-12-02T03:41:37-05:00 testsuite: Fix location of typing_stubs module This should fix the build on Debian 8. - - - - - 53251413 by Ben Gamari at 2019-12-02T03:42:14-05:00 testsuite: Don't override LD_LIBRARY_PATH, only prepend NixOS development environments often require that LD_LIBRARY_PATH be set in order to find system libraries. T1407 was overriding LD_LIBRARY_PATH, dropping these directories. Now it merely prepends, its directory. - - - - - 65400314 by Krzysztof Gogolewski at 2019-12-02T03:42:57-05:00 Convert warnings into assertions Since the invariants always hold in the testsuite, we can convert them to asserts. - - - - - 18baed64 by Alan Zimmerman at 2019-12-02T03:43:37-05:00 API Annotations: Unicode '->' on HsForallTy The code fragment type family Proxy2' ∷ ∀ k → k → Type where Proxy2' = Proxy' Generates AnnRarrow instead of AnnRarrowU for the first →. Fixes #17519 - - - - - 717f3236 by Brian Wignall at 2019-12-02T03:44:16-05:00 Fix more typos - - - - - bde48f8e by Ben Gamari at 2019-12-02T11:55:34-05:00 More Haddock syntax in GHC.Hs.Utils As suggested by RyanGlScott in !2163. - - - - - 038bedbc by Ben Gamari at 2019-12-02T11:56:18-05:00 Simplify: Fix pretty-printing of strictness A colleague recently hit the panic in Simplify.addEvals and I noticed that the message is quite unreadable due to incorrect pretty-printing. Fix this. - - - - - c500f652 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Fix changelog linting logic - - - - - 8ead967d by Ben Gamari at 2019-12-02T11:56:54-05:00 win32-init: Drop workaround for #17480 The `process` changes have now been merged into `hsc2hs`. (cherry picked from commit fa029f53132ad59f847ed012d3b835452cf16615) - - - - - d402209a by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Disable Sphinx build on Debian 8 The docutils version available appears to be too old to support the `table` directive's `:widths:` options. (cherry picked from commit 75764487a96a7a026948b5af5022781872d12baa) - - - - - f1f68824 by Ben Gamari at 2019-12-02T11:56:54-05:00 base: Fix <unistd.h> #include Previously we were including <sys/unistd.h> which is available on glibc but not musl. (cherry picked from commit e44b695ca7cb5f3f99eecfba05c9672c6a22205e) - - - - - 37eb94b3 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Bump Docker images Installs pxz on Centos7 (cherry picked from commit 86960e691f7a600be247c32a7cf795bf9abf7cc4) - - - - - aec98a79 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: pxz is unavailable on CentOS 7 Fall back to xz - - - - - 6708b8e5 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Set LANG on CentOS 7 It otherwise seems to default to ascii - - - - - 470ef0e7 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Consolidate release build configuration - - - - - 38338757 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Add Debian 10 builds - - - - - 012f13b5 by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Fix Windows bindist collection Apparently variable interpolation in the `artifacts.paths` key of `gitlab-ci.yml` doesn't work on Windows as it does on WIndows. (cherry picked from commit 100cc756faa4468ed6950116bae30609c1c3468b) - - - - - a0f09e23 by Ben Gamari at 2019-12-02T11:56:54-05:00 testsuite: Simplify Python <3.5 fallback for TextIO (cherry picked from commit d092d8598694c23bc07cdcc504dff52fa5f33be1) - - - - - 2b2370ec by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Add release-x86_64-linux-deb9 job (cherry picked from commit cbedb3c4a90649f474cb716842ba53afc5a642ca) - - - - - b1c206fd by Ben Gamari at 2019-12-02T11:56:54-05:00 gitlab-ci: Always build source tarball (cherry picked from commit 67b5de88ef923971f1980335137e3c7193213abd) - - - - - 4cbd5b47 by Sergei Trofimovich at 2019-12-02T11:57:33-05:00 configure.ac: make cross-compiler detection stricter Be more precise at detecting cross-compilation case. Before the change configuration $ ./configure --host=x86_64-pc-linux-gnu --target=x86_64-gentoo-linux-musl was not considered a cross-target. Even though libcs are different (`glibc` vs. `musl`). Without this patch build fails as: ``` "inplace/bin/ghc-cabal" check libraries/integer-gmp "inplace/bin/ghc-cabal" configure libraries/integer-gmp dist-install \ --with-ghc="/home/slyfox/dev/git/ghc/inplace/bin/ghc-stage1" \ --with-ghc-pkg="/home/slyfox/dev/git/ghc/inplace/bin/ghc-pkg" \ --disable-library-for-ghci --enable-library-vanilla --enable-library-for-ghci \ --enable-library-profiling --enable-shared --with-hscolour="/usr/bin/HsColour" \ --configure-option=CFLAGS="-Wall \ -Werror=unused-but-set-variable -Wno-error=inline \ -iquote /home/slyfox/dev/git/ghc/libraries/integer-gmp" \ --configure-option=LDFLAGS=" " --configure-option=CPPFLAGS=" \ " --gcc-options="-Wall -Werror=unused-but-set-variable -Wno-error=inline -iquote /home/slyfox/dev/git/ghc/libraries/integer-gmp \ " --with-gcc="x86_64-gentoo-linux-musl-gcc" --with-ld="x86_64-gentoo-linux-musl-ld.gold" --with-ar="x86_64-gentoo-linux-musl-ar" \ --with-alex="/usr/bin/alex" --with-happy="/usr/bin/happy" Configuring integer-gmp-1.0.2.0... configure: WARNING: unrecognized options: --with-compiler checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu checking for gcc... /usr/lib/ccache/bin/x86_64-gentoo-linux-musl-gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... configure: error: in `/home/slyfox/dev/git/ghc/libraries/integer-gmp/dist-install/build': configure: error: cannot run C compiled programs. If you meant to cross compile, use `--host'. See `config.log' for more details make[1]: *** [libraries/integer-gmp/ghc.mk:5: libraries/integer-gmp/dist-install/package-data.mk] Error 1 make: *** [Makefile:126: all] Error 2 ``` Note: here `ghc-stage1` is assumed to target `musl` target but is passed `glibc` toolchain. It happens because initial ./configure phase did not detect host/target as different. Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - 5f7cb423 by Sylvain Henry at 2019-12-02T23:59:29-05:00 Add `timesInt2#` primop - - - - - fbbe18a2 by Sylvain Henry at 2019-12-02T23:59:29-05:00 Use the new timesInt2# primop in integer-gmp (#9431) - - - - - 5a4b8d0c by Athas at 2019-12-03T00:00:09-05:00 Document RTS behaviour upon encountering '--'. - - - - - 705a16df by Ben Gamari at 2019-12-03T07:11:33-05:00 Make BCO# lifted In #17424 Simon PJ noted that there is a potentially unsafe occurrence of unsafeCoerce#, coercing from an unlifted to lifted type. However, nowhere in the compiler do we assume that a BCO# is not a thunk. Moreover, in the case of a CAF the result returned by `createBCO` *will* be a thunk (as noted in [Updatable CAF BCOs]). Consequently it seems better to rather make BCO# a lifted type and rename it to BCO. - - - - - 35afe4f3 by Sylvain Henry at 2019-12-03T07:12:13-05:00 Use Int# primops in `Bits Int{8,16,32,64}` instances - - - - - 7a51b587 by Sylvain Henry at 2019-12-03T07:12:13-05:00 Add constant folding rule (#16402) narrowN (x .&. m) m .&. (2^N-1) = 2^N-1 ==> narrowN x e.g. narrow16 (x .&. 0x12FFFF) ==> narrow16 x - - - - - 10caee7f by Ben Gamari at 2019-12-03T21:04:50-05:00 users-guide: Add 8.12.1 release notes - - - - - 25019d18 by Ben Gamari at 2019-12-03T21:04:50-05:00 Drop Uniquable constraint for AnnTarget This relied on deriveUnique, which was far too subtle to be safely applied. Thankfully the instance doesn't appear to be used so let's just drop it. - - - - - 78b67ad0 by Ben Gamari at 2019-12-03T21:04:50-05:00 Simplify uniqAway This does two things: * Eliminate all uses of Unique.deriveUnique, which was quite easy to mis-use and extremely subtle. * Rename the previous "derived unique" notion to "local unique". This is possible because the only places where `uniqAway` can be safely used are those where local uniqueness (with respect to some InScopeSet) is sufficient. * Rework the implementation of VarEnv.uniqAway, as discussed in #17462. This should make the operation significantly more efficient than its previous iterative implementation.. Metric Decrease: T9872c T12227 T9233 T14683 T5030 T12545 hie002 Metric Increase: T9961 - - - - - f03a41d4 by Ben Gamari at 2019-12-03T21:05:27-05:00 Elf: Fix link info note generation Previously we would use the `.int` assembler directive to generate 32-bit words in the note section. However, `.int` is note guaranteed to produce 4-bytes; in fact, on some platforms (e.g. AArch64) it produces 8-bytes. Use the `.4bytes` directive to avoid this. Moreover, we used the `.align` directive, which is quite platform dependent. On AArch64 it appears to not even be idempotent (despite what the documentation claims). `.balign` is consequentially preferred as it offers consistent behavior across platforms. - - - - - 84585e5e by Vladislav Zavialov at 2019-12-05T16:07:44-05:00 Meaning-preserving SCC annotations (#15730) This patch implements GHC Proposal #176: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0176-scc-parsing.rst Before the change: 1 / 2 / 2 = 0.25 1 / {-# SCC "name" #-} 2 / 2 = 1.0 After the change: 1 / 2 / 2 = 0.25 1 / {-# SCC "name" #-} 2 / 2 = parse error - - - - - e49e5470 by Vladislav Zavialov at 2019-12-05T16:07:44-05:00 Improve error messages for SCC pragmas - - - - - a2b535d9 by Ben Gamari at 2019-12-05T16:07:45-05:00 users guide: Try to silence underfull \hbox warnings We use two tricks, as suggested here [1]: * Use microtype to try to reduce the incidence of underfull boxes * Bump up \hbadness to eliminate the warnings - - - - - 4e47217f by Bodigrim at 2019-12-05T16:07:47-05:00 Make sameNat and sameSymbol proxy-polymorphic - - - - - 8324f0b7 by Bodigrim at 2019-12-05T16:07:47-05:00 Test proxy-polymorphic sameNat and sameSymbol - - - - - 69001f54 by Ben Gamari at 2019-12-05T16:07:48-05:00 nonmoving: Clear segment bitmaps during sweep Previously we would clear the bitmaps of segments which we are going to sweep during the preparatory pause. However, this is unnecessary: the existence of the mark epoch ensures that the sweep will correctly identify non-reachable objects, even if we do not clear the bitmap. We now defer clearing the bitmap to sweep, which happens concurrently with mutation. - - - - - 58a9c429 by Ben Gamari at 2019-12-05T16:07:48-05:00 testsuite: Disable divByZero on non-NCG targets The LLVM backend does not guarantee any particular semantics for division by zero, making this test unreliable across platforms. - - - - - 8280bd8a by Ben Gamari at 2019-12-05T16:07:49-05:00 testsuite: Factor out terminal coloring - - - - - 92a52aaa by Ben Gamari at 2019-12-05T16:07:49-05:00 testsuite: Make performance metric summary more readable Along with some refactoring. - - - - - c4ca29c7 by Ben Gamari at 2019-12-05T16:07:49-05:00 testsuite: Use colors more consistently - - - - - 3354c68e by Vladislav Zavialov at 2019-12-05T16:07:49-05:00 Pretty-printing of the * kind Before this patch, GHC always printed the * kind unparenthesized. This led to two issues: 1. Sometimes GHC printed invalid or incorrect code. For example, GHC would print: type F @* x = x when it meant to print: type F @(*) x = x In the former case, instead of a kind application we were getting a type operator (@*). 2. Sometimes GHC printed kinds that were correct but hard to read. Should Either * Int be read as Either (*) Int or as (*) Either Int ? This depends on whether -XStarIsType is enabled, but it would be easier if we didn't have to check for the flag when reading the code. We can solve both problems by assigning (*) a different precedence. Note that Haskell98 kinds are not affected: ((* -> *) -> *) -> * does NOT become (((*) -> (*)) -> (*)) -> (*) The parentheses are added when (*) is used in a function argument position: F * * * becomes F (*) (*) (*) F A * B becomes F A (*) B Proxy * becomes Proxy (*) a * -> * becomes a (*) -> * - - - - - 70dd0e4b by Vladislav Zavialov at 2019-12-05T16:07:49-05:00 Parenthesize the * kind in TH.Ppr - - - - - a7a4efbf by Ben Gamari at 2019-12-05T16:07:49-05:00 rts/NonMovingSweep: Fix locking of new mutable list allocation Previously we used allocBlockOnNode_sync in nonmovingSweepMutLists despite the fact that we aren't in the GC and therefore the allocation spinlock isn't in use. This meant that sweep would end up spinning until the next minor GC, when the SM lock was moved away from the SM_MUTEX to the spinlock. This isn't a correctness issue but it sure isn't good for performance. Found thanks for Ward. Fixes #17539. - - - - - f171b358 by Matthias Braun at 2019-12-05T16:07:51-05:00 Fix typo in documentation of Base.hs. - - - - - 9897e8c8 by Gabor Greif at 2019-12-06T21:20:38-05:00 Implement pointer tagging for big families (#14373) Formerly we punted on these and evaluated constructors always got a tag of 1. We now cascade switches because we have to check the tag first and when it is MAX_PTR_TAG then get the precise tag from the info table and switch on that. The only technically tricky part is that the default case needs (logical) duplication. To do this we emit an extra label for it and branch to that from the second switch. This avoids duplicated codegen. Here's a simple example of the new code gen: data D = D1 | D2 | D3 | D4 | D5 | D6 | D7 | D8 On a 64-bit system previously all constructors would be tagged 1. With the new code gen D7 and D8 are tagged 7: [Lib.D7_con_entry() { ... {offset c1eu: // global R1 = R1 + 7; call (P64[Sp])(R1) args: 8, res: 0, upd: 8; } }] [Lib.D8_con_entry() { ... {offset c1ez: // global R1 = R1 + 7; call (P64[Sp])(R1) args: 8, res: 0, upd: 8; } }] When switching we now look at the info table only when the tag is 7. For example, if we derive Enum for the type above, the Cmm looks like this: c2Le: _s2Js::P64 = R1; _c2Lq::P64 = _s2Js::P64 & 7; switch [1 .. 7] _c2Lq::P64 { case 1 : goto c2Lk; case 2 : goto c2Ll; case 3 : goto c2Lm; case 4 : goto c2Ln; case 5 : goto c2Lo; case 6 : goto c2Lp; case 7 : goto c2Lj; } // Read info table for tag c2Lj: _c2Lv::I64 = %MO_UU_Conv_W32_W64(I32[I64[_s2Js::P64 & (-8)] - 4]); if (_c2Lv::I64 != 6) goto c2Lu; else goto c2Lt; Generated Cmm sizes do not change too much, but binaries are very slightly larger, due to the fact that the new instructions are longer in encoded form. E.g. previously entry code for D8 above would be 00000000000001c0 <Lib_D8_con_info>: 1c0: 48 ff c3 inc %rbx 1c3: ff 65 00 jmpq *0x0(%rbp) With this patch 00000000000001d0 <Lib_D8_con_info>: 1d0: 48 83 c3 07 add $0x7,%rbx 1d4: ff 65 00 jmpq *0x0(%rbp) This is one byte longer. Secondly, reading info table directly and then switching is shorter _c1co: movq -1(%rbx),%rax movl -4(%rax),%eax // Switch on info table tag jmp *_n1d5(,%rax,8) than doing the same switch, and then for the tag 7 doing another switch: // When tag is 7 _c1ct: andq $-8,%rbx movq (%rbx),%rax movl -4(%rax),%eax // Switch on info table tag ... Some changes of binary sizes in actual programs: - In NoFib the worst case is 0.1% increase in benchmark "parser" (see NoFib results below). All programs get slightly larger. - Stage 2 compiler size does not change. - In "containers" (the library) size of all object files increases 0.0005%. Size of the test program "bitqueue-properties" increases 0.03%. nofib benchmarks kindly provided by Ömer (@osa1): NoFib Results ============= -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS +0.0% 0.0% -0.0% -0.0% -0.0% CSD +0.0% 0.0% 0.0% +0.0% +0.0% FS +0.0% 0.0% 0.0% +0.0% 0.0% S +0.0% 0.0% -0.0% 0.0% 0.0% VS +0.0% 0.0% -0.0% +0.0% +0.0% VSD +0.0% 0.0% -0.0% +0.0% -0.0% VSM +0.0% 0.0% 0.0% 0.0% 0.0% anna +0.0% 0.0% +0.1% -0.9% -0.0% ansi +0.0% 0.0% -0.0% +0.0% +0.0% atom +0.0% 0.0% 0.0% 0.0% 0.0% awards +0.0% 0.0% -0.0% +0.0% 0.0% banner +0.0% 0.0% -0.0% +0.0% 0.0% bernouilli +0.0% 0.0% +0.0% +0.0% +0.0% binary-trees +0.0% 0.0% -0.0% -0.0% -0.0% boyer +0.0% 0.0% +0.0% 0.0% -0.0% boyer2 +0.0% 0.0% +0.0% 0.0% -0.0% bspt +0.0% 0.0% +0.0% +0.0% 0.0% cacheprof +0.0% 0.0% +0.1% -0.8% 0.0% calendar +0.0% 0.0% -0.0% +0.0% -0.0% cichelli +0.0% 0.0% +0.0% 0.0% 0.0% circsim +0.0% 0.0% -0.0% -0.1% -0.0% clausify +0.0% 0.0% +0.0% +0.0% 0.0% comp_lab_zift +0.0% 0.0% +0.0% 0.0% -0.0% compress +0.0% 0.0% +0.0% +0.0% 0.0% compress2 +0.0% 0.0% 0.0% 0.0% 0.0% constraints +0.0% 0.0% -0.0% -0.0% -0.0% cryptarithm1 +0.0% 0.0% +0.0% 0.0% 0.0% cryptarithm2 +0.0% 0.0% +0.0% -0.0% 0.0% cse +0.0% 0.0% +0.0% +0.0% 0.0% digits-of-e1 +0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e2 +0.0% 0.0% +0.0% -0.0% -0.0% dom-lt +0.0% 0.0% +0.0% +0.0% 0.0% eliza +0.0% 0.0% -0.0% +0.0% 0.0% event +0.0% 0.0% -0.0% -0.0% -0.0% exact-reals +0.0% 0.0% +0.0% +0.0% +0.0% exp3_8 +0.0% 0.0% -0.0% -0.0% -0.0% expert +0.0% 0.0% +0.0% +0.0% +0.0% fannkuch-redux +0.0% 0.0% +0.0% 0.0% 0.0% fasta +0.0% 0.0% -0.0% -0.0% -0.0% fem +0.0% 0.0% +0.0% +0.0% +0.0% fft +0.0% 0.0% +0.0% -0.0% -0.0% fft2 +0.0% 0.0% +0.0% +0.0% +0.0% fibheaps +0.0% 0.0% +0.0% +0.0% 0.0% fish +0.0% 0.0% +0.0% +0.0% 0.0% fluid +0.0% 0.0% +0.0% +0.0% +0.0% fulsom +0.0% 0.0% +0.0% -0.0% +0.0% gamteb +0.0% 0.0% +0.0% -0.0% -0.0% gcd +0.0% 0.0% +0.0% +0.0% 0.0% gen_regexps +0.0% 0.0% +0.0% -0.0% -0.0% genfft +0.0% 0.0% -0.0% -0.0% -0.0% gg +0.0% 0.0% 0.0% -0.0% 0.0% grep +0.0% 0.0% +0.0% +0.0% +0.0% hidden +0.0% 0.0% +0.0% -0.0% -0.0% hpg +0.0% 0.0% +0.0% -0.1% -0.0% ida +0.0% 0.0% +0.0% -0.0% -0.0% infer +0.0% 0.0% -0.0% -0.0% -0.0% integer +0.0% 0.0% -0.0% -0.0% -0.0% integrate +0.0% 0.0% 0.0% +0.0% 0.0% k-nucleotide +0.0% 0.0% -0.0% -0.0% -0.0% kahan +0.0% 0.0% -0.0% -0.0% -0.0% knights +0.0% 0.0% +0.0% -0.0% -0.0% lambda +0.0% 0.0% +1.2% -6.1% -0.0% last-piece +0.0% 0.0% +0.0% -0.0% -0.0% lcss +0.0% 0.0% +0.0% -0.0% -0.0% life +0.0% 0.0% +0.0% -0.0% -0.0% lift +0.0% 0.0% +0.0% +0.0% 0.0% linear +0.0% 0.0% +0.0% +0.0% +0.0% listcompr +0.0% 0.0% -0.0% -0.0% -0.0% listcopy +0.0% 0.0% -0.0% -0.0% -0.0% maillist +0.0% 0.0% +0.0% -0.0% -0.0% mandel +0.0% 0.0% +0.0% +0.0% +0.0% mandel2 +0.0% 0.0% +0.0% +0.0% -0.0% mate +0.0% 0.0% +0.0% +0.0% +0.0% minimax +0.0% 0.0% -0.0% +0.0% -0.0% mkhprog +0.0% 0.0% +0.0% +0.0% +0.0% multiplier +0.0% 0.0% 0.0% +0.0% -0.0% n-body +0.0% 0.0% +0.0% -0.0% -0.0% nucleic2 +0.0% 0.0% +0.0% +0.0% -0.0% para +0.0% 0.0% +0.0% +0.0% +0.0% paraffins +0.0% 0.0% +0.0% +0.0% +0.0% parser +0.1% 0.0% +0.4% -1.7% -0.0% parstof +0.0% 0.0% -0.0% -0.0% -0.0% pic +0.0% 0.0% +0.0% 0.0% -0.0% pidigits +0.0% 0.0% -0.0% -0.0% -0.0% power +0.0% 0.0% +0.0% -0.0% -0.0% pretty +0.0% 0.0% +0.0% +0.0% +0.0% primes +0.0% 0.0% +0.0% 0.0% 0.0% primetest +0.0% 0.0% +0.0% +0.0% +0.0% prolog +0.0% 0.0% +0.0% +0.0% +0.0% puzzle +0.0% 0.0% +0.0% +0.0% +0.0% queens +0.0% 0.0% 0.0% +0.0% +0.0% reptile +0.0% 0.0% +0.0% +0.0% 0.0% reverse-complem +0.0% 0.0% -0.0% -0.0% -0.0% rewrite +0.0% 0.0% +0.0% 0.0% -0.0% rfib +0.0% 0.0% +0.0% +0.0% +0.0% rsa +0.0% 0.0% +0.0% +0.0% +0.0% scc +0.0% 0.0% +0.0% +0.0% +0.0% sched +0.0% 0.0% +0.0% +0.0% +0.0% scs +0.0% 0.0% +0.0% +0.0% 0.0% simple +0.0% 0.0% +0.0% +0.0% +0.0% solid +0.0% 0.0% +0.0% +0.0% 0.0% sorting +0.0% 0.0% +0.0% -0.0% 0.0% spectral-norm +0.0% 0.0% -0.0% -0.0% -0.0% sphere +0.0% 0.0% +0.0% -1.0% 0.0% symalg +0.0% 0.0% +0.0% +0.0% +0.0% tak +0.0% 0.0% +0.0% +0.0% +0.0% transform +0.0% 0.0% +0.4% -1.3% +0.0% treejoin +0.0% 0.0% +0.0% -0.0% 0.0% typecheck +0.0% 0.0% -0.0% +0.0% 0.0% veritas +0.0% 0.0% +0.0% -0.1% +0.0% wang +0.0% 0.0% +0.0% +0.0% +0.0% wave4main +0.0% 0.0% +0.0% 0.0% -0.0% wheel-sieve1 +0.0% 0.0% +0.0% +0.0% +0.0% wheel-sieve2 +0.0% 0.0% +0.0% +0.0% 0.0% x2n1 +0.0% 0.0% +0.0% +0.0% 0.0% -------------------------------------------------------------------------------- Min +0.0% 0.0% -0.0% -6.1% -0.0% Max +0.1% 0.0% +1.2% +0.0% +0.0% Geometric Mean +0.0% -0.0% +0.0% -0.1% -0.0% NoFib GC Results ================ -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- circsim +0.0% 0.0% -0.0% -0.0% -0.0% constraints +0.0% 0.0% -0.0% 0.0% -0.0% fibheaps +0.0% 0.0% 0.0% -0.0% -0.0% fulsom +0.0% 0.0% 0.0% -0.6% -0.0% gc_bench +0.0% 0.0% 0.0% 0.0% -0.0% hash +0.0% 0.0% -0.0% -0.0% -0.0% lcss +0.0% 0.0% 0.0% -0.0% 0.0% mutstore1 +0.0% 0.0% 0.0% -0.0% -0.0% mutstore2 +0.0% 0.0% +0.0% -0.0% -0.0% power +0.0% 0.0% -0.0% 0.0% -0.0% spellcheck +0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min +0.0% 0.0% -0.0% -0.6% -0.0% Max +0.0% 0.0% +0.0% 0.0% 0.0% Geometric Mean +0.0% +0.0% +0.0% -0.1% +0.0% Fixes #14373 These performance regressions appear to be a fluke in CI. See the discussion in !1742 for details. Metric Increase: T6048 T12234 T12425 Naperian T12150 T5837 T13035 - - - - - ee07421f by Simon Peyton Jones at 2019-12-06T21:21:14-05:00 Work in progress on coercionLKind, coercionRKind This is a preliminary patch for #17515 - - - - - 0a4ca9eb by Simon Peyton Jones at 2019-12-06T21:21:14-05:00 Split up coercionKind This patch implements the idea in #17515, splitting `coercionKind` into: * `coercion{Left,Right}Kind`, which computes the left/right side of the pair * `coercionKind`, which computes the pair of coercible types This is reduces allocation since we frequently only need only one side of the pair. Specifically, we see the following improvements on x86-64 Debian 9: | test | new | old | relative chg. | | :------- | ---------: | ------------: | ------------: | | T5030 | 695537752 | 747641152.0 | -6.97% | | T5321Fun | 449315744 | 474009040.0 | -5.21% | | T9872a | 2611071400 | 2645040952.0 | -1.28% | | T9872c | 2957097904 | 2994260264.0 | -1.24% | | T12227 | 773435072 | 812367768.0 | -4.79% | | T12545 | 3142687224 | 3215714752.0 | -2.27% | | T14683 | 9392407664 | 9824775000.0 | -4.40% | Metric Decrease: T12545 T9872a T14683 T5030 T12227 T9872c T5321Fun T9872b - - - - - d46a72e1 by Gabor Greif at 2019-12-09T12:05:15-05:00 Fix comment typos The below is only necessary to fix the CI perf fluke that happened in 9897e8c8ef0b19a9571ef97a1d9bb050c1ee9121: ------------------------- Metric Decrease: T5837 T6048 T9020 T12425 T12234 T13035 T12150 Naperian ------------------------- - - - - - e3bba7e4 by Micha Wiedenmann at 2019-12-10T19:52:44-05:00 users guide: Motivation of DefaultSignatures - - - - - 843ceb38 by Ben Gamari at 2019-12-10T19:53:54-05:00 rts: Add a long form flag to enable the non-moving GC The old flag, `-xn`, was quite cryptic. Here we add `--nonmoving-gc` in addition. - - - - - 921d3238 by Ryan Scott at 2019-12-10T19:54:34-05:00 Ignore unary constraint tuples during typechecking (#17511) We deliberately avoid defining a magical `Unit%` class, for reasons that I have expounded upon in the newly added `Note [Ignore unary constraint tuples]` in `TcHsType`. However, a sneaky user could try to insert `Unit%` into their program by way of Template Haskell, leading to the interface-file error observed in #17511. To avoid this, any time we encounter a unary constraint tuple during typechecking, we drop the surrounding constraint tuple application. This is safe to do since `Unit% a` and `a` would be semantically equivalent (unlike other forms of unary tuples). Fixes #17511. - - - - - 436ec9f3 by Ben Gamari at 2019-12-10T19:55:37-05:00 gitlab-ci: Move changelog linting logic to shell script Allowing it to be easily used locally. - - - - - 2f6b434f by Ben Gamari at 2019-12-10T19:55:37-05:00 gitlab-ci: Move changelog linting logic to shell script Allowing it to be easily used locally. - - - - - 7a5a6e07 by Ben Gamari at 2019-12-10T19:56:25-05:00 base: Fix incorrect @since in GHC.Natural Fixes #17547. - - - - - 2bbfaf8a by Ben Gamari at 2019-12-10T19:57:01-05:00 hadrian: AArch64 supports the GHCi interpreter and SMP I'm not sure how this was omitted from the list of supported architectures. - - - - - 8f1ceb67 by John Ericson at 2019-12-10T19:57:39-05:00 Move Int# section of primops.txt.pp This matches the organization of the fixed-sized ones, and keeps each Int* next to its corresponding Word*. - - - - - 7a823b0f by John Ericson at 2019-12-10T19:57:39-05:00 Move Int64# and Word64# sections of primops.txt.pp This way it is next to the other fixed-sized ones. - - - - - 8dd9929a by Ben Gamari at 2019-12-10T19:58:19-05:00 testsuite: Add (broken) test for #17510 - - - - - 6e47a76a by Ben Gamari at 2019-12-10T19:58:59-05:00 Re-layout validate script This script was previously a whitespace nightmare. - - - - - f80c4a66 by Crazycolorz5 at 2019-12-11T14:12:17-05:00 rts: Specialize hashing at call site rather than in struct. Separate word and string hash tables on the type level, and do not store the hashing function. Thus when a different hash function is desire it is provided upon accessing the table. This is worst case the same as before the change, and in the majority of cases is better. Also mark the functions for aggressive inlining to improve performance. {F1686506} Reviewers: bgamari, erikd, simonmar Subscribers: rwbarton, thomie, carter GHC Trac Issues: #13165 Differential Revision: https://phabricator.haskell.org/D4889 - - - - - 2d1b9619 by Richard Eisenberg at 2019-12-11T14:12:55-05:00 Warn on inferred polymorphic recursion Silly users sometimes try to use visible dependent quantification and polymorphic recursion without a CUSK or SAK. This causes unexpected errors. So we now adjust expectations with a bit of helpful messaging. Closes #17541 and closes #17131. test cases: dependent/should_fail/T{17541{,b},17131} - - - - - 4dde485e by Oleg Grenrus at 2019-12-12T02:24:46-05:00 Add --show-unit-ids flag to ghc-pkg I only added it into --simple-output and ghc-pkg check output; there are probably other places where it can be adopted. - - - - - e6e1ec08 by Ben Gamari at 2019-12-12T02:25:33-05:00 testsuite: Simplify and clarify performance test baseline search The previous implementation was extremely complicated, seemingly to allow the local and CI namespaces to be searched incrementally. However, it's quite unclear why this is needed and moreover the implementation seems to have had quadratic runtime cost in the search depth(!). - - - - - 29c4609c by Ben Gamari at 2019-12-12T02:26:19-05:00 testsuite: Add test for #17549 - - - - - 9f0ee253 by Ben Gamari at 2019-12-12T02:26:56-05:00 gitlab-ci: Move -dwarf and -debug jobs to full-build stage This sacrifices some precision in favor of improving parallelism. - - - - - 7179b968 by Ben Gamari at 2019-12-12T02:27:34-05:00 Revert "rts: Drop redundant flags for libffi" This seems to have regressed builds using `--with-system-libffi` (#17520). This reverts commit 3ce18700f80a12c48a029b49c6201ad2410071bb. - - - - - cc7d5650 by Oleg Grenrus at 2019-12-16T10:20:56+02:00 Having no shake upper bound is irresposible Given that shake is far from "done" API wise, and is central component to the build system. - - - - - 9431f905 by Oleg Grenrus at 2019-12-16T10:55:50+02:00 Add index-state to hadrian/cabal.project Then one is freer to omit upper bounds, as we won't pick any new entries on Hackage while building hadrian itself. - - - - - 3e17a866 by Krzysztof Gogolewski at 2019-12-16T19:31:44-05:00 Remove dataConSig As suggested in #17291 - - - - - 75355fde by Krzysztof Gogolewski at 2019-12-16T19:31:44-05:00 Use "OrCoVar" functions less As described in #17291, we'd like to separate coercions and expressions in a more robust fashion. This is a small step in this direction. - `mkLocalId` now panicks on a covar. Calls where this was not the case were changed to `mkLocalIdOrCoVar`. - Don't use "OrCoVar" functions in places where we know the type is not a coercion. - - - - - f9686e13 by Richard Eisenberg at 2019-12-16T19:32:21-05:00 Do more validity checks for quantified constraints Close #17583. Test case: typecheck/should_fail/T17563 - - - - - af763765 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Fix Windows artifact collection Variable interpolation in gitlab-ci.yml apparently doesn't work. Sigh. - - - - - e6d4b902 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Use xz --threads on Debian 10 - - - - - 8ba650e9 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Allow debian 8 build to fail The python release shipped with deb8 (3.3) is too old for our testsuite driver. - - - - - ac25a3f6 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Use xz --threads on Alpine - - - - - cc628088 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Another approach for xz detection - - - - - 37d788ab by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Re-add release-x86_64-deb9 job Also eliminate some redundancy. - - - - - f8279138 by Ben Gamari at 2019-12-16T19:33:01-05:00 gitlab-ci: Drop redundant release-x86_64-linux-deb9 job - - - - - 8148ff06 by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark cgrun057 as broken on ARMv7 Due to #17554. It's very surprising that this only occurs on ARMv7 but this is the only place I've seen this failure thusfar. - - - - - 85e5696d by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark prog001 as fragile on ARMv7 Due to #17555. - - - - - a5f0aab0 by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark T10272 as broken on ARMv7 Due to #17556. - - - - - 1e6827c6 by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark T13825-debugger as broken on ARMv7 Due to #17557. - - - - - 7cef0b7d by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark T14028 as broken on ARMv7 Due to #17558. - - - - - 6ea4eb4b by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Make ghc_built_by_llvm check more precise Previously it would hackily look at the flavour name to determine whether LLVM was used to build stage2 ghc. However, this didn't work at all with Hadrian and would miss cases like ARM where we use the LLVM backend by default. See #16087 for the motivation for why ghc_built_by_llvm is needed at all. This should catch one of the ARMv7 failures described in #17555. - - - - - c3e82bf7 by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark T5435_* tests as broken on ARM `T5435_v_asm_a`, `T5435_v_asm_b`, and `T5435_v_gcc` all fail on ARMv7. See #17559. - - - - - eb2aa851 by Ben Gamari at 2019-12-17T07:24:40-05:00 gitlab-ci: Don't allow armv7 jobs to fail - - - - - efc92216 by Ben Gamari at 2019-12-17T07:24:40-05:00 Revert "testsuite: Mark cgrun057 as broken on ARMv7" This reverts commit 6cfc47ec8a478e1751cb3e7338954da1853c3996. - - - - - 1d2bb9eb by Ben Gamari at 2019-12-17T07:24:40-05:00 testsuite: Mark print002 as fragile on ARM Due to #17557. Also accepting spurious performance change. Metric Decrease: T1969 - - - - - 41f4e4fb by Josh Meredith at 2019-12-17T07:25:17-05:00 Fix ambiguous occurence error when building Hadrian - - - - - 4374983a by Josh Meredith at 2019-12-17T07:25:17-05:00 Rename SphinxMode constructors - - - - - a8f7ecd5 by Josh Meredith at 2019-12-17T07:25:17-05:00 Use *Mode suffix instead of *M - - - - - 58655b9d by Sylvain Henry at 2019-12-18T13:43:37+01:00 Add GHC-API logging hooks * Add 'dumpAction' hook to DynFlags. It allows GHC API users to catch dumped intermediate codes and information. The format of the dump (Core, Stg, raw text, etc.) is now reported allowing easier automatic handling. * Add 'traceAction' hook to DynFlags. Some dumps go through the trace mechanism (for instance unfoldings that have been considered for inlining). This is problematic because: 1) dumps aren't written into files even with -ddump-to-file on 2) dumps are written on stdout even with GHC API 3) in this specific case, dumping depends on unsafe globally stored DynFlags which is bad for GHC API users We introduce 'traceAction' hook which allows GHC API to catch those traces and to avoid using globally stored DynFlags. * Avoid dumping empty logs via dumpAction/traceAction (but still write empty files to keep the existing behavior) - - - - - fad866e0 by Moritz Kiefer at 2019-12-19T11:15:39-05:00 Avoid race condition in hDuplicateTo In our codebase we have some code along the lines of ``` newStdout <- hDuplicate stdout stderr `hDuplicateTo` stdout ``` to avoid stray `putStrLn`s from corrupting a protocol (LSP) that is run over stdout. On CI we have seen a bunch of issues where `dup2` returned `EBUSY` so this fails with `ResourceExhausted` in Haskell. I’ve spent some time looking at the docs for `dup2` and the code in `base` and afaict the following race condition is being triggered here: 1. The user calls `hDuplicateTo stderr stdout`. 2. `hDuplicateTo` calls `hClose_help stdout_`, this closes the file handle for stdout. 3. The file handle for stdout is now free, so another thread allocating a file might get stdout. 4. If `dup2` is called while `stdout` (now pointing to something else) is half-open, it returns EBUSY. I think there might actually be an even worse case where `dup2` is run after FD 1 is fully open again. In that case, you will end up not just redirecting the original stdout to stderr but also the whatever resulted in that file handle being allocated. As far as I can tell, `dup2` takes care of closing the file handle itself so there is no reason to do this in `hDuplicateTo`. So this PR replaces the call to `hClose_help` by the only part of `hClose_help` that we actually care about, namely, `flushWriteBuffer`. I tested this on our codebase fairly extensively and haven’t been able to reproduce the issue with this patch. - - - - - 0c114c65 by Sylvain Henry at 2019-12-19T11:16:17-05:00 Handle large ARR_WORDS in heap census (fix #17572) We can do a heap census with a non-profiling RTS. With a non-profiling RTS we don't zero superfluous bytes of shrunk arrays hence a need to handle the case specifically to avoid a crash. Revert part of a586b33f8e8ad60b5c5ef3501c89e9b71794bbed - - - - - 1a0d1a65 by John Ericson at 2019-12-20T10:50:22-05:00 Deduplicate copied monad failure handler code - - - - - 70e56b27 by Ryan Scott at 2019-12-20T10:50:57-05:00 lookupBindGroupOcc: recommend names in the same namespace (#17593) Previously, `lookupBindGroupOcc`'s error message would recommend all similar names in scope, regardless of whether they were type constructors, data constructors, or functions, leading to the confusion witnessed in #17593. This is easily fixed by only recommending names in the same namespace, using the `nameSpacesRelated` function. Fixes #17593. - - - - - 3c12355e by Stefan Schulze Frielinghaus at 2019-12-24T01:03:44-05:00 Fix endian handling w.r.t. CPP macro WORDS_BIGENDIAN Include header file `ghcautoconf.h` where the CPP macro `WORDS_BIGENDIAN` is defined. This finally fixes #17337 (in conjunction with commit 6c59cc71dc). - - - - - 11f8eef5 by Stefan Schulze Frielinghaus at 2019-12-24T01:03:44-05:00 fixup! Fix endian handling w.r.t. CPP macro WORDS_BIGENDIAN - - - - - 40327b03 by Sylvain Henry at 2019-12-24T01:04:24-05:00 Remove outdated comment - - - - - aeea92ef by Sylvain Henry at 2019-12-25T19:23:54-05:00 Switch to ReadTheDocs theme for the user-guide - - - - - 26493eab by Gabor Greif at 2019-12-25T19:24:32-05:00 Fix copy-paste error in comment - - - - - 776df719 by Gabor Greif at 2019-12-25T19:24:32-05:00 Fix comment about minimal gcc version to be consistent what FP_GCC_VERSION requires - - - - - 3b17114d by Ömer Sinan Ağacan at 2019-12-26T14:09:11-05:00 Minor refactor in ghc.cabal.in: - Remove outdated comments - Move cutils.c from parser to cbits - Remove unused cutils.h - - - - - 334290b6 by Ryan Scott at 2019-12-26T14:09:48-05:00 Replace panic/notHandled with noExtCon in DsMeta There are many spots in `DsMeta` where `panic` or `notHandled` is used after pattern-matching on a TTG extension constructor. This is overkill, however, as using `noExtCon` would work just as well. This patch switches out these panics for `noExtCon`. - - - - - 68252aa3 by Ben Gamari at 2019-12-27T15:11:38-05:00 testsuite: Skip T17499 when built against integer-simple Since it routinely times out in CI. - - - - - 0c51aeeb by Gabor Greif at 2019-12-27T15:12:17-05:00 suppress popup dialog about missing Xcode at configure tested with `bash` and `zsh`. - - - - - 8d76bcc2 by Gabor Greif at 2019-12-27T15:12:17-05:00 while at it rename XCode to the official Xcode - - - - - 47a68205 by Ben Gamari at 2019-12-27T15:12:55-05:00 testsuite: Mark cgrun057 as fragile on ARM As reported in #17554. Only marking on ARM for now although there is evidence to suggest that the issue may occur on other platforms as well. - - - - - d03dec8f by Gabor Greif at 2019-12-27T15:13:32-05:00 use shell variable CcLlvmBackend for test Previously we used `AC_DEFINE`d variable `CC_LLVM_BACKEND` which has an empty shell expansion. - - - - - 2528e684 by Ben Gamari at 2019-12-30T06:51:32-05:00 driver: Include debug level in the recompilation check hash Fixes #17586. - - - - - f14bb50b by Ben Gamari at 2019-12-30T06:52:09-05:00 rts: Ensure that nonmoving gc isn't used with profiling - - - - - b426de37 by Ben Gamari at 2019-12-30T06:52:45-05:00 llvmGen: Ensure that entry labels don't have predecessors The LLVM IR forbids the entry label of a procedure from having any predecessors. In the case of a simple looping function the LLVM code generator broke this invariant, as noted in #17589. Fix this by moving the function prologue to its own basic block, as suggested by @kavon in #11649. Fixes #11649 and #17589. - - - - - 613f7265 by Ben Gamari at 2019-12-30T06:52:45-05:00 llvmGen: Drop old fix for #11649 This was a hack which is no longer necessary now since we introduce a dedicated entry block for each procedure. - - - - - fdeffa5e by Ben Gamari at 2019-12-30T06:53:23-05:00 rts: Error on invalid --numa flags Previously things like `+RTS --numa-debug` would enable NUMA support, despite being an invalid flag. - - - - - 9ce3ba68 by Ben Gamari at 2019-12-30T06:53:23-05:00 rts: Fix --debug-numa mode under Docker As noted in #17606, Docker disallows the get_mempolicy syscall by default. This caused numerous tests to fail under CI in the `debug_numa` way. Avoid this by disabling the NUMA probing logic when --debug-numa is in use, instead setting n_numa_nodes in RtsFlags.c. Fixes #17606. - - - - - 5baa2a43 by Ben Gamari at 2019-12-30T06:54:01-05:00 testsuite: Disable derefnull when built with LLVM LLVM does not guarantee any particular semantics when dereferencing null pointers. Consequently, this test actually passes when built with the LLVM backend. - - - - - bd544d3d by Ben Gamari at 2019-12-30T06:54:38-05:00 hadrian: Track hash of Cabal Setup builder arguments Lest we fail to rebuild when they change. Fixes #17611. - - - - - 6e2c495e by Ben Gamari at 2019-12-30T06:55:19-05:00 TcIface: Fix inverted logic in typechecking of source ticks Previously we would throw away source ticks when the debug level was non-zero. This is precisely the opposite of what was intended. Fixes #17616. Metric Decrease: T13056 T9020 T9961 T12425 - - - - - 7fad387d by Ben Gamari at 2019-12-30T06:55:55-05:00 perf_notes: Add --zero-y argument This makes it easier to see the true magnitude of fluctuations. Also do some house-keeping in the argument parsing department. - - - - - 0d42b287 by Ben Gamari at 2019-12-30T06:55:55-05:00 testsuite: Enlarge acceptance window for T1969 As noted in #17624, it's quite unstable, especially, for some reason, on i386 and armv7 (something about 32-bit platforms perhaps?). Metric Increase: T1969 - - - - - eb608235 by Sylvain Henry at 2019-12-31T14:22:32-05:00 Module hierarchy (#13009): Stg - - - - - d710fd66 by Vladislav Zavialov at 2019-12-31T14:23:10-05:00 Testsuite: update some Haddock tests Fixed tests: * haddockA039: added to all.T * haddockE004: replaced with T17561 (marked as expect_broken) New tests: * haddockA040: deriving clause for a data instance * haddockA041: haddock and CPP #include - - - - - 859ebdd4 by Kevin Buhr at 2019-12-31T23:44:39-05:00 Add "-Iw" RTS flag for minimum wait between idle GCs (#11134) - - - - - dd4b6551 by Kevin Buhr at 2019-12-31T23:44:39-05:00 Add additional Note explaining the -Iw flag - - - - - c4279ff1 by Kevin Buhr at 2019-12-31T23:44:39-05:00 Fix some sloppy indentation - - - - - b84c09d5 by Ömer Sinan Ağacan at 2019-12-31T23:45:19-05:00 Tweak Cmm dumps to avoid generating sections for empty groups When dumping Cmm groups check if the group is empty, to avoid generating empty sections in dump files like ==================== Output Cmm ==================== [] Also fixes a few bad indentation in the code around changes. - - - - - b2e0323f by Gabor Greif at 2020-01-03T21:22:36-05:00 Simplify mrStr - - - - - 3c9dc06b by Brian Wignall at 2020-01-04T15:55:06-05:00 Fix typos, via a Levenshtein-style corrector - - - - - d561c8f6 by Sylvain Henry at 2020-01-04T15:55:46-05:00 Add Cmm related hooks * stgToCmm hook * cmmToRawCmm hook These hooks are used by Asterius and could be useful to other clients of the GHC API. It increases the Parser dependencies (test CountParserDeps) to 184. It's still less than 200 which was the initial request (cf https://mail.haskell.org/pipermail/ghc-devs/2019-September/018122.html) so I think it's ok to merge this. - - - - - ae6b6276 by Oleg Grenrus at 2020-01-04T15:56:22-05:00 Update to Cabal submodule to v3.2.0.0-alpha3 Metric Increase: haddock.Cabal - - - - - 073f7cfd by Vladislav Zavialov at 2020-01-04T15:56:59-05:00 Add lexerDbg to dump the tokens fed to the parser This a small utility function that comes in handy when debugging the lexer and the parser. - - - - - 558d4d4a by Sylvain Henry at 2020-01-04T15:57:38-05:00 Split integerGmpInternals test in several parts This is to prepare for ghc-bignum which implements some but not all of gmp functions. - - - - - 4056b966 by Ben Gamari at 2020-01-04T15:58:15-05:00 testsuite: Mark cgrun057 as fragile on all platforms I have seen this fail both on x86-64/Debian 9 and armv7/Debian 9 See #17554. - - - - - 5ffea0c6 by Tamar Christina at 2020-01-06T18:38:37-05:00 Fix overflow. - - - - - 99a9f51b by Sylvain Henry at 2020-01-06T18:39:22-05:00 Module hierarchy: Iface (cf #13009) - - - - - 7aa4a061 by Ben Gamari at 2020-01-07T13:11:48-05:00 configure: Only check GCC version if CC is GCC Also refactor FP_GCC_EXTRA_FLAGS in a few ways: * We no longer support compilers which lack support for -fno-builtin and -fwrapv so remove the condition on GccVersion * These flags are only necessary when using the via-C backend so make them conditional on Unregisterised. Fixes #15742. - - - - - 0805ed7e by John Ericson at 2020-01-07T13:12:25-05:00 Use non-empty lists to remove partiality in matching code - - - - - 7844f3a8 by Ben Gamari at 2020-01-07T13:13:02-05:00 testsuite: Mark T17073 as broken on Windows Due to #17607. - - - - - acf40cae by Ben Gamari at 2020-01-07T13:13:02-05:00 gitlab-ci: Disallow Windows from failing - - - - - 34bc02c7 by Ben Gamari at 2020-01-07T13:13:02-05:00 configure: Find Python3 for testsuite In addition, we prefer the Mingw64 Python distribution on Windows due to #17483. - - - - - e35fe8d5 by Ben Gamari at 2020-01-07T13:13:02-05:00 testsuite: Fix Windows platform test Previously we used platform.system() and while this worked fine (e.g. returned `Windows`, as expected) locally under both msys and MingW64 Python distributions, it inexplicably returned `MINGW64_NT-10.0` under MingW64 Python on CI. It seems os.name is more reliable so we now use that instead.. - - - - - 48ef6217 by Ben Gamari at 2020-01-07T13:13:39-05:00 gitlab-ci: Rename push-test-metrics.sh to test-metrics.sh Refactoring to follow. - - - - - 2234fa92 by Ben Gamari at 2020-01-07T13:13:39-05:00 gitlab-ci: Pull test metrics before running testsuite Otherwise the testsuite driver may not have an up-to-date baseline. - - - - - 1ca9adbc by Sylvain Henry at 2020-01-07T13:14:18-05:00 Remove `parallel` check from configure.ac `parallel` is no longer a submodule since 3cb063c805ec841ca33b8371ef8aba9329221b6c - - - - - b69a3460 by Ryan Scott at 2020-01-07T13:14:57-05:00 Monomorphize HsModule to GhcPs (#17642) Analyzing the call sites for `HsModule` reveals that it is only ever used with parsed code (i.e., `GhcPs`). This simplifies `HsModule` by concretizing its `pass` parameter to always be `GhcPs`. Fixes #17642. - - - - - d491a679 by Sylvain Henry at 2020-01-08T06:16:31-05:00 Module hierarchy: Renamer (cf #13009) - - - - - d589410f by Ben Gamari at 2020-01-08T06:17:09-05:00 Bump haskeline submodule to 0.8.0.1 (cherry picked from commit feb3b955402d53c3875dd7a9a39f322827e5bd69) - - - - - 923a1272 by Ryan Scott at 2020-01-08T06:17:47-05:00 Print Core type applications with no whitespace after @ (#17643) This brings the pretty-printer for Core in line with how visible type applications are normally printed: namely, with no whitespace after the `@` character (i.e., `f @a` instead of `f @ a`). While I'm in town, I also give the same treatment to type abstractions (i.e., `\(@a)` instead of `\(@ a)`) and coercion applications (i.e., `f @~x` instead of `f @~ x`). Fixes #17643. - - - - - 49f83a0d by Adam Sandberg Eriksson at 2020-01-12T21:28:09-05:00 improve docs for HeaderInfo.getImports [skip ci] - - - - - 9129210f by Matthew Pickering at 2020-01-12T21:28:47-05:00 Overloaded Quotation Brackets (#246) This patch implements overloaded quotation brackets which generalise the desugaring of all quotation forms in terms of a new minimal interface. The main change is that a quotation, for example, [e| 5 |], will now have type `Quote m => m Exp` rather than `Q Exp`. The `Quote` typeclass contains a single method for generating new names which is used when desugaring binding structures. The return type of functions from the `Lift` type class, `lift` and `liftTyped` have been restricted to `forall m . Quote m => m Exp` rather than returning a result in a Q monad. More details about the feature can be read in the GHC proposal. https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0246-overloaded-bracket.rst - - - - - 350e2b78 by Richard Eisenberg at 2020-01-12T21:29:27-05:00 Don't zap to Any; error instead This changes GHC's treatment of so-called Naughty Quantification Candidates to issue errors, instead of zapping to Any. Close #16775. No new test cases, because existing ones cover this well. - - - - - 0b5ddc7f by Brian Wignall at 2020-01-12T21:30:08-05:00 Fix more typos, via an improved Levenshtein-style corrector - - - - - f732dbec by Ben Gamari at 2020-01-12T21:30:49-05:00 gitlab-ci: Retain bindists used by head.hackage for longer Previously we would keep them for two weeks. However, on the stable branches two weeks can easily elapse with no pushes. - - - - - c8636da5 by Sylvain Henry at 2020-01-12T21:31:30-05:00 Fix LANG=C for readelf invocation in T14999 The test fails when used with LANG=fr_FR.UTF-8 - - - - - 077a88de by Jean-Baptiste Mazon at 2020-01-12T21:32:08-05:00 users-guide/debug-info: typo “behivior” - - - - - 61916c5d by Simon Peyton Jones at 2020-01-12T21:32:44-05:00 Add comments about TH levels - - - - - 1fd766ca by Simon Peyton Jones at 2020-01-12T21:32:44-05:00 Comments about constraint floating - - - - - de01427e by Simon Peyton Jones at 2020-01-12T21:32:45-05:00 Minor refactor around quantified constraints This patch clarifies a dark corner of quantified constraints. * See Note [Yukky eq_sel for a HoleDest] in TcSMonad * Minor refactor, breaking out new function TcInteract.doTopReactEqPred - - - - - 30be3bf1 by Simon Peyton Jones at 2020-01-12T21:32:45-05:00 Comments in TcHsType - - - - - c5977d4d by Sebastian Graf at 2020-01-16T05:58:58-05:00 Better documentation for mkEtaWW [skip ci] So that hopefully I understand it faster next time. Also got rid of the confusing `orig_expr`, which makes the call site in `etaExpand` look out of sync with the passed `n` (which is not the original `n`). - - - - - 22c0bdc3 by John Ericson at 2020-01-16T05:59:37-05:00 Handle TagToEnum in the same big case as the other primops Before, it was a panic because it was handled above. But there must have been an error in my reasoning (another caller?) because #17442 reported the panic was hit. But, rather than figuring out what happened, I can just make it impossible by construction. By adding just a bit more bureaucracy in the return types, I can handle TagToEnum in the same case as all the others, so the big case is is now total, and the panic is removed. Fixes #17442 - - - - - ee5d63f4 by John Ericson at 2020-01-16T05:59:37-05:00 Get rid of OpDest `OpDest` was basically a defunctionalization. Just turn the code that cased on it into those functions, and call them directly. - - - - - 1ff55226 by John Ericson at 2020-01-16T06:00:16-05:00 Remove special case case of bool during STG -> C-- Allow removing the no longer needed cgPrimOp, getting rid of a small a small layer violation too. Change which made the special case no longer needed was #6135 / 6579a6c73082387f82b994305011f011d9d8382b, which dates back to 2013, making me feel better. - - - - - f416fe64 by Adam Wespiser at 2020-01-16T06:00:53-05:00 replace dead html link (fixes #17661) - - - - - f6bf2ce8 by Sebastian Graf at 2020-01-16T06:01:32-05:00 Revert "`exprOkForSpeculation` for Note [IO hack in the demand analyser]" This reverts commit ce64b397777408731c6dd3f5c55ea8415f9f565b on the grounds of the regression it would introduce in a couple of packages. Fixes #17653. Also undoes a slight metric increase in #13701 introduced by that commit that we didn't see prior to !1983. Metric Decrease: T13701 - - - - - a71323ff by Ben Gamari at 2020-01-17T08:43:16-05:00 gitlab-ci: Don't FORCE_SYMLINKS on Windows Not all runners have symlink permissions enabled. - - - - - 0499e3bc by Ömer Sinan Ağacan at 2020-01-20T15:31:33-05:00 Fix +RTS -Z flag documentation Stack squeezing is done on context switch, not on GC or stack overflow. Fix the documentation. Fixes #17685 [ci skip] - - - - - a661df91 by Ömer Sinan Ağacan at 2020-01-20T15:32:13-05:00 Document Stg.FVs module Fixes #17662 [ci skip] - - - - - db24e480 by Ben Gamari at 2020-01-20T15:32:52-05:00 llvmGen: Don't trash STG registers Fixes #13904. - - - - - f3d7fdb3 by Ben Gamari at 2020-01-20T15:32:52-05:00 llvmGen: Fix typo in readnone attribute - - - - - 442751c6 by Ben Gamari at 2020-01-20T15:32:52-05:00 llvmGen: Add lower-expect to the -O0 optimisation set @kavon says that this will improve block layout for stack checks. - - - - - e90ecc93 by Ben Gamari at 2020-01-20T15:32:52-05:00 llvmGen: Fix #14251 Fixes the calling convention for functions passing raw SSE-register values by adding padding as needed to get the values in the right registers. This problem cropped up when some args were unused an dropped from the live list. This folds together 2e23e1c7de01c92b038e55ce53d11bf9db993dd4 and 73273be476a8cc6c13368660b042b3b0614fd928 previously from @kavon. Metric Increase: T12707 ManyConstructors - - - - - 66e511a4 by Ben Gamari at 2020-01-20T15:33:28-05:00 testsuite: Preserve more information in framework failures Namely print the entire exception in hopes that this will help track down #17649. - - - - - b62b8cea by Ömer Sinan Ağacan at 2020-01-20T15:34:06-05:00 Remove deprecated -smp flag It was deprecated in 2012 with 46258b40 - - - - - 0c04a86a by Ben Gamari at 2020-01-20T15:34:43-05:00 gitlab-ci: Reenable submodule linter - - - - - 2bfabd22 by Ben Gamari at 2020-01-20T15:34:43-05:00 gitlab-ci: Allow submodule cleaning to fail on Windows Currently CI is inexplicably failing with ``` $ git submodule foreach git clean -xdf fatal: not a git repository: libffi-tarballs/../.git/modules/libffi-tarballs ``` I have no idea how this working tree got into such a state but we do need to fail more gracefully when it happens. Consequently, we allow the cleaning step to fail. - - - - - 14bced99 by Xavier Denis at 2020-01-20T15:35:21-05:00 Put the docs for :instances in alphabetical position - - - - - 7e0bb82b by Ben Gamari at 2020-01-20T15:35:57-05:00 Add missing Note [Improvement from Ground Wanteds] Closes #17659. - - - - - 17e43a7c by Ben Gamari at 2020-01-20T15:36:32-05:00 unregisterised: Fix declaration for stg_NO_FINALIZER Previously it had a redundant _entry suffix. We never noticed this previously presumably because we never generated references to it (however hard to believe this may be). However, it did start failing in !1304. - - - - - 3dae006f by PHO at 2020-01-20T15:37:08-05:00 Avoid ./configure failure on NetBSD - - - - - 738e2912 by Ben Gamari at 2020-01-24T13:42:56-05:00 testsuite: Widen acceptance window of T1969 I have seen >20% fluctuations in this number, leading to spurious failures. - - - - - ad4eb7a7 by Gabor Greif at 2020-01-25T05:19:07-05:00 Document the fact, that openFileBlocking can consume an OS thread indefinitely. Also state that a deadlock can happen with the non-threaded runtime. [ci skip] - - - - - be910728 by Sebastian Graf at 2020-01-25T05:19:46-05:00 `-ddump-str-signatures` dumps Text, not STG [skip ci] - - - - - 0e57d8a1 by Ömer Sinan Ağacan at 2020-01-25T05:20:27-05:00 Fix chaining tagged and untagged ptrs in compacting GC Currently compacting GC has the invariant that in a chain all fields are tagged the same. However this does not really hold: root pointers are not tagged, so when we thread a root we initialize a chain without a tag. When the pointed objects is evaluated and we have more pointers to it from the heap, we then add *tagged* fields to the chain (because pointers to it from the heap are tagged), ending up chaining fields with different tags (pointers from roots are NOT tagged, pointers from heap are). This breaks the invariant and as a result compacting GC turns tagged pointers into non-tagged. This later causes problem in the generated code where we do reads assuming that the pointer is aligned, e.g. 0x7(%rax) -- assumes that pointer is tagged 1 which causes misaligned reads. This caused #17088. We fix this using the "pointer tagging for large families" patch (#14373, !1742): - With the pointer tagging patch the GC can know what the tagged pointer to a CONSTR should be (previously we'd need to know the family size -- large families are always tagged 1, small families are tagged depending on the constructor). - Since we now know what the tags should be we no longer need to store the pointer tag in the info table pointers when forming chains in the compacting GC. As a result we no longer need to tag pointers in chains with 1/2 depending on whether the field points to an info table pointer, or to another field: an info table pointer is always tagged 0, everything else in the chain is tagged 1. The lost tags in pointers can be retrieved by looking at the info table. Finally, instead of using tag 1 for fields and tag 0 for info table pointers, we use two different tags for fields: - 1 for fields that have untagged pointers - 2 for fields that have tagged pointers When unchaining we then look at the pointer to a field, and depending on its tag we either leave a tagged pointer or an untagged pointer in the field. This allows chaining untagged and tagged fields together in compacting GC. Fixes #17088 Nofib results ------------- Binaries are smaller because of smaller `Compact.c` code. make mode=fast EXTRA_RUNTEST_OPTS="-cachegrind" EXTRA_HC_OPTS="-with-rtsopts=-c" NoFibRuns=1 -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS -0.3% 0.0% +0.0% +0.0% +0.0% CSD -0.3% 0.0% +0.0% +0.0% +0.0% FS -0.3% 0.0% +0.0% -0.0% -0.0% S -0.3% 0.0% +5.4% +0.8% +3.9% VS -0.3% 0.0% +0.0% -0.0% -0.0% VSD -0.3% 0.0% -0.0% -0.0% -0.2% VSM -0.3% 0.0% +0.0% +0.0% +0.0% anna -0.1% 0.0% +0.0% +0.0% +0.0% ansi -0.3% 0.0% +0.1% +0.0% +0.0% atom -0.2% 0.0% +0.0% +0.0% +0.0% awards -0.2% 0.0% +0.0% 0.0% -0.0% banner -0.3% 0.0% +0.0% +0.0% +0.0% bernouilli -0.3% 0.0% +0.1% +0.0% +0.0% binary-trees -0.2% 0.0% +0.0% 0.0% +0.0% boyer -0.3% 0.0% +0.2% +0.0% +0.0% boyer2 -0.2% 0.0% +0.2% +0.1% +0.0% bspt -0.2% 0.0% +0.0% +0.0% +0.0% cacheprof -0.2% 0.0% +0.0% +0.0% +0.0% calendar -0.3% 0.0% +0.0% +0.0% +0.0% cichelli -0.3% 0.0% +1.1% +0.2% +0.5% circsim -0.2% 0.0% +0.0% -0.0% -0.0% clausify -0.3% 0.0% +0.0% -0.0% -0.0% comp_lab_zift -0.2% 0.0% +0.0% +0.0% +0.0% compress -0.3% 0.0% +0.0% +0.0% +0.0% compress2 -0.3% 0.0% +0.0% -0.0% -0.0% constraints -0.3% 0.0% +0.2% +0.1% +0.1% cryptarithm1 -0.3% 0.0% +0.0% -0.0% 0.0% cryptarithm2 -0.3% 0.0% +0.0% +0.0% +0.0% cse -0.3% 0.0% +0.0% +0.0% +0.0% digits-of-e1 -0.3% 0.0% +0.0% +0.0% +0.0% digits-of-e2 -0.3% 0.0% +0.0% +0.0% -0.0% dom-lt -0.2% 0.0% +0.0% +0.0% +0.0% eliza -0.2% 0.0% +0.0% +0.0% +0.0% event -0.3% 0.0% +0.1% +0.0% -0.0% exact-reals -0.2% 0.0% +0.0% +0.0% +0.0% exp3_8 -0.3% 0.0% +0.0% +0.0% +0.0% expert -0.2% 0.0% +0.0% +0.0% +0.0% fannkuch-redux -0.3% 0.0% -0.0% -0.0% -0.0% fasta -0.3% 0.0% +0.0% +0.0% +0.0% fem -0.2% 0.0% +0.1% +0.0% +0.0% fft -0.2% 0.0% +0.0% -0.0% -0.0% fft2 -0.2% 0.0% +0.0% -0.0% +0.0% fibheaps -0.3% 0.0% +0.0% -0.0% -0.0% fish -0.3% 0.0% +0.0% +0.0% +0.0% fluid -0.2% 0.0% +0.4% +0.1% +0.1% fulsom -0.2% 0.0% +0.0% +0.0% +0.0% gamteb -0.2% 0.0% +0.1% +0.0% +0.0% gcd -0.3% 0.0% +0.0% +0.0% +0.0% gen_regexps -0.3% 0.0% +0.0% -0.0% -0.0% genfft -0.3% 0.0% +0.0% +0.0% +0.0% gg -0.2% 0.0% +0.7% +0.3% +0.2% grep -0.2% 0.0% +0.0% +0.0% +0.0% hidden -0.2% 0.0% +0.0% +0.0% +0.0% hpg -0.2% 0.0% +0.1% +0.0% +0.0% ida -0.3% 0.0% +0.0% +0.0% +0.0% infer -0.2% 0.0% +0.0% -0.0% -0.0% integer -0.3% 0.0% +0.0% +0.0% +0.0% integrate -0.2% 0.0% +0.0% +0.0% +0.0% k-nucleotide -0.2% 0.0% +0.0% +0.0% -0.0% kahan -0.3% 0.0% -0.0% -0.0% -0.0% knights -0.3% 0.0% +0.0% -0.0% -0.0% lambda -0.3% 0.0% +0.0% -0.0% -0.0% last-piece -0.3% 0.0% +0.0% +0.0% +0.0% lcss -0.3% 0.0% +0.0% +0.0% 0.0% life -0.3% 0.0% +0.0% -0.0% -0.0% lift -0.2% 0.0% +0.0% +0.0% +0.0% linear -0.2% 0.0% +0.0% +0.0% +0.0% listcompr -0.3% 0.0% +0.0% +0.0% +0.0% listcopy -0.3% 0.0% +0.0% +0.0% +0.0% maillist -0.3% 0.0% +0.0% -0.0% -0.0% mandel -0.2% 0.0% +0.0% +0.0% +0.0% mandel2 -0.3% 0.0% +0.0% +0.0% +0.0% mate -0.2% 0.0% +0.0% +0.0% +0.0% minimax -0.3% 0.0% +0.0% +0.0% +0.0% mkhprog -0.2% 0.0% +0.0% +0.0% +0.0% multiplier -0.3% 0.0% +0.0% -0.0% -0.0% n-body -0.2% 0.0% -0.0% -0.0% -0.0% nucleic2 -0.2% 0.0% +0.0% +0.0% +0.0% para -0.2% 0.0% +0.0% -0.0% -0.0% paraffins -0.3% 0.0% +0.0% -0.0% -0.0% parser -0.2% 0.0% +0.0% +0.0% +0.0% parstof -0.2% 0.0% +0.8% +0.2% +0.2% pic -0.2% 0.0% +0.1% -0.1% -0.1% pidigits -0.3% 0.0% +0.0% +0.0% +0.0% power -0.2% 0.0% +0.0% -0.0% -0.0% pretty -0.3% 0.0% -0.0% -0.0% -0.1% primes -0.3% 0.0% +0.0% +0.0% -0.0% primetest -0.2% 0.0% +0.0% -0.0% -0.0% prolog -0.3% 0.0% +0.0% -0.0% -0.0% puzzle -0.3% 0.0% +0.0% +0.0% +0.0% queens -0.3% 0.0% +0.0% +0.0% +0.0% reptile -0.2% 0.0% +0.2% +0.1% +0.0% reverse-complem -0.3% 0.0% +0.0% +0.0% +0.0% rewrite -0.3% 0.0% +0.0% -0.0% -0.0% rfib -0.2% 0.0% +0.0% +0.0% -0.0% rsa -0.2% 0.0% +0.0% +0.0% +0.0% scc -0.3% 0.0% -0.0% -0.0% -0.1% sched -0.3% 0.0% +0.0% +0.0% +0.0% scs -0.2% 0.0% +0.1% +0.0% +0.0% simple -0.2% 0.0% +3.4% +1.0% +1.8% solid -0.2% 0.0% +0.0% +0.0% +0.0% sorting -0.3% 0.0% +0.0% +0.0% +0.0% spectral-norm -0.2% 0.0% -0.0% -0.0% -0.0% sphere -0.2% 0.0% +0.0% +0.0% +0.0% symalg -0.2% 0.0% +0.0% +0.0% +0.0% tak -0.3% 0.0% +0.0% +0.0% -0.0% transform -0.2% 0.0% +0.2% +0.1% +0.1% treejoin -0.3% 0.0% +0.2% -0.0% -0.1% typecheck -0.3% 0.0% +0.0% +0.0% +0.0% veritas -0.1% 0.0% +0.0% +0.0% +0.0% wang -0.2% 0.0% +0.0% -0.0% -0.0% wave4main -0.3% 0.0% +0.0% -0.0% -0.0% wheel-sieve1 -0.3% 0.0% +0.0% -0.0% -0.0% wheel-sieve2 -0.3% 0.0% +0.0% -0.0% -0.0% x2n1 -0.3% 0.0% +0.0% +0.0% +0.0% -------------------------------------------------------------------------------- Min -0.3% 0.0% -0.0% -0.1% -0.2% Max -0.1% 0.0% +5.4% +1.0% +3.9% Geometric Mean -0.3% -0.0% +0.1% +0.0% +0.1% -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- circsim -0.2% 0.0% +1.6% +0.4% +0.7% constraints -0.3% 0.0% +4.3% +1.5% +2.3% fibheaps -0.3% 0.0% +3.5% +1.2% +1.3% fulsom -0.2% 0.0% +3.6% +1.2% +1.8% gc_bench -0.3% 0.0% +4.1% +1.3% +2.3% hash -0.3% 0.0% +6.6% +2.2% +3.6% lcss -0.3% 0.0% +0.7% +0.2% +0.7% mutstore1 -0.3% 0.0% +4.8% +1.4% +2.8% mutstore2 -0.3% 0.0% +3.4% +1.0% +1.7% power -0.2% 0.0% +2.7% +0.6% +1.9% spellcheck -0.3% 0.0% +1.1% +0.4% +0.4% -------------------------------------------------------------------------------- Min -0.3% 0.0% +0.7% +0.2% +0.4% Max -0.2% 0.0% +6.6% +2.2% +3.6% Geometric Mean -0.3% +0.0% +3.3% +1.0% +1.8% Metric changes -------------- While it sounds ridiculous, this change causes increased allocations in the following tests. We concluded that this change can't cause a difference in allocations and decided to land this patch. Fluctuations in "bytes allocated" metric is tracked in #17686. Metric Increase: Naperian T10547 T12150 T12234 T12425 T13035 T5837 T6048 - - - - - 8038cbd9 by Sebastian Graf at 2020-01-25T05:21:05-05:00 PmCheck: Formulate as translation between Clause Trees We used to check `GrdVec`s arising from multiple clauses and guards in isolation. That resulted in a split between `pmCheck` and `pmCheckGuards`, the implementations of which were similar, but subtly different in detail. Also the throttling mechanism described in `Note [Countering exponential blowup]` ultimately got quite complicated because it had to cater for both checking functions. This patch realises that pattern match checking doesn't just consider single guarded RHSs, but that it's always a whole set of clauses, each of which can have multiple guarded RHSs in turn. We do so by translating a list of `Match`es to a `GrdTree`: ```haskell data GrdTree = Rhs !RhsInfo | Guard !PmGrd !GrdTree -- captures lef-to-right match semantics | Sequence !GrdTree !GrdTree -- captures top-to-bottom match semantics | Empty -- For -XEmptyCase, neutral element of Sequence ``` Then we have a function `checkGrdTree` that matches a given `GrdTree` against an incoming set of values, represented by `Deltas`: ```haskell checkGrdTree :: GrdTree -> Deltas -> CheckResult ... ``` Throttling is isolated to the `Sequence` case and becomes as easy as one would expect: When the union of uncovered values becomes too big, just return the original incoming `Deltas` instead (which is always a superset of the union, thus a sound approximation). The returned `CheckResult` contains two things: 1. The set of values that were not covered by any of the clauses, for exhaustivity warnings. 2. The `AnnotatedTree` that enriches the syntactic structure of the input program with divergence and inaccessibility information. This is `AnnotatedTree`: ```haskell data AnnotatedTree = AccessibleRhs !RhsInfo | InaccessibleRhs !RhsInfo | MayDiverge !AnnotatedTree | SequenceAnn !AnnotatedTree !AnnotatedTree | EmptyAnn ``` Crucially, `MayDiverge` asserts that the tree may force diverging values, so not all of its wrapped clauses can be redundant. While the set of uncovered values can be used to generate the missing equations for warning messages, redundant and proper inaccessible equations can be extracted from `AnnotatedTree` by `redundantAndInaccessibleRhss`. For this to work properly, the interface to the Oracle had to change. There's only `addPmCts` now, which takes a bag of `PmCt`s. There's a whole bunch of `PmCt` variants to replace the different oracle functions from before. The new `AnnotatedTree` structure allows for more accurate warning reporting (as evidenced by a number of changes spread throughout GHC's code base), thus we fix #17465. Fixes #17646 on the go. Metric Decrease: T11822 T9233 PmSeriesS haddock.compiler - - - - - 86966d48 by Sebastian Graf at 2020-01-25T05:21:05-05:00 PmCheck: Properly handle constructor-bound type variables In https://gitlab.haskell.org/ghc/ghc/merge_requests/2192#note_246551 Simon convinced me that ignoring type variables existentially bound by data constructors have to be the same way as value binders. Sadly I couldn't think of a regression test, but I'm confident that this change strictly improves on the status quo. - - - - - c3fde723 by Ryan Scott at 2020-01-25T05:21:40-05:00 Handle local fixity declarations in DsMeta properly `DsMeta.rep_sig` used to skip over `FixSig` entirely, which had the effect of causing local fixity declarations to be dropped when quoted in Template Haskell. But there is no good reason for this state of affairs, as the code in `DsMeta.repFixD` (which handles top-level fixity declarations) handles local fixity declarations just fine. This patch factors out the necessary parts of `repFixD` so that they can be used in `rep_sig` as well. There was one minor complication: the fixity signatures for class methods in each `HsGroup` were stored both in `FixSig`s _and_ the list of `LFixitySig`s for top-level fixity signatures, so I needed to take action to prevent fixity signatures for class methods being converted to `Dec`s twice. I tweaked `RnSource.add` to avoid putting these fixity signatures in two places and added `Note [Top-level fixity signatures in an HsGroup]` in `GHC.Hs.Decls` to explain the new design. Fixes #17608. Bumps the Haddock submodule. - - - - - 6e2d9ee2 by Sylvain Henry at 2020-01-25T05:22:20-05:00 Module hierarchy: Cmm (cf #13009) - - - - - 8b726534 by PHO at 2020-01-25T05:23:01-05:00 Fix rts allocateExec() on NetBSD Similar to SELinux, NetBSD "PaX mprotect" prohibits marking a page mapping both writable and executable at the same time. Use libffi which knows how to work around it. - - - - - 6eb566a0 by Xavier Denis at 2020-01-25T05:23:39-05:00 Add ghc-in-ghci for stack based builds - - - - - b1a32170 by Xavier Denis at 2020-01-25T05:23:39-05:00 Create ghci.cabal.sh - - - - - 0a5e4f5f by Sylvain Henry at 2020-01-25T05:24:19-05:00 Split glasgow_exts into several files (#17316) - - - - - b3e5c678 by Ben Gamari at 2020-01-25T05:24:57-05:00 hadrian: Throw error on duplicate-named flavours Throw an error if the user requests a flavour for which there is more than one match. Fixes #17156. - - - - - 0940b59a by Ryan Scott at 2020-01-25T08:15:05-05:00 Do not bring visible foralls into scope in hsScopedTvs Previously, `hsScopedTvs` (and its cousin `hsWcScopedTvs`) pretended that visible dependent quantification could not possibly happen at the term level, and cemented that assumption with an `ASSERT`: ```hs hsScopedTvs (HsForAllTy { hst_fvf = vis_flag, ... }) = ASSERT( vis_flag == ForallInvis ) ... ``` It turns out that this assumption is wrong. You can end up tripping this `ASSERT` if you stick it to the man and write a type for a term that uses visible dependent quantification anyway, like in this example: ```hs {-# LANGUAGE ScopedTypeVariables #-} x :: forall a -> a -> a x = x ``` That won't typecheck, but that's not the point. Before the typechecker has a chance to reject this, the renamer will try to use `hsScopedTvs` to bring `a` into scope over the body of `x`, since `a` is quantified by a `forall`. This, in turn, causes the `ASSERT` to fail. Bummer. Instead of walking on this dangerous ground, this patch makes GHC adopt a more hardline stance by pattern-matching directly on `ForallInvis` in `hsScopedTvs`: ```hs hsScopedTvs (HsForAllTy { hst_fvf = ForallInvis, ... }) = ... ``` Now `a` will not be brought over the body of `x` at all (which is how it should be), there's no chance of the `ASSERT` failing anymore (as it's gone), and best of all, the behavior of `hsScopedTvs` does not change. Everyone wins! Fixes #17687. - - - - - 1132602f by Ryan Scott at 2020-01-27T10:03:42-05:00 Use splitLHs{ForAll,Sigma}TyInvis throughout the codebase Richard points out in #17688 that we use `splitLHsForAllTy` and `splitLHsSigmaTy` in places that we ought to be using the corresponding `-Invis` variants instead, identifying two bugs that are caused by this oversight: * Certain TH-quoted type signatures, such as those that appear in quoted `SPECIALISE` pragmas, silently turn visible `forall`s into invisible `forall`s. * When quoted, the type `forall a -> (a ~ a) => a` will turn into `forall a -> a` due to a bug in `DsMeta.repForall` that drops contexts that follow visible `forall`s. These are both ultimately caused by the fact that `splitLHsForAllTy` and `splitLHsSigmaTy` split apart visible `forall`s in addition to invisible ones. This patch cleans things up: * We now use `splitLHsForAllTyInvis` and `splitLHsSigmaTyInvis` throughout the codebase. Relatedly, the `splitLHsForAllTy` and `splitLHsSigmaTy` have been removed, as they are easy to misuse. * `DsMeta.repForall` now only handles invisible `forall`s to reduce the chance for confusion with visible `forall`s, which need to be handled differently. I also renamed it from `repForall` to `repForallT` to emphasize that its distinguishing characteristic is the fact that it desugars down to `L.H.TH.Syntax.ForallT`. Fixes #17688. - - - - - 97d0b0a3 by Matthew Pickering at 2020-01-27T10:04:19-05:00 Make Block.h compile with c++ compilers - - - - - 4bada77d by Tom Ellis at 2020-01-27T12:30:46-05:00 Disable two warnings for files that trigger them incomplete-uni-patterns and incomplete-record-updates will be in -Wall at a future date, so prepare for that by disabling those warnings on files that trigger them. - - - - - 0188404a by Tom Ellis at 2020-01-27T12:30:46-05:00 Add two warnings to stage 2 build - - - - - acae02c1 by Tom Ellis at 2020-01-27T12:30:46-05:00 Add two warnings to Hadrian - - - - - bf38a20e by Sylvain Henry at 2020-01-31T02:46:15-05:00 Call `interpretPackageEnv` from `setSessionDynFlags` interpretPackageEnv modifies the flags by reading the dreaded package environments. It is much less surprising to call it from `setSessionDynFlags` instead of reading package environments as a side-effect of `initPackages`. - - - - - 29c701c1 by Sylvain Henry at 2020-01-31T02:46:15-05:00 Refactor package related code The package terminology is a bit of a mess. Cabal packages contain components. Instances of these components when built with some flags/options/dependencies are called units. Units are registered into package databases and their metadata are called PackageConfig. GHC only knows about package databases containing units. It is a sad mismatch not fixed by this patch (we would have to rename parameters such as `package-id <unit-id>` which would affect users). This patch however fixes the following internal names: - Renames PackageConfig into UnitInfo. - Rename systemPackageConfig into globalPackageDatabase[Path] - Rename PkgConfXX into PkgDbXX - Rename pkgIdMap into unitIdMap - Rename ModuleToPkgDbAll into ModuleNameProvidersMap - Rename lookupPackage into lookupUnit - Add comments on DynFlags package related fields It also introduces a new `PackageDatabase` datatype instead of explicitly passing the following tuple: `(FilePath,[PackageConfig])`. The `pkgDatabase` field in `DynFlags` now contains the unit info for each unit of each package database exactly as they have been read from disk. Previously the command-line flag `-distrust-all-packages` would modify these unit info. Now this flag only affects the "dynamic" consolidated package state found in `pkgState` field. It makes sense because `initPackages` could be called first with this `distrust-all-packages` flag set and then again (using ghc-api) without and it should work (package databases are not read again from disk when `initPackages` is called the second time). Bump haddock submodule - - - - - 942c7148 by Ben Gamari at 2020-01-31T02:46:54-05:00 rename: Eliminate usage of mkVarOccUnique Replacing it with `newSysName`. Fixes #17061. - - - - - 41117d71 by Ben Gamari at 2020-01-31T02:47:31-05:00 base: Use one-shot kqueue on macOS The underlying reason requiring that one-shot usage be disabled (#13903) has been fixed. Closes #15768. - - - - - 01b15b83 by Ben Gamari at 2020-01-31T02:48:08-05:00 testsuite: Don't crash on encoding failure in print If the user doesn't use a Unicode locale then the testsuite driver would previously throw framework failures due to encoding failures. We now rather use the `replace` error-handling strategy. - - - - - c846618a by Ömer Sinan Ağacan at 2020-01-31T12:21:10+03:00 Do CafInfo/SRT analysis in Cmm This patch removes all CafInfo predictions and various hacks to preserve predicted CafInfos from the compiler and assigns final CafInfos to interface Ids after code generation. SRT analysis is extended to support static data, and Cmm generator is modified to allow generating static_link fields after SRT analysis. This also fixes `-fcatch-bottoms`, which introduces error calls in case expressions in CorePrep, which runs *after* CoreTidy (which is where we decide on CafInfos) and turns previously non-CAFFY things into CAFFY. Fixes #17648 Fixes #9718 Evaluation ========== NoFib ----- Boot with: `make boot mode=fast` Run: `make mode=fast EXTRA_RUNTEST_OPTS="-cachegrind" NoFibRuns=1` -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS -0.0% 0.0% -0.0% -0.0% -0.0% CSD -0.0% 0.0% -0.0% -0.0% -0.0% FS -0.0% 0.0% -0.0% -0.0% -0.0% S -0.0% 0.0% -0.0% -0.0% -0.0% VS -0.0% 0.0% -0.0% -0.0% -0.0% VSD -0.0% 0.0% -0.0% -0.0% -0.5% VSM -0.0% 0.0% -0.0% -0.0% -0.0% anna -0.1% 0.0% -0.0% -0.0% -0.0% ansi -0.0% 0.0% -0.0% -0.0% -0.0% atom -0.0% 0.0% -0.0% -0.0% -0.0% awards -0.0% 0.0% -0.0% -0.0% -0.0% banner -0.0% 0.0% -0.0% -0.0% -0.0% bernouilli -0.0% 0.0% -0.0% -0.0% -0.0% binary-trees -0.0% 0.0% -0.0% -0.0% -0.0% boyer -0.0% 0.0% -0.0% -0.0% -0.0% boyer2 -0.0% 0.0% -0.0% -0.0% -0.0% bspt -0.0% 0.0% -0.0% -0.0% -0.0% cacheprof -0.0% 0.0% -0.0% -0.0% -0.0% calendar -0.0% 0.0% -0.0% -0.0% -0.0% cichelli -0.0% 0.0% -0.0% -0.0% -0.0% circsim -0.0% 0.0% -0.0% -0.0% -0.0% clausify -0.0% 0.0% -0.0% -0.0% -0.0% comp_lab_zift -0.0% 0.0% -0.0% -0.0% -0.0% compress -0.0% 0.0% -0.0% -0.0% -0.0% compress2 -0.0% 0.0% -0.0% -0.0% -0.0% constraints -0.0% 0.0% -0.0% -0.0% -0.0% cryptarithm1 -0.0% 0.0% -0.0% -0.0% -0.0% cryptarithm2 -0.0% 0.0% -0.0% -0.0% -0.0% cse -0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e1 -0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e2 -0.0% 0.0% -0.0% -0.0% -0.0% dom-lt -0.0% 0.0% -0.0% -0.0% -0.0% eliza -0.0% 0.0% -0.0% -0.0% -0.0% event -0.0% 0.0% -0.0% -0.0% -0.0% exact-reals -0.0% 0.0% -0.0% -0.0% -0.0% exp3_8 -0.0% 0.0% -0.0% -0.0% -0.0% expert -0.0% 0.0% -0.0% -0.0% -0.0% fannkuch-redux -0.0% 0.0% -0.0% -0.0% -0.0% fasta -0.0% 0.0% -0.0% -0.0% -0.0% fem -0.0% 0.0% -0.0% -0.0% -0.0% fft -0.0% 0.0% -0.0% -0.0% -0.0% fft2 -0.0% 0.0% -0.0% -0.0% -0.0% fibheaps -0.0% 0.0% -0.0% -0.0% -0.0% fish -0.0% 0.0% -0.0% -0.0% -0.0% fluid -0.1% 0.0% -0.0% -0.0% -0.0% fulsom -0.0% 0.0% -0.0% -0.0% -0.0% gamteb -0.0% 0.0% -0.0% -0.0% -0.0% gcd -0.0% 0.0% -0.0% -0.0% -0.0% gen_regexps -0.0% 0.0% -0.0% -0.0% -0.0% genfft -0.0% 0.0% -0.0% -0.0% -0.0% gg -0.0% 0.0% -0.0% -0.0% -0.0% grep -0.0% 0.0% -0.0% -0.0% -0.0% hidden -0.0% 0.0% -0.0% -0.0% -0.0% hpg -0.1% 0.0% -0.0% -0.0% -0.0% ida -0.0% 0.0% -0.0% -0.0% -0.0% infer -0.0% 0.0% -0.0% -0.0% -0.0% integer -0.0% 0.0% -0.0% -0.0% -0.0% integrate -0.0% 0.0% -0.0% -0.0% -0.0% k-nucleotide -0.0% 0.0% -0.0% -0.0% -0.0% kahan -0.0% 0.0% -0.0% -0.0% -0.0% knights -0.0% 0.0% -0.0% -0.0% -0.0% lambda -0.0% 0.0% -0.0% -0.0% -0.0% last-piece -0.0% 0.0% -0.0% -0.0% -0.0% lcss -0.0% 0.0% -0.0% -0.0% -0.0% life -0.0% 0.0% -0.0% -0.0% -0.0% lift -0.0% 0.0% -0.0% -0.0% -0.0% linear -0.1% 0.0% -0.0% -0.0% -0.0% listcompr -0.0% 0.0% -0.0% -0.0% -0.0% listcopy -0.0% 0.0% -0.0% -0.0% -0.0% maillist -0.0% 0.0% -0.0% -0.0% -0.0% mandel -0.0% 0.0% -0.0% -0.0% -0.0% mandel2 -0.0% 0.0% -0.0% -0.0% -0.0% mate -0.0% 0.0% -0.0% -0.0% -0.0% minimax -0.0% 0.0% -0.0% -0.0% -0.0% mkhprog -0.0% 0.0% -0.0% -0.0% -0.0% multiplier -0.0% 0.0% -0.0% -0.0% -0.0% n-body -0.0% 0.0% -0.0% -0.0% -0.0% nucleic2 -0.0% 0.0% -0.0% -0.0% -0.0% para -0.0% 0.0% -0.0% -0.0% -0.0% paraffins -0.0% 0.0% -0.0% -0.0% -0.0% parser -0.1% 0.0% -0.0% -0.0% -0.0% parstof -0.1% 0.0% -0.0% -0.0% -0.0% pic -0.0% 0.0% -0.0% -0.0% -0.0% pidigits -0.0% 0.0% -0.0% -0.0% -0.0% power -0.0% 0.0% -0.0% -0.0% -0.0% pretty -0.0% 0.0% -0.3% -0.4% -0.4% primes -0.0% 0.0% -0.0% -0.0% -0.0% primetest -0.0% 0.0% -0.0% -0.0% -0.0% prolog -0.0% 0.0% -0.0% -0.0% -0.0% puzzle -0.0% 0.0% -0.0% -0.0% -0.0% queens -0.0% 0.0% -0.0% -0.0% -0.0% reptile -0.0% 0.0% -0.0% -0.0% -0.0% reverse-complem -0.0% 0.0% -0.0% -0.0% -0.0% rewrite -0.0% 0.0% -0.0% -0.0% -0.0% rfib -0.0% 0.0% -0.0% -0.0% -0.0% rsa -0.0% 0.0% -0.0% -0.0% -0.0% scc -0.0% 0.0% -0.3% -0.5% -0.4% sched -0.0% 0.0% -0.0% -0.0% -0.0% scs -0.0% 0.0% -0.0% -0.0% -0.0% simple -0.1% 0.0% -0.0% -0.0% -0.0% solid -0.0% 0.0% -0.0% -0.0% -0.0% sorting -0.0% 0.0% -0.0% -0.0% -0.0% spectral-norm -0.0% 0.0% -0.0% -0.0% -0.0% sphere -0.0% 0.0% -0.0% -0.0% -0.0% symalg -0.0% 0.0% -0.0% -0.0% -0.0% tak -0.0% 0.0% -0.0% -0.0% -0.0% transform -0.0% 0.0% -0.0% -0.0% -0.0% treejoin -0.0% 0.0% -0.0% -0.0% -0.0% typecheck -0.0% 0.0% -0.0% -0.0% -0.0% veritas -0.0% 0.0% -0.0% -0.0% -0.0% wang -0.0% 0.0% -0.0% -0.0% -0.0% wave4main -0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve1 -0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve2 -0.0% 0.0% -0.0% -0.0% -0.0% x2n1 -0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min -0.1% 0.0% -0.3% -0.5% -0.5% Max -0.0% 0.0% -0.0% -0.0% -0.0% Geometric Mean -0.0% -0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- circsim -0.1% 0.0% -0.0% -0.0% -0.0% constraints -0.0% 0.0% -0.0% -0.0% -0.0% fibheaps -0.0% 0.0% -0.0% -0.0% -0.0% gc_bench -0.0% 0.0% -0.0% -0.0% -0.0% hash -0.0% 0.0% -0.0% -0.0% -0.0% lcss -0.0% 0.0% -0.0% -0.0% -0.0% power -0.0% 0.0% -0.0% -0.0% -0.0% spellcheck -0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min -0.1% 0.0% -0.0% -0.0% -0.0% Max -0.0% 0.0% -0.0% -0.0% -0.0% Geometric Mean -0.0% +0.0% -0.0% -0.0% -0.0% Manual inspection of programs in testsuite/tests/programs --------------------------------------------------------- I built these programs with a bunch of dump flags and `-O` and compared STG, Cmm, and Asm dumps and file sizes. (Below the numbers in parenthesis show number of modules in the program) These programs have identical compiler (same .hi and .o sizes, STG, and Cmm and Asm dumps): - Queens (1), andre_monad (1), cholewo-eval (2), cvh_unboxing (3), andy_cherry (7), fun_insts (1), hs-boot (4), fast2haskell (2), jl_defaults (1), jq_readsPrec (1), jules_xref (1), jtod_circint (4), jules_xref2 (1), lennart_range (1), lex (1), life_space_leak (1), bargon-mangler-bug (7), record_upd (1), rittri (1), sanders_array (1), strict_anns (1), thurston-module-arith (2), okeefe_neural (1), joao-circular (6), 10queens (1) Programs with different compiler outputs: - jl_defaults (1): For some reason GHC HEAD marks a lot of top-level `[Int]` closures as CAFFY for no reason. With this patch we no longer make them CAFFY and generate less SRT entries. For some reason Main.o is slightly larger with this patch (1.3%) and the executable sizes are the same. (I'd expect both to be smaller) - launchbury (1): Same as jl_defaults: top-level `[Int]` closures marked as CAFFY for no reason. Similarly `Main.o` is 1.4% larger but the executable sizes are the same. - galois_raytrace (13): Differences are in the Parse module. There are a lot, but some of the changes are caused by the fact that for some reason (I think a bug) GHC HEAD marks the dictionary for `Functor Identity` as CAFFY. Parse.o is 0.4% larger, the executable size is the same. - north_array: We now generate less SRT entries because some of array primops used in this program like `NewArrayOp` get eliminated during Stg-to-Cmm and turn some CAFFY things into non-CAFFY. Main.o gets 24% larger (9224 bytes from 9000 bytes), executable sizes are the same. - seward-space-leak: Difference in this program is better shown by this smaller example: module Lib where data CDS = Case [CDS] [(Int, CDS)] | Call CDS CDS instance Eq CDS where Case sels1 rets1 == Case sels2 rets2 = sels1 == sels2 && rets1 == rets2 Call a1 b1 == Call a2 b2 = a1 == a2 && b1 == b2 _ == _ = False In this program GHC HEAD builds a new SRT for the recursive group of `(==)`, `(/=)` and the dictionary closure. Then `/=` points to `==` in its SRT field, and `==` uses the SRT object as its SRT. With this patch we use the closure for `/=` as the SRT and add `==` there. Then `/=` gets an empty SRT field and `==` points to `/=` in its SRT field. This change looks fine to me. Main.o gets 0.07% larger, executable sizes are identical. head.hackage ------------ head.hackage's CI script builds 428 packages from Hackage using this patch with no failures. Compiler performance -------------------- The compiler perf tests report that the compiler allocates slightly more (worst case observed so far is 4%). However most programs in the test suite are small, single file programs. To benchmark compiler performance on something more realistic I build Cabal (the library, 236 modules) with different optimisation levels. For the "max residency" row I run GHC with `+RTS -s -A100k -i0 -h` for more accurate numbers. Other rows are generated with just `-s`. (This is because `-i0` causes running GC much more frequently and as a result "bytes copied" gets inflated by more than 25x in some cases) * -O0 | | GHC HEAD | This MR | Diff | | --------------- | -------------- | -------------- | ------ | | Bytes allocated | 54,413,350,872 | 54,701,099,464 | +0.52% | | Bytes copied | 4,926,037,184 | 4,990,638,760 | +1.31% | | Max residency | 421,225,624 | 424,324,264 | +0.73% | * -O1 | | GHC HEAD | This MR | Diff | | --------------- | --------------- | --------------- | ------ | | Bytes allocated | 245,849,209,992 | 246,562,088,672 | +0.28% | | Bytes copied | 26,943,452,560 | 27,089,972,296 | +0.54% | | Max residency | 982,643,440 | 991,663,432 | +0.91% | * -O2 | | GHC HEAD | This MR | Diff | | --------------- | --------------- | --------------- | ------ | | Bytes allocated | 291,044,511,408 | 291,863,910,912 | +0.28% | | Bytes copied | 37,044,237,616 | 36,121,690,472 | -2.49% | | Max residency | 1,071,600,328 | 1,086,396,256 | +1.38% | Extra compiler allocations -------------------------- Runtime allocations of programs are as reported above (NoFib section). The compiler now allocates more than before. Main source of allocation in this patch compared to base commit is the new SRT algorithm (GHC.Cmm.Info.Build). Below is some of the extra work we do with this patch, numbers generated by profiled stage 2 compiler when building a pathological case (the test 'ManyConstructors') with '-O2': - We now sort the final STG for a module, which means traversing the entire program, generating free variable set for each top-level binding, doing SCC analysis, and re-ordering the program. In ManyConstructors this step allocates 97,889,952 bytes. - We now do SRT analysis on static data, which in a program like ManyConstructors causes analysing 10,000 bindings that we would previously just skip. This step allocates 70,898,352 bytes. - We now maintain an SRT map for the entire module as we compile Cmm groups: data ModuleSRTInfo = ModuleSRTInfo { ... , moduleSRTMap :: SRTMap } (SRTMap is just a strict Map from the 'containers' library) This map gets an entry for most bindings in a module (exceptions are THUNKs and CAFFY static functions). For ManyConstructors this map gets 50015 entries. - Once we're done with code generation we generate a NameSet from SRTMap for the non-CAFFY names in the current module. This set gets the same number of entries as the SRTMap. - Finally we update CafInfos in ModDetails for the non-CAFFY Ids, using the NameSet generated in the previous step. This usually does the least amount of allocation among the work listed here. Only place with this patch where we do less work in the CAF analysis in the tidying pass (CoreTidy). However that doesn't save us much, as the pass still needs to traverse the whole program and update IdInfos for other reasons. Only thing we don't here do is the `hasCafRefs` pass over the RHS of bindings, which is a stateless pass that returns a boolean value, so it doesn't allocate much. (Metric changes blow are all increased allocations) Metric changes -------------- Metric Increase: ManyAlternatives ManyConstructors T13035 T14683 T1969 T9961 - - - - - 2a87a565 by Andreas Klebinger at 2020-01-31T12:21:10+03:00 A few optimizations in STG and Cmm parts: (Guided by the profiler output) - Add a few bang patterns, INLINABLE annotations, and a seqList in a few places in Cmm and STG parts. - Do not add external variables as dependencies in STG dependency analysis (GHC.Stg.DepAnal). - - - - - bef704b6 by Simon Peyton Jones at 2020-02-01T02:28:45-05:00 Improve skolemisation This patch avoids skolemiseUnboundMetaTyVar making up a fresh Name when it doesn't need to. See Note [Skolemising and identity] Improves error messsages for partial type signatures. - - - - - cd110423 by Simon Peyton Jones at 2020-02-01T02:28:45-05:00 Improve pretty-printing for TyConBinders In particular, show their kinds. - - - - - 913287a0 by Simon Peyton Jones at 2020-02-01T02:28:45-05:00 Fix scoping of TyCon binders in TcTyClsDecls This patch fixes #17566 by refactoring the way we decide the final identity of the tyvars in the TyCons of a possibly-recursive nest of type and class decls, possibly with associated types. It's all laid out in Note [Swizzling the tyvars before generaliseTcTyCon] Main changes: * We have to generalise each decl (with its associated types) all at once: TcTyClsDecls.generaliseTyClDecl * The main new work is done in TcTyClsDecls.swizzleTcTyConBndrs * The mysterious TcHsSyn.zonkRecTyVarBndrs dies altogether Other smaller things: * A little refactoring, moving bindTyClTyVars from tcTyClDecl1 to tcDataDefn, tcSynRhs, etc. Clearer, reduces the number of parameters * Reduce the amount of swizzling required. Specifically, bindExplicitTKBndrs_Q_Tv doesn't need to clone a new Name for the TyVarTv, and not cloning means that in the vasly common case, swizzleTyConBndrs is a no-op In detail: Rename newTyVarTyVar --> cloneTyVarTyVar Add newTyVarTyTyVar that doesn't clone Use the non-cloning newTyVarTyVar in bindExplicitTKBndrs_Q_Tv Rename newFlexiKindedTyVarTyVar --> cloneFlexiKindedTyVarTyVar * Define new utility function and use it HsDecls.familyDeclName :: FamilyDecl (GhcPass p) -> IdP (GhcPass p) Updates haddock submodule. - - - - - 58ed6c4a by Ben Gamari at 2020-02-01T02:29:23-05:00 rts/M32Alloc: Don't attempt to unmap non-existent pages The m32 allocator's `pages` list may contain NULLs in the case that the page was flushed. Some `munmap` implementations (e.g. FreeBSD's) don't like it if we pass them NULL. Don't do that. - - - - - 859db7d6 by Ömer Sinan Ağacan at 2020-02-01T14:18:49+03:00 Improve/fix -fcatch-bottoms documentation Old documentation suggests that -fcatch-bottoms only adds a default alternative to bottoming case expression, but that's not true. We use a very simplistic "is exhaustive" check and add default alternatives to any case expression that does not cover all constructors of the type. In case of GADTs this simple check assumes all constructors should be covered, even the ones ruled out by the type of the scrutinee. Update the documentation to reflect this. (Originally noticed in #17648) [ci skip] - - - - - 54dfa94a by John Ericson at 2020-02-03T21:14:24-05:00 Fix docs for FrontendResult Other variant was removed in ac1a379363618a6f2f17fff65ce9129164b6ef30 but docs were no changed. - - - - - 5e63d9c0 by John Ericson at 2020-02-03T21:15:02-05:00 Refactor HscMain.finish I found the old control flow a bit hard to follow; I rewrote it to first decide whether to desugar, and then use that choice when computing whether to simplify / what sort of interface file to write. I hope eventually we will always write post-tc interface files, which will make the logic of this function even simpler, and continue the thrust of this refactor. - - - - - e580e5b8 by Stefan Schulze Frielinghaus at 2020-02-04T09:29:00-05:00 Do not build StgCRunAsm.S for unregisterised builds For unregisterised builds StgRun/StgReturn are implemented via a mini interpreter in StgCRun.c and therefore would collide with the implementations in StgCRunAsm.S. - - - - - e3b0bd97 by Stefan Schulze Frielinghaus at 2020-02-04T09:29:00-05:00 fixup! fixup! Do not build StgCRunAsm.S for unregisterised builds - - - - - eb629fab by John Ericson at 2020-02-04T09:29:38-05:00 Delete some superfluous helper functions in HscMain The driver code is some of the nastiest in GHC, and I am worried about being able to untangle all the tech debt. In `HscMain` we have a number of helpers which are either not-used or little used. I delete them so we can reduce cognative load, distilling the essential complexity away from the cruft. - - - - - c90eca55 by Sebastian Graf at 2020-02-05T09:21:29-05:00 PmCheck: Record type constraints arising from existentials in `PmCoreCt`s In #17703 (a follow-up of !2192), we established that contrary to my belief, type constraints arising from existentials in code like ```hs data Ex where Ex :: a -> Ex f _ | let x = Ex @Int 15 = case x of Ex -> ... ``` are in fact useful. This commit makes a number of refactorings and improvements to comments, but fundamentally changes `addCoreCt.core_expr` to record the type constraint `a ~ Int` in addition to `x ~ Ex @a y` and `y ~ 15`. Fixes #17703. - - - - - 6d3b5d57 by Ömer Sinan Ağacan at 2020-02-05T09:22:10-05:00 testlib: Extend existing *_opts in extra_*_opts Previously we'd override the existing {run,hc} opts in extra_{run,hc}_opts, which caused flakiness in T1969, see #17712. extra_{run,hc}_opts now extends {run,hc} opts, instead of overriding. Also we shrank the allocation area for T1969 in order to increase residency sampling frequency. Fixes #17712 - - - - - 9c89a48d by Ömer Sinan Ağacan at 2020-02-05T09:22:52-05:00 Remove CafInfo-related code from STG lambda lift pass After c846618ae0 we don't have accurate CafInfos for Ids in the current module and we're free to introduce new CAFFY or non-CAFFY bindings or change CafInfos of existing binders; so no we no longer need to maintain CafInfos in Core or STG passes. - - - - - 70ddb8bf by Ryan Scott at 2020-02-05T09:23:30-05:00 Add regression test for #17773 - - - - - e8004e5d by Ben Gamari at 2020-02-05T13:55:19-05:00 gitlab-ci: Allow Windows builds to fail again Due to T7702 and the process issues described in #17777. - - - - - 29b72c00 by Ben Gamari at 2020-02-06T11:55:41-05:00 VarSet: Introduce nonDetFoldVarSet - - - - - c4e6b35d by Ben Gamari at 2020-02-06T11:55:41-05:00 Move closeOverKinds and friends to TyCoFVs - - - - - ed2f0e5c by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Reform the free variable finders for types This patch delivers on (much of) #17509. * Introduces the shallow vs deep free variable distinction * Introduce TyCoRep.foldType, foldType :: Monoid a => TyCoFolder env a -> env -> Type -> a and use it in the free variable finders. * Substitution in TyCoSubst * ASSERTs are on for checkValidSubst * checkValidSubst uses shallowTyCoVarsOfTypes etc Quite a few things still to do * We could use foldType in lots of other places * We could use mapType for substitution. (Check that we get good code!) * Some (but not yet all) clients of substitution can now save time by using shallowTyCoVarsOfTypes * All calls to tyCoVarsOfTypes should be inspected; most of them should be shallow. Maybe. * Currently shallowTyCoVarsOfTypes still returns unification variables, but not CoVarHoles. Reason: we need to return unification variables in some of the calls in TcSimplify, eg when promoting. * We should do the same thing for tyCoFVsOfTypes, which is currently unchanged. * tyCoFVsOfTypes returns CoVarHoles, because of the use in TcSimplify.mkResidualConstraints. See Note [Emitting the residual implication in simplifyInfer] * #17509 talks about "relevant" variables too. - - - - - 01a1f4fb by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Use foldTyCo for noFreeVarsOfType - - - - - 0e59afd6 by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Simplify closeOverKinds - - - - - 9ca5c88e by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Use foldTyCo for coVarsOfType - - - - - 5541b87c by Simon Peyton Jones at 2020-02-06T11:55:41-05:00 Use foldTyCo for exactTyCoVarsOfType This entailed * Adding a tcf_view field to TyCoFolder * Moving exactTyCoVarsOtType to TcType. It properly belongs there, since only the typechecker calls this function. But it also means that we can "see" and inline tcView. Metric Decrease: T14683 - - - - - 7c122851 by Simon Peyton Jones at 2020-02-06T11:56:02-05:00 Comments only - - - - - 588acb99 by Adam Sandberg Eriksson at 2020-02-08T10:15:38-05:00 slightly better named cost-centres for simple pattern bindings #17006 ``` main = do print $ g [1..100] a where g xs x = map (`mod` x) xs a :: Int = 324 ``` The above program previously attributed the cost of computing 324 to a cost centre named `(...)`, with this change the cost is attributed to `a` instead. This change only affects simple pattern bindings (decorated variables: type signatures, parens, ~ annotations and ! annotations). - - - - - 309f8cfd by Richard Eisenberg at 2020-02-08T10:16:33-05:00 Remove unnecessary parentheses - - - - - 7755ffc2 by Richard Eisenberg at 2020-02-08T10:16:33-05:00 Introduce IsPass; refactor wrappers. There are two main payloads of this patch: 1. This introduces IsPass, which allows e.g. printing code to ask what pass it is running in (Renamed vs Typechecked) and thus print extension fields. See Note [IsPass] in Hs.Extension 2. This moves the HsWrap constructor into an extension field, where it rightly belongs. This is done for HsExpr and HsCmd, but not for HsPat, which is left as an exercise for the reader. There is also some refactoring around SyntaxExprs, but this is really just incidental. This patch subsumes !1721 (sorry @chreekat). Along the way, there is a bit of refactoring in GHC.Hs.Extension, including the removal of NameOrRdrName in favor of NoGhcTc. This meant that we had no real need for GHC.Hs.PlaceHolder, so I got rid of it. Updates haddock submodule. ------------------------- Metric Decrease: haddock.compiler ------------------------- - - - - - 7d452be4 by Dylan Yudaken at 2020-02-08T10:17:17-05:00 Fix hs_try_putmvar losing track of running cap If hs_try_putmvar was called through an unsafe import, it would lose track of the running cap causing a deadlock - - - - - c2e301ae by Ben Gamari at 2020-02-08T10:17:55-05:00 compiler: Qualify imports of Data.List - - - - - aede171a by Ben Gamari at 2020-02-08T10:17:55-05:00 testsuite: Fix -Wcompat-unqualified-imports issues - - - - - 4435a8e0 by Ben Gamari at 2020-02-08T10:17:55-05:00 Introduce -Wcompat-unqualified-imports This implements the warning proposed in option (B) of the Data.List.singleton CLC [discussion][]. This warning, which is included in `-Wcompat` is intended to help users identify imports of modules that will change incompatibly in future GHC releases. This currently only includes `Data.List` due to the expected specialisation and addition of `Data.List.singleton`. Fixes #17244. [discussion]: https://groups.google.com/d/msg/haskell-core-libraries/q3zHLmzBa5E/PmlAs_kYAQAJ - - - - - 28b5349a by Ben Gamari at 2020-02-08T10:17:55-05:00 Bump stm and process submodules - - - - - 7d04b9f2 by Ben Gamari at 2020-02-08T10:18:31-05:00 hadrian: Allow override of Cabal configuration in hadrian.settings Fixes #17612 by adding a `cabal.configure.opts` key for `hadrian.settings`. - - - - - 88bf81aa by Andreas Klebinger at 2020-02-08T10:19:10-05:00 Optimize unpackCString# to allocate less. unpackCString# is a recursive function which for each iteration returns a Cons cell containing the current Char, and a thunk for unpacking the rest of the string. In this patch we change from storing addr + offset inside this thunk to storing only the addr, simply incrementing the address on each iteration. This saves one word of allocation per unpacked character. For a program like "main = print "<largishString>" this amounts to 2-3% fewer % in bytes allocated. I also removed the now redundant local unpack definitions. This removes one call per unpack operation. - - - - - bec76733 by Ben Gamari at 2020-02-08T10:19:57-05:00 Fix GhcThreaded setting This adopts a patch from NetBSD's packaging fixing the `GhcThreaded` option of the make build system. In addition we introduce a `ghcThreaded` option in hadrian's `Flavour` type. Also fix Hadrian's treatment of the `Use Threaded` entry in `settings`. Previously it would incorrectly claim `Use Threaded = True` if we were building the `threaded` runtime way. However, this is inconsistent with the `make` build system, which defines it to be whether the `ghc` executable is linked against the threaded runtime. Fixes #17692. - - - - - 545cf1e1 by Ben Gamari at 2020-02-08T10:20:37-05:00 hadrian: Depend upon libray dependencies when configuring packages This will hopefully fix #17631. - - - - - 047d3d75 by Ben Gamari at 2020-02-08T10:21:16-05:00 testsuite: Add test for #15316 This is the full testcase for T15316. - - - - - 768e5866 by Julien Debon at 2020-02-08T10:22:07-05:00 doc(Data.List): Add some examples to Data.List - - - - - 3900cb83 by Julien Debon at 2020-02-08T10:22:07-05:00 Apply suggestion to libraries/base/GHC/List.hs - - - - - bd666766 by Ben Gamari at 2020-02-08T10:22:45-05:00 users-guide: Clarify that bundled patsyns were introduced in GHC 8.0 Closes #17094. - - - - - 95741ea1 by Pepe Iborra at 2020-02-08T10:23:23-05:00 Update to hie-bios 0.3.2 style program cradle - - - - - fb5c1912 by Sylvain Henry at 2020-02-08T10:24:07-05:00 Remove redundant case This alternative is redundant and triggers no warning when building with 8.6.5 - - - - - 5d83d948 by Matthew Pickering at 2020-02-08T10:24:43-05:00 Add mkHieFileWithSource which doesn't read the source file from disk cc/ @pepeiborra - - - - - dfdae56d by Andreas Klebinger at 2020-02-08T10:25:20-05:00 Rename ghcAssert to stgAssert in hp2ps/Main.h. This fixes #17763 - - - - - 658f7ac6 by Ben Gamari at 2020-02-08T10:26:00-05:00 includes: Avoid using single-line comments in HsFFI.h While single-line comments are supported by C99, dtrace on SmartOS apparently doesn't support them yet. - - - - - c95920a6 by Ömer Sinan Ağacan at 2020-02-08T10:26:42-05:00 Import qualified Prelude in parser This is in preparation of backwards-incompatible changes in happy. See https://github.com/simonmar/happy/issues/166 - - - - - b6dc319a by Ömer Sinan Ağacan at 2020-02-08T10:27:23-05:00 Add regression test for #12760 The bug seems to be fixed in the meantime, make sure it stays fixed. Closes #12760 - - - - - b3857b62 by Ben Gamari at 2020-02-08T10:28:03-05:00 base: Drop out-of-date comment The comment in GHC.Base claimed that ($) couldn't be used in that module as it was wired-in. However, this is no longer true; ($) is merely known key and is defined in Haskell (with a RuntimeRep-polymorphic type) in GHC.Base. The one piece of magic that ($) retains is that it a special typing rule to allow type inference with higher-rank types (e.g. `runST $ blah`; see Note [Typing rule for ($)] in TcExpr). - - - - - 1183ae94 by Daniel Gröber at 2020-02-08T10:29:00-05:00 rts: Fix Arena blocks accounting for MBlock sized allocations When requesting more than BLOCKS_PER_MBLOCK blocks allocGroup can return a different number of blocks than requested. Here we use the number of requested blocks, however arenaFree will subtract the actual number of blocks we got from arena_blocks (possibly) resulting in a negative value and triggering ASSERT(arena_blocks >= 0). - - - - - 97d59db5 by Daniel Gröber at 2020-02-08T10:29:48-05:00 rts: Fix need_prealloc being reset when retainer profiling is on - - - - - 1f630025 by Krzysztof Gogolewski at 2020-02-09T02:52:27-05:00 Add a test for #15712 - - - - - 2ac784ab by Ben Gamari at 2020-02-09T02:53:05-05:00 hadrian: Add --test-metrics argument Allowing the test metric output to be captured to a file, a la the METRIC_FILE environment variable of the make build system. - - - - - f432d8c6 by Ben Gamari at 2020-02-09T02:53:05-05:00 hadrian: Fix --test-summary argument This appears to be a cut-and-paste error. - - - - - a906595f by Arnaud Spiwack at 2020-02-09T02:53:50-05:00 Fix an outdated note link This link appears to have been forgotten in 0dad81ca5fd1f63bf8a3b6ad09787559e8bd05c0 . - - - - - 3ae83da1 by Alp Mestanogullari at 2020-02-09T02:54:28-05:00 hadrian: Windows fixes (bindists, CI) This commit implements a few Windows-specific fixes which get us from a CI job that can't even get as far as starting the testsuite driver, to a state where we can run the entire testssuite (but have test failures to fix). - Don't forget about a potential extension for the haddock program, when preparing the bindist. - Build the timeout program, used by the testsuite driver on Windows in place of the Python script used elsewhere, using the boot compiler. We could alternatively build it with the compiler that we're going to test but this would be a lot more tedious to write. - Implement a wrapper-script less installation procedure for Windows, in `hadrian/bindist/Makefile. - Make dependencies a bit more accurate in the aforementioned Makefile. - Update Windows/Hadrian CI job accordingly. This patch fixes #17486. - - - - - 82f9be8c by Roland Senn at 2020-02-09T02:55:06-05:00 Fix #14628: Panic (No skolem Info) in GHCi This patch implements the [sugggestion from Simon (PJ)](https://gitlab.haskell.org/ghc/ghc/issues/14628#note_146559): - Make `TcErrors.getSkolemInfo` return a `SkolemInfo` rather than an `Implication`. - If `getSkolemInfo` gets `RuntimeUnk`s, just return a new data constructor in `SkolemInfo`, called `RuntimeUnkSkol`. - In `TcErrors.pprSkols` print something sensible for a `RuntimeUnkSkol`. The `getSkolemInfo` function paniced while formating suggestions to add type annotations (subfunction `suggestAddSig`) to a *"Couldn't match type ‘x’ with ‘y’"* error message. The `getSkolemInfo` function didn't find any Implication value and paniced. With this patch the `getSkolemInfo` function does no longer panic, if it finds `RuntimeUnkSkol`s. As the panic occured while processing an error message, we don't need to implement any new error message! - - - - - b2e18e26 by Andreas Klebinger at 2020-02-09T02:55:46-05:00 Fix -ddump-stg-final. Once again make sure this dumps the STG used for codegen. - - - - - 414e2f62 by Sylvain Henry at 2020-02-09T02:56:26-05:00 Force -fPIC for intree GMP (fix #17799) Configure intree GMP with `--with-pic` instead of patching it. Moreover the correct patching was only done for x86_64/darwin (see #17799). - - - - - f0fd72ee by Sebastian Graf at 2020-02-09T17:22:38-05:00 8.10 Release notes for improvements to the pattern-match checker [skip ci] A little late to the game, but better late than never. - - - - - 00dc0f7e by Ömer Sinan Ağacan at 2020-02-09T17:23:17-05:00 Add regression test for #13142 Closes #13142 - - - - - f3e737bb by Sebastian Graf at 2020-02-10T20:04:09-05:00 Fix long distance info for record updates For record updates where the `record_expr` is a variable, as in #17783: ```hs data PartialRec = No | Yes { a :: Int, b :: Bool } update No = No update r@(Yes {}) = r { b = False } ``` We should make use of long distance info in `-Wincomplete-record-updates` checking. But the call to `matchWrapper` in the `RecUpd` case didn't specify a scrutinee expression, which would correspond to the `record_expr` `r` here. That is fixed now. Fixes #17783. - - - - - 5670881d by Tamar Christina at 2020-02-10T20:05:04-05:00 Fs: Fix UNC remapping code. - - - - - 375b3c45 by Oleg Grenrus at 2020-02-11T05:07:30-05:00 Add singleton to Data.OldList - - - - - de32beff by Richard Eisenberg at 2020-02-11T05:08:10-05:00 Do not create nested quantified constraints Previously, we would accidentally make constraints like forall a. C a => forall b. D b => E a b c as we traversed superclasses. No longer! This patch also expands Note [Eagerly expand given superclasses] to work over quantified constraints; necessary for T16502b. Close #17202 and #16502. test cases: typecheck/should_compile/T{17202,16502{,b}} - - - - - e319570e by Ben Gamari at 2020-02-11T05:08:47-05:00 rts: Use nanosleep instead of usleep usleep was removed in POSIX.1-2008. - - - - - b75e7486 by Ben Gamari at 2020-02-11T05:09:24-05:00 rts: Remove incorrect assertions around MSG_THROWTO messages Previously we would assert that threads which are sending a `MSG_THROWTO` message must have their blocking status be blocked on the message. In the usual case of a thread throwing to another thread this is guaranteed by `stg_killThreadzh`. However, `throwToSelf`, used by the GC to kill threads which ran out of heap, failed to guarantee this. Noted while debugging #17785. - - - - - aba51b65 by Sylvain Henry at 2020-02-11T05:10:04-05:00 Add arithmetic exception primops (#14664) - - - - - b157399f by Ben Gamari at 2020-02-11T05:10:40-05:00 configure: Don't assume Gnu linker on Solaris Compl Yue noticed that the linker was dumping the link map on SmartOS. This is because Smartos uses the Solaris linker, which uses the `-64` flag, not `-m64` like Gnu ld, to indicate that it should link for 64-bits. Fix the configure script to handle the Solaris linker correctly. - - - - - d8d73d77 by Simon Peyton Jones at 2020-02-11T05:11:18-05:00 Notes only: telescopes This documentation-only patch fixes #17793 - - - - - 58a4ddef by Alp Mestanogullari at 2020-02-11T05:12:17-05:00 hadrian: build (and ship) iserv on Windows - - - - - 82023524 by Matthew Pickering at 2020-02-11T18:04:17-05:00 TemplateHaskellQuotes: Allow nested splices There is no issue with nested splices as they do not require any compile time code execution. All execution is delayed until the top-level splice. - - - - - 50e24edd by Ömer Sinan Ağacan at 2020-02-11T18:04:57-05:00 Remove Hadrian's copy of (Data.Functor.<&>) The function was added to base with base-4.11 (GHC 8.4) - - - - - f82a2f90 by Sylvain Henry at 2020-02-12T01:56:46-05:00 Document GMP build [skip ci] - - - - - da7f7479 by Sylvain Henry at 2020-02-12T01:57:27-05:00 Module hierarchy: ByteCode and Runtime (cf #13009) Update haddock submodule - - - - - 04f51297 by Ömer Sinan Ağacan at 2020-02-12T01:58:11-05:00 Fix naming of tests for #12923 - - - - - 31fc3321 by Ömer Sinan Ağacan at 2020-02-12T01:58:11-05:00 Add regression test for #12926 Closes #12926 - - - - - f0c0ee7d by Krzysztof Gogolewski at 2020-02-12T01:58:51-05:00 Fix order of arguments in specializer (#17801) See https://gitlab.haskell.org/ghc/ghc/issues/17801#note_253330 No regression test, as it's hard to trigger. - - - - - 059c3c9d by Sebastian Graf at 2020-02-12T11:00:58+01:00 Separate CPR analysis from the Demand analyser The reasons for that can be found in the wiki: https://gitlab.haskell.org/ghc/ghc/wikis/nested-cpr/split-off-cpr We now run CPR after demand analysis (except for after the final demand analysis run just before code gen). CPR got its own dump flags (`-ddump-cpr-anal`, `-ddump-cpr-signatures`), but not its own flag to activate/deactivate. It will run with `-fstrictness`/`-fworker-wrapper`. As explained on the wiki page, this step is necessary for a sane Nested CPR analysis. And it has quite positive impact on compiler performance: Metric Decrease: T9233 T9675 T9961 T15263 - - - - - f5ffd8d9 by Ben Gamari at 2020-02-12T17:22:37-05:00 base: Expose GHC.Unicode.unicodeVersion This exposes a Data.Version.Version representing the version of the Unicode database used by `base`. This should clear up some confusion I have seen in tickets regarding with which Unicode versions a given GHC can be expected to work. While in town I also regenerated (but did not update) the Unicode database with database 12.0.0. Strangely, the file cited in the README no longer existed. Consequently, I used https://www.unicode.org/Public/12.0.0/ucd/UnicodeData.txt and was slightly surprised to find that there were a few changes. - - - - - 6c2585e0 by Ben Gamari at 2020-02-12T17:22:37-05:00 base: Update Unicode database to 12.1.0 Using `curl https://www.unicode.org/Public/12.1.0/ucd/UnicodeData.txt | libraries/base/cbits/ubconfc 12.1.0`. - - - - - df084681 by Krzysztof Gogolewski at 2020-02-12T23:58:52+01:00 Always display inferred variables using braces We now always show "forall {a}. T" for inferred variables, previously this was controlled by -fprint-explicit-foralls. This implements part 1 of https://github.com/ghc-proposals/ghc-proposals/pull/179. Part of GHC ticket #16320. Furthermore, when printing a levity restriction error, we now display the HsWrap of the expression. This lets users see the full elaboration with -fprint-typechecker-elaboration (see also #17670) - - - - - 16d643cf by Sylvain Henry at 2020-02-13T09:16:04-05:00 Remove -ddump-srts flag This flag is deemed not useful. - - - - - fa28ae95 by Sylvain Henry at 2020-02-13T09:16:04-05:00 Fix flag documentation (#17826) - - - - - 1bfd8259 by Sylvain Henry at 2020-02-13T09:16:43-05:00 Ensure that Hadrian is built correctly before using it When Hadrian failed to build, the script would pick a previously built Hadrian (if available) instead of failing. - - - - - cd6e786a by Ömer Sinan Ağacan at 2020-02-14T05:29:56-05:00 Add test for #17648 - - - - - 9f2c3677 by Sylvain Henry at 2020-02-14T05:30:39-05:00 GMP expects the Target platform as --host parameter - - - - - aa6086fd by Oleg Grenrus at 2020-02-14T05:31:16-05:00 Add explicit LANGUAGE Safe to template-haskell (cherry picked from commit a5e0f376821ca882880b03b07b451aa574e289ec) - - - - - af6a0c36 by Ben Gamari at 2020-02-14T05:31:53-05:00 hadrian: Add execution and target architecture to stage-compilation figure - - - - - cf739945 by Sylvain Henry at 2020-02-14T05:32:37-05:00 Module hierarchy: HsToCore (cf #13009) - - - - - 719db318 by Simon Peyton Jones at 2020-02-14T05:33:16-05:00 De-duplicate overlapping Notes Documentation only. Fixes #17827 - - - - - 7550417a by Sylvain Henry at 2020-02-14T05:33:56-05:00 Hadrian: drop Sphinx flag checking for PDF documentation (#17825) It seems that Sphinx produces the ghc-flags.txt in doc/users_guide/_build rather than pdfRoot. We could copy ghc-flags.txt into pdfRoot (like happens naturally in the HTML case) but the benefit is pretty small. Let's just only check the HTML case. - - - - - 813842f4 by Ben Gamari at 2020-02-14T10:16:36-05:00 make: Be more selective in building windows-extra-src tarball - - - - - 0725f4bb by Ben Gamari at 2020-02-14T10:16:36-05:00 Rework handling of win32 toolchain tarballs - - - - - 565ce7ae by Ben Gamari at 2020-02-14T10:16:36-05:00 gitlab-ci: Consolidate CI logic This moves nearly all of the CI logic to .gitlab/ci.sh. This improves things in a number of ways: * it's harder for inconsistencies to arise between architectures * it's easier to share logic between architectures * on Windows, it's easier to ensure that all CI steps are executed from within a properly initialized mingw session. While in town I also add a FreeBSD build job and update the Windows job to use the gitlab-runner PowerShell executor, since cmd.exe will be deprecated soon (fixing #17699). - - - - - 9cbace74 by Ben Gamari at 2020-02-14T10:16:36-05:00 gitlab-ci: Deduplicate nightly job configuration - - - - - 6e837144 by Ben Gamari at 2020-02-14T10:16:36-05:00 integer-gmp: Fix unused command-line argument -L is only needed during linking. - - - - - e5ee07ab by Ben Gamari at 2020-02-14T10:16:36-05:00 testsuite: Don't ask sed to operate in-place on symlinks Some sed implementations (e.g. FreeBSD) refuse to operate in-place on symlinks. - - - - - 71e5e68f by Ben Gamari at 2020-02-14T10:16:36-05:00 testsuite: Disable tests that assume name of libstdc++ on FreeBSD - - - - - 7b2da0f4 by Ben Gamari at 2020-02-14T10:16:36-05:00 testsuite: Mark T6132 as broken on FreeBSD - - - - - 8ef7a15a by Ben Gamari at 2020-02-14T10:16:36-05:00 testsuite/T16930: Don't rely on gnu grep specific --include In BSD grep this flag only affects directory recursion. - - - - - 6060003e by Ben Gamari at 2020-02-14T10:16:36-05:00 Pass -Wno-unused-command-line-arguments during link on FreeBSD FreeBSD cc throws a warning if we pass -pthread without actually using any pthread symbols. - - - - - 97497bae by Ben Gamari at 2020-02-14T10:16:36-05:00 base: Always clamp reads/writes to 2GB in length Previously we did this only on Darwin due to #17414. However, even on other platforms >2GB writes are on shaky ground. POSIX explicitly says that the result is implementation-specified and Linux will write at most 0x7ffff000, even on 64-bit platforms. Moreover, getting the sign of the syscall result correct is tricky, as demonstrated by the fact that T17414 currently fails on FreeBSD. For simplicity we now just uniformly clamp to 0x7ffff000 on all platforms. - - - - - 49be2a3f by Ben Gamari at 2020-02-14T10:16:36-05:00 configure: Fix sphinx version test The check for the "v" prefix is redundant. - - - - - f7f7a556 by Ben Gamari at 2020-02-14T10:16:37-05:00 users-guide: Fix unknown link targets - - - - - a204102c by Ben Gamari at 2020-02-14T10:16:37-05:00 docs/compare-flags: Don't use python f-strings - - - - - 92e15a37 by Ben Gamari at 2020-02-14T10:16:37-05:00 gitlab-ci: Fix various shellcheck warnings - - - - - 459f7c6e by Ben Gamari at 2020-02-14T10:16:37-05:00 hadrian: Drop empty arguments from target list Fixes #17748. - - - - - c06df28d by Ben Gamari at 2020-02-14T10:16:37-05:00 users-guide: Fix "invalid file" failure I have no idea how this worked previously. Different Python version? - - - - - 3fe8444f by Ben Gamari at 2020-02-14T10:16:59-05:00 testsuite: Mark T7702 as fragile on Windows Due to #16799. There was previously an attempt to mark it as broken but the `opsys` name was incorrect. - - - - - fe02f781 by Ben Gamari at 2020-02-14T10:16:59-05:00 testsuite: Assert the opsys names are known Previously opsys would take any string. This meant it was very easy for a typo to silently render the predicate ineffective. Fix this by checking the given operating system name against a list of known values. - - - - - 149e2a3a by Ben Gamari at 2020-02-14T10:16:59-05:00 compare-flags: Don't rely on encoding flag of subprocess.check_output Apparently it isn't supported by some slightly older Python versions. - - - - - 798d59f6 by Ben Gamari at 2020-02-14T10:16:59-05:00 rts: Add more debug output to failed path in onIOComplete This will help track down #17035. - - - - - e35f3f98 by Ben Gamari at 2020-02-14T10:16:59-05:00 gitlab-ci: Allow i386 Windows builds to fail again Due to the resistance of #17736 to resolution. - - - - - 261a3cf8 by Ben Gamari at 2020-02-14T10:17:00-05:00 gitlab-ci: Build integer-simple job in the validate flavour - - - - - b613a961 by Ben Gamari at 2020-02-14T10:17:00-05:00 gitlab-ci: Always use mingw64 python on Windows - - - - - 1bc8c8cd by Ben Gamari at 2020-02-14T10:17:00-05:00 gitlab-ci: Allow Windows build to fail due to #17777 The fact that `exec` isn't POSIX compliant means that things can break in arbitrarily bad ways. Sometimes things happen to work correctly but sadly this isn't always the case. - - - - - ac63020d by Ben Gamari at 2020-02-14T10:17:00-05:00 gitlab-ci: Drop unnecessary GHC_VERSION check - - - - - 6926f369 by Ben Gamari at 2020-02-14T10:17:00-05:00 Bump process submodule Folds in the second part of Phyx's Windows process exit fixes [1], hopefully finally resolving issue #17480. [1] https://github.com/haskell/process/pull/160 - - - - - 584eee71 by Tamar Christina at 2020-02-14T10:17:00-05:00 SysTools: Use "process job" when spawning processes on Windows GHC should make calls using process jobs when calling out to GCC and LD. The reason is these use the exec () family of posix functions. Window's process model doesn't allow replacement of processes so this is emulated by creating a new process and immediately exiting the old one. Because of this when using normal Windows wait functions you would return even without the child process having finished. In this case if you are depending on data from the child you will enter a race condition. The usual fix for this is to use process jobs and wait for the termination of all children that have ever been spawn by the process you called. But also waiting for the freeing of all resources. - - - - - ecabfa28 by Tamar Christina at 2020-02-14T10:17:00-05:00 Revert "compiler: Disable atomic renaming on Windows" The original reason this was disabled should be fixed by the previous commit. This reverts commit 1c1b63d63efe8b0f789aa7d5b87cfac3edd213eb. - - - - - 06d60c66 by Ben Gamari at 2020-02-14T10:17:00-05:00 Bump Cabal submodule - - - - - 8cabb384 by Ben Gamari at 2020-02-14T10:17:00-05:00 compare-flags: Fix output - - - - - 8cf646d3 by Ben Gamari at 2020-02-14T10:17:00-05:00 users-guide: Document -ddump-srts - - - - - 932307a5 by Ben Gamari at 2020-02-14T10:17:00-05:00 users-guide: Fix broken reference - - - - - e77818de by Ben Gamari at 2020-02-15T09:26:55-05:00 Accept performance changes These manifested in the integer-simple job. Metric Decrease: T12227 T5549 T14936 T4830 Conversions T5237 T8766 T4801 T10359 Metric Increase: T12234 T6048 T3294 T14683 T3064 T9872b T9872c T783 T5837 T10678 T14697 T5631 T9203 T13719 T12707 T13056 T9630 T10547 T9872d T1969 WWRec T10370 T5321FD haddock.Cabal T5642 T9872a T15263 T12425 MultiLayerModules T5205 T9233 T13379 haddock.base T9020 T13035 T12150 T9961 - - - - - 785008c1 by Ben Gamari at 2020-02-15T09:30:13-05:00 testsuite: Sort test names in expected change output - - - - - 9e851472 by Ömer Sinan Ağacan at 2020-02-16T10:38:41+03:00 Revert "users-guide: Document -ddump-srts" This reverts commit 8cf646d36b02b8ea1c289cb52781c9171853b514. The flag was removed by 16d643cf. [ci skip] - - - - - 9792c816 by Ben Gamari at 2020-02-16T09:47:08-05:00 testsuite: Probe whether symlinks are usable on Windows Closes #17706. - - - - - ee1e5342 by Vladislav Zavialov at 2020-02-16T09:47:44-05:00 Fix the "unused terminals: 2" warning in Parser.y - - - - - b4a8ce52 by Roland Senn at 2020-02-18T20:14:42-05:00 If a :reload finds syntax errors in the module graph, remove the loaded modules. (Fixes #17549) The processing in `compiler/main/GhcMake.hs` computes the ModuleGraph. If it finds errors in the module header or in the import specifications, then the new module graph is incomplete and should not be used. The code before #17549 just reported the errors and left the old ModuleGraph in place. The new code of this MR replaces the old ModuleGraph with an empty one. - - - - - d7029cc0 by Sylvain Henry at 2020-02-18T20:15:30-05:00 Hadrian: refactor GMP in-tree build support (#17756) * Hadrian doesn't use integer-gmp/config.mk file anymore to determine if building GMP in-tree is required. "config.mk" is created by Cabal when the integer-gmp package is configured and this file is still untracked by Hadrian. This led to a tricky configure "race" because "config.mk" is built by the "setup-config" rule, but this rule is also used to find dependencies, in particular the "ghc-gmp.h" header, but the creation of this file was depending (without being tracked) on "config.mk". Now Hadrian only builds in-tree GMP if `--with-intree-gmp` is passed to the top-level configure script. * in-tree GMP isn't built once for all in a fixed stage (Stage1) anymore. It is built per stage which is required if we build a cross-compiler * switching between in-tree and external GMP is now supported without having to clean the build directory first. * "wrappers.c" now includes "ghc-gmp.h" instead of "ghc.h". It helps ensuring that the build system generates "ghc-gmp.h". * build in-tree GMP in "<root>/stageN/gmp/gmpbuild" and produce useful artefacts (libgmp.a, gmp.h, objs/*.o) in "<root>/stageN/gmp" - - - - - 40d917fb by Vladislav Zavialov at 2020-02-18T20:16:07-05:00 Remove the MonadFail P instance There were two issues with this instance: * its existence meant that a pattern match failure in the P monad would produce a user-visible parse error, but the error message would not be helpful to the user * due to the MFP migration strategy, we had to use CPP in Lexer.x, and that created issues for #17750 Updates haddock submodule. - - - - - 5a1ce45d by Joshua Price at 2020-02-18T20:16:47-05:00 Fix unboxed tuple size limit (#17837) - - - - - 192caf58 by Vladislav Zavialov at 2020-02-18T20:17:24-05:00 Fix testsuite driver output (#17847) - - - - - 1500f089 by Sylvain Henry at 2020-02-18T20:18:12-05:00 Modules: Llvm (#13009) - - - - - d53e81c0 by Niklas Hambüchen at 2020-02-20T10:36:22-05:00 8.10 Release notes for atomic .o writes [skip ci] - - - - - 19680ee5 by Niklas Hambüchen at 2020-02-20T10:37:53-05:00 8.10 Release notes for --disable-delayed-os-memory-return [skip ci] - - - - - 74ad75e8 by Simon Peyton Jones at 2020-02-20T21:17:57-05:00 Re-implement unsafe coercions in terms of unsafe equality proofs (Commit message written by Omer, most of the code is written by Simon and Richard) See Note [Implementing unsafeCoerce] for how unsafe equality proofs and the new unsafeCoerce# are implemented. New notes added: - [Checking for levity polymorphism] in CoreLint.hs - [Implementing unsafeCoerce] in base/Unsafe/Coerce.hs - [Patching magic definitions] in Desugar.hs - [Wiring in unsafeCoerce#] in Desugar.hs Only breaking change in this patch is unsafeCoerce# is not exported from GHC.Exts, instead of GHC.Prim. Fixes #17443 Fixes #16893 NoFib ----- -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS -0.1% 0.0% -0.0% -0.0% -0.0% CSD -0.1% 0.0% -0.0% -0.0% -0.0% FS -0.1% 0.0% -0.0% -0.0% -0.0% S -0.1% 0.0% -0.0% -0.0% -0.0% VS -0.1% 0.0% -0.0% -0.0% -0.0% VSD -0.1% 0.0% -0.0% -0.0% -0.1% VSM -0.1% 0.0% -0.0% -0.0% -0.0% anna -0.0% 0.0% -0.0% -0.0% -0.0% ansi -0.1% 0.0% -0.0% -0.0% -0.0% atom -0.1% 0.0% -0.0% -0.0% -0.0% awards -0.1% 0.0% -0.0% -0.0% -0.0% banner -0.1% 0.0% -0.0% -0.0% -0.0% bernouilli -0.1% 0.0% -0.0% -0.0% -0.0% binary-trees -0.1% 0.0% -0.0% -0.0% -0.0% boyer -0.1% 0.0% -0.0% -0.0% -0.0% boyer2 -0.1% 0.0% -0.0% -0.0% -0.0% bspt -0.1% 0.0% -0.0% -0.0% -0.0% cacheprof -0.1% 0.0% -0.0% -0.0% -0.0% calendar -0.1% 0.0% -0.0% -0.0% -0.0% cichelli -0.1% 0.0% -0.0% -0.0% -0.0% circsim -0.1% 0.0% -0.0% -0.0% -0.0% clausify -0.1% 0.0% -0.0% -0.0% -0.0% comp_lab_zift -0.1% 0.0% -0.0% -0.0% -0.0% compress -0.1% 0.0% -0.0% -0.0% -0.0% compress2 -0.1% 0.0% -0.0% -0.0% -0.0% constraints -0.1% 0.0% -0.0% -0.0% -0.0% cryptarithm1 -0.1% 0.0% -0.0% -0.0% -0.0% cryptarithm2 -0.1% 0.0% -0.0% -0.0% -0.0% cse -0.1% 0.0% -0.0% -0.0% -0.0% digits-of-e1 -0.1% 0.0% -0.0% -0.0% -0.0% digits-of-e2 -0.1% 0.0% -0.0% -0.0% -0.0% dom-lt -0.1% 0.0% -0.0% -0.0% -0.0% eliza -0.1% 0.0% -0.0% -0.0% -0.0% event -0.1% 0.0% -0.0% -0.0% -0.0% exact-reals -0.1% 0.0% -0.0% -0.0% -0.0% exp3_8 -0.1% 0.0% -0.0% -0.0% -0.0% expert -0.1% 0.0% -0.0% -0.0% -0.0% fannkuch-redux -0.1% 0.0% -0.0% -0.0% -0.0% fasta -0.1% 0.0% -0.5% -0.3% -0.4% fem -0.1% 0.0% -0.0% -0.0% -0.0% fft -0.1% 0.0% -0.0% -0.0% -0.0% fft2 -0.1% 0.0% -0.0% -0.0% -0.0% fibheaps -0.1% 0.0% -0.0% -0.0% -0.0% fish -0.1% 0.0% -0.0% -0.0% -0.0% fluid -0.1% 0.0% -0.0% -0.0% -0.0% fulsom -0.1% 0.0% +0.0% +0.0% +0.0% gamteb -0.1% 0.0% -0.0% -0.0% -0.0% gcd -0.1% 0.0% -0.0% -0.0% -0.0% gen_regexps -0.1% 0.0% -0.0% -0.0% -0.0% genfft -0.1% 0.0% -0.0% -0.0% -0.0% gg -0.1% 0.0% -0.0% -0.0% -0.0% grep -0.1% 0.0% -0.0% -0.0% -0.0% hidden -0.1% 0.0% -0.0% -0.0% -0.0% hpg -0.1% 0.0% -0.0% -0.0% -0.0% ida -0.1% 0.0% -0.0% -0.0% -0.0% infer -0.1% 0.0% -0.0% -0.0% -0.0% integer -0.1% 0.0% -0.0% -0.0% -0.0% integrate -0.1% 0.0% -0.0% -0.0% -0.0% k-nucleotide -0.1% 0.0% -0.0% -0.0% -0.0% kahan -0.1% 0.0% -0.0% -0.0% -0.0% knights -0.1% 0.0% -0.0% -0.0% -0.0% lambda -0.1% 0.0% -0.0% -0.0% -0.0% last-piece -0.1% 0.0% -0.0% -0.0% -0.0% lcss -0.1% 0.0% -0.0% -0.0% -0.0% life -0.1% 0.0% -0.0% -0.0% -0.0% lift -0.1% 0.0% -0.0% -0.0% -0.0% linear -0.1% 0.0% -0.0% -0.0% -0.0% listcompr -0.1% 0.0% -0.0% -0.0% -0.0% listcopy -0.1% 0.0% -0.0% -0.0% -0.0% maillist -0.1% 0.0% -0.0% -0.0% -0.0% mandel -0.1% 0.0% -0.0% -0.0% -0.0% mandel2 -0.1% 0.0% -0.0% -0.0% -0.0% mate -0.1% 0.0% -0.0% -0.0% -0.0% minimax -0.1% 0.0% -0.0% -0.0% -0.0% mkhprog -0.1% 0.0% -0.0% -0.0% -0.0% multiplier -0.1% 0.0% -0.0% -0.0% -0.0% n-body -0.1% 0.0% -0.0% -0.0% -0.0% nucleic2 -0.1% 0.0% -0.0% -0.0% -0.0% para -0.1% 0.0% -0.0% -0.0% -0.0% paraffins -0.1% 0.0% -0.0% -0.0% -0.0% parser -0.1% 0.0% -0.0% -0.0% -0.0% parstof -0.1% 0.0% -0.0% -0.0% -0.0% pic -0.1% 0.0% -0.0% -0.0% -0.0% pidigits -0.1% 0.0% -0.0% -0.0% -0.0% power -0.1% 0.0% -0.0% -0.0% -0.0% pretty -0.1% 0.0% -0.1% -0.1% -0.1% primes -0.1% 0.0% -0.0% -0.0% -0.0% primetest -0.1% 0.0% -0.0% -0.0% -0.0% prolog -0.1% 0.0% -0.0% -0.0% -0.0% puzzle -0.1% 0.0% -0.0% -0.0% -0.0% queens -0.1% 0.0% -0.0% -0.0% -0.0% reptile -0.1% 0.0% -0.0% -0.0% -0.0% reverse-complem -0.1% 0.0% -0.0% -0.0% -0.0% rewrite -0.1% 0.0% -0.0% -0.0% -0.0% rfib -0.1% 0.0% -0.0% -0.0% -0.0% rsa -0.1% 0.0% -0.0% -0.0% -0.0% scc -0.1% 0.0% -0.1% -0.1% -0.1% sched -0.1% 0.0% -0.0% -0.0% -0.0% scs -0.1% 0.0% -0.0% -0.0% -0.0% simple -0.1% 0.0% -0.0% -0.0% -0.0% solid -0.1% 0.0% -0.0% -0.0% -0.0% sorting -0.1% 0.0% -0.0% -0.0% -0.0% spectral-norm -0.1% 0.0% -0.0% -0.0% -0.0% sphere -0.1% 0.0% -0.0% -0.0% -0.0% symalg -0.1% 0.0% -0.0% -0.0% -0.0% tak -0.1% 0.0% -0.0% -0.0% -0.0% transform -0.1% 0.0% -0.0% -0.0% -0.0% treejoin -0.1% 0.0% -0.0% -0.0% -0.0% typecheck -0.1% 0.0% -0.0% -0.0% -0.0% veritas -0.0% 0.0% -0.0% -0.0% -0.0% wang -0.1% 0.0% -0.0% -0.0% -0.0% wave4main -0.1% 0.0% -0.0% -0.0% -0.0% wheel-sieve1 -0.1% 0.0% -0.0% -0.0% -0.0% wheel-sieve2 -0.1% 0.0% -0.0% -0.0% -0.0% x2n1 -0.1% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min -0.1% 0.0% -0.5% -0.3% -0.4% Max -0.0% 0.0% +0.0% +0.0% +0.0% Geometric Mean -0.1% -0.0% -0.0% -0.0% -0.0% Test changes ------------ - break006 is marked as broken, see #17833 - The compiler allocates less when building T14683 (an unsafeCoerce#- heavy happy-generated code) on 64-platforms. Allocates more on 32-bit platforms. - Rest of the increases are tiny amounts (still enough to pass the threshold) in micro-benchmarks. I briefly looked at each one in a profiling build: most of the increased allocations seem to be because of random changes in the generated code. Metric Decrease: T14683 Metric Increase: T12150 T12234 T12425 T13035 T14683 T5837 T6048 Co-Authored-By: Richard Eisenberg <rae at cs.brynmawr.edu> Co-Authored-By: Ömer Sinan Ağacan <omeragacan at gmail.com> - - - - - 6880d6aa by Sylvain Henry at 2020-02-20T21:18:48-05:00 Disentangle DynFlags and SDoc Remove several uses of `sdocWithDynFlags`. The remaining ones are mostly CodeGen related (e.g. depend on target platform constants) and will be fixed separately. Metric Decrease: T12425 T9961 WWRec T1969 T14683 - - - - - 70a90110 by Julien Debon at 2020-02-20T21:19:27-05:00 doc(List): Add examples to GHC.List * Add examples * Cleanup documentation * Clarify merge process and Marge bot - - - - - c8439fc7 by Peter Trommler at 2020-02-20T21:20:05-05:00 Fix testsuite on powerpc64le Remove expect broken on recomp tests, #11260 was closed by !2264 and #11323 most likely by !2264 as well. GHCi scripts tests work on GHCi but not the external interpreter, adjust test configuration accordingly. Fixes unexpected passes. Mark test requiring DWARF expect fail on powerpc64[le] for #11261. - - - - - 65b7256a by Ömer Sinan Ağacan at 2020-02-20T21:20:45-05:00 Use concatMap(M) instead of `concat . map` and the monadic variant - - - - - 8b76d457 by Roland Senn at 2020-02-20T21:21:28-05:00 Fix #17832: Weird handling of exports named main in 8.10-rc1 Switching from `lookupGlobalOccRn_maybe` to `lookupInfoOccRn` to check whether a `main` function is in scope. Unfortunately `lookupGlobalOccRn_maybe` complains if there are multiple `main` functions in scope. - - - - - 466e1ad5 by Krzysztof Gogolewski at 2020-02-20T21:22:11-05:00 Use TTG for HsSplicedT constructor The constructor HsSplicedT occurs only in the GhcTc pass. This enforces this fact statically via TTG. - - - - - 4e622fca by Alexis King at 2020-02-20T21:22:49-05:00 Normalize types when dropping absent arguments from workers fixes #17852 - - - - - a533e547 by Adam Sandberg Eriksson at 2020-02-20T21:23:31-05:00 Mention users guide and release notes in merge request template - - - - - 05251b17 by Ben Gamari at 2020-02-20T21:24:08-05:00 gitlab-ci: Fix typo in BIN_DIST_PREP_TAR_COMP variable name - - - - - f44c7e67 by Ben Gamari at 2020-02-20T21:24:46-05:00 gitlab-ci: Avoid duplicating ~/.cabal contents with every build Previously our attempt to cache the cabal store would `cp cabal-cache ~/.cabal`. However, if the latter already existed this meant that we would end up with ~/.cabal/cabal-cache. Not only would this not help caching but it would exponentially grow the size of ~/.cabal. Not good! - - - - - c5ec9965 by Ben Gamari at 2020-02-20T21:56:13-05:00 GHC.Hs.Extension: Use Type instead of * - - - - - 89cb4cc4 by Ben Gamari at 2020-02-20T21:56:13-05:00 Use Type instead of * in GHC - - - - - 04eb0d6c by Ben Gamari at 2020-02-20T21:56:13-05:00 Enable -Wstar-is-type in -Wall As noted in [proposal 0143][proposal] this is supposed to happen in 8.12. Also fix an incorrect claim in the users guide that -Wstar-is-type is enabled by default. [proposal]: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0143-remove-star-kind.rst - - - - - 6de966f1 by Andreas Klebinger at 2020-02-20T21:56:15-05:00 Fix #17724 by having occAnal preserve used bindings. It sometimes happened that occAnal would remove bindings as dead code by relying on bindings to be in dependency order. The fix was contributed by SPJ. - - - - - abd7f962 by Ben Gamari at 2020-02-20T21:56:15-05:00 users-guide: Mention dependency on `exceptions` in release notes Fixes #17845. - - - - - 58175379 by Sylvain Henry at 2020-02-20T21:56:20-05:00 Hadrian: minor GMP refactoring Somehow I forgot to totally remove `gmpContext` in d7029cc09edc052c2f97effe33233c53340fcce0. This patch fixes it and adds some additional comments. - - - - - 33fa8d94 by Ryan Scott at 2020-02-20T21:56:21-05:00 Generalize liftData to work over any Quote (#17857) The Overloaded Quotations proposal generalized the type of `lift` to work over any `Quote`, but not the type of `liftData`, leading to #17857. Thankfully, generalizing `liftData` is extremely straightforward. Fixes #17857. - - - - - 3cea6795 by Sylvain Henry at 2020-02-20T21:56:23-05:00 Make: fix sdist target (#17848) - - - - - e2cce997 by Sylvain Henry at 2020-02-20T21:56:23-05:00 Hadrian: fix source-dist target (#17849) - - - - - 0a4c89b2 by Matthew Pickering at 2020-02-21T20:44:45-05:00 Special case `mkTyConApp liftedTypeKind []` We really need to make sure that these are shared because otherwise GHC will allocate thousands of identical `TyConApp` nodes. See #17292 ------------------------- Metric Decrease: haddock.Cabal T14683 ------------------------- - - - - - 0482f58a by Matthew Pickering at 2020-02-21T20:45:21-05:00 TH: wrapGenSyns, don't split the element type too much The invariant which allowed the pervious method of splitting the type of the body to find the type of the elements didn't work in the new overloaded quotation world as the type can be something like `WriterT () m a` rather than `Q a` like before. Fixes #17839 - - - - - be7068a6 by Vladislav Zavialov at 2020-02-21T20:45:59-05:00 Parser API annotations: RealSrcLoc During parsing, GHC collects lexical information about AST nodes and stores it in a map. It is needed to faithfully restore original source code, e.g. compare these expressions: a = b a = b The position of the equality sign is not recorded in the AST, so it must be stored elsewhere. This system is described in Note [Api annotations]. Before this patch, the mapping was represented by: Map (SrcSpan, AnnKeywordId) SrcSpan After this patch, the mapping is represented by: Map (RealSrcSpan, AnnKeywordId) RealSrcSpan The motivation behind this change is to avoid using the Ord SrcSpan instance (required by Map here), as it interferes with #17632 (see the discussion there). SrcSpan is isomorphic to Either String RealSrcSpan, but we shouldn't use those strings as Map keys. Those strings are intended as hints to the user, e.g. "<interactive>" or "<compiler-generated code>", so they are not a valid way to identify nodes in the source code. - - - - - 240f5bf6 by Sylvain Henry at 2020-02-21T20:46:40-05:00 Modules: Driver (#13009) submodule updates: nofib, haddock - - - - - 9d094111 by Sylvain Henry at 2020-02-21T20:47:19-05:00 Hadrian: `docs` rule needs `configure` (#17840) - - - - - 1674353a by Ben Gamari at 2020-02-23T17:31:19-05:00 fs: Port fixes from ghc-jailbreak repository * Override rename, unlink, and remove * Factor out wchar conversion - - - - - 853210f2 by Adam Sandberg Ericsson at 2020-02-23T17:32:03-05:00 show gcc linker options in configure summary - - - - - 2831544a by Adam Sandberg Ericsson at 2020-02-23T17:32:44-05:00 hadrian: docs depend on stage1 ghc - - - - - 1d9df9e0 by Adam Sandberg Ericsson at 2020-02-23T17:33:23-05:00 ci: after 5ce63d52fed the linux bindist for doc-tarball has changed name - - - - - 26e8fff3 by Vladislav Zavialov at 2020-02-24T02:05:30-05:00 Remove Ord SrcLoc, Ord SrcSpan Before this patch, GHC relied on Ord SrcSpan to identify source elements, by using SrcSpan as Map keys: blackList :: Map SrcSpan () -- compiler/GHC/HsToCore/Coverage.hs instanceMap :: Map SrcSpan Name -- compiler/GHC/HsToCore/Docs.hs Firstly, this design is not valid in presence of UnhelpfulSpan, as it distinguishes between UnhelpfulSpan "X" and UnhelpfulSpan "Y", but those strings are messages for the user, unfit to serve as identifiers for source elements. Secondly, this design made it hard to extend SrcSpan with additional data. Recall that the definition of SrcSpan is: data SrcSpan = RealSrcSpan !RealSrcSpan | UnhelpfulSpan !FastString Say we want to extend the RealSrcSpan constructor with additional information: data SrcSpan = RealSrcSpan !RealSrcSpan !AdditionalInformation | UnhelpfulSpan !FastString getAdditionalInformation :: SrcSpan -> AdditionalInformation getAdditionalInformation (RealSrcSpan _ a) = a Now, in order for Map SrcSpan to keep working correctly, we must *ignore* additional information when comparing SrcSpan values: instance Ord SrcSpan where compare (RealSrcSpan r1 _) (RealSrcSpan r2 _) = compare r1 r2 ... However, this would violate an important law: a == b therefore f a == f b Ignoring AdditionalInformation in comparisons would mean that with f=getAdditionalInformation, the law above does not hold. A more robust design is to avoid Ord SrcSpan altogether, which is what this patch implements. The mappings are changed to use RealSrcSpan instead: blackList :: Set RealSrcSpan -- compiler/GHC/HsToCore/Coverage.hs instanceMap :: Map RealSrcSpan Name -- compiler/GHC/HsToCore/Docs.hs All SrcSpan comparisons are now done with explicit comparison strategies: SrcLoc.leftmost_smallest SrcLoc.leftmost_largest SrcLoc.rightmost_smallest These strategies are not subject to the law mentioned above and can easily discard both the string stored in UnhelpfulSpan and AdditionalInformation. Updates haddock submodule. - - - - - 5aa6c188 by Ben Gamari at 2020-02-24T02:06:09-05:00 users-guide: Shuffle text - - - - - e3f17413 by Ben Gamari at 2020-02-24T02:06:09-05:00 users-guide: Drop old release notes - - - - - 84dd9610 by Ben Gamari at 2020-02-24T02:06:09-05:00 Bump directory submodule to 1.3.6.0 - - - - - e295a024 by Stefan Pavikevik at 2020-02-24T20:53:44-05:00 check for safe arguments, raising error when invalid (fix #17720) - - - - - 354e2787 by Krzysztof Gogolewski at 2020-02-24T20:54:35-05:00 Comments, small refactor * Remove outdated Note [HsForAllTy tyvar binders] and [Context quantification]. Since the wildcard refactor 1e041b7382, HsForAllTy no longer has an flag controlling explicity. The field `hsq_implicit` is gone too. The current situation is covered by Note [HsType binders] which is already linked from LHsQTyVars. * Small refactor in CoreLint, extracting common code to a function * Remove "not so sure about WpFun" in TcEvidence, per Richard's comment https://gitlab.haskell.org/ghc/ghc/merge_requests/852#note_223226 * Use mkIfThenElse in Foreign/Call, as it does exactly what we need. - - - - - 1b1067d1 by Sylvain Henry at 2020-02-24T20:55:25-05:00 Modules: CmmToAsm (#13009) - - - - - 621468f6 by Alexis King at 2020-02-26T15:08:09-05:00 Treat coercions as arguments for floating and inlining This reverts commit 8924224ecfa065ebc67b96a90d01cf9d2edd0e77 and fixes #17787. - - - - - def486c9 by Ben Gamari at 2020-02-26T15:08:47-05:00 hadrian: Allow libnuma library path to be specified - - - - - ed03d4e7 by Ben Gamari at 2020-02-26T15:08:47-05:00 hadrian: Refactor gmp arguments Move the gmp configuration to its own binding. - - - - - 09b88384 by Ben Gamari at 2020-02-26T15:08:47-05:00 hadrian: Tell Cabal about integer-gmp library location - - - - - 161e08c5 by Krzysztof Gogolewski at 2020-02-26T15:09:30-05:00 Remove dead code * FailablePattern can no longer be created since ab51bee40c82 Therefore, Opt_WarnMissingMonadFailInstances has no effect anymore. * XWrap is no longer used, it was moved to an extension field - - - - - e0d09db3 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Use 8.8.3 to bootstrap on Windows This should fix #17861. - - - - - 972bcf3a by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Fix symlink test Needs to `write` bytes, not str. - - - - - 273e60de by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Add shell subcommand for debugging within CI environment - - - - - 43b13ed3 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Fix colors on Darwin Darwin sh doesn't support \e. - - - - - 217546a7 by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Flush stdout buffers in InitEventLogging Otherwise we are sensitive to libc's buffering strategy. Similar to the issue fixed in 543dfaab166c81f46ac4af76918ce32190aaab22. - - - - - c7d4fa55 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Add run_hadrian subcommand I've ruined two trees already by failing to pass --flavour to hadrian. Let's factor this out so it can be reused during troubleshooting. - - - - - 7dc54873 by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Allow tests to be marked as broken on the command line This allows us to work-around distribution-specific breakage easily. - - - - - 25e2458e by Ben Gamari at 2020-02-26T15:10:09-05:00 hadrian: Add --broken-test flag This exposes the flag of the same name supported by the testsuite driver. - - - - - 55769996 by Ben Gamari at 2020-02-26T15:10:09-05:00 gitlab-ci: Mark some tests as broken on Alpine - - - - - 9ee7f87d by Ben Gamari at 2020-02-26T15:10:09-05:00 SysTools: Don't use process jobs if they are broken - - - - - bfaa3961 by Ben Gamari at 2020-02-26T15:10:09-05:00 Bump hsc2hs submodule Fixes name of C compiler. - - - - - b2b49a0a by Ben Gamari at 2020-02-26T15:10:09-05:00 testsuite: Make hasMetricsFile RHS more descriptive - - - - - 817f93ea by Sylvain Henry at 2020-02-26T15:10:58-05:00 Modules: Core (#13009) Update haddock submodule - - - - - 74311e10 by Sebastian Graf at 2020-02-27T16:22:45-05:00 PmCheck: Implement Long-distance information with Covered sets Consider ```hs data T = A | B | C f :: T -> Int f A = 1 f x = case x of A -> 2 B -> 3 C -> 4 ``` Clearly, the RHS returning 2 is redundant. But we don't currently see that, because our approximation to the covered set of the inner case expression just picks up the positive information from surrounding pattern matches. It lacks the context sensivity that `x` can't be `A` anymore! Therefore, we adopt the conceptually and practically superior approach of reusing the covered set of a particular GRHS from an outer pattern match. In this case, we begin checking the `case` expression with the covered set of `f`s second clause, which encodes the information that `x` can't be `A` anymore. After this MR, we will successfully warn about the RHS returning 2 being redundant. Perhaps surprisingly, this was a great simplification to the code of both the coverage checker and the desugarer. Found a redundant case alternative in `unix` submodule, so we have to bump it with a fix. Metric Decrease: T12227 - - - - - 59c023ba by Adam Sandberg Ericsson at 2020-02-27T16:23:25-05:00 configure: correctly generate LIBRARY_template_haskell_VERSION - - - - - 9be82389 by Krzysztof Gogolewski at 2020-02-28T02:35:35-05:00 boot: Remove remote origin check Previously, we used relative paths in submodules. When cloning from GitHub, they had to be manually tweaked. Since a76b233d we use absolute paths, so this workaround can be removed. - - - - - f4b6b594 by Ben Gamari at 2020-02-28T02:36:12-05:00 nonmoving: Fix marking in compact regions Previously we were tracing the object we were asked to mark, even if it lives in a compact region. However, there is no need to do this; we need only to mark the region itself as live. I have seen a segfault due to this due to the concurrent mark seeing a an object in the process of being compacted by the mutator. - - - - - f97d1fb6 by Alp Mestanogullari at 2020-02-28T02:36:59-05:00 base: use an explicit import list in System.Environment.ExecutablePath This was making -Werror builds fail on Windows (at least with Hadrian). - - - - - 66f5d6d6 by Simon Peyton Jones at 2020-02-28T22:03:23-05:00 Improve error handling for VTA + deferred type errors This fixes #17792 See Note [VTA for out-of-scope functions] in TcExpr - - - - - 37f12603 by Ilias Tsitsimpis at 2020-02-28T22:04:04-05:00 llvm-targets: Add arm-unknown-linux-gnueabi Add arm-unknown-linux-gnueabi, which is used by Debian's ARM EABI port (armel), as an LLVM target. - - - - - 327b29e1 by Vladislav Zavialov at 2020-02-29T05:06:31-05:00 Monotonic locations (#17632) When GHC is parsing a file generated by a tool, e.g. by the C preprocessor, the tool may insert #line pragmas to adjust the locations reported to the user. As the result, the locations recorded in RealSrcLoc are not monotonic. Elements that appear later in the StringBuffer are not guaranteed to have a higher line/column number. In fact, there are no guarantees whatsoever, as #line pragmas can arbitrarily modify locations. This lack of guarantees makes ideas such as #17544 infeasible. This patch adds an additional bit of information to every SrcLoc: newtype BufPos = BufPos { bufPos :: Int } A BufPos represents the location in the StringBuffer, unaffected by any pragmas. Updates haddock submodule. Metric Increase: haddock.Cabal haddock.base haddock.compiler MultiLayerModules Naperian parsing001 T12150 - - - - - 99d2de86 by Ben Gamari at 2020-02-29T05:07:10-05:00 plugins: Ensure that loadInterface plugins can see annotations loadInterface replaces the `mi_decls`, `mi_insts`, `mi_fam_insts`, `mi_rules`, `mi_anns` fields of ModIface with `undefined` before inserting the interface into the EPS. However, we still want to give loadInterface plugins access to these fields. Consequently, we want to pass the unmodified `ModIface` the plugin. - - - - - a999ee96 by Xavier Denis at 2020-02-29T05:07:50-05:00 Rename ghci.sh and build.sh to ghci and build respectively Convert hadrian buildscripts to unsuffixed, dashed form final cleanups - - - - - b5fb58fd by Ömer Sinan Ağacan at 2020-02-29T05:08:36-05:00 Document and refactor a few things around bitmap scavenging - Added a few comments in StgPAP - Added a few comments and assertions in scavenge_small_bitmap and walk_large_bitmap - Did tiny refactor in GHC.Data.Bitmap: added some comments, deleted dead code, used PlatformWordSize type. - - - - - 18757cab by Sylvain Henry at 2020-02-29T05:09:25-05:00 Refactor runtime interpreter code In #14335 we want to be able to use both the internal interpreter (for the plugins) and the external interpreter (for TH and GHCi) at the same time. This patch performs some preliminary refactoring: the `hsc_interp` field of HscEnv replaces `hsc_iserv` and is now used to indicate which interpreter (internal, external) to use to execute TH and GHCi. Opt_ExternalInterpreter flag and iserv options in DynFlags are now queried only when we set the session DynFlags. It should help making GHC multi-target in the future by selecting an interpreter according to the selected target. - - - - - b86a6395 by Adam Sandberg Ericsson at 2020-02-29T05:10:06-05:00 docs: correct relative links to haddocks from users guide (fixes #17866) - - - - - 0f55df7f by Adam Sandberg Ericsson at 2020-02-29T05:10:06-05:00 docs: correct link to th haddocks from users guide - - - - - 252e5117 by Jean-Baptiste Mazon at 2020-02-29T05:10:46-05:00 rts: enforce POSIX numeric locale for heap profiles - - - - - 34c7d230 by Sylvain Henry at 2020-02-29T05:11:27-05:00 Fix Hadrian's ``--configure`` (fix #17883) - - - - - 04d30137 by Ömer Sinan Ağacan at 2020-02-29T05:12:06-05:00 Simplify IfaceIdInfo type IfaceIdInfo type is confusing: there's practically no difference between `NoInfo` and `HasInfo []`. The comments say NoInfo is used when -fomit-interface-pragmas is enabled, but we don't need to distinguish `NoInfo` from `HasInfo []` in when reading the interface so the distinction is not important. This patch simplifies the type by removing NoInfo. When we have no info we use an empty list. With this change we no longer read the info list lazily when reading an IfaceInfoItem, but when reading an IfaceId the ifIdInfo field is read lazily, so I doubt this is going to be a problem. - - - - - 3979485b by Roland Senn at 2020-02-29T17:36:59+01:00 Show breakpoint locations of breakpoints which were ignored during :force (#2950) GHCi is split up into 2 major parts: The user-interface (UI) and the byte-code interpreter. With `-fexternal-interpreter` they even run in different processes. Communication between the UI and the Interpreter (called `iserv`) is done using messages over a pipe. This is called `Remote GHCI` and explained in the Note [Remote GHCi] in `compiler/ghci/GHCi.hs`. To process a `:force` command the UI sends a `Seq` message to the `iserv` process. Then `iserv` does the effective evaluation of the value. When during this process a breakpoint is hit, the `iserv` process has no additional information to enhance the `Ignoring breakpoint` output with the breakpoint location. To be able to print additional breakpoint information, there are 2 possible implementation choices: 1. Store the needed information in the `iserv` process. 2. Print the `Ignoring breakpoint` from the UI process. For option 1 we need to store the breakpoint info redundantely in 2 places and this is bad. Therfore option 2 was implemented in this MR: - The user enters a `force` command - The UI sends a `Seq` message to the `iserv` process. - If processing of the `Seq` message hits a breakpoint, the `iserv` process returns control to the UI process. - The UI looks up the source location of the breakpoint, and prints the enhanced `Ignoring breakpoint` output. - The UI sends a `ResumeSeq` message to the `iserv` process, to continue forcing. - - - - - 3cf7303b by Krzysztof Gogolewski at 2020-03-02T01:18:33-05:00 Remove dead code * The names in PrelName and THNames are no longer used since TH merged types and kinds, Typeable is kind-polymorphic, .net support was removed * unqualQuasiQuote no longer used since 6f8ff0bbad3b9fa3 - - - - - dbea7e9d by Ilias Tsitsimpis at 2020-03-02T01:19:12-05:00 Do not define hs_atomic{read,write}64() on non-64bit Do not define hs_atomicread64() and hs_atomicwrite64() on machines where WORD_SIZE_IN_BITS is less than 64, just like we do with the rest of the atomic functions which work on 64-bit values. Without this, compilation fails on MIPSel and PowerPC with the following error: /usr/bin/ld: /<<PKGBUILDDIR>>/libraries/ghc-prim/dist-install/build/libHSghc-prim-0.5.3_p.a(atomic.p_o): in function `hs_atomicread64': atomic.c:(.text.hs_atomicread64+0x8): undefined reference to `__sync_add_and_fetch_8' /usr/bin/ld: /<<PKGBUILDDIR>>/libraries/ghc-prim/dist-install/build/libHSghc-prim-0.5.3_p.a(atomic.p_o): in function `hs_atomicwrite64': atomic.c:(.text.hs_atomicwrite64+0x38): undefined reference to `__sync_bool_compare_and_swap_8' Fixes #17886. - - - - - 7c0c76fb by Roland Senn at 2020-03-02T17:13:55-05:00 Set `ImpredicativeTypes` during :print command. (#14828) If ImpredicativeTypes is not enabled, then `:print <term>` will fail if the type of <term> has nested `forall`s or `=>`s. This is because the GHCi debugger's internals will attempt to unify a metavariable with the type of <term> and then display the result, but if the type has nested `forall`s or `=>`s, then unification will fail. As a result, `:print` will bail out and the unhelpful result will be `<term> = (_t1::t1)` (where `t1` is a metavariable). Beware: <term> can have nested `forall`s even if its definition doesn't use RankNTypes! Here is an example from #14828: class Functor f where fmap :: (a -> b) -> f a -> f b Somewhat surprisingly, `:print fmap` considers the type of fmap to have nested foralls. This is because the GHCi debugger sees the type `fmap :: forall f. Functor f => forall a b. (a -> b) -> f a -> f b`. We could envision deeply instantiating this type to get the type `forall f a b. Functor f => (a -> b) -> f a -> f b`, but this trick wouldn't work for higher-rank types. Instead, we adopt a simpler fix: enable `ImpredicativeTypes` when using `:print` and friends in the GHCi debugger. This is allows metavariables to unify with types that have nested (or higher-rank) `forall`s/`=>`s, which makes `:print fmap` display as `fmap = (_t1::forall a b. Functor f => (a -> b) -> f a -> f b)`, as expected. Although ImpredicativeTypes is a somewhat unpredictable from a type inference perspective, there is no danger in using it in the GHCi debugger, since all of the terms that the GHCi debugger deals with have already been typechecked. - - - - - 2a2f51d7 by Sylvain Henry at 2020-03-02T17:14:38-05:00 Use configure script to detect that we should use in-tree GMP on Windows - - - - - 8c663c2c by Andreas Klebinger at 2020-03-04T16:12:14+01:00 Be explicit about how stack usage of mvar primops are covered. This fixes #17893 [skip-ci] - - - - - cedd6f30 by Ben Gamari at 2020-03-05T14:53:12-05:00 rts: Add getCurrentThreadCPUTime helper - - - - - ace618cd by Ben Gamari at 2020-03-05T14:53:12-05:00 nonmoving-gc: Track time usage of nonmoving marking - - - - - 022b5ad5 by Ben Gamari at 2020-03-05T14:53:12-05:00 Stats: Add sync pauses to +RTS -S output - - - - - 06763234 by Ben Gamari at 2020-03-05T14:53:12-05:00 rts: Report nonmoving collector statistics in machine-readable output - - - - - 70d2b995 by Ben Gamari at 2020-03-09T06:10:52-04:00 nonmoving: Fix collection of sparks Previously sparks living in the non-moving heap would be promptly GC'd by the minor collector since pruneSparkQueue uses the BF_EVACUATED flag, which non-moving heap blocks do not have set. Fix this by implementing proper support in pruneSparkQueue for determining reachability in the non-moving heap. The story is told in Note [Spark management in the nonmoving heap]. - - - - - 9668781a by Ben Gamari at 2020-03-09T06:11:30-04:00 gitlab-ci: Disable Sphinx documentation in Alpine build - - - - - 8eb2c263 by Jean-Baptiste Mazon at 2020-03-09T16:33:37-04:00 Fix Windows breakage by not touching locales on Windows - - - - - b8dab057 by Jean-Baptiste Mazon at 2020-03-09T16:33:37-04:00 rts: ensure C numerics in heap profiles using Windows locales if needed - - - - - 7d95260f by Jean-Baptiste Mazon at 2020-03-09T16:33:37-04:00 rts: refactor and comment profile locales - - - - - 5b627813 by Ryan Scott at 2020-03-09T16:34:14-04:00 Use InstanceSigs in GND/DerivingVia-generated code (#17899) Aside from making the generated code easier to read when `-ddump-deriv` is enabled, this makes the error message in `T15073` substantially simpler (see the updated `T15073` expected stderr). Fixes #17899. - - - - - 70b50778 by Ben Gamari at 2020-03-10T02:05:42-04:00 SysTools: Ensure that error parser can handle absolute paths on Windows This fixes #17786, where the error parser fails to correctly handle the drive name in absolute Windows paths. Unfortunately I couldn't find a satisfactory way to test this. - - - - - 85b861d8 by Ben Gamari at 2020-03-10T02:05:42-04:00 testsuite: Add test for #17786 This isn't pretty but it's perhaps better than nothing. - - - - - ee2c50cb by Sylvain Henry at 2020-03-10T02:06:33-04:00 Hadrian: track missing configure results - - - - - ca8f51d4 by Ömer Sinan Ağacan at 2020-03-10T02:07:22-04:00 Add regression test for T17904 Closes #17904 - - - - - 5fa9cb82 by Richard Eisenberg at 2020-03-10T12:29:46-04:00 anyRewritableTyVar now looks in RuntimeReps Previously, anyRewritableTyVar looked only at the arg and res of `arg -> res`, but their RuntimeReps are also subject to rewriting. Easy to fix. Test case: typecheck/should_compile/T17024 Fixes #17024. - - - - - 5ba01d83 by Ben Price at 2020-03-10T12:30:27-04:00 Clarify a Lint message When developing a plugin I had a shadowing problem, where I generated code app = \f{v r7B} x{v r7B} -> f{v r7B} x{v r7B} This is obviously wrong, since the occurrence of `f` to the right of the arrow refers to the `x` binder (they share a Unique). However, it is rather confusing when Lint reports Mismatch in type between binder and occurrence Var: x{v rB7} since it is printing the binder, rather than the occurrence. It is rather easy to read this as claiming there is something wrong with the `x` occurrence! We change the report to explicitly print both the binder and the occurrence variables. - - - - - 7b2c827b by Simon Peyton Jones at 2020-03-10T12:31:15-04:00 Comments only Clarify code added in #17852 and MR !2724 - - - - - 3300eeac by Krzysztof Gogolewski at 2020-03-10T12:31:54-04:00 Misc cleanup - Remove Note [Existentials in shift_con_pat]. The function shift_con_pat has been removed 15 years ago in 23f40f0e9be6d4. - Remove kcLookupTcTyCon - it's the same as tcLookupTcTyCon - Remove ASSERT in tyConAppArgN. It's already done by getNth, and it's the only reason getNth exists. - Remove unused function nextRole - - - - - abf5736b by Krzysztof Gogolewski at 2020-03-10T18:05:01+01:00 Typos in comments [skip ci] - - - - - bb586f89 by Ben Gamari at 2020-03-11T00:14:59-04:00 rts: Prefer darwin-specific getCurrentThreadCPUTime macOS Catalina now supports a non-POSIX-compliant version of clock_gettime which cannot use the clock_gettime codepath. Fixes #17906. - - - - - 20800b9a by Sylvain Henry at 2020-03-11T08:17:19-04:00 Split GHC.Iface.Utils module * GHC.Iface.Recomp: recompilation avoidance stuff * GHC.Iface.Make: mkIface* Moved `writeIfaceFile` into GHC.Iface.Load alongside `readIface` and renamed it `writeIface` for consistency. - - - - - 1daa2029 by Greg Steuck at 2020-03-11T08:17:56-04:00 Fixed a minor typo in codegen.rst - - - - - 0bc23338 by Ryan Scott at 2020-03-11T08:18:32-04:00 Re-quantify when generalising over rewrite rule types Previously, `tcRules` would check for naughty quantification candidates (see `Note [Naughty quantification candidates]` in `TcMType`) when generalising over the type of a rewrite rule. This caused sensible-looking rewrite rules (like those in #17710) to be rejected. A more permissing (and easier-to-implement) approach is to do what is described in `Note [Generalising in tcTyFamInstEqnGuts]` in `TcTyClsDecls`: just re-quantify all the type variable binders, regardless of the order in which the user specified them. After all, the notion of type variable specificity has no real meaning in rewrite rules, since one cannot "visibly apply" a rewrite rule. I have written up this wisdom in `Note [Re-quantify type variables in rules]` in `TcRules`. As a result of this patch, compiling the `ExplicitForAllRules1` test case now generates one fewer warning than it used to. As far as I can tell, this is benign, since the thing that the disappearing warning talked about was also mentioned in an entirely separate warning. Fixes #17710. - - - - - 336eac7e by Ben Gamari at 2020-03-11T08:19:08-04:00 testsuite: Mark ghci056 and ghcilink004 as fragile in unreg As noted in #17018. Also fix fragile declaration of T13786, which only runs in the normal way. - - - - - c61b9b02 by Simon Peyton Jones at 2020-03-11T08:19:44-04:00 Deepen call stack for isIn I see quite a few warnings like: WARNING: file compiler/utils/Util.hs, line 593 Over-long elem in unionLists But the call stack is uninformative. Better to add HasDebugCallStack to isIn. Ditto isn'tIn. - - - - - 3aa9b35f by Ömer Sinan Ağacan at 2020-03-11T08:20:27-04:00 Zero any slop after compaction in compacting GC In copying GC, with the relevant debug flags enabled, we release the old blocks after a GC, and the block allocator zeroes the space before releasing a block. This effectively zeros the old heap. In compacting GC we reuse the blocks and previously we didn't zero the unused space in a compacting generation after compaction. With this patch we zero the slop between the free pointer and the end of the block when we're done with compaction and when switching to a new block (because the current block doesn't have enough space for the next object we're shifting). - - - - - 8e6febce by Sylvain Henry at 2020-03-11T20:33:37-04:00 Refactor GHC.Driver.Session (Ways and Flags) * extract flags and ways into their own modules (with some renaming) * remove one SOURCE import of GHC.Driver.Session from GHC.Driver.Phases * when GHC uses dynamic linking (WayDyn), `interpWays` was only reporting WayDyn even if the host was profiled (WayProf). Now it returns both as expected (might fix #16803). * `mkBuildTag :: [Way] -> String` wasn't reporting a canonical tag for differently ordered lists. Now we sort and nub the list to fix this. - - - - - bc41e471 by Sylvain Henry at 2020-03-11T20:33:37-04:00 Refactor interpreterDynamic and interpreterProfiled * `interpreterDynamic` and `interpreterProfiled` now take `Interp` parameters instead of DynFlags * slight refactoring of `ExternalInterp` so that we can read the iserv configuration (which is pure) without reading an MVar. - - - - - a6989971 by Sylvain Henry at 2020-03-11T20:33:37-04:00 Use a Set to represent Ways Should make `member` queries faster and avoid messing up with missing `nubSort`. Metric Increase: hie002 - - - - - cb93a1a4 by Ryan Scott at 2020-03-11T20:34:14-04:00 Make DeriveFunctor-generated code require fewer beta reductions Issue #17880 demonstrates that `DeriveFunctor`-generated code is surprisingly fragile when rank-_n_ types are involved. The culprit is that `$fmap` (the algorithm used to generate `fmap` implementations) was too keen on applying arguments with rank-_n_ types to lambdas, which fail to typecheck more often than not. In this patch, I change `$fmap` (both the specification and the implementation) to produce code that avoids creating as many lambdas, avoiding problems when rank-_n_ field types arise. See the comments titled "Functor instances" in `TcGenFunctor` for a more detailed description. Not only does this fix #17880, but it also ensures that the code that `DeriveFunctor` generates will continue to work after simplified subsumption is implemented (see #17775). What is truly amazing is that #17880 is actually a regression (introduced in GHC 7.6.3) caused by commit 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e, the fix #7436. Prior to that commit, the version of `$fmap` that was used was almost identical to the one used in this patch! Why did that commit change `$fmap` then? It was to avoid severe performance issues that would arise for recursive `fmap` implementations, such as in the example below: ```hs data List a = Nil | Cons a (List a) deriving Functor -- ===> instance Functor List where fmap f Nil = Nil fmap f (Cons x xs) = Cons (f x) (fmap (\y -> f y) xs) ``` The fact that `\y -> f y` was eta expanded caused significant performance overheads. Commit 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e fixed this performance issue, but it went too far. As a result, this patch partially reverts 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e. To ensure that the performance issues pre-#7436 do not resurface, I have taken some precautionary measures: * I have added a special case to `$fmap` for situations where the last type variable in an application of some type occurs directly. If this special case fires, we avoid creating a lambda expression. This ensures that we generate `fmap f (Cons x xs) = Cons (f x) (fmap f xs)` in the derived `Functor List` instance above. For more details, see `Note [Avoid unnecessary eta expansion in derived fmap implementations]` in `TcGenFunctor`. * I have added a `T7436b` test case to ensure that the performance of this derived `Functor List`-style code does not regress. When implementing this, I discovered that `$replace`, the algorithm which generates implementations of `(<$)`, has a special case that is very similar to the `$fmap` special case described above. `$replace` marked this special case with a custom `Replacer` data type, which was a bit overkill. In order to use the same machinery for both `Functor` methods, I ripped out `Replacer` and instead implemented a simple way to detect the special case. See the updated commentary in `Note [Deriving <$]` for more details. - - - - - 1f9db3e7 by Kirill Elagin at 2020-03-12T09:45:51-04:00 pretty-printer: Properly parenthesise LastStmt After ApplicatveDo strips the last `return` during renaming, the pretty printer has to restore it. However, if the return was followed by `$`, the dollar was stripped too and not restored. For example, the last stamement in: ``` foo = do x <- ... ... return $ f x ``` would be printed as: ``` return f x ``` This commit preserved the dolar, so it becomes: ``` return $ f x ``` - - - - - 5cb93af7 by Kirill Elagin at 2020-03-12T09:45:51-04:00 pretty-printer: Do not print ApplicativeDo join * Do not print `join` in ApplictiveStmt, unless ppr-debug * Print parens around multiple parallel binds When ApplicativeDo is enabled, the renamer analyses the statements of a `do` block and in certain cases marks them as needing to be rewritten using `join`. For example, if you have: ``` foo = do a <- e1 b <- e2 doSomething a b ``` it will be desugared into: ``` foo = join (doSomething <$> e1 <*> e2) ``` After renaming but before desugaring the expression is stored essentially as: ``` foo = do [will need join] (a <- e1 | b <- e2) [no return] doSomething a b ``` Before this change, the pretty printer would print a call to `join`, even though it is not needed at this stage at all. The expression will be actually rewritten into one using join only at desugaring, at which point a literal call to join will be inserted. - - - - - 3a259092 by Simon Peyton Jones at 2020-03-12T09:46:29-04:00 Expose compulsory unfoldings always The unsafeCoerce# patch requires that unsafeCoerce# has a compulsory unfolding that is always available. So we have to be careful to expose compulsory unfoldings unconditionally and consistently. We didn't get this quite right: #17871. This patch fixes it. No real surprises here. See Note [Always expose compulsory unfoldings] in GHC.Iface.Tidy - - - - - 6a65b8c2 by Alp Mestanogullari at 2020-03-13T02:29:20-04:00 hadrian: improve dependency tracking for the check-* programs The code in Rules.Register responsible for finding all the build artifacts that Cabal installs when registering a library (static/shared libs, .hi files, ...) was looking in the wrong place. This patch fixes that logic and makes sure we gather all those artifacts in a list to declare that the rule for a given `.conf` file, our proxy for "Hadrian, please install this package in the package db for this stage", also produces those artifacts under the said package database. We also were completely missing some logic to declare that the check-* programs have dependencies besides their source code, at least when testing an in-tree compiler. Finally, this patch also removes redundant packages from 'testsuitePackages', since they should already be covered by the stage<N>Packages lists from Settings.Default. With this patch, after a complete build and freezing stage 1, a change to `compiler/parser/Parser.y` results in rebuilding the ghc lib, reinstalling it, and rebuilding the few programs that depend on it, _including_ `check-ppr` and `check-api-annotations` (therefore fixing #17273). - - - - - 44fad4a9 by Sylvain Henry at 2020-03-13T02:30:22-04:00 Rename isDllName I wanted to fix the dangling comment in `isDllName` ("This is the cause of #", #8696 is already mentioned earlier). I took the opportunity to change the function name to better reflect what it does. - - - - - 2f292db8 by Paavo at 2020-03-13T02:31:03-04:00 Update documentation for closureSize - - - - - f124ff0d by Ben Gamari at 2020-03-13T02:31:40-04:00 gitlab-ci: Rework triggering of release builds Use a push option instead of tagging. - - - - - 7f25557a by Ben Gamari at 2020-03-13T10:38:09-04:00 gitlab-ci: Distinguish integer-simple test envs Previously two integer-simple jobs declared the same test environment. One (the nightly job) was built in the perf way, the other in the validate way. Consequently they had appreciably different performance characteristics, causing in the nightly job to spuriously fail with performance changes. - - - - - c12a2ec5 by Simon Peyton Jones at 2020-03-14T05:25:30-04:00 Fix Lint Ticket #17590 pointed out a bug in the way the linter dealt with type lets, exposed by the new uniqAway story. The fix is described in Note [Linting type lets]. I ended up putting the in-scope Ids in a different env field, le_ids, rather than (as before) sneaking them into the TCvSubst. Surprisingly tiresome, but done. Metric Decrease: hie002 - - - - - b989845e by Sylvain Henry at 2020-03-14T05:26:11-04:00 Hadrian: fix absolute buildroot support (#17822) Shake's "**" wildcard doesn't match absolute root. We must use "//" instead. - - - - - 4f117135 by Sylvain Henry at 2020-03-14T05:26:49-04:00 Make: refactor GMP rules Document and use simpler rules for the ghc-gmp.h header. - - - - - 7432b327 by Sylvain Henry at 2020-03-14T05:27:28-04:00 Use correct option name (-opti) (fix #17314) s/pgmo/opti - - - - - 8f7dd571 by Judah Jacobson at 2020-03-14T05:28:07-04:00 Allow overriding LD_STAGE0 and AR_STAGE0 in the configure script. Previously it was possible to override the stage0 C compiler via `CC_STAGE0`, but you couldn't override `ld` or `ar` in stage0. This change allows overriding them by setting `LD_STAGE0` or `AR_STAGE0`, respectively. Our team uses this feature internally to take more control of our GHC build and make it run more hermetically. - - - - - 7c3e39a9 by Judah Jacobson at 2020-03-14T05:28:07-04:00 Use AC_ARG_VAR for LD_STAGE0 and AR_STAGE0. - - - - - 20d4d676 by Ben Gamari at 2020-03-14T05:28:43-04:00 nonmoving: Don't traverse filled segment list in pause The non-moving collector would previously walk the entire filled segment list during the preparatory pause. However, this is far more work than is strictly necessary. We can rather get away with merely collecting the allocators' filled segment list heads and process the lists themselves during the concurrent phase. This can significantly reduce the maximum gen1 GC pause time in programs with high rates of long-lived allocations. - - - - - fdfa2d01 by Ben Gamari at 2020-03-14T05:29:18-04:00 nonmoving: Remove redundant bitmap clearing nonmovingSweep already clears the bitmap in the sweep loop. There is no reason to do so a second time. - - - - - 2f8c7767 by Simon Peyton Jones at 2020-03-14T05:29:55-04:00 Simple refactor of cheapEqExpr No change in functionality. Just seems tidier (and signficantly more efficient) to deal with ticks directly than to call stripTicksTopE. - - - - - 88f7a762 by Simon Peyton Jones at 2020-03-14T05:29:55-04:00 Improve CSE.combineAlts This patch improves the way that CSE combines identical alternatives. See #17901. I'm still not happy about the duplication between CSE.combineAlts and GHC.Core.Utils.combineIdenticalAlts; see the Notes with those functions. But this patch is a step forward. Metric Decrease: T12425 T5642 - - - - - 8b95ddd3 by Ben Gamari at 2020-03-14T05:30:31-04:00 gitlab-ci: Add integer-simple release build for Windows Closes #16144. - - - - - e3c374cc by Simon Peyton Jones at 2020-03-14T05:31:07-04:00 Wrap an implication around class-sig kind errors Ticket #17841 showed that we can get a kind error in a class signature, but lack an enclosing implication that binds its skolems. This patch * Adds the wrapping implication: the new call to checkTvConstraints in tcClassDecl1 * Simplifies the API to checkTvConstraints, which was not otherwise called at all. * Simplifies TcErrors.report_unsolved by *not* initialising the TidyEnv from the typechecker lexical envt. It's enough to do so from the free vars of the unsolved constraints; and we get silly renamings if we add variables twice: once from the lexical scope and once from the implication constraint. - - - - - 73133a3b by Simon Peyton Jones at 2020-03-14T05:31:07-04:00 Refactoring in TcSMonad This patch is just refactoring: no change in behaviour. I removed the rather complicated checkConstraintsTcS checkTvConstraintsTcS in favour of simpler functions emitImplicationTcS emitTvImplicationTcS pushLevelNoWorkList The last of these is a little strange, but overall it's much better I think. - - - - - 93c88c26 by Ben Gamari at 2020-03-14T05:31:42-04:00 base: Make `open` calls interruptible As noted in #17912, `open` system calls were `safe` rather than `interruptible`. Consequently, the program could not be interrupted with SIGINT if stuck in a slow open operation. Fix this by marking `c_safe_open` as interruptible. - - - - - bee4cdad by Vladislav Zavialov at 2020-03-14T05:32:18-04:00 Remove second tcLookupTcTyCon in tcDataDefn Before this patch, tcDataDefn used to call tcLookupTcTyCon twice in a row: 1. in bindTyClTyVars itself 2. in the continuation passed to it Now bindTyClTyVars passes the TcTyCon to the continuation, making the second lookup unnecessary. - - - - - 3f116d35 by Cale Gibbard at 2020-03-14T19:34:42-04:00 Enable stage1 build of haddock The submodule has already been bumped to contain the fix. - - - - - 49e9d739 by Ömer Sinan Ağacan at 2020-03-14T19:35:24-04:00 rts: Fix printClosure when printing fwd ptrs - - - - - 1de3ab4a by Krzysztof Gogolewski at 2020-03-14T19:36:04-04:00 Remove unused field var_inline (#17915) - - - - - d30aeb4b by Krzysztof Gogolewski at 2020-03-15T03:57:41-04:00 Document restriction on SCC pragma syntax Currently, the names of cost centres must be quoted or be lowercase identifiers. Fixes #17916. - - - - - b4774598 by Brian Foley at 2020-03-15T03:58:18-04:00 Remove some dead code >From the notes.ghc.drop list found using weeder in #17713 - - - - - dd6ffe6b by Viktor Dukhovni at 2020-03-15T03:58:55-04:00 Note platform-specific Foreign.C.Types in context Also fix the markup in the general note at the top of the module. Haddock (usability trade-off), does not support multi-line emphasised text. - - - - - 2e82465f by Sylvain Henry at 2020-03-15T10:57:10-04:00 Refactor CmmToAsm (disentangle DynFlags) This patch disentangles a bit more DynFlags from the native code generator (CmmToAsm). In more details: - add a new NCGConfig datatype in GHC.CmmToAsm.Config which contains the configuration of a native code generation session - explicitly pass NCGConfig/Platform arguments when necessary - as a consequence `sdocWithPlatform` is gone and there are only a few `sdocWithDynFlags` left - remove the use of `unsafeGlobalDynFlags` from GHC.CmmToAsm.CFG - remove `sdocDebugLevel` (now we pass the debug level via NCGConfig) There are still some places where DynFlags is used, especially because of pretty-printing (CLabel), because of Cmm helpers (such as `cmmExprType`) and because of `Outputable` instance for the instructions. These are left for future refactoring as this patch is already big. - - - - - c35c545d by Judah Jacobson at 2020-03-15T10:57:48-04:00 Add a -no-haddock flag. This flag undoes the effect of a previous "-haddock" flag. Having both flags makes it easier for build systems to enable Haddock parsing in a set of global flags, but then disable it locally for specific targets (e.g., third-party packages whose comments don't pass the validation in the latest GHC). I added the flag to expected-undocumented-flags.txt since `-haddock` was alreadyin that list. - - - - - cfcc3c9a by Ömer Sinan Ağacan at 2020-03-15T10:58:27-04:00 Fix global_link of TSOs for threads reachable via dead weaks Fixes #17785 Here's how the problem occurs: - In generation 0 we have a TSO that is finished (i.e. it has no more work to do or it is killed). - The TSO only becomes reachable after collectDeadWeakPtrs(). - After collectDeadWeakPtrs() we switch to WeakDone phase where we don't move TSOs to different lists anymore (like the next gen's thread list or the resurrected_threads list). - So the TSO will never be moved to a generation's thread list, but it will be promoted to generation 1. - Generation 1 collected via mark-compact, and because the TSO is reachable it is marked, and its `global_link` field, which is bogus at this point (because the TSO is not in a list), will be threaded. - Chaos ensues. In other words, when these conditions hold: - A TSO is reachable only after collectDeadWeakPtrs() - It's finished (what_next is ThreadComplete or ThreadKilled) - It's retained by mark-compact collector (moving collector doesn't evacuate the global_list field) We end up doing random mutations on the heap because the TSO's global_list field is not valid, but it still looks like a heap pointer so we thread it during compacting GC. The fix is simple: when we traverse old_threads lists to resurrect unreachable threads the threads that won't be resurrected currently stays on the old_threads lists. Those threads will never be visited again by MarkWeak so we now reset the global_list fields. This way compacting GC does not thread pointers to nowhere. Testing ------- The reproducer in #17785 is quite large and hard to build, because of the dependencies, so I'm not adding a regression test. In my testing the reproducer would take a less than 5 seconds to run, and once in every ~5 runs would fail with a segfault or an assertion error. In other cases it also fails with a test failure. Because the tests never fail with the bug fix, assuming the code is correct, this also means that this bug can sometimes lead to incorrect runtime results. After the fix I was able to run the reproducer repeatedly for about an hour, with no runtime crashes or test failures. To run the reproducer clone the git repo: $ git clone https://github.com/osa1/streamly --branch ghc-segfault Then clone primitive and atomic-primops from their git repos and point to the clones in cabal.project.local. The project should then be buildable using GHC HEAD. Run the executable `properties` with `+RTS -c -DZ`. In addition to the reproducer above I run the test suite using: $ make slowtest EXTRA_HC_OPTS="-debug -with-rtsopts=-DS \ -with-rtsopts=-c +RTS -c -RTS" SKIPWAY='nonmoving nonmoving_thr' This enables compacting GC always in both GHC when building the test programs and when running the test programs, and also enables sanity checking when running the test programs. These set of flags are not compatible for all tests so there are some failures, but I got the same set of failures with this patch compared to GHC HEAD. - - - - - 818b3c38 by Lysxia at 2020-03-16T23:52:42-04:00 base: add strict IO functions: readFile', getContents', hGetContents' - - - - - 18a346a4 by Sylvain Henry at 2020-03-16T23:53:24-04:00 Modules: Core (#13009) Update submodule: haddock - - - - - 92327e3a by Ömer Sinan Ağacan at 2020-03-16T23:54:04-04:00 Update sanity checking for TSOs: - Remove an invalid assumption about GC checking what_next field. The GC doesn't care about what_next at all, if a TSO is reachable then all its pointers are followed (other than global_tso, which is only followed by compacting GC). - Remove checkSTACK in checkTSO: TSO stacks will be visited in checkHeapChain, or checkLargeObjects etc. - Add an assertion in checkTSO to check that the global_link field is sane. - Did some refactor to remove forward decls in checkGlobalTSOList and added braces around single-statement if statements. - - - - - e1aa4052 by PHO at 2020-03-17T07:36:09-04:00 Don't use non-portable operator "==" in configure.ac The test operator "==" is a Bash extension and produces a wrong result if /bin/sh is not Bash. - - - - - 89f034dd by Maximilian Tagher at 2020-03-17T07:36:48-04:00 Document the units of -ddump-timings Right now, in the output of -ddump-timings to a file, you can't tell what the units are: ``` CodeGen [TemplateTestImports]: alloc=22454880 time=14.597 ``` I believe bytes/milliseconds are the correct units, but confirmation would be appreciated. I'm basing it off of this snippet from `withTiming'`: ``` when (verbosity dflags >= 2 && prtimings == PrintTimings) $ liftIO $ logInfo dflags (defaultUserStyle dflags) (text "!!!" <+> what <> colon <+> text "finished in" <+> doublePrec 2 time <+> text "milliseconds" <> comma <+> text "allocated" <+> doublePrec 3 (realToFrac alloc / 1024 / 1024) <+> text "megabytes") ``` which implies time is in milliseconds, and allocations in bytes (which divided by 1024 would be KB, and again would be MB) - - - - - beffa147 by Simon Peyton Jones at 2020-03-17T07:37:25-04:00 Implement mapTyCo like foldTyCo This patch makes mapType use the successful idiom described in TyCoRep Note [Specialising foldType] I have not yet changed any functions to use mapType, though there may be some suitable candidates. This patch should be a no-op in terms of functionality but, because it inlines the mapper itself, I'm hoping that there may be some modest perf improvements. Metric Decrease: T5631 T5642 T3064 T9020 T14683 hie002 haddock.Cabal haddock.base haddock.compiler - - - - - 5800ebfe by Ömer Sinan Ağacan at 2020-03-17T07:38:08-04:00 Don't update ModDetails with CafInfos when opts are disabled This is consistent with the interface file behavior where we omit HsNoCafRefs annotations with -fomit-interface-pragmas (implied by -O0). ModDetails and ModIface are just different representations of the same thing, so they really need to be in sync. This patch does the right thing and does not need too much explanation, but here's an example of a problem not doing this causes in !2842: -- MyInteger.hs module MyInteger ( MyInteger (MyInteger) , ToMyInteger (toMyInteger) ) where newtype MyInteger = MyInteger Integer class ToMyInteger a where toMyInteger :: a -> MyInteger instance ToMyInteger Integer where toMyInteger = MyInteger {- . succ -} -- Main.hs module Main ( main ) where import MyInteger (MyInteger (MyInteger), toMyInteger) main :: IO () main = do let (MyInteger i) = (id . toMyInteger) (41 :: Integer) print i If I build this with -O0, without this fix, we generate a ModDetails with accurate LFInfo for toMyInteger (MyInteger.$fToMyIntegerInteger) which says that it's a LFReEntrant with arity 1. This means in the use site (Main) we tag the value: R3 = MyInteger.$fToMyIntegerInteger_closure + 1; R2 = GHC.Base.id_closure; R1 = GHC.Base.._closure; Sp = Sp - 16; call stg_ap_ppp_fast(R4, R3, R2, R1) args: 24, res: 0, upd: 24; Now we change the definition by uncommenting the `succ` part and it becomes a thunk: MyInteger.$fToMyIntegerInteger [InlPrag=INLINE (sat-args=0)] :: MyInteger.ToMyInteger GHC.Integer.Type.Integer [GblId[DFunId(nt)]] = {} \u [] $ctoMyInteger_rEA; and its LFInfo is now LFThunk. This change in LFInfo makes a difference in the use site: we can no longer tag it. But becuase the interface fingerprint does not change (because ModIface does not change) we don't rebuild Main and tag the thunk. (1.2% increase in allocations when building T12545 on armv7 because we generate more code without CafInfos) Metric Increase: T12545 - - - - - 5b632dad by Paavo at 2020-03-17T07:38:48-04:00 Add example for Data.Semigroup.diff - - - - - 4d85d68b by Paavo at 2020-03-17T07:38:48-04:00 Clean up - - - - - 75168d07 by Paavo at 2020-03-17T07:38:48-04:00 Make example collapsible - - - - - 53ff2cd0 by Richard Eisenberg at 2020-03-17T13:46:57+00:00 Fix #17021 by checking more return kinds All the details are in new Note [Datatype return kinds] in TcTyClsDecls. Test case: typecheck/should_fail/T17021{,b} typecheck/should_compile/T17021a Updates haddock submodule - - - - - 528df8ec by Sylvain Henry at 2020-03-18T10:06:43-04:00 Modules: Core operations (#13009) - - - - - 4e8a71c1 by Richard Eisenberg at 2020-03-18T10:07:19-04:00 Add release note about fix to #16502. We thought we needed to update the manual, but the fix for #16502 actually brings the implementation in line with the manual. So we just alert users of how to update their code. - - - - - 5cbf9934 by Andreas Klebinger at 2020-03-19T00:39:27-04:00 Update "GHC differences to the FFI Chapter" in user guide. The old entry had a heavy focus on how things had been. Which is not what I generally look for in a user guide. I also added a small section on behaviour of nested safe ffi calls. [skip-ci] - - - - - b03fd3bc by Sebastian Graf at 2020-03-19T00:40:06-04:00 PmCheck: Use ConLikeSet to model negative info In #17911, Simon recognised many warnings stemming from over-long list unions while coverage checking Cabal's `LicenseId` module. This patch introduces a new `PmAltConSet` type which uses a `UniqDSet` instead of an association list for `ConLike`s. For `PmLit`s, it will still use an assocation list, though, because a similar map data structure would entail a lot of busy work. Fixes #17911. - - - - - 64f20756 by Sylvain Henry at 2020-03-19T12:16:49-04:00 Refactoring: use Platform instead of DynFlags when possible Metric Decrease: ManyConstructors T12707 T13035 T1969 - - - - - cb1785d9 by Ömer Sinan Ağacan at 2020-03-19T12:16:54-04:00 FastString: fix eager reading of string ptr in hashStr This read causes NULL dereferencing when len is 0. Fixes #17909 In the reproducer in #17909 this bug is triggered as follows: - SimplOpt.dealWithStringLiteral is called with a single-char string ("=" in #17909) - tailFS gets called on the FastString of the single-char string. - tailFS checks the length of the string, which is 1, and calls mkFastStringByteString on the tail of the ByteString, which is an empty ByteString as the original ByteString has only one char. - ByteString's unsafeUseAsCStringLen returns (NULL, 0) for the empty ByteString, which is passed to mkFastStringWith. - mkFastStringWith gets hash of the NULL pointer via hashStr, which fails on empty strings because of this bug. - - - - - 73a7383e by Richard Eisenberg at 2020-03-20T20:42:56-04:00 Simplify treatment of heterogeneous equality Previously, if we had a [W] (a :: k1) ~ (rhs :: k2), we would spit out a [D] k1 ~ k2 and part the W as irreducible, hoping for a unification. But we needn't do this. Instead, we now spit out a [W] co :: k2 ~ k1 and then use co to cast the rhs of the original Wanted. This means that we retain the connection between the spat-out constraint and the original. The problem with this new approach is that we cannot use the casted equality for substitution; it's too like wanteds-rewriting- wanteds. So, we forbid CTyEqCans that mention coercion holes. All the details are in Note [Equalities with incompatible kinds] in TcCanonical. There are a few knock-on effects, documented where they occur. While debugging an error in this patch, Simon and I ran into infelicities in how patterns and matches are printed; we made small improvements. This patch includes mitigations for #17828, which causes spurious pattern-match warnings. When #17828 is fixed, these lines should be removed. - - - - - faa36e5b by Sylvain Henry at 2020-03-20T20:43:41-04:00 Hadrian: ignore in-tree GMP objects with ``--lint`` - - - - - 9a96ff6b by Richard Eisenberg at 2020-03-20T20:44:17-04:00 Update core spec to reflect changes to Core. Key changes: * Adds a new rule for forall-coercions over coercion variables, which was implemented but conspicuously missing from the spec. * Adds treatment for FunCo. * Adds treatment for ForAllTy over coercion variables. * Improves commentary (including restoring a Note lost in 03d4852658e1b7407abb4da84b1b03bfa6f6db3b) in the source. No changes to running code. - - - - - 7e0451c6 by Sergej Jaskiewicz at 2020-03-20T20:44:55-04:00 Fix event message in withTiming' This typo caused generating 'end' events without the corresponding 'begin' events. - - - - - 1542a626 by Ben Gamari at 2020-03-22T22:37:47-04:00 fs.h: Add missing declarations on Windows - - - - - 3bcf2ccd by Ben Gamari at 2020-03-22T22:37:47-04:00 Bump process submodule Avoids redundant case alternative warning. - - - - - 3b363ef9 by Ben Gamari at 2020-03-22T22:37:47-04:00 testsuite: Normalize slashes in ghc-api annotations output Enable `normalise_slashes` on `annotations`, `listcomps`, and `parseTree` to fix Windows failures. - - - - - 25fc9429 by Ben Gamari at 2020-03-22T22:37:47-04:00 testsuite: Update expected output on Windows - - - - - 7f58ec6d by Ben Gamari at 2020-03-22T22:37:47-04:00 testsuite: Fix TOP of T17786 - - - - - aadcd909 by GHC GitLab CI at 2020-03-22T22:37:47-04:00 testsuite: Update expected output on Windows - - - - - dc1eb10d by GHC GitLab CI at 2020-03-22T22:37:47-04:00 hadrian: Fix executable extension passed to testsuite driver - - - - - 58f62e2c by GHC GitLab CI at 2020-03-22T22:37:47-04:00 gitlab-ci: Require that Windows-hadrian job passes - - - - - 8dd2415d by Ben Gamari at 2020-03-22T22:37:47-04:00 hadrian: Eliminate redundant .exe from GHC path Previously we were invoking: bash -c "c:/GitLabRunner/builds/eEQrxK4p/0/ghc/ghc/toolchain/bin/ghc.exe.exe testsuite/mk/ghc-config.hs -o _build/test/bin/ghc-config.exe" - - - - - 373621f6 by Ben Gamari at 2020-03-22T22:37:47-04:00 Bump hsc2hs submodule - - - - - abc02b40 by Hécate at 2020-03-22T22:38:33-04:00 Annotate the non-total function in Data.Foldable as such - - - - - 19f12557 by Josef Svenningsson at 2020-03-23T14:05:33-04:00 Fix ApplicativeDo regression #17835 A previous fix for #15344 made sure that monadic 'fail' is used properly when translating ApplicativeDo. However, it didn't properly account for when a 'fail' will be inserted which resulted in some programs failing with a type error. - - - - - 2643ba46 by Paavo at 2020-03-24T08:31:32-04:00 Add example and doc for Arg (Fixes #17153) - - - - - 703221f4 by Roland Senn at 2020-03-25T14:45:04-04:00 Use export list of Main module in function TcRnDriver.hs:check_main (Fix #16453) - Provide the export list of the `Main` module as parameter to the `compiler/typecheck/TcRnDriver.hs:check_main` function. - Instead of `lookupOccRn_maybe` call the function `lookupInfoOccRn`. It returns the list `mains_all` of all the main functions in scope. - Select from this list `mains_all` all `main` functions that are in the export list of the `Main` module. - If this new list contains exactly one single `main` function, then typechecking continues. - Otherwise issue an appropriate error message. - - - - - 3e27205a by Sebastian Graf at 2020-03-25T14:45:40-04:00 Remove -fkill-absence and -fkill-one-shot flags They seem to be a benchmarking vestige of the Cardinality paper and probably shouldn't have been merged to HEAD in the first place. - - - - - 262e42aa by Peter Trommler at 2020-03-25T22:41:39-04:00 Do not panic on linker errors - - - - - 0de03cd7 by Sylvain Henry at 2020-03-25T22:42:02-04:00 DynFlags refactoring III Use Platform instead of DynFlags when possible: * `tARGET_MIN_INT` et al. replaced with `platformMinInt` et al. * no more DynFlags in PreRules: added a new `RuleOpts` datatype * don't use `wORD_SIZE` in the compiler * make `wordAlignment` use `Platform` * make `dOUBLE_SIZE` a constant Metric Decrease: T13035 T1969 - - - - - 7a04920b by Tristan Cacqueray at 2020-03-25T22:42:06-04:00 Base: fix a typo in liftA doc This change removes an extra '|' that should not be rendered in the liftA documentation. Tracking: #17929 - - - - - 1c5a15f7 by Tristan Cacqueray at 2020-03-25T22:42:06-04:00 Base: add Control.Applicative optional example This change adds an optional example. Tracking: #17929 - - - - - 6d172e63 by Tristan Cacqueray at 2020-03-25T22:42:06-04:00 Base: add markup around Except - - - - - eb2162c8 by John Ericson at 2020-03-26T12:37:08-04:00 Remove unused `ghciTablesNextToCode` from compiler proper - - - - - f51efc4b by Joachim Breitner at 2020-03-26T12:37:09-04:00 Prepare to use run-time tablesNextToCode in compiler exclusively Factor out CPP as much as possible to prepare for runtime determinattion. Progress towards #15548 - - - - - 1c446220 by Joachim Breitner at 2020-03-26T12:37:09-04:00 Use run-time tablesNextToCode in compiler exclusively (#15548) Summary: - There is no more use of the TABLES_NEXT_TO_CODE CPP macro in `compiler/`. GHCI_TABLES_NEXT_TO_CODE is also removed entirely. The field within `PlatformMisc` within `DynFlags` is used instead. - The field is still not exposed as a CLI flag. We might consider some way to ensure the right RTS / libraries are used before doing that. Original reviewers: Original subscribers: TerrorJack, rwbarton, carter Original Differential Revision: https://phabricator.haskell.org/D5082 - - - - - 1941ef4f by Sylvain Henry at 2020-03-29T17:28:51-04:00 Modules: Types (#13009) Update Haddock submodule Metric Increase: haddock.compiler - - - - - 1c7c6f1a by Sylvain Henry at 2020-03-29T17:28:51-04:00 Remove GHC.Types.Unique.Map module This module isn't used anywhere in GHC. - - - - - f1a6c73d by Sylvain Henry at 2020-03-29T17:28:51-04:00 Merge GHC.Types.CostCentre.Init into GHC.Driver.CodeOutput - - - - - 54250f2d by Simon Peyton Jones at 2020-03-29T17:29:30-04:00 Demand analysis: simplify the demand for a RHS Ticket #17932 showed that we were using a stupid demand for the RHS of a let-binding, when the result is a product. This was the result of a "fix" in 2013, which (happily) turns out to no longer be necessary. So I just deleted the code, which simplifies the demand analyser, and fixes #17932. That in turn uncovered that the anticipation of worker/wrapper in CPR analysis was inaccurate, hence the logic that decides whether to unbox an argument in WW was extracted into a function `wantToUnbox`, now consulted by CPR analysis. I tried nofib, and got 0.0% perf changes. All this came up when messing about with !2873 (ticket #17917), but is idependent of it. Unfortunately, this patch regresses #4267 and realised that it is now blocked on #16335. - - - - - 03060b2f by Ben Gamari at 2020-03-29T17:30:05-04:00 testsuite: Fix T17786 on Windows Fixes line ending normalization issue. - - - - - 1f7995ba by Ben Gamari at 2020-03-29T17:30:05-04:00 testsuite: Fix T17786 Fix missing quoting and expected exit code. - - - - - ef9c608e by Ben Gamari at 2020-03-29T17:30:05-04:00 testsuite: Mark T12971 as broken on Windows Due to #17945. - - - - - e54500c1 by Sylvain Henry at 2020-03-29T17:30:47-04:00 Store ComponentId details As far as GHC is concerned, installed package components ("units") are identified by an opaque ComponentId string provided by Cabal. But we don't want to display it to users (as it contains a hash) so GHC queries the database to retrieve some infos about the original source package (name, version, component name). This patch caches these infos in the ComponentId itself so that we don't need to provide DynFlags (which contains installed package informations) to print a ComponentId. In the future we want GHC to support several independent package states (e.g. for plugins and for target code), hence we need to avoid implicitly querying a single global package state. - - - - - 7e7cb714 by Marius Bakke at 2020-03-29T17:31:27-04:00 testsuite: Remove test that dlopens a PIE object. glibc 2.30 disallowed dlopening PIE objects, so just remove the test. Fixes #17952. - - - - - 6c8f80d8 by Andreas Klebinger at 2020-03-29T17:32:04-04:00 Correct haddocks for testBit in Data.Bits It conflated the nth bit with the bit at offset n. Now we instead give the definition in terms of `bit and `.&.` on top of clearer phrasing. - - - - - c916f190 by Andreas Klebinger at 2020-03-29T17:32:04-04:00 Apply suggestion to libraries/base/Data/Bits.hs - - - - - 64bf7f51 by Ben Gamari at 2020-03-29T17:32:41-04:00 gitlab-ci: Add FreeBSD release job - - - - - a0d8e92e by Ryan Scott at 2020-03-29T17:33:20-04:00 Run checkNewDataCon before constraint-solving newtype constructors Within `checkValidDataCon`, we used to run `checkValidType` on the argument types of a newtype constructor before running `checkNewDataCon`, which ensures that the user does not attempt non-sensical things such as newtypes with multiple arguments or constraints. This works out in most situations, but this falls over on a corner case revealed in #17955: ```hs newtype T = Coercible () T => T () ``` `checkValidType`, among other things, peforms an ambiguity check on the context of a data constructor, and that it turn invokes the constraint solver. It turns out that there is a special case in the constraint solver for representational equalities (read: `Coercible` constraints) that causes newtypes to be unwrapped (see `Note [Unwrap newtypes first]` in `TcCanonical`). This special case does not know how to cope with an ill formed newtype like `T`, so it ends up panicking. The solution is surprisingly simple: just invoke `checkNewDataCon` before `checkValidType` to ensure that the illicit newtype constructor context is detected before the constraint solver can run amok with it. Fixes #17955. - - - - - 45eb9d8c by Krzysztof Gogolewski at 2020-03-29T17:33:59-04:00 Minor cleanup - Simplify mkBuildExpr, the function newTyVars was called only on a one-element list. - TTG: use noExtCon in more places. This is more future-proof. - In zonkExpr, panic instead of printing a warning. - - - - - f024b6e3 by Sylvain Henry at 2020-03-30T12:48:39+02:00 Expect T4267 to pass Since 54250f2d8de910b094070c1b48f086030df634b1 we expected T4267 to fail, but it passes on CI. - - - - - 57b888c0 by Ryan Scott at 2020-03-31T10:54:20-04:00 Require GHC 8.8 as the minimum compiler for bootstrapping This allows us to remove several bits of CPP that are either always true or no longer reachable. As an added bonus, we no longer need to worry about importing `Control.Monad.Fail.fail` qualified to avoid clashing with `Control.Monad.fail`, since the latter is now the same as the former. - - - - - 33f09551 by Ryan Scott at 2020-03-31T10:54:57-04:00 Add regression test for #17963 The panic in #17963 happened to be fixed by commit e3c374cc5bd7eb49649b9f507f9f7740697e3f70. This patch adds a regression test to ensure that it remains fixed. Fixes #17963. - - - - - 09a36e80 by Ömer Sinan Ağacan at 2020-03-31T10:55:37-04:00 Simplify stderrSupportsAnsiColors The combinator andM is used only once, and the code is shorter and simpler if you inline it. - - - - - 95bccdd0 by Ben Gamari at 2020-03-31T10:56:19-04:00 base: Ensure that encoding global variables aren't inlined As noted in #17970, these (e.g. `getFileSystemEncoding` and `setFileSystemEncoding`) previously had unfoldings, which would break their global-ness. While not strictly necessary, I also add a NOINLINE on `initLocaleEncoding` since it is used in `System.IO`, ensuring that we only system's query the locale encoding once. Fixes #17970. - - - - - 982aaa83 by Andreas Klebinger at 2020-03-31T10:56:55-04:00 Update hadrian index revision. Required in order to build hadrian using ghc-8.10 - - - - - 4b9c5864 by Ben Gamari at 2020-03-31T10:57:32-04:00 integer-gmp: Bump version and add changelog entry - - - - - 9b39f2e6 by Ryan Scott at 2020-04-01T01:20:00-04:00 Clean up "Eta reduction for data families" Notes Before, there were two distinct Notes named "Eta reduction for data families". This renames one of them to "Implementing eta reduction for data families" to disambiguate the two and fixes references in other parts of the codebase to ensure that they are pointing to the right place. Fixes #17313. [ci skip] - - - - - 7627eab5 by Ryan Scott at 2020-04-01T01:20:38-04:00 Fix the changelog/@since information for hGetContents'/getContents'/readFile' Fixes #17979. [ci skip] - - - - - 0002db1b by Sylvain Henry at 2020-04-01T01:21:27-04:00 Kill wORDS_BIGENDIAN and replace it with platformByteOrder (#17957) Metric Decrease: T13035 T1969 - - - - - 7b217179 by Sebastian Graf at 2020-04-01T15:03:24-04:00 PmCheck: Adjust recursion depth for inhabitation test In #17977, we ran into the reduction depth limit of the typechecker. That was only a symptom of a much broader issue: The recursion depth of the coverage checker for trying to instantiate strict fields in the `nonVoid` test was far too high (100, the `defaultMaxTcBound`). As a result, we were performing quite poorly on `T17977`. Short of a proper termination analysis to prove emptyness of a type, we just arbitrarily default to a much lower recursion limit of 3. Fixes #17977. - - - - - 3c09f636 by Andreas Klebinger at 2020-04-01T15:03:59-04:00 Make hadrian pass on the no-colour setting to GHC. Fixes #17983. - - - - - b943b25d by Simon Peyton Jones at 2020-04-02T01:45:58-04:00 Re-engineer the binder-swap transformation The binder-swap transformation is implemented by the occurrence analyser -- see Note [Binder swap] in OccurAnal. However it had a very nasty corner in it, for the case where the case scrutinee was a GlobalId. This led to trouble and hacks, and ultimately to #16296. This patch re-engineers how the occurrence analyser implements the binder-swap, by actually carrying out a substitution rather than by adding a let-binding. It's all described in Note [The binder-swap substitution]. I did a few other things along the way * Fix a bug in StgCse, which could allow a loop breaker to be CSE'd away. See Note [Care with loop breakers] in StgCse. I think it can only show up if occurrence analyser sets up bad loop breakers, but still. * Better commenting in SimplUtils.prepareAlts * A little refactoring in CoreUnfold; nothing significant e.g. rename CoreUnfold.mkTopUnfolding to mkFinalUnfolding * Renamed CoreSyn.isFragileUnfolding to hasCoreUnfolding * Move mkRuleInfo to CoreFVs We observed respectively 4.6% and 5.9% allocation decreases for the following tests: Metric Decrease: T9961 haddock.base - - - - - 42d68364 by Sebastian Graf at 2020-04-02T01:46:34-04:00 Preserve precise exceptions in strictness analysis Fix #13380 and #17676 by 1. Changing `raiseIO#` to have `topDiv` instead of `botDiv` 2. Give it special treatment in `Simplifier.Util.mkArgInfo`, treating it as if it still had `botDiv`, to recover dead code elimination. This is the first commit of the plan outlined in https://gitlab.haskell.org/ghc/ghc/-/merge_requests/2525#note_260886. - - - - - 0a88dd11 by Ömer Sinan Ağacan at 2020-04-02T01:47:25-04:00 Fix a pointer format string in RTS - - - - - 5beac042 by Ömer Sinan Ağacan at 2020-04-02T01:48:05-04:00 Remove unused closure stg_IND_direct - - - - - 88f38b03 by Ben Gamari at 2020-04-02T01:48:42-04:00 Session: Memoize stderrSupportsAnsiColors Not only is this a reasonable efficiency measure but it avoids making reentrant calls into ncurses, which is not thread-safe. See #17922. - - - - - 27740f24 by Ryan Scott at 2020-04-02T01:49:21-04:00 Make Hadrian build with Cabal-3.2 GHC 8.10 ships with `Cabal-3.2.0.0`, so it would be convenient to make Hadrian supporting building against 3.2.* instead of having to rebuild the entirety of `Cabal-3.0.0.0`. There is one API change in `Cabal-3.2.*` that affects Hadrian: the `synopsis` and `description` functions now return `ShortText` instead of `String`. Since Hadrian manipulates these `String`s in various places, I found that the simplest fix was to use CPP to convert `ShortText` to `String`s where appropriate. - - - - - 49802002 by Sylvain Henry at 2020-04-02T01:50:00-04:00 Update Stack resolver for hadrian/build-stack Broken by 57b888c0e90be7189285a6b078c30b26d0923809 - - - - - 30a63e79 by Ryan Scott at 2020-04-02T01:50:36-04:00 Fix two ASSERT buglets in reifyDataCon Two `ASSERT`s in `reifyDataCon` were always using `arg_tys`, but `arg_tys` is not meaningful for GADT constructors. In fact, it's worse than non-meaningful, since using `arg_tys` when reifying a GADT constructor can lead to failed `ASSERT`ions, as #17305 demonstrates. This patch applies the simplest possible fix to the immediate problem. The `ASSERT`s now use `r_arg_tys` instead of `arg_tys`, as the former makes sure to give something meaningful for GADT constructors. This makes the panic go away at the very least. There is still an underlying issue with the way the internals of `reifyDataCon` work, as described in https://gitlab.haskell.org/ghc/ghc/issues/17305#note_227023, but we leave that as future work, since fixing the underlying issue is much trickier (see https://gitlab.haskell.org/ghc/ghc/issues/17305#note_227087). - - - - - ef7576c4 by Zubin Duggal at 2020-04-03T06:24:56-04:00 Add outputable instances for the types in GHC.Iface.Ext.Types, add -ddump-hie flag to dump pretty printed contents of the .hie file Metric Increase: hie002 Because of the regression on i386: compile_time/bytes allocated increased from i386-linux-deb9 baseline @ HEAD~10: Expected hie002 (normal) compile_time/bytes allocated: 583014888.0 +/-10% Lower bound hie002 (normal) compile_time/bytes allocated: 524713399 Upper bound hie002 (normal) compile_time/bytes allocated: 641316377 Actual hie002 (normal) compile_time/bytes allocated: 877986292 Deviation hie002 (normal) compile_time/bytes allocated: 50.6 % *** unexpected stat test failure for hie002(normal) - - - - - 9462452a by Andreas Klebinger at 2020-04-03T06:25:33-04:00 Improve and refactor StgToCmm codegen for DataCons. We now differentiate three cases of constructor bindings: 1)Bindings which we can "replace" with a reference to an existing closure. Reference the replacement closure when accessing the binding. 2)Bindings which we can "replace" as above. But we still generate a closure which will be referenced by modules importing this binding. 3)For any other binding generate a closure. Then reference it. Before this patch 1) did only apply to local bindings and we didn't do 2) at all. - - - - - a214d214 by Moritz Bruder at 2020-04-03T06:26:11-04:00 Add singleton to NonEmpty in libraries/base This adds a definition to construct a singleton non-empty list (Data.List.NonEmpty) according to issue #17851. - - - - - f7597aa0 by Sylvain Henry at 2020-04-03T06:26:54-04:00 Testsuite: measure compiler stats for T16190 We were mistakenly measuring program stats - - - - - a485c3c4 by Sylvain Henry at 2020-04-03T06:26:54-04:00 Move blob handling into StgToCmm Move handling of big literal strings from CmmToAsm to StgToCmm. It avoids the use of `sdocWithDynFlags` (cf #10143). We might need to move this handling even higher in the pipeline in the future (cf #17960): this patch will make it easier. - - - - - cc2918a0 by Sylvain Henry at 2020-04-03T06:26:54-04:00 Refactor CmmStatics In !2959 we noticed that there was some redundant code (in GHC.Cmm.Utils and GHC.Cmm.StgToCmm.Utils) used to deal with `CmmStatics` datatype (before SRT generation) and `RawCmmStatics` datatype (after SRT generation). This patch removes this redundant code by using a single GADT for (Raw)CmmStatics. - - - - - 9e60273d by Maxim Koltsov at 2020-04-03T06:27:32-04:00 Fix haddock formatting in Control.Monad.ST.Lazy.Imp.hs - - - - - 1b7e8a94 by Andreas Klebinger at 2020-04-03T06:28:08-04:00 Turn newlines into spaces for hadrian/ghci. The newlines break the command on windows. - - - - - 4291bdda by Simon Peyton Jones at 2020-04-03T06:28:44-04:00 Major improvements to the specialiser This patch is joint work of Alexis King and Simon PJ. It does some significant refactoring of the type-class specialiser. Main highlights: * We can specialise functions with types like f :: Eq a => a -> Ord b => b => blah where the classes aren't all at the front (#16473). Here we can correctly specialise 'f' based on a call like f @Int @Bool dEqInt x dOrdBool This change really happened in an earlier patch commit 2d0cf6252957b8980d89481ecd0b79891da4b14b Author: Sandy Maguire <sandy at sandymaguire.me> Date: Thu May 16 12:12:10 2019 -0400 work that this new patch builds directly on that work, and refactors it a bit. * We can specialise functions with implicit parameters (#17930) g :: (?foo :: Bool, Show a) => a -> String Previously we could not, but now they behave just like a non-class argument as in 'f' above. * We can specialise under-saturated calls, where some (but not all of the dictionary arguments are provided (#17966). For example, we can specialise the above 'f' based on a call map (f @Int dEqInt) xs even though we don't (and can't) give Ord dictionary. This may sound exotic, but #17966 is a program from the wild, and showed significant perf loss for functions like f, if you need saturation of all dictionaries. * We fix a buglet in which a floated dictionary had a bogus demand (#17810), by using zapIdDemandInfo in the NonRec case of specBind. * A tiny side benefit: we can drop dead arguments to specialised functions; see Note [Drop dead args from specialisations] * Fixed a bug in deciding what dictionaries are "interesting"; see Note [Keep the old dictionaries interesting] This is all achieved by by building on Sandy Macguire's work in defining SpecArg, which mkCallUDs uses to describe the arguments of the call. Main changes: * Main work is in specHeader, which marched down the [InBndr] from the function definition and the [SpecArg] from the call site, together. * specCalls no longer has an arity check; the entire mechanism now handles unders-saturated calls fine. * mkCallUDs decides on an argument-by-argument basis whether to specialise a particular dictionary argument; this is new. See mk_spec_arg in mkCallUDs. It looks as if there are many more lines of code, but I think that all the extra lines are comments! - - - - - 40a85563 by Ömer Sinan Ağacan at 2020-04-03T18:26:19+03:00 Revert accidental change in 9462452 [ci skip] - - - - - bd75e5da by Ryan Scott at 2020-04-04T07:07:58-04:00 Enable ImpredicativeTypes internally when typechecking selector bindings This is necessary for certain record selectors with higher-rank types, such as the examples in #18005. See `Note [Impredicative record selectors]` in `TcTyDecls`. Fixes #18005. - - - - - dcfe29c8 by Ömer Sinan Ağacan at 2020-04-06T13:16:08-04:00 Don't override proc CafInfos in ticky builds Fixes #17947 When we have a ticky label for a proc, IdLabels for the ticky counter and proc entry share the same Name. This caused overriding proc CafInfos with the ticky CafInfos (i.e. NoCafRefs) during SRT analysis. We now ignore the ticky labels when building SRTMaps. This makes sense because: - When building the current module they don't need to be in SRTMaps as they're initialized as non-CAFFY (see mkRednCountsLabel), so they don't take part in the dependency analysis and they're never added to SRTs. (Reminder: a "dependency" in the SRT analysis is a CAFFY dependency, non-CAFFY uses are not considered as dependencies for the algorithm) - They don't appear in the interfaces as they're not exported, so it doesn't matter for cross-module concerns whether they're in the SRTMap or not. See also the new Note [Ticky labels in SRT analysis]. - - - - - cec2c71f by Simon Peyton Jones at 2020-04-06T13:16:44-04:00 Fix an tricky specialiser loop Issue #17151 was a very tricky example of a bug in which the specialiser accidentally constructs a recurive dictionary, so that everything turns into bottom. I have fixed variants of this bug at least twice before: see Note [Avoiding loops]. It was a bit of a struggle to isolate the problem, greatly aided by the work that Alexey Kuleshevich did in distilling a test case. Once I'd understood the problem, it was not difficult to fix, though it did lead me a bit of refactoring in specImports. - - - - - e850d14f by Simon Peyton Jones at 2020-04-06T13:16:44-04:00 Refactoring only This refactors DictBinds into a data type rather than a pair. No change in behaviour, just better code - - - - - f38e8d61 by Daniel Gröber at 2020-04-07T02:00:05-04:00 rts: ProfHeap: Fix memory leak when not compiled with profiling If we're doing heap profiling on an unprofiled executable we keep allocating new space in initEra via nextEra on each profiler run but we don't have a corresponding freeEra call. We do free the last era in endHeapProfiling but previous eras will have been overwritten by initEra and will never get free()ed. Metric Decrease: space_leak_001 - - - - - bcd66859 by Sebastian Graf at 2020-04-07T02:00:41-04:00 Re-export GHC.Magic.noinline from base - - - - - 3d2991f8 by Ben Gamari at 2020-04-07T18:36:09-04:00 simplifier: Kill off ufKeenessFactor We used to have another factor, ufKeenessFactor, which would scale the discounts before they were subtracted from the size. This was justified with the following comment: -- We multiple the raw discounts (args_discount and result_discount) -- ty opt_UnfoldingKeenessFactor because the former have to do with -- *size* whereas the discounts imply that there's some extra -- *efficiency* to be gained (e.g. beta reductions, case reductions) -- by inlining. However, this is highly suspect since it means that we subtract a *scaled* size from an absolute size, resulting in crazy (e.g. negative) scores in some cases (#15304). We consequently killed off ufKeenessFactor and bumped up the ufUseThreshold to compensate. Adjustment of unfolding use threshold ===================================== Since this removes a discount from our inlining heuristic, I revisited our default choice of -funfolding-use-threshold to minimize the change in overall inlining behavior. Specifically, I measured runtime allocations and executable size of nofib and the testsuite performance tests built using compilers (and core libraries) built with several values of -funfolding-use-threshold. This comes as a result of a quantitative comparison of testsuite performance and code size as a function of ufUseThreshold, comparing GHC trees using values of 50, 60, 70, 80, 90, and 100. The test set consisted of nofib and the testsuite performance tests. A full summary of these measurements are found in the description of !2608 Comparing executable sizes (relative to the base commit) across all nofib tests, we see that sizes are similar to the baseline: gmean min max median thresh 50 -6.36% -7.04% -4.82% -6.46% 60 -5.04% -5.97% -3.83% -5.11% 70 -2.90% -3.84% -2.31% -2.92% 80 -0.75% -2.16% -0.42% -0.73% 90 +0.24% -0.41% +0.55% +0.26% 100 +1.36% +0.80% +1.64% +1.37% baseline +0.00% +0.00% +0.00% +0.00% Likewise, looking at runtime allocations we see that 80 gives slightly better optimisation than the baseline: gmean min max median thresh 50 +0.16% -0.16% +4.43% +0.00% 60 +0.09% -0.00% +3.10% +0.00% 70 +0.04% -0.09% +2.29% +0.00% 80 +0.02% -1.17% +2.29% +0.00% 90 -0.02% -2.59% +1.86% +0.00% 100 +0.00% -2.59% +7.51% -0.00% baseline +0.00% +0.00% +0.00% +0.00% Finally, I had to add a NOINLINE in T4306 to ensure that `upd` is worker-wrappered as the test expects. This makes me wonder whether the inlining heuristic is now too liberal as `upd` is quite a large function. The same measure was taken in T12600. Wall clock time compiling Cabal with -O0 thresh 50 60 70 80 90 100 baseline build-Cabal 93.88 89.58 92.59 90.09 100.26 94.81 89.13 Also, this change happens to avoid the spurious test output in `plugin-recomp-change` and `plugin-recomp-change-prof` (see #17308). Metric Decrease: hie002 T12234 T13035 T13719 T14683 T4801 T5631 T5642 T9020 T9872d T9961 Metric Increase: T12150 T12425 T13701 T14697 T15426 T1969 T3064 T5837 T6048 T9203 T9872a T9872b T9872c T9872d haddock.Cabal haddock.base haddock.compiler - - - - - 255418da by Sylvain Henry at 2020-04-07T18:36:49-04:00 Modules: type-checker (#13009) Update Haddock submodule - - - - - 04b6cf94 by Ryan Scott at 2020-04-07T19:43:20-04:00 Make NoExtCon fields strict This changes every unused TTG extension constructor to be strict in its field so that the pattern-match coverage checker is smart enough any such constructors are unreachable in pattern matches. This lets us remove nearly every use of `noExtCon` in the GHC API. The only ones we cannot remove are ones underneath uses of `ghcPass`, but that is only because GHC 8.8's and 8.10's coverage checkers weren't smart enough to perform this kind of reasoning. GHC HEAD's coverage checker, on the other hand, _is_ smart enough, so we guard these uses of `noExtCon` with CPP for now. Bumps the `haddock` submodule. Fixes #17992. - - - - - 7802fa17 by Ryan Scott at 2020-04-08T16:43:44-04:00 Handle promoted data constructors in typeToLHsType correctly Instead of using `nlHsTyVar`, which hardcodes `NotPromoted`, have `typeToLHsType` pick between `Promoted` and `NotPromoted` by checking if a type constructor is promoted using `isPromotedDataCon`. Fixes #18020. - - - - - ce481361 by Ben Gamari at 2020-04-09T16:17:21-04:00 hadrian: Use --export-dynamic when linking iserv As noticed in #17962, the make build system currently does this (see 3ce0e0ba) but the change was never ported to Hadrian. - - - - - fa66f143 by Ben Gamari at 2020-04-09T16:17:21-04:00 iserv: Don't pass --export-dynamic on FreeBSD This is definitely a hack but it's probably the best we can do for now. Hadrian does the right thing here by passing --export-dynamic only to the linker. - - - - - 39075176 by Ömer Sinan Ağacan at 2020-04-09T16:18:00-04:00 Fix CNF handling in compacting GC Fixes #17937 Previously compacting GC simply ignored CNFs. This is mostly fine as most (see "What about small compacts?" below) CNF objects don't have outgoing pointers, and are "large" (allocated in large blocks) and large objects are not moved or compacted. However if we do GC *during* sharing-preserving compaction then the CNF will have a hash table mapping objects that have been moved to the CNF to their location in the CNF, to be able to preserve sharing. This case is handled in the copying collector, in `scavenge_compact`, where we evacuate hash table entries and then rehash the table. Compacting GC ignored this case. We now visit CNFs in all generations when threading pointers to the compacted heap and thread hash table keys. A visited CNF is added to the list `nfdata_chain`. After compaction is done, we re-visit the CNFs in that list and rehash the tables. The overhead is minimal: the list is static in `Compact.c`, and link field is added to `StgCompactNFData` closure. Programs that don't use CNFs should not be affected. To test this CNF tests are now also run in a new way 'compacting_gc', which just passes `-c` to the RTS, enabling compacting GC for the oldest generation. Before this patch the result would be: Unexpected failures: compact_gc.run compact_gc [bad exit code (139)] (compacting_gc) compact_huge_array.run compact_huge_array [bad exit code (1)] (compacting_gc) With this patch all tests pass. I can also pass `-c -DS` without any failures. What about small compacts? Small CNFs are still not handled by the compacting GC. However so far I'm unable to write a test that triggers a runtime panic ("update_fwd: unknown/strange object") by allocating a small CNF in a compated heap. It's possible that I'm missing something and it's not possible to have a small CNF. NoFib Results: -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS +0.1% 0.0% 0.0% +0.0% +0.0% CSD +0.1% 0.0% 0.0% 0.0% 0.0% FS +0.1% 0.0% 0.0% 0.0% 0.0% S +0.1% 0.0% 0.0% 0.0% 0.0% VS +0.1% 0.0% 0.0% 0.0% 0.0% VSD +0.1% 0.0% +0.0% +0.0% -0.0% VSM +0.1% 0.0% +0.0% -0.0% 0.0% anna +0.0% 0.0% -0.0% -0.0% -0.0% ansi +0.1% 0.0% +0.0% +0.0% +0.0% atom +0.1% 0.0% +0.0% +0.0% +0.0% awards +0.1% 0.0% +0.0% +0.0% +0.0% banner +0.1% 0.0% +0.0% +0.0% +0.0% bernouilli +0.1% 0.0% 0.0% -0.0% +0.0% binary-trees +0.1% 0.0% -0.0% -0.0% 0.0% boyer +0.1% 0.0% +0.0% +0.0% +0.0% boyer2 +0.1% 0.0% +0.0% +0.0% +0.0% bspt +0.1% 0.0% -0.0% -0.0% -0.0% cacheprof +0.1% 0.0% -0.0% -0.0% -0.0% calendar +0.1% 0.0% +0.0% +0.0% +0.0% cichelli +0.1% 0.0% +0.0% +0.0% +0.0% circsim +0.1% 0.0% +0.0% +0.0% +0.0% clausify +0.1% 0.0% -0.0% +0.0% +0.0% comp_lab_zift +0.1% 0.0% +0.0% +0.0% +0.0% compress +0.1% 0.0% +0.0% +0.0% 0.0% compress2 +0.1% 0.0% -0.0% 0.0% 0.0% constraints +0.1% 0.0% +0.0% +0.0% +0.0% cryptarithm1 +0.1% 0.0% +0.0% +0.0% +0.0% cryptarithm2 +0.1% 0.0% +0.0% +0.0% +0.0% cse +0.1% 0.0% +0.0% +0.0% +0.0% digits-of-e1 +0.1% 0.0% +0.0% -0.0% -0.0% digits-of-e2 +0.1% 0.0% -0.0% -0.0% -0.0% dom-lt +0.1% 0.0% +0.0% +0.0% +0.0% eliza +0.1% 0.0% +0.0% +0.0% +0.0% event +0.1% 0.0% +0.0% +0.0% +0.0% exact-reals +0.1% 0.0% +0.0% +0.0% +0.0% exp3_8 +0.1% 0.0% +0.0% -0.0% 0.0% expert +0.1% 0.0% +0.0% +0.0% +0.0% fannkuch-redux +0.1% 0.0% -0.0% 0.0% 0.0% fasta +0.1% 0.0% -0.0% +0.0% +0.0% fem +0.1% 0.0% -0.0% +0.0% 0.0% fft +0.1% 0.0% -0.0% +0.0% +0.0% fft2 +0.1% 0.0% +0.0% +0.0% +0.0% fibheaps +0.1% 0.0% +0.0% +0.0% +0.0% fish +0.1% 0.0% +0.0% +0.0% +0.0% fluid +0.0% 0.0% +0.0% +0.0% +0.0% fulsom +0.1% 0.0% -0.0% +0.0% 0.0% gamteb +0.1% 0.0% +0.0% +0.0% 0.0% gcd +0.1% 0.0% +0.0% +0.0% +0.0% gen_regexps +0.1% 0.0% -0.0% +0.0% 0.0% genfft +0.1% 0.0% +0.0% +0.0% +0.0% gg +0.1% 0.0% 0.0% +0.0% +0.0% grep +0.1% 0.0% -0.0% +0.0% +0.0% hidden +0.1% 0.0% +0.0% -0.0% 0.0% hpg +0.1% 0.0% -0.0% -0.0% -0.0% ida +0.1% 0.0% +0.0% +0.0% +0.0% infer +0.1% 0.0% +0.0% 0.0% -0.0% integer +0.1% 0.0% +0.0% +0.0% +0.0% integrate +0.1% 0.0% -0.0% -0.0% -0.0% k-nucleotide +0.1% 0.0% +0.0% +0.0% 0.0% kahan +0.1% 0.0% +0.0% +0.0% +0.0% knights +0.1% 0.0% -0.0% -0.0% -0.0% lambda +0.1% 0.0% +0.0% +0.0% -0.0% last-piece +0.1% 0.0% +0.0% 0.0% 0.0% lcss +0.1% 0.0% +0.0% +0.0% 0.0% life +0.1% 0.0% -0.0% +0.0% +0.0% lift +0.1% 0.0% +0.0% +0.0% +0.0% linear +0.1% 0.0% -0.0% +0.0% 0.0% listcompr +0.1% 0.0% +0.0% +0.0% +0.0% listcopy +0.1% 0.0% +0.0% +0.0% +0.0% maillist +0.1% 0.0% +0.0% -0.0% -0.0% mandel +0.1% 0.0% +0.0% +0.0% 0.0% mandel2 +0.1% 0.0% +0.0% +0.0% +0.0% mate +0.1% 0.0% +0.0% 0.0% +0.0% minimax +0.1% 0.0% -0.0% 0.0% -0.0% mkhprog +0.1% 0.0% +0.0% +0.0% +0.0% multiplier +0.1% 0.0% +0.0% 0.0% 0.0% n-body +0.1% 0.0% +0.0% +0.0% +0.0% nucleic2 +0.1% 0.0% +0.0% +0.0% +0.0% para +0.1% 0.0% 0.0% +0.0% +0.0% paraffins +0.1% 0.0% +0.0% -0.0% 0.0% parser +0.1% 0.0% -0.0% -0.0% -0.0% parstof +0.1% 0.0% +0.0% +0.0% +0.0% pic +0.1% 0.0% -0.0% -0.0% 0.0% pidigits +0.1% 0.0% +0.0% -0.0% -0.0% power +0.1% 0.0% +0.0% +0.0% +0.0% pretty +0.1% 0.0% -0.0% -0.0% -0.1% primes +0.1% 0.0% -0.0% -0.0% -0.0% primetest +0.1% 0.0% -0.0% -0.0% -0.0% prolog +0.1% 0.0% -0.0% -0.0% -0.0% puzzle +0.1% 0.0% -0.0% -0.0% -0.0% queens +0.1% 0.0% +0.0% +0.0% +0.0% reptile +0.1% 0.0% -0.0% -0.0% +0.0% reverse-complem +0.1% 0.0% +0.0% 0.0% -0.0% rewrite +0.1% 0.0% -0.0% -0.0% -0.0% rfib +0.1% 0.0% +0.0% +0.0% +0.0% rsa +0.1% 0.0% -0.0% +0.0% -0.0% scc +0.1% 0.0% -0.0% -0.0% -0.1% sched +0.1% 0.0% +0.0% +0.0% +0.0% scs +0.1% 0.0% +0.0% +0.0% +0.0% simple +0.1% 0.0% -0.0% -0.0% -0.0% solid +0.1% 0.0% +0.0% +0.0% +0.0% sorting +0.1% 0.0% -0.0% -0.0% -0.0% spectral-norm +0.1% 0.0% +0.0% +0.0% +0.0% sphere +0.1% 0.0% -0.0% -0.0% -0.0% symalg +0.1% 0.0% -0.0% -0.0% -0.0% tak +0.1% 0.0% +0.0% +0.0% +0.0% transform +0.1% 0.0% +0.0% +0.0% +0.0% treejoin +0.1% 0.0% +0.0% -0.0% -0.0% typecheck +0.1% 0.0% +0.0% +0.0% +0.0% veritas +0.0% 0.0% +0.0% +0.0% +0.0% wang +0.1% 0.0% 0.0% +0.0% +0.0% wave4main +0.1% 0.0% +0.0% +0.0% +0.0% wheel-sieve1 +0.1% 0.0% +0.0% +0.0% +0.0% wheel-sieve2 +0.1% 0.0% +0.0% +0.0% +0.0% x2n1 +0.1% 0.0% +0.0% +0.0% +0.0% -------------------------------------------------------------------------------- Min +0.0% 0.0% -0.0% -0.0% -0.1% Max +0.1% 0.0% +0.0% +0.0% +0.0% Geometric Mean +0.1% -0.0% -0.0% -0.0% -0.0% Bumping numbers of nonsensical perf tests: Metric Increase: T12150 T12234 T12425 T13035 T5837 T6048 It's simply not possible for this patch to increase allocations, and I've wasted enough time on these test in the past (see #17686). I think these tests should not be perf tests, but for now I'll bump the numbers. - - - - - dce50062 by Sylvain Henry at 2020-04-09T16:18:44-04:00 Rts: show errno on failure (#18033) - - - - - 045139f4 by Hécate at 2020-04-09T23:10:44-04:00 Add an example to liftIO and explain its purpose - - - - - 101fab6e by Sebastian Graf at 2020-04-09T23:11:21-04:00 Special case `isConstraintKindCon` on `AlgTyCon` Previously, the `tyConUnique` record selector would unfold into a huge case expression that would be inlined in all call sites, such as the `INLINE`-annotated `coreView`, see #18026. `constraintKindTyConKey` only occurs as the `Unique` of an `AlgTyCon` anyway, so we can make the code a lot more compact, but have to move it to GHC.Core.TyCon. Metric Decrease: T12150 T12234 - - - - - f5212dfc by Sebastian Graf at 2020-04-09T23:11:57-04:00 DmdAnal: No need to attach a StrictSig to DataCon workers In GHC.Types.Id.Make we were giving a strictness signature to every data constructor wrapper Id that we weren't looking at in demand analysis anyway. We used to use its CPR info, but that has its own CPR signature now. `Note [Data-con worker strictness]` then felt very out of place, so I moved it to GHC.Core.DataCon. - - - - - 75a185dc by Sylvain Henry at 2020-04-09T23:12:37-04:00 Hadrian: fix --summary - - - - - 723062ed by Ömer Sinan Ağacan at 2020-04-10T09:18:14+03:00 testsuite: Move no_lint to the top level, tweak hie002 - We don't want to benchmark linting so disable lints in hie002 perf test - Move no_lint to the top-level to be able to use it in tests other than those in `testsuite/tests/perf/compiler`. - Filter out -dstg-lint in no_lint. - hie002 allocation numbers on 32-bit are unstable, so skip it on 32-bit Metric Decrease: hie002 ManyConstructors T12150 T12234 T13035 T1969 T4801 T9233 T9961 - - - - - bcafaa82 by Peter Trommler at 2020-04-10T19:29:33-04:00 Testsuite: mark T11531 fragile The test depends on a link editor allowing undefined symbols in an ELF shared object. This is the standard but it seems some distributions patch their link editor. See the report by @hsyl20 in #11531. Fixes #11531 - - - - - 0889f5ee by Takenobu Tani at 2020-04-12T11:44:52+09:00 testsuite: Fix comment for a language extension [skip ci] - - - - - cd4f92b5 by Simon Peyton Jones at 2020-04-12T11:20:58-04:00 Significant refactor of Lint This refactoring of Lint was triggered by #17923, which is fixed by this patch. The main change is this. Instead of lintType :: Type -> LintM LintedKind we now have lintType :: Type -> LintM LintedType Previously, all of typeKind was effectively duplicate in lintType. Moreover, since we have an ambient substitution, we still had to apply the substition here and there, sometimes more than once. It was all very tricky, in the end, and made my head hurt. Now, lintType returns a fully linted type, with all substitutions performed on it. This is much simpler. The same thing is needed for Coercions. Instead of lintCoercion :: OutCoercion -> LintM (LintedKind, LintedKind, LintedType, LintedType, Role) we now have lintCoercion :: Coercion -> LintM LintedCoercion Much simpler! The code is shorter and less bug-prone. There are a lot of knock on effects. But life is now better. Metric Decrease: T1969 - - - - - 0efaf301 by Josh Meredith at 2020-04-12T11:21:34-04:00 Implement extensible interface files - - - - - 54ca66a7 by Ryan Scott at 2020-04-12T11:22:10-04:00 Use conLikeUserTyVarBinders to quantify field selector types This patch: 1. Writes up a specification for how the types of top-level field selectors should be determined in a new section of the GHC User's Guide, and 2. Makes GHC actually implement that specification by using `conLikeUserTyVarBinders` in `mkOneRecordSelector` to preserve the order and specificity of type variables written by the user. Fixes #18023. - - - - - 35799dda by Ben Gamari at 2020-04-12T11:22:50-04:00 hadrian: Don't --export-dynamic on Darwin When fixing #17962 I neglected to consider that --export-dynamic is only supported on ELF platforms. - - - - - e8029816 by Alexis King at 2020-04-12T11:23:27-04:00 Add an INLINE pragma to Control.Category.>>> This fixes #18013 by adding INLINE pragmas to both Control.Category.>>> and GHC.Desugar.>>>. The functional change in this patch is tiny (just two lines of pragmas!), but an accompanying Note explains in gory detail what’s going on. - - - - - 0da186c1 by Krzysztof Gogolewski at 2020-04-14T07:55:20-04:00 Change zipWith to zipWithEqual in a few places - - - - - 074c1ccd by Andreas Klebinger at 2020-04-14T07:55:55-04:00 Small change to the windows ticker. We already have a function to go from time to ms so use it. Also expand on the state of timer resolution. - - - - - b69cc884 by Alp Mestanogullari at 2020-04-14T07:56:38-04:00 hadrian: get rid of unnecessary levels of nesting in source-dist - - - - - d0c3b069 by Julien Debon at 2020-04-14T07:57:16-04:00 doc (Foldable): Add examples to Data.Foldable See #17929 - - - - - 5b08e0c0 by Ben Gamari at 2020-04-14T23:28:20-04:00 StgCRun: Enable unwinding only on Linux It's broken on macOS due and SmartOS due to assembler differences (#15207) so let's be conservative in enabling it. Also, refactor things to make the intent clearer. - - - - - 27cc2e7b by Ben Gamari at 2020-04-14T23:28:57-04:00 rts: Don't mark evacuate_large as inline This function has two callsites and is quite large. GCC consequently decides not to inline and warns instead. Given the situation, I can't blame it. Let's just remove the inline specifier. - - - - - 9853fc5e by Ben Gamari at 2020-04-14T23:29:48-04:00 base: Enable large file support for OFD locking impl. Not only is this a good idea in general but this should also avoid issue #17950 by ensuring that off_t is 64-bits. - - - - - 7b41f21b by Matthew Pickering at 2020-04-14T23:30:24-04:00 Hadrian: Make -i paths absolute The primary reason for this change is that ghcide does not work with relative paths. It also matches what cabal and stack do, they always pass absolute paths. - - - - - 41230e26 by Daniel Gröber at 2020-04-14T23:31:01-04:00 Zero out pinned block alignment slop when profiling The heap profiler currently cannot traverse pinned blocks because of alignment slop. This used to just be a minor annoyance as the whole block is accounted into a special cost center rather than the respective object's CCS, cf. #7275. However for the new root profiler we would like to be able to visit _every_ closure on the heap. We need to do this so we can get rid of the current 'flip' bit hack in the heap traversal code. Since info pointers are always non-zero we can in principle skip all the slop in the profiler if we can rely on it being zeroed. This assumption caused problems in the past though, commit a586b33f8e ("rts: Correct handling of LARGE ARR_WORDS in LDV profiler"), part of !1118, tried to use the same trick for BF_LARGE objects but neglected to take into account that shrink*Array# functions don't ensure that slop is zeroed when not compiling with profiling. Later, commit 0c114c6599 ("Handle large ARR_WORDS in heap census (fix as we will only be assuming slop is zeroed when profiling is on. This commit also reduces the ammount of slop we introduce in the first place by calculating the needed alignment before doing the allocation for small objects where we know the next available address. For large objects we don't know how much alignment we'll have to do yet since those details are hidden behind the allocateMightFail function so there we continue to allocate the maximum additional words we'll need to do the alignment. So we don't have to duplicate all this logic in the cmm code we pull it into the RTS allocatePinned function instead. Metric Decrease: T7257 haddock.Cabal haddock.base - - - - - 15fa9bd6 by Daniel Gröber at 2020-04-14T23:31:01-04:00 rts: Expand and add more notes regarding slop - - - - - caf3f444 by Daniel Gröber at 2020-04-14T23:31:01-04:00 rts: allocatePinned: Fix confusion about word/byte units - - - - - c3c0f662 by Daniel Gröber at 2020-04-14T23:31:01-04:00 rts: Underline some Notes as is conventional - - - - - e149dea9 by Daniel Gröber at 2020-04-14T23:31:38-04:00 rts: Fix nomenclature in OVERWRITING_CLOSURE macros The additional commentary introduced by commit 8916e64e5437 ("Implement shrinkSmallMutableArray# and resizeSmallMutableArray#.") unfortunately got this wrong. We set 'prim' to true in overwritingClosureOfs because we _don't_ want to call LDV_recordDead(). The reason is because of this "inherently used" distinction made in the LDV profiler so I rename the variable to be more appropriate. - - - - - 1dd3d18c by Daniel Gröber at 2020-04-14T23:31:38-04:00 Remove call to LDV_RECORD_CREATE for array resizing - - - - - 19de2fb0 by Daniel Gröber at 2020-04-14T23:31:38-04:00 rts: Assert LDV_recordDead is not called for inherently used closures The comments make it clear LDV_recordDead should not be called for inhererently used closures, so add an assertion to codify this fact. - - - - - 0b934e30 by Ryan Scott at 2020-04-14T23:32:14-04:00 Bump template-haskell version to 2.17.0.0 This requires bumping the `exceptions` and `text` submodules to bring in commits that bump their respective upper version bounds on `template-haskell`. Fixes #17645. Fixes #17696. Note that the new `text` commit includes a fair number of additions to the Haddocks in that library. As a result, Haddock has to do more work during the `haddock.Cabal` test case, increasing the number of allocations it requires. Therefore, ------------------------- Metric Increase: haddock.Cabal ------------------------- - - - - - 22cc8e51 by Ryan Scott at 2020-04-15T17:48:47-04:00 Fix #18052 by using pprPrefixOcc in more places This fixes several small oversights in the choice of pretty-printing function to use. Fixes #18052. - - - - - ec77b2f1 by Daniel Gröber at 2020-04-15T17:49:24-04:00 rts: ProfHeap: Fix wrong time in last heap profile sample We've had this longstanding issue in the heap profiler, where the time of the last sample in the profile is sometimes way off causing the rendered graph to be quite useless for long runs. It seems to me the problem is that we use mut_user_time() for the last sample as opposed to getRTSStats(), which we use when calling heapProfile() in GC.c. The former is equivalent to getProcessCPUTime() but the latter does some additional stuff: getProcessCPUTime() - end_init_cpu - stats.gc_cpu_ns - stats.nonmoving_gc_cpu_ns So to fix this just use getRTSStats() in both places. - - - - - 85fc32f0 by Sylvain Henry at 2020-04-17T12:45:25-04:00 Hadrian: fix dyn_o/dyn_hi rule (#17534) - - - - - bfde3b76 by Ryan Scott at 2020-04-17T12:46:02-04:00 Fix #18065 by fixing an InstCo oversight in Core Lint There was a small thinko in Core Lint's treatment of `InstCo` coercions that ultimately led to #18065. The fix: add an apostrophe. That's it! Fixes #18065. Co-authored-by: Simon Peyton Jones <simonpj at microsoft.com> - - - - - a05348eb by Cale Gibbard at 2020-04-17T13:08:47-04:00 Change the fail operator argument of BindStmt to be a Maybe Don't use noSyntaxExpr for it. There is no good way to defensively case on that, nor is it clear one ought to do so. - - - - - 79e27144 by John Ericson at 2020-04-17T13:08:47-04:00 Use trees that grow for rebindable operators for `<-` binds Also add more documentation. - - - - - 18bc16ed by Cale Gibbard at 2020-04-17T13:08:47-04:00 Use FailOperator in more places, define a couple datatypes (XBindStmtRn and XBindStmtTc) to help clarify the meaning of XBindStmt in the renamer and typechecker - - - - - 84cc8394 by Simon Peyton Jones at 2020-04-18T13:20:29-04:00 Add a missing zonk in tcHsPartialType I omitted a vital zonk when refactoring tcHsPartialType in commit 48fb3482f8cbc8a4b37161021e846105f980eed4 Author: Simon Peyton Jones <simonpj at microsoft.com> Date: Wed Jun 5 08:55:17 2019 +0100 Fix typechecking of partial type signatures This patch fixes it and adds commentary to explain why. Fixes #18008 - - - - - 2ee96ac1 by Ben Gamari at 2020-04-18T13:21:05-04:00 gitlab-ci: Bump FreeBSD bootstrap compiler to 8.10.1 - - - - - 434312e5 by Ben Gamari at 2020-04-18T13:21:05-04:00 gitlab-ci: Enable FreeBSD job for so-labelled MRs - - - - - ddffb227 by Ben Gamari at 2020-04-18T13:21:05-04:00 gitlab-ci: Use rules syntax for conditional jobs - - - - - e2586828 by Ben Gamari at 2020-04-18T13:21:05-04:00 Bump hsc2hs submodule - - - - - 15ab6cd5 by Ömer Sinan Ağacan at 2020-04-18T13:21:44-04:00 Improve prepForeignCall error reporting Show parameters and description of the error code when ffi_prep_cif fails. This may be helpful for debugging #17018. - - - - - 3ca52151 by Sylvain Henry at 2020-04-18T20:04:14+02:00 GHC.Core.Opt renaming * GHC.Core.Op => GHC.Core.Opt * GHC.Core.Opt.Simplify.Driver => GHC.Core.Opt.Driver * GHC.Core.Opt.Tidy => GHC.Core.Tidy * GHC.Core.Opt.WorkWrap.Lib => GHC.Core.Opt.WorkWrap.Utils As discussed in: * https://mail.haskell.org/pipermail/ghc-devs/2020-April/018758.html * https://gitlab.haskell.org/ghc/ghc/issues/13009#note_264650 - - - - - 15312bbb by Sylvain Henry at 2020-04-18T20:04:46+02:00 Modules (#13009) * SysTools * Parser * GHC.Builtin * GHC.Iface.Recomp * Settings Update Haddock submodule Metric Decrease: Naperian parsing001 - - - - - eaed0a32 by Alexis King at 2020-04-19T03:16:44-04:00 Add missing addInScope call for letrec binders in OccurAnal This fixes #18044, where a shadowed variable was incorrectly substituted by the binder swap on the RHS of a floated-in letrec. This can only happen when the uniques line up *just* right, so writing a regression test would be very difficult, but at least the fix is small and straightforward. - - - - - 36882493 by Shayne Fletcher at 2020-04-20T04:36:43-04:00 Derive Ord instance for Extension Metric Increase: T12150 T12234 - - - - - b43365ad by Simon Peyton Jones at 2020-04-20T04:37:20-04:00 Fix a buglet in redundant-constraint warnings Ticket #18036 pointed out that we were reporting a redundant constraint when it really really wasn't. Turned out to be a buglet in the SkolemInfo for the relevant implication constraint. Easily fixed! - - - - - d5fae7da by Ömer Sinan Ağacan at 2020-04-20T14:39:28-04:00 Mark T12010 fragile on 32-bit - - - - - bca02fca by Adam Sandberg Ericsson at 2020-04-21T06:38:45-04:00 docs: drop note about not supporting shared libraries on unix systems [skip ci] - - - - - 6655f933 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Use ParserFlags in GHC.Runtime.Eval (#17957) Instead of passing `DynFlags` to functions such as `isStmt` and `hasImport` in `GHC.Runtime.Eval` we pass `ParserFlags`. It's a much simpler structure that can be created purely with `mkParserFlags'`. - - - - - 70be0fbc by Sylvain Henry at 2020-04-21T06:39:32-04:00 GHC.Runtime: avoid DynFlags (#17957) * add `getPlatform :: TcM Platform` helper * remove unused `DynFlags` parameter from `emptyPLS` - - - - - 35e43d48 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Avoid DynFlags in Ppr code (#17957) * replace `DynFlags` parameters with `SDocContext` parameters for a few Ppr related functions: `bufLeftRenderSDoc`, `printSDoc`, `printSDocLn`, `showSDocOneLine`. * remove the use of `pprCols :: DynFlags -> Int` in Outputable. We already have the information via `sdocLineLength :: SDocContext -> Int` - - - - - ce5c2999 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Avoid using sdocWithDynFlags (#17957) Remove one use of `sdocWithDynFlags` from `GHC.CmmToLlvm.llvmCodeGen'` and from `GHC.Driver.CodeOutput.profilingInitCode` - - - - - f2a98996 by Sylvain Henry at 2020-04-21T06:39:32-04:00 Avoid `sdocWithDynFlags` in `pprCLbl` (#17957) * add a `DynFlags` parameter to `pprCLbl` * put `maybe_underscore` and `pprAsmCLbl` in a `where` clause to avoid `DynFlags` parameters - - - - - 747093b7 by Sylvain Henry at 2020-04-21T06:39:32-04:00 CmmToAsm DynFlags refactoring (#17957) * Remove `DynFlags` parameter from `isDynLinkName`: `isDynLinkName` used to test the global `ExternalDynamicRefs` flag. Now we test it outside of `isDynLinkName` * Add new fields into `NCGConfig`: current unit id, sse/bmi versions, externalDynamicRefs, etc. * Replace many uses of `DynFlags` by `NCGConfig` * Moved `BMI/SSE` datatypes into `GHC.Platform` - - - - - ffd7eef2 by Takenobu Tani at 2020-04-22T23:09:50-04:00 stg-spec: Modify file paths according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * GHC/Stg/Syntax.hs <= stgSyn/StgSyn.hs * GHC/Types/Literal.hs <= basicTypes/Literal.hs * GHC/Types/CostCentre.hs <= profiling/CostCentre.hs This patch also updates old file path [2]: * utils/genapply/Main.hs <= utils/genapply/GenApply.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: commit 0cc4aad36f [skip ci] - - - - - e8a5d81b by Jonathan DK Gibbons at 2020-04-22T23:10:28-04:00 Refactor the `MatchResult` type in the desugarer This way, it does a better job of proving whether or not the fail operator is used. - - - - - dcb7fe5a by John Ericson at 2020-04-22T23:10:28-04:00 Remove panic in dsHandleMonadicFailure Rework dsHandleMonadicFailure to be correct by construction instead of using an unreachable panic. - - - - - cde23cd4 by John Ericson at 2020-04-22T23:10:28-04:00 Inline `adjustMatchResult` It is just `fmap` - - - - - 72cb6bcc by John Ericson at 2020-04-22T23:10:28-04:00 Generalize type of `matchCanFail` - - - - - 401f7bb3 by John Ericson at 2020-04-22T23:10:28-04:00 `MatchResult'` -> `MatchResult` Inline `MatchResult` alias accordingly. - - - - - 6c9fae23 by Alexis King at 2020-04-22T23:11:12-04:00 Mark DataCon wrappers CONLIKE Now that DataCon wrappers don’t inline until phase 0 (see commit b78cc64e923716ac0512c299f42d4d0012306c05), it’s important that case-of-known-constructor and RULE matching be able to see saturated applications of DataCon wrappers in unfoldings. Making them conlike is a natural way to do it, since they are, in fact, precisely the sort of thing the CONLIKE pragma exists to solve. Fixes #18012. This also bumps the version of the parsec submodule to incorporate a patch that avoids a metric increase on the haddock perf tests. The increase was not really a flaw in this patch, as parsec was implicitly relying on inlining heuristics. The patch to parsec just adds some INLINABLE pragmas, and we get a nice performance bump out of it (well beyond the performance we lost from this patch). Metric Decrease: T12234 WWRec haddock.Cabal haddock.base haddock.compiler - - - - - 48b8951e by Roland Senn at 2020-04-22T23:11:51-04:00 Fix tab-completion for :break (#17989) In tab-completion for the `:break` command, only those identifiers should be shown, that are accepted in the `:break` command. Hence these identifiers must be - defined in an interpreted module - top-level - currently in scope - listed in a `ModBreaks` value as a possible breakpoint. The identifiers my be qualified or unqualified. To get all possible top-level breakpoints for tab-completeion with the correct qualification do: 1. Build the list called `pifsBreaks` of all pairs of (Identifier, module-filename) from the `ModBreaks` values. Here all identifiers are unqualified. 2. Build the list called `pifInscope` of all pairs of (Identifiers, module-filename) with identifiers from the `GlobalRdrEnv`. Take only those identifiers that are in scope and have the correct prefix. Here the identifiers may be qualified. 3. From the `pifInscope` list seclect all pairs that can be found in the `pifsBreaks` list, by comparing only the unqualified part of the identifier. The remaining identifiers can be used for tab-completion. This ensures, that we show only identifiers, that can be used in a `:break` command. - - - - - 34a45ee6 by Peter Trommler at 2020-04-22T23:12:27-04:00 PPC NCG: Add DWARF constants and debug labels Fixes #11261 - - - - - ffde2348 by Simon Peyton Jones at 2020-04-22T23:13:06-04:00 Do eager instantation in terms This patch implements eager instantiation, a small but critical change to the type inference engine, #17173. The main change is this: When inferring types, always return an instantiated type (for now, deeply instantiated; in future shallowly instantiated) There is more discussion in https://www.tweag.io/posts/2020-04-02-lazy-eager-instantiation.html There is quite a bit of refactoring in this patch: * The ir_inst field of GHC.Tc.Utils.TcType.InferResultk has entirely gone. So tcInferInst and tcInferNoInst have collapsed into tcInfer. * Type inference of applications, via tcInferApp and tcInferAppHead, are substantially refactored, preparing the way for Quick Look impredicativity. * New pure function GHC.Tc.Gen.Expr.collectHsArgs and applyHsArgs are beatifully dual. We can see the zipper! * GHC.Tc.Gen.Expr.tcArgs is now much nicer; no longer needs to return a wrapper * In HsExpr, HsTypeApp now contains the the actual type argument, and is used in desugaring, rather than putting it in a mysterious wrapper. * I struggled a bit with good error reporting in Unify.matchActualFunTysPart. It's a little bit simpler than before, but still not great. Some smaller things * Rename tcPolyExpr --> tcCheckExpr tcMonoExpr --> tcLExpr * tcPatSig moves from GHC.Tc.Gen.HsType to GHC.Tc.Gen.Pat Metric Decrease: T9961 Reduction of 1.6% in comiler allocation on T9961, I think. - - - - - 6f84aca3 by Ben Gamari at 2020-04-22T23:13:43-04:00 rts: Ensure that sigaction structs are initialized I noticed these may have uninitialized fields when looking into #18037. The reporter says that zeroing them doesn't fix the MSAN failures they observe but zeroing them is the right thing to do regardless. - - - - - c29f0fa6 by Andreas Klebinger at 2020-04-22T23:14:21-04:00 Add "ddump-cmm-opt" as alias for "ddump-opt-cmm". - - - - - 4b4a8b60 by Ben Gamari at 2020-04-22T23:14:57-04:00 llvmGen: Remove -fast-llvm flag Issue #18076 drew my attention to the undocumented `-fast-llvm` flag for the LLVM code generator introduced in 22733532171330136d87533d523f565f2a4f102f. Speaking to Moritz about this, the motivation for this flag was to avoid potential incompatibilities between LLVM and the assembler/linker toolchain by making LLVM responsible for machine-code generation. Unfortunately, this cannot possibly work: the LLVM backend's mangler performs a number of transforms on the assembler generated by LLVM that are necessary for correctness. These are currently: * mangling Haskell functions' symbol types to be `object` instead of `function` on ELF platforms (necessary for tables-next-to-code) * mangling AVX instructions to ensure that we don't assume alignment (which LLVM otherwise does) * mangling Darwin's subsections-via-symbols directives Given that these are all necessary I don't believe that we can support `-fast-llvm`. Let's rather remove it. - - - - - 831b6642 by Moritz Angermann at 2020-04-22T23:15:33-04:00 Fix build warning; add more informative information to the linker; fix linker for empty sections - - - - - c409961a by Ryan Scott at 2020-04-22T23:16:12-04:00 Update commentary and slightly refactor GHC.Tc.Deriv.Infer There was some out-of-date commentary in `GHC.Tc.Deriv.Infer` that has been modernized. Along the way, I removed the `bad` constraints in `simplifyDeriv`, which did not serve any useful purpose (besides being printed in debugging output). Fixes #18073. - - - - - 125aa2b8 by Ömer Sinan Ağacan at 2020-04-22T23:16:51-04:00 Remove leftover comment in tcRnModule', redundant bind The code for the comment was moved in dc8c03b2a5c but the comment was forgotten. - - - - - 8ea37b01 by Sylvain Henry at 2020-04-22T23:17:34-04:00 RTS: workaround a Linux kernel bug in timerfd Reading a timerfd may return 0: https://lkml.org/lkml/2019/8/16/335. This is currently undocumented behavior and documentation "won't happen anytime soon" (https://lkml.org/lkml/2020/2/13/295). With this patch, we just ignore the result instead of crashing. It may fix #18033 but we can't be sure because we don't have enough information. See also this discussion about the kernel bug: https://github.com/Azure/sonic-swss-common/pull/302/files/1f070e7920c2e5d63316c0105bf4481e73d72dc9 - - - - - cd8409c2 by Ryan Scott at 2020-04-23T11:39:24-04:00 Create di_scoped_tvs for associated data family instances properly See `Note [Associated data family instances and di_scoped_tvs]` in `GHC.Tc.TyCl.Instance`, which explains all of the moving parts. Fixes #18055. - - - - - 339e8ece by Ben Gamari at 2020-04-23T11:40:02-04:00 hadrian/ghci: Allow arguments to be passed to GHCi Previously the arguments passed to hadrian/ghci were passed both to `hadrian` and GHCi. This is rather odd given that there are essentially not arguments in the intersection of the two. Let's just pass them to GHCi; this allows `hadrian/ghci -Werror`. - - - - - 5946c85a by Ben Gamari at 2020-04-23T11:40:38-04:00 testsuite: Don't attempt to read .std{err,out} files if they don't exist Simon reports that he was previously seeing framework failures due to an attempt to read the non-existing T13456.stderr. While I don't know exactly what this is due to, it does seem like a non-existing .std{out,err} file should be equivalent to an empty file. Teach the testsuite driver to treat it as such. - - - - - c42754d5 by John Ericson at 2020-04-23T18:32:43-04:00 Trees That Grow refactor for `ConPat` and `CoPat` - `ConPat{In,Out}` -> `ConPat` - `CoPat` -> `XPat (CoPat ..)` Note that `GHC.HS.*` still uses `HsWrap`, but only when `p ~ GhcTc`. After this change, moving the type family instances out of `GHC.HS.*` is sufficient to break the cycle. Add XCollectPat class to decide how binders are collected from XXPat based on the pass. Previously we did this with IsPass, but that doesn't work for Haddock's DocNameI, and the constraint doesn't express what actual distinction is being made. Perhaps a class for collecting binders more generally is in order, but we haven't attempted this yet. Pure refactor of code around ConPat - InPat/OutPat synonyms removed - rename several identifiers - redundant constraints removed - move extension field in ConPat to be first - make ConPat use record syntax more consistently Fix T6145 (ConPatIn became ConPat) Add comments from SPJ. Add comment about haddock's use of CollectPass. Updates haddock submodule. - - - - - 72da0c29 by mniip at 2020-04-23T18:33:21-04:00 Add :doc to GHC.Prim - - - - - 2c23e2e3 by mniip at 2020-04-23T18:33:21-04:00 Include docs for non-primop entries in primops.txt as well - - - - - 0ac29c88 by mniip at 2020-04-23T18:33:21-04:00 GHC.Prim docs: note and test - - - - - b0fbfc75 by John Ericson at 2020-04-24T12:07:14-04:00 Switch order on `GhcMake.IsBoot` In !1798 we were requested to replace many `Bool`s with this data type. But those bools had `False` meaning `NotBoot`, so the `Ord` instance would be flipped if we use this data-type as-is. Since the planned formally-`Bool` occurrences vastly outnumber the current occurrences, we figured it would be better to conform the `Ord` instance to how the `Bool` is used now, fixing any issues, rather than fix them currently with the bigger refactor later in !1798. That way, !1798 can be a "pure" refactor with no behavioral changes. - - - - - af332442 by Sylvain Henry at 2020-04-26T13:55:14-04:00 Modules: Utils and Data (#13009) Update Haddock submodule Metric Increase: haddock.compiler - - - - - cd4434c8 by Sylvain Henry at 2020-04-26T13:55:16-04:00 Fix misleading Ptr phantom type in SerializedCompact (#15653) - - - - - 22bf5c73 by Ömer Sinan Ağacan at 2020-04-26T13:55:22-04:00 Tweak includes in non-moving GC headers We don't use hash tables in non-moving GC so remove the includes. This breaks Compact.c as existing includes no longer include Hash.h, so include Hash.h explicitly in Compact.c. - - - - - 99823ed2 by Sylvain Henry at 2020-04-27T20:24:46-04:00 TH: fix Show/Eq/Ord instances for Bytes (#16457) We shouldn't compare pointer values but the actual bytes. - - - - - c62271a2 by Alp Mestanogullari at 2020-04-27T20:25:33-04:00 hadrian: always capture both stdout and stderr when running a builder fails The idea being that when a builder('s command) fails, we quite likely want to have all the information available to figure out why. Depending on the builder _and_ the particular problem, the useful bits of information can be printed on stdout or stderr. We accomplish this by defining a simple wrapper for Shake's `cmd` function, that just _always_ captures both streams in case the command returns a non-zero exit code, and by using this wrapper everywhere in `hadrian/src/Builder.hs`. Fixes #18089. - - - - - 4b9764db by Ryan Scott at 2020-04-28T15:40:04-04:00 Define a Quote IO instance Fixes #18103. - - - - - 518a63d4 by Ryan Scott at 2020-04-28T15:40:42-04:00 Make boxed 1-tuples have known keys Unlike other tuples, which use special syntax and are "known" by way of a special `isBuiltInOcc_maybe` code path, boxed 1-tuples do not use special syntax. Therefore, in order to make sure that the internals of GHC are aware of the `data Unit a = Unit a` definition in `GHC.Tuple`, we give `Unit` known keys. For the full details, see `Note [One-tuples] (Wrinkle: Make boxed one-tuple names have known keys)` in `GHC.Builtin.Types`. Fixes #18097. - - - - - 2cfc4ab9 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Document backpack fields in DynFlags - - - - - 10a2ba90 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Refactor UnitInfo * Rename InstalledPackageInfo into GenericUnitInfo The name InstalledPackageInfo is only kept for alleged backward compatibility reason in Cabal. ghc-boot has its own stripped down copy of this datatype but it doesn't need to keep the name. Internally we already use type aliases (UnitInfo in GHC, PackageCacheFormat in ghc-pkg). * Rename UnitInfo fields: add "unit" prefix and fix misleading names * Add comments on every UnitInfo field * Rename SourcePackageId into PackageId "Package" already indicates that it's a "source package". Installed package components are called units. Update Haddock submodule - - - - - 69562e34 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Remove unused `emptyGenericUnitInfo` - - - - - 9e2c8e0e by Sylvain Henry at 2020-04-30T01:56:56-04:00 Refactor UnitInfo load/store from databases Converting between UnitInfo stored in package databases and UnitInfo as they are used in ghc-pkg and ghc was done in a very convoluted way (via BinaryStringRep and DbUnitModuleRep type classes using fun deps, etc.). It was difficult to understand and even more to modify (I wanted to try to use a GADT for UnitId but fun deps got in the way). The new code uses much more straightforward functions to convert between the different representations. Much simpler. - - - - - ea717aa4 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Factorize mungePackagePaths code This patch factorizes the duplicated code used in ghc-pkg and in GHC to munge package paths/urls. It also fixes haddock-html munging in GHC (allowed to be either a file or a url) to mimic ghc-pkg behavior. - - - - - 10d15f1e by Sylvain Henry at 2020-04-30T01:56:56-04:00 Refactoring unit management code Over the years the unit management code has been modified a lot to keep up with changes in Cabal (e.g. support for several library components in the same package), to integrate BackPack, etc. I found it very hard to understand as the terminology wasn't consistent, was referring to past concepts, etc. The terminology is now explained as clearly as I could in the Note "About Units" and the code is refactored to reflect it. ------------------- Many names were misleading: UnitId is not an Id but could be a virtual unit (an indefinite one instantiated on the fly), IndefUnitId constructor may contain a definite instantiated unit, etc. * Rename IndefUnitId into InstantiatedUnit * Rename IndefModule into InstantiatedModule * Rename UnitId type into Unit * Rename IndefiniteUnitId constructor into VirtUnit * Rename DefiniteUnitId constructor into RealUnit * Rename packageConfigId into mkUnit * Rename getPackageDetails into unsafeGetUnitInfo * Rename InstalledUnitId into UnitId Remove references to misleading ComponentId: a ComponentId is just an indefinite unit-id to be instantiated. * Rename ComponentId into IndefUnitId * Rename ComponentDetails into UnitPprInfo * Fix display of UnitPprInfo with empty version: this is now used for units dynamically generated by BackPack Generalize several types (Module, Unit, etc.) so that they can be used with different unit identifier types: UnitKey, UnitId, Unit, etc. * GenModule: Module, InstantiatedModule and InstalledModule are now instances of this type * Generalize DefUnitId, IndefUnitId, Unit, InstantiatedUnit, PackageDatabase Replace BackPack fake "hole" UnitId by a proper HoleUnit constructor. Add basic support for UnitKey. They should be used more in the future to avoid mixing them up with UnitId as we do now. Add many comments. Update Haddock submodule - - - - - 8bfb0219 by Sylvain Henry at 2020-04-30T01:56:56-04:00 Unit: split and rename modules Introduce GHC.Unit.* hierarchy for everything concerning units, packages and modules. Update Haddock submodule - - - - - 71484b09 by Alexis King at 2020-04-30T01:57:35-04:00 Allow block arguments in arrow control operators Arrow control operators have their own entries in the grammar, so they did not cooperate with BlockArguments. This was just a minor oversight, so this patch adjusts the grammar to add the desired behavior. fixes #18050 - - - - - a48cd2a0 by Alexis King at 2020-04-30T01:57:35-04:00 Allow LambdaCase to be used as a command in proc notation - - - - - f4d3773c by Alexis King at 2020-04-30T01:57:35-04:00 Document BlockArguments/LambdaCase support in arrow notation - - - - - 5bdfdd13 by Simon Peyton Jones at 2020-04-30T01:58:15-04:00 Add tests for #17873 - - - - - 19b701c2 by Simon Peyton Jones at 2020-04-30T07:30:13-04:00 Mark rule args as non-tail-called This was just an omission...b I'd failed to call markAllNonTailCall on rule args. I think this bug has been here a long time, but it's quite hard to trigger. Fixes #18098 - - - - - 014ef4a3 by Matthew Pickering at 2020-04-30T07:30:50-04:00 Hadrian: Improve tool-args command to support more components There is a new command to hadrian, tool:path/to/file.hs, which returns the options needed to compile that file in GHCi. This is now used in the ghci script with argument `ghc/Main.hs` but its main purpose is to support the new multi-component branch of ghcide. - - - - - 2aa67611 by Ben Gamari at 2020-04-30T21:34:44-04:00 nonmoving: Clear bitmap after initializing block size Previously nonmovingInitSegment would clear the bitmap before initializing the segment's block size. This is broken since nonmovingClearBitmap looks at the segment's block size to determine how much bitmap to clear. - - - - - 54dad3cf by Ben Gamari at 2020-04-30T21:34:44-04:00 nonmoving: Explicitly memoize block count A profile cast doubt on whether the compiler hoisted the bound out the loop as I would have expected here. It turns out it did but nevertheless it seems clearer to just do this manually. - - - - - 99ff8145 by Ben Gamari at 2020-04-30T21:34:44-04:00 nonmoving: Eagerly flush all capabilities' update remembered sets (cherry picked from commit 2fa79119570b358a4db61446396889b8260d7957) - - - - - 05b0a9fd by Ömer Sinan Ağacan at 2020-04-30T21:35:24-04:00 Remove OneShotInfo field of LFReEntrant, document OneShotInfo The field is only used in withNewTickyCounterFun and it's easier to directly pass a parameter for one-shot info to withNewTickyCounterFun instead of passing it via LFReEntrant. This also makes !2842 simpler. Other changes: - New Note (by SPJ) [OneShotInfo overview] added. - Arity argument of thunkCode removed as it's always 0. - - - - - a43620c6 by Ömer Sinan Ağacan at 2020-04-30T21:35:24-04:00 GHC.StgToCmm.Ticky: remove a few unused stuff - - - - - 780de9e1 by Sylvain Henry at 2020-05-01T10:37:39-04:00 Use platform in Iface Binary - - - - - f8386c7b by Sylvain Henry at 2020-05-01T10:37:39-04:00 Refactor PprDebug handling If `-dppr-debug` is set, then PprUser and PprDump styles are silently replaced with PprDebug style. This was done in `mkUserStyle` and `mkDumpStyle` smart constructors. As a consequence they needed a DynFlags parameter. Now we keep the original PprUser and PprDump styles until they are used to create an `SDocContext`. I.e. the substitution is only performed in `initSDocContext`. - - - - - b3df9e78 by Sylvain Henry at 2020-05-01T10:37:39-04:00 Remove PprStyle param of logging actions Use `withPprStyle` instead to apply a specific style to a SDoc. - - - - - de9fc995 by Sylvain Henry at 2020-05-01T10:37:39-04:00 Fully remove PprDebug PprDebug was a pain to deal with consistently as it is implied by `-dppr-debug` but it isn't really a PprStyle. We remove it completely and query the appropriate SDoc flag instead (`sdocPprDebug`) via helpers (`getPprDebug` and its friends). - - - - - 8b51fcbd by Sebastian Graf at 2020-05-01T10:38:16-04:00 PmCheck: Only call checkSingle if we would report warnings - - - - - fd7ea0fe by Sebastian Graf at 2020-05-01T10:38:16-04:00 PmCheck: Pick up `EvVar`s bound in `HsWrapper`s for long-distance info `HsWrapper`s introduce evidence bindings through `WpEvLam` which the pattern-match coverage checker should be made aware of. Failing to do so caused #18049, where the resulting impreciseness of imcompleteness warnings seemingly contradicted with `-Winaccessible-code`. The solution is simple: Collect all the evidence binders of an `HsWrapper` and add it to the ambient `Deltas` before desugaring the wrapped expression. But that means we pick up many more evidence bindings, even when they wrap around code without a single pattern match to check! That regressed `T3064` by over 300%, so now we are adding long-distance info lazily through judicious use of `unsafeInterleaveIO`. Fixes #18049. - - - - - 7bfe9ac5 by Ben Gamari at 2020-05-03T04:41:33-04:00 rts: Enable tracing of nonmoving heap census with -ln Previously this was not easily available to the user. Fix this. Non-moving collection lifecycle events are now reported with -lg. - - - - - c560dd07 by Ben Gamari at 2020-05-03T04:41:33-04:00 users guide: Move eventlog documentation users guide - - - - - 02543d5e by Ben Gamari at 2020-05-03T04:41:33-04:00 users guide: Add documentation for non-moving GC events - - - - - b465dd45 by Alexis King at 2020-05-03T04:42:12-04:00 Flatten nested casts in the simple optimizer Normally, we aren’t supposed to generated any nested casts, since mkCast takes care to flatten them, but the simple optimizer didn’t use mkCast, so they could show up after inlining. This isn’t really a problem, since the simplifier will clean them up immediately anyway, but it can clutter the -ddump-ds output, and it’s an extremely easy fix. closes #18112 - - - - - 8bdc03d6 by Simon Peyton Jones at 2020-05-04T01:56:59-04:00 Don't return a panic in tcNestedSplice In GHC.Tc.Gen.Splice.tcNestedSplice we were returning a typechecked expression of "panic". That is usually OK, because the result is discarded. But it happens that tcApp now looks at the typechecked expression, trivially, to ask if it is tagToEnum. So being bottom is bad. Moreover a debug-trace might print it out. So better to return a civilised expression, even though it is usually discarded. - - - - - 0bf640b1 by Baldur Blöndal at 2020-05-04T01:57:36-04:00 Don't require parentheses around via type (`-XDerivingVia'). Fixes #18130". - - - - - 30272412 by Artem Pelenitsyn at 2020-05-04T13:19:59-04:00 Remove custom ExceptionMonad class (#18075) (updating haddock submodule accordingly) - - - - - b9f7c08f by jneira at 2020-05-04T13:20:37-04:00 Remove unused hs-boot file - - - - - 1d8f80cd by Sylvain Henry at 2020-05-05T03:22:46-04:00 Remove references to -package-key * remove references to `-package-key` which has been removed in 2016 (240ddd7c39536776e955e881d709bbb039b48513) * remove support for `-this-package-key` which has been deprecated at the same time - - - - - 7bc3a65b by Sylvain Henry at 2020-05-05T03:23:31-04:00 Remove SpecConstrAnnotation (#13681) This has been deprecated since 2013. Use GHC.Types.SPEC instead. Make GHC.Exts "not-home" for haddock Metric Decrease: haddock.base - - - - - 3c862f63 by DenisFrezzato at 2020-05-05T03:24:15-04:00 Fix Haskell98 short description in documentation - - - - - 2420c555 by Ryan Scott at 2020-05-05T03:24:53-04:00 Add regression tests for #16244, #16245, #16758 Commit e3c374cc5bd7eb49649b9f507f9f7740697e3f70 ended up fixing quite a few bugs: * This commit fixes #16244 completely. A regression test has been added. * This commit fixes one program from #16245. (The program in https://gitlab.haskell.org/ghc/ghc/issues/16245#note_211369 still panics, and the program in https://gitlab.haskell.org/ghc/ghc/issues/16245#note_211400 still loops infinitely.) A regression test has been added for this program. * This commit fixes #16758. Accordingly, this patch removes the `expect_broken` label from the `T16758` test case, moves it from `should_compile` to `should_fail` (as it should produce an error message), and checks in the expected stderr. - - - - - 40c71c2c by Sylvain Henry at 2020-05-05T03:25:31-04:00 Fix colorized error messages (#18128) In b3df9e780fb2f5658412c644849cd0f1e6f50331 I broke colorized messages by using "dump" style instead of "user" style. This commits fixes it. - - - - - 7ab6ab09 by Richard Eisenberg at 2020-05-06T04:39:32-04:00 Refactor hole constraints. Previously, holes (both expression holes / out of scope variables and partial-type-signature wildcards) were emitted as *constraints* via the CHoleCan constructor. While this worked fine for error reporting, there was a fair amount of faff in keeping these constraints in line. In particular, and unlike other constraints, we could never change a CHoleCan to become CNonCanonical. In addition: * the "predicate" of a CHoleCan constraint was really the type of the hole, which is not a predicate at all * type-level holes (partial type signature wildcards) carried evidence, which was never used * tcNormalise (used in the pattern-match checker) had to create a hole constraint just to extract it again; it was quite messy The new approach is to record holes directly in WantedConstraints. It flows much more nicely now. Along the way, I did some cleaning up of commentary in GHC.Tc.Errors.Hole, which I had a hard time understanding. This was instigated by a future patch that will refactor the way predicates are handled. The fact that CHoleCan's "predicate" wasn't really a predicate is incompatible with that future patch. No test case, because this is meant to be purely internal. It turns out that this change improves the performance of the pattern-match checker, likely because fewer constraints are sloshing about in tcNormalise. I have not investigated deeply, but an improvement is not a surprise here: ------------------------- Metric Decrease: PmSeriesG ------------------------- - - - - - 420b957d by Ben Gamari at 2020-05-06T04:40:08-04:00 rts: Zero block flags with -DZ Block flags are very useful for determining the state of a block. However, some block allocator users don't touch them, leading to misleading values. Ensure that we zero then when zero-on-gc is set. This is safe and makes the flags more useful during debugging. - - - - - 740b3b8d by Ben Gamari at 2020-05-06T04:40:08-04:00 nonmoving: Fix incorrect failed_to_evac value during deadlock gc Previously we would incorrectly set the failed_to_evac flag if we evacuated a value due to a deadlock GC. This would cause us to mark more things as dirty than strictly necessary. It also turned up a nasty but which I will fix next. - - - - - b2d72c75 by Ben Gamari at 2020-05-06T04:40:08-04:00 nonmoving: Fix handling of dirty objects Previously we (incorrectly) relied on failed_to_evac to be "precise". That is, we expected it to only be true if *all* of an object's fields lived outside of the non-moving heap. However, does not match the behavior of failed_to_evac, which is true if *any* of the object's fields weren't promoted (meaning that some others *may* live in the non-moving heap). This is problematic as we skip the non-moving write barrier for dirty objects (which we can only safely do if *all* fields point outside of the non-moving heap). Clearly this arises due to a fundamental difference in the behavior expected of failed_to_evac in the moving and non-moving collector. e.g., in the moving collector it is always safe to conservatively say failed_to_evac=true whereas in the non-moving collector the safe value is false. This issue went unnoticed as I never wrote down the dirtiness invariant enforced by the non-moving collector. We now define this invariant as An object being marked as dirty implies that all of its fields are on the mark queue (or, equivalently, update remembered set). To maintain this invariant we teach nonmovingScavengeOne to push the fields of objects which we fail to evacuate to the update remembered set. This is a simple and reasonably cheap solution and avoids the complexity and fragility that other, more strict alternative invariants would require. All of this is described in a new Note, Note [Dirty flags in the non-moving collector] in NonMoving.c. - - - - - 9f3e6884 by Zubin Duggal at 2020-05-06T04:41:08-04:00 Allow atomic update of NameCache in readHieFile The situation arises in ghcide where multiple different threads may need to update the name cache, therefore with the older interface it could happen that you start reading a hie file with name cache A and produce name cache A + B, but another thread in the meantime updated the namecache to A + C. Therefore if you write the new namecache you will lose the A' updates from the second thread. Updates haddock submodule - - - - - edec6a6c by Ryan Scott at 2020-05-06T04:41:57-04:00 Make isTauTy detect higher-rank contexts Previously, `isTauTy` would only detect higher-rank `forall`s, not higher-rank contexts, which led to some minor bugs observed in #18127. Easily fixed by adding a case for `(FunTy InvisArg _ _)`. Fixes #18127. - - - - - a95e7fe0 by Ömer Sinan Ağacan at 2020-05-06T04:42:39-04:00 ELF linker: increment curSymbol after filling in fields of current entry The bug was introduced in a8b7cef4d45 which added a field to the `symbols` array elements and then updated this code incorrectly: - oc->symbols[curSymbol++] = nm; + oc->symbols[curSymbol++].name = nm; + oc->symbols[curSymbol].addr = symbol->addr; - - - - - cab1871a by Sylvain Henry at 2020-05-06T04:43:21-04:00 Move LeadingUnderscore into Platform (#17957) Avoid direct use of DynFlags to know if symbols must be prefixed by an underscore. - - - - - 94e7c563 by Sylvain Henry at 2020-05-06T04:43:21-04:00 Don't use DynFlags in showLinkerState (#17957) - - - - - 9afd9251 by Ryan Scott at 2020-05-06T04:43:58-04:00 Refactoring: Use bindSigTyVarsFV in rnMethodBinds `rnMethodBinds` was explicitly using `xoptM` to determine if `ScopedTypeVariables` is enabled before bringing type variables bound by the class/instance header into scope. However, this `xoptM` logic is already performed by the `bindSigTyVarsFV` function. This patch uses `bindSigTyVarsFV` in `rnMethodBinds` to reduce the number of places where we need to consult if `ScopedTypeVariables` is on. This is purely refactoring, and there should be no user-visible change in behavior. - - - - - 6f6d72b2 by Brian Foley at 2020-05-08T15:29:25-04:00 Remove further dead code found by a simple Python script. Avoid removing some functions that are part of an API even though they're not used in-tree at the moment. - - - - - 78bf8bf9 by Julien Debon at 2020-05-08T15:29:28-04:00 Add doc examples for Bifoldable See #17929 - - - - - 66f0a847 by Julien Debon at 2020-05-08T15:29:29-04:00 doc (Bitraversable): Add examples to Bitraversable * Add examples to Data.Bitraversable * Fix formatting for (,) in Bitraversable and Bifoldable * Fix mistake on bimapAccumR documentation See #17929 - - - - - 9749fe12 by Baldur Blöndal at 2020-05-08T15:29:32-04:00 Specify kind variables for inferred kinds in base. - - - - - 4e9aef9e by John Ericson at 2020-05-08T15:29:36-04:00 HsSigWcTypeScoping: Pull in documentation from stray location - - - - - f4d5c6df by John Ericson at 2020-05-08T15:29:36-04:00 Rename local `real_fvs` to `implicit_vs` It doesn't make sense to call the "free" variables we are about to implicitly bind the real ones. - - - - - 20570b4b by John Ericson at 2020-05-08T15:29:36-04:00 A few tiny style nits with renaming - Use case rather than guards that repeatedly scrutenize same thing. - No need for view pattern when `L` is fine. - Use type synnonym to convey the intent like elsewhere. - - - - - 09ac8de5 by John Ericson at 2020-05-08T15:29:36-04:00 Add `forAllOrNothing` function with note - - - - - bb35c0e5 by Joseph C. Sible at 2020-05-08T15:29:40-04:00 Document lawlessness of Ap's Num instance - - - - - cdd229ff by Joseph C. Sible at 2020-05-08T15:29:40-04:00 Apply suggestion to libraries/base/Data/Monoid.hs - - - - - 926d2aab by Joseph C. Sible at 2020-05-08T15:29:40-04:00 Apply more suggestions from Simon Jakobi - - - - - 7a763cff by Adam Gundry at 2020-05-08T15:29:41-04:00 Reject all duplicate declarations involving DuplicateRecordFields (fixes #17965) This fixes a bug that resulted in some programs being accepted that used the same identifier as a field label and another declaration, depending on the order they appeared in the source code. - - - - - 88e3c815 by Simon Peyton Jones at 2020-05-08T15:29:41-04:00 Fix specialisation for DFuns When specialising a DFun we must take care to saturate the unfolding. See Note [Specialising DFuns] in Specialise. Fixes #18120 - - - - - 86c77b36 by Greg Steuck at 2020-05-08T15:29:45-04:00 Remove unused SEGMENT_PROT_RWX It's been unused for a year and is problematic on any OS which requires W^X for security. - - - - - 9d97f4b5 by nineonine at 2020-05-08T15:30:03-04:00 Add test for #16167 - - - - - aa318338 by Ryan Scott at 2020-05-08T15:30:04-04:00 Bump exceptions submodule so that dist-boot is .gitignore'd `exceptions` is a stage-0 boot library as of commit 30272412fa437ab8e7a8035db94a278e10513413, which means that building `exceptions` in a GHC tree will generate a `dist-boot` directory. However, this directory was not specified in `exceptions`' `.gitignore` file, which causes it to dirty up the current `git` working directory. Accordingly, this bumps the `exceptions` submodule to commit ghc/packages/exceptions at 23c0b8a50d7592af37ca09beeec16b93080df98f, which adds `dist-boot` to the `.gitignore` file. - - - - - ea86360f by Ömer Sinan Ağacan at 2020-05-08T15:30:30-04:00 Linker.c: initialize n_symbols of ObjectCode with other fields - - - - - 951c1fb0 by Sylvain Henry at 2020-05-09T21:46:38-04:00 Fix unboxed-sums GC ptr-slot rubbish value (#17791) This patch allows boot libraries to use unboxed sums without implicitly depending on `base` package because of `absentSumFieldError`. See updated Note [aBSENT_SUM_FIELD_ERROR_ID] in GHC.Core.Make - - - - - b352d63c by Ben Gamari at 2020-05-09T21:47:14-04:00 rts: Make non-existent linker search path merely a warning As noted in #18105, previously this resulted in a rather intrusive error message. This is in contrast to the general expectation that search paths are merely places to look, not places that must exist. Fixes #18105. - - - - - cf4f1e2f by Ben Gamari at 2020-05-13T02:02:33-04:00 rts/CNF: Fix fixup comparison function Previously we would implicitly convert the difference between two words to an int, resulting in an integer overflow on 64-bit machines. Fixes #16992 - - - - - a03da9bf by Ömer Sinan Ağacan at 2020-05-13T02:03:16-04:00 Pack some of IdInfo fields into a bit field This reduces residency of compiler quite a bit on some programs. Example stats when building T10370: Before: 2,871,242,832 bytes allocated in the heap 4,693,328,008 bytes copied during GC 33,941,448 bytes maximum residency (276 sample(s)) 375,976 bytes maximum slop 83 MiB total memory in use (0 MB lost due to fragmentation) After: 2,858,897,344 bytes allocated in the heap 4,629,255,440 bytes copied during GC 32,616,624 bytes maximum residency (278 sample(s)) 314,400 bytes maximum slop 80 MiB total memory in use (0 MB lost due to fragmentation) So -3.9% residency, -1.3% bytes copied and -0.4% allocations. Fixes #17497 Metric Decrease: T9233 T9675 - - - - - 670c3e5c by Ben Gamari at 2020-05-13T02:03:54-04:00 get-win32-tarballs: Fix base URL Revert a change previously made for testing purposes. - - - - - 8ad8dc41 by Ben Gamari at 2020-05-13T02:03:54-04:00 get-win32-tarballs: Improve diagnostics output - - - - - 8c0740b7 by Simon Jakobi at 2020-05-13T02:04:33-04:00 docs: Add examples for Data.Semigroup.Arg{Min,Max} Context: #17153 - - - - - cb22348f by Ben Gamari at 2020-05-13T02:05:11-04:00 Add few cleanups of the CAF logic Give the NameSet of non-CAFfy names a proper newtype to distinguish it from all of the other NameSets floating about. - - - - - 90e38b81 by Emeka Nkurumeh at 2020-05-13T02:05:51-04:00 fix printf warning when using with ghc with clang on mingw - - - - - 86d8ac22 by Sebastian Graf at 2020-05-13T02:06:29-04:00 CprAnal: Don't attach CPR sigs to expandable bindings (#18154) Instead, look through expandable unfoldings in `cprTransform`. See the new Note [CPR for expandable unfoldings]: ``` Long static data structures (whether top-level or not) like xs = x1 : xs1 xs1 = x2 : xs2 xs2 = x3 : xs3 should not get CPR signatures, because they * Never get WW'd, so their CPR signature should be irrelevant after analysis (in fact the signature might even be harmful for that reason) * Would need to be inlined/expanded to see their constructed product * Recording CPR on them blows up interface file sizes and is redundant with their unfolding. In case of Nested CPR, this blow-up can be quadratic! But we can't just stop giving DataCon application bindings the CPR property, for example fac 0 = 1 fac n = n * fac (n-1) fac certainly has the CPR property and should be WW'd! But FloatOut will transform the first clause to lvl = 1 fac 0 = lvl If lvl doesn't have the CPR property, fac won't either. But lvl doesn't have a CPR signature to extrapolate into a CPR transformer ('cprTransform'). So instead we keep on cprAnal'ing through *expandable* unfoldings for these arity 0 bindings via 'cprExpandUnfolding_maybe'. In practice, GHC generates a lot of (nested) TyCon and KindRep bindings, one for each data declaration. It's wasteful to attach CPR signatures to each of them (and intractable in case of Nested CPR). ``` Fixes #18154. - - - - - e34bf656 by Ben Gamari at 2020-05-13T02:07:08-04:00 users-guide: Add discussion of shared object naming Fixes #18074. - - - - - 5d0f2445 by Ben Gamari at 2020-05-13T02:07:47-04:00 testsuite: Print sign of performance changes Executes the minor formatting change in the tabulated performance changes suggested in #18135. - - - - - 9e4b981f by Ben Gamari at 2020-05-13T02:08:24-04:00 testsuite: Add testcase for #18129 - - - - - 266310c3 by Ivan-Yudin at 2020-05-13T02:09:03-04:00 doc: Reformulate the opening paragraph of Ch. 4 in User's guide Removes mentioning of Hugs (it is not helpful for new users anymore). Changes the wording for the rest of the paragraph. Fixes #18132. - - - - - 55e35c0b by Baldur Blöndal at 2020-05-13T20:02:48-04:00 Predicate, Equivalence derive via `.. -> a -> All' - - - - - d7e0b57f by Alp Mestanogullari at 2020-05-13T20:03:30-04:00 hadrian: add a --freeze2 option to freeze stage 1 and 2 - - - - - d880d6b2 by Artem Pelenitsyn at 2020-05-13T20:04:11-04:00 Don't reload environment files on every setSessionDynFlags Makes `interpretPackageEnv` (which loads envirinment files) a part of `parseDynamicFlags` (parsing command-line arguments, which is typically done once) instead of `setSessionDynFlags` (which is typically called several times). Making several (transitive) calls to `interpretPackageEnv`, as before, caused #18125 #16318, which should be fixed now. - - - - - 102cfd67 by Ryan Scott at 2020-05-13T20:04:46-04:00 Factor out HsPatSigType for pat sigs/RULE term sigs (#16762) This implements chunks (2) and (3) of https://gitlab.haskell.org/ghc/ghc/issues/16762#note_270170. Namely, it introduces a dedicated `HsPatSigType` AST type, which represents the types that can appear in pattern signatures and term-level `RULE` binders. Previously, these were represented with `LHsSigWcType`. Although `LHsSigWcType` is isomorphic to `HsPatSigType`, the intended semantics of the two types are slightly different, as evidenced by the fact that they have different code paths in the renamer and typechecker. See also the new `Note [Pattern signature binders and scoping]` in `GHC.Hs.Types`. - - - - - b17574f7 by Hécate at 2020-05-13T20:05:28-04:00 fix(documentation): Fix the RST links to GHC.Prim - - - - - df021fb1 by Baldur Blöndal at 2020-05-13T20:06:06-04:00 Document (->) using inferred quantification for its runtime representations. Fixes #18142. - - - - - 1a93ea57 by Takenobu Tani at 2020-05-13T20:06:54-04:00 Tweak man page for ghc command This commit updates the ghc command's man page as followings: * Enable `man_show_urls` to show URL addresses in the `DESCRIPTION` section of ghc.rst, because sphinx currently removes hyperlinks for man pages. * Add a `SEE ALSO` section to point to the GHC homepage - - - - - a951e1ba by Takenobu Tani at 2020-05-13T20:07:37-04:00 GHCi: Add link to the user's guide in help message This commit adds a link to the user's guide in ghci's `:help` message. Newcomers could easily reach to details of ghci. - - - - - 404581ea by Jeff Happily at 2020-05-13T20:08:15-04:00 Handle single unused import - - - - - 1c999e5d by Ben Gamari at 2020-05-13T20:09:07-04:00 Ensure that printMinimalImports closes handle Fixes #18166. - - - - - c9f5a8f4 by Ben Gamari at 2020-05-13T20:09:51-04:00 hadrian: Tell testsuite driver about LLVM availability This reflects the logic present in the Make build system into Hadrian. Fixes #18167. - - - - - c05c0659 by Simon Jakobi at 2020-05-14T03:31:21-04:00 Improve some folds over Uniq[D]FM * Replace some non-deterministic lazy folds with strict folds. * Replace some O(n log n) folds in deterministic order with O(n) non-deterministic folds. * Replace some folds with set-operations on the underlying IntMaps. This reduces max residency when compiling `nofib/spectral/simple/Main.hs` with -O0 by about 1%. Maximum residency when compiling Cabal also seems reduced on the order of 3-9%. - - - - - 477f13bb by Simon Jakobi at 2020-05-14T03:31:58-04:00 Use Data.IntMap.disjoint Data.IntMap gained a dedicated `disjoint` function in containers-0.6.2.1. This patch applies this function where appropriate in hopes of modest compiler performance improvements. Closes #16806. - - - - - e9c0110c by Ben Gamari at 2020-05-14T12:25:53-04:00 IdInfo: Add reference to bitfield-packing ticket - - - - - 9bd20e83 by Sebastian Graf at 2020-05-15T10:42:09-04:00 DmdAnal: Improve handling of precise exceptions This patch does two things: Fix possible unsoundness in what was called the "IO hack" and implement part 2.1 of the "fixing precise exceptions" plan in https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions, which, in combination with !2956, supersedes !3014 and !2525. **IO hack** The "IO hack" (which is a fallback to preserve precise exceptions semantics and thus soundness, rather than some smart thing that increases precision) is called `exprMayThrowPreciseException` now. I came up with two testcases exemplifying possible unsoundness (if twisted enough) in the old approach: - `T13380d`: Demonstrating unsoundness of the "IO hack" when resorting to manual state token threading and direct use of primops. More details below. - `T13380e`: Demonstrating unsoundness of the "IO hack" when we have Nested CPR. Not currently relevant, as we don't have Nested CPR yet. - `T13380f`: Demonstrating unsoundness of the "IO hack" for safe FFI calls. Basically, the IO hack assumed that precise exceptions can only be thrown from a case scrutinee of type `(# State# RealWorld, _ #)`. I couldn't come up with a program using the `IO` abstraction that violates this assumption. But it's easy to do so via manual state token threading and direct use of primops, see `T13380d`. Also similar code might be generated by Nested CPR in the (hopefully not too) distant future, see `T13380e`. Hence, we now have a more careful test in `forcesRealWorld` that passes `T13380{d,e}` (and will hopefully be robust to Nested CPR). **Precise exceptions** In #13380 and #17676 we saw that we didn't preserve precise exception semantics in demand analysis. We fixed that with minimal changes in !2956, but that was terribly unprincipled. That unprincipledness resulted in a loss of precision, which is tracked by these new test cases: - `T13380b`: Regression in dead code elimination, because !2956 was too syntactic about `raiseIO#` - `T13380c`: No need to apply the "IO hack" when the IO action may not throw a precise exception (and the existing IO hack doesn't detect that) Fixing both issues in !3014 turned out to be too complicated and had the potential to regress in the future. Hence we decided to only fix `T13380b` and augment the `Divergence` lattice with a new middle-layer element, `ExnOrDiv`, which means either `Diverges` (, throws an imprecise exception) or throws a *precise* exception. See the wiki page on Step 2.1 for more implementational details: https://gitlab.haskell.org/ghc/ghc/wikis/fixing-precise-exceptions#dead-code-elimination-for-raiseio-with-isdeadenddiv-introducing-exnordiv-step-21 - - - - - 568d7279 by Ben Gamari at 2020-05-15T10:42:46-04:00 GHC.Cmm.Opt: Handle MO_XX_Conv This MachOp was introduced by 2c959a1894311e59cd2fd469c1967491c1e488f3 but a wildcard match in cmmMachOpFoldM hid the fact that it wasn't handled. Ideally we would eliminate the match but this appears to be a larger task. Fixes #18141. - - - - - 5bcf8606 by Ryan Scott at 2020-05-17T08:46:38-04:00 Remove duplicate Note [When to print foralls] in GHC.Core.TyCo.Ppr There are two different Notes named `[When to print foralls]`. The most up-to-date one is in `GHC.Iface.Type`, but there is a second one in `GHC.Core.TyCo.Ppr`. The latter is less up-to-date, as it was written before GHC switched over to using ifaces to pretty-print types. I decided to just remove the latter and replace it with a reference to the former. [ci skip] - - - - - 55f0e783 by Fumiaki Kinoshita at 2020-05-21T12:10:44-04:00 base: Add Generic instances to various datatypes under GHC.* * GHC.Fingerprint.Types: Fingerprint * GHC.RTS.Flags: GiveGCStats, GCFlags, ConcFlags, DebugFlags, CCFlags, DoHeapProfile, ProfFlags, DoTrace, TraceFlags, TickyFlags, ParFlags and RTSFlags * GHC.Stats: RTSStats and GCStats * GHC.ByteOrder: ByteOrder * GHC.Unicode: GeneralCategory * GHC.Stack.Types: SrcLoc Metric Increase: haddock.base - - - - - a9311cd5 by Gert-Jan Bottu at 2020-05-21T12:11:31-04:00 Explicit Specificity Implementation for Ticket #16393. Explicit specificity allows users to manually create inferred type variables, by marking them with braces. This way, the user determines which variables can be instantiated through visible type application. The additional syntax is included in the parser, allowing users to write braces in type variable binders (type signatures, data constructors etc). This information is passed along through the renamer and verified in the type checker. The AST for type variable binders, data constructors, pattern synonyms, partial signatures and Template Haskell has been updated to include the specificity of type variables. Minor notes: - Bumps haddock submodule - Disables pattern match checking in GHC.Iface.Type with GHC 8.8 - - - - - 24e61aad by Ben Price at 2020-05-21T12:12:17-04:00 Lint should say when it is checking a rule It is rather confusing that when lint finds an error in a rule attached to a binder, it reports the error as in the RHS, not the rule: ... In the RHS of foo We add a clarifying line: ... In the RHS of foo In a rule attached to foo The implication that the rule lives inside the RHS is a bit odd, but this niggle is already present for unfoldings, whose pattern we are following. - - - - - 78c6523c by Ben Gamari at 2020-05-21T12:13:01-04:00 nonmoving: Optimise the write barrier - - - - - 13f6c9d0 by Andreas Klebinger at 2020-05-21T12:13:45-04:00 Refactor linear reg alloc to remember past assignments. When assigning registers we now first try registers we assigned to in the past, instead of picking the "first" one. This is in extremely helpful when dealing with loops for which variables are dead for part of the loop. This is important for patterns like this: foo = arg1 loop: use(foo) ... foo = getVal() goto loop; There we: * assign foo to the register of arg1. * use foo, it's dead after this use as it's overwritten after. * do other things. * look for a register to put foo in. If we pick an arbitrary one it might differ from the register the start of the loop expect's foo to be in. To fix this we simply look for past register assignments for the given variable. If we find one and the register is free we use that register. This reduces the need for fixup blocks which match the register assignment between blocks. In the example above between the end and the head of the loop. This patch also moves branch weight estimation ahead of register allocation and adds a flag to control it (cmm-static-pred). * It means the linear allocator is more likely to assign the hotter code paths first. * If it assign these first we are: + Less likely to spill on the hot path. + Less likely to introduce fixup blocks on the hot path. These two measure combined are surprisingly effective. Based on nofib we get in the mean: * -0.9% instructions executed * -0.1% reads/writes * -0.2% code size. * -0.1% compiler allocations. * -0.9% compile time. * -0.8% runtime. Most of the benefits are simply a result of removing redundant moves and spills. Reduced compiler allocations likely are the result of less code being generated. (The added lookup is mostly non-allocating). - - - - - edc2cc58 by Andreas Klebinger at 2020-05-21T12:14:25-04:00 NCG: Codelayout: Distinguish conditional and other branches. In #18053 we ended up with a suboptimal code layout because the code layout algorithm didn't distinguish between conditional and unconditional control flow. We can completely eliminate unconditional control flow instructions by placing blocks next to each other, not so much for conditionals. In terms of implementation we simply give conditional branches less weight before computing the layout. Fixes #18053 - - - - - b7a6b2f4 by Gleb Popov at 2020-05-21T12:15:26-04:00 gitlab-ci: Set locale to C.UTF-8. - - - - - a8c27cf6 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Allow spaces in GHCi :script file names This patch updates the user interface of GHCi so that file names passed to the ':script' command may contain spaces escaped with a backslash. For example: :script foo\ bar.script The implementation uses a modified version of 'words' that does not break on escaped spaces. Fixes #18027. - - - - - 82663959 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Add extra tests for GHCi :script syntax checks The syntax for GHCi's ":script" command allows for only a single file name to be passed as an argument. This patch adds a test for the cases in which a file name is missing or multiple file names are passed. Related to #T18027. - - - - - a0b79e1b by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Allow GHCi :script file names in double quotes This patch updates the user interface of GHCi so that file names passed to the ':script' command can be wrapped in double quotes. For example: :script "foo bar.script" The implementation uses a modified version of 'words' that treats character sequences enclosed in double quotes as single words. Fixes #18027. - - - - - cf566330 by Stefan Holdermans at 2020-05-21T12:16:08-04:00 Update documentation for GHCi :script This patch adds the fixes that allow for file names containing spaces to be passed to GHCi's ':script' command to the release notes for 8.12 and expands the user-guide documentation for ':script' by mentioning how such file names can be passed. Related to #18027. - - - - - 0004ccb8 by Tuan Le at 2020-05-21T12:16:46-04:00 llvmGen: Consider Relocatable read-only data as not constantReferences: #18137 - - - - - 964d3ea2 by John Ericson at 2020-05-21T12:17:30-04:00 Use `Checker` for `tc_pat` - - - - - b797aa42 by John Ericson at 2020-05-21T12:17:30-04:00 Use `Checker` for `tc_lpat` and `tc_lpats` - - - - - 5108e84a by John Ericson at 2020-05-21T12:17:30-04:00 More judiciously panic in `ts_pat` - - - - - 510e0451 by John Ericson at 2020-05-21T12:17:30-04:00 Put `PatEnv` first in `GHC.Tc.Gen.Pat.Checker` - - - - - cb4231db by John Ericson at 2020-05-21T12:17:30-04:00 Tiny cleaup eta-reduce away a function argument In GHC, not in the code being compiled! - - - - - 6890c38d by John Ericson at 2020-05-21T12:17:30-04:00 Use braces with do in `SplicePat` case for consistency - - - - - 3451584f by buggymcbugfix at 2020-05-21T12:18:06-04:00 Fix spelling mistakes and typos - - - - - b552e531 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Add INLINABLE pragmas to Enum list producers The INLINABLE pragmas ensure that we export stable (unoptimised) unfoldings in the interface file so we can do list fusion at usage sites. Related tickets: #15185, #8763, #18178. - - - - - e7480063 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Piggyback on Enum Word methods for Word64 If we are on a 64 bit platform, we can use the efficient Enum Word methods for the Enum Word64 instance. - - - - - 892b0c41 by buggymcbugfix at 2020-05-21T12:18:06-04:00 Document INLINE(ABLE) pragmas that enable fusion - - - - - 2b363ebb by Richard Eisenberg at 2020-05-21T12:18:45-04:00 MR template should ask for key part - - - - - a95bbd0b by Sebastian Graf at 2020-05-21T12:19:37-04:00 Make `Int`'s `mod` and `rem` strict in their first arguments They used to be strict until 4d2ac2d (9 years ago). It's obviously better to be strict for performance reasons. It also blocks #18067. NoFib results: ``` -------------------------------------------------------------------------------- Program Allocs Instrs -------------------------------------------------------------------------------- integer -1.1% +0.4% wheel-sieve2 +21.2% +20.7% -------------------------------------------------------------------------------- Min -1.1% -0.0% Max +21.2% +20.7% Geometric Mean +0.2% +0.2% ``` The regression in `wheel-sieve2` is due to reboxing that likely will go away with the resolution of #18067. See !3282 for details. Fixes #18187. - - - - - d3d055b8 by Galen Huntington at 2020-05-21T12:20:18-04:00 Clarify pitfalls of NegativeLiterals; see #18022. - - - - - 1b508a9e by Alexey Kuleshevich at 2020-05-21T12:21:02-04:00 Fix wording in primops documentation to reflect the correct reasoning: * Besides resizing functions, shrinking ones also mutate the size of a mutable array and because of those two `sizeofMutabeByteArray` and `sizeofSmallMutableArray` are now deprecated * Change reference in documentation to the newer functions `getSizeof*` instead of `sizeof*` for shrinking functions * Fix incorrect mention of "byte" instead of "small" - - - - - 4ca0c8a1 by Andreas Klebinger at 2020-05-21T12:21:53-04:00 Don't variable-length encode magic iface constant. We changed to use variable length encodings for many types by default, including Word32. This makes sense for numbers but not when Word32 is meant to represent four bytes. I added a FixedLengthEncoding newtype to Binary who's instances interpret their argument as a collection of bytes instead of a number. We then use this when writing/reading magic numbers to the iface file. I also took the libery to remove the dummy iface field. This fixes #18180. - - - - - a1275081 by Krzysztof Gogolewski at 2020-05-21T12:22:35-04:00 Add a regression test for #11506 The testcase works now. See explanation in https://gitlab.haskell.org/ghc/ghc/issues/11506#note_273202 - - - - - 8a816e5f by Krzysztof Gogolewski at 2020-05-21T12:23:55-04:00 Sort deterministically metric output Previously, we sorted according to the test name and way, but the metrics (max_bytes_used/peak_megabytes_allocated etc.) were appearing in nondeterministic order. - - - - - 566cc73f by Sylvain Henry at 2020-05-21T12:24:45-04:00 Move isDynLinkName into GHC.Types.Name It doesn't belong into GHC.Unit.State - - - - - d830bbc9 by Adam Sandberg Ericsson at 2020-05-23T13:36:20-04:00 docs: fix formatting and add some links [skip ci] - - - - - 49301ad6 by Andrew Martin at 2020-05-23T13:37:01-04:00 Implement cstringLength# and FinalPtr This function and its accompanying rule resolve issue #5218. A future PR to the bytestring library will make the internal Data.ByteString.Internal.unsafePackAddress compute string length with cstringLength#. This will improve the status quo because it is eligible for constant folding. Additionally, introduce a new data constructor to ForeignPtrContents named FinalPtr. This additional data constructor, when used in the IsString instance for ByteString, leads to more Core-to-Core optimization opportunities, fewer runtime allocations, and smaller binaries. Also, this commit re-exports all the functions from GHC.CString (including cstringLength#) in GHC.Exts. It also adds a new test driver. This test driver is used to perform substring matches on Core that is dumped after all the simplifier passes. In this commit, it is used to check that constant folding of cstringLength# works. - - - - - dcd6bdcc by Ben Gamari at 2020-05-23T13:37:48-04:00 simplCore: Ignore ticks in rule templates This fixes #17619, where a tick snuck in to the template of a rule, resulting in a panic during rule matching. The tick in question was introduced via post-inlining, as discussed in `Note [Simplifying rules]`. The solution we decided upon was to simply ignore ticks in the rule template, as discussed in `Note [Tick annotations in RULE matching]`. Fixes #18162. Fixes #17619. - - - - - 82cb8913 by John Ericson at 2020-05-23T13:38:32-04:00 Fix #18145 and also avoid needless work with implicit vars - `forAllOrNothing` now is monadic, so we can trace whether we bind an explicit `forall` or not. - #18145 arose because the free vars calculation was needlessly complex. It is now greatly simplified. - Replaced some other implicit var code with `filterFreeVarsToBind`. Co-authored-by: Ryan Scott <ryan.gl.scott at gmail.com> - - - - - a60dc835 by Ben Gamari at 2020-05-23T13:39:12-04:00 Bump process submodule Fixes #17926. - - - - - 856adf54 by Ben Gamari at 2020-05-23T13:40:21-04:00 users-guide: Clarify meaning of -haddock flag Fixes #18206. - - - - - 7ae57afd by Ben Gamari at 2020-05-23T13:41:03-04:00 git: Add ignored commits file This can be used to tell git to ignore bulk renaming commits like the recently-finished module hierarchy refactoring. Configured with, git config blame.ignoreRevsFile .git-ignore-revs - - - - - 63d30e60 by jneira at 2020-05-24T01:54:42-04:00 Add hie-bios script for windows systems It is a direct translation of the sh script - - - - - 59182b88 by jneira at 2020-05-24T01:54:42-04:00 Honour previous values for CABAL and CABFLAGS The immediate goal is let the hie-bios.bat script set CABFLAGS with `-v0` and remove all cabal output except the compiler arguments - - - - - 932dc54e by jneira at 2020-05-24T01:54:42-04:00 Add specific configuration for windows in hie.yaml - - - - - e0eda070 by jneira at 2020-05-24T01:54:42-04:00 Remove not needed hie-bios output - - - - - a0ea59d6 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Move Config module into GHC.Settings - - - - - 37430251 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Rename GHC.Core.Arity into GHC.Core.Opt.Arity - - - - - a426abb9 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Rename GHC.Hs.Types into GHC.Hs.Type See discussion in https://gitlab.haskell.org/ghc/ghc/issues/13009#note_268610 - - - - - 1c91a7a0 by Sylvain Henry at 2020-05-24T01:55:24-04:00 Bump haddock submodule - - - - - 66bd24d1 by Ryan Scott at 2020-05-24T01:56:03-04:00 Add orderingTyCon to wiredInTyCons (#18185) `Ordering` needs to be wired in for use in the built-in `CmpNat` and `CmpSymbol` type families, but somehow it was never added to the list of `wiredInTyCons`, leading to the various oddities observed in #18185. Easily fixed by moving `orderingTyCon` from `basicKnownKeyNames` to `wiredInTyCons`. Fixes #18185. - - - - - 01c43634 by Matthew Pickering at 2020-05-24T01:56:42-04:00 Remove unused hs-boot file - - - - - 7a07aa71 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix cross-compiler build (#16051) - - - - - 15ccca16 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix distDir per stage - - - - - b420fb24 by Sylvain Henry at 2020-05-24T15:22:17-04:00 Hadrian: fix hp2ps error during cross-compilation Fixed by @alp (see https://gitlab.haskell.org/ghc/ghc/issues/16051#note_274265) - - - - - cd339ef0 by Joshua Price at 2020-05-24T15:22:56-04:00 Make Unicode brackets opening/closing tokens (#18225) The tokens `[|`, `|]`, `(|`, and `|)` are opening/closing tokens as described in GHC Proposal #229. This commit makes the unicode variants (`⟦`, `⟧`, `⦇`, and `⦈`) act the same as their ASCII counterparts. - - - - - 013d7120 by Ben Gamari at 2020-05-25T09:48:17-04:00 Revert "Specify kind variables for inferred kinds in base." As noted in !3132, this has rather severe knock-on consequences in user-code. We'll need to revisit this before merging something along these lines. This reverts commit 9749fe1223d182b1f8e7e4f7378df661c509f396. - - - - - 4c4312ed by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Drop redundant ad-hoc boot module check To determine whether the module is a boot module Coverage.addTicksToBinds was checking for a `boot` suffix in the module source filename. This is quite ad-hoc and shouldn't be necessary; the callsite in `deSugar` already checks that the module isn't a boot module. - - - - - 1abf3c84 by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Make tickBoxCount strict This could otherwise easily cause a leak of (+) thunks. - - - - - b2813750 by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Make ccIndices strict This just seems like a good idea. - - - - - 02e278eb by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Don't produce ModBreaks if not HscInterpreted emptyModBreaks contains a bottom and consequently it's important that we don't use it unless necessary. - - - - - b8c014ce by Ben Gamari at 2020-05-25T09:48:53-04:00 Coverage: Factor out addMixEntry - - - - - 53814a64 by Zubin Duggal at 2020-05-26T03:03:24-04:00 Add info about typeclass evidence to .hie files See `testsuite/tests/hiefile/should_run/HieQueries.hs` and `testsuite/tests/hiefile/should_run/HieQueries.stdout` for an example of this We add two new fields, `EvidenceVarBind` and `EvidenceVarUse` to the `ContextInfo` associated with an Identifier. These are associated with the appropriate identifiers for the evidence variables collected when we come across `HsWrappers`, `TcEvBinds` and `IPBinds` while traversing the AST. Instance dictionary and superclass selector dictionaries from `tcg_insts` and classes defined in `tcg_tcs` are also recorded in the AST as originating from their definition span This allows us to save a complete picture of the evidence constructed by the constraint solver, and will let us report this to the user, enabling features like going to the instance definition from the invocation of a class method(or any other method taking a constraint) and finding all usages of a particular instance. Additionally, - Mark NodeInfo with an origin so we can differentiate between bindings origininating in the source vs those in ghc - Along with typeclass evidence info, also include information on Implicit Parameters - Add a few utility functions to HieUtils in order to query the new info Updates haddock submodule - - - - - 6604906c by Sebastian Graf at 2020-05-26T03:04:04-04:00 Make WorkWrap.Lib.isWorkerSmallEnough aware of the old arity We should allow a wrapper with up to 82 parameters when the original function had 82 parameters to begin with. I verified that this made no difference on NoFib, but then again it doesn't use huge records... Fixes #18122. - - - - - cf772f19 by Sylvain Henry at 2020-05-26T03:04:45-04:00 Enhance Note [About units] for Backpack - - - - - ede24126 by Takenobu Tani at 2020-05-27T00:13:55-04:00 core-spec: Modify file paths according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * GHC/Core.hs <= coreSyn/CoreSyn.hs * GHC/Core/Coercion.hs <= types/Coercion.hs * GHC/Core/Coercion/Axiom.hs <= types/CoAxiom.hs * GHC/Core/Coercion/Opt.hs <= types/OptCoercion.hs * GHC/Core/DataCon.hs <= basicTypes/DataCon.hs * GHC/Core/FamInstEnv.hs <= types/FamInstEnv.hs * GHC/Core/Lint.hs <= coreSyn/CoreLint.hs * GHC/Core/Subst.hs <= coreSyn/CoreSubst.hs * GHC/Core/TyCo/Rep.hs <= types/TyCoRep.hs * GHC/Core/TyCon.hs <= types/TyCon.hs * GHC/Core/Type.hs <= types/Type.hs * GHC/Core/Unify.hs <= types/Unify.hs * GHC/Types/Literal.hs <= basicTypes/Literal.hs * GHC/Types/Var.hs <= basicTypes/Var.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [skip ci] - - - - - 04750304 by Ben Gamari at 2020-05-27T00:14:33-04:00 eventlog: Fix racy flushing Previously no attempt was made to avoid multiple threads writing their capability-local eventlog buffers to the eventlog writer simultaneously. This could result in multiple eventlog streams being interleaved. Fix this by documenting that the EventLogWriter's write() and flush() functions may be called reentrantly and fix the default writer to protect its FILE* by a mutex. Fixes #18210. - - - - - d6203f24 by Joshua Price at 2020-05-27T00:15:17-04:00 Make `identifier` parse unparenthesized `->` (#18060) - - - - - 28deee28 by Ben Gamari at 2020-05-28T16:23:21-04:00 GHC.Core.Unfold: Refactor traceInline This reduces duplication as well as fixes a bug wherein -dinlining-check would override -ddump-inlinings. Moreover, the new variant - - - - - 1f393e1e by Ben Gamari at 2020-05-28T16:23:21-04:00 Avoid unnecessary allocations due to tracing utilities While ticky-profiling the typechecker I noticed that hundreds of millions of SDocs are being allocated just in case -ddump-*-trace is enabled. This is awful. We avoid this by ensuring that the dump flag check is inlined into the call site, ensuring that the tracing document needn't be allocated unless it's actually needed. See Note [INLINE conditional tracing utilities] for details. Fixes #18168. Metric Decrease: T9961 haddock.Cabal haddock.base haddock.compiler - - - - - 5f621a78 by Vladislav Zavialov at 2020-05-28T16:23:58-04:00 Add Semigroup/Monoid for Q (#18123) - - - - - dc5f004c by Xavier Denis at 2020-05-28T16:24:37-04:00 Fix #18071 Run the core linter on candidate instances to ensure they are well-kinded. Better handle quantified constraints by using a CtWanted to avoid having unsolved constraints thrown away at the end by the solver. - - - - - 10e6982c by Sebastian Graf at 2020-05-28T16:25:14-04:00 FloatOut: Only eta-expand dead-end RHS if arity will increase (#18231) Otherwise we risk turning trivial RHS into non-trivial RHS, introducing unnecessary bindings in the next Simplifier run, resulting in more churn. Fixes #18231. - - - - - 08dab5f7 by Sebastian Graf at 2020-05-28T16:25:14-04:00 DmdAnal: Recognise precise exceptions from case alternatives (#18086) Consider ```hs m :: IO () m = do putStrLn "foo" error "bar" ``` `m` (from #18086) always throws a (precise or imprecise) exception or diverges. Yet demand analysis infers `<L,A>` as demand signature instead of `<L,A>x` for it. That's because the demand analyser sees `putStrLn` occuring in a case scrutinee and decides that it has to `deferAfterPreciseException`, because `putStrLn` throws a precise exception on some control flow paths. This will mask the `botDiv` `Divergence`of the single case alt containing `error` to `topDiv`. Since `putStrLn` has `topDiv` itself, the final `Divergence` is `topDiv`. This is easily fixed: `deferAfterPreciseException` works by `lub`ing with the demand type of a virtual case branch denoting the precise exceptional control flow. We used `nopDmdType` before, but we can be more precise and use `exnDmdType`, which is `nopDmdType` with `exnDiv`. Now the `Divergence` from the case alt will degrade `botDiv` to `exnDiv` instead of `topDiv`, which combines with the result from the scrutinee to `exnDiv`, and all is well. Fixes #18086. - - - - - aef95f11 by Ben Gamari at 2020-05-28T16:25:53-04:00 Ticky-ticky: Record DataCon name in ticker name This makes it significantly easier to spot the nature of allocations regressions and comes at a reasonably low cost. - - - - - 8f021b8c by Ben Gamari at 2020-05-28T16:26:34-04:00 hadrian: Don't track GHC's verbosity argument Teach hadrian to ignore GHC's -v argument in its recompilation check, thus fixing #18131. - - - - - 13d9380b by Ben Gamari at 2020-05-28T16:27:20-04:00 Rip out CmmStackInfo(updfr_space) As noted in #18232, this field is currently completely unused and moreover doesn't have a clear meaning. - - - - - f10d11fa by Andreas Klebinger at 2020-05-29T01:38:42-04:00 Fix "build/elem" RULE. An redundant constraint prevented the rule from matching. Fixing this allows a call to elem on a known list to be translated into a series of equality checks, and eventually a simple case expression. Surprisingly this seems to regress elem for strings. To avoid this we now also allow foldrCString to inline and add an UTF8 variant. This results in elem being compiled to a tight non-allocating loop over the primitive string literal which performs a linear search. In the process this commit adds UTF8 variants for some of the functions in GHC.CString. This is required to make this work for both ASCII and UTF8 strings. There are also small tweaks to the CString related rules. We now allow ourselfes the luxury to compare the folding function via eqExpr, which helps to ensure the rule fires before we inline foldrCString*. Together with a few changes to allow matching on both the UTF8 and ASCII variants of the CString functions. - - - - - bbeb2389 by Ben Gamari at 2020-05-29T01:39:19-04:00 CoreToStg: Add Outputable ArgInfo instance - - - - - 0e3361ca by Simon Peyton Jones at 2020-05-29T01:39:19-04:00 Make Lint check return type of a join point Consider join x = rhs in body It's important that the type of 'rhs' is the same as the type of 'body', but Lint wasn't checking that invariant. Now it does! This was exposed by investigation into !3113. - - - - - c49f7df0 by Simon Peyton Jones at 2020-05-29T01:39:19-04:00 Do not float join points in exprIsConApp_maybe We hvae been making exprIsConApp_maybe cleverer in recent times: commit b78cc64e923716ac0512c299f42d4d0012306c05 Date: Thu Nov 15 17:14:31 2018 +0100 Make constructor wrappers inline only during the final phase commit 7833cf407d1f608bebb1d38bb99d3035d8d735e6 Date: Thu Jan 24 17:58:50 2019 +0100 Look through newtype wrappers (Trac #16254) commit c25b135ff5b9c69a90df0ccf51b04952c2dc6ee1 Date: Thu Feb 21 12:03:22 2019 +0000 Fix exprIsConApp_maybe But alas there was still a bug, now immortalised in Note [Don't float join points] in SimpleOpt. It's quite hard to trigger because it requires a dead join point, but it came up when compiling Cabal Cabal.Distribution.Fields.Lexer.hs, when working on !3113. Happily, the fix is extremly easy. Finding the bug was not so easy. - - - - - 46720997 by Ben Gamari at 2020-05-29T01:39:19-04:00 Allow simplification through runRW# Because runRW# inlines so late, we were previously able to do very little simplification across it. For instance, given even a simple program like case runRW# (\s -> let n = I# 42# in n) of I# n# -> f n# we previously had no way to avoid the allocation of the I#. This patch allows the simplifier to push strict contexts into the continuation of a runRW# application, as explained in in Note [Simplification of runRW#] in GHC.CoreToStg.Prep. Fixes #15127. Metric Increase: T9961 Metric Decrease: ManyConstructors Co-Authored-By: Simon Peyton-Jone <simonpj at microsoft.com> - - - - - 277c2f26 by Ben Gamari at 2020-05-29T01:39:55-04:00 Eta expand un-saturated primops Now since we no longer try to predict CAFfyness we have no need for the solution to #16846. Eta expanding unsaturated primop applications is conceptually simpler, especially in the presence of levity polymorphism. This essentially reverts cac8dc9f51e31e4c0a6cd9bc302f7e1bc7c03beb, as suggested in #18079. Closes #18079. - - - - - f44d7ae0 by Simon Jakobi at 2020-05-29T01:40:34-04:00 base: Scrap deprecation plan for Data.Monoid.{First,Last} See the discussion on the libraries mailing list for context: https://mail.haskell.org/pipermail/libraries/2020-April/030357.html - - - - - 8b494895 by Jeremy Schlatter at 2020-05-29T01:41:12-04:00 Fix typo in documentation - - - - - 998450f4 by Gleb Popov at 2020-05-29T01:41:53-04:00 Always define USE_PTHREAD_FOR_ITIMER for FreeBSD. - - - - - f9a513e0 by Alp Mestanogullari at 2020-05-29T01:42:36-04:00 hadrian: introduce 'install' target Its logic is very simple. It `need`s the `binary-dist-dir` target and runs suitable `configure` and `make install` commands for the user. A new `--prefix` command line argument is introduced to specify where GHC should be installed. - - - - - 67738db1 by Travis Whitaker at 2020-05-29T13:34:48-04:00 Build a threaded stage 1 if the bootstrapping GHC supports it. - - - - - aac19e6c by Peter Trommler at 2020-05-29T13:35:24-04:00 PPC NCG: No per-symbol .section ".toc" directives All position independent symbols are collected during code generation and emitted in one go. Prepending each symbol with a .section ".toc" directive is redundant. This patch drops the per-symbol directives leading to smaller assembler files. Fixes #18250 - - - - - 4413828b by Ben Gamari at 2020-05-30T06:07:31-04:00 rts: Teach getNumProcessors to return available processors Previously we would report the number of physical processors, which can be quite wrong in a containerized setting. Now we rather return how many processors are in our affinity mask when possible. I also refactored the code to prefer platform-specific since this will report logical CPUs instead of physical (using `machdep.cpu.thread_count` on Darwin and `cpuset_getaffinity` on FreeBSD). Fixes #14781. - - - - - 1449435c by Ben Gamari at 2020-05-30T06:07:31-04:00 users-guide: Note change in getNumProcessors in users guide - - - - - 3d960169 by Ben Gamari at 2020-05-30T06:07:31-04:00 rts: Drop compatibility shims for Windows Vista We can now assume that the thread and processor group interfaces are available. - - - - - 7f8f948c by Peter Trommler at 2020-05-30T06:08:07-04:00 PPC NCG: Fix .size directive on powerpc64 ELF v1 Thanks to Sergei Trofimovich for pointing out the issue. Fixes #18237 - - - - - 7c555b05 by Andreas Klebinger at 2020-05-30T06:08:43-04:00 Optimize GHC.Utils.Monad. Many functions in this module are recursive and as such are marked loop breakers. Which means they are unlikely to get an unfolding. This is *bad*. We always want to specialize them to specific Monads. Which requires a visible unfolding at the use site. I rewrote the recursive ones from: foo f x = ... foo x' ... to foo f x = go x where go x = ... As well as giving some pragmas to make all of them available for specialization. The end result is a reduction of allocations of about -1.4% for nofib/spectral/simple/Main.hs when compiled with `-O`. ------------------------- Metric Decrease: T12425 T14683 T5631 T9233 T9675 T9961 WWRec ------------------------- - - - - - 8b1cb5df by Ben Gamari at 2020-05-30T06:09:20-04:00 Windows: Bump Windows toolchain to 0.2 - - - - - 6947231a by Zubin Duggal at 2020-05-30T06:10:02-04:00 Simplify contexts in GHC.Iface.Ext.Ast - - - - - 2ee4f36c by Daniel Gröber at 2020-06-01T06:32:56-04:00 Cleanup OVERWRITING_CLOSURE logic The code is just more confusing than it needs to be. We don't need to mix the threaded check with the ldv profiling check since ldv's init already checks for this. Hence they can be two separate checks. Taking the sanity checking into account is also cleaner via DebugFlags.sanity. No need for checking the DEBUG define. The ZERO_SLOP_FOR_LDV_PROF and ZERO_SLOP_FOR_SANITY_CHECK definitions the old code had also make things a lot more opaque IMO so I removed those. - - - - - 6159559b by Daniel Gröber at 2020-06-01T06:32:56-04:00 Fix OVERWRITING_CLOSURE assuming closures are not inherently used The new ASSERT in LDV_recordDead() was being tripped up by MVars when removeFromMVarBlockedQueue() calls OVERWRITING_CLOSURE() via OVERWRITE_INFO(). - - - - - 38992085 by Daniel Gröber at 2020-06-01T06:32:56-04:00 Always zero shrunk mutable array slop when profiling When shrinking arrays in the profiling way we currently don't always zero the leftover slop. This means we can't traverse such closures in the heap profiler. The old Note [zeroing slop] and #8402 have some rationale for why this is so but I belive the reasoning doesn't apply to mutable closures. There users already have to ensure multiple threads don't step on each other's toes so zeroing should be safe. - - - - - b0c1f2a6 by Ben Gamari at 2020-06-01T06:33:37-04:00 testsuite: Add test for #18151 - - - - - 9a99a178 by Ben Gamari at 2020-06-01T06:33:37-04:00 testsuite: Add test for desugaring of PostfixOperators - - - - - 2b89ca5b by Ben Gamari at 2020-06-01T06:33:37-04:00 HsToCore: Eta expand left sections Strangely, the comment next to this code already alluded to the fact that even simply eta-expanding will sacrifice laziness. It's quite unclear how we regressed so far. See #18151. - - - - - d412d7a3 by Kirill Elagin at 2020-06-01T06:34:21-04:00 Winferred-safe-imports: Do not exit with error Currently, when -Winferred-safe-imports is enabled, even when it is not turned into an error, the compiler will still exit with exit code 1 if this warning was emitted. Make sure it is really treated as a warning. - - - - - f945eea5 by Ben Gamari at 2020-06-01T06:34:58-04:00 nonmoving: Optimise log2_ceil - - - - - aab606e4 by Bodigrim at 2020-06-01T06:35:36-04:00 Clarify description of fromListN - - - - - 7e5220e2 by Bodigrim at 2020-06-01T06:35:36-04:00 Apply suggestion to libraries/base/GHC/Exts.hs - - - - - f3fb1ce9 by fendor at 2020-06-01T06:36:18-04:00 Add `isInScope` check to `lintCoercion` Mirrors the behaviour of `lintType`. - - - - - 5ac4d946 by fendor at 2020-06-01T06:36:18-04:00 Lint rhs of IfaceRule - - - - - 1cef6126 by Jeremy Schlatter at 2020-06-01T06:37:00-04:00 Fix wording in documentation The duplicate "orphan instance" phrase here doesn't make sense, and was probably an accident. - - - - - 5aaf08f2 by Takenobu Tani at 2020-06-01T06:37:43-04:00 configure: Modify aclocal.m4 according to new module hierarchy This patch updates file paths according to new module hierarchy [1]: * Rename: * compiler/GHC/Parser.hs <= compiler/parser/Parser.hs * compiler/GHC/Parser/Lexer.hs <= compiler/Parser/Lexer.hs * Add: * compiler/GHC/Cmm/Lexer.hs [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular - - - - - 15857ad8 by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Don't fail if we can't unlink __symlink_test Afterall, it's possible we were unable to create it due to lack of symlink permission. - - - - - 4a7229ef by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Refactor ghostscript detection Tamar reported that he saw crashes due to unhandled exceptions. - - - - - 2ab37eaf by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite/perf_notes: Fix ill-typed assignments - - - - - e45d5b66 by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite/testutil: Fix bytes/str mismatch - - - - - 7002d0cb by Ben Gamari at 2020-06-01T06:38:26-04:00 testsuite: Work around spurious mypy failure - - - - - 11390e3a by Takenobu Tani at 2020-06-01T06:39:05-04:00 Clean up file paths for new module hierarchy This updates comments only. This patch replaces file references according to new module hierarchy. See also: * https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular * https://gitlab.haskell.org/ghc/ghc/issues/13009 - - - - - 8f2e5732 by Takenobu Tani at 2020-06-01T06:39:05-04:00 Modify file paths to module paths for new module hierarchy This updates comments only. This patch replaces module references according to new module hierarchy [1][2]. For files under the `compiler/` directory, I replace them as module paths instead of file paths. For instance, `GHC.Unit.State` instead of `compiler/GHC/Unit/State.hs` [3]. For current and future haddock's markup, this patch encloses the module name with "" [4]. [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: https://gitlab.haskell.org/ghc/ghc/issues/13009 [3]: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3375#note_276613 [4]: https://haskell-haddock.readthedocs.io/en/latest/markup.html#linking-to-modules - - - - - 68b71c4a by Tom Ellis at 2020-06-01T06:39:55-04:00 Rename the singleton tuple GHC.Tuple.Unit to GHC.Tuple.Solo - - - - - 95da76c2 by Sylvain Henry at 2020-06-01T06:40:41-04:00 Hadrian: fix binary-dist target for cross-compilation - - - - - 730fcd54 by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for the @-operator Since GHC diverges from the Haskell Report by allowing the user to define (@) as an infix operator, we better give a good error message when the user does so unintentionally. In general, this is rather hard to do, as some failures will be discovered only in the renamer or the type checker: x :: (Integer, Integer) x @ (a, b) = (1, 2) This patch does *not* address this general case. However, it gives much better error messages when the binding is not syntactically valid: pairs xs @ (_:xs') = zip xs xs' Before this patch, the error message was rather puzzling: <interactive>:1:1: error: Parse error in pattern: pairs After this patch, the error message includes a hint: <interactive>:1:1: error: Parse error in pattern: pairs In a function binding for the ‘@’ operator. Perhaps you meant an as-pattern, which must not be surrounded by whitespace - - - - - 0fde5377 by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for TypeApplications With this patch, we always parse f @t as a type application, thereby producing better error messages. This steals two syntactic forms: * Prefix form of the @-operator in expressions. Since the @-operator is a divergence from the Haskell Report anyway, this is not a major loss. * Prefix form of @-patterns. Since we are stealing loose infix form anyway, might as well sacrifice the prefix form for the sake of much better error messages. - - - - - c68e7e1e by Vladislav Zavialov at 2020-06-01T06:41:18-04:00 Improve parser error messages for TemplateHaskellQuotes While [e| |], [t| |], [d| |], and so on, steal syntax from list comprehensions, [| |] and [|| ||] do not steal any syntax. Thus we can improve error messages by always accepting them in the lexer. Turns out the renamer already performs necessary validation. - - - - - 120aedbd by Ben Gamari at 2020-06-01T16:07:02-04:00 gitlab-ci: Disable use of ld.lld on ARMv7 It turns out that lld non-deterministically fails on ARMv7. I suspect this may be due to the a kernel regression as this only started happening when we upgraded to 5.4. Nevertheless, easily avoided by simply sticking with gold. Works around #18280. - - - - - d6279ff0 by Ben Gamari at 2020-06-02T13:03:30-04:00 gitlab-ci: Ensure that workaround for #18280 applies to bindisttest We need to ensure that the `configure` flags working around #18280 are propagated to the bindisttest `configure` as well. - - - - - cb5c31b5 by Ben Gamari at 2020-06-03T17:55:04-04:00 gitlab-ci: Allow ARMv7 job to fail Due to #18298. - - - - - 32a4ae90 by John Ericson at 2020-06-04T04:34:42-04:00 Clean up boot vs non-boot disambiguating types We often have (ModuleName, Bool) or (Module, Bool) pairs for "extended" module names (without or with a unit id) disambiguating boot and normal modules. We think this is important enough across the compiler that it deserves a new nominal product type. We do this with synnoyms and a functor named with a `Gen` prefix, matching other newly created definitions. It was also requested that we keep custom `IsBoot` / `NotBoot` sum type. So we have it too. This means changing many the many bools to use that instead. Updates `haddock` submodule. - - - - - c05756cd by Niklas Hambüchen at 2020-06-04T04:35:24-04:00 docs: Add more details on InterruptibleFFI. Details from https://gitlab.haskell.org/ghc/ghc/issues/8684 and https://github.com/takano-akio/filelock/pull/7#discussion_r280332430 - - - - - 1b975aed by Andrew Martin at 2020-06-04T04:36:03-04:00 Allow finalizeForeignPtr to be called on FinalPtr/PlainPtr. MR 2165 (commit 49301ad6226d9a83d110bee8c419615dd94f5ded) regressed finalizeForeignPtr by throwing exceptions when PlainPtr was encounterd. This regression did not make it into a release of GHC. Here, the original behavior is restored, and FinalPtr is given the same treatment as PlainPtr. - - - - - 2bd3929a by Luke Lau at 2020-06-04T04:36:41-04:00 Fix documentation on type families not being extracted It looks like the location of the Names used for CoAxioms on type families are now located at their type constructors. Previously, Docs.hs thought the Names were located in the RHS, so the RealSrcSpan in the instanceMap and getInstLoc didn't match up. Fixes #18241 - - - - - 6735b9d9 by Ben Gamari at 2020-06-04T04:37:21-04:00 GHC.Hs.Instances: Compile with -O0 This module contains exclusively Data instances, which are going to be slow no matter what we do. Furthermore, they are incredibly slow to compile with optimisation (see #9557). Consequently we compile this with -O0. See #18254. - - - - - c330331a by nineonine at 2020-06-04T04:37:59-04:00 Add test for #17669 - - - - - cab684f0 by Ben Gamari at 2020-06-04T04:38:36-04:00 rts: Add Windows-specific implementation of rtsSleep Previously we would use the POSIX path, which uses `nanosleep`. However, it turns out that `nanosleep` is provided by `libpthread` on Windows. In general we don't want to incur such a dependency. Avoid this by simply using `Sleep` on Windows. Fixes #18272. - - - - - ad44b504 by Ben Gamari at 2020-06-04T04:38:36-04:00 compiler: Disable use of process jobs with process < 1.6.9 Due to #17926. - - - - - 6a4098a4 by Moritz Angermann at 2020-06-04T04:55:51-04:00 [linker] Adds void printLoadedObjects(void); This allows us to dump in-memory object code locations for debugging. Fixup printLoadedObjects prototype - - - - - af5e3a88 by Artem Pelenitsyn at 2020-06-05T03:18:49-04:00 base: fix sign confusion in log1mexp implementation (fix #17125) author: claude (https://gitlab.haskell.org/trac-claude) The correct threshold for log1mexp is -(log 2) with the current specification of log1mexp. This change improves accuracy for large negative inputs. To avoid code duplication, a small helper function is added; it isn't the default implementation in Floating because it needs Ord. This patch does nothing to address that the Haskell specification is different from that in common use in other languages. - - - - - 2b792fac by Simon Peyton Jones at 2020-06-05T09:27:50-04:00 Simple subsumption This patch simplifies GHC to use simple subsumption. Ticket #17775 Implements GHC proposal #287 https://github.com/ghc-proposals/ghc-proposals/blob/master/ proposals/0287-simplify-subsumption.rst All the motivation is described there; I will not repeat it here. The implementation payload: * tcSubType and friends become noticably simpler, because it no longer uses eta-expansion when checking subsumption. * No deeplyInstantiate or deeplySkolemise That in turn means that some tests fail, by design; they can all be fixed by eta expansion. There is a list of such changes below. Implementing the patch led me into a variety of sticky corners, so the patch includes several othe changes, some quite significant: * I made String wired-in, so that "foo" :: String rather than "foo" :: [Char] This improves error messages, and fixes #15679 * The pattern match checker relies on knowing about in-scope equality constraints, andd adds them to the desugarer's environment using addTyCsDs. But the co_fn in a FunBind was missed, and for some reason simple-subsumption ends up with dictionaries there. So I added a call to addTyCsDs. This is really part of #18049. * I moved the ic_telescope field out of Implication and into ForAllSkol instead. This is a nice win; just expresses the code much better. * There was a bug in GHC.Tc.TyCl.Instance.tcDataFamInstHeader. We called checkDataKindSig inside tc_kind_sig, /before/ solveEqualities and zonking. Obviously wrong, easily fixed. * solveLocalEqualitiesX: there was a whole mess in here, around failing fast enough. I discovered a bad latent bug where we could successfully kind-check a type signature, and use it, but have unsolved constraints that could fill in coercion holes in that signature -- aargh. It's all explained in Note [Failure in local type signatures] in GHC.Tc.Solver. Much better now. * I fixed a serious bug in anonymous type holes. IN f :: Int -> (forall a. a -> _) -> Int that "_" should be a unification variable at the /outer/ level; it cannot be instantiated to 'a'. This was plain wrong. New fields mode_lvl and mode_holes in TcTyMode, and auxiliary data type GHC.Tc.Gen.HsType.HoleMode. This fixes #16292, but makes no progress towards the more ambitious #16082 * I got sucked into an enormous refactoring of the reporting of equality errors in GHC.Tc.Errors, especially in mkEqErr1 mkTyVarEqErr misMatchMsg misMatchMsgOrCND In particular, the very tricky mkExpectedActualMsg function is gone. It took me a full day. But the result is far easier to understand. (Still not easy!) This led to various minor improvements in error output, and an enormous number of test-case error wibbles. One particular point: for occurs-check errors I now just say Can't match 'a' against '[a]' rather than using the intimidating language of "occurs check". * Pretty-printing AbsBinds Tests review * Eta expansions T11305: one eta expansion T12082: one eta expansion (undefined) T13585a: one eta expansion T3102: one eta expansion T3692: two eta expansions (tricky) T2239: two eta expansions T16473: one eta determ004: two eta expansions (undefined) annfail06: two eta (undefined) T17923: four eta expansions (a strange program indeed!) tcrun035: one eta expansion * Ambiguity check at higher rank. Now that we have simple subsumption, a type like f :: (forall a. Eq a => Int) -> Int is no longer ambiguous, because we could write g :: (forall a. Eq a => Int) -> Int g = f and it'd typecheck just fine. But f's type is a bit suspicious, and we might want to consider making the ambiguity check do a check on each sub-term. Meanwhile, these tests are accepted, whereas they were previously rejected as ambiguous: T7220a T15438 T10503 T9222 * Some more interesting error message wibbles T13381: Fine: one error (Int ~ Exp Int) rather than two (Int ~ Exp Int, Exp Int ~ Int) T9834: Small change in error (improvement) T10619: Improved T2414: Small change, due to order of unification, fine T2534: A very simple case in which a change of unification order means we get tow unsolved constraints instead of one tc211: bizarre impredicative tests; just accept this for now Updates Cabal and haddock submodules. Metric Increase: T12150 T12234 T5837 haddock.base Metric Decrease: haddock.compiler haddock.Cabal haddock.base Merge note: This appears to break the `UnliftedNewtypesDifficultUnification` test. It has been marked as broken in the interest of merging. (cherry picked from commit 66b7b195cb3dce93ed5078b80bf568efae904cc5) - - - - - 2dff8141 by Ryan Scott at 2020-06-05T14:21:24-04:00 Simplify bindLHsTyVarBndrs and bindHsQTyVars Both `bindLHsTyVarBndrs` and `bindHsQTyVars` take two separate `Maybe` arguments, which I find terribly confusing. Thankfully, it's possible to remove one `Maybe` argument from each of these functions, which this patch accomplishes: * `bindHsQTyVars` takes a `Maybe SDoc` argument, which is `Just` if GHC should warn about any of the quantified type variables going unused. However, every call site uses `Nothing` in practice. This makes sense, since it doesn't really make sense to warn about unused type variables bound by an `LHsQTyVars`. For instance, you wouldn't warn about the `a` in `data Proxy a = Proxy` going unused. As a result, I simply remove this `Maybe SDoc` argument altogether. * `bindLHsTyVarBndrs` also takes a `Maybe SDoc` argument for the same reasons that `bindHsQTyVars` took one. To make things more confusing, however, `bindLHsTyVarBndrs` also takes a separate `HsDocContext` argument, which is pretty-printed (to an `SDoc`) in warnings and error messages. In practice, the `Maybe SDoc` and the `HsDocContext` often contain the same text. See the call sites for `bindLHsTyVarBndrs` in `rnFamInstEqn` and `rnConDecl`, for instance. There are only a handful of call sites where the text differs between the `Maybe SDoc` and `HsDocContext` arguments: * In `rnHsRuleDecl`, where the `Maybe SDoc` says "`In the rule`" and the `HsDocContext` says "`In the transformation rule`". * In `rnHsTyKi`/`rn_ty`, where the `Maybe SDoc` says "`In the type`" but the `HsDocContext` is inhereted from the surrounding context (e.g., if `rnHsTyKi` were called on a top-level type signature, the `HsDocContext` would be "`In the type signature`" instead) In both cases, warnings/error messages arguably _improve_ by unifying making the `Maybe SDoc`'s text match that of the `HsDocContext`. As a result, I decided to remove the `Maybe SDoc` argument to `bindLHsTyVarBndrs` entirely and simply reuse the text from the `HsDocContext`. (I decided to change the phrase "transformation rule" to "rewrite rule" while I was in the area.) The `Maybe SDoc` argument has one other purpose: signaling when to emit "`Unused quantified type variable`" warnings. To recover this functionality, I replaced the `Maybe SDoc` argument with a boolean-like `WarnUnusedForalls` argument. The only `bindLHsTyVarBndrs` call site that chooses _not_ to emit these warnings in `bindHsQTyVars`. - - - - - e372331b by Ben Gamari at 2020-06-07T08:46:41-04:00 hadrian: Add missing deriveConstants dependency on ghcplatform.h deriveConstants wants to compile C sources which #include PosixSource.h, which itself #includes ghcplatform.h. Make sure that Hadrian knows about this dependency. Fixes #18290. - - - - - b022051a by Moritz Angermann at 2020-06-07T08:46:42-04:00 ghc-prim needs to depend on libc and libm libm is just an empty shell on musl, and all the math functions are contained in libc. - - - - - 6dae6548 by Moritz Angermann at 2020-06-07T08:46:42-04:00 Disable DLL loading if without system linker Some platforms (musl, aarch64) do not have a working dynamic linker implemented in the libc, even though we might see dlopen. It will ultimately just return that this is not supported. Hence we'll add a flag to the compiler to flat our disable loading dlls. This is needed as we will otherwise try to load the shared library even if this will subsequently fail. At that point we have given up looking for static options though. - - - - - 4a158ffc by Moritz Angermann at 2020-06-07T08:46:43-04:00 Range is actually +/-2^32, not +/-2^31 See also: https://static.docs.arm.com/ihi0056/g/aaelf64.pdf - - - - - f1bfb806 by Ben Gamari at 2020-06-07T10:49:30-04:00 OccurAnal: Avoid exponential behavior due to where clauses Previously the `Var` case of `occAnalApp` could in some cases (namely in the case of `runRW#` applications) call `occAnalRhs` two. In the case of nested `runRW#`s this results in exponential complexity. In some cases the compilation time that resulted would be very long indeed (see #18296). Fixes #18296. Metric Decrease: T9961 T12150 T12234 - - - - - 9b607671 by Takenobu Tani at 2020-06-09T08:05:46-04:00 Add link to GHC's wiki in the GHC API header This adds a URL to point to GHC's wiki in the GHC API header. Newcomers could easily find more information from the GHC API's web like [1]. [1]: Current version, https://ghc.gitlab.haskell.org/ghc/doc/libraries/ghc-8.11.0.20200604/index.html [skip ci] - - - - - 72c7fe9a by Ryan Scott at 2020-06-09T08:06:24-04:00 Make GADT constructors adhere to the forall-or-nothing rule properly Issue #18191 revealed that the types of GADT constructors don't quite adhere to the `forall`-or-nothing rule. This patch serves to clean up this sad state of affairs somewhat. The main change is not in the code itself, but in the documentation, as this patch introduces two sections to the GHC User's Guide: * A "Formal syntax for GADTs" section that presents a BNF-style grammar for what is and isn't allowed in GADT constructor types. This mostly exists to codify GHC's existing behavior, but it also imposes a new restriction that addresses #18191: the outermost `forall` and/or context in a GADT constructor is not allowed to be surrounded by parentheses. Doing so would make these `forall`s/contexts nested, and GADTs do not support nested `forall`s/contexts at present. * A "`forall`-or-nothing rule" section that describes exactly what the `forall`-or-nothing rule is all about. Surprisingly, there was no mention of this anywhere in the User's Guide up until now! To adhere the new specification in the "Formal syntax for GADTs" section of the User's Guide, the following code changes were made: * A new function, `GHC.Hs.Type.splitLHsGADTPrefixTy`, was introduced. This is very much like `splitLHsSigmaTy`, except that it avoids splitting apart any parentheses, which can be syntactically significant for GADT types. See `Note [No nested foralls or contexts in GADT constructors]` in `GHC.Hs.Type`. * `ConDeclGADTPrefixPs`, an extension constructor for `XConDecl`, was introduced so that `GHC.Parser.PostProcess.mkGadtDecl` can return it when given a prefix GADT constructor. Unlike `ConDeclGADT`, `ConDeclGADTPrefixPs` does not split the GADT type into its argument and result types, as this cannot be done until after the type is renamed (see `Note [GADT abstract syntax]` in `GHC.Hs.Decls` for why this is the case). * `GHC.Renamer.Module.rnConDecl` now has an additional case for `ConDeclGADTPrefixPs` that (1) splits apart the full `LHsType` into its `forall`s, context, argument types, and result type, and (2) checks for nested `forall`s/contexts. Step (2) used to be performed the typechecker (in `GHC.Tc.TyCl.badDataConTyCon`) rather than the renamer, but now the relevant code from the typechecker can simply be deleted. One nice side effect of this change is that we are able to give a more accurate error message for GADT constructors that use visible dependent quantification (e.g., `MkFoo :: forall a -> a -> Foo a`), which improves the stderr in the `T16326_Fail6` test case. Fixes #18191. Bumps the Haddock submodule. - - - - - a47e6442 by Ryan Scott at 2020-06-10T03:39:12-04:00 Always use rnImplicitBndrs to bring implicit tyvars into scope This implements a first step towards #16762 by changing the renamer to always use `rnImplicitBndrs` to bring implicitly bound type variables into scope. The main change is in `rnFamInstEqn` and `bindHsQTyVars`, which previously used _ad hoc_ methods of binding their implicit tyvars. There are a number of knock-on consequences: * One of the reasons that `rnFamInstEqn` used an _ad hoc_ binding mechanism was to give more precise source locations in `-Wunused-type-patterns` warnings. (See https://gitlab.haskell.org/ghc/ghc/issues/16762#note_273343 for an example of this.) However, these warnings are actually a little _too_ precise, since implicitly bound type variables don't have exact binding sites like explicitly bound type variables do. A similar problem existed for "`Different names for the same type variable`" errors involving implicit tyvars bound by `bindHsQTyVars`. Therefore, we simply accept the less precise (but more accurate) source locations from `rnImplicitBndrs` in `rnFamInstEqn` and `bindHsQTyVars`. See `Note [Source locations for implicitly bound type variables]` in `GHC.Rename.HsType` for the full story. * In order for `rnImplicitBndrs` to work in `rnFamInstEqn`, it needs to be able to look up names from the parent class (in the event that we are renaming an associated type family instance). As a result, `rnImplicitBndrs` now takes an argument of type `Maybe assoc`, which is `Just` in the event that a type family instance is associated with a class. * Previously, GHC kept track of three type synonyms for free type variables in the renamer: `FreeKiTyVars`, `FreeKiTyVarsDups` (which are allowed to contain duplicates), and `FreeKiTyVarsNoDups` (which contain no duplicates). However, making is a distinction between `-Dups` and `-NoDups` is now pointless, as all code that returns `FreeKiTyVars{,Dups,NoDups}` will eventually end up being passed to `rnImplicitBndrs`, which removes duplicates. As a result, I decided to just get rid of `FreeKiTyVarsDups` and `FreeKiTyVarsNoDups`, leaving only `FreeKiTyVars`. * The `bindLRdrNames` and `deleteBys` functions are now dead code, so I took the liberty of removing them. - - - - - 24879129 by Takenobu Tani at 2020-06-10T03:39:59-04:00 Clarify leaf module names for new module hierarchy This updates comments only. This patch replaces leaf module names according to new module hierarchy [1][2] as followings: * Expand leaf names to easily find the module path: for instance, `Id.hs` to `GHC.Types.Id`. * Modify leaf names according to new module hierarchy: for instance, `Convert.hs` to `GHC.ThToHs`. * Fix typo: for instance, `GHC.Core.TyCo.Rep.hs` to `GHC.Core.TyCo.Rep` See also !3375 [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: https://gitlab.haskell.org/ghc/ghc/issues/13009 - - - - - 92de9e25 by Ömer Sinan Ağacan at 2020-06-10T03:41:07-04:00 rts: Remove unused GET_ENTRY closure macro This macro is not used and got broken in the meantime, as ENTRY_CODE was deleted. - - - - - 87102928 by Ömer Sinan Ağacan at 2020-06-10T03:41:50-04:00 Fix -fkeep-cafs flag name in users guide - - - - - ccd6843d by Shayne Fletcher at 2020-06-10T04:14:57-04:00 Expose impliedGFlags, impledOffGFlags, impliedXFlags - - - - - 7a737e89 by Ömer Sinan Ağacan at 2020-06-10T04:14:58-04:00 Cross-module LambdaFormInfo passing - Store LambdaFormInfos of exported Ids in interface files - Use them in importing modules This is for optimization purposes: if we know LambdaFormInfo of imported Ids we can generate more efficient calling code, see `getCallMethod`. Exporting (putting them in interface files or in ModDetails) and importing (reading them from interface files) are both optional. We don't assume known LambdaFormInfos anywhere and do not change how we call Ids with unknown LambdaFormInfos. Runtime, allocation, and residency numbers when building Cabal-the-library (commit 0d4ee7ba3): (Log and .hp files are in the MR: !2842) | | GHC HEAD | This patch | Diff | |-----|----------|------------|----------------| | -O0 | 0:35.89 | 0:34.10 | -1.78s, -4.98% | | -O1 | 2:24.01 | 2:23.62 | -0.39s, -0.27% | | -O2 | 2:52.23 | 2:51.35 | -0.88s, -0.51% | | | GHC HEAD | This patch | Diff | |-----|-----------------|-----------------|----------------------------| | -O0 | 54,843,608,416 | 54,878,769,544 | +35,161,128 bytes, +0.06% | | -O1 | 227,136,076,400 | 227,569,045,168 | +432,968,768 bytes, +0.19% | | -O2 | 266,147,063,296 | 266,749,643,440 | +602,580,144 bytes, +0.22% | NOTE: Residency is measured with extra runtime args: `-i0 -h` which effectively turn all GCs into major GCs, and do GC more often. | | GHC HEAD | This patch | Diff | |-----|----------------------------|------------------------------|----------------------------| | -O0 | 410,284,000 (910 samples) | 411,745,008 (906 samples) | +1,461,008 bytes, +0.35% | | -O1 | 928,580,856 (2109 samples) | 943,506,552 (2103 samples) | +14,925,696 bytes, +1.60% | | -O2 | 993,951,352 (2549 samples) | 1,010,156,328 (2545 samples) | +16,204,9760 bytes, +1.63% | NoFib results: -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS 0.0% 0.0% +0.0% +0.0% +0.0% CSD 0.0% 0.0% 0.0% +0.0% +0.0% FS 0.0% 0.0% +0.0% +0.0% +0.0% S 0.0% 0.0% +0.0% +0.0% +0.0% VS 0.0% 0.0% +0.0% +0.0% +0.0% VSD 0.0% 0.0% +0.0% +0.0% +0.1% VSM 0.0% 0.0% +0.0% +0.0% +0.0% anna 0.0% 0.0% -0.3% -0.8% -0.0% ansi 0.0% 0.0% -0.0% -0.0% 0.0% atom 0.0% 0.0% -0.0% -0.0% 0.0% awards 0.0% 0.0% -0.1% -0.3% 0.0% banner 0.0% 0.0% -0.0% -0.0% -0.0% bernouilli 0.0% 0.0% -0.0% -0.0% -0.0% binary-trees 0.0% 0.0% -0.0% -0.0% +0.0% boyer 0.0% 0.0% -0.0% -0.0% 0.0% boyer2 0.0% 0.0% -0.0% -0.0% 0.0% bspt 0.0% 0.0% -0.0% -0.2% 0.0% cacheprof 0.0% 0.0% -0.1% -0.4% +0.0% calendar 0.0% 0.0% -0.0% -0.0% 0.0% cichelli 0.0% 0.0% -0.9% -2.4% 0.0% circsim 0.0% 0.0% -0.0% -0.0% 0.0% clausify 0.0% 0.0% -0.1% -0.3% 0.0% comp_lab_zift 0.0% 0.0% -0.0% -0.0% +0.0% compress 0.0% 0.0% -0.0% -0.0% -0.0% compress2 0.0% 0.0% -0.0% -0.0% 0.0% constraints 0.0% 0.0% -0.1% -0.2% -0.0% cryptarithm1 0.0% 0.0% -0.0% -0.0% 0.0% cryptarithm2 0.0% 0.0% -1.4% -4.1% -0.0% cse 0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e1 0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e2 0.0% 0.0% -0.0% -0.0% -0.0% dom-lt 0.0% 0.0% -0.1% -0.2% 0.0% eliza 0.0% 0.0% -0.5% -1.5% 0.0% event 0.0% 0.0% -0.0% -0.0% -0.0% exact-reals 0.0% 0.0% -0.1% -0.3% +0.0% exp3_8 0.0% 0.0% -0.0% -0.0% -0.0% expert 0.0% 0.0% -0.3% -1.0% -0.0% fannkuch-redux 0.0% 0.0% +0.0% +0.0% +0.0% fasta 0.0% 0.0% -0.0% -0.0% +0.0% fem 0.0% 0.0% -0.0% -0.0% 0.0% fft 0.0% 0.0% -0.0% -0.0% 0.0% fft2 0.0% 0.0% -0.0% -0.0% 0.0% fibheaps 0.0% 0.0% -0.0% -0.0% +0.0% fish 0.0% 0.0% 0.0% -0.0% +0.0% fluid 0.0% 0.0% -0.4% -1.2% +0.0% fulsom 0.0% 0.0% -0.0% -0.0% 0.0% gamteb 0.0% 0.0% -0.1% -0.3% 0.0% gcd 0.0% 0.0% -0.0% -0.0% 0.0% gen_regexps 0.0% 0.0% -0.0% -0.0% -0.0% genfft 0.0% 0.0% -0.0% -0.0% 0.0% gg 0.0% 0.0% -0.0% -0.0% +0.0% grep 0.0% 0.0% -0.0% -0.0% -0.0% hidden 0.0% 0.0% -0.1% -0.4% -0.0% hpg 0.0% 0.0% -0.2% -0.5% +0.0% ida 0.0% 0.0% -0.0% -0.0% +0.0% infer 0.0% 0.0% -0.3% -0.8% -0.0% integer 0.0% 0.0% -0.0% -0.0% +0.0% integrate 0.0% 0.0% -0.0% -0.0% 0.0% k-nucleotide 0.0% 0.0% -0.0% -0.0% +0.0% kahan 0.0% 0.0% -0.0% -0.0% +0.0% knights 0.0% 0.0% -2.2% -5.4% 0.0% lambda 0.0% 0.0% -0.6% -1.8% 0.0% last-piece 0.0% 0.0% -0.0% -0.0% 0.0% lcss 0.0% 0.0% -0.0% -0.1% 0.0% life 0.0% 0.0% -0.0% -0.1% 0.0% lift 0.0% 0.0% -0.2% -0.6% +0.0% linear 0.0% 0.0% -0.0% -0.0% -0.0% listcompr 0.0% 0.0% -0.0% -0.0% 0.0% listcopy 0.0% 0.0% -0.0% -0.0% 0.0% maillist 0.0% 0.0% -0.1% -0.3% +0.0% mandel 0.0% 0.0% -0.0% -0.0% 0.0% mandel2 0.0% 0.0% -0.0% -0.0% -0.0% mate +0.0% 0.0% -0.0% -0.0% -0.0% minimax 0.0% 0.0% -0.2% -1.0% 0.0% mkhprog 0.0% 0.0% -0.1% -0.2% -0.0% multiplier 0.0% 0.0% -0.0% -0.0% -0.0% n-body 0.0% 0.0% -0.0% -0.0% +0.0% nucleic2 0.0% 0.0% -0.1% -0.2% 0.0% para 0.0% 0.0% -0.0% -0.0% -0.0% paraffins 0.0% 0.0% -0.0% -0.0% 0.0% parser 0.0% 0.0% -0.2% -0.7% 0.0% parstof 0.0% 0.0% -0.0% -0.0% +0.0% pic 0.0% 0.0% -0.0% -0.0% 0.0% pidigits 0.0% 0.0% +0.0% +0.0% +0.0% power 0.0% 0.0% -0.2% -0.6% +0.0% pretty 0.0% 0.0% -0.0% -0.0% -0.0% primes 0.0% 0.0% -0.0% -0.0% 0.0% primetest 0.0% 0.0% -0.0% -0.0% -0.0% prolog 0.0% 0.0% -0.3% -1.1% 0.0% puzzle 0.0% 0.0% -0.0% -0.0% 0.0% queens 0.0% 0.0% -0.0% -0.0% +0.0% reptile 0.0% 0.0% -0.0% -0.0% 0.0% reverse-complem 0.0% 0.0% -0.0% -0.0% +0.0% rewrite 0.0% 0.0% -0.7% -2.5% -0.0% rfib 0.0% 0.0% -0.0% -0.0% 0.0% rsa 0.0% 0.0% -0.0% -0.0% 0.0% scc 0.0% 0.0% -0.1% -0.2% -0.0% sched 0.0% 0.0% -0.0% -0.0% -0.0% scs 0.0% 0.0% -1.0% -2.6% +0.0% simple 0.0% 0.0% +0.0% -0.0% +0.0% solid 0.0% 0.0% -0.0% -0.0% 0.0% sorting 0.0% 0.0% -0.6% -1.6% 0.0% spectral-norm 0.0% 0.0% +0.0% 0.0% +0.0% sphere 0.0% 0.0% -0.0% -0.0% -0.0% symalg 0.0% 0.0% -0.0% -0.0% +0.0% tak 0.0% 0.0% -0.0% -0.0% 0.0% transform 0.0% 0.0% -0.0% -0.0% 0.0% treejoin 0.0% 0.0% -0.0% -0.0% 0.0% typecheck 0.0% 0.0% -0.0% -0.0% +0.0% veritas +0.0% 0.0% -0.2% -0.4% +0.0% wang 0.0% 0.0% -0.0% -0.0% 0.0% wave4main 0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve1 0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve2 0.0% 0.0% -0.0% -0.0% +0.0% x2n1 0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min 0.0% 0.0% -2.2% -5.4% -0.0% Max +0.0% 0.0% +0.0% +0.0% +0.1% Geometric Mean -0.0% -0.0% -0.1% -0.3% +0.0% Metric increases micro benchmarks tracked in #17686: Metric Increase: T12150 T12234 T12425 T13035 T5837 T6048 T9233 Co-authored-by: Andreas Klebinger <klebinger.andreas at gmx.at> - - - - - 3b22b14a by Shayne Fletcher at 2020-06-10T04:15:01-04:00 Give Language a Bounded instance - - - - - 9454511b by Simon Peyton Jones at 2020-06-10T04:17:06-04:00 Optimisation in Unique.Supply This patch switches on -fno-state-hack in GHC.Types.Unique.Supply. It turned out that my fixes for #18078 (coercion floating) changed the optimisation pathway for mkSplitUniqSupply in such a way that we had an extra allocation inside the inner loop. Adding -fno-state-hack fixed that -- and indeed the loop in mkSplitUniqSupply is a classic example of the way in which -fno-state-hack can be bad; see #18238. Moreover, the new code is better than the old. They allocate the same, but the old code ends up with a partial application. The net effect is that the test perf/should_run/UniqLoop runs 20% faster! From 2.5s down to 2.0s. The allocation numbers are the same -- but elapsed time falls. Good! The bad thing about this is that it's terribly delicate. But at least it's a good example of such delicacy in action. There is a long Note [Optimising the unique supply] which now explains all this. - - - - - 6d49d5be by Simon Peyton Jones at 2020-06-10T04:17:06-04:00 Implement cast worker/wrapper properly The cast worker/wrapper transformation transforms x = e |> co into y = e x = y |> co This is done by the simplifier, but we were being careless about transferring IdInfo from x to y, and about what to do if x is a NOINLNE function. This resulted in a series of bugs: #17673, #18093, #18078. This patch fixes all that: * Main change is in GHC.Core.Opt.Simplify, and the new prepareBinding function, which does this cast worker/wrapper transform. See Note [Cast worker/wrappers]. * There is quite a bit of refactoring around prepareRhs, makeTrivial etc. It's nicer now. * Some wrappers from strictness and cast w/w, notably those for a function with a NOINLINE, should inline very late. There wasn't really a mechanism for that, which was an existing bug really; so I invented a new finalPhase = Phase (-1). It's used for all simplifier runs after the user-visible phase 2,1,0 have run. (No new runs of the simplifier are introduced thereby.) See new Note [Compiler phases] in GHC.Types.Basic; the main changes are in GHC.Core.Opt.Driver * Doing this made me trip over two places where the AnonArgFlag on a FunTy was being lost so we could end up with (Num a -> ty) rather than (Num a => ty) - In coercionLKind/coercionRKind - In contHoleType in the Simplifier I fixed the former by defining mkFunctionType and using it in coercionLKind/RKind. I could have done the same for the latter, but the information is almost to hand. So I fixed the latter by - adding sc_hole_ty to ApplyToVal (like ApplyToTy), - adding as_hole_ty to ValArg (like TyArg) - adding sc_fun_ty to StrictArg Turned out I could then remove ai_type from ArgInfo. This is just moving the deck chairs around, but it worked out nicely. See the new Note [AnonArgFlag] in GHC.Types.Var * When looking at the 'arity decrease' thing (#18093) I discovered that stable unfoldings had a much lower arity than the actual optimised function. That's what led to the arity-decrease message. Simple solution: eta-expand. It's described in Note [Eta-expand stable unfoldings] in GHC.Core.Opt.Simplify * I also discovered that unsafeCoerce wasn't being inlined if the context was boring. So (\x. f (unsafeCoerce x)) would create a thunk -- yikes! I fixed that by making inlineBoringOK a bit cleverer: see Note [Inline unsafeCoerce] in GHC.Core.Unfold. I also found that unsafeCoerceName was unused, so I removed it. I made a test case for #18078, and a very similar one for #17673. The net effect of all this on nofib is very modest, but positive: -------------------------------------------------------------------------------- Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- anna -0.4% -0.1% -3.1% -3.1% 0.0% fannkuch-redux -0.4% -0.3% -0.1% -0.1% 0.0% maillist -0.4% -0.1% -7.8% -1.0% -14.3% primetest -0.4% -15.6% -7.1% -6.6% 0.0% -------------------------------------------------------------------------------- Min -0.9% -15.6% -13.3% -14.2% -14.3% Max -0.3% 0.0% +12.1% +12.4% 0.0% Geometric Mean -0.4% -0.2% -2.3% -2.2% -0.1% All following metric decreases are compile-time allocation decreases between -1% and -3%: Metric Decrease: T5631 T13701 T14697 T15164 - - - - - 32fd37f5 by Luke Lau at 2020-06-10T04:17:22-04:00 Fix lookupGlobalOccRn_maybe sometimes reporting an error In some cases it was possible for lookupGlobalOccRn_maybe to return an error, when it should be returning a Nothing. If it called lookupExactOcc_either when there were no matching GlobalRdrElts in the otherwise case, it would return an error message. This could be caused when lookupThName_maybe in Template Haskell was looking in different namespaces (thRdrNameGuesses), guessing different namespaces that the name wasn't guaranteed to be found in. However, by addressing this some more accurate errors were being lost in the conversion to Maybes. So some of the lookup* functions have been shuffled about so that errors should always be ignored in lookup*_maybes, and propagated otherwise. This fixes #18263 - - - - - 9b283e1b by Roland Senn at 2020-06-10T04:17:34-04:00 Initialize the allocation counter in GHCi to 0 (Fixes #16012) According to the documentation for the function `getAllocationCounter` in [System.Mem](http://hackage.haskell.org/package/base-4.14.0.0/docs/System-Mem.html) initialize the allocationCounter also in GHCi to 0. - - - - - 8d07c48c by Sylvain Henry at 2020-06-10T04:17:36-04:00 test: fix conc038 We had spurious failures of conc038 test on CI with stdout: ``` newThread started -mainThread -Haskell: 2 newThread back again +mainThread 1 sec later shutting down +Haskell: 2 ``` - - - - - 4c7e9689 by Sebastian Graf at 2020-06-11T10:37:38+02:00 Release Notes: Add news from the pattern-match checker [skip ci] - - - - - 3445b965 by Sylvain Henry at 2020-06-13T02:13:01-04:00 Only test T16190 with the NCG T16190 is meant to test a NCG feature. It has already caused spurious failures in other MRs (e.g. !2165) when LLVM is used. - - - - - 2517a51c by Sylvain Henry at 2020-06-13T02:13:01-04:00 DynFlags refactoring VIII (#17957) * Remove several uses of `sdocWithDynFlags`, especially in GHC.Llvm.* * Add LlvmOpts datatype to store Llvm backend options * Remove Outputable instances (for LlvmVar, LlvmLit, LlvmStatic and Llvm.MetaExpr) which require LlvmOpts. * Rename ppMetaExpr into ppMetaAnnotExpr (pprMetaExpr is now used in place of `ppr :: MetaExpr -> SDoc`) - - - - - 7a02599a by Sylvain Henry at 2020-06-13T02:13:02-04:00 Remove unused code - - - - - 72d08610 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Refactor homeUnit * rename thisPackage into homeUnit * document and refactor several Backpack things - - - - - 8dc71f55 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Rename unsafeGetUnitInfo into unsafeLookupUnit - - - - - f6be6e43 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Add allowVirtualUnits field in PackageState Instead of always querying DynFlags to know whether we are allowed to use virtual units (i.e. instantiated on-the-fly, cf Note [About units] in GHC.Unit), we store it once for all in `PackageState.allowVirtualUnits`. This avoids using DynFlags too much (cf #17957) and is preliminary work for #14335. - - - - - e7272d53 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Enhance UnitId use * use UnitId instead of String to identify wired-in units * use UnitId instead of Unit in the backend (Unit are only use by Backpack to produce type-checked interfaces, not real code) * rename lookup functions for consistency * documentation - - - - - 9c5572cd by Sylvain Henry at 2020-06-13T02:13:02-04:00 Remove LinkerUnitId type alias - - - - - d345edfe by Sylvain Henry at 2020-06-13T02:13:02-04:00 Refactor WiredMap * Remove WiredInUnitId and WiredUnitId type aliases - - - - - 3d171cd6 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Document and refactor `mkUnit` and `mkUnitInfoMap` - - - - - d2109b4f by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove PreloadUnitId type alias - - - - - f50c19b8 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename listUnitInfoMap into listUnitInfo There is no Map involved - - - - - ed533ec2 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename Package into Unit The terminology changed over time and now package databases contain "units" (there can be several units compiled from a single Cabal package: one per-component, one for each option set, one per instantiation, etc.). We should try to be consistent internally and use "units": that's what this renaming does. Maybe one day we'll fix the UI too (e.g. replace -package-id with -unit-id, we already have -this-unit-id and ghc-pkg has -unit-id...) but it's not done in this patch. * rename getPkgFrameworkOpts into getUnitFrameworkOpts * rename UnitInfoMap into ClosureUnitInfoMap * rename InstalledPackageIndex into UnitInfoMap * rename UnusablePackages into UnusableUnits * rename PackagePrecedenceIndex into UnitPrecedenceMap * rename PackageDatabase into UnitDatabase * rename pkgDatabase into unitDatabases * rename pkgState into unitState * rename initPackages into initUnits * rename renamePackage into renameUnitInfo * rename UnusablePackageReason into UnusableUnitReason * rename getPackage* into getUnit* * etc. - - - - - 202728e5 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Make ClosureUnitInfoMap uses UnitInfoMap - - - - - 55b4263e by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove ClosureUnitInfoMap - - - - - 653d17bd by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename Package into Unit (2) * rename PackageState into UnitState * rename findWiredInPackages into findWiredInUnits * rename lookupModuleInAll[Packages,Units] * etc. - - - - - ae900605 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move dump_mod_map into initUnits - - - - - 598cc1dd by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move wiring of homeUnitInstantiations outside of mkUnitState - - - - - 437265eb by Sylvain Henry at 2020-06-13T02:13:03-04:00 Avoid timing module map dump in initUnits - - - - - 9400aa93 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove preload parameter of mkUnitState * Remove preload parameter (unused) * Don't explicitly return preloaded units: redundant because already returned as "preloadUnits" field of UnitState - - - - - 266bc3d9 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: refactor unwireUnit - - - - - 9e715c1b by Sylvain Henry at 2020-06-13T02:13:03-04:00 Document getPreloadUnitsAnd - - - - - bd5810dc by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: remove useless add_package parameter - - - - - 36e1daf0 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: make listVisibleModuleNames take a UnitState - - - - - 5226da37 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Refactor and document add_package - - - - - 4b53aac1 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Refactor and document closeUnitDeps - - - - - 42c054f6 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: findWiredInUnits - - - - - a444d01b by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: reportCycles, reportUnusable - - - - - 8408d521 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: merge_databases - - - - - fca2d25f by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: add UnitConfig datatype Avoid directly querying flags from DynFlags to build the UnitState. Instead go via UnitConfig so that we could reuse this to make another UnitState for plugins. - - - - - 4274688a by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move distrustAll into mkUnitState - - - - - 28d804e1 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Create helper upd_wired_in_home_instantiations - - - - - ac964c83 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Put database cache in UnitConfig - - - - - bfd0a78c by Sylvain Henry at 2020-06-13T02:13:03-04:00 Don't return preload units when we set DyNFlags Preload units can be retrieved in UnitState when needed (i.e. in GHCi) - - - - - 1fbb4bf5 by Sylvain Henry at 2020-06-13T02:13:03-04:00 NCGConfig: remove useless ncgUnitId field - - - - - c10ff7e7 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Doc: fix some comments - - - - - 456e17f0 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Bump haddock submodule and allow metric decrease Metric Decrease: T12150 T12234 T5837 Metric Increase: T16190 - - - - - 42953902 by Simon Peyton Jones at 2020-06-13T02:13:03-04:00 Trim the demand for recursive product types Ticket #18304 showed that we need to be very careful when exploring the demand (esp usage demand) on recursive product types. This patch solves the problem by trimming the demand on such types -- in effect, a form of "widening". See the Note [Trimming a demand to a type] in DmdAnal, which explains how I did this by piggy-backing on an existing mechansim for trimming demands becuase of GADTs. The significant payload of this patch is very small indeed: * Make GHC.Core.Opt.WorkWrap.Utils.typeShape use RecTcChecker to avoid looking through recursive types. But on the way * I found that ae_rec_tc was entirely inoperative and did nothing. So I removed it altogether from DmdAnal. * I moved some code around in DmdAnal and Demand. (There are no actual changes in dmdFix.) * I changed the API of DmsAnal.dmdAnalRhsLetDown to return a StrictSig rather than a decorated Id * I removed the dead function peelTsFuns from Demand Performance effects: Nofib: 0.0% changes. Not surprising, because they don't use recursive products Perf tests T12227: 1% increase in compiler allocation, becuase $cto gets w/w'd. It did not w/w before because it takes a deeply nested argument, so the worker gets too many args, so we abandon w/w altogether (see GHC.Core.Opt.WorkWrap.Utils.isWorkerSmallEnough) With this patch we trim the demands. That is not strictly necessary (since these Generic type constructors are like tuples -- they can't cause a loop) but the net result is that we now w/w $cto which is fine. UniqLoop: 16% decrease in /runtime/ allocation. The UniqSupply is a recursive product, so currently we abandon all strictness on 'churn'. With this patch 'churn' gets useful strictness, and we w/w it. Hooray Metric Decrease: UniqLoop Metric Increase: T12227 - - - - - 87d504f4 by Viktor Dukhovni at 2020-06-13T02:13:05-04:00 Add introductory prose for Data.Traversable - - - - - 9f09b608 by Oleg Grenrus at 2020-06-13T02:13:07-04:00 Fix #12073: Add MonadFix Q instance - - - - - 220c2d34 by Ben Gamari at 2020-06-13T02:13:07-04:00 testsuite: Increase size of T12150 As noted in #18319, this test was previously very fragile. Increase its size to make it more likely that its fails with its newly-increased acceptance threshold. Metric Increase: T12150 - - - - - 8bba1c26 by Ben Gamari at 2020-06-13T04:59:06-04:00 gitlab-ci: Always push perf notes Previously we ci.sh would run with `set -e` implying that we wouldn't push perf notes if the testsuite were to fail, even if it *only* failed due to perf notes. This rendered the whole performance testing story quite fragile as a single regressing commit would cause every successive commit to fail since a new baseline would not be uploaded. Fix this by ensuring that we always push performance notes. - - - - - 7a773f16 by Ben Gamari at 2020-06-13T15:10:55-04:00 gitlab-ci: Eliminate redundant push of CI metrics - - - - - a31218f7 by Ryan Scott at 2020-06-13T15:58:37-04:00 Use HsForAllTelescope to avoid inferred, visible foralls Currently, `HsForAllTy` permits the combination of `ForallVis` and `Inferred`, but you can't actually typecheck code that uses it (e.g., `forall {a} ->`). This patch refactors `HsForAllTy` to use a new `HsForAllTelescope` data type that makes a type-level distinction between visible and invisible `forall`s such that visible `forall`s do not track `Specificity`. That part of the patch is actually quite small; the rest is simply changing consumers of `HsType` to accommodate this new type. Fixes #18235. Bumps the `haddock` submodule. - - - - - c0e6dee9 by Tamar Christina at 2020-06-14T09:07:44-04:00 winio: Add Atomic Exchange PrimOp and implement Atomic Ptr exchanges. The initial version was rewritten by Tamar Christina. It was rewritten in large parts by Andreas Klebinger. Co-authored-by: Andreas Klebinger <klebinger.andreas at gmx.at> - - - - - 9a7462fb by Ben Gamari at 2020-06-14T15:35:23-04:00 codeGen: Don't discard live case binders in unsafeEqualityProof logic Previously CoreToStg would unconditionally discard cases of the form: case unsafeEqualityProof of wild { _ -> rhs } and rather replace the whole thing with `rhs`. However, in some cases (see #18227) the case binder is still live, resulting in unbound occurrences in `rhs`. Fix this by only discarding the case if the case binder is dead. Fixes #18227. - - - - - e4137c48 by Ben Gamari at 2020-06-14T15:35:23-04:00 testsuite: Add tests for #18227 T18227A is the original issue which gave rise to the ticket and depends upon bytestring. T18227B is a minimized reproducer. - - - - - 8bab9ff1 by Ben Gamari at 2020-06-14T15:35:59-04:00 hadrian: Fix rts include and library paths Fixes two bugs: * (?) and (<>) associated in a surprising way * We neglected to include libdw paths in the rts configure flags - - - - - bd761185 by Ben Gamari at 2020-06-14T15:35:59-04:00 hadrian: Drop redundant GHC arguments Cabal should already be passing this arguments to GHC. - - - - - 01f7052c by Peter Trommler at 2020-06-14T15:36:38-04:00 FFI: Fix pass small ints in foreign call wrappers The Haskell calling convention requires integer parameters smaller than wordsize to be promoted to wordsize (where the upper bits are don't care). To access such small integer parameter read a word from the parameter array and then cast that word to the small integer target type. Fixes #15933 - - - - - 502647f7 by Krzysztof Gogolewski at 2020-06-14T15:37:14-04:00 Fix "ndecreasingIndentation" in manual (#18116) - - - - - 9a9cc089 by Simon Jakobi at 2020-06-15T13:10:00-04:00 Use foldl' in unionManyUniqDSets - - - - - 761dcb84 by Moritz Angermann at 2020-06-15T13:10:36-04:00 Load .lo as well. Some archives contain so called linker objects, with the affectionate .lo suffic. For example the musl libc.a will come in that form. We still want to load those objects, hence we should not discard them and look for .lo as well. Ultimately we might want to fix this proerly by looking at the file magic. - - - - - cf01477f by Vladislav Zavialov at 2020-06-15T13:11:20-04:00 User's Guide: KnownNat evidence is Natural This bit of documentation got outdated after commit 1fcede43d2b30f33b7505e25eb6b1f321be0407f - - - - - d0dcbfe6 by Jan Hrček at 2020-06-16T20:36:38+02:00 Fix typos and formatting in user guide - - - - - 56a9e95f by Jan Hrček at 2020-06-16T20:36:38+02:00 Resolve TODO - - - - - 3e884d14 by Jan Hrček at 2020-06-16T20:36:38+02:00 Rename TcHoleErrors to GHC.Tc.Errors.Hole - - - - - d23fc678 by Stefan Schulze Frielinghaus at 2020-06-17T15:31:09-04:00 hadrian: Build with threaded runtime if available See #16873. - - - - - 0639dc10 by Sylvain Henry at 2020-06-17T15:31:53-04:00 T16190: only measure bytes_allocated Just adding `{-# LANGUAGE BangPatterns #-}` makes the two other metrics fluctuate by 13%. - - - - - 4cab6897 by Adam Sandberg Ericsson at 2020-06-17T15:32:44-04:00 docs: fix formatting in users guide - - - - - eb8115a8 by Sylvain Henry at 2020-06-17T15:33:23-04:00 Move CLabel assertions into smart constructors (#17957) It avoids using DynFlags in the Outputable instance of Clabel to check assertions at pretty-printing time. - - - - - 7faa4509 by Ben Gamari at 2020-06-17T15:43:31-04:00 base: Bump to 4.15.0.0 - - - - - 20616959 by Ben Gamari at 2020-06-17T15:43:31-04:00 configure: Use grep -q instead of --quiet The latter is apparently not supported by busybox. - - - - - 40fa237e by Krzysztof Gogolewski at 2020-06-17T16:21:58-04:00 Linear types (#15981) This is the first step towards implementation of the linear types proposal (https://github.com/ghc-proposals/ghc-proposals/pull/111). It features * A language extension -XLinearTypes * Syntax for linear functions in the surface language * Linearity checking in Core Lint, enabled with -dlinear-core-lint * Core-to-core passes are mostly compatible with linearity * Fields in a data type can be linear or unrestricted; linear fields have multiplicity-polymorphic constructors. If -XLinearTypes is disabled, the GADT syntax defaults to linear fields The following items are not yet supported: * a # m -> b syntax (only prefix FUN is supported for now) * Full multiplicity inference (multiplicities are really only checked) * Decent linearity error messages * Linear let, where, and case expressions in the surface language (each of these currently introduce the unrestricted variant) * Multiplicity-parametric fields * Syntax for annotating lambda-bound or let-bound with a multiplicity * Syntax for non-linear/multiple-field-multiplicity records * Linear projections for records with a single linear field * Linear pattern synonyms * Multiplicity coercions (test LinearPolyType) A high-level description can be found at https://ghc.haskell.org/trac/ghc/wiki/LinearTypes/Implementation Following the link above you will find a description of the changes made to Core. This commit has been authored by * Richard Eisenberg * Krzysztof Gogolewski * Matthew Pickering * Arnaud Spiwack With contributions from: * Mark Barbone * Alexander Vershilov Updates haddock submodule. - - - - - 6cb84c46 by Krzysztof Gogolewski at 2020-06-17T16:22:03-04:00 Various performance improvements This implements several general performance improvements to GHC, to offset the effect of the linear types change. General optimisations: - Add a `coreFullView` function which iterates `coreView` on the head. This avoids making function recursive solely because the iterate `coreView` themselves. As a consequence, this functions can be inlined, and trigger case-of-known constructor (_e.g._ `kindRep_maybe`, `isLiftedRuntimeRep`, `isMultiplicityTy`, `getTyVar_maybe`, `splitAppTy_maybe`, `splitFunType_maybe`, `tyConAppTyCon_maybe`). The common pattern about all these functions is that they are almost always used as views, and immediately consumed by a case expression. This commit also mark them asx `INLINE`. - In `subst_ty` add a special case for nullary `TyConApp`, which avoid allocations altogether. - Use `mkTyConApp` in `subst_ty` for the general `TyConApp`. This required quite a bit of module shuffling. case. `myTyConApp` enforces crucial sharing, which was lost during substitution. See also !2952 . - Make `subst_ty` stricter. - In `eqType` (specifically, in `nonDetCmpType`), add a special case, tested first, for the very common case of nullary `TyConApp`. `nonDetCmpType` has been made `INLINE` otherwise it is actually a regression. This is similar to the optimisations in !2952. Linear-type specific optimisations: - Use `tyConAppTyCon_maybe` instead of the more complex `eqType` in the definition of the pattern synonyms `One` and `Many`. - Break the `hs-boot` cycles between `Multiplicity.hs` and `Type.hs`: `Multiplicity` now import `Type` normally, rather than from the `hs-boot`. This way `tyConAppTyCon_maybe` can inline properly in the `One` and `Many` pattern synonyms. - Make `updateIdTypeAndMult` strict in its type and multiplicity - The `scaleIdBy` gets a specialised definition rather than being an alias to `scaleVarBy` - `splitFunTy_maybe` is given the type `Type -> Maybe (Mult, Type, Type)` instead of `Type -> Maybe (Scaled Type, Type)` - Remove the `MultMul` pattern synonym in favour of a view `isMultMul` because pattern synonyms appear not to inline well. - in `eqType`, in a `FunTy`, compare multiplicities last: they are almost always both `Many`, so it helps failing faster. - Cache `manyDataConTy` in `mkTyConApp`, to make sure that all the instances of `TyConApp ManyDataConTy []` are physically the same. This commit has been authored by * Richard Eisenberg * Krzysztof Gogolewski * Arnaud Spiwack Metric Decrease: haddock.base T12227 T12545 T12990 T1969 T3064 T5030 T9872b Metric Increase: haddock.base haddock.Cabal haddock.compiler T12150 T12234 T12425 T12707 T13035 T13056 T15164 T16190 T18304 T1969 T3064 T3294 T5631 T5642 T5837 T6048 T9020 T9233 T9675 T9872a T9961 WWRec - - - - - 57db91d8 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Remove integer-simple integer-simple uses lists of words (`[Word]`) to represent big numbers instead of ByteArray#: * it is less efficient than the newer ghc-bignum native backend * it isn't compatible with the big number representation that is now shared by all the ghc-bignum backends (based on the one that was used only in integer-gmp before). As a consequence, we simply drop integer-simple - - - - - 9f96bc12 by Sylvain Henry at 2020-06-17T16:22:03-04:00 ghc-bignum library ghc-bignum is a newer package that aims to replace the legacy integer-simple and integer-gmp packages. * it supports several backends. In particular GMP is still supported and most of the code from integer-gmp has been merged in the "gmp" backend. * the pure Haskell "native" backend is new and is much faster than the previous pure Haskell implementation provided by integer-simple * new backends are easier to write because they only have to provide a few well defined functions. All the other code is common to all backends. In particular they all share the efficient small/big number distinction previously used only in integer-gmp. * backends can all be tested against the "native" backend with a simple Cabal flag. Backends are only allowed to differ in performance, their results should be the same. * Add `integer-gmp` compat package: provide some pattern synonyms and function aliases for those in `ghc-bignum`. It is intended to avoid breaking packages that depend on `integer-gmp` internals. Update submodules: text, bytestring Metric Decrease: Conversions ManyAlternatives ManyConstructors Naperian T10359 T10547 T10678 T12150 T12227 T12234 T12425 T13035 T13719 T14936 T1969 T4801 T4830 T5237 T5549 T5837 T8766 T9020 parsing001 space_leak_001 T16190 haddock.base On ARM and i386, T17499 regresses (+6% > 5%). On x86_64 unregistered, T13701 sometimes regresses (+2.2% > 2%). Metric Increase: T17499 T13701 - - - - - 96aa5787 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update compiler Thanks to ghc-bignum, the compiler can be simplified: * Types and constructors of Integer and Natural can be wired-in. It means that we don't have to query them from interfaces. It also means that numeric literals don't have to carry their type with them. * The same code is used whatever ghc-bignum backend is enabled. In particular, conversion of bignum literals into final Core expressions is now much more straightforward. Bignum closure inspection too. * GHC itself doesn't depend on any integer-* package anymore * The `integerLibrary` setting is gone. - - - - - 0f67e344 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update `base` package * GHC.Natural isn't implemented in `base` anymore. It is provided by ghc-bignum in GHC.Num.Natural. It means that we can safely use Natural primitives in `base` without fearing issues with built-in rewrite rules (cf #15286) * `base` doesn't conditionally depend on an integer-* package anymore, it depends on ghc-bignum * Some duplicated code in integer-* can now be factored in GHC.Float * ghc-bignum tries to use a uniform naming convention so most of the other changes are renaming - - - - - aa9e7b71 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update `make` based build system * replace integer-* package selection with ghc-bignum backend selection - - - - - f817d816 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Update testsuite * support detection of slow ghc-bignum backend (to replace the detection of integer-simple use). There are still some test cases that the native backend doesn't handle efficiently enough. * remove tests for GMP only functions that have been removed from ghc-bignum * fix test results showing dependent packages (e.g. integer-gmp) or showing suggested instances * fix test using Integer/Natural API or showing internal names - - - - - dceecb09 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Update Hadrian * support ghc-bignum backend selection in flavours and command-line * support ghc-bignum "--check" flag (compare results of selected backend against results of the native one) in flavours and command-line (e.g. pass --bignum=check-gmp" to check the "gmp" backend) * remove the hack to workaround #15286 * build GMP only when the gmp backend is used * remove hacks to workaround `text` package flags about integer-*. We fix `text` to use ghc-bignum unconditionally in another patch - - - - - fa4281d6 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Bump bytestring and text submodules - - - - - 1a3f6f34 by Adam Sandberg Ericsson at 2020-06-18T23:03:36-04:00 docs: mention -hiedir in docs for -outputdir [skip ci] - - - - - 729bcb02 by Sylvain Henry at 2020-06-18T23:04:17-04:00 Hadrian: fix build on Mac OS Catalina (#17798) - - - - - 95e18292 by Andreas Klebinger at 2020-06-18T23:04:58-04:00 Relax allocation threshold for T12150. This test performs little work, so the most minor allocation changes often cause the test to fail. Increasing the threshold to 2% should help with this. - - - - - 8ce6c393 by Sebastian Graf at 2020-06-18T23:05:36-04:00 hadrian: Bump pinned cabal.project to an existent index-state - - - - - 08c1cb0f by Ömer Sinan Ağacan at 2020-06-18T23:06:21-04:00 Fix uninitialized field read in Linker.c Valgrind report of the bug when running the test `linker_unload`: ==29666== Conditional jump or move depends on uninitialised value(s) ==29666== at 0x369C5B4: setOcInitialStatus (Linker.c:1305) ==29666== by 0x369C6C5: mkOc (Linker.c:1347) ==29666== by 0x36C027A: loadArchive_ (LoadArchive.c:522) ==29666== by 0x36C0600: loadArchive (LoadArchive.c:626) ==29666== by 0x2C144CD: ??? (in /home/omer/haskell/ghc_2/testsuite/tests/rts/linker/linker_unload.run/linker_unload) ==29666== ==29666== Conditional jump or move depends on uninitialised value(s) ==29666== at 0x369C5B4: setOcInitialStatus (Linker.c:1305) ==29666== by 0x369C6C5: mkOc (Linker.c:1347) ==29666== by 0x369C9F6: preloadObjectFile (Linker.c:1507) ==29666== by 0x369CA8D: loadObj_ (Linker.c:1536) ==29666== by 0x369CB17: loadObj (Linker.c:1557) ==29666== by 0x3866BC: main (linker_unload.c:33) The problem is `mkOc` allocates a new `ObjectCode` and calls `setOcInitialStatus` without initializing the `status` field. `setOcInitialStatus` reads the field as first thing: static void setOcInitialStatus(ObjectCode* oc) { if (oc->status == OBJECT_DONT_RESOLVE) return; if (oc->archiveMemberName == NULL) { oc->status = OBJECT_NEEDED; } else { oc->status = OBJECT_LOADED; } } `setOcInitialStatus` is unsed in two places for two different purposes: in `mkOc` where we don't have the `status` field initialized yet (`mkOc` is supposed to initialize it), and `loadOc` where we do have `status` field initialized and we want to update it. Instead of splitting the function into two functions which are both called just once I inline the functions in the use sites and remove it. Fixes #18342 - - - - - da18ff99 by Tamar Christina at 2020-06-18T23:07:03-04:00 fix windows bootstrap due to linker changes - - - - - 2af0ec90 by Sylvain Henry at 2020-06-18T23:07:47-04:00 DynFlags: store default depth in SDocContext (#17957) It avoids having to use DynFlags to reach for pprUserLength. - - - - - d4a0be75 by Sylvain Henry at 2020-06-18T23:08:35-04:00 Move tablesNextToCode field into Platform tablesNextToCode is a platform setting and doesn't belong into DynFlags (#17957). Doing this is also a prerequisite to fix #14335 where we deal with two platforms (target and host) that may have different platform settings. - - - - - 809caedf by John Ericson at 2020-06-23T22:47:37-04:00 Switch from HscSource to IsBootInterface for module lookup in GhcMake We look up modules by their name, and not their contents. There is no way to separately reference a signature vs regular module; you get what you get. Only boot files can be referenced indepenently with `import {-# SOURCE #-}`. - - - - - 7750bd45 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Cmm: introduce SAVE_REGS/RESTORE_REGS We don't want to save both Fn and Dn register sets on x86-64 as they are aliased to the same arch register (XMMn). Moreover, when SAVE_STGREGS was used in conjunction with `jump foo [*]` which makes a set of Cmm registers alive so that they cover all arch registers used to pass parameter, we could have Fn, Dn and XMMn alive at the same time. It made the LLVM code generator choke (see #17920). Now `SAVE_REGS/RESTORE_REGS` and `jump foo [*]` use the same set of registers. - - - - - 2636794d by Sylvain Henry at 2020-06-23T22:48:18-04:00 CmmToC: don't add extern decl to parsed Cmm data Previously, if a .cmm file *not in the RTS* contained something like: ```cmm section "rodata" { msg : bits8[] "Test\n"; } ``` It would get compiled by CmmToC into: ```c ERW_(msg); const char msg[] = "Test\012"; ``` and fail with: ``` /tmp/ghc32129_0/ghc_4.hc:5:12: error: error: conflicting types for \u2018msg\u2019 const char msg[] = "Test\012"; ^~~ In file included from /tmp/ghc32129_0/ghc_4.hc:3:0: error: /tmp/ghc32129_0/ghc_4.hc:4:6: error: note: previous declaration of \u2018msg\u2019 was here ERW_(msg); ^ /builds/hsyl20/ghc/_build/install/lib/ghc-8.11.0.20200605/lib/../lib/x86_64-linux-ghc-8.11.0.20200605/rts-1.0/include/Stg.h:253:46: error: note: in definition of macro \u2018ERW_\u2019 #define ERW_(X) extern StgWordArray (X) ^ ``` See the rationale for this on https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/backends/ppr-c#prototypes Now we don't generate these extern declarations (ERW_, etc.) for top-level data. It shouldn't change anything for the RTS (the only place we use .cmm files) as it is already special cased in `GHC.Cmm.CLabel.needsCDecl`. And hand-written Cmm can use explicit extern declarations when needed. Note that it allows `cgrun069` test to pass with CmmToC (cf #15467). - - - - - 5f6a0665 by Sylvain Henry at 2020-06-23T22:48:18-04:00 LLVM: refactor and comment register padding code (#17920) - - - - - cad62ef1 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Add tests for #17920 Metric Decrease: T12150 T12234 - - - - - a2a9006b by Xavier Denis at 2020-06-23T22:48:56-04:00 Fix issue #18262 by zonking constraints after solving Zonk residual constraints in checkForExistence to reveal user type errors. Previously when `:instances` was used with instances that have TypeError constraints the result would look something like: instance [safe] s0 => Err 'A -- Defined at ../Bug2.hs:8:10 whereas after zonking, `:instances` now sees the `TypeError` and properly eliminates the constraint from the results. - - - - - 181516bc by Simon Peyton Jones at 2020-06-23T22:49:33-04:00 Fix a buglet in Simplify.simplCast This bug, revealed by #18347, is just a missing update to sc_hole_ty in simplCast. I'd missed a code path when I made the recentchanges in commit 6d49d5be904c0c01788fa7aae1b112d5b4dfaf1c Author: Simon Peyton Jones <simonpj at microsoft.com> Date: Thu May 21 12:53:35 2020 +0100 Implement cast worker/wrapper properly The fix is very easy. Two other minor changes * Tidy up in SimpleOpt.simple_opt_expr. In fact I think this is an outright bug, introduced in the fix to #18112: we were simplifying the same coercion twice *with the same substitution*, which is just wrong. It'd be a hard bug to trigger, so I just fixed it; less code too. * Better debug printing of ApplyToVal - - - - - 625a7f54 by Simon Peyton Jones at 2020-06-23T22:50:11-04:00 Two small tweaks to Coercion.simplifyArgsWorker These tweaks affect the inner loop of simplifyArgsWorker, which in turn is called from the flattener in Flatten.hs. This is a key perf bottleneck to T9872{a,b,c,d}. These two small changes have a modest but useful benefit. No change in functionality whatsoever. Relates to #18354 - - - - - b5768cce by Sylvain Henry at 2020-06-23T22:50:49-04:00 Don't use timesInt2# with GHC < 8.11 (fix #18358) - - - - - 7ad4085c by Sylvain Henry at 2020-06-23T22:51:27-04:00 Fix invalid printf format - - - - - a1f34d37 by Krzysztof Gogolewski at 2020-06-23T22:52:09-04:00 Add missing entry to freeNamesItem (#18369) - - - - - 03a708ba by Andreas Klebinger at 2020-06-25T03:54:37-04:00 Enable large address space optimization on windows. Starting with Win 8.1/Server 2012 windows no longer preallocates page tables for reserverd memory eagerly, which prevented us from using this approach in the past. We also try to allocate the heap high in the memory space. Hopefully this makes it easier to allocate things in the low 4GB of memory that need to be there. Like jump islands for the linker. - - - - - 7e6d3d09 by Roland Senn at 2020-06-25T03:54:38-04:00 In `:break ident` allow out of scope and nested identifiers (Fix #3000) This patch fixes the bug and implements the feature request of #3000. 1. If `Module` is a real module name and `identifier` a name of a top-level function in `Module` then `:break Module.identifer` works also for an `identifier` that is out of scope. 2. Extend the syntax for `:break identifier` to: :break [ModQual.]topLevelIdent[.nestedIdent]...[.nestedIdent] `ModQual` is optional and is either the effective name of a module or the local alias of a qualified import statement. `topLevelIdent` is the name of a top level function in the module referenced by `ModQual`. `nestedIdent` is optional and the name of a function nested in a let or where clause inside the previously mentioned function `nestedIdent` or `topLevelIdent`. If `ModQual` is a module name, then `topLevelIdent` can be any top level identifier in this module. If `ModQual` is missing or a local alias of a qualified import, then `topLevelIdent` must be in scope. Breakpoints can be set on arbitrarily deeply nested functions, but the whole chain of nested function names must be specified. 3. To support the new functionality rewrite the code to tab complete `:break`. - - - - - 30e42652 by Ben Gamari at 2020-06-25T03:54:39-04:00 make: Respect XELATEX variable Previously we simply ignored the XELATEX variable when building PDF documentation. - - - - - 4acc2934 by Ben Gamari at 2020-06-25T03:54:39-04:00 hadrian/make: Detect makeindex Previously we would simply assume that makeindex was available. Now we correctly detect it in `configure` and respect this conclusion in hadrian and make. - - - - - 0d61f866 by Simon Peyton Jones at 2020-06-25T03:54:40-04:00 Expunge GhcTcId GHC.Hs.Extension had type GhcPs = GhcPass 'Parsed type GhcRn = GhcPass 'Renamed type GhcTc = GhcPass 'Typechecked type GhcTcId = GhcTc The last of these, GhcTcId, is a vestige of the past. This patch expunges it from GHC. - - - - - 8ddbed4a by Adam Wespiser at 2020-06-25T03:54:40-04:00 add examples to Data.Traversable - - - - - 284001d0 by Oleg Grenrus at 2020-06-25T03:54:42-04:00 Export readBinIface_ - - - - - 90f43872 by Zubin Duggal at 2020-06-25T03:54:43-04:00 Export everything from HsToCore. This lets us reuse these functions in haddock, avoiding synchronization bugs. Also fixed some divergences with haddock in that file Updates haddock submodule - - - - - c7dd6da7 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part1) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Hs.* - GHC.Core.* - GHC.Stg.* - GHC.Cmm.* - GHC.Types.* - GHC.Data.* - GHC.Builtin.* - GHC.Parser.* - GHC.Driver.* - GHC top - - - - - 1eb997a8 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part2) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Iface.* - GHC.Llvm.* - GHC.Rename.* - GHC.Tc.* - GHC.HsToCore.* - GHC.StgToCmm.* - GHC.CmmToAsm.* - GHC.Runtime.* - GHC.Unit.* - GHC.Utils.* - GHC.SysTools.* - - - - - 67a86b4d by Oleg Grenrus at 2020-06-25T03:54:46-04:00 Add MonadZip and MonadFix instances for Complex These instances are taken from https://hackage.haskell.org/package/linear-1.21/docs/Linear-Instances.html They are the unique possible, so let they be in `base`. - - - - - c50ef26e by Artem Pelenitsyn at 2020-06-25T03:54:47-04:00 test suite: add reproducer for #17516 - - - - - fe281b27 by Roland Senn at 2020-06-25T03:54:48-04:00 Enable maxBound checks for OverloadedLists (Fixes #18172) Consider the Literal `[256] :: [Data.Word.Word8]` When the `OverloadedLists` extension is not active, then the `ol_ext` field in the `OverLitTc` record that is passed to the function `getIntegralLit` contains the type `Word8`. This is a simple type, and we can use its type constructor immediately for the `warnAboutOverflowedLiterals` function. When the `OverloadedLists` extension is active, then the `ol_ext` field contains the type family `Item [Word8]`. The function `nomaliseType` is used to convert it to the needed type `Word8`. - - - - - a788d4d1 by Ben Gamari at 2020-06-25T03:54:52-04:00 rts/Hash: Simplify freeing of HashListChunks While looking at #18348 I noticed that the treatment of HashLists are a bit more complex than necessary (which lead to some initial confusion on my part). Specifically, we allocate HashLists in chunks. Each chunk allocation makes two allocations: one for the chunk itself and one for a HashListChunk to link together the chunks for the purposes of freeing. Simplify this (and hopefully make the relationship between these clearer) but allocating the HashLists and HashListChunk in a single malloc. This will both make the implementation easier to follow and reduce C heap fragmentation. Note that even after this patch we fail to bound the size of the free HashList pool. However, this is a separate bug. - - - - - d3c2d59b by Sylvain Henry at 2020-06-25T03:54:55-04:00 RTS: avoid overflow on 32-bit arch (#18375) We're now correctly computing allocated bytes on 32-bit arch, so we get huge increases. Metric Increase: haddock.Cabal haddock.base haddock.compiler space_leak_001 - - - - - a3d69dc6 by Sebastian Graf at 2020-06-25T23:06:18-04:00 GHC.Core.Unify: Make UM actions one-shot by default This MR makes the UM monad in GHC.Core.Unify into a one-shot monad. See the long Note [The one-shot state monad trick]. See also #18202 and !3309, which applies this to all Reader/State-like monads in GHC for compile-time perf improvements. The pattern used here enables something similar to the state-hack, but is applicable to user-defined monads, not just `IO`. Metric Decrease 'runtime/bytes allocated' (test_env='i386-linux-deb9'): haddock.Cabal - - - - - 9ee58f8d by Matthias Pall Gissurarson at 2020-06-26T17:12:45+00:00 Implement the proposed -XQualifiedDo extension Co-authored-by: Facundo Domínguez <facundo.dominguez at tweag.io> QualifiedDo is implemented using the same placeholders for operation names in the AST that were devised for RebindableSyntax. Whenever the renamer checks which names to use for do syntax, it first checks if the do block is qualified (e.g. M.do { stmts }), in which case it searches for qualified names in the module M. This allows users to write {-# LANGUAGE QualifiedDo #-} import qualified SomeModule as M f x = M.do -- desugars to: y <- M.return x -- M.return x M.>>= \y -> M.return y -- M.return y M.>> M.return y -- M.return y See Note [QualifiedDo] and the users' guide for more details. Issue #18214 Proposal: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0216-qualified-do.rst Since we change the constructors `ITdo` and `ITmdo` to carry the new module name, we need to bump the haddock submodule to account or the new shape of these constructors. - - - - - ce987865 by Ryan Scott at 2020-06-27T11:55:21-04:00 Revamp the treatment of auxiliary bindings for derived instances This started as a simple fix for #18321 that organically grew into a much more sweeping refactor of how auxiliary bindings for derived instances are handled. I have rewritten `Note [Auxiliary binders]` in `GHC.Tc.Deriv.Generate` to explain all of the moving parts, but the highlights are: * Previously, the OccName of each auxiliary binding would be given a suffix containing a hash of its package name, module name, and parent data type to avoid name clashes. This was needlessly complicated, so we take the more direct approach of generating `Exact` `RdrName`s for each auxiliary binding with the same `OccName`, but using an underlying `System` `Name` with a fresh `Unique` for each binding. Unlike hashes, allocating new `Unique`s does not require any cleverness and avoid name clashes all the same... * ...speaking of which, in order to convince the renamer that multiple auxiliary bindings with the same `OccName` (but different `Unique`s) are kosher, we now use `rnLocalValBindsLHS` instead of `rnTopBindsLHS` to rename auxiliary bindings. Again, see `Note [Auxiliary binders]` for the full story. * I have removed the `DerivHsBind` constructor for `DerivStuff`—which was only used for `Data.Data`-related auxiliary bindings—and refactored `gen_Data_binds` to use `DerivAuxBind` instead. This brings the treatment of `Data.Data`-related auxiliary bindings in line with every other form of auxiliary binding. Fixes #18321. - - - - - a403eb91 by Sylvain Henry at 2020-06-27T11:55:59-04:00 ghc-bignum: fix division by zero (#18359) - - - - - 1b3d13b6 by Sylvain Henry at 2020-06-27T11:55:59-04:00 Fix ghc-bignum exceptions We must ensure that exceptions are not simplified. Previously we used: case raiseDivZero of _ -> 0## -- dummyValue But it was wrong because the evaluation of `raiseDivZero` was removed and the dummy value was directly returned. See new Note [ghc-bignum exceptions]. I've also removed the exception triggering primops which were fragile. We don't need them to be primops, we can have them exported by ghc-prim. I've also added a test for #18359 which triggered this patch. - - - - - a74ec37c by Simon Peyton Jones at 2020-06-27T11:56:34-04:00 Better loop detection in findTypeShape Andreas pointed out, in !3466, that my fix for #18304 was not quite right. This patch fixes it properly, by having just one RecTcChecker rather than (implicitly) two nested ones, in findTypeShape. - - - - - a04020b8 by Sylvain Henry at 2020-06-27T11:57:11-04:00 DynFlags: don't store buildTag `DynFlags.buildTag` was a field created from the set of Ways in `DynFlags.ways`. It had to be kept in sync with `DynFlags.ways` which was fragile. We want to avoid global state like this (#17957). Moreover in #14335 we also want to support loading units with different ways: target units would still use `DynFlags.ways` but plugins would use `GHC.Driver.Ways.hostFullWays`. To avoid having to deal both with build tag and with ways, we recompute the buildTag on-the-fly (should be pretty cheap) and we remove `DynFlags.buildTag` field. - - - - - 0e83efa2 by Krzysztof Gogolewski at 2020-06-27T11:57:49-04:00 Don't generalize when typechecking a tuple section The code is simpler and cleaner. - - - - - d8ba9e6f by Peter Trommler at 2020-06-28T09:19:11-04:00 RTS: Refactor Haskell-C glue for PPC 64-bit Make sure the stack is 16 byte aligned even when reserved stack bytes are not a multiple of 16 bytes. Avoid saving r2 (TOC). On ELF v1 the function descriptor of StgReturn has the same TOC as StgRun, on ELF v2 the TOC is recomputed in the function prologue. Use the ABI provided functions to save clobbered GPRs and FPRs. Improve comments. Describe what the stack looks like and how it relates to the respective ABIs. - - - - - 42f797b0 by Ryan Scott at 2020-06-28T09:19:46-04:00 Use NHsCoreTy to embed types into GND-generated code `GeneralizedNewtypeDeriving` is in the unique situation where it must produce an `LHsType GhcPs` from a Core `Type`. Historically, this was done with the `typeToLHsType` function, which walked over the entire `Type` and attempted to construct an `LHsType` with the same overall structure. `typeToLHsType` is quite complicated, however, and has been the subject of numerous bugs over the years (e.g., #14579). Luckily, there is an easier way to accomplish the same thing: the `XHsType` constructor of `HsType`. `XHsType` bundles an `NHsCoreTy`, which allows embedding a Core `Type` directly into an `HsType`, avoiding the need to laboriously convert from one to another (as `typeToLHsType` did). Moreover, renaming and typechecking an `XHsType` is simple, since one doesn't need to do anything to a Core `Type`... ...well, almost. For the reasons described in `Note [Typechecking NHsCoreTys]` in `GHC.Tc.Gen.HsType`, we must apply a substitution that we build from the local `tcl_env` type environment. But that's a relatively modest price to pay. Now that `GeneralizedNewtypeDeriving` uses `NHsCoreTy`, the `typeToLHsType` function no longer has any uses in GHC, so this patch rips it out. Some additional tweaks to `hsTypeNeedsParens` were necessary to make the new `-ddump-deriv` output correctly parenthesized, but other than that, this patch is quite straightforward. This is a mostly internal refactoring, although it is likely that `GeneralizedNewtypeDeriving`-generated code will now need fewer language extensions in certain situations than it did before. - - - - - 68530b1c by Jan Hrček at 2020-06-28T09:20:22-04:00 Fix duplicated words and typos in comments and user guide - - - - - 15b79bef by Ryan Scott at 2020-06-28T09:20:57-04:00 Add integer-gmp's ghc.mk and GNUmakefile to .gitignore - - - - - bfa5698b by Simon Peyton Jones at 2020-06-28T09:21:32-04:00 Fix a typo in Lint This simple error in GHC.Core.Litn.lintJoinLams meant that Lint reported bogus errors. Fixes #18399 - - - - - 71006532 by Ryan Scott at 2020-06-30T07:10:42-04:00 Reject nested foralls/contexts in instance types more consistently GHC is very wishy-washy about rejecting instance declarations with nested `forall`s or contexts that are surrounded by outermost parentheses. This can even lead to some strange interactions with `ScopedTypeVariables`, as demonstrated in #18240. This patch makes GHC more consistently reject instance types with nested `forall`s/contexts so as to prevent these strange interactions. On the implementation side, this patch tweaks `splitLHsInstDeclTy` and `getLHsInstDeclHead` to not look through parentheses, which can be semantically significant. I've added a `Note [No nested foralls or contexts in instance types]` in `GHC.Hs.Type` to explain why. This also introduces a `no_nested_foralls_contexts_err` function in `GHC.Rename.HsType` to catch nested `forall`s/contexts in instance types. This function is now used in `rnClsInstDecl` (for ordinary instance declarations) and `rnSrcDerivDecl` (for standalone `deriving` declarations), the latter of which fixes #18271. On the documentation side, this adds a new "Formal syntax for instance declaration types" section to the GHC User's Guide that presents a BNF-style grammar for what is and isn't allowed in instance types. Fixes #18240. Fixes #18271. - - - - - bccf3351 by Sylvain Henry at 2020-06-30T07:10:46-04:00 Add ghc-bignum to 8.12 release notes - - - - - 81704a6f by David Eichmann at 2020-06-30T07:10:48-04:00 Update ssh keys in CI performance metrics upload script - - - - - 85310fb8 by Joshua Price at 2020-06-30T07:10:49-04:00 Add missing Ix instances for tuples of size 6 through 15 (#16643) - - - - - cbb6b62f by Vladislav Zavialov at 2020-07-01T15:41:38-04:00 Implement -XLexicalNegation (GHC Proposal #229) This patch introduces a new extension, -XLexicalNegation, which detects whether the minus sign stands for negation or subtraction using the whitespace-based rules described in GHC Proposal #229. Updates haddock submodule. - - - - - fb5a0d01 by Martin Handley at 2020-07-01T15:42:14-04:00 #17169: Clarify Fixed's Enum instance. - - - - - b316804d by Simon Peyton Jones at 2020-07-01T15:42:49-04:00 Improve debug tracing for substitution This patch improves debug tracing a bit (#18395) * Remove the ancient SDoc argument to substitution, replacing it with a HasDebugCallStack constraint. The latter does the same job (indicate the call site) but much better. * Add HasDebugCallStack to simpleOptExpr, exprIsConApp_maybe I needed this to help nail the lookupIdSubst panic in #18326, #17784 - - - - - 5c9fabb8 by Hécate at 2020-07-01T15:43:25-04:00 Add most common return values for `os` and `arch` - - - - - 76d8cc74 by Ryan Scott at 2020-07-01T15:44:01-04:00 Desugar quoted uses of DerivingVia and expression type signatures properly The way that `GHC.HsToCore.Quote` desugared quoted `via` types (e.g., `deriving via forall a. [a] instance Eq a => Eq (List a)`) and explicit type annotations in signatures (e.g., `f = id @a :: forall a. a -> a`) was completely wrong, as it did not implement the scoping guidelines laid out in `Note [Scoped type variables in bindings]`. This is easily fixed. While I was in town, I did some minor cleanup of related Notes: * `Note [Scoped type variables in bindings]` and `Note [Scoped type variables in class and instance declarations]` say very nearly the same thing. I decided to just consolidate the two Notes into `Note [Scoped type variables in quotes]`. * `Note [Don't quantify implicit type variables in quotes]` is somewhat outdated, as it predates GHC 8.10, where the `forall`-or-nothing rule requires kind variables to be explicitly quantified in the presence of an explicit `forall`. As a result, the running example in that Note doesn't even compile. I have changed the example to something simpler that illustrates the same point that the original Note was making. Fixes #18388. - - - - - 44d6a335 by Andreas Klebinger at 2020-07-02T02:54:54-04:00 T16012: Be verbose on failure. - - - - - f9853330 by Ryan Scott at 2020-07-02T02:55:29-04:00 Bump ghc-prim version to 0.7.0 Fixes #18279. Bumps the `text` submodule. - - - - - 23e4e047 by Sylvain Henry at 2020-07-02T10:46:31-04:00 Hadrian: fix PowerPC64le support (#17601) [ci skip] - - - - - 3cdd8d69 by Sylvain Henry at 2020-07-02T10:47:08-04:00 NCG: correctly handle addresses with huge offsets (#15570) Before this patch we could generate addresses of this form: movzbl cP0_str+-9223372036854775808,%eax The linker can't handle them because the offset is too large: ld.lld: error: Main.o:(.text+0xB3): relocation R_X86_64_32S out of range: -9223372036852653050 is not in [-2147483648, 2147483647] With this patch we detect those cases and generate: movq $-9223372036854775808,%rax addq $cP0_str,%rax movzbl (%rax),%eax I've also refactored `getAmode` a little bit to make it easier to understand and to trace. - - - - - 4d90b3ff by Gabor Greif at 2020-07-02T20:07:59-04:00 No need for CURSES_INCLUDE_DIRS This is a leftover from ef63ff27251a20ff11e58c9303677fa31e609a88 - - - - - f08d6316 by Sylvain Henry at 2020-07-02T20:08:36-04:00 Replace Opt_SccProfilingOn flag with sccProfilingEnabled helper function SCC profiling was enabled in a convoluted way: if WayProf was enabled, Opt_SccProfilingOn general flag was set (in `GHC.Driver.Ways.wayGeneralFlags`), and then this flag was queried in various places. There is no need to go via general flags, so this patch defines a `sccProfilingEnabled :: DynFlags -> Bool` helper function that just checks whether WayProf is enabled. - - - - - 8cc7274b by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Only allocate the Censuses that we need When not LDV profiling there is no reason to allocate 32 Censuses; one will do. This is a very small memory footprint optimisation, but it comes for free. - - - - - b835112c by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Free old allocations when reinitialising Censuses Previously when not LDV profiling we would repeatedly reinitialise `censuses[0]` with `initEra`. This failed to free the `Arena` and `HashTable` from the old census, resulting in a memory leak. Fixes #18348. - - - - - 34be6523 by Valery Tolstov at 2020-07-03T02:50:03-04:00 Mention flags that are not enabled by -Wall (#18372) * Mention missing flags that are not actually enabled by -Wall (docs/users_guide/using-warnings.rst) * Additionally remove -Wmissing-monadfail-instances from the list of flags enabled by -Wcompat, as it is not the case since 8.8 - - - - - edc8d22b by Sylvain Henry at 2020-07-03T02:50:40-04:00 LLVM: support R9 and R10 registers d535ef006d85dbdb7cda2b09c5bc35cb80108909 allowed the use of up to 10 vanilla registers but didn't update LLVM backend to support them. This patch fixes it. - - - - - 4bf18646 by Simon Peyton Jones at 2020-07-03T08:37:42+01:00 Improve handling of data type return kinds Following a long conversation with Richard, this patch tidies up the handling of return kinds for data/newtype declarations (vanilla, family, and instance). I have substantially edited the Notes in TyCl, so they would bear careful reading. Fixes #18300, #18357 In GHC.Tc.Instance.Family.newFamInst we were checking some Lint-like properties with ASSSERT. Instead Richard and I have added a proper linter for axioms, and called it from lintGblEnv, which in turn is called in tcRnModuleTcRnM New tests (T18300, T18357) cause an ASSERT failure in HEAD. - - - - - 41d26492 by Sylvain Henry at 2020-07-03T17:33:59-04:00 DynFlags: avoid the use of sdocWithDynFlags in GHC.Core.Rules (#17957) - - - - - 7aa6ef11 by Hécate at 2020-07-03T17:34:36-04:00 Add the __GHC_FULL_VERSION__ CPP macro to expose the full GHC version - - - - - e61d5395 by Chaitanya Koparkar at 2020-07-07T13:55:59-04:00 ghc-prim: Turn some comments into haddocks [ci skip] - - - - - 37743f91 by John Ericson at 2020-07-07T13:56:00-04:00 Support `timesInt2#` in LLVM backend - - - - - 46397e53 by John Ericson at 2020-07-07T13:56:00-04:00 `genericIntMul2Op`: Call `genericWordMul2Op` directly This unblocks a refactor, and removes partiality. It might be a PowerPC regression but that should be fixable. - - - - - 8a1c0584 by John Ericson at 2020-07-07T13:56:00-04:00 Simplify `PrimopCmmEmit` Follow @simonpj's suggestion of pushing the "into regs" logic into `emitPrimOp`. With the previous commit getting rid of the recursion in `genericIntMul2Op`, this is now an easy refactor. - - - - - 6607f203 by John Ericson at 2020-07-07T13:56:00-04:00 `opAllDone` -> `opIntoRegs` The old name was and terrible and became worse after the previous commit's refactor moved non-trivial funcationlity into its body. - - - - - fdcc53ba by Sylvain Henry at 2020-07-07T13:56:00-04:00 Optimise genericIntMul2Op We shouldn't directly call 'genericWordMul2Op' in genericIntMul2Op because a target may provide a faster primop for 'WordMul2Op': we'd better use it! - - - - - 686e7225 by Moritz Angermann at 2020-07-07T13:56:01-04:00 [linker/rtsSymbols] More linker symbols Mostly symbols needed for aarch64/armv7l and in combination with musl, where we have to rely on loading *all* objects/archives - __stack_chk_* only when not DYNAMIC - - - - - 3f60b94d by Moritz Angermann at 2020-07-07T13:56:01-04:00 better if guards. - - - - - 7abffced by Moritz Angermann at 2020-07-07T13:56:01-04:00 Fix (1) - - - - - cdfeb3f2 by Moritz Angermann at 2020-07-07T13:56:01-04:00 AArch32 symbols only on aarch32. - - - - - f496c955 by Adam Sandberg Ericsson at 2020-07-07T13:56:02-04:00 add -flink-rts flag to link the rts when linking a shared or static library #18072 By default we don't link the RTS when linking shared libraries because in the most usual mode a shared library is an intermediary product, for example a Haskell library, that will be linked into some executable in the end. So we wish to defer the RTS flavour to link to the final link. However sometimes the final product is the shared library, for example when writing a plugin for some other system, so we do wish the shared library to link the RTS. For consistency we also make -staticlib honor this flag and its inversion. -staticlib currently implies -flink-shared. - - - - - c59faf67 by Stefan Schulze Frielinghaus at 2020-07-07T13:56:04-04:00 hadrian: link check-ppr against debugging RTS if ghcDebugged - - - - - 0effc57d by Adam Sandberg Ericsson at 2020-07-07T13:56:05-04:00 rts linker: teach the linker about GLIBC's special handling of *stat, mknod and atexit functions #7072 - - - - - 96153433 by Adam Sandberg Ericsson at 2020-07-07T13:56:06-04:00 hadrian: make hadrian/ghci use the bootstrap compiler from configure #18190 - - - - - 4d24f886 by Adam Sandberg Ericsson at 2020-07-07T13:56:07-04:00 hadrian: ignore cabal configure verbosity related flags #18131 - - - - - 7332bbff by Ben Gamari at 2020-07-07T13:56:08-04:00 testsuite: Widen T12234 acceptance window to 2% Previously it wasn't uncommon to see +/-1% fluctuations in compiler allocations on this test. - - - - - 180b6313 by Gabor Greif at 2020-07-07T13:56:08-04:00 When running libtool, report it as such - - - - - d3bd6897 by Sylvain Henry at 2020-07-07T13:56:11-04:00 BigNum: rename BigNat types Before this patch BigNat names were confusing because we had: * GHC.Num.BigNat.BigNat: unlifted type used everywhere else * GHC.Num.BigNat.BigNatW: lifted type only used to share static constants * GHC.Natural.BigNat: lifted type only used for backward compatibility After this patch we have: * GHC.Num.BigNat.BigNat#: unlifted type * GHC.Num.BigNat.BigNat: lifted type (reexported from GHC.Natural) Thanks to @RyanGlScott for spotting this. - - - - - 929d26db by Sylvain Henry at 2020-07-07T13:56:12-04:00 Bignum: don't build ghc-bignum with stage0 Noticed by @Ericson2314 - - - - - d25b6851 by Sylvain Henry at 2020-07-07T13:56:12-04:00 Hadrian: ghc-gmp.h shouldn't be a compiler dependency - - - - - 0ddae2ba by Sylvain Henry at 2020-07-07T13:56:14-04:00 DynFlags: factor out pprUnitId from "Outputable UnitId" instance - - - - - 204f3f5d by Krzysztof Gogolewski at 2020-07-07T13:56:18-04:00 Remove unused function pprHsForAllExtra (#18423) The function `pprHsForAllExtra` was called only on `Nothing` since 2015 (1e041b7382b6aa). - - - - - 3033e0e4 by Adam Sandberg Ericsson at 2020-07-08T20:36:49-04:00 hadrian: add flag to skip rebuilding dependency information #17636 - - - - - b7de4b96 by Stefan Schulze Frielinghaus at 2020-07-09T09:49:22-04:00 Fix GHCi :print on big-endian platforms On big-endian platforms executing import GHC.Exts data Foo = Foo Float# deriving Show foo = Foo 42.0# foo :print foo results in an arithmetic overflow exception which is caused by function index where moveBytes equals word_size - (r + item_size_b) * 8 Here we have a mixture of units. Both, word_size and item_size_b have unit bytes whereas r has unit bits. On 64-bit platforms moveBytes equals then 8 - (0 + 4) * 8 which results in a negative and therefore invalid second parameter for a shiftL operation. In order to make things more clear the expression (word .&. (mask `shiftL` moveBytes)) `shiftR` moveBytes is equivalent to (word `shiftR` moveBytes) .&. mask On big-endian platforms the shift must be a left shift instead of a right shift. For symmetry reasons not a mask is used but two shifts in order to zero out bits. Thus the fixed version equals case endian of BigEndian -> (word `shiftL` moveBits) `shiftR` zeroOutBits `shiftL` zeroOutBits LittleEndian -> (word `shiftR` moveBits) `shiftL` zeroOutBits `shiftR` zeroOutBits Fixes #16548 and #14455 - - - - - 3656dff8 by Sylvain Henry at 2020-07-09T09:50:01-04:00 LLVM: fix MO_S_Mul2 support (#18434) The value indicating if the carry is useful wasn't taken into account. - - - - - d9f09506 by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Define multiShotIO and use it in mkSplitUniqueSupply This patch is part of the ongoing eta-expansion saga; see #18238. It implements a neat trick (suggested by Sebastian Graf) that allows the programmer to disable the default one-shot behaviour of IO (the "state hack"). The trick is to use a new multiShotIO function; see Note [multiShotIO]. For now, multiShotIO is defined here in Unique.Supply; but it should ultimately be moved to the IO library. The change is necessary to get good code for GHC's unique supply; see Note [Optimising the unique supply]. However it makes no difference to GHC as-is. Rather, it makes a difference when a subsequent commit Improve eta-expansion using ArityType lands. - - - - - bce695cc by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Make arityType deal with join points As Note [Eta-expansion and join points] describes, this patch makes arityType deal correctly with join points. What was there before was not wrong, but yielded lower arities than it could. Fixes #18328 In base GHC this makes no difference to nofib. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- n-body -0.1% -0.1% -1.2% -1.1% 0.0% -------------------------------------------------------------------------------- Min -0.1% -0.1% -55.0% -56.5% 0.0% Max -0.0% 0.0% +16.1% +13.4% 0.0% Geometric Mean -0.0% -0.0% -30.1% -31.0% -0.0% But it starts to make real difference when we land the change to the way mkDupableAlts handles StrictArg, in fixing #13253 and friends. I think this is because we then get more non-inlined join points. - - - - - 2b7c71cb by Simon Peyton Jones at 2020-07-11T12:17:02-04:00 Improve eta-expansion using ArityType As #18355 shows, we were failing to preserve one-shot info when eta-expanding. It's rather easy to fix, by using ArityType more, rather than just Arity. This patch is important to suport the one-shot monad trick; see #18202. But the extra tracking of one-shot-ness requires the patch Define multiShotIO and use it in mkSplitUniqueSupply If that patch is missing, ths patch makes things worse in GHC.Types.Uniq.Supply. With it, however, we see these improvements T3064 compiler bytes allocated -2.2% T3294 compiler bytes allocated -1.3% T12707 compiler bytes allocated -1.3% T13056 compiler bytes allocated -2.2% Metric Decrease: T3064 T3294 T12707 T13056 - - - - - de139cc4 by Artem Pelenitsyn at 2020-07-12T02:53:20-04:00 add reproducer for #15630 - - - - - c4de6a7a by Andreas Klebinger at 2020-07-12T02:53:55-04:00 Give Uniq[D]FM a phantom type for its key. This fixes #17667 and should help to avoid such issues going forward. The changes are mostly mechanical in nature. With two notable exceptions. * The register allocator. The register allocator references registers by distinct uniques. However they come from the types of VirtualReg, Reg or Unique in various places. As a result we sometimes cast the key type of the map and use functions which operate on the now typed map but take a raw Unique as actual key. The logic itself has not changed it just becomes obvious where we do so now. * <Type>Env Modules. As an example a ClassEnv is currently queried using the types `Class`, `Name`, and `TyCon`. This is safe since for a distinct class value all these expressions give the same unique. getUnique cls getUnique (classTyCon cls) getUnique (className cls) getUnique (tcName $ classTyCon cls) This is for the most part contained within the modules defining the interface. However it requires us to play dirty when we are given a `Name` to lookup in a `UniqFM Class a` map. But again the logic did not change and it's for the most part hidden behind the Env Module. Some of these cases could be avoided by refactoring but this is left for future work. We also bump the haddock submodule as it uses UniqFM. - - - - - c2cfdfde by Aaron Allen at 2020-07-13T09:00:33-04:00 Warn about empty Char enumerations (#18402) Currently the "Enumeration is empty" warning (-Wempty-enumerations) only fires for numeric literals. This patch adds support for `Char` literals so that enumerating an empty list of `Char`s will also trigger the warning. - - - - - c3ac87ec by Stefan Schulze Frielinghaus at 2020-07-13T09:01:10-04:00 hadrian: build check-ppr dynamic if GHC is build dynamic Fixes #18361 - - - - - 9ad072b4 by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Use dumpStyle when printing inlinings This just makes debug-printing consistent, and more informative. - - - - - e78c4efb by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Comments only - - - - - 7ccb760b by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Reduce result discount in conSize Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c - - - - - 7f0b671e by Ben Gamari at 2020-07-13T14:52:49-04:00 testsuite: Widen acceptance threshold on T5837 This test is positively tiny and consequently the bytes allocated measurement will be relatively noisy. Consequently I have seen this fail spuriously quite often. - - - - - 118e1c3d by Alp Mestanogullari at 2020-07-14T21:30:52-04:00 compiler: re-engineer the treatment of rebindable if Executing on the plan described in #17582, this patch changes the way if expressions are handled in the compiler in the presence of rebindable syntax. We get rid of the SyntaxExpr field of HsIf and instead, when rebindable syntax is on, we rewrite the HsIf node to the appropriate sequence of applications of the local `ifThenElse` function. In order to be able to report good error messages, with expressions as they were written by the user (and not as desugared by the renamer), we make use of TTG extensions to extend GhcRn expression ASTs with an `HsExpansion` construct, which keeps track of a source (GhcPs) expression and the desugared (GhcRn) expression that it gives rise to. This way, we can typecheck the latter while reporting the former in error messages. In order to discard the error context lines that arise from typechecking the desugared expressions (because they talk about expressions that the user has not written), we carefully give a special treatment to the nodes fabricated by this new renaming-time transformation when typechecking them. See Note [Rebindable syntax and HsExpansion] for more details. The note also includes a recipe to apply the same treatment to other rebindable constructs. Tests 'rebindable11' and 'rebindable12' have been added to make sure we report identical error messages as before this patch under various circumstances. We also now disable rebindable syntax when processing untyped TH quotes, as per the discussion in #18102 and document the interaction of rebindable syntax and Template Haskell, both in Note [Template Haskell quotes and Rebindable Syntax] and in the user guide, adding a test to make sure that we do not regress in that regard. - - - - - 64c774b0 by Andreas Klebinger at 2020-07-14T21:31:27-04:00 Explain why keeping DynFlags in AnalEnv saves allocation. - - - - - 254245d0 by Ben Gamari at 2020-07-14T21:32:03-04:00 docs/users-guide: Update default -funfolding-use-threshold value This was changed in 3d2991f8 but I neglected to update the documentation. Fixes #18419. - - - - - 4c259f86 by Andreas Klebinger at 2020-07-14T21:32:41-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. - - - - - 23797224 by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 .gitlab: re-enable integer-simple substitute (BIGNUM_BACKEND) Recently build system migrated from INTEGER_LIBRARY to BIGNUM_BACKEND. But gitlab CI was never updated. Let's enable BIGNUM_BACKEND=native. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - e0db878a by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 ghc-bignum: bring in sync .hs-boot files with module declarations Before this change `BIGNUM_BACKEND=native` build was failing as: ``` libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs:708:16: error: * Variable not in scope: naturalFromBigNat# :: WordArray# -> t * Perhaps you meant one of these: `naturalFromBigNat' (imported from GHC.Num.Natural), `naturalToBigNat' (imported from GHC.Num.Natural) | 708 | m' = naturalFromBigNat# m | ``` This happens because `.hs-boot` files are slightly out of date. This change brings in data and function types in sync. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - c9f65c36 by Stefan Schulze Frielinghaus at 2020-07-14T21:33:57-04:00 rts/Disassembler.c: Use FMT_HexWord for printing values in hex format - - - - - 58ae62eb by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 macOS: Load frameworks without stating them first. macOS Big Sur makes the following change to how frameworks are shipped with the OS: > New in macOS Big Sur 11 beta, the system ships with a built-in > dynamic linker cache of all system-provided libraries. As part of > this change, copies of dynamic libraries are no longer present on > the filesystem. Code that attempts to check for dynamic library > presence by looking for a file at a path or enumerating a directory > will fail. Instead, check for library presence by attempting to > dlopen() the path, which will correctly check for the library in the > cache. (62986286) https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/ Therefore, the previous method of checking whether a library exists before attempting to load it makes GHC.Runtime.Linker.loadFramework fail to find frameworks installed at /System/Library/Frameworks. GHC.Runtime.Linker.loadFramework now opportunistically loads the framework libraries without checking for their existence first, failing only if all attempts to load a given framework from any of the various possible locations fail. - - - - - cdc4a6b0 by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 loadFramework: Output the errors collected in all loading attempts. With the recent change away from first finding and then loading a framework, loadFramework had no way of communicating the real reason why loadDLL failed if it was any reason other than the framework missing from the file system. It now collects all loading attempt errors into a list and concatenates them into a string to return to the caller. - - - - - 51dbfa52 by Ben Gamari at 2020-07-15T04:05:34-04:00 StgToCmm: Use CmmRegOff smart constructor Previously we would generate expressions of the form `CmmRegOff BaseReg 0`. This should do no harm (and really should be handled by the NCG anyways) but it's better to just generate a plain `CmmReg`. - - - - - ae11bdfd by Ben Gamari at 2020-07-15T04:06:08-04:00 testsuite: Add regression test for #17744 Test due to @monoidal. - - - - - 0e3c277a by Ben Gamari at 2020-07-15T16:41:01-04:00 Bump Cabal submodule Updates a variety of tests as Cabal is now more strict about Cabal file form. - - - - - ceed994a by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Drop Windows Vista support, require Windows 7 - - - - - 00a23bfd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Update Windows FileSystem wrapper utilities. - - - - - 459e1c5f by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Use SlimReaderLocks and ConditonalVariables provided by the OS instead of emulated ones - - - - - 763088fc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Small linker comment and ifdef cleanups - - - - - 1a228ff9 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Flush event logs eagerly. - - - - - e9e04dda by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Refactor Buffer structures to be able to track async operations - - - - - 356dc3fe by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Implement new Console API - - - - - 90e69f77 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add IOPort synchronization primitive - - - - - 71245fcc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add new io-manager cmdline options - - - - - d548a3b3 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Init Windows console Codepage to UTF-8. - - - - - 58ef6366 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add unsafeSplat to GHC.Event.Array - - - - - d660725e by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add size and iterate to GHC.Event.IntTable. - - - - - 050da6dd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Switch Testsuite to test winio by default - - - - - 4bf542bf by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Multiple refactorings and support changes. - - - - - 4489af6b by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core threaded I/O manager - - - - - 64d8f2fe by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core non-threaded I/O manager - - - - - 8da15a09 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix a scheduler bug with the threaded-runtime. - - - - - 84ea3d14 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Relaxing some constraints in io-manager. - - - - - ccf0d107 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix issues with non-threaded I/O manager after split. - - - - - b492fe6e by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Remove some barf statements that are a bit strict. - - - - - 01423fd2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Expand comments describing non-threaded loop - - - - - 4b69004f by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: fix FileSize unstat-able handles - - - - - 9b384270 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Implement new tempfile routines for winio - - - - - f1e0be82 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix input truncation when reading from handle. This was caused by not upholding the read buffer invariant that bufR == bufL == 0 for empty read buffers. - - - - - e176b625 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix output truncation for writes larger than buffer size - - - - - a831ce0e by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Rewrite bufWrite. I think it's far easier to follow the code now. It's also correct now as I had still missed a spot where we didn't update the offset. - - - - - 6aefdf62 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix offset set by bufReadEmpty. bufReadEmpty returns the bytes read *including* content that was already buffered, But for calculating the offset we only care about the number of bytes read into the new buffer. - - - - - 750ebaee by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Clean up code surrounding IOPort primitives. According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc. - - - - - ffd31db9 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix multi threaded threadDelay and a few other small changes. Multithreaded threadDelay suffered from a race condition based on the ioManagerStatus. Since the status isn't needed for WIO I removed it completely. This resulted in a light refactoring, as consequence we will always wake up the IO manager using interruptSystemManager, which uses `postQueuedCompletionStatus` internally. I also added a few comments which hopefully makes the code easier to dive into for the next person diving in. - - - - - 6ec26df2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 wionio: Make IO subsystem check a no-op on non-windows platforms. - - - - - 29bcd936 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Set handle offset when opening files in Append mode. Otherwise we would truncate the file. - - - - - 55c29700 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Remove debug event log trace - - - - - 9acb9f40 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix sqrt and openFile009 test cases - - - - - 57017cb7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Allow hp2ps to build with -DDEBUG - - - - - b8cd9995 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update output of T9681 since we now actually run it. - - - - - 10af5b14 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: A few more improvements to the IOPort primitives. - - - - - 39afc4a7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix expected tempfiles output. Tempfiles now works properly on windows, as such we can delete the win32 specific output. - - - - - 99db46e0 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Assign thread labels to IOManager threads. - - - - - be6af732 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Properly check for the tso of an incall to be zero. - - - - - e2c6dac7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark FD instances as unsupported under WINIO. - - - - - fd02ceed by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix threadDelay maxBound invocations. Instead of letting the ns timer overflow now clamp it at (maxBound :: Word64) ns. That still gives a few hundred years. - - - - - bc79f9f1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comments/cleanup an import in base - - - - - 1d197f4b by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark outstanding_service_requests volatile. As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration. - - - - - dc438186 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Make last_event a local variable - - - - - 2fc957c5 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comment about thread safety of processCompletion. - - - - - 4c026b6c by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: nonthreaded: Create io processing threads in main thread. We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread. - - - - - f47c7208 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add an exported isHeapAlloced function to the RTS - - - - - cc5d7bb1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Queue IO processing threads at the front of the queue. This will unblock the IO thread sooner hopefully leading to higher throughput in some situations. - - - - - e7630115 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: ThreadDelay001: Use higher resolution timer. - - - - - 451b5f96 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update T9681 output, disable T4808 on windows. T4808 tests functionality of the FD interface which won't be supported under WINIO. T9681 just has it's expected output tweaked. - - - - - dd06f930 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Wake io manager once per registerTimeout. Which is implicitly done in editTimeouts, so need to wake it up twice. - - - - - e87d0bf9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update placeholder comment with actual function name. - - - - - fc9025db by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Always lock win32 event queue - - - - - c24c9a1f by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Display thread labels when tracing scheduler events. - - - - - 06542b03 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Refactor non-threaded runner thread and scheduler interface. Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event. - - - - - 256299b1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove outstanding_requests from runner. We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port. - - - - - 3ebd8ad9 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Various fixes related to rebase and testdriver - - - - - 6be6bcba by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Fix rebase artifacts - - - - - 2c649dc3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename unsafeSplat to unsafeCopyFromBuffer - - - - - a18b73f3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove unused size/iterate operations from IntTable - - - - - 16bab48e by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Detect running IO Backend via peeking at RtsConfig - - - - - 8b8405a0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update temp path so GCC etc can handle it. Also fix PIPE support, clean up error casting, fix memory leaks - - - - - 2092bc54 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Minor comments/renamings - - - - - a5b5b6c0 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Checking if an error code indicates completion is now a function. - - - - - 362176fd by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Small refactor in withOverlappedEx - - - - - 32e20597 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: A few comments and commented out dbxIO - - - - - a4bfc1d9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't drop buffer offset in byteView/cwcharView - - - - - b3ad2a54 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: revert BHandle changes. - - - - - 3dcd87e2 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Fix imports - - - - - 5a371890 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update ghc-cabal to handle new Cabal submodule bump - - - - - d07ebe0d by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Only compile sources on Windows - - - - - dcb42393 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Actually return Nothing on EOF for non-blocking read - - - - - 895a3beb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate logic in encodeMultiByte[Raw]IO. - - - - - e06e6734 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate openFile logic - - - - - b59430c0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: fix -werror issue in encoding file - - - - - f8d39a51 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't mention windows specific functions when building on Linux. - - - - - 6a533d2a by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add a note about file locking in the RTS. - - - - - cf37ce34 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Add version to @since annotation - - - - - 0fafa2eb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename GHC.Conc.IOCP -> GHC.Conc.WinIO - - - - - 1854fc23 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Expand GHC.Conc.POSIX description It now explains users may not use these functions when using the old IO manager. - - - - - fcc7ba41 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Fix potential spaceleak in __createUUIDTempFileErrNo - - - - - 6b3fd9fa by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant -Wno-missing-signatures pragmas - - - - - 916fc861 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Make it explicit that we only create one IO manager - - - - - f260a721 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Note why we don't use blocking waits. - - - - - aa0a4bbf by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove commented out pragma - - - - - d679b544 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant buffer write in Handle/Text.hs:bufReadEmpty - - - - - d3f94368 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename SmartHandles to StdHandles - - - - - bd6b8ec1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add comment stating failure behaviour for getUniqueFileInfo. - - - - - 12846b85 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update IOPort haddocks. - - - - - 9f39fb14 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Add a note cross reference - - - - - 62dd5a73 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Name Haskell/OS I/O Manager explicitly in Note - - - - - fa807828 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Expand BlockedOnIOCompletion description. - - - - - f0880a1d by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove historical todos - - - - - 8e58e714 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Update note, remove debugging pragma. - - - - - aa4d84d5 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: flushCharReadBuffer shouldn't need to adjust offsets. - - - - - e580893a by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove obsolete comment about cond. variables - - - - - d54e9d79 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix initial linux validate build - - - - - 3cd4de46 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix ThreadDelay001 CPP - - - - - c88b1b9f by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix openFile009 merge conflict leftover - - - - - 849e8889 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept T9681 output. GHC now reports String instead of [Char]. - - - - - e7701818 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix cabal006 after upgrading cabal submodule Demand cabal 2.0 syntax instead of >= 1.20 as required by newer cabal versions. - - - - - a44f0373 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix stderr output for ghci/linking/dyn tests. We used to filter rtsopts, i opted to instead just accept the warning of it having no effect. This works both for -rtsopts, as well as -with-rtsopts which winio adds. - - - - - 515d9896 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T15261b stdout for --io-manager flag. - - - - - 949aaacc by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T5435_dyn_asm stderr The warning about rtsopts having no consequences is expected. So accept new stderr. - - - - - 7d424e1e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Also accept T7037 stderr - - - - - 1f009768 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal04 by filtering rts args - - - - - 981a9f2e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal01 by accepting expected stderr - - - - - b7b0464e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix safePkg01 by accepting expected stderr - - - - - 32734b29 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix T5435_dyn_gcc by accepting expected stderr - - - - - acc5cebf by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix tempfiles test on linux - - - - - c577b789 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for T3807 - - - - - c108c527 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload - - - - - 2b0b9a08 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload_multiple_objs - - - - - 67afb03c by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify wording on conditional variables. - - - - - 3bd41572 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify comment on cooked mode. - - - - - ded58a03 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: update lockfile signature and remove mistaken symbol in rts. - - - - - 2143c492 by Ben Gamari at 2020-07-15T16:41:04-04:00 testsuite: Add winio and winio_threaded ways Reverts many of the testsuite changes - - - - - c0979cc5 by Ben Gamari at 2020-07-16T10:56:54-04:00 Merge remote-tracking branch 'origin/wip/winio' - - - - - 750a1595 by Ben Gamari at 2020-07-18T07:26:41-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. - - - - - 6ba6a881 by Hécate at 2020-07-18T07:26:42-04:00 Implement `fullCompilerVersion` Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403 This MR adds `fullCompilerVersion`, a function that shares the same backend as the `--numeric-version` GHC flag, exposing a full, three-digit version datatype. - - - - - e6cf27df by Hécate at 2020-07-18T07:26:43-04:00 Add a Lint hadrian rule and an .hlint.yaml file in base/ - - - - - bcb177dd by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Allow multiple case branches to have a higher rank type As #18412 points out, it should be OK for multiple case alternatives to have a higher rank type, provided they are all the same. This patch implements that change. It sweeps away GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it with an enhanced version of fillInferResult. The basic change to fillInferResult is to permit the case in which another case alternative has already filled in the result; and in that case simply unify. It's very simple actually. See the new Note [fillInferResult] in TcMType Other refactoring: - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType (previously some of it was in Unify) - Move tcInstType and friends from TcMType to Instantiate, where it more properly belongs. (TCMType was getting very long.) - - - - - e5525a51 by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Improve typechecking of NPlusK patterns This patch (due to Richard Eisenberg) improves documentation of the wrapper returned by tcSubMult (see Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify). And, more substantially, it cleans up the multiplicity handling in the typechecking of NPlusKPat - - - - - 12f90352 by Krzysztof Gogolewski at 2020-07-18T07:26:45-04:00 Remove {-# CORE #-} pragma (part of #18048) This pragma has no effect since 2011. It was introduced for External Core, which no longer exists. Updates haddock submodule. - - - - - e504c913 by Simon Peyton Jones at 2020-07-18T07:26:45-04:00 Refactor the simplification of join binders This MR (for #18449) refactors the Simplifier's treatment of join-point binders. Specifically, it puts together, into GHC.Core.Opt.Simplify.Env.adjustJoinPointType two currently-separate ways in which we adjust the type of a join point. As the comment says: -- (adjustJoinPointType mult new_res_ty join_id) does two things: -- -- 1. Set the return type of the join_id to new_res_ty -- See Note [Return type for join points] -- -- 2. Adjust the multiplicity of arrows in join_id's type, as -- directed by 'mult'. See Note [Scaling join point arguments] I think this actually fixes a latent bug, by ensuring that the seIdSubst and seInScope have the right multiplicity on the type of join points. I did some tidying up while I was at it. No more setJoinResTy, or modifyJoinResTy: instead it's done locally in Simplify.Env.adjustJoinPointType - - - - - 49b265f0 by Chaitanya Koparkar at 2020-07-18T07:26:46-04:00 Fix minor typos in a Core.hs note - - - - - 8d59aed6 by Stefan Schulze Frielinghaus at 2020-07-18T07:26:47-04:00 GHCi: Fix isLittleEndian - - - - - c26e81d1 by Ben Gamari at 2020-07-18T07:26:47-04:00 testsuite: Mark ghci tests as fragile under unreg compiler In particular I have seen T16012 fail repeatedly under the unregisterised compiler. - - - - - 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 293c7fba by Sylvain Henry at 2020-08-21T09:36:38-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - 50eb4460 by Sylvain Henry at 2020-08-21T09:36:38-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 659eb31b by Sylvain Henry at 2020-08-21T09:36:38-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 2d8ca917 by Sylvain Henry at 2020-08-21T09:37:15-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - fddddbf4 by Vladislav Zavialov at 2020-08-21T09:37:49-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - 989c1c27 by Ben Gamari at 2020-08-21T11:27:53-04:00 gitlab-ci: Test master branch as well While these builds are strictly speaking redundant (since every commit is tested by @marge-bot before making it into `master`), they are nevertheless useful as they are displayed in the branch's commit list in GitLab's web interface. Fixes #18595. - - - - - e67ae884 by Aditya Gupta at 2020-08-22T03:29:00-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - 03cfcfd4 by Wander Hillen at 2020-08-22T03:29:36-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 3f501545 by Craig Ferguson at 2020-08-22T03:30:13-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 8b865092 by Krzysztof Gogolewski at 2020-08-23T14:12:53+02:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - d8f61182 by Krzysztof Gogolewski at 2020-08-23T14:12:56+02:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - 364258e0 by Krzysztof Gogolewski at 2020-08-24T00:32:31-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - b1eb38a0 by Sylvain Henry at 2020-08-24T00:33:13-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 0a1ecc5f by Ben Gamari at 2020-08-25T07:37:05-04:00 SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' In #18069 we are observing MVar deadlocks from somewhere in ghc.exe. This use of MVar stood out as being one of the more likely culprits. Here we make sure that it is exception-safe. - - - - - db8793ad by Richard Eisenberg at 2020-08-25T07:37:40-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - fb77207a by Simon Peyton Jones at 2020-08-25T07:38:16-04:00 Use LIdP rather than (XRec p (IdP p)) This patch mainly just replaces use of XRec p (IdP p) with LIdP p One slightly more significant change is to parameterise HsPatSynDetails over the pass rather than the argument type, so that it's uniform with HsConDeclDetails and HsConPatDetails. I also got rid of the dead code GHC.Hs.type.conDetailsArgs But this is all just minor refactoring. No change in functionality. - - - - - 8426a136 by Krzysztof Gogolewski at 2020-08-25T07:38:54-04:00 Add a test for #18585 - - - - - 253ee6c8 by Vladislav Zavialov at 2020-08-25T18:03:49+03:00 Require happy >=1.20 - - - - - 81f6b2e2 by Vladislav Zavialov at 2020-08-25T18:18:12+03:00 Resolve shift/reduce conflicts with %shift (#17232) - - - - - 21 changed files: - .ghcid - + .git-ignore-revs - .gitignore - .gitlab-ci.yml - + .gitlab/ci.sh - − .gitlab/darwin-init.sh - + .gitlab/linters/check-changelogs.sh - .gitlab/linters/check-cpp.py - .gitlab/linters/check-makefiles.py - .gitlab/linters/linter.py - .gitlab/merge_request_templates/merge-request.md - − .gitlab/prepare-system.sh - − .gitlab/push-test-metrics.sh - + .gitlab/test-metrics.sh - − .gitlab/win32-init.sh - .gitmodules - CODEOWNERS - HACKING.md - Makefile - aclocal.m4 - boot The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/744d4f328a1b4034e1ed3a1810cdf06c71dcb010...81f6b2e28d2626529dc46291b1d3a2bbbbdde11c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/744d4f328a1b4034e1ed3a1810cdf06c71dcb010...81f6b2e28d2626529dc46291b1d3a2bbbbdde11c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 18:19:00 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Tue, 25 Aug 2020 14:19:00 -0400 Subject: [Git][ghc/ghc][wip/happy-1.20] Require happy >=1.20 Message-ID: <5f455614aed7d_80b3f8486857894946989c@gitlab.haskell.org.mail> Vladislav Zavialov pushed to branch wip/happy-1.20 at Glasgow Haskell Compiler / GHC Commits: 44338dfc by Vladislav Zavialov at 2020-08-25T21:18:40+03:00 Require happy >=1.20 - - - - - 4 changed files: - .gitlab-ci.yml - aclocal.m4 - hadrian/cabal.project - hadrian/hadrian.cabal Changes: ===================================== .gitlab-ci.yml ===================================== @@ -2,7 +2,7 @@ variables: GIT_SSL_NO_VERIFY: "1" # Commit of ghc/ci-images repository from which to pull Docker images - DOCKER_REV: b65e1145d7c0a62c3533904a88dac14f56fb371b + DOCKER_REV: f408f461fcadcb6081a330f6570186425d99ade7 # Sequential version number capturing the versions of all tools fetched by # .gitlab/ci.sh. ===================================== aclocal.m4 ===================================== @@ -1021,8 +1021,8 @@ changequote([, ])dnl ]) if test ! -f compiler/GHC/Parser.hs || test ! -f compiler/GHC/Cmm/Parser.hs then - FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.19.10], - [AC_MSG_ERROR([Happy version 1.19.10 or later is required to compile GHC.])])[] + FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.20.0], + [AC_MSG_ERROR([Happy version 1.20.0 or later is required to compile GHC.])])[] fi HappyVersion=$fptools_cv_happy_version; AC_SUBST(HappyVersion) ===================================== hadrian/cabal.project ===================================== @@ -1,7 +1,7 @@ packages: ./ -- This essentially freezes the build plan for hadrian -index-state: 2020-06-16T03:59:14Z +index-state: 2020-08-25T12:30:13Z -- N.B. Compile with -O0 since this is not a performance-critical executable -- and the Cabal takes nearly twice as long to build with -O1. See #16817. ===================================== hadrian/hadrian.cabal ===================================== @@ -148,7 +148,7 @@ executable hadrian , transformers >= 0.4 && < 0.6 , unordered-containers >= 0.2.1 && < 0.3 build-tools: alex >= 3.1 - , happy >= 1.19.10 + , happy >= 1.20.0 ghc-options: -Wall -Wincomplete-record-updates -Wredundant-constraints View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/44338dfcaca21628c4f9f5a06497de0db2d5669c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/44338dfcaca21628c4f9f5a06497de0db2d5669c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 18:47:52 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 25 Aug 2020 14:47:52 -0400 Subject: [Git][ghc/ghc][wip/ci-fixes] 7 commits: gitlab-ci: More intelligent detection of locale availability Message-ID: <5f455cd893b67_80b3f842731681c94702fd@gitlab.haskell.org.mail> Ben Gamari pushed to branch wip/ci-fixes at Glasgow Haskell Compiler / GHC Commits: ddccd3d3 by Ben Gamari at 2020-08-25T14:47:36-04:00 gitlab-ci: More intelligent detection of locale availability Previously ci.sh would unconditionally use C.UTF-8. However, this fails on Centos 7, which appears not to provide this locale. Now we first try C.UTF-8, then try en_US.UTF-8, then fail. Works around #18607. - - - - - 23c5a756 by Ben Gamari at 2020-08-25T14:47:36-04:00 gitlab-ci: Rename RELEASE variable to RELEASE_JOB This interfered with the autoconf variable of the same name, breaking pre-release builds. - - - - - 566ac68d by Ben Gamari at 2020-08-25T14:47:36-04:00 gitlab-ci: Bump Windows toolchain version This should have been done when we bumped the bootstrap compiler to 8.8.4. - - - - - 72036e1c by Ben Gamari at 2020-08-25T14:47:36-04:00 gitlab-ci: Drop Windows make job These are a significant burden on our CI resources and end up failing quite often due to #18274. Here I drop the make jobs during validaion; it is now run only during the nightly builds. - - - - - 4597752a by Ben Gamari at 2020-08-25T14:47:37-04:00 testsuite: Drop Windows-specific output for parseTree The normalise_slashes normaliser should handle this. - - - - - 5b12bb7c by Ben Gamari at 2020-08-25T14:47:37-04:00 testsuite: Mark T5975[ab] as broken on Windows Due to #7305. - - - - - c4fd8947 by Ben Gamari at 2020-08-25T14:47:37-04:00 gitlab-ci: Fix typo A small typo in a rule regular expression. - - - - - 4 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - − testsuite/tests/ghc-api/annotations/parseTree.stdout-mingw32 - testsuite/tests/ghci/scripts/all.T Changes: ===================================== .gitlab-ci.yml ===================================== @@ -6,7 +6,7 @@ variables: # Sequential version number capturing the versions of all tools fetched by # .gitlab/ci.sh. - WINDOWS_TOOLCHAIN_VERSION: 1 + WINDOWS_TOOLCHAIN_VERSION: 2 # Disable shallow clones; they break our linting rules GIT_DEPTH: 0 @@ -49,7 +49,7 @@ workflow: - if: $CI_COMMIT_TAG - if: '$CI_COMMIT_BRANCH == "master"' - if: '$CI_COMMIT_BRANCH == "wip/marge_bot_batch_merge_job"' - - if: '$CI_COMMIT_BRANCH =~ /ghc-[0.9]+\.[0-9]+/' + - if: '$CI_COMMIT_BRANCH =~ /ghc-[0-9]+\.[0-9]+/' - if: '$CI_PIPELINE_SOURCE == "web"' .nightly: &nightly @@ -67,7 +67,7 @@ workflow: when: always expire_in: 1 year rules: - - if: '$RELEASE == "yes"' + - if: '$RELEASE_JOB == "yes"' ############################################################ # Runner Tags @@ -896,9 +896,6 @@ validate-x86_64-windows-hadrian: cache: key: "x86_64-windows-$WINDOWS_TOOLCHAIN_VERSION" -validate-x86_64-windows: - extends: .build-x86_64-windows-make - nightly-x86_64-windows: <<: *nightly extends: .build-x86_64-windows-make @@ -909,13 +906,13 @@ nightly-x86_64-windows: # Normal Windows validate builds are profiled; that won't do for releases. release-x86_64-windows: <<: *release - extends: validate-x86_64-windows + extends: .build-x86_64-windows-make variables: BUILD_FLAVOUR: "perf" # release-x86_64-windows-integer-simple: <<: *release - extends: validate-x86_64-windows + extends: .build-x86_64-windows-make variables: BIGNUM_BACKEND: native BUILD_FLAVOUR: "perf" @@ -970,7 +967,7 @@ doc-tarball: image: "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb9:$DOCKER_REV" dependencies: - validate-x86_64-linux-deb9-debug - - validate-x86_64-windows + - validate-x86_64-windows-hadrian variables: LINUX_BINDIST: "ghc-x86_64-deb9-linux-debug.tar.xz" WINDOWS_BINDIST: "ghc-x86_64-mingw32.tar.xz" ===================================== .gitlab/ci.sh ===================================== @@ -26,9 +26,6 @@ LT_CYAN="1;36" WHITE="1;37" LT_GRAY="0;37" -export LANG=C.UTF-8 -export LC_ALL=C.UTF-8 - # GitLab Pipelines log section delimiters # https://gitlab.com/gitlab-org/gitlab-foss/issues/14664 start_section() { @@ -60,6 +57,30 @@ function run() { TOP="$(pwd)" +function setup_locale() { + # BSD grep terminates early with -q, consequently locale -a will get a + # SIGPIPE and the pipeline will fail with pipefail. + shopt -o -u pipefail + if locale -a | grep -q C.UTF-8; then + # Debian + export LANG=C.UTF-8 + elif locale -a | grep -q C.utf8; then + # Fedora calls it this + export LANG=C.utf8 + elif locale -a | grep -q en_US.UTF-8; then + # Centos doesn't have C.UTF-8 + export LANG=en_US.UTF-8 + else + error "Failed to find usable locale" + info "Available locales:" + locale -a + fail "No usable locale, aborting..." + fi + info "Using locale $LANG..." + export LC_ALL=$LANG + shopt -o -s pipefail +} + function mingw_init() { case "$MSYSTEM" in MINGW32) @@ -423,6 +444,8 @@ function shell() { run $cmd } +setup_locale + # Determine Cabal data directory case "$(uname)" in MSYS_*|MINGW*) exe=".exe"; cabal_dir="$APPDATA/cabal" ;; ===================================== testsuite/tests/ghc-api/annotations/parseTree.stdout-mingw32 deleted ===================================== @@ -1,160 +0,0 @@ -[(AnnotationTuple.hs:14:20, [p], Solo 1), - (AnnotationTuple.hs:14:23-29, [p], Solo "hello"), - (AnnotationTuple.hs:14:35-37, [p], Solo 6.5), - (AnnotationTuple.hs:14:39, [m], ()), - (AnnotationTuple.hs:14:41-52, [p], Solo [5, 5, 6, 7]), - (AnnotationTuple.hs:16:8, [p], Solo 1), - (AnnotationTuple.hs:16:11-17, [p], Solo "hello"), - (AnnotationTuple.hs:16:20-22, [p], Solo 6.5), - (AnnotationTuple.hs:16:24, [m], ()), - (AnnotationTuple.hs:16:25, [m], ()), - (AnnotationTuple.hs:16:26, [m], ()), (, [m], ())] -[ -(AK AnnotationTuple.hs:1:1 AnnCloseC = [AnnotationTuple.hs:27:1]) - -(AK AnnotationTuple.hs:1:1 AnnModule = [AnnotationTuple.hs:3:1-6]) - -(AK AnnotationTuple.hs:1:1 AnnOpenC = [AnnotationTuple.hs:5:1]) - -(AK AnnotationTuple.hs:1:1 AnnWhere = [AnnotationTuple.hs:3:30-34]) - -(AK AnnotationTuple.hs:3:24-28 AnnCloseP = [AnnotationTuple.hs:3:28]) - -(AK AnnotationTuple.hs:3:24-28 AnnOpenP = [AnnotationTuple.hs:3:24]) - -(AK AnnotationTuple.hs:6:1-32 AnnAs = [AnnotationTuple.hs:6:28-29]) - -(AK AnnotationTuple.hs:6:1-32 AnnImport = [AnnotationTuple.hs:6:1-6]) - -(AK AnnotationTuple.hs:6:1-32 AnnQualified = [AnnotationTuple.hs:6:8-16]) - -(AK AnnotationTuple.hs:6:1-32 AnnSemi = [AnnotationTuple.hs:7:1]) - -(AK AnnotationTuple.hs:(8,1)-(11,14) AnnEqual = [AnnotationTuple.hs:8:5]) - -(AK AnnotationTuple.hs:(8,1)-(11,14) AnnFunId = [AnnotationTuple.hs:8:1-3]) - -(AK AnnotationTuple.hs:(8,1)-(11,14) AnnSemi = [AnnotationTuple.hs:13:1]) - -(AK AnnotationTuple.hs:(8,7)-(11,14) AnnIn = [AnnotationTuple.hs:11:7-8]) - -(AK AnnotationTuple.hs:(8,7)-(11,14) AnnLet = [AnnotationTuple.hs:8:7-9]) - -(AK AnnotationTuple.hs:9:9-13 AnnEqual = [AnnotationTuple.hs:9:11]) - -(AK AnnotationTuple.hs:9:9-13 AnnFunId = [AnnotationTuple.hs:9:9]) - -(AK AnnotationTuple.hs:9:9-13 AnnSemi = [AnnotationTuple.hs:10:9]) - -(AK AnnotationTuple.hs:10:9-13 AnnEqual = [AnnotationTuple.hs:10:11]) - -(AK AnnotationTuple.hs:10:9-13 AnnFunId = [AnnotationTuple.hs:10:9]) - -(AK AnnotationTuple.hs:11:10-14 AnnVal = [AnnotationTuple.hs:11:12]) - -(AK AnnotationTuple.hs:14:1-72 AnnEqual = [AnnotationTuple.hs:14:5]) - -(AK AnnotationTuple.hs:14:1-72 AnnFunId = [AnnotationTuple.hs:14:1-3]) - -(AK AnnotationTuple.hs:14:1-72 AnnSemi = [AnnotationTuple.hs:15:1]) - -(AK AnnotationTuple.hs:14:7-72 AnnVal = [AnnotationTuple.hs:14:13]) - -(AK AnnotationTuple.hs:14:19-53 AnnCloseP = [AnnotationTuple.hs:14:53]) - -(AK AnnotationTuple.hs:14:19-53 AnnOpenP = [AnnotationTuple.hs:14:19]) - -(AK AnnotationTuple.hs:14:20 AnnComma = [AnnotationTuple.hs:14:21]) - -(AK AnnotationTuple.hs:14:23-29 AnnComma = [AnnotationTuple.hs:14:33]) - -(AK AnnotationTuple.hs:14:35-37 AnnComma = [AnnotationTuple.hs:14:38]) - -(AK AnnotationTuple.hs:14:39 AnnComma = [AnnotationTuple.hs:14:39]) - -(AK AnnotationTuple.hs:14:41-52 AnnCloseS = [AnnotationTuple.hs:14:52]) - -(AK AnnotationTuple.hs:14:41-52 AnnOpenS = [AnnotationTuple.hs:14:41]) - -(AK AnnotationTuple.hs:14:42 AnnComma = [AnnotationTuple.hs:14:43]) - -(AK AnnotationTuple.hs:14:45 AnnComma = [AnnotationTuple.hs:14:46]) - -(AK AnnotationTuple.hs:14:48 AnnComma = [AnnotationTuple.hs:14:49]) - -(AK AnnotationTuple.hs:14:55-72 AnnCloseS = [AnnotationTuple.hs:14:72]) - -(AK AnnotationTuple.hs:14:55-72 AnnOpenS = [AnnotationTuple.hs:14:55]) - -(AK AnnotationTuple.hs:14:56-62 AnnComma = [AnnotationTuple.hs:14:63]) - -(AK AnnotationTuple.hs:14:61-62 AnnCloseP = [AnnotationTuple.hs:14:62]) - -(AK AnnotationTuple.hs:14:61-62 AnnOpenP = [AnnotationTuple.hs:14:61]) - -(AK AnnotationTuple.hs:16:1-41 AnnEqual = [AnnotationTuple.hs:16:5]) - -(AK AnnotationTuple.hs:16:1-41 AnnFunId = [AnnotationTuple.hs:16:1-3]) - -(AK AnnotationTuple.hs:16:1-41 AnnSemi = [AnnotationTuple.hs:17:1]) - -(AK AnnotationTuple.hs:16:7-27 AnnCloseP = [AnnotationTuple.hs:16:27]) - -(AK AnnotationTuple.hs:16:7-27 AnnOpenP = [AnnotationTuple.hs:16:7]) - -(AK AnnotationTuple.hs:16:8 AnnComma = [AnnotationTuple.hs:16:9]) - -(AK AnnotationTuple.hs:16:11-17 AnnComma = [AnnotationTuple.hs:16:18]) - -(AK AnnotationTuple.hs:16:20-22 AnnComma = [AnnotationTuple.hs:16:23]) - -(AK AnnotationTuple.hs:16:24 AnnComma = [AnnotationTuple.hs:16:24]) - -(AK AnnotationTuple.hs:16:25 AnnComma = [AnnotationTuple.hs:16:25]) - -(AK AnnotationTuple.hs:16:26 AnnComma = [AnnotationTuple.hs:16:26]) - -(AK AnnotationTuple.hs:16:33-41 AnnCloseP = [AnnotationTuple.hs:16:41]) - -(AK AnnotationTuple.hs:16:33-41 AnnOpenP = [AnnotationTuple.hs:16:33]) - -(AK AnnotationTuple.hs:16:39-40 AnnCloseP = [AnnotationTuple.hs:16:40]) - -(AK AnnotationTuple.hs:16:39-40 AnnOpenP = [AnnotationTuple.hs:16:39]) - -(AK AnnotationTuple.hs:18:1-28 AnnData = [AnnotationTuple.hs:18:1-4]) - -(AK AnnotationTuple.hs:18:1-28 AnnDcolon = [AnnotationTuple.hs:18:20-21]) - -(AK AnnotationTuple.hs:18:1-28 AnnFamily = [AnnotationTuple.hs:18:6-11]) - -(AK AnnotationTuple.hs:18:1-28 AnnSemi = [AnnotationTuple.hs:19:1]) - -(AK AnnotationTuple.hs:18:23 AnnRarrow = [AnnotationTuple.hs:18:25-26]) - -(AK AnnotationTuple.hs:18:23-28 AnnRarrow = [AnnotationTuple.hs:18:25-26]) - -(AK AnnotationTuple.hs:(20,1)-(24,14) AnnFunId = [AnnotationTuple.hs:20:1-5]) - -(AK AnnotationTuple.hs:(20,1)-(24,14) AnnSemi = [AnnotationTuple.hs:25:1]) - -(AK AnnotationTuple.hs:(21,7)-(24,14) AnnEqual = [AnnotationTuple.hs:24:7]) - -(AK AnnotationTuple.hs:(21,7)-(24,14) AnnVbar = [AnnotationTuple.hs:21:7]) - -(AK AnnotationTuple.hs:21:9-24 AnnComma = [AnnotationTuple.hs:22:7]) - -(AK AnnotationTuple.hs:21:9-24 AnnLarrow = [AnnotationTuple.hs:21:16-17]) - -(AK AnnotationTuple.hs:22:9-25 AnnComma = [AnnotationTuple.hs:23:7]) - -(AK AnnotationTuple.hs:22:9-25 AnnLarrow = [AnnotationTuple.hs:22:16-17]) - -(AK AnnotationTuple.hs:23:9-24 AnnLarrow = [AnnotationTuple.hs:23:16-17]) - -(AK AnnotationTuple.hs:26:1-10 AnnDcolon = [AnnotationTuple.hs:26:5-6]) - -(AK AnnotationTuple.hs:26:1-14 AnnEqual = [AnnotationTuple.hs:26:12]) -] - -EOF: Just SrcSpanPoint ".\\AnnotationTuple.hs" 32 1 ===================================== testsuite/tests/ghci/scripts/all.T ===================================== @@ -141,8 +141,11 @@ test('T5979', normalise_slashes, normalise_version("transformers")], ghci_script, ['T5979.script']) -test('T5975a', [pre_cmd('touch föøbàr1.hs')], ghci_script, ['T5975a.script']) -test('T5975b', [pre_cmd('touch föøbàr2.hs'), extra_hc_opts('föøbàr2.hs')], +test('T5975a', + [pre_cmd('touch föøbàr1.hs'), when(opsys('mingw32'), expect_broken(7305))], + ghci_script, ['T5975a.script']) +test('T5975b', + [pre_cmd('touch föøbàr2.hs'), extra_hc_opts('föøbàr2.hs'), when(opsys('mingw32'), expect_broken(7305))], ghci_script, ['T5975b.script']) test('T6027ghci', normal, ghci_script, ['T6027ghci.script']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/015afc46003f346502d65ecda44e84235bc98126...c4fd8947f4104e7b6d6bf3d320a63a361191bde1 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/015afc46003f346502d65ecda44e84235bc98126...c4fd8947f4104e7b6d6bf3d320a63a361191bde1 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 19:03:17 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 25 Aug 2020 15:03:17 -0400 Subject: [Git][ghc/ghc][ghc-9.0] Fix types in silly shifts (#18589) Message-ID: <5f45607579b7a_80bac4156c9474211@gitlab.haskell.org.mail> Ben Gamari pushed to branch ghc-9.0 at Glasgow Haskell Compiler / GHC Commits: 5ccf44c6 by Krzysztof Gogolewski at 2020-08-24T21:35:48-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. (cherry picked from commit 364258e0ad25bc95e69745554f5ca831ce80baf8) - - - - - 3 changed files: - compiler/GHC/Core/Opt/ConstantFold.hs - + testsuite/tests/simplCore/should_compile/T18589.hs - testsuite/tests/simplCore/should_compile/all.T Changes: ===================================== compiler/GHC/Core/Opt/ConstantFold.hs ===================================== @@ -140,11 +140,11 @@ primOpRules nm = \case , inversePrimOp NotIOp ] IntNegOp -> mkPrimOpRule nm 1 [ unaryLit negOp , inversePrimOp IntNegOp ] - ISllOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftL) + ISllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const Bits.shiftL) , rightIdentityPlatform zeroi ] - ISraOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftR) + ISraOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const Bits.shiftR) , rightIdentityPlatform zeroi ] - ISrlOp -> mkPrimOpRule nm 2 [ shiftRule shiftRightLogical + ISrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt shiftRightLogical , rightIdentityPlatform zeroi ] -- Word operations @@ -186,8 +186,8 @@ primOpRules nm = \case , equalArgs >> retLit zerow ] NotOp -> mkPrimOpRule nm 1 [ unaryLit complementOp , inversePrimOp NotOp ] - SllOp -> mkPrimOpRule nm 2 [ shiftRule (const Bits.shiftL) ] - SrlOp -> mkPrimOpRule nm 2 [ shiftRule shiftRightLogical ] + SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord (const Bits.shiftL) ] + SrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord shiftRightLogical ] -- coercions Word2IntOp -> mkPrimOpRule nm 1 [ liftLitPlatform word2IntLit @@ -474,12 +474,14 @@ wordOpC2 op env (LitNumber LitNumWord w1) (LitNumber LitNumWord w2) = wordCResult (roPlatform env) (fromInteger w1 `op` fromInteger w2) wordOpC2 _ _ _ _ = Nothing -shiftRule :: (Platform -> Integer -> Int -> Integer) -> RuleM CoreExpr +shiftRule :: LitNumType -- Type of the result, either LitNumInt or LitNumWord + -> (Platform -> Integer -> Int -> Integer) + -> RuleM CoreExpr -- Shifts take an Int; hence third arg of op is Int -- Used for shift primops --- ISllOp, ISraOp, ISrlOp :: Word# -> Int# -> Word# +-- ISllOp, ISraOp, ISrlOp :: Int# -> Int# -> Int# -- SllOp, SrlOp :: Word# -> Int# -> Word# -shiftRule shift_op +shiftRule lit_num_ty shift_op = do { platform <- getPlatform ; [e1, Lit (LitNumber LitNumInt shift_len)] <- getArgs ; case e1 of @@ -487,7 +489,9 @@ shiftRule shift_op -> return e1 -- See Note [Guarding against silly shifts] | shift_len < 0 || shift_len > toInteger (platformWordSizeInBits platform) - -> return $ Lit $ mkLitNumberWrap platform LitNumInt 0 + -> return $ Lit $ mkLitNumberWrap platform lit_num_ty 0 + -- Be sure to use lit_num_ty here, so we get a correctly typed zero + -- of type Int# or Word# resp. See #18589 -- Do the shift at type Integer, but shift length is Int Lit (LitNumber nt x) ===================================== testsuite/tests/simplCore/should_compile/T18589.hs ===================================== @@ -0,0 +1,12 @@ +{-# LANGUAGE MagicHash #-} +module T18589 where + +import GHC.Prim + +-- See Note [Guarding against silly shifts] +-- Make sure that a silly shift is optimized correctly +f1 x = uncheckedIShiftL# x -1# +f2 x = uncheckedIShiftRA# x -1# +f3 x = uncheckedIShiftRL# x -1# +f4 x = uncheckedShiftL# x -1# +f5 x = uncheckedShiftRL# x -1# ===================================== testsuite/tests/simplCore/should_compile/all.T ===================================== @@ -332,3 +332,4 @@ test('T18328', [ only_ways(['optasm']), grep_errmsg(r'Arity=') ], compile, ['-dd test('T18347', normal, compile, ['-dcore-lint -O']) test('T18355', [ grep_errmsg(r'OneShot') ], compile, ['-O -ddump-simpl -dsuppress-uniques']) test('T18399', normal, compile, ['-dcore-lint -O']) +test('T18589', normal, compile, ['-dcore-lint -O']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5ccf44c6f0e27e83bf2828f0834bb790b1834929 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5ccf44c6f0e27e83bf2828f0834bb790b1834929 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 19:03:16 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Tue, 25 Aug 2020 15:03:16 -0400 Subject: [Git][ghc/ghc] Deleted branch wip/backports Message-ID: <5f45607456e70_80b3f84a401c3dc94740cf@gitlab.haskell.org.mail> Ben Gamari deleted branch wip/backports at Glasgow Haskell Compiler / GHC -- You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 19:37:29 2020 From: gitlab at gitlab.haskell.org (Alan Zimmerman) Date: Tue, 25 Aug 2020 15:37:29 -0400 Subject: [Git][ghc/ghc][wip/az/exactprint] Fix up after rebasing to bring in XRec Message-ID: <5f456879e84da_80b3f84693c1eb494763c1@gitlab.haskell.org.mail> Alan Zimmerman pushed to branch wip/az/exactprint at Glasgow Haskell Compiler / GHC Commits: a091397a by Alan Zimmerman at 2020-08-25T20:28:35+01:00 Fix up after rebasing to bring in XRec Main thing is to make type instance XRec (GhcPass p) a = GenLocated (Anno a) a type family Anno a = b But this has massive implications. - - - - - 22 changed files: - compiler/GHC.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Hs.hs - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Expr.hs-boot - compiler/GHC/Hs/Extension.hs - compiler/GHC/Hs/ImpExp.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Pat.hs-boot - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/Arrows.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Docs.hs - compiler/GHC/HsToCore/Foreign/Decl.hs - compiler/GHC/HsToCore/ListComp.hs - compiler/GHC/HsToCore/Quote.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Iface/Ext/Ast.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a091397a2710955d7929f99cd4853c1588967d10 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a091397a2710955d7929f99cd4853c1588967d10 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Tue Aug 25 23:04:56 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Tue, 25 Aug 2020 19:04:56 -0400 Subject: [Git][ghc/ghc][wip/T18223] 7 commits: Add a test for #18397 Message-ID: <5f459918eda5_80b3f84a401c3dc9485865@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18223 at Glasgow Haskell Compiler / GHC Commits: a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 0a1ecc5f by Ben Gamari at 2020-08-25T07:37:05-04:00 SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' In #18069 we are observing MVar deadlocks from somewhere in ghc.exe. This use of MVar stood out as being one of the more likely culprits. Here we make sure that it is exception-safe. - - - - - db8793ad by Richard Eisenberg at 2020-08-25T07:37:40-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - fb77207a by Simon Peyton Jones at 2020-08-25T07:38:16-04:00 Use LIdP rather than (XRec p (IdP p)) This patch mainly just replaces use of XRec p (IdP p) with LIdP p One slightly more significant change is to parameterise HsPatSynDetails over the pass rather than the argument type, so that it's uniform with HsConDeclDetails and HsConPatDetails. I also got rid of the dead code GHC.Hs.type.conDetailsArgs But this is all just minor refactoring. No change in functionality. - - - - - 8426a136 by Krzysztof Gogolewski at 2020-08-25T07:38:54-04:00 Add a test for #18585 - - - - - 6362994e by Simon Peyton Jones at 2020-08-26T00:04:07+01:00 Better eta-expansion (again) and don't specilise DFuns This patch fixes #18223, which made GHC generate an exponential amount of code. There are three quite separate changes in here 1. Re-engineer eta-expansion (again). The eta-expander was generating lots of intermediate stuff, which could be optimised away, but which choked the simplifier meanwhile. Relatively easy to kill it off at source. See Note [The EtaInfo mechanism] in GHC.Core.Opt.Arity. The main new thing is the use of pushCoArg in getArg_maybe. 2. Stop Specialise specalising DFuns. This is the cause of a huge (and utterly unnecessary) blowup in program size in #18223. See Note [Do not specialise DFuns] in GHC.Core.Opt.Specialise. I also refactored the Specialise monad a bit... it was silly, because it passed on unchanging values as if they were mutable state. 3. Do an extra Simplifer run, after SpecConstra and before late-Specialise. I found (investigating perf/compiler/T16473) that failing to do this was crippling *both* SpecConstr *and* Specialise. See Note [Simplify after SpecConstr] in GHC.Core.Opt.Pipeline. This change does mean an extra run of the Simplifier, but only with -O2, and I think that's acceptable. T16473 allocates *three* times less with this change. (I changed it to check runtime rather than compile time.) Some smaller consequences * I moved pushCoercion, pushCoArg and friends from SimpleOpt to Arity, because it was needed by the new etaInfoApp. And pushCoValArg now returns a MCoercion rather than Coercion for the argument Coercion. * A minor, incidental improvement to Core pretty-printing This does fix #18223, (which was otherwise uncompilable. Hooray. But there is still a big intermediate because there are some very deeply nested types in that program. Modest reductions in compile-time allocation on a couple of benchmarks 12425 -2.5% 13253 -10.4% MultiLayerModules -0.6% Metric increase with -O2, due to extra simplifier run T9233 +5.8% T12227 +1.7% Metric Increase T9233 T12227 - - - - - 30 changed files: - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Env.hs - compiler/GHC/Core/Opt/Specialise.hs - compiler/GHC/Core/Ppr.hs - compiler/GHC/Core/SimpleOpt.hs - compiler/GHC/Core/Subst.hs - compiler/GHC/Core/Type.hs - compiler/GHC/Core/Unify.hs - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Extension.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/Match/Constructor.hs - compiler/GHC/HsToCore/Quote.hs - compiler/GHC/HsToCore/Utils.hs - compiler/GHC/Parser.y - compiler/GHC/SysTools/Process.hs - compiler/GHC/Tc/TyCl/PatSyn.hs - compiler/GHC/Tc/Utils/Zonk.hs - + testsuite/tests/codeGen/should_compile/T18397.hs - testsuite/tests/codeGen/should_compile/all.T - testsuite/tests/perf/compiler/Makefile - testsuite/tests/perf/compiler/T16473.stdout The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e3c76de3eb2a09d78ebc14cc5c11b667b69c5807...6362994e6e6de297f4b8704a6386fd396312bd85 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e3c76de3eb2a09d78ebc14cc5c11b667b69c5807...6362994e6e6de297f4b8704a6386fd396312bd85 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 03:20:21 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Tue, 25 Aug 2020 23:20:21 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: linters: Make CPP linter skip image files Message-ID: <5f45d4f57cc83_80b3f84693c1eb4951425c@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 02e2f16d by Takenobu Tani at 2020-08-25T23:20:08-04:00 linters: Make CPP linter skip image files This patch adds an exclusion rule for `docs/users_guide/images`, to avoid lint errors of PDF files. - - - - - 1810eea4 by Takenobu Tani at 2020-08-25T23:20:08-04:00 users-guide: Color the logo on the front page of the PDF This patch updates the logo with a recent color scheme. This affects only the PDF version of the user's guide. See also: * https://mail.haskell.org/pipermail/ghc-devs/2020-August/019139.html * https://gitlab.haskell.org/ghc/ghc/-/wikis/logo - - - - - 7858f039 by Sylvain Henry at 2020-08-25T23:20:12-04:00 Refactor UnitId pretty-printing When we pretty-print a UnitId for the user, we try to map it back to its origin package name, version and component to print "package-version:component" instead of some hash. The UnitId type doesn't carry these information, so we have to look into a UnitState to find them. This is why the Outputable instance of UnitId used `sdocWithDynFlags` in order to access the `unitState` field of DynFlags. This is wrong for several reasons: 1. The DynFlags are accessed when the message is printed, not when it is generated. So we could imagine that the unitState may have changed in-between. Especially if we want to allow unit unloading. 2. We want GHC to support several independent sessions at once, hence several UnitState. The current approach supposes there is a unique UnitState as a UnitId doesn't indicate which UnitState to use. See the Note [Pretty-printing UnitId] in GHC.Unit for the new approach implemented by this patch. One step closer to remove `sdocDynFlags` field from `SDocContext` (#10143). Fix #18124. Also fix some Backpack code to use SDoc instead of String. - - - - - 4d1425f5 by Sylvain Henry at 2020-08-25T23:20:13-04:00 Bignum: fix BigNat subtraction (#18604) There was a confusion between the boolean expected by withNewWordArrayTrimedMaybe and the boolean returned by subtracting functions. - - - - - 30 changed files: - .gitlab/linters/check-cpp.py - compiler/GHC.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Driver/Finder.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/Runtime/Eval.hs - compiler/GHC/Tc/Module.hs - compiler/GHC/Tc/Utils/Backpack.hs - compiler/GHC/Tc/Utils/Instantiate.hs - compiler/GHC/Tc/Utils/Monad.hs - compiler/GHC/Unit.hs - compiler/GHC/Unit/Home.hs - compiler/GHC/Unit/Info.hs - compiler/GHC/Unit/Parser.hs - compiler/GHC/Unit/State.hs - compiler/GHC/Unit/State.hs-boot - compiler/GHC/Unit/Types.hs - compiler/GHC/Utils/Error.hs - compiler/GHC/Utils/Outputable.hs - docs/users_guide/images/logo.pdf - libraries/ghc-bignum/src/GHC/Num/BigNat.hs - libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs - libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs - libraries/ghc-bignum/src/GHC/Num/WordArray.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/cf4da2653a68209e13d8efe39f6e644b8a4ddb89...4d1425f54776668b8e22d6d245a08cee31114224 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/cf4da2653a68209e13d8efe39f6e644b8a4ddb89...4d1425f54776668b8e22d6d245a08cee31114224 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 08:50:26 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 26 Aug 2020 04:50:26 -0400 Subject: [Git][ghc/ghc][master] 2 commits: linters: Make CPP linter skip image files Message-ID: <5f46225256ef9_80b3f84902b125095227f4@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 2d635a50 by Takenobu Tani at 2020-08-26T04:50:21-04:00 linters: Make CPP linter skip image files This patch adds an exclusion rule for `docs/users_guide/images`, to avoid lint errors of PDF files. - - - - - b7d98cb2 by Takenobu Tani at 2020-08-26T04:50:21-04:00 users-guide: Color the logo on the front page of the PDF This patch updates the logo with a recent color scheme. This affects only the PDF version of the user's guide. See also: * https://mail.haskell.org/pipermail/ghc-devs/2020-August/019139.html * https://gitlab.haskell.org/ghc/ghc/-/wikis/logo - - - - - 2 changed files: - .gitlab/linters/check-cpp.py - docs/users_guide/images/logo.pdf Changes: ===================================== .gitlab/linters/check-cpp.py ===================================== @@ -29,6 +29,9 @@ for l in linters: # Don't lint font files l.add_path_filter(lambda path: not path.parent == Path('docs','users_guide', 'rtd-theme', 'static', 'fonts')) + # Don't lint image files + l.add_path_filter(lambda path: not path.parent == Path('docs','users_guide', + 'images')) # Don't lint core spec l.add_path_filter(lambda path: not path.name == 'core-spec.pdf') ===================================== docs/users_guide/images/logo.pdf ===================================== Binary files a/docs/users_guide/images/logo.pdf and b/docs/users_guide/images/logo.pdf differ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/8426a1364ba450fe48fc41a95b2ba76c8d1bb7c8...b7d98cb2606997e05ad6406929dae3aba746fbb9 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/8426a1364ba450fe48fc41a95b2ba76c8d1bb7c8...b7d98cb2606997e05ad6406929dae3aba746fbb9 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 08:51:08 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 26 Aug 2020 04:51:08 -0400 Subject: [Git][ghc/ghc][master] Refactor UnitId pretty-printing Message-ID: <5f46227c7ce4a_80b3f84a401c3dc952894b@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 0b17fa18 by Sylvain Henry at 2020-08-26T04:50:58-04:00 Refactor UnitId pretty-printing When we pretty-print a UnitId for the user, we try to map it back to its origin package name, version and component to print "package-version:component" instead of some hash. The UnitId type doesn't carry these information, so we have to look into a UnitState to find them. This is why the Outputable instance of UnitId used `sdocWithDynFlags` in order to access the `unitState` field of DynFlags. This is wrong for several reasons: 1. The DynFlags are accessed when the message is printed, not when it is generated. So we could imagine that the unitState may have changed in-between. Especially if we want to allow unit unloading. 2. We want GHC to support several independent sessions at once, hence several UnitState. The current approach supposes there is a unique UnitState as a UnitId doesn't indicate which UnitState to use. See the Note [Pretty-printing UnitId] in GHC.Unit for the new approach implemented by this patch. One step closer to remove `sdocDynFlags` field from `SDocContext` (#10143). Fix #18124. Also fix some Backpack code to use SDoc instead of String. - - - - - 24 changed files: - compiler/GHC.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Driver/Finder.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/Runtime/Eval.hs - compiler/GHC/Tc/Module.hs - compiler/GHC/Tc/Utils/Backpack.hs - compiler/GHC/Tc/Utils/Instantiate.hs - compiler/GHC/Tc/Utils/Monad.hs - compiler/GHC/Unit.hs - compiler/GHC/Unit/Home.hs - compiler/GHC/Unit/Info.hs - compiler/GHC/Unit/Parser.hs - compiler/GHC/Unit/State.hs - compiler/GHC/Unit/State.hs-boot - compiler/GHC/Unit/Types.hs - compiler/GHC/Utils/Error.hs - compiler/GHC/Utils/Outputable.hs Changes: ===================================== compiler/GHC.hs ===================================== @@ -1682,7 +1682,7 @@ interpretPackageEnv dflags = do return dflags Just envfile -> do content <- readFile envfile - compilationProgressMsg dflags ("Loaded package environment from " ++ envfile) + compilationProgressMsg dflags (text "Loaded package environment from " <> text envfile) let (_, dflags') = runCmdLine (runEwM (setFlagsFromEnvFile envfile content)) dflags return dflags' ===================================== compiler/GHC/Driver/Backpack.hs ===================================== @@ -88,7 +88,7 @@ doBackpack [src_filename] = do -- OK, so we have an LHsUnit PackageName, but we want an -- LHsUnit HsComponentId. So let's rename it. let pkgstate = unitState dflags - let bkp = renameHsUnits pkgstate (bkpPackageNameMap pkgstate pkgname_bkp) pkgname_bkp + let bkp = renameHsUnits pkgstate (bkpPackageNameMap pkgname_bkp) pkgname_bkp initBkpM src_filename bkp $ forM_ (zip [1..] bkp) $ \(i, lunit) -> do let comp_name = unLoc (hsunitName (unLoc lunit)) @@ -96,7 +96,7 @@ doBackpack [src_filename] = do innerBkpM $ do let (cid, insts) = computeUnitId lunit if null insts - then if cid == Indefinite (UnitId (fsLit "main")) Nothing + then if cid == Indefinite (UnitId (fsLit "main")) then compileExe lunit else compileUnit cid [] else typecheckUnit cid insts @@ -209,7 +209,7 @@ withBkpSession cid insts deps session_type do_this = do withBkpExeSession :: [(Unit, ModRenaming)] -> BkpM a -> BkpM a withBkpExeSession deps do_this = do - withBkpSession (Indefinite (UnitId (fsLit "main")) Nothing) [] deps ExeSession do_this + withBkpSession (Indefinite (UnitId (fsLit "main"))) [] deps ExeSession do_this getSource :: IndefUnitId -> BkpM (LHsUnit HsComponentId) getSource cid = do @@ -491,9 +491,10 @@ initBkpM file bkp m = do -- | Print a compilation progress message, but with indentation according -- to @level@ (for nested compilation). -backpackProgressMsg :: Int -> DynFlags -> String -> IO () +backpackProgressMsg :: Int -> DynFlags -> SDoc -> IO () backpackProgressMsg level dflags msg = - compilationProgressMsg dflags $ replicate (level * 2) ' ' ++ msg + compilationProgressMsg dflags $ text (replicate (level * 2) ' ') -- TODO: use GHC.Utils.Ppr.RStr + <> msg -- | Creates a 'Messager' for Backpack compilation; this is basically -- a carbon copy of 'batchMsg' but calling 'backpackProgressMsg', which @@ -503,17 +504,18 @@ mkBackpackMsg = do level <- getBkpLevel return $ \hsc_env mod_index recomp mod_summary -> let dflags = hsc_dflags hsc_env + state = unitState dflags showMsg msg reason = - backpackProgressMsg level dflags $ - showModuleIndex mod_index ++ - msg ++ showModMsg dflags (recompileRequired recomp) mod_summary - ++ reason + backpackProgressMsg level dflags $ pprWithUnitState state $ + showModuleIndex mod_index <> + msg <> showModMsg dflags (recompileRequired recomp) mod_summary + <> reason in case recomp of - MustCompile -> showMsg "Compiling " "" + MustCompile -> showMsg (text "Compiling ") empty UpToDate - | verbosity (hsc_dflags hsc_env) >= 2 -> showMsg "Skipping " "" + | verbosity (hsc_dflags hsc_env) >= 2 -> showMsg (text "Skipping ") empty | otherwise -> return () - RecompBecause reason -> showMsg "Compiling " (" [" ++ reason ++ "]") + RecompBecause reason -> showMsg (text "Compiling ") (text " [" <> text reason <> text "]") -- | 'PprStyle' for Backpack messages; here we usually want the module to -- be qualified (so we can tell how it was instantiated.) But we try not @@ -531,27 +533,29 @@ msgTopPackage (i,n) (HsComponentId (PackageName fs_pn) _) = do dflags <- getDynFlags level <- getBkpLevel liftIO . backpackProgressMsg level dflags - $ showModuleIndex (i, n) ++ "Processing " ++ unpackFS fs_pn + $ showModuleIndex (i, n) <> text "Processing " <> ftext fs_pn -- | Message when we instantiate a Backpack unit. msgUnitId :: Unit -> BkpM () msgUnitId pk = do dflags <- getDynFlags level <- getBkpLevel + let state = unitState dflags liftIO . backpackProgressMsg level dflags - $ "Instantiating " ++ renderWithContext - (initSDocContext dflags backpackStyle) - (ppr pk) + $ pprWithUnitState state + $ text "Instantiating " + <> withPprStyle backpackStyle (ppr pk) -- | Message when we include a Backpack unit. msgInclude :: (Int,Int) -> Unit -> BkpM () msgInclude (i,n) uid = do dflags <- getDynFlags level <- getBkpLevel + let state = unitState dflags liftIO . backpackProgressMsg level dflags - $ showModuleIndex (i, n) ++ "Including " ++ - renderWithContext (initSDocContext dflags backpackStyle) - (ppr uid) + $ pprWithUnitState state + $ showModuleIndex (i, n) <> text "Including " + <> withPprStyle backpackStyle (ppr uid) -- ---------------------------------------------------------------------------- -- Conversion from PackageName to HsComponentId @@ -560,12 +564,12 @@ type PackageNameMap a = Map PackageName a -- For now, something really simple, since we're not actually going -- to use this for anything -unitDefines :: UnitState -> LHsUnit PackageName -> (PackageName, HsComponentId) -unitDefines pkgstate (L _ HsUnit{ hsunitName = L _ pn@(PackageName fs) }) - = (pn, HsComponentId pn (mkIndefUnitId pkgstate (UnitId fs))) +unitDefines :: LHsUnit PackageName -> (PackageName, HsComponentId) +unitDefines (L _ HsUnit{ hsunitName = L _ pn@(PackageName fs) }) + = (pn, HsComponentId pn (Indefinite (UnitId fs))) -bkpPackageNameMap :: UnitState -> [LHsUnit PackageName] -> PackageNameMap HsComponentId -bkpPackageNameMap pkgstate units = Map.fromList (map (unitDefines pkgstate) units) +bkpPackageNameMap :: [LHsUnit PackageName] -> PackageNameMap HsComponentId +bkpPackageNameMap units = Map.fromList (map unitDefines units) renameHsUnits :: UnitState -> PackageNameMap HsComponentId -> [LHsUnit PackageName] -> [LHsUnit HsComponentId] renameHsUnits pkgstate m units = map (fmap renameHsUnit) units ===================================== compiler/GHC/Driver/Finder.hs ===================================== @@ -620,11 +620,12 @@ findObjectLinkable mod obj_fn obj_time = return (LM obj_time mod [DotO obj_fn]) -- Error messages cannotFindModule :: DynFlags -> ModuleName -> FindResult -> SDoc -cannotFindModule flags mod res = +cannotFindModule dflags mod res = pprWithUnitState unit_state $ cantFindErr (sLit cannotFindMsg) (sLit "Ambiguous module name") - flags mod res + dflags mod res where + unit_state = unitState dflags cannotFindMsg = case res of NotFound { fr_mods_hidden = hidden_mods ===================================== compiler/GHC/Driver/Main.hs ===================================== @@ -887,25 +887,25 @@ oneShotMsg hsc_env recomp = case recomp of UpToDate -> compilationProgressMsg (hsc_dflags hsc_env) $ - "compilation IS NOT required" + text "compilation IS NOT required" _ -> return () batchMsg :: Messager batchMsg hsc_env mod_index recomp mod_summary = case recomp of - MustCompile -> showMsg "Compiling " "" + MustCompile -> showMsg (text "Compiling ") empty UpToDate - | verbosity (hsc_dflags hsc_env) >= 2 -> showMsg "Skipping " "" + | verbosity (hsc_dflags hsc_env) >= 2 -> showMsg (text "Skipping ") empty | otherwise -> return () - RecompBecause reason -> showMsg "Compiling " (" [" ++ reason ++ "]") + RecompBecause reason -> showMsg (text "Compiling ") (text " [" <> text reason <> text "]") where dflags = hsc_dflags hsc_env showMsg msg reason = compilationProgressMsg dflags $ - (showModuleIndex mod_index ++ - msg ++ showModMsg dflags (recompileRequired recomp) mod_summary) - ++ reason + (showModuleIndex mod_index <> + msg <> showModMsg dflags (recompileRequired recomp) mod_summary) + <> reason -------------------------------------------------------------- -- Safe Haskell @@ -1174,7 +1174,8 @@ hscCheckSafe' m l = do pkgTrustErr = unitBag $ mkErrMsg dflags l (pkgQual state) $ sep [ ppr (moduleName m) <> text ": Can't be safely imported!" - , text "The package (" <> ppr (moduleUnit m) + , text "The package (" + <> (pprWithUnitState state $ ppr (moduleUnit m)) <> text ") the module resides in isn't trusted." ] modTrustErr = unitBag $ mkErrMsg dflags l (pkgQual state) $ @@ -1225,8 +1226,10 @@ checkPkgTrust pkgs = do = acc | otherwise = (:acc) $ mkErrMsg dflags noSrcSpan (pkgQual state) - $ text "The package (" <> ppr pkg <> text ") is required" <> - text " to be trusted but it isn't!" + $ pprWithUnitState state + $ text "The package (" + <> ppr pkg + <> text ") is required to be trusted but it isn't!" case errors of [] -> return () _ -> (liftIO . throwIO . mkSrcErr . listToBag) errors @@ -1940,9 +1943,9 @@ dumpIfaceStats hsc_env = do %* * %********************************************************************* -} -showModuleIndex :: (Int, Int) -> String -showModuleIndex (i,n) = "[" ++ padded ++ " of " ++ n_str ++ "] " +showModuleIndex :: (Int, Int) -> SDoc +showModuleIndex (i,n) = text "[" <> pad <> int i <> text " of " <> int n <> text "] " where - n_str = show n - i_str = show i - padded = replicate (length n_str - length i_str) ' ' ++ i_str + -- compute the length of x > 0 in base 10 + len x = ceiling (logBase 10 (fromIntegral x+1) :: Float) + pad = text (replicate (len n - len i) ' ') -- TODO: use GHC.Utils.Ppr.RStr ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -474,7 +474,7 @@ link' dflags batch_attempt_linking hpt return Succeeded else do - compilationProgressMsg dflags ("Linking " ++ exe_file ++ " ...") + compilationProgressMsg dflags (text "Linking " <> text exe_file <> text " ...") -- Don't showPass in Batch mode; doLink will do that for us. let link = case ghcLink dflags of ===================================== compiler/GHC/Driver/Ppr.hs ===================================== @@ -30,6 +30,7 @@ import GHC.Utils.Misc import GHC.Utils.Outputable import GHC.Utils.Panic import GHC.Utils.Ppr ( Mode(..) ) +import {-# SOURCE #-} GHC.Unit.State import System.IO ( Handle ) import Control.Monad.IO.Class @@ -46,7 +47,11 @@ showPprUnsafe a = showPpr unsafeGlobalDynFlags a -- | Allows caller to specify the PrintUnqualified to use showSDocForUser :: DynFlags -> PrintUnqualified -> SDoc -> String -showSDocForUser dflags unqual doc = renderWithContext (initSDocContext dflags (mkUserStyle unqual AllTheWay)) doc +showSDocForUser dflags unqual doc = renderWithContext (initSDocContext dflags sty) doc' + where + sty = mkUserStyle unqual AllTheWay + unit_state = unitState dflags + doc' = pprWithUnitState unit_state doc showSDocDump :: DynFlags -> SDoc -> String showSDocDump dflags d = renderWithContext (initSDocContext dflags defaultDumpStyle) d ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -5080,6 +5080,7 @@ initSDocContext dflags style = SDC , sdocImpredicativeTypes = xopt LangExt.ImpredicativeTypes dflags , sdocLinearTypes = xopt LangExt.LinearTypes dflags , sdocPrintTypeAbbreviations = True + , sdocUnitIdForUser = ftext , sdocDynFlags = dflags } ===================================== compiler/GHC/Driver/Types.hs ===================================== @@ -2995,8 +2995,8 @@ instance Outputable ModSummary where char '}' ] -showModMsg :: DynFlags -> Bool -> ModSummary -> String -showModMsg dflags recomp mod_summary = showSDoc dflags $ +showModMsg :: DynFlags -> Bool -> ModSummary -> SDoc +showModMsg dflags recomp mod_summary = if gopt Opt_HideSourcePaths dflags then text mod_str else hsep $ ===================================== compiler/GHC/Iface/Load.hs ===================================== @@ -1121,6 +1121,7 @@ For some background on this choice see trac #15269. showIface :: HscEnv -> FilePath -> IO () showIface hsc_env filename = do let dflags = hsc_dflags hsc_env + unit_state = unitState dflags printer = putLogMsg dflags NoReason SevOutput noSrcSpan . withPprStyle defaultDumpStyle -- skip the hi way check; we don't want to worry about profiled vs. @@ -1136,7 +1137,9 @@ showIface hsc_env filename = do neverQualifyModules neverQualifyPackages putLogMsg dflags NoReason SevDump noSrcSpan - $ withPprStyle (mkDumpStyle print_unqual) (pprModIface iface) + $ withPprStyle (mkDumpStyle print_unqual) + $ pprWithUnitState unit_state + $ pprModIface iface -- Show a ModIface but don't display details; suitable for ModIfaces stored in -- the EPT. ===================================== compiler/GHC/Iface/Make.hs ===================================== @@ -123,7 +123,9 @@ mkFullIface hsc_env partial_iface mb_cg_infos = do addFingerprints hsc_env partial_iface{ mi_decls = decls } -- Debug printing - dumpIfSet_dyn (hsc_dflags hsc_env) Opt_D_dump_hi "FINAL INTERFACE" FormatText (pprModIface full_iface) + let unit_state = unitState (hsc_dflags hsc_env) + dumpIfSet_dyn (hsc_dflags hsc_env) Opt_D_dump_hi "FINAL INTERFACE" FormatText + (pprWithUnitState unit_state $ pprModIface full_iface) return full_iface ===================================== compiler/GHC/Runtime/Eval.hs ===================================== @@ -1257,7 +1257,7 @@ showModule mod_summary = withSession $ \hsc_env -> do interpreted <- moduleIsBootOrNotObjectLinkable mod_summary let dflags = hsc_dflags hsc_env - return (showModMsg dflags interpreted mod_summary) + return (showSDoc dflags $ showModMsg dflags interpreted mod_summary) moduleIsBootOrNotObjectLinkable :: GhcMonad m => ModSummary -> m Bool moduleIsBootOrNotObjectLinkable mod_summary = withSession $ \hsc_env -> ===================================== compiler/GHC/Tc/Module.hs ===================================== @@ -2866,11 +2866,12 @@ rnDump rn = dumpOptTcRn Opt_D_dump_rn "Renamer" FormatHaskell (ppr rn) tcDump :: TcGblEnv -> TcRn () tcDump env = do { dflags <- getDynFlags ; + unit_state <- unitState <$> getDynFlags ; -- Dump short output if -ddump-types or -ddump-tc when (dopt Opt_D_dump_types dflags || dopt Opt_D_dump_tc dflags) (dumpTcRn True (dumpOptionsFromFlag Opt_D_dump_types) - "" FormatText short_dump) ; + "" FormatText (pprWithUnitState unit_state short_dump)) ; -- Dump bindings if -ddump-tc dumpOptTcRn Opt_D_dump_tc "Typechecker" FormatHaskell full_dump; ===================================== compiler/GHC/Tc/Utils/Backpack.hs ===================================== @@ -234,16 +234,15 @@ check_inst sig_inst = do -- | Return this list of requirement interfaces that need to be merged -- to form @mod_name@, or @[]@ if this is not a requirement. requirementMerges :: UnitState -> ModuleName -> [InstantiatedModule] -requirementMerges pkgstate mod_name = - fmap fixupModule $ fromMaybe [] (Map.lookup mod_name (requirementContext pkgstate)) +requirementMerges unit_state mod_name = + fmap fixupModule $ fromMaybe [] (Map.lookup mod_name (requirementContext unit_state)) where -- update IndefUnitId ppr info as they may have changed since the -- time the IndefUnitId was created fixupModule (Module iud name) = Module iud' name where - iud' = iud { instUnitInstanceOf = cid' } + iud' = iud { instUnitInstanceOf = cid } cid = instUnitInstanceOf iud - cid' = updateIndefUnitId pkgstate cid -- | For a module @modname@ of type 'HscSource', determine the list -- of extra "imports" of other requirements which should be considered part of @@ -276,8 +275,8 @@ findExtraSigImports' hsc_env HsigFile modname = $ moduleFreeHolesPrecise (text "findExtraSigImports") (mkModule (VirtUnit iuid) mod_name))) where - pkgstate = unitState (hsc_dflags hsc_env) - reqs = requirementMerges pkgstate modname + unit_state = unitState (hsc_dflags hsc_env) + reqs = requirementMerges unit_state modname findExtraSigImports' _ _ _ = return emptyUniqDSet @@ -535,17 +534,17 @@ mergeSignatures }) $ do tcg_env <- getGblEnv - let outer_mod = tcg_mod tcg_env - inner_mod = tcg_semantic_mod tcg_env - mod_name = moduleName (tcg_mod tcg_env) - pkgstate = unitState dflags - home_unit = mkHomeUnitFromFlags dflags + let outer_mod = tcg_mod tcg_env + inner_mod = tcg_semantic_mod tcg_env + mod_name = moduleName (tcg_mod tcg_env) + unit_state = unitState dflags + home_unit = mkHomeUnitFromFlags dflags -- STEP 1: Figure out all of the external signature interfaces -- we are going to merge in. - let reqs = requirementMerges pkgstate mod_name + let reqs = requirementMerges unit_state mod_name - addErrCtxt (merge_msg mod_name reqs) $ do + addErrCtxt (pprWithUnitState unit_state $ merge_msg mod_name reqs) $ do -- STEP 2: Read in the RAW forms of all of these interfaces ireq_ifaces0 <- forM reqs $ \(Module iuid mod_name) -> @@ -572,7 +571,7 @@ mergeSignatures let insts = instUnitInsts iuid isFromSignaturePackage = let inst_uid = instUnitInstanceOf iuid - pkg = unsafeLookupUnitId pkgstate (indefUnit inst_uid) + pkg = unsafeLookupUnitId unit_state (indefUnit inst_uid) in null (unitExposedModules pkg) -- 3(a). Rename the exports according to how the dependency -- was instantiated. The resulting export list will be accurate @@ -900,18 +899,21 @@ tcRnInstantiateSignature hsc_env this_mod real_loc = exportOccs :: [AvailInfo] -> [OccName] exportOccs = concatMap (map occName . availNames) -impl_msg :: Module -> InstantiatedModule -> SDoc -impl_msg impl_mod (Module req_uid req_mod_name) = - text "while checking that" <+> ppr impl_mod <+> - text "implements signature" <+> ppr req_mod_name <+> - text "in" <+> ppr req_uid +impl_msg :: UnitState -> Module -> InstantiatedModule -> SDoc +impl_msg unit_state impl_mod (Module req_uid req_mod_name) + = pprWithUnitState unit_state $ + text "while checking that" <+> ppr impl_mod <+> + text "implements signature" <+> ppr req_mod_name <+> + text "in" <+> ppr req_uid -- | Check if module implements a signature. (The signature is -- always un-hashed, which is why its components are specified -- explicitly.) checkImplements :: Module -> InstantiatedModule -> TcRn TcGblEnv -checkImplements impl_mod req_mod@(Module uid mod_name) = - addErrCtxt (impl_msg impl_mod req_mod) $ do +checkImplements impl_mod req_mod@(Module uid mod_name) = do + dflags <- getDynFlags + let unit_state = unitState dflags + addErrCtxt (impl_msg unit_state impl_mod req_mod) $ do let insts = instUnitInsts uid -- STEP 1: Load the implementing interface, and make a RdrEnv @@ -931,7 +933,6 @@ checkImplements impl_mod req_mod@(Module uid mod_name) = loadModuleInterfaces (text "Loading orphan modules (from implementor of hsig)") (dep_orphs (mi_deps impl_iface)) - dflags <- getDynFlags let avails = calculateAvails dflags impl_iface False{- safe -} NotBoot ImportedBySystem fix_env = mkNameEnv [ (gre_name rdr_elt, FixItem occ f) @@ -969,9 +970,8 @@ checkImplements impl_mod req_mod@(Module uid mod_name) = forM_ (exportOccs (mi_exports isig_iface)) $ \occ -> case lookupGlobalRdrEnv impl_gr occ of [] -> addErr $ quotes (ppr occ) - <+> text "is exported by the hsig file, but not" - <+> text "exported by the implementing module" - <+> quotes (ppr impl_mod) + <+> text "is exported by the hsig file, but not exported by the implementing module" + <+> quotes (pprWithUnitState unit_state $ ppr impl_mod) _ -> return () failIfErrsM @@ -1002,15 +1002,12 @@ instantiateSignature = do let outer_mod = tcg_mod tcg_env inner_mod = tcg_semantic_mod tcg_env home_unit = mkHomeUnitFromFlags dflags - unit_state = unitState dflags -- TODO: setup the local RdrEnv so the error messages look a little better. -- But this information isn't stored anywhere. Should we RETYPECHECK -- the local one just to get the information? Hmm... MASSERT( isHomeModule home_unit outer_mod ) MASSERT( isHomeUnitInstantiating home_unit) - -- we need to fetch the most recent ppr infos from the unit - -- database because we might have modified it - let uid = mkIndefUnitId unit_state (homeUnitInstanceOf home_unit) + let uid = Indefinite (homeUnitInstanceOf home_unit) inner_mod `checkImplements` Module (mkInstantiatedUnit uid (homeUnitInstantiations home_unit)) ===================================== compiler/GHC/Tc/Utils/Instantiate.hs ===================================== @@ -80,6 +80,7 @@ import GHC.Utils.Panic import GHC.Utils.Outputable import GHC.Types.Basic ( TypeOrKind(..) ) import qualified GHC.LanguageExtensions as LangExt +import GHC.Unit.State import Data.List ( sortBy, mapAccumL ) import Control.Monad( unless ) @@ -972,9 +973,10 @@ dupInstErr ispec dup_ispec [ispec, dup_ispec] addClsInstsErr :: SDoc -> [ClsInst] -> TcRn () -addClsInstsErr herald ispecs - = setSrcSpan (getSrcSpan (head sorted)) $ - addErr (hang herald 2 (pprInstances sorted)) +addClsInstsErr herald ispecs = do + unit_state <- unitState <$> getDynFlags + setSrcSpan (getSrcSpan (head sorted)) $ + addErr $ pprWithUnitState unit_state $ (hang herald 2 (pprInstances sorted)) where sorted = sortBy (SrcLoc.leftmost_smallest `on` getSrcSpan) ispecs -- The sortBy just arranges that instances are displayed in order ===================================== compiler/GHC/Tc/Utils/Monad.hs ===================================== @@ -977,13 +977,19 @@ mkLongErrAt :: SrcSpan -> MsgDoc -> MsgDoc -> TcRn ErrMsg mkLongErrAt loc msg extra = do { dflags <- getDynFlags ; printer <- getPrintUnqualified dflags ; - return $ mkLongErrMsg dflags loc printer msg extra } + unit_state <- unitState <$> getDynFlags ; + let msg' = pprWithUnitState unit_state msg in + return $ mkLongErrMsg dflags loc printer msg' extra } mkErrDocAt :: SrcSpan -> ErrDoc -> TcRn ErrMsg mkErrDocAt loc errDoc = do { dflags <- getDynFlags ; printer <- getPrintUnqualified dflags ; - return $ mkErrDoc dflags loc printer errDoc } + unit_state <- unitState <$> getDynFlags ; + let f = pprWithUnitState unit_state + errDoc' = mapErrDoc f errDoc + in + return $ mkErrDoc dflags loc printer errDoc' } addLongErrAt :: SrcSpan -> MsgDoc -> MsgDoc -> TcRn () addLongErrAt loc msg extra = mkLongErrAt loc msg extra >>= reportError ===================================== compiler/GHC/Unit.hs ===================================== @@ -272,39 +272,58 @@ themselves. It is a reminiscence of previous terminology (when "instanceOf" was TODO: We should probably have `instanceOf :: Maybe IndefUnitId` instead. -Pretty-printing UnitId ----------------------- +Note [Pretty-printing UnitId] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When we pretty-print a UnitId for the user, we try to map it back to its origin +package name, version and component to print "package-version:component" instead +of some hash. How to retrieve these information from a UnitId? + +Solution 0: ask for a UnitState to be passed each time we want to pretty-print a +SDoc so that the Outputable instance for UnitId could retrieve the information +from it. That what we used in the past: a DynFlags was passed and the UnitState +was retrieved from it. This is wrong for several reasons: + + 1. The UnitState is accessed when the message is printed, not when it is + generated. So we could imagine that the UnitState could have changed + in-between. Especially if we want to allow unit unloading. + + 2. We want GHC to support several independent sessions at once, hence + several UnitState. This approach supposes there is a unique UnitState + (the one given at printing-time), moreover a UnitId doesn't indicate + which UnitState it comes from (think about statically defined UnitId for + wired-in units). + +Solution 1: an obvious approach would be to store the required information in +the UnitId itself. However it doesn't work because some UnitId are defined +statically for wired-in units and the same UnitId can map to different units in +different contexts. This solution would make wired-in units harder to deal with. + +Solution 2: another approach would be to thread the UnitState to all places +where a UnitId is pretty-printed and to retrieve the information from the +UnitState only when needed. It would mean that UnitId couldn't have an +Outputable instance as it would need an additional UnitState parameter to be +printed. It means that many other types couldn't have an Outputable instance +either: Unit, Module, Name, InstEnv, etc. Too many to make this solution +feasible. + +Solution 3: the approach we use is a compromise between solutions 0 and 2: the +appropriate UnitState has to be threaded close enough to the function generating +the SDoc so that the latter can use `pprWithUnitState` to set the UnitState to +fetch information from. However the UnitState doesn't have to be threaded +explicitly all the way down to the point where the UnitId itself is printed: +instead the Outputable instance of UnitId fetches the "sdocUnitIdForUser" +field in the SDocContext to pretty-print. + + 1. We can still have Outputable instances for common types (Module, Unit, + Name, etc.) + + 2. End-users don't have to pass a UnitState (via a DynFlags) to print a SDoc. + + 3. By default "sdocUnitIdForUser" prints the UnitId hash. In case of a bug + (i.e. GHC doesn't correctly call `pprWithUnitState` before pretty-printing a + UnitId), that's what will be shown to the user so it's no big deal. -GHC mostly deals with UnitIds which are some opaque strings. We could display -them when we pretty-print a module origin, a name, etc. But it wouldn't be -very friendly to the user because of the hash they usually contain. E.g. - - foo-4.18.1:thelib-XYZsomeUglyHashABC - -Instead when we want to pretty-print a 'UnitId' we query the database to -get the 'UnitInfo' and print something nicer to the user: - - foo-4.18.1:thelib - -We do the same for wired-in units. - -Currently (2020-04-06), we don't thread the database into every function that -pretty-prints a Name/Module/Unit. Instead querying the database is delayed -until the `SDoc` is transformed into a `Doc` using the database that is -active at this point in time. This is an issue because we want to be able to -unload units from the database and we also want to support several -independent databases loaded at the same time (see #14335). The alternatives -we have are: - - * threading the database into every function that pretty-prints a UnitId - for the user (directly or indirectly). - - * storing enough info to correctly display a UnitId into the UnitId - datatype itself. This is done in the IndefUnitId wrapper (see - 'UnitPprInfo' datatype) but not for every 'UnitId'. Statically defined - 'UnitId' for wired-in units would have empty UnitPprInfo so we need to - find some places to update them if we want to display wired-in UnitId - correctly. This leads to a solution similar to the first one above. Note [VirtUnit to RealUnit improvement] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/Unit/Home.hs ===================================== @@ -105,7 +105,7 @@ homeUnitInstanceOfMaybe _ = Nothing -- produce any code object that rely on the unit id of this virtual unit. homeUnitAsUnit :: HomeUnit -> Unit homeUnitAsUnit (DefiniteHomeUnit u _) = RealUnit (Definite u) -homeUnitAsUnit (IndefiniteHomeUnit u is) = mkVirtUnit (Indefinite u Nothing) is +homeUnitAsUnit (IndefiniteHomeUnit u is) = mkVirtUnit (Indefinite u) is -- | Map over the unit identifier for instantiating units homeUnitMap :: IsUnitId v => (u -> v) -> GenHomeUnit u -> GenHomeUnit v ===================================== compiler/GHC/Unit/Info.hs ===================================== @@ -68,7 +68,7 @@ mkUnitKeyInfo = mapGenericUnitInfo mkPackageName' = PackageName . mkFastStringByteString mkUnitKey' = UnitKey . mkFastStringByteString mkModuleName' = mkModuleNameFS . mkFastStringByteString - mkIndefUnitKey' cid = Indefinite (mkUnitKey' cid) Nothing + mkIndefUnitKey' cid = Indefinite (mkUnitKey' cid) mkVirtUnitKey' i = case i of DbInstUnitId cid insts -> mkVirtUnit (mkIndefUnitKey' cid) (fmap (bimap mkModuleName' mkModule') insts) DbUnitId uid -> RealUnit (Definite (mkUnitKey' uid)) ===================================== compiler/GHC/Unit/Parser.hs ===================================== @@ -36,7 +36,7 @@ parseUnitId = do parseIndefUnitId :: ReadP IndefUnitId parseIndefUnitId = do uid <- parseUnitId - return (Indefinite uid Nothing) + return (Indefinite uid) parseHoleyModule :: ReadP Module parseHoleyModule = parseModuleVar <++ parseModule ===================================== compiler/GHC/Unit/State.hs ===================================== @@ -68,10 +68,9 @@ module GHC.Unit.State ( pprUnitIdForUser, pprUnitInfoForUser, pprModuleMap, + pprWithUnitState, -- * Utils - mkIndefUnitId, - updateIndefUnitId, unwireUnit ) where @@ -2128,15 +2127,6 @@ pprUnitInfoForUser info = ppr (mkUnitPprInfo unitIdFS info) lookupUnitPprInfo :: UnitState -> UnitId -> Maybe UnitPprInfo lookupUnitPprInfo state uid = fmap (mkUnitPprInfo unitIdFS) (lookupUnitId state uid) --- | Create a IndefUnitId. -mkIndefUnitId :: UnitState -> UnitId -> IndefUnitId -mkIndefUnitId state uid = Indefinite uid $! lookupUnitPprInfo state uid - --- | Update component ID details from the database -updateIndefUnitId :: UnitState -> IndefUnitId -> IndefUnitId -updateIndefUnitId pkgstate uid = mkIndefUnitId pkgstate (indefUnit uid) - - -- ----------------------------------------------------------------------------- -- Displaying packages @@ -2270,3 +2260,8 @@ instModuleToModule :: UnitState -> InstantiatedModule -> Module instModuleToModule pkgstate (Module iuid mod_name) = mkModule (instUnitToUnit pkgstate iuid) mod_name +-- | Print unit-ids with UnitInfo found in the given UnitState +pprWithUnitState :: UnitState -> SDoc -> SDoc +pprWithUnitState state = updSDocContext (\ctx -> ctx + { sdocUnitIdForUser = \fs -> pprUnitIdForUser state (UnitId fs) + }) ===================================== compiler/GHC/Unit/State.hs-boot ===================================== @@ -1,12 +1,11 @@ module GHC.Unit.State where import {-# SOURCE #-} GHC.Utils.Outputable -import {-# SOURCE #-} GHC.Unit.Types (IndefUnitId, UnitId) +import {-# SOURCE #-} GHC.Unit.Types (UnitId) data UnitState data UnitDatabase unit emptyUnitState :: UnitState -mkIndefUnitId :: UnitState -> UnitId -> IndefUnitId pprUnitIdForUser :: UnitState -> UnitId -> SDoc -updateIndefUnitId :: UnitState -> IndefUnitId -> IndefUnitId +pprWithUnitState :: UnitState -> SDoc -> SDoc ===================================== compiler/GHC/Unit/Types.hs ===================================== @@ -2,6 +2,8 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE DerivingStrategies #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} -- | Unit & Module types -- @@ -87,7 +89,6 @@ where import GHC.Prelude import GHC.Types.Unique import GHC.Types.Unique.DSet -import GHC.Unit.Ppr import GHC.Unit.Module.Name import GHC.Utils.Binary import GHC.Utils.Outputable @@ -104,9 +105,6 @@ import Data.Bifunctor import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as BS.Char8 -import {-# SOURCE #-} GHC.Unit.State (pprUnitIdForUser) -import {-# SOURCE #-} GHC.Driver.Session (unitState) - --------------------------------------------------------------------- -- MODULES --------------------------------------------------------------------- @@ -186,12 +184,6 @@ instance IsUnitId u => IsUnitId (GenUnit u) where unitFS (RealUnit (Definite x)) = unitFS x unitFS HoleUnit = holeFS -instance IsUnitId u => IsUnitId (Definite u) where - unitFS (Definite x) = unitFS x - -instance IsUnitId u => IsUnitId (Indefinite u) where - unitFS (Indefinite x _) = unitFS x - pprModule :: Module -> SDoc pprModule mod@(Module p n) = getPprStyle doc where @@ -365,12 +357,6 @@ instance Binary Unit where 1 -> fmap VirtUnit (get bh) _ -> pure HoleUnit -instance Binary unit => Binary (Indefinite unit) where - put_ bh (Indefinite fs _) = put_ bh fs - get bh = do { fs <- get bh; return (Indefinite fs Nothing) } - - - -- | Retrieve the set of free module holes of a 'Unit'. unitFreeModuleHoles :: GenUnit u -> UniqDSet ModuleName unitFreeModuleHoles (VirtUnit x) = instUnitHoles x @@ -524,7 +510,8 @@ instance Uniquable UnitId where getUnique = getUnique . unitIdFS instance Outputable UnitId where - ppr uid = sdocWithDynFlags $ \dflags -> pprUnitIdForUser (unitState dflags) uid + ppr (UnitId fs) = sdocOption sdocUnitIdForUser ($ fs) -- see Note [Pretty-printing UnitId] + -- in "GHC.Unit" -- | A 'DefUnitId' is an 'UnitId' with the invariant that -- it only refers to a definite library; i.e., one we have generated @@ -543,44 +530,16 @@ stringToUnitId = UnitId . mkFastString -- | A definite unit (i.e. without any free module hole) newtype Definite unit = Definite { unDefinite :: unit } - deriving (Eq, Ord, Functor) - -instance Outputable unit => Outputable (Definite unit) where - ppr (Definite uid) = ppr uid - -instance Binary unit => Binary (Definite unit) where - put_ bh (Definite uid) = put_ bh uid - get bh = do uid <- get bh; return (Definite uid) - + deriving (Functor) + deriving newtype (Eq, Ord, Outputable, Binary, Uniquable, IsUnitId) -- | An 'IndefUnitId' is an 'UnitId' with the invariant that it only -- refers to an indefinite library; i.e., one that can be instantiated. type IndefUnitId = Indefinite UnitId -data Indefinite unit = Indefinite - { indefUnit :: !unit -- ^ Unit identifier - , indefUnitPprInfo :: Maybe UnitPprInfo -- ^ Cache for some unit info retrieved from the DB - } +newtype Indefinite unit = Indefinite { indefUnit :: unit } deriving (Functor) - -instance Eq unit => Eq (Indefinite unit) where - a == b = indefUnit a == indefUnit b - -instance Ord unit => Ord (Indefinite unit) where - compare a b = compare (indefUnit a) (indefUnit b) - - -instance Uniquable unit => Uniquable (Indefinite unit) where - getUnique (Indefinite n _) = getUnique n - -instance Outputable unit => Outputable (Indefinite unit) where - ppr (Indefinite uid Nothing) = ppr uid - ppr (Indefinite uid (Just pprinfo)) = - getPprDebug $ \debug -> - if debug - then ppr uid - else ppr pprinfo - + deriving newtype (Eq, Ord, Outputable, Binary, Uniquable, IsUnitId) --------------------------------------------------------------------- -- WIRED-IN UNITS ===================================== compiler/GHC/Utils/Error.hs ===================================== @@ -18,6 +18,7 @@ module GHC.Utils.Error ( -- * Messages ErrMsg, errMsgDoc, errMsgSeverity, errMsgReason, ErrDoc, errDoc, errDocImportant, errDocContext, errDocSupplementary, + mapErrDoc, WarnMsg, MsgDoc, Messages, ErrorMessages, WarningMessages, unionMessages, @@ -162,6 +163,9 @@ data ErrDoc = ErrDoc { errDoc :: [MsgDoc] -> [MsgDoc] -> [MsgDoc] -> ErrDoc errDoc = ErrDoc +mapErrDoc :: (MsgDoc -> MsgDoc) -> ErrDoc -> ErrDoc +mapErrDoc f (ErrDoc a b c) = ErrDoc (map f a) (map f b) (map f c) + type WarnMsg = ErrMsg data Severity @@ -635,11 +639,12 @@ fatalErrorMsg dflags msg = fatalErrorMsg'' :: FatalMessager -> String -> IO () fatalErrorMsg'' fm msg = fm msg -compilationProgressMsg :: DynFlags -> String -> IO () +compilationProgressMsg :: DynFlags -> SDoc -> IO () compilationProgressMsg dflags msg = do - traceEventIO $ "GHC progress: " ++ msg + let str = showSDoc dflags msg + traceEventIO $ "GHC progress: " ++ str ifVerbose dflags 1 $ - logOutput dflags $ withPprStyle defaultUserStyle (text msg) + logOutput dflags $ withPprStyle defaultUserStyle msg showPass :: DynFlags -> String -> IO () showPass dflags what ===================================== compiler/GHC/Utils/Outputable.hs ===================================== @@ -357,6 +357,20 @@ data SDocContext = SDC , sdocLinearTypes :: !Bool , sdocImpredicativeTypes :: !Bool , sdocPrintTypeAbbreviations :: !Bool + , sdocUnitIdForUser :: !(FastString -> SDoc) + -- ^ Used to map UnitIds to more friendly "package-version:component" + -- strings while pretty-printing. + -- + -- Use `GHC.Unit.State.pprWithUnitState` to set it. Users should never + -- have to set it to pretty-print SDocs emitted by GHC, otherwise it's a + -- bug. It's an internal field used to thread the UnitState so that the + -- Outputable instance of UnitId can use it. + -- + -- See Note [Pretty-printing UnitId] in "GHC.Unit" for more details. + -- + -- Note that we use `FastString` instead of `UnitId` to avoid boring + -- module inter-dependency issues. + , sdocDynFlags :: DynFlags -- TODO: remove } @@ -404,6 +418,7 @@ defaultSDocContext = SDC , sdocImpredicativeTypes = False , sdocLinearTypes = False , sdocPrintTypeAbbreviations = True + , sdocUnitIdForUser = ftext , sdocDynFlags = error "defaultSDocContext: DynFlags not available" } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0b17fa185aec793861364afd9a05aa4219fbc019 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0b17fa185aec793861364afd9a05aa4219fbc019 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 08:51:42 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 26 Aug 2020 04:51:42 -0400 Subject: [Git][ghc/ghc][master] Bignum: fix BigNat subtraction (#18604) Message-ID: <5f46229e59e0b_80b3f84902b125095314fd@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: dc476a50 by Sylvain Henry at 2020-08-26T04:51:35-04:00 Bignum: fix BigNat subtraction (#18604) There was a confusion between the boolean expected by withNewWordArrayTrimedMaybe and the boolean returned by subtracting functions. - - - - - 7 changed files: - libraries/ghc-bignum/src/GHC/Num/BigNat.hs - libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs - libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs - libraries/ghc-bignum/src/GHC/Num/WordArray.hs - + testsuite/tests/numeric/should_run/T18604.hs - + testsuite/tests/numeric/should_run/T18604.stdout - testsuite/tests/numeric/should_run/all.T Changes: ===================================== libraries/ghc-bignum/src/GHC/Num/BigNat.hs ===================================== @@ -506,7 +506,7 @@ bigNatSubUnsafe a b let szA = wordArraySize# a in withNewWordArrayTrimed# szA \mwa s-> case inline bignat_sub mwa a b s of - (# s', 0# #) -> s' + (# s', 1# #) -> s' (# s', _ #) -> case raiseUnderflow of !_ -> s' -- see Note [ghc-bignum exceptions] in ===================================== libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs ===================================== @@ -92,8 +92,8 @@ bignat_sub {-# INLINE bignat_sub #-} bignat_sub mwa wa wb s = case ioWord# (c_mpn_sub mwa wa (wordArraySize# wa) wb (wordArraySize# wb)) s of - (# s', 0## #) -> (# s', 0# #) - (# s', _ #) -> (# s', 1# #) + (# s', 1## #) -> (# s', 0# #) -- overflow + (# s', _ #) -> (# s', 1# #) -- no overflow bignat_sub_word :: MutableWordArray# RealWorld @@ -104,8 +104,8 @@ bignat_sub_word {-# INLINE bignat_sub_word #-} bignat_sub_word mwa wa b s = case ioWord# (c_mpn_sub_1 mwa wa (wordArraySize# wa) b) s of - (# s', 0## #) -> (# s', 0# #) - (# s', _ #) -> (# s', 1# #) + (# s', 1## #) -> (# s', 0# #) -- overflow + (# s', _ #) -> (# s', 1# #) -- no overflow bignat_mul :: MutableWordArray# RealWorld ===================================== libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs ===================================== @@ -127,17 +127,17 @@ bignat_sub_word mwa wa b = go b 0# !sz = wordArraySize# wa go carry i s | isTrue# (i >=# sz) - = (# s, carry `neWord#` 0## #) + = (# s, carry `eqWord#` 0## #) | 0## <- carry = case mwaArrayCopy# mwa i wa i (sz -# i) s of - s' -> (# s', 0# #) + s' -> (# s', 1# #) -- no overflow | True = case subWordC# (indexWordArray# wa i) carry of (# 0##, 0# #) | isTrue# (i ==# sz) -> case mwaShrink# mwa 1# s of - s' -> (# s', 0# #) + s' -> (# s', 1# #) -- no overflow (# l , c #) -> case mwaWrite# mwa i l s of s1 -> go (int2Word# c) (i +# 1#) s1 ===================================== libraries/ghc-bignum/src/GHC/Num/WordArray.hs ===================================== @@ -318,7 +318,7 @@ mwaAddInplaceWord# mwa i y s = case readWordArray# mwa i s of -- | Sub Word# inplace (at the specified offset) in the mwa with carry -- propagation. -- --- Return True# on overflow +-- Return False# on overflow mwaSubInplaceWord# :: MutableWordArray# d -> Int# @@ -328,9 +328,9 @@ mwaSubInplaceWord# mwaSubInplaceWord# mwa ii iw s1 = case mwaSize# mwa s1 of (# is, sz #) -> let - go _ 0## s = (# s, 0# #) -- no overflow + go _ 0## s = (# s, 1# #) -- no overflow go i y s - | isTrue# (i >=# sz) = (# s, 1# #) -- overflow + | isTrue# (i >=# sz) = (# s, 0# #) -- overflow | True = case readWordArray# mwa i s of (# s1, x #) -> let !(# l,h #) = subWordC# x y in case mwaWrite# mwa i l s1 of @@ -368,16 +368,16 @@ mwaTrimCompare k mwa wb s1 -- -- We don't trim the resulting array! -- --- Return True# on overflow. +-- Return False# on overflow. mwaSubInplaceArray :: MutableWordArray# d -> Int# -> WordArray# -> State# d -> (# State# d, Bool# #) mwaSubInplaceArray mwa off wb = go (wordArraySize# wb -# 1#) where go i s - | isTrue# (i <# 0#) = (# s, 0# #) -- no overflow + | isTrue# (i <# 0#) = (# s, 1# #) -- no overflow | True = case mwaSubInplaceWord# mwa (off +# i) (indexWordArray# wb i) s of - (# s2, 0# #) -> go (i -# 1#) s2 - (# s2, _ #) -> (# s2, 1# #) -- overflow + (# s2, 1# #) -> go (i -# 1#) s2 + (# s2, _ #) -> (# s2, 0# #) -- overflow -- | Add array inplace (a the specified offset) in the mwa with carry propagation. -- @@ -398,19 +398,19 @@ mwaAddInplaceArray mwa off wb = go 0# 0## -- -- We don't trim the resulting array! -- --- Return True# on overflow. +-- Return False# on overflow. mwaSubInplaceMutableArray :: MutableWordArray# d -> Int# -> MutableWordArray# d -> State# d -> (# State# d, Bool# #) mwaSubInplaceMutableArray mwa off mwb s0 = case mwaSize# mwb s0 of (# s1, szB #) -> go (szB -# 1#) s1 where go i s - | isTrue# (i <# 0#) = (# s, 0# #) -- no overflow + | isTrue# (i <# 0#) = (# s, 1# #) -- no overflow | True = case readWordArray# mwb i s of (# s1, bi #) -> case mwaSubInplaceWord# mwa (off +# i) bi s1 of - (# s2, 0# #) -> go (i -# 1#) s2 - (# s2, _ #) -> (# s2, 1# #) -- overflow + (# s2, 1# #) -> go (i -# 1#) s2 + (# s2, _ #) -> (# s2, 0# #) -- overflow -- | Sub an array inplace and then trim zeroes -- ===================================== testsuite/tests/numeric/should_run/T18604.hs ===================================== @@ -0,0 +1,10 @@ +module Main (main) where + +import Numeric.Natural + +main :: IO () +main = print (n - s) + where + n, s :: Natural + n = 137503105969312982142385040956303729937425409769904987267247644890331944583201 + s = 370814112419299627365008243601943822482 ===================================== testsuite/tests/numeric/should_run/T18604.stdout ===================================== @@ -0,0 +1 @@ +137503105969312982142385040956303729937054595657485687639882636646730000760719 ===================================== testsuite/tests/numeric/should_run/all.T ===================================== @@ -73,3 +73,4 @@ test('T18359', normal, compile_and_run, ['']) test('T18499', normal, compile_and_run, ['']) test('T18509', normal, compile_and_run, ['']) test('T18515', normal, compile_and_run, ['']) +test('T18604', normal, compile_and_run, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dc476a5040cdc64c177de0f78edaafec0972cff4 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dc476a5040cdc64c177de0f78edaafec0972cff4 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 09:08:54 2020 From: gitlab at gitlab.haskell.org (Andreas Klebinger) Date: Wed, 26 Aug 2020 05:08:54 -0400 Subject: [Git][ghc/ghc][wip/andreask/dom-lt-fixes] 2 commits: Update dominator code with fixes from the dom-lt package. Message-ID: <5f4626a6ea208_80b3f84693c1eb49533673@gitlab.haskell.org.mail> Andreas Klebinger pushed to branch wip/andreask/dom-lt-fixes at Glasgow Haskell Compiler / GHC Commits: 85b691ea by Andreas Klebinger at 2020-08-26T11:07:26+02:00 Update dominator code with fixes from the dom-lt package. Two bugs turned out in the package that have been fixed since. This MR includes this fixes in the GHC port of the code. - - - - - b3999181 by Andreas Klebinger at 2020-08-26T11:08:37+02:00 Dominators.hs: Use unix line endings - - - - - 1 changed file: - compiler/GHC/CmmToAsm/CFG/Dominators.hs Changes: ===================================== compiler/GHC/CmmToAsm/CFG/Dominators.hs ===================================== @@ -1,597 +1,563 @@ -{-# LANGUAGE RankNTypes, BangPatterns, FlexibleContexts, Strict #-} - -{- | - Module : Dominators - Copyright : (c) Matt Morrow 2009 - License : BSD3 - Maintainer : - Stability : experimental - Portability : portable - - Taken from the dom-lt package. - - The Lengauer-Tarjan graph dominators algorithm. - - \[1\] Lengauer, Tarjan, - /A Fast Algorithm for Finding Dominators in a Flowgraph/, 1979. - - \[2\] Muchnick, - /Advanced Compiler Design and Implementation/, 1997. - - \[3\] Brisk, Sarrafzadeh, - /Interference Graphs for Procedures in Static Single/ - /Information Form are Interval Graphs/, 2007. - - Originally taken from the dom-lt package. --} - -module GHC.CmmToAsm.CFG.Dominators ( - Node,Path,Edge - ,Graph,Rooted - ,idom,ipdom - ,domTree,pdomTree - ,dom,pdom - ,pddfs,rpddfs - ,fromAdj,fromEdges - ,toAdj,toEdges - ,asTree,asGraph - ,parents,ancestors -) where - -import GHC.Prelude - -import Data.Bifunctor -import Data.Tuple (swap) - -import Data.Tree -import Data.IntMap(IntMap) -import Data.IntSet(IntSet) -import qualified Data.IntMap.Strict as IM -import qualified Data.IntSet as IS - -import Control.Monad -import Control.Monad.ST.Strict - -import Data.Array.ST -import Data.Array.Base hiding ((!)) - -- (unsafeNewArray_ - -- ,unsafeWrite,unsafeRead - -- ,readArray,writeArray) - -import GHC.Utils.Misc (debugIsOn) - ------------------------------------------------------------------------------ - -type Node = Int -type Path = [Node] -type Edge = (Node,Node) -type Graph = IntMap IntSet -type Rooted = (Node, Graph) - ------------------------------------------------------------------------------ - --- | /Dominators/. --- Complexity as for @idom@ -dom :: Rooted -> [(Node, Path)] -dom = ancestors . domTree - --- | /Post-dominators/. --- Complexity as for @idom at . -pdom :: Rooted -> [(Node, Path)] -pdom = ancestors . pdomTree - --- | /Dominator tree/. --- Complexity as for @idom at . -domTree :: Rooted -> Tree Node -domTree a@(r,_) = - let is = filter ((/=r).fst) (idom a) - tg = fromEdges (fmap swap is) - in asTree (r,tg) - --- | /Post-dominator tree/. --- Complexity as for @idom at . -pdomTree :: Rooted -> Tree Node -pdomTree a@(r,_) = - let is = filter ((/=r).fst) (ipdom a) - tg = fromEdges (fmap swap is) - in asTree (r,tg) - --- | /Immediate dominators/. --- /O(|E|*alpha(|E|,|V|))/, where /alpha(m,n)/ is --- \"a functional inverse of Ackermann's function\". --- --- This Complexity bound assumes /O(1)/ indexing. Since we're --- using @IntMap@, it has an additional /lg |V|/ factor --- somewhere in there. I'm not sure where. -idom :: Rooted -> [(Node,Node)] -idom rg = runST (evalS idomM =<< initEnv (pruneReach rg)) - --- | /Immediate post-dominators/. --- Complexity as for @idom at . -ipdom :: Rooted -> [(Node,Node)] -ipdom rg = runST (evalS idomM =<< initEnv (pruneReach (second predG rg))) - ------------------------------------------------------------------------------ - --- | /Post-dominated depth-first search/. -pddfs :: Rooted -> [Node] -pddfs = reverse . rpddfs - --- | /Reverse post-dominated depth-first search/. -rpddfs :: Rooted -> [Node] -rpddfs = concat . levels . pdomTree - ------------------------------------------------------------------------------ - -type Dom s a = S s (Env s) a -type NodeSet = IntSet -type NodeMap a = IntMap a -data Env s = Env - {succE :: !Graph - ,predE :: !Graph - ,bucketE :: !Graph - ,dfsE :: {-# UNPACK #-}!Int - ,zeroE :: {-# UNPACK #-}!Node - ,rootE :: {-# UNPACK #-}!Node - ,labelE :: {-# UNPACK #-}!(Arr s Node) - ,parentE :: {-# UNPACK #-}!(Arr s Node) - ,ancestorE :: {-# UNPACK #-}!(Arr s Node) - ,childE :: {-# UNPACK #-}!(Arr s Node) - ,ndfsE :: {-# UNPACK #-}!(Arr s Node) - ,dfnE :: {-# UNPACK #-}!(Arr s Int) - ,sdnoE :: {-# UNPACK #-}!(Arr s Int) - ,sizeE :: {-# UNPACK #-}!(Arr s Int) - ,domE :: {-# UNPACK #-}!(Arr s Node) - ,rnE :: {-# UNPACK #-}!(Arr s Node)} - ------------------------------------------------------------------------------ - -idomM :: Dom s [(Node,Node)] -idomM = do - dfsDom =<< rootM - n <- gets dfsE - forM_ [n,n-1..1] (\i-> do - w <- ndfsM i - sw <- sdnoM w - ps <- predsM w - forM_ ps (\v-> do - u <- eval v - su <- sdnoM u - when (su < sw) - (store sdnoE w su)) - z <- ndfsM =<< sdnoM w - modify(\e->e{bucketE=IM.adjust - (w`IS.insert`) - z (bucketE e)}) - pw <- parentM w - link pw w - bps <- bucketM pw - forM_ bps (\v-> do - u <- eval v - su <- sdnoM u - sv <- sdnoM v - let dv = case su < sv of - True-> u - False-> pw - store domE v dv)) - forM_ [1..n] (\i-> do - w <- ndfsM i - j <- sdnoM w - z <- ndfsM j - dw <- domM w - when (dw /= z) - (do ddw <- domM dw - store domE w ddw)) - fromEnv - ------------------------------------------------------------------------------ - -eval :: Node -> Dom s Node -eval v = do - n0 <- zeroM - a <- ancestorM v - case a==n0 of - True-> labelM v - False-> do - compress v - a <- ancestorM v - l <- labelM v - la <- labelM a - sl <- sdnoM l - sla <- sdnoM la - case sl <= sla of - True-> return l - False-> return la - -compress :: Node -> Dom s () -compress v = do - n0 <- zeroM - a <- ancestorM v - aa <- ancestorM a - when (aa /= n0) (do - compress a - a <- ancestorM v - aa <- ancestorM a - l <- labelM v - la <- labelM a - sl <- sdnoM l - sla <- sdnoM la - when (sla < sl) - (store labelE v la) - store ancestorE v aa) - ------------------------------------------------------------------------------ - -link :: Node -> Node -> Dom s () -link v w = do - n0 <- zeroM - lw <- labelM w - slw <- sdnoM lw - let balance s = do - c <- childM s - lc <- labelM c - slc <- sdnoM lc - case slw < slc of - False-> return s - True-> do - zs <- sizeM s - zc <- sizeM c - cc <- childM c - zcc <- sizeM cc - case 2*zc <= zs+zcc of - True-> do - store ancestorE c s - store childE s cc - balance s - False-> do - store sizeE c zs - store ancestorE s c - balance c - s <- balance w - lw <- labelM w - zw <- sizeM w - store labelE s lw - store sizeE v . (+zw) =<< sizeM v - let follow s = do - when (s /= n0) (do - store ancestorE s v - follow =<< childM s) - zv <- sizeM v - follow =<< case zv < 2*zw of - False-> return s - True-> do - cv <- childM v - store childE v s - return cv - ------------------------------------------------------------------------------ - -dfsDom :: Node -> Dom s () -dfsDom i = do - _ <- go i - n0 <- zeroM - r <- rootM - store parentE r n0 - where go i = do - n <- nextM - store dfnE i n - store sdnoE i n - store ndfsE n i - store labelE i i - ss <- succsM i - forM_ ss (\j-> do - s <- sdnoM j - case s==0 of - False-> return() - True-> do - store parentE j i - go j) - ------------------------------------------------------------------------------ - -initEnv :: Rooted -> ST s (Env s) -initEnv (r0,g0) = do - let (g,rnmap) = renum 1 g0 - pred = predG g - r = rnmap IM.! r0 - n = IM.size g - ns = [0..n] - m = n+1 - - let bucket = IM.fromList - (zip ns (repeat mempty)) - - rna <- newI m - writes rna (fmap swap - (IM.toList rnmap)) - - doms <- newI m - sdno <- newI m - size <- newI m - parent <- newI m - ancestor <- newI m - child <- newI m - label <- newI m - ndfs <- newI m - dfn <- newI m - - forM_ [0..n] (doms.=0) - forM_ [0..n] (sdno.=0) - forM_ [1..n] (size.=1) - forM_ [0..n] (ancestor.=0) - forM_ [0..n] (child.=0) - - (doms.=r) r - (size.=0) 0 - (label.=0) 0 - - return (Env - {rnE = rna - ,dfsE = 0 - ,zeroE = 0 - ,rootE = r - ,labelE = label - ,parentE = parent - ,ancestorE = ancestor - ,childE = child - ,ndfsE = ndfs - ,dfnE = dfn - ,sdnoE = sdno - ,sizeE = size - ,succE = g - ,predE = pred - ,bucketE = bucket - ,domE = doms}) - -fromEnv :: Dom s [(Node,Node)] -fromEnv = do - dom <- gets domE - rn <- gets rnE - -- r <- gets rootE - (_,n) <- st (getBounds dom) - forM [1..n] (\i-> do - j <- st(rn!:i) - d <- st(dom!:i) - k <- st(rn!:d) - return (j,k)) - ------------------------------------------------------------------------------ - -zeroM :: Dom s Node -zeroM = gets zeroE -domM :: Node -> Dom s Node -domM = fetch domE -rootM :: Dom s Node -rootM = gets rootE -succsM :: Node -> Dom s [Node] -succsM i = gets (IS.toList . (! i) . succE) -predsM :: Node -> Dom s [Node] -predsM i = gets (IS.toList . (! i) . predE) -bucketM :: Node -> Dom s [Node] -bucketM i = gets (IS.toList . (! i) . bucketE) -sizeM :: Node -> Dom s Int -sizeM = fetch sizeE -sdnoM :: Node -> Dom s Int -sdnoM = fetch sdnoE --- dfnM :: Node -> Dom s Int --- dfnM = fetch dfnE -ndfsM :: Int -> Dom s Node -ndfsM = fetch ndfsE -childM :: Node -> Dom s Node -childM = fetch childE -ancestorM :: Node -> Dom s Node -ancestorM = fetch ancestorE -parentM :: Node -> Dom s Node -parentM = fetch parentE -labelM :: Node -> Dom s Node -labelM = fetch labelE -nextM :: Dom s Int -nextM = do - n <- gets dfsE - let n' = n+1 - modify(\e->e{dfsE=n'}) - return n' - ------------------------------------------------------------------------------ - -type A = STUArray -type Arr s a = A s Int a - -infixl 9 !: -infixr 2 .= - -(.=) :: (MArray (A s) a (ST s)) - => Arr s a -> a -> Int -> ST s () -(v .= x) i - | debugIsOn = writeArray v i x - | otherwise = unsafeWrite v i x - -(!:) :: (MArray (A s) a (ST s)) - => A s Int a -> Int -> ST s a -a !: i - | debugIsOn = do - o <- readArray a i - return $! o - | otherwise = do - o <- unsafeRead a i - return $! o - -new :: (MArray (A s) a (ST s)) - => Int -> ST s (Arr s a) -new n = unsafeNewArray_ (0,n-1) - -newI :: Int -> ST s (Arr s Int) -newI = new - --- newD :: Int -> ST s (Arr s Double) --- newD = new - --- dump :: (MArray (A s) a (ST s)) => Arr s a -> ST s [a] --- dump a = do --- (m,n) <- getBounds a --- forM [m..n] (\i -> a!:i) - -writes :: (MArray (A s) a (ST s)) - => Arr s a -> [(Int,a)] -> ST s () -writes a xs = forM_ xs (\(i,x) -> (a.=x) i) - --- arr :: (MArray (A s) a (ST s)) => [a] -> ST s (Arr s a) --- arr xs = do --- let n = length xs --- a <- new n --- go a n 0 xs --- return a --- where go _ _ _ [] = return () --- go a n i (x:xs) --- | i <= n = (a.=x) i >> go a n (i+1) xs --- | otherwise = return () - ------------------------------------------------------------------------------ - -(!) :: Monoid a => IntMap a -> Int -> a -(!) g n = maybe mempty id (IM.lookup n g) - -fromAdj :: [(Node, [Node])] -> Graph -fromAdj = IM.fromList . fmap (second IS.fromList) - -fromEdges :: [Edge] -> Graph -fromEdges = collectI IS.union fst (IS.singleton . snd) - -toAdj :: Graph -> [(Node, [Node])] -toAdj = fmap (second IS.toList) . IM.toList - -toEdges :: Graph -> [Edge] -toEdges = concatMap (uncurry (fmap . (,))) . toAdj - -predG :: Graph -> Graph -predG g = IM.unionWith IS.union (go g) g0 - where g0 = fmap (const mempty) g - f :: IntMap IntSet -> Int -> IntSet -> IntMap IntSet - f m i a = foldl' (\m p -> IM.insertWith mappend p - (IS.singleton i) m) - m - (IS.toList a) - go :: IntMap IntSet -> IntMap IntSet - go = flip IM.foldlWithKey' mempty f - -pruneReach :: Rooted -> Rooted -pruneReach (r,g) = (r,g2) - where is = reachable - (maybe mempty id - . flip IM.lookup g) $ r - g2 = IM.fromList - . fmap (second (IS.filter (`IS.member`is))) - . filter ((`IS.member`is) . fst) - . IM.toList $ g - -tip :: Tree a -> (a, [Tree a]) -tip (Node a ts) = (a, ts) - -parents :: Tree a -> [(a, a)] -parents (Node i xs) = p i xs - ++ concatMap parents xs - where p i = fmap (flip (,) i . rootLabel) - -ancestors :: Tree a -> [(a, [a])] -ancestors = go [] - where go acc (Node i xs) - = let acc' = i:acc - in p acc' xs ++ concatMap (go acc') xs - p is = fmap (flip (,) is . rootLabel) - -asGraph :: Tree Node -> Rooted -asGraph t@(Node a _) = let g = go t in (a, fromAdj g) - where go (Node a ts) = let as = (fst . unzip . fmap tip) ts - in (a, as) : concatMap go ts - -asTree :: Rooted -> Tree Node -asTree (r,g) = let go a = Node a (fmap go ((IS.toList . f) a)) - f = (g !) - in go r - -reachable :: (Node -> NodeSet) -> (Node -> NodeSet) -reachable f a = go (IS.singleton a) a - where go seen a = let s = f a - as = IS.toList (s `IS.difference` seen) - in foldl' go (s `IS.union` seen) as - -collectI :: (c -> c -> c) - -> (a -> Int) -> (a -> c) -> [a] -> IntMap c -collectI (<>) f g - = foldl' (\m a -> IM.insertWith (<>) - (f a) - (g a) m) mempty - --- collect :: (Ord b) => (c -> c -> c) --- -> (a -> b) -> (a -> c) -> [a] -> Map b c --- collect (<>) f g --- = foldl' (\m a -> SM.insertWith (<>) --- (f a) --- (g a) m) mempty - --- (renamed, old -> new) -renum :: Int -> Graph -> (Graph, NodeMap Node) -renum from = (\(_,m,g)->(g,m)) - . IM.foldlWithKey' - f (from,mempty,mempty) - where - f :: (Int, NodeMap Node, IntMap IntSet) -> Node -> IntSet - -> (Int, NodeMap Node, IntMap IntSet) - f (!n,!env,!new) i ss = - let (j,n2,env2) = go n env i - (n3,env3,ss2) = IS.fold - (\k (!n,!env,!new)-> - case go n env k of - (l,n2,env2)-> (n2,env2,l `IS.insert` new)) - (n2,env2,mempty) ss - new2 = IM.insertWith IS.union j ss2 new - in (n3,env3,new2) - go :: Int - -> NodeMap Node - -> Node - -> (Node,Int,NodeMap Node) - go !n !env i = - case IM.lookup i env of - Just j -> (j,n,env) - Nothing -> (n,n+1,IM.insert i n env) - ------------------------------------------------------------------------------ - -newtype S z s a = S {unS :: forall o. (a -> s -> ST z o) -> s -> ST z o} -instance Functor (S z s) where - fmap f (S g) = S (\k -> g (k . f)) -instance Monad (S z s) where - return = pure - S g >>= f = S (\k -> g (\a -> unS (f a) k)) -instance Applicative (S z s) where - pure a = S (\k -> k a) - (<*>) = ap --- get :: S z s s --- get = S (\k s -> k s s) -gets :: (s -> a) -> S z s a -gets f = S (\k s -> k (f s) s) --- set :: s -> S z s () --- set s = S (\k _ -> k () s) -modify :: (s -> s) -> S z s () -modify f = S (\k -> k () . f) --- runS :: S z s a -> s -> ST z (a, s) --- runS (S g) = g (\a s -> return (a,s)) -evalS :: S z s a -> s -> ST z a -evalS (S g) = g ((return .) . const) --- execS :: S z s a -> s -> ST z s --- execS (S g) = g ((return .) . flip const) -st :: ST z a -> S z s a -st m = S (\k s-> do - a <- m - k a s) -store :: (MArray (A z) a (ST z)) - => (s -> Arr z a) -> Int -> a -> S z s () -store f i x = do - a <- gets f - st ((a.=x) i) -fetch :: (MArray (A z) a (ST z)) - => (s -> Arr z a) -> Int -> S z s a -fetch f i = do - a <- gets f - st (a!:i) - +{-# LANGUAGE RankNTypes, BangPatterns, FlexibleContexts, Strict #-} + +{- | + Module : GHC.CmmToAsm.CFG.Dominators + Copyright : (c) Matt Morrow 2009 + License : BSD3 + Maintainer : + Stability : stable + Portability : portable + + The Lengauer-Tarjan graph dominators algorithm. + + \[1\] Lengauer, Tarjan, + /A Fast Algorithm for Finding Dominators in a Flowgraph/, 1979. + + \[2\] Muchnick, + /Advanced Compiler Design and Implementation/, 1997. + + \[3\] Brisk, Sarrafzadeh, + /Interference Graphs for Procedures in Static Single/ + /Information Form are Interval Graphs/, 2007. + + * Strictness + + Unless stated otherwise all exposed functions might fully evaluate their input + but are not guaranteed to do so. + +-} + +module GHC.CmmToAsm.CFG.Dominators ( + Node,Path,Edge + ,Graph,Rooted + ,idom,ipdom + ,domTree,pdomTree + ,dom,pdom + ,pddfs,rpddfs + ,fromAdj,fromEdges + ,toAdj,toEdges + ,asTree,asGraph + ,parents,ancestors +) where + +import GHC.Prelude +import Data.Bifunctor +import Data.Tuple (swap) + +import Data.Tree +import Data.IntMap(IntMap) +import Data.IntSet(IntSet) +import qualified Data.IntMap.Strict as IM +import qualified Data.IntSet as IS + +import Control.Monad +import Control.Monad.ST.Strict + +import Data.Array.ST +import Data.Array.Base + (unsafeNewArray_ + ,unsafeWrite,unsafeRead) + +----------------------------------------------------------------------------- + +type Node = Int +type Path = [Node] +type Edge = (Node,Node) +type Graph = IntMap IntSet +type Rooted = (Node, Graph) + +----------------------------------------------------------------------------- + +-- | /Dominators/. +-- Complexity as for @idom@ +dom :: Rooted -> [(Node, Path)] +dom = ancestors . domTree + +-- | /Post-dominators/. +-- Complexity as for @idom at . +pdom :: Rooted -> [(Node, Path)] +pdom = ancestors . pdomTree + +-- | /Dominator tree/. +-- Complexity as for @idom at . +domTree :: Rooted -> Tree Node +domTree a@(r,_) = + let is = filter ((/=r).fst) (idom a) + tg = fromEdges (fmap swap is) + in asTree (r,tg) + +-- | /Post-dominator tree/. +-- Complexity as for @idom at . +pdomTree :: Rooted -> Tree Node +pdomTree a@(r,_) = + let is = filter ((/=r).fst) (ipdom a) + tg = fromEdges (fmap swap is) + in asTree (r,tg) + +-- | /Immediate dominators/. +-- /O(|E|*alpha(|E|,|V|))/, where /alpha(m,n)/ is +-- \"a functional inverse of Ackermann's function\". +-- +-- This Complexity bound assumes /O(1)/ indexing. Since we're +-- using @IntMap@, it has an additional /lg |V|/ factor +-- somewhere in there. I'm not sure where. +idom :: Rooted -> [(Node,Node)] +idom rg = runST (evalS idomM =<< initEnv (pruneReach rg)) + +-- | /Immediate post-dominators/. +-- Complexity as for @idom at . +ipdom :: Rooted -> [(Node,Node)] +ipdom rg = runST (evalS idomM =<< initEnv (pruneReach (second predG rg))) + +----------------------------------------------------------------------------- + +-- | /Post-dominated depth-first search/. +pddfs :: Rooted -> [Node] +pddfs = reverse . rpddfs + +-- | /Reverse post-dominated depth-first search/. +rpddfs :: Rooted -> [Node] +rpddfs = concat . levels . pdomTree + +----------------------------------------------------------------------------- + +type Dom s a = S s (Env s) a +type NodeSet = IntSet +type NodeMap a = IntMap a +data Env s = Env + {succE :: !Graph + ,predE :: !Graph + ,bucketE :: !Graph + ,dfsE :: {-# UNPACK #-}!Int + ,zeroE :: {-# UNPACK #-}!Node + ,rootE :: {-# UNPACK #-}!Node + ,labelE :: {-# UNPACK #-}!(Arr s Node) + ,parentE :: {-# UNPACK #-}!(Arr s Node) + ,ancestorE :: {-# UNPACK #-}!(Arr s Node) + ,childE :: {-# UNPACK #-}!(Arr s Node) + ,ndfsE :: {-# UNPACK #-}!(Arr s Node) + ,dfnE :: {-# UNPACK #-}!(Arr s Int) + ,sdnoE :: {-# UNPACK #-}!(Arr s Int) + ,sizeE :: {-# UNPACK #-}!(Arr s Int) + ,domE :: {-# UNPACK #-}!(Arr s Node) + ,rnE :: {-# UNPACK #-}!(Arr s Node)} + +----------------------------------------------------------------------------- + +idomM :: Dom s [(Node,Node)] +idomM = do + dfsDom =<< rootM + n <- gets dfsE + forM_ [n,n-1..1] (\i-> do + w <- ndfsM i + ps <- predsM w + forM_ ps (\v-> do + sw <- sdnoM w + u <- eval v + su <- sdnoM u + when (su < sw) + (store sdnoE w su)) + z <- ndfsM =<< sdnoM w + modify(\e->e{bucketE=IM.adjust + (w`IS.insert`) + z (bucketE e)}) + pw <- parentM w + link pw w + bps <- bucketM pw + forM_ bps (\v-> do + u <- eval v + su <- sdnoM u + sv <- sdnoM v + let dv = case su < sv of + True-> u + False-> pw + store domE v dv)) + forM_ [1..n] (\i-> do + w <- ndfsM i + j <- sdnoM w + z <- ndfsM j + dw <- domM w + when (dw /= z) + (do ddw <- domM dw + store domE w ddw)) + fromEnv + +----------------------------------------------------------------------------- + +eval :: Node -> Dom s Node +eval v = do + n0 <- zeroM + a <- ancestorM v + case a==n0 of + True-> labelM v + False-> do + compress v + a <- ancestorM v + l <- labelM v + la <- labelM a + sl <- sdnoM l + sla <- sdnoM la + case sl <= sla of + True-> return l + False-> return la + +compress :: Node -> Dom s () +compress v = do + n0 <- zeroM + a <- ancestorM v + aa <- ancestorM a + when (aa /= n0) (do + compress a + a <- ancestorM v + aa <- ancestorM a + l <- labelM v + la <- labelM a + sl <- sdnoM l + sla <- sdnoM la + when (sla < sl) + (store labelE v la) + store ancestorE v aa) + +----------------------------------------------------------------------------- + +link :: Node -> Node -> Dom s () +link v w = do + n0 <- zeroM + lw <- labelM w + slw <- sdnoM lw + let balance s = do + c <- childM s + lc <- labelM c + slc <- sdnoM lc + case slw < slc of + False-> return s + True-> do + zs <- sizeM s + zc <- sizeM c + cc <- childM c + zcc <- sizeM cc + case 2*zc <= zs+zcc of + True-> do + store ancestorE c s + store childE s cc + balance s + False-> do + store sizeE c zs + store ancestorE s c + balance c + s <- balance w + lw <- labelM w + zw <- sizeM w + store labelE s lw + store sizeE v . (+zw) =<< sizeM v + let follow s = do + when (s /= n0) (do + store ancestorE s v + follow =<< childM s) + zv <- sizeM v + follow =<< case zv < 2*zw of + False-> return s + True-> do + cv <- childM v + store childE v s + return cv + +----------------------------------------------------------------------------- + +dfsDom :: Node -> Dom s () +dfsDom i = do + _ <- go i + n0 <- zeroM + r <- rootM + store parentE r n0 + where go i = do + n <- nextM + store dfnE i n + store sdnoE i n + store ndfsE n i + store labelE i i + ss <- succsM i + forM_ ss (\j-> do + s <- sdnoM j + case s==0 of + False-> return() + True-> do + store parentE j i + go j) + +----------------------------------------------------------------------------- + +initEnv :: Rooted -> ST s (Env s) +initEnv (r0,g0) = do + -- Graph renumbered to indices from 1 to |V| + let (g,rnmap) = renum 1 g0 + pred = predG g -- reverse graph + root = rnmap IM.! r0 -- renamed root + n = IM.size g + ns = [0..n] + m = n+1 + + let bucket = IM.fromList + (zip ns (repeat mempty)) + + rna <- newI m + writes rna (fmap swap + (IM.toList rnmap)) + + doms <- newI m + sdno <- newI m + size <- newI m + parent <- newI m + ancestor <- newI m + child <- newI m + label <- newI m + ndfs <- newI m + dfn <- newI m + + -- Initialize all arrays + forM_ [0..n] (doms.=0) + forM_ [0..n] (sdno.=0) + forM_ [1..n] (size.=1) + forM_ [0..n] (ancestor.=0) + forM_ [0..n] (child.=0) + + (doms.=root) root + (size.=0) 0 + (label.=0) 0 + + return (Env + {rnE = rna + ,dfsE = 0 + ,zeroE = 0 + ,rootE = root + ,labelE = label + ,parentE = parent + ,ancestorE = ancestor + ,childE = child + ,ndfsE = ndfs + ,dfnE = dfn + ,sdnoE = sdno + ,sizeE = size + ,succE = g + ,predE = pred + ,bucketE = bucket + ,domE = doms}) + +fromEnv :: Dom s [(Node,Node)] +fromEnv = do + dom <- gets domE + rn <- gets rnE + -- r <- gets rootE + (_,n) <- st (getBounds dom) + forM [1..n] (\i-> do + j <- st(rn!:i) + d <- st(dom!:i) + k <- st(rn!:d) + return (j,k)) + +----------------------------------------------------------------------------- + +zeroM :: Dom s Node +zeroM = gets zeroE +domM :: Node -> Dom s Node +domM = fetch domE +rootM :: Dom s Node +rootM = gets rootE +succsM :: Node -> Dom s [Node] +succsM i = gets (IS.toList . (! i) . succE) +predsM :: Node -> Dom s [Node] +predsM i = gets (IS.toList . (! i) . predE) +bucketM :: Node -> Dom s [Node] +bucketM i = gets (IS.toList . (! i) . bucketE) +sizeM :: Node -> Dom s Int +sizeM = fetch sizeE +sdnoM :: Node -> Dom s Int +sdnoM = fetch sdnoE +-- dfnM :: Node -> Dom s Int +-- dfnM = fetch dfnE +ndfsM :: Int -> Dom s Node +ndfsM = fetch ndfsE +childM :: Node -> Dom s Node +childM = fetch childE +ancestorM :: Node -> Dom s Node +ancestorM = fetch ancestorE +parentM :: Node -> Dom s Node +parentM = fetch parentE +labelM :: Node -> Dom s Node +labelM = fetch labelE +nextM :: Dom s Int +nextM = do + n <- gets dfsE + let n' = n+1 + modify(\e->e{dfsE=n'}) + return n' + +----------------------------------------------------------------------------- + +type A = STUArray +type Arr s a = A s Int a + +infixl 9 !: +infixr 2 .= + +-- | arr .= x idx => write x to index +(.=) :: (MArray (A s) a (ST s)) + => Arr s a -> a -> Int -> ST s () +(v .= x) i = unsafeWrite v i x + +(!:) :: (MArray (A s) a (ST s)) + => A s Int a -> Int -> ST s a +a !: i = do + o <- unsafeRead a i + return $! o + +new :: (MArray (A s) a (ST s)) + => Int -> ST s (Arr s a) +new n = unsafeNewArray_ (0,n-1) + +newI :: Int -> ST s (Arr s Int) +newI = new + +writes :: (MArray (A s) a (ST s)) + => Arr s a -> [(Int,a)] -> ST s () +writes a xs = forM_ xs (\(i,x) -> (a.=x) i) + + +(!) :: Monoid a => IntMap a -> Int -> a +(!) g n = maybe mempty id (IM.lookup n g) + +fromAdj :: [(Node, [Node])] -> Graph +fromAdj = IM.fromList . fmap (second IS.fromList) + +fromEdges :: [Edge] -> Graph +fromEdges = collectI IS.union fst (IS.singleton . snd) + +toAdj :: Graph -> [(Node, [Node])] +toAdj = fmap (second IS.toList) . IM.toList + +toEdges :: Graph -> [Edge] +toEdges = concatMap (uncurry (fmap . (,))) . toAdj + +predG :: Graph -> Graph +predG g = IM.unionWith IS.union (go g) g0 + where g0 = fmap (const mempty) g + go = flip IM.foldrWithKey mempty (\i a m -> + foldl' (\m p -> IM.insertWith mappend p + (IS.singleton i) m) + m + (IS.toList a)) + +pruneReach :: Rooted -> Rooted +pruneReach (r,g) = (r,g2) + where is = reachable + (maybe mempty id + . flip IM.lookup g) $ r + g2 = IM.fromList + . fmap (second (IS.filter (`IS.member`is))) + . filter ((`IS.member`is) . fst) + . IM.toList $ g + +tip :: Tree a -> (a, [Tree a]) +tip (Node a ts) = (a, ts) + +parents :: Tree a -> [(a, a)] +parents (Node i xs) = p i xs + ++ concatMap parents xs + where p i = fmap (flip (,) i . rootLabel) + +ancestors :: Tree a -> [(a, [a])] +ancestors = go [] + where go acc (Node i xs) + = let acc' = i:acc + in p acc' xs ++ concatMap (go acc') xs + p is = fmap (flip (,) is . rootLabel) + +asGraph :: Tree Node -> Rooted +asGraph t@(Node a _) = let g = go t in (a, fromAdj g) + where go (Node a ts) = let as = (fst . unzip . fmap tip) ts + in (a, as) : concatMap go ts + +asTree :: Rooted -> Tree Node +asTree (r,g) = let go a = Node a (fmap go ((IS.toList . f) a)) + f = (g !) + in go r + +reachable :: (Node -> NodeSet) -> (Node -> NodeSet) +reachable f a = go (IS.singleton a) a + where go seen a = let s = f a + as = IS.toList (s `IS.difference` seen) + in foldl' go (s `IS.union` seen) as + +collectI :: (c -> c -> c) + -> (a -> Int) -> (a -> c) -> [a] -> IntMap c +collectI (<>) f g + = foldl' (\m a -> IM.insertWith (<>) + (f a) + (g a) m) mempty + +-- | renum n g: Rename all nodes +-- +-- Gives nodes sequential names starting at n. +-- Returns the new graph and a mapping. +-- (renamed, old -> new) +renum :: Int -> Graph -> (Graph, NodeMap Node) +renum from = (\(_,m,g)->(g,m)) + . IM.foldrWithKey + (\i ss (!n,!env,!new)-> + let (j,n2,env2) = go n env i + (n3,env3,ss2) = IS.fold + (\k (!n,!env,!new)-> + case go n env k of + (l,n2,env2)-> (n2,env2,l `IS.insert` new)) + (n2,env2,mempty) ss + new2 = IM.insertWith IS.union j ss2 new + in (n3,env3,new2)) (from,mempty,mempty) + where go :: Int + -> NodeMap Node + -> Node + -> (Node,Int,NodeMap Node) + go !n !env i = + case IM.lookup i env of + Just j -> (j,n,env) + Nothing -> (n,n+1,IM.insert i n env) + +----------------------------------------------------------------------------- + +-- Nothing better than reinvinting the state monad. +newtype S z s a = S {unS :: forall o. (a -> s -> ST z o) -> s -> ST z o} +instance Functor (S z s) where + fmap f (S g) = S (\k -> g (k . f)) +instance Monad (S z s) where + return = pure + S g >>= f = S (\k -> g (\a -> unS (f a) k)) +instance Applicative (S z s) where + pure a = S (\k -> k a) + (<*>) = ap +-- get :: S z s s +-- get = S (\k s -> k s s) +gets :: (s -> a) -> S z s a +gets f = S (\k s -> k (f s) s) +-- set :: s -> S z s () +-- set s = S (\k _ -> k () s) +modify :: (s -> s) -> S z s () +modify f = S (\k -> k () . f) +-- runS :: S z s a -> s -> ST z (a, s) +-- runS (S g) = g (\a s -> return (a,s)) +evalS :: S z s a -> s -> ST z a +evalS (S g) = g ((return .) . const) +-- execS :: S z s a -> s -> ST z s +-- execS (S g) = g ((return .) . flip const) +st :: ST z a -> S z s a +st m = S (\k s-> do + a <- m + k a s) +store :: (MArray (A z) a (ST z)) + => (s -> Arr z a) -> Int -> a -> S z s () +store f i x = do + a <- gets f + st ((a.=x) i) +fetch :: (MArray (A z) a (ST z)) + => (s -> Arr z a) -> Int -> S z s a +fetch f i = do + a <- gets f + st (a!:i) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fa115f2a88adfd16eddeda68ca08860d2bb4f343...b3999181045e119cd015868ecd016993b18dd7ab -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fa115f2a88adfd16eddeda68ca08860d2bb4f343...b3999181045e119cd015868ecd016993b18dd7ab You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 09:22:33 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 26 Aug 2020 05:22:33 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 6 commits: linters: Make CPP linter skip image files Message-ID: <5f4629d92b418_80b3f8495f2fc98954211@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 2d635a50 by Takenobu Tani at 2020-08-26T04:50:21-04:00 linters: Make CPP linter skip image files This patch adds an exclusion rule for `docs/users_guide/images`, to avoid lint errors of PDF files. - - - - - b7d98cb2 by Takenobu Tani at 2020-08-26T04:50:21-04:00 users-guide: Color the logo on the front page of the PDF This patch updates the logo with a recent color scheme. This affects only the PDF version of the user's guide. See also: * https://mail.haskell.org/pipermail/ghc-devs/2020-August/019139.html * https://gitlab.haskell.org/ghc/ghc/-/wikis/logo - - - - - 0b17fa18 by Sylvain Henry at 2020-08-26T04:50:58-04:00 Refactor UnitId pretty-printing When we pretty-print a UnitId for the user, we try to map it back to its origin package name, version and component to print "package-version:component" instead of some hash. The UnitId type doesn't carry these information, so we have to look into a UnitState to find them. This is why the Outputable instance of UnitId used `sdocWithDynFlags` in order to access the `unitState` field of DynFlags. This is wrong for several reasons: 1. The DynFlags are accessed when the message is printed, not when it is generated. So we could imagine that the unitState may have changed in-between. Especially if we want to allow unit unloading. 2. We want GHC to support several independent sessions at once, hence several UnitState. The current approach supposes there is a unique UnitState as a UnitId doesn't indicate which UnitState to use. See the Note [Pretty-printing UnitId] in GHC.Unit for the new approach implemented by this patch. One step closer to remove `sdocDynFlags` field from `SDocContext` (#10143). Fix #18124. Also fix some Backpack code to use SDoc instead of String. - - - - - dc476a50 by Sylvain Henry at 2020-08-26T04:51:35-04:00 Bignum: fix BigNat subtraction (#18604) There was a confusion between the boolean expected by withNewWordArrayTrimedMaybe and the boolean returned by subtracting functions. - - - - - c70a0d21 by Peter Trommler at 2020-08-26T05:22:19-04:00 PPC and X86: Portable printing of IEEE floats GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness. This was brought up in #18431 by @hsyl20. - - - - - bbc1e10b by Krzysztof Gogolewski at 2020-08-26T05:22:25-04:00 primops: Remove Monadic and Dyadic categories There were four categories of primops: Monadic, Dyadic, Compare, GenPrimOp. The compiler does not treat Monadic and Dyadic in any special way, we can just replace them with GenPrimOp. Compare is still used in isComparisonPrimOp. - - - - - 30 changed files: - .gitlab/linters/check-cpp.py - compiler/GHC.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/Ppr.hs - compiler/GHC/CmmToAsm/SPARC/Ppr.hs - compiler/GHC/CmmToAsm/X86/Ppr.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Driver/Finder.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/Runtime/Eval.hs - compiler/GHC/StgToCmm/Prim.hs - compiler/GHC/Tc/Module.hs - compiler/GHC/Tc/Utils/Backpack.hs - compiler/GHC/Tc/Utils/Instantiate.hs - compiler/GHC/Tc/Utils/Monad.hs - compiler/GHC/Unit.hs - compiler/GHC/Unit/Home.hs - compiler/GHC/Unit/Info.hs - compiler/GHC/Unit/Parser.hs - compiler/GHC/Unit/State.hs - compiler/GHC/Unit/State.hs-boot - compiler/GHC/Unit/Types.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4d1425f54776668b8e22d6d245a08cee31114224...bbc1e10b276a2f37d29dc0f35c21866bd1f8202d -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4d1425f54776668b8e22d6d245a08cee31114224...bbc1e10b276a2f37d29dc0f35c21866bd1f8202d You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 09:38:11 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Wed, 26 Aug 2020 05:38:11 -0400 Subject: [Git][ghc/ghc][wip/T18223] Better eta-expansion (again) and don't specilise DFuns Message-ID: <5f462d83292ac_80b3f8495f2fc9895424c0@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18223 at Glasgow Haskell Compiler / GHC Commits: 9b2e3687 by Simon Peyton Jones at 2020-08-26T10:36:09+01:00 Better eta-expansion (again) and don't specilise DFuns This patch fixes #18223, which made GHC generate an exponential amount of code. There are three quite separate changes in here 1. Re-engineer eta-expansion (again). The eta-expander was generating lots of intermediate stuff, which could be optimised away, but which choked the simplifier meanwhile. Relatively easy to kill it off at source. See Note [The EtaInfo mechanism] in GHC.Core.Opt.Arity. The main new thing is the use of pushCoArg in getArg_maybe. 2. Stop Specialise specalising DFuns. This is the cause of a huge (and utterly unnecessary) blowup in program size in #18223. See Note [Do not specialise DFuns] in GHC.Core.Opt.Specialise. I also refactored the Specialise monad a bit... it was silly, because it passed on unchanging values as if they were mutable state. 3. Do an extra Simplifer run, after SpecConstra and before late-Specialise. I found (investigating perf/compiler/T16473) that failing to do this was crippling *both* SpecConstr *and* Specialise. See Note [Simplify after SpecConstr] in GHC.Core.Opt.Pipeline. This change does mean an extra run of the Simplifier, but only with -O2, and I think that's acceptable. T16473 allocates *three* times less with this change. (I changed it to check runtime rather than compile time.) Some smaller consequences * I moved pushCoercion, pushCoArg and friends from SimpleOpt to Arity, because it was needed by the new etaInfoApp. And pushCoValArg now returns a MCoercion rather than Coercion for the argument Coercion. * A minor, incidental improvement to Core pretty-printing This does fix #18223, (which was otherwise uncompilable. Hooray. But there is still a big intermediate because there are some very deeply nested types in that program. Modest reductions in compile-time allocation on a couple of benchmarks T12425 -2.0% T13253 -10.3% Metric increase with -O2, due to extra simplifier run T9233 +5.8% T12227 +1.8% T15630 +5.0% Metric Increase T9233 T12227 Metric Decrease T12425 T13253 - - - - - 16 changed files: - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Env.hs - compiler/GHC/Core/Opt/Specialise.hs - compiler/GHC/Core/Ppr.hs - compiler/GHC/Core/SimpleOpt.hs - compiler/GHC/Core/Subst.hs - testsuite/tests/perf/compiler/Makefile - testsuite/tests/perf/compiler/T16473.stdout - + testsuite/tests/perf/compiler/T18223.hs - testsuite/tests/perf/compiler/all.T - testsuite/tests/printer/T18052a.stderr - testsuite/tests/simplCore/should_compile/T17966.stdout - testsuite/tests/stranal/should_compile/T18122.stderr Changes: ===================================== compiler/GHC/Core/Coercion.hs ===================================== @@ -31,7 +31,7 @@ module GHC.Core.Coercion ( mkAxInstRHS, mkUnbranchedAxInstRHS, mkAxInstLHS, mkUnbranchedAxInstLHS, mkPiCo, mkPiCos, mkCoCast, - mkSymCo, mkTransCo, mkTransMCo, + mkSymCo, mkTransCo, mkNthCo, nthCoRole, mkLRCo, mkInstCo, mkAppCo, mkAppCos, mkTyConAppCo, mkFunCo, mkForAllCo, mkForAllCos, mkHomoForAllCos, @@ -65,7 +65,8 @@ module GHC.Core.Coercion ( pickLR, isGReflCo, isReflCo, isReflCo_maybe, isGReflCo_maybe, isReflexiveCo, isReflexiveCo_maybe, - isReflCoVar_maybe, isGReflMCo, coToMCo, + isReflCoVar_maybe, isGReflMCo, + coToMCo, mkTransMCo, mkTransMCoL, -- ** Coercion variables mkCoVar, isCoVar, coVarName, setCoVarName, setCoVarUnique, @@ -288,6 +289,44 @@ tidyCoAxBndrsForUser init_env tcvs ('_' : rest) -> all isDigit rest _ -> False + +{- ********************************************************************* +* * + MCoercion +* * +********************************************************************* -} + +coToMCo :: Coercion -> MCoercion +-- Convert a coercion to a MCoercion, +-- It's not clear whether or not isReflexiveCo would be better here +coToMCo co | isReflCo co = MRefl + | otherwise = MCo co + +-- | Tests if this MCoercion is obviously generalized reflexive +-- Guaranteed to work very quickly. +isGReflMCo :: MCoercion -> Bool +isGReflMCo MRefl = True +isGReflMCo (MCo co) | isGReflCo co = True +isGReflMCo _ = False + +-- | Make a generalized reflexive coercion +mkGReflCo :: Role -> Type -> MCoercionN -> Coercion +mkGReflCo r ty mco + | isGReflMCo mco = if r == Nominal then Refl ty + else GRefl r ty MRefl + | otherwise = GRefl r ty mco + +-- | Compose two MCoercions via transitivity +mkTransMCo :: MCoercion -> MCoercion -> MCoercion +mkTransMCo MRefl co2 = co2 +mkTransMCo co1 MRefl = co1 +mkTransMCo (MCo co1) (MCo co2) = MCo (mkTransCo co1 co2) + +mkTransMCoL :: MCoercion -> Coercion -> MCoercion +mkTransMCoL MRefl co2 = MCo co2 +mkTransMCoL (MCo co1) co2 = MCo (mkTransCo co1 co2) + + {- %************************************************************************ %* * @@ -556,13 +595,6 @@ isGReflCo (GRefl{}) = True isGReflCo (Refl{}) = True -- Refl ty == GRefl N ty MRefl isGReflCo _ = False --- | Tests if this MCoercion is obviously generalized reflexive --- Guaranteed to work very quickly. -isGReflMCo :: MCoercion -> Bool -isGReflMCo MRefl = True -isGReflMCo (MCo co) | isGReflCo co = True -isGReflMCo _ = False - -- | Tests if this coercion is obviously reflexive. Guaranteed to work -- very quickly. Sometimes a coercion can be reflexive, but not obviously -- so. c.f. 'isReflexiveCo' @@ -603,10 +635,6 @@ isReflexiveCo_maybe co = Nothing where (Pair ty1 ty2, r) = coercionKindRole co -coToMCo :: Coercion -> MCoercion -coToMCo c = if isReflCo c - then MRefl - else MCo c {- %************************************************************************ @@ -669,13 +697,6 @@ role is bizarre and a caller should have to ask for this behavior explicitly. -} --- | Make a generalized reflexive coercion -mkGReflCo :: Role -> Type -> MCoercionN -> Coercion -mkGReflCo r ty mco - | isGReflMCo mco = if r == Nominal then Refl ty - else GRefl r ty MRefl - | otherwise = GRefl r ty mco - -- | Make a reflexive coercion mkReflCo :: Role -> Type -> Coercion mkReflCo Nominal ty = Refl ty @@ -990,12 +1011,6 @@ mkTransCo (GRefl r t1 (MCo co1)) (GRefl _ _ (MCo co2)) = GRefl r t1 (MCo $ mkTransCo co1 co2) mkTransCo co1 co2 = TransCo co1 co2 --- | Compose two MCoercions via transitivity -mkTransMCo :: MCoercion -> MCoercion -> MCoercion -mkTransMCo MRefl co2 = co2 -mkTransMCo co1 MRefl = co1 -mkTransMCo (MCo co1) (MCo co2) = MCo (mkTransCo co1 co2) - mkNthCo :: HasDebugCallStack => Role -- The role of the coercion you're creating -> Int -- Zero-indexed ===================================== compiler/GHC/Core/Opt/Arity.hs ===================================== @@ -15,10 +15,18 @@ module GHC.Core.Opt.Arity ( manifestArity, joinRhsArity, exprArity, typeArity , exprEtaExpandArity, findRhsArity , etaExpand, etaExpandAT - , etaExpandToJoinPoint, etaExpandToJoinPointRule , exprBotStrictness_maybe + + -- ** ArityType , ArityType(..), expandableArityType, arityTypeArity , maxWithArity, isBotArityType, idArityType + + -- ** Join points + , etaExpandToJoinPoint, etaExpandToJoinPointRule + + -- ** Coercions and casts + , pushCoArg, pushCoArgs, pushCoValArg, pushCoTyArg + , pushCoercionIntoLambda, pushCoDataCon, collectBindersPushingCo ) where @@ -31,15 +39,21 @@ import GHC.Driver.Ppr import GHC.Core import GHC.Core.FVs import GHC.Core.Utils -import GHC.Core.Subst import GHC.Types.Demand import GHC.Types.Var import GHC.Types.Var.Env import GHC.Types.Id -import GHC.Core.Type as Type -import GHC.Core.TyCon ( initRecTc, checkRecTc ) + +-- We have two sorts of substitution: +-- GHC.Core.Subst.Subst, and GHC.Core.TyCo.TCvSubst +-- Both have substTy, substCo Hence need for qualification +import GHC.Core.Subst as Core +import GHC.Core.Type as Type +import GHC.Core.Coercion as Type + +import GHC.Core.DataCon +import GHC.Core.TyCon ( initRecTc, checkRecTc, tyConArity ) import GHC.Core.Predicate ( isDictTy ) -import GHC.Core.Coercion as Coercion import GHC.Core.Multiplicity import GHC.Types.Var.Set import GHC.Types.Basic @@ -48,7 +62,8 @@ import GHC.Driver.Session ( DynFlags, GeneralFlag(..), gopt ) import GHC.Utils.Outputable import GHC.Utils.Panic import GHC.Data.FastString -import GHC.Utils.Misc ( lengthAtLeast ) +import GHC.Data.Pair +import GHC.Utils.Misc {- ************************************************************************ @@ -1076,12 +1091,11 @@ eta_expand one_shots orig_expr go oss (Cast expr co) = Cast (go oss expr) co go oss expr - = -- pprTrace "ee" (vcat [ppr orig_expr, ppr expr, ppr etas]) $ - retick $ etaInfoAbs etas (etaInfoApp subst' sexpr etas) + = -- pprTrace "ee" (vcat [ppr orig_expr, ppr expr, pprEtaInfos etas]) $ + retick $ etaInfoAbs etas (etaInfoApp in_scope' sexpr etas) where in_scope = mkInScopeSet (exprFreeVars expr) (in_scope', etas) = mkEtaWW oss (ppr orig_expr) in_scope (exprType expr) - subst' = mkEmptySubst in_scope' -- Find ticks behind type apps. -- See Note [Eta expansion and source notes] @@ -1090,76 +1104,191 @@ eta_expand one_shots orig_expr sexpr = foldl' App expr'' args retick expr = foldr mkTick expr ticks - -- Abstraction Application +{- ********************************************************************* +* * + The EtaInfo mechanism + mkEtaWW, etaInfoAbs, etaInfoApp +* * +********************************************************************* -} + +{- Note [The EtaInfo mechanism] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Suppose we have (e :: ty) and we want to eta-expand it to arity N. +This what eta_expand does. We do it in two steps: + +1. mkEtaWW: from 'ty' and 'N' build a [EtaInfo] which describes + the shape of the expansion necessary to expand to arity N. + +2. Build the term + \ v1..vn. e v1 .. vn + where those abstractions and applications are described by + the same [EtaInfo]. Specifically we build the term + + etaInfoAbs etas (etaInfoApp in_scope e etas) + + where etas :: [EtaInfo]# + etaInfoAbs builds the lambdas + etaInfoApp builds the applictions + + Note that the /same/ [EtaInfo] drives both etaInfoAbs and etaInfoApp + +To a first approximation [EtaInfo] is just [Var]. But +casts complicate the question. If we have + newtype N a = MkN (S -> a) +and + ty = N (N Int) +then the eta-expansion must look like + (\x (\y. ((e |> co1) x) |> co2) y) + |> sym co2) + |> sym co1 +where + co1 :: N (N Int) ~ S -> N Int + co2 :: N Int ~ S -> Int + +Blimey! Look at all those casts. Moreover, if the type +is very deeply nested (as happens in #18223), the repetition +of types can make the overall term very large. So there is a big +payoff in cancelling out casts aggressively wherever possible. +(See also Note [No crap in eta-expanded code].) + +This matters a lot in etaEInfoApp, where we +* Do beta-reduction on the fly +* Use getARg_mabye to get a cast out of the way, + so that we can do beta reduction +Together this makes a big difference. Consider when e is + case x of + True -> (\x -> e1) |> c1 + False -> (\p -> e2) |> c2 + +When we eta-expand this to arity 1, say, etaInfoAbs will wrap +a (\eta) around the outside and use etaInfoApp to apply each +alternative to 'eta'. We want to beta-reduce all that junk +away. + +#18223 was a dramtic example in which the intermediate term was +grotesquely huge, even though the next Simplifier iteration squashed +it. Better to kill it at birth. +-} + -------------- -data EtaInfo = EtaVar Var -- /\a. [] [] a - -- \x. [] [] x - | EtaCo Coercion -- [] |> sym co [] |> co +data EtaInfo -- Abstraction Application + = EtaVar Var -- /\a. [] [] a + -- (\x. []) [] x + | EtaCo CoercionR -- [] |> sym co [] |> co instance Outputable EtaInfo where - ppr (EtaVar v) = text "EtaVar" <+> ppr v - ppr (EtaCo co) = text "EtaCo" <+> ppr co + ppr (EtaVar v) = text "EtaVar" <+> ppr v <+> dcolon <+> ppr (idType v) + ppr (EtaCo co) = text "EtaCo" <+> hang (ppr co) 2 (dcolon <+> ppr (coercionType co)) + +-- Used in debug-printing +-- pprEtaInfos :: [EtaInfo] -> SDoc +-- pprEtaInfos eis = brackets $ vcat $ punctuate comma $ map ppr eis pushCoercion :: Coercion -> [EtaInfo] -> [EtaInfo] +-- Puts a EtaCo on the front of a [EtaInfo], but combining +-- with an existing EtaCo if possible +-- A minor improvement pushCoercion co1 (EtaCo co2 : eis) | isReflCo co = eis | otherwise = EtaCo co : eis where co = co1 `mkTransCo` co2 -pushCoercion co eis = EtaCo co : eis +pushCoercion co eis + = EtaCo co : eis + +getArg_maybe :: [EtaInfo] -> Maybe (CoreArg, [EtaInfo]) +-- Get an argument to the front of the [EtaInfo], if possible, +-- by pushing any EtaCo through the argument +getArg_maybe eis = go MRefl eis + where + go :: MCoercion -> [EtaInfo] -> Maybe (CoreArg, [EtaInfo]) + go _ [] = Nothing + go mco (EtaCo co2 : eis) = go (mkTransMCoL mco co2) eis + go MRefl (EtaVar v : eis) = Just (varToCoreExpr v, eis) + go (MCo co) (EtaVar v : eis) + | Just (arg, mco) <- pushCoArg co (varToCoreExpr v) + = case mco of + MRefl -> Just (arg, eis) + MCo co -> Just (arg, pushCoercion co eis) + | otherwise + = Nothing + +mkCastMCo :: CoreExpr -> MCoercionR -> CoreExpr +mkCastMCo e MRefl = e +mkCastMCo e (MCo co) = Cast e co + +mkPiMCo :: Var -> MCoercionR -> MCoercionR +mkPiMCo _ MRefl = MRefl +mkPiMCo v (MCo co) = MCo (mkPiCo Representational v co) -------------- etaInfoAbs :: [EtaInfo] -> CoreExpr -> CoreExpr -etaInfoAbs [] expr = expr -etaInfoAbs (EtaVar v : eis) expr = Lam v (etaInfoAbs eis expr) -etaInfoAbs (EtaCo co : eis) expr = Cast (etaInfoAbs eis expr) (mkSymCo co) +etaInfoAbs eis expr + | null eis = expr + | otherwise = case final_mco of + MRefl -> expr' + MCo co -> mkCast expr' co + where + (expr', final_mco) = foldr do_one (split_cast expr) eis + + do_one :: EtaInfo -> (CoreExpr, MCoercion) -> (CoreExpr, MCoercion) + do_one (EtaVar v) (expr, mco) = (Lam v expr, mkPiMCo v mco) + do_one (EtaCo co) (expr, mco) = (expr, mco `mkTransMCoL` mkSymCo co) + + split_cast :: CoreExpr -> (CoreExpr, MCoercion) + split_cast (Cast e co) = (e, MCo co) + split_cast e = (e, MRefl) + -- We could look in the body of lets, and the branches of a case + -- But then we would have to worry about whether the cast mentioned + -- any of the bound variables, which is tiresome. Later maybe. + -- Result: we may end up with + -- (\(x::Int). case x of { DEFAULT -> e1 |> co }) |> sym (->co) + -- and fail to optimise it away -------------- -etaInfoApp :: Subst -> CoreExpr -> [EtaInfo] -> CoreExpr +etaInfoApp :: InScopeSet -> CoreExpr -> [EtaInfo] -> CoreExpr -- (etaInfoApp s e eis) returns something equivalent to --- ((substExpr s e) `appliedto` eis) - -etaInfoApp subst (Lam v1 e) (EtaVar v2 : eis) - = etaInfoApp (GHC.Core.Subst.extendSubstWithVar subst v1 v2) e eis - -etaInfoApp subst (Cast e co1) eis - = etaInfoApp subst e (pushCoercion co' eis) - where - co' = GHC.Core.Subst.substCo subst co1 +-- (substExpr s e `appliedto` eis) -etaInfoApp subst (Case e b ty alts) eis - = Case (subst_expr subst e) b1 ty' alts' +etaInfoApp in_scope expr eis + = go (mkEmptySubst in_scope) expr eis where - (subst1, b1) = substBndr subst b - alts' = map subst_alt alts - ty' = etaInfoAppTy (GHC.Core.Subst.substTy subst ty) eis - subst_alt (con, bs, rhs) = (con, bs', etaInfoApp subst2 rhs eis) - where - (subst2,bs') = substBndrs subst1 bs - -etaInfoApp subst (Let b e) eis - | not (isJoinBind b) - -- See Note [Eta expansion for join points] - = Let b' (etaInfoApp subst' e eis) - where - (subst', b') = substBindSC subst b + go :: Subst -> CoreExpr -> [EtaInfo] -> CoreExpr + -- 'go' pushed down the eta-infos into the branch of a case + -- and the body of a let; and does beta-reduction if possible + go subst (Tick t e) eis + = Tick (substTickish subst t) (go subst e eis) + go subst (Cast e co) eis + = go subst e (pushCoercion (Core.substCo subst co) eis) + go subst (Case e b ty alts) eis + = Case (Core.substExprSC subst e) b1 ty' alts' + where + (subst1, b1) = Core.substBndr subst b + alts' = map subst_alt alts + ty' = etaInfoAppTy (Core.substTy subst ty) eis + subst_alt (con, bs, rhs) = (con, bs', go subst2 rhs eis) + where + (subst2,bs') = Core.substBndrs subst1 bs + go subst (Let b e) eis + | not (isJoinBind b) -- See Note [Eta expansion for join points] + = Let b' (go subst' e eis) + where + (subst', b') = Core.substBindSC subst b -etaInfoApp subst (Tick t e) eis - = Tick (substTickish subst t) (etaInfoApp subst e eis) + -- Beta-reduction if possible, using getArg_maybe to push + -- any intervening casts past the argument + -- See Note [The EtaInfo mechansim] + go subst (Lam v e) eis + | Just (arg, eis') <- getArg_maybe eis + = go (Core.extendSubst subst v arg) e eis' -etaInfoApp subst expr _ - | (Var fun, _) <- collectArgs expr - , Var fun' <- lookupIdSubst subst fun - , isJoinId fun' - = subst_expr subst expr + -- Stop pushing down; just wrap the expression up + go subst e eis = wrap (Core.substExprSC subst e) eis -etaInfoApp subst e eis - = go (subst_expr subst e) eis - where - go e [] = e - go e (EtaVar v : eis) = go (App e (varToCoreExpr v)) eis - go e (EtaCo co : eis) = go (Cast e co) eis + wrap e [] = e + wrap e (EtaVar v : eis) = wrap (App e (varToCoreExpr v)) eis + wrap e (EtaCo co : eis) = wrap (Cast e co) eis -------------- @@ -1235,7 +1364,7 @@ mkEtaWW orig_oss ppr_orig_expr in_scope orig_ty -- We want to get -- coerce T (\x::[T] -> (coerce ([T]->Int) e) x) | Just (co, ty') <- topNormaliseNewType_maybe ty - , let co' = Coercion.substCo subst co + , let co' = Type.substCo subst co -- Remember to apply the substitution to co (#16979) -- (or we could have applied to ty, but then -- we'd have had to zap it for the recursive call) @@ -1253,21 +1382,290 @@ mkEtaWW orig_oss ppr_orig_expr in_scope orig_ty -- with an explicit lambda having a non-function type +{- ********************************************************************* +* * + The "push rules" +* * +************************************************************************ ------------- -subst_expr :: Subst -> CoreExpr -> CoreExpr --- Apply a substitution to an expression. We use substExpr --- not substExprSC (short-cutting substitution) because --- we may be changing the types of join points, so applying --- the in-scope set is necessary. +Here we implement the "push rules" from FC papers: + +* The push-argument rules, where we can move a coercion past an argument. + We have + (fun |> co) arg + and we want to transform it to + (fun arg') |> co' + for some suitable co' and transformed arg'. + +* The PushK rule for data constructors. We have + (K e1 .. en) |> co + and we want to transform to + (K e1' .. en') + by pushing the coercion into the arguments +-} + +pushCoArgs :: CoercionR -> [CoreArg] -> Maybe ([CoreArg], MCoercion) +pushCoArgs co [] = return ([], MCo co) +pushCoArgs co (arg:args) = do { (arg', m_co1) <- pushCoArg co arg + ; case m_co1 of + MCo co1 -> do { (args', m_co2) <- pushCoArgs co1 args + ; return (arg':args', m_co2) } + MRefl -> return (arg':args, MRefl) } + +pushCoArg :: CoercionR -> CoreArg -> Maybe (CoreArg, MCoercion) +-- We have (fun |> co) arg, and we want to transform it to +-- (fun arg) |> co +-- This may fail, e.g. if (fun :: N) where N is a newtype +-- C.f. simplCast in GHC.Core.Opt.Simplify +-- 'co' is always Representational +-- If the returned coercion is Nothing, then it would have been reflexive +pushCoArg co (Type ty) = do { (ty', m_co') <- pushCoTyArg co ty + ; return (Type ty', m_co') } +pushCoArg co val_arg = do { (arg_co, m_co') <- pushCoValArg co + ; return (val_arg `mkCastMCo` arg_co, m_co') } + +pushCoTyArg :: CoercionR -> Type -> Maybe (Type, MCoercionR) +-- We have (fun |> co) @ty +-- Push the coercion through to return +-- (fun @ty') |> co' +-- 'co' is always Representational +-- If the returned coercion is Nothing, then it would have been reflexive; +-- it's faster not to compute it, though. +pushCoTyArg co ty + -- The following is inefficient - don't do `eqType` here, the coercion + -- optimizer will take care of it. See #14737. + -- -- | tyL `eqType` tyR + -- -- = Just (ty, Nothing) + + | isReflCo co + = Just (ty, MRefl) + + | isForAllTy_ty tyL + = ASSERT2( isForAllTy_ty tyR, ppr co $$ ppr ty ) + Just (ty `mkCastTy` co1, MCo co2) + + | otherwise + = Nothing + where + Pair tyL tyR = coercionKind co + -- co :: tyL ~ tyR + -- tyL = forall (a1 :: k1). ty1 + -- tyR = forall (a2 :: k2). ty2 + + co1 = mkSymCo (mkNthCo Nominal 0 co) + -- co1 :: k2 ~N k1 + -- Note that NthCo can extract a Nominal equality between the + -- kinds of the types related by a coercion between forall-types. + -- See the NthCo case in GHC.Core.Lint. + + co2 = mkInstCo co (mkGReflLeftCo Nominal ty co1) + -- co2 :: ty1[ (ty|>co1)/a1 ] ~ ty2[ ty/a2 ] + -- Arg of mkInstCo is always nominal, hence mkNomReflCo + +pushCoValArg :: CoercionR -> Maybe (MCoercionR, MCoercionR) +-- We have (fun |> co) arg +-- Push the coercion through to return +-- (fun (arg |> co_arg)) |> co_res +-- 'co' is always Representational +-- If the second returned Coercion is actually Nothing, then no cast is necessary; +-- the returned coercion would have been reflexive. +pushCoValArg co + -- The following is inefficient - don't do `eqType` here, the coercion + -- optimizer will take care of it. See #14737. + -- -- | tyL `eqType` tyR + -- -- = Just (mkRepReflCo arg, Nothing) + + | isReflCo co + = Just (MRefl, MRefl) + + | isFunTy tyL + , (co_mult, co1, co2) <- decomposeFunCo Representational co + , isReflexiveCo co_mult + -- We can't push the coercion in the case where co_mult isn't reflexivity: + -- it could be an unsafe axiom, and losing this information could yield + -- ill-typed terms. For instance (fun x ::(1) Int -> (fun _ -> () |> co) x) + -- with co :: (Int -> ()) ~ (Int #-> ()), would reduce to (fun x ::(1) Int + -- -> (fun _ ::(Many) Int -> ()) x) which is ill-typed + + -- If co :: (tyL1 -> tyL2) ~ (tyR1 -> tyR2) + -- then co1 :: tyL1 ~ tyR1 + -- co2 :: tyL2 ~ tyR2 + = ASSERT2( isFunTy tyR, ppr co $$ ppr arg ) + Just (coToMCo (mkSymCo co1), coToMCo co2) + -- Critically, coToMCo to checks for ReflCo; the whole coercion may not + -- be reflexive, but either of its components might be + -- We could use isReflexiveCo, but it's not clear if the benefit + -- is worth the cost, and it makes no difference in #18223 + + | otherwise + = Nothing + where + arg = funArgTy tyR + Pair tyL tyR = coercionKind co + +pushCoercionIntoLambda + :: InScopeSet -> Var -> CoreExpr -> CoercionR -> Maybe (Var, CoreExpr) +-- This implements the Push rule from the paper on coercions +-- (\x. e) |> co +-- ===> +-- (\x'. e |> co') +pushCoercionIntoLambda in_scope x e co + | ASSERT(not (isTyVar x) && not (isCoVar x)) True + , Pair s1s2 t1t2 <- coercionKind co + , Just (_, _s1,_s2) <- splitFunTy_maybe s1s2 + , Just (w1, t1,_t2) <- splitFunTy_maybe t1t2 + , (co_mult, co1, co2) <- decomposeFunCo Representational co + , isReflexiveCo co_mult + -- We can't push the coercion in the case where co_mult isn't + -- reflexivity. See pushCoValArg for more details. + = let + -- Should we optimize the coercions here? + -- Otherwise they might not match too well + x' = x `setIdType` t1 `setIdMult` w1 + in_scope' = in_scope `extendInScopeSet` x' + subst = extendIdSubst (mkEmptySubst in_scope') + x + (mkCast (Var x') co1) + in Just (x', substExpr subst e `mkCast` co2) + | otherwise + = pprTrace "exprIsLambda_maybe: Unexpected lambda in case" (ppr (Lam x e)) + Nothing + +pushCoDataCon :: DataCon -> [CoreExpr] -> Coercion + -> Maybe (DataCon + , [Type] -- Universal type args + , [CoreExpr]) -- All other args incl existentials +-- Implement the KPush reduction rule as described in "Down with kinds" +-- The transformation applies iff we have +-- (C e1 ... en) `cast` co +-- where co :: (T t1 .. tn) ~ to_ty +-- The left-hand one must be a T, because exprIsConApp returned True +-- but the right-hand one might not be. (Though it usually will.) +pushCoDataCon dc dc_args co + | isReflCo co || from_ty `eqType` to_ty -- try cheap test first + , let (univ_ty_args, rest_args) = splitAtList (dataConUnivTyVars dc) dc_args + = Just (dc, map exprToType univ_ty_args, rest_args) + + | Just (to_tc, to_tc_arg_tys) <- splitTyConApp_maybe to_ty + , to_tc == dataConTyCon dc + -- These two tests can fail; we might see + -- (C x y) `cast` (g :: T a ~ S [a]), + -- where S is a type function. In fact, exprIsConApp + -- will probably not be called in such circumstances, + -- but there's nothing wrong with it + + = let + tc_arity = tyConArity to_tc + dc_univ_tyvars = dataConUnivTyVars dc + dc_ex_tcvars = dataConExTyCoVars dc + arg_tys = dataConRepArgTys dc + + non_univ_args = dropList dc_univ_tyvars dc_args + (ex_args, val_args) = splitAtList dc_ex_tcvars non_univ_args + + -- Make the "Psi" from the paper + omegas = decomposeCo tc_arity co (tyConRolesRepresentational to_tc) + (psi_subst, to_ex_arg_tys) + = liftCoSubstWithEx Representational + dc_univ_tyvars + omegas + dc_ex_tcvars + (map exprToType ex_args) + + -- Cast the value arguments (which include dictionaries) + new_val_args = zipWith cast_arg (map scaledThing arg_tys) val_args + cast_arg arg_ty arg = mkCast arg (psi_subst arg_ty) + + to_ex_args = map Type to_ex_arg_tys + + dump_doc = vcat [ppr dc, ppr dc_univ_tyvars, ppr dc_ex_tcvars, + ppr arg_tys, ppr dc_args, + ppr ex_args, ppr val_args, ppr co, ppr from_ty, ppr to_ty, ppr to_tc + , ppr $ mkTyConApp to_tc (map exprToType $ takeList dc_univ_tyvars dc_args) ] + in + ASSERT2( eqType from_ty (mkTyConApp to_tc (map exprToType $ takeList dc_univ_tyvars dc_args)), dump_doc ) + ASSERT2( equalLength val_args arg_tys, dump_doc ) + Just (dc, to_tc_arg_tys, to_ex_args ++ new_val_args) + + | otherwise + = Nothing + + where + Pair from_ty to_ty = coercionKind co + +collectBindersPushingCo :: CoreExpr -> ([Var], CoreExpr) +-- Collect lambda binders, pushing coercions inside if possible +-- E.g. (\x.e) |> g g :: -> blah +-- = (\x. e |> Nth 1 g) +-- +-- That is, -- --- ToDo: we could instead check if we actually *are* --- changing any join points' types, and if not use substExprSC. -subst_expr = substExpr +-- collectBindersPushingCo ((\x.e) |> g) === ([x], e |> Nth 1 g) +collectBindersPushingCo e + = go [] e + where + -- Peel off lambdas until we hit a cast. + go :: [Var] -> CoreExpr -> ([Var], CoreExpr) + -- The accumulator is in reverse order + go bs (Lam b e) = go (b:bs) e + go bs (Cast e co) = go_c bs e co + go bs e = (reverse bs, e) + + -- We are in a cast; peel off casts until we hit a lambda. + go_c :: [Var] -> CoreExpr -> CoercionR -> ([Var], CoreExpr) + -- (go_c bs e c) is same as (go bs e (e |> c)) + go_c bs (Cast e co1) co2 = go_c bs e (co1 `mkTransCo` co2) + go_c bs (Lam b e) co = go_lam bs b e co + go_c bs e co = (reverse bs, mkCast e co) + + -- We are in a lambda under a cast; peel off lambdas and build a + -- new coercion for the body. + go_lam :: [Var] -> Var -> CoreExpr -> CoercionR -> ([Var], CoreExpr) + -- (go_lam bs b e c) is same as (go_c bs (\b.e) c) + go_lam bs b e co + | isTyVar b + , let Pair tyL tyR = coercionKind co + , ASSERT( isForAllTy_ty tyL ) + isForAllTy_ty tyR + , isReflCo (mkNthCo Nominal 0 co) -- See Note [collectBindersPushingCo] + = go_c (b:bs) e (mkInstCo co (mkNomReflCo (mkTyVarTy b))) + + | isCoVar b + , let Pair tyL tyR = coercionKind co + , ASSERT( isForAllTy_co tyL ) + isForAllTy_co tyR + , isReflCo (mkNthCo Nominal 0 co) -- See Note [collectBindersPushingCo] + , let cov = mkCoVarCo b + = go_c (b:bs) e (mkInstCo co (mkNomReflCo (mkCoercionTy cov))) + + | isId b + , let Pair tyL tyR = coercionKind co + , ASSERT( isFunTy tyL) isFunTy tyR + , (co_mult, co_arg, co_res) <- decomposeFunCo Representational co + , isReflCo co_mult -- See Note [collectBindersPushingCo] + , isReflCo co_arg -- See Note [collectBindersPushingCo] + = go_c (b:bs) e co_res + + | otherwise = (reverse bs, mkCast (Lam b e) co) +{- --------------- +Note [collectBindersPushingCo] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +We just look for coercions of form + # w -> blah +(and similarly for foralls) to keep this function simple. We could do +more elaborate stuff, but it'd involve substitution etc. + +-} + +{- ********************************************************************* +* * + Join points +* * +********************************************************************* -} +------------------- -- | Split an expression into the given number of binders and a body, -- eta-expanding if necessary. Counts value *and* type binders. etaExpandToJoinPoint :: JoinArity -> CoreExpr -> ([CoreBndr], CoreExpr) @@ -1307,7 +1705,7 @@ etaBodyForJoinPoint need_args body = (reverse rev_bs, e) go n ty subst rev_bs e | Just (tv, res_ty) <- splitForAllTy_maybe ty - , let (subst', tv') = Type.substVarBndr subst tv + , let (subst', tv') = substVarBndr subst tv = go (n-1) res_ty subst' (tv' : rev_bs) (e `App` varToCoreExpr tv') | Just (mult, arg_ty, res_ty) <- splitFunTy_maybe ty , let (subst', b) = freshEtaId n subst (Scaled mult arg_ty) @@ -1318,6 +1716,8 @@ etaBodyForJoinPoint need_args body init_subst e = mkEmptyTCvSubst (mkInScopeSet (exprFreeVars e)) + + -------------- freshEtaId :: Int -> TCvSubst -> Scaled Type -> (TCvSubst, Id) -- Make a fresh Id, with specified type (after applying substitution) @@ -1336,3 +1736,4 @@ freshEtaId n subst ty -- "OrCoVar" since this can be used to eta-expand -- coercion abstractions subst' = extendTCvInScope subst eta_id' + ===================================== compiler/GHC/Core/Opt/Pipeline.hs ===================================== @@ -311,33 +311,38 @@ getCoreToDo dflags runWhen do_float_in CoreDoFloatInwards, + simplify "final", -- Final tidy-up + maybe_rule_check FinalPhase, + -------- After this we have -O2 passes ----------------- + -- None of them run with -O + -- Case-liberation for -O2. This should be after -- strictness analysis and the simplification which follows it. - runWhen liberate_case (CoreDoPasses [ - CoreLiberateCase, - simplify "post-liberate-case" - ]), -- Run the simplifier after LiberateCase to vastly - -- reduce the possibility of shadowing - -- Reason: see Note [Shadowing] in GHC.Core.Opt.SpecConstr + runWhen liberate_case $ CoreDoPasses + [ CoreLiberateCase, simplify "post-liberate-case" ], + -- Run the simplifier after LiberateCase to vastly + -- reduce the possibility of shadowing + -- Reason: see Note [Shadowing] in GHC.Core.Opt.SpecConstr - runWhen spec_constr CoreDoSpecConstr, + runWhen spec_constr $ CoreDoPasses + [ CoreDoSpecConstr, simplify "post-spec-constr"], + -- See Note [Simplify after SpecConstr] maybe_rule_check FinalPhase, - runWhen late_specialise - (CoreDoPasses [ CoreDoSpecialising - , simplify "post-late-spec"]), + runWhen late_specialise $ CoreDoPasses + [ CoreDoSpecialising, simplify "post-late-spec"], -- LiberateCase can yield new CSE opportunities because it peels -- off one layer of a recursive function (concretely, I saw this -- in wheel-sieve1), and I'm guessing that SpecConstr can too -- And CSE is a very cheap pass. So it seems worth doing here. - runWhen ((liberate_case || spec_constr) && cse) CoreCSE, + runWhen ((liberate_case || spec_constr) && cse) $ CoreDoPasses + [ CoreCSE, simplify "post-final-cse" ], - -- Final clean-up simplification: - simplify "final", + --------- End of -O2 passes -------------- runWhen late_dmd_anal $ CoreDoPasses ( dmd_cpr_ww ++ [simplify "post-late-ww"] @@ -406,6 +411,27 @@ or with -O0. Two reasons: But watch out: list fusion can prevent floating. So use phase control to switch off those rules until after floating. +Note [Simplify after SpecConstr] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +We want to run the simplifier after SpecConstr, and before late-Specialise, +for two reasons, both shown up in test perf/compiler/T16473, +with -O2 -flate-specialise + +1. I found that running late-Specialise after SpecConstr, with no + simplification in between meant that the carefullly constructed + SpecConstr rule never got to fire. (It was something like + lvl = f a -- Arity 1 + ....g lvl.... + SpecConstr specialised g for argument lvl; but Specialise then + specialised lvl = f a to lvl = $sf, and inlined. Or something like + that.) + +2. Specialise relies on unfoldings being available for top-level dictionary + bindings; but SpecConstr kills them all! The Simplifer restores them. + +This extra run of the simplifier has a cost, but this is only with -O2. + + ************************************************************************ * * The CoreToDo interpreter ===================================== compiler/GHC/Core/Opt/Simplify.hs ===================================== @@ -48,9 +48,9 @@ import GHC.Types.Unique ( hasKey ) import GHC.Core.Unfold import GHC.Core.Utils import GHC.Core.Opt.Arity ( ArityType(..), arityTypeArity, isBotArityType + , pushCoTyArg, pushCoValArg , idArityType, etaExpandAT ) -import GHC.Core.SimpleOpt ( pushCoTyArg, pushCoValArg - , joinPointBinding_maybe, joinPointBindings_maybe ) +import GHC.Core.SimpleOpt ( joinPointBinding_maybe, joinPointBindings_maybe ) import GHC.Core.FVs ( mkRuleInfo ) import GHC.Core.Rules ( lookupRule, getRules, initRuleOpts ) import GHC.Types.Basic @@ -315,7 +315,7 @@ simplLazyBind env top_lvl is_rec bndr bndr1 rhs rhs_se ; let rhs_cont = mkRhsStop (substTy body_env (exprType body)) ; (body_floats0, body0) <- {-#SCC "simplExprF" #-} simplExprF body_env body rhs_cont - -- Never float join-floats out of a non-join let-binding + -- Never float join-floats out of a non-join let-binding (which this is) -- So wrap the body in the join-floats right now -- Hence: body_floats1 consists only of let-floats ; let (body_floats1, body1) = wrapJoinFloatsX body_floats0 body0 @@ -1411,25 +1411,23 @@ simplCast env body co0 cont0 -- type of the hole changes (#16312) -- (f |> co) e ===> (f (e |> co1)) |> co2 - -- where co :: (s1->s2) ~ (t1~t2) + -- where co :: (s1->s2) ~ (t1->t2) -- co1 :: t1 ~ s1 -- co2 :: s2 ~ t2 addCoerce co cont@(ApplyToVal { sc_arg = arg, sc_env = arg_se , sc_dup = dup, sc_cont = tail }) - | Just (co1, m_co2) <- pushCoValArg co - , let new_ty = coercionRKind co1 - , not (isTypeLevPoly new_ty) -- Without this check, we get a lev-poly arg - -- See Note [Levity polymorphism invariants] in GHC.Core - -- test: typecheck/should_run/EtaExpandLevPoly + | Just (m_co1, m_co2) <- pushCoValArg co + , levity_ok m_co1 = {-#SCC "addCoerce-pushCoValArg" #-} do { tail' <- addCoerceM m_co2 tail - ; if isReflCo co1 - then return (cont { sc_cont = tail' - , sc_hole_ty = coercionLKind co }) + ; case m_co1 of { + MRefl -> return (cont { sc_cont = tail' + , sc_hole_ty = coercionLKind co }) ; -- Avoid simplifying if possible; -- See Note [Avoiding exponential behaviour] - else do - { (dup', arg_se', arg') <- simplArg env dup arg_se arg + + MCo co1 -> + do { (dup', arg_se', arg') <- simplArg env dup arg_se arg -- When we build the ApplyTo we can't mix the OutCoercion -- 'co' with the InExpr 'arg', so we simplify -- to make it all consistent. It's a bit messy. @@ -1439,7 +1437,7 @@ simplCast env body co0 cont0 , sc_env = arg_se' , sc_dup = dup' , sc_cont = tail' - , sc_hole_ty = coercionLKind co }) } } + , sc_hole_ty = coercionLKind co }) } } } addCoerce co cont | isReflexiveCo co = return cont -- Having this at the end makes a huge @@ -1447,6 +1445,13 @@ simplCast env body co0 cont0 -- See Note [Optimising reflexivity] | otherwise = return (CastIt co cont) + levity_ok :: MCoercionR -> Bool + levity_ok MRefl = True + levity_ok (MCo co) = not $ isTypeLevPoly $ coercionRKind co + -- Without this check, we get a lev-poly arg + -- See Note [Levity polymorphism invariants] in GHC.Core + -- test: typecheck/should_run/EtaExpandLevPoly + simplArg :: SimplEnv -> DupFlag -> StaticEnv -> CoreExpr -> SimplM (DupFlag, StaticEnv, OutExpr) simplArg env dup_flag arg_env arg @@ -3111,7 +3116,7 @@ knownCon :: SimplEnv knownCon env scrut dc_floats dc dc_ty_args dc_args bndr bs rhs cont = do { (floats1, env1) <- bind_args env bs dc_args - ; (floats2, env2) <- bind_case_bndr env1 + ; (floats2, env2) <- bind_case_bndr env1 ; (floats3, expr') <- simplExprF env2 rhs cont ; case dc_floats of [] -> @@ -3237,6 +3242,7 @@ altsWouldDup [_] = False altsWouldDup (alt:alts) | is_bot_alt alt = altsWouldDup alts | otherwise = not (all is_bot_alt alts) + -- otherwise case: first alt is non-bot, so all the rest must be bot where is_bot_alt (_,_,rhs) = exprIsDeadEnd rhs ===================================== compiler/GHC/Core/Opt/Simplify/Env.hs ===================================== @@ -591,7 +591,7 @@ addJoinFlts :: JoinFloats -> JoinFloats -> JoinFloats addJoinFlts = appOL mkRecFloats :: SimplFloats -> SimplFloats --- Flattens the floats from env2 into a single Rec group, +-- Flattens the floats into a single Rec group, -- They must either all be lifted LetFloats or all JoinFloats mkRecFloats floats@(SimplFloats { sfLetFloats = LetFloats bs ff , sfJoinFloats = jbs ===================================== compiler/GHC/Core/Opt/Specialise.hs ===================================== @@ -21,7 +21,7 @@ import GHC.Tc.Utils.TcType hiding( substTy ) import GHC.Core.Type hiding( substTy, extendTvSubstList ) import GHC.Core.Multiplicity import GHC.Core.Predicate -import GHC.Unit.Module( Module, HasModule(..) ) +import GHC.Unit.Module( Module ) import GHC.Core.Coercion( Coercion ) import GHC.Core.Opt.Monad import qualified GHC.Core.Subst as Core @@ -31,11 +31,11 @@ import GHC.Types.Var.Set import GHC.Types.Var.Env import GHC.Core import GHC.Core.Rules -import GHC.Core.SimpleOpt ( collectBindersPushingCo ) import GHC.Core.Utils ( exprIsTrivial, getIdFromTrivialExpr_maybe , mkCast, exprType ) import GHC.Core.FVs -import GHC.Core.Opt.Arity ( etaExpandToJoinPointRule ) +import GHC.Core.Opt.Arity ( collectBindersPushingCo + , etaExpandToJoinPointRule ) import GHC.Types.Unique.Supply import GHC.Types.Name import GHC.Types.Id.Make ( voidArgId, voidPrimId ) @@ -51,12 +51,9 @@ import GHC.Utils.Misc import GHC.Utils.Outputable import GHC.Utils.Panic import GHC.Data.FastString -import GHC.Utils.Monad.State import GHC.Types.Unique.DFM import GHC.Core.TyCo.Rep (TyCoBinder (..)) -import Control.Monad - {- ************************************************************************ * * @@ -590,28 +587,29 @@ specProgram guts@(ModGuts { mg_module = this_mod , mg_binds = binds }) = do { dflags <- getDynFlags + -- We need to start with a Subst that knows all the things + -- that are in scope, so that the substitution engine doesn't + -- accidentally re-use a unique that's already in use + -- Easiest thing is to do it all at once, as if all the top-level + -- decls were mutually recursive + ; let top_env = SE { se_subst = Core.mkEmptySubst $ mkInScopeSet $ mkVarSet $ + bindersOfBinds binds + , se_interesting = emptyVarSet + , se_module = this_mod + , se_dflags = dflags } + + go [] = return ([], emptyUDs) + go (bind:binds) = do (binds', uds) <- go binds + (bind', uds') <- specBind top_env bind uds + return (bind' ++ binds', uds') + -- Specialise the bindings of this module - ; (binds', uds) <- runSpecM dflags this_mod (go binds) + ; (binds', uds) <- runSpecM (go binds) - ; (spec_rules, spec_binds) <- specImports dflags this_mod top_env - local_rules uds + ; (spec_rules, spec_binds) <- specImports top_env local_rules uds ; return (guts { mg_binds = spec_binds ++ binds' , mg_rules = spec_rules ++ local_rules }) } - where - -- We need to start with a Subst that knows all the things - -- that are in scope, so that the substitution engine doesn't - -- accidentally re-use a unique that's already in use - -- Easiest thing is to do it all at once, as if all the top-level - -- decls were mutually recursive - top_env = SE { se_subst = Core.mkEmptySubst $ mkInScopeSet $ mkVarSet $ - bindersOfBinds binds - , se_interesting = emptyVarSet } - - go [] = return ([], emptyUDs) - go (bind:binds) = do (binds', uds) <- go binds - (bind', uds') <- specBind top_env bind uds - return (bind' ++ binds', uds') {- Note [Wrap bindings returned by specImports] @@ -641,13 +639,13 @@ See #10491 * * ********************************************************************* -} -specImports :: DynFlags -> Module -> SpecEnv +specImports :: SpecEnv -> [CoreRule] -> UsageDetails -> CoreM ([CoreRule], [CoreBind]) -specImports dflags this_mod top_env local_rules +specImports top_env local_rules (MkUD { ud_binds = dict_binds, ud_calls = calls }) - | not $ gopt Opt_CrossModuleSpecialise dflags + | not $ gopt Opt_CrossModuleSpecialise (se_dflags top_env) -- See Note [Disabling cross-module specialisation] = return ([], wrapDictBinds dict_binds []) @@ -655,8 +653,7 @@ specImports dflags this_mod top_env local_rules = do { hpt_rules <- getRuleBase ; let rule_base = extendRuleBaseList hpt_rules local_rules - ; (spec_rules, spec_binds) <- spec_imports dflags this_mod top_env - [] rule_base + ; (spec_rules, spec_binds) <- spec_imports top_env [] rule_base dict_binds calls -- Don't forget to wrap the specialized bindings with @@ -672,9 +669,7 @@ specImports dflags this_mod top_env local_rules } -- | Specialise a set of calls to imported bindings -spec_imports :: DynFlags - -> Module - -> SpecEnv -- Passed in so that all top-level Ids are in scope +spec_imports :: SpecEnv -- Passed in so that all top-level Ids are in scope -> [Id] -- Stack of imported functions being specialised -- See Note [specImport call stack] -> RuleBase -- Rules from this module and the home package @@ -684,8 +679,7 @@ spec_imports :: DynFlags -> CallDetails -- Calls for imported things -> CoreM ( [CoreRule] -- New rules , [CoreBind] ) -- Specialised bindings -spec_imports dflags this_mod top_env - callers rule_base dict_binds calls +spec_imports top_env callers rule_base dict_binds calls = do { let import_calls = dVarEnvElts calls -- ; debugTraceMsg (text "specImports {" <+> -- vcat [ text "calls:" <+> ppr import_calls @@ -699,16 +693,13 @@ spec_imports dflags this_mod top_env go _ [] = return ([], []) go rb (cis : other_calls) = do { -- debugTraceMsg (text "specImport {" <+> ppr cis) - ; (rules1, spec_binds1) <- spec_import dflags this_mod top_env - callers rb dict_binds cis + ; (rules1, spec_binds1) <- spec_import top_env callers rb dict_binds cis -- ; debugTraceMsg (text "specImport }" <+> ppr cis) ; (rules2, spec_binds2) <- go (extendRuleBaseList rb rules1) other_calls ; return (rules1 ++ rules2, spec_binds1 ++ spec_binds2) } -spec_import :: DynFlags - -> Module - -> SpecEnv -- Passed in so that all top-level Ids are in scope +spec_import :: SpecEnv -- Passed in so that all top-level Ids are in scope -> [Id] -- Stack of imported functions being specialised -- See Note [specImport call stack] -> RuleBase -- Rules from this module @@ -717,8 +708,7 @@ spec_import :: DynFlags -> CallInfoSet -- Imported function and calls for it -> CoreM ( [CoreRule] -- New rules , [CoreBind] ) -- Specialised bindings -spec_import dflags this_mod top_env callers - rb dict_binds cis@(CIS fn _) +spec_import top_env callers rb dict_binds cis@(CIS fn _) | isIn "specImport" fn callers = return ([], []) -- No warning. This actually happens all the time -- when specialising a recursive function, because @@ -729,8 +719,7 @@ spec_import dflags this_mod top_env callers = do { -- debugTraceMsg (text "specImport:no valid calls") ; return ([], []) } - | wantSpecImport dflags unfolding - , Just rhs <- maybeUnfoldingTemplate unfolding + | Just rhs <- canSpecImport dflags fn = do { -- Get rules from the external package state -- We keep doing this in case we "page-fault in" -- more rules as we go along @@ -742,8 +731,8 @@ spec_import dflags this_mod top_env callers ; (rules1, spec_pairs, MkUD { ud_binds = dict_binds1, ud_calls = new_calls }) <- do { -- debugTraceMsg (text "specImport1" <+> vcat [ppr fn, ppr good_calls, ppr rhs]) - ; runSpecM dflags this_mod $ - specCalls (Just this_mod) top_env rules_for_fn good_calls fn rhs } + ; runSpecM $ + specCalls True top_env rules_for_fn good_calls fn rhs } ; let spec_binds1 = [NonRec b r | (b,r) <- spec_pairs] -- After the rules kick in we may get recursion, but -- we rely on a global GlomBinds to sort that out later @@ -751,7 +740,7 @@ spec_import dflags this_mod top_env callers -- Now specialise any cascaded calls -- ; debugTraceMsg (text "specImport 2" <+> (ppr fn $$ ppr rules1 $$ ppr spec_binds1)) - ; (rules2, spec_binds2) <- spec_imports dflags this_mod top_env + ; (rules2, spec_binds2) <- spec_imports top_env (fn:callers) (extendRuleBaseList rb rules1) (dict_binds `unionBags` dict_binds1) @@ -767,11 +756,34 @@ spec_import dflags this_mod top_env callers ; return ([], [])} where - unfolding = realIdUnfolding fn -- We want to see the unfolding even for loop breakers + dflags = se_dflags top_env good_calls = filterCalls cis dict_binds -- SUPER IMPORTANT! Drop calls that (directly or indirectly) refer to fn -- See Note [Avoiding loops in specImports] +canSpecImport :: DynFlags -> Id -> Maybe CoreExpr +-- See Note [Specialise imported INLINABLE things] +canSpecImport dflags fn + | CoreUnfolding { uf_src = src, uf_tmpl = rhs } <- unf + , isStableSource src + = Just rhs -- By default, specialise only imported things that have a stable + -- unfolding; that is, have an INLINE or INLINABLE pragma + -- Specialise even INLINE things; it hasn't inlined yet, + -- so perhaps it never will. Moreover it may have calls + -- inside it that we want to specialise + + -- CoreUnfolding case does /not/ include DFunUnfoldings; + -- We only specialise DFunUnfoldings with -fspecialise-aggressively + -- See Note [Do not specialise imported DFuns] + + | gopt Opt_SpecialiseAggressively dflags + = maybeUnfoldingTemplate unf -- With -fspecialise-aggressively, specialise anything + -- with an unfolding, stable or not, DFun or not + + | otherwise = Nothing + where + unf = realIdUnfolding fn -- We want to see the unfolding even for loop breakers + -- | Returns whether or not to show a missed-spec warning. -- If -Wall-missed-specializations is on, show the warning. -- Otherwise, if -Wmissed-specializations is on, only show a warning @@ -796,24 +808,47 @@ tryWarnMissingSpecs dflags callers fn calls_for_fn , whenPprDebug (text "calls:" <+> vcat (map (pprCallInfo fn) calls_for_fn)) , text "Probable fix: add INLINABLE pragma on" <+> quotes (ppr fn) ]) -wantSpecImport :: DynFlags -> Unfolding -> Bool --- See Note [Specialise imported INLINABLE things] -wantSpecImport dflags unf - = case unf of - NoUnfolding -> False - BootUnfolding -> False - OtherCon {} -> False - DFunUnfolding {} -> True - CoreUnfolding { uf_src = src, uf_guidance = _guidance } - | gopt Opt_SpecialiseAggressively dflags -> True - | isStableSource src -> True - -- Specialise even INLINE things; it hasn't inlined yet, - -- so perhaps it never will. Moreover it may have calls - -- inside it that we want to specialise - | otherwise -> False -- Stable, not INLINE, hence INLINABLE -{- Note [Avoiding loops in specImports] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +{- Note [Do not specialise imported DFuns] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Ticket #18223 shows that specialising calls of DFuns is can cause a huge +and entirely unnecessary blowup in program size. Consider a call to + f @[[[[[[[[T]]]]]]]] d1 x +where df :: C a => C [a] + d1 :: C [[[[[[[[T]]]]]]]] = dfC[] @[[[[[[[T]]]]]]] d1 + d2 :: C [[[[[[[T]]]]]]] = dfC[] @[[[[[[T]]]]]] d3 + ... +Now we'll specialise f's RHS, which may give rise to calls to 'g', +also overloaded, which we will specialise, and so on. However, if +we specialise the calls to dfC[], we'll generate specialised copies of +all methods of C, at all types; and the same for C's superclasses. + +And many of these specialised functions will never be called. We are +going to call the specialised 'f', and the specialised 'g', but DFuns +group functions into a tuple, many of whose elements may never be used. + +With deeply-nested types this can lead to a simply overwhelming number +of specialisations: see #18223 for a simple example (from the wild). +I measured the number of specialisations for various numbers of calls +of `flip evalStateT ()`, and got this + + Size after one simplification + #calls #SPEC rules Terms Types + 5 56 3100 10600 + 9 108 13660 77206 + +The real tests case has 60+ calls, which blew GHC out of the water. + +Solution: don't specialise DFuns. The downside is that if we end +up with (h (dfun d)), /and/ we don't specialise 'h', then we won't +pass to 'h' a tuple of specialised functions. + +However, the flag -fspecialise-aggressively (experimental, off by default) +allows DFuns to specialise as well. + +Note [Avoiding loops in specImports] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We must take great care when specialising instance declarations (functions like $fOrdList) lest we accidentally build a recursive dictionary. See Note [Avoiding loops]. @@ -1001,6 +1036,9 @@ data SpecEnv -- Dict Ids that we know something about -- and hence may be worth specialising against -- See Note [Interesting dictionary arguments] + + , se_module :: Module + , se_dflags :: DynFlags } instance Outputable SpecEnv where @@ -1308,7 +1346,7 @@ specDefn :: SpecEnv specDefn env body_uds fn rhs = do { let (body_uds_without_me, calls_for_me) = callsForMe fn body_uds rules_for_me = idCoreRules fn - ; (rules, spec_defns, spec_uds) <- specCalls Nothing env rules_for_me + ; (rules, spec_defns, spec_uds) <- specCalls False env rules_for_me calls_for_me fn rhs ; return ( fn `addIdSpecialisations` rules , spec_defns @@ -1321,8 +1359,8 @@ specDefn env body_uds fn rhs -- body_uds_without_me --------------------------- -specCalls :: Maybe Module -- Just this_mod => specialising imported fn - -- Nothing => specialising local fn +specCalls :: Bool -- True => specialising imported fn + -- False => specialising local fn -> SpecEnv -> [CoreRule] -- Existing RULES for the fn -> [CallInfo] @@ -1337,7 +1375,7 @@ type SpecInfo = ( [CoreRule] -- Specialisation rules , [(Id,CoreExpr)] -- Specialised definition , UsageDetails ) -- Usage details from specialised RHSs -specCalls mb_mod env existing_rules calls_for_me fn rhs +specCalls spec_imp env existing_rules calls_for_me fn rhs -- The first case is the interesting one | notNull calls_for_me -- And there are some calls to specialise && not (isNeverActive (idInlineActivation fn)) @@ -1368,7 +1406,9 @@ specCalls mb_mod env existing_rules calls_for_me fn rhs inl_act = inlinePragmaActivation inl_prag is_local = isLocalId fn is_dfun = isDFunId fn - + dflags = se_dflags env + ropts = initRuleOpts dflags + this_mod = se_module env -- Figure out whether the function has an INLINE pragma -- See Note [Inline specialisations] @@ -1410,8 +1450,6 @@ specCalls mb_mod env existing_rules calls_for_me fn rhs -- , ppr dx_binds ]) $ -- return () - ; dflags <- getDynFlags - ; let ropts = initRuleOpts dflags ; if not useful -- No useful specialisation || already_covered ropts rules_acc rule_lhs_args then return spec_acc @@ -1439,17 +1477,15 @@ specCalls mb_mod env existing_rules calls_for_me fn rhs = Nothing ; spec_fn <- newSpecIdSM fn spec_fn_ty spec_join_arity - ; this_mod <- getModule ; let -- The rule to put in the function's specialisation is: -- forall x @b d1' d2'. -- f x @T1 @b @T2 d1' d2' = f1 x @b -- See Note [Specialising Calls] - herald = case mb_mod of - Nothing -- Specialising local fn - -> text "SPEC" - Just this_mod -- Specialising imported fn - -> text "SPEC/" <> ppr this_mod + herald | spec_imp = -- Specialising imported fn + text "SPEC/" <> ppr this_mod + | otherwise = -- Specialising local fn + text "SPEC" rule_name = mkFastString $ showSDoc dflags $ herald <+> ftext (occNameFS (getOccName fn)) @@ -2476,15 +2512,15 @@ mkCallUDs env f args res = mkCallUDs' env f args mkCallUDs' env f args - | not (want_calls_for f) -- Imported from elsewhere - || null ci_key -- No useful specialisation - -- See also Note [Specialisations already covered] + | wantCallsFor env f -- We want it, and... + , not (null ci_key) -- this call site has a useful specialisation + = -- pprTrace "mkCallUDs: keeping" _trace_doc + singleCall f ci_key + + | otherwise -- See also Note [Specialisations already covered] = -- pprTrace "mkCallUDs: discarding" _trace_doc emptyUDs - | otherwise - = -- pprTrace "mkCallUDs: keeping" _trace_doc - singleCall f ci_key where _trace_doc = vcat [ppr f, ppr args, ppr ci_key] pis = fst $ splitPiTys $ idType f @@ -2518,13 +2554,6 @@ mkCallUDs' env f args mk_spec_arg _ (Anon VisArg _) = UnspecArg - want_calls_for f = isLocalId f || isJust (maybeUnfoldingTemplate (realIdUnfolding f)) - -- For imported things, we gather call instances if - -- there is an unfolding that we could in principle specialise - -- We might still decide not to use it (consulting dflags) - -- in specImports - -- Use 'realIdUnfolding' to ignore the loop-breaker flag! - type_determines_value pred -- See Note [Type determines value] = case classifyPredType pred of ClassPred cls _ -> not (isIPClass cls) -- Superclasses can't be IPs @@ -2533,9 +2562,17 @@ mkCallUDs' env f args -- Constraint-ranged family; #7785 ForAllPred {} -> True -{- -Note [Type determines value] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +wantCallsFor :: SpecEnv -> Id -> Bool +wantCallsFor _env _f = True + -- We could be less eager about collecting calls for LocalIds: there's + -- no point for ones that are lambda-bound. But we can't use the + -- unfolding, because unfoldings for local functions are discarded by + -- cloneBindSM. We could keep a candidate set of let-binders to + -- reduce the size of the UsageDetails + + +{- Note [Type determines value] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Only specialise on non-IP *class* params, because these are the ones whose *type* determines their *value*. In particular, with implicit params, the type args *don't* say what the value of the implicit param @@ -2796,55 +2833,12 @@ deleteCallsFor bs calls = delDVarEnvList calls bs ************************************************************************ -} -newtype SpecM a = SpecM (State SpecState a) deriving (Functor) - -data SpecState = SpecState { - spec_uniq_supply :: UniqSupply, - spec_module :: Module, - spec_dflags :: DynFlags - } - -instance Applicative SpecM where - pure x = SpecM $ return x - (<*>) = ap - -instance Monad SpecM where - SpecM x >>= f = SpecM $ do y <- x - case f y of - SpecM z -> - z - -instance MonadFail SpecM where - fail str = SpecM $ error str - -instance MonadUnique SpecM where - getUniqueSupplyM - = SpecM $ do st <- get - let (us1, us2) = splitUniqSupply $ spec_uniq_supply st - put $ st { spec_uniq_supply = us2 } - return us1 - - getUniqueM - = SpecM $ do st <- get - let (u,us') = takeUniqFromSupply $ spec_uniq_supply st - put $ st { spec_uniq_supply = us' } - return u - -instance HasDynFlags SpecM where - getDynFlags = SpecM $ liftM spec_dflags get - -instance HasModule SpecM where - getModule = SpecM $ liftM spec_module get - -runSpecM :: DynFlags -> Module -> SpecM a -> CoreM a -runSpecM dflags this_mod (SpecM spec) - = do us <- getUniqueSupplyM - let initialState = SpecState { - spec_uniq_supply = us, - spec_module = this_mod, - spec_dflags = dflags - } - return $ evalState spec initialState +type SpecM a = UniqSM a + +runSpecM :: SpecM a -> CoreM a +runSpecM thing_inside + = do { us <- getUniqueSupplyM + ; return (initUs_ us thing_inside) } mapAndCombineSM :: (a -> SpecM (b, UsageDetails)) -> [a] -> SpecM ([b], UsageDetails) mapAndCombineSM _ [] = return ([], emptyUDs) ===================================== compiler/GHC/Core/Ppr.hs ===================================== @@ -161,15 +161,20 @@ pprOptCo co = sdocOption sdocSuppressCoercions $ \case True -> angleBrackets (text "Co:" <> int (coercionSize co)) False -> parens $ sep [ppr co, dcolon <+> ppr (coercionType co)] +ppr_id_occ :: (SDoc -> SDoc) -> Id -> SDoc +ppr_id_occ add_par id + | isJoinId id = add_par ((text "jump") <+> pp_id) + | otherwise = pp_id + where + pp_id = ppr id -- We could use pprPrefixOcc to print (+) etc, but this is + -- Core where we don't print things infix anyway, so doing + -- so just adds extra redundant parens + ppr_expr :: OutputableBndr b => (SDoc -> SDoc) -> Expr b -> SDoc -- The function adds parens in context that need -- an atomic value (e.g. function args) -ppr_expr add_par (Var name) - | isJoinId name = add_par ((text "jump") <+> pp_name) - | otherwise = pp_name - where - pp_name = pprPrefixOcc name +ppr_expr add_par (Var id) = ppr_id_occ add_par id ppr_expr add_par (Type ty) = add_par (text "TYPE:" <+> ppr ty) -- Weird ppr_expr add_par (Coercion co) = add_par (text "CO:" <+> ppr co) ppr_expr add_par (Lit lit) = pprLiteral add_par lit @@ -212,8 +217,7 @@ ppr_expr add_par expr@(App {}) _ -> parens (hang fun_doc 2 pp_args) where - fun_doc | isJoinId f = text "jump" <+> ppr f - | otherwise = ppr f + fun_doc = ppr_id_occ noParens f _ -> parens (hang (pprParendExpr fun) 2 pp_args) } ===================================== compiler/GHC/Core/SimpleOpt.hs ===================================== @@ -16,17 +16,14 @@ module GHC.Core.SimpleOpt ( -- ** Predicates on expressions exprIsConApp_maybe, exprIsLiteral_maybe, exprIsLambda_maybe, - -- ** Coercions and casts - pushCoArg, pushCoValArg, pushCoTyArg, collectBindersPushingCo ) where #include "HsVersions.h" import GHC.Prelude -import GHC.Core.Opt.Arity( etaExpandToJoinPoint ) - import GHC.Core +import GHC.Core.Opt.Arity import GHC.Core.Subst import GHC.Core.Utils import GHC.Core.FVs @@ -46,18 +43,14 @@ import GHC.Core.Coercion.Opt ( optCoercion ) import GHC.Core.Type hiding ( substTy, extendTvSubst, extendCvSubst, extendTvSubstList , isInScope, substTyVarBndr, cloneTyVarBndr ) import GHC.Core.Coercion hiding ( substCo, substCoVarBndr ) -import GHC.Core.TyCon ( tyConArity ) -import GHC.Core.Multiplicity import GHC.Builtin.Types import GHC.Builtin.Names import GHC.Types.Basic import GHC.Unit.Module ( Module ) import GHC.Utils.Error import GHC.Driver.Session -import GHC.Driver.Ppr import GHC.Utils.Outputable import GHC.Utils.Panic -import GHC.Data.Pair import GHC.Utils.Misc import GHC.Data.Maybe ( orElse ) import GHC.Data.FastString @@ -756,6 +749,28 @@ a good cause. And it won't hurt other RULES and such that it comes across. ************************************************************************ -} +{- Note [Strictness and join points] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Suppose we have + + let f = \x. if x>200 then e1 else e1 + +and we know that f is strict in x. Then if we subsequently +discover that f is an arity-2 join point, we'll eta-expand it to + + let f = \x y. if x>200 then e1 else e1 + +and now it's only strict if applied to two arguments. So we should +adjust the strictness info. + +A more common case is when + + f = \x. error ".." + +and again its arity increases (#15517) +-} + + -- | Returns Just (bndr,rhs) if the binding is a join point: -- If it's a JoinId, just return it -- If it's not yet a JoinId but is always tail-called, @@ -789,27 +804,6 @@ joinPointBindings_maybe bndrs = mapM (uncurry joinPointBinding_maybe) bndrs -{- Note [Strictness and join points] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Suppose we have - - let f = \x. if x>200 then e1 else e1 - -and we know that f is strict in x. Then if we subsequently -discover that f is an arity-2 join point, we'll eta-expand it to - - let f = \x y. if x>200 then e1 else e1 - -and now it's only strict if applied to two arguments. So we should -adjust the strictness info. - -A more common case is when - - f = \x. error ".." - -and again its arity increases (#15517) --} - {- ********************************************************************* * * exprIsConApp_maybe @@ -1324,275 +1318,3 @@ exprIsLambda_maybe _ _e Nothing -{- ********************************************************************* -* * - The "push rules" -* * -************************************************************************ - -Here we implement the "push rules" from FC papers: - -* The push-argument rules, where we can move a coercion past an argument. - We have - (fun |> co) arg - and we want to transform it to - (fun arg') |> co' - for some suitable co' and transformed arg'. - -* The PushK rule for data constructors. We have - (K e1 .. en) |> co - and we want to transform to - (K e1' .. en') - by pushing the coercion into the arguments --} - -pushCoArgs :: CoercionR -> [CoreArg] -> Maybe ([CoreArg], MCoercion) -pushCoArgs co [] = return ([], MCo co) -pushCoArgs co (arg:args) = do { (arg', m_co1) <- pushCoArg co arg - ; case m_co1 of - MCo co1 -> do { (args', m_co2) <- pushCoArgs co1 args - ; return (arg':args', m_co2) } - MRefl -> return (arg':args, MRefl) } - -pushCoArg :: CoercionR -> CoreArg -> Maybe (CoreArg, MCoercion) --- We have (fun |> co) arg, and we want to transform it to --- (fun arg) |> co --- This may fail, e.g. if (fun :: N) where N is a newtype --- C.f. simplCast in GHC.Core.Opt.Simplify --- 'co' is always Representational --- If the returned coercion is Nothing, then it would have been reflexive -pushCoArg co (Type ty) = do { (ty', m_co') <- pushCoTyArg co ty - ; return (Type ty', m_co') } -pushCoArg co val_arg = do { (arg_co, m_co') <- pushCoValArg co - ; return (val_arg `mkCast` arg_co, m_co') } - -pushCoTyArg :: CoercionR -> Type -> Maybe (Type, MCoercionR) --- We have (fun |> co) @ty --- Push the coercion through to return --- (fun @ty') |> co' --- 'co' is always Representational --- If the returned coercion is Nothing, then it would have been reflexive; --- it's faster not to compute it, though. -pushCoTyArg co ty - -- The following is inefficient - don't do `eqType` here, the coercion - -- optimizer will take care of it. See #14737. - -- -- | tyL `eqType` tyR - -- -- = Just (ty, Nothing) - - | isReflCo co - = Just (ty, MRefl) - - | isForAllTy_ty tyL - = ASSERT2( isForAllTy_ty tyR, ppr co $$ ppr ty ) - Just (ty `mkCastTy` co1, MCo co2) - - | otherwise - = Nothing - where - Pair tyL tyR = coercionKind co - -- co :: tyL ~ tyR - -- tyL = forall (a1 :: k1). ty1 - -- tyR = forall (a2 :: k2). ty2 - - co1 = mkSymCo (mkNthCo Nominal 0 co) - -- co1 :: k2 ~N k1 - -- Note that NthCo can extract a Nominal equality between the - -- kinds of the types related by a coercion between forall-types. - -- See the NthCo case in GHC.Core.Lint. - - co2 = mkInstCo co (mkGReflLeftCo Nominal ty co1) - -- co2 :: ty1[ (ty|>co1)/a1 ] ~ ty2[ ty/a2 ] - -- Arg of mkInstCo is always nominal, hence mkNomReflCo - -pushCoValArg :: CoercionR -> Maybe (Coercion, MCoercion) --- We have (fun |> co) arg --- Push the coercion through to return --- (fun (arg |> co_arg)) |> co_res --- 'co' is always Representational --- If the second returned Coercion is actually Nothing, then no cast is necessary; --- the returned coercion would have been reflexive. -pushCoValArg co - -- The following is inefficient - don't do `eqType` here, the coercion - -- optimizer will take care of it. See #14737. - -- -- | tyL `eqType` tyR - -- -- = Just (mkRepReflCo arg, Nothing) - - | isReflCo co - = Just (mkRepReflCo arg, MRefl) - - | isFunTy tyL - , (co_mult, co1, co2) <- decomposeFunCo Representational co - , isReflexiveCo co_mult - -- We can't push the coercion in the case where co_mult isn't reflexivity: - -- it could be an unsafe axiom, and losing this information could yield - -- ill-typed terms. For instance (fun x ::(1) Int -> (fun _ -> () |> co) x) - -- with co :: (Int -> ()) ~ (Int #-> ()), would reduce to (fun x ::(1) Int - -- -> (fun _ ::(Many) Int -> ()) x) which is ill-typed - - -- If co :: (tyL1 -> tyL2) ~ (tyR1 -> tyR2) - -- then co1 :: tyL1 ~ tyR1 - -- co2 :: tyL2 ~ tyR2 - = ASSERT2( isFunTy tyR, ppr co $$ ppr arg ) - Just (mkSymCo co1, MCo co2) - - | otherwise - = Nothing - where - arg = funArgTy tyR - Pair tyL tyR = coercionKind co - -pushCoercionIntoLambda - :: InScopeSet -> Var -> CoreExpr -> CoercionR -> Maybe (Var, CoreExpr) --- This implements the Push rule from the paper on coercions --- (\x. e) |> co --- ===> --- (\x'. e |> co') -pushCoercionIntoLambda in_scope x e co - | ASSERT(not (isTyVar x) && not (isCoVar x)) True - , Pair s1s2 t1t2 <- coercionKind co - , Just (_, _s1,_s2) <- splitFunTy_maybe s1s2 - , Just (w1, t1,_t2) <- splitFunTy_maybe t1t2 - , (co_mult, co1, co2) <- decomposeFunCo Representational co - , isReflexiveCo co_mult - -- We can't push the coercion in the case where co_mult isn't - -- reflexivity. See pushCoValArg for more details. - = let - -- Should we optimize the coercions here? - -- Otherwise they might not match too well - x' = x `setIdType` t1 `setIdMult` w1 - in_scope' = in_scope `extendInScopeSet` x' - subst = extendIdSubst (mkEmptySubst in_scope') - x - (mkCast (Var x') co1) - in Just (x', substExpr subst e `mkCast` co2) - | otherwise - = pprTrace "exprIsLambda_maybe: Unexpected lambda in case" (ppr (Lam x e)) - Nothing - -pushCoDataCon :: DataCon -> [CoreExpr] -> Coercion - -> Maybe (DataCon - , [Type] -- Universal type args - , [CoreExpr]) -- All other args incl existentials --- Implement the KPush reduction rule as described in "Down with kinds" --- The transformation applies iff we have --- (C e1 ... en) `cast` co --- where co :: (T t1 .. tn) ~ to_ty --- The left-hand one must be a T, because exprIsConApp returned True --- but the right-hand one might not be. (Though it usually will.) -pushCoDataCon dc dc_args co - | isReflCo co || from_ty `eqType` to_ty -- try cheap test first - , let (univ_ty_args, rest_args) = splitAtList (dataConUnivTyVars dc) dc_args - = Just (dc, map exprToType univ_ty_args, rest_args) - - | Just (to_tc, to_tc_arg_tys) <- splitTyConApp_maybe to_ty - , to_tc == dataConTyCon dc - -- These two tests can fail; we might see - -- (C x y) `cast` (g :: T a ~ S [a]), - -- where S is a type function. In fact, exprIsConApp - -- will probably not be called in such circumstances, - -- but there's nothing wrong with it - - = let - tc_arity = tyConArity to_tc - dc_univ_tyvars = dataConUnivTyVars dc - dc_ex_tcvars = dataConExTyCoVars dc - arg_tys = dataConRepArgTys dc - - non_univ_args = dropList dc_univ_tyvars dc_args - (ex_args, val_args) = splitAtList dc_ex_tcvars non_univ_args - - -- Make the "Psi" from the paper - omegas = decomposeCo tc_arity co (tyConRolesRepresentational to_tc) - (psi_subst, to_ex_arg_tys) - = liftCoSubstWithEx Representational - dc_univ_tyvars - omegas - dc_ex_tcvars - (map exprToType ex_args) - - -- Cast the value arguments (which include dictionaries) - new_val_args = zipWith cast_arg (map scaledThing arg_tys) val_args - cast_arg arg_ty arg = mkCast arg (psi_subst arg_ty) - - to_ex_args = map Type to_ex_arg_tys - - dump_doc = vcat [ppr dc, ppr dc_univ_tyvars, ppr dc_ex_tcvars, - ppr arg_tys, ppr dc_args, - ppr ex_args, ppr val_args, ppr co, ppr from_ty, ppr to_ty, ppr to_tc - , ppr $ mkTyConApp to_tc (map exprToType $ takeList dc_univ_tyvars dc_args) ] - in - ASSERT2( eqType from_ty (mkTyConApp to_tc (map exprToType $ takeList dc_univ_tyvars dc_args)), dump_doc ) - ASSERT2( equalLength val_args arg_tys, dump_doc ) - Just (dc, to_tc_arg_tys, to_ex_args ++ new_val_args) - - | otherwise - = Nothing - - where - Pair from_ty to_ty = coercionKind co - -collectBindersPushingCo :: CoreExpr -> ([Var], CoreExpr) --- Collect lambda binders, pushing coercions inside if possible --- E.g. (\x.e) |> g g :: -> blah --- = (\x. e |> Nth 1 g) --- --- That is, --- --- collectBindersPushingCo ((\x.e) |> g) === ([x], e |> Nth 1 g) -collectBindersPushingCo e - = go [] e - where - -- Peel off lambdas until we hit a cast. - go :: [Var] -> CoreExpr -> ([Var], CoreExpr) - -- The accumulator is in reverse order - go bs (Lam b e) = go (b:bs) e - go bs (Cast e co) = go_c bs e co - go bs e = (reverse bs, e) - - -- We are in a cast; peel off casts until we hit a lambda. - go_c :: [Var] -> CoreExpr -> CoercionR -> ([Var], CoreExpr) - -- (go_c bs e c) is same as (go bs e (e |> c)) - go_c bs (Cast e co1) co2 = go_c bs e (co1 `mkTransCo` co2) - go_c bs (Lam b e) co = go_lam bs b e co - go_c bs e co = (reverse bs, mkCast e co) - - -- We are in a lambda under a cast; peel off lambdas and build a - -- new coercion for the body. - go_lam :: [Var] -> Var -> CoreExpr -> CoercionR -> ([Var], CoreExpr) - -- (go_lam bs b e c) is same as (go_c bs (\b.e) c) - go_lam bs b e co - | isTyVar b - , let Pair tyL tyR = coercionKind co - , ASSERT( isForAllTy_ty tyL ) - isForAllTy_ty tyR - , isReflCo (mkNthCo Nominal 0 co) -- See Note [collectBindersPushingCo] - = go_c (b:bs) e (mkInstCo co (mkNomReflCo (mkTyVarTy b))) - - | isCoVar b - , let Pair tyL tyR = coercionKind co - , ASSERT( isForAllTy_co tyL ) - isForAllTy_co tyR - , isReflCo (mkNthCo Nominal 0 co) -- See Note [collectBindersPushingCo] - , let cov = mkCoVarCo b - = go_c (b:bs) e (mkInstCo co (mkNomReflCo (mkCoercionTy cov))) - - | isId b - , let Pair tyL tyR = coercionKind co - , ASSERT( isFunTy tyL) isFunTy tyR - , (co_mult, co_arg, co_res) <- decomposeFunCo Representational co - , isReflCo co_mult -- See Note [collectBindersPushingCo] - , isReflCo co_arg -- See Note [collectBindersPushingCo] - = go_c (b:bs) e co_res - - | otherwise = (reverse bs, mkCast (Lam b e) co) - -{- - -Note [collectBindersPushingCo] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -We just look for coercions of form - # w -> blah -(and similarly for foralls) to keep this function simple. We could do -more elaborate stuff, but it'd involve substitution etc. - --} ===================================== compiler/GHC/Core/Subst.hs ===================================== @@ -343,6 +343,8 @@ instance Outputable Subst where substExprSC :: HasDebugCallStack => Subst -> CoreExpr -> CoreExpr -- Just like substExpr, but a no-op if the substitution is empty +-- Note that this does /not/ replace occurrences of free vars with +-- their canonical representatives in the in-scope set substExprSC subst orig_expr | isEmptySubst subst = orig_expr | otherwise = -- pprTrace "enter subst-expr" (doc $$ ppr orig_expr) $ @@ -628,6 +630,9 @@ substIdInfo subst new_id info ------------------ -- | Substitutes for the 'Id's within an unfolding +-- NB: substUnfolding /discards/ any unfolding without +-- without a Stable source. This is usually what we want, +-- but it may be a bit unexpected substUnfolding, substUnfoldingSC :: Subst -> Unfolding -> Unfolding -- Seq'ing on the returned Unfolding is enough to cause -- all the substitutions to happen completely ===================================== testsuite/tests/perf/compiler/Makefile ===================================== @@ -7,7 +7,3 @@ T4007: $(RM) -f T4007.hi T4007.o '$(TEST_HC)' $(TEST_HC_OPTS) -c -O -ddump-rule-firings T4007.hs -T16473: - $(RM) -f T16473.hi T16473.o - '$(TEST_HC)' $(TEST_HC_OPTS) -c -O -ddump-rule-firings T16473.hs - ===================================== testsuite/tests/perf/compiler/T16473.stdout ===================================== @@ -1,97 +1 @@ -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op liftA2 (BUILTIN) -Rule fired: Class op <*> (BUILTIN) -Rule fired: Class op $p1Applicative (BUILTIN) -Rule fired: Class op <$ (BUILTIN) -Rule fired: Class op <*> (BUILTIN) -Rule fired: Class op $p1Applicative (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op get (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op >> (BUILTIN) -Rule fired: Class op put (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op get (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op >> (BUILTIN) -Rule fired: Class op put (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op show (BUILTIN) -Rule fired: Class op mempty (BUILTIN) -Rule fired: Class op fromInteger (BUILTIN) -Rule fired: Integer -> Int# (BUILTIN) -Rule fired: Class op <> (BUILTIN) -Rule fired: Class op + (BUILTIN) -Rule fired: Class op enumFromTo (BUILTIN) -Rule fired: Class op *> (BUILTIN) -Rule fired: Class op *> (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op *> (BUILTIN) -Rule fired: Class op *> (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op *> (BUILTIN) -Rule fired: Class op *> (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: fold/build (GHC.Base) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op $p1Applicative (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op $p1Applicative (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: ># (BUILTIN) -Rule fired: ==# (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op <*> (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op $p1Applicative (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op $p1Applicative (BUILTIN) -Rule fired: SPEC/Main $fMonadStateT_$c>>= @Identity _ (Main) -Rule fired: SPEC/Main $fApplicativeStateT_$c<*> @Identity _ (Main) -Rule fired: SPEC/Main $fApplicativeStateT_$cpure @Identity _ (Main) -Rule fired: SPEC/Main $fFunctorStateT @Identity _ (Main) -Rule fired: SPEC/Main $fFunctorStateT_$cfmap @Identity _ (Main) -Rule fired: Class op fmap (BUILTIN) -Rule fired: SPEC/Main $fFunctorStateT_$cfmap @Identity _ (Main) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op return (BUILTIN) +5050 ===================================== testsuite/tests/perf/compiler/T18223.hs ===================================== @@ -0,0 +1,78 @@ +{-# LANGUAGE PartialTypeSignatures #-} +{-# LANGUAGE Strict #-} + +import Control.Monad.State + +tester :: MonadState a m => m () +tester = modify' id + +-- manyState :: StateT () (StateT () IO) () -> IO () +-- manyState :: _ -> IO () +manyState x = + (flip evalStateT () -- 1 + . flip evalStateT () -- 2 + . flip evalStateT () -- 3 + . flip evalStateT () -- 4 + . flip evalStateT () -- 5 + . flip evalStateT () -- 6 + . flip evalStateT () -- 7 + . flip evalStateT () -- 8 + . flip evalStateT () -- 9 + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + ) x :: IO () + +main :: IO () +main = manyState tester >>= print ===================================== testsuite/tests/perf/compiler/all.T ===================================== @@ -367,7 +367,13 @@ test('T16190', multimod_compile, ['T16190.hs', '-v0']) -test('T16473', normal, makefile_test, ['T16473']) +# Run this program. If specialisation fails, it'll start to allocate much more +test ('T16473', + [ collect_stats('bytes allocated',5) + , only_ways(['normal']) + ], + compile_and_run, + ['-O2 -flate-specialise']) test('T17516', [ collect_compiler_stats('bytes allocated', 5), @@ -415,3 +421,8 @@ test ('T13253-spj', ], compile, ['-v0 -O']) +test ('T18223', + [ collect_compiler_stats('bytes allocated',2) + ], + compile, + ['-v0 -O']) ===================================== testsuite/tests/printer/T18052a.stderr ===================================== @@ -20,7 +20,7 @@ T18052a.$b:||: = \ (@a) (@b) (x :: a) (y :: b) -> (x, y) -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} (+++) :: forall {a}. [a] -> [a] -> [a] [GblId] -(+++) = (++) +(+++) = ++ -- RHS size: {terms: 13, types: 20, coercions: 0, joins: 0/0} T18052a.$m:||: ===================================== testsuite/tests/simplCore/should_compile/T17966.stdout ===================================== @@ -1,5 +1,2 @@ RULES: "SPEC $cm @()" [0] RULES: "SPEC f @Bool @() @(Maybe Integer)" [0] -"SPEC/T17966 $fShowMaybe_$cshow @Integer" -"SPEC/T17966 $fShowMaybe_$cshowList @Integer" -"SPEC/T17966 $fShowMaybe @Integer" ===================================== testsuite/tests/stranal/should_compile/T18122.stderr ===================================== @@ -13,9 +13,8 @@ Lib.$trModule4 = "main"# -- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} Lib.$trModule3 :: GHC.Types.TrName [GblId, - Cpr=m1, Unf=Unf{Src=, TopLvl=True, Value=True, ConLike=True, - WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 20}] + WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] Lib.$trModule3 = GHC.Types.TrNameS Lib.$trModule4 -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} @@ -28,27 +27,25 @@ Lib.$trModule2 = "Lib"# -- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} Lib.$trModule1 :: GHC.Types.TrName [GblId, - Cpr=m1, Unf=Unf{Src=, TopLvl=True, Value=True, ConLike=True, - WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 20}] + WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] Lib.$trModule1 = GHC.Types.TrNameS Lib.$trModule2 -- RHS size: {terms: 3, types: 0, coercions: 0, joins: 0/0} Lib.$trModule :: GHC.Types.Module [GblId, - Cpr=m1, Unf=Unf{Src=, TopLvl=True, Value=True, ConLike=True, - WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 30}] + WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] Lib.$trModule = GHC.Types.Module Lib.$trModule3 Lib.$trModule1 -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} Lib.$wfoo [InlPrag=NOINLINE] :: GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int# [GblId, Arity=2, Str=, Unf=OtherCon []] -Lib.$wfoo = (GHC.Prim.+#) +Lib.$wfoo = GHC.Prim.+# -- RHS size: {terms: 18, types: 14, coercions: 0, joins: 0/0} -foo [InlPrag=NOUSERINLINE[0]] :: (Int, Int) -> Int -> Int +foo [InlPrag=NOUSERINLINE[final]] :: (Int, Int) -> Int -> Int [GblId, Arity=2, Str=, @@ -56,24 +53,25 @@ foo [InlPrag=NOUSERINLINE[0]] :: (Int, Int) -> Int -> Int Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=2,unsat_ok=True,boring_ok=False) - Tmpl= \ (w_sHs [Occ=Once!] :: (Int, Int)) - (w1_sHt [Occ=Once!] :: Int) -> - case w_sHs of { (ww1_sHw [Occ=Once!], _ [Occ=Dead]) -> - case ww1_sHw of { GHC.Types.I# ww4_sHz [Occ=Once] -> - case w1_sHt of { GHC.Types.I# ww6_sHF [Occ=Once] -> - case Lib.$wfoo ww4_sHz ww6_sHF of ww7_sHJ [Occ=Once] { __DEFAULT -> - GHC.Types.I# ww7_sHJ + Tmpl= \ (w_sEf [Occ=Once1!] :: (Int, Int)) + (w1_sEg [Occ=Once1!] :: Int) -> + case w_sEf of { (ww1_sEj [Occ=Once1!], _ [Occ=Dead]) -> + case ww1_sEj of { GHC.Types.I# ww4_sEm [Occ=Once1] -> + case w1_sEg of { GHC.Types.I# ww6_sEs [Occ=Once1] -> + case Lib.$wfoo ww4_sEm ww6_sEs of ww7_sEw [Occ=Once1] + { __DEFAULT -> + GHC.Types.I# ww7_sEw } } } }}] foo - = \ (w_sHs :: (Int, Int)) (w1_sHt :: Int) -> - case w_sHs of { (ww1_sHw, ww2_sHB) -> - case ww1_sHw of { GHC.Types.I# ww4_sHz -> - case w1_sHt of { GHC.Types.I# ww6_sHF -> - case Lib.$wfoo ww4_sHz ww6_sHF of ww7_sHJ { __DEFAULT -> - GHC.Types.I# ww7_sHJ + = \ (w_sEf :: (Int, Int)) (w1_sEg :: Int) -> + case w_sEf of { (ww1_sEj, ww2_sEo) -> + case ww1_sEj of { GHC.Types.I# ww4_sEm -> + case w1_sEg of { GHC.Types.I# ww6_sEs -> + case Lib.$wfoo ww4_sEm ww6_sEs of ww7_sEw { __DEFAULT -> + GHC.Types.I# ww7_sEw } } } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9b2e3687a7e1f47f62e124f639b9a6cf3d3a44d2 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9b2e3687a7e1f47f62e124f639b9a6cf3d3a44d2 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 11:37:29 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Wed, 26 Aug 2020 07:37:29 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] Check pointers with pattern matching (#18405) Message-ID: <5f464979ce4b1_80b3f848685789495505ed@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: 4e120fab by Sven Tennie at 2020-08-26T13:37:07+02:00 Check pointers with pattern matching (#18405) This is nicer than to check the length of the pointer's list and index on it. - - - - - 1 changed file: - libraries/ghc-heap/GHC/Exts/Heap.hs Changes: ===================================== libraries/ghc-heap/GHC/Exts/Heap.hs ===================================== @@ -346,55 +346,48 @@ getClosureX get_closure_raw x = do , finalizer = pts !! 3 , link = pts !! 4 } - TSO -> do - unless (length pts == 6) $ - fail $ "Expected 6 ptr arguments to TSO, found " + TSO | [ u_lnk, u_gbl_lnk, tso_stack, u_trec, u_blk_ex, u_bq] <- pts + -> withArray wds (\ptr -> do + fields <- FFIClosures.peekTSOFields peekStgTSOProfInfo ptr + pure $ TSOClosure + { info = itbl + , unsafe_link = u_lnk + , unsafe_global_link = u_gbl_lnk + , tsoStack = tso_stack + , unsafe_trec = u_trec + , unsafe_blocked_exceptions = u_blk_ex + , unsafe_bq = u_bq + , what_next = FFIClosures.tso_what_next fields + , why_blocked = FFIClosures.tso_why_blocked fields + , flags = FFIClosures.tso_flags fields + , threadId = FFIClosures.tso_threadId fields + , saved_errno = FFIClosures.tso_saved_errno fields + , tso_dirty = FFIClosures.tso_dirty fields + , alloc_limit = FFIClosures.tso_alloc_limit fields + , tot_stack_size = FFIClosures.tso_tot_stack_size fields + , prof = FFIClosures.tso_prof fields + }) + | otherwise + -> fail $ "Expected 6 ptr arguments to TSO, found " ++ show (length pts) - - allocaArray (length wds) (\ptr -> do - pokeArray ptr wds - - fields <- FFIClosures.peekTSOFields peekStgTSOProfInfo ptr - pure $ TSOClosure - { info = itbl - , unsafe_link = (pts !! 0) - , unsafe_global_link = (pts !! 1) - , tsoStack = (pts !! 2) - , unsafe_trec = (pts !! 3) - , unsafe_blocked_exceptions = (pts !! 4) - , unsafe_bq = (pts !! 5) - , what_next = FFIClosures.tso_what_next fields - , why_blocked = FFIClosures.tso_why_blocked fields - , flags = FFIClosures.tso_flags fields - , threadId = FFIClosures.tso_threadId fields - , saved_errno = FFIClosures.tso_saved_errno fields - , tso_dirty = FFIClosures.tso_dirty fields - , alloc_limit = FFIClosures.tso_alloc_limit fields - , tot_stack_size = FFIClosures.tso_tot_stack_size fields - , prof = FFIClosures.tso_prof fields - } - ) - STACK -> do - unless (length pts == 1) $ - fail $ "Expected 1 ptr argument to STACK, found " - ++ show (length pts) - - allocaArray (length wds) (\ptr -> do - pokeArray ptr wds - - fields <- FFIClosures.peekStackFields ptr - - pure $ StackClosure - { info = itbl - , stack_size = FFIClosures.stack_size fields - , stack_dirty = FFIClosures.stack_dirty fields - , unsafeStackPointer = (pts !! 0) - , unsafeStack = FFIClosures.stack fields + STACK | [u_sp] <- pts + -> withArray wds (\ptr -> do + fields <- FFIClosures.peekStackFields ptr + + pure $ StackClosure + { info = itbl + , stack_size = FFIClosures.stack_size fields + , stack_dirty = FFIClosures.stack_dirty fields + , unsafeStackPointer = u_sp + , unsafeStack = FFIClosures.stack fields #if __GLASGOW_HASKELL__ >= 811 - , stack_marking = FFIClosures.stack_marking fields + , stack_marking = FFIClosures.stack_marking fields #endif - } - ) + }) + | otherwise + -> fail $ "Expected 1 ptr argument to STACK, found " + ++ show (length pts) + _ -> pure $ UnsupportedClosure itbl View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4e120fab41432d16679eeb3eba07a5b4156f3739 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4e120fab41432d16679eeb3eba07a5b4156f3739 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 13:26:34 2020 From: gitlab at gitlab.haskell.org (Ryan Scott) Date: Wed, 26 Aug 2020 09:26:34 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18612 Message-ID: <5f46630aae1c8_80bd4d01909557227@gitlab.haskell.org.mail> Ryan Scott pushed new branch wip/T18612 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18612 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 14:42:36 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 26 Aug 2020 10:42:36 -0400 Subject: [Git][ghc/ghc][master] PPC and X86: Portable printing of IEEE floats Message-ID: <5f4674dcb93f5_80b55febdc957022d@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: fcb10b6c by Peter Trommler at 2020-08-26T10:42:30-04:00 PPC and X86: Portable printing of IEEE floats GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness. This was brought up in #18431 by @hsyl20. - - - - - 4 changed files: - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/Ppr.hs - compiler/GHC/CmmToAsm/SPARC/Ppr.hs - compiler/GHC/CmmToAsm/X86/Ppr.hs Changes: ===================================== compiler/GHC/CmmToAsm/PPC/Ppr.hs ===================================== @@ -237,9 +237,8 @@ pprImm (ImmInteger i) = integer i pprImm (ImmCLbl l) = ppr l pprImm (ImmIndex l i) = ppr l <> char '+' <> int i pprImm (ImmLit s) = s - -pprImm (ImmFloat _) = text "naughty float immediate" -pprImm (ImmDouble _) = text "naughty double immediate" +pprImm (ImmFloat f) = float $ fromRational f +pprImm (ImmDouble d) = double $ fromRational d pprImm (ImmConstantSum a b) = pprImm a <> char '+' <> pprImm b pprImm (ImmConstantDiff a b) = pprImm a <> char '-' @@ -337,13 +336,8 @@ pprDataItem platform lit <> int (fromIntegral (fromIntegral x :: Word32))] - ppr_item FF32 (CmmFloat r _) - = let bs = floatToBytes (fromRational r) - in map (\b -> text "\t.byte\t" <> pprImm (ImmInt b)) bs - - ppr_item FF64 (CmmFloat r _) - = let bs = doubleToBytes (fromRational r) - in map (\b -> text "\t.byte\t" <> pprImm (ImmInt b)) bs + ppr_item FF32 _ = [text "\t.float\t" <> pprImm imm] + ppr_item FF64 _ = [text "\t.double\t" <> pprImm imm] ppr_item _ _ = panic "PPC.Ppr.pprDataItem: no match" ===================================== compiler/GHC/CmmToAsm/Ppr.hs ===================================== @@ -9,9 +9,6 @@ ----------------------------------------------------------------------------- module GHC.CmmToAsm.Ppr ( - castFloatToWord8Array, - castDoubleToWord8Array, - floatToBytes, doubleToBytes, pprASCII, pprString, @@ -44,13 +41,13 @@ import qualified Data.ByteString as BS import GHC.Exts import GHC.Word - - -- ----------------------------------------------------------------------------- -- Converting floating-point literals to integrals for printing -castFloatToWord8Array :: STUArray s Int Float -> ST s (STUArray s Int Word8) -castFloatToWord8Array = U.castSTUArray +-- ToDo: this code is currently shared between SPARC and LLVM. +-- Similar functions for (single precision) floats are +-- present in the SPARC backend only. We need to fix both +-- LLVM and SPARC. castDoubleToWord8Array :: STUArray s Int Double -> ST s (STUArray s Int Word8) castDoubleToWord8Array = U.castSTUArray @@ -63,19 +60,6 @@ castDoubleToWord8Array = U.castSTUArray -- ToDo: this stuff is very similar to the shenanigans in PprAbs, -- could they be merged? -floatToBytes :: Float -> [Int] -floatToBytes f - = runST (do - arr <- newArray_ ((0::Int),3) - writeArray arr 0 f - arr <- castFloatToWord8Array arr - i0 <- readArray arr 0 - i1 <- readArray arr 1 - i2 <- readArray arr 2 - i3 <- readArray arr 3 - return (map fromIntegral [i0,i1,i2,i3]) - ) - doubleToBytes :: Double -> [Int] doubleToBytes d = runST (do ===================================== compiler/GHC/CmmToAsm/SPARC/Ppr.hs ===================================== @@ -25,6 +25,12 @@ where import GHC.Prelude +import Data.Word +import qualified Data.Array.Unsafe as U ( castSTUArray ) +import Data.Array.ST + +import Control.Monad.ST + import GHC.CmmToAsm.SPARC.Regs import GHC.CmmToAsm.SPARC.Instr import GHC.CmmToAsm.SPARC.Cond @@ -369,6 +375,22 @@ pprDataItem platform lit ppr_item II64 _ = [text "\t.quad\t" <> pprImm imm] ppr_item _ _ = panic "SPARC.Ppr.pprDataItem: no match" +floatToBytes :: Float -> [Int] +floatToBytes f + = runST (do + arr <- newArray_ ((0::Int),3) + writeArray arr 0 f + arr <- castFloatToWord8Array arr + i0 <- readArray arr 0 + i1 <- readArray arr 1 + i2 <- readArray arr 2 + i3 <- readArray arr 3 + return (map fromIntegral [i0,i1,i2,i3]) + ) + +castFloatToWord8Array :: STUArray s Int Float -> ST s (STUArray s Int Word8) +castFloatToWord8Array = U.castSTUArray + -- | Pretty print an instruction. pprInstr :: Instr -> SDoc ===================================== compiler/GHC/CmmToAsm/X86/Ppr.hs ===================================== @@ -423,9 +423,8 @@ pprImm (ImmInteger i) = integer i pprImm (ImmCLbl l) = ppr l pprImm (ImmIndex l i) = ppr l <> char '+' <> int i pprImm (ImmLit s) = s - -pprImm (ImmFloat _) = text "naughty float immediate" -pprImm (ImmDouble _) = text "naughty double immediate" +pprImm (ImmFloat f) = float $ fromRational f +pprImm (ImmDouble d) = double $ fromRational d pprImm (ImmConstantSum a b) = pprImm a <> char '+' <> pprImm b pprImm (ImmConstantDiff a b) = pprImm a <> char '-' @@ -514,13 +513,8 @@ pprDataItem config lit ppr_item II16 _ = [text "\t.word\t" <> pprImm imm] ppr_item II32 _ = [text "\t.long\t" <> pprImm imm] - ppr_item FF32 (CmmFloat r _) - = let bs = floatToBytes (fromRational r) - in map (\b -> text "\t.byte\t" <> pprImm (ImmInt b)) bs - - ppr_item FF64 (CmmFloat r _) - = let bs = doubleToBytes (fromRational r) - in map (\b -> text "\t.byte\t" <> pprImm (ImmInt b)) bs + ppr_item FF32 _ = [text "\t.float\t" <> pprImm imm] + ppr_item FF64 _ = [text "\t.double\t" <> pprImm imm] ppr_item II64 _ = case platformOS platform of @@ -558,9 +552,6 @@ pprDataItem config lit _ -> [text "\t.quad\t" <> pprImm imm] - ppr_item _ _ - = panic "X86.Ppr.ppr_item: no match" - asmComment :: SDoc -> SDoc asmComment c = whenPprDebug $ text "# " <> c View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fcb10b6c69e388d8c6e777baf39920e2cc694501 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fcb10b6c69e388d8c6e777baf39920e2cc694501 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 14:43:20 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Wed, 26 Aug 2020 10:43:20 -0400 Subject: [Git][ghc/ghc][master] primops: Remove Monadic and Dyadic categories Message-ID: <5f46750898333_80b3f84861dab4c9571192@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 770100e0 by Krzysztof Gogolewski at 2020-08-26T10:43:13-04:00 primops: Remove Monadic and Dyadic categories There were four categories of primops: Monadic, Dyadic, Compare, GenPrimOp. The compiler does not treat Monadic and Dyadic in any special way, we can just replace them with GenPrimOp. Compare is still used in isComparisonPrimOp. - - - - - 8 changed files: - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/StgToCmm/Prim.hs - utils/genprimopcode/Lexer.x - utils/genprimopcode/Main.hs - utils/genprimopcode/Parser.y - utils/genprimopcode/ParserM.hs - utils/genprimopcode/Syntax.hs Changes: ===================================== compiler/GHC/Builtin/PrimOps.hs ===================================== @@ -38,7 +38,7 @@ import GHC.Types.Name import GHC.Builtin.Names ( gHC_PRIMOPWRAPPERS ) import GHC.Core.TyCon ( TyCon, isPrimTyCon, PrimRep(..) ) import GHC.Core.Type -import GHC.Types.RepType ( typePrimRep1, tyConPrimRep1 ) +import GHC.Types.RepType ( tyConPrimRep1 ) import GHC.Types.Basic ( Arity, Fixity(..), FixityDirection(..), Boxity(..), SourceText(..) ) import GHC.Types.SrcLoc ( wiredInSrcSpan ) @@ -103,33 +103,17 @@ tagToEnumKey = mkPrimOpIdUnique (primOpTag TagToEnumOp) \subsection[PrimOp-info]{The essential info about each @PrimOp@} * * ************************************************************************ - -The @String@ in the @PrimOpInfos@ is the ``base name'' by which the user may -refer to the primitive operation. The conventional \tr{#}-for- -unboxed ops is added on later. - -The reason for the funny characters in the names is so we do not -interfere with the programmer's Haskell name spaces. - -We use @PrimKinds@ for the ``type'' information, because they're -(slightly) more convenient to use than @TyCons at . -} data PrimOpInfo - = Dyadic OccName -- string :: T -> T -> T - Type - | Monadic OccName -- string :: T -> T - Type - | Compare OccName -- string :: T -> T -> Int# + = Compare OccName -- string :: T -> T -> Int# Type | GenPrimOp OccName -- string :: \/a1..an . T1 -> .. -> Tk -> T [TyVar] [Type] Type -mkDyadic, mkMonadic, mkCompare :: FastString -> Type -> PrimOpInfo -mkDyadic str ty = Dyadic (mkVarOccFS str) ty -mkMonadic str ty = Monadic (mkVarOccFS str) ty +mkCompare :: FastString -> Type -> PrimOpInfo mkCompare str ty = Compare (mkVarOccFS str) ty mkGenPrimOp :: FastString -> [TyVar] -> [Type] -> Type -> PrimOpInfo @@ -575,8 +559,6 @@ primOpCodeSizeForeignCall = 4 primOpType :: PrimOp -> Type -- you may want to use primOpSig instead primOpType op = case primOpInfo op of - Dyadic _occ ty -> dyadic_fun_ty ty - Monadic _occ ty -> monadic_fun_ty ty Compare _occ ty -> compare_fun_ty ty GenPrimOp _occ tyvars arg_tys res_ty -> @@ -585,15 +567,11 @@ primOpType op primOpResultType :: PrimOp -> Type primOpResultType op = case primOpInfo op of - Dyadic _occ ty -> ty - Monadic _occ ty -> ty Compare _occ _ty -> intPrimTy GenPrimOp _occ _tyvars _arg_tys res_ty -> res_ty primOpOcc :: PrimOp -> OccName primOpOcc op = case primOpInfo op of - Dyadic occ _ -> occ - Monadic occ _ -> occ Compare occ _ -> occ GenPrimOp occ _ _ _ -> occ @@ -692,8 +670,8 @@ primOpWrapperId op = mkVanillaGlobalWithInfo name ty info isComparisonPrimOp :: PrimOp -> Bool isComparisonPrimOp op = case primOpInfo op of - Compare {} -> True - _ -> False + Compare {} -> True + GenPrimOp {} -> False -- primOpSig is like primOpType but gives the result split apart: -- (type variables, argument types, result type) @@ -706,8 +684,6 @@ primOpSig op arity = length arg_tys (tyvars, arg_tys, res_ty) = case (primOpInfo op) of - Monadic _occ ty -> ([], [ty], ty ) - Dyadic _occ ty -> ([], [ty,ty], ty ) Compare _occ ty -> ([], [ty,ty], intPrimTy) GenPrimOp _occ tyvars arg_tys res_ty -> (tyvars, arg_tys, res_ty ) @@ -722,8 +698,6 @@ data PrimOpResultInfo getPrimOpResultInfo :: PrimOp -> PrimOpResultInfo getPrimOpResultInfo op = case (primOpInfo op) of - Dyadic _ ty -> ReturnsPrim (typePrimRep1 ty) - Monadic _ ty -> ReturnsPrim (typePrimRep1 ty) Compare _ _ -> ReturnsPrim (tyConPrimRep1 intPrimTyCon) GenPrimOp _ _ _ ty | isPrimTyCon tc -> ReturnsPrim (tyConPrimRep1 tc) | otherwise -> ReturnsAlg tc @@ -747,9 +721,7 @@ commutableOp :: PrimOp -> Bool -- Utils: -dyadic_fun_ty, monadic_fun_ty, compare_fun_ty :: Type -> Type -dyadic_fun_ty ty = mkVisFunTysMany [ty, ty] ty -monadic_fun_ty ty = mkVisFunTyMany ty ty +compare_fun_ty :: Type -> Type compare_fun_ty ty = mkVisFunTysMany [ty, ty] intPrimTy -- Output stuff: ===================================== compiler/GHC/Builtin/primops.txt.pp ===================================== @@ -42,11 +42,9 @@ -- (eg, out_of_line), whilst avoiding parsing complex expressions -- needed for strictness info. -- --- type refers to the general category of the primop. Valid settings include, +-- type refers to the general category of the primop. There are only two: -- -- * Compare: A comparison operation of the shape a -> a -> Int# --- * Monadic: A unary operation of shape a -> a --- * Dyadic: A binary operation of shape a -> a -> a -- * GenPrimOp: Any other sort of primop -- @@ -238,23 +236,23 @@ primtype Int8# primop Int8Extend "extendInt8#" GenPrimOp Int8# -> Int# primop Int8Narrow "narrowInt8#" GenPrimOp Int# -> Int8# -primop Int8NegOp "negateInt8#" Monadic Int8# -> Int8# +primop Int8NegOp "negateInt8#" GenPrimOp Int8# -> Int8# -primop Int8AddOp "plusInt8#" Dyadic Int8# -> Int8# -> Int8# +primop Int8AddOp "plusInt8#" GenPrimOp Int8# -> Int8# -> Int8# with commutable = True -primop Int8SubOp "subInt8#" Dyadic Int8# -> Int8# -> Int8# +primop Int8SubOp "subInt8#" GenPrimOp Int8# -> Int8# -> Int8# -primop Int8MulOp "timesInt8#" Dyadic Int8# -> Int8# -> Int8# +primop Int8MulOp "timesInt8#" GenPrimOp Int8# -> Int8# -> Int8# with commutable = True -primop Int8QuotOp "quotInt8#" Dyadic Int8# -> Int8# -> Int8# +primop Int8QuotOp "quotInt8#" GenPrimOp Int8# -> Int8# -> Int8# with can_fail = True -primop Int8RemOp "remInt8#" Dyadic Int8# -> Int8# -> Int8# +primop Int8RemOp "remInt8#" GenPrimOp Int8# -> Int8# -> Int8# with can_fail = True @@ -279,23 +277,23 @@ primtype Word8# primop Word8Extend "extendWord8#" GenPrimOp Word8# -> Word# primop Word8Narrow "narrowWord8#" GenPrimOp Word# -> Word8# -primop Word8NotOp "notWord8#" Monadic Word8# -> Word8# +primop Word8NotOp "notWord8#" GenPrimOp Word8# -> Word8# -primop Word8AddOp "plusWord8#" Dyadic Word8# -> Word8# -> Word8# +primop Word8AddOp "plusWord8#" GenPrimOp Word8# -> Word8# -> Word8# with commutable = True -primop Word8SubOp "subWord8#" Dyadic Word8# -> Word8# -> Word8# +primop Word8SubOp "subWord8#" GenPrimOp Word8# -> Word8# -> Word8# -primop Word8MulOp "timesWord8#" Dyadic Word8# -> Word8# -> Word8# +primop Word8MulOp "timesWord8#" GenPrimOp Word8# -> Word8# -> Word8# with commutable = True -primop Word8QuotOp "quotWord8#" Dyadic Word8# -> Word8# -> Word8# +primop Word8QuotOp "quotWord8#" GenPrimOp Word8# -> Word8# -> Word8# with can_fail = True -primop Word8RemOp "remWord8#" Dyadic Word8# -> Word8# -> Word8# +primop Word8RemOp "remWord8#" GenPrimOp Word8# -> Word8# -> Word8# with can_fail = True @@ -320,23 +318,23 @@ primtype Int16# primop Int16Extend "extendInt16#" GenPrimOp Int16# -> Int# primop Int16Narrow "narrowInt16#" GenPrimOp Int# -> Int16# -primop Int16NegOp "negateInt16#" Monadic Int16# -> Int16# +primop Int16NegOp "negateInt16#" GenPrimOp Int16# -> Int16# -primop Int16AddOp "plusInt16#" Dyadic Int16# -> Int16# -> Int16# +primop Int16AddOp "plusInt16#" GenPrimOp Int16# -> Int16# -> Int16# with commutable = True -primop Int16SubOp "subInt16#" Dyadic Int16# -> Int16# -> Int16# +primop Int16SubOp "subInt16#" GenPrimOp Int16# -> Int16# -> Int16# -primop Int16MulOp "timesInt16#" Dyadic Int16# -> Int16# -> Int16# +primop Int16MulOp "timesInt16#" GenPrimOp Int16# -> Int16# -> Int16# with commutable = True -primop Int16QuotOp "quotInt16#" Dyadic Int16# -> Int16# -> Int16# +primop Int16QuotOp "quotInt16#" GenPrimOp Int16# -> Int16# -> Int16# with can_fail = True -primop Int16RemOp "remInt16#" Dyadic Int16# -> Int16# -> Int16# +primop Int16RemOp "remInt16#" GenPrimOp Int16# -> Int16# -> Int16# with can_fail = True @@ -361,23 +359,23 @@ primtype Word16# primop Word16Extend "extendWord16#" GenPrimOp Word16# -> Word# primop Word16Narrow "narrowWord16#" GenPrimOp Word# -> Word16# -primop Word16NotOp "notWord16#" Monadic Word16# -> Word16# +primop Word16NotOp "notWord16#" GenPrimOp Word16# -> Word16# -primop Word16AddOp "plusWord16#" Dyadic Word16# -> Word16# -> Word16# +primop Word16AddOp "plusWord16#" GenPrimOp Word16# -> Word16# -> Word16# with commutable = True -primop Word16SubOp "subWord16#" Dyadic Word16# -> Word16# -> Word16# +primop Word16SubOp "subWord16#" GenPrimOp Word16# -> Word16# -> Word16# -primop Word16MulOp "timesWord16#" Dyadic Word16# -> Word16# -> Word16# +primop Word16MulOp "timesWord16#" GenPrimOp Word16# -> Word16# -> Word16# with commutable = True -primop Word16QuotOp "quotWord16#" Dyadic Word16# -> Word16# -> Word16# +primop Word16QuotOp "quotWord16#" GenPrimOp Word16# -> Word16# -> Word16# with can_fail = True -primop Word16RemOp "remWord16#" Dyadic Word16# -> Word16# -> Word16# +primop Word16RemOp "remWord16#" GenPrimOp Word16# -> Word16# -> Word16# with can_fail = True @@ -420,16 +418,16 @@ section "Int#" primtype Int# -primop IntAddOp "+#" Dyadic +primop IntAddOp "+#" GenPrimOp Int# -> Int# -> Int# with commutable = True fixity = infixl 6 -primop IntSubOp "-#" Dyadic Int# -> Int# -> Int# +primop IntSubOp "-#" GenPrimOp Int# -> Int# -> Int# with fixity = infixl 6 primop IntMulOp "*#" - Dyadic Int# -> Int# -> Int# + GenPrimOp Int# -> Int# -> Int# {Low word of signed integer multiply.} with commutable = True fixity = infixl 7 @@ -442,7 +440,7 @@ primop IntMul2Op "timesInt2#" GenPrimOp 0#) or not (isHighNeeded = 1#).} primop IntMulMayOfloOp "mulIntMayOflo#" - Dyadic Int# -> Int# -> Int# + GenPrimOp Int# -> Int# -> Int# {Return non-zero if there is any possibility that the upper word of a signed integer multiply might contain useful information. Return zero only if you are completely sure that no overflow can occur. @@ -465,14 +463,14 @@ primop IntMulMayOfloOp "mulIntMayOflo#" } with commutable = True -primop IntQuotOp "quotInt#" Dyadic +primop IntQuotOp "quotInt#" GenPrimOp Int# -> Int# -> Int# {Rounds towards zero. The behavior is undefined if the second argument is zero. } with can_fail = True -primop IntRemOp "remInt#" Dyadic +primop IntRemOp "remInt#" GenPrimOp Int# -> Int# -> Int# {Satisfies \texttt{(quotInt\# x y) *\# y +\# (remInt\# x y) == x}. The behavior is undefined if the second argument is zero. @@ -484,22 +482,22 @@ primop IntQuotRemOp "quotRemInt#" GenPrimOp {Rounds towards zero.} with can_fail = True -primop AndIOp "andI#" Dyadic Int# -> Int# -> Int# +primop AndIOp "andI#" GenPrimOp Int# -> Int# -> Int# {Bitwise "and".} with commutable = True -primop OrIOp "orI#" Dyadic Int# -> Int# -> Int# +primop OrIOp "orI#" GenPrimOp Int# -> Int# -> Int# {Bitwise "or".} with commutable = True -primop XorIOp "xorI#" Dyadic Int# -> Int# -> Int# +primop XorIOp "xorI#" GenPrimOp Int# -> Int# -> Int# {Bitwise "xor".} with commutable = True -primop NotIOp "notI#" Monadic Int# -> Int# +primop NotIOp "notI#" GenPrimOp Int# -> Int# {Bitwise "not", also known as the binary complement.} -primop IntNegOp "negateInt#" Monadic Int# -> Int# +primop IntNegOp "negateInt#" GenPrimOp Int# -> Int# {Unary negation. Since the negative {\tt Int#} range extends one further than the positive range, {\tt negateInt#} of the most negative number is an @@ -573,7 +571,7 @@ section "Word#" primtype Word# -primop WordAddOp "plusWord#" Dyadic Word# -> Word# -> Word# +primop WordAddOp "plusWord#" GenPrimOp Word# -> Word# -> Word# with commutable = True primop WordAddCOp "addWordC#" GenPrimOp Word# -> Word# -> (# Word#, Int# #) @@ -596,9 +594,9 @@ primop WordAdd2Op "plusWord2#" GenPrimOp Word# -> Word# -> (# Word#, Wor with code_size = 2 commutable = True -primop WordSubOp "minusWord#" Dyadic Word# -> Word# -> Word# +primop WordSubOp "minusWord#" GenPrimOp Word# -> Word# -> Word# -primop WordMulOp "timesWord#" Dyadic Word# -> Word# -> Word# +primop WordMulOp "timesWord#" GenPrimOp Word# -> Word# -> Word# with commutable = True -- Returns (# high, low #) @@ -606,10 +604,10 @@ primop WordMul2Op "timesWord2#" GenPrimOp Word# -> Word# -> (# Word#, Word# #) with commutable = True -primop WordQuotOp "quotWord#" Dyadic Word# -> Word# -> Word# +primop WordQuotOp "quotWord#" GenPrimOp Word# -> Word# -> Word# with can_fail = True -primop WordRemOp "remWord#" Dyadic Word# -> Word# -> Word# +primop WordRemOp "remWord#" GenPrimOp Word# -> Word# -> Word# with can_fail = True primop WordQuotRemOp "quotRemWord#" GenPrimOp @@ -622,16 +620,16 @@ primop WordQuotRem2Op "quotRemWord2#" GenPrimOp Requires that high word < divisor.} with can_fail = True -primop AndOp "and#" Dyadic Word# -> Word# -> Word# +primop AndOp "and#" GenPrimOp Word# -> Word# -> Word# with commutable = True -primop OrOp "or#" Dyadic Word# -> Word# -> Word# +primop OrOp "or#" GenPrimOp Word# -> Word# -> Word# with commutable = True -primop XorOp "xor#" Dyadic Word# -> Word# -> Word# +primop XorOp "xor#" GenPrimOp Word# -> Word# -> Word# with commutable = True -primop NotOp "not#" Monadic Word# -> Word# +primop NotOp "not#" GenPrimOp Word# -> Word# primop SllOp "uncheckedShiftL#" GenPrimOp Word# -> Int# -> Word# {Shift left logical. Result undefined if shift amount is not @@ -650,79 +648,79 @@ primop WordNeOp "neWord#" Compare Word# -> Word# -> Int# primop WordLtOp "ltWord#" Compare Word# -> Word# -> Int# primop WordLeOp "leWord#" Compare Word# -> Word# -> Int# -primop PopCnt8Op "popCnt8#" Monadic Word# -> Word# +primop PopCnt8Op "popCnt8#" GenPrimOp Word# -> Word# {Count the number of set bits in the lower 8 bits of a word.} -primop PopCnt16Op "popCnt16#" Monadic Word# -> Word# +primop PopCnt16Op "popCnt16#" GenPrimOp Word# -> Word# {Count the number of set bits in the lower 16 bits of a word.} -primop PopCnt32Op "popCnt32#" Monadic Word# -> Word# +primop PopCnt32Op "popCnt32#" GenPrimOp Word# -> Word# {Count the number of set bits in the lower 32 bits of a word.} primop PopCnt64Op "popCnt64#" GenPrimOp WORD64 -> Word# {Count the number of set bits in a 64-bit word.} -primop PopCntOp "popCnt#" Monadic Word# -> Word# +primop PopCntOp "popCnt#" GenPrimOp Word# -> Word# {Count the number of set bits in a word.} -primop Pdep8Op "pdep8#" Dyadic Word# -> Word# -> Word# +primop Pdep8Op "pdep8#" GenPrimOp Word# -> Word# -> Word# {Deposit bits to lower 8 bits of a word at locations specified by a mask.} -primop Pdep16Op "pdep16#" Dyadic Word# -> Word# -> Word# +primop Pdep16Op "pdep16#" GenPrimOp Word# -> Word# -> Word# {Deposit bits to lower 16 bits of a word at locations specified by a mask.} -primop Pdep32Op "pdep32#" Dyadic Word# -> Word# -> Word# +primop Pdep32Op "pdep32#" GenPrimOp Word# -> Word# -> Word# {Deposit bits to lower 32 bits of a word at locations specified by a mask.} primop Pdep64Op "pdep64#" GenPrimOp WORD64 -> WORD64 -> WORD64 {Deposit bits to a word at locations specified by a mask.} -primop PdepOp "pdep#" Dyadic Word# -> Word# -> Word# +primop PdepOp "pdep#" GenPrimOp Word# -> Word# -> Word# {Deposit bits to a word at locations specified by a mask.} -primop Pext8Op "pext8#" Dyadic Word# -> Word# -> Word# +primop Pext8Op "pext8#" GenPrimOp Word# -> Word# -> Word# {Extract bits from lower 8 bits of a word at locations specified by a mask.} -primop Pext16Op "pext16#" Dyadic Word# -> Word# -> Word# +primop Pext16Op "pext16#" GenPrimOp Word# -> Word# -> Word# {Extract bits from lower 16 bits of a word at locations specified by a mask.} -primop Pext32Op "pext32#" Dyadic Word# -> Word# -> Word# +primop Pext32Op "pext32#" GenPrimOp Word# -> Word# -> Word# {Extract bits from lower 32 bits of a word at locations specified by a mask.} primop Pext64Op "pext64#" GenPrimOp WORD64 -> WORD64 -> WORD64 {Extract bits from a word at locations specified by a mask.} -primop PextOp "pext#" Dyadic Word# -> Word# -> Word# +primop PextOp "pext#" GenPrimOp Word# -> Word# -> Word# {Extract bits from a word at locations specified by a mask.} -primop Clz8Op "clz8#" Monadic Word# -> Word# +primop Clz8Op "clz8#" GenPrimOp Word# -> Word# {Count leading zeros in the lower 8 bits of a word.} -primop Clz16Op "clz16#" Monadic Word# -> Word# +primop Clz16Op "clz16#" GenPrimOp Word# -> Word# {Count leading zeros in the lower 16 bits of a word.} -primop Clz32Op "clz32#" Monadic Word# -> Word# +primop Clz32Op "clz32#" GenPrimOp Word# -> Word# {Count leading zeros in the lower 32 bits of a word.} primop Clz64Op "clz64#" GenPrimOp WORD64 -> Word# {Count leading zeros in a 64-bit word.} -primop ClzOp "clz#" Monadic Word# -> Word# +primop ClzOp "clz#" GenPrimOp Word# -> Word# {Count leading zeros in a word.} -primop Ctz8Op "ctz8#" Monadic Word# -> Word# +primop Ctz8Op "ctz8#" GenPrimOp Word# -> Word# {Count trailing zeros in the lower 8 bits of a word.} -primop Ctz16Op "ctz16#" Monadic Word# -> Word# +primop Ctz16Op "ctz16#" GenPrimOp Word# -> Word# {Count trailing zeros in the lower 16 bits of a word.} -primop Ctz32Op "ctz32#" Monadic Word# -> Word# +primop Ctz32Op "ctz32#" GenPrimOp Word# -> Word# {Count trailing zeros in the lower 32 bits of a word.} primop Ctz64Op "ctz64#" GenPrimOp WORD64 -> Word# {Count trailing zeros in a 64-bit word.} -primop CtzOp "ctz#" Monadic Word# -> Word# +primop CtzOp "ctz#" GenPrimOp Word# -> Word# {Count trailing zeros in a word.} -primop BSwap16Op "byteSwap16#" Monadic Word# -> Word# +primop BSwap16Op "byteSwap16#" GenPrimOp Word# -> Word# {Swap bytes in the lower 16 bits of a word. The higher bytes are undefined. } -primop BSwap32Op "byteSwap32#" Monadic Word# -> Word# +primop BSwap32Op "byteSwap32#" GenPrimOp Word# -> Word# {Swap bytes in the lower 32 bits of a word. The higher bytes are undefined. } -primop BSwap64Op "byteSwap64#" Monadic WORD64 -> WORD64 +primop BSwap64Op "byteSwap64#" GenPrimOp WORD64 -> WORD64 {Swap bytes in a 64 bits of a word.} -primop BSwapOp "byteSwap#" Monadic Word# -> Word# +primop BSwapOp "byteSwap#" GenPrimOp Word# -> Word# {Swap bytes in a word.} -primop BRev8Op "bitReverse8#" Monadic Word# -> Word# +primop BRev8Op "bitReverse8#" GenPrimOp Word# -> Word# {Reverse the order of the bits in a 8-bit word.} -primop BRev16Op "bitReverse16#" Monadic Word# -> Word# +primop BRev16Op "bitReverse16#" GenPrimOp Word# -> Word# {Reverse the order of the bits in a 16-bit word.} -primop BRev32Op "bitReverse32#" Monadic Word# -> Word# +primop BRev32Op "bitReverse32#" GenPrimOp Word# -> Word# {Reverse the order of the bits in a 32-bit word.} -primop BRev64Op "bitReverse64#" Monadic WORD64 -> WORD64 +primop BRev64Op "bitReverse64#" GenPrimOp WORD64 -> WORD64 {Reverse the order of the bits in a 64-bit word.} -primop BRevOp "bitReverse#" Monadic Word# -> Word# +primop BRevOp "bitReverse#" GenPrimOp Word# -> Word# {Reverse the order of the bits in a word.} ------------------------------------------------------------------------ @@ -730,12 +728,12 @@ section "Narrowings" {Explicit narrowing of native-sized ints or words.} ------------------------------------------------------------------------ -primop Narrow8IntOp "narrow8Int#" Monadic Int# -> Int# -primop Narrow16IntOp "narrow16Int#" Monadic Int# -> Int# -primop Narrow32IntOp "narrow32Int#" Monadic Int# -> Int# -primop Narrow8WordOp "narrow8Word#" Monadic Word# -> Word# -primop Narrow16WordOp "narrow16Word#" Monadic Word# -> Word# -primop Narrow32WordOp "narrow32Word#" Monadic Word# -> Word# +primop Narrow8IntOp "narrow8Int#" GenPrimOp Int# -> Int# +primop Narrow16IntOp "narrow16Int#" GenPrimOp Int# -> Int# +primop Narrow32IntOp "narrow32Int#" GenPrimOp Int# -> Int# +primop Narrow8WordOp "narrow8Word#" GenPrimOp Word# -> Word# +primop Narrow16WordOp "narrow16Word#" GenPrimOp Word# -> Word# +primop Narrow32WordOp "narrow32Word#" GenPrimOp Word# -> Word# ------------------------------------------------------------------------ section "Double#" @@ -766,27 +764,27 @@ primop DoubleLtOp "<##" Compare Double# -> Double# -> Int# primop DoubleLeOp "<=##" Compare Double# -> Double# -> Int# with fixity = infix 4 -primop DoubleAddOp "+##" Dyadic +primop DoubleAddOp "+##" GenPrimOp Double# -> Double# -> Double# with commutable = True fixity = infixl 6 -primop DoubleSubOp "-##" Dyadic Double# -> Double# -> Double# +primop DoubleSubOp "-##" GenPrimOp Double# -> Double# -> Double# with fixity = infixl 6 -primop DoubleMulOp "*##" Dyadic +primop DoubleMulOp "*##" GenPrimOp Double# -> Double# -> Double# with commutable = True fixity = infixl 7 -primop DoubleDivOp "/##" Dyadic +primop DoubleDivOp "/##" GenPrimOp Double# -> Double# -> Double# with can_fail = True fixity = infixl 7 -primop DoubleNegOp "negateDouble#" Monadic Double# -> Double# +primop DoubleNegOp "negateDouble#" GenPrimOp Double# -> Double# -primop DoubleFabsOp "fabsDouble#" Monadic Double# -> Double# +primop DoubleFabsOp "fabsDouble#" GenPrimOp Double# -> Double# primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int# {Truncates a {\tt Double#} value to the nearest {\tt Int#}. @@ -795,96 +793,96 @@ primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int# primop Double2FloatOp "double2Float#" GenPrimOp Double# -> Float# -primop DoubleExpOp "expDouble#" Monadic +primop DoubleExpOp "expDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleExpM1Op "expm1Double#" Monadic +primop DoubleExpM1Op "expm1Double#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleLogOp "logDouble#" Monadic +primop DoubleLogOp "logDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop DoubleLog1POp "log1pDouble#" Monadic +primop DoubleLog1POp "log1pDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop DoubleSqrtOp "sqrtDouble#" Monadic +primop DoubleSqrtOp "sqrtDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleSinOp "sinDouble#" Monadic +primop DoubleSinOp "sinDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleCosOp "cosDouble#" Monadic +primop DoubleCosOp "cosDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleTanOp "tanDouble#" Monadic +primop DoubleTanOp "tanDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleAsinOp "asinDouble#" Monadic +primop DoubleAsinOp "asinDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop DoubleAcosOp "acosDouble#" Monadic +primop DoubleAcosOp "acosDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop DoubleAtanOp "atanDouble#" Monadic +primop DoubleAtanOp "atanDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleSinhOp "sinhDouble#" Monadic +primop DoubleSinhOp "sinhDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleCoshOp "coshDouble#" Monadic +primop DoubleCoshOp "coshDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleTanhOp "tanhDouble#" Monadic +primop DoubleTanhOp "tanhDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleAsinhOp "asinhDouble#" Monadic +primop DoubleAsinhOp "asinhDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleAcoshOp "acoshDouble#" Monadic +primop DoubleAcoshOp "acoshDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleAtanhOp "atanhDouble#" Monadic +primop DoubleAtanhOp "atanhDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoublePowerOp "**##" Dyadic +primop DoublePowerOp "**##" GenPrimOp Double# -> Double# -> Double# {Exponentiation.} with @@ -924,119 +922,119 @@ primop FloatNeOp "neFloat#" Compare primop FloatLtOp "ltFloat#" Compare Float# -> Float# -> Int# primop FloatLeOp "leFloat#" Compare Float# -> Float# -> Int# -primop FloatAddOp "plusFloat#" Dyadic +primop FloatAddOp "plusFloat#" GenPrimOp Float# -> Float# -> Float# with commutable = True -primop FloatSubOp "minusFloat#" Dyadic Float# -> Float# -> Float# +primop FloatSubOp "minusFloat#" GenPrimOp Float# -> Float# -> Float# -primop FloatMulOp "timesFloat#" Dyadic +primop FloatMulOp "timesFloat#" GenPrimOp Float# -> Float# -> Float# with commutable = True -primop FloatDivOp "divideFloat#" Dyadic +primop FloatDivOp "divideFloat#" GenPrimOp Float# -> Float# -> Float# with can_fail = True -primop FloatNegOp "negateFloat#" Monadic Float# -> Float# +primop FloatNegOp "negateFloat#" GenPrimOp Float# -> Float# -primop FloatFabsOp "fabsFloat#" Monadic Float# -> Float# +primop FloatFabsOp "fabsFloat#" GenPrimOp Float# -> Float# primop Float2IntOp "float2Int#" GenPrimOp Float# -> Int# {Truncates a {\tt Float#} value to the nearest {\tt Int#}. Results are undefined if the truncation if truncation yields a value outside the range of {\tt Int#}.} -primop FloatExpOp "expFloat#" Monadic +primop FloatExpOp "expFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatExpM1Op "expm1Float#" Monadic +primop FloatExpM1Op "expm1Float#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatLogOp "logFloat#" Monadic +primop FloatLogOp "logFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop FloatLog1POp "log1pFloat#" Monadic +primop FloatLog1POp "log1pFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop FloatSqrtOp "sqrtFloat#" Monadic +primop FloatSqrtOp "sqrtFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatSinOp "sinFloat#" Monadic +primop FloatSinOp "sinFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatCosOp "cosFloat#" Monadic +primop FloatCosOp "cosFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatTanOp "tanFloat#" Monadic +primop FloatTanOp "tanFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatAsinOp "asinFloat#" Monadic +primop FloatAsinOp "asinFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop FloatAcosOp "acosFloat#" Monadic +primop FloatAcosOp "acosFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop FloatAtanOp "atanFloat#" Monadic +primop FloatAtanOp "atanFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatSinhOp "sinhFloat#" Monadic +primop FloatSinhOp "sinhFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatCoshOp "coshFloat#" Monadic +primop FloatCoshOp "coshFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatTanhOp "tanhFloat#" Monadic +primop FloatTanhOp "tanhFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatAsinhOp "asinhFloat#" Monadic +primop FloatAsinhOp "asinhFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatAcoshOp "acoshFloat#" Monadic +primop FloatAcoshOp "acoshFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatAtanhOp "atanhFloat#" Monadic +primop FloatAtanhOp "atanhFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatPowerOp "powerFloat#" Dyadic +primop FloatPowerOp "powerFloat#" GenPrimOp Float# -> Float# -> Float# with code_size = { primOpCodeSizeForeignCall } @@ -3575,48 +3573,48 @@ primop VecInsertOp "insert#" GenPrimOp llvm_only = True vector = ALL_VECTOR_TYPES -primop VecAddOp "plus#" Dyadic +primop VecAddOp "plus#" GenPrimOp VECTOR -> VECTOR -> VECTOR { Add two vectors element-wise. } with commutable = True llvm_only = True vector = ALL_VECTOR_TYPES -primop VecSubOp "minus#" Dyadic +primop VecSubOp "minus#" GenPrimOp VECTOR -> VECTOR -> VECTOR { Subtract two vectors element-wise. } with llvm_only = True vector = ALL_VECTOR_TYPES -primop VecMulOp "times#" Dyadic +primop VecMulOp "times#" GenPrimOp VECTOR -> VECTOR -> VECTOR { Multiply two vectors element-wise. } with commutable = True llvm_only = True vector = ALL_VECTOR_TYPES -primop VecDivOp "divide#" Dyadic +primop VecDivOp "divide#" GenPrimOp VECTOR -> VECTOR -> VECTOR { Divide two vectors element-wise. } with can_fail = True llvm_only = True vector = FLOAT_VECTOR_TYPES -primop VecQuotOp "quot#" Dyadic +primop VecQuotOp "quot#" GenPrimOp VECTOR -> VECTOR -> VECTOR { Rounds towards zero element-wise. } with can_fail = True llvm_only = True vector = INT_VECTOR_TYPES -primop VecRemOp "rem#" Dyadic +primop VecRemOp "rem#" GenPrimOp VECTOR -> VECTOR -> VECTOR { Satisfies \texttt{(quot\# x y) times\# y plus\# (rem\# x y) == x}. } with can_fail = True llvm_only = True vector = INT_VECTOR_TYPES -primop VecNegOp "negate#" Monadic +primop VecNegOp "negate#" GenPrimOp VECTOR -> VECTOR { Negate element-wise. } with llvm_only = True ===================================== compiler/GHC/StgToCmm/Prim.hs ===================================== @@ -1,6 +1,5 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE LambdaCase #-} -{-# LANGUAGE MultiWayIf #-} #if __GLASGOW_HASKELL__ <= 808 -- GHC 8.10 deprecates this flag, but GHC 8.8 needs it @@ -1562,19 +1561,17 @@ emitPrimOp dflags primop = case primop of -> FCode ()) -> PrimopCmmEmit opIntoRegs f = PrimopCmmEmit_Internal $ \res_ty -> do - regs <- if - | ReturnsPrim VoidRep <- result_info - -> pure [] + regs <- case result_info of + ReturnsPrim VoidRep -> pure [] + ReturnsPrim rep + -> do reg <- newTemp (primRepCmmType platform rep) + pure [reg] - | ReturnsPrim rep <- result_info - -> do reg <- newTemp (primRepCmmType platform rep) - pure [reg] + ReturnsAlg tycon | isUnboxedTupleTyCon tycon + -> do (regs, _hints) <- newUnboxedTupleRegs res_ty + pure regs - | ReturnsAlg tycon <- result_info, isUnboxedTupleTyCon tycon - -> do (regs, _hints) <- newUnboxedTupleRegs res_ty - pure regs - - | otherwise -> panic "cgOpApp" + _ -> panic "cgOpApp" f regs pure $ map (CmmReg . CmmLocal) regs ===================================== utils/genprimopcode/Lexer.x ===================================== @@ -44,8 +44,6 @@ words :- <0> "defaults" { mkT TDefaults } <0> "True" { mkT TTrue } <0> "False" { mkT TFalse } - <0> "Dyadic" { mkT TDyadic } - <0> "Monadic" { mkT TMonadic } <0> "Compare" { mkT TCompare } <0> "GenPrimOp" { mkT TGenPrimOp } <0> "fixity" { mkT TFixity } ===================================== utils/genprimopcode/Main.hs ===================================== @@ -836,16 +836,6 @@ mkPOI_RHS_text i TyF t1 (TyF _ _) -> "mkCompare " ++ sl_name i ++ ppType t1 _ -> error "Type error in comparison op" - Monadic - -> case ty i of - TyF t1 _ - -> "mkMonadic " ++ sl_name i ++ ppType t1 - _ -> error "Type error in monadic op" - Dyadic - -> case ty i of - TyF t1 (TyF _ _) - -> "mkDyadic " ++ sl_name i ++ ppType t1 - _ -> error "Type error in dyadic op" GenPrimOp -> let (argTys, resTy) = flatTys (ty i) tvs = nub (tvsIn (ty i)) ===================================== utils/genprimopcode/Parser.y ===================================== @@ -36,8 +36,6 @@ import Syntax defaults { TDefaults } true { TTrue } false { TFalse } - dyadic { TDyadic } - monadic { TMonadic } compare { TCompare } genprimop { TGenPrimOp } fixity { TFixity } @@ -122,9 +120,7 @@ pWithOptions : with pOptions { $2 } | {- empty -} { [] } pCategory :: { Category } -pCategory : dyadic { Dyadic } - | monadic { Monadic } - | compare { Compare } +pCategory : compare { Compare } | genprimop { GenPrimOp } pDesc :: { String } ===================================== utils/genprimopcode/ParserM.hs ===================================== @@ -94,8 +94,6 @@ data Token = TEOF | TDefaults | TTrue | TFalse - | TDyadic - | TMonadic | TCompare | TGenPrimOp | TThatsAllFolks ===================================== utils/genprimopcode/Syntax.hs ===================================== @@ -65,7 +65,7 @@ data Option -- categorises primops data Category - = Dyadic | Monadic | Compare | GenPrimOp + = Compare | GenPrimOp deriving Show -- types @@ -155,10 +155,6 @@ sanityPrimOp def_names p sane_ty :: Category -> Ty -> Bool sane_ty Compare (TyF t1 (TyF t2 td)) | t1 == t2 && td == TyApp (TyCon "Int#") [] = True -sane_ty Monadic (TyF t1 td) - | t1 == td = True -sane_ty Dyadic (TyF t1 (TyF t2 td)) - | t1 == td && t2 == td = True sane_ty GenPrimOp _ = True sane_ty _ _ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/770100e0266750a313b34a52a60968410fcf0769 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/770100e0266750a313b34a52a60968410fcf0769 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 15:10:09 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Wed, 26 Aug 2020 11:10:09 -0400 Subject: [Git][ghc/ghc][wip/parsing-shift] 3 commits: Require happy >=1.20 Message-ID: <5f467b51825b1_80b3f8468ccd1d095759c1@gitlab.haskell.org.mail> Vladislav Zavialov pushed to branch wip/parsing-shift at Glasgow Haskell Compiler / GHC Commits: 44338dfc by Vladislav Zavialov at 2020-08-25T21:18:40+03:00 Require happy >=1.20 - - - - - 5bb141e9 by Vladislav Zavialov at 2020-08-25T23:19:01+03:00 Resolve shift/reduce conflicts with %shift (#17232) - - - - - 3d9297cd by Vladislav Zavialov at 2020-08-26T18:08:14+03:00 WIP: docs [ci skip] - - - - - 5 changed files: - .gitlab-ci.yml - aclocal.m4 - compiler/GHC/Parser.y - hadrian/cabal.project - hadrian/hadrian.cabal Changes: ===================================== .gitlab-ci.yml ===================================== @@ -2,7 +2,7 @@ variables: GIT_SSL_NO_VERIFY: "1" # Commit of ghc/ci-images repository from which to pull Docker images - DOCKER_REV: b65e1145d7c0a62c3533904a88dac14f56fb371b + DOCKER_REV: f408f461fcadcb6081a330f6570186425d99ade7 # Sequential version number capturing the versions of all tools fetched by # .gitlab/ci.sh. ===================================== aclocal.m4 ===================================== @@ -1021,8 +1021,8 @@ changequote([, ])dnl ]) if test ! -f compiler/GHC/Parser.hs || test ! -f compiler/GHC/Cmm/Parser.hs then - FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.19.10], - [AC_MSG_ERROR([Happy version 1.19.10 or later is required to compile GHC.])])[] + FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.20.0], + [AC_MSG_ERROR([Happy version 1.20.0 or later is required to compile GHC.])])[] fi HappyVersion=$fptools_cv_happy_version; AC_SUBST(HappyVersion) ===================================== compiler/GHC/Parser.y ===================================== @@ -95,27 +95,146 @@ import GHC.Builtin.Types ( unitTyCon, unitDataCon, tupleTyCon, tupleDataCon, nil manyDataConTyCon) } -%expect 232 -- shift/reduce conflicts +%expect 0 -- shift/reduce conflicts -{- Last updated: 08 June 2020 +{- Note [shift/reduce conflicts] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The 'happy' tool turns this grammar into an efficient parser that follows the +shift-reduce parsing model. There's a parse stack that contains items parsed so +far (both terminals and non-terminals). Every next token produced by the lexer +results in one of two actions: -If you modify this parser and add a conflict, please update this comment. -You can learn more about the conflicts by passing 'happy' the -i flag: + SHIFT: push the token onto the parse stack - happy -agc --strict compiler/GHC/Parser.y -idetailed-info + REDUCE: pop a few items off the parse stack and combine them + with a function (reduction rule) -How is this section formatted? Look up the state the conflict is -reported at, and copy the list of applicable rules (at the top, without the -rule numbers). Mark *** for the rule that is the conflicting reduction (that -is, the interpretation which is NOT taken). NB: Happy doesn't print a rule -in a state if it is empty, but you should include it in the list (you can -look these up in the Grammar section of the info file). +However, sometimes it's unclear which of the two actions to take. +Consider this code example: -Obviously the state numbers are not stable across modifications to the parser, -the idea is to reproduce enough information on each conflict so you can figure -out what happened if the states were renumbered. Try not to gratuitously move -productions around in this file. + if x then y else f z +There are two ways to parse it: + + (if x then y else f) z + if x then y else (f z) + +How is this determined? At some point, the parser gets to the following state: + + parse stack: 'if' exp 'then' exp 'else' "f" + next token: "z" + +Scenario A (simplified): + + 1. REDUCE, parse stack: 'if' exp 'then' exp 'else' exp + next token: "z" + + 2. REDUCE, parse stack: exp + next token: "z" + + 3. SHIFT, parse stack: exp "z" + next token: ... + + 4. REDUCE, parse stack: exp + next token: ... + + This way we get: (if x then y else f) z + +Scenario B (simplified): + + 1. SHIFT, parse stack: 'if' exp 'then' exp 'else' "f" "z" + next token: ... + + 2. REDUCE, parse stack: 'if' exp 'then' exp 'else' exp + next token: ... + + 3. REDUCE, parse stack: exp + next token: "z" + + This way we get: if x then y else (f z) + +The end result is determined by the chosen action. When Happy detects this, it +reports a shift/reduce conflict. At the top of the file, we have the following +directive: + + %expect 0 + +It means that we expect no unresolved shift/reduce conflicts in this grammar. +If you modify the grammar and get shift/reduce conflicts, follow the steps +below to resolve them. + +STEP ONE + is to figure out what causes the conflict. + That's where the -i flag comes in handy: + + happy -agc --strict compiler/GHC/Parser.y -idetailed-info + + By analysing the output of this command, you can figure out which reduction + rule causes the issue. At the top of the generated report, you will see a + line like this: + + state 147 contains 67 shift/reduce conflicts. + + Scroll down to section State 147 (in your case it could be a different + state). The start of the section lists the reduction rules that can fire + and shows their context: + + exp10 -> fexp . (rule 492) + fexp -> fexp . aexp (rule 498) + fexp -> fexp . PREFIX_AT atype (rule 499) + + And then, for every token, it tells you the parsing action: + + ']' reduce using rule 492 + '::' reduce using rule 492 + '(' shift, and enter state 178 + QVARID shift, and enter state 44 + DO shift, and enter state 182 + ... + + But if you look closer, some of these tokens also have another parsing action + in parentheses: + + QVARID shift, and enter state 44 + (reduce using rule 492) + + That's how you know rule 492 is causing trouble. + Scroll back to the top to see what this rule is: + + ---------------------------------- + Grammar + ---------------------------------- + ... + ... + exp10 -> fexp (492) + optSemi -> ';' (493) + ... + ... + + Hence the shift/reduce conflict is caused by this parser production: + + exp10 :: { ECP } + : '-' fexp { ... } + | fexp { ... } -- problematic rule + +STEP TWO + is to mark the problematic rule with the %shift pragma. This signals to + 'happy' that any shift/reduce conflicts involving this rule must be resolved + in favor of a shift. + +STEP THREE + is to add a dedicated Note for this specific conflict, as is done for all + other conflicts below. +-} + +{- Note [%shift: rule_activation -> {- empty -}] + +TODO (int-index) + +-} + + +{- ------------------------------------------------------------------------------- state 60 contains 1 shift/reduce conflict. @@ -1682,7 +1801,8 @@ rule :: { LRuleDecl GhcPs } -- Rules can be specified to be NeverActive, unlike inline/specialize pragmas rule_activation :: { ([AddAnn],Maybe Activation) } - : {- empty -} { ([],Nothing) } + -- See Note [%shift: rule_activation -> {- empty -}] + : {- empty -} %shift { ([],Nothing) } | rule_explicit_activation { (fst $1,Just (snd $1)) } -- This production is used to parse the tilde syntax in pragmas such as @@ -1718,9 +1838,12 @@ rule_foralls :: { ([AddAnn], Maybe [LHsTyVarBndr () GhcPs], [LRuleBndr GhcPs]) } >> return ([mu AnnForall $1,mj AnnDot $3, mu AnnForall $4,mj AnnDot $6], Just (mkRuleTyVarBndrs $2), mkRuleBndrs $5) } - | 'forall' rule_vars '.' { ([mu AnnForall $1,mj AnnDot $3], + + -- See Note [%shift: rule_foralls -> 'forall' rule_vars '.'] + | 'forall' rule_vars '.' %shift { ([mu AnnForall $1,mj AnnDot $3], Nothing, mkRuleBndrs $2) } - | {- empty -} { ([], Nothing, []) } + -- See Note [%shift: rule_foralls -> {- empty -}] + | {- empty -} %shift { ([], Nothing, []) } rule_vars :: { [LRuleTyTmVar] } : rule_var rule_vars { $1 : $2 } @@ -1954,7 +2077,8 @@ is connected to the first type too. -} type :: { LHsType GhcPs } - : btype { $1 } + -- See Note [%shift: type -> btype] + : btype %shift { $1 } | btype '->' ctype {% ams $1 [mu AnnRarrow $2] -- See note [GADT decl discards annotations] >> ams (sLL $1 $> $ HsFunTy noExtField HsUnrestrictedArrow $1 $3) [mu AnnRarrow $2] } @@ -1970,7 +2094,8 @@ btype :: { LHsType GhcPs } : infixtype {% runPV $1 } infixtype :: { forall b. DisambTD b => PV (Located b) } - : ftype { $1 } + -- See Note [%shift: infixtype -> ftype] + : ftype %shift { $1 } | ftype tyop infixtype { $1 >>= \ $1 -> $3 >>= \ $3 -> mkHsOpTyPV $1 $2 $3 } @@ -1999,7 +2124,8 @@ tyop :: { Located RdrName } atype :: { LHsType GhcPs } : ntgtycon { sL1 $1 (HsTyVar noExtField NotPromoted $1) } -- Not including unit tuples - | tyvar { sL1 $1 (HsTyVar noExtField NotPromoted $1) } -- (See Note [Unit tuples]) + -- See Note [%shift: atype -> tyvar] + | tyvar %shift { sL1 $1 (HsTyVar noExtField NotPromoted $1) } -- (See Note [Unit tuples]) | '*' {% do { warnStarIsType (getLoc $1) ; return $ sL1 $1 (HsStarTy noExtField (isUnicode $1)) } } @@ -2485,7 +2611,8 @@ exp :: { ECP } ams (sLL $1 $> $ HsCmdArrApp noExtField $3 $1 HsHigherOrderApp False) [mu AnnRarrowtail $2] } - | infixexp { $1 } + -- See Note [%shift: exp -> infixexp] + | infixexp %shift { $1 } | exp_prag(exp) { $1 } -- See Note [Pragmas and operator fixity] infixexp :: { ECP } @@ -2513,11 +2640,13 @@ exp_prag(e) :: { ECP } (fst $ unLoc $1) } exp10 :: { ECP } - : '-' fexp { ECP $ + -- See Note [%shift: exp10 -> '-' fexp] + : '-' fexp %shift { ECP $ unECP $2 >>= \ $2 -> amms (mkHsNegAppPV (comb2 $1 $>) $2) [mj AnnMinus $1] } - | fexp { $1 } + -- See Note [%shift: exp10 -> fexp] + | fexp %shift { $1 } optSemi :: { ([Located Token],Bool) } : ';' { ([$1],True) } @@ -2708,7 +2837,8 @@ aexp1 :: { ECP } aexp2 :: { ECP } : qvar { ECP $ mkHsVarPV $! $1 } | qcon { ECP $ mkHsVarPV $! $1 } - | ipvar { ecpFromExp $ sL1 $1 (HsIPVar noExtField $! unLoc $1) } + -- See Note [%shift: aexp2 -> ipvar] + | ipvar %shift { ecpFromExp $ sL1 $1 (HsIPVar noExtField $! unLoc $1) } | overloaded_label { ecpFromExp $ sL1 $1 (HsOverLabel noExtField Nothing $! unLoc $1) } | literal { ECP $ mkHsLitPV $! $1 } -- This will enable overloaded strings permanently. Normally the renamer turns HsString @@ -2750,7 +2880,8 @@ aexp2 :: { ECP } | SIMPLEQUOTE qcon {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField True (unLoc $2))) [mj AnnSimpleQuote $1,mj AnnName $2] } | TH_TY_QUOTE tyvar {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } | TH_TY_QUOTE gtycon {% fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (VarBr noExtField False (unLoc $2))) [mj AnnThTyQuote $1,mj AnnName $2] } - | TH_TY_QUOTE {- nothing -} {% reportEmptyDoubleQuotes (getLoc $1) } + -- See Note [%shift: aexp2 -> TH_TY_QUOTE] + | TH_TY_QUOTE %shift {% reportEmptyDoubleQuotes (getLoc $1) } | '[|' exp '|]' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromExp $ ams (sLL $1 $> $ HsBracket noExtField (ExpBr noExtField $2)) @@ -2892,7 +3023,8 @@ tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] } return ((L (gl $1) (Just $1)) : snd $2) } | texp { unECP $1 >>= \ $1 -> return [L (gl $1) (Just $1)] } - | {- empty -} { return [noLoc Nothing] } + -- See Note [%shift: tup_tail -> {- empty -}] + | {- empty -} %shift { return [noLoc Nothing] } ----------------------------------------------------------------------------- -- List expressions @@ -3403,7 +3535,8 @@ child. -} qtyconop :: { Located RdrName } -- Qualified or unqualified - : qtyconsym { $1 } + -- See Note [%shift: qtyconop -> qtyconsym] + : qtyconsym %shift { $1 } | '`' qtycon '`' {% ams (sLL $1 $> (unLoc $2)) [mj AnnBackquote $1,mj AnnVal $2 ,mj AnnBackquote $3] } @@ -3570,7 +3703,8 @@ special_id | 'capi' { sL1 $1 (fsLit "capi") } | 'prim' { sL1 $1 (fsLit "prim") } | 'javascript' { sL1 $1 (fsLit "javascript") } - | 'group' { sL1 $1 (fsLit "group") } + -- See Note [%shift: special_id -> 'group'] + | 'group' %shift { sL1 $1 (fsLit "group") } | 'stock' { sL1 $1 (fsLit "stock") } | 'anyclass' { sL1 $1 (fsLit "anyclass") } | 'via' { sL1 $1 (fsLit "via") } ===================================== hadrian/cabal.project ===================================== @@ -1,7 +1,7 @@ packages: ./ -- This essentially freezes the build plan for hadrian -index-state: 2020-06-16T03:59:14Z +index-state: 2020-08-25T12:30:13Z -- N.B. Compile with -O0 since this is not a performance-critical executable -- and the Cabal takes nearly twice as long to build with -O1. See #16817. ===================================== hadrian/hadrian.cabal ===================================== @@ -148,7 +148,7 @@ executable hadrian , transformers >= 0.4 && < 0.6 , unordered-containers >= 0.2.1 && < 0.3 build-tools: alex >= 3.1 - , happy >= 1.19.10 + , happy >= 1.20.0 ghc-options: -Wall -Wincomplete-record-updates -Wredundant-constraints View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/81f6b2e28d2626529dc46291b1d3a2bbbbdde11c...3d9297cd4525a2b0b8000580eaf26964cd0fabdc -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/81f6b2e28d2626529dc46291b1d3a2bbbbdde11c...3d9297cd4525a2b0b8000580eaf26964cd0fabdc You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 15:23:07 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Wed, 26 Aug 2020 11:23:07 -0400 Subject: [Git][ghc/ghc][wip/happy-1.20] Require happy >=1.20 Message-ID: <5f467e5b3ece7_80b3f8492437b54958068c@gitlab.haskell.org.mail> Vladislav Zavialov pushed to branch wip/happy-1.20 at Glasgow Haskell Compiler / GHC Commits: c8b84815 by Vladislav Zavialov at 2020-08-26T18:20:44+03:00 Require happy >=1.20 - - - - - 5 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - aclocal.m4 - hadrian/cabal.project - hadrian/hadrian.cabal Changes: ===================================== .gitlab-ci.yml ===================================== @@ -2,7 +2,7 @@ variables: GIT_SSL_NO_VERIFY: "1" # Commit of ghc/ci-images repository from which to pull Docker images - DOCKER_REV: b65e1145d7c0a62c3533904a88dac14f56fb371b + DOCKER_REV: f408f461fcadcb6081a330f6570186425d99ade7 # Sequential version number capturing the versions of all tools fetched by # .gitlab/ci.sh. ===================================== .gitlab/ci.sh ===================================== @@ -6,7 +6,7 @@ set -e -o pipefail # Configuration: -hackage_index_state="@1579718451" +hackage_index_state="2020-08-25T12:30:13Z" # Colors BLACK="0;30" ===================================== aclocal.m4 ===================================== @@ -1021,8 +1021,8 @@ changequote([, ])dnl ]) if test ! -f compiler/GHC/Parser.hs || test ! -f compiler/GHC/Cmm/Parser.hs then - FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.19.10], - [AC_MSG_ERROR([Happy version 1.19.10 or later is required to compile GHC.])])[] + FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.20.0], + [AC_MSG_ERROR([Happy version 1.20.0 or later is required to compile GHC.])])[] fi HappyVersion=$fptools_cv_happy_version; AC_SUBST(HappyVersion) ===================================== hadrian/cabal.project ===================================== @@ -1,7 +1,7 @@ packages: ./ -- This essentially freezes the build plan for hadrian -index-state: 2020-06-16T03:59:14Z +index-state: 2020-08-25T12:30:13Z -- N.B. Compile with -O0 since this is not a performance-critical executable -- and the Cabal takes nearly twice as long to build with -O1. See #16817. ===================================== hadrian/hadrian.cabal ===================================== @@ -148,7 +148,7 @@ executable hadrian , transformers >= 0.4 && < 0.6 , unordered-containers >= 0.2.1 && < 0.3 build-tools: alex >= 3.1 - , happy >= 1.19.10 + , happy >= 1.20.0 ghc-options: -Wall -Wincomplete-record-updates -Wredundant-constraints View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c8b84815a4448008c6857f8982fba22ede41650c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c8b84815a4448008c6857f8982fba22ede41650c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 15:31:58 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Wed, 26 Aug 2020 11:31:58 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] Remove unsave function (#18405) Message-ID: <5f46806e8a88e_80b3f8468ccd1d09585549@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: 335cd211 by Sven Tennie at 2020-08-26T17:31:44+02:00 Remove unsave function (#18405) heap_view_closurePtrsAsWords is currently only used by ghc-debug, so it can be defined there. - - - - - 2 changed files: - includes/rts/storage/Heap.h - rts/Heap.c Changes: ===================================== includes/rts/storage/Heap.h ===================================== @@ -11,9 +11,10 @@ #include "rts/storage/Closures.h" StgMutArrPtrs *heap_view_closurePtrs(Capability *cap, StgClosure *closure); -StgArrBytes *heap_view_closurePtrsAsWords(Capability *cap, StgClosure *closure); void heap_view_closure_ptrs_in_pap_payload(StgClosure *ptrs[], StgWord *nptrs , StgClosure *fun, StgClosure **payload, StgWord size); StgWord heap_view_closureSize(StgClosure *closure); + +StgWord collect_pointers(StgClosure *closure, StgWord size, StgClosure *ptrs[]); ===================================== rts/Heap.c ===================================== @@ -80,7 +80,7 @@ void heap_view_closure_ptrs_in_pap_payload(StgClosure *ptrs[], StgWord *nptrs * Collect the pointers of a closure into the given array. size should be * heap_view_closureSize(closure). Returns the number of pointers collected. */ -static StgWord collect_pointers(StgClosure *closure, StgWord size, StgClosure *ptrs[size]) { +StgWord collect_pointers(StgClosure *closure, StgWord size, StgClosure *ptrs[size]) { StgClosure **end; const StgInfoTable *info = get_itbl(closure); StgWord nptrs = 0; @@ -246,37 +246,6 @@ static StgWord collect_pointers(StgClosure *closure, StgWord size, StgClosure *p return nptrs; } -StgArrBytes *heap_view_closurePtrsAsWords(Capability *cap, StgClosure *closure) { - if(!rts_isPaused()){ - errorBelch("Warning: " - "The RTS must be paused (see rts_pause()) to inspect it's heap!"); - - return NULL; - } - - ASSERT(LOOKS_LIKE_CLOSURE_PTR(closure)); - - StgWord size = heap_view_closureSize(closure); - - // First collect all pointers here, with the comfortable memory bound - // of the whole closure. Afterwards we know how many pointers are in - // the closure and then we can allocate space on the heap and copy them - // there - StgClosure *ptrs[size]; - StgWord nptrs = collect_pointers(closure, size, ptrs); - StgArrBytes *arr = - (StgArrBytes *)allocate(cap, sizeofW(StgArrBytes) + nptrs); - TICK_ALLOC_PRIM(sizeofW(StgArrBytes), nptrs, 0); - SET_HDR(arr, &stg_ARR_WORDS_info, cap->r.rCCCS); - arr->bytes = sizeof(StgWord) * nptrs; - - for (StgWord i = 0; ipayload[i] = (StgWord)ptrs[i]; - } - - return arr; -} - StgMutArrPtrs *heap_view_closurePtrs(Capability *cap, StgClosure *closure) { ASSERT(LOOKS_LIKE_CLOSURE_PTR(closure)); View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/335cd21124f7c3ace718b16ab046b20a077ad44f -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/335cd21124f7c3ace718b16ab046b20a077ad44f You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 15:33:05 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Wed, 26 Aug 2020 11:33:05 -0400 Subject: [Git][ghc/ghc][wip/T18223] Better eta-expansion (again) and don't specilise DFuns Message-ID: <5f4680b1e70b0_80b3f8492437b549587688@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18223 at Glasgow Haskell Compiler / GHC Commits: 3bf9cde7 by Simon Peyton Jones at 2020-08-26T16:31:29+01:00 Better eta-expansion (again) and don't specilise DFuns This patch fixes #18223, which made GHC generate an exponential amount of code. There are three quite separate changes in here 1. Re-engineer eta-expansion (again). The eta-expander was generating lots of intermediate stuff, which could be optimised away, but which choked the simplifier meanwhile. Relatively easy to kill it off at source. See Note [The EtaInfo mechanism] in GHC.Core.Opt.Arity. The main new thing is the use of pushCoArg in getArg_maybe. 2. Stop Specialise specalising DFuns. This is the cause of a huge (and utterly unnecessary) blowup in program size in #18223. See Note [Do not specialise DFuns] in GHC.Core.Opt.Specialise. I also refactored the Specialise monad a bit... it was silly, because it passed on unchanging values as if they were mutable state. 3. Do an extra Simplifer run, after SpecConstra and before late-Specialise. I found (investigating perf/compiler/T16473) that failing to do this was crippling *both* SpecConstr *and* Specialise. See Note [Simplify after SpecConstr] in GHC.Core.Opt.Pipeline. This change does mean an extra run of the Simplifier, but only with -O2, and I think that's acceptable. T16473 allocates *three* times less with this change. (I changed it to check runtime rather than compile time.) Some smaller consequences * I moved pushCoercion, pushCoArg and friends from SimpleOpt to Arity, because it was needed by the new etaInfoApp. And pushCoValArg now returns a MCoercion rather than Coercion for the argument Coercion. * A minor, incidental improvement to Core pretty-printing This does fix #18223, (which was otherwise uncompilable. Hooray. But there is still a big intermediate because there are some very deeply nested types in that program. Modest reductions in compile-time allocation on a couple of benchmarks T12425 -2.0% T13253 -10.3% Metric increase with -O2, due to extra simplifier run T9233 +5.8% T12227 +1.8% T15630 +5.0% There is a spurious apparent increase on heap residency on T9630, on some architectures at least. I tried it with -G1 and the residency is essentially unchanged. Metric Increase T9233 T12227 T9630 Metric Decrease T12425 T13253 - - - - - 16 changed files: - compiler/GHC/Core/Coercion.hs - compiler/GHC/Core/Opt/Arity.hs - compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Core/Opt/Simplify.hs - compiler/GHC/Core/Opt/Simplify/Env.hs - compiler/GHC/Core/Opt/Specialise.hs - compiler/GHC/Core/Ppr.hs - compiler/GHC/Core/SimpleOpt.hs - compiler/GHC/Core/Subst.hs - testsuite/tests/perf/compiler/Makefile - testsuite/tests/perf/compiler/T16473.stdout - + testsuite/tests/perf/compiler/T18223.hs - testsuite/tests/perf/compiler/all.T - testsuite/tests/printer/T18052a.stderr - testsuite/tests/simplCore/should_compile/T17966.stdout - testsuite/tests/stranal/should_compile/T18122.stderr Changes: ===================================== compiler/GHC/Core/Coercion.hs ===================================== @@ -31,7 +31,7 @@ module GHC.Core.Coercion ( mkAxInstRHS, mkUnbranchedAxInstRHS, mkAxInstLHS, mkUnbranchedAxInstLHS, mkPiCo, mkPiCos, mkCoCast, - mkSymCo, mkTransCo, mkTransMCo, + mkSymCo, mkTransCo, mkNthCo, nthCoRole, mkLRCo, mkInstCo, mkAppCo, mkAppCos, mkTyConAppCo, mkFunCo, mkForAllCo, mkForAllCos, mkHomoForAllCos, @@ -65,7 +65,8 @@ module GHC.Core.Coercion ( pickLR, isGReflCo, isReflCo, isReflCo_maybe, isGReflCo_maybe, isReflexiveCo, isReflexiveCo_maybe, - isReflCoVar_maybe, isGReflMCo, coToMCo, + isReflCoVar_maybe, isGReflMCo, + coToMCo, mkTransMCo, mkTransMCoL, -- ** Coercion variables mkCoVar, isCoVar, coVarName, setCoVarName, setCoVarUnique, @@ -288,6 +289,44 @@ tidyCoAxBndrsForUser init_env tcvs ('_' : rest) -> all isDigit rest _ -> False + +{- ********************************************************************* +* * + MCoercion +* * +********************************************************************* -} + +coToMCo :: Coercion -> MCoercion +-- Convert a coercion to a MCoercion, +-- It's not clear whether or not isReflexiveCo would be better here +coToMCo co | isReflCo co = MRefl + | otherwise = MCo co + +-- | Tests if this MCoercion is obviously generalized reflexive +-- Guaranteed to work very quickly. +isGReflMCo :: MCoercion -> Bool +isGReflMCo MRefl = True +isGReflMCo (MCo co) | isGReflCo co = True +isGReflMCo _ = False + +-- | Make a generalized reflexive coercion +mkGReflCo :: Role -> Type -> MCoercionN -> Coercion +mkGReflCo r ty mco + | isGReflMCo mco = if r == Nominal then Refl ty + else GRefl r ty MRefl + | otherwise = GRefl r ty mco + +-- | Compose two MCoercions via transitivity +mkTransMCo :: MCoercion -> MCoercion -> MCoercion +mkTransMCo MRefl co2 = co2 +mkTransMCo co1 MRefl = co1 +mkTransMCo (MCo co1) (MCo co2) = MCo (mkTransCo co1 co2) + +mkTransMCoL :: MCoercion -> Coercion -> MCoercion +mkTransMCoL MRefl co2 = MCo co2 +mkTransMCoL (MCo co1) co2 = MCo (mkTransCo co1 co2) + + {- %************************************************************************ %* * @@ -556,13 +595,6 @@ isGReflCo (GRefl{}) = True isGReflCo (Refl{}) = True -- Refl ty == GRefl N ty MRefl isGReflCo _ = False --- | Tests if this MCoercion is obviously generalized reflexive --- Guaranteed to work very quickly. -isGReflMCo :: MCoercion -> Bool -isGReflMCo MRefl = True -isGReflMCo (MCo co) | isGReflCo co = True -isGReflMCo _ = False - -- | Tests if this coercion is obviously reflexive. Guaranteed to work -- very quickly. Sometimes a coercion can be reflexive, but not obviously -- so. c.f. 'isReflexiveCo' @@ -603,10 +635,6 @@ isReflexiveCo_maybe co = Nothing where (Pair ty1 ty2, r) = coercionKindRole co -coToMCo :: Coercion -> MCoercion -coToMCo c = if isReflCo c - then MRefl - else MCo c {- %************************************************************************ @@ -669,13 +697,6 @@ role is bizarre and a caller should have to ask for this behavior explicitly. -} --- | Make a generalized reflexive coercion -mkGReflCo :: Role -> Type -> MCoercionN -> Coercion -mkGReflCo r ty mco - | isGReflMCo mco = if r == Nominal then Refl ty - else GRefl r ty MRefl - | otherwise = GRefl r ty mco - -- | Make a reflexive coercion mkReflCo :: Role -> Type -> Coercion mkReflCo Nominal ty = Refl ty @@ -990,12 +1011,6 @@ mkTransCo (GRefl r t1 (MCo co1)) (GRefl _ _ (MCo co2)) = GRefl r t1 (MCo $ mkTransCo co1 co2) mkTransCo co1 co2 = TransCo co1 co2 --- | Compose two MCoercions via transitivity -mkTransMCo :: MCoercion -> MCoercion -> MCoercion -mkTransMCo MRefl co2 = co2 -mkTransMCo co1 MRefl = co1 -mkTransMCo (MCo co1) (MCo co2) = MCo (mkTransCo co1 co2) - mkNthCo :: HasDebugCallStack => Role -- The role of the coercion you're creating -> Int -- Zero-indexed ===================================== compiler/GHC/Core/Opt/Arity.hs ===================================== @@ -15,10 +15,18 @@ module GHC.Core.Opt.Arity ( manifestArity, joinRhsArity, exprArity, typeArity , exprEtaExpandArity, findRhsArity , etaExpand, etaExpandAT - , etaExpandToJoinPoint, etaExpandToJoinPointRule , exprBotStrictness_maybe + + -- ** ArityType , ArityType(..), expandableArityType, arityTypeArity , maxWithArity, isBotArityType, idArityType + + -- ** Join points + , etaExpandToJoinPoint, etaExpandToJoinPointRule + + -- ** Coercions and casts + , pushCoArg, pushCoArgs, pushCoValArg, pushCoTyArg + , pushCoercionIntoLambda, pushCoDataCon, collectBindersPushingCo ) where @@ -31,15 +39,21 @@ import GHC.Driver.Ppr import GHC.Core import GHC.Core.FVs import GHC.Core.Utils -import GHC.Core.Subst import GHC.Types.Demand import GHC.Types.Var import GHC.Types.Var.Env import GHC.Types.Id -import GHC.Core.Type as Type -import GHC.Core.TyCon ( initRecTc, checkRecTc ) + +-- We have two sorts of substitution: +-- GHC.Core.Subst.Subst, and GHC.Core.TyCo.TCvSubst +-- Both have substTy, substCo Hence need for qualification +import GHC.Core.Subst as Core +import GHC.Core.Type as Type +import GHC.Core.Coercion as Type + +import GHC.Core.DataCon +import GHC.Core.TyCon ( initRecTc, checkRecTc, tyConArity ) import GHC.Core.Predicate ( isDictTy ) -import GHC.Core.Coercion as Coercion import GHC.Core.Multiplicity import GHC.Types.Var.Set import GHC.Types.Basic @@ -48,7 +62,8 @@ import GHC.Driver.Session ( DynFlags, GeneralFlag(..), gopt ) import GHC.Utils.Outputable import GHC.Utils.Panic import GHC.Data.FastString -import GHC.Utils.Misc ( lengthAtLeast ) +import GHC.Data.Pair +import GHC.Utils.Misc {- ************************************************************************ @@ -1076,12 +1091,11 @@ eta_expand one_shots orig_expr go oss (Cast expr co) = Cast (go oss expr) co go oss expr - = -- pprTrace "ee" (vcat [ppr orig_expr, ppr expr, ppr etas]) $ - retick $ etaInfoAbs etas (etaInfoApp subst' sexpr etas) + = -- pprTrace "ee" (vcat [ppr orig_expr, ppr expr, pprEtaInfos etas]) $ + retick $ etaInfoAbs etas (etaInfoApp in_scope' sexpr etas) where in_scope = mkInScopeSet (exprFreeVars expr) (in_scope', etas) = mkEtaWW oss (ppr orig_expr) in_scope (exprType expr) - subst' = mkEmptySubst in_scope' -- Find ticks behind type apps. -- See Note [Eta expansion and source notes] @@ -1090,76 +1104,191 @@ eta_expand one_shots orig_expr sexpr = foldl' App expr'' args retick expr = foldr mkTick expr ticks - -- Abstraction Application +{- ********************************************************************* +* * + The EtaInfo mechanism + mkEtaWW, etaInfoAbs, etaInfoApp +* * +********************************************************************* -} + +{- Note [The EtaInfo mechanism] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Suppose we have (e :: ty) and we want to eta-expand it to arity N. +This what eta_expand does. We do it in two steps: + +1. mkEtaWW: from 'ty' and 'N' build a [EtaInfo] which describes + the shape of the expansion necessary to expand to arity N. + +2. Build the term + \ v1..vn. e v1 .. vn + where those abstractions and applications are described by + the same [EtaInfo]. Specifically we build the term + + etaInfoAbs etas (etaInfoApp in_scope e etas) + + where etas :: [EtaInfo]# + etaInfoAbs builds the lambdas + etaInfoApp builds the applictions + + Note that the /same/ [EtaInfo] drives both etaInfoAbs and etaInfoApp + +To a first approximation [EtaInfo] is just [Var]. But +casts complicate the question. If we have + newtype N a = MkN (S -> a) +and + ty = N (N Int) +then the eta-expansion must look like + (\x (\y. ((e |> co1) x) |> co2) y) + |> sym co2) + |> sym co1 +where + co1 :: N (N Int) ~ S -> N Int + co2 :: N Int ~ S -> Int + +Blimey! Look at all those casts. Moreover, if the type +is very deeply nested (as happens in #18223), the repetition +of types can make the overall term very large. So there is a big +payoff in cancelling out casts aggressively wherever possible. +(See also Note [No crap in eta-expanded code].) + +This matters a lot in etaEInfoApp, where we +* Do beta-reduction on the fly +* Use getARg_mabye to get a cast out of the way, + so that we can do beta reduction +Together this makes a big difference. Consider when e is + case x of + True -> (\x -> e1) |> c1 + False -> (\p -> e2) |> c2 + +When we eta-expand this to arity 1, say, etaInfoAbs will wrap +a (\eta) around the outside and use etaInfoApp to apply each +alternative to 'eta'. We want to beta-reduce all that junk +away. + +#18223 was a dramtic example in which the intermediate term was +grotesquely huge, even though the next Simplifier iteration squashed +it. Better to kill it at birth. +-} + -------------- -data EtaInfo = EtaVar Var -- /\a. [] [] a - -- \x. [] [] x - | EtaCo Coercion -- [] |> sym co [] |> co +data EtaInfo -- Abstraction Application + = EtaVar Var -- /\a. [] [] a + -- (\x. []) [] x + | EtaCo CoercionR -- [] |> sym co [] |> co instance Outputable EtaInfo where - ppr (EtaVar v) = text "EtaVar" <+> ppr v - ppr (EtaCo co) = text "EtaCo" <+> ppr co + ppr (EtaVar v) = text "EtaVar" <+> ppr v <+> dcolon <+> ppr (idType v) + ppr (EtaCo co) = text "EtaCo" <+> hang (ppr co) 2 (dcolon <+> ppr (coercionType co)) + +-- Used in debug-printing +-- pprEtaInfos :: [EtaInfo] -> SDoc +-- pprEtaInfos eis = brackets $ vcat $ punctuate comma $ map ppr eis pushCoercion :: Coercion -> [EtaInfo] -> [EtaInfo] +-- Puts a EtaCo on the front of a [EtaInfo], but combining +-- with an existing EtaCo if possible +-- A minor improvement pushCoercion co1 (EtaCo co2 : eis) | isReflCo co = eis | otherwise = EtaCo co : eis where co = co1 `mkTransCo` co2 -pushCoercion co eis = EtaCo co : eis +pushCoercion co eis + = EtaCo co : eis + +getArg_maybe :: [EtaInfo] -> Maybe (CoreArg, [EtaInfo]) +-- Get an argument to the front of the [EtaInfo], if possible, +-- by pushing any EtaCo through the argument +getArg_maybe eis = go MRefl eis + where + go :: MCoercion -> [EtaInfo] -> Maybe (CoreArg, [EtaInfo]) + go _ [] = Nothing + go mco (EtaCo co2 : eis) = go (mkTransMCoL mco co2) eis + go MRefl (EtaVar v : eis) = Just (varToCoreExpr v, eis) + go (MCo co) (EtaVar v : eis) + | Just (arg, mco) <- pushCoArg co (varToCoreExpr v) + = case mco of + MRefl -> Just (arg, eis) + MCo co -> Just (arg, pushCoercion co eis) + | otherwise + = Nothing + +mkCastMCo :: CoreExpr -> MCoercionR -> CoreExpr +mkCastMCo e MRefl = e +mkCastMCo e (MCo co) = Cast e co + +mkPiMCo :: Var -> MCoercionR -> MCoercionR +mkPiMCo _ MRefl = MRefl +mkPiMCo v (MCo co) = MCo (mkPiCo Representational v co) -------------- etaInfoAbs :: [EtaInfo] -> CoreExpr -> CoreExpr -etaInfoAbs [] expr = expr -etaInfoAbs (EtaVar v : eis) expr = Lam v (etaInfoAbs eis expr) -etaInfoAbs (EtaCo co : eis) expr = Cast (etaInfoAbs eis expr) (mkSymCo co) +etaInfoAbs eis expr + | null eis = expr + | otherwise = case final_mco of + MRefl -> expr' + MCo co -> mkCast expr' co + where + (expr', final_mco) = foldr do_one (split_cast expr) eis + + do_one :: EtaInfo -> (CoreExpr, MCoercion) -> (CoreExpr, MCoercion) + do_one (EtaVar v) (expr, mco) = (Lam v expr, mkPiMCo v mco) + do_one (EtaCo co) (expr, mco) = (expr, mco `mkTransMCoL` mkSymCo co) + + split_cast :: CoreExpr -> (CoreExpr, MCoercion) + split_cast (Cast e co) = (e, MCo co) + split_cast e = (e, MRefl) + -- We could look in the body of lets, and the branches of a case + -- But then we would have to worry about whether the cast mentioned + -- any of the bound variables, which is tiresome. Later maybe. + -- Result: we may end up with + -- (\(x::Int). case x of { DEFAULT -> e1 |> co }) |> sym (->co) + -- and fail to optimise it away -------------- -etaInfoApp :: Subst -> CoreExpr -> [EtaInfo] -> CoreExpr +etaInfoApp :: InScopeSet -> CoreExpr -> [EtaInfo] -> CoreExpr -- (etaInfoApp s e eis) returns something equivalent to --- ((substExpr s e) `appliedto` eis) - -etaInfoApp subst (Lam v1 e) (EtaVar v2 : eis) - = etaInfoApp (GHC.Core.Subst.extendSubstWithVar subst v1 v2) e eis - -etaInfoApp subst (Cast e co1) eis - = etaInfoApp subst e (pushCoercion co' eis) - where - co' = GHC.Core.Subst.substCo subst co1 +-- (substExpr s e `appliedto` eis) -etaInfoApp subst (Case e b ty alts) eis - = Case (subst_expr subst e) b1 ty' alts' +etaInfoApp in_scope expr eis + = go (mkEmptySubst in_scope) expr eis where - (subst1, b1) = substBndr subst b - alts' = map subst_alt alts - ty' = etaInfoAppTy (GHC.Core.Subst.substTy subst ty) eis - subst_alt (con, bs, rhs) = (con, bs', etaInfoApp subst2 rhs eis) - where - (subst2,bs') = substBndrs subst1 bs - -etaInfoApp subst (Let b e) eis - | not (isJoinBind b) - -- See Note [Eta expansion for join points] - = Let b' (etaInfoApp subst' e eis) - where - (subst', b') = substBindSC subst b + go :: Subst -> CoreExpr -> [EtaInfo] -> CoreExpr + -- 'go' pushed down the eta-infos into the branch of a case + -- and the body of a let; and does beta-reduction if possible + go subst (Tick t e) eis + = Tick (substTickish subst t) (go subst e eis) + go subst (Cast e co) eis + = go subst e (pushCoercion (Core.substCo subst co) eis) + go subst (Case e b ty alts) eis + = Case (Core.substExprSC subst e) b1 ty' alts' + where + (subst1, b1) = Core.substBndr subst b + alts' = map subst_alt alts + ty' = etaInfoAppTy (Core.substTy subst ty) eis + subst_alt (con, bs, rhs) = (con, bs', go subst2 rhs eis) + where + (subst2,bs') = Core.substBndrs subst1 bs + go subst (Let b e) eis + | not (isJoinBind b) -- See Note [Eta expansion for join points] + = Let b' (go subst' e eis) + where + (subst', b') = Core.substBindSC subst b -etaInfoApp subst (Tick t e) eis - = Tick (substTickish subst t) (etaInfoApp subst e eis) + -- Beta-reduction if possible, using getArg_maybe to push + -- any intervening casts past the argument + -- See Note [The EtaInfo mechansim] + go subst (Lam v e) eis + | Just (arg, eis') <- getArg_maybe eis + = go (Core.extendSubst subst v arg) e eis' -etaInfoApp subst expr _ - | (Var fun, _) <- collectArgs expr - , Var fun' <- lookupIdSubst subst fun - , isJoinId fun' - = subst_expr subst expr + -- Stop pushing down; just wrap the expression up + go subst e eis = wrap (Core.substExprSC subst e) eis -etaInfoApp subst e eis - = go (subst_expr subst e) eis - where - go e [] = e - go e (EtaVar v : eis) = go (App e (varToCoreExpr v)) eis - go e (EtaCo co : eis) = go (Cast e co) eis + wrap e [] = e + wrap e (EtaVar v : eis) = wrap (App e (varToCoreExpr v)) eis + wrap e (EtaCo co : eis) = wrap (Cast e co) eis -------------- @@ -1235,7 +1364,7 @@ mkEtaWW orig_oss ppr_orig_expr in_scope orig_ty -- We want to get -- coerce T (\x::[T] -> (coerce ([T]->Int) e) x) | Just (co, ty') <- topNormaliseNewType_maybe ty - , let co' = Coercion.substCo subst co + , let co' = Type.substCo subst co -- Remember to apply the substitution to co (#16979) -- (or we could have applied to ty, but then -- we'd have had to zap it for the recursive call) @@ -1253,21 +1382,290 @@ mkEtaWW orig_oss ppr_orig_expr in_scope orig_ty -- with an explicit lambda having a non-function type +{- ********************************************************************* +* * + The "push rules" +* * +************************************************************************ ------------- -subst_expr :: Subst -> CoreExpr -> CoreExpr --- Apply a substitution to an expression. We use substExpr --- not substExprSC (short-cutting substitution) because --- we may be changing the types of join points, so applying --- the in-scope set is necessary. +Here we implement the "push rules" from FC papers: + +* The push-argument rules, where we can move a coercion past an argument. + We have + (fun |> co) arg + and we want to transform it to + (fun arg') |> co' + for some suitable co' and transformed arg'. + +* The PushK rule for data constructors. We have + (K e1 .. en) |> co + and we want to transform to + (K e1' .. en') + by pushing the coercion into the arguments +-} + +pushCoArgs :: CoercionR -> [CoreArg] -> Maybe ([CoreArg], MCoercion) +pushCoArgs co [] = return ([], MCo co) +pushCoArgs co (arg:args) = do { (arg', m_co1) <- pushCoArg co arg + ; case m_co1 of + MCo co1 -> do { (args', m_co2) <- pushCoArgs co1 args + ; return (arg':args', m_co2) } + MRefl -> return (arg':args, MRefl) } + +pushCoArg :: CoercionR -> CoreArg -> Maybe (CoreArg, MCoercion) +-- We have (fun |> co) arg, and we want to transform it to +-- (fun arg) |> co +-- This may fail, e.g. if (fun :: N) where N is a newtype +-- C.f. simplCast in GHC.Core.Opt.Simplify +-- 'co' is always Representational +-- If the returned coercion is Nothing, then it would have been reflexive +pushCoArg co (Type ty) = do { (ty', m_co') <- pushCoTyArg co ty + ; return (Type ty', m_co') } +pushCoArg co val_arg = do { (arg_co, m_co') <- pushCoValArg co + ; return (val_arg `mkCastMCo` arg_co, m_co') } + +pushCoTyArg :: CoercionR -> Type -> Maybe (Type, MCoercionR) +-- We have (fun |> co) @ty +-- Push the coercion through to return +-- (fun @ty') |> co' +-- 'co' is always Representational +-- If the returned coercion is Nothing, then it would have been reflexive; +-- it's faster not to compute it, though. +pushCoTyArg co ty + -- The following is inefficient - don't do `eqType` here, the coercion + -- optimizer will take care of it. See #14737. + -- -- | tyL `eqType` tyR + -- -- = Just (ty, Nothing) + + | isReflCo co + = Just (ty, MRefl) + + | isForAllTy_ty tyL + = ASSERT2( isForAllTy_ty tyR, ppr co $$ ppr ty ) + Just (ty `mkCastTy` co1, MCo co2) + + | otherwise + = Nothing + where + Pair tyL tyR = coercionKind co + -- co :: tyL ~ tyR + -- tyL = forall (a1 :: k1). ty1 + -- tyR = forall (a2 :: k2). ty2 + + co1 = mkSymCo (mkNthCo Nominal 0 co) + -- co1 :: k2 ~N k1 + -- Note that NthCo can extract a Nominal equality between the + -- kinds of the types related by a coercion between forall-types. + -- See the NthCo case in GHC.Core.Lint. + + co2 = mkInstCo co (mkGReflLeftCo Nominal ty co1) + -- co2 :: ty1[ (ty|>co1)/a1 ] ~ ty2[ ty/a2 ] + -- Arg of mkInstCo is always nominal, hence mkNomReflCo + +pushCoValArg :: CoercionR -> Maybe (MCoercionR, MCoercionR) +-- We have (fun |> co) arg +-- Push the coercion through to return +-- (fun (arg |> co_arg)) |> co_res +-- 'co' is always Representational +-- If the second returned Coercion is actually Nothing, then no cast is necessary; +-- the returned coercion would have been reflexive. +pushCoValArg co + -- The following is inefficient - don't do `eqType` here, the coercion + -- optimizer will take care of it. See #14737. + -- -- | tyL `eqType` tyR + -- -- = Just (mkRepReflCo arg, Nothing) + + | isReflCo co + = Just (MRefl, MRefl) + + | isFunTy tyL + , (co_mult, co1, co2) <- decomposeFunCo Representational co + , isReflexiveCo co_mult + -- We can't push the coercion in the case where co_mult isn't reflexivity: + -- it could be an unsafe axiom, and losing this information could yield + -- ill-typed terms. For instance (fun x ::(1) Int -> (fun _ -> () |> co) x) + -- with co :: (Int -> ()) ~ (Int #-> ()), would reduce to (fun x ::(1) Int + -- -> (fun _ ::(Many) Int -> ()) x) which is ill-typed + + -- If co :: (tyL1 -> tyL2) ~ (tyR1 -> tyR2) + -- then co1 :: tyL1 ~ tyR1 + -- co2 :: tyL2 ~ tyR2 + = ASSERT2( isFunTy tyR, ppr co $$ ppr arg ) + Just (coToMCo (mkSymCo co1), coToMCo co2) + -- Critically, coToMCo to checks for ReflCo; the whole coercion may not + -- be reflexive, but either of its components might be + -- We could use isReflexiveCo, but it's not clear if the benefit + -- is worth the cost, and it makes no difference in #18223 + + | otherwise + = Nothing + where + arg = funArgTy tyR + Pair tyL tyR = coercionKind co + +pushCoercionIntoLambda + :: InScopeSet -> Var -> CoreExpr -> CoercionR -> Maybe (Var, CoreExpr) +-- This implements the Push rule from the paper on coercions +-- (\x. e) |> co +-- ===> +-- (\x'. e |> co') +pushCoercionIntoLambda in_scope x e co + | ASSERT(not (isTyVar x) && not (isCoVar x)) True + , Pair s1s2 t1t2 <- coercionKind co + , Just (_, _s1,_s2) <- splitFunTy_maybe s1s2 + , Just (w1, t1,_t2) <- splitFunTy_maybe t1t2 + , (co_mult, co1, co2) <- decomposeFunCo Representational co + , isReflexiveCo co_mult + -- We can't push the coercion in the case where co_mult isn't + -- reflexivity. See pushCoValArg for more details. + = let + -- Should we optimize the coercions here? + -- Otherwise they might not match too well + x' = x `setIdType` t1 `setIdMult` w1 + in_scope' = in_scope `extendInScopeSet` x' + subst = extendIdSubst (mkEmptySubst in_scope') + x + (mkCast (Var x') co1) + in Just (x', substExpr subst e `mkCast` co2) + | otherwise + = pprTrace "exprIsLambda_maybe: Unexpected lambda in case" (ppr (Lam x e)) + Nothing + +pushCoDataCon :: DataCon -> [CoreExpr] -> Coercion + -> Maybe (DataCon + , [Type] -- Universal type args + , [CoreExpr]) -- All other args incl existentials +-- Implement the KPush reduction rule as described in "Down with kinds" +-- The transformation applies iff we have +-- (C e1 ... en) `cast` co +-- where co :: (T t1 .. tn) ~ to_ty +-- The left-hand one must be a T, because exprIsConApp returned True +-- but the right-hand one might not be. (Though it usually will.) +pushCoDataCon dc dc_args co + | isReflCo co || from_ty `eqType` to_ty -- try cheap test first + , let (univ_ty_args, rest_args) = splitAtList (dataConUnivTyVars dc) dc_args + = Just (dc, map exprToType univ_ty_args, rest_args) + + | Just (to_tc, to_tc_arg_tys) <- splitTyConApp_maybe to_ty + , to_tc == dataConTyCon dc + -- These two tests can fail; we might see + -- (C x y) `cast` (g :: T a ~ S [a]), + -- where S is a type function. In fact, exprIsConApp + -- will probably not be called in such circumstances, + -- but there's nothing wrong with it + + = let + tc_arity = tyConArity to_tc + dc_univ_tyvars = dataConUnivTyVars dc + dc_ex_tcvars = dataConExTyCoVars dc + arg_tys = dataConRepArgTys dc + + non_univ_args = dropList dc_univ_tyvars dc_args + (ex_args, val_args) = splitAtList dc_ex_tcvars non_univ_args + + -- Make the "Psi" from the paper + omegas = decomposeCo tc_arity co (tyConRolesRepresentational to_tc) + (psi_subst, to_ex_arg_tys) + = liftCoSubstWithEx Representational + dc_univ_tyvars + omegas + dc_ex_tcvars + (map exprToType ex_args) + + -- Cast the value arguments (which include dictionaries) + new_val_args = zipWith cast_arg (map scaledThing arg_tys) val_args + cast_arg arg_ty arg = mkCast arg (psi_subst arg_ty) + + to_ex_args = map Type to_ex_arg_tys + + dump_doc = vcat [ppr dc, ppr dc_univ_tyvars, ppr dc_ex_tcvars, + ppr arg_tys, ppr dc_args, + ppr ex_args, ppr val_args, ppr co, ppr from_ty, ppr to_ty, ppr to_tc + , ppr $ mkTyConApp to_tc (map exprToType $ takeList dc_univ_tyvars dc_args) ] + in + ASSERT2( eqType from_ty (mkTyConApp to_tc (map exprToType $ takeList dc_univ_tyvars dc_args)), dump_doc ) + ASSERT2( equalLength val_args arg_tys, dump_doc ) + Just (dc, to_tc_arg_tys, to_ex_args ++ new_val_args) + + | otherwise + = Nothing + + where + Pair from_ty to_ty = coercionKind co + +collectBindersPushingCo :: CoreExpr -> ([Var], CoreExpr) +-- Collect lambda binders, pushing coercions inside if possible +-- E.g. (\x.e) |> g g :: -> blah +-- = (\x. e |> Nth 1 g) +-- +-- That is, -- --- ToDo: we could instead check if we actually *are* --- changing any join points' types, and if not use substExprSC. -subst_expr = substExpr +-- collectBindersPushingCo ((\x.e) |> g) === ([x], e |> Nth 1 g) +collectBindersPushingCo e + = go [] e + where + -- Peel off lambdas until we hit a cast. + go :: [Var] -> CoreExpr -> ([Var], CoreExpr) + -- The accumulator is in reverse order + go bs (Lam b e) = go (b:bs) e + go bs (Cast e co) = go_c bs e co + go bs e = (reverse bs, e) + + -- We are in a cast; peel off casts until we hit a lambda. + go_c :: [Var] -> CoreExpr -> CoercionR -> ([Var], CoreExpr) + -- (go_c bs e c) is same as (go bs e (e |> c)) + go_c bs (Cast e co1) co2 = go_c bs e (co1 `mkTransCo` co2) + go_c bs (Lam b e) co = go_lam bs b e co + go_c bs e co = (reverse bs, mkCast e co) + + -- We are in a lambda under a cast; peel off lambdas and build a + -- new coercion for the body. + go_lam :: [Var] -> Var -> CoreExpr -> CoercionR -> ([Var], CoreExpr) + -- (go_lam bs b e c) is same as (go_c bs (\b.e) c) + go_lam bs b e co + | isTyVar b + , let Pair tyL tyR = coercionKind co + , ASSERT( isForAllTy_ty tyL ) + isForAllTy_ty tyR + , isReflCo (mkNthCo Nominal 0 co) -- See Note [collectBindersPushingCo] + = go_c (b:bs) e (mkInstCo co (mkNomReflCo (mkTyVarTy b))) + + | isCoVar b + , let Pair tyL tyR = coercionKind co + , ASSERT( isForAllTy_co tyL ) + isForAllTy_co tyR + , isReflCo (mkNthCo Nominal 0 co) -- See Note [collectBindersPushingCo] + , let cov = mkCoVarCo b + = go_c (b:bs) e (mkInstCo co (mkNomReflCo (mkCoercionTy cov))) + + | isId b + , let Pair tyL tyR = coercionKind co + , ASSERT( isFunTy tyL) isFunTy tyR + , (co_mult, co_arg, co_res) <- decomposeFunCo Representational co + , isReflCo co_mult -- See Note [collectBindersPushingCo] + , isReflCo co_arg -- See Note [collectBindersPushingCo] + = go_c (b:bs) e co_res + + | otherwise = (reverse bs, mkCast (Lam b e) co) +{- --------------- +Note [collectBindersPushingCo] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +We just look for coercions of form + # w -> blah +(and similarly for foralls) to keep this function simple. We could do +more elaborate stuff, but it'd involve substitution etc. + +-} + +{- ********************************************************************* +* * + Join points +* * +********************************************************************* -} +------------------- -- | Split an expression into the given number of binders and a body, -- eta-expanding if necessary. Counts value *and* type binders. etaExpandToJoinPoint :: JoinArity -> CoreExpr -> ([CoreBndr], CoreExpr) @@ -1307,7 +1705,7 @@ etaBodyForJoinPoint need_args body = (reverse rev_bs, e) go n ty subst rev_bs e | Just (tv, res_ty) <- splitForAllTy_maybe ty - , let (subst', tv') = Type.substVarBndr subst tv + , let (subst', tv') = substVarBndr subst tv = go (n-1) res_ty subst' (tv' : rev_bs) (e `App` varToCoreExpr tv') | Just (mult, arg_ty, res_ty) <- splitFunTy_maybe ty , let (subst', b) = freshEtaId n subst (Scaled mult arg_ty) @@ -1318,6 +1716,8 @@ etaBodyForJoinPoint need_args body init_subst e = mkEmptyTCvSubst (mkInScopeSet (exprFreeVars e)) + + -------------- freshEtaId :: Int -> TCvSubst -> Scaled Type -> (TCvSubst, Id) -- Make a fresh Id, with specified type (after applying substitution) @@ -1336,3 +1736,4 @@ freshEtaId n subst ty -- "OrCoVar" since this can be used to eta-expand -- coercion abstractions subst' = extendTCvInScope subst eta_id' + ===================================== compiler/GHC/Core/Opt/Pipeline.hs ===================================== @@ -311,33 +311,38 @@ getCoreToDo dflags runWhen do_float_in CoreDoFloatInwards, + simplify "final", -- Final tidy-up + maybe_rule_check FinalPhase, + -------- After this we have -O2 passes ----------------- + -- None of them run with -O + -- Case-liberation for -O2. This should be after -- strictness analysis and the simplification which follows it. - runWhen liberate_case (CoreDoPasses [ - CoreLiberateCase, - simplify "post-liberate-case" - ]), -- Run the simplifier after LiberateCase to vastly - -- reduce the possibility of shadowing - -- Reason: see Note [Shadowing] in GHC.Core.Opt.SpecConstr + runWhen liberate_case $ CoreDoPasses + [ CoreLiberateCase, simplify "post-liberate-case" ], + -- Run the simplifier after LiberateCase to vastly + -- reduce the possibility of shadowing + -- Reason: see Note [Shadowing] in GHC.Core.Opt.SpecConstr - runWhen spec_constr CoreDoSpecConstr, + runWhen spec_constr $ CoreDoPasses + [ CoreDoSpecConstr, simplify "post-spec-constr"], + -- See Note [Simplify after SpecConstr] maybe_rule_check FinalPhase, - runWhen late_specialise - (CoreDoPasses [ CoreDoSpecialising - , simplify "post-late-spec"]), + runWhen late_specialise $ CoreDoPasses + [ CoreDoSpecialising, simplify "post-late-spec"], -- LiberateCase can yield new CSE opportunities because it peels -- off one layer of a recursive function (concretely, I saw this -- in wheel-sieve1), and I'm guessing that SpecConstr can too -- And CSE is a very cheap pass. So it seems worth doing here. - runWhen ((liberate_case || spec_constr) && cse) CoreCSE, + runWhen ((liberate_case || spec_constr) && cse) $ CoreDoPasses + [ CoreCSE, simplify "post-final-cse" ], - -- Final clean-up simplification: - simplify "final", + --------- End of -O2 passes -------------- runWhen late_dmd_anal $ CoreDoPasses ( dmd_cpr_ww ++ [simplify "post-late-ww"] @@ -406,6 +411,27 @@ or with -O0. Two reasons: But watch out: list fusion can prevent floating. So use phase control to switch off those rules until after floating. +Note [Simplify after SpecConstr] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +We want to run the simplifier after SpecConstr, and before late-Specialise, +for two reasons, both shown up in test perf/compiler/T16473, +with -O2 -flate-specialise + +1. I found that running late-Specialise after SpecConstr, with no + simplification in between meant that the carefullly constructed + SpecConstr rule never got to fire. (It was something like + lvl = f a -- Arity 1 + ....g lvl.... + SpecConstr specialised g for argument lvl; but Specialise then + specialised lvl = f a to lvl = $sf, and inlined. Or something like + that.) + +2. Specialise relies on unfoldings being available for top-level dictionary + bindings; but SpecConstr kills them all! The Simplifer restores them. + +This extra run of the simplifier has a cost, but this is only with -O2. + + ************************************************************************ * * The CoreToDo interpreter ===================================== compiler/GHC/Core/Opt/Simplify.hs ===================================== @@ -48,9 +48,9 @@ import GHC.Types.Unique ( hasKey ) import GHC.Core.Unfold import GHC.Core.Utils import GHC.Core.Opt.Arity ( ArityType(..), arityTypeArity, isBotArityType + , pushCoTyArg, pushCoValArg , idArityType, etaExpandAT ) -import GHC.Core.SimpleOpt ( pushCoTyArg, pushCoValArg - , joinPointBinding_maybe, joinPointBindings_maybe ) +import GHC.Core.SimpleOpt ( joinPointBinding_maybe, joinPointBindings_maybe ) import GHC.Core.FVs ( mkRuleInfo ) import GHC.Core.Rules ( lookupRule, getRules, initRuleOpts ) import GHC.Types.Basic @@ -315,7 +315,7 @@ simplLazyBind env top_lvl is_rec bndr bndr1 rhs rhs_se ; let rhs_cont = mkRhsStop (substTy body_env (exprType body)) ; (body_floats0, body0) <- {-#SCC "simplExprF" #-} simplExprF body_env body rhs_cont - -- Never float join-floats out of a non-join let-binding + -- Never float join-floats out of a non-join let-binding (which this is) -- So wrap the body in the join-floats right now -- Hence: body_floats1 consists only of let-floats ; let (body_floats1, body1) = wrapJoinFloatsX body_floats0 body0 @@ -1411,25 +1411,23 @@ simplCast env body co0 cont0 -- type of the hole changes (#16312) -- (f |> co) e ===> (f (e |> co1)) |> co2 - -- where co :: (s1->s2) ~ (t1~t2) + -- where co :: (s1->s2) ~ (t1->t2) -- co1 :: t1 ~ s1 -- co2 :: s2 ~ t2 addCoerce co cont@(ApplyToVal { sc_arg = arg, sc_env = arg_se , sc_dup = dup, sc_cont = tail }) - | Just (co1, m_co2) <- pushCoValArg co - , let new_ty = coercionRKind co1 - , not (isTypeLevPoly new_ty) -- Without this check, we get a lev-poly arg - -- See Note [Levity polymorphism invariants] in GHC.Core - -- test: typecheck/should_run/EtaExpandLevPoly + | Just (m_co1, m_co2) <- pushCoValArg co + , levity_ok m_co1 = {-#SCC "addCoerce-pushCoValArg" #-} do { tail' <- addCoerceM m_co2 tail - ; if isReflCo co1 - then return (cont { sc_cont = tail' - , sc_hole_ty = coercionLKind co }) + ; case m_co1 of { + MRefl -> return (cont { sc_cont = tail' + , sc_hole_ty = coercionLKind co }) ; -- Avoid simplifying if possible; -- See Note [Avoiding exponential behaviour] - else do - { (dup', arg_se', arg') <- simplArg env dup arg_se arg + + MCo co1 -> + do { (dup', arg_se', arg') <- simplArg env dup arg_se arg -- When we build the ApplyTo we can't mix the OutCoercion -- 'co' with the InExpr 'arg', so we simplify -- to make it all consistent. It's a bit messy. @@ -1439,7 +1437,7 @@ simplCast env body co0 cont0 , sc_env = arg_se' , sc_dup = dup' , sc_cont = tail' - , sc_hole_ty = coercionLKind co }) } } + , sc_hole_ty = coercionLKind co }) } } } addCoerce co cont | isReflexiveCo co = return cont -- Having this at the end makes a huge @@ -1447,6 +1445,13 @@ simplCast env body co0 cont0 -- See Note [Optimising reflexivity] | otherwise = return (CastIt co cont) + levity_ok :: MCoercionR -> Bool + levity_ok MRefl = True + levity_ok (MCo co) = not $ isTypeLevPoly $ coercionRKind co + -- Without this check, we get a lev-poly arg + -- See Note [Levity polymorphism invariants] in GHC.Core + -- test: typecheck/should_run/EtaExpandLevPoly + simplArg :: SimplEnv -> DupFlag -> StaticEnv -> CoreExpr -> SimplM (DupFlag, StaticEnv, OutExpr) simplArg env dup_flag arg_env arg @@ -3111,7 +3116,7 @@ knownCon :: SimplEnv knownCon env scrut dc_floats dc dc_ty_args dc_args bndr bs rhs cont = do { (floats1, env1) <- bind_args env bs dc_args - ; (floats2, env2) <- bind_case_bndr env1 + ; (floats2, env2) <- bind_case_bndr env1 ; (floats3, expr') <- simplExprF env2 rhs cont ; case dc_floats of [] -> @@ -3237,6 +3242,7 @@ altsWouldDup [_] = False altsWouldDup (alt:alts) | is_bot_alt alt = altsWouldDup alts | otherwise = not (all is_bot_alt alts) + -- otherwise case: first alt is non-bot, so all the rest must be bot where is_bot_alt (_,_,rhs) = exprIsDeadEnd rhs ===================================== compiler/GHC/Core/Opt/Simplify/Env.hs ===================================== @@ -591,7 +591,7 @@ addJoinFlts :: JoinFloats -> JoinFloats -> JoinFloats addJoinFlts = appOL mkRecFloats :: SimplFloats -> SimplFloats --- Flattens the floats from env2 into a single Rec group, +-- Flattens the floats into a single Rec group, -- They must either all be lifted LetFloats or all JoinFloats mkRecFloats floats@(SimplFloats { sfLetFloats = LetFloats bs ff , sfJoinFloats = jbs ===================================== compiler/GHC/Core/Opt/Specialise.hs ===================================== @@ -21,7 +21,7 @@ import GHC.Tc.Utils.TcType hiding( substTy ) import GHC.Core.Type hiding( substTy, extendTvSubstList ) import GHC.Core.Multiplicity import GHC.Core.Predicate -import GHC.Unit.Module( Module, HasModule(..) ) +import GHC.Unit.Module( Module ) import GHC.Core.Coercion( Coercion ) import GHC.Core.Opt.Monad import qualified GHC.Core.Subst as Core @@ -31,11 +31,11 @@ import GHC.Types.Var.Set import GHC.Types.Var.Env import GHC.Core import GHC.Core.Rules -import GHC.Core.SimpleOpt ( collectBindersPushingCo ) import GHC.Core.Utils ( exprIsTrivial, getIdFromTrivialExpr_maybe , mkCast, exprType ) import GHC.Core.FVs -import GHC.Core.Opt.Arity ( etaExpandToJoinPointRule ) +import GHC.Core.Opt.Arity ( collectBindersPushingCo + , etaExpandToJoinPointRule ) import GHC.Types.Unique.Supply import GHC.Types.Name import GHC.Types.Id.Make ( voidArgId, voidPrimId ) @@ -51,12 +51,9 @@ import GHC.Utils.Misc import GHC.Utils.Outputable import GHC.Utils.Panic import GHC.Data.FastString -import GHC.Utils.Monad.State import GHC.Types.Unique.DFM import GHC.Core.TyCo.Rep (TyCoBinder (..)) -import Control.Monad - {- ************************************************************************ * * @@ -590,28 +587,29 @@ specProgram guts@(ModGuts { mg_module = this_mod , mg_binds = binds }) = do { dflags <- getDynFlags + -- We need to start with a Subst that knows all the things + -- that are in scope, so that the substitution engine doesn't + -- accidentally re-use a unique that's already in use + -- Easiest thing is to do it all at once, as if all the top-level + -- decls were mutually recursive + ; let top_env = SE { se_subst = Core.mkEmptySubst $ mkInScopeSet $ mkVarSet $ + bindersOfBinds binds + , se_interesting = emptyVarSet + , se_module = this_mod + , se_dflags = dflags } + + go [] = return ([], emptyUDs) + go (bind:binds) = do (binds', uds) <- go binds + (bind', uds') <- specBind top_env bind uds + return (bind' ++ binds', uds') + -- Specialise the bindings of this module - ; (binds', uds) <- runSpecM dflags this_mod (go binds) + ; (binds', uds) <- runSpecM (go binds) - ; (spec_rules, spec_binds) <- specImports dflags this_mod top_env - local_rules uds + ; (spec_rules, spec_binds) <- specImports top_env local_rules uds ; return (guts { mg_binds = spec_binds ++ binds' , mg_rules = spec_rules ++ local_rules }) } - where - -- We need to start with a Subst that knows all the things - -- that are in scope, so that the substitution engine doesn't - -- accidentally re-use a unique that's already in use - -- Easiest thing is to do it all at once, as if all the top-level - -- decls were mutually recursive - top_env = SE { se_subst = Core.mkEmptySubst $ mkInScopeSet $ mkVarSet $ - bindersOfBinds binds - , se_interesting = emptyVarSet } - - go [] = return ([], emptyUDs) - go (bind:binds) = do (binds', uds) <- go binds - (bind', uds') <- specBind top_env bind uds - return (bind' ++ binds', uds') {- Note [Wrap bindings returned by specImports] @@ -641,13 +639,13 @@ See #10491 * * ********************************************************************* -} -specImports :: DynFlags -> Module -> SpecEnv +specImports :: SpecEnv -> [CoreRule] -> UsageDetails -> CoreM ([CoreRule], [CoreBind]) -specImports dflags this_mod top_env local_rules +specImports top_env local_rules (MkUD { ud_binds = dict_binds, ud_calls = calls }) - | not $ gopt Opt_CrossModuleSpecialise dflags + | not $ gopt Opt_CrossModuleSpecialise (se_dflags top_env) -- See Note [Disabling cross-module specialisation] = return ([], wrapDictBinds dict_binds []) @@ -655,8 +653,7 @@ specImports dflags this_mod top_env local_rules = do { hpt_rules <- getRuleBase ; let rule_base = extendRuleBaseList hpt_rules local_rules - ; (spec_rules, spec_binds) <- spec_imports dflags this_mod top_env - [] rule_base + ; (spec_rules, spec_binds) <- spec_imports top_env [] rule_base dict_binds calls -- Don't forget to wrap the specialized bindings with @@ -672,9 +669,7 @@ specImports dflags this_mod top_env local_rules } -- | Specialise a set of calls to imported bindings -spec_imports :: DynFlags - -> Module - -> SpecEnv -- Passed in so that all top-level Ids are in scope +spec_imports :: SpecEnv -- Passed in so that all top-level Ids are in scope -> [Id] -- Stack of imported functions being specialised -- See Note [specImport call stack] -> RuleBase -- Rules from this module and the home package @@ -684,8 +679,7 @@ spec_imports :: DynFlags -> CallDetails -- Calls for imported things -> CoreM ( [CoreRule] -- New rules , [CoreBind] ) -- Specialised bindings -spec_imports dflags this_mod top_env - callers rule_base dict_binds calls +spec_imports top_env callers rule_base dict_binds calls = do { let import_calls = dVarEnvElts calls -- ; debugTraceMsg (text "specImports {" <+> -- vcat [ text "calls:" <+> ppr import_calls @@ -699,16 +693,13 @@ spec_imports dflags this_mod top_env go _ [] = return ([], []) go rb (cis : other_calls) = do { -- debugTraceMsg (text "specImport {" <+> ppr cis) - ; (rules1, spec_binds1) <- spec_import dflags this_mod top_env - callers rb dict_binds cis + ; (rules1, spec_binds1) <- spec_import top_env callers rb dict_binds cis -- ; debugTraceMsg (text "specImport }" <+> ppr cis) ; (rules2, spec_binds2) <- go (extendRuleBaseList rb rules1) other_calls ; return (rules1 ++ rules2, spec_binds1 ++ spec_binds2) } -spec_import :: DynFlags - -> Module - -> SpecEnv -- Passed in so that all top-level Ids are in scope +spec_import :: SpecEnv -- Passed in so that all top-level Ids are in scope -> [Id] -- Stack of imported functions being specialised -- See Note [specImport call stack] -> RuleBase -- Rules from this module @@ -717,8 +708,7 @@ spec_import :: DynFlags -> CallInfoSet -- Imported function and calls for it -> CoreM ( [CoreRule] -- New rules , [CoreBind] ) -- Specialised bindings -spec_import dflags this_mod top_env callers - rb dict_binds cis@(CIS fn _) +spec_import top_env callers rb dict_binds cis@(CIS fn _) | isIn "specImport" fn callers = return ([], []) -- No warning. This actually happens all the time -- when specialising a recursive function, because @@ -729,8 +719,7 @@ spec_import dflags this_mod top_env callers = do { -- debugTraceMsg (text "specImport:no valid calls") ; return ([], []) } - | wantSpecImport dflags unfolding - , Just rhs <- maybeUnfoldingTemplate unfolding + | Just rhs <- canSpecImport dflags fn = do { -- Get rules from the external package state -- We keep doing this in case we "page-fault in" -- more rules as we go along @@ -742,8 +731,8 @@ spec_import dflags this_mod top_env callers ; (rules1, spec_pairs, MkUD { ud_binds = dict_binds1, ud_calls = new_calls }) <- do { -- debugTraceMsg (text "specImport1" <+> vcat [ppr fn, ppr good_calls, ppr rhs]) - ; runSpecM dflags this_mod $ - specCalls (Just this_mod) top_env rules_for_fn good_calls fn rhs } + ; runSpecM $ + specCalls True top_env rules_for_fn good_calls fn rhs } ; let spec_binds1 = [NonRec b r | (b,r) <- spec_pairs] -- After the rules kick in we may get recursion, but -- we rely on a global GlomBinds to sort that out later @@ -751,7 +740,7 @@ spec_import dflags this_mod top_env callers -- Now specialise any cascaded calls -- ; debugTraceMsg (text "specImport 2" <+> (ppr fn $$ ppr rules1 $$ ppr spec_binds1)) - ; (rules2, spec_binds2) <- spec_imports dflags this_mod top_env + ; (rules2, spec_binds2) <- spec_imports top_env (fn:callers) (extendRuleBaseList rb rules1) (dict_binds `unionBags` dict_binds1) @@ -767,11 +756,34 @@ spec_import dflags this_mod top_env callers ; return ([], [])} where - unfolding = realIdUnfolding fn -- We want to see the unfolding even for loop breakers + dflags = se_dflags top_env good_calls = filterCalls cis dict_binds -- SUPER IMPORTANT! Drop calls that (directly or indirectly) refer to fn -- See Note [Avoiding loops in specImports] +canSpecImport :: DynFlags -> Id -> Maybe CoreExpr +-- See Note [Specialise imported INLINABLE things] +canSpecImport dflags fn + | CoreUnfolding { uf_src = src, uf_tmpl = rhs } <- unf + , isStableSource src + = Just rhs -- By default, specialise only imported things that have a stable + -- unfolding; that is, have an INLINE or INLINABLE pragma + -- Specialise even INLINE things; it hasn't inlined yet, + -- so perhaps it never will. Moreover it may have calls + -- inside it that we want to specialise + + -- CoreUnfolding case does /not/ include DFunUnfoldings; + -- We only specialise DFunUnfoldings with -fspecialise-aggressively + -- See Note [Do not specialise imported DFuns] + + | gopt Opt_SpecialiseAggressively dflags + = maybeUnfoldingTemplate unf -- With -fspecialise-aggressively, specialise anything + -- with an unfolding, stable or not, DFun or not + + | otherwise = Nothing + where + unf = realIdUnfolding fn -- We want to see the unfolding even for loop breakers + -- | Returns whether or not to show a missed-spec warning. -- If -Wall-missed-specializations is on, show the warning. -- Otherwise, if -Wmissed-specializations is on, only show a warning @@ -796,24 +808,47 @@ tryWarnMissingSpecs dflags callers fn calls_for_fn , whenPprDebug (text "calls:" <+> vcat (map (pprCallInfo fn) calls_for_fn)) , text "Probable fix: add INLINABLE pragma on" <+> quotes (ppr fn) ]) -wantSpecImport :: DynFlags -> Unfolding -> Bool --- See Note [Specialise imported INLINABLE things] -wantSpecImport dflags unf - = case unf of - NoUnfolding -> False - BootUnfolding -> False - OtherCon {} -> False - DFunUnfolding {} -> True - CoreUnfolding { uf_src = src, uf_guidance = _guidance } - | gopt Opt_SpecialiseAggressively dflags -> True - | isStableSource src -> True - -- Specialise even INLINE things; it hasn't inlined yet, - -- so perhaps it never will. Moreover it may have calls - -- inside it that we want to specialise - | otherwise -> False -- Stable, not INLINE, hence INLINABLE -{- Note [Avoiding loops in specImports] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +{- Note [Do not specialise imported DFuns] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Ticket #18223 shows that specialising calls of DFuns is can cause a huge +and entirely unnecessary blowup in program size. Consider a call to + f @[[[[[[[[T]]]]]]]] d1 x +where df :: C a => C [a] + d1 :: C [[[[[[[[T]]]]]]]] = dfC[] @[[[[[[[T]]]]]]] d1 + d2 :: C [[[[[[[T]]]]]]] = dfC[] @[[[[[[T]]]]]] d3 + ... +Now we'll specialise f's RHS, which may give rise to calls to 'g', +also overloaded, which we will specialise, and so on. However, if +we specialise the calls to dfC[], we'll generate specialised copies of +all methods of C, at all types; and the same for C's superclasses. + +And many of these specialised functions will never be called. We are +going to call the specialised 'f', and the specialised 'g', but DFuns +group functions into a tuple, many of whose elements may never be used. + +With deeply-nested types this can lead to a simply overwhelming number +of specialisations: see #18223 for a simple example (from the wild). +I measured the number of specialisations for various numbers of calls +of `flip evalStateT ()`, and got this + + Size after one simplification + #calls #SPEC rules Terms Types + 5 56 3100 10600 + 9 108 13660 77206 + +The real tests case has 60+ calls, which blew GHC out of the water. + +Solution: don't specialise DFuns. The downside is that if we end +up with (h (dfun d)), /and/ we don't specialise 'h', then we won't +pass to 'h' a tuple of specialised functions. + +However, the flag -fspecialise-aggressively (experimental, off by default) +allows DFuns to specialise as well. + +Note [Avoiding loops in specImports] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We must take great care when specialising instance declarations (functions like $fOrdList) lest we accidentally build a recursive dictionary. See Note [Avoiding loops]. @@ -1001,6 +1036,9 @@ data SpecEnv -- Dict Ids that we know something about -- and hence may be worth specialising against -- See Note [Interesting dictionary arguments] + + , se_module :: Module + , se_dflags :: DynFlags } instance Outputable SpecEnv where @@ -1308,7 +1346,7 @@ specDefn :: SpecEnv specDefn env body_uds fn rhs = do { let (body_uds_without_me, calls_for_me) = callsForMe fn body_uds rules_for_me = idCoreRules fn - ; (rules, spec_defns, spec_uds) <- specCalls Nothing env rules_for_me + ; (rules, spec_defns, spec_uds) <- specCalls False env rules_for_me calls_for_me fn rhs ; return ( fn `addIdSpecialisations` rules , spec_defns @@ -1321,8 +1359,8 @@ specDefn env body_uds fn rhs -- body_uds_without_me --------------------------- -specCalls :: Maybe Module -- Just this_mod => specialising imported fn - -- Nothing => specialising local fn +specCalls :: Bool -- True => specialising imported fn + -- False => specialising local fn -> SpecEnv -> [CoreRule] -- Existing RULES for the fn -> [CallInfo] @@ -1337,7 +1375,7 @@ type SpecInfo = ( [CoreRule] -- Specialisation rules , [(Id,CoreExpr)] -- Specialised definition , UsageDetails ) -- Usage details from specialised RHSs -specCalls mb_mod env existing_rules calls_for_me fn rhs +specCalls spec_imp env existing_rules calls_for_me fn rhs -- The first case is the interesting one | notNull calls_for_me -- And there are some calls to specialise && not (isNeverActive (idInlineActivation fn)) @@ -1368,7 +1406,9 @@ specCalls mb_mod env existing_rules calls_for_me fn rhs inl_act = inlinePragmaActivation inl_prag is_local = isLocalId fn is_dfun = isDFunId fn - + dflags = se_dflags env + ropts = initRuleOpts dflags + this_mod = se_module env -- Figure out whether the function has an INLINE pragma -- See Note [Inline specialisations] @@ -1410,8 +1450,6 @@ specCalls mb_mod env existing_rules calls_for_me fn rhs -- , ppr dx_binds ]) $ -- return () - ; dflags <- getDynFlags - ; let ropts = initRuleOpts dflags ; if not useful -- No useful specialisation || already_covered ropts rules_acc rule_lhs_args then return spec_acc @@ -1439,17 +1477,15 @@ specCalls mb_mod env existing_rules calls_for_me fn rhs = Nothing ; spec_fn <- newSpecIdSM fn spec_fn_ty spec_join_arity - ; this_mod <- getModule ; let -- The rule to put in the function's specialisation is: -- forall x @b d1' d2'. -- f x @T1 @b @T2 d1' d2' = f1 x @b -- See Note [Specialising Calls] - herald = case mb_mod of - Nothing -- Specialising local fn - -> text "SPEC" - Just this_mod -- Specialising imported fn - -> text "SPEC/" <> ppr this_mod + herald | spec_imp = -- Specialising imported fn + text "SPEC/" <> ppr this_mod + | otherwise = -- Specialising local fn + text "SPEC" rule_name = mkFastString $ showSDoc dflags $ herald <+> ftext (occNameFS (getOccName fn)) @@ -2476,15 +2512,15 @@ mkCallUDs env f args res = mkCallUDs' env f args mkCallUDs' env f args - | not (want_calls_for f) -- Imported from elsewhere - || null ci_key -- No useful specialisation - -- See also Note [Specialisations already covered] + | wantCallsFor env f -- We want it, and... + , not (null ci_key) -- this call site has a useful specialisation + = -- pprTrace "mkCallUDs: keeping" _trace_doc + singleCall f ci_key + + | otherwise -- See also Note [Specialisations already covered] = -- pprTrace "mkCallUDs: discarding" _trace_doc emptyUDs - | otherwise - = -- pprTrace "mkCallUDs: keeping" _trace_doc - singleCall f ci_key where _trace_doc = vcat [ppr f, ppr args, ppr ci_key] pis = fst $ splitPiTys $ idType f @@ -2518,13 +2554,6 @@ mkCallUDs' env f args mk_spec_arg _ (Anon VisArg _) = UnspecArg - want_calls_for f = isLocalId f || isJust (maybeUnfoldingTemplate (realIdUnfolding f)) - -- For imported things, we gather call instances if - -- there is an unfolding that we could in principle specialise - -- We might still decide not to use it (consulting dflags) - -- in specImports - -- Use 'realIdUnfolding' to ignore the loop-breaker flag! - type_determines_value pred -- See Note [Type determines value] = case classifyPredType pred of ClassPred cls _ -> not (isIPClass cls) -- Superclasses can't be IPs @@ -2533,9 +2562,17 @@ mkCallUDs' env f args -- Constraint-ranged family; #7785 ForAllPred {} -> True -{- -Note [Type determines value] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +wantCallsFor :: SpecEnv -> Id -> Bool +wantCallsFor _env _f = True + -- We could be less eager about collecting calls for LocalIds: there's + -- no point for ones that are lambda-bound. But we can't use the + -- unfolding, because unfoldings for local functions are discarded by + -- cloneBindSM. We could keep a candidate set of let-binders to + -- reduce the size of the UsageDetails + + +{- Note [Type determines value] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Only specialise on non-IP *class* params, because these are the ones whose *type* determines their *value*. In particular, with implicit params, the type args *don't* say what the value of the implicit param @@ -2796,55 +2833,12 @@ deleteCallsFor bs calls = delDVarEnvList calls bs ************************************************************************ -} -newtype SpecM a = SpecM (State SpecState a) deriving (Functor) - -data SpecState = SpecState { - spec_uniq_supply :: UniqSupply, - spec_module :: Module, - spec_dflags :: DynFlags - } - -instance Applicative SpecM where - pure x = SpecM $ return x - (<*>) = ap - -instance Monad SpecM where - SpecM x >>= f = SpecM $ do y <- x - case f y of - SpecM z -> - z - -instance MonadFail SpecM where - fail str = SpecM $ error str - -instance MonadUnique SpecM where - getUniqueSupplyM - = SpecM $ do st <- get - let (us1, us2) = splitUniqSupply $ spec_uniq_supply st - put $ st { spec_uniq_supply = us2 } - return us1 - - getUniqueM - = SpecM $ do st <- get - let (u,us') = takeUniqFromSupply $ spec_uniq_supply st - put $ st { spec_uniq_supply = us' } - return u - -instance HasDynFlags SpecM where - getDynFlags = SpecM $ liftM spec_dflags get - -instance HasModule SpecM where - getModule = SpecM $ liftM spec_module get - -runSpecM :: DynFlags -> Module -> SpecM a -> CoreM a -runSpecM dflags this_mod (SpecM spec) - = do us <- getUniqueSupplyM - let initialState = SpecState { - spec_uniq_supply = us, - spec_module = this_mod, - spec_dflags = dflags - } - return $ evalState spec initialState +type SpecM a = UniqSM a + +runSpecM :: SpecM a -> CoreM a +runSpecM thing_inside + = do { us <- getUniqueSupplyM + ; return (initUs_ us thing_inside) } mapAndCombineSM :: (a -> SpecM (b, UsageDetails)) -> [a] -> SpecM ([b], UsageDetails) mapAndCombineSM _ [] = return ([], emptyUDs) ===================================== compiler/GHC/Core/Ppr.hs ===================================== @@ -161,15 +161,20 @@ pprOptCo co = sdocOption sdocSuppressCoercions $ \case True -> angleBrackets (text "Co:" <> int (coercionSize co)) False -> parens $ sep [ppr co, dcolon <+> ppr (coercionType co)] +ppr_id_occ :: (SDoc -> SDoc) -> Id -> SDoc +ppr_id_occ add_par id + | isJoinId id = add_par ((text "jump") <+> pp_id) + | otherwise = pp_id + where + pp_id = ppr id -- We could use pprPrefixOcc to print (+) etc, but this is + -- Core where we don't print things infix anyway, so doing + -- so just adds extra redundant parens + ppr_expr :: OutputableBndr b => (SDoc -> SDoc) -> Expr b -> SDoc -- The function adds parens in context that need -- an atomic value (e.g. function args) -ppr_expr add_par (Var name) - | isJoinId name = add_par ((text "jump") <+> pp_name) - | otherwise = pp_name - where - pp_name = pprPrefixOcc name +ppr_expr add_par (Var id) = ppr_id_occ add_par id ppr_expr add_par (Type ty) = add_par (text "TYPE:" <+> ppr ty) -- Weird ppr_expr add_par (Coercion co) = add_par (text "CO:" <+> ppr co) ppr_expr add_par (Lit lit) = pprLiteral add_par lit @@ -212,8 +217,7 @@ ppr_expr add_par expr@(App {}) _ -> parens (hang fun_doc 2 pp_args) where - fun_doc | isJoinId f = text "jump" <+> ppr f - | otherwise = ppr f + fun_doc = ppr_id_occ noParens f _ -> parens (hang (pprParendExpr fun) 2 pp_args) } ===================================== compiler/GHC/Core/SimpleOpt.hs ===================================== @@ -16,17 +16,14 @@ module GHC.Core.SimpleOpt ( -- ** Predicates on expressions exprIsConApp_maybe, exprIsLiteral_maybe, exprIsLambda_maybe, - -- ** Coercions and casts - pushCoArg, pushCoValArg, pushCoTyArg, collectBindersPushingCo ) where #include "HsVersions.h" import GHC.Prelude -import GHC.Core.Opt.Arity( etaExpandToJoinPoint ) - import GHC.Core +import GHC.Core.Opt.Arity import GHC.Core.Subst import GHC.Core.Utils import GHC.Core.FVs @@ -46,18 +43,14 @@ import GHC.Core.Coercion.Opt ( optCoercion ) import GHC.Core.Type hiding ( substTy, extendTvSubst, extendCvSubst, extendTvSubstList , isInScope, substTyVarBndr, cloneTyVarBndr ) import GHC.Core.Coercion hiding ( substCo, substCoVarBndr ) -import GHC.Core.TyCon ( tyConArity ) -import GHC.Core.Multiplicity import GHC.Builtin.Types import GHC.Builtin.Names import GHC.Types.Basic import GHC.Unit.Module ( Module ) import GHC.Utils.Error import GHC.Driver.Session -import GHC.Driver.Ppr import GHC.Utils.Outputable import GHC.Utils.Panic -import GHC.Data.Pair import GHC.Utils.Misc import GHC.Data.Maybe ( orElse ) import GHC.Data.FastString @@ -756,6 +749,28 @@ a good cause. And it won't hurt other RULES and such that it comes across. ************************************************************************ -} +{- Note [Strictness and join points] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Suppose we have + + let f = \x. if x>200 then e1 else e1 + +and we know that f is strict in x. Then if we subsequently +discover that f is an arity-2 join point, we'll eta-expand it to + + let f = \x y. if x>200 then e1 else e1 + +and now it's only strict if applied to two arguments. So we should +adjust the strictness info. + +A more common case is when + + f = \x. error ".." + +and again its arity increases (#15517) +-} + + -- | Returns Just (bndr,rhs) if the binding is a join point: -- If it's a JoinId, just return it -- If it's not yet a JoinId but is always tail-called, @@ -789,27 +804,6 @@ joinPointBindings_maybe bndrs = mapM (uncurry joinPointBinding_maybe) bndrs -{- Note [Strictness and join points] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Suppose we have - - let f = \x. if x>200 then e1 else e1 - -and we know that f is strict in x. Then if we subsequently -discover that f is an arity-2 join point, we'll eta-expand it to - - let f = \x y. if x>200 then e1 else e1 - -and now it's only strict if applied to two arguments. So we should -adjust the strictness info. - -A more common case is when - - f = \x. error ".." - -and again its arity increases (#15517) --} - {- ********************************************************************* * * exprIsConApp_maybe @@ -1324,275 +1318,3 @@ exprIsLambda_maybe _ _e Nothing -{- ********************************************************************* -* * - The "push rules" -* * -************************************************************************ - -Here we implement the "push rules" from FC papers: - -* The push-argument rules, where we can move a coercion past an argument. - We have - (fun |> co) arg - and we want to transform it to - (fun arg') |> co' - for some suitable co' and transformed arg'. - -* The PushK rule for data constructors. We have - (K e1 .. en) |> co - and we want to transform to - (K e1' .. en') - by pushing the coercion into the arguments --} - -pushCoArgs :: CoercionR -> [CoreArg] -> Maybe ([CoreArg], MCoercion) -pushCoArgs co [] = return ([], MCo co) -pushCoArgs co (arg:args) = do { (arg', m_co1) <- pushCoArg co arg - ; case m_co1 of - MCo co1 -> do { (args', m_co2) <- pushCoArgs co1 args - ; return (arg':args', m_co2) } - MRefl -> return (arg':args, MRefl) } - -pushCoArg :: CoercionR -> CoreArg -> Maybe (CoreArg, MCoercion) --- We have (fun |> co) arg, and we want to transform it to --- (fun arg) |> co --- This may fail, e.g. if (fun :: N) where N is a newtype --- C.f. simplCast in GHC.Core.Opt.Simplify --- 'co' is always Representational --- If the returned coercion is Nothing, then it would have been reflexive -pushCoArg co (Type ty) = do { (ty', m_co') <- pushCoTyArg co ty - ; return (Type ty', m_co') } -pushCoArg co val_arg = do { (arg_co, m_co') <- pushCoValArg co - ; return (val_arg `mkCast` arg_co, m_co') } - -pushCoTyArg :: CoercionR -> Type -> Maybe (Type, MCoercionR) --- We have (fun |> co) @ty --- Push the coercion through to return --- (fun @ty') |> co' --- 'co' is always Representational --- If the returned coercion is Nothing, then it would have been reflexive; --- it's faster not to compute it, though. -pushCoTyArg co ty - -- The following is inefficient - don't do `eqType` here, the coercion - -- optimizer will take care of it. See #14737. - -- -- | tyL `eqType` tyR - -- -- = Just (ty, Nothing) - - | isReflCo co - = Just (ty, MRefl) - - | isForAllTy_ty tyL - = ASSERT2( isForAllTy_ty tyR, ppr co $$ ppr ty ) - Just (ty `mkCastTy` co1, MCo co2) - - | otherwise - = Nothing - where - Pair tyL tyR = coercionKind co - -- co :: tyL ~ tyR - -- tyL = forall (a1 :: k1). ty1 - -- tyR = forall (a2 :: k2). ty2 - - co1 = mkSymCo (mkNthCo Nominal 0 co) - -- co1 :: k2 ~N k1 - -- Note that NthCo can extract a Nominal equality between the - -- kinds of the types related by a coercion between forall-types. - -- See the NthCo case in GHC.Core.Lint. - - co2 = mkInstCo co (mkGReflLeftCo Nominal ty co1) - -- co2 :: ty1[ (ty|>co1)/a1 ] ~ ty2[ ty/a2 ] - -- Arg of mkInstCo is always nominal, hence mkNomReflCo - -pushCoValArg :: CoercionR -> Maybe (Coercion, MCoercion) --- We have (fun |> co) arg --- Push the coercion through to return --- (fun (arg |> co_arg)) |> co_res --- 'co' is always Representational --- If the second returned Coercion is actually Nothing, then no cast is necessary; --- the returned coercion would have been reflexive. -pushCoValArg co - -- The following is inefficient - don't do `eqType` here, the coercion - -- optimizer will take care of it. See #14737. - -- -- | tyL `eqType` tyR - -- -- = Just (mkRepReflCo arg, Nothing) - - | isReflCo co - = Just (mkRepReflCo arg, MRefl) - - | isFunTy tyL - , (co_mult, co1, co2) <- decomposeFunCo Representational co - , isReflexiveCo co_mult - -- We can't push the coercion in the case where co_mult isn't reflexivity: - -- it could be an unsafe axiom, and losing this information could yield - -- ill-typed terms. For instance (fun x ::(1) Int -> (fun _ -> () |> co) x) - -- with co :: (Int -> ()) ~ (Int #-> ()), would reduce to (fun x ::(1) Int - -- -> (fun _ ::(Many) Int -> ()) x) which is ill-typed - - -- If co :: (tyL1 -> tyL2) ~ (tyR1 -> tyR2) - -- then co1 :: tyL1 ~ tyR1 - -- co2 :: tyL2 ~ tyR2 - = ASSERT2( isFunTy tyR, ppr co $$ ppr arg ) - Just (mkSymCo co1, MCo co2) - - | otherwise - = Nothing - where - arg = funArgTy tyR - Pair tyL tyR = coercionKind co - -pushCoercionIntoLambda - :: InScopeSet -> Var -> CoreExpr -> CoercionR -> Maybe (Var, CoreExpr) --- This implements the Push rule from the paper on coercions --- (\x. e) |> co --- ===> --- (\x'. e |> co') -pushCoercionIntoLambda in_scope x e co - | ASSERT(not (isTyVar x) && not (isCoVar x)) True - , Pair s1s2 t1t2 <- coercionKind co - , Just (_, _s1,_s2) <- splitFunTy_maybe s1s2 - , Just (w1, t1,_t2) <- splitFunTy_maybe t1t2 - , (co_mult, co1, co2) <- decomposeFunCo Representational co - , isReflexiveCo co_mult - -- We can't push the coercion in the case where co_mult isn't - -- reflexivity. See pushCoValArg for more details. - = let - -- Should we optimize the coercions here? - -- Otherwise they might not match too well - x' = x `setIdType` t1 `setIdMult` w1 - in_scope' = in_scope `extendInScopeSet` x' - subst = extendIdSubst (mkEmptySubst in_scope') - x - (mkCast (Var x') co1) - in Just (x', substExpr subst e `mkCast` co2) - | otherwise - = pprTrace "exprIsLambda_maybe: Unexpected lambda in case" (ppr (Lam x e)) - Nothing - -pushCoDataCon :: DataCon -> [CoreExpr] -> Coercion - -> Maybe (DataCon - , [Type] -- Universal type args - , [CoreExpr]) -- All other args incl existentials --- Implement the KPush reduction rule as described in "Down with kinds" --- The transformation applies iff we have --- (C e1 ... en) `cast` co --- where co :: (T t1 .. tn) ~ to_ty --- The left-hand one must be a T, because exprIsConApp returned True --- but the right-hand one might not be. (Though it usually will.) -pushCoDataCon dc dc_args co - | isReflCo co || from_ty `eqType` to_ty -- try cheap test first - , let (univ_ty_args, rest_args) = splitAtList (dataConUnivTyVars dc) dc_args - = Just (dc, map exprToType univ_ty_args, rest_args) - - | Just (to_tc, to_tc_arg_tys) <- splitTyConApp_maybe to_ty - , to_tc == dataConTyCon dc - -- These two tests can fail; we might see - -- (C x y) `cast` (g :: T a ~ S [a]), - -- where S is a type function. In fact, exprIsConApp - -- will probably not be called in such circumstances, - -- but there's nothing wrong with it - - = let - tc_arity = tyConArity to_tc - dc_univ_tyvars = dataConUnivTyVars dc - dc_ex_tcvars = dataConExTyCoVars dc - arg_tys = dataConRepArgTys dc - - non_univ_args = dropList dc_univ_tyvars dc_args - (ex_args, val_args) = splitAtList dc_ex_tcvars non_univ_args - - -- Make the "Psi" from the paper - omegas = decomposeCo tc_arity co (tyConRolesRepresentational to_tc) - (psi_subst, to_ex_arg_tys) - = liftCoSubstWithEx Representational - dc_univ_tyvars - omegas - dc_ex_tcvars - (map exprToType ex_args) - - -- Cast the value arguments (which include dictionaries) - new_val_args = zipWith cast_arg (map scaledThing arg_tys) val_args - cast_arg arg_ty arg = mkCast arg (psi_subst arg_ty) - - to_ex_args = map Type to_ex_arg_tys - - dump_doc = vcat [ppr dc, ppr dc_univ_tyvars, ppr dc_ex_tcvars, - ppr arg_tys, ppr dc_args, - ppr ex_args, ppr val_args, ppr co, ppr from_ty, ppr to_ty, ppr to_tc - , ppr $ mkTyConApp to_tc (map exprToType $ takeList dc_univ_tyvars dc_args) ] - in - ASSERT2( eqType from_ty (mkTyConApp to_tc (map exprToType $ takeList dc_univ_tyvars dc_args)), dump_doc ) - ASSERT2( equalLength val_args arg_tys, dump_doc ) - Just (dc, to_tc_arg_tys, to_ex_args ++ new_val_args) - - | otherwise - = Nothing - - where - Pair from_ty to_ty = coercionKind co - -collectBindersPushingCo :: CoreExpr -> ([Var], CoreExpr) --- Collect lambda binders, pushing coercions inside if possible --- E.g. (\x.e) |> g g :: -> blah --- = (\x. e |> Nth 1 g) --- --- That is, --- --- collectBindersPushingCo ((\x.e) |> g) === ([x], e |> Nth 1 g) -collectBindersPushingCo e - = go [] e - where - -- Peel off lambdas until we hit a cast. - go :: [Var] -> CoreExpr -> ([Var], CoreExpr) - -- The accumulator is in reverse order - go bs (Lam b e) = go (b:bs) e - go bs (Cast e co) = go_c bs e co - go bs e = (reverse bs, e) - - -- We are in a cast; peel off casts until we hit a lambda. - go_c :: [Var] -> CoreExpr -> CoercionR -> ([Var], CoreExpr) - -- (go_c bs e c) is same as (go bs e (e |> c)) - go_c bs (Cast e co1) co2 = go_c bs e (co1 `mkTransCo` co2) - go_c bs (Lam b e) co = go_lam bs b e co - go_c bs e co = (reverse bs, mkCast e co) - - -- We are in a lambda under a cast; peel off lambdas and build a - -- new coercion for the body. - go_lam :: [Var] -> Var -> CoreExpr -> CoercionR -> ([Var], CoreExpr) - -- (go_lam bs b e c) is same as (go_c bs (\b.e) c) - go_lam bs b e co - | isTyVar b - , let Pair tyL tyR = coercionKind co - , ASSERT( isForAllTy_ty tyL ) - isForAllTy_ty tyR - , isReflCo (mkNthCo Nominal 0 co) -- See Note [collectBindersPushingCo] - = go_c (b:bs) e (mkInstCo co (mkNomReflCo (mkTyVarTy b))) - - | isCoVar b - , let Pair tyL tyR = coercionKind co - , ASSERT( isForAllTy_co tyL ) - isForAllTy_co tyR - , isReflCo (mkNthCo Nominal 0 co) -- See Note [collectBindersPushingCo] - , let cov = mkCoVarCo b - = go_c (b:bs) e (mkInstCo co (mkNomReflCo (mkCoercionTy cov))) - - | isId b - , let Pair tyL tyR = coercionKind co - , ASSERT( isFunTy tyL) isFunTy tyR - , (co_mult, co_arg, co_res) <- decomposeFunCo Representational co - , isReflCo co_mult -- See Note [collectBindersPushingCo] - , isReflCo co_arg -- See Note [collectBindersPushingCo] - = go_c (b:bs) e co_res - - | otherwise = (reverse bs, mkCast (Lam b e) co) - -{- - -Note [collectBindersPushingCo] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -We just look for coercions of form - # w -> blah -(and similarly for foralls) to keep this function simple. We could do -more elaborate stuff, but it'd involve substitution etc. - --} ===================================== compiler/GHC/Core/Subst.hs ===================================== @@ -343,6 +343,8 @@ instance Outputable Subst where substExprSC :: HasDebugCallStack => Subst -> CoreExpr -> CoreExpr -- Just like substExpr, but a no-op if the substitution is empty +-- Note that this does /not/ replace occurrences of free vars with +-- their canonical representatives in the in-scope set substExprSC subst orig_expr | isEmptySubst subst = orig_expr | otherwise = -- pprTrace "enter subst-expr" (doc $$ ppr orig_expr) $ @@ -628,6 +630,9 @@ substIdInfo subst new_id info ------------------ -- | Substitutes for the 'Id's within an unfolding +-- NB: substUnfolding /discards/ any unfolding without +-- without a Stable source. This is usually what we want, +-- but it may be a bit unexpected substUnfolding, substUnfoldingSC :: Subst -> Unfolding -> Unfolding -- Seq'ing on the returned Unfolding is enough to cause -- all the substitutions to happen completely ===================================== testsuite/tests/perf/compiler/Makefile ===================================== @@ -7,7 +7,3 @@ T4007: $(RM) -f T4007.hi T4007.o '$(TEST_HC)' $(TEST_HC_OPTS) -c -O -ddump-rule-firings T4007.hs -T16473: - $(RM) -f T16473.hi T16473.o - '$(TEST_HC)' $(TEST_HC_OPTS) -c -O -ddump-rule-firings T16473.hs - ===================================== testsuite/tests/perf/compiler/T16473.stdout ===================================== @@ -1,97 +1 @@ -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op liftA2 (BUILTIN) -Rule fired: Class op <*> (BUILTIN) -Rule fired: Class op $p1Applicative (BUILTIN) -Rule fired: Class op <$ (BUILTIN) -Rule fired: Class op <*> (BUILTIN) -Rule fired: Class op $p1Applicative (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op get (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op >> (BUILTIN) -Rule fired: Class op put (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op get (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op >> (BUILTIN) -Rule fired: Class op put (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op show (BUILTIN) -Rule fired: Class op mempty (BUILTIN) -Rule fired: Class op fromInteger (BUILTIN) -Rule fired: Integer -> Int# (BUILTIN) -Rule fired: Class op <> (BUILTIN) -Rule fired: Class op + (BUILTIN) -Rule fired: Class op enumFromTo (BUILTIN) -Rule fired: Class op *> (BUILTIN) -Rule fired: Class op *> (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op *> (BUILTIN) -Rule fired: Class op *> (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op *> (BUILTIN) -Rule fired: Class op *> (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: fold/build (GHC.Base) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op $p1Applicative (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op $p1Applicative (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: ># (BUILTIN) -Rule fired: ==# (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op <*> (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op $p1Applicative (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op pure (BUILTIN) -Rule fired: Class op $p1Monad (BUILTIN) -Rule fired: Class op $p1Applicative (BUILTIN) -Rule fired: SPEC/Main $fMonadStateT_$c>>= @Identity _ (Main) -Rule fired: SPEC/Main $fApplicativeStateT_$c<*> @Identity _ (Main) -Rule fired: SPEC/Main $fApplicativeStateT_$cpure @Identity _ (Main) -Rule fired: SPEC/Main $fFunctorStateT @Identity _ (Main) -Rule fired: SPEC/Main $fFunctorStateT_$cfmap @Identity _ (Main) -Rule fired: Class op fmap (BUILTIN) -Rule fired: SPEC/Main $fFunctorStateT_$cfmap @Identity _ (Main) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op fmap (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op return (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op >>= (BUILTIN) -Rule fired: Class op return (BUILTIN) +5050 ===================================== testsuite/tests/perf/compiler/T18223.hs ===================================== @@ -0,0 +1,78 @@ +{-# LANGUAGE PartialTypeSignatures #-} +{-# LANGUAGE Strict #-} + +import Control.Monad.State + +tester :: MonadState a m => m () +tester = modify' id + +-- manyState :: StateT () (StateT () IO) () -> IO () +-- manyState :: _ -> IO () +manyState x = + (flip evalStateT () -- 1 + . flip evalStateT () -- 2 + . flip evalStateT () -- 3 + . flip evalStateT () -- 4 + . flip evalStateT () -- 5 + . flip evalStateT () -- 6 + . flip evalStateT () -- 7 + . flip evalStateT () -- 8 + . flip evalStateT () -- 9 + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + . flip evalStateT () + ) x :: IO () + +main :: IO () +main = manyState tester >>= print ===================================== testsuite/tests/perf/compiler/all.T ===================================== @@ -367,7 +367,13 @@ test('T16190', multimod_compile, ['T16190.hs', '-v0']) -test('T16473', normal, makefile_test, ['T16473']) +# Run this program. If specialisation fails, it'll start to allocate much more +test ('T16473', + [ collect_stats('bytes allocated',5) + , only_ways(['normal']) + ], + compile_and_run, + ['-O2 -flate-specialise']) test('T17516', [ collect_compiler_stats('bytes allocated', 5), @@ -415,3 +421,8 @@ test ('T13253-spj', ], compile, ['-v0 -O']) +test ('T18223', + [ collect_compiler_stats('bytes allocated',2) + ], + compile, + ['-v0 -O']) ===================================== testsuite/tests/printer/T18052a.stderr ===================================== @@ -20,7 +20,7 @@ T18052a.$b:||: = \ (@a) (@b) (x :: a) (y :: b) -> (x, y) -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} (+++) :: forall {a}. [a] -> [a] -> [a] [GblId] -(+++) = (++) +(+++) = ++ -- RHS size: {terms: 13, types: 20, coercions: 0, joins: 0/0} T18052a.$m:||: ===================================== testsuite/tests/simplCore/should_compile/T17966.stdout ===================================== @@ -1,5 +1,2 @@ RULES: "SPEC $cm @()" [0] RULES: "SPEC f @Bool @() @(Maybe Integer)" [0] -"SPEC/T17966 $fShowMaybe_$cshow @Integer" -"SPEC/T17966 $fShowMaybe_$cshowList @Integer" -"SPEC/T17966 $fShowMaybe @Integer" ===================================== testsuite/tests/stranal/should_compile/T18122.stderr ===================================== @@ -13,9 +13,8 @@ Lib.$trModule4 = "main"# -- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} Lib.$trModule3 :: GHC.Types.TrName [GblId, - Cpr=m1, Unf=Unf{Src=, TopLvl=True, Value=True, ConLike=True, - WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 20}] + WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] Lib.$trModule3 = GHC.Types.TrNameS Lib.$trModule4 -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} @@ -28,27 +27,25 @@ Lib.$trModule2 = "Lib"# -- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} Lib.$trModule1 :: GHC.Types.TrName [GblId, - Cpr=m1, Unf=Unf{Src=, TopLvl=True, Value=True, ConLike=True, - WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 20}] + WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] Lib.$trModule1 = GHC.Types.TrNameS Lib.$trModule2 -- RHS size: {terms: 3, types: 0, coercions: 0, joins: 0/0} Lib.$trModule :: GHC.Types.Module [GblId, - Cpr=m1, Unf=Unf{Src=, TopLvl=True, Value=True, ConLike=True, - WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 30}] + WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] Lib.$trModule = GHC.Types.Module Lib.$trModule3 Lib.$trModule1 -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} Lib.$wfoo [InlPrag=NOINLINE] :: GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int# [GblId, Arity=2, Str=, Unf=OtherCon []] -Lib.$wfoo = (GHC.Prim.+#) +Lib.$wfoo = GHC.Prim.+# -- RHS size: {terms: 18, types: 14, coercions: 0, joins: 0/0} -foo [InlPrag=NOUSERINLINE[0]] :: (Int, Int) -> Int -> Int +foo [InlPrag=NOUSERINLINE[final]] :: (Int, Int) -> Int -> Int [GblId, Arity=2, Str=, @@ -56,24 +53,25 @@ foo [InlPrag=NOUSERINLINE[0]] :: (Int, Int) -> Int -> Int Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=2,unsat_ok=True,boring_ok=False) - Tmpl= \ (w_sHs [Occ=Once!] :: (Int, Int)) - (w1_sHt [Occ=Once!] :: Int) -> - case w_sHs of { (ww1_sHw [Occ=Once!], _ [Occ=Dead]) -> - case ww1_sHw of { GHC.Types.I# ww4_sHz [Occ=Once] -> - case w1_sHt of { GHC.Types.I# ww6_sHF [Occ=Once] -> - case Lib.$wfoo ww4_sHz ww6_sHF of ww7_sHJ [Occ=Once] { __DEFAULT -> - GHC.Types.I# ww7_sHJ + Tmpl= \ (w_sEf [Occ=Once1!] :: (Int, Int)) + (w1_sEg [Occ=Once1!] :: Int) -> + case w_sEf of { (ww1_sEj [Occ=Once1!], _ [Occ=Dead]) -> + case ww1_sEj of { GHC.Types.I# ww4_sEm [Occ=Once1] -> + case w1_sEg of { GHC.Types.I# ww6_sEs [Occ=Once1] -> + case Lib.$wfoo ww4_sEm ww6_sEs of ww7_sEw [Occ=Once1] + { __DEFAULT -> + GHC.Types.I# ww7_sEw } } } }}] foo - = \ (w_sHs :: (Int, Int)) (w1_sHt :: Int) -> - case w_sHs of { (ww1_sHw, ww2_sHB) -> - case ww1_sHw of { GHC.Types.I# ww4_sHz -> - case w1_sHt of { GHC.Types.I# ww6_sHF -> - case Lib.$wfoo ww4_sHz ww6_sHF of ww7_sHJ { __DEFAULT -> - GHC.Types.I# ww7_sHJ + = \ (w_sEf :: (Int, Int)) (w1_sEg :: Int) -> + case w_sEf of { (ww1_sEj, ww2_sEo) -> + case ww1_sEj of { GHC.Types.I# ww4_sEm -> + case w1_sEg of { GHC.Types.I# ww6_sEs -> + case Lib.$wfoo ww4_sEm ww6_sEs of ww7_sEw { __DEFAULT -> + GHC.Types.I# ww7_sEw } } } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3bf9cde7313d1d8dc6edd0485a25f3da729de615 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3bf9cde7313d1d8dc6edd0485a25f3da729de615 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 18:20:30 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Wed, 26 Aug 2020 14:20:30 -0400 Subject: [Git][ghc/ghc][wip/happy-1.20] 7 commits: linters: Make CPP linter skip image files Message-ID: <5f46a7ee53a5a_80b3f84942281e095999f2@gitlab.haskell.org.mail> Vladislav Zavialov pushed to branch wip/happy-1.20 at Glasgow Haskell Compiler / GHC Commits: 2d635a50 by Takenobu Tani at 2020-08-26T04:50:21-04:00 linters: Make CPP linter skip image files This patch adds an exclusion rule for `docs/users_guide/images`, to avoid lint errors of PDF files. - - - - - b7d98cb2 by Takenobu Tani at 2020-08-26T04:50:21-04:00 users-guide: Color the logo on the front page of the PDF This patch updates the logo with a recent color scheme. This affects only the PDF version of the user's guide. See also: * https://mail.haskell.org/pipermail/ghc-devs/2020-August/019139.html * https://gitlab.haskell.org/ghc/ghc/-/wikis/logo - - - - - 0b17fa18 by Sylvain Henry at 2020-08-26T04:50:58-04:00 Refactor UnitId pretty-printing When we pretty-print a UnitId for the user, we try to map it back to its origin package name, version and component to print "package-version:component" instead of some hash. The UnitId type doesn't carry these information, so we have to look into a UnitState to find them. This is why the Outputable instance of UnitId used `sdocWithDynFlags` in order to access the `unitState` field of DynFlags. This is wrong for several reasons: 1. The DynFlags are accessed when the message is printed, not when it is generated. So we could imagine that the unitState may have changed in-between. Especially if we want to allow unit unloading. 2. We want GHC to support several independent sessions at once, hence several UnitState. The current approach supposes there is a unique UnitState as a UnitId doesn't indicate which UnitState to use. See the Note [Pretty-printing UnitId] in GHC.Unit for the new approach implemented by this patch. One step closer to remove `sdocDynFlags` field from `SDocContext` (#10143). Fix #18124. Also fix some Backpack code to use SDoc instead of String. - - - - - dc476a50 by Sylvain Henry at 2020-08-26T04:51:35-04:00 Bignum: fix BigNat subtraction (#18604) There was a confusion between the boolean expected by withNewWordArrayTrimedMaybe and the boolean returned by subtracting functions. - - - - - fcb10b6c by Peter Trommler at 2020-08-26T10:42:30-04:00 PPC and X86: Portable printing of IEEE floats GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness. This was brought up in #18431 by @hsyl20. - - - - - 770100e0 by Krzysztof Gogolewski at 2020-08-26T10:43:13-04:00 primops: Remove Monadic and Dyadic categories There were four categories of primops: Monadic, Dyadic, Compare, GenPrimOp. The compiler does not treat Monadic and Dyadic in any special way, we can just replace them with GenPrimOp. Compare is still used in isComparisonPrimOp. - - - - - 86ac4dbf by Vladislav Zavialov at 2020-08-26T21:20:02+03:00 Require happy >=1.20 - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/linters/check-cpp.py - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/Ppr.hs - compiler/GHC/CmmToAsm/SPARC/Ppr.hs - compiler/GHC/CmmToAsm/X86/Ppr.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Driver/Finder.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/Runtime/Eval.hs - compiler/GHC/StgToCmm/Prim.hs - compiler/GHC/Tc/Module.hs - compiler/GHC/Tc/Utils/Backpack.hs - compiler/GHC/Tc/Utils/Instantiate.hs - compiler/GHC/Tc/Utils/Monad.hs - compiler/GHC/Unit.hs - compiler/GHC/Unit/Home.hs - compiler/GHC/Unit/Info.hs - compiler/GHC/Unit/Parser.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c8b84815a4448008c6857f8982fba22ede41650c...86ac4dbff79443509c2acfdefd59d562c48335e7 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c8b84815a4448008c6857f8982fba22ede41650c...86ac4dbff79443509c2acfdefd59d562c48335e7 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Wed Aug 26 23:17:11 2020 From: gitlab at gitlab.haskell.org (Ryan Scott) Date: Wed, 26 Aug 2020 19:17:11 -0400 Subject: [Git][ghc/ghc][wip/T18612] Make {hsExpr, hsType, pat}NeedsParens aware of boxed 1-tuples Message-ID: <5f46ed774c12d_80b3f849426a5cc96089ad@gitlab.haskell.org.mail> Ryan Scott pushed to branch wip/T18612 at Glasgow Haskell Compiler / GHC Commits: 222a8788 by Ryan Scott at 2020-08-26T19:16:56-04:00 Make {hsExpr,hsType,pat}NeedsParens aware of boxed 1-tuples `hsExprNeedsParens`, `hsTypeNeedsParens`, and `patNeedsParens` previously assumed that all uses of explicit tuples in the source syntax never need to be parenthesized. This is true save for one exception: boxed one-tuples, which use the `Solo` data type from `GHC.Tuple` instead of special tuple syntax. This patch adds the necessary logic to the three `*NeedsParens` functions to handle `Solo` correctly. Fixes #18612. - - - - - 6 changed files: - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - + testsuite/tests/th/T18612.hs - + testsuite/tests/th/T18612.stderr - testsuite/tests/th/all.T Changes: ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -1320,6 +1320,11 @@ hsExprNeedsParens p = go go (NegApp{}) = p > topPrec go (SectionL{}) = True go (SectionR{}) = True + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go (ExplicitTuple _ [L _ Present{}] Boxed) + = p >= appPrec go (ExplicitTuple{}) = False go (ExplicitSum{}) = False go (HsLam{}) = p > topPrec ===================================== compiler/GHC/Hs/Pat.hs ===================================== @@ -857,7 +857,12 @@ patNeedsParens p = go go (BangPat {}) = False go (ParPat {}) = False go (AsPat {}) = False - go (TuplePat {}) = False + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go (TuplePat _ [_] Boxed) + = p >= appPrec + go (TuplePat{}) = False go (SumPat {}) = False go (ListPat {}) = False go (LitPat _ l) = hsLitNeedsParens p l ===================================== compiler/GHC/Hs/Type.hs ===================================== @@ -1979,6 +1979,15 @@ hsTypeNeedsParens p = go_hs_ty go_hs_ty (HsRecTy{}) = False go_hs_ty (HsTyVar{}) = False go_hs_ty (HsFunTy{}) = p >= funPrec + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go_hs_ty (HsTupleTy _ con [L _ ty]) + = case con of + HsBoxedTuple -> p >= appPrec + HsBoxedOrConstraintTuple -> p >= appPrec + HsConstraintTuple -> go_hs_ty ty + HsUnboxedTuple -> False go_hs_ty (HsTupleTy{}) = False go_hs_ty (HsSumTy{}) = False go_hs_ty (HsKindSig{}) = p >= sigPrec @@ -1986,6 +1995,11 @@ hsTypeNeedsParens p = go_hs_ty go_hs_ty (HsIParamTy{}) = p > topPrec go_hs_ty (HsSpliceTy{}) = False go_hs_ty (HsExplicitListTy{}) = False + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Proxy ('Solo x)`, not `Proxy 'Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go_hs_ty (HsExplicitTupleTy _ [_]) + = p >= appPrec go_hs_ty (HsExplicitTupleTy{}) = False go_hs_ty (HsTyLit{}) = False go_hs_ty (HsWildCardTy{}) = False ===================================== testsuite/tests/th/T18612.hs ===================================== @@ -0,0 +1,14 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -ddump-splices #-} +module T18612 where + +import Data.Functor.Identity +import Data.Proxy +import Language.Haskell.TH + +f :: $(arrowT `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))) + `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0)))) +f $(conP 'Identity [tupP [tupP []]]) = $(conE 'Identity `appE` tupE [tupE []]) + +type G = $(conT ''Proxy `appT` (promotedTupleT 1 `appT` (tupleT 0))) ===================================== testsuite/tests/th/T18612.stderr ===================================== @@ -0,0 +1,13 @@ +T18612.hs:14:11-68: Splicing type + conT ''Proxy `appT` (promotedTupleT 1 `appT` (tupleT 0)) + ======> + Proxy ('Solo ()) +T18612.hs:(10,7)-(11,75): Splicing type + arrowT `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))) + `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))) + ======> + Identity (Solo ()) -> Identity (Solo ()) +T18612.hs:12:4-36: Splicing pattern + conP 'Identity [tupP [tupP []]] ======> Identity (Solo()) +T18612.hs:12:41-78: Splicing expression + conE 'Identity `appE` tupE [tupE []] ======> Identity (Solo ()) ===================================== testsuite/tests/th/all.T ===================================== @@ -513,3 +513,4 @@ test('T18102b', extra_files(['T18102b_aux.hs']), compile_and_run, ['']) test('T18121', normal, compile, ['']) test('T18123', normal, compile, ['']) test('T18388', normal, compile, ['']) +test('T18612', normal, compile, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/222a878875b0e093e82f81d6f83fa39ac42d53b5 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/222a878875b0e093e82f81d6f83fa39ac42d53b5 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 27 12:19:32 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 27 Aug 2020 08:19:32 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: PPC and X86: Portable printing of IEEE floats Message-ID: <5f47a4d4598e8_80b3f8494cf495c9638162@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: fcb10b6c by Peter Trommler at 2020-08-26T10:42:30-04:00 PPC and X86: Portable printing of IEEE floats GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness. This was brought up in #18431 by @hsyl20. - - - - - 770100e0 by Krzysztof Gogolewski at 2020-08-26T10:43:13-04:00 primops: Remove Monadic and Dyadic categories There were four categories of primops: Monadic, Dyadic, Compare, GenPrimOp. The compiler does not treat Monadic and Dyadic in any special way, we can just replace them with GenPrimOp. Compare is still used in isComparisonPrimOp. - - - - - bcd1cba0 by Aditya Gupta at 2020-08-27T08:19:18-04:00 Consolidate imports in getMinimalImports (#18264) - - - - - e0b3cbda by Ryan Scott at 2020-08-27T08:19:19-04:00 Make {hsExpr,hsType,pat}NeedsParens aware of boxed 1-tuples `hsExprNeedsParens`, `hsTypeNeedsParens`, and `patNeedsParens` previously assumed that all uses of explicit tuples in the source syntax never need to be parenthesized. This is true save for one exception: boxed one-tuples, which use the `Solo` data type from `GHC.Tuple` instead of special tuple syntax. This patch adds the necessary logic to the three `*NeedsParens` functions to handle `Solo` correctly. Fixes #18612. - - - - - 23 changed files: - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/Ppr.hs - compiler/GHC/CmmToAsm/SPARC/Ppr.hs - compiler/GHC/CmmToAsm/X86/Ppr.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Rename/Names.hs - compiler/GHC/StgToCmm/Prim.hs - testsuite/tests/rename/should_compile/Makefile - + testsuite/tests/rename/should_compile/T18264.hs - + testsuite/tests/rename/should_compile/T18264.stdout - testsuite/tests/rename/should_compile/all.T - + testsuite/tests/th/T18612.hs - + testsuite/tests/th/T18612.stderr - testsuite/tests/th/all.T - utils/genprimopcode/Lexer.x - utils/genprimopcode/Main.hs - utils/genprimopcode/Parser.y - utils/genprimopcode/ParserM.hs - utils/genprimopcode/Syntax.hs Changes: ===================================== compiler/GHC/Builtin/PrimOps.hs ===================================== @@ -38,7 +38,7 @@ import GHC.Types.Name import GHC.Builtin.Names ( gHC_PRIMOPWRAPPERS ) import GHC.Core.TyCon ( TyCon, isPrimTyCon, PrimRep(..) ) import GHC.Core.Type -import GHC.Types.RepType ( typePrimRep1, tyConPrimRep1 ) +import GHC.Types.RepType ( tyConPrimRep1 ) import GHC.Types.Basic ( Arity, Fixity(..), FixityDirection(..), Boxity(..), SourceText(..) ) import GHC.Types.SrcLoc ( wiredInSrcSpan ) @@ -103,33 +103,17 @@ tagToEnumKey = mkPrimOpIdUnique (primOpTag TagToEnumOp) \subsection[PrimOp-info]{The essential info about each @PrimOp@} * * ************************************************************************ - -The @String@ in the @PrimOpInfos@ is the ``base name'' by which the user may -refer to the primitive operation. The conventional \tr{#}-for- -unboxed ops is added on later. - -The reason for the funny characters in the names is so we do not -interfere with the programmer's Haskell name spaces. - -We use @PrimKinds@ for the ``type'' information, because they're -(slightly) more convenient to use than @TyCons at . -} data PrimOpInfo - = Dyadic OccName -- string :: T -> T -> T - Type - | Monadic OccName -- string :: T -> T - Type - | Compare OccName -- string :: T -> T -> Int# + = Compare OccName -- string :: T -> T -> Int# Type | GenPrimOp OccName -- string :: \/a1..an . T1 -> .. -> Tk -> T [TyVar] [Type] Type -mkDyadic, mkMonadic, mkCompare :: FastString -> Type -> PrimOpInfo -mkDyadic str ty = Dyadic (mkVarOccFS str) ty -mkMonadic str ty = Monadic (mkVarOccFS str) ty +mkCompare :: FastString -> Type -> PrimOpInfo mkCompare str ty = Compare (mkVarOccFS str) ty mkGenPrimOp :: FastString -> [TyVar] -> [Type] -> Type -> PrimOpInfo @@ -575,8 +559,6 @@ primOpCodeSizeForeignCall = 4 primOpType :: PrimOp -> Type -- you may want to use primOpSig instead primOpType op = case primOpInfo op of - Dyadic _occ ty -> dyadic_fun_ty ty - Monadic _occ ty -> monadic_fun_ty ty Compare _occ ty -> compare_fun_ty ty GenPrimOp _occ tyvars arg_tys res_ty -> @@ -585,15 +567,11 @@ primOpType op primOpResultType :: PrimOp -> Type primOpResultType op = case primOpInfo op of - Dyadic _occ ty -> ty - Monadic _occ ty -> ty Compare _occ _ty -> intPrimTy GenPrimOp _occ _tyvars _arg_tys res_ty -> res_ty primOpOcc :: PrimOp -> OccName primOpOcc op = case primOpInfo op of - Dyadic occ _ -> occ - Monadic occ _ -> occ Compare occ _ -> occ GenPrimOp occ _ _ _ -> occ @@ -692,8 +670,8 @@ primOpWrapperId op = mkVanillaGlobalWithInfo name ty info isComparisonPrimOp :: PrimOp -> Bool isComparisonPrimOp op = case primOpInfo op of - Compare {} -> True - _ -> False + Compare {} -> True + GenPrimOp {} -> False -- primOpSig is like primOpType but gives the result split apart: -- (type variables, argument types, result type) @@ -706,8 +684,6 @@ primOpSig op arity = length arg_tys (tyvars, arg_tys, res_ty) = case (primOpInfo op) of - Monadic _occ ty -> ([], [ty], ty ) - Dyadic _occ ty -> ([], [ty,ty], ty ) Compare _occ ty -> ([], [ty,ty], intPrimTy) GenPrimOp _occ tyvars arg_tys res_ty -> (tyvars, arg_tys, res_ty ) @@ -722,8 +698,6 @@ data PrimOpResultInfo getPrimOpResultInfo :: PrimOp -> PrimOpResultInfo getPrimOpResultInfo op = case (primOpInfo op) of - Dyadic _ ty -> ReturnsPrim (typePrimRep1 ty) - Monadic _ ty -> ReturnsPrim (typePrimRep1 ty) Compare _ _ -> ReturnsPrim (tyConPrimRep1 intPrimTyCon) GenPrimOp _ _ _ ty | isPrimTyCon tc -> ReturnsPrim (tyConPrimRep1 tc) | otherwise -> ReturnsAlg tc @@ -747,9 +721,7 @@ commutableOp :: PrimOp -> Bool -- Utils: -dyadic_fun_ty, monadic_fun_ty, compare_fun_ty :: Type -> Type -dyadic_fun_ty ty = mkVisFunTysMany [ty, ty] ty -monadic_fun_ty ty = mkVisFunTyMany ty ty +compare_fun_ty :: Type -> Type compare_fun_ty ty = mkVisFunTysMany [ty, ty] intPrimTy -- Output stuff: ===================================== compiler/GHC/Builtin/primops.txt.pp ===================================== @@ -42,11 +42,9 @@ -- (eg, out_of_line), whilst avoiding parsing complex expressions -- needed for strictness info. -- --- type refers to the general category of the primop. Valid settings include, +-- type refers to the general category of the primop. There are only two: -- -- * Compare: A comparison operation of the shape a -> a -> Int# --- * Monadic: A unary operation of shape a -> a --- * Dyadic: A binary operation of shape a -> a -> a -- * GenPrimOp: Any other sort of primop -- @@ -238,23 +236,23 @@ primtype Int8# primop Int8Extend "extendInt8#" GenPrimOp Int8# -> Int# primop Int8Narrow "narrowInt8#" GenPrimOp Int# -> Int8# -primop Int8NegOp "negateInt8#" Monadic Int8# -> Int8# +primop Int8NegOp "negateInt8#" GenPrimOp Int8# -> Int8# -primop Int8AddOp "plusInt8#" Dyadic Int8# -> Int8# -> Int8# +primop Int8AddOp "plusInt8#" GenPrimOp Int8# -> Int8# -> Int8# with commutable = True -primop Int8SubOp "subInt8#" Dyadic Int8# -> Int8# -> Int8# +primop Int8SubOp "subInt8#" GenPrimOp Int8# -> Int8# -> Int8# -primop Int8MulOp "timesInt8#" Dyadic Int8# -> Int8# -> Int8# +primop Int8MulOp "timesInt8#" GenPrimOp Int8# -> Int8# -> Int8# with commutable = True -primop Int8QuotOp "quotInt8#" Dyadic Int8# -> Int8# -> Int8# +primop Int8QuotOp "quotInt8#" GenPrimOp Int8# -> Int8# -> Int8# with can_fail = True -primop Int8RemOp "remInt8#" Dyadic Int8# -> Int8# -> Int8# +primop Int8RemOp "remInt8#" GenPrimOp Int8# -> Int8# -> Int8# with can_fail = True @@ -279,23 +277,23 @@ primtype Word8# primop Word8Extend "extendWord8#" GenPrimOp Word8# -> Word# primop Word8Narrow "narrowWord8#" GenPrimOp Word# -> Word8# -primop Word8NotOp "notWord8#" Monadic Word8# -> Word8# +primop Word8NotOp "notWord8#" GenPrimOp Word8# -> Word8# -primop Word8AddOp "plusWord8#" Dyadic Word8# -> Word8# -> Word8# +primop Word8AddOp "plusWord8#" GenPrimOp Word8# -> Word8# -> Word8# with commutable = True -primop Word8SubOp "subWord8#" Dyadic Word8# -> Word8# -> Word8# +primop Word8SubOp "subWord8#" GenPrimOp Word8# -> Word8# -> Word8# -primop Word8MulOp "timesWord8#" Dyadic Word8# -> Word8# -> Word8# +primop Word8MulOp "timesWord8#" GenPrimOp Word8# -> Word8# -> Word8# with commutable = True -primop Word8QuotOp "quotWord8#" Dyadic Word8# -> Word8# -> Word8# +primop Word8QuotOp "quotWord8#" GenPrimOp Word8# -> Word8# -> Word8# with can_fail = True -primop Word8RemOp "remWord8#" Dyadic Word8# -> Word8# -> Word8# +primop Word8RemOp "remWord8#" GenPrimOp Word8# -> Word8# -> Word8# with can_fail = True @@ -320,23 +318,23 @@ primtype Int16# primop Int16Extend "extendInt16#" GenPrimOp Int16# -> Int# primop Int16Narrow "narrowInt16#" GenPrimOp Int# -> Int16# -primop Int16NegOp "negateInt16#" Monadic Int16# -> Int16# +primop Int16NegOp "negateInt16#" GenPrimOp Int16# -> Int16# -primop Int16AddOp "plusInt16#" Dyadic Int16# -> Int16# -> Int16# +primop Int16AddOp "plusInt16#" GenPrimOp Int16# -> Int16# -> Int16# with commutable = True -primop Int16SubOp "subInt16#" Dyadic Int16# -> Int16# -> Int16# +primop Int16SubOp "subInt16#" GenPrimOp Int16# -> Int16# -> Int16# -primop Int16MulOp "timesInt16#" Dyadic Int16# -> Int16# -> Int16# +primop Int16MulOp "timesInt16#" GenPrimOp Int16# -> Int16# -> Int16# with commutable = True -primop Int16QuotOp "quotInt16#" Dyadic Int16# -> Int16# -> Int16# +primop Int16QuotOp "quotInt16#" GenPrimOp Int16# -> Int16# -> Int16# with can_fail = True -primop Int16RemOp "remInt16#" Dyadic Int16# -> Int16# -> Int16# +primop Int16RemOp "remInt16#" GenPrimOp Int16# -> Int16# -> Int16# with can_fail = True @@ -361,23 +359,23 @@ primtype Word16# primop Word16Extend "extendWord16#" GenPrimOp Word16# -> Word# primop Word16Narrow "narrowWord16#" GenPrimOp Word# -> Word16# -primop Word16NotOp "notWord16#" Monadic Word16# -> Word16# +primop Word16NotOp "notWord16#" GenPrimOp Word16# -> Word16# -primop Word16AddOp "plusWord16#" Dyadic Word16# -> Word16# -> Word16# +primop Word16AddOp "plusWord16#" GenPrimOp Word16# -> Word16# -> Word16# with commutable = True -primop Word16SubOp "subWord16#" Dyadic Word16# -> Word16# -> Word16# +primop Word16SubOp "subWord16#" GenPrimOp Word16# -> Word16# -> Word16# -primop Word16MulOp "timesWord16#" Dyadic Word16# -> Word16# -> Word16# +primop Word16MulOp "timesWord16#" GenPrimOp Word16# -> Word16# -> Word16# with commutable = True -primop Word16QuotOp "quotWord16#" Dyadic Word16# -> Word16# -> Word16# +primop Word16QuotOp "quotWord16#" GenPrimOp Word16# -> Word16# -> Word16# with can_fail = True -primop Word16RemOp "remWord16#" Dyadic Word16# -> Word16# -> Word16# +primop Word16RemOp "remWord16#" GenPrimOp Word16# -> Word16# -> Word16# with can_fail = True @@ -420,16 +418,16 @@ section "Int#" primtype Int# -primop IntAddOp "+#" Dyadic +primop IntAddOp "+#" GenPrimOp Int# -> Int# -> Int# with commutable = True fixity = infixl 6 -primop IntSubOp "-#" Dyadic Int# -> Int# -> Int# +primop IntSubOp "-#" GenPrimOp Int# -> Int# -> Int# with fixity = infixl 6 primop IntMulOp "*#" - Dyadic Int# -> Int# -> Int# + GenPrimOp Int# -> Int# -> Int# {Low word of signed integer multiply.} with commutable = True fixity = infixl 7 @@ -442,7 +440,7 @@ primop IntMul2Op "timesInt2#" GenPrimOp 0#) or not (isHighNeeded = 1#).} primop IntMulMayOfloOp "mulIntMayOflo#" - Dyadic Int# -> Int# -> Int# + GenPrimOp Int# -> Int# -> Int# {Return non-zero if there is any possibility that the upper word of a signed integer multiply might contain useful information. Return zero only if you are completely sure that no overflow can occur. @@ -465,14 +463,14 @@ primop IntMulMayOfloOp "mulIntMayOflo#" } with commutable = True -primop IntQuotOp "quotInt#" Dyadic +primop IntQuotOp "quotInt#" GenPrimOp Int# -> Int# -> Int# {Rounds towards zero. The behavior is undefined if the second argument is zero. } with can_fail = True -primop IntRemOp "remInt#" Dyadic +primop IntRemOp "remInt#" GenPrimOp Int# -> Int# -> Int# {Satisfies \texttt{(quotInt\# x y) *\# y +\# (remInt\# x y) == x}. The behavior is undefined if the second argument is zero. @@ -484,22 +482,22 @@ primop IntQuotRemOp "quotRemInt#" GenPrimOp {Rounds towards zero.} with can_fail = True -primop AndIOp "andI#" Dyadic Int# -> Int# -> Int# +primop AndIOp "andI#" GenPrimOp Int# -> Int# -> Int# {Bitwise "and".} with commutable = True -primop OrIOp "orI#" Dyadic Int# -> Int# -> Int# +primop OrIOp "orI#" GenPrimOp Int# -> Int# -> Int# {Bitwise "or".} with commutable = True -primop XorIOp "xorI#" Dyadic Int# -> Int# -> Int# +primop XorIOp "xorI#" GenPrimOp Int# -> Int# -> Int# {Bitwise "xor".} with commutable = True -primop NotIOp "notI#" Monadic Int# -> Int# +primop NotIOp "notI#" GenPrimOp Int# -> Int# {Bitwise "not", also known as the binary complement.} -primop IntNegOp "negateInt#" Monadic Int# -> Int# +primop IntNegOp "negateInt#" GenPrimOp Int# -> Int# {Unary negation. Since the negative {\tt Int#} range extends one further than the positive range, {\tt negateInt#} of the most negative number is an @@ -573,7 +571,7 @@ section "Word#" primtype Word# -primop WordAddOp "plusWord#" Dyadic Word# -> Word# -> Word# +primop WordAddOp "plusWord#" GenPrimOp Word# -> Word# -> Word# with commutable = True primop WordAddCOp "addWordC#" GenPrimOp Word# -> Word# -> (# Word#, Int# #) @@ -596,9 +594,9 @@ primop WordAdd2Op "plusWord2#" GenPrimOp Word# -> Word# -> (# Word#, Wor with code_size = 2 commutable = True -primop WordSubOp "minusWord#" Dyadic Word# -> Word# -> Word# +primop WordSubOp "minusWord#" GenPrimOp Word# -> Word# -> Word# -primop WordMulOp "timesWord#" Dyadic Word# -> Word# -> Word# +primop WordMulOp "timesWord#" GenPrimOp Word# -> Word# -> Word# with commutable = True -- Returns (# high, low #) @@ -606,10 +604,10 @@ primop WordMul2Op "timesWord2#" GenPrimOp Word# -> Word# -> (# Word#, Word# #) with commutable = True -primop WordQuotOp "quotWord#" Dyadic Word# -> Word# -> Word# +primop WordQuotOp "quotWord#" GenPrimOp Word# -> Word# -> Word# with can_fail = True -primop WordRemOp "remWord#" Dyadic Word# -> Word# -> Word# +primop WordRemOp "remWord#" GenPrimOp Word# -> Word# -> Word# with can_fail = True primop WordQuotRemOp "quotRemWord#" GenPrimOp @@ -622,16 +620,16 @@ primop WordQuotRem2Op "quotRemWord2#" GenPrimOp Requires that high word < divisor.} with can_fail = True -primop AndOp "and#" Dyadic Word# -> Word# -> Word# +primop AndOp "and#" GenPrimOp Word# -> Word# -> Word# with commutable = True -primop OrOp "or#" Dyadic Word# -> Word# -> Word# +primop OrOp "or#" GenPrimOp Word# -> Word# -> Word# with commutable = True -primop XorOp "xor#" Dyadic Word# -> Word# -> Word# +primop XorOp "xor#" GenPrimOp Word# -> Word# -> Word# with commutable = True -primop NotOp "not#" Monadic Word# -> Word# +primop NotOp "not#" GenPrimOp Word# -> Word# primop SllOp "uncheckedShiftL#" GenPrimOp Word# -> Int# -> Word# {Shift left logical. Result undefined if shift amount is not @@ -650,79 +648,79 @@ primop WordNeOp "neWord#" Compare Word# -> Word# -> Int# primop WordLtOp "ltWord#" Compare Word# -> Word# -> Int# primop WordLeOp "leWord#" Compare Word# -> Word# -> Int# -primop PopCnt8Op "popCnt8#" Monadic Word# -> Word# +primop PopCnt8Op "popCnt8#" GenPrimOp Word# -> Word# {Count the number of set bits in the lower 8 bits of a word.} -primop PopCnt16Op "popCnt16#" Monadic Word# -> Word# +primop PopCnt16Op "popCnt16#" GenPrimOp Word# -> Word# {Count the number of set bits in the lower 16 bits of a word.} -primop PopCnt32Op "popCnt32#" Monadic Word# -> Word# +primop PopCnt32Op "popCnt32#" GenPrimOp Word# -> Word# {Count the number of set bits in the lower 32 bits of a word.} primop PopCnt64Op "popCnt64#" GenPrimOp WORD64 -> Word# {Count the number of set bits in a 64-bit word.} -primop PopCntOp "popCnt#" Monadic Word# -> Word# +primop PopCntOp "popCnt#" GenPrimOp Word# -> Word# {Count the number of set bits in a word.} -primop Pdep8Op "pdep8#" Dyadic Word# -> Word# -> Word# +primop Pdep8Op "pdep8#" GenPrimOp Word# -> Word# -> Word# {Deposit bits to lower 8 bits of a word at locations specified by a mask.} -primop Pdep16Op "pdep16#" Dyadic Word# -> Word# -> Word# +primop Pdep16Op "pdep16#" GenPrimOp Word# -> Word# -> Word# {Deposit bits to lower 16 bits of a word at locations specified by a mask.} -primop Pdep32Op "pdep32#" Dyadic Word# -> Word# -> Word# +primop Pdep32Op "pdep32#" GenPrimOp Word# -> Word# -> Word# {Deposit bits to lower 32 bits of a word at locations specified by a mask.} primop Pdep64Op "pdep64#" GenPrimOp WORD64 -> WORD64 -> WORD64 {Deposit bits to a word at locations specified by a mask.} -primop PdepOp "pdep#" Dyadic Word# -> Word# -> Word# +primop PdepOp "pdep#" GenPrimOp Word# -> Word# -> Word# {Deposit bits to a word at locations specified by a mask.} -primop Pext8Op "pext8#" Dyadic Word# -> Word# -> Word# +primop Pext8Op "pext8#" GenPrimOp Word# -> Word# -> Word# {Extract bits from lower 8 bits of a word at locations specified by a mask.} -primop Pext16Op "pext16#" Dyadic Word# -> Word# -> Word# +primop Pext16Op "pext16#" GenPrimOp Word# -> Word# -> Word# {Extract bits from lower 16 bits of a word at locations specified by a mask.} -primop Pext32Op "pext32#" Dyadic Word# -> Word# -> Word# +primop Pext32Op "pext32#" GenPrimOp Word# -> Word# -> Word# {Extract bits from lower 32 bits of a word at locations specified by a mask.} primop Pext64Op "pext64#" GenPrimOp WORD64 -> WORD64 -> WORD64 {Extract bits from a word at locations specified by a mask.} -primop PextOp "pext#" Dyadic Word# -> Word# -> Word# +primop PextOp "pext#" GenPrimOp Word# -> Word# -> Word# {Extract bits from a word at locations specified by a mask.} -primop Clz8Op "clz8#" Monadic Word# -> Word# +primop Clz8Op "clz8#" GenPrimOp Word# -> Word# {Count leading zeros in the lower 8 bits of a word.} -primop Clz16Op "clz16#" Monadic Word# -> Word# +primop Clz16Op "clz16#" GenPrimOp Word# -> Word# {Count leading zeros in the lower 16 bits of a word.} -primop Clz32Op "clz32#" Monadic Word# -> Word# +primop Clz32Op "clz32#" GenPrimOp Word# -> Word# {Count leading zeros in the lower 32 bits of a word.} primop Clz64Op "clz64#" GenPrimOp WORD64 -> Word# {Count leading zeros in a 64-bit word.} -primop ClzOp "clz#" Monadic Word# -> Word# +primop ClzOp "clz#" GenPrimOp Word# -> Word# {Count leading zeros in a word.} -primop Ctz8Op "ctz8#" Monadic Word# -> Word# +primop Ctz8Op "ctz8#" GenPrimOp Word# -> Word# {Count trailing zeros in the lower 8 bits of a word.} -primop Ctz16Op "ctz16#" Monadic Word# -> Word# +primop Ctz16Op "ctz16#" GenPrimOp Word# -> Word# {Count trailing zeros in the lower 16 bits of a word.} -primop Ctz32Op "ctz32#" Monadic Word# -> Word# +primop Ctz32Op "ctz32#" GenPrimOp Word# -> Word# {Count trailing zeros in the lower 32 bits of a word.} primop Ctz64Op "ctz64#" GenPrimOp WORD64 -> Word# {Count trailing zeros in a 64-bit word.} -primop CtzOp "ctz#" Monadic Word# -> Word# +primop CtzOp "ctz#" GenPrimOp Word# -> Word# {Count trailing zeros in a word.} -primop BSwap16Op "byteSwap16#" Monadic Word# -> Word# +primop BSwap16Op "byteSwap16#" GenPrimOp Word# -> Word# {Swap bytes in the lower 16 bits of a word. The higher bytes are undefined. } -primop BSwap32Op "byteSwap32#" Monadic Word# -> Word# +primop BSwap32Op "byteSwap32#" GenPrimOp Word# -> Word# {Swap bytes in the lower 32 bits of a word. The higher bytes are undefined. } -primop BSwap64Op "byteSwap64#" Monadic WORD64 -> WORD64 +primop BSwap64Op "byteSwap64#" GenPrimOp WORD64 -> WORD64 {Swap bytes in a 64 bits of a word.} -primop BSwapOp "byteSwap#" Monadic Word# -> Word# +primop BSwapOp "byteSwap#" GenPrimOp Word# -> Word# {Swap bytes in a word.} -primop BRev8Op "bitReverse8#" Monadic Word# -> Word# +primop BRev8Op "bitReverse8#" GenPrimOp Word# -> Word# {Reverse the order of the bits in a 8-bit word.} -primop BRev16Op "bitReverse16#" Monadic Word# -> Word# +primop BRev16Op "bitReverse16#" GenPrimOp Word# -> Word# {Reverse the order of the bits in a 16-bit word.} -primop BRev32Op "bitReverse32#" Monadic Word# -> Word# +primop BRev32Op "bitReverse32#" GenPrimOp Word# -> Word# {Reverse the order of the bits in a 32-bit word.} -primop BRev64Op "bitReverse64#" Monadic WORD64 -> WORD64 +primop BRev64Op "bitReverse64#" GenPrimOp WORD64 -> WORD64 {Reverse the order of the bits in a 64-bit word.} -primop BRevOp "bitReverse#" Monadic Word# -> Word# +primop BRevOp "bitReverse#" GenPrimOp Word# -> Word# {Reverse the order of the bits in a word.} ------------------------------------------------------------------------ @@ -730,12 +728,12 @@ section "Narrowings" {Explicit narrowing of native-sized ints or words.} ------------------------------------------------------------------------ -primop Narrow8IntOp "narrow8Int#" Monadic Int# -> Int# -primop Narrow16IntOp "narrow16Int#" Monadic Int# -> Int# -primop Narrow32IntOp "narrow32Int#" Monadic Int# -> Int# -primop Narrow8WordOp "narrow8Word#" Monadic Word# -> Word# -primop Narrow16WordOp "narrow16Word#" Monadic Word# -> Word# -primop Narrow32WordOp "narrow32Word#" Monadic Word# -> Word# +primop Narrow8IntOp "narrow8Int#" GenPrimOp Int# -> Int# +primop Narrow16IntOp "narrow16Int#" GenPrimOp Int# -> Int# +primop Narrow32IntOp "narrow32Int#" GenPrimOp Int# -> Int# +primop Narrow8WordOp "narrow8Word#" GenPrimOp Word# -> Word# +primop Narrow16WordOp "narrow16Word#" GenPrimOp Word# -> Word# +primop Narrow32WordOp "narrow32Word#" GenPrimOp Word# -> Word# ------------------------------------------------------------------------ section "Double#" @@ -766,27 +764,27 @@ primop DoubleLtOp "<##" Compare Double# -> Double# -> Int# primop DoubleLeOp "<=##" Compare Double# -> Double# -> Int# with fixity = infix 4 -primop DoubleAddOp "+##" Dyadic +primop DoubleAddOp "+##" GenPrimOp Double# -> Double# -> Double# with commutable = True fixity = infixl 6 -primop DoubleSubOp "-##" Dyadic Double# -> Double# -> Double# +primop DoubleSubOp "-##" GenPrimOp Double# -> Double# -> Double# with fixity = infixl 6 -primop DoubleMulOp "*##" Dyadic +primop DoubleMulOp "*##" GenPrimOp Double# -> Double# -> Double# with commutable = True fixity = infixl 7 -primop DoubleDivOp "/##" Dyadic +primop DoubleDivOp "/##" GenPrimOp Double# -> Double# -> Double# with can_fail = True fixity = infixl 7 -primop DoubleNegOp "negateDouble#" Monadic Double# -> Double# +primop DoubleNegOp "negateDouble#" GenPrimOp Double# -> Double# -primop DoubleFabsOp "fabsDouble#" Monadic Double# -> Double# +primop DoubleFabsOp "fabsDouble#" GenPrimOp Double# -> Double# primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int# {Truncates a {\tt Double#} value to the nearest {\tt Int#}. @@ -795,96 +793,96 @@ primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int# primop Double2FloatOp "double2Float#" GenPrimOp Double# -> Float# -primop DoubleExpOp "expDouble#" Monadic +primop DoubleExpOp "expDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleExpM1Op "expm1Double#" Monadic +primop DoubleExpM1Op "expm1Double#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleLogOp "logDouble#" Monadic +primop DoubleLogOp "logDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop DoubleLog1POp "log1pDouble#" Monadic +primop DoubleLog1POp "log1pDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop DoubleSqrtOp "sqrtDouble#" Monadic +primop DoubleSqrtOp "sqrtDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleSinOp "sinDouble#" Monadic +primop DoubleSinOp "sinDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleCosOp "cosDouble#" Monadic +primop DoubleCosOp "cosDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleTanOp "tanDouble#" Monadic +primop DoubleTanOp "tanDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleAsinOp "asinDouble#" Monadic +primop DoubleAsinOp "asinDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop DoubleAcosOp "acosDouble#" Monadic +primop DoubleAcosOp "acosDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop DoubleAtanOp "atanDouble#" Monadic +primop DoubleAtanOp "atanDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleSinhOp "sinhDouble#" Monadic +primop DoubleSinhOp "sinhDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleCoshOp "coshDouble#" Monadic +primop DoubleCoshOp "coshDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleTanhOp "tanhDouble#" Monadic +primop DoubleTanhOp "tanhDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleAsinhOp "asinhDouble#" Monadic +primop DoubleAsinhOp "asinhDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleAcoshOp "acoshDouble#" Monadic +primop DoubleAcoshOp "acoshDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoubleAtanhOp "atanhDouble#" Monadic +primop DoubleAtanhOp "atanhDouble#" GenPrimOp Double# -> Double# with code_size = { primOpCodeSizeForeignCall } -primop DoublePowerOp "**##" Dyadic +primop DoublePowerOp "**##" GenPrimOp Double# -> Double# -> Double# {Exponentiation.} with @@ -924,119 +922,119 @@ primop FloatNeOp "neFloat#" Compare primop FloatLtOp "ltFloat#" Compare Float# -> Float# -> Int# primop FloatLeOp "leFloat#" Compare Float# -> Float# -> Int# -primop FloatAddOp "plusFloat#" Dyadic +primop FloatAddOp "plusFloat#" GenPrimOp Float# -> Float# -> Float# with commutable = True -primop FloatSubOp "minusFloat#" Dyadic Float# -> Float# -> Float# +primop FloatSubOp "minusFloat#" GenPrimOp Float# -> Float# -> Float# -primop FloatMulOp "timesFloat#" Dyadic +primop FloatMulOp "timesFloat#" GenPrimOp Float# -> Float# -> Float# with commutable = True -primop FloatDivOp "divideFloat#" Dyadic +primop FloatDivOp "divideFloat#" GenPrimOp Float# -> Float# -> Float# with can_fail = True -primop FloatNegOp "negateFloat#" Monadic Float# -> Float# +primop FloatNegOp "negateFloat#" GenPrimOp Float# -> Float# -primop FloatFabsOp "fabsFloat#" Monadic Float# -> Float# +primop FloatFabsOp "fabsFloat#" GenPrimOp Float# -> Float# primop Float2IntOp "float2Int#" GenPrimOp Float# -> Int# {Truncates a {\tt Float#} value to the nearest {\tt Int#}. Results are undefined if the truncation if truncation yields a value outside the range of {\tt Int#}.} -primop FloatExpOp "expFloat#" Monadic +primop FloatExpOp "expFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatExpM1Op "expm1Float#" Monadic +primop FloatExpM1Op "expm1Float#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatLogOp "logFloat#" Monadic +primop FloatLogOp "logFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop FloatLog1POp "log1pFloat#" Monadic +primop FloatLog1POp "log1pFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop FloatSqrtOp "sqrtFloat#" Monadic +primop FloatSqrtOp "sqrtFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatSinOp "sinFloat#" Monadic +primop FloatSinOp "sinFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatCosOp "cosFloat#" Monadic +primop FloatCosOp "cosFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatTanOp "tanFloat#" Monadic +primop FloatTanOp "tanFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatAsinOp "asinFloat#" Monadic +primop FloatAsinOp "asinFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop FloatAcosOp "acosFloat#" Monadic +primop FloatAcosOp "acosFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } can_fail = True -primop FloatAtanOp "atanFloat#" Monadic +primop FloatAtanOp "atanFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatSinhOp "sinhFloat#" Monadic +primop FloatSinhOp "sinhFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatCoshOp "coshFloat#" Monadic +primop FloatCoshOp "coshFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatTanhOp "tanhFloat#" Monadic +primop FloatTanhOp "tanhFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatAsinhOp "asinhFloat#" Monadic +primop FloatAsinhOp "asinhFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatAcoshOp "acoshFloat#" Monadic +primop FloatAcoshOp "acoshFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatAtanhOp "atanhFloat#" Monadic +primop FloatAtanhOp "atanhFloat#" GenPrimOp Float# -> Float# with code_size = { primOpCodeSizeForeignCall } -primop FloatPowerOp "powerFloat#" Dyadic +primop FloatPowerOp "powerFloat#" GenPrimOp Float# -> Float# -> Float# with code_size = { primOpCodeSizeForeignCall } @@ -3575,48 +3573,48 @@ primop VecInsertOp "insert#" GenPrimOp llvm_only = True vector = ALL_VECTOR_TYPES -primop VecAddOp "plus#" Dyadic +primop VecAddOp "plus#" GenPrimOp VECTOR -> VECTOR -> VECTOR { Add two vectors element-wise. } with commutable = True llvm_only = True vector = ALL_VECTOR_TYPES -primop VecSubOp "minus#" Dyadic +primop VecSubOp "minus#" GenPrimOp VECTOR -> VECTOR -> VECTOR { Subtract two vectors element-wise. } with llvm_only = True vector = ALL_VECTOR_TYPES -primop VecMulOp "times#" Dyadic +primop VecMulOp "times#" GenPrimOp VECTOR -> VECTOR -> VECTOR { Multiply two vectors element-wise. } with commutable = True llvm_only = True vector = ALL_VECTOR_TYPES -primop VecDivOp "divide#" Dyadic +primop VecDivOp "divide#" GenPrimOp VECTOR -> VECTOR -> VECTOR { Divide two vectors element-wise. } with can_fail = True llvm_only = True vector = FLOAT_VECTOR_TYPES -primop VecQuotOp "quot#" Dyadic +primop VecQuotOp "quot#" GenPrimOp VECTOR -> VECTOR -> VECTOR { Rounds towards zero element-wise. } with can_fail = True llvm_only = True vector = INT_VECTOR_TYPES -primop VecRemOp "rem#" Dyadic +primop VecRemOp "rem#" GenPrimOp VECTOR -> VECTOR -> VECTOR { Satisfies \texttt{(quot\# x y) times\# y plus\# (rem\# x y) == x}. } with can_fail = True llvm_only = True vector = INT_VECTOR_TYPES -primop VecNegOp "negate#" Monadic +primop VecNegOp "negate#" GenPrimOp VECTOR -> VECTOR { Negate element-wise. } with llvm_only = True ===================================== compiler/GHC/CmmToAsm/PPC/Ppr.hs ===================================== @@ -237,9 +237,8 @@ pprImm (ImmInteger i) = integer i pprImm (ImmCLbl l) = ppr l pprImm (ImmIndex l i) = ppr l <> char '+' <> int i pprImm (ImmLit s) = s - -pprImm (ImmFloat _) = text "naughty float immediate" -pprImm (ImmDouble _) = text "naughty double immediate" +pprImm (ImmFloat f) = float $ fromRational f +pprImm (ImmDouble d) = double $ fromRational d pprImm (ImmConstantSum a b) = pprImm a <> char '+' <> pprImm b pprImm (ImmConstantDiff a b) = pprImm a <> char '-' @@ -337,13 +336,8 @@ pprDataItem platform lit <> int (fromIntegral (fromIntegral x :: Word32))] - ppr_item FF32 (CmmFloat r _) - = let bs = floatToBytes (fromRational r) - in map (\b -> text "\t.byte\t" <> pprImm (ImmInt b)) bs - - ppr_item FF64 (CmmFloat r _) - = let bs = doubleToBytes (fromRational r) - in map (\b -> text "\t.byte\t" <> pprImm (ImmInt b)) bs + ppr_item FF32 _ = [text "\t.float\t" <> pprImm imm] + ppr_item FF64 _ = [text "\t.double\t" <> pprImm imm] ppr_item _ _ = panic "PPC.Ppr.pprDataItem: no match" ===================================== compiler/GHC/CmmToAsm/Ppr.hs ===================================== @@ -9,9 +9,6 @@ ----------------------------------------------------------------------------- module GHC.CmmToAsm.Ppr ( - castFloatToWord8Array, - castDoubleToWord8Array, - floatToBytes, doubleToBytes, pprASCII, pprString, @@ -44,13 +41,13 @@ import qualified Data.ByteString as BS import GHC.Exts import GHC.Word - - -- ----------------------------------------------------------------------------- -- Converting floating-point literals to integrals for printing -castFloatToWord8Array :: STUArray s Int Float -> ST s (STUArray s Int Word8) -castFloatToWord8Array = U.castSTUArray +-- ToDo: this code is currently shared between SPARC and LLVM. +-- Similar functions for (single precision) floats are +-- present in the SPARC backend only. We need to fix both +-- LLVM and SPARC. castDoubleToWord8Array :: STUArray s Int Double -> ST s (STUArray s Int Word8) castDoubleToWord8Array = U.castSTUArray @@ -63,19 +60,6 @@ castDoubleToWord8Array = U.castSTUArray -- ToDo: this stuff is very similar to the shenanigans in PprAbs, -- could they be merged? -floatToBytes :: Float -> [Int] -floatToBytes f - = runST (do - arr <- newArray_ ((0::Int),3) - writeArray arr 0 f - arr <- castFloatToWord8Array arr - i0 <- readArray arr 0 - i1 <- readArray arr 1 - i2 <- readArray arr 2 - i3 <- readArray arr 3 - return (map fromIntegral [i0,i1,i2,i3]) - ) - doubleToBytes :: Double -> [Int] doubleToBytes d = runST (do ===================================== compiler/GHC/CmmToAsm/SPARC/Ppr.hs ===================================== @@ -25,6 +25,12 @@ where import GHC.Prelude +import Data.Word +import qualified Data.Array.Unsafe as U ( castSTUArray ) +import Data.Array.ST + +import Control.Monad.ST + import GHC.CmmToAsm.SPARC.Regs import GHC.CmmToAsm.SPARC.Instr import GHC.CmmToAsm.SPARC.Cond @@ -369,6 +375,22 @@ pprDataItem platform lit ppr_item II64 _ = [text "\t.quad\t" <> pprImm imm] ppr_item _ _ = panic "SPARC.Ppr.pprDataItem: no match" +floatToBytes :: Float -> [Int] +floatToBytes f + = runST (do + arr <- newArray_ ((0::Int),3) + writeArray arr 0 f + arr <- castFloatToWord8Array arr + i0 <- readArray arr 0 + i1 <- readArray arr 1 + i2 <- readArray arr 2 + i3 <- readArray arr 3 + return (map fromIntegral [i0,i1,i2,i3]) + ) + +castFloatToWord8Array :: STUArray s Int Float -> ST s (STUArray s Int Word8) +castFloatToWord8Array = U.castSTUArray + -- | Pretty print an instruction. pprInstr :: Instr -> SDoc ===================================== compiler/GHC/CmmToAsm/X86/Ppr.hs ===================================== @@ -423,9 +423,8 @@ pprImm (ImmInteger i) = integer i pprImm (ImmCLbl l) = ppr l pprImm (ImmIndex l i) = ppr l <> char '+' <> int i pprImm (ImmLit s) = s - -pprImm (ImmFloat _) = text "naughty float immediate" -pprImm (ImmDouble _) = text "naughty double immediate" +pprImm (ImmFloat f) = float $ fromRational f +pprImm (ImmDouble d) = double $ fromRational d pprImm (ImmConstantSum a b) = pprImm a <> char '+' <> pprImm b pprImm (ImmConstantDiff a b) = pprImm a <> char '-' @@ -514,13 +513,8 @@ pprDataItem config lit ppr_item II16 _ = [text "\t.word\t" <> pprImm imm] ppr_item II32 _ = [text "\t.long\t" <> pprImm imm] - ppr_item FF32 (CmmFloat r _) - = let bs = floatToBytes (fromRational r) - in map (\b -> text "\t.byte\t" <> pprImm (ImmInt b)) bs - - ppr_item FF64 (CmmFloat r _) - = let bs = doubleToBytes (fromRational r) - in map (\b -> text "\t.byte\t" <> pprImm (ImmInt b)) bs + ppr_item FF32 _ = [text "\t.float\t" <> pprImm imm] + ppr_item FF64 _ = [text "\t.double\t" <> pprImm imm] ppr_item II64 _ = case platformOS platform of @@ -558,9 +552,6 @@ pprDataItem config lit _ -> [text "\t.quad\t" <> pprImm imm] - ppr_item _ _ - = panic "X86.Ppr.ppr_item: no match" - asmComment :: SDoc -> SDoc asmComment c = whenPprDebug $ text "# " <> c ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -1320,6 +1320,11 @@ hsExprNeedsParens p = go go (NegApp{}) = p > topPrec go (SectionL{}) = True go (SectionR{}) = True + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go (ExplicitTuple _ [L _ Present{}] Boxed) + = p >= appPrec go (ExplicitTuple{}) = False go (ExplicitSum{}) = False go (HsLam{}) = p > topPrec ===================================== compiler/GHC/Hs/Pat.hs ===================================== @@ -857,7 +857,12 @@ patNeedsParens p = go go (BangPat {}) = False go (ParPat {}) = False go (AsPat {}) = False - go (TuplePat {}) = False + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go (TuplePat _ [_] Boxed) + = p >= appPrec + go (TuplePat{}) = False go (SumPat {}) = False go (ListPat {}) = False go (LitPat _ l) = hsLitNeedsParens p l ===================================== compiler/GHC/Hs/Type.hs ===================================== @@ -1979,6 +1979,15 @@ hsTypeNeedsParens p = go_hs_ty go_hs_ty (HsRecTy{}) = False go_hs_ty (HsTyVar{}) = False go_hs_ty (HsFunTy{}) = p >= funPrec + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go_hs_ty (HsTupleTy _ con [L _ ty]) + = case con of + HsBoxedTuple -> p >= appPrec + HsBoxedOrConstraintTuple -> p >= appPrec + HsConstraintTuple -> go_hs_ty ty + HsUnboxedTuple -> False go_hs_ty (HsTupleTy{}) = False go_hs_ty (HsSumTy{}) = False go_hs_ty (HsKindSig{}) = p >= sigPrec @@ -1986,6 +1995,11 @@ hsTypeNeedsParens p = go_hs_ty go_hs_ty (HsIParamTy{}) = p > topPrec go_hs_ty (HsSpliceTy{}) = False go_hs_ty (HsExplicitListTy{}) = False + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Proxy ('Solo x)`, not `Proxy 'Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go_hs_ty (HsExplicitTupleTy _ [_]) + = p >= appPrec go_hs_ty (HsExplicitTupleTy{}) = False go_hs_ty (HsTyLit{}) = False go_hs_ty (HsWildCardTy{}) = False ===================================== compiler/GHC/Rename/Names.hs ===================================== @@ -4,7 +4,7 @@ Extracting imported and top-level names in scope -} -{-# LANGUAGE CPP, NondecreasingIndentation, MultiWayIf, NamedFieldPuns #-} +{-# LANGUAGE CPP, NondecreasingIndentation #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -72,7 +72,7 @@ import Data.Either ( partitionEithers, isRight, rights ) import Data.Map ( Map ) import qualified Data.Map as Map import Data.Ord ( comparing ) -import Data.List ( partition, (\\), find, sortBy ) +import Data.List ( partition, (\\), find, sortBy, groupBy, sortOn ) import Data.Function ( on ) import qualified Data.Set as S import System.FilePath (()) @@ -1570,7 +1570,7 @@ decls, and simply trim their import lists. NB that -} getMinimalImports :: [ImportDeclUsage] -> RnM [LImportDecl GhcRn] -getMinimalImports = mapM mk_minimal +getMinimalImports = fmap combine . mapM mk_minimal where mk_minimal (L l decl, used_gres, unused) | null unused @@ -1623,6 +1623,25 @@ getMinimalImports = mapM mk_minimal all_non_overloaded = all (not . flIsOverloaded) + combine :: [LImportDecl GhcRn] -> [LImportDecl GhcRn] + combine = map merge . groupBy ((==) `on` getKey) . sortOn getKey + + getKey :: LImportDecl GhcRn -> (Bool, Maybe ModuleName, ModuleName) + getKey decl = + ( isImportDeclQualified . ideclQualified $ idecl -- is this qualified? (important that this be first) + , unLoc <$> ideclAs idecl -- what is the qualifier (inside Maybe monad) + , unLoc . ideclName $ idecl -- Module Name + ) + where + idecl :: ImportDecl GhcRn + idecl = unLoc decl + + merge :: [LImportDecl GhcRn] -> LImportDecl GhcRn + merge [] = error "getMinimalImports: unexpected empty list" + merge decls@((L l decl) : _) = L l (decl { ideclHiding = Just (False, L l lies) }) + where lies = concatMap (unLoc . snd) $ mapMaybe (ideclHiding . unLoc) decls + + printMinimalImports :: HscSource -> [ImportDeclUsage] -> RnM () -- See Note [Printing minimal imports] printMinimalImports hsc_src imports_w_usage ===================================== compiler/GHC/StgToCmm/Prim.hs ===================================== @@ -1,6 +1,5 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE LambdaCase #-} -{-# LANGUAGE MultiWayIf #-} #if __GLASGOW_HASKELL__ <= 808 -- GHC 8.10 deprecates this flag, but GHC 8.8 needs it @@ -1562,19 +1561,17 @@ emitPrimOp dflags primop = case primop of -> FCode ()) -> PrimopCmmEmit opIntoRegs f = PrimopCmmEmit_Internal $ \res_ty -> do - regs <- if - | ReturnsPrim VoidRep <- result_info - -> pure [] + regs <- case result_info of + ReturnsPrim VoidRep -> pure [] + ReturnsPrim rep + -> do reg <- newTemp (primRepCmmType platform rep) + pure [reg] - | ReturnsPrim rep <- result_info - -> do reg <- newTemp (primRepCmmType platform rep) - pure [reg] + ReturnsAlg tycon | isUnboxedTupleTyCon tycon + -> do (regs, _hints) <- newUnboxedTupleRegs res_ty + pure regs - | ReturnsAlg tycon <- result_info, isUnboxedTupleTyCon tycon - -> do (regs, _hints) <- newUnboxedTupleRegs res_ty - pure regs - - | otherwise -> panic "cgOpApp" + _ -> panic "cgOpApp" f regs pure $ map (CmmReg . CmmLocal) regs ===================================== testsuite/tests/rename/should_compile/Makefile ===================================== @@ -60,3 +60,8 @@ T7969: T18497: '$(TEST_HC)' $(TEST_HC_OPTS) -fno-code T18497_Foo.hs T18497_Bar.hs -ddump-minimal-imports cat T18497_Bar.imports-boot + +T18264: + $(RM) T18264.hi T18264.o T18264.imports + '$(TEST_HC)' $(TEST_HC_OPTS) -ddump-minimal-imports -c T18264.hs + cat T18264.imports ===================================== testsuite/tests/rename/should_compile/T18264.hs ===================================== @@ -0,0 +1,20 @@ +module T18264 where + +import Data.Char (isDigit) +import Data.Maybe (isJust) +import Data.Char (isPrint) +import Data.List (sortOn) +import Data.Char (isLetter) +import Data.Maybe hiding (isNothing) + +import qualified Data.List as S (sort) +import qualified Data.Char as C --only isDigit & isLetter used later +import qualified Data.List as T (nub) + +test1 x = isDigit x || isLetter x +test2a = isJust +test2b = fromJust +test3 x = C.isDigit x || C.isLetter x +test4 xs = S.sort xs +test5 xs = T.nub xs +test6 f xs = sortOn f xs ===================================== testsuite/tests/rename/should_compile/T18264.stdout ===================================== @@ -0,0 +1,6 @@ +import Data.Char ( isDigit, isLetter ) +import Data.List ( sortOn ) +import Data.Maybe ( fromJust, isJust ) +import qualified Data.Char as C ( isLetter, isDigit ) +import qualified Data.List as S ( sort ) +import qualified Data.List as T ( nub ) ===================================== testsuite/tests/rename/should_compile/all.T ===================================== @@ -175,3 +175,4 @@ test('T17244C', normal, compile, ['']) test('T17832', [], multimod_compile, ['T17832M1', 'T17832M2']) test('T17837', normal, compile, ['']) test('T18497', [], makefile_test, ['T18497']) +test('T18264', [], makefile_test, ['T18264']) ===================================== testsuite/tests/th/T18612.hs ===================================== @@ -0,0 +1,14 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -ddump-splices #-} +module T18612 where + +import Data.Functor.Identity +import Data.Proxy +import Language.Haskell.TH + +f :: $(arrowT `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))) + `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0)))) +f $(conP 'Identity [tupP [tupP []]]) = $(conE 'Identity `appE` tupE [tupE []]) + +type G = $(conT ''Proxy `appT` (promotedTupleT 1 `appT` (tupleT 0))) ===================================== testsuite/tests/th/T18612.stderr ===================================== @@ -0,0 +1,13 @@ +T18612.hs:14:11-68: Splicing type + conT ''Proxy `appT` (promotedTupleT 1 `appT` (tupleT 0)) + ======> + Proxy ('Solo ()) +T18612.hs:(10,7)-(11,75): Splicing type + arrowT `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))) + `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))) + ======> + Identity (Solo ()) -> Identity (Solo ()) +T18612.hs:12:4-36: Splicing pattern + conP 'Identity [tupP [tupP []]] ======> Identity (Solo()) +T18612.hs:12:41-78: Splicing expression + conE 'Identity `appE` tupE [tupE []] ======> Identity (Solo ()) ===================================== testsuite/tests/th/all.T ===================================== @@ -513,3 +513,4 @@ test('T18102b', extra_files(['T18102b_aux.hs']), compile_and_run, ['']) test('T18121', normal, compile, ['']) test('T18123', normal, compile, ['']) test('T18388', normal, compile, ['']) +test('T18612', normal, compile, ['']) ===================================== utils/genprimopcode/Lexer.x ===================================== @@ -44,8 +44,6 @@ words :- <0> "defaults" { mkT TDefaults } <0> "True" { mkT TTrue } <0> "False" { mkT TFalse } - <0> "Dyadic" { mkT TDyadic } - <0> "Monadic" { mkT TMonadic } <0> "Compare" { mkT TCompare } <0> "GenPrimOp" { mkT TGenPrimOp } <0> "fixity" { mkT TFixity } ===================================== utils/genprimopcode/Main.hs ===================================== @@ -836,16 +836,6 @@ mkPOI_RHS_text i TyF t1 (TyF _ _) -> "mkCompare " ++ sl_name i ++ ppType t1 _ -> error "Type error in comparison op" - Monadic - -> case ty i of - TyF t1 _ - -> "mkMonadic " ++ sl_name i ++ ppType t1 - _ -> error "Type error in monadic op" - Dyadic - -> case ty i of - TyF t1 (TyF _ _) - -> "mkDyadic " ++ sl_name i ++ ppType t1 - _ -> error "Type error in dyadic op" GenPrimOp -> let (argTys, resTy) = flatTys (ty i) tvs = nub (tvsIn (ty i)) ===================================== utils/genprimopcode/Parser.y ===================================== @@ -36,8 +36,6 @@ import Syntax defaults { TDefaults } true { TTrue } false { TFalse } - dyadic { TDyadic } - monadic { TMonadic } compare { TCompare } genprimop { TGenPrimOp } fixity { TFixity } @@ -122,9 +120,7 @@ pWithOptions : with pOptions { $2 } | {- empty -} { [] } pCategory :: { Category } -pCategory : dyadic { Dyadic } - | monadic { Monadic } - | compare { Compare } +pCategory : compare { Compare } | genprimop { GenPrimOp } pDesc :: { String } ===================================== utils/genprimopcode/ParserM.hs ===================================== @@ -94,8 +94,6 @@ data Token = TEOF | TDefaults | TTrue | TFalse - | TDyadic - | TMonadic | TCompare | TGenPrimOp | TThatsAllFolks ===================================== utils/genprimopcode/Syntax.hs ===================================== @@ -65,7 +65,7 @@ data Option -- categorises primops data Category - = Dyadic | Monadic | Compare | GenPrimOp + = Compare | GenPrimOp deriving Show -- types @@ -155,10 +155,6 @@ sanityPrimOp def_names p sane_ty :: Category -> Ty -> Bool sane_ty Compare (TyF t1 (TyF t2 td)) | t1 == t2 && td == TyApp (TyCon "Int#") [] = True -sane_ty Monadic (TyF t1 td) - | t1 == td = True -sane_ty Dyadic (TyF t1 (TyF t2 td)) - | t1 == td && t2 == td = True sane_ty GenPrimOp _ = True sane_ty _ _ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/bbc1e10b276a2f37d29dc0f35c21866bd1f8202d...e0b3cbdac94de38586d2cbe0654a2ef35e96635f -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/bbc1e10b276a2f37d29dc0f35c21866bd1f8202d...e0b3cbdac94de38586d2cbe0654a2ef35e96635f You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 27 14:39:03 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Thu, 27 Aug 2020 10:39:03 -0400 Subject: [Git][ghc/ghc][wip/T18565] 55 commits: Correct a typo in ghc.mk Message-ID: <5f47c587d5ee4_80b3f84924b67249644051@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18565 at Glasgow Haskell Compiler / GHC Commits: 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 293c7fba by Sylvain Henry at 2020-08-21T09:36:38-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - 50eb4460 by Sylvain Henry at 2020-08-21T09:36:38-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 659eb31b by Sylvain Henry at 2020-08-21T09:36:38-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 2d8ca917 by Sylvain Henry at 2020-08-21T09:37:15-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - fddddbf4 by Vladislav Zavialov at 2020-08-21T09:37:49-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - 989c1c27 by Ben Gamari at 2020-08-21T11:27:53-04:00 gitlab-ci: Test master branch as well While these builds are strictly speaking redundant (since every commit is tested by @marge-bot before making it into `master`), they are nevertheless useful as they are displayed in the branch's commit list in GitLab's web interface. Fixes #18595. - - - - - e67ae884 by Aditya Gupta at 2020-08-22T03:29:00-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - 03cfcfd4 by Wander Hillen at 2020-08-22T03:29:36-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 3f501545 by Craig Ferguson at 2020-08-22T03:30:13-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 8b865092 by Krzysztof Gogolewski at 2020-08-23T14:12:53+02:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - d8f61182 by Krzysztof Gogolewski at 2020-08-23T14:12:56+02:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - 364258e0 by Krzysztof Gogolewski at 2020-08-24T00:32:31-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - b1eb38a0 by Sylvain Henry at 2020-08-24T00:33:13-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 0a1ecc5f by Ben Gamari at 2020-08-25T07:37:05-04:00 SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' In #18069 we are observing MVar deadlocks from somewhere in ghc.exe. This use of MVar stood out as being one of the more likely culprits. Here we make sure that it is exception-safe. - - - - - db8793ad by Richard Eisenberg at 2020-08-25T07:37:40-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - fb77207a by Simon Peyton Jones at 2020-08-25T07:38:16-04:00 Use LIdP rather than (XRec p (IdP p)) This patch mainly just replaces use of XRec p (IdP p) with LIdP p One slightly more significant change is to parameterise HsPatSynDetails over the pass rather than the argument type, so that it's uniform with HsConDeclDetails and HsConPatDetails. I also got rid of the dead code GHC.Hs.type.conDetailsArgs But this is all just minor refactoring. No change in functionality. - - - - - 8426a136 by Krzysztof Gogolewski at 2020-08-25T07:38:54-04:00 Add a test for #18585 - - - - - 2d635a50 by Takenobu Tani at 2020-08-26T04:50:21-04:00 linters: Make CPP linter skip image files This patch adds an exclusion rule for `docs/users_guide/images`, to avoid lint errors of PDF files. - - - - - b7d98cb2 by Takenobu Tani at 2020-08-26T04:50:21-04:00 users-guide: Color the logo on the front page of the PDF This patch updates the logo with a recent color scheme. This affects only the PDF version of the user's guide. See also: * https://mail.haskell.org/pipermail/ghc-devs/2020-August/019139.html * https://gitlab.haskell.org/ghc/ghc/-/wikis/logo - - - - - 0b17fa18 by Sylvain Henry at 2020-08-26T04:50:58-04:00 Refactor UnitId pretty-printing When we pretty-print a UnitId for the user, we try to map it back to its origin package name, version and component to print "package-version:component" instead of some hash. The UnitId type doesn't carry these information, so we have to look into a UnitState to find them. This is why the Outputable instance of UnitId used `sdocWithDynFlags` in order to access the `unitState` field of DynFlags. This is wrong for several reasons: 1. The DynFlags are accessed when the message is printed, not when it is generated. So we could imagine that the unitState may have changed in-between. Especially if we want to allow unit unloading. 2. We want GHC to support several independent sessions at once, hence several UnitState. The current approach supposes there is a unique UnitState as a UnitId doesn't indicate which UnitState to use. See the Note [Pretty-printing UnitId] in GHC.Unit for the new approach implemented by this patch. One step closer to remove `sdocDynFlags` field from `SDocContext` (#10143). Fix #18124. Also fix some Backpack code to use SDoc instead of String. - - - - - dc476a50 by Sylvain Henry at 2020-08-26T04:51:35-04:00 Bignum: fix BigNat subtraction (#18604) There was a confusion between the boolean expected by withNewWordArrayTrimedMaybe and the boolean returned by subtracting functions. - - - - - fcb10b6c by Peter Trommler at 2020-08-26T10:42:30-04:00 PPC and X86: Portable printing of IEEE floats GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness. This was brought up in #18431 by @hsyl20. - - - - - 770100e0 by Krzysztof Gogolewski at 2020-08-26T10:43:13-04:00 primops: Remove Monadic and Dyadic categories There were four categories of primops: Monadic, Dyadic, Compare, GenPrimOp. The compiler does not treat Monadic and Dyadic in any special way, we can just replace them with GenPrimOp. Compare is still used in isComparisonPrimOp. - - - - - c7364154 by Sebastian Graf at 2020-08-26T19:10:53+02:00 Add long-distance info for pattern bindings (#18572) We didn't consider the RHS of a pattern-binding before, which led to surprising warnings listed in #18572. As can be seen from the regression test T18572, we get the expected output now. - - - - - 67b96f65 by Sebastian Graf at 2020-08-27T16:38:35+02:00 PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Previously, we desugared and coverage checked plain guard trees as described in Lower Your Guards. That caused (in !3849) quite a bit of pain when we need to partially recover tree structure of the input syntax to return covered sets for long-distance information, for example. In this refactor, I introduced a guard tree variant for each relevant source syntax component of a pattern-match (mainly match groups, match, GRHS, empty case, pattern binding). I made sure to share as much coverage checking code as possible, so that the syntax-specific checking functions are just wrappers around the more substantial checking functions for the LYG primitives (`checkSequence`, `checkGrds`). The refactoring payed off in clearer code and elimination of all panics related to assumed guard tree structure and thus fixes #18565. I also took the liberty to rename and re-arrange the order of functions and comments in the module, deleted some dead and irrelevant Notes, wrote some new ones and gave an overview module haddock. - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/linters/check-cpp.py - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs - compiler/GHC/Cmm/Switch.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2080f63da4e11bc9051e6705f0e31032eecf8275...67b96f65d98ea12002f9cff23cc672645a6248cf -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2080f63da4e11bc9051e6705f0e31032eecf8275...67b96f65d98ea12002f9cff23cc672645a6248cf You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 27 15:13:11 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Thu, 27 Aug 2020 11:13:11 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/T18603 Message-ID: <5f47cd87d5e6f_80b3f846992f3249646270@gitlab.haskell.org.mail> Simon Peyton Jones pushed new branch wip/T18603 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T18603 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 27 18:13:53 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Thu, 27 Aug 2020 14:13:53 -0400 Subject: [Git][ghc/ghc][wip/T18565] PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Message-ID: <5f47f7e19b4a8_80bf57111096564c4@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18565 at Glasgow Haskell Compiler / GHC Commits: eca5efc0 by Sebastian Graf at 2020-08-27T20:13:30+02:00 PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Previously, we desugared and coverage checked plain guard trees as described in Lower Your Guards. That caused (in !3849) quite a bit of pain when we need to partially recover tree structure of the input syntax to return covered sets for long-distance information, for example. In this refactor, I introduced a guard tree variant for each relevant source syntax component of a pattern-match (mainly match groups, match, GRHS, empty case, pattern binding). I made sure to share as much coverage checking code as possible, so that the syntax-specific checking functions are just wrappers around the more substantial checking functions for the LYG primitives (`checkSequence`, `checkGrds`). The refactoring payed off in clearer code and elimination of all panics related to assumed guard tree structure and thus fixes #18565. I also took the liberty to rename and re-arrange the order of functions and comments in the module, deleted some dead and irrelevant Notes, wrote some new ones and gave an overview module haddock. - - - - - 14 changed files: - compiler/GHC/Data/OrdList.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - compiler/GHC/HsToCore/PmCheck/Types.hs - compiler/GHC/Tc/Types.hs - compiler/GHC/Utils/Misc.hs - testsuite/tests/deSugar/should_compile/ds020.stderr - testsuite/tests/module/all.T - testsuite/tests/pmcheck/should_compile/T18572.hs - testsuite/tests/rename/should_compile/T7085.stderr - testsuite/tests/unboxedsums/all.T Changes: ===================================== compiler/GHC/Data/OrdList.hs ===================================== @@ -5,13 +5,16 @@ -} {-# LANGUAGE DeriveFunctor #-} - {-# LANGUAGE BangPatterns #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE UnboxedSums #-} +{-# LANGUAGE UnboxedTuples #-} -- | Provide trees (of instructions), so that lists of instructions can be -- appended in linear time. module GHC.Data.OrdList ( - OrdList, + OrdList, pattern NilOL, pattern ConsOL, pattern SnocOL, nilOL, isNilOL, unitOL, appOL, consOL, snocOL, concatOL, lastOL, headOL, mapOL, fromOL, toOL, foldrOL, foldlOL, reverseOL, fromOLReverse, @@ -79,6 +82,48 @@ snocOL as b = Snoc as b consOL a bs = Cons a bs concatOL aas = foldr appOL None aas +pattern NilOL :: OrdList a +pattern NilOL <- (isNilOL -> True) where + NilOL = None + +-- | An unboxed 'Maybe' type with two unboxed fields in the 'Just' case. +-- Useful for defining 'viewCons' and 'viewSnoc' without overhead. +type VMaybe a b = (# (# a, b #) | (# #) #) +pattern VJust :: a -> b -> VMaybe a b +pattern VJust a b = (# (# a, b #) | #) +pattern VNothing :: VMaybe a b +pattern VNothing = (# | (# #) #) +{-# COMPLETE VJust, VNothing #-} + +pattern ConsOL :: a -> OrdList a -> OrdList a +pattern ConsOL x xs <- (viewCons -> VJust x xs) where + ConsOL x xs = consOL x xs +viewCons :: OrdList a -> VMaybe a (OrdList a) +viewCons (One a) = VJust a NilOL +viewCons (Cons a as) = VJust a as +viewCons (Snoc as a) = case viewCons as of + VJust a' as' -> VJust a' (Snoc as' a) + VNothing -> VJust a NilOL +viewCons (Two as1 as2) = case viewCons as1 of + VJust a' as1' -> VJust a' (Two as1' as2) + VNothing -> viewCons as2 +viewCons _ = VNothing + +pattern SnocOL :: OrdList a -> a -> OrdList a +pattern SnocOL xs x <- (viewSnoc -> VJust xs x) where + SnocOL xs x = snocOL xs x +viewSnoc :: OrdList a -> VMaybe (OrdList a) a +viewSnoc (One a) = VJust NilOL a +viewSnoc (Many (reverse -> a:as)) = VJust (Many (reverse as)) a +viewSnoc (Snoc as a) = VJust as a +viewSnoc (Cons a as) = case viewSnoc as of + VJust as' a' -> VJust (Cons a as') a' + VNothing -> VJust NilOL a +viewSnoc (Two as1 as2) = case viewSnoc as2 of + VJust as2' a' -> VJust (Two as1 as2') a' + VNothing -> viewSnoc as1 +viewSnoc _ = VNothing + headOL None = panic "headOL" headOL (One a) = a headOL (Many as) = head as @@ -189,5 +234,3 @@ strictlyOrdOL (Two a1 a2) (Two b1 b2) = strictlyOrdOL (Two _ _) _ = LT strictlyOrdOL (Many as) (Many bs) = compare as bs strictlyOrdOL (Many _ ) _ = GT - - ===================================== compiler/GHC/HsToCore/Binds.hs ===================================== @@ -33,7 +33,7 @@ import {-# SOURCE #-} GHC.HsToCore.Match ( matchWrapper ) import GHC.HsToCore.Monad import GHC.HsToCore.GuardedRHSs import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck ( addTyCsDs, covCheckGRHSs ) +import GHC.HsToCore.PmCheck ( addTyCs, covCheckGRHSs ) import GHC.Hs -- lots of things import GHC.Core -- lots of things @@ -151,14 +151,14 @@ dsHsBind dflags b@(FunBind { fun_id = L loc fun , fun_matches = matches , fun_ext = co_fn , fun_tick = tick }) - = do { (args, body) <- addTyCsDs FromSource (hsWrapDictBinders co_fn) $ + = do { (args, body) <- addTyCs FromSource (hsWrapDictBinders co_fn) $ -- FromSource might not be accurate (we don't have any -- origin annotations for things in this module), but at -- worst we do superfluous calls to the pattern match -- oracle. - -- addTyCsDs: Add type evidence to the refinement type + -- addTyCs: Add type evidence to the refinement type -- predicate of the coverage checker - -- See Note [Type and Term Equality Propagation] in "GHC.HsToCore.PmCheck" + -- See Note [Long-distance information] in "GHC.HsToCore.PmCheck" matchWrapper (mkPrefixFunRhs (L loc (idName fun))) Nothing matches @@ -200,11 +200,11 @@ dsHsBind dflags (AbsBinds { abs_tvs = tyvars, abs_ev_vars = dicts , abs_exports = exports , abs_ev_binds = ev_binds , abs_binds = binds, abs_sig = has_sig }) - = do { ds_binds <- addTyCsDs FromSource (listToBag dicts) $ + = do { ds_binds <- addTyCs FromSource (listToBag dicts) $ dsLHsBinds binds - -- addTyCsDs: push type constraints deeper + -- addTyCs: push type constraints deeper -- for inner pattern match check - -- See Check, Note [Type and Term Equality Propagation] + -- See Check, Note [Long-distance information] ; ds_ev_binds <- dsTcEvBinds_s ev_binds ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -31,7 +31,7 @@ import GHC.HsToCore.ListComp import GHC.HsToCore.Utils import GHC.HsToCore.Arrows import GHC.HsToCore.Monad -import GHC.HsToCore.PmCheck ( addTyCsDs, covCheckGRHSs ) +import GHC.HsToCore.PmCheck ( addTyCs, covCheckGRHSs ) import GHC.Types.Name import GHC.Types.Name.Env import GHC.Core.FamInstEnv( topNormaliseType ) @@ -283,7 +283,7 @@ dsExpr hswrap@(XExpr (WrapExpr (HsWrap co_fn e))) HsConLikeOut _ (RealDataCon dc) -> return $ varToCoreExpr (dataConWrapId dc) XExpr (WrapExpr (HsWrap _ _)) -> pprPanic "dsExpr: HsWrap inside HsWrap" (ppr hswrap) HsPar _ _ -> pprPanic "dsExpr: HsPar inside HsWrap" (ppr hswrap) - _ -> addTyCsDs FromSource (hsWrapDictBinders co_fn) $ + _ -> addTyCs FromSource (hsWrapDictBinders co_fn) $ dsExpr e -- See Note [Detecting forced eta expansion] ; wrap' <- dsHsWrapper co_fn ===================================== compiler/GHC/HsToCore/Match.hs ===================================== @@ -770,8 +770,8 @@ matchWrapper ctxt mb_scr (MG { mg_alts = L _ matches -- Each Match will split off one Deltas for its RHSs from this. ; matches_deltas <- if isMatchContextPmChecked dflags origin ctxt then addHsScrutTmCs mb_scr new_vars $ - -- See Note [Type and Term Equality Propagation] - covCheckMatchGroup (DsMatchContext ctxt locn) new_vars matches + -- See Note [Long-distance information] + covCheckMatches (DsMatchContext ctxt locn) new_vars matches else pure (initDeltasMatches matches) ; eqns_info <- zipWithM mk_eqn_info matches matches_deltas @@ -881,7 +881,7 @@ matchSinglePatVar var mb_scrut ctx pat ty match_result -- Pattern match check warnings ; when (isMatchContextPmChecked dflags FromSource ctx) $ addCoreScrutTmCs mb_scrut [var] $ - covCheckPatBind dflags (DsMatchContext ctx locn) var (unLoc pat) + covCheckPatBind (DsMatchContext ctx locn) var (unLoc pat) ; let eqn_info = EqnInfo { eqn_pats = [unLoc (decideBangHood dflags pat)] , eqn_orig = FromSource ===================================== compiler/GHC/HsToCore/PmCheck.hs ===================================== @@ -1,24 +1,45 @@ -{- -Author: George Karachalias - -Pattern Matching Coverage Checking. --} - -{-# LANGUAGE CPP #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE TupleSections #-} -{-# LANGUAGE ViewPatterns #-} -{-# LANGUAGE MultiWayIf #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE NamedFieldPuns #-} - +{-# LANGUAGE CPP #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE TupleSections #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE MultiWayIf #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE NamedFieldPuns #-} + +-- | This module coverage checks pattern matches. It finds +-- +-- * Uncovered patterns, certifying non-exhaustivity +-- * Redundant equations +-- * Equations with an inaccessible right-hand-side +-- +-- The algorithm is based on the paper +-- [Lower Your Guards: A Compositional Pattern-Match Coverage Checker"](https://dl.acm.org/doi/abs/10.1145/3408989) +-- +-- An overview, which follows the structure of the entry points such as +-- 'covCheckMatches': +-- +-- 1. Desugar source syntax (like 'LMatch') to guard tree variants (like +-- 'GrdMatch'), with one of the desugaring functions (like 'desugarMatch') +-- 2. Coverage check guard trees (with a function like 'checkMatch') to get a +-- 'CheckResult', containing +-- a. The set of uncovered values, 'cr_uncov' +-- b. And an annotated tree variant (like 'AnnMatch') that captures +-- redundancy and inaccessibility information as 'RedSets' annotations +-- 3. Collect redundancy information into a 'CIRB' with a 'CIRBCollector' such +-- as 'collectMatch'. This is done as part of the next step... +-- 4. Format and report uncovered patterns and redundant equations ('CIRB') +-- with 'formatReportWarnings'. +-- 5. Return 'Deltas' reaching syntactic sub-components for +-- Note [Long-distance information]. +-- module GHC.HsToCore.PmCheck ( -- Checking and printing - covCheckPatBind, covCheckMatchGroup, covCheckGRHSs, + covCheckPatBind, covCheckMatches, covCheckGRHSs, isMatchContextPmChecked, - -- See Note [Type and Term Equality Propagation] - addTyCsDs, addCoreScrutTmCs, addHsScrutTmCs + -- See Note [Long-distance information] + addTyCs, addCoreScrutTmCs, addHsScrutTmCs ) where #include "HsVersions.h" @@ -37,7 +58,6 @@ import GHC.Tc.Utils.Zonk (shortCutLit) import GHC.Types.Id import GHC.Core.ConLike import GHC.Types.Name -import GHC.Tc.Instance.Family import GHC.Builtin.Types import GHC.Types.SrcLoc import GHC.Utils.Misc @@ -62,35 +82,132 @@ import GHC.Core.Type import GHC.HsToCore.Utils (isTrueLHsExpr) import GHC.Data.Maybe import qualified GHC.LanguageExtensions as LangExt -import GHC.Utils.Monad (concatMapM) +import GHC.Utils.Monad (concatMapM, mapMaybeM) import Control.Monad (when, forM_, zipWithM) import Data.List (elemIndex) import qualified Data.Semigroup as Semi -import Data.List.NonEmpty (NonEmpty(..)) +import Data.List.NonEmpty ( NonEmpty(..) ) +import qualified Data.List.NonEmpty as NE +import Data.Coerce + +-- +-- * Exported entry points to the checker +-- -{- -This module checks pattern matches for: -\begin{enumerate} - \item Equations that are redundant - \item Equations with inaccessible right-hand-side - \item Exhaustiveness -\end{enumerate} +-- | Check a pattern binding (let, where) for exhaustiveness. +covCheckPatBind :: DsMatchContext -> Id -> Pat GhcTc -> DsM () +-- See Note [covCheckPatBind only checks PatBindRhs] +covCheckPatBind ctxt@(DsMatchContext PatBindRhs loc) var p = do + missing <- getPmDeltas + pat_bind <- desugarPatBind loc var p + tracePm "covCheckPatBind {" (vcat [ppr ctxt, ppr var, ppr p, ppr pat_bind, ppr missing]) + result <- unCA (checkPatBind pat_bind) missing + tracePm "}: " (ppr (cr_uncov result)) + formatReportWarnings collectPatBind ctxt [var] result +covCheckPatBind _ _ _ = pure () + +-- | Exhaustive for guard matches, is used for guards in pattern bindings and +-- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. +covCheckGRHSs + :: HsMatchContext GhcRn -- ^ Match context, for warning messages + -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check + -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long + -- distance info +covCheckGRHSs hs_ctxt guards@(GRHSs _ grhss _) = do + let combined_loc = foldl1 combineSrcSpans (map getLoc grhss) + ctxt = DsMatchContext hs_ctxt combined_loc + matches <- desugarGRHSs combined_loc empty guards + missing <- getPmDeltas + tracePm "covCheckGRHSs" (hang (vcat [ppr ctxt + , text "Guards:"]) + 2 + (pprGRHSs hs_ctxt guards $$ ppr missing)) + result <- unCA (checkGRHSs matches) missing + tracePm "}: " (ppr (cr_uncov result)) + formatReportWarnings (collectGRHSs missing) ctxt [] result -The algorithm is based on the paper: +-- | Check a list of syntactic /match/es (part of case, functions, etc.), each +-- with a /pat/ and one or more /grhss/: +-- +-- @ +-- f x y | x == y = 1 -- match on x and y with two guarded RHSs +-- | otherwise = 2 +-- f _ _ = 3 -- clause with a single, un-guarded RHS +-- @ +-- +-- Returns one 'Deltas' for each GRHS, representing its covered values, or the +-- incoming uncovered 'Deltas' (from 'getPmDeltas') if the GRHS is inaccessible. +-- Since there is at least one /grhs/ per /match/, the list of 'Deltas' is at +-- least as long as the list of matches. +-- +-- Special case: When there are /no matches/ and only a single match variable, +-- then this function assumes it checks an -XEmptyCase. +-- See Note [Checking EmptyCase]. +covCheckMatches + :: DsMatchContext -- ^ Match context, for warnings messages + -> [Id] -- ^ Match variables, i.e. x and y above + -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches + -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per RHS, for long + -- distance info. +covCheckMatches ctxt vars matches = do + missing <- getPmDeltas + tracePm "covCheckMatches {" (hang (vcat [ppr ctxt, ppr vars, text "Matches:"]) + 2 + (vcat (map ppr matches) $$ ppr missing)) + case NE.nonEmpty matches of + Nothing -> do + -- This must be an -XEmptyCase. See Note [Checking EmptyCase] + let var = only vars + empty_case <- desugarEmptyCase var + result <- unCA (checkEmptyCase empty_case) missing + tracePm "}: " (ppr (cr_uncov result)) + [] <$ formatReportWarnings collectEmptyCase ctxt vars result + Just matches -> do + matches <- desugarMatches vars matches + result <- unCA (checkMatchGroup matches) missing + tracePm "}: " (ppr (cr_uncov result)) + NE.toList <$> formatReportWarnings (collectMatchGroup missing) ctxt vars result + +{- Note [covCheckPatBind only checks PatBindRhs] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + at covCheckPatBind@'s sole purpose is to check vanilla pattern bindings, like + at x :: Int; Just x = e@, which is in a @PatBindRhs@ context. +But its caller is also called for individual pattern guards in a @StmtCtxt at . +For example, both pattern guards in @f x y | True <- x, False <- y = ...@ will +go through this function. It makes no sense to do coverage checking there: + * Pattern guards may well fail. Fall-through is not an unrecoverable panic, + but rather behavior the programmer expects, so inexhaustivity should not be + reported. + * Redundancy is already reported for the whole GRHS via one of the other + exported coverage checking functions. Also reporting individual redundant + guards is... redundant. See #17646. +Note that we can't just omit checking of @StmtCtxt@ altogether (by adjusting +'isMatchContextPmChecked'), because that affects the other checking functions, +too. + +Note [Checking EmptyCase] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-XEmptyCase is useful for matching on empty data types like 'Void'. For example, +the following is a complete match: - "GADTs Meet Their Match: - Pattern-matching Warnings That Account for GADTs, Guards, and Laziness" + f :: Void -> () + f x = case x of {} - https://www.microsoft.com/en-us/research/wp-content/uploads/2016/08/gadtpm-acm.pdf +Really, -XEmptyCase is the only way to write a program that at the same time is +safe (@f _ = error "boom"@ is not because of ⊥), doesn't trigger a warning +(@f !_ = error "inaccessible" has inaccessible RHS) and doesn't turn an +exception into divergence (@f x = f x@). -%************************************************************************ -%* * - Pattern Match Check Types -%* * -%************************************************************************ +Semantically, unlike every other case expression, -XEmptyCase is strict in its +match var x, which rules out ⊥ as an inhabitant. So we add x /~ ⊥ to the +initial Delta and check if there are any values left to match on. -} +-- +-- * Guard language +-- + -- | A very simple language for pattern guards. Let bindings, bang patterns, -- and matching variables against flat constructor patterns. data PmGrd @@ -106,9 +223,9 @@ data PmGrd } -- | @PmBang x@ corresponds to a @seq x True@ guard. - -- If the extra SrcInfo is present, the bang guard came from a source - -- bang pattern, in which case we might want to report it as redundant, - -- see Note [Dead bang patterns]. + -- If the extra 'SrcInfo' is present, the bang guard came from a source + -- bang pattern, in which case we might want to report it as redundant. + -- See Note [Dead bang patterns]. | PmBang { pm_id :: !Id, pm_loc :: !(Maybe SrcInfo) @@ -144,24 +261,118 @@ instance Monoid Precision where mempty = Precise mappend = (Semi.<>) --- | Means by which we identify source location for later pretty-printing --- in a warning message. 'SDoc' for the equation to show, 'Located' for --- the location. +-- +-- * Guard tree language +-- + +-- | Means by which we identify a source construct for later pretty-printing in +-- a warning message. 'SDoc' for the equation to show, 'Located' for the +-- location. type SrcInfo = Located SDoc --- | A representation of the desugaring to 'PmGrd's of all clauses of a --- function definition/pattern match/etc. -data GrdTree - = Rhs !SrcInfo - | Guard !PmGrd !GrdTree - -- ^ @Guard grd t@ will try to match @grd@ and on success continue to match - -- @t at . Falls through if either match fails. Models left-to-right semantics - -- of pattern matching. - | Sequence ![GrdTree] - -- ^ @Sequence (t:ts)@ matches against @t@, and then matches all - -- fallen-through values against @Sequence ts at . Models top-to-bottom semantics - -- of pattern matching. - -- @Sequence []@ always fails; it is useful for Note [Checking EmptyCase]. +-- | A guard tree denoting 'MatchGroup'. +data GrdMatchGroup = GrdMatchGroup !(NonEmpty GrdMatch) + +-- | A guard tree denoting 'Match'. +data GrdMatch = GrdMatch { gm_pats :: ![PmGrd], gm_grhss :: !(NonEmpty GrdGRHS) } + +-- | A guard tree denoting 'GRHS'. +data GrdGRHS = GrdGRHS { gg_grds :: ![PmGrd], gg_rhs :: !SrcInfo } + +-- | A guard tree denoting an -XEmptyCase. +data GrdEmptyCase = GrdEmptyCase { ge_var :: Id } + +-- | A guard tree denoting a pattern binding. +newtype GrdPatBind = + -- just reuse GrdGRHS and pretend its @SrcInfo@ is info on the /pattern/, + -- rather than on the pattern bindings. + GrdPatBind GrdGRHS + +-- | Redundancy sets, used to determine redundancy of RHSs and bang patterns +-- (later digested into a 'CIRB'). +data RedSets + = RedSets + { rs_cov :: !Deltas + -- ^ The /Covered/ set; the set of values reaching a particular program + -- point. + , rs_div :: !Deltas + -- ^ The /Diverging/ set; empty if no match can lead to divergence. + -- If it wasn't empty, we have to turn redundancy warnings into + -- inaccessibility warnings for any subclauses. + , rs_bangs :: !(OrdList (Deltas, SrcInfo)) + -- ^ If any of the 'Deltas' is empty, the corresponding 'SrcInfo' pin-points + -- a bang pattern in source that is redundant. See Note [Dead bang patterns]. + } + +emptyRedSets :: RedSets +-- Semigroup instance would be misleading! +emptyRedSets = RedSets mempty mempty mempty + +-- | An annotated tree denoting 'MatchGroup'. +data AnnMatchGroup = AnnMatchGroup !(NonEmpty AnnMatch) + +-- | An annotated tree denoting 'Match'. +data AnnMatch = AnnMatch { am_red :: !RedSets, am_grhss :: !(NonEmpty AnnGRHS) } + +-- | An annotated tree denoting 'GRHS'. +data AnnGRHS = AnnGRHS { ag_red :: !RedSets, ag_rhs :: !SrcInfo } + +-- | An annotated tree denoting an -XEmptyCase. +data AnnEmptyCase = AnnEmptyCase + +-- | An annotated tree denoting a pattern binding. +newtype AnnPatBind = AnnPatBind AnnGRHS + +pprSrcInfo :: SrcInfo -> SDoc +pprSrcInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) +pprSrcInfo (L s _) = ppr s + +-- | Format LYG guards as "| True <- x, let x = 42, !z" +pprLygGuards :: [PmGrd] -> SDoc +pprLygGuards [] = empty +pprLygGuards (g:gs) = fsep (char '|' <+> ppr g : map ((comma <+>) . ppr) gs) + +-- | Format a LYG sequence (e.g. 'Match'es of a 'MatchGroup' or 'GRHSs') as +-- "{ ; ...; }" +pprLygSequence :: Outputable a => NonEmpty a -> SDoc +pprLygSequence (NE.toList -> as) = + braces (space <> fsep (punctuate semi (map ppr as)) <> space) + +instance Outputable GrdMatchGroup where + ppr (GrdMatchGroup matches) = pprLygSequence matches + +instance Outputable GrdMatch where + ppr (GrdMatch { gm_pats = grds, gm_grhss = grhss }) = + pprLygGuards grds <+> ppr grhss + +instance Outputable GrdGRHS where + ppr (GrdGRHS { gg_grds = grds, gg_rhs = rhs }) = + pprLygGuards grds <+> text "->" <+> pprSrcInfo rhs + +instance Outputable GrdPatBind where + ppr (GrdPatBind GrdGRHS { gg_grds = grds, gg_rhs = bind }) = + ppr bind <+> pprLygGuards grds <+> text "=" <+> text "..." + +instance Outputable GrdEmptyCase where + ppr (GrdEmptyCase { ge_var = var }) = + text " ppr var <> text ">" + +pprRedSets :: RedSets -> SDoc +-- Its useful to change this definition for different verbosity levels in +-- printf-debugging +pprRedSets RedSets { rs_cov = _cov, rs_div = _div, rs_bangs = _bangs } + = empty + +instance Outputable AnnMatchGroup where + ppr (AnnMatchGroup matches) = pprLygSequence matches + +instance Outputable AnnMatch where + ppr (AnnMatch { am_red = red, am_grhss = grhss }) = + pprRedSets red <+> ppr grhss + +instance Outputable AnnGRHS where + ppr (AnnGRHS { ag_red = red, ag_rhs = rhs }) = + pprRedSets red <+> text "->" <+> pprSrcInfo rhs {- Note [Dead bang patterns] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -197,236 +408,9 @@ it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. -} --- | The digest of 'checkGrdTree', representing the annotated pattern-match --- tree. 'extractRedundancyInfo' can figure out redundant and proper --- inaccessible RHSs from this, as well as dead bangs. -data AnnotatedTree - = AccessibleRhs !Deltas !SrcInfo - -- ^ A RHS deemed accessible. The 'Deltas' is the (non-empty) set of covered - -- values. - | InaccessibleRhs !SrcInfo - -- ^ A RHS deemed inaccessible; it covers no value. - | MayDiverge !AnnotatedTree - -- ^ Asserts that the tree may force diverging values, so not all of its - -- clauses can be redundant. - | SequenceAnn !Deltas ![AnnotatedTree] - -- ^ @SequenceAnn inc ts@ mirrors @'Sequence' ts@ for preserving the - -- skeleton of a 'GrdTree's @ts at . It also carries the set of incoming values - -- @inc at . - | RedundantSrcBang !SrcInfo !AnnotatedTree - -- ^ For tracking redundant bangs. See Note [Dead bang patterns] - -pprSrcInfo :: SrcInfo -> SDoc -pprSrcInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) -pprSrcInfo (L s _) = ppr s - -instance Outputable GrdTree where - ppr (Rhs info) = text "->" <+> pprSrcInfo info - -- Format guards as "| True <- x, let x = 42, !z" - ppr g at Guard{} = fsep (prefix (map ppr grds)) <+> ppr t - where - (t, grds) = collect_grds g - collect_grds (Guard grd t) = (grd :) <$> collect_grds t - collect_grds t = (t, []) - prefix [] = [] - prefix (s:sdocs) = char '|' <+> s : map (comma <+>) sdocs - ppr (Sequence []) = text "" - ppr (Sequence ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) - -instance Outputable AnnotatedTree where - ppr (AccessibleRhs _delta info) = parens (ppr _delta) <+> pprSrcInfo info - ppr (InaccessibleRhs info) = text "inaccessible" <+> pprSrcInfo info - ppr (MayDiverge t) = text "div" <+> ppr t - ppr (SequenceAnn _ []) = text "" - ppr (SequenceAnn _ ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) - ppr (RedundantSrcBang l t) = text "redundant bang" <+> pprSrcInfo l <+> ppr t - --- | Lift 'addPmCts' over 'Deltas'. -addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas -addPmCtsDeltas deltas cts = liftDeltasM (\d -> addPmCts d cts) deltas - --- | 'addPmCtsDeltas' a single 'PmCt'. -addPmCtDeltas :: Deltas -> PmCt -> DsM Deltas -addPmCtDeltas deltas ct = addPmCtsDeltas deltas (unitBag ct) - --- | Test if any of the 'Delta's is inhabited. Currently this is pure, because --- we preserve the invariant that there are no uninhabited 'Delta's. But that --- could change in the future, for example by implementing this function in --- terms of @notNull <$> provideEvidence 1 ds at . -isInhabited :: Deltas -> DsM Bool -isInhabited (MkDeltas ds) = pure (not (null ds)) - --- | Pattern-match check result -data CheckResult - = CheckResult - { cr_clauses :: !AnnotatedTree - -- ^ Captures redundancy info for each clause in the original program. - -- (for -Woverlapping-patterns) - , cr_uncov :: !Deltas - -- ^ The set of uncovered values falling out at the bottom. - -- (for -Wincomplete-patterns) - , cr_approx :: !Precision - -- ^ A flag saying whether we ran into the 'maxPmCheckModels' limit for the - -- purpose of suggesting to crank it up in the warning message - } - -instance Outputable CheckResult where - ppr (CheckResult c unc pc) - = text "CheckResult" <+> ppr_precision pc <+> braces (fsep - [ field "clauses" c <> comma - , field "uncov" unc]) - where - ppr_precision Precise = empty - ppr_precision Approximate = text "(Approximate)" - field name value = text name <+> equals <+> ppr value - -{- -%************************************************************************ -%* * - Entry points to the checker: covCheckPatBind and covCheckMatchGroup -%* * -%************************************************************************ --} - --- | Check a pattern binding (let, where) for exhaustiveness. -covCheckPatBind :: DynFlags -> DsMatchContext -> Id -> Pat GhcTc -> DsM () -covCheckPatBind dflags ctxt@(DsMatchContext _ locn) var p = do - -- We only ever need to run this in a context where we need exhaustivity - -- warnings (so not in pattern guards or comprehensions, for example, because - -- they are perfectly fine to fail). - -- Omitting checking this flag emits redundancy warnings twice in obscure - -- cases like #17646. - -- Given the context in which this function is called, it will only ever do - -- something for - -- * PatBindRhs, -Wincomplete-uni-patterns: @let True = False@ - -- * PatBindGuards, -Wincomplete-patterns: @Just x | False = Just 42@ - missing <- getPmDeltas - tracePm "covCheckPatBind" (vcat [ppr ctxt, ppr var, ppr p, ppr missing]) - fam_insts <- dsGetFamInstEnvs - grd_tree <- mkGrdTreeRhs (L locn $ ppr p) <$> translatePat fam_insts var p - res <- checkGrdTree grd_tree missing - dsPmWarn dflags ctxt [var] res - --- | Exhaustive for guard matches, is used for guards in pattern bindings and --- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. -covCheckGRHSs - :: HsMatchContext GhcRn -- ^ Match context, for warning messages - -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check - -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long - -- distance info -covCheckGRHSs hs_ctx guards@(GRHSs _ grhss _) = do - let combinedLoc = foldl1 combineSrcSpans (map getLoc grhss) - dsMatchContext = DsMatchContext hs_ctx combinedLoc - match = L combinedLoc $ - Match { m_ext = noExtField - , m_ctxt = hs_ctx - , m_pats = [] - , m_grhss = guards } - [(_, deltas)] <- covCheckMatchGroup dsMatchContext [] [match] - pure deltas - --- | Check a list of syntactic /match/es (part of case, functions, etc.), each --- with a /pat/ and one or more /grhss/: -- --- @ --- f x y | x == y = 1 -- match on x and y with two guarded RHSs --- | otherwise = 2 --- f _ _ = 3 -- clause with a single, un-guarded RHS --- @ +-- * Desugaring source syntax to guard trees -- --- Returns one 'Deltas' for each GRHS, representing its covered values, or the --- incoming uncovered 'Deltas' (from 'getPmDeltas') if the GRHS is inaccessible. --- Since there is at least one /grhs/ per /match/, the list of 'Deltas' is at --- least as long as the list of matches. -covCheckMatchGroup - :: DsMatchContext -- ^ Match context, for warnings messages - -> [Id] -- ^ Match variables, i.e. x and y above - -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches - -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per RHS, for long - -- distance info. -covCheckMatchGroup ctxt vars matches = do - tracePm "covCheckMatchGroup" (hang (vcat [ppr ctxt - , ppr vars - , text "Matches:"]) - 2 - (vcat (map ppr matches))) - - init_deltas <- getPmDeltas - missing <- case matches of - -- This must be an -XEmptyCase. See Note [Checking EmptyCase] - [] | [var] <- vars -> addPmCtDeltas init_deltas (PmNotBotCt var) - _ -> pure init_deltas - fam_insts <- dsGetFamInstEnvs - grd_tree <- translateMatches fam_insts vars matches - res <- checkGrdTree grd_tree missing - - dflags <- getDynFlags - dsPmWarn dflags ctxt vars res - - return (extractRhsDeltas (cr_clauses res)) - --- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree' for a match --- group. --- For 'AccessibleRhs's, this is stored in the tree node, whereas --- 'InaccessibleRhs's fall back to the supplied original 'Deltas'. --- See @Note [Recovering from unsatisfiable pattern-matching constraints]@. -extractRhsDeltas :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] -extractRhsDeltas = go_matches - where - go_matches :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] - go_matches (SequenceAnn def ts) = map (go_match def) ts -- -XEmptyCase handled here! - go_matches t = pprPanic "extractRhsDeltas.go_matches" (text "Matches must start with SequenceAnn. But was" $$ ppr t) - - go_match :: Deltas -> AnnotatedTree -> (Deltas, NonEmpty Deltas) - -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ - -- is non-empty! - go_match def (SequenceAnn pat ts) = (pat, foldMap1 (text "go_match: empty SequenceAnn") (go_grhss def) ts) - go_match def (MayDiverge t) = go_match def t - go_match def (RedundantSrcBang _ t) = go_match def t - -- Even if there's only a single GRHS, we wrap it in a SequenceAnn for the - -- Deltas covered by the pattern. So the remaining cases are impossible! - go_match _ t = pprPanic "extractRhsDeltas.go_match" (text "Single GRHS must be wrapped in SequenceAnn. But got " $$ ppr t) - - go_grhss :: Deltas -> AnnotatedTree -> NonEmpty Deltas - -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ - -- is non-empty! - go_grhss def (SequenceAnn _ ts) = foldMap1 (text "go_grhss: empty SequenceAnn") (go_grhss def) ts - go_grhss def (MayDiverge t) = go_grhss def t - go_grhss def (RedundantSrcBang _ t) = go_grhss def t - go_grhss _ (AccessibleRhs deltas _) = deltas :| [] - go_grhss def (InaccessibleRhs _) = def :| [] - - foldMap1 msg _ [] = pprPanic "extractRhsDeltas.foldMap1" msg - foldMap1 _ f (x:xs) = foldl' (\acc x -> acc Semi.<> f x) (f x) xs - -{- Note [Checking EmptyCase] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --XEmptyCase is useful for matching on empty data types like 'Void'. For example, -the following is a complete match: - - f :: Void -> () - f x = case x of {} - -Really, -XEmptyCase is the only way to write a program that at the same time is -safe (@f _ = error "boom"@ is not because of ⊥), doesn't trigger a warning -(@f !_ = error "inaccessible" has inaccessible RHS) and doesn't turn an -exception into divergence (@f x = f x@). - -Semantically, unlike every other case expression, -XEmptyCase is strict in its -match var x, which rules out ⊥ as an inhabitant. So we add x /~ ⊥ to the -initial Delta and check if there are any values left to match on. --} - -{- -%************************************************************************ -%* * - Transform source syntax to *our* syntax -%* * -%************************************************************************ --} - --- ----------------------------------------------------------------------- --- * Utilities -- | Smart constructor that eliminates trivial lets mkPmLetVar :: Id -> Id -> GrdVec @@ -459,7 +443,7 @@ mkListGrds a ((x, head_grds):xs) = do -- | Create a 'GrdVec' refining a match variable to a 'PmLit'. mkPmLitGrds :: Id -> PmLit -> DsM GrdVec mkPmLitGrds x (PmLit _ (PmLitString s)) = do - -- We translate String literals to list literals for better overlap reasoning. + -- We desugar String literals to list literals for better overlap reasoning. -- It's a little unfortunate we do this here rather than in -- 'GHC.HsToCore.PmCheck.Oracle.trySolve' and -- 'GHC.HsToCore.PmCheck.Oracle.addRefutableAltCon', but it's so much simpler @@ -477,37 +461,34 @@ mkPmLitGrds x lit = do , pm_con_args = [] } pure [grd] --- ----------------------------------------------------------------------- --- * Transform (Pat Id) into GrdVec - --- | @translatePat _ x pat@ transforms @pat@ into a 'GrdVec', where +-- | @desugarPat _ x pat@ transforms @pat@ into a 'GrdVec', where -- the variable representing the match is @x at . -translatePat :: FamInstEnvs -> Id -> Pat GhcTc -> DsM GrdVec -translatePat fam_insts x pat = case pat of +desugarPat :: Id -> Pat GhcTc -> DsM GrdVec +desugarPat x pat = case pat of WildPat _ty -> pure [] VarPat _ y -> pure (mkPmLetVar (unLoc y) x) - ParPat _ p -> translateLPat fam_insts x p + ParPat _ p -> desugarLPat x p LazyPat _ _ -> pure [] -- like a wildcard BangPat _ p@(L l p') -> -- Add the bang in front of the list, because it will happen before any -- nested stuff. - (PmBang x pm_loc :) <$> translateLPat fam_insts x p - where pm_loc = Just (L l (ppr p')) + (PmBang x pm_loc :) <$> desugarLPat x p + where pm_loc = Just (L l (ppr p')) - -- (x at pat) ==> Translate pat with x as match var and handle impedance + -- (x at pat) ==> Desugar pat with x as match var and handle impedance -- mismatch with incoming match var - AsPat _ (L _ y) p -> (mkPmLetVar y x ++) <$> translateLPat fam_insts y p + AsPat _ (L _ y) p -> (mkPmLetVar y x ++) <$> desugarLPat y p - SigPat _ p _ty -> translateLPat fam_insts x p + SigPat _ p _ty -> desugarLPat x p - -- See Note [Translate CoPats] + -- See Note [Desugar CoPats] -- Generally the translation is -- pat |> co ===> let y = x |> co, pat <- y where y is a match var of pat XPat (CoPat wrapper p _ty) - | isIdHsWrapper wrapper -> translatePat fam_insts x p - | WpCast co <- wrapper, isReflexiveCo co -> translatePat fam_insts x p + | isIdHsWrapper wrapper -> desugarPat x p + | WpCast co <- wrapper, isReflexiveCo co -> desugarPat x p | otherwise -> do - (y, grds) <- translatePatV fam_insts p + (y, grds) <- desugarPatV p wrap_rhs_y <- dsHsWrapper wrapper pure (PmLet y (wrap_rhs_y (Var x)) : grds) @@ -522,13 +503,13 @@ translatePat fam_insts x pat = case pat of -- (fun -> pat) ===> let y = fun x, pat <- y where y is a match var of pat ViewPat _arg_ty lexpr pat -> do - (y, grds) <- translateLPatV fam_insts pat + (y, grds) <- desugarLPatV pat fun <- dsLExpr lexpr pure $ PmLet y (App fun (Var x)) : grds -- list ListPat (ListPatTc _elem_ty Nothing) ps -> - translateListPat fam_insts x ps + desugarListPat x ps -- overloaded list ListPat (ListPatTc elem_ty (Just (pat_ty, to_list))) pats -> do @@ -536,11 +517,11 @@ translatePat fam_insts x pat = case pat of case splitListTyConApp_maybe pat_ty of Just _e_ty | not (xopt LangExt.RebindableSyntax dflags) - -- Just translate it as a regular ListPat - -> translateListPat fam_insts x pats + -- Just desugar it as a regular ListPat + -> desugarListPat x pats _ -> do y <- mkPmId (mkListTy elem_ty) - grds <- translateListPat fam_insts y pats + grds <- desugarListPat y pats rhs_y <- dsSyntaxExpr to_list [Var x] pure $ PmLet y rhs_y : grds @@ -566,7 +547,7 @@ translatePat fam_insts x pat = case pat of , cpt_dicts = dicts } } -> do - translateConPatOut fam_insts x con arg_tys ex_tvs dicts ps + desugarConPatOut x con arg_tys ex_tvs dicts ps NPat ty (L _ olit) mb_neg _ -> do -- See Note [Literal short cut] in "GHC.HsToCore.Match.Literal" @@ -595,46 +576,44 @@ translatePat fam_insts x pat = case pat of mkPmLitGrds x lit TuplePat _tys pats boxity -> do - (vars, grdss) <- mapAndUnzipM (translateLPatV fam_insts) pats + (vars, grdss) <- mapAndUnzipM desugarLPatV pats let tuple_con = tupleDataCon boxity (length vars) pure $ vanillaConGrd x tuple_con vars : concat grdss SumPat _ty p alt arity -> do - (y, grds) <- translateLPatV fam_insts p + (y, grds) <- desugarLPatV p let sum_con = sumDataCon alt arity -- See Note [Unboxed tuple RuntimeRep vars] in GHC.Core.TyCon pure $ vanillaConGrd x sum_con [y] : grds - -- -------------------------------------------------------------------------- - -- Not supposed to happen - SplicePat {} -> panic "Check.translatePat: SplicePat" + SplicePat {} -> panic "Check.desugarPat: SplicePat" --- | 'translatePat', but also select and return a new match var. -translatePatV :: FamInstEnvs -> Pat GhcTc -> DsM (Id, GrdVec) -translatePatV fam_insts pat = do +-- | 'desugarPat', but also select and return a new match var. +desugarPatV :: Pat GhcTc -> DsM (Id, GrdVec) +desugarPatV pat = do x <- selectMatchVar Many pat - grds <- translatePat fam_insts x pat + grds <- desugarPat x pat pure (x, grds) -translateLPat :: FamInstEnvs -> Id -> LPat GhcTc -> DsM GrdVec -translateLPat fam_insts x = translatePat fam_insts x . unLoc +desugarLPat :: Id -> LPat GhcTc -> DsM GrdVec +desugarLPat x = desugarPat x . unLoc --- | 'translateLPat', but also select and return a new match var. -translateLPatV :: FamInstEnvs -> LPat GhcTc -> DsM (Id, GrdVec) -translateLPatV fam_insts = translatePatV fam_insts . unLoc +-- | 'desugarLPat', but also select and return a new match var. +desugarLPatV :: LPat GhcTc -> DsM (Id, GrdVec) +desugarLPatV = desugarPatV . unLoc --- | @translateListPat _ x [p1, ..., pn]@ is basically --- @translateConPatOut _ x $(mkListConPatOuts [p1, ..., pn]>@ without ever +-- | @desugarListPat _ x [p1, ..., pn]@ is basically +-- @desugarConPatOut _ x $(mkListConPatOuts [p1, ..., pn]>@ without ever -- constructing the 'ConPatOut's. -translateListPat :: FamInstEnvs -> Id -> [LPat GhcTc] -> DsM GrdVec -translateListPat fam_insts x pats = do - vars_and_grdss <- traverse (translateLPatV fam_insts) pats +desugarListPat :: Id -> [LPat GhcTc] -> DsM GrdVec +desugarListPat x pats = do + vars_and_grdss <- traverse desugarLPatV pats mkListGrds x vars_and_grdss --- | Translate a constructor pattern -translateConPatOut :: FamInstEnvs -> Id -> ConLike -> [Type] -> [TyVar] +-- | Desugar a constructor pattern +desugarConPatOut :: Id -> ConLike -> [Type] -> [TyVar] -> [EvVar] -> HsConPatDetails GhcTc -> DsM GrdVec -translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case +desugarConPatOut x con univ_tys ex_tvs dicts = \case PrefixCon ps -> go_field_pats (zip [0..] ps) InfixCon p1 p2 -> go_field_pats (zip [0..] [p1,p2]) RecCon (HsRecFields fs _) -> go_field_pats (rec_field_ps fs) @@ -648,7 +627,7 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case where tagged_pat f = (lbl_to_index (getName (hsRecFieldId f)), hsRecFieldArg f) -- Unfortunately the label info is empty when the DataCon wasn't defined - -- with record field labels, hence we translate to field index. + -- with record field labels, hence we desugar to field index. orig_lbls = map flSelector $ conLikeFieldLabels con lbl_to_index lbl = expectJust "lbl_to_index" $ elemIndex lbl orig_lbls @@ -659,10 +638,10 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- the first field of @tagged_pats at . -- See Note [Field match order for RecCon] - -- Translate the mentioned field patterns. We're doing this first to get + -- Desugar the mentioned field patterns. We're doing this first to get -- the Ids for pm_con_args. let trans_pat (n, pat) = do - (var, pvec) <- translateLPatV fam_insts pat + (var, pvec) <- desugarLPatV pat pure ((n, var), pvec) (tagged_vars, arg_grdss) <- mapAndUnzipM trans_pat tagged_pats @@ -688,77 +667,81 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- 1. 2. 3. pure (con_grd : bang_grds ++ arg_grds) --- | Translate a the 'Match'es of a 'MatchGroup' -translateMatches :: FamInstEnvs -> [Id] -> [LMatch GhcTc (LHsExpr GhcTc)] - -> DsM GrdTree -translateMatches fam_insts vars matches = - -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. - -- 'extractRhsDeltas' needs this to recover 'MatchGroup' structure. - Sequence <$> traverse (translateMatch fam_insts vars) matches - --- Translate a single match -translateMatch :: FamInstEnvs -> [Id] -> LMatch GhcTc (LHsExpr GhcTc) - -> DsM GrdTree -translateMatch fam_insts vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do - pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats - grhss' <- translateGRHSs fam_insts match_loc (sep (map ppr pats)) grhss - -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss']) - return (foldr Guard grhss' pats') - -mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree -mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) - -translateGRHSs :: FamInstEnvs -> SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateGRHSs fam_insts match_loc pp_pats grhss = - -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. - -- 'extractRhsDeltas' needs this to recover 'GRHSs' structure. - Sequence <$> traverse (translateLGRHS fam_insts match_loc pp_pats) (grhssGRHSs grhss) - --- | Translate a guarded right-hand side to a single 'GrdTree' -translateLGRHS :: FamInstEnvs -> SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateLGRHS fam_insts match_loc pp_pats (L _loc (GRHS _ gs _)) = - -- _loc points to the match separator (ie =, ->) that comes after the guards.. - mkGrdTreeRhs loc_sdoc <$> concatMapM (translateGuard fam_insts . unLoc) gs - where - loc_sdoc - -- pp_pats is the space-separated pattern of the current Match this - -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . - | null gs = L match_loc pp_pats - | otherwise = L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) - L grd_loc _ = head gs - --- | Translate a guard statement to a 'GrdVec' -translateGuard :: FamInstEnvs -> GuardStmt GhcTc -> DsM GrdVec -translateGuard fam_insts guard = case guard of - BodyStmt _ e _ _ -> translateBoolGuard e - LetStmt _ binds -> translateLet (unLoc binds) - BindStmt _ p e -> translateBind fam_insts p e - LastStmt {} -> panic "translateGuard LastStmt" - ParStmt {} -> panic "translateGuard ParStmt" - TransStmt {} -> panic "translateGuard TransStmt" - RecStmt {} -> panic "translateGuard RecStmt" - ApplicativeStmt {} -> panic "translateGuard ApplicativeLastStmt" - --- | Translate let-bindings -translateLet :: HsLocalBinds GhcTc -> DsM GrdVec -translateLet _binds = return [] - --- | Translate a pattern guard +desugarPatBind :: SrcSpan -> Id -> Pat GhcTc -> DsM GrdPatBind +-- See 'GrdPatBind' for how this simply repurposes GrdGRHS. +desugarPatBind loc var pat = + GrdPatBind . flip GrdGRHS (L loc (ppr pat)) <$> desugarPat var pat + +desugarEmptyCase :: Id -> DsM GrdEmptyCase +desugarEmptyCase var = pure GrdEmptyCase { ge_var = var } + +-- | Desugar the non-empty 'Match'es of a 'MatchGroup'. +desugarMatches :: [Id] -> NonEmpty (LMatch GhcTc (LHsExpr GhcTc)) + -> DsM GrdMatchGroup +desugarMatches vars matches = + GrdMatchGroup <$> traverse (desugarMatch vars) matches + +-- Desugar a single match +desugarMatch :: [Id] -> LMatch GhcTc (LHsExpr GhcTc) -> DsM GrdMatch +desugarMatch vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do + pats' <- concat <$> zipWithM desugarLPat vars pats + grhss' <- desugarGRHSs match_loc (sep (map ppr pats)) grhss + -- tracePm "desugarMatch" (vcat [ppr pats, ppr pats', ppr grhss']) + return GrdMatch { gm_pats = pats', gm_grhss = grhss' } + +desugarGRHSs :: SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM (NonEmpty GrdGRHS) +desugarGRHSs match_loc pp_pats grhss + = traverse (desugarLGRHS match_loc pp_pats) + . expectJust "desugarGRHSs" + . NE.nonEmpty + $ grhssGRHSs grhss + +-- | Desugar a guarded right-hand side to a single 'GrdTree' +desugarLGRHS :: SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdGRHS +desugarLGRHS match_loc pp_pats (L _loc (GRHS _ gs _)) = do + -- _loc points to the match separator (ie =, ->) that comes after the guards. + -- Hence we have to pass in the match_loc, which we use in case that the RHS + -- is unguarded. + -- pp_pats is the space-separated pattern of the current Match this + -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . + let rhs_info = case gs of + [] -> L match_loc pp_pats + (L grd_loc _):_ -> L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) + grds <- concatMapM (desugarGuard . unLoc) gs + pure GrdGRHS { gg_grds = grds, gg_rhs = rhs_info } + +-- | Desugar a guard statement to a 'GrdVec' +desugarGuard :: GuardStmt GhcTc -> DsM GrdVec +desugarGuard guard = case guard of + BodyStmt _ e _ _ -> desugarBoolGuard e + LetStmt _ binds -> desugarLet (unLoc binds) + BindStmt _ p e -> desugarBind p e + LastStmt {} -> panic "desugarGuard LastStmt" + ParStmt {} -> panic "desugarGuard ParStmt" + TransStmt {} -> panic "desugarGuard TransStmt" + RecStmt {} -> panic "desugarGuard RecStmt" + ApplicativeStmt {} -> panic "desugarGuard ApplicativeLastStmt" + +-- | Desugar let-bindings +desugarLet :: HsLocalBinds GhcTc -> DsM GrdVec +desugarLet _binds = return [] + +-- | Desugar a pattern guard -- @pat <- e ==> let x = e; @ -translateBind :: FamInstEnvs -> LPat GhcTc -> LHsExpr GhcTc -> DsM GrdVec -translateBind fam_insts p e = dsLExpr e >>= \case +desugarBind :: LPat GhcTc -> LHsExpr GhcTc -> DsM GrdVec +desugarBind p e = dsLExpr e >>= \case Var y | Nothing <- isDataConId_maybe y -- RHS is a variable, so that will allow us to omit the let - -> translateLPat fam_insts y p + -> desugarLPat y p rhs -> do - (x, grds) <- translateLPatV fam_insts p + (x, grds) <- desugarLPatV p pure (PmLet x rhs : grds) --- | Translate a boolean guard +-- | Desugar a boolean guard -- @e ==> let x = e; True <- x@ -translateBoolGuard :: LHsExpr GhcTc -> DsM GrdVec -translateBoolGuard e +desugarBoolGuard :: LHsExpr GhcTc -> DsM GrdVec +desugarBoolGuard e | isJust (isTrueLHsExpr e) = return [] -- The formal thing to do would be to generate (True <- True) -- but it is trivial to solve so instead we give back an empty @@ -803,7 +786,7 @@ for a pattern match appear matter. Consider a situation similar to T5117: f (0:_) = () f (0:[]) = () -The latter clause is clearly redundant. Yet if we translate the second clause as +The latter clause is clearly redundant. Yet if we desugar the second clause as [x:xs' <- xs, [] <- xs', 0 <- x] @@ -815,51 +798,10 @@ translation would have been And we have to take in the guards on list cells into @mkListGrds at . -Note [Countering exponential blowup] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Precise pattern match exhaustiveness checking is necessarily exponential in -the size of some input programs. We implement a counter-measure in the form of -the -fmax-pmcheck-models flag, limiting the number of Deltas we check against -each pattern by a constant. - -How do we do that? Consider - - f True True = () - f True True = () - -And imagine we set our limit to 1 for the sake of the example. The first clause -will be checked against the initial Delta, {}. Doing so will produce an -Uncovered set of size 2, containing the models {x/~True} and {x~True,y/~True}. -Also we find the first clause to cover the model {x~True,y~True}. - -But the Uncovered set we get out of the match is too huge! We somehow have to -ensure not to make things worse as they are already, so we continue checking -with a singleton Uncovered set of the initial Delta {}. Why is this -sound (wrt. notion of the GADTs Meet their Match paper)? Well, it basically -amounts to forgetting that we matched against the first clause. The values -represented by {} are a superset of those represented by its two refinements -{x/~True} and {x~True,y/~True}. - -This forgetfulness becomes very apparent in the example above: By continuing -with {} we don't detect the second clause as redundant, as it again covers the -same non-empty subset of {}. So we don't flag everything as redundant anymore, -but still will never flag something as redundant that isn't. - -For exhaustivity, the converse applies: We will report @f@ as non-exhaustive -and report @f _ _@ as missing, which is a superset of the actual missing -matches. But soundness means we will never fail to report a missing match. - -This mechanism is implemented in 'throttle'. - -Guards are an extreme example in this regard, with #11195 being a particularly -dreadful example: Since their RHS are often pretty much unique, we split on a -variable (the one representing the RHS) that doesn't occur anywhere else in the -program, so we don't actually get useful information out of that split! - -Note [Translate CoPats] +Note [Desugar CoPats] ~~~~~~~~~~~~~~~~~~~~~~~ The pattern match checker did not know how to handle coerced patterns `CoPat` -efficiently, which gave rise to #11276. The original approach translated +efficiently, which gave rise to #11276. The original approach desugard `CoPat`s: pat |> co ===> x (pat <- (x |> co)) @@ -875,108 +817,92 @@ a lot of false warnings. But we can check whether the coercion is a hole or if it is just refl, in which case we can drop it. - -%************************************************************************ -%* * - Utilities for Pattern Match Checking -%* * -%************************************************************************ -} --- ---------------------------------------------------------------------------- --- * Basic utilities - -{- -Note [Extensions to GADTs Meet Their Match] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The GADTs Meet Their Match paper presents the formalism that GHC's coverage -checker adheres to. Since the paper's publication, there have been some -additional features added to the coverage checker which are not described in -the paper. This Note serves as a reference for these new features. - -* Value abstractions are severely simplified to the point where they are just - variables. The information about the shape of a variable is encoded in - the oracle state 'Delta' instead. -* Handling of uninhabited fields like `!Void`. - See Note [Strict argument type constraints] in GHC.HsToCore.PmCheck.Oracle. -* Efficient handling of literal splitting, large enumerations and accurate - redundancy warnings for `COMPLETE` groups through the oracle. - -Note [Filtering out non-matching COMPLETE sets] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Currently, conlikes in a COMPLETE set are simply grouped by the -type constructor heading the return type. This is nice and simple, but it does -mean that there are scenarios when a COMPLETE set might be incompatible with -the type of a scrutinee. For instance, consider (from #14135): - - data Foo a = Foo1 a | Foo2 a - - pattern MyFoo2 :: Int -> Foo Int - pattern MyFoo2 i = Foo2 i - - {-# COMPLETE Foo1, MyFoo2 #-} - - f :: Foo a -> a - f (Foo1 x) = x - -`f` has an incomplete pattern-match, so when choosing which constructors to -report as unmatched in a warning, GHC must choose between the original set of -data constructors {Foo1, Foo2} and the COMPLETE set {Foo1, MyFoo2}. But observe -that GHC shouldn't even consider the COMPLETE set as a possibility: the return -type of MyFoo2, Foo Int, does not match the type of the scrutinee, Foo a, since -there's no substitution `s` such that s(Foo Int) = Foo a. - -To ensure that GHC doesn't pick this COMPLETE set, it checks each pattern -synonym constructor's return type matches the type of the scrutinee, and if one -doesn't, then we remove the whole COMPLETE set from consideration. - -One might wonder why GHC only checks /pattern synonym/ constructors, and not -/data/ constructors as well. The reason is because that the type of a -GADT constructor very well may not match the type of a scrutinee, and that's -OK. Consider this example (from #14059): - - data SBool (z :: Bool) where - SFalse :: SBool False - STrue :: SBool True - - pattern STooGoodToBeTrue :: forall (z :: Bool). () - => z ~ True - => SBool z - pattern STooGoodToBeTrue = STrue - {-# COMPLETE SFalse, STooGoodToBeTrue #-} - - wobble :: SBool z -> Bool - wobble STooGoodToBeTrue = True - -In the incomplete pattern match for `wobble`, we /do/ want to warn that SFalse -should be matched against, even though its type, SBool False, does not match -the scrutinee type, SBool z. - -SG: Another angle at this is that the implied constraints when we instantiate -universal type variables in the return type of a GADT will lead to *provided* -thetas, whereas when we instantiate the return type of a pattern synonym that -corresponds to a *required* theta. See Note [Pattern synonym result type] in -PatSyn. Note how isValidCompleteMatches will successfully filter out - - pattern Just42 :: Maybe Int - pattern Just42 = Just 42 - -But fail to filter out the equivalent - - pattern Just'42 :: (a ~ Int) => Maybe a - pattern Just'42 = Just 42 - -Which seems fine as far as tcMatchTy is concerned, but it raises a few eye -brows. --} +-- +-- * Coverage checking guard trees into annotated trees +-- -{- -%************************************************************************ -%* * - Heart of the algorithm: checkGrdTree -%* * -%************************************************************************ --} +-- | Pattern-match coverage check result +data CheckResult a + = CheckResult + { cr_ret :: !a + -- ^ A hole for redundancy info and covered sets. + , cr_uncov :: !Deltas + -- ^ The set of uncovered values falling out at the bottom. + -- (for -Wincomplete-patterns, but also important state for the algorithm) + , cr_approx :: !Precision + -- ^ A flag saying whether we ran into the 'maxPmCheckModels' limit for the + -- purpose of suggesting to crank it up in the warning message. Writer state. + } deriving Functor + +instance Outputable a => Outputable (CheckResult a) where + ppr (CheckResult c unc pc) + = text "CheckResult" <+> ppr_precision pc <+> braces (fsep + [ field "ret" c <> comma + , field "uncov" unc]) + where + ppr_precision Precise = empty + ppr_precision Approximate = text "(Approximate)" + field name value = text name <+> equals <+> ppr value + +-- | Lift 'addPmCts' over 'Deltas'. +addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas +addPmCtsDeltas deltas cts = liftDeltasM (\d -> addPmCts d cts) deltas + +-- | 'addPmCtsDeltas' a single 'PmCt'. +addPmCtDeltas :: Deltas -> PmCt -> DsM Deltas +addPmCtDeltas deltas ct = addPmCtsDeltas deltas (unitBag ct) + +-- | Test if any of the 'Delta's is inhabited. Currently this is pure, because +-- we preserve the invariant that there are no uninhabited 'Delta's. But that +-- could change in the future, for example by implementing this function in +-- terms of @notNull <$> provideEvidence 1 ds at . +isInhabited :: Deltas -> DsM Bool +isInhabited (MkDeltas ds) = pure (not (null ds)) + +-- | Coverage checking action. Can be composed 'leftToRight' or 'topToBottom'. +newtype CheckAction a = CA { unCA :: Deltas -> DsM (CheckResult a) } + deriving Functor + +-- | Composes 'CheckAction's top-to-bottom: +-- If a value falls through the resulting action, then it must fall through the +-- first action and then through the second action. +-- If a value matches the resulting action, then it either matches the +-- first action or matches the second action. +-- Basically the semantics of the LYG branching construct. +topToBottom :: (top -> bot -> ret) + -> CheckAction top + -> CheckAction bot + -> CheckAction ret +topToBottom f (CA top) (CA bot) = CA $ \inc -> do + t <- top inc + b <- bot (cr_uncov t) + pure CheckResult { cr_ret = f (cr_ret t) (cr_ret b) + , cr_uncov = cr_uncov b + , cr_approx = cr_approx t Semi.<> cr_approx b } + + +-- | Composes 'CheckAction's left-to-right: +-- If a value falls through the resulting action, then it either falls through the +-- first action or through the second action. +-- If a value matches the resulting action, then it must match the first action +-- and then match the second action. +-- Basically the semantics of the LYG guard construct. +leftToRight :: (RedSets -> right -> ret) + -> CheckAction RedSets + -> CheckAction right + -> CheckAction ret +leftToRight f (CA left) (CA right) = CA $ \inc -> do + l <- left inc + r <- right (rs_cov (cr_ret l)) + limit <- maxPmCheckModels <$> getDynFlags + let uncov = cr_uncov l Semi.<> cr_uncov r + -- See Note [Countering exponential blowup] + let (prec', uncov') = throttle limit inc uncov + pure CheckResult { cr_ret = f (cr_ret l) (cr_ret r) + , cr_uncov = uncov' + , cr_approx = prec' Semi.<> cr_approx l Semi.<> cr_approx r } -- | @throttle limit old new@ returns @old@ if the number of 'Delta's in @new@ -- is exceeding the given @limit@ and the @old@ number of 'Delta's. @@ -994,237 +920,241 @@ conMatchForces (PmAltConLike (RealDataCon dc)) | isNewTyCon (dataConTyCon dc) = False conMatchForces _ = True --- | Makes sure that we only wrap a single 'MayDiverge' around an --- 'AnnotatedTree', purely for esthetic reasons. -mayDiverge :: AnnotatedTree -> AnnotatedTree -mayDiverge a@(MayDiverge _) = a -mayDiverge a = MayDiverge a - --- | Computes two things: --- --- * The set of uncovered values not matched by any of the clauses of the --- 'GrdTree'. Note that 'PmCon' guards are the only way in which values --- fall through from one 'Many' branch to the next. --- * An 'AnnotatedTree' that contains divergence and inaccessibility info --- for all clauses. Will be fed to 'extractRedundancyInfo' for --- presenting redundant and proper innaccessible RHSs, as well as dead --- bangs to the user. -checkGrdTree' :: GrdTree -> Deltas -> DsM CheckResult --- RHS: Check that it covers something and wrap Inaccessible if not -checkGrdTree' (Rhs sdoc) deltas = do - is_covered <- isInhabited deltas - let clauses - | is_covered = AccessibleRhs deltas sdoc - | otherwise = InaccessibleRhs sdoc - pure CheckResult - { cr_clauses = clauses - , cr_uncov = MkDeltas emptyBag - , cr_approx = Precise } --- let x = e: Refine with x ~ e -checkGrdTree' (Guard (PmLet x e) tree) deltas = do - deltas' <- addPmCtDeltas deltas (PmCoreCt x e) - checkGrdTree' tree deltas' --- Bang x: Diverge on x ~ ⊥, refine with x /~ ⊥ -checkGrdTree' (Guard (PmBang x src_bang_info) tree) deltas = do - has_diverged <- addPmCtDeltas deltas (PmBotCt x) >>= isInhabited - deltas' <- addPmCtDeltas deltas (PmNotBotCt x) - res <- checkGrdTree' tree deltas' - let clauses - | not has_diverged - , Just info <- src_bang_info - = RedundantSrcBang info (cr_clauses res) - | has_diverged - = mayDiverge (cr_clauses res) - | otherwise -- won't diverge and it wasn't a source bang - = cr_clauses res - - pure res{ cr_clauses = clauses } - --- Con: Diverge on x ~ ⊥, fall through on x /~ K and refine with x ~ K ys --- and type info -checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do - has_diverged <- - if conMatchForces con - then addPmCtDeltas deltas (PmBotCt x) >>= isInhabited - else pure False - unc_this <- addPmCtDeltas deltas (PmNotConCt x con) - deltas' <- addPmCtsDeltas deltas $ - listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args - -- tracePm "checkGrdTree:Con" (ppr deltas $$ ppr x $$ ppr con $$ ppr dicts $$ ppr deltas') - CheckResult tree' unc_inner prec <- checkGrdTree' tree deltas' - limit <- maxPmCheckModels <$> getDynFlags - let (prec', unc') = throttle limit deltas (unc_this Semi.<> unc_inner) - pure CheckResult - { cr_clauses = applyWhen has_diverged mayDiverge tree' - , cr_uncov = unc' - , cr_approx = prec Semi.<> prec' } --- Sequence: Thread residual uncovered sets from equation to equation -checkGrdTree' (Sequence ts) init_unc = go [] init_unc Precise ts +-- First the functions that correspond to checking LYG primitives: + +checkSequence :: (grdtree -> CheckAction anntree) -> NonEmpty grdtree -> CheckAction (NonEmpty anntree) +-- The implementation is pretty similar to +-- @traverse1 :: Apply f => (a -> f b) -> NonEmpty a -> f (NonEmpty b)@ +checkSequence act (t:|[]) = (:|[]) <$> act t +checkSequence act (t1:|(t2:ts)) = + topToBottom (NE.<|) (act t1) (checkSequence act (t2:|ts)) + +checkGrd :: PmGrd -> CheckAction RedSets +checkGrd grd = CA $ \inc -> case grd of + -- let x = e: Refine with x ~ e + PmLet x e -> do + matched <- addPmCtDeltas inc (PmCoreCt x e) + pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched } + , cr_uncov = mempty + , cr_approx = Precise } + -- Bang x _: Diverge on x ~ ⊥, refine with x /~ ⊥ + PmBang x mb_info -> do + div <- addPmCtDeltas inc (PmBotCt x) + matched <- addPmCtDeltas inc (PmNotBotCt x) + -- See Note [Dead bang patterns] + -- mb_info = Just info <==> PmBang originates from bang pattern in source + let bangs | Just info <- mb_info = unitOL (div, info) + | otherwise = NilOL + pure CheckResult { cr_ret = RedSets { rs_cov = matched, rs_div = div, rs_bangs = bangs } + , cr_uncov = mempty + , cr_approx = Precise } + -- Con: Diverge on x ~ ⊥, fall through on x /~ K and refine with x ~ K ys + -- and type info + PmCon x con tvs dicts args -> do + div <- if conMatchForces con + then addPmCtDeltas inc (PmBotCt x) + else pure mempty + uncov <- addPmCtDeltas inc (PmNotConCt x con) + matched <- addPmCtsDeltas inc $ + listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args + -- tracePm "checkGrd:Con" (ppr inc $$ ppr x $$ ppr con $$ ppr dicts $$ ppr matched) + pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched, rs_div = div } + , cr_uncov = uncov + , cr_approx = Precise } + +checkGrds :: [PmGrd] -> CheckAction RedSets +checkGrds [] = CA $ \inc -> + pure CheckResult { cr_ret = emptyRedSets { rs_cov = inc } + , cr_uncov = mempty + , cr_approx = Precise } +checkGrds (g:grds) = leftToRight merge (checkGrd g) (checkGrds grds) where - -- | Accumulates a CheckResult. Its type is more like - -- @CheckResult -> [GrdTree] -> CheckResult@, but cr_clauses is a single - -- 'AnnotatedTree', not a list thereof. Hence 3 parameters to thread the - -- fields. - go :: [AnnotatedTree] -> Deltas -> Precision -> [GrdTree] -> DsM CheckResult - -- No cases left: Fall through for all values - go ts' unc prec [] = pure CheckResult - { cr_clauses = SequenceAnn init_unc (reverse ts') - , cr_uncov = unc - , cr_approx = prec } - go ts' unc prec (t:ts) = do - CheckResult t' unc_1 prec_t <- checkGrdTree' t unc - go (t':ts') unc_1 (prec_t Semi.<> prec) ts - --- | Print diagnostic info and actually call 'checkGrdTree''. -checkGrdTree :: GrdTree -> Deltas -> DsM CheckResult -checkGrdTree guards deltas = do - tracePm "checkGrdTree {" $ vcat [ ppr guards - , ppr deltas ] - res <- checkGrdTree' guards deltas - tracePm "checkGrdTree }:" (ppr res) -- braces are easier to match by tooling - return res - --- ---------------------------------------------------------------------------- --- * Propagation of term constraints inwards when checking nested matches - -{- Note [Type and Term Equality Propagation] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -When checking a match it would be great to have all type and term information -available so we can get more precise results. For this reason we have functions -`addDictsDs' and `addTmVarCsDs' in GHC.HsToCore.Monad that store in the -environment type and term constraints (respectively) as we go deeper. - -The type constraints we propagate inwards are collected by `collectEvVarsPats' -in GHC.Hs.Pat. This handles bug #4139 ( see example - https://gitlab.haskell.org/ghc/ghc/snippets/672 ) -where this is needed. - -For term equalities we do less, we just generate equalities for HsCase. For -example we accurately give 2 redundancy warnings for the marked cases: - -f :: [a] -> Bool -f x = case x of - - [] -> case x of -- brings (x ~ []) in scope - [] -> True - (_:_) -> False -- can't happen - - (_:_) -> case x of -- brings (x ~ (_:_)) in scope - (_:_) -> True - [] -> False -- can't happen - -Functions `add*ScrutTmCs' is responsible for generating -these constraints. --} + merge ri_g ri_grds = -- This operation would /not/ form a Semigroup! + RedSets { rs_cov = rs_cov ri_grds + , rs_div = rs_div ri_g Semi.<> rs_div ri_grds + , rs_bangs = rs_bangs ri_g Semi.<> rs_bangs ri_grds } --- | Locally update 'dsl_deltas' with the given action, but defer evaluation --- with 'unsafeInterleaveM' in order not to do unnecessary work. -locallyExtendPmDelta :: (Deltas -> DsM Deltas) -> DsM a -> DsM a -locallyExtendPmDelta ext k = do - deltas <- getPmDeltas - deltas' <- unsafeInterleaveM $ do - deltas' <- ext deltas - inh <- isInhabited deltas' - -- If adding a constraint would lead to a contradiction, don't add it. - -- See @Note [Recovering from unsatisfiable pattern-matching constraints]@ - -- for why this is done. - if inh - then pure deltas' - else pure deltas - updPmDeltas deltas' k +checkMatchGroup :: GrdMatchGroup -> CheckAction AnnMatchGroup +checkMatchGroup (GrdMatchGroup matches) = + AnnMatchGroup <$> checkSequence checkMatch matches --- | Add in-scope type constraints if the coverage checker might run and then --- run the given action. -addTyCsDs :: Origin -> Bag EvVar -> DsM a -> DsM a -addTyCsDs origin ev_vars m = do - dflags <- getDynFlags - applyWhen (needToRunPmCheck dflags origin) - (locallyExtendPmDelta (\deltas -> addPmCtsDeltas deltas (PmTyCt . evVarPred <$> ev_vars))) - m +checkMatch :: GrdMatch -> CheckAction AnnMatch +checkMatch (GrdMatch { gm_pats = grds, gm_grhss = grhss }) = + leftToRight AnnMatch (checkGrds grds) (checkGRHSs grhss) --- | Add equalities for the 'CoreExpr' scrutinee to the local 'DsM' environment --- when checking a case expression: --- case e of x { matches } --- When checking matches we record that (x ~ e) where x is the initial --- uncovered. All matches will have to satisfy this equality. -addCoreScrutTmCs :: Maybe CoreExpr -> [Id] -> DsM a -> DsM a -addCoreScrutTmCs Nothing _ k = k -addCoreScrutTmCs (Just scr) [x] k = - flip locallyExtendPmDelta k $ \deltas -> - addPmCtsDeltas deltas (unitBag (PmCoreCt x scr)) -addCoreScrutTmCs _ _ _ = panic "addCoreScrutTmCs: scrutinee, but more than one match id" +checkGRHSs :: NonEmpty GrdGRHS -> CheckAction (NonEmpty AnnGRHS) +checkGRHSs = checkSequence checkGRHS --- | 'addCoreScrutTmCs', but desugars the 'LHsExpr' first. -addHsScrutTmCs :: Maybe (LHsExpr GhcTc) -> [Id] -> DsM a -> DsM a -addHsScrutTmCs Nothing _ k = k -addHsScrutTmCs (Just scr) vars k = do - scr_e <- dsLExpr scr - addCoreScrutTmCs (Just scr_e) vars k +checkGRHS :: GrdGRHS -> CheckAction AnnGRHS +checkGRHS (GrdGRHS { gg_grds = grds, gg_rhs = rhs_info }) = + flip AnnGRHS rhs_info <$> checkGrds grds -{- -%************************************************************************ -%* * - Pretty printing of exhaustiveness/redundancy check warnings -%* * -%************************************************************************ --} +checkEmptyCase :: GrdEmptyCase -> CheckAction AnnEmptyCase +checkEmptyCase (GrdEmptyCase { ge_var = var }) = CA $ \inc -> do + unc <- addPmCtDeltas inc (PmNotBotCt var) + pure CheckResult { cr_ret = AnnEmptyCase, cr_uncov = unc, cr_approx = mempty } --- | Check whether any part of pattern match checking is enabled for this --- 'HsMatchContext' (does not matter whether it is the redundancy check or the --- exhaustiveness check). -isMatchContextPmChecked :: DynFlags -> Origin -> HsMatchContext id -> Bool -isMatchContextPmChecked dflags origin kind - | isGenerated origin - = False - | otherwise - = overlapping dflags kind || exhaustive dflags kind +checkPatBind :: GrdPatBind -> CheckAction AnnPatBind +checkPatBind = coerce checkGRHS --- | Return True when any of the pattern match warnings ('allPmCheckWarnings') --- are enabled, in which case we need to run the pattern match checker. -needToRunPmCheck :: DynFlags -> Origin -> Bool -needToRunPmCheck dflags origin - | isGenerated origin - = False - | otherwise - = notNull (filter (`wopt` dflags) allPmCheckWarnings) +{- Note [Countering exponential blowup] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Precise pattern match exhaustiveness checking is necessarily exponential in +the size of some input programs. We implement a counter-measure in the form of +the -fmax-pmcheck-models flag, limiting the number of Deltas we check against +each pattern by a constant. + +How do we do that? Consider + + f True True = () + f True True = () + +And imagine we set our limit to 1 for the sake of the example. The first clause +will be checked against the initial Delta, {}. Doing so will produce an +Uncovered set of size 2, containing the models {x/~True} and {x~True,y/~True}. +Also we find the first clause to cover the model {x~True,y~True}. + +But the Uncovered set we get out of the match is too huge! We somehow have to +ensure not to make things worse as they are already, so we continue checking +with a singleton Uncovered set of the initial Delta {}. Why is this +sound (wrt. notion of the GADTs Meet their Match paper)? Well, it basically +amounts to forgetting that we matched against the first clause. The values +represented by {} are a superset of those represented by its two refinements +{x/~True} and {x~True,y/~True}. --- | A type for organising information to be used in warnings. -data RedundancyInfo - = RedundancyInfo - { redundant_rhss :: ![SrcInfo] - , inaccessible_rhss :: ![SrcInfo] - , redundant_bangs :: ![Located SDoc] +This forgetfulness becomes very apparent in the example above: By continuing +with {} we don't detect the second clause as redundant, as it again covers the +same non-empty subset of {}. So we don't flag everything as redundant anymore, +but still will never flag something as redundant that isn't. + +For exhaustivity, the converse applies: We will report @f@ as non-exhaustive +and report @f _ _@ as missing, which is a superset of the actual missing +matches. But soundness means we will never fail to report a missing match. + +This mechanism is implemented in 'throttle'. + +Guards are an extreme example in this regard, with #11195 being a particularly +dreadful example: Since their RHS are often pretty much unique, we split on a +variable (the one representing the RHS) that doesn't occur anywhere else in the +program, so we don't actually get useful information out of that split! +-} + +-- +-- * Collecting redundancy information +-- + +-- | The result of redundancy checking: +-- * RHSs classified as /C/overed, /I/naccessible and /R/edundant +-- * And redundant (B)ang patterns. +data CIRB + = CIRB + { cirb_cov :: !(OrdList SrcInfo) + , cirb_inacc :: !(OrdList SrcInfo) + , cirb_red :: !(OrdList SrcInfo) + , cirb_bangs :: !(OrdList SrcInfo) } -extractRedundancyInfo :: AnnotatedTree -> RedundancyInfo -extractRedundancyInfo tree = - RedundancyInfo { redundant_rhss = fromOL ol_red - , inaccessible_rhss = fromOL ol_inacc - , redundant_bangs = fromOL ol_bangs } - where - (_ol_acc, ol_inacc, ol_red, ol_bangs) = go tree - -- | Collects - -- 1. accessible RHSs - -- 2. proper inaccessible RHSs (so we can't delete them) - -- 3. hypothetically redundant RHSs (so not only inaccessible, but we can - -- even safely delete the equation without altering semantics) - -- 4. 'Dead' bangs from the source, collected to be warned about - -- See Note [Determining inaccessible clauses] - -- See Note [Dead bang patterns] - go :: AnnotatedTree -> (OrdList SrcInfo, OrdList SrcInfo, OrdList SrcInfo, OrdList SrcInfo) - go (AccessibleRhs _ info) = (unitOL info, nilOL, nilOL , nilOL) - go (InaccessibleRhs info) = (nilOL, nilOL, unitOL info, nilOL) -- presumably redundant - go (MayDiverge t) = case go t of - -- See Note [Determining inaccessible clauses] - (acc, inacc, red, bs) - | isNilOL acc && isNilOL inacc -> (nilOL, red, nilOL, bs) - res -> res - go (SequenceAnn _ ts) = foldMap go ts - go (RedundantSrcBang l t) = case go t of - -- See Note [Dead bang patterns] - res@(acc, inacc, _, _) - | isNilOL acc, isNilOL inacc -> res - | otherwise -> (nilOL, nilOL, nilOL, unitOL l) Semi.<> res +instance Semigroup CIRB where + CIRB a b c d <> CIRB e f g h = CIRB (a <> e) (b <> f) (c <> g) (d <> h) + where (<>) = (Semi.<>) + +instance Monoid CIRB where + mempty = CIRB mempty mempty mempty mempty + +markAllRedundant :: CIRB -> CIRB +markAllRedundant CIRB { cirb_cov = cov, cirb_inacc = inacc, cirb_red = red } = + mempty { cirb_red = cov Semi.<> inacc Semi.<> red } + +-- See Note [Determining inaccessible clauses] +ensureOneNotRedundant :: CIRB -> CIRB +ensureOneNotRedundant ci = case ci of + CIRB { cirb_cov = NilOL, cirb_inacc = NilOL, cirb_red = ConsOL r rs } + -> ci { cirb_inacc = unitOL r, cirb_red = rs } + _ -> ci + +-- | Only adds the redundant bangs to the @CIRB@ if there is at least one +-- non-redundant 'SrcInfo'. There is no point in remembering a redundant bang +-- if the whole match is redundant! +addRedundantBangs :: OrdList SrcInfo -> CIRB -> CIRB +addRedundantBangs _red_bangs cirb at CIRB { cirb_cov = NilOL, cirb_inacc = NilOL } = + cirb +addRedundantBangs red_bangs cirb = + cirb { cirb_bangs = cirb_bangs cirb Semi.<> red_bangs } + +-- | A function that walks along an annotated tree @ann@ and extracts two kinds +-- of coverage info: +-- +-- 1. A 'CIRB', classifying every encountered RHS in the tree as +-- redundant, inaccessible or covered. +-- 2. A piece of long-distance information @ldi@, consisting of a +-- nesting of 'Deltas' mirroring tree structure. +-- For example, 'collectMatchGroup' operates on a Match Group and thus +-- returns a list of 'Deltas' for the pattern part of each Match, as well as +-- a further nested list of 'Deltas' for each of the GRHS of the Match. +type CIRBCollector ann ldi = ann -> DsM (CIRB, ldi) + +-- | Checks the 'Deltas' in a 'RedSets' for inhabitants and returns +-- 1. Whether the Covered set was inhabited +-- 2. Whether the Diverging set was inhabited +-- 3. The new inhabited Covered set for long-distance information. +-- See Note [Recovering from unsatisfiable pattern-matching constraints]. +-- 4. All source bangs whose 'Deltas' were empty, which means they are +-- redundant. +testRedSets :: Deltas -> RedSets -> DsM (Bool, Bool, Deltas, OrdList SrcInfo) +testRedSets ldi RedSets { rs_cov = cov, rs_div = div, rs_bangs = bangs } = do + is_covered <- isInhabited cov + may_diverge <- isInhabited div + red_bangs <- flip mapMaybeM (fromOL bangs) $ \(deltas, bang) -> do + isInhabited deltas >>= \case + True -> pure Nothing + False -> pure (Just bang) + -- See Note [Recovering from unsatisfiable pattern-matching constraints] + -- Deltas for long-distance info: Use (non-empty!) fallback ldi if Covered + -- set was empty + let ldi' + | is_covered = cov + | otherwise = ldi + pure (is_covered, may_diverge, ldi', toOL red_bangs) + +collectMatchGroup :: Deltas -> CIRBCollector AnnMatchGroup (NonEmpty (Deltas, NonEmpty Deltas)) +collectMatchGroup ldi (AnnMatchGroup matches) = do + (cirbs, ldis) <- NE.unzip <$> traverse (collectMatch ldi) matches + pure (Semi.sconcat cirbs, ldis) + +collectMatch :: Deltas -> CIRBCollector AnnMatch (Deltas, NonEmpty Deltas) +collectMatch ldi AnnMatch { am_red = red, am_grhss = grhss } = do + (is_covered, may_diverge, ldi', red_bangs) <- testRedSets ldi red + (cirb, ldis) <- collectGRHSs ldi' grhss + let cirb' = addRedundantBangs red_bangs + -- See Note [Determining inaccessible clauses] + $ applyWhen may_diverge ensureOneNotRedundant + $ applyWhen (not is_covered) markAllRedundant + $ cirb + pure (cirb', (ldi', ldis)) + +collectGRHSs :: Deltas -> CIRBCollector (NonEmpty AnnGRHS) (NonEmpty Deltas) +collectGRHSs ldi grhss = do + (cirbs, ldis) <- NE.unzip <$> traverse (collectGRHS ldi) grhss + pure (Semi.sconcat cirbs, ldis) + +collectGRHS :: Deltas -> CIRBCollector AnnGRHS Deltas +collectGRHS ldi AnnGRHS { ag_red = red, ag_rhs = info } = do + (is_covered, may_diverge, ldi', red_bangs) <- testRedSets ldi red + let cirb | is_covered = mempty { cirb_cov = unitOL info } + | may_diverge = mempty { cirb_inacc = unitOL info } + | otherwise = mempty { cirb_red = unitOL info } + pure (addRedundantBangs red_bangs cirb, ldi') + +collectEmptyCase :: CIRBCollector AnnEmptyCase () +collectEmptyCase _ = pure (mempty, ()) + +collectPatBind :: CIRBCollector AnnPatBind () +-- We don't make use of long-distance information in pattern bindings, hence +-- @()@ instead of some 'Deltas'. +collectPatBind (AnnPatBind grhs) = do + -- use 'mempty' as fallback 'Deltas' because we discard it anyway + (cirb, _) <- collectGRHS mempty grhs + pure (cirb, ()) {- Note [Determining inaccessible clauses] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1239,26 +1169,29 @@ arguments we can ever reach clause 2's RHS, so we say it has inaccessible RHS (as opposed to being completely redundant). We detect an inaccessible RHS simply by pretending it's redundant, until we see -that it's part of a sub-tree in the pattern match that forces some argument -(which corresponds to wrapping the 'AnnotatedTree' in 'MayDiverge'). Then we -turn all supposedly redundant RHSs into inaccessible ones. - -But as it turns out (@g@ from #17465) this is too conservative: - g () | False = () - | otherwise = () -g's first clause has an inaccessible RHS, but it's also safe to delete. So it's -redundant, really! But by just turning all redundant child clauses into -inaccessible ones, we report the first clause as inaccessible. - -Clearly, it is enough if we say that we only degrade if *not all* of the child -clauses are redundant. As long as there is at least one clause which we announce -not to be redundant, the guard prefix responsible for the 'MayDiverge' will -survive. Hence we check for that in 'extractRedundancyInfo'. -} --- | Issue all the warnings (coverage, exhaustiveness, inaccessibility) -dsPmWarn :: DynFlags -> DsMatchContext -> [Id] -> CheckResult -> DsM () -dsPmWarn dflags ctx@(DsMatchContext kind loc) vars result +-- +-- * Formatting and reporting warnings +-- + +-- | Given a 'CIRBCollector', this function will emit warnings for a +-- 'CheckResult' and return the collected long-distance information. +formatReportWarnings :: CIRBCollector ann ldi -> DsMatchContext -> [Id] -> CheckResult ann -> DsM ldi +formatReportWarnings collect ctx vars cr at CheckResult { cr_ret = ann } = do + (cov_info, ldi) <- collect ann + dflags <- getDynFlags + reportWarnings dflags ctx vars cr{cr_ret=cov_info} + pure ldi + +-- | Issue all the warnings (redundancy, inaccessibility, exhaustiveness) +reportWarnings :: DynFlags -> DsMatchContext -> [Id] -> CheckResult CIRB -> DsM () +reportWarnings dflags ctx@(DsMatchContext kind loc) vars + CheckResult { cr_ret = CIRB { cirb_inacc = inaccessible_rhss + , cirb_red = redundant_rhss + , cirb_bangs = redundant_bangs } + , cr_uncov = uncovered + , cr_approx = precision } = when (flag_i || flag_u || flag_b) $ do unc_examples <- getNFirstUncovered vars (maxPatterns + 1) uncovered let exists_r = flag_i && notNull redundant_rhss @@ -1284,13 +1217,6 @@ dsPmWarn dflags ctx@(DsMatchContext kind loc) vars result when exists_u $ putSrcSpanDs loc $ warnDs flag_u_reason $ pprEqns vars unc_examples where - CheckResult - { cr_clauses = clauses - , cr_uncov = uncovered - , cr_approx = precision } = result - RedundancyInfo{redundant_rhss, inaccessible_rhss, redundant_bangs} - = extractRedundancyInfo clauses - flag_i = overlapping dflags kind flag_u = exhaustive dflags kind flag_b = redundant_bang dflags @@ -1331,44 +1257,31 @@ getNFirstUncovered vars n (MkDeltas deltas) = go n (bagToList deltas) back <- go (n - length front) deltas pure (front ++ back) -{- Note [Inaccessible warnings for record updates] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider (#12957) - data T a where - T1 :: { x :: Int } -> T Bool - T2 :: { x :: Int } -> T a - T3 :: T a - - f :: T Char -> T a - f r = r { x = 3 } - -The desugarer will (conservatively generate a case for T1 even though -it's impossible: - f r = case r of - T1 x -> T1 3 -- Inaccessible branch - T2 x -> T2 3 - _ -> error "Missing" - -We don't want to warn about the inaccessible branch because the programmer -didn't put it there! So we filter out the warning here. - -The same can happen for long distance term constraints instead of type -constraints (#17783): - - data T = A { x :: Int } | B { x :: Int } - f r at A{} = r { x = 3 } - f _ = B 0 - -Here, the long distance info from the FunRhs match (@r ~ A x@) will make the -clause matching on @B@ of the desugaring to @case@ redundant. It's generated -code that we don't want to warn about. --} - dots :: Int -> [a] -> SDoc dots maxPatterns qs | qs `lengthExceeds` maxPatterns = text "..." | otherwise = empty +-- True <==> singular +pprContext :: Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc +pprContext singular (DsMatchContext kind _loc) msg rest_of_msg_fun + = vcat [text txt <+> msg, + sep [ text "In" <+> ppr_match <> char ':' + , nest 4 (rest_of_msg_fun pref)]] + where + txt | singular = "Pattern match" + | otherwise = "Pattern match(es)" + + (ppr_match, pref) + = case kind of + FunRhs { mc_fun = L _ fun } + -> (pprMatchContext kind, \ pp -> ppr fun <+> pp) + _ -> (pprMatchContext kind, \ pp -> pp) + +-- +-- * Utilities +-- + -- | All warning flags that need to run the pattern match checker. allPmCheckWarnings :: [WarningFlag] allPmCheckWarnings = @@ -1411,18 +1324,151 @@ exhaustiveWarningFlag ThPatQuote = Nothing -- etc. They are often *supposed* to be incomplete exhaustiveWarningFlag (StmtCtxt {}) = Nothing --- True <==> singular -pprContext :: Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc -pprContext singular (DsMatchContext kind _loc) msg rest_of_msg_fun - = vcat [text txt <+> msg, - sep [ text "In" <+> ppr_match <> char ':' - , nest 4 (rest_of_msg_fun pref)]] - where - txt | singular = "Pattern match" - | otherwise = "Pattern match(es)" +-- | Check whether any part of pattern match checking is enabled for this +-- 'HsMatchContext' (does not matter whether it is the redundancy check or the +-- exhaustiveness check). +isMatchContextPmChecked :: DynFlags -> Origin -> HsMatchContext id -> Bool +isMatchContextPmChecked dflags origin kind + | isGenerated origin + = False + | otherwise + = overlapping dflags kind || exhaustive dflags kind - (ppr_match, pref) - = case kind of - FunRhs { mc_fun = L _ fun } - -> (pprMatchContext kind, \ pp -> ppr fun <+> pp) - _ -> (pprMatchContext kind, \ pp -> pp) +-- | Return True when any of the pattern match warnings ('allPmCheckWarnings') +-- are enabled, in which case we need to run the pattern match checker. +needToRunPmCheck :: DynFlags -> Origin -> Bool +needToRunPmCheck dflags origin + | isGenerated origin + = False + | otherwise + = notNull (filter (`wopt` dflags) allPmCheckWarnings) + +{- Note [Inaccessible warnings for record updates] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider (#12957) + data T a where + T1 :: { x :: Int } -> T Bool + T2 :: { x :: Int } -> T a + T3 :: T a + + f :: T Char -> T a + f r = r { x = 3 } + +The desugarer will (conservatively generate a case for T1 even though +it's impossible: + f r = case r of + T1 x -> T1 3 -- Inaccessible branch + T2 x -> T2 3 + _ -> error "Missing" + +We don't want to warn about the inaccessible branch because the programmer +didn't put it there! So we filter out the warning here. + +The same can happen for long distance term constraints instead of type +constraints (#17783): + + data T = A { x :: Int } | B { x :: Int } + f r at A{} = r { x = 3 } + f _ = B 0 + +Here, the long distance info from the FunRhs match (@r ~ A x@) will make the +clause matching on @B@ of the desugaring to @case@ redundant. It's generated +code that we don't want to warn about. +-} + +-- +-- * Long-distance information +-- + +-- | Locally update 'dsl_deltas' with the given action, but defer evaluation +-- with 'unsafeInterleaveM' in order not to do unnecessary work. +locallyExtendPmDeltas :: (Deltas -> DsM Deltas) -> DsM a -> DsM a +locallyExtendPmDeltas ext k = do + deltas <- getPmDeltas + deltas' <- unsafeInterleaveM $ do + deltas' <- ext deltas + inh <- isInhabited deltas' + -- If adding a constraint would lead to a contradiction, don't add it. + -- See Note [Recovering from unsatisfiable pattern-matching constraints] + -- for why this is done. + if inh + then pure deltas' + else pure deltas + updPmDeltas deltas' k + +-- | Add in-scope type constraints if the coverage checker might run and then +-- run the given action. +addTyCs :: Origin -> Bag EvVar -> DsM a -> DsM a +addTyCs origin ev_vars m = do + dflags <- getDynFlags + applyWhen (needToRunPmCheck dflags origin) + (locallyExtendPmDeltas (\deltas -> addPmCtsDeltas deltas (PmTyCt . evVarPred <$> ev_vars))) + m + +-- | Add equalities for the 'CoreExpr' scrutinee to the local 'DsM' environment +-- when checking a case expression: +-- case e of x { matches } +-- When checking matches we record that (x ~ e) where x is the initial +-- uncovered. All matches will have to satisfy this equality. +addCoreScrutTmCs :: Maybe CoreExpr -> [Id] -> DsM a -> DsM a +addCoreScrutTmCs Nothing _ k = k +addCoreScrutTmCs (Just scr) [x] k = + flip locallyExtendPmDeltas k $ \deltas -> + addPmCtsDeltas deltas (unitBag (PmCoreCt x scr)) +addCoreScrutTmCs _ _ _ = panic "addCoreScrutTmCs: scrutinee, but more than one match id" + +-- | 'addCoreScrutTmCs', but desugars the 'LHsExpr' first. +addHsScrutTmCs :: Maybe (LHsExpr GhcTc) -> [Id] -> DsM a -> DsM a +addHsScrutTmCs Nothing _ k = k +addHsScrutTmCs (Just scr) vars k = do + scr_e <- dsLExpr scr + addCoreScrutTmCs (Just scr_e) vars k + +{- Note [Long-distance information] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider + + data Color = R | G | B + f :: Color -> Int + f R = … + f c = … (case c of + G -> True + B -> False) … + +Humans can make the "long-distance connection" between the outer pattern match +and the nested case pattern match to see that the inner pattern match is +exhaustive: @c@ can't be @R@ anymore because it was matched in the first clause +of @f at . + +To achieve similar reasoning in the coverage checker, we keep track of the set +of values that can reach a particular program point (often loosely referred to +as "Covered set") in 'GHC.HsToCore.Monad.dsl_deltas'. +We fill that set with Covered Deltas returned by the exported checking +functions, which the call sites put into place with +'GHC.HsToCore.Monad.updPmDeltas'. +Call sites also extend this set with facts from type-constraint dictionaries, +case scrutinees, etc. with the exported functions 'addTyCs', 'addCoreScrutTmCs' +and 'addHsScrutTmCs'. + +Note [Recovering from unsatisfiable pattern-matching constraints] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider the following code (see #12957 and #15450): + + f :: Int ~ Bool => () + f = case True of { False -> () } + +We want to warn that the pattern-matching in `f` is non-exhaustive. But GHC +used not to do this; in fact, it would warn that the match was /redundant/! +This is because the constraint (Int ~ Bool) in `f` is unsatisfiable, and the +coverage checker deems any matches with unsatisfiable constraint sets to be +unreachable. + +We can do better than this, by making sure that the Covered set used for +Note [Long-distance information] is always inhabited. +For Covered sets returned by the exported checking functions, that is ensured +in 'testRedSets', which takes and returns a non-empty fallback 'Deltas' in case +the refined Covered set became uninhabited. +Also, whenever "external" knowledge from a type constraint or case scrutinee is +integrated, we only commit that knowledge to 'GHC.HsToCore.Monad.dsl_deltas' if +the set remains inhabited. That check happens in 'locallyExtendPmDeltas'. +-} ===================================== compiler/GHC/HsToCore/PmCheck/Oracle.hs ===================================== @@ -166,25 +166,6 @@ mkOneConFull arg_tys con = do -- * Pattern match oracle -{- Note [Recovering from unsatisfiable pattern-matching constraints] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider the following code (see #12957 and #15450): - - f :: Int ~ Bool => () - f = case True of { False -> () } - -We want to warn that the pattern-matching in `f` is non-exhaustive. But GHC -used not to do this; in fact, it would warn that the match was /redundant/! -This is because the constraint (Int ~ Bool) in `f` is unsatisfiable, and the -coverage checker deems any matches with unsatisfiable constraint sets to be -unreachable. - -We decide to better than this. When beginning coverage checking, we first -check if the constraints in scope are unsatisfiable, and if so, we start -afresh with an empty set of constraints. This way, we'll get the warnings -that we expect. --} - ------------------------------------- -- * Composable satisfiability checks @@ -1265,7 +1246,7 @@ isTyConTriviallyInhabited tc = elementOfUniqSet tc triviallyInhabitedTyCons {- Note [Checking EmptyCase Expressions] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Empty case expressions are strict on the scrutinee. That is, `case x of {}` -will force argument `x`. Hence, `covCheckMatchGroup` is not sufficient for checking +will force argument `x`. Hence, `covCheckMatches` is not sufficient for checking empty cases, because it assumes that the match is not strict (which is true for all other cases, apart from EmptyCase). This gave rise to #10746. Instead, we do the following: ===================================== compiler/GHC/HsToCore/PmCheck/Types.hs ===================================== @@ -592,5 +592,8 @@ instance Outputable Deltas where instance Semigroup Deltas where MkDeltas l <> MkDeltas r = MkDeltas (l `unionBags` r) +instance Monoid Deltas where + mempty = MkDeltas emptyBag + liftDeltasM :: Monad m => (Delta -> m (Maybe Delta)) -> Deltas -> m Deltas liftDeltasM f (MkDeltas ds) = MkDeltas . catBagMaybes <$> (traverse f ds) ===================================== compiler/GHC/Tc/Types.hs ===================================== @@ -323,7 +323,7 @@ data DsLclEnv = DsLclEnv { dsl_meta :: DsMetaEnv, -- Template Haskell bindings dsl_loc :: RealSrcSpan, -- To put in pattern-matching error msgs - -- See Note [Note [Type and Term Equality Propagation] in "GHC.HsToCore.PmCheck" + -- See Note [Note [Long-distance information] in "GHC.HsToCore.PmCheck" -- The set of reaching values Deltas is augmented as we walk inwards, -- refined through each pattern match in turn dsl_deltas :: Deltas ===================================== compiler/GHC/Utils/Misc.hs ===================================== @@ -556,9 +556,8 @@ isSingleton :: [a] -> Bool isSingleton [_] = True isSingleton _ = False -notNull :: [a] -> Bool -notNull [] = False -notNull _ = True +notNull :: Foldable f => f a -> Bool +notNull = not . null only :: [a] -> a #if defined(DEBUG) ===================================== testsuite/tests/deSugar/should_compile/ds020.stderr ===================================== @@ -18,3 +18,11 @@ ds020.hs:20:1: warning: [-Woverlapping-patterns (in -Wdefault)] ds020.hs:23:1: warning: [-Woverlapping-patterns (in -Wdefault)] Pattern match is redundant In an equation for ‘f’: f x@(~[]) = ... + +ds020.hs:32:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: (x1 : xs1 : ys1) = ... + +ds020.hs:33:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: (~x : ~xs : ~ys) = ... ===================================== testsuite/tests/module/all.T ===================================== @@ -83,7 +83,7 @@ test('mod61', normal, compile_fail, ['']) test('mod62', normal, compile_fail, ['']) test('mod63', normal, compile_fail, ['']) test('mod64', normal, compile, ['']) -test('mod65', normal, compile, ['']) +test('mod65', normal, compile, ['-Wno-overlapping-patterns']) test('mod66', normal, compile_fail, ['']) test('mod67', normal, compile_fail, ['']) test('mod68', normal, compile_fail, ['']) ===================================== testsuite/tests/pmcheck/should_compile/T18572.hs ===================================== @@ -3,10 +3,10 @@ module T18572 where -True = True +True = True -- no warning data SBool (b :: Bool) where STrue :: SBool True SFalse :: SBool False -STrue = SFalse +STrue = SFalse -- "redundant", not "inaccessible" ===================================== testsuite/tests/rename/should_compile/T7085.stderr ===================================== @@ -1,3 +1,7 @@ T7085.hs:8:6: warning: [-Wunused-pattern-binds (in -Wextra, -Wunused-binds)] This pattern-binding binds no variables: Nothing = Just n + +T7085.hs:8:6: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: Nothing = ... ===================================== testsuite/tests/unboxedsums/all.T ===================================== @@ -30,5 +30,5 @@ test('T12711', only_ways(['ghci']), ghci_script, ['T12711.script']) # extra_files([ "unboxedsums" + str(i) + ".hs" for i in range(1, 12) ])], # makefile_test, []) -test('UbxSumLevPoly', normal, compile, ['']) +test('UbxSumLevPoly', normal, compile, ['-Wno-overlapping-patterns']) test('T14051', normal, multi_compile, ['T14051.hs', [('T14051a.hs', '')], '-O2 -v0']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/eca5efc0c62fc53f50db6cf7b5afe2f5b495b825 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/eca5efc0c62fc53f50db6cf7b5afe2f5b495b825 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 27 18:14:18 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Thu, 27 Aug 2020 14:14:18 -0400 Subject: [Git][ghc/ghc][wip/T18341] 383 commits: Implement -XLexicalNegation (GHC Proposal #229) Message-ID: <5f47f7fa710c_80be8140a8965698b@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18341 at Glasgow Haskell Compiler / GHC Commits: cbb6b62f by Vladislav Zavialov at 2020-07-01T15:41:38-04:00 Implement -XLexicalNegation (GHC Proposal #229) This patch introduces a new extension, -XLexicalNegation, which detects whether the minus sign stands for negation or subtraction using the whitespace-based rules described in GHC Proposal #229. Updates haddock submodule. - - - - - fb5a0d01 by Martin Handley at 2020-07-01T15:42:14-04:00 #17169: Clarify Fixed's Enum instance. - - - - - b316804d by Simon Peyton Jones at 2020-07-01T15:42:49-04:00 Improve debug tracing for substitution This patch improves debug tracing a bit (#18395) * Remove the ancient SDoc argument to substitution, replacing it with a HasDebugCallStack constraint. The latter does the same job (indicate the call site) but much better. * Add HasDebugCallStack to simpleOptExpr, exprIsConApp_maybe I needed this to help nail the lookupIdSubst panic in #18326, #17784 - - - - - 5c9fabb8 by Hécate at 2020-07-01T15:43:25-04:00 Add most common return values for `os` and `arch` - - - - - 76d8cc74 by Ryan Scott at 2020-07-01T15:44:01-04:00 Desugar quoted uses of DerivingVia and expression type signatures properly The way that `GHC.HsToCore.Quote` desugared quoted `via` types (e.g., `deriving via forall a. [a] instance Eq a => Eq (List a)`) and explicit type annotations in signatures (e.g., `f = id @a :: forall a. a -> a`) was completely wrong, as it did not implement the scoping guidelines laid out in `Note [Scoped type variables in bindings]`. This is easily fixed. While I was in town, I did some minor cleanup of related Notes: * `Note [Scoped type variables in bindings]` and `Note [Scoped type variables in class and instance declarations]` say very nearly the same thing. I decided to just consolidate the two Notes into `Note [Scoped type variables in quotes]`. * `Note [Don't quantify implicit type variables in quotes]` is somewhat outdated, as it predates GHC 8.10, where the `forall`-or-nothing rule requires kind variables to be explicitly quantified in the presence of an explicit `forall`. As a result, the running example in that Note doesn't even compile. I have changed the example to something simpler that illustrates the same point that the original Note was making. Fixes #18388. - - - - - 44d6a335 by Andreas Klebinger at 2020-07-02T02:54:54-04:00 T16012: Be verbose on failure. - - - - - f9853330 by Ryan Scott at 2020-07-02T02:55:29-04:00 Bump ghc-prim version to 0.7.0 Fixes #18279. Bumps the `text` submodule. - - - - - 23e4e047 by Sylvain Henry at 2020-07-02T10:46:31-04:00 Hadrian: fix PowerPC64le support (#17601) [ci skip] - - - - - 3cdd8d69 by Sylvain Henry at 2020-07-02T10:47:08-04:00 NCG: correctly handle addresses with huge offsets (#15570) Before this patch we could generate addresses of this form: movzbl cP0_str+-9223372036854775808,%eax The linker can't handle them because the offset is too large: ld.lld: error: Main.o:(.text+0xB3): relocation R_X86_64_32S out of range: -9223372036852653050 is not in [-2147483648, 2147483647] With this patch we detect those cases and generate: movq $-9223372036854775808,%rax addq $cP0_str,%rax movzbl (%rax),%eax I've also refactored `getAmode` a little bit to make it easier to understand and to trace. - - - - - 4d90b3ff by Gabor Greif at 2020-07-02T20:07:59-04:00 No need for CURSES_INCLUDE_DIRS This is a leftover from ef63ff27251a20ff11e58c9303677fa31e609a88 - - - - - f08d6316 by Sylvain Henry at 2020-07-02T20:08:36-04:00 Replace Opt_SccProfilingOn flag with sccProfilingEnabled helper function SCC profiling was enabled in a convoluted way: if WayProf was enabled, Opt_SccProfilingOn general flag was set (in `GHC.Driver.Ways.wayGeneralFlags`), and then this flag was queried in various places. There is no need to go via general flags, so this patch defines a `sccProfilingEnabled :: DynFlags -> Bool` helper function that just checks whether WayProf is enabled. - - - - - 8cc7274b by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Only allocate the Censuses that we need When not LDV profiling there is no reason to allocate 32 Censuses; one will do. This is a very small memory footprint optimisation, but it comes for free. - - - - - b835112c by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Free old allocations when reinitialising Censuses Previously when not LDV profiling we would repeatedly reinitialise `censuses[0]` with `initEra`. This failed to free the `Arena` and `HashTable` from the old census, resulting in a memory leak. Fixes #18348. - - - - - 34be6523 by Valery Tolstov at 2020-07-03T02:50:03-04:00 Mention flags that are not enabled by -Wall (#18372) * Mention missing flags that are not actually enabled by -Wall (docs/users_guide/using-warnings.rst) * Additionally remove -Wmissing-monadfail-instances from the list of flags enabled by -Wcompat, as it is not the case since 8.8 - - - - - edc8d22b by Sylvain Henry at 2020-07-03T02:50:40-04:00 LLVM: support R9 and R10 registers d535ef006d85dbdb7cda2b09c5bc35cb80108909 allowed the use of up to 10 vanilla registers but didn't update LLVM backend to support them. This patch fixes it. - - - - - 4bf18646 by Simon Peyton Jones at 2020-07-03T08:37:42+01:00 Improve handling of data type return kinds Following a long conversation with Richard, this patch tidies up the handling of return kinds for data/newtype declarations (vanilla, family, and instance). I have substantially edited the Notes in TyCl, so they would bear careful reading. Fixes #18300, #18357 In GHC.Tc.Instance.Family.newFamInst we were checking some Lint-like properties with ASSSERT. Instead Richard and I have added a proper linter for axioms, and called it from lintGblEnv, which in turn is called in tcRnModuleTcRnM New tests (T18300, T18357) cause an ASSERT failure in HEAD. - - - - - 41d26492 by Sylvain Henry at 2020-07-03T17:33:59-04:00 DynFlags: avoid the use of sdocWithDynFlags in GHC.Core.Rules (#17957) - - - - - 7aa6ef11 by Hécate at 2020-07-03T17:34:36-04:00 Add the __GHC_FULL_VERSION__ CPP macro to expose the full GHC version - - - - - e61d5395 by Chaitanya Koparkar at 2020-07-07T13:55:59-04:00 ghc-prim: Turn some comments into haddocks [ci skip] - - - - - 37743f91 by John Ericson at 2020-07-07T13:56:00-04:00 Support `timesInt2#` in LLVM backend - - - - - 46397e53 by John Ericson at 2020-07-07T13:56:00-04:00 `genericIntMul2Op`: Call `genericWordMul2Op` directly This unblocks a refactor, and removes partiality. It might be a PowerPC regression but that should be fixable. - - - - - 8a1c0584 by John Ericson at 2020-07-07T13:56:00-04:00 Simplify `PrimopCmmEmit` Follow @simonpj's suggestion of pushing the "into regs" logic into `emitPrimOp`. With the previous commit getting rid of the recursion in `genericIntMul2Op`, this is now an easy refactor. - - - - - 6607f203 by John Ericson at 2020-07-07T13:56:00-04:00 `opAllDone` -> `opIntoRegs` The old name was and terrible and became worse after the previous commit's refactor moved non-trivial funcationlity into its body. - - - - - fdcc53ba by Sylvain Henry at 2020-07-07T13:56:00-04:00 Optimise genericIntMul2Op We shouldn't directly call 'genericWordMul2Op' in genericIntMul2Op because a target may provide a faster primop for 'WordMul2Op': we'd better use it! - - - - - 686e7225 by Moritz Angermann at 2020-07-07T13:56:01-04:00 [linker/rtsSymbols] More linker symbols Mostly symbols needed for aarch64/armv7l and in combination with musl, where we have to rely on loading *all* objects/archives - __stack_chk_* only when not DYNAMIC - - - - - 3f60b94d by Moritz Angermann at 2020-07-07T13:56:01-04:00 better if guards. - - - - - 7abffced by Moritz Angermann at 2020-07-07T13:56:01-04:00 Fix (1) - - - - - cdfeb3f2 by Moritz Angermann at 2020-07-07T13:56:01-04:00 AArch32 symbols only on aarch32. - - - - - f496c955 by Adam Sandberg Ericsson at 2020-07-07T13:56:02-04:00 add -flink-rts flag to link the rts when linking a shared or static library #18072 By default we don't link the RTS when linking shared libraries because in the most usual mode a shared library is an intermediary product, for example a Haskell library, that will be linked into some executable in the end. So we wish to defer the RTS flavour to link to the final link. However sometimes the final product is the shared library, for example when writing a plugin for some other system, so we do wish the shared library to link the RTS. For consistency we also make -staticlib honor this flag and its inversion. -staticlib currently implies -flink-shared. - - - - - c59faf67 by Stefan Schulze Frielinghaus at 2020-07-07T13:56:04-04:00 hadrian: link check-ppr against debugging RTS if ghcDebugged - - - - - 0effc57d by Adam Sandberg Ericsson at 2020-07-07T13:56:05-04:00 rts linker: teach the linker about GLIBC's special handling of *stat, mknod and atexit functions #7072 - - - - - 96153433 by Adam Sandberg Ericsson at 2020-07-07T13:56:06-04:00 hadrian: make hadrian/ghci use the bootstrap compiler from configure #18190 - - - - - 4d24f886 by Adam Sandberg Ericsson at 2020-07-07T13:56:07-04:00 hadrian: ignore cabal configure verbosity related flags #18131 - - - - - 7332bbff by Ben Gamari at 2020-07-07T13:56:08-04:00 testsuite: Widen T12234 acceptance window to 2% Previously it wasn't uncommon to see +/-1% fluctuations in compiler allocations on this test. - - - - - 180b6313 by Gabor Greif at 2020-07-07T13:56:08-04:00 When running libtool, report it as such - - - - - d3bd6897 by Sylvain Henry at 2020-07-07T13:56:11-04:00 BigNum: rename BigNat types Before this patch BigNat names were confusing because we had: * GHC.Num.BigNat.BigNat: unlifted type used everywhere else * GHC.Num.BigNat.BigNatW: lifted type only used to share static constants * GHC.Natural.BigNat: lifted type only used for backward compatibility After this patch we have: * GHC.Num.BigNat.BigNat#: unlifted type * GHC.Num.BigNat.BigNat: lifted type (reexported from GHC.Natural) Thanks to @RyanGlScott for spotting this. - - - - - 929d26db by Sylvain Henry at 2020-07-07T13:56:12-04:00 Bignum: don't build ghc-bignum with stage0 Noticed by @Ericson2314 - - - - - d25b6851 by Sylvain Henry at 2020-07-07T13:56:12-04:00 Hadrian: ghc-gmp.h shouldn't be a compiler dependency - - - - - 0ddae2ba by Sylvain Henry at 2020-07-07T13:56:14-04:00 DynFlags: factor out pprUnitId from "Outputable UnitId" instance - - - - - 204f3f5d by Krzysztof Gogolewski at 2020-07-07T13:56:18-04:00 Remove unused function pprHsForAllExtra (#18423) The function `pprHsForAllExtra` was called only on `Nothing` since 2015 (1e041b7382b6aa). - - - - - 3033e0e4 by Adam Sandberg Ericsson at 2020-07-08T20:36:49-04:00 hadrian: add flag to skip rebuilding dependency information #17636 - - - - - b7de4b96 by Stefan Schulze Frielinghaus at 2020-07-09T09:49:22-04:00 Fix GHCi :print on big-endian platforms On big-endian platforms executing import GHC.Exts data Foo = Foo Float# deriving Show foo = Foo 42.0# foo :print foo results in an arithmetic overflow exception which is caused by function index where moveBytes equals word_size - (r + item_size_b) * 8 Here we have a mixture of units. Both, word_size and item_size_b have unit bytes whereas r has unit bits. On 64-bit platforms moveBytes equals then 8 - (0 + 4) * 8 which results in a negative and therefore invalid second parameter for a shiftL operation. In order to make things more clear the expression (word .&. (mask `shiftL` moveBytes)) `shiftR` moveBytes is equivalent to (word `shiftR` moveBytes) .&. mask On big-endian platforms the shift must be a left shift instead of a right shift. For symmetry reasons not a mask is used but two shifts in order to zero out bits. Thus the fixed version equals case endian of BigEndian -> (word `shiftL` moveBits) `shiftR` zeroOutBits `shiftL` zeroOutBits LittleEndian -> (word `shiftR` moveBits) `shiftL` zeroOutBits `shiftR` zeroOutBits Fixes #16548 and #14455 - - - - - 3656dff8 by Sylvain Henry at 2020-07-09T09:50:01-04:00 LLVM: fix MO_S_Mul2 support (#18434) The value indicating if the carry is useful wasn't taken into account. - - - - - d9f09506 by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Define multiShotIO and use it in mkSplitUniqueSupply This patch is part of the ongoing eta-expansion saga; see #18238. It implements a neat trick (suggested by Sebastian Graf) that allows the programmer to disable the default one-shot behaviour of IO (the "state hack"). The trick is to use a new multiShotIO function; see Note [multiShotIO]. For now, multiShotIO is defined here in Unique.Supply; but it should ultimately be moved to the IO library. The change is necessary to get good code for GHC's unique supply; see Note [Optimising the unique supply]. However it makes no difference to GHC as-is. Rather, it makes a difference when a subsequent commit Improve eta-expansion using ArityType lands. - - - - - bce695cc by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Make arityType deal with join points As Note [Eta-expansion and join points] describes, this patch makes arityType deal correctly with join points. What was there before was not wrong, but yielded lower arities than it could. Fixes #18328 In base GHC this makes no difference to nofib. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- n-body -0.1% -0.1% -1.2% -1.1% 0.0% -------------------------------------------------------------------------------- Min -0.1% -0.1% -55.0% -56.5% 0.0% Max -0.0% 0.0% +16.1% +13.4% 0.0% Geometric Mean -0.0% -0.0% -30.1% -31.0% -0.0% But it starts to make real difference when we land the change to the way mkDupableAlts handles StrictArg, in fixing #13253 and friends. I think this is because we then get more non-inlined join points. - - - - - 2b7c71cb by Simon Peyton Jones at 2020-07-11T12:17:02-04:00 Improve eta-expansion using ArityType As #18355 shows, we were failing to preserve one-shot info when eta-expanding. It's rather easy to fix, by using ArityType more, rather than just Arity. This patch is important to suport the one-shot monad trick; see #18202. But the extra tracking of one-shot-ness requires the patch Define multiShotIO and use it in mkSplitUniqueSupply If that patch is missing, ths patch makes things worse in GHC.Types.Uniq.Supply. With it, however, we see these improvements T3064 compiler bytes allocated -2.2% T3294 compiler bytes allocated -1.3% T12707 compiler bytes allocated -1.3% T13056 compiler bytes allocated -2.2% Metric Decrease: T3064 T3294 T12707 T13056 - - - - - de139cc4 by Artem Pelenitsyn at 2020-07-12T02:53:20-04:00 add reproducer for #15630 - - - - - c4de6a7a by Andreas Klebinger at 2020-07-12T02:53:55-04:00 Give Uniq[D]FM a phantom type for its key. This fixes #17667 and should help to avoid such issues going forward. The changes are mostly mechanical in nature. With two notable exceptions. * The register allocator. The register allocator references registers by distinct uniques. However they come from the types of VirtualReg, Reg or Unique in various places. As a result we sometimes cast the key type of the map and use functions which operate on the now typed map but take a raw Unique as actual key. The logic itself has not changed it just becomes obvious where we do so now. * <Type>Env Modules. As an example a ClassEnv is currently queried using the types `Class`, `Name`, and `TyCon`. This is safe since for a distinct class value all these expressions give the same unique. getUnique cls getUnique (classTyCon cls) getUnique (className cls) getUnique (tcName $ classTyCon cls) This is for the most part contained within the modules defining the interface. However it requires us to play dirty when we are given a `Name` to lookup in a `UniqFM Class a` map. But again the logic did not change and it's for the most part hidden behind the Env Module. Some of these cases could be avoided by refactoring but this is left for future work. We also bump the haddock submodule as it uses UniqFM. - - - - - c2cfdfde by Aaron Allen at 2020-07-13T09:00:33-04:00 Warn about empty Char enumerations (#18402) Currently the "Enumeration is empty" warning (-Wempty-enumerations) only fires for numeric literals. This patch adds support for `Char` literals so that enumerating an empty list of `Char`s will also trigger the warning. - - - - - c3ac87ec by Stefan Schulze Frielinghaus at 2020-07-13T09:01:10-04:00 hadrian: build check-ppr dynamic if GHC is build dynamic Fixes #18361 - - - - - 9ad072b4 by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Use dumpStyle when printing inlinings This just makes debug-printing consistent, and more informative. - - - - - e78c4efb by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Comments only - - - - - 7ccb760b by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Reduce result discount in conSize Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c - - - - - 7f0b671e by Ben Gamari at 2020-07-13T14:52:49-04:00 testsuite: Widen acceptance threshold on T5837 This test is positively tiny and consequently the bytes allocated measurement will be relatively noisy. Consequently I have seen this fail spuriously quite often. - - - - - 118e1c3d by Alp Mestanogullari at 2020-07-14T21:30:52-04:00 compiler: re-engineer the treatment of rebindable if Executing on the plan described in #17582, this patch changes the way if expressions are handled in the compiler in the presence of rebindable syntax. We get rid of the SyntaxExpr field of HsIf and instead, when rebindable syntax is on, we rewrite the HsIf node to the appropriate sequence of applications of the local `ifThenElse` function. In order to be able to report good error messages, with expressions as they were written by the user (and not as desugared by the renamer), we make use of TTG extensions to extend GhcRn expression ASTs with an `HsExpansion` construct, which keeps track of a source (GhcPs) expression and the desugared (GhcRn) expression that it gives rise to. This way, we can typecheck the latter while reporting the former in error messages. In order to discard the error context lines that arise from typechecking the desugared expressions (because they talk about expressions that the user has not written), we carefully give a special treatment to the nodes fabricated by this new renaming-time transformation when typechecking them. See Note [Rebindable syntax and HsExpansion] for more details. The note also includes a recipe to apply the same treatment to other rebindable constructs. Tests 'rebindable11' and 'rebindable12' have been added to make sure we report identical error messages as before this patch under various circumstances. We also now disable rebindable syntax when processing untyped TH quotes, as per the discussion in #18102 and document the interaction of rebindable syntax and Template Haskell, both in Note [Template Haskell quotes and Rebindable Syntax] and in the user guide, adding a test to make sure that we do not regress in that regard. - - - - - 64c774b0 by Andreas Klebinger at 2020-07-14T21:31:27-04:00 Explain why keeping DynFlags in AnalEnv saves allocation. - - - - - 254245d0 by Ben Gamari at 2020-07-14T21:32:03-04:00 docs/users-guide: Update default -funfolding-use-threshold value This was changed in 3d2991f8 but I neglected to update the documentation. Fixes #18419. - - - - - 4c259f86 by Andreas Klebinger at 2020-07-14T21:32:41-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. - - - - - 23797224 by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 .gitlab: re-enable integer-simple substitute (BIGNUM_BACKEND) Recently build system migrated from INTEGER_LIBRARY to BIGNUM_BACKEND. But gitlab CI was never updated. Let's enable BIGNUM_BACKEND=native. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - e0db878a by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 ghc-bignum: bring in sync .hs-boot files with module declarations Before this change `BIGNUM_BACKEND=native` build was failing as: ``` libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs:708:16: error: * Variable not in scope: naturalFromBigNat# :: WordArray# -> t * Perhaps you meant one of these: `naturalFromBigNat' (imported from GHC.Num.Natural), `naturalToBigNat' (imported from GHC.Num.Natural) | 708 | m' = naturalFromBigNat# m | ``` This happens because `.hs-boot` files are slightly out of date. This change brings in data and function types in sync. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - c9f65c36 by Stefan Schulze Frielinghaus at 2020-07-14T21:33:57-04:00 rts/Disassembler.c: Use FMT_HexWord for printing values in hex format - - - - - 58ae62eb by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 macOS: Load frameworks without stating them first. macOS Big Sur makes the following change to how frameworks are shipped with the OS: > New in macOS Big Sur 11 beta, the system ships with a built-in > dynamic linker cache of all system-provided libraries. As part of > this change, copies of dynamic libraries are no longer present on > the filesystem. Code that attempts to check for dynamic library > presence by looking for a file at a path or enumerating a directory > will fail. Instead, check for library presence by attempting to > dlopen() the path, which will correctly check for the library in the > cache. (62986286) https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/ Therefore, the previous method of checking whether a library exists before attempting to load it makes GHC.Runtime.Linker.loadFramework fail to find frameworks installed at /System/Library/Frameworks. GHC.Runtime.Linker.loadFramework now opportunistically loads the framework libraries without checking for their existence first, failing only if all attempts to load a given framework from any of the various possible locations fail. - - - - - cdc4a6b0 by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 loadFramework: Output the errors collected in all loading attempts. With the recent change away from first finding and then loading a framework, loadFramework had no way of communicating the real reason why loadDLL failed if it was any reason other than the framework missing from the file system. It now collects all loading attempt errors into a list and concatenates them into a string to return to the caller. - - - - - 51dbfa52 by Ben Gamari at 2020-07-15T04:05:34-04:00 StgToCmm: Use CmmRegOff smart constructor Previously we would generate expressions of the form `CmmRegOff BaseReg 0`. This should do no harm (and really should be handled by the NCG anyways) but it's better to just generate a plain `CmmReg`. - - - - - ae11bdfd by Ben Gamari at 2020-07-15T04:06:08-04:00 testsuite: Add regression test for #17744 Test due to @monoidal. - - - - - 0e3c277a by Ben Gamari at 2020-07-15T16:41:01-04:00 Bump Cabal submodule Updates a variety of tests as Cabal is now more strict about Cabal file form. - - - - - ceed994a by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Drop Windows Vista support, require Windows 7 - - - - - 00a23bfd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Update Windows FileSystem wrapper utilities. - - - - - 459e1c5f by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Use SlimReaderLocks and ConditonalVariables provided by the OS instead of emulated ones - - - - - 763088fc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Small linker comment and ifdef cleanups - - - - - 1a228ff9 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Flush event logs eagerly. - - - - - e9e04dda by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Refactor Buffer structures to be able to track async operations - - - - - 356dc3fe by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Implement new Console API - - - - - 90e69f77 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add IOPort synchronization primitive - - - - - 71245fcc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add new io-manager cmdline options - - - - - d548a3b3 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Init Windows console Codepage to UTF-8. - - - - - 58ef6366 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add unsafeSplat to GHC.Event.Array - - - - - d660725e by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add size and iterate to GHC.Event.IntTable. - - - - - 050da6dd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Switch Testsuite to test winio by default - - - - - 4bf542bf by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Multiple refactorings and support changes. - - - - - 4489af6b by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core threaded I/O manager - - - - - 64d8f2fe by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core non-threaded I/O manager - - - - - 8da15a09 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix a scheduler bug with the threaded-runtime. - - - - - 84ea3d14 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Relaxing some constraints in io-manager. - - - - - ccf0d107 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix issues with non-threaded I/O manager after split. - - - - - b492fe6e by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Remove some barf statements that are a bit strict. - - - - - 01423fd2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Expand comments describing non-threaded loop - - - - - 4b69004f by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: fix FileSize unstat-able handles - - - - - 9b384270 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Implement new tempfile routines for winio - - - - - f1e0be82 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix input truncation when reading from handle. This was caused by not upholding the read buffer invariant that bufR == bufL == 0 for empty read buffers. - - - - - e176b625 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix output truncation for writes larger than buffer size - - - - - a831ce0e by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Rewrite bufWrite. I think it's far easier to follow the code now. It's also correct now as I had still missed a spot where we didn't update the offset. - - - - - 6aefdf62 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix offset set by bufReadEmpty. bufReadEmpty returns the bytes read *including* content that was already buffered, But for calculating the offset we only care about the number of bytes read into the new buffer. - - - - - 750ebaee by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Clean up code surrounding IOPort primitives. According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc. - - - - - ffd31db9 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix multi threaded threadDelay and a few other small changes. Multithreaded threadDelay suffered from a race condition based on the ioManagerStatus. Since the status isn't needed for WIO I removed it completely. This resulted in a light refactoring, as consequence we will always wake up the IO manager using interruptSystemManager, which uses `postQueuedCompletionStatus` internally. I also added a few comments which hopefully makes the code easier to dive into for the next person diving in. - - - - - 6ec26df2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 wionio: Make IO subsystem check a no-op on non-windows platforms. - - - - - 29bcd936 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Set handle offset when opening files in Append mode. Otherwise we would truncate the file. - - - - - 55c29700 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Remove debug event log trace - - - - - 9acb9f40 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix sqrt and openFile009 test cases - - - - - 57017cb7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Allow hp2ps to build with -DDEBUG - - - - - b8cd9995 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update output of T9681 since we now actually run it. - - - - - 10af5b14 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: A few more improvements to the IOPort primitives. - - - - - 39afc4a7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix expected tempfiles output. Tempfiles now works properly on windows, as such we can delete the win32 specific output. - - - - - 99db46e0 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Assign thread labels to IOManager threads. - - - - - be6af732 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Properly check for the tso of an incall to be zero. - - - - - e2c6dac7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark FD instances as unsupported under WINIO. - - - - - fd02ceed by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix threadDelay maxBound invocations. Instead of letting the ns timer overflow now clamp it at (maxBound :: Word64) ns. That still gives a few hundred years. - - - - - bc79f9f1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comments/cleanup an import in base - - - - - 1d197f4b by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark outstanding_service_requests volatile. As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration. - - - - - dc438186 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Make last_event a local variable - - - - - 2fc957c5 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comment about thread safety of processCompletion. - - - - - 4c026b6c by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: nonthreaded: Create io processing threads in main thread. We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread. - - - - - f47c7208 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add an exported isHeapAlloced function to the RTS - - - - - cc5d7bb1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Queue IO processing threads at the front of the queue. This will unblock the IO thread sooner hopefully leading to higher throughput in some situations. - - - - - e7630115 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: ThreadDelay001: Use higher resolution timer. - - - - - 451b5f96 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update T9681 output, disable T4808 on windows. T4808 tests functionality of the FD interface which won't be supported under WINIO. T9681 just has it's expected output tweaked. - - - - - dd06f930 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Wake io manager once per registerTimeout. Which is implicitly done in editTimeouts, so need to wake it up twice. - - - - - e87d0bf9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update placeholder comment with actual function name. - - - - - fc9025db by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Always lock win32 event queue - - - - - c24c9a1f by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Display thread labels when tracing scheduler events. - - - - - 06542b03 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Refactor non-threaded runner thread and scheduler interface. Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event. - - - - - 256299b1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove outstanding_requests from runner. We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port. - - - - - 3ebd8ad9 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Various fixes related to rebase and testdriver - - - - - 6be6bcba by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Fix rebase artifacts - - - - - 2c649dc3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename unsafeSplat to unsafeCopyFromBuffer - - - - - a18b73f3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove unused size/iterate operations from IntTable - - - - - 16bab48e by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Detect running IO Backend via peeking at RtsConfig - - - - - 8b8405a0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update temp path so GCC etc can handle it. Also fix PIPE support, clean up error casting, fix memory leaks - - - - - 2092bc54 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Minor comments/renamings - - - - - a5b5b6c0 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Checking if an error code indicates completion is now a function. - - - - - 362176fd by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Small refactor in withOverlappedEx - - - - - 32e20597 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: A few comments and commented out dbxIO - - - - - a4bfc1d9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't drop buffer offset in byteView/cwcharView - - - - - b3ad2a54 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: revert BHandle changes. - - - - - 3dcd87e2 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Fix imports - - - - - 5a371890 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update ghc-cabal to handle new Cabal submodule bump - - - - - d07ebe0d by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Only compile sources on Windows - - - - - dcb42393 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Actually return Nothing on EOF for non-blocking read - - - - - 895a3beb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate logic in encodeMultiByte[Raw]IO. - - - - - e06e6734 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate openFile logic - - - - - b59430c0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: fix -werror issue in encoding file - - - - - f8d39a51 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't mention windows specific functions when building on Linux. - - - - - 6a533d2a by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add a note about file locking in the RTS. - - - - - cf37ce34 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Add version to @since annotation - - - - - 0fafa2eb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename GHC.Conc.IOCP -> GHC.Conc.WinIO - - - - - 1854fc23 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Expand GHC.Conc.POSIX description It now explains users may not use these functions when using the old IO manager. - - - - - fcc7ba41 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Fix potential spaceleak in __createUUIDTempFileErrNo - - - - - 6b3fd9fa by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant -Wno-missing-signatures pragmas - - - - - 916fc861 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Make it explicit that we only create one IO manager - - - - - f260a721 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Note why we don't use blocking waits. - - - - - aa0a4bbf by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove commented out pragma - - - - - d679b544 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant buffer write in Handle/Text.hs:bufReadEmpty - - - - - d3f94368 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename SmartHandles to StdHandles - - - - - bd6b8ec1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add comment stating failure behaviour for getUniqueFileInfo. - - - - - 12846b85 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update IOPort haddocks. - - - - - 9f39fb14 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Add a note cross reference - - - - - 62dd5a73 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Name Haskell/OS I/O Manager explicitly in Note - - - - - fa807828 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Expand BlockedOnIOCompletion description. - - - - - f0880a1d by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove historical todos - - - - - 8e58e714 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Update note, remove debugging pragma. - - - - - aa4d84d5 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: flushCharReadBuffer shouldn't need to adjust offsets. - - - - - e580893a by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove obsolete comment about cond. variables - - - - - d54e9d79 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix initial linux validate build - - - - - 3cd4de46 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix ThreadDelay001 CPP - - - - - c88b1b9f by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix openFile009 merge conflict leftover - - - - - 849e8889 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept T9681 output. GHC now reports String instead of [Char]. - - - - - e7701818 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix cabal006 after upgrading cabal submodule Demand cabal 2.0 syntax instead of >= 1.20 as required by newer cabal versions. - - - - - a44f0373 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix stderr output for ghci/linking/dyn tests. We used to filter rtsopts, i opted to instead just accept the warning of it having no effect. This works both for -rtsopts, as well as -with-rtsopts which winio adds. - - - - - 515d9896 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T15261b stdout for --io-manager flag. - - - - - 949aaacc by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T5435_dyn_asm stderr The warning about rtsopts having no consequences is expected. So accept new stderr. - - - - - 7d424e1e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Also accept T7037 stderr - - - - - 1f009768 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal04 by filtering rts args - - - - - 981a9f2e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal01 by accepting expected stderr - - - - - b7b0464e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix safePkg01 by accepting expected stderr - - - - - 32734b29 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix T5435_dyn_gcc by accepting expected stderr - - - - - acc5cebf by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix tempfiles test on linux - - - - - c577b789 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for T3807 - - - - - c108c527 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload - - - - - 2b0b9a08 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload_multiple_objs - - - - - 67afb03c by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify wording on conditional variables. - - - - - 3bd41572 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify comment on cooked mode. - - - - - ded58a03 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: update lockfile signature and remove mistaken symbol in rts. - - - - - 2143c492 by Ben Gamari at 2020-07-15T16:41:04-04:00 testsuite: Add winio and winio_threaded ways Reverts many of the testsuite changes - - - - - c0979cc5 by Ben Gamari at 2020-07-16T10:56:54-04:00 Merge remote-tracking branch 'origin/wip/winio' - - - - - 750a1595 by Ben Gamari at 2020-07-18T07:26:41-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. - - - - - 6ba6a881 by Hécate at 2020-07-18T07:26:42-04:00 Implement `fullCompilerVersion` Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403 This MR adds `fullCompilerVersion`, a function that shares the same backend as the `--numeric-version` GHC flag, exposing a full, three-digit version datatype. - - - - - e6cf27df by Hécate at 2020-07-18T07:26:43-04:00 Add a Lint hadrian rule and an .hlint.yaml file in base/ - - - - - bcb177dd by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Allow multiple case branches to have a higher rank type As #18412 points out, it should be OK for multiple case alternatives to have a higher rank type, provided they are all the same. This patch implements that change. It sweeps away GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it with an enhanced version of fillInferResult. The basic change to fillInferResult is to permit the case in which another case alternative has already filled in the result; and in that case simply unify. It's very simple actually. See the new Note [fillInferResult] in TcMType Other refactoring: - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType (previously some of it was in Unify) - Move tcInstType and friends from TcMType to Instantiate, where it more properly belongs. (TCMType was getting very long.) - - - - - e5525a51 by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Improve typechecking of NPlusK patterns This patch (due to Richard Eisenberg) improves documentation of the wrapper returned by tcSubMult (see Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify). And, more substantially, it cleans up the multiplicity handling in the typechecking of NPlusKPat - - - - - 12f90352 by Krzysztof Gogolewski at 2020-07-18T07:26:45-04:00 Remove {-# CORE #-} pragma (part of #18048) This pragma has no effect since 2011. It was introduced for External Core, which no longer exists. Updates haddock submodule. - - - - - e504c913 by Simon Peyton Jones at 2020-07-18T07:26:45-04:00 Refactor the simplification of join binders This MR (for #18449) refactors the Simplifier's treatment of join-point binders. Specifically, it puts together, into GHC.Core.Opt.Simplify.Env.adjustJoinPointType two currently-separate ways in which we adjust the type of a join point. As the comment says: -- (adjustJoinPointType mult new_res_ty join_id) does two things: -- -- 1. Set the return type of the join_id to new_res_ty -- See Note [Return type for join points] -- -- 2. Adjust the multiplicity of arrows in join_id's type, as -- directed by 'mult'. See Note [Scaling join point arguments] I think this actually fixes a latent bug, by ensuring that the seIdSubst and seInScope have the right multiplicity on the type of join points. I did some tidying up while I was at it. No more setJoinResTy, or modifyJoinResTy: instead it's done locally in Simplify.Env.adjustJoinPointType - - - - - 49b265f0 by Chaitanya Koparkar at 2020-07-18T07:26:46-04:00 Fix minor typos in a Core.hs note - - - - - 8d59aed6 by Stefan Schulze Frielinghaus at 2020-07-18T07:26:47-04:00 GHCi: Fix isLittleEndian - - - - - c26e81d1 by Ben Gamari at 2020-07-18T07:26:47-04:00 testsuite: Mark ghci tests as fragile under unreg compiler In particular I have seen T16012 fail repeatedly under the unregisterised compiler. - - - - - 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 293c7fba by Sylvain Henry at 2020-08-21T09:36:38-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - 50eb4460 by Sylvain Henry at 2020-08-21T09:36:38-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 659eb31b by Sylvain Henry at 2020-08-21T09:36:38-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 2d8ca917 by Sylvain Henry at 2020-08-21T09:37:15-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - fddddbf4 by Vladislav Zavialov at 2020-08-21T09:37:49-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - 989c1c27 by Ben Gamari at 2020-08-21T11:27:53-04:00 gitlab-ci: Test master branch as well While these builds are strictly speaking redundant (since every commit is tested by @marge-bot before making it into `master`), they are nevertheless useful as they are displayed in the branch's commit list in GitLab's web interface. Fixes #18595. - - - - - e67ae884 by Aditya Gupta at 2020-08-22T03:29:00-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - 03cfcfd4 by Wander Hillen at 2020-08-22T03:29:36-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 3f501545 by Craig Ferguson at 2020-08-22T03:30:13-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 8b865092 by Krzysztof Gogolewski at 2020-08-23T14:12:53+02:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - d8f61182 by Krzysztof Gogolewski at 2020-08-23T14:12:56+02:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - 364258e0 by Krzysztof Gogolewski at 2020-08-24T00:32:31-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - b1eb38a0 by Sylvain Henry at 2020-08-24T00:33:13-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 0a1ecc5f by Ben Gamari at 2020-08-25T07:37:05-04:00 SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' In #18069 we are observing MVar deadlocks from somewhere in ghc.exe. This use of MVar stood out as being one of the more likely culprits. Here we make sure that it is exception-safe. - - - - - db8793ad by Richard Eisenberg at 2020-08-25T07:37:40-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - fb77207a by Simon Peyton Jones at 2020-08-25T07:38:16-04:00 Use LIdP rather than (XRec p (IdP p)) This patch mainly just replaces use of XRec p (IdP p) with LIdP p One slightly more significant change is to parameterise HsPatSynDetails over the pass rather than the argument type, so that it's uniform with HsConDeclDetails and HsConPatDetails. I also got rid of the dead code GHC.Hs.type.conDetailsArgs But this is all just minor refactoring. No change in functionality. - - - - - 8426a136 by Krzysztof Gogolewski at 2020-08-25T07:38:54-04:00 Add a test for #18585 - - - - - 2d635a50 by Takenobu Tani at 2020-08-26T04:50:21-04:00 linters: Make CPP linter skip image files This patch adds an exclusion rule for `docs/users_guide/images`, to avoid lint errors of PDF files. - - - - - b7d98cb2 by Takenobu Tani at 2020-08-26T04:50:21-04:00 users-guide: Color the logo on the front page of the PDF This patch updates the logo with a recent color scheme. This affects only the PDF version of the user's guide. See also: * https://mail.haskell.org/pipermail/ghc-devs/2020-August/019139.html * https://gitlab.haskell.org/ghc/ghc/-/wikis/logo - - - - - 0b17fa18 by Sylvain Henry at 2020-08-26T04:50:58-04:00 Refactor UnitId pretty-printing When we pretty-print a UnitId for the user, we try to map it back to its origin package name, version and component to print "package-version:component" instead of some hash. The UnitId type doesn't carry these information, so we have to look into a UnitState to find them. This is why the Outputable instance of UnitId used `sdocWithDynFlags` in order to access the `unitState` field of DynFlags. This is wrong for several reasons: 1. The DynFlags are accessed when the message is printed, not when it is generated. So we could imagine that the unitState may have changed in-between. Especially if we want to allow unit unloading. 2. We want GHC to support several independent sessions at once, hence several UnitState. The current approach supposes there is a unique UnitState as a UnitId doesn't indicate which UnitState to use. See the Note [Pretty-printing UnitId] in GHC.Unit for the new approach implemented by this patch. One step closer to remove `sdocDynFlags` field from `SDocContext` (#10143). Fix #18124. Also fix some Backpack code to use SDoc instead of String. - - - - - dc476a50 by Sylvain Henry at 2020-08-26T04:51:35-04:00 Bignum: fix BigNat subtraction (#18604) There was a confusion between the boolean expected by withNewWordArrayTrimedMaybe and the boolean returned by subtracting functions. - - - - - fcb10b6c by Peter Trommler at 2020-08-26T10:42:30-04:00 PPC and X86: Portable printing of IEEE floats GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness. This was brought up in #18431 by @hsyl20. - - - - - 770100e0 by Krzysztof Gogolewski at 2020-08-26T10:43:13-04:00 primops: Remove Monadic and Dyadic categories There were four categories of primops: Monadic, Dyadic, Compare, GenPrimOp. The compiler does not treat Monadic and Dyadic in any special way, we can just replace them with GenPrimOp. Compare is still used in isComparisonPrimOp. - - - - - c7364154 by Sebastian Graf at 2020-08-26T19:10:53+02:00 Add long-distance info for pattern bindings (#18572) We didn't consider the RHS of a pattern-binding before, which led to surprising warnings listed in #18572. As can be seen from the regression test T18572, we get the expected output now. - - - - - 67b96f65 by Sebastian Graf at 2020-08-27T16:38:35+02:00 PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Previously, we desugared and coverage checked plain guard trees as described in Lower Your Guards. That caused (in !3849) quite a bit of pain when we need to partially recover tree structure of the input syntax to return covered sets for long-distance information, for example. In this refactor, I introduced a guard tree variant for each relevant source syntax component of a pattern-match (mainly match groups, match, GRHS, empty case, pattern binding). I made sure to share as much coverage checking code as possible, so that the syntax-specific checking functions are just wrappers around the more substantial checking functions for the LYG primitives (`checkSequence`, `checkGrds`). The refactoring payed off in clearer code and elimination of all panics related to assumed guard tree structure and thus fixes #18565. I also took the liberty to rename and re-arrange the order of functions and comments in the module, deleted some dead and irrelevant Notes, wrote some new ones and gave an overview module haddock. - - - - - b6393d81 by Sebastian Graf at 2020-08-27T18:35:14+02:00 Fix #18341 - - - - - 03fdd0cc by Sebastian Graf at 2020-08-27T18:42:08+02:00 Make PmConCt lazy and preserve ⊥ - - - - - 29bdb308 by Sebastian Graf at 2020-08-27T18:45:36+02:00 Fix a few bugs - - - - - a4c51506 by Sebastian Graf at 2020-08-27T18:45:36+02:00 Accept tests - - - - - 7d00db9d by Sebastian Graf at 2020-08-27T18:46:40+02:00 Add regression test for #18341 - - - - - 15d07c79 by Sebastian Graf at 2020-08-27T18:46:40+02:00 Add regression test for #17725 - - - - - 2b2e256e by Sebastian Graf at 2020-08-27T19:06:53+02:00 Add regression test for #17378 - - - - - 0ae134af by Sebastian Graf at 2020-08-27T19:07:01+02:00 Add regression test for #10183 - - - - - d61e4d9f by Sebastian Graf at 2020-08-27T19:07:01+02:00 Add regression test for #17729 - - - - - d0af65aa by Sebastian Graf at 2020-08-27T19:07:01+02:00 Add regression test for fixed #18273 - - - - - 5754499c by Sebastian Graf at 2020-08-27T19:50:19+02:00 Refactor ensureInhabited and resolve a scoping bug from the previous refactor - - - - - 9eb1f47a by Sebastian Graf at 2020-08-27T19:51:23+02:00 review feedback - - - - - 30 changed files: - .gitignore - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/linters/check-cpp.py - .gitlab/test-metrics.sh - CODEOWNERS - Makefile - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - + compiler/GHC/Builtin/RebindableNames.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/ByteCode/InfoTable.hs - compiler/GHC/Cmm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Graph.hs - compiler/GHC/Cmm/Info.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6f30cf6b606dbf0e5eeee8106ae3155e5d494670...9eb1f47ae367b973948acb4d5e595722b3cc5de6 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6f30cf6b606dbf0e5eeee8106ae3155e5d494670...9eb1f47ae367b973948acb4d5e595722b3cc5de6 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 27 18:19:31 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 27 Aug 2020 14:19:31 -0400 Subject: [Git][ghc/ghc][master] Consolidate imports in getMinimalImports (#18264) Message-ID: <5f47f9336a236_80be8140a89657537@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 01ff8c89 by Aditya Gupta at 2020-08-27T14:19:26-04:00 Consolidate imports in getMinimalImports (#18264) - - - - - 5 changed files: - compiler/GHC/Rename/Names.hs - testsuite/tests/rename/should_compile/Makefile - + testsuite/tests/rename/should_compile/T18264.hs - + testsuite/tests/rename/should_compile/T18264.stdout - testsuite/tests/rename/should_compile/all.T Changes: ===================================== compiler/GHC/Rename/Names.hs ===================================== @@ -4,7 +4,7 @@ Extracting imported and top-level names in scope -} -{-# LANGUAGE CPP, NondecreasingIndentation, MultiWayIf, NamedFieldPuns #-} +{-# LANGUAGE CPP, NondecreasingIndentation #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -72,7 +72,7 @@ import Data.Either ( partitionEithers, isRight, rights ) import Data.Map ( Map ) import qualified Data.Map as Map import Data.Ord ( comparing ) -import Data.List ( partition, (\\), find, sortBy ) +import Data.List ( partition, (\\), find, sortBy, groupBy, sortOn ) import Data.Function ( on ) import qualified Data.Set as S import System.FilePath (()) @@ -1570,7 +1570,7 @@ decls, and simply trim their import lists. NB that -} getMinimalImports :: [ImportDeclUsage] -> RnM [LImportDecl GhcRn] -getMinimalImports = mapM mk_minimal +getMinimalImports = fmap combine . mapM mk_minimal where mk_minimal (L l decl, used_gres, unused) | null unused @@ -1623,6 +1623,25 @@ getMinimalImports = mapM mk_minimal all_non_overloaded = all (not . flIsOverloaded) + combine :: [LImportDecl GhcRn] -> [LImportDecl GhcRn] + combine = map merge . groupBy ((==) `on` getKey) . sortOn getKey + + getKey :: LImportDecl GhcRn -> (Bool, Maybe ModuleName, ModuleName) + getKey decl = + ( isImportDeclQualified . ideclQualified $ idecl -- is this qualified? (important that this be first) + , unLoc <$> ideclAs idecl -- what is the qualifier (inside Maybe monad) + , unLoc . ideclName $ idecl -- Module Name + ) + where + idecl :: ImportDecl GhcRn + idecl = unLoc decl + + merge :: [LImportDecl GhcRn] -> LImportDecl GhcRn + merge [] = error "getMinimalImports: unexpected empty list" + merge decls@((L l decl) : _) = L l (decl { ideclHiding = Just (False, L l lies) }) + where lies = concatMap (unLoc . snd) $ mapMaybe (ideclHiding . unLoc) decls + + printMinimalImports :: HscSource -> [ImportDeclUsage] -> RnM () -- See Note [Printing minimal imports] printMinimalImports hsc_src imports_w_usage ===================================== testsuite/tests/rename/should_compile/Makefile ===================================== @@ -60,3 +60,8 @@ T7969: T18497: '$(TEST_HC)' $(TEST_HC_OPTS) -fno-code T18497_Foo.hs T18497_Bar.hs -ddump-minimal-imports cat T18497_Bar.imports-boot + +T18264: + $(RM) T18264.hi T18264.o T18264.imports + '$(TEST_HC)' $(TEST_HC_OPTS) -ddump-minimal-imports -c T18264.hs + cat T18264.imports ===================================== testsuite/tests/rename/should_compile/T18264.hs ===================================== @@ -0,0 +1,20 @@ +module T18264 where + +import Data.Char (isDigit) +import Data.Maybe (isJust) +import Data.Char (isPrint) +import Data.List (sortOn) +import Data.Char (isLetter) +import Data.Maybe hiding (isNothing) + +import qualified Data.List as S (sort) +import qualified Data.Char as C --only isDigit & isLetter used later +import qualified Data.List as T (nub) + +test1 x = isDigit x || isLetter x +test2a = isJust +test2b = fromJust +test3 x = C.isDigit x || C.isLetter x +test4 xs = S.sort xs +test5 xs = T.nub xs +test6 f xs = sortOn f xs ===================================== testsuite/tests/rename/should_compile/T18264.stdout ===================================== @@ -0,0 +1,6 @@ +import Data.Char ( isDigit, isLetter ) +import Data.List ( sortOn ) +import Data.Maybe ( fromJust, isJust ) +import qualified Data.Char as C ( isLetter, isDigit ) +import qualified Data.List as S ( sort ) +import qualified Data.List as T ( nub ) ===================================== testsuite/tests/rename/should_compile/all.T ===================================== @@ -175,3 +175,4 @@ test('T17244C', normal, compile, ['']) test('T17832', [], multimod_compile, ['T17832M1', 'T17832M2']) test('T17837', normal, compile, ['']) test('T18497', [], makefile_test, ['T18497']) +test('T18264', [], makefile_test, ['T18264']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/01ff8c89727a91cbc1571ae54f73f5919d6aaa71 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/01ff8c89727a91cbc1571ae54f73f5919d6aaa71 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 27 18:20:08 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 27 Aug 2020 14:20:08 -0400 Subject: [Git][ghc/ghc][master] Make {hsExpr,hsType,pat}NeedsParens aware of boxed 1-tuples Message-ID: <5f47f9586f769_80b8d87bd0966408a@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: bacccb73 by Ryan Scott at 2020-08-27T14:20:01-04:00 Make {hsExpr,hsType,pat}NeedsParens aware of boxed 1-tuples `hsExprNeedsParens`, `hsTypeNeedsParens`, and `patNeedsParens` previously assumed that all uses of explicit tuples in the source syntax never need to be parenthesized. This is true save for one exception: boxed one-tuples, which use the `Solo` data type from `GHC.Tuple` instead of special tuple syntax. This patch adds the necessary logic to the three `*NeedsParens` functions to handle `Solo` correctly. Fixes #18612. - - - - - 6 changed files: - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - + testsuite/tests/th/T18612.hs - + testsuite/tests/th/T18612.stderr - testsuite/tests/th/all.T Changes: ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -1320,6 +1320,11 @@ hsExprNeedsParens p = go go (NegApp{}) = p > topPrec go (SectionL{}) = True go (SectionR{}) = True + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go (ExplicitTuple _ [L _ Present{}] Boxed) + = p >= appPrec go (ExplicitTuple{}) = False go (ExplicitSum{}) = False go (HsLam{}) = p > topPrec ===================================== compiler/GHC/Hs/Pat.hs ===================================== @@ -857,7 +857,12 @@ patNeedsParens p = go go (BangPat {}) = False go (ParPat {}) = False go (AsPat {}) = False - go (TuplePat {}) = False + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go (TuplePat _ [_] Boxed) + = p >= appPrec + go (TuplePat{}) = False go (SumPat {}) = False go (ListPat {}) = False go (LitPat _ l) = hsLitNeedsParens p l ===================================== compiler/GHC/Hs/Type.hs ===================================== @@ -1979,6 +1979,15 @@ hsTypeNeedsParens p = go_hs_ty go_hs_ty (HsRecTy{}) = False go_hs_ty (HsTyVar{}) = False go_hs_ty (HsFunTy{}) = p >= funPrec + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go_hs_ty (HsTupleTy _ con [L _ ty]) + = case con of + HsBoxedTuple -> p >= appPrec + HsBoxedOrConstraintTuple -> p >= appPrec + HsConstraintTuple -> go_hs_ty ty + HsUnboxedTuple -> False go_hs_ty (HsTupleTy{}) = False go_hs_ty (HsSumTy{}) = False go_hs_ty (HsKindSig{}) = p >= sigPrec @@ -1986,6 +1995,11 @@ hsTypeNeedsParens p = go_hs_ty go_hs_ty (HsIParamTy{}) = p > topPrec go_hs_ty (HsSpliceTy{}) = False go_hs_ty (HsExplicitListTy{}) = False + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Proxy ('Solo x)`, not `Proxy 'Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go_hs_ty (HsExplicitTupleTy _ [_]) + = p >= appPrec go_hs_ty (HsExplicitTupleTy{}) = False go_hs_ty (HsTyLit{}) = False go_hs_ty (HsWildCardTy{}) = False ===================================== testsuite/tests/th/T18612.hs ===================================== @@ -0,0 +1,14 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -ddump-splices #-} +module T18612 where + +import Data.Functor.Identity +import Data.Proxy +import Language.Haskell.TH + +f :: $(arrowT `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))) + `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0)))) +f $(conP 'Identity [tupP [tupP []]]) = $(conE 'Identity `appE` tupE [tupE []]) + +type G = $(conT ''Proxy `appT` (promotedTupleT 1 `appT` (tupleT 0))) ===================================== testsuite/tests/th/T18612.stderr ===================================== @@ -0,0 +1,13 @@ +T18612.hs:14:11-68: Splicing type + conT ''Proxy `appT` (promotedTupleT 1 `appT` (tupleT 0)) + ======> + Proxy ('Solo ()) +T18612.hs:(10,7)-(11,75): Splicing type + arrowT `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))) + `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))) + ======> + Identity (Solo ()) -> Identity (Solo ()) +T18612.hs:12:4-36: Splicing pattern + conP 'Identity [tupP [tupP []]] ======> Identity (Solo()) +T18612.hs:12:41-78: Splicing expression + conE 'Identity `appE` tupE [tupE []] ======> Identity (Solo ()) ===================================== testsuite/tests/th/all.T ===================================== @@ -513,3 +513,4 @@ test('T18102b', extra_files(['T18102b_aux.hs']), compile_and_run, ['']) test('T18121', normal, compile, ['']) test('T18123', normal, compile, ['']) test('T18388', normal, compile, ['']) +test('T18612', normal, compile, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bacccb73c9b080c3c01a5e55ecb0a00cd8a77e55 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bacccb73c9b080c3c01a5e55ecb0a00cd8a77e55 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Thu Aug 27 21:48:53 2020 From: gitlab at gitlab.haskell.org (Vladislav Zavialov) Date: Thu, 27 Aug 2020 17:48:53 -0400 Subject: [Git][ghc/ghc][wip/parsing-shift] 8 commits: linters: Make CPP linter skip image files Message-ID: <5f482a454ed05_80bd9c25189675939@gitlab.haskell.org.mail> Vladislav Zavialov pushed to branch wip/parsing-shift at Glasgow Haskell Compiler / GHC Commits: 2d635a50 by Takenobu Tani at 2020-08-26T04:50:21-04:00 linters: Make CPP linter skip image files This patch adds an exclusion rule for `docs/users_guide/images`, to avoid lint errors of PDF files. - - - - - b7d98cb2 by Takenobu Tani at 2020-08-26T04:50:21-04:00 users-guide: Color the logo on the front page of the PDF This patch updates the logo with a recent color scheme. This affects only the PDF version of the user's guide. See also: * https://mail.haskell.org/pipermail/ghc-devs/2020-August/019139.html * https://gitlab.haskell.org/ghc/ghc/-/wikis/logo - - - - - 0b17fa18 by Sylvain Henry at 2020-08-26T04:50:58-04:00 Refactor UnitId pretty-printing When we pretty-print a UnitId for the user, we try to map it back to its origin package name, version and component to print "package-version:component" instead of some hash. The UnitId type doesn't carry these information, so we have to look into a UnitState to find them. This is why the Outputable instance of UnitId used `sdocWithDynFlags` in order to access the `unitState` field of DynFlags. This is wrong for several reasons: 1. The DynFlags are accessed when the message is printed, not when it is generated. So we could imagine that the unitState may have changed in-between. Especially if we want to allow unit unloading. 2. We want GHC to support several independent sessions at once, hence several UnitState. The current approach supposes there is a unique UnitState as a UnitId doesn't indicate which UnitState to use. See the Note [Pretty-printing UnitId] in GHC.Unit for the new approach implemented by this patch. One step closer to remove `sdocDynFlags` field from `SDocContext` (#10143). Fix #18124. Also fix some Backpack code to use SDoc instead of String. - - - - - dc476a50 by Sylvain Henry at 2020-08-26T04:51:35-04:00 Bignum: fix BigNat subtraction (#18604) There was a confusion between the boolean expected by withNewWordArrayTrimedMaybe and the boolean returned by subtracting functions. - - - - - fcb10b6c by Peter Trommler at 2020-08-26T10:42:30-04:00 PPC and X86: Portable printing of IEEE floats GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness. This was brought up in #18431 by @hsyl20. - - - - - 770100e0 by Krzysztof Gogolewski at 2020-08-26T10:43:13-04:00 primops: Remove Monadic and Dyadic categories There were four categories of primops: Monadic, Dyadic, Compare, GenPrimOp. The compiler does not treat Monadic and Dyadic in any special way, we can just replace them with GenPrimOp. Compare is still used in isComparisonPrimOp. - - - - - 86ac4dbf by Vladislav Zavialov at 2020-08-26T21:20:02+03:00 Require happy >=1.20 - - - - - b657eb9d by Vladislav Zavialov at 2020-08-28T00:48:34+03:00 Resolve shift/reduce conflicts with %shift (#17232) - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/linters/check-cpp.py - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/Ppr.hs - compiler/GHC/CmmToAsm/SPARC/Ppr.hs - compiler/GHC/CmmToAsm/X86/Ppr.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Driver/Finder.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/Parser.y - compiler/GHC/Runtime/Eval.hs - compiler/GHC/StgToCmm/Prim.hs - compiler/GHC/Tc/Module.hs - compiler/GHC/Tc/Utils/Backpack.hs - compiler/GHC/Tc/Utils/Instantiate.hs - compiler/GHC/Tc/Utils/Monad.hs - compiler/GHC/Unit.hs - compiler/GHC/Unit/Home.hs - compiler/GHC/Unit/Info.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/3d9297cd4525a2b0b8000580eaf26964cd0fabdc...b657eb9d6b67d36ff7e185c8782ffd9bfef13409 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/3d9297cd4525a2b0b8000580eaf26964cd0fabdc...b657eb9d6b67d36ff7e185c8782ffd9bfef13409 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 28 00:22:38 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Thu, 27 Aug 2020 20:22:38 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 5 commits: Consolidate imports in getMinimalImports (#18264) Message-ID: <5f484e4e51790_80b110de18c968843e@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: 01ff8c89 by Aditya Gupta at 2020-08-27T14:19:26-04:00 Consolidate imports in getMinimalImports (#18264) - - - - - bacccb73 by Ryan Scott at 2020-08-27T14:20:01-04:00 Make {hsExpr,hsType,pat}NeedsParens aware of boxed 1-tuples `hsExprNeedsParens`, `hsTypeNeedsParens`, and `patNeedsParens` previously assumed that all uses of explicit tuples in the source syntax never need to be parenthesized. This is true save for one exception: boxed one-tuples, which use the `Solo` data type from `GHC.Tuple` instead of special tuple syntax. This patch adds the necessary logic to the three `*NeedsParens` functions to handle `Solo` correctly. Fixes #18612. - - - - - 2d6d3b0a by Krzysztof Gogolewski at 2020-08-27T20:22:26-04:00 Add missing primop documentation (#18454) - Add three pseudoops to primops.txt.pp, so that Haddock renders the documentation - Update comments - Remove special case for "->" - it's no longer exported from GHC.Prim - Remove reference to Note [Compiling GHC.Prim] - the ad-hoc fix is no longer there after updates to levity polymorphism. - Document GHC.Prim - Remove the comment that lazy is levity-polymorphic. As far as I can tell, it never was: in 80e399639, only the unfolding was given an open type variable. - Remove haddock hack in GHC.Magic - no longer neccessary after adding realWorld# to primops.txt.pp. - - - - - de672122 by Tamar Christina at 2020-08-27T20:22:28-04:00 Fix use distro toolchian - - - - - 36098d00 by Tamar Christina at 2020-08-27T20:22:28-04:00 document how build system find toolchains on Windows - - - - - 29 changed files: - aclocal.m4 - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/Rename/Names.hs - compiler/GHC/SysTools/BaseDir.hs - compiler/GHC/Types/Id/Make.hs - compiler/GHC/Types/Unique/Supply.hs - configure.ac - hadrian/cfg/system.config.in - hadrian/src/Oracles/Flag.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - includes/ghc.mk - libraries/ghc-prim/GHC/Magic.hs - mk/config.mk.in - mk/project.mk.in - testsuite/tests/rename/should_compile/Makefile - + testsuite/tests/rename/should_compile/T18264.hs - + testsuite/tests/rename/should_compile/T18264.stdout - testsuite/tests/rename/should_compile/all.T - + testsuite/tests/th/T18612.hs - + testsuite/tests/th/T18612.stderr - testsuite/tests/th/all.T - utils/genprimopcode/Main.hs - utils/genprimopcode/Parser.y Changes: ===================================== aclocal.m4 ===================================== @@ -507,6 +507,7 @@ AC_DEFUN([GET_ARM_ISA], # FP_SETTINGS # ---------------------------------- # Set the variables used in the settings file +# See Note [tooldir: How GHC finds mingw on Windows] AC_DEFUN([FP_SETTINGS], [ if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" @@ -583,6 +584,7 @@ AC_DEFUN([FP_SETTINGS], SettingsCCompilerLinkFlags="$CONF_GCC_LINKER_OPTS_STAGE2" SettingsCCompilerSupportsNoPie="$CONF_GCC_SUPPORTS_NO_PIE" SettingsLdFlags="$CONF_LD_LINKER_OPTS_STAGE2" + SettingsUseDistroMINGW="$EnableDistroToolchain" AC_SUBST(SettingsCCompilerCommand) AC_SUBST(SettingsHaskellCPPCommand) AC_SUBST(SettingsHaskellCPPFlags) @@ -601,6 +603,7 @@ AC_DEFUN([FP_SETTINGS], AC_SUBST(SettingsClangCommand) AC_SUBST(SettingsLlcCommand) AC_SUBST(SettingsOptCommand) + AC_SUBST(SettingsUseDistroMINGW) ]) # Helper for cloning a shell variable's state ===================================== compiler/GHC/Builtin/Utils.hs ===================================== @@ -257,9 +257,6 @@ primOpId op = primOpIds ! primOpTag op Export lists for pseudo-modules (GHC.Prim) * * ************************************************************************ - -GHC.Prim "exports" all the primops and primitive types, some -wired-in Ids. -} ghcPrimExports :: [IfaceExport] ===================================== compiler/GHC/Builtin/primops.txt.pp ===================================== @@ -15,14 +15,86 @@ -- -- It should first be preprocessed. -- +-- Note in particular that Haskell block-style comments are not recognized +-- here, so stick to '--' (even for Notes spanning multiple lines). + +-- Note [GHC.Prim] +-- ~~~~~~~~~~~~~~~ +-- GHC.Prim is a special module: +-- +-- * It can be imported by any module (import GHC.Prim). +-- However, in the future we might change which functions are primitives +-- and which are defined in Haskell. +-- Users should import GHC.Exts, which reexports GHC.Prim and is more stable. +-- In particular, we might move some of the primops to 'foreign import prim' +-- (see ticket #16929 and Note [When do out-of-line primops go in primops.txt.pp]) +-- +-- * It provides primitives of three sorts: +-- - primitive types such as Int64#, MutableByteArray# +-- - primops such as (+#), newTVar#, touch# +-- - pseudoops such as realWorld#, nullAddr# +-- +-- * The pseudoops are described in Note [ghcPrimIds (aka pseudoops)] +-- in GHC.Types.Id.Make. +-- +-- * The primitives (primtypes, primops, pseudoops) cannot be defined in +-- source Haskell. +-- There is no GHC/Prim.hs file with definitions. +-- Instead, we support importing GHC.Prim by manually defining its +-- ModIface (see Iface.Load.ghcPrimIface). +-- +-- * The primitives are listed in this file, primops.txt.pp. +-- It goes through CPP, which creates primops.txt. +-- It is then consumed by the utility program genprimopcode, which produces +-- the following three types of files. +-- +-- 1. The files with extension .hs-incl. +-- They can be found by grepping for hs-incl. +-- They are #included in compiler sources. +-- +-- One of them, primop-data-decl.hs-incl, defines the PrimOp type: +-- data PrimOp +-- = IntAddOp +-- | IntSubOp +-- | CharGtOp +-- | CharGeOp +-- | ... +-- +-- The remaining files define properties of the primops +-- by pattern matching, for example: +-- primOpFixity IntAddOp = Just (Fixity NoSourceText 6 InfixL) +-- primOpFixity IntSubOp = Just (Fixity NoSourceText 6 InfixL) +-- ... +-- This includes fixity, has-side-effects, commutability, +-- IDs used to generate Uniques etc. +-- +-- Additionally, we pattern match on PrimOp when generating Cmm in +-- GHC/StgToCmm/Prim.hs. +-- +-- 2. The dummy Prim.hs file, which is used for Haddock and +-- contains descriptions taken from primops.txt.pp. +-- All definitions are replaced by placeholders. +-- See Note [GHC.Prim Docs] in genprimopcode. +-- +-- 3. The module PrimopWrappers.hs, which wraps every call for GHCi; +-- see Note [Primop wrappers] in GHC.Builtin.Primops for details. +-- +-- * This file does not list internal-only equality types +-- (GHC.Builtin.Types.Prim.unexposedPrimTyCons and coercionToken# +-- in GHC.Types.Id.Make) which are defined but not exported from GHC.Prim. +-- Every export of GHC.Prim should be in listed in this file. +-- +-- * The primitive types should be listed in primTyCons in Builtin.Types.Prim +-- in addition to primops.txt.pp. +-- (This task should be delegated to genprimopcode in the future.) +-- +-- +-- -- Information on how PrimOps are implemented and the steps necessary to -- add a new one can be found in the Commentary: -- -- https://gitlab.haskell.org/ghc/ghc/wikis/commentary/prim-ops -- --- Note in particular that Haskell block-style comments are not recognized --- here, so stick to '--' (even for Notes spanning multiple lines). - -- This file is divided into named sections, each containing or more -- primop entries. Section headers have the format: -- @@ -76,7 +148,6 @@ defaults vector = [] deprecated_msg = {} -- A non-empty message indicates deprecation - -- Note [When do out-of-line primops go in primops.txt.pp] -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- @@ -189,19 +260,6 @@ section "The word size story." #define WORD64 Word# #endif --- This type won't be exported directly (since there is no concrete --- syntax for this sort of export) so we'll have to manually patch --- export lists in both GHC and Haddock. -primtype FUN m a b - {The builtin function type, written in infix form as {\tt a # m -> b}. - Values of this type are functions taking inputs of type {\tt a} and - producing outputs of type {\tt b}. The multiplicity of the input is - {\tt m}. - - Note that {\tt FUN m a b} permits levity-polymorphism in both {\tt a} and - {\tt b}, so that types like {\tt Int\# -> Int\#} can still be well-kinded. - } - ------------------------------------------------------------------------ section "Char#" {Operations on 31-bit characters.} @@ -3377,6 +3435,37 @@ section "Etc" {Miscellaneous built-ins} ------------------------------------------------------------------------ +primtype FUN m a b + {The builtin function type, written in infix form as {\tt a # m -> b}. + Values of this type are functions taking inputs of type {\tt a} and + producing outputs of type {\tt b}. The multiplicity of the input is + {\tt m}. + + Note that {\tt FUN m a b} permits levity-polymorphism in both {\tt a} and + {\tt b}, so that types like {\tt Int\# -> Int\#} can still be well-kinded. + } + +pseudoop "realWorld#" + State# RealWorld + { The token used in the implementation of the IO monad as a state monad. + It does not pass any information at runtime. + See also {\tt GHC.Magic.runRW\#}. } + +pseudoop "void#" + (# #) + { This is an alias for the unboxed unit tuple constructor. + In earlier versions of GHC, {\tt void\#} was a value + of the primitive type {\tt Void\#}, which is now defined to be {\tt (\# \#)}. + } + with deprecated_msg = { Use an unboxed unit tuple instead } + +pseudoop "magicDict" + a + { {\tt magicDict} is a special-purpose placeholder value. + It is used internally by modules such as {\tt GHC.TypeNats} to cast a typeclass + dictionary with a single method. It is eliminated by a rule during compilation. + For the details, see Note [magicDictId magic] in GHC. } + primtype Proxy# a { The type constructor {\tt Proxy#} is used to bear witness to some type variable. It's used when you want to pass around proxy values ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -1320,6 +1320,11 @@ hsExprNeedsParens p = go go (NegApp{}) = p > topPrec go (SectionL{}) = True go (SectionR{}) = True + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go (ExplicitTuple _ [L _ Present{}] Boxed) + = p >= appPrec go (ExplicitTuple{}) = False go (ExplicitSum{}) = False go (HsLam{}) = p > topPrec ===================================== compiler/GHC/Hs/Pat.hs ===================================== @@ -857,7 +857,12 @@ patNeedsParens p = go go (BangPat {}) = False go (ParPat {}) = False go (AsPat {}) = False - go (TuplePat {}) = False + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go (TuplePat _ [_] Boxed) + = p >= appPrec + go (TuplePat{}) = False go (SumPat {}) = False go (ListPat {}) = False go (LitPat _ l) = hsLitNeedsParens p l ===================================== compiler/GHC/Hs/Type.hs ===================================== @@ -1979,6 +1979,15 @@ hsTypeNeedsParens p = go_hs_ty go_hs_ty (HsRecTy{}) = False go_hs_ty (HsTyVar{}) = False go_hs_ty (HsFunTy{}) = p >= funPrec + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go_hs_ty (HsTupleTy _ con [L _ ty]) + = case con of + HsBoxedTuple -> p >= appPrec + HsBoxedOrConstraintTuple -> p >= appPrec + HsConstraintTuple -> go_hs_ty ty + HsUnboxedTuple -> False go_hs_ty (HsTupleTy{}) = False go_hs_ty (HsSumTy{}) = False go_hs_ty (HsKindSig{}) = p >= sigPrec @@ -1986,6 +1995,11 @@ hsTypeNeedsParens p = go_hs_ty go_hs_ty (HsIParamTy{}) = p > topPrec go_hs_ty (HsSpliceTy{}) = False go_hs_ty (HsExplicitListTy{}) = False + -- Special-case unary boxed tuple applications so that they are + -- parenthesized as `Proxy ('Solo x)`, not `Proxy 'Solo x` (#18612) + -- See Note [One-tuples] in GHC.Builtin.Types + go_hs_ty (HsExplicitTupleTy _ [_]) + = p >= appPrec go_hs_ty (HsExplicitTupleTy{}) = False go_hs_ty (HsTyLit{}) = False go_hs_ty (HsWildCardTy{}) = False ===================================== compiler/GHC/Iface/Load.hs ===================================== @@ -915,6 +915,7 @@ findAndReadIface doc_str mod wanted_mod_with_insts hi_boot_file nest 4 (text "reason:" <+> doc_str)]) -- Check for GHC.Prim, and return its static interface + -- See Note [GHC.Prim] in primops.txt.pp. -- TODO: make this check a function if mod `installedModuleEq` gHC_PRIM then do @@ -1059,6 +1060,7 @@ initExternalPackageState home_unit ********************************************************* -} +-- See Note [GHC.Prim] in primops.txt.pp. ghcPrimIface :: ModIface ghcPrimIface = empty_iface { @@ -1071,7 +1073,7 @@ ghcPrimIface where empty_iface = emptyFullModIface gHC_PRIM - -- The fixities listed here for @`seq`@ or @->@ should match + -- The fixity listed here for @`seq`@ should match -- those in primops.txt.pp (from which Haddock docs are generated). fixities = (getOccName seqId, Fixity NoSourceText 0 InfixR) : mapMaybe mkFixity allThePrimOps ===================================== compiler/GHC/Rename/Names.hs ===================================== @@ -4,7 +4,7 @@ Extracting imported and top-level names in scope -} -{-# LANGUAGE CPP, NondecreasingIndentation, MultiWayIf, NamedFieldPuns #-} +{-# LANGUAGE CPP, NondecreasingIndentation #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -72,7 +72,7 @@ import Data.Either ( partitionEithers, isRight, rights ) import Data.Map ( Map ) import qualified Data.Map as Map import Data.Ord ( comparing ) -import Data.List ( partition, (\\), find, sortBy ) +import Data.List ( partition, (\\), find, sortBy, groupBy, sortOn ) import Data.Function ( on ) import qualified Data.Set as S import System.FilePath (()) @@ -1570,7 +1570,7 @@ decls, and simply trim their import lists. NB that -} getMinimalImports :: [ImportDeclUsage] -> RnM [LImportDecl GhcRn] -getMinimalImports = mapM mk_minimal +getMinimalImports = fmap combine . mapM mk_minimal where mk_minimal (L l decl, used_gres, unused) | null unused @@ -1623,6 +1623,25 @@ getMinimalImports = mapM mk_minimal all_non_overloaded = all (not . flIsOverloaded) + combine :: [LImportDecl GhcRn] -> [LImportDecl GhcRn] + combine = map merge . groupBy ((==) `on` getKey) . sortOn getKey + + getKey :: LImportDecl GhcRn -> (Bool, Maybe ModuleName, ModuleName) + getKey decl = + ( isImportDeclQualified . ideclQualified $ idecl -- is this qualified? (important that this be first) + , unLoc <$> ideclAs idecl -- what is the qualifier (inside Maybe monad) + , unLoc . ideclName $ idecl -- Module Name + ) + where + idecl :: ImportDecl GhcRn + idecl = unLoc decl + + merge :: [LImportDecl GhcRn] -> LImportDecl GhcRn + merge [] = error "getMinimalImports: unexpected empty list" + merge decls@((L l decl) : _) = L l (decl { ideclHiding = Just (False, L l lies) }) + where lies = concatMap (unLoc . snd) $ mapMaybe (ideclHiding . unLoc) decls + + printMinimalImports :: HscSource -> [ImportDeclUsage] -> RnM () -- See Note [Printing minimal imports] printMinimalImports hsc_src imports_w_usage ===================================== compiler/GHC/SysTools/BaseDir.hs ===================================== @@ -34,16 +34,6 @@ import System.FilePath import System.Directory (doesDirectoryExist) #endif -#if defined(mingw32_HOST_OS) -# if defined(i386_HOST_ARCH) -# define WINDOWS_CCONV stdcall -# elif defined(x86_64_HOST_ARCH) -# define WINDOWS_CCONV ccall -# else -# error Unknown mingw32 arch -# endif -#endif - {- Note [topdir: How GHC finds its files] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -70,16 +60,89 @@ Note [tooldir: How GHC finds mingw on Windows] GHC has some custom logic on Windows for finding the mingw toolchain and perl. Depending on whether GHC is built with the make build system or Hadrian, and on whether we're -running a bindist, we might find the mingw toolchain and perl +running a bindist, we might find the mingw toolchain either under $topdir/../{mingw, perl}/ or $topdir/../../{mingw, perl}/. +This story is long and with lots of twist and turns.. But lets talk about how +the build system finds and wires through the toolchain information. + +1) It all starts in configure.ac which has two modes it operates on: + a) The default is where `EnableDistroToolchain` is false. This indicates + that we want to use the in-tree bundled toolchains. In this mode we will + download and unpack some custom toolchains into the `inplace/mingw` folder + and everything is pointed to that folder. + b) The second path is when `EnableDistroToolchain` is true. This makes the + toolchain behave a lot like Linux, in that the environment is queried for + information on the tools we require. + + From configure.ac we export the standard variables to set the paths to the + tools for the build system to use. + +2) After we have the path to the tools we have to generate the right paths to + store in the settings file for ghc to use. This is done in aclocal.m4. + Again we have two modes of operation: + a) If not `EnableDistroToolchain` the paths are rewritten to paths using a + variable `$tooldir` as we need an absolute path. $tooldir is filled in by + the `expandToolDir` function in this module at GHC startup. + b) When `EnableDistroToolchain` then instead of filling in a absolute path + we fill in just the program name. The assumption here is that at runtime + the environment GHC is operating on will be the same as the one configure + was run in. This means we expect `gcc, ld, as` etc to be on the PATH. + + From `aclocal.m4` we export a couple of variables starting with `Settings` + which will be used to generate the settings file. + +3) The next step is to generate the settings file, this is where things diverge + based on the build system. Both Make and Hadrian handle this differently: + +make) + Make deals with this rather simply. As an output of configure.ac + `config.mk.in` is processed and `config.mk` generated which has the values we + set in `aclocal.m4`. This allows the rest of the build system to have access + to these and other values determined by configure. + + Based on this file, `includes/ghc.mk` when ran will produce the settings file + by echoing the values into a the final file. Coincidentally this is also + where `ghcplatform.h` and `ghcversion.h` generated which contains information + about the build platform and sets CPP for use by the entire build. + +hadrian) + For hadrian the file `cfg/system.config.in` is preprocessed by configure and + the output written to `system.config`. This serves the same purpose as + `config.mk` but it rewrites the values that were exported. As an example + `SettingsCCompilerCommand` is rewritten to `settings-c-compiler-command`. + + Next up is `src/Oracles/Settings.hs` which makes from some Haskell ADT to + the settings `keys` in the `system.config`. As an example, + `settings-c-compiler-command` is mapped to + `SettingsFileSetting_CCompilerCommand`. + + The last part of this is the `generateSettings` in `src/Rules/Generate.hs` + which produces the desired settings file out of Hadrian. This is the + equivalent to `includes/ghc.mk`. + +-- + +So why do we have these? On Windows there's no such thing as a platform compiler +and as such we need to provide GCC and binutils. The easiest way is to bundle +these with the compiler and wire them up. This gives you a relocatable +binball. This works fine for most users. However mingw-w64 have a different +requirement. They require all packages in the repo to be compiled using the +same version of the compiler. So it means when they are rebuilding the world to +add support for GCC X, they expect all packages to have been compiled with GCC X +which is a problem since we ship an older GCC version. + +GHC is a package in mingw-w64 because there are Haskell packages in the +repository which of course requires a Haskell compiler. To help them we +provide the override which allows GHC to instead of using an inplace compiler to +play nice with the system compiler instead. -} -- | Expand occurrences of the @$tooldir@ interpolation in a string -- on Windows, leave the string untouched otherwise. expandToolDir :: Maybe FilePath -> String -> String -#if defined(mingw32_HOST_OS) +#if defined(mingw32_HOST_OS) && !defined(USE_INPLACE_MINGW_TOOLCHAIN) expandToolDir (Just tool_dir) s = expandPathVar "tooldir" tool_dir s expandToolDir Nothing _ = panic "Could not determine $tooldir" #else @@ -113,14 +176,15 @@ tryFindTopDir Nothing Nothing -> getBaseDir --- See Note [tooldir: How GHC finds mingw and perl on Windows] +-- See Note [tooldir: How GHC finds mingw on Windows] -- Returns @Nothing@ when not on Windows. -- When called on Windows, it either throws an error when the -- tooldir can't be located, or returns @Just tooldirpath at . +-- If the distro toolchain is being used we treat Windows the same as Linux findToolDir :: FilePath -- ^ topdir -> IO (Maybe FilePath) -#if defined(mingw32_HOST_OS) +#if defined(mingw32_HOST_OS) && !defined(USE_INPLACE_MINGW_TOOLCHAIN) findToolDir top_dir = go 0 (top_dir "..") where maxDepth = 3 go :: Int -> FilePath -> IO (Maybe FilePath) ===================================== compiler/GHC/Types/Id/Make.hs ===================================== @@ -118,7 +118,8 @@ Note [ghcPrimIds (aka pseudoops)] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The ghcPrimIds - * Are exported from GHC.Prim + * Are exported from GHC.Prim (see ghcPrimExports, used in ghcPrimInterface) + See Note [GHC.Prim] in primops.txt.pp for the remaining items in GHC.Prim. * Can't be defined in Haskell, and hence no Haskell binding site, but have perfectly reasonable unfoldings in Core @@ -141,7 +142,17 @@ The magicIds * May or may not have a CompulsoryUnfolding. * But have some special behaviour that can't be done via an - unfolding from an interface file + unfolding from an interface file. + + * May have IdInfo that differs from what would be imported from GHC.Magic.hi. + For example, 'lazy' gets a lazy strictness signature, per Note [lazyId magic]. + + The two remaining identifiers in GHC.Magic, runRW# and inline, are not listed + in magicIds: they have special behavior but they can be known-key and + not wired-in. + runRW#: see Note [Simplification of runRW#] in Prep, runRW# code in + Simplifier, Note [Linting of runRW#]. + inline: see Note [inlineId magic] -} wiredInIds :: [Id] @@ -1402,12 +1413,12 @@ These Ids can't be defined in Haskell. They could be defined in unfoldings in the wired-in GHC.Prim interface file, but we'd have to ensure that they were definitely, definitely inlined, because there is no curried identifier for them. That's what mkCompulsoryUnfolding -does. If we had a way to get a compulsory unfolding from an interface -file, we could do that, but we don't right now. +does. Alternatively, we could add the definitions to mi_decls of ghcPrimIface +but it's not clear if this would be simpler. -The type variables we use here are "open" type variables: this means -they can unify with both unlifted and lifted types. Hence we provide -another gun with which to shoot yourself in the foot. +coercionToken# is not listed in ghcPrimIds, since its type uses (~#) +which is not supposed to be used in expressions (GHC throws an assertion +failure when trying.) -} nullAddrName, seqName, @@ -1422,6 +1433,7 @@ magicDictName = mkWiredInIdName gHC_PRIM (fsLit "magicDict") magicDict coerceName = mkWiredInIdName gHC_PRIM (fsLit "coerce") coerceKey coerceId proxyName = mkWiredInIdName gHC_PRIM (fsLit "proxy#") proxyHashKey proxyHashId +-- Names listed in magicIds; see Note [magicIds] lazyIdName, oneShotName, noinlineIdName :: Name lazyIdName = mkWiredInIdName gHC_MAGIC (fsLit "lazy") lazyIdKey lazyId oneShotName = mkWiredInIdName gHC_MAGIC (fsLit "oneShot") oneShotKey oneShotId @@ -1598,7 +1610,7 @@ See also: Note [User-defined RULES for seq] in GHC.Core.Opt.Simplify. Note [lazyId magic] ~~~~~~~~~~~~~~~~~~~ -lazy :: forall a?. a? -> a? (i.e. works for unboxed types too) +lazy :: forall a. a -> a 'lazy' is used to make sure that a sub-expression, and its free variables, are truly used call-by-need, with no code motion. Key examples: @@ -1616,7 +1628,7 @@ are truly used call-by-need, with no code motion. Key examples: Implementing 'lazy' is a bit tricky: * It must not have a strictness signature: by being a built-in Id, - all the info about lazyId comes from here, not from GHC.Base.hi. + all the info about lazyId comes from here, not from GHC.Magic.hi. This is important, because the strictness analyser will spot it as strict! @@ -1777,7 +1789,7 @@ voidPrimId = pcMiscPrelId voidPrimIdName unboxedUnitTy voidArgId :: Id -- Local lambda-bound :: Void# voidArgId = mkSysLocal (fsLit "void") voidArgIdKey Many unboxedUnitTy -coercionTokenId :: Id -- :: () ~ () +coercionTokenId :: Id -- :: () ~# () coercionTokenId -- See Note [Coercion tokens] in "GHC.CoreToStg" = pcMiscPrelId coercionTokenName (mkTyConApp eqPrimTyCon [liftedTypeKind, liftedTypeKind, unitTy, unitTy]) @@ -1786,8 +1798,3 @@ coercionTokenId -- See Note [Coercion tokens] in "GHC.CoreToStg" pcMiscPrelId :: Name -> Type -> IdInfo -> Id pcMiscPrelId name ty info = mkVanillaGlobalWithInfo name ty info - -- We lie and say the thing is imported; otherwise, we get into - -- a mess with dependency analysis; e.g., core2stg may heave in - -- random calls to GHCbase.unpackPS__. If GHCbase is the module - -- being compiled, then it's just a matter of luck if the definition - -- will be in "the right place" to be in scope. ===================================== compiler/GHC/Types/Unique/Supply.hs ===================================== @@ -180,7 +180,7 @@ The magic `inline` function does two things * It helps ensure that 'm' really does inline. -Note that 'inline' evaporates in phase 0. See Note [inlineIdMagic] +Note that 'inline' evaporates in phase 0. See Note [inlineId magic] in GHC.Core.Opt.ConstantFold.match_inline. The INLINE pragma on multiShotIO is very important, else the ===================================== configure.ac ===================================== @@ -435,6 +435,7 @@ set_up_tarballs() { fi } +# See Note [tooldir: How GHC finds mingw on Windows] if test "$HostOS" = "mingw32" -a "$EnableDistroToolchain" = "NO" then test -d inplace || mkdir inplace @@ -455,6 +456,7 @@ fi # We don't want to bundle a MinGW-w64 toolchain # So we have to find these individual tools. +# See Note [tooldir: How GHC finds mingw on Windows] if test "$EnableDistroToolchain" = "YES" then # Ideally should use AC_CHECK_TARGET_TOOL but our triples @@ -462,6 +464,7 @@ then # so never tried without the prefix. AC_PATH_PROG([CC],[gcc], [clang]) AC_PATH_PROG([NM],[nm]) + AC_PATH_PROG([LD],[ld]) AC_PATH_PROG([AR],[ar]) AC_PATH_PROG([RANLIB],[ranlib]) AC_PATH_PROG([OBJDUMP],[objdump]) ===================================== hadrian/cfg/system.config.in ===================================== @@ -92,6 +92,8 @@ project-patch-level1 = @ProjectPatchLevel1@ project-patch-level2 = @ProjectPatchLevel2@ project-git-commit-id = @ProjectGitCommitId@ +system-use-distro-mingw = @SettingsUseDistroMINGW@ + # Compilation and linking flags: #=============================== @@ -127,6 +129,7 @@ conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ # We are in the process of moving the settings file from being entirely # generated by configure, to generated being by the build system. Many of these # might become redundant. +# See Note [tooldir: How GHC finds mingw on Windows] gcc-extra-via-c-opts = @GccExtraViaCOpts@ ld-has-no-compact-unwind = @LdHasNoCompactUnwind@ ===================================== hadrian/src/Oracles/Flag.hs ===================================== @@ -25,6 +25,7 @@ data Flag = ArSupportsAtFile | HaveLibMingwEx | UseSystemFfi | BootstrapThreadedRts + | SystemDistroMINGW -- Note, if a flag is set to empty string we treat it as set to NO. This seems -- fragile, but some flags do behave like this. @@ -45,6 +46,7 @@ flag f = do HaveLibMingwEx -> "have-lib-mingw-ex" UseSystemFfi -> "use-system-ffi" BootstrapThreadedRts -> "bootstrap-threaded-rts" + SystemDistroMINGW -> "system-use-distro-mingw" value <- lookupValueOrError configFile key when (value `notElem` ["YES", "NO", ""]) . error $ "Configuration flag " ++ quote (key ++ " = " ++ value) ++ " cannot be parsed." ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -184,6 +184,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the -- result. +-- See Note [tooldir: How GHC finds mingw on Windows] settingsFileSetting :: SettingsFileSetting -> Action String settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerCommand -> "settings-c-compiler-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -245,6 +245,7 @@ generateGhcPlatformH = do hostOs <- chooseSetting HostOs TargetOs hostVendor <- chooseSetting HostVendor TargetVendor ghcUnreg <- getFlag GhcUnregisterised + inplaceTools <- getFlag SystemDistroMINGW return . unlines $ [ "#if !defined(__GHCPLATFORM_H__)" , "#define __GHCPLATFORM_H__" @@ -274,12 +275,15 @@ generateGhcPlatformH = do , "" ] ++ + [ "#define USE_INPLACE_MINGW_TOOLCHAIN 1" | inplaceTools ] + ++ [ "#define UnregisterisedCompiler 1" | ghcUnreg ] ++ [ "" , "#endif /* __GHCPLATFORM_H__ */" ] +-- See Note [tooldir: How GHC finds mingw on Windows] generateSettings :: Expr String generateSettings = do ctx <- getContext ===================================== includes/ghc.mk ===================================== @@ -186,6 +186,9 @@ $$(includes_$1_H_PLATFORM) : includes/ghc.mk includes/Makefile | $$$$(dir $$$$@) @echo "#define BUILD_VENDOR \"$(BuildVendor_$1_CPP)\"" >> $$@ @echo "#define HOST_VENDOR \"$(HostVendor_$1_CPP)\"" >> $$@ @echo >> $$@ +ifeq "$$(SettingsUseDistroMINGW)" "YES" + @echo "#define USE_INPLACE_MINGW_TOOLCHAIN 1" >> $$@ +endif ifeq "$$(GhcUnregisterised)" "YES" @echo "#define UnregisterisedCompiler 1" >> $$@ endif @@ -204,6 +207,7 @@ $(eval $(call includesHeaderPlatform,1)) # These settings are read by GHC at runtime, so as to not cause spurious # rebuilds. +# See Note [tooldir: How GHC finds mingw on Windows] includes_SETTINGS = includes/dist/build/settings ===================================== libraries/ghc-prim/GHC/Magic.hs ===================================== @@ -1,8 +1,6 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE Trustworthy #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE MagicHash #-} -{-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -32,13 +30,8 @@ module GHC.Magic ( inline, noinline, lazy, oneShot, runRW# ) where -- Here import TYPE explicitly from GHC.Types and not from GHC.Prim. This is -- because TYPE is not exported by the source Haskell module generated by --- genprimops which Haddock will typecheck. --- Likewise, realWorld# is not generated by genprimops so we use CPP and only --- import/use it when not building haddock docs. -#if !defined(__HADDOCK_VERSION__) -import GHC.Prim (realWorld#) -#endif -import GHC.Prim (State#, RealWorld) +-- genprimops which Haddock will typecheck (#15935). +import GHC.Prim (State#, realWorld#, RealWorld) import GHC.Types (RuntimeRep, TYPE) -- | The call @inline f@ arranges that @f@ is inlined, regardless of @@ -83,8 +76,6 @@ noinline x = x -- -- If 'lazy' were not lazy, 'Control.Parallel.par' would look strict in -- @y@ which would defeat the whole purpose of 'Control.Parallel.par'. --- --- Like 'seq', the argument of 'lazy' can have an unboxed type. lazy :: a -> a lazy x = x -- Implementation note: its strictness and unfolding are over-ridden @@ -124,8 +115,4 @@ runRW# :: forall (r :: RuntimeRep) (o :: TYPE r). (State# RealWorld -> o) -> o -- See Note [runRW magic] in GHC.CoreToStg.Prep. {-# NOINLINE runRW# #-} -- runRW# is inlined manually in CorePrep -#if !defined(__HADDOCK_VERSION__) runRW# m = m realWorld# -#else -runRW# = runRW# -- The realWorld# is too much for haddock -#endif ===================================== mk/config.mk.in ===================================== @@ -475,6 +475,7 @@ endif # We are in the process of moving the settings file from being entirely # generated by configure, to generated being by the build system. Many of these # might become redundant. +# See Note [tooldir: How GHC finds mingw on Windows] GccExtraViaCOpts = @GccExtraViaCOpts@ LdHasFilelist = @LdHasFilelist@ ===================================== mk/project.mk.in ===================================== @@ -20,8 +20,8 @@ # # The ProjectVersionInt is included in interface files, and GHC # checks that it's reading interface generated by the same ProjectVersion -# as itself. It does this even though interface file syntax may not -# change between versions. Rationale: calling conventions or other +# as itself. It does this even though interface file syntax may not +# change between versions. Rationale: calling conventions or other # random .o-file stuff might change even if the .hi syntax doesn't ProjectName = @ProjectName@ @@ -127,6 +127,7 @@ BuildVendor_CPP = @BuildVendor_CPP@ # Valid options: YES/NO # LeadingUnderscore=@LeadingUnderscore@ +SettingsUseDistroMINGW=@SettingsUseDistroMINGW@ # Pin a suffix on executables? If so, what (Windows only). exeext0=@exeext_host@ ===================================== testsuite/tests/rename/should_compile/Makefile ===================================== @@ -60,3 +60,8 @@ T7969: T18497: '$(TEST_HC)' $(TEST_HC_OPTS) -fno-code T18497_Foo.hs T18497_Bar.hs -ddump-minimal-imports cat T18497_Bar.imports-boot + +T18264: + $(RM) T18264.hi T18264.o T18264.imports + '$(TEST_HC)' $(TEST_HC_OPTS) -ddump-minimal-imports -c T18264.hs + cat T18264.imports ===================================== testsuite/tests/rename/should_compile/T18264.hs ===================================== @@ -0,0 +1,20 @@ +module T18264 where + +import Data.Char (isDigit) +import Data.Maybe (isJust) +import Data.Char (isPrint) +import Data.List (sortOn) +import Data.Char (isLetter) +import Data.Maybe hiding (isNothing) + +import qualified Data.List as S (sort) +import qualified Data.Char as C --only isDigit & isLetter used later +import qualified Data.List as T (nub) + +test1 x = isDigit x || isLetter x +test2a = isJust +test2b = fromJust +test3 x = C.isDigit x || C.isLetter x +test4 xs = S.sort xs +test5 xs = T.nub xs +test6 f xs = sortOn f xs ===================================== testsuite/tests/rename/should_compile/T18264.stdout ===================================== @@ -0,0 +1,6 @@ +import Data.Char ( isDigit, isLetter ) +import Data.List ( sortOn ) +import Data.Maybe ( fromJust, isJust ) +import qualified Data.Char as C ( isLetter, isDigit ) +import qualified Data.List as S ( sort ) +import qualified Data.List as T ( nub ) ===================================== testsuite/tests/rename/should_compile/all.T ===================================== @@ -175,3 +175,4 @@ test('T17244C', normal, compile, ['']) test('T17832', [], multimod_compile, ['T17832M1', 'T17832M2']) test('T17837', normal, compile, ['']) test('T18497', [], makefile_test, ['T18497']) +test('T18264', [], makefile_test, ['T18264']) ===================================== testsuite/tests/th/T18612.hs ===================================== @@ -0,0 +1,14 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -ddump-splices #-} +module T18612 where + +import Data.Functor.Identity +import Data.Proxy +import Language.Haskell.TH + +f :: $(arrowT `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))) + `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0)))) +f $(conP 'Identity [tupP [tupP []]]) = $(conE 'Identity `appE` tupE [tupE []]) + +type G = $(conT ''Proxy `appT` (promotedTupleT 1 `appT` (tupleT 0))) ===================================== testsuite/tests/th/T18612.stderr ===================================== @@ -0,0 +1,13 @@ +T18612.hs:14:11-68: Splicing type + conT ''Proxy `appT` (promotedTupleT 1 `appT` (tupleT 0)) + ======> + Proxy ('Solo ()) +T18612.hs:(10,7)-(11,75): Splicing type + arrowT `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))) + `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))) + ======> + Identity (Solo ()) -> Identity (Solo ()) +T18612.hs:12:4-36: Splicing pattern + conP 'Identity [tupP [tupP []]] ======> Identity (Solo()) +T18612.hs:12:41-78: Splicing expression + conE 'Identity `appE` tupE [tupE []] ======> Identity (Solo ()) ===================================== testsuite/tests/th/all.T ===================================== @@ -513,3 +513,4 @@ test('T18102b', extra_files(['T18102b_aux.hs']), compile_and_run, ['']) test('T18121', normal, compile, ['']) test('T18123', normal, compile, ['']) test('T18388', normal, compile, ['']) +test('T18612', normal, compile, ['']) ===================================== utils/genprimopcode/Main.hs ===================================== @@ -1,5 +1,7 @@ ------------------------------------------------------------------ -- A primop-table mangling program -- +-- +-- See Note [GHC.Prim] in primops.txt.pp for details. ------------------------------------------------------------------ module Main where @@ -293,8 +295,6 @@ gen_hs_source (Info defaults entries) = hdr (PrimOpSpec { name = n }) = wrapOp n ++ "," hdr (PrimVecOpSpec { name = n }) = wrapOp n ++ "," hdr (PseudoOpSpec { name = n }) = wrapOp n ++ "," - hdr (PrimTypeSpec { ty = TyApp (TyCon "->") _ }) = "" - -- GHC lacks the syntax to explicitly export "->" hdr (PrimTypeSpec { ty = TyApp (TyCon n) _ }) = wrapOp n ++ "," hdr (PrimTypeSpec {}) = error $ "Illegal type spec" hdr (PrimVecTypeSpec { ty = TyApp (VecTyCon n _) _ }) = wrapOp n ++ "," @@ -398,8 +398,6 @@ keep GHC's renamer and typechecker happy enough for what Haddock needs. Our main plan is to say foo :: foo = foo -We have to silence GHC's complaints about unboxed-top-level declarations -with an ad-hoc fix in GHC.Tc.Gen.Bind: see Note [Compiling GHC.Prim] in GHC.Tc.Gen.Bind. That works for all the primitive functions except tagToEnum#. If we generate the binding ===================================== utils/genprimopcode/Parser.y ===================================== @@ -163,6 +163,7 @@ paT : pTycon ppTs { TyApp $1 $2 } pUnboxedTupleTy :: { Ty } pUnboxedTupleTy : '(#' pCommaTypes '#)' { TyUTup $2 } + | '(#' '#)' { TyUTup [] } pCommaTypes :: { [Ty] } pCommaTypes : pType ',' pCommaTypes { $1 : $3 } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e0b3cbdac94de38586d2cbe0654a2ef35e96635f...36098d00f0906efd87bc4ca7d37001c7658904d5 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e0b3cbdac94de38586d2cbe0654a2ef35e96635f...36098d00f0906efd87bc4ca7d37001c7658904d5 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 28 02:53:00 2020 From: gitlab at gitlab.haskell.org (Moritz Angermann) Date: Thu, 27 Aug 2020 22:53:00 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/angerman/fix-3431-flag-type Message-ID: <5f48718c65231_80b3f844caaf1809692598@gitlab.haskell.org.mail> Moritz Angermann pushed new branch wip/angerman/fix-3431-flag-type at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/angerman/fix-3431-flag-type You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 28 06:22:43 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 28 Aug 2020 02:22:43 -0400 Subject: [Git][ghc/ghc][master] Add missing primop documentation (#18454) Message-ID: <5f48a2b3712e4_80b8b9994096988ed@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: c6f50cea by Krzysztof Gogolewski at 2020-08-28T02:22:36-04:00 Add missing primop documentation (#18454) - Add three pseudoops to primops.txt.pp, so that Haddock renders the documentation - Update comments - Remove special case for "->" - it's no longer exported from GHC.Prim - Remove reference to Note [Compiling GHC.Prim] - the ad-hoc fix is no longer there after updates to levity polymorphism. - Document GHC.Prim - Remove the comment that lazy is levity-polymorphic. As far as I can tell, it never was: in 80e399639, only the unfolding was given an open type variable. - Remove haddock hack in GHC.Magic - no longer neccessary after adding realWorld# to primops.txt.pp. - - - - - 8 changed files: - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/Iface/Load.hs - compiler/GHC/Types/Id/Make.hs - compiler/GHC/Types/Unique/Supply.hs - libraries/ghc-prim/GHC/Magic.hs - utils/genprimopcode/Main.hs - utils/genprimopcode/Parser.y Changes: ===================================== compiler/GHC/Builtin/Utils.hs ===================================== @@ -257,9 +257,6 @@ primOpId op = primOpIds ! primOpTag op Export lists for pseudo-modules (GHC.Prim) * * ************************************************************************ - -GHC.Prim "exports" all the primops and primitive types, some -wired-in Ids. -} ghcPrimExports :: [IfaceExport] ===================================== compiler/GHC/Builtin/primops.txt.pp ===================================== @@ -15,14 +15,86 @@ -- -- It should first be preprocessed. -- +-- Note in particular that Haskell block-style comments are not recognized +-- here, so stick to '--' (even for Notes spanning multiple lines). + +-- Note [GHC.Prim] +-- ~~~~~~~~~~~~~~~ +-- GHC.Prim is a special module: +-- +-- * It can be imported by any module (import GHC.Prim). +-- However, in the future we might change which functions are primitives +-- and which are defined in Haskell. +-- Users should import GHC.Exts, which reexports GHC.Prim and is more stable. +-- In particular, we might move some of the primops to 'foreign import prim' +-- (see ticket #16929 and Note [When do out-of-line primops go in primops.txt.pp]) +-- +-- * It provides primitives of three sorts: +-- - primitive types such as Int64#, MutableByteArray# +-- - primops such as (+#), newTVar#, touch# +-- - pseudoops such as realWorld#, nullAddr# +-- +-- * The pseudoops are described in Note [ghcPrimIds (aka pseudoops)] +-- in GHC.Types.Id.Make. +-- +-- * The primitives (primtypes, primops, pseudoops) cannot be defined in +-- source Haskell. +-- There is no GHC/Prim.hs file with definitions. +-- Instead, we support importing GHC.Prim by manually defining its +-- ModIface (see Iface.Load.ghcPrimIface). +-- +-- * The primitives are listed in this file, primops.txt.pp. +-- It goes through CPP, which creates primops.txt. +-- It is then consumed by the utility program genprimopcode, which produces +-- the following three types of files. +-- +-- 1. The files with extension .hs-incl. +-- They can be found by grepping for hs-incl. +-- They are #included in compiler sources. +-- +-- One of them, primop-data-decl.hs-incl, defines the PrimOp type: +-- data PrimOp +-- = IntAddOp +-- | IntSubOp +-- | CharGtOp +-- | CharGeOp +-- | ... +-- +-- The remaining files define properties of the primops +-- by pattern matching, for example: +-- primOpFixity IntAddOp = Just (Fixity NoSourceText 6 InfixL) +-- primOpFixity IntSubOp = Just (Fixity NoSourceText 6 InfixL) +-- ... +-- This includes fixity, has-side-effects, commutability, +-- IDs used to generate Uniques etc. +-- +-- Additionally, we pattern match on PrimOp when generating Cmm in +-- GHC/StgToCmm/Prim.hs. +-- +-- 2. The dummy Prim.hs file, which is used for Haddock and +-- contains descriptions taken from primops.txt.pp. +-- All definitions are replaced by placeholders. +-- See Note [GHC.Prim Docs] in genprimopcode. +-- +-- 3. The module PrimopWrappers.hs, which wraps every call for GHCi; +-- see Note [Primop wrappers] in GHC.Builtin.Primops for details. +-- +-- * This file does not list internal-only equality types +-- (GHC.Builtin.Types.Prim.unexposedPrimTyCons and coercionToken# +-- in GHC.Types.Id.Make) which are defined but not exported from GHC.Prim. +-- Every export of GHC.Prim should be in listed in this file. +-- +-- * The primitive types should be listed in primTyCons in Builtin.Types.Prim +-- in addition to primops.txt.pp. +-- (This task should be delegated to genprimopcode in the future.) +-- +-- +-- -- Information on how PrimOps are implemented and the steps necessary to -- add a new one can be found in the Commentary: -- -- https://gitlab.haskell.org/ghc/ghc/wikis/commentary/prim-ops -- --- Note in particular that Haskell block-style comments are not recognized --- here, so stick to '--' (even for Notes spanning multiple lines). - -- This file is divided into named sections, each containing or more -- primop entries. Section headers have the format: -- @@ -76,7 +148,6 @@ defaults vector = [] deprecated_msg = {} -- A non-empty message indicates deprecation - -- Note [When do out-of-line primops go in primops.txt.pp] -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- @@ -189,19 +260,6 @@ section "The word size story." #define WORD64 Word# #endif --- This type won't be exported directly (since there is no concrete --- syntax for this sort of export) so we'll have to manually patch --- export lists in both GHC and Haddock. -primtype FUN m a b - {The builtin function type, written in infix form as {\tt a # m -> b}. - Values of this type are functions taking inputs of type {\tt a} and - producing outputs of type {\tt b}. The multiplicity of the input is - {\tt m}. - - Note that {\tt FUN m a b} permits levity-polymorphism in both {\tt a} and - {\tt b}, so that types like {\tt Int\# -> Int\#} can still be well-kinded. - } - ------------------------------------------------------------------------ section "Char#" {Operations on 31-bit characters.} @@ -3377,6 +3435,37 @@ section "Etc" {Miscellaneous built-ins} ------------------------------------------------------------------------ +primtype FUN m a b + {The builtin function type, written in infix form as {\tt a # m -> b}. + Values of this type are functions taking inputs of type {\tt a} and + producing outputs of type {\tt b}. The multiplicity of the input is + {\tt m}. + + Note that {\tt FUN m a b} permits levity-polymorphism in both {\tt a} and + {\tt b}, so that types like {\tt Int\# -> Int\#} can still be well-kinded. + } + +pseudoop "realWorld#" + State# RealWorld + { The token used in the implementation of the IO monad as a state monad. + It does not pass any information at runtime. + See also {\tt GHC.Magic.runRW\#}. } + +pseudoop "void#" + (# #) + { This is an alias for the unboxed unit tuple constructor. + In earlier versions of GHC, {\tt void\#} was a value + of the primitive type {\tt Void\#}, which is now defined to be {\tt (\# \#)}. + } + with deprecated_msg = { Use an unboxed unit tuple instead } + +pseudoop "magicDict" + a + { {\tt magicDict} is a special-purpose placeholder value. + It is used internally by modules such as {\tt GHC.TypeNats} to cast a typeclass + dictionary with a single method. It is eliminated by a rule during compilation. + For the details, see Note [magicDictId magic] in GHC. } + primtype Proxy# a { The type constructor {\tt Proxy#} is used to bear witness to some type variable. It's used when you want to pass around proxy values ===================================== compiler/GHC/Iface/Load.hs ===================================== @@ -915,6 +915,7 @@ findAndReadIface doc_str mod wanted_mod_with_insts hi_boot_file nest 4 (text "reason:" <+> doc_str)]) -- Check for GHC.Prim, and return its static interface + -- See Note [GHC.Prim] in primops.txt.pp. -- TODO: make this check a function if mod `installedModuleEq` gHC_PRIM then do @@ -1059,6 +1060,7 @@ initExternalPackageState home_unit ********************************************************* -} +-- See Note [GHC.Prim] in primops.txt.pp. ghcPrimIface :: ModIface ghcPrimIface = empty_iface { @@ -1071,7 +1073,7 @@ ghcPrimIface where empty_iface = emptyFullModIface gHC_PRIM - -- The fixities listed here for @`seq`@ or @->@ should match + -- The fixity listed here for @`seq`@ should match -- those in primops.txt.pp (from which Haddock docs are generated). fixities = (getOccName seqId, Fixity NoSourceText 0 InfixR) : mapMaybe mkFixity allThePrimOps ===================================== compiler/GHC/Types/Id/Make.hs ===================================== @@ -118,7 +118,8 @@ Note [ghcPrimIds (aka pseudoops)] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The ghcPrimIds - * Are exported from GHC.Prim + * Are exported from GHC.Prim (see ghcPrimExports, used in ghcPrimInterface) + See Note [GHC.Prim] in primops.txt.pp for the remaining items in GHC.Prim. * Can't be defined in Haskell, and hence no Haskell binding site, but have perfectly reasonable unfoldings in Core @@ -141,7 +142,17 @@ The magicIds * May or may not have a CompulsoryUnfolding. * But have some special behaviour that can't be done via an - unfolding from an interface file + unfolding from an interface file. + + * May have IdInfo that differs from what would be imported from GHC.Magic.hi. + For example, 'lazy' gets a lazy strictness signature, per Note [lazyId magic]. + + The two remaining identifiers in GHC.Magic, runRW# and inline, are not listed + in magicIds: they have special behavior but they can be known-key and + not wired-in. + runRW#: see Note [Simplification of runRW#] in Prep, runRW# code in + Simplifier, Note [Linting of runRW#]. + inline: see Note [inlineId magic] -} wiredInIds :: [Id] @@ -1402,12 +1413,12 @@ These Ids can't be defined in Haskell. They could be defined in unfoldings in the wired-in GHC.Prim interface file, but we'd have to ensure that they were definitely, definitely inlined, because there is no curried identifier for them. That's what mkCompulsoryUnfolding -does. If we had a way to get a compulsory unfolding from an interface -file, we could do that, but we don't right now. +does. Alternatively, we could add the definitions to mi_decls of ghcPrimIface +but it's not clear if this would be simpler. -The type variables we use here are "open" type variables: this means -they can unify with both unlifted and lifted types. Hence we provide -another gun with which to shoot yourself in the foot. +coercionToken# is not listed in ghcPrimIds, since its type uses (~#) +which is not supposed to be used in expressions (GHC throws an assertion +failure when trying.) -} nullAddrName, seqName, @@ -1422,6 +1433,7 @@ magicDictName = mkWiredInIdName gHC_PRIM (fsLit "magicDict") magicDict coerceName = mkWiredInIdName gHC_PRIM (fsLit "coerce") coerceKey coerceId proxyName = mkWiredInIdName gHC_PRIM (fsLit "proxy#") proxyHashKey proxyHashId +-- Names listed in magicIds; see Note [magicIds] lazyIdName, oneShotName, noinlineIdName :: Name lazyIdName = mkWiredInIdName gHC_MAGIC (fsLit "lazy") lazyIdKey lazyId oneShotName = mkWiredInIdName gHC_MAGIC (fsLit "oneShot") oneShotKey oneShotId @@ -1598,7 +1610,7 @@ See also: Note [User-defined RULES for seq] in GHC.Core.Opt.Simplify. Note [lazyId magic] ~~~~~~~~~~~~~~~~~~~ -lazy :: forall a?. a? -> a? (i.e. works for unboxed types too) +lazy :: forall a. a -> a 'lazy' is used to make sure that a sub-expression, and its free variables, are truly used call-by-need, with no code motion. Key examples: @@ -1616,7 +1628,7 @@ are truly used call-by-need, with no code motion. Key examples: Implementing 'lazy' is a bit tricky: * It must not have a strictness signature: by being a built-in Id, - all the info about lazyId comes from here, not from GHC.Base.hi. + all the info about lazyId comes from here, not from GHC.Magic.hi. This is important, because the strictness analyser will spot it as strict! @@ -1777,7 +1789,7 @@ voidPrimId = pcMiscPrelId voidPrimIdName unboxedUnitTy voidArgId :: Id -- Local lambda-bound :: Void# voidArgId = mkSysLocal (fsLit "void") voidArgIdKey Many unboxedUnitTy -coercionTokenId :: Id -- :: () ~ () +coercionTokenId :: Id -- :: () ~# () coercionTokenId -- See Note [Coercion tokens] in "GHC.CoreToStg" = pcMiscPrelId coercionTokenName (mkTyConApp eqPrimTyCon [liftedTypeKind, liftedTypeKind, unitTy, unitTy]) @@ -1786,8 +1798,3 @@ coercionTokenId -- See Note [Coercion tokens] in "GHC.CoreToStg" pcMiscPrelId :: Name -> Type -> IdInfo -> Id pcMiscPrelId name ty info = mkVanillaGlobalWithInfo name ty info - -- We lie and say the thing is imported; otherwise, we get into - -- a mess with dependency analysis; e.g., core2stg may heave in - -- random calls to GHCbase.unpackPS__. If GHCbase is the module - -- being compiled, then it's just a matter of luck if the definition - -- will be in "the right place" to be in scope. ===================================== compiler/GHC/Types/Unique/Supply.hs ===================================== @@ -180,7 +180,7 @@ The magic `inline` function does two things * It helps ensure that 'm' really does inline. -Note that 'inline' evaporates in phase 0. See Note [inlineIdMagic] +Note that 'inline' evaporates in phase 0. See Note [inlineId magic] in GHC.Core.Opt.ConstantFold.match_inline. The INLINE pragma on multiShotIO is very important, else the ===================================== libraries/ghc-prim/GHC/Magic.hs ===================================== @@ -1,8 +1,6 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE Trustworthy #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE MagicHash #-} -{-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -32,13 +30,8 @@ module GHC.Magic ( inline, noinline, lazy, oneShot, runRW# ) where -- Here import TYPE explicitly from GHC.Types and not from GHC.Prim. This is -- because TYPE is not exported by the source Haskell module generated by --- genprimops which Haddock will typecheck. --- Likewise, realWorld# is not generated by genprimops so we use CPP and only --- import/use it when not building haddock docs. -#if !defined(__HADDOCK_VERSION__) -import GHC.Prim (realWorld#) -#endif -import GHC.Prim (State#, RealWorld) +-- genprimops which Haddock will typecheck (#15935). +import GHC.Prim (State#, realWorld#, RealWorld) import GHC.Types (RuntimeRep, TYPE) -- | The call @inline f@ arranges that @f@ is inlined, regardless of @@ -83,8 +76,6 @@ noinline x = x -- -- If 'lazy' were not lazy, 'Control.Parallel.par' would look strict in -- @y@ which would defeat the whole purpose of 'Control.Parallel.par'. --- --- Like 'seq', the argument of 'lazy' can have an unboxed type. lazy :: a -> a lazy x = x -- Implementation note: its strictness and unfolding are over-ridden @@ -124,8 +115,4 @@ runRW# :: forall (r :: RuntimeRep) (o :: TYPE r). (State# RealWorld -> o) -> o -- See Note [runRW magic] in GHC.CoreToStg.Prep. {-# NOINLINE runRW# #-} -- runRW# is inlined manually in CorePrep -#if !defined(__HADDOCK_VERSION__) runRW# m = m realWorld# -#else -runRW# = runRW# -- The realWorld# is too much for haddock -#endif ===================================== utils/genprimopcode/Main.hs ===================================== @@ -1,5 +1,7 @@ ------------------------------------------------------------------ -- A primop-table mangling program -- +-- +-- See Note [GHC.Prim] in primops.txt.pp for details. ------------------------------------------------------------------ module Main where @@ -293,8 +295,6 @@ gen_hs_source (Info defaults entries) = hdr (PrimOpSpec { name = n }) = wrapOp n ++ "," hdr (PrimVecOpSpec { name = n }) = wrapOp n ++ "," hdr (PseudoOpSpec { name = n }) = wrapOp n ++ "," - hdr (PrimTypeSpec { ty = TyApp (TyCon "->") _ }) = "" - -- GHC lacks the syntax to explicitly export "->" hdr (PrimTypeSpec { ty = TyApp (TyCon n) _ }) = wrapOp n ++ "," hdr (PrimTypeSpec {}) = error $ "Illegal type spec" hdr (PrimVecTypeSpec { ty = TyApp (VecTyCon n _) _ }) = wrapOp n ++ "," @@ -398,8 +398,6 @@ keep GHC's renamer and typechecker happy enough for what Haddock needs. Our main plan is to say foo :: foo = foo -We have to silence GHC's complaints about unboxed-top-level declarations -with an ad-hoc fix in GHC.Tc.Gen.Bind: see Note [Compiling GHC.Prim] in GHC.Tc.Gen.Bind. That works for all the primitive functions except tagToEnum#. If we generate the binding ===================================== utils/genprimopcode/Parser.y ===================================== @@ -163,6 +163,7 @@ paT : pTycon ppTs { TyApp $1 $2 } pUnboxedTupleTy :: { Ty } pUnboxedTupleTy : '(#' pCommaTypes '#)' { TyUTup $2 } + | '(#' '#)' { TyUTup [] } pCommaTypes :: { [Ty] } pCommaTypes : pType ',' pCommaTypes { $1 : $3 } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c6f50cea42a9ffc947bf4243986663cc820b0ec8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c6f50cea42a9ffc947bf4243986663cc820b0ec8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 28 06:23:19 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Fri, 28 Aug 2020 02:23:19 -0400 Subject: [Git][ghc/ghc][master] 2 commits: Fix use distro toolchian Message-ID: <5f48a2d7e70f1_80b10bcb0009699743@gitlab.haskell.org.mail> Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: f065b6b0 by Tamar Christina at 2020-08-28T02:23:13-04:00 Fix use distro toolchian - - - - - 4517a382 by Tamar Christina at 2020-08-28T02:23:13-04:00 document how build system find toolchains on Windows - - - - - 10 changed files: - aclocal.m4 - compiler/GHC/SysTools/BaseDir.hs - configure.ac - hadrian/cfg/system.config.in - hadrian/src/Oracles/Flag.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - includes/ghc.mk - mk/config.mk.in - mk/project.mk.in Changes: ===================================== aclocal.m4 ===================================== @@ -507,6 +507,7 @@ AC_DEFUN([GET_ARM_ISA], # FP_SETTINGS # ---------------------------------- # Set the variables used in the settings file +# See Note [tooldir: How GHC finds mingw on Windows] AC_DEFUN([FP_SETTINGS], [ if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" @@ -583,6 +584,7 @@ AC_DEFUN([FP_SETTINGS], SettingsCCompilerLinkFlags="$CONF_GCC_LINKER_OPTS_STAGE2" SettingsCCompilerSupportsNoPie="$CONF_GCC_SUPPORTS_NO_PIE" SettingsLdFlags="$CONF_LD_LINKER_OPTS_STAGE2" + SettingsUseDistroMINGW="$EnableDistroToolchain" AC_SUBST(SettingsCCompilerCommand) AC_SUBST(SettingsHaskellCPPCommand) AC_SUBST(SettingsHaskellCPPFlags) @@ -601,6 +603,7 @@ AC_DEFUN([FP_SETTINGS], AC_SUBST(SettingsClangCommand) AC_SUBST(SettingsLlcCommand) AC_SUBST(SettingsOptCommand) + AC_SUBST(SettingsUseDistroMINGW) ]) # Helper for cloning a shell variable's state ===================================== compiler/GHC/SysTools/BaseDir.hs ===================================== @@ -34,16 +34,6 @@ import System.FilePath import System.Directory (doesDirectoryExist) #endif -#if defined(mingw32_HOST_OS) -# if defined(i386_HOST_ARCH) -# define WINDOWS_CCONV stdcall -# elif defined(x86_64_HOST_ARCH) -# define WINDOWS_CCONV ccall -# else -# error Unknown mingw32 arch -# endif -#endif - {- Note [topdir: How GHC finds its files] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -70,16 +60,89 @@ Note [tooldir: How GHC finds mingw on Windows] GHC has some custom logic on Windows for finding the mingw toolchain and perl. Depending on whether GHC is built with the make build system or Hadrian, and on whether we're -running a bindist, we might find the mingw toolchain and perl +running a bindist, we might find the mingw toolchain either under $topdir/../{mingw, perl}/ or $topdir/../../{mingw, perl}/. +This story is long and with lots of twist and turns.. But lets talk about how +the build system finds and wires through the toolchain information. + +1) It all starts in configure.ac which has two modes it operates on: + a) The default is where `EnableDistroToolchain` is false. This indicates + that we want to use the in-tree bundled toolchains. In this mode we will + download and unpack some custom toolchains into the `inplace/mingw` folder + and everything is pointed to that folder. + b) The second path is when `EnableDistroToolchain` is true. This makes the + toolchain behave a lot like Linux, in that the environment is queried for + information on the tools we require. + + From configure.ac we export the standard variables to set the paths to the + tools for the build system to use. + +2) After we have the path to the tools we have to generate the right paths to + store in the settings file for ghc to use. This is done in aclocal.m4. + Again we have two modes of operation: + a) If not `EnableDistroToolchain` the paths are rewritten to paths using a + variable `$tooldir` as we need an absolute path. $tooldir is filled in by + the `expandToolDir` function in this module at GHC startup. + b) When `EnableDistroToolchain` then instead of filling in a absolute path + we fill in just the program name. The assumption here is that at runtime + the environment GHC is operating on will be the same as the one configure + was run in. This means we expect `gcc, ld, as` etc to be on the PATH. + + From `aclocal.m4` we export a couple of variables starting with `Settings` + which will be used to generate the settings file. + +3) The next step is to generate the settings file, this is where things diverge + based on the build system. Both Make and Hadrian handle this differently: + +make) + Make deals with this rather simply. As an output of configure.ac + `config.mk.in` is processed and `config.mk` generated which has the values we + set in `aclocal.m4`. This allows the rest of the build system to have access + to these and other values determined by configure. + + Based on this file, `includes/ghc.mk` when ran will produce the settings file + by echoing the values into a the final file. Coincidentally this is also + where `ghcplatform.h` and `ghcversion.h` generated which contains information + about the build platform and sets CPP for use by the entire build. + +hadrian) + For hadrian the file `cfg/system.config.in` is preprocessed by configure and + the output written to `system.config`. This serves the same purpose as + `config.mk` but it rewrites the values that were exported. As an example + `SettingsCCompilerCommand` is rewritten to `settings-c-compiler-command`. + + Next up is `src/Oracles/Settings.hs` which makes from some Haskell ADT to + the settings `keys` in the `system.config`. As an example, + `settings-c-compiler-command` is mapped to + `SettingsFileSetting_CCompilerCommand`. + + The last part of this is the `generateSettings` in `src/Rules/Generate.hs` + which produces the desired settings file out of Hadrian. This is the + equivalent to `includes/ghc.mk`. + +-- + +So why do we have these? On Windows there's no such thing as a platform compiler +and as such we need to provide GCC and binutils. The easiest way is to bundle +these with the compiler and wire them up. This gives you a relocatable +binball. This works fine for most users. However mingw-w64 have a different +requirement. They require all packages in the repo to be compiled using the +same version of the compiler. So it means when they are rebuilding the world to +add support for GCC X, they expect all packages to have been compiled with GCC X +which is a problem since we ship an older GCC version. + +GHC is a package in mingw-w64 because there are Haskell packages in the +repository which of course requires a Haskell compiler. To help them we +provide the override which allows GHC to instead of using an inplace compiler to +play nice with the system compiler instead. -} -- | Expand occurrences of the @$tooldir@ interpolation in a string -- on Windows, leave the string untouched otherwise. expandToolDir :: Maybe FilePath -> String -> String -#if defined(mingw32_HOST_OS) +#if defined(mingw32_HOST_OS) && !defined(USE_INPLACE_MINGW_TOOLCHAIN) expandToolDir (Just tool_dir) s = expandPathVar "tooldir" tool_dir s expandToolDir Nothing _ = panic "Could not determine $tooldir" #else @@ -113,14 +176,15 @@ tryFindTopDir Nothing Nothing -> getBaseDir --- See Note [tooldir: How GHC finds mingw and perl on Windows] +-- See Note [tooldir: How GHC finds mingw on Windows] -- Returns @Nothing@ when not on Windows. -- When called on Windows, it either throws an error when the -- tooldir can't be located, or returns @Just tooldirpath at . +-- If the distro toolchain is being used we treat Windows the same as Linux findToolDir :: FilePath -- ^ topdir -> IO (Maybe FilePath) -#if defined(mingw32_HOST_OS) +#if defined(mingw32_HOST_OS) && !defined(USE_INPLACE_MINGW_TOOLCHAIN) findToolDir top_dir = go 0 (top_dir "..") where maxDepth = 3 go :: Int -> FilePath -> IO (Maybe FilePath) ===================================== configure.ac ===================================== @@ -435,6 +435,7 @@ set_up_tarballs() { fi } +# See Note [tooldir: How GHC finds mingw on Windows] if test "$HostOS" = "mingw32" -a "$EnableDistroToolchain" = "NO" then test -d inplace || mkdir inplace @@ -455,6 +456,7 @@ fi # We don't want to bundle a MinGW-w64 toolchain # So we have to find these individual tools. +# See Note [tooldir: How GHC finds mingw on Windows] if test "$EnableDistroToolchain" = "YES" then # Ideally should use AC_CHECK_TARGET_TOOL but our triples @@ -462,6 +464,7 @@ then # so never tried without the prefix. AC_PATH_PROG([CC],[gcc], [clang]) AC_PATH_PROG([NM],[nm]) + AC_PATH_PROG([LD],[ld]) AC_PATH_PROG([AR],[ar]) AC_PATH_PROG([RANLIB],[ranlib]) AC_PATH_PROG([OBJDUMP],[objdump]) ===================================== hadrian/cfg/system.config.in ===================================== @@ -92,6 +92,8 @@ project-patch-level1 = @ProjectPatchLevel1@ project-patch-level2 = @ProjectPatchLevel2@ project-git-commit-id = @ProjectGitCommitId@ +system-use-distro-mingw = @SettingsUseDistroMINGW@ + # Compilation and linking flags: #=============================== @@ -127,6 +129,7 @@ conf-merge-objects-args-stage3 = @SettingsMergeObjectsFlags@ # We are in the process of moving the settings file from being entirely # generated by configure, to generated being by the build system. Many of these # might become redundant. +# See Note [tooldir: How GHC finds mingw on Windows] gcc-extra-via-c-opts = @GccExtraViaCOpts@ ld-has-no-compact-unwind = @LdHasNoCompactUnwind@ ===================================== hadrian/src/Oracles/Flag.hs ===================================== @@ -25,6 +25,7 @@ data Flag = ArSupportsAtFile | HaveLibMingwEx | UseSystemFfi | BootstrapThreadedRts + | SystemDistroMINGW -- Note, if a flag is set to empty string we treat it as set to NO. This seems -- fragile, but some flags do behave like this. @@ -45,6 +46,7 @@ flag f = do HaveLibMingwEx -> "have-lib-mingw-ex" UseSystemFfi -> "use-system-ffi" BootstrapThreadedRts -> "bootstrap-threaded-rts" + SystemDistroMINGW -> "system-use-distro-mingw" value <- lookupValueOrError configFile key when (value `notElem` ["YES", "NO", ""]) . error $ "Configuration flag " ++ quote (key ++ " = " ++ value) ++ " cannot be parsed." ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -184,6 +184,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the -- result. +-- See Note [tooldir: How GHC finds mingw on Windows] settingsFileSetting :: SettingsFileSetting -> Action String settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_CCompilerCommand -> "settings-c-compiler-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -245,6 +245,7 @@ generateGhcPlatformH = do hostOs <- chooseSetting HostOs TargetOs hostVendor <- chooseSetting HostVendor TargetVendor ghcUnreg <- getFlag GhcUnregisterised + inplaceTools <- getFlag SystemDistroMINGW return . unlines $ [ "#if !defined(__GHCPLATFORM_H__)" , "#define __GHCPLATFORM_H__" @@ -274,12 +275,15 @@ generateGhcPlatformH = do , "" ] ++ + [ "#define USE_INPLACE_MINGW_TOOLCHAIN 1" | inplaceTools ] + ++ [ "#define UnregisterisedCompiler 1" | ghcUnreg ] ++ [ "" , "#endif /* __GHCPLATFORM_H__ */" ] +-- See Note [tooldir: How GHC finds mingw on Windows] generateSettings :: Expr String generateSettings = do ctx <- getContext ===================================== includes/ghc.mk ===================================== @@ -186,6 +186,9 @@ $$(includes_$1_H_PLATFORM) : includes/ghc.mk includes/Makefile | $$$$(dir $$$$@) @echo "#define BUILD_VENDOR \"$(BuildVendor_$1_CPP)\"" >> $$@ @echo "#define HOST_VENDOR \"$(HostVendor_$1_CPP)\"" >> $$@ @echo >> $$@ +ifeq "$$(SettingsUseDistroMINGW)" "YES" + @echo "#define USE_INPLACE_MINGW_TOOLCHAIN 1" >> $$@ +endif ifeq "$$(GhcUnregisterised)" "YES" @echo "#define UnregisterisedCompiler 1" >> $$@ endif @@ -204,6 +207,7 @@ $(eval $(call includesHeaderPlatform,1)) # These settings are read by GHC at runtime, so as to not cause spurious # rebuilds. +# See Note [tooldir: How GHC finds mingw on Windows] includes_SETTINGS = includes/dist/build/settings ===================================== mk/config.mk.in ===================================== @@ -475,6 +475,7 @@ endif # We are in the process of moving the settings file from being entirely # generated by configure, to generated being by the build system. Many of these # might become redundant. +# See Note [tooldir: How GHC finds mingw on Windows] GccExtraViaCOpts = @GccExtraViaCOpts@ LdHasFilelist = @LdHasFilelist@ ===================================== mk/project.mk.in ===================================== @@ -20,8 +20,8 @@ # # The ProjectVersionInt is included in interface files, and GHC # checks that it's reading interface generated by the same ProjectVersion -# as itself. It does this even though interface file syntax may not -# change between versions. Rationale: calling conventions or other +# as itself. It does this even though interface file syntax may not +# change between versions. Rationale: calling conventions or other # random .o-file stuff might change even if the .hi syntax doesn't ProjectName = @ProjectName@ @@ -127,6 +127,7 @@ BuildVendor_CPP = @BuildVendor_CPP@ # Valid options: YES/NO # LeadingUnderscore=@LeadingUnderscore@ +SettingsUseDistroMINGW=@SettingsUseDistroMINGW@ # Pin a suffix on executables? If so, what (Windows only). exeext0=@exeext_host@ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c6f50cea42a9ffc947bf4243986663cc820b0ec8...4517a38215eb72a4824c72d97377b9325059bf55 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c6f50cea42a9ffc947bf4243986663cc820b0ec8...4517a38215eb72a4824c72d97377b9325059bf55 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 28 06:53:31 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Fri, 28 Aug 2020 02:53:31 -0400 Subject: [Git][ghc/ghc][wip/ghc-debug] 55 commits: Allow unsaturated runRW# applications Message-ID: <5f48a9eb879b9_80b3f8468f966c8970219c@gitlab.haskell.org.mail> Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC Commits: f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 293c7fba by Sylvain Henry at 2020-08-21T09:36:38-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - 50eb4460 by Sylvain Henry at 2020-08-21T09:36:38-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 659eb31b by Sylvain Henry at 2020-08-21T09:36:38-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 2d8ca917 by Sylvain Henry at 2020-08-21T09:37:15-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - fddddbf4 by Vladislav Zavialov at 2020-08-21T09:37:49-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - 989c1c27 by Ben Gamari at 2020-08-21T11:27:53-04:00 gitlab-ci: Test master branch as well While these builds are strictly speaking redundant (since every commit is tested by @marge-bot before making it into `master`), they are nevertheless useful as they are displayed in the branch's commit list in GitLab's web interface. Fixes #18595. - - - - - e67ae884 by Aditya Gupta at 2020-08-22T03:29:00-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - 03cfcfd4 by Wander Hillen at 2020-08-22T03:29:36-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 3f501545 by Craig Ferguson at 2020-08-22T03:30:13-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 8b865092 by Krzysztof Gogolewski at 2020-08-23T14:12:53+02:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - d8f61182 by Krzysztof Gogolewski at 2020-08-23T14:12:56+02:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - 364258e0 by Krzysztof Gogolewski at 2020-08-24T00:32:31-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - b1eb38a0 by Sylvain Henry at 2020-08-24T00:33:13-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 0a1ecc5f by Ben Gamari at 2020-08-25T07:37:05-04:00 SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' In #18069 we are observing MVar deadlocks from somewhere in ghc.exe. This use of MVar stood out as being one of the more likely culprits. Here we make sure that it is exception-safe. - - - - - db8793ad by Richard Eisenberg at 2020-08-25T07:37:40-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - fb77207a by Simon Peyton Jones at 2020-08-25T07:38:16-04:00 Use LIdP rather than (XRec p (IdP p)) This patch mainly just replaces use of XRec p (IdP p) with LIdP p One slightly more significant change is to parameterise HsPatSynDetails over the pass rather than the argument type, so that it's uniform with HsConDeclDetails and HsConPatDetails. I also got rid of the dead code GHC.Hs.type.conDetailsArgs But this is all just minor refactoring. No change in functionality. - - - - - 8426a136 by Krzysztof Gogolewski at 2020-08-25T07:38:54-04:00 Add a test for #18585 - - - - - 2d635a50 by Takenobu Tani at 2020-08-26T04:50:21-04:00 linters: Make CPP linter skip image files This patch adds an exclusion rule for `docs/users_guide/images`, to avoid lint errors of PDF files. - - - - - b7d98cb2 by Takenobu Tani at 2020-08-26T04:50:21-04:00 users-guide: Color the logo on the front page of the PDF This patch updates the logo with a recent color scheme. This affects only the PDF version of the user's guide. See also: * https://mail.haskell.org/pipermail/ghc-devs/2020-August/019139.html * https://gitlab.haskell.org/ghc/ghc/-/wikis/logo - - - - - 0b17fa18 by Sylvain Henry at 2020-08-26T04:50:58-04:00 Refactor UnitId pretty-printing When we pretty-print a UnitId for the user, we try to map it back to its origin package name, version and component to print "package-version:component" instead of some hash. The UnitId type doesn't carry these information, so we have to look into a UnitState to find them. This is why the Outputable instance of UnitId used `sdocWithDynFlags` in order to access the `unitState` field of DynFlags. This is wrong for several reasons: 1. The DynFlags are accessed when the message is printed, not when it is generated. So we could imagine that the unitState may have changed in-between. Especially if we want to allow unit unloading. 2. We want GHC to support several independent sessions at once, hence several UnitState. The current approach supposes there is a unique UnitState as a UnitId doesn't indicate which UnitState to use. See the Note [Pretty-printing UnitId] in GHC.Unit for the new approach implemented by this patch. One step closer to remove `sdocDynFlags` field from `SDocContext` (#10143). Fix #18124. Also fix some Backpack code to use SDoc instead of String. - - - - - dc476a50 by Sylvain Henry at 2020-08-26T04:51:35-04:00 Bignum: fix BigNat subtraction (#18604) There was a confusion between the boolean expected by withNewWordArrayTrimedMaybe and the boolean returned by subtracting functions. - - - - - fcb10b6c by Peter Trommler at 2020-08-26T10:42:30-04:00 PPC and X86: Portable printing of IEEE floats GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness. This was brought up in #18431 by @hsyl20. - - - - - 770100e0 by Krzysztof Gogolewski at 2020-08-26T10:43:13-04:00 primops: Remove Monadic and Dyadic categories There were four categories of primops: Monadic, Dyadic, Compare, GenPrimOp. The compiler does not treat Monadic and Dyadic in any special way, we can just replace them with GenPrimOp. Compare is still used in isComparisonPrimOp. - - - - - 01ff8c89 by Aditya Gupta at 2020-08-27T14:19:26-04:00 Consolidate imports in getMinimalImports (#18264) - - - - - bacccb73 by Ryan Scott at 2020-08-27T14:20:01-04:00 Make {hsExpr,hsType,pat}NeedsParens aware of boxed 1-tuples `hsExprNeedsParens`, `hsTypeNeedsParens`, and `patNeedsParens` previously assumed that all uses of explicit tuples in the source syntax never need to be parenthesized. This is true save for one exception: boxed one-tuples, which use the `Solo` data type from `GHC.Tuple` instead of special tuple syntax. This patch adds the necessary logic to the three `*NeedsParens` functions to handle `Solo` correctly. Fixes #18612. - - - - - 909efbc8 by Matthew Pickering at 2020-08-28T08:23:39+02:00 rts: Implement ghc-debug API (#18405) There are four components to this patch which make it possible to implement `ghc-debug`. 1. Add four new functions to the RtsAPI. * rts_pause and rts_unpause allow an external process to completely pause and unpause the RTS. * rts_listThreads and rts_listMiscRoots are used to find the current roots of the garbage collector. These changes also mean that `Task.h` is exposed to the user. 2. Generalise the `ghc-heap` API so that raw `Word`s can be returned rather than actual objects. This is necessary when trying to decode closures on an external process because the pointers in such closures are correct for the internal rather than external process. If you used the previous API then you would get a segfault as the garbage collector would try to traverse into these nonsensical branches. ``` -- before getClosureData :: a -> IO Closure -- after getClosureDataX :: (forall c . c -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) ``` For the normal case `b` is instantiated to `Box`, which contains a pointer to a heap object. ``` data Box = Box a -- GenClosure Box ``` For `ghc-debug` we instead just take the word of the address as we have to explicitly interpret it on the external process. ``` GenClosure Word ``` 3. Support for decoding `TSO` and `STACK` closures is partially implemented. There is still quite a bit of work to do to finish both but these at least allow us to make some more progress. 4. findPtr is generalised to take a callback argument. This means that its result can be communicated to the debugger rather than just printing out the result. The debugger has a function which invokes `findPtr` and passes a callback which sends the result over a socket. Co-authored-by: Ben Gamari <ben at smart-cactus.org> - - - - - f1f1de64 by Sven Tennie at 2020-08-28T08:23:39+02:00 Decode more StgTSO and StgStack fields (#18405) Use hsc2hs to get an understandable and stable mapping from the C structs to Haskell. It's important to keep StgTSO and StgStack decoding downwards compatible. This is especially needed for hadrian/ghci. - - - - - c3cea59f by Sven Tennie at 2020-08-28T08:23:39+02:00 Add test for StgTSO decoding (#18405) This makes sure ghc-heap decodes StgTSO and StgStack correctly. To assert - otherwise dynamic - properties, a new, non-running TSO is created in create_tso() (create_tso.c). size is renamed to stack_size to use a dedicated type. size was already defined as a HalfWord in GenClosure, which is only equivalent to Word32 on 64bit architectures. - - - - - 6cb3485b by Sven Tennie at 2020-08-28T08:23:39+02:00 Add documentation to ghc-debug functions (#18405) - - - - - 574560d8 by Sven Tennie at 2020-08-28T08:23:39+02:00 Adjust type of getClosureX to type of getClosureDataX (#18405) After a rebase the compiler complained: libraries/ghc-heap/GHC/Exts/Heap.hs:89:23: error: • Couldn't match type: a -> IO (Ptr StgInfoTable, [Word], [b]) with: forall c. c -> IO (Ptr StgInfoTable, [Word], [b]) Expected: (forall c. c -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) Actual: (a -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) • In the expression: getClosureX In an equation for ‘getClosureDataX’: getClosureDataX = getClosureX In the instance declaration for ‘HasHeapRep a’ • Relevant bindings include getClosureDataX :: (forall c. c -> IO (Ptr StgInfoTable, [Word], [b])) -> a -> IO (GenClosure b) (bound at libraries/ghc-heap/GHC/Exts/Heap.hs:89:5) | 89 | getClosureDataX = getClosureX | ^^^^^^^^^^^ ) - - - - - 29550137 by Sven Tennie at 2020-08-28T08:23:39+02:00 Add test for rts_pause and rts_unpause (#18405) - - - - - 91367faf by Sven Tennie at 2020-08-28T08:23:39+02:00 Add test list_threads_and_misc_roots (#18405) It uses rts_listThreads() and rts_listMiscRoots(). - - - - - 574b953a by Sven Tennie at 2020-08-28T08:23:39+02:00 Introduce rts_isPaused() (#18405) Some operations are only save when the RTS is paused. This predicate helps to make such checks. - - - - - 00bda91a by Sven Tennie at 2020-08-28T08:23:39+02:00 Decode CostCentreStacks, CostCentres and InfoTables (#18405) These are the data structures used by profiling, i.e. they are only available when the RTS is used with `-prof`. Otherwise fetching them results into `Nothing`. To reduce unnecessary decoding, a state monad transformer is used to provide caching for CostCentres. Because the three types form a circular data structure, loop-breakers are applied to prevent endless decoding loops. - - - - - e5711e5a by Sven Tennie at 2020-08-28T08:23:39+02:00 Use more precise types in tests (#18405) Use `Ptr ()` instead of `Word` to communicate that addresses/pointers are meant. - - - - - 120289fb by Sven Tennie at 2020-08-28T08:23:39+02:00 Introduce LiftedClosure (#18405) This is a representation for closures that do not have a representation in the Haskell language. I.e. things like StgTSOs. - - - - - 42559bcd by Sven Tennie at 2020-08-28T08:23:39+02:00 Expect stack_marking starting from GHC 8.10 (#18405) This field was introduced with GHC 8.10. - - - - - 51befcb1 by Sven Tennie at 2020-08-28T08:23:39+02:00 Add WhatNext, WhyBlocked and TsoFlags to TSO closure (#18405) These constants can easily be decoded to sum types. Additionally extract TestUtils with common test functions. - - - - - a2a388f4 by Sven Tennie at 2020-08-28T08:23:39+02:00 END_TSO_QUEUE is not a closure type on it's own (#18405) Indeed it's a CONSTR_NOCAF. - - - - - 9af8a921 by Sven Tennie at 2020-08-28T08:23:39+02:00 Rename boundTaskExiting and getTask (#18405) Both are directly related to myTask, which the new names now reflect. - - - - - 801a46d8 by Sven Tennie at 2020-08-28T08:23:39+02:00 Mark unsafe accesses (#18405) StgTSO and StgStack are very dynamic by nature. Accesses to outdated pointers lead to segmentation faults or absolutely wrong results. So, make sure (by naming) that the users nows about these facts. The safe way to access these fields it to stop the RTS via RTS API. - - - - - 9ed2a47e by Sven Tennie at 2020-08-28T08:23:39+02:00 Check pointers with pattern matching (#18405) This is nicer than to check the length of the pointer's list and index on it. - - - - - 3c805925 by Sven Tennie at 2020-08-28T08:23:39+02:00 Remove unsave function (#18405) heap_view_closurePtrsAsWords is currently only used by ghc-debug, so it can be defined there. - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/linters/check-cpp.py - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/Types.hs - compiler/GHC/Cmm.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/CmmToAsm.hs - compiler/GHC/CmmToAsm/BlockLayout.hs - compiler/GHC/CmmToAsm/CFG.hs - + compiler/GHC/CmmToAsm/CFG/Weight.hs - compiler/GHC/CmmToAsm/Config.hs - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/Instr.hs - compiler/GHC/CmmToAsm/Monad.hs - compiler/GHC/CmmToAsm/PIC.hs - + compiler/GHC/CmmToAsm/PPC.hs - compiler/GHC/CmmToAsm/PPC/CodeGen.hs - compiler/GHC/CmmToAsm/PPC/Instr.hs - compiler/GHC/CmmToAsm/PPC/Ppr.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/335cd21124f7c3ace718b16ab046b20a077ad44f...3c805925c1d9345ae1ed7a7a7db00294a5685ed4 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/335cd21124f7c3ace718b16ab046b20a077ad44f...3c805925c1d9345ae1ed7a7a7db00294a5685ed4 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 28 07:44:55 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Fri, 28 Aug 2020 03:44:55 -0400 Subject: [Git][ghc/ghc][wip/T18603] wibbles Message-ID: <5f48b5f75eeb5_80bd39f5a0970582c@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18603 at Glasgow Haskell Compiler / GHC Commits: 91d15840 by Simon Peyton Jones at 2020-08-28T00:30:33+01:00 wibbles - - - - - 2 changed files: - compiler/GHC/Core/FVs.hs - compiler/GHC/Core/Opt/OccurAnal.hs Changes: ===================================== compiler/GHC/Core/FVs.hs ===================================== @@ -10,16 +10,12 @@ Taken quite directly from the Peyton Jones/Lester paper. -- | A module concerned with finding the free variables of an expression. module GHC.Core.FVs ( -- * Free variables of expressions and binding groups - exprFreeVars, + exprFreeVars, exprsFreeVars, exprFreeVarsDSet, - exprFreeVarsList, - exprFreeIds, - exprFreeIdsDSet, - exprFreeIdsList, - exprsFreeIdsDSet, - exprsFreeIdsList, - exprsFreeVars, - exprsFreeVarsList, + exprFreeVarsList, exprsFreeVarsList, + exprFreeIds, exprsFreeIds, + exprFreeIdsDSet, exprsFreeIdsDSet, + exprFreeIdsList, exprsFreeIdsList, bindFreeVars, -- * Selective free variables of expressions @@ -126,6 +122,9 @@ exprFreeVarsList = fvVarList . exprFVs exprFreeIds :: CoreExpr -> IdSet -- Find all locally-defined free Ids exprFreeIds = exprSomeFreeVars isLocalId +exprsFreeIds :: [CoreExpr] -> IdSet -- Find all locally-defined free Ids +exprsFreeIds = exprsSomeFreeVars isLocalId + -- | Find all locally-defined free Ids in an expression -- returning a deterministic set. exprFreeIdsDSet :: CoreExpr -> DIdSet -- Find all locally-defined free Ids ===================================== compiler/GHC/Core/Opt/OccurAnal.hs ===================================== @@ -64,7 +64,7 @@ Here's the externally-callable interface: occurAnalysePgm :: Module -- Used only in debug output -> (Id -> Bool) -- Active unfoldings -> (Activation -> Bool) -- Active rules - -> [CoreRule] + -> [CoreRule] -- Local rules for imported Ids -> CoreProgram -> CoreProgram occurAnalysePgm this_mod active_unf active_rule imp_rules binds | isEmptyDetails final_usage @@ -96,20 +96,20 @@ occurAnalysePgm this_mod active_unf active_rule imp_rules binds -- The RULES declarations keep things alive! -- imp_rule_edges maps a top-level local binder 'f' to the - -- RHS free vars of any local RULES for an imported function, + -- RHS free vars of any active local RULES for an imported function, -- where 'f' appears on the LHS -- e.g. RULE foldr f = blah -- imp_rule_edges contains f :-> fvs(blah) -- See Note [Preventing loops due to imported functions rules] imp_rule_edges :: ImpRuleEdges imp_rule_edges = foldr (plusVarEnv_C unionVarSet) emptyVarEnv - [ mapVarEnv (const maps_to) $ - getUniqSet (exprFreeIds arg `delVarSetList` ru_bndrs imp_rule) - | imp_rule <- imp_rules - , not (isBuiltinRule imp_rule) -- See Note [Plugin rules] - , let maps_to = exprFreeIds (ru_rhs imp_rule) - `delVarSetList` ru_bndrs imp_rule - , arg <- ru_args imp_rule ] + [ mapVarEnv (const rhs_fvs) $ getUniqSet $ + exprsFreeIds args `delVarSetList` bndrs + | Rule { ru_act = act, ru_bndrs = bndrs + , ru_args = args, ru_rhs = rhs } <- imp_rules + -- Not BuiltinRules; see Note [Plugin rules] + , active_rule act -- Only active rules + , let rhs_fvs = exprFreeIds rhs `delVarSetList` bndrs ] go :: OccEnv -> [CoreBind] -> (UsageDetails, [CoreBind]) go _ [] @@ -260,13 +260,11 @@ always in scope. (because it isn't referenced any more), then the children will die too (unless they are already referenced directly). - To that end, we build a Rec group for each cyclic strongly - connected component, - *treating f's rules as extra RHSs for 'f'*. More concretely, the SCC analysis runs on a graph with an edge from f -> g iff g is mentioned in - (a) f's rhs - (b) f's RULES + (a) f's RHS + (b) The LHS or RHS of all of f's RULES, active or inactive + (i.e. regardless of phase) These are rec_edges. Under (b) we include variables free in *either* LHS *or* RHS of @@ -275,6 +273,9 @@ always in scope. will be put in the same Rec, even though their 'main' RHSs are both non-recursive. + We must also include inactive rules, so that their free vars + remain in scope. + * Note [Rule dependency info] ~~~~~~~~~~~~~~~~~~~~~~~~~~~ The VarSet in a RuleInfo is used for dependency analysis in the @@ -819,45 +820,45 @@ occAnalNonRecBind env lvl imp_rule_edges bndr rhs body_usage = (body_usage, []) | otherwise -- It's mentioned in the body - = (body_usage' `andUDs` rhs_usage4, [NonRec final_bndr rhs']) + = (body_usage' `andUDs` rhs_usage, [NonRec final_bndr rhs']) where (body_usage', tagged_bndr) = tagNonRecBinder lvl body_usage bndr final_bndr = tagged_bndr `setIdUnfolding` unf' `setIdSpecialisation` mkRuleInfo rules' - inl_fvs = inlineFreeVars unf unf_usage rhs_usage1 + rhs_usage = rhs_uds `andUDs` unf_uds `andUDs` rule_uds -- Get the join info from the *new* decision -- See Note [Join points and unfoldings/rules] mb_join_arity = willBeJoinId_maybe tagged_bndr is_join_point = isJust mb_join_arity - + --------- Right hand side --------- env1 | is_join_point = env -- See Note [Join point RHSs] | certainly_inline = env -- See Note [Cascading inlines] | otherwise = rhsCtxt env -- See Note [Sources of one-shot information] rhs_env = env1 { occ_one_shots = argOneShots dmd } + (rhs_uds, rhs') = occAnalRhs rhs_env NonRecursive mb_join_arity rhs - (rhs_usage1, rhs') = occAnalRhs rhs_env mb_join_arity rhs - - -- Unfoldings + --------- Unfolding --------- -- See Note [Unfoldings and join points] unf = idUnfolding bndr - (unf_usage, unf') = occAnalUnfolding rhs_env mb_join_arity unf - rhs_usage2 = rhs_usage1 `andUDs` unf_usage + (unf_uds, unf') = occAnalUnfolding rhs_env NonRecursive mb_join_arity unf - -- Rules + --------- Rules --------- -- See Note [Rules are extra RHSs] and Note [Rule dependency info] rules_w_uds = occAnalRules rhs_env mb_join_arity bndr - rule_uds = map (\(_, l, r) -> l `andUDs` r) rules_w_uds rules' = map fstOf3 rules_w_uds - rhs_usage3 = foldr andUDs rhs_usage2 rule_uds - rhs_usage4 = case lookupVarEnv imp_rule_edges bndr of - Nothing -> rhs_usage3 - Just vs -> addManyOccs rhs_usage3 vs + imp_rule_uds = case lookupVarEnv imp_rule_edges bndr of + Nothing -> emptyDetails + Just vs -> addManyOccs emptyDetails vs -- See Note [Preventing loops due to imported functions rules] + rule_uds = foldr add_rule_uds imp_rule_uds rules_w_uds + add_rule_uds (_, l, r) uds = l `andUDs` r `andUDs` uds + + ---------- occ = idOccInfo tagged_bndr certainly_inline -- See Note [Cascading inlines] = case occ of @@ -869,16 +870,6 @@ occAnalNonRecBind env lvl imp_rule_edges bndr rhs body_usage active = isAlwaysActive (idInlineActivation bndr) not_stable = not (isStableUnfolding (idUnfolding bndr)) -setNonRecLoopBreaker :: TopLevelFlag -> RuleFvEnv -> VarSet -> Id -> Id --- See Note [Non-recursive loop breakers] -setNonRecLoopBreaker lvl rule_fv_env inl_fvs bndr - | isTopLevel lvl -- Only relevant for top-level binders - -- since nested binders are never in rng(rule_fv_env) - , rule_loop = mk_loop_breaker bndr - | otherwise = bndr - where - rule_loop = bndr `elemVarSet` extendFvs_ rule_fv_env inl_fvs - ----------------- occAnalRecBind :: OccEnv -> TopLevelFlag -> ImpRuleEdges -> [(Var,CoreExpr)] -> UsageDetails -> (UsageDetails, [CoreBind]) @@ -904,15 +895,13 @@ occAnalRecBind env lvl imp_rule_edges pairs body_usage rule_fv_env :: RuleFvEnv -- Maps a variable f to the variables from this group - -- mentioned in RHS of active rules for f + -- mentioned in RHS of /active/ rules for f -- Domain is *subset* of bound vars (others have no rule fvs) - rule_fv_env = transClosureFV (mkVarEnv init_rule_fvs) - init_rule_fvs -- See Note [Finding rule RHS free vars] - = [ (b, trimmed_rule_fvs) - | (node_payload -> ND { nd_bndr = b - , nd_active_rule_fvs = rule_fvs }) <- nodes - , let trimmed_rule_fvs = rule_fvs `intersectVarSet` bndr_set - , not (isEmptyVarSet trimmed_rule_fvs) ] + rule_fv_env -- See Note [Finding rule RHS free vars] + = mkVarEnv [ (b, rule_fvs) + | (node_payload -> ND { nd_bndr = b + , nd_active_rule_fvs = rule_fvs }) <- nodes + , not (isEmptyVarSet rule_fvs) ] {- @@ -944,7 +933,7 @@ occAnalRec _ lvl rule_fv_env where (body_uds', tagged_bndr) = tagNonRecBinder lvl body_uds bndr final_bndr = setNonRecLoopBreaker lvl rule_fv_env inl_fvs tagged_bndr - rhs_uds' = adjustRhsUsage (willBeJoinId_maybe tagged_bndr) NonRecursive + rhs_uds' = adjustRhsUsage NonRecursive (willBeJoinId_maybe tagged_bndr) rhs_bndrs rhs_uds -- The Rec case is the interesting one @@ -993,6 +982,16 @@ occAnalRec env lvl rule_fv_env -- Loop breaking ------------------------------------------------------------------ +setNonRecLoopBreaker :: TopLevelFlag -> RuleFvEnv -> VarSet -> Id -> Id +-- See Note [Non-recursive loop breakers] +setNonRecLoopBreaker lvl rule_fv_env inl_fvs bndr + | isTopLevel lvl -- Only relevant for top-level binders + -- since nested binders are never in rng(rule_fv_env) + , rule_loop = mk_loop_breaker bndr + | otherwise = bndr + where + rule_loop = bndr `elemVarSet` extendFvs_ rule_fv_env inl_fvs + type Binding = (Id,CoreExpr) loopBreakNodes :: Int @@ -1243,9 +1242,6 @@ type ImpRuleEdges = RuleFvEnv -- Mapping from a local Id 'f' to the free vars of the RHS of -- local rules for an imported Id that mention 'f' on the LHS -lookupRuleFvEnv :: RuleFvEnv -> Id -> IdSet -lookupRuleFvEnv env id = lookupVarEnv env id `orElse` emptyVarSet - noImpRuleEdges :: ImpRuleEdges noImpRuleEdges = emptyVarEnv @@ -1317,15 +1313,20 @@ makeNode env imp_rule_edges bndr_set (bndr, rhs) details = ND { nd_bndr = bndr' , nd_rhs = rhs' , nd_rhs_bndrs = bndrs' - , nd_uds = rhs_usage3 + , nd_uds = rhs_usage , nd_inl = inl_fvs , nd_weak = node_fvs `minusVarSet` inl_fvs - , nd_active_rule_fvs = active_rule_fvs + , nd_active_rule_fvs = active_rule_fvs `intersectVarSet` bndr_set , nd_score = pprPanic "makeNodeDetails" (ppr bndr) } bndr' = bndr `setIdUnfolding` unf' `setIdSpecialisation` mkRuleInfo rules' + rhs_usage = rhs_uds `andUDs` unf_uds `andUDs` rule_uds + -- Note [Rules are extra RHSs] + -- Note [Rule dependency info] + node_fvs = udFreeVars bndr_set rhs_usage + -- Get join point info from the *current* decision -- We don't know what the new decision will be! -- Using the old decision at least allows us to @@ -1333,42 +1334,43 @@ makeNode env imp_rule_edges bndr_set (bndr, rhs) -- See Note [Join points and unfoldings/rules] mb_join_arity = isJoinId_maybe bndr + --------- Right hand side --------- -- Constructing the edges for the main Rec computation -- See Note [Forming Rec groups] - (bndrs, body) = collectBinders rhs - rhs_env = rhsCtxt env - (rhs_usage1, bndrs', body') = occAnalLamOrRhs rhs_env bndrs body - rhs' = mkLams bndrs' body' - rhs_usage3 = foldr andUDs rhs_usage1 rule_uds - `andUDs` unf_uds - -- Note [Rules are extra RHSs] - -- Note [Rule dependency info] - node_fvs = udFreeVars bndr_set rhs_usage3 - - -- Finding the free variables of the rules - is_active = occ_rule_act env :: Activation -> Bool + -- Do not use occAnalRhs because we don't yet know + -- the final answer for mb_join_arity + (bndrs, body) = collectBinders rhs + rhs_env = rhsCtxt env + (rhs_uds, bndrs', body') = occAnalLamOrRhs rhs_env bndrs body + rhs' = mkLams bndrs' body' + + --------- Unfolding --------- + -- See Note [Unfoldings and join points] + unf = realIdUnfolding bndr -- realIdUnfolding: Ignore loop-breaker-ness + -- here because that is what we are setting! + (unf_uds, unf') = occAnalUnfolding rhs_env Recursive mb_join_arity unf + inl_fvs = restrictFreeVars bndr_set (inlineFreeVars unf unf_uds rhs_uds) + --------- Rules --------- rules_w_uds :: [(CoreRule, UsageDetails, UsageDetails)] rules_w_uds = occAnalRules rhs_env mb_join_arity bndr + rules' = map fstOf3 rules_w_uds - rules' = map fstOf3 rules_w_uds - - rules_w_rhs_fvs :: [(Activation, VarSet)] -- Find the RHS fvs - rules_w_rhs_fvs = maybe id (\ids -> ((AlwaysActive, ids):)) - (lookupVarEnv imp_rule_edges bndr) - -- See Note [Preventing loops due to imported functions rules] - [ (ru_act rule, udFreeVars bndr_set rhs_uds) - | (rule, _, rhs_uds) <- rules_w_uds ] - rule_uds = map (\(_, l, r) -> l `andUDs` r) rules_w_uds - active_rule_fvs = unionVarSets [fvs | (a,fvs) <- rules_w_rhs_fvs - , is_active a] + rule_uds = foldr add_rule_uds imp_rule_uds rules_w_uds + add_rule_uds (_, l, r) uds = l `andUDs` r `andUDs` uds + imp_rule_uds = case lookupVarEnv imp_rule_edges bndr of + Nothing -> emptyDetails + Just vs -> addManyOccs emptyDetails vs - -- Finding the usage details of the INLINE pragma (if any) - unf = realIdUnfolding bndr -- realIdUnfolding: Ignore loop-breaker-ness - -- here because that is what we are setting! - (unf_uds, unf') = occAnalUnfolding rhs_env mb_join_arity unf - inl_fvs = restrictFreeVars bndr_set (inlineFreeVars unf unf_uds rhs_usage1) + is_active = occ_rule_act env :: Activation -> Bool + imp_rule_fvs = udFreeVars bndr_set imp_rule_uds + active_rule_fvs = foldr add_active_rule imp_rule_fvs rules_w_uds + add_active_rule (rule, _, rhs_uds) fvs + | is_active (ruleActivation rule) + = udFreeVars bndr_set rhs_uds `unionVarSet` fvs + | otherwise + = fvs inlineFreeVars :: Unfolding -> UsageDetails -- Of the unfolding @@ -1632,29 +1634,31 @@ Hence the is_lb field of NodeScore ************************************************************************ -} -occAnalRhs :: OccEnv -> Maybe JoinArity +occAnalRhs :: OccEnv -> RecFlag -> Maybe JoinArity -> CoreExpr -- RHS -> (UsageDetails, CoreExpr) -occAnalRhs env mb_join_arity rhs +occAnalRhs env is_rec mb_join_arity rhs = case occAnalLamOrRhs env bndrs body of { (body_usage, bndrs', body') -> - let rhs' = mkLams (markJoinOneShots mb_join_arity bndrs') body' + let final_bndrs | isRec is_rec = bndrs' + | otherwise = markJoinOneShots mb_join_arity bndrs' -- For a /non-recursive/ join point we can mark all -- its join-lambda as one-shot; and it's a good idea to do so -- Final adjustment - rhs_usage = adjustRhsUsage mb_join_arity NonRecursive bndrs' body_usage + rhs_usage = adjustRhsUsage is_rec mb_join_arity final_bndrs body_usage - in (rhs_usage, rhs') } + in (rhs_usage, mkLams final_bndrs body') } where (bndrs, body) = collectBinders rhs occAnalUnfolding :: OccEnv + -> RecFlag -> Maybe JoinArity -- See Note [Join points and unfoldings/rules] -> Unfolding -> (UsageDetails, Unfolding) -- Occurrence-analyse a stable unfolding; -- discard a non-stable one altogether. -occAnalUnfolding env mb_join_arity unf +occAnalUnfolding env is_rec mb_join_arity unf = case unf of unf@(CoreUnfolding { uf_tmpl = rhs, uf_src = src }) | isStableSource src -> (usage, unf') @@ -1665,7 +1669,7 @@ occAnalUnfolding env mb_join_arity unf -- to guide its decisions. It's ok to leave un-substituted -- expressions in the tree because all the variables that were in -- scope remain in scope; there is no cloning etc. - (usage, rhs') = occAnalRhs env mb_join_arity rhs + (usage, rhs') = occAnalRhs env is_rec mb_join_arity rhs unf' | noBinderSwaps env = unf -- Note [Unfoldings and rules] | otherwise = unf { uf_tmpl = rhs' } @@ -1962,7 +1966,7 @@ occAnalApp env (Var fun, args, ticks) -- This caused #18296 | fun `hasKey` runRWKey , [t1, t2, arg] <- args - , let (usage, arg') = occAnalRhs env (Just 1) arg + , let (usage, arg') = occAnalRhs env NonRecursive (Just 1) arg = (usage, mkTicks ticks $ mkApps (Var fun) [t1, t2, arg']) occAnalApp env (Var fun, args, ticks) @@ -2298,6 +2302,7 @@ addAppCtxt :: OccEnv -> [Arg CoreBndr] -> OccEnv addAppCtxt env@(OccEnv { occ_one_shots = ctxt }) args = env { occ_one_shots = replicate (valArgCount args) OneShotLam ++ ctxt } +{- transClosureFV :: VarEnv VarSet -> VarEnv VarSet -- If (f,g), (g,h) are in the input, then (f,h) is in the output -- as well as (f,g), (g,h) @@ -2313,7 +2318,7 @@ transClosureFV env | otherwise = (False, (b,new_fvs)) where (new_fvs, no_change_here) = extendFvs env fvs - +-} ------------- extendFvs_ :: VarEnv VarSet -> VarSet -> VarSet extendFvs_ env s = fst (extendFvs env s) -- Discard the Bool flag @@ -2780,20 +2785,20 @@ flattenUsageDetails ud ------------------- -- See Note [Adjusting right-hand sides] -adjustRhsUsage :: Maybe JoinArity -> RecFlag +adjustRhsUsage :: RecFlag -> Maybe JoinArity -> [CoreBndr] -- Outer lambdas, AFTER occ anal -> UsageDetails -- From body of lambda -> UsageDetails -adjustRhsUsage mb_join_arity rec_flag bndrs usage - = markAllInsideLamIf (not one_shot) $ +adjustRhsUsage is_rec mb_join_arity bndrs usage + = markAllInsideLamIf (not one_shot) $ markAllNonTailIf (not exact_join) $ usage where one_shot = case mb_join_arity of Just join_arity - | isRec rec_flag -> False - | otherwise -> all isOneShotBndr (drop join_arity bndrs) - Nothing -> all isOneShotBndr bndrs + | isRec is_rec -> False + | otherwise -> all isOneShotBndr (drop join_arity bndrs) + Nothing -> all isOneShotBndr bndrs exact_join = exactJoin mb_join_arity bndrs @@ -2874,7 +2879,7 @@ tagRecBinders lvl body_uds triples -- join-point-hood decision rhs_udss' = map adjust triples adjust (bndr, rhs_uds, rhs_bndrs) - = adjustRhsUsage mb_join_arity Recursive rhs_bndrs rhs_uds + = adjustRhsUsage Recursive mb_join_arity rhs_bndrs rhs_uds where -- Can't use willBeJoinId_maybe here because we haven't tagged the -- binder yet (the tag depends on these adjustments!) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/91d15840d7c4a7bf26d70b45ecad70d6fb940eaa -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/91d15840d7c4a7bf26d70b45ecad70d6fb940eaa You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 28 07:50:02 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Fri, 28 Aug 2020 03:50:02 -0400 Subject: [Git][ghc/ghc][wip/T18603] wibbles Message-ID: <5f48b72a32ebd_80b3f8496348e889707620@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18603 at Glasgow Haskell Compiler / GHC Commits: aad0497e by Simon Peyton Jones at 2020-08-28T08:49:29+01:00 wibbles - - - - - 2 changed files: - compiler/GHC/Core/FVs.hs - compiler/GHC/Core/Opt/OccurAnal.hs Changes: ===================================== compiler/GHC/Core/FVs.hs ===================================== @@ -10,16 +10,12 @@ Taken quite directly from the Peyton Jones/Lester paper. -- | A module concerned with finding the free variables of an expression. module GHC.Core.FVs ( -- * Free variables of expressions and binding groups - exprFreeVars, + exprFreeVars, exprsFreeVars, exprFreeVarsDSet, - exprFreeVarsList, - exprFreeIds, - exprFreeIdsDSet, - exprFreeIdsList, - exprsFreeIdsDSet, - exprsFreeIdsList, - exprsFreeVars, - exprsFreeVarsList, + exprFreeVarsList, exprsFreeVarsList, + exprFreeIds, exprsFreeIds, + exprFreeIdsDSet, exprsFreeIdsDSet, + exprFreeIdsList, exprsFreeIdsList, bindFreeVars, -- * Selective free variables of expressions @@ -126,6 +122,9 @@ exprFreeVarsList = fvVarList . exprFVs exprFreeIds :: CoreExpr -> IdSet -- Find all locally-defined free Ids exprFreeIds = exprSomeFreeVars isLocalId +exprsFreeIds :: [CoreExpr] -> IdSet -- Find all locally-defined free Ids +exprsFreeIds = exprsSomeFreeVars isLocalId + -- | Find all locally-defined free Ids in an expression -- returning a deterministic set. exprFreeIdsDSet :: CoreExpr -> DIdSet -- Find all locally-defined free Ids ===================================== compiler/GHC/Core/Opt/OccurAnal.hs ===================================== @@ -64,7 +64,7 @@ Here's the externally-callable interface: occurAnalysePgm :: Module -- Used only in debug output -> (Id -> Bool) -- Active unfoldings -> (Activation -> Bool) -- Active rules - -> [CoreRule] + -> [CoreRule] -- Local rules for imported Ids -> CoreProgram -> CoreProgram occurAnalysePgm this_mod active_unf active_rule imp_rules binds | isEmptyDetails final_usage @@ -96,20 +96,20 @@ occurAnalysePgm this_mod active_unf active_rule imp_rules binds -- The RULES declarations keep things alive! -- imp_rule_edges maps a top-level local binder 'f' to the - -- RHS free vars of any local RULES for an imported function, + -- RHS free vars of any active local RULES for an imported function, -- where 'f' appears on the LHS -- e.g. RULE foldr f = blah -- imp_rule_edges contains f :-> fvs(blah) -- See Note [Preventing loops due to imported functions rules] imp_rule_edges :: ImpRuleEdges imp_rule_edges = foldr (plusVarEnv_C unionVarSet) emptyVarEnv - [ mapVarEnv (const maps_to) $ - getUniqSet (exprFreeIds arg `delVarSetList` ru_bndrs imp_rule) - | imp_rule <- imp_rules - , not (isBuiltinRule imp_rule) -- See Note [Plugin rules] - , let maps_to = exprFreeIds (ru_rhs imp_rule) - `delVarSetList` ru_bndrs imp_rule - , arg <- ru_args imp_rule ] + [ mapVarEnv (const rhs_fvs) $ getUniqSet $ + exprsFreeIds args `delVarSetList` bndrs + | Rule { ru_act = act, ru_bndrs = bndrs + , ru_args = args, ru_rhs = rhs } <- imp_rules + -- Not BuiltinRules; see Note [Plugin rules] + , active_rule act -- Only active rules + , let rhs_fvs = exprFreeIds rhs `delVarSetList` bndrs ] go :: OccEnv -> [CoreBind] -> (UsageDetails, [CoreBind]) go _ [] @@ -208,7 +208,7 @@ Really, we want 'f' to be a loop breaker, even though it's non-recursive. When analysing "g = ...", occAnalNonRecBind will produce a usage of 'f' see Note [Preventing loops due to imported functions rules]. So we'll -do glomming +do glomming Note [Dead code] ~~~~~~~~~~~~~~~~ @@ -260,13 +260,11 @@ always in scope. (because it isn't referenced any more), then the children will die too (unless they are already referenced directly). - To that end, we build a Rec group for each cyclic strongly - connected component, - *treating f's rules as extra RHSs for 'f'*. More concretely, the SCC analysis runs on a graph with an edge from f -> g iff g is mentioned in - (a) f's rhs - (b) f's RULES + (a) f's RHS + (b) The LHS or RHS of all of f's RULES, active or inactive + (i.e. regardless of phase) These are rec_edges. Under (b) we include variables free in *either* LHS *or* RHS of @@ -275,6 +273,9 @@ always in scope. will be put in the same Rec, even though their 'main' RHSs are both non-recursive. + We must also include inactive rules, so that their free vars + remain in scope. + * Note [Rule dependency info] ~~~~~~~~~~~~~~~~~~~~~~~~~~~ The VarSet in a RuleInfo is used for dependency analysis in the @@ -819,45 +820,45 @@ occAnalNonRecBind env lvl imp_rule_edges bndr rhs body_usage = (body_usage, []) | otherwise -- It's mentioned in the body - = (body_usage' `andUDs` rhs_usage4, [NonRec final_bndr rhs']) + = (body_usage' `andUDs` rhs_usage, [NonRec final_bndr rhs']) where (body_usage', tagged_bndr) = tagNonRecBinder lvl body_usage bndr final_bndr = tagged_bndr `setIdUnfolding` unf' `setIdSpecialisation` mkRuleInfo rules' - inl_fvs = inlineFreeVars unf unf_usage rhs_usage1 + rhs_usage = rhs_uds `andUDs` unf_uds `andUDs` rule_uds -- Get the join info from the *new* decision -- See Note [Join points and unfoldings/rules] mb_join_arity = willBeJoinId_maybe tagged_bndr is_join_point = isJust mb_join_arity - + --------- Right hand side --------- env1 | is_join_point = env -- See Note [Join point RHSs] | certainly_inline = env -- See Note [Cascading inlines] | otherwise = rhsCtxt env -- See Note [Sources of one-shot information] rhs_env = env1 { occ_one_shots = argOneShots dmd } + (rhs_uds, rhs') = occAnalRhs rhs_env NonRecursive mb_join_arity rhs - (rhs_usage1, rhs') = occAnalRhs rhs_env mb_join_arity rhs - - -- Unfoldings + --------- Unfolding --------- -- See Note [Unfoldings and join points] unf = idUnfolding bndr - (unf_usage, unf') = occAnalUnfolding rhs_env mb_join_arity unf - rhs_usage2 = rhs_usage1 `andUDs` unf_usage + (unf_uds, unf') = occAnalUnfolding rhs_env NonRecursive mb_join_arity unf - -- Rules + --------- Rules --------- -- See Note [Rules are extra RHSs] and Note [Rule dependency info] rules_w_uds = occAnalRules rhs_env mb_join_arity bndr - rule_uds = map (\(_, l, r) -> l `andUDs` r) rules_w_uds rules' = map fstOf3 rules_w_uds - rhs_usage3 = foldr andUDs rhs_usage2 rule_uds - rhs_usage4 = case lookupVarEnv imp_rule_edges bndr of - Nothing -> rhs_usage3 - Just vs -> addManyOccs rhs_usage3 vs + imp_rule_uds = case lookupVarEnv imp_rule_edges bndr of + Nothing -> emptyDetails + Just vs -> addManyOccs emptyDetails vs -- See Note [Preventing loops due to imported functions rules] + rule_uds = foldr add_rule_uds imp_rule_uds rules_w_uds + add_rule_uds (_, l, r) uds = l `andUDs` r `andUDs` uds + + ---------- occ = idOccInfo tagged_bndr certainly_inline -- See Note [Cascading inlines] = case occ of @@ -869,16 +870,6 @@ occAnalNonRecBind env lvl imp_rule_edges bndr rhs body_usage active = isAlwaysActive (idInlineActivation bndr) not_stable = not (isStableUnfolding (idUnfolding bndr)) -setNonRecLoopBreaker :: TopLevelFlag -> RuleFvEnv -> VarSet -> Id -> Id --- See Note [Non-recursive loop breakers] -setNonRecLoopBreaker lvl rule_fv_env inl_fvs bndr - | isTopLevel lvl -- Only relevant for top-level binders - -- since nested binders are never in rng(rule_fv_env) - , rule_loop = mk_loop_breaker bndr - | otherwise = bndr - where - rule_loop = bndr `elemVarSet` extendFvs_ rule_fv_env inl_fvs - ----------------- occAnalRecBind :: OccEnv -> TopLevelFlag -> ImpRuleEdges -> [(Var,CoreExpr)] -> UsageDetails -> (UsageDetails, [CoreBind]) @@ -904,15 +895,13 @@ occAnalRecBind env lvl imp_rule_edges pairs body_usage rule_fv_env :: RuleFvEnv -- Maps a variable f to the variables from this group - -- mentioned in RHS of active rules for f + -- mentioned in RHS of /active/ rules for f -- Domain is *subset* of bound vars (others have no rule fvs) - rule_fv_env = transClosureFV (mkVarEnv init_rule_fvs) - init_rule_fvs -- See Note [Finding rule RHS free vars] - = [ (b, trimmed_rule_fvs) - | (node_payload -> ND { nd_bndr = b - , nd_active_rule_fvs = rule_fvs }) <- nodes - , let trimmed_rule_fvs = rule_fvs `intersectVarSet` bndr_set - , not (isEmptyVarSet trimmed_rule_fvs) ] + rule_fv_env -- See Note [Finding rule RHS free vars] + = mkVarEnv [ (b, rule_fvs) + | (node_payload -> ND { nd_bndr = b + , nd_active_rule_fvs = rule_fvs }) <- nodes + , not (isEmptyVarSet rule_fvs) ] {- @@ -944,7 +933,7 @@ occAnalRec _ lvl rule_fv_env where (body_uds', tagged_bndr) = tagNonRecBinder lvl body_uds bndr final_bndr = setNonRecLoopBreaker lvl rule_fv_env inl_fvs tagged_bndr - rhs_uds' = adjustRhsUsage (willBeJoinId_maybe tagged_bndr) NonRecursive + rhs_uds' = adjustRhsUsage NonRecursive (willBeJoinId_maybe tagged_bndr) rhs_bndrs rhs_uds -- The Rec case is the interesting one @@ -993,6 +982,16 @@ occAnalRec env lvl rule_fv_env -- Loop breaking ------------------------------------------------------------------ +setNonRecLoopBreaker :: TopLevelFlag -> RuleFvEnv -> VarSet -> Id -> Id +-- See Note [Non-recursive loop breakers] +setNonRecLoopBreaker lvl rule_fv_env inl_fvs bndr + | isTopLevel lvl -- Only relevant for top-level binders + -- since nested binders are never in rng(rule_fv_env) + , rule_loop = mk_loop_breaker bndr + | otherwise = bndr + where + rule_loop = bndr `elemVarSet` extendFvs_ rule_fv_env inl_fvs + type Binding = (Id,CoreExpr) loopBreakNodes :: Int @@ -1243,9 +1242,6 @@ type ImpRuleEdges = RuleFvEnv -- Mapping from a local Id 'f' to the free vars of the RHS of -- local rules for an imported Id that mention 'f' on the LHS -lookupRuleFvEnv :: RuleFvEnv -> Id -> IdSet -lookupRuleFvEnv env id = lookupVarEnv env id `orElse` emptyVarSet - noImpRuleEdges :: ImpRuleEdges noImpRuleEdges = emptyVarEnv @@ -1317,15 +1313,20 @@ makeNode env imp_rule_edges bndr_set (bndr, rhs) details = ND { nd_bndr = bndr' , nd_rhs = rhs' , nd_rhs_bndrs = bndrs' - , nd_uds = rhs_usage3 + , nd_uds = rhs_usage , nd_inl = inl_fvs , nd_weak = node_fvs `minusVarSet` inl_fvs - , nd_active_rule_fvs = active_rule_fvs + , nd_active_rule_fvs = active_rule_fvs `intersectVarSet` bndr_set , nd_score = pprPanic "makeNodeDetails" (ppr bndr) } bndr' = bndr `setIdUnfolding` unf' `setIdSpecialisation` mkRuleInfo rules' + rhs_usage = rhs_uds `andUDs` unf_uds `andUDs` rule_uds + -- Note [Rules are extra RHSs] + -- Note [Rule dependency info] + node_fvs = udFreeVars bndr_set rhs_usage + -- Get join point info from the *current* decision -- We don't know what the new decision will be! -- Using the old decision at least allows us to @@ -1333,42 +1334,43 @@ makeNode env imp_rule_edges bndr_set (bndr, rhs) -- See Note [Join points and unfoldings/rules] mb_join_arity = isJoinId_maybe bndr + --------- Right hand side --------- -- Constructing the edges for the main Rec computation -- See Note [Forming Rec groups] - (bndrs, body) = collectBinders rhs - rhs_env = rhsCtxt env - (rhs_usage1, bndrs', body') = occAnalLamOrRhs rhs_env bndrs body - rhs' = mkLams bndrs' body' - rhs_usage3 = foldr andUDs rhs_usage1 rule_uds - `andUDs` unf_uds - -- Note [Rules are extra RHSs] - -- Note [Rule dependency info] - node_fvs = udFreeVars bndr_set rhs_usage3 - - -- Finding the free variables of the rules - is_active = occ_rule_act env :: Activation -> Bool + -- Do not use occAnalRhs because we don't yet know + -- the final answer for mb_join_arity + (bndrs, body) = collectBinders rhs + rhs_env = rhsCtxt env + (rhs_uds, bndrs', body') = occAnalLamOrRhs rhs_env bndrs body + rhs' = mkLams bndrs' body' + + --------- Unfolding --------- + -- See Note [Unfoldings and join points] + unf = realIdUnfolding bndr -- realIdUnfolding: Ignore loop-breaker-ness + -- here because that is what we are setting! + (unf_uds, unf') = occAnalUnfolding rhs_env Recursive mb_join_arity unf + inl_fvs = restrictFreeVars bndr_set (inlineFreeVars unf unf_uds rhs_uds) + --------- Rules --------- rules_w_uds :: [(CoreRule, UsageDetails, UsageDetails)] rules_w_uds = occAnalRules rhs_env mb_join_arity bndr + rules' = map fstOf3 rules_w_uds - rules' = map fstOf3 rules_w_uds - - rules_w_rhs_fvs :: [(Activation, VarSet)] -- Find the RHS fvs - rules_w_rhs_fvs = maybe id (\ids -> ((AlwaysActive, ids):)) - (lookupVarEnv imp_rule_edges bndr) - -- See Note [Preventing loops due to imported functions rules] - [ (ru_act rule, udFreeVars bndr_set rhs_uds) - | (rule, _, rhs_uds) <- rules_w_uds ] - rule_uds = map (\(_, l, r) -> l `andUDs` r) rules_w_uds - active_rule_fvs = unionVarSets [fvs | (a,fvs) <- rules_w_rhs_fvs - , is_active a] + rule_uds = foldr add_rule_uds imp_rule_uds rules_w_uds + add_rule_uds (_, l, r) uds = l `andUDs` r `andUDs` uds + imp_rule_uds = case lookupVarEnv imp_rule_edges bndr of + Nothing -> emptyDetails + Just vs -> addManyOccs emptyDetails vs - -- Finding the usage details of the INLINE pragma (if any) - unf = realIdUnfolding bndr -- realIdUnfolding: Ignore loop-breaker-ness - -- here because that is what we are setting! - (unf_uds, unf') = occAnalUnfolding rhs_env mb_join_arity unf - inl_fvs = restrictFreeVars bndr_set (inlineFreeVars unf unf_uds rhs_usage1) + is_active = occ_rule_act env :: Activation -> Bool + imp_rule_fvs = udFreeVars bndr_set imp_rule_uds + active_rule_fvs = foldr add_active_rule imp_rule_fvs rules_w_uds + add_active_rule (rule, _, rhs_uds) fvs + | is_active (ruleActivation rule) + = udFreeVars bndr_set rhs_uds `unionVarSet` fvs + | otherwise + = fvs inlineFreeVars :: Unfolding -> UsageDetails -- Of the unfolding @@ -1632,29 +1634,31 @@ Hence the is_lb field of NodeScore ************************************************************************ -} -occAnalRhs :: OccEnv -> Maybe JoinArity +occAnalRhs :: OccEnv -> RecFlag -> Maybe JoinArity -> CoreExpr -- RHS -> (UsageDetails, CoreExpr) -occAnalRhs env mb_join_arity rhs +occAnalRhs env is_rec mb_join_arity rhs = case occAnalLamOrRhs env bndrs body of { (body_usage, bndrs', body') -> - let rhs' = mkLams (markJoinOneShots mb_join_arity bndrs') body' + let final_bndrs | isRec is_rec = bndrs' + | otherwise = markJoinOneShots mb_join_arity bndrs' -- For a /non-recursive/ join point we can mark all -- its join-lambda as one-shot; and it's a good idea to do so -- Final adjustment - rhs_usage = adjustRhsUsage mb_join_arity NonRecursive bndrs' body_usage + rhs_usage = adjustRhsUsage is_rec mb_join_arity final_bndrs body_usage - in (rhs_usage, rhs') } + in (rhs_usage, mkLams final_bndrs body') } where (bndrs, body) = collectBinders rhs occAnalUnfolding :: OccEnv + -> RecFlag -> Maybe JoinArity -- See Note [Join points and unfoldings/rules] -> Unfolding -> (UsageDetails, Unfolding) -- Occurrence-analyse a stable unfolding; -- discard a non-stable one altogether. -occAnalUnfolding env mb_join_arity unf +occAnalUnfolding env is_rec mb_join_arity unf = case unf of unf@(CoreUnfolding { uf_tmpl = rhs, uf_src = src }) | isStableSource src -> (usage, unf') @@ -1665,7 +1669,7 @@ occAnalUnfolding env mb_join_arity unf -- to guide its decisions. It's ok to leave un-substituted -- expressions in the tree because all the variables that were in -- scope remain in scope; there is no cloning etc. - (usage, rhs') = occAnalRhs env mb_join_arity rhs + (usage, rhs') = occAnalRhs env is_rec mb_join_arity rhs unf' | noBinderSwaps env = unf -- Note [Unfoldings and rules] | otherwise = unf { uf_tmpl = rhs' } @@ -1962,7 +1966,7 @@ occAnalApp env (Var fun, args, ticks) -- This caused #18296 | fun `hasKey` runRWKey , [t1, t2, arg] <- args - , let (usage, arg') = occAnalRhs env (Just 1) arg + , let (usage, arg') = occAnalRhs env NonRecursive (Just 1) arg = (usage, mkTicks ticks $ mkApps (Var fun) [t1, t2, arg']) occAnalApp env (Var fun, args, ticks) @@ -2298,6 +2302,7 @@ addAppCtxt :: OccEnv -> [Arg CoreBndr] -> OccEnv addAppCtxt env@(OccEnv { occ_one_shots = ctxt }) args = env { occ_one_shots = replicate (valArgCount args) OneShotLam ++ ctxt } +{- transClosureFV :: VarEnv VarSet -> VarEnv VarSet -- If (f,g), (g,h) are in the input, then (f,h) is in the output -- as well as (f,g), (g,h) @@ -2313,7 +2318,7 @@ transClosureFV env | otherwise = (False, (b,new_fvs)) where (new_fvs, no_change_here) = extendFvs env fvs - +-} ------------- extendFvs_ :: VarEnv VarSet -> VarSet -> VarSet extendFvs_ env s = fst (extendFvs env s) -- Discard the Bool flag @@ -2780,20 +2785,20 @@ flattenUsageDetails ud ------------------- -- See Note [Adjusting right-hand sides] -adjustRhsUsage :: Maybe JoinArity -> RecFlag +adjustRhsUsage :: RecFlag -> Maybe JoinArity -> [CoreBndr] -- Outer lambdas, AFTER occ anal -> UsageDetails -- From body of lambda -> UsageDetails -adjustRhsUsage mb_join_arity rec_flag bndrs usage - = markAllInsideLamIf (not one_shot) $ +adjustRhsUsage is_rec mb_join_arity bndrs usage + = markAllInsideLamIf (not one_shot) $ markAllNonTailIf (not exact_join) $ usage where one_shot = case mb_join_arity of Just join_arity - | isRec rec_flag -> False - | otherwise -> all isOneShotBndr (drop join_arity bndrs) - Nothing -> all isOneShotBndr bndrs + | isRec is_rec -> False + | otherwise -> all isOneShotBndr (drop join_arity bndrs) + Nothing -> all isOneShotBndr bndrs exact_join = exactJoin mb_join_arity bndrs @@ -2874,7 +2879,7 @@ tagRecBinders lvl body_uds triples -- join-point-hood decision rhs_udss' = map adjust triples adjust (bndr, rhs_uds, rhs_bndrs) - = adjustRhsUsage mb_join_arity Recursive rhs_bndrs rhs_uds + = adjustRhsUsage Recursive mb_join_arity rhs_bndrs rhs_uds where -- Can't use willBeJoinId_maybe here because we haven't tagged the -- binder yet (the tag depends on these adjustments!) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/aad0497e8754df189ff821e1f40cf569a176e408 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/aad0497e8754df189ff821e1f40cf569a176e408 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 28 09:13:06 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Fri, 28 Aug 2020 05:13:06 -0400 Subject: [Git][ghc/ghc][wip/T18603] Wibbles 2 Message-ID: <5f48caa2d8740_80b3f848652a2d497150d9@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18603 at Glasgow Haskell Compiler / GHC Commits: 8e332d66 by Simon Peyton Jones at 2020-08-28T10:12:32+01:00 Wibbles 2 - - - - - 1 changed file: - compiler/GHC/Core/Opt/OccurAnal.hs Changes: ===================================== compiler/GHC/Core/Opt/OccurAnal.hs ===================================== @@ -208,7 +208,6 @@ Really, we want 'f' to be a loop breaker, even though it's non-recursive. When analysing "g = ...", occAnalNonRecBind will produce a usage of 'f' see Note [Preventing loops due to imported functions rules]. So we'll -do glomming Note [Dead code] ~~~~~~~~~~~~~~~~ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8e332d669a6a53819f2eac0be16374f5a4fc26d2 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8e332d669a6a53819f2eac0be16374f5a4fc26d2 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 28 09:37:27 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Fri, 28 Aug 2020 05:37:27 -0400 Subject: [Git][ghc/ghc][wip/T18565] PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Message-ID: <5f48d057ace91_80b3f8486484488971697f@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18565 at Glasgow Haskell Compiler / GHC Commits: b5a6da4b by Sebastian Graf at 2020-08-28T11:37:15+02:00 PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Previously, we desugared and coverage checked plain guard trees as described in Lower Your Guards. That caused (in !3849) quite a bit of pain when we need to partially recover tree structure of the input syntax to return covered sets for long-distance information, for example. In this refactor, I introduced a guard tree variant for each relevant source syntax component of a pattern-match (mainly match groups, match, GRHS, empty case, pattern binding). I made sure to share as much coverage checking code as possible, so that the syntax-specific checking functions are just wrappers around the more substantial checking functions for the LYG primitives (`checkSequence`, `checkGrds`). The refactoring payed off in clearer code and elimination of all panics related to assumed guard tree structure and thus fixes #18565. I also took the liberty to rename and re-arrange the order of functions and comments in the module, deleted some dead and irrelevant Notes, wrote some new ones and gave an overview module haddock. - - - - - 14 changed files: - compiler/GHC/Data/OrdList.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - compiler/GHC/HsToCore/PmCheck/Types.hs - compiler/GHC/Tc/Types.hs - compiler/GHC/Utils/Misc.hs - testsuite/tests/deSugar/should_compile/ds020.stderr - testsuite/tests/module/all.T - testsuite/tests/pmcheck/should_compile/T18572.hs - testsuite/tests/rename/should_compile/T7085.stderr - testsuite/tests/unboxedsums/all.T Changes: ===================================== compiler/GHC/Data/OrdList.hs ===================================== @@ -5,13 +5,16 @@ -} {-# LANGUAGE DeriveFunctor #-} - {-# LANGUAGE BangPatterns #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE UnboxedSums #-} +{-# LANGUAGE UnboxedTuples #-} -- | Provide trees (of instructions), so that lists of instructions can be -- appended in linear time. module GHC.Data.OrdList ( - OrdList, + OrdList, pattern NilOL, pattern ConsOL, pattern SnocOL, nilOL, isNilOL, unitOL, appOL, consOL, snocOL, concatOL, lastOL, headOL, mapOL, fromOL, toOL, foldrOL, foldlOL, reverseOL, fromOLReverse, @@ -79,6 +82,50 @@ snocOL as b = Snoc as b consOL a bs = Cons a bs concatOL aas = foldr appOL None aas +pattern NilOL :: OrdList a +pattern NilOL <- (isNilOL -> True) where + NilOL = None + +-- | An unboxed 'Maybe' type with two unboxed fields in the 'Just' case. +-- Useful for defining 'viewCons' and 'viewSnoc' without overhead. +type VMaybe a b = (# (# a, b #) | (# #) #) +pattern VJust :: a -> b -> VMaybe a b +pattern VJust a b = (# (# a, b #) | #) +pattern VNothing :: VMaybe a b +pattern VNothing = (# | (# #) #) +{-# COMPLETE VJust, VNothing #-} + +pattern ConsOL :: a -> OrdList a -> OrdList a +pattern ConsOL x xs <- (viewCons -> VJust x xs) where + ConsOL x xs = consOL x xs +{-# COMPLETE NilOL, ConsOL #-} +viewCons :: OrdList a -> VMaybe a (OrdList a) +viewCons (One a) = VJust a NilOL +viewCons (Cons a as) = VJust a as +viewCons (Snoc as a) = case viewCons as of + VJust a' as' -> VJust a' (Snoc as' a) + VNothing -> VJust a NilOL +viewCons (Two as1 as2) = case viewCons as1 of + VJust a' as1' -> VJust a' (Two as1' as2) + VNothing -> viewCons as2 +viewCons _ = VNothing + +pattern SnocOL :: OrdList a -> a -> OrdList a +pattern SnocOL xs x <- (viewSnoc -> VJust xs x) where + SnocOL xs x = snocOL xs x +{-# COMPLETE NilOL, SnocOL #-} +viewSnoc :: OrdList a -> VMaybe (OrdList a) a +viewSnoc (One a) = VJust NilOL a +viewSnoc (Many (reverse -> a:as)) = VJust (Many (reverse as)) a +viewSnoc (Snoc as a) = VJust as a +viewSnoc (Cons a as) = case viewSnoc as of + VJust as' a' -> VJust (Cons a as') a' + VNothing -> VJust NilOL a +viewSnoc (Two as1 as2) = case viewSnoc as2 of + VJust as2' a' -> VJust (Two as1 as2') a' + VNothing -> viewSnoc as1 +viewSnoc _ = VNothing + headOL None = panic "headOL" headOL (One a) = a headOL (Many as) = head as @@ -189,5 +236,3 @@ strictlyOrdOL (Two a1 a2) (Two b1 b2) = strictlyOrdOL (Two _ _) _ = LT strictlyOrdOL (Many as) (Many bs) = compare as bs strictlyOrdOL (Many _ ) _ = GT - - ===================================== compiler/GHC/HsToCore/Binds.hs ===================================== @@ -33,7 +33,7 @@ import {-# SOURCE #-} GHC.HsToCore.Match ( matchWrapper ) import GHC.HsToCore.Monad import GHC.HsToCore.GuardedRHSs import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck ( addTyCsDs, covCheckGRHSs ) +import GHC.HsToCore.PmCheck ( addTyCs, covCheckGRHSs ) import GHC.Hs -- lots of things import GHC.Core -- lots of things @@ -151,14 +151,14 @@ dsHsBind dflags b@(FunBind { fun_id = L loc fun , fun_matches = matches , fun_ext = co_fn , fun_tick = tick }) - = do { (args, body) <- addTyCsDs FromSource (hsWrapDictBinders co_fn) $ + = do { (args, body) <- addTyCs FromSource (hsWrapDictBinders co_fn) $ -- FromSource might not be accurate (we don't have any -- origin annotations for things in this module), but at -- worst we do superfluous calls to the pattern match -- oracle. - -- addTyCsDs: Add type evidence to the refinement type + -- addTyCs: Add type evidence to the refinement type -- predicate of the coverage checker - -- See Note [Type and Term Equality Propagation] in "GHC.HsToCore.PmCheck" + -- See Note [Long-distance information] in "GHC.HsToCore.PmCheck" matchWrapper (mkPrefixFunRhs (L loc (idName fun))) Nothing matches @@ -200,11 +200,11 @@ dsHsBind dflags (AbsBinds { abs_tvs = tyvars, abs_ev_vars = dicts , abs_exports = exports , abs_ev_binds = ev_binds , abs_binds = binds, abs_sig = has_sig }) - = do { ds_binds <- addTyCsDs FromSource (listToBag dicts) $ + = do { ds_binds <- addTyCs FromSource (listToBag dicts) $ dsLHsBinds binds - -- addTyCsDs: push type constraints deeper + -- addTyCs: push type constraints deeper -- for inner pattern match check - -- See Check, Note [Type and Term Equality Propagation] + -- See Check, Note [Long-distance information] ; ds_ev_binds <- dsTcEvBinds_s ev_binds ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -31,7 +31,7 @@ import GHC.HsToCore.ListComp import GHC.HsToCore.Utils import GHC.HsToCore.Arrows import GHC.HsToCore.Monad -import GHC.HsToCore.PmCheck ( addTyCsDs, covCheckGRHSs ) +import GHC.HsToCore.PmCheck ( addTyCs, covCheckGRHSs ) import GHC.Types.Name import GHC.Types.Name.Env import GHC.Core.FamInstEnv( topNormaliseType ) @@ -283,7 +283,7 @@ dsExpr hswrap@(XExpr (WrapExpr (HsWrap co_fn e))) HsConLikeOut _ (RealDataCon dc) -> return $ varToCoreExpr (dataConWrapId dc) XExpr (WrapExpr (HsWrap _ _)) -> pprPanic "dsExpr: HsWrap inside HsWrap" (ppr hswrap) HsPar _ _ -> pprPanic "dsExpr: HsPar inside HsWrap" (ppr hswrap) - _ -> addTyCsDs FromSource (hsWrapDictBinders co_fn) $ + _ -> addTyCs FromSource (hsWrapDictBinders co_fn) $ dsExpr e -- See Note [Detecting forced eta expansion] ; wrap' <- dsHsWrapper co_fn ===================================== compiler/GHC/HsToCore/Match.hs ===================================== @@ -770,8 +770,8 @@ matchWrapper ctxt mb_scr (MG { mg_alts = L _ matches -- Each Match will split off one Deltas for its RHSs from this. ; matches_deltas <- if isMatchContextPmChecked dflags origin ctxt then addHsScrutTmCs mb_scr new_vars $ - -- See Note [Type and Term Equality Propagation] - covCheckMatchGroup (DsMatchContext ctxt locn) new_vars matches + -- See Note [Long-distance information] + covCheckMatches (DsMatchContext ctxt locn) new_vars matches else pure (initDeltasMatches matches) ; eqns_info <- zipWithM mk_eqn_info matches matches_deltas @@ -881,7 +881,7 @@ matchSinglePatVar var mb_scrut ctx pat ty match_result -- Pattern match check warnings ; when (isMatchContextPmChecked dflags FromSource ctx) $ addCoreScrutTmCs mb_scrut [var] $ - covCheckPatBind dflags (DsMatchContext ctx locn) var (unLoc pat) + covCheckPatBind (DsMatchContext ctx locn) var (unLoc pat) ; let eqn_info = EqnInfo { eqn_pats = [unLoc (decideBangHood dflags pat)] , eqn_orig = FromSource ===================================== compiler/GHC/HsToCore/PmCheck.hs ===================================== @@ -1,24 +1,49 @@ -{- -Author: George Karachalias - -Pattern Matching Coverage Checking. --} - -{-# LANGUAGE CPP #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE TupleSections #-} -{-# LANGUAGE ViewPatterns #-} -{-# LANGUAGE MultiWayIf #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE NamedFieldPuns #-} - +{-# LANGUAGE CPP #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE TupleSections #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE MultiWayIf #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE NamedFieldPuns #-} + +-- | This module coverage checks pattern matches. It finds +-- +-- * Uncovered patterns, certifying non-exhaustivity +-- * Redundant equations +-- * Equations with an inaccessible right-hand-side +-- +-- The algorithm is based on the paper +-- [Lower Your Guards: A Compositional Pattern-Match Coverage Checker"](https://dl.acm.org/doi/abs/10.1145/3408989) +-- +-- There is an overview Figure 2 in there that's probably helpful. +-- Here is an overview of how it's implemented, which follows the structure of +-- the entry points such as 'covCheckMatches': +-- +-- 1. Desugar source syntax (like 'LMatch') to guard tree variants (like +-- 'GrdMatch'), with one of the desugaring functions (like 'desugarMatch'). +-- Follows Section 3.1 in the paper. +-- 2. Coverage check guard trees (with a function like 'checkMatch') to get a +-- 'CheckResult', containing +-- a. The set of uncovered values, 'cr_uncov' +-- b. And an annotated tree variant (like 'AnnMatch') that captures +-- redundancy and inaccessibility information as 'RedSets' annotations +-- Basically the UA function from Section 5.1. The Normalised Refinement Types +-- Nabla are modeled as 'Deltas' and checked in "GHC.HsToCore.PmCheck.Oracle". +-- 3. Collect redundancy information into a 'CIRB' with a 'CIRBCollector' such +-- as 'collectMatch'. Follows the R function from Figure 6 of the paper. +-- 4. Format and report uncovered patterns and redundant equations ('CIRB') +-- with 'formatReportWarnings'. Basically job of the G function, plus proper +-- pretty printing of the warnings (Section 5.4 of the paper). +-- 5. Return 'Deltas' reaching syntactic sub-components for +-- Note [Long-distance information]. See Section 4.1 of the paper. module GHC.HsToCore.PmCheck ( -- Checking and printing - covCheckPatBind, covCheckMatchGroup, covCheckGRHSs, + covCheckPatBind, covCheckMatches, covCheckGRHSs, isMatchContextPmChecked, - -- See Note [Type and Term Equality Propagation] - addTyCsDs, addCoreScrutTmCs, addHsScrutTmCs + -- See Note [Long-distance information] + addTyCs, addCoreScrutTmCs, addHsScrutTmCs ) where #include "HsVersions.h" @@ -37,7 +62,6 @@ import GHC.Tc.Utils.Zonk (shortCutLit) import GHC.Types.Id import GHC.Core.ConLike import GHC.Types.Name -import GHC.Tc.Instance.Family import GHC.Builtin.Types import GHC.Types.SrcLoc import GHC.Utils.Misc @@ -62,35 +86,130 @@ import GHC.Core.Type import GHC.HsToCore.Utils (isTrueLHsExpr) import GHC.Data.Maybe import qualified GHC.LanguageExtensions as LangExt -import GHC.Utils.Monad (concatMapM) +import GHC.Utils.Monad (concatMapM, mapMaybeM) import Control.Monad (when, forM_, zipWithM) import Data.List (elemIndex) import qualified Data.Semigroup as Semi -import Data.List.NonEmpty (NonEmpty(..)) +import Data.List.NonEmpty ( NonEmpty(..) ) +import qualified Data.List.NonEmpty as NE +import Data.Coerce -{- -This module checks pattern matches for: -\begin{enumerate} - \item Equations that are redundant - \item Equations with inaccessible right-hand-side - \item Exhaustiveness -\end{enumerate} +-- +-- * Exported entry points to the checker +-- -The algorithm is based on the paper: +-- | Check a pattern binding (let, where) for exhaustiveness. +covCheckPatBind :: DsMatchContext -> Id -> Pat GhcTc -> DsM () +-- See Note [covCheckPatBind only checks PatBindRhs] +covCheckPatBind ctxt@(DsMatchContext PatBindRhs loc) var p = do + missing <- getPmDeltas + pat_bind <- desugarPatBind loc var p + tracePm "covCheckPatBind {" (vcat [ppr ctxt, ppr var, ppr p, ppr pat_bind, ppr missing]) + result <- unCA (checkPatBind pat_bind) missing + tracePm "}: " (ppr (cr_uncov result)) + formatReportWarnings collectPatBind ctxt [var] result +covCheckPatBind _ _ _ = pure () - "GADTs Meet Their Match: - Pattern-matching Warnings That Account for GADTs, Guards, and Laziness" +-- | Exhaustive for guard matches, is used for guards in pattern bindings and +-- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. +covCheckGRHSs + :: HsMatchContext GhcRn -- ^ Match context, for warning messages + -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check + -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long + -- distance info +covCheckGRHSs hs_ctxt guards@(GRHSs _ grhss _) = do + let combined_loc = foldl1 combineSrcSpans (map getLoc grhss) + ctxt = DsMatchContext hs_ctxt combined_loc + matches <- desugarGRHSs combined_loc empty guards + missing <- getPmDeltas + tracePm "covCheckGRHSs" (hang (vcat [ppr ctxt + , text "Guards:"]) + 2 + (pprGRHSs hs_ctxt guards $$ ppr missing)) + result <- unCA (checkGRHSs matches) missing + tracePm "}: " (ppr (cr_uncov result)) + formatReportWarnings (collectGRHSs missing) ctxt [] result + +-- | Check a list of syntactic 'Match'es (part of case, functions, etc.), each +-- with a 'Pat' and one or more 'GRHSs': +-- +-- @ +-- f x y | x == y = 1 -- match on x and y with two guarded RHSs +-- | otherwise = 2 +-- f _ _ = 3 -- clause with a single, un-guarded RHS +-- @ +-- +-- Returns one non-empty 'Deltas' for 1.) each pattern of a 'Match' and 2.) +-- each of a 'Match'es 'GRHS' for Note [Long-distance information]. +-- +-- Special case: When there are /no matches/, then the functionassumes it +-- checks and @-XEmptyCase@ with only a single match variable. +-- See Note [Checking EmptyCase]. +covCheckMatches + :: DsMatchContext -- ^ Match context, for warnings messages + -> [Id] -- ^ Match variables, i.e. x and y above + -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches + -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per Match and + -- GRHS, for long distance info. +covCheckMatches ctxt vars matches = do + missing <- getPmDeltas + tracePm "covCheckMatches {" (hang (vcat [ppr ctxt, ppr vars, text "Matches:"]) + 2 + (vcat (map ppr matches) $$ ppr missing)) + case NE.nonEmpty matches of + Nothing -> do + -- This must be an -XEmptyCase. See Note [Checking EmptyCase] + let var = only vars + empty_case <- desugarEmptyCase var + result <- unCA (checkEmptyCase empty_case) missing + tracePm "}: " (ppr (cr_uncov result)) + [] <$ formatReportWarnings collectEmptyCase ctxt vars result + Just matches -> do + matches <- desugarMatches vars matches + result <- unCA (checkMatchGroup matches) missing + tracePm "}: " (ppr (cr_uncov result)) + NE.toList <$> formatReportWarnings (collectMatchGroup missing) ctxt vars result + +{- Note [covCheckPatBind only checks PatBindRhs] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + at covCheckPatBind@'s sole purpose is to check vanilla pattern bindings, like + at x :: Int; Just x = e@, which is in a @PatBindRhs@ context. +But its caller is also called for individual pattern guards in a @StmtCtxt at . +For example, both pattern guards in @f x y | True <- x, False <- y = ...@ will +go through this function. It makes no sense to do coverage checking there: + * Pattern guards may well fail. Fall-through is not an unrecoverable panic, + but rather behavior the programmer expects, so inexhaustivity should not be + reported. + * Redundancy is already reported for the whole GRHS via one of the other + exported coverage checking functions. Also reporting individual redundant + guards is... redundant. See #17646. +Note that we can't just omit checking of @StmtCtxt@ altogether (by adjusting +'isMatchContextPmChecked'), because that affects the other checking functions, +too. + +Note [Checking EmptyCase] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-XEmptyCase is useful for matching on empty data types like 'Void'. For example, +the following is a complete match: - https://www.microsoft.com/en-us/research/wp-content/uploads/2016/08/gadtpm-acm.pdf + f :: Void -> () + f x = case x of {} -%************************************************************************ -%* * - Pattern Match Check Types -%* * -%************************************************************************ +Really, -XEmptyCase is the only way to write a program that at the same time is +safe (@f _ = error "boom"@ is not because of ⊥), doesn't trigger a warning +(@f !_ = error "inaccessible" has inaccessible RHS) and doesn't turn an +exception into divergence (@f x = f x@). + +Semantically, unlike every other case expression, -XEmptyCase is strict in its +match var x, which rules out ⊥ as an inhabitant. So we add x /~ ⊥ to the +initial Delta and check if there are any values left to match on. -} +-- +-- * Guard language +-- + -- | A very simple language for pattern guards. Let bindings, bang patterns, -- and matching variables against flat constructor patterns. data PmGrd @@ -106,9 +225,9 @@ data PmGrd } -- | @PmBang x@ corresponds to a @seq x True@ guard. - -- If the extra SrcInfo is present, the bang guard came from a source - -- bang pattern, in which case we might want to report it as redundant, - -- see Note [Dead bang patterns]. + -- If the extra 'SrcInfo' is present, the bang guard came from a source + -- bang pattern, in which case we might want to report it as redundant. + -- See Note [Dead bang patterns]. | PmBang { pm_id :: !Id, pm_loc :: !(Maybe SrcInfo) @@ -144,24 +263,118 @@ instance Monoid Precision where mempty = Precise mappend = (Semi.<>) --- | Means by which we identify source location for later pretty-printing --- in a warning message. 'SDoc' for the equation to show, 'Located' for --- the location. +-- +-- * Guard tree language +-- + +-- | Means by which we identify a source construct for later pretty-printing in +-- a warning message. 'SDoc' for the equation to show, 'Located' for the +-- location. type SrcInfo = Located SDoc --- | A representation of the desugaring to 'PmGrd's of all clauses of a --- function definition/pattern match/etc. -data GrdTree - = Rhs !SrcInfo - | Guard !PmGrd !GrdTree - -- ^ @Guard grd t@ will try to match @grd@ and on success continue to match - -- @t at . Falls through if either match fails. Models left-to-right semantics - -- of pattern matching. - | Sequence ![GrdTree] - -- ^ @Sequence (t:ts)@ matches against @t@, and then matches all - -- fallen-through values against @Sequence ts at . Models top-to-bottom semantics - -- of pattern matching. - -- @Sequence []@ always fails; it is useful for Note [Checking EmptyCase]. +-- | A guard tree denoting 'MatchGroup'. +newtype GrdMatchGroup = GrdMatchGroup (NonEmpty GrdMatch) + +-- | A guard tree denoting 'Match'. +data GrdMatch = GrdMatch { gm_pats :: ![PmGrd], gm_grhss :: !(NonEmpty GrdGRHS) } + +-- | A guard tree denoting 'GRHS'. +data GrdGRHS = GrdGRHS { gg_grds :: ![PmGrd], gg_rhs :: !SrcInfo } + +-- | A guard tree denoting an -XEmptyCase. +newtype GrdEmptyCase = GrdEmptyCase { ge_var :: Id } + +-- | A guard tree denoting a pattern binding. +newtype GrdPatBind = + -- just reuse GrdGRHS and pretend its @SrcInfo@ is info on the /pattern/, + -- rather than on the pattern bindings. + GrdPatBind GrdGRHS + +-- | Redundancy sets, used to determine redundancy of RHSs and bang patterns +-- (later digested into a 'CIRB'). +data RedSets + = RedSets + { rs_cov :: !Deltas + -- ^ The /Covered/ set; the set of values reaching a particular program + -- point. + , rs_div :: !Deltas + -- ^ The /Diverging/ set; empty if no match can lead to divergence. + -- If it wasn't empty, we have to turn redundancy warnings into + -- inaccessibility warnings for any subclauses. + , rs_bangs :: !(OrdList (Deltas, SrcInfo)) + -- ^ If any of the 'Deltas' is empty, the corresponding 'SrcInfo' pin-points + -- a bang pattern in source that is redundant. See Note [Dead bang patterns]. + } + +emptyRedSets :: RedSets +-- Semigroup instance would be misleading! +emptyRedSets = RedSets mempty mempty mempty + +-- | An annotated tree denoting 'MatchGroup'. +newtype AnnMatchGroup = AnnMatchGroup (NonEmpty AnnMatch) + +-- | An annotated tree denoting 'Match'. +data AnnMatch = AnnMatch { am_red :: !RedSets, am_grhss :: !(NonEmpty AnnGRHS) } + +-- | An annotated tree denoting 'GRHS'. +data AnnGRHS = AnnGRHS { ag_red :: !RedSets, ag_rhs :: !SrcInfo } + +-- | An annotated tree denoting an -XEmptyCase. +data AnnEmptyCase = AnnEmptyCase + +-- | An annotated tree denoting a pattern binding. +newtype AnnPatBind = AnnPatBind AnnGRHS + +pprSrcInfo :: SrcInfo -> SDoc +pprSrcInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) +pprSrcInfo (L s _) = ppr s + +-- | Format LYG guards as @| True <- x, let x = 42, !z@ +pprLygGuards :: [PmGrd] -> SDoc +pprLygGuards [] = empty +pprLygGuards (g:gs) = fsep (char '|' <+> ppr g : map ((comma <+>) . ppr) gs) + +-- | Format a LYG sequence (e.g. 'Match'es of a 'MatchGroup' or 'GRHSs') as +-- @{ ; ...; }@ +pprLygSequence :: Outputable a => NonEmpty a -> SDoc +pprLygSequence (NE.toList -> as) = + braces (space <> fsep (punctuate semi (map ppr as)) <> space) + +instance Outputable GrdMatchGroup where + ppr (GrdMatchGroup matches) = pprLygSequence matches + +instance Outputable GrdMatch where + ppr (GrdMatch { gm_pats = grds, gm_grhss = grhss }) = + pprLygGuards grds <+> ppr grhss + +instance Outputable GrdGRHS where + ppr (GrdGRHS { gg_grds = grds, gg_rhs = rhs }) = + pprLygGuards grds <+> text "->" <+> pprSrcInfo rhs + +instance Outputable GrdPatBind where + ppr (GrdPatBind GrdGRHS { gg_grds = grds, gg_rhs = bind }) = + ppr bind <+> pprLygGuards grds <+> text "=" <+> text "..." + +instance Outputable GrdEmptyCase where + ppr (GrdEmptyCase { ge_var = var }) = + text " ppr var <> text ">" + +pprRedSets :: RedSets -> SDoc +-- It's useful to change this definition for different verbosity levels in +-- printf-debugging +pprRedSets RedSets { rs_cov = _cov, rs_div = _div, rs_bangs = _bangs } + = empty + +instance Outputable AnnMatchGroup where + ppr (AnnMatchGroup matches) = pprLygSequence matches + +instance Outputable AnnMatch where + ppr (AnnMatch { am_red = red, am_grhss = grhss }) = + pprRedSets red <+> ppr grhss + +instance Outputable AnnGRHS where + ppr (AnnGRHS { ag_red = red, ag_rhs = rhs }) = + pprRedSets red <+> text "->" <+> pprSrcInfo rhs {- Note [Dead bang patterns] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -197,236 +410,9 @@ it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. -} --- | The digest of 'checkGrdTree', representing the annotated pattern-match --- tree. 'extractRedundancyInfo' can figure out redundant and proper --- inaccessible RHSs from this, as well as dead bangs. -data AnnotatedTree - = AccessibleRhs !Deltas !SrcInfo - -- ^ A RHS deemed accessible. The 'Deltas' is the (non-empty) set of covered - -- values. - | InaccessibleRhs !SrcInfo - -- ^ A RHS deemed inaccessible; it covers no value. - | MayDiverge !AnnotatedTree - -- ^ Asserts that the tree may force diverging values, so not all of its - -- clauses can be redundant. - | SequenceAnn !Deltas ![AnnotatedTree] - -- ^ @SequenceAnn inc ts@ mirrors @'Sequence' ts@ for preserving the - -- skeleton of a 'GrdTree's @ts at . It also carries the set of incoming values - -- @inc at . - | RedundantSrcBang !SrcInfo !AnnotatedTree - -- ^ For tracking redundant bangs. See Note [Dead bang patterns] - -pprSrcInfo :: SrcInfo -> SDoc -pprSrcInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) -pprSrcInfo (L s _) = ppr s - -instance Outputable GrdTree where - ppr (Rhs info) = text "->" <+> pprSrcInfo info - -- Format guards as "| True <- x, let x = 42, !z" - ppr g at Guard{} = fsep (prefix (map ppr grds)) <+> ppr t - where - (t, grds) = collect_grds g - collect_grds (Guard grd t) = (grd :) <$> collect_grds t - collect_grds t = (t, []) - prefix [] = [] - prefix (s:sdocs) = char '|' <+> s : map (comma <+>) sdocs - ppr (Sequence []) = text "" - ppr (Sequence ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) - -instance Outputable AnnotatedTree where - ppr (AccessibleRhs _delta info) = parens (ppr _delta) <+> pprSrcInfo info - ppr (InaccessibleRhs info) = text "inaccessible" <+> pprSrcInfo info - ppr (MayDiverge t) = text "div" <+> ppr t - ppr (SequenceAnn _ []) = text "" - ppr (SequenceAnn _ ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) - ppr (RedundantSrcBang l t) = text "redundant bang" <+> pprSrcInfo l <+> ppr t - --- | Lift 'addPmCts' over 'Deltas'. -addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas -addPmCtsDeltas deltas cts = liftDeltasM (\d -> addPmCts d cts) deltas - --- | 'addPmCtsDeltas' a single 'PmCt'. -addPmCtDeltas :: Deltas -> PmCt -> DsM Deltas -addPmCtDeltas deltas ct = addPmCtsDeltas deltas (unitBag ct) - --- | Test if any of the 'Delta's is inhabited. Currently this is pure, because --- we preserve the invariant that there are no uninhabited 'Delta's. But that --- could change in the future, for example by implementing this function in --- terms of @notNull <$> provideEvidence 1 ds at . -isInhabited :: Deltas -> DsM Bool -isInhabited (MkDeltas ds) = pure (not (null ds)) - --- | Pattern-match check result -data CheckResult - = CheckResult - { cr_clauses :: !AnnotatedTree - -- ^ Captures redundancy info for each clause in the original program. - -- (for -Woverlapping-patterns) - , cr_uncov :: !Deltas - -- ^ The set of uncovered values falling out at the bottom. - -- (for -Wincomplete-patterns) - , cr_approx :: !Precision - -- ^ A flag saying whether we ran into the 'maxPmCheckModels' limit for the - -- purpose of suggesting to crank it up in the warning message - } - -instance Outputable CheckResult where - ppr (CheckResult c unc pc) - = text "CheckResult" <+> ppr_precision pc <+> braces (fsep - [ field "clauses" c <> comma - , field "uncov" unc]) - where - ppr_precision Precise = empty - ppr_precision Approximate = text "(Approximate)" - field name value = text name <+> equals <+> ppr value - -{- -%************************************************************************ -%* * - Entry points to the checker: covCheckPatBind and covCheckMatchGroup -%* * -%************************************************************************ --} - --- | Check a pattern binding (let, where) for exhaustiveness. -covCheckPatBind :: DynFlags -> DsMatchContext -> Id -> Pat GhcTc -> DsM () -covCheckPatBind dflags ctxt@(DsMatchContext _ locn) var p = do - -- We only ever need to run this in a context where we need exhaustivity - -- warnings (so not in pattern guards or comprehensions, for example, because - -- they are perfectly fine to fail). - -- Omitting checking this flag emits redundancy warnings twice in obscure - -- cases like #17646. - -- Given the context in which this function is called, it will only ever do - -- something for - -- * PatBindRhs, -Wincomplete-uni-patterns: @let True = False@ - -- * PatBindGuards, -Wincomplete-patterns: @Just x | False = Just 42@ - missing <- getPmDeltas - tracePm "covCheckPatBind" (vcat [ppr ctxt, ppr var, ppr p, ppr missing]) - fam_insts <- dsGetFamInstEnvs - grd_tree <- mkGrdTreeRhs (L locn $ ppr p) <$> translatePat fam_insts var p - res <- checkGrdTree grd_tree missing - dsPmWarn dflags ctxt [var] res - --- | Exhaustive for guard matches, is used for guards in pattern bindings and --- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. -covCheckGRHSs - :: HsMatchContext GhcRn -- ^ Match context, for warning messages - -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check - -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long - -- distance info -covCheckGRHSs hs_ctx guards@(GRHSs _ grhss _) = do - let combinedLoc = foldl1 combineSrcSpans (map getLoc grhss) - dsMatchContext = DsMatchContext hs_ctx combinedLoc - match = L combinedLoc $ - Match { m_ext = noExtField - , m_ctxt = hs_ctx - , m_pats = [] - , m_grhss = guards } - [(_, deltas)] <- covCheckMatchGroup dsMatchContext [] [match] - pure deltas - --- | Check a list of syntactic /match/es (part of case, functions, etc.), each --- with a /pat/ and one or more /grhss/: -- --- @ --- f x y | x == y = 1 -- match on x and y with two guarded RHSs --- | otherwise = 2 --- f _ _ = 3 -- clause with a single, un-guarded RHS --- @ +-- * Desugaring source syntax to guard trees -- --- Returns one 'Deltas' for each GRHS, representing its covered values, or the --- incoming uncovered 'Deltas' (from 'getPmDeltas') if the GRHS is inaccessible. --- Since there is at least one /grhs/ per /match/, the list of 'Deltas' is at --- least as long as the list of matches. -covCheckMatchGroup - :: DsMatchContext -- ^ Match context, for warnings messages - -> [Id] -- ^ Match variables, i.e. x and y above - -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches - -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per RHS, for long - -- distance info. -covCheckMatchGroup ctxt vars matches = do - tracePm "covCheckMatchGroup" (hang (vcat [ppr ctxt - , ppr vars - , text "Matches:"]) - 2 - (vcat (map ppr matches))) - - init_deltas <- getPmDeltas - missing <- case matches of - -- This must be an -XEmptyCase. See Note [Checking EmptyCase] - [] | [var] <- vars -> addPmCtDeltas init_deltas (PmNotBotCt var) - _ -> pure init_deltas - fam_insts <- dsGetFamInstEnvs - grd_tree <- translateMatches fam_insts vars matches - res <- checkGrdTree grd_tree missing - - dflags <- getDynFlags - dsPmWarn dflags ctxt vars res - - return (extractRhsDeltas (cr_clauses res)) - --- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree' for a match --- group. --- For 'AccessibleRhs's, this is stored in the tree node, whereas --- 'InaccessibleRhs's fall back to the supplied original 'Deltas'. --- See @Note [Recovering from unsatisfiable pattern-matching constraints]@. -extractRhsDeltas :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] -extractRhsDeltas = go_matches - where - go_matches :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] - go_matches (SequenceAnn def ts) = map (go_match def) ts -- -XEmptyCase handled here! - go_matches t = pprPanic "extractRhsDeltas.go_matches" (text "Matches must start with SequenceAnn. But was" $$ ppr t) - - go_match :: Deltas -> AnnotatedTree -> (Deltas, NonEmpty Deltas) - -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ - -- is non-empty! - go_match def (SequenceAnn pat ts) = (pat, foldMap1 (text "go_match: empty SequenceAnn") (go_grhss def) ts) - go_match def (MayDiverge t) = go_match def t - go_match def (RedundantSrcBang _ t) = go_match def t - -- Even if there's only a single GRHS, we wrap it in a SequenceAnn for the - -- Deltas covered by the pattern. So the remaining cases are impossible! - go_match _ t = pprPanic "extractRhsDeltas.go_match" (text "Single GRHS must be wrapped in SequenceAnn. But got " $$ ppr t) - - go_grhss :: Deltas -> AnnotatedTree -> NonEmpty Deltas - -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ - -- is non-empty! - go_grhss def (SequenceAnn _ ts) = foldMap1 (text "go_grhss: empty SequenceAnn") (go_grhss def) ts - go_grhss def (MayDiverge t) = go_grhss def t - go_grhss def (RedundantSrcBang _ t) = go_grhss def t - go_grhss _ (AccessibleRhs deltas _) = deltas :| [] - go_grhss def (InaccessibleRhs _) = def :| [] - - foldMap1 msg _ [] = pprPanic "extractRhsDeltas.foldMap1" msg - foldMap1 _ f (x:xs) = foldl' (\acc x -> acc Semi.<> f x) (f x) xs - -{- Note [Checking EmptyCase] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --XEmptyCase is useful for matching on empty data types like 'Void'. For example, -the following is a complete match: - - f :: Void -> () - f x = case x of {} - -Really, -XEmptyCase is the only way to write a program that at the same time is -safe (@f _ = error "boom"@ is not because of ⊥), doesn't trigger a warning -(@f !_ = error "inaccessible" has inaccessible RHS) and doesn't turn an -exception into divergence (@f x = f x@). - -Semantically, unlike every other case expression, -XEmptyCase is strict in its -match var x, which rules out ⊥ as an inhabitant. So we add x /~ ⊥ to the -initial Delta and check if there are any values left to match on. --} - -{- -%************************************************************************ -%* * - Transform source syntax to *our* syntax -%* * -%************************************************************************ --} - --- ----------------------------------------------------------------------- --- * Utilities -- | Smart constructor that eliminates trivial lets mkPmLetVar :: Id -> Id -> GrdVec @@ -459,7 +445,7 @@ mkListGrds a ((x, head_grds):xs) = do -- | Create a 'GrdVec' refining a match variable to a 'PmLit'. mkPmLitGrds :: Id -> PmLit -> DsM GrdVec mkPmLitGrds x (PmLit _ (PmLitString s)) = do - -- We translate String literals to list literals for better overlap reasoning. + -- We desugar String literals to list literals for better overlap reasoning. -- It's a little unfortunate we do this here rather than in -- 'GHC.HsToCore.PmCheck.Oracle.trySolve' and -- 'GHC.HsToCore.PmCheck.Oracle.addRefutableAltCon', but it's so much simpler @@ -477,37 +463,34 @@ mkPmLitGrds x lit = do , pm_con_args = [] } pure [grd] --- ----------------------------------------------------------------------- --- * Transform (Pat Id) into GrdVec - --- | @translatePat _ x pat@ transforms @pat@ into a 'GrdVec', where +-- | @desugarPat _ x pat@ transforms @pat@ into a 'GrdVec', where -- the variable representing the match is @x at . -translatePat :: FamInstEnvs -> Id -> Pat GhcTc -> DsM GrdVec -translatePat fam_insts x pat = case pat of +desugarPat :: Id -> Pat GhcTc -> DsM GrdVec +desugarPat x pat = case pat of WildPat _ty -> pure [] VarPat _ y -> pure (mkPmLetVar (unLoc y) x) - ParPat _ p -> translateLPat fam_insts x p + ParPat _ p -> desugarLPat x p LazyPat _ _ -> pure [] -- like a wildcard BangPat _ p@(L l p') -> -- Add the bang in front of the list, because it will happen before any -- nested stuff. - (PmBang x pm_loc :) <$> translateLPat fam_insts x p - where pm_loc = Just (L l (ppr p')) + (PmBang x pm_loc :) <$> desugarLPat x p + where pm_loc = Just (L l (ppr p')) - -- (x at pat) ==> Translate pat with x as match var and handle impedance + -- (x at pat) ==> Desugar pat with x as match var and handle impedance -- mismatch with incoming match var - AsPat _ (L _ y) p -> (mkPmLetVar y x ++) <$> translateLPat fam_insts y p + AsPat _ (L _ y) p -> (mkPmLetVar y x ++) <$> desugarLPat y p - SigPat _ p _ty -> translateLPat fam_insts x p + SigPat _ p _ty -> desugarLPat x p - -- See Note [Translate CoPats] + -- See Note [Desugar CoPats] -- Generally the translation is -- pat |> co ===> let y = x |> co, pat <- y where y is a match var of pat XPat (CoPat wrapper p _ty) - | isIdHsWrapper wrapper -> translatePat fam_insts x p - | WpCast co <- wrapper, isReflexiveCo co -> translatePat fam_insts x p + | isIdHsWrapper wrapper -> desugarPat x p + | WpCast co <- wrapper, isReflexiveCo co -> desugarPat x p | otherwise -> do - (y, grds) <- translatePatV fam_insts p + (y, grds) <- desugarPatV p wrap_rhs_y <- dsHsWrapper wrapper pure (PmLet y (wrap_rhs_y (Var x)) : grds) @@ -522,13 +505,13 @@ translatePat fam_insts x pat = case pat of -- (fun -> pat) ===> let y = fun x, pat <- y where y is a match var of pat ViewPat _arg_ty lexpr pat -> do - (y, grds) <- translateLPatV fam_insts pat + (y, grds) <- desugarLPatV pat fun <- dsLExpr lexpr pure $ PmLet y (App fun (Var x)) : grds -- list ListPat (ListPatTc _elem_ty Nothing) ps -> - translateListPat fam_insts x ps + desugarListPat x ps -- overloaded list ListPat (ListPatTc elem_ty (Just (pat_ty, to_list))) pats -> do @@ -536,11 +519,11 @@ translatePat fam_insts x pat = case pat of case splitListTyConApp_maybe pat_ty of Just _e_ty | not (xopt LangExt.RebindableSyntax dflags) - -- Just translate it as a regular ListPat - -> translateListPat fam_insts x pats + -- Just desugar it as a regular ListPat + -> desugarListPat x pats _ -> do y <- mkPmId (mkListTy elem_ty) - grds <- translateListPat fam_insts y pats + grds <- desugarListPat y pats rhs_y <- dsSyntaxExpr to_list [Var x] pure $ PmLet y rhs_y : grds @@ -566,7 +549,7 @@ translatePat fam_insts x pat = case pat of , cpt_dicts = dicts } } -> do - translateConPatOut fam_insts x con arg_tys ex_tvs dicts ps + desugarConPatOut x con arg_tys ex_tvs dicts ps NPat ty (L _ olit) mb_neg _ -> do -- See Note [Literal short cut] in "GHC.HsToCore.Match.Literal" @@ -595,46 +578,44 @@ translatePat fam_insts x pat = case pat of mkPmLitGrds x lit TuplePat _tys pats boxity -> do - (vars, grdss) <- mapAndUnzipM (translateLPatV fam_insts) pats + (vars, grdss) <- mapAndUnzipM desugarLPatV pats let tuple_con = tupleDataCon boxity (length vars) pure $ vanillaConGrd x tuple_con vars : concat grdss SumPat _ty p alt arity -> do - (y, grds) <- translateLPatV fam_insts p + (y, grds) <- desugarLPatV p let sum_con = sumDataCon alt arity -- See Note [Unboxed tuple RuntimeRep vars] in GHC.Core.TyCon pure $ vanillaConGrd x sum_con [y] : grds - -- -------------------------------------------------------------------------- - -- Not supposed to happen - SplicePat {} -> panic "Check.translatePat: SplicePat" + SplicePat {} -> panic "Check.desugarPat: SplicePat" --- | 'translatePat', but also select and return a new match var. -translatePatV :: FamInstEnvs -> Pat GhcTc -> DsM (Id, GrdVec) -translatePatV fam_insts pat = do +-- | 'desugarPat', but also select and return a new match var. +desugarPatV :: Pat GhcTc -> DsM (Id, GrdVec) +desugarPatV pat = do x <- selectMatchVar Many pat - grds <- translatePat fam_insts x pat + grds <- desugarPat x pat pure (x, grds) -translateLPat :: FamInstEnvs -> Id -> LPat GhcTc -> DsM GrdVec -translateLPat fam_insts x = translatePat fam_insts x . unLoc +desugarLPat :: Id -> LPat GhcTc -> DsM GrdVec +desugarLPat x = desugarPat x . unLoc --- | 'translateLPat', but also select and return a new match var. -translateLPatV :: FamInstEnvs -> LPat GhcTc -> DsM (Id, GrdVec) -translateLPatV fam_insts = translatePatV fam_insts . unLoc +-- | 'desugarLPat', but also select and return a new match var. +desugarLPatV :: LPat GhcTc -> DsM (Id, GrdVec) +desugarLPatV = desugarPatV . unLoc --- | @translateListPat _ x [p1, ..., pn]@ is basically --- @translateConPatOut _ x $(mkListConPatOuts [p1, ..., pn]>@ without ever +-- | @desugarListPat _ x [p1, ..., pn]@ is basically +-- @desugarConPatOut _ x $(mkListConPatOuts [p1, ..., pn]>@ without ever -- constructing the 'ConPatOut's. -translateListPat :: FamInstEnvs -> Id -> [LPat GhcTc] -> DsM GrdVec -translateListPat fam_insts x pats = do - vars_and_grdss <- traverse (translateLPatV fam_insts) pats +desugarListPat :: Id -> [LPat GhcTc] -> DsM GrdVec +desugarListPat x pats = do + vars_and_grdss <- traverse desugarLPatV pats mkListGrds x vars_and_grdss --- | Translate a constructor pattern -translateConPatOut :: FamInstEnvs -> Id -> ConLike -> [Type] -> [TyVar] +-- | Desugar a constructor pattern +desugarConPatOut :: Id -> ConLike -> [Type] -> [TyVar] -> [EvVar] -> HsConPatDetails GhcTc -> DsM GrdVec -translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case +desugarConPatOut x con univ_tys ex_tvs dicts = \case PrefixCon ps -> go_field_pats (zip [0..] ps) InfixCon p1 p2 -> go_field_pats (zip [0..] [p1,p2]) RecCon (HsRecFields fs _) -> go_field_pats (rec_field_ps fs) @@ -648,7 +629,7 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case where tagged_pat f = (lbl_to_index (getName (hsRecFieldId f)), hsRecFieldArg f) -- Unfortunately the label info is empty when the DataCon wasn't defined - -- with record field labels, hence we translate to field index. + -- with record field labels, hence we desugar to field index. orig_lbls = map flSelector $ conLikeFieldLabels con lbl_to_index lbl = expectJust "lbl_to_index" $ elemIndex lbl orig_lbls @@ -659,10 +640,10 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- the first field of @tagged_pats at . -- See Note [Field match order for RecCon] - -- Translate the mentioned field patterns. We're doing this first to get + -- Desugar the mentioned field patterns. We're doing this first to get -- the Ids for pm_con_args. let trans_pat (n, pat) = do - (var, pvec) <- translateLPatV fam_insts pat + (var, pvec) <- desugarLPatV pat pure ((n, var), pvec) (tagged_vars, arg_grdss) <- mapAndUnzipM trans_pat tagged_pats @@ -688,77 +669,81 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- 1. 2. 3. pure (con_grd : bang_grds ++ arg_grds) --- | Translate a the 'Match'es of a 'MatchGroup' -translateMatches :: FamInstEnvs -> [Id] -> [LMatch GhcTc (LHsExpr GhcTc)] - -> DsM GrdTree -translateMatches fam_insts vars matches = - -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. - -- 'extractRhsDeltas' needs this to recover 'MatchGroup' structure. - Sequence <$> traverse (translateMatch fam_insts vars) matches - --- Translate a single match -translateMatch :: FamInstEnvs -> [Id] -> LMatch GhcTc (LHsExpr GhcTc) - -> DsM GrdTree -translateMatch fam_insts vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do - pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats - grhss' <- translateGRHSs fam_insts match_loc (sep (map ppr pats)) grhss - -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss']) - return (foldr Guard grhss' pats') - -mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree -mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) - -translateGRHSs :: FamInstEnvs -> SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateGRHSs fam_insts match_loc pp_pats grhss = - -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. - -- 'extractRhsDeltas' needs this to recover 'GRHSs' structure. - Sequence <$> traverse (translateLGRHS fam_insts match_loc pp_pats) (grhssGRHSs grhss) - --- | Translate a guarded right-hand side to a single 'GrdTree' -translateLGRHS :: FamInstEnvs -> SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateLGRHS fam_insts match_loc pp_pats (L _loc (GRHS _ gs _)) = - -- _loc points to the match separator (ie =, ->) that comes after the guards.. - mkGrdTreeRhs loc_sdoc <$> concatMapM (translateGuard fam_insts . unLoc) gs - where - loc_sdoc - -- pp_pats is the space-separated pattern of the current Match this - -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . - | null gs = L match_loc pp_pats - | otherwise = L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) - L grd_loc _ = head gs - --- | Translate a guard statement to a 'GrdVec' -translateGuard :: FamInstEnvs -> GuardStmt GhcTc -> DsM GrdVec -translateGuard fam_insts guard = case guard of - BodyStmt _ e _ _ -> translateBoolGuard e - LetStmt _ binds -> translateLet (unLoc binds) - BindStmt _ p e -> translateBind fam_insts p e - LastStmt {} -> panic "translateGuard LastStmt" - ParStmt {} -> panic "translateGuard ParStmt" - TransStmt {} -> panic "translateGuard TransStmt" - RecStmt {} -> panic "translateGuard RecStmt" - ApplicativeStmt {} -> panic "translateGuard ApplicativeLastStmt" - --- | Translate let-bindings -translateLet :: HsLocalBinds GhcTc -> DsM GrdVec -translateLet _binds = return [] - --- | Translate a pattern guard +desugarPatBind :: SrcSpan -> Id -> Pat GhcTc -> DsM GrdPatBind +-- See 'GrdPatBind' for how this simply repurposes GrdGRHS. +desugarPatBind loc var pat = + GrdPatBind . flip GrdGRHS (L loc (ppr pat)) <$> desugarPat var pat + +desugarEmptyCase :: Id -> DsM GrdEmptyCase +desugarEmptyCase var = pure GrdEmptyCase { ge_var = var } + +-- | Desugar the non-empty 'Match'es of a 'MatchGroup'. +desugarMatches :: [Id] -> NonEmpty (LMatch GhcTc (LHsExpr GhcTc)) + -> DsM GrdMatchGroup +desugarMatches vars matches = + GrdMatchGroup <$> traverse (desugarMatch vars) matches + +-- Desugar a single match +desugarMatch :: [Id] -> LMatch GhcTc (LHsExpr GhcTc) -> DsM GrdMatch +desugarMatch vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do + pats' <- concat <$> zipWithM desugarLPat vars pats + grhss' <- desugarGRHSs match_loc (sep (map ppr pats)) grhss + -- tracePm "desugarMatch" (vcat [ppr pats, ppr pats', ppr grhss']) + return GrdMatch { gm_pats = pats', gm_grhss = grhss' } + +desugarGRHSs :: SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM (NonEmpty GrdGRHS) +desugarGRHSs match_loc pp_pats grhss + = traverse (desugarLGRHS match_loc pp_pats) + . expectJust "desugarGRHSs" + . NE.nonEmpty + $ grhssGRHSs grhss + +-- | Desugar a guarded right-hand side to a single 'GrdTree' +desugarLGRHS :: SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdGRHS +desugarLGRHS match_loc pp_pats (L _loc (GRHS _ gs _)) = do + -- _loc points to the match separator (ie =, ->) that comes after the guards. + -- Hence we have to pass in the match_loc, which we use in case that the RHS + -- is unguarded. + -- pp_pats is the space-separated pattern of the current Match this + -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . + let rhs_info = case gs of + [] -> L match_loc pp_pats + (L grd_loc _):_ -> L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) + grds <- concatMapM (desugarGuard . unLoc) gs + pure GrdGRHS { gg_grds = grds, gg_rhs = rhs_info } + +-- | Desugar a guard statement to a 'GrdVec' +desugarGuard :: GuardStmt GhcTc -> DsM GrdVec +desugarGuard guard = case guard of + BodyStmt _ e _ _ -> desugarBoolGuard e + LetStmt _ binds -> desugarLet (unLoc binds) + BindStmt _ p e -> desugarBind p e + LastStmt {} -> panic "desugarGuard LastStmt" + ParStmt {} -> panic "desugarGuard ParStmt" + TransStmt {} -> panic "desugarGuard TransStmt" + RecStmt {} -> panic "desugarGuard RecStmt" + ApplicativeStmt {} -> panic "desugarGuard ApplicativeLastStmt" + +-- | Desugar let-bindings +desugarLet :: HsLocalBinds GhcTc -> DsM GrdVec +desugarLet _binds = return [] + +-- | Desugar a pattern guard -- @pat <- e ==> let x = e; @ -translateBind :: FamInstEnvs -> LPat GhcTc -> LHsExpr GhcTc -> DsM GrdVec -translateBind fam_insts p e = dsLExpr e >>= \case +desugarBind :: LPat GhcTc -> LHsExpr GhcTc -> DsM GrdVec +desugarBind p e = dsLExpr e >>= \case Var y | Nothing <- isDataConId_maybe y -- RHS is a variable, so that will allow us to omit the let - -> translateLPat fam_insts y p + -> desugarLPat y p rhs -> do - (x, grds) <- translateLPatV fam_insts p + (x, grds) <- desugarLPatV p pure (PmLet x rhs : grds) --- | Translate a boolean guard +-- | Desugar a boolean guard -- @e ==> let x = e; True <- x@ -translateBoolGuard :: LHsExpr GhcTc -> DsM GrdVec -translateBoolGuard e +desugarBoolGuard :: LHsExpr GhcTc -> DsM GrdVec +desugarBoolGuard e | isJust (isTrueLHsExpr e) = return [] -- The formal thing to do would be to generate (True <- True) -- but it is trivial to solve so instead we give back an empty @@ -803,7 +788,7 @@ for a pattern match appear matter. Consider a situation similar to T5117: f (0:_) = () f (0:[]) = () -The latter clause is clearly redundant. Yet if we translate the second clause as +The latter clause is clearly redundant. Yet if we desugar the second clause as [x:xs' <- xs, [] <- xs', 0 <- x] @@ -815,52 +800,11 @@ translation would have been And we have to take in the guards on list cells into @mkListGrds at . -Note [Countering exponential blowup] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Precise pattern match exhaustiveness checking is necessarily exponential in -the size of some input programs. We implement a counter-measure in the form of -the -fmax-pmcheck-models flag, limiting the number of Deltas we check against -each pattern by a constant. - -How do we do that? Consider - - f True True = () - f True True = () - -And imagine we set our limit to 1 for the sake of the example. The first clause -will be checked against the initial Delta, {}. Doing so will produce an -Uncovered set of size 2, containing the models {x/~True} and {x~True,y/~True}. -Also we find the first clause to cover the model {x~True,y~True}. - -But the Uncovered set we get out of the match is too huge! We somehow have to -ensure not to make things worse as they are already, so we continue checking -with a singleton Uncovered set of the initial Delta {}. Why is this -sound (wrt. notion of the GADTs Meet their Match paper)? Well, it basically -amounts to forgetting that we matched against the first clause. The values -represented by {} are a superset of those represented by its two refinements -{x/~True} and {x~True,y/~True}. - -This forgetfulness becomes very apparent in the example above: By continuing -with {} we don't detect the second clause as redundant, as it again covers the -same non-empty subset of {}. So we don't flag everything as redundant anymore, -but still will never flag something as redundant that isn't. - -For exhaustivity, the converse applies: We will report @f@ as non-exhaustive -and report @f _ _@ as missing, which is a superset of the actual missing -matches. But soundness means we will never fail to report a missing match. - -This mechanism is implemented in 'throttle'. - -Guards are an extreme example in this regard, with #11195 being a particularly -dreadful example: Since their RHS are often pretty much unique, we split on a -variable (the one representing the RHS) that doesn't occur anywhere else in the -program, so we don't actually get useful information out of that split! - -Note [Translate CoPats] +Note [Desugar CoPats] ~~~~~~~~~~~~~~~~~~~~~~~ -The pattern match checker did not know how to handle coerced patterns `CoPat` -efficiently, which gave rise to #11276. The original approach translated -`CoPat`s: +The pattern match checker did not know how to handle coerced patterns +`CoPat` efficiently, which gave rise to #11276. The original approach +desugared `CoPat`s: pat |> co ===> x (pat <- (x |> co)) @@ -875,108 +819,92 @@ a lot of false warnings. But we can check whether the coercion is a hole or if it is just refl, in which case we can drop it. - -%************************************************************************ -%* * - Utilities for Pattern Match Checking -%* * -%************************************************************************ -} --- ---------------------------------------------------------------------------- --- * Basic utilities - -{- -Note [Extensions to GADTs Meet Their Match] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The GADTs Meet Their Match paper presents the formalism that GHC's coverage -checker adheres to. Since the paper's publication, there have been some -additional features added to the coverage checker which are not described in -the paper. This Note serves as a reference for these new features. - -* Value abstractions are severely simplified to the point where they are just - variables. The information about the shape of a variable is encoded in - the oracle state 'Delta' instead. -* Handling of uninhabited fields like `!Void`. - See Note [Strict argument type constraints] in GHC.HsToCore.PmCheck.Oracle. -* Efficient handling of literal splitting, large enumerations and accurate - redundancy warnings for `COMPLETE` groups through the oracle. - -Note [Filtering out non-matching COMPLETE sets] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Currently, conlikes in a COMPLETE set are simply grouped by the -type constructor heading the return type. This is nice and simple, but it does -mean that there are scenarios when a COMPLETE set might be incompatible with -the type of a scrutinee. For instance, consider (from #14135): - - data Foo a = Foo1 a | Foo2 a - - pattern MyFoo2 :: Int -> Foo Int - pattern MyFoo2 i = Foo2 i - - {-# COMPLETE Foo1, MyFoo2 #-} - - f :: Foo a -> a - f (Foo1 x) = x - -`f` has an incomplete pattern-match, so when choosing which constructors to -report as unmatched in a warning, GHC must choose between the original set of -data constructors {Foo1, Foo2} and the COMPLETE set {Foo1, MyFoo2}. But observe -that GHC shouldn't even consider the COMPLETE set as a possibility: the return -type of MyFoo2, Foo Int, does not match the type of the scrutinee, Foo a, since -there's no substitution `s` such that s(Foo Int) = Foo a. - -To ensure that GHC doesn't pick this COMPLETE set, it checks each pattern -synonym constructor's return type matches the type of the scrutinee, and if one -doesn't, then we remove the whole COMPLETE set from consideration. - -One might wonder why GHC only checks /pattern synonym/ constructors, and not -/data/ constructors as well. The reason is because that the type of a -GADT constructor very well may not match the type of a scrutinee, and that's -OK. Consider this example (from #14059): - - data SBool (z :: Bool) where - SFalse :: SBool False - STrue :: SBool True - - pattern STooGoodToBeTrue :: forall (z :: Bool). () - => z ~ True - => SBool z - pattern STooGoodToBeTrue = STrue - {-# COMPLETE SFalse, STooGoodToBeTrue #-} - - wobble :: SBool z -> Bool - wobble STooGoodToBeTrue = True - -In the incomplete pattern match for `wobble`, we /do/ want to warn that SFalse -should be matched against, even though its type, SBool False, does not match -the scrutinee type, SBool z. - -SG: Another angle at this is that the implied constraints when we instantiate -universal type variables in the return type of a GADT will lead to *provided* -thetas, whereas when we instantiate the return type of a pattern synonym that -corresponds to a *required* theta. See Note [Pattern synonym result type] in -PatSyn. Note how isValidCompleteMatches will successfully filter out - - pattern Just42 :: Maybe Int - pattern Just42 = Just 42 - -But fail to filter out the equivalent - - pattern Just'42 :: (a ~ Int) => Maybe a - pattern Just'42 = Just 42 - -Which seems fine as far as tcMatchTy is concerned, but it raises a few eye -brows. --} +-- +-- * Coverage checking guard trees into annotated trees +-- -{- -%************************************************************************ -%* * - Heart of the algorithm: checkGrdTree -%* * -%************************************************************************ --} +-- | Pattern-match coverage check result +data CheckResult a + = CheckResult + { cr_ret :: !a + -- ^ A hole for redundancy info and covered sets. + , cr_uncov :: !Deltas + -- ^ The set of uncovered values falling out at the bottom. + -- (for -Wincomplete-patterns, but also important state for the algorithm) + , cr_approx :: !Precision + -- ^ A flag saying whether we ran into the 'maxPmCheckModels' limit for the + -- purpose of suggesting to crank it up in the warning message. Writer state. + } deriving Functor + +instance Outputable a => Outputable (CheckResult a) where + ppr (CheckResult c unc pc) + = text "CheckResult" <+> ppr_precision pc <+> braces (fsep + [ field "ret" c <> comma + , field "uncov" unc]) + where + ppr_precision Precise = empty + ppr_precision Approximate = text "(Approximate)" + field name value = text name <+> equals <+> ppr value + +-- | Lift 'addPmCts' over 'Deltas'. +addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas +addPmCtsDeltas deltas cts = liftDeltasM (\d -> addPmCts d cts) deltas + +-- | 'addPmCtsDeltas' for a single 'PmCt'. +addPmCtDeltas :: Deltas -> PmCt -> DsM Deltas +addPmCtDeltas deltas ct = addPmCtsDeltas deltas (unitBag ct) + +-- | Test if any of the 'Delta's is inhabited. Currently this is pure, because +-- we preserve the invariant that there are no uninhabited 'Delta's. But that +-- could change in the future, for example by implementing this function in +-- terms of @notNull <$> provideEvidence 1 ds at . +isInhabited :: Deltas -> DsM Bool +isInhabited (MkDeltas ds) = pure (not (null ds)) + +-- | Coverage checking action. Can be composed 'leftToRight' or 'topToBottom'. +newtype CheckAction a = CA { unCA :: Deltas -> DsM (CheckResult a) } + deriving Functor + +-- | Composes 'CheckAction's top-to-bottom: +-- If a value falls through the resulting action, then it must fall through the +-- first action and then through the second action. +-- If a value matches the resulting action, then it either matches the +-- first action or matches the second action. +-- Basically the semantics of the LYG branching construct. +topToBottom :: (top -> bot -> ret) + -> CheckAction top + -> CheckAction bot + -> CheckAction ret +topToBottom f (CA top) (CA bot) = CA $ \inc -> do + t <- top inc + b <- bot (cr_uncov t) + pure CheckResult { cr_ret = f (cr_ret t) (cr_ret b) + , cr_uncov = cr_uncov b + , cr_approx = cr_approx t Semi.<> cr_approx b } + + +-- | Composes 'CheckAction's left-to-right: +-- If a value falls through the resulting action, then it either falls through the +-- first action or through the second action. +-- If a value matches the resulting action, then it must match the first action +-- and then match the second action. +-- Basically the semantics of the LYG guard construct. +leftToRight :: (RedSets -> right -> ret) + -> CheckAction RedSets + -> CheckAction right + -> CheckAction ret +leftToRight f (CA left) (CA right) = CA $ \inc -> do + l <- left inc + r <- right (rs_cov (cr_ret l)) + limit <- maxPmCheckModels <$> getDynFlags + let uncov = cr_uncov l Semi.<> cr_uncov r + -- See Note [Countering exponential blowup] + let (prec', uncov') = throttle limit inc uncov + pure CheckResult { cr_ret = f (cr_ret l) (cr_ret r) + , cr_uncov = uncov' + , cr_approx = prec' Semi.<> cr_approx l Semi.<> cr_approx r } -- | @throttle limit old new@ returns @old@ if the number of 'Delta's in @new@ -- is exceeding the given @limit@ and the @old@ number of 'Delta's. @@ -994,237 +922,241 @@ conMatchForces (PmAltConLike (RealDataCon dc)) | isNewTyCon (dataConTyCon dc) = False conMatchForces _ = True --- | Makes sure that we only wrap a single 'MayDiverge' around an --- 'AnnotatedTree', purely for esthetic reasons. -mayDiverge :: AnnotatedTree -> AnnotatedTree -mayDiverge a@(MayDiverge _) = a -mayDiverge a = MayDiverge a - --- | Computes two things: --- --- * The set of uncovered values not matched by any of the clauses of the --- 'GrdTree'. Note that 'PmCon' guards are the only way in which values --- fall through from one 'Many' branch to the next. --- * An 'AnnotatedTree' that contains divergence and inaccessibility info --- for all clauses. Will be fed to 'extractRedundancyInfo' for --- presenting redundant and proper innaccessible RHSs, as well as dead --- bangs to the user. -checkGrdTree' :: GrdTree -> Deltas -> DsM CheckResult --- RHS: Check that it covers something and wrap Inaccessible if not -checkGrdTree' (Rhs sdoc) deltas = do - is_covered <- isInhabited deltas - let clauses - | is_covered = AccessibleRhs deltas sdoc - | otherwise = InaccessibleRhs sdoc - pure CheckResult - { cr_clauses = clauses - , cr_uncov = MkDeltas emptyBag - , cr_approx = Precise } --- let x = e: Refine with x ~ e -checkGrdTree' (Guard (PmLet x e) tree) deltas = do - deltas' <- addPmCtDeltas deltas (PmCoreCt x e) - checkGrdTree' tree deltas' --- Bang x: Diverge on x ~ ⊥, refine with x /~ ⊥ -checkGrdTree' (Guard (PmBang x src_bang_info) tree) deltas = do - has_diverged <- addPmCtDeltas deltas (PmBotCt x) >>= isInhabited - deltas' <- addPmCtDeltas deltas (PmNotBotCt x) - res <- checkGrdTree' tree deltas' - let clauses - | not has_diverged - , Just info <- src_bang_info - = RedundantSrcBang info (cr_clauses res) - | has_diverged - = mayDiverge (cr_clauses res) - | otherwise -- won't diverge and it wasn't a source bang - = cr_clauses res - - pure res{ cr_clauses = clauses } - --- Con: Diverge on x ~ ⊥, fall through on x /~ K and refine with x ~ K ys --- and type info -checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do - has_diverged <- - if conMatchForces con - then addPmCtDeltas deltas (PmBotCt x) >>= isInhabited - else pure False - unc_this <- addPmCtDeltas deltas (PmNotConCt x con) - deltas' <- addPmCtsDeltas deltas $ - listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args - -- tracePm "checkGrdTree:Con" (ppr deltas $$ ppr x $$ ppr con $$ ppr dicts $$ ppr deltas') - CheckResult tree' unc_inner prec <- checkGrdTree' tree deltas' - limit <- maxPmCheckModels <$> getDynFlags - let (prec', unc') = throttle limit deltas (unc_this Semi.<> unc_inner) - pure CheckResult - { cr_clauses = applyWhen has_diverged mayDiverge tree' - , cr_uncov = unc' - , cr_approx = prec Semi.<> prec' } --- Sequence: Thread residual uncovered sets from equation to equation -checkGrdTree' (Sequence ts) init_unc = go [] init_unc Precise ts +-- First the functions that correspond to checking LYG primitives: + +checkSequence :: (grdtree -> CheckAction anntree) -> NonEmpty grdtree -> CheckAction (NonEmpty anntree) +-- The implementation is pretty similar to +-- @traverse1 :: Apply f => (a -> f b) -> NonEmpty a -> f (NonEmpty b)@ +checkSequence act (t:|[]) = (:|[]) <$> act t +checkSequence act (t1:|(t2:ts)) = + topToBottom (NE.<|) (act t1) (checkSequence act (t2:|ts)) + +checkGrd :: PmGrd -> CheckAction RedSets +checkGrd grd = CA $ \inc -> case grd of + -- let x = e: Refine with x ~ e + PmLet x e -> do + matched <- addPmCtDeltas inc (PmCoreCt x e) + pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched } + , cr_uncov = mempty + , cr_approx = Precise } + -- Bang x _: Diverge on x ~ ⊥, refine with x /~ ⊥ + PmBang x mb_info -> do + div <- addPmCtDeltas inc (PmBotCt x) + matched <- addPmCtDeltas inc (PmNotBotCt x) + -- See Note [Dead bang patterns] + -- mb_info = Just info <==> PmBang originates from bang pattern in source + let bangs | Just info <- mb_info = unitOL (div, info) + | otherwise = NilOL + pure CheckResult { cr_ret = RedSets { rs_cov = matched, rs_div = div, rs_bangs = bangs } + , cr_uncov = mempty + , cr_approx = Precise } + -- Con: Diverge on x ~ ⊥, fall through on x /~ K and refine with x ~ K ys + -- and type info + PmCon x con tvs dicts args -> do + div <- if conMatchForces con + then addPmCtDeltas inc (PmBotCt x) + else pure mempty + uncov <- addPmCtDeltas inc (PmNotConCt x con) + matched <- addPmCtsDeltas inc $ + listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args + -- tracePm "checkGrd:Con" (ppr inc $$ ppr x $$ ppr con $$ ppr dicts $$ ppr matched) + pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched, rs_div = div } + , cr_uncov = uncov + , cr_approx = Precise } + +checkGrds :: [PmGrd] -> CheckAction RedSets +checkGrds [] = CA $ \inc -> + pure CheckResult { cr_ret = emptyRedSets { rs_cov = inc } + , cr_uncov = mempty + , cr_approx = Precise } +checkGrds (g:grds) = leftToRight merge (checkGrd g) (checkGrds grds) where - -- | Accumulates a CheckResult. Its type is more like - -- @CheckResult -> [GrdTree] -> CheckResult@, but cr_clauses is a single - -- 'AnnotatedTree', not a list thereof. Hence 3 parameters to thread the - -- fields. - go :: [AnnotatedTree] -> Deltas -> Precision -> [GrdTree] -> DsM CheckResult - -- No cases left: Fall through for all values - go ts' unc prec [] = pure CheckResult - { cr_clauses = SequenceAnn init_unc (reverse ts') - , cr_uncov = unc - , cr_approx = prec } - go ts' unc prec (t:ts) = do - CheckResult t' unc_1 prec_t <- checkGrdTree' t unc - go (t':ts') unc_1 (prec_t Semi.<> prec) ts - --- | Print diagnostic info and actually call 'checkGrdTree''. -checkGrdTree :: GrdTree -> Deltas -> DsM CheckResult -checkGrdTree guards deltas = do - tracePm "checkGrdTree {" $ vcat [ ppr guards - , ppr deltas ] - res <- checkGrdTree' guards deltas - tracePm "checkGrdTree }:" (ppr res) -- braces are easier to match by tooling - return res - --- ---------------------------------------------------------------------------- --- * Propagation of term constraints inwards when checking nested matches - -{- Note [Type and Term Equality Propagation] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -When checking a match it would be great to have all type and term information -available so we can get more precise results. For this reason we have functions -`addDictsDs' and `addTmVarCsDs' in GHC.HsToCore.Monad that store in the -environment type and term constraints (respectively) as we go deeper. - -The type constraints we propagate inwards are collected by `collectEvVarsPats' -in GHC.Hs.Pat. This handles bug #4139 ( see example - https://gitlab.haskell.org/ghc/ghc/snippets/672 ) -where this is needed. - -For term equalities we do less, we just generate equalities for HsCase. For -example we accurately give 2 redundancy warnings for the marked cases: - -f :: [a] -> Bool -f x = case x of - - [] -> case x of -- brings (x ~ []) in scope - [] -> True - (_:_) -> False -- can't happen - - (_:_) -> case x of -- brings (x ~ (_:_)) in scope - (_:_) -> True - [] -> False -- can't happen - -Functions `add*ScrutTmCs' is responsible for generating -these constraints. --} + merge ri_g ri_grds = -- This operation would /not/ form a Semigroup! + RedSets { rs_cov = rs_cov ri_grds + , rs_div = rs_div ri_g Semi.<> rs_div ri_grds + , rs_bangs = rs_bangs ri_g Semi.<> rs_bangs ri_grds } --- | Locally update 'dsl_deltas' with the given action, but defer evaluation --- with 'unsafeInterleaveM' in order not to do unnecessary work. -locallyExtendPmDelta :: (Deltas -> DsM Deltas) -> DsM a -> DsM a -locallyExtendPmDelta ext k = do - deltas <- getPmDeltas - deltas' <- unsafeInterleaveM $ do - deltas' <- ext deltas - inh <- isInhabited deltas' - -- If adding a constraint would lead to a contradiction, don't add it. - -- See @Note [Recovering from unsatisfiable pattern-matching constraints]@ - -- for why this is done. - if inh - then pure deltas' - else pure deltas - updPmDeltas deltas' k +checkMatchGroup :: GrdMatchGroup -> CheckAction AnnMatchGroup +checkMatchGroup (GrdMatchGroup matches) = + AnnMatchGroup <$> checkSequence checkMatch matches --- | Add in-scope type constraints if the coverage checker might run and then --- run the given action. -addTyCsDs :: Origin -> Bag EvVar -> DsM a -> DsM a -addTyCsDs origin ev_vars m = do - dflags <- getDynFlags - applyWhen (needToRunPmCheck dflags origin) - (locallyExtendPmDelta (\deltas -> addPmCtsDeltas deltas (PmTyCt . evVarPred <$> ev_vars))) - m +checkMatch :: GrdMatch -> CheckAction AnnMatch +checkMatch (GrdMatch { gm_pats = grds, gm_grhss = grhss }) = + leftToRight AnnMatch (checkGrds grds) (checkGRHSs grhss) --- | Add equalities for the 'CoreExpr' scrutinee to the local 'DsM' environment --- when checking a case expression: --- case e of x { matches } --- When checking matches we record that (x ~ e) where x is the initial --- uncovered. All matches will have to satisfy this equality. -addCoreScrutTmCs :: Maybe CoreExpr -> [Id] -> DsM a -> DsM a -addCoreScrutTmCs Nothing _ k = k -addCoreScrutTmCs (Just scr) [x] k = - flip locallyExtendPmDelta k $ \deltas -> - addPmCtsDeltas deltas (unitBag (PmCoreCt x scr)) -addCoreScrutTmCs _ _ _ = panic "addCoreScrutTmCs: scrutinee, but more than one match id" +checkGRHSs :: NonEmpty GrdGRHS -> CheckAction (NonEmpty AnnGRHS) +checkGRHSs = checkSequence checkGRHS --- | 'addCoreScrutTmCs', but desugars the 'LHsExpr' first. -addHsScrutTmCs :: Maybe (LHsExpr GhcTc) -> [Id] -> DsM a -> DsM a -addHsScrutTmCs Nothing _ k = k -addHsScrutTmCs (Just scr) vars k = do - scr_e <- dsLExpr scr - addCoreScrutTmCs (Just scr_e) vars k +checkGRHS :: GrdGRHS -> CheckAction AnnGRHS +checkGRHS (GrdGRHS { gg_grds = grds, gg_rhs = rhs_info }) = + flip AnnGRHS rhs_info <$> checkGrds grds -{- -%************************************************************************ -%* * - Pretty printing of exhaustiveness/redundancy check warnings -%* * -%************************************************************************ --} +checkEmptyCase :: GrdEmptyCase -> CheckAction AnnEmptyCase +checkEmptyCase (GrdEmptyCase { ge_var = var }) = CA $ \inc -> do + unc <- addPmCtDeltas inc (PmNotBotCt var) + pure CheckResult { cr_ret = AnnEmptyCase, cr_uncov = unc, cr_approx = mempty } --- | Check whether any part of pattern match checking is enabled for this --- 'HsMatchContext' (does not matter whether it is the redundancy check or the --- exhaustiveness check). -isMatchContextPmChecked :: DynFlags -> Origin -> HsMatchContext id -> Bool -isMatchContextPmChecked dflags origin kind - | isGenerated origin - = False - | otherwise - = overlapping dflags kind || exhaustive dflags kind +checkPatBind :: GrdPatBind -> CheckAction AnnPatBind +checkPatBind = coerce checkGRHS --- | Return True when any of the pattern match warnings ('allPmCheckWarnings') --- are enabled, in which case we need to run the pattern match checker. -needToRunPmCheck :: DynFlags -> Origin -> Bool -needToRunPmCheck dflags origin - | isGenerated origin - = False - | otherwise - = notNull (filter (`wopt` dflags) allPmCheckWarnings) +{- Note [Countering exponential blowup] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Precise pattern match exhaustiveness checking is necessarily exponential in +the size of some input programs. We implement a counter-measure in the form of +the -fmax-pmcheck-models flag, limiting the number of Deltas we check against +each pattern by a constant. + +How do we do that? Consider + + f True True = () + f True True = () + +And imagine we set our limit to 1 for the sake of the example. The first clause +will be checked against the initial Delta, {}. Doing so will produce an +Uncovered set of size 2, containing the models {x/~True} and {x~True,y/~True}. +Also we find the first clause to cover the model {x~True,y~True}. + +But the Uncovered set we get out of the match is too huge! We somehow have to +ensure not to make things worse as they are already, so we continue checking +with a singleton Uncovered set of the initial Delta {}. Why is this +sound (wrt. the notion in GADTs Meet Their Match)? Well, it basically amounts +to forgetting that we matched against the first clause. The values represented +by {} are a superset of those represented by its two refinements {x/~True} and +{x~True,y/~True}. + +This forgetfulness becomes very apparent in the example above: By continuing +with {} we don't detect the second clause as redundant, as it again covers the +same non-empty subset of {}. So we don't flag everything as redundant anymore, +but still will never flag something as redundant that isn't. --- | A type for organising information to be used in warnings. -data RedundancyInfo - = RedundancyInfo - { redundant_rhss :: ![SrcInfo] - , inaccessible_rhss :: ![SrcInfo] - , redundant_bangs :: ![Located SDoc] +For exhaustivity, the converse applies: We will report @f@ as non-exhaustive +and report @f _ _@ as missing, which is a superset of the actual missing +matches. But soundness means we will never fail to report a missing match. + +This mechanism is implemented in 'throttle'. + +Guards are an extreme example in this regard, with #11195 being a particularly +dreadful example: Since their RHS are often pretty much unique, we split on a +variable (the one representing the RHS) that doesn't occur anywhere else in the +program, so we don't actually get useful information out of that split! +-} + +-- +-- * Collecting redundancy information +-- + +-- | The result of redundancy checking: +-- * RHSs classified as /C/overed, /I/naccessible and /R/edundant +-- * And redundant (B)ang patterns. +data CIRB + = CIRB + { cirb_cov :: !(OrdList SrcInfo) + , cirb_inacc :: !(OrdList SrcInfo) + , cirb_red :: !(OrdList SrcInfo) + , cirb_bangs :: !(OrdList SrcInfo) } -extractRedundancyInfo :: AnnotatedTree -> RedundancyInfo -extractRedundancyInfo tree = - RedundancyInfo { redundant_rhss = fromOL ol_red - , inaccessible_rhss = fromOL ol_inacc - , redundant_bangs = fromOL ol_bangs } - where - (_ol_acc, ol_inacc, ol_red, ol_bangs) = go tree - -- | Collects - -- 1. accessible RHSs - -- 2. proper inaccessible RHSs (so we can't delete them) - -- 3. hypothetically redundant RHSs (so not only inaccessible, but we can - -- even safely delete the equation without altering semantics) - -- 4. 'Dead' bangs from the source, collected to be warned about - -- See Note [Determining inaccessible clauses] - -- See Note [Dead bang patterns] - go :: AnnotatedTree -> (OrdList SrcInfo, OrdList SrcInfo, OrdList SrcInfo, OrdList SrcInfo) - go (AccessibleRhs _ info) = (unitOL info, nilOL, nilOL , nilOL) - go (InaccessibleRhs info) = (nilOL, nilOL, unitOL info, nilOL) -- presumably redundant - go (MayDiverge t) = case go t of - -- See Note [Determining inaccessible clauses] - (acc, inacc, red, bs) - | isNilOL acc && isNilOL inacc -> (nilOL, red, nilOL, bs) - res -> res - go (SequenceAnn _ ts) = foldMap go ts - go (RedundantSrcBang l t) = case go t of - -- See Note [Dead bang patterns] - res@(acc, inacc, _, _) - | isNilOL acc, isNilOL inacc -> res - | otherwise -> (nilOL, nilOL, nilOL, unitOL l) Semi.<> res +instance Semigroup CIRB where + CIRB a b c d <> CIRB e f g h = CIRB (a <> e) (b <> f) (c <> g) (d <> h) + where (<>) = (Semi.<>) + +instance Monoid CIRB where + mempty = CIRB mempty mempty mempty mempty + +markAllRedundant :: CIRB -> CIRB +markAllRedundant CIRB { cirb_cov = cov, cirb_inacc = inacc, cirb_red = red } = + mempty { cirb_red = cov Semi.<> inacc Semi.<> red } + +-- See Note [Determining inaccessible clauses] +ensureOneNotRedundant :: CIRB -> CIRB +ensureOneNotRedundant ci = case ci of + CIRB { cirb_cov = NilOL, cirb_inacc = NilOL, cirb_red = ConsOL r rs } + -> ci { cirb_inacc = unitOL r, cirb_red = rs } + _ -> ci + +-- | Only adds the redundant bangs to the @CIRB@ if there is at least one +-- non-redundant 'SrcInfo'. There is no point in remembering a redundant bang +-- if the whole match is redundant! +addRedundantBangs :: OrdList SrcInfo -> CIRB -> CIRB +addRedundantBangs _red_bangs cirb at CIRB { cirb_cov = NilOL, cirb_inacc = NilOL } = + cirb +addRedundantBangs red_bangs cirb = + cirb { cirb_bangs = cirb_bangs cirb Semi.<> red_bangs } + +-- | A function that walks along an annotated tree @ann@ and extracts two kinds +-- of coverage info: +-- +-- 1. A 'CIRB', classifying every encountered RHS in the tree as +-- redundant, inaccessible or covered. +-- 2. A piece of long-distance information @ldi@, consisting of a +-- nesting of 'Deltas' mirroring tree structure. +-- For example, 'collectMatchGroup' operates on a Match Group and thus +-- returns a list of 'Deltas' for the pattern part of each Match, as well as +-- a further nested list of 'Deltas' for each of the GRHS of the Match. +type CIRBCollector ann ldi = ann -> DsM (CIRB, ldi) + +-- | Checks the 'Deltas' in a 'RedSets' for inhabitants and returns +-- 1. Whether the Covered set was inhabited +-- 2. Whether the Diverging set was inhabited +-- 3. The new inhabited Covered set for long-distance information. +-- See Note [Recovering from unsatisfiable pattern-matching constraints]. +-- 4. All source bangs whose 'Deltas' were empty, which means they are +-- redundant. +testRedSets :: Deltas -> RedSets -> DsM (Bool, Bool, Deltas, OrdList SrcInfo) +testRedSets ldi RedSets { rs_cov = cov, rs_div = div, rs_bangs = bangs } = do + is_covered <- isInhabited cov + may_diverge <- isInhabited div + red_bangs <- flip mapMaybeM (fromOL bangs) $ \(deltas, bang) -> do + isInhabited deltas >>= \case + True -> pure Nothing + False -> pure (Just bang) + -- See Note [Recovering from unsatisfiable pattern-matching constraints] + -- Deltas for long-distance info: Use (non-empty!) fallback ldi if Covered + -- set was empty + let ldi' + | is_covered = cov + | otherwise = ldi + pure (is_covered, may_diverge, ldi', toOL red_bangs) + +collectMatchGroup :: Deltas -> CIRBCollector AnnMatchGroup (NonEmpty (Deltas, NonEmpty Deltas)) +collectMatchGroup ldi (AnnMatchGroup matches) = do + (cirbs, ldis) <- NE.unzip <$> traverse (collectMatch ldi) matches + pure (Semi.sconcat cirbs, ldis) + +collectMatch :: Deltas -> CIRBCollector AnnMatch (Deltas, NonEmpty Deltas) +collectMatch ldi AnnMatch { am_red = red, am_grhss = grhss } = do + (is_covered, may_diverge, ldi', red_bangs) <- testRedSets ldi red + (cirb, ldis) <- collectGRHSs ldi' grhss + let cirb' = addRedundantBangs red_bangs + -- See Note [Determining inaccessible clauses] + $ applyWhen may_diverge ensureOneNotRedundant + $ applyWhen (not is_covered) markAllRedundant + $ cirb + pure (cirb', (ldi', ldis)) + +collectGRHSs :: Deltas -> CIRBCollector (NonEmpty AnnGRHS) (NonEmpty Deltas) +collectGRHSs ldi grhss = do + (cirbs, ldis) <- NE.unzip <$> traverse (collectGRHS ldi) grhss + pure (Semi.sconcat cirbs, ldis) + +collectGRHS :: Deltas -> CIRBCollector AnnGRHS Deltas +collectGRHS ldi AnnGRHS { ag_red = red, ag_rhs = info } = do + (is_covered, may_diverge, ldi', red_bangs) <- testRedSets ldi red + let cirb | is_covered = mempty { cirb_cov = unitOL info } + | may_diverge = mempty { cirb_inacc = unitOL info } + | otherwise = mempty { cirb_red = unitOL info } + pure (addRedundantBangs red_bangs cirb, ldi') + +collectEmptyCase :: CIRBCollector AnnEmptyCase () +collectEmptyCase _ = pure (mempty, ()) + +collectPatBind :: CIRBCollector AnnPatBind () +-- We don't make use of long-distance information in pattern bindings, hence +-- @()@ instead of some 'Deltas'. +collectPatBind (AnnPatBind grhs) = do + -- use 'mempty' as fallback 'Deltas' because we discard it anyway + (cirb, _) <- collectGRHS mempty grhs + pure (cirb, ()) {- Note [Determining inaccessible clauses] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1239,26 +1171,30 @@ arguments we can ever reach clause 2's RHS, so we say it has inaccessible RHS (as opposed to being completely redundant). We detect an inaccessible RHS simply by pretending it's redundant, until we see -that it's part of a sub-tree in the pattern match that forces some argument -(which corresponds to wrapping the 'AnnotatedTree' in 'MayDiverge'). Then we -turn all supposedly redundant RHSs into inaccessible ones. - -But as it turns out (@g@ from #17465) this is too conservative: - g () | False = () - | otherwise = () -g's first clause has an inaccessible RHS, but it's also safe to delete. So it's -redundant, really! But by just turning all redundant child clauses into -inaccessible ones, we report the first clause as inaccessible. - -Clearly, it is enough if we say that we only degrade if *not all* of the child -clauses are redundant. As long as there is at least one clause which we announce -not to be redundant, the guard prefix responsible for the 'MayDiverge' will -survive. Hence we check for that in 'extractRedundancyInfo'. -} --- | Issue all the warnings (coverage, exhaustiveness, inaccessibility) -dsPmWarn :: DynFlags -> DsMatchContext -> [Id] -> CheckResult -> DsM () -dsPmWarn dflags ctx@(DsMatchContext kind loc) vars result +-- +-- * Formatting and reporting warnings +-- + +-- | Given a 'CIRBCollector', this function will emit warnings for a +-- 'CheckResult' and return the collected long-distance information. +formatReportWarnings :: CIRBCollector ann ldi -> DsMatchContext -> [Id] -> CheckResult ann -> DsM ldi +formatReportWarnings collect ctx vars cr at CheckResult { cr_ret = ann } = do + (cov_info, ldi) <- collect ann + dflags <- getDynFlags + reportWarnings dflags ctx vars cr{cr_ret=cov_info} + pure ldi + +-- | Issue all the warnings +-- (redundancy, inaccessibility, exhaustiveness, redundant bangs). +reportWarnings :: DynFlags -> DsMatchContext -> [Id] -> CheckResult CIRB -> DsM () +reportWarnings dflags ctx@(DsMatchContext kind loc) vars + CheckResult { cr_ret = CIRB { cirb_inacc = inaccessible_rhss + , cirb_red = redundant_rhss + , cirb_bangs = redundant_bangs } + , cr_uncov = uncovered + , cr_approx = precision } = when (flag_i || flag_u || flag_b) $ do unc_examples <- getNFirstUncovered vars (maxPatterns + 1) uncovered let exists_r = flag_i && notNull redundant_rhss @@ -1284,13 +1220,6 @@ dsPmWarn dflags ctx@(DsMatchContext kind loc) vars result when exists_u $ putSrcSpanDs loc $ warnDs flag_u_reason $ pprEqns vars unc_examples where - CheckResult - { cr_clauses = clauses - , cr_uncov = uncovered - , cr_approx = precision } = result - RedundancyInfo{redundant_rhss, inaccessible_rhss, redundant_bangs} - = extractRedundancyInfo clauses - flag_i = overlapping dflags kind flag_u = exhaustive dflags kind flag_b = redundant_bang dflags @@ -1331,44 +1260,30 @@ getNFirstUncovered vars n (MkDeltas deltas) = go n (bagToList deltas) back <- go (n - length front) deltas pure (front ++ back) -{- Note [Inaccessible warnings for record updates] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider (#12957) - data T a where - T1 :: { x :: Int } -> T Bool - T2 :: { x :: Int } -> T a - T3 :: T a - - f :: T Char -> T a - f r = r { x = 3 } - -The desugarer will (conservatively generate a case for T1 even though -it's impossible: - f r = case r of - T1 x -> T1 3 -- Inaccessible branch - T2 x -> T2 3 - _ -> error "Missing" - -We don't want to warn about the inaccessible branch because the programmer -didn't put it there! So we filter out the warning here. - -The same can happen for long distance term constraints instead of type -constraints (#17783): - - data T = A { x :: Int } | B { x :: Int } - f r at A{} = r { x = 3 } - f _ = B 0 - -Here, the long distance info from the FunRhs match (@r ~ A x@) will make the -clause matching on @B@ of the desugaring to @case@ redundant. It's generated -code that we don't want to warn about. --} - dots :: Int -> [a] -> SDoc dots maxPatterns qs | qs `lengthExceeds` maxPatterns = text "..." | otherwise = empty +pprContext :: Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc +pprContext singular (DsMatchContext kind _loc) msg rest_of_msg_fun + = vcat [text txt <+> msg, + sep [ text "In" <+> ppr_match <> char ':' + , nest 4 (rest_of_msg_fun pref)]] + where + txt | singular = "Pattern match" + | otherwise = "Pattern match(es)" + + (ppr_match, pref) + = case kind of + FunRhs { mc_fun = L _ fun } + -> (pprMatchContext kind, \ pp -> ppr fun <+> pp) + _ -> (pprMatchContext kind, \ pp -> pp) + +-- +-- * Utilities +-- + -- | All warning flags that need to run the pattern match checker. allPmCheckWarnings :: [WarningFlag] allPmCheckWarnings = @@ -1411,18 +1326,151 @@ exhaustiveWarningFlag ThPatQuote = Nothing -- etc. They are often *supposed* to be incomplete exhaustiveWarningFlag (StmtCtxt {}) = Nothing --- True <==> singular -pprContext :: Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc -pprContext singular (DsMatchContext kind _loc) msg rest_of_msg_fun - = vcat [text txt <+> msg, - sep [ text "In" <+> ppr_match <> char ':' - , nest 4 (rest_of_msg_fun pref)]] - where - txt | singular = "Pattern match" - | otherwise = "Pattern match(es)" +-- | Check whether any part of pattern match checking is enabled for this +-- 'HsMatchContext' (does not matter whether it is the redundancy check or the +-- exhaustiveness check). +isMatchContextPmChecked :: DynFlags -> Origin -> HsMatchContext id -> Bool +isMatchContextPmChecked dflags origin kind + | isGenerated origin + = False + | otherwise + = overlapping dflags kind || exhaustive dflags kind - (ppr_match, pref) - = case kind of - FunRhs { mc_fun = L _ fun } - -> (pprMatchContext kind, \ pp -> ppr fun <+> pp) - _ -> (pprMatchContext kind, \ pp -> pp) +-- | Return True when any of the pattern match warnings ('allPmCheckWarnings') +-- are enabled, in which case we need to run the pattern match checker. +needToRunPmCheck :: DynFlags -> Origin -> Bool +needToRunPmCheck dflags origin + | isGenerated origin + = False + | otherwise + = notNull (filter (`wopt` dflags) allPmCheckWarnings) + +{- Note [Inaccessible warnings for record updates] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider (#12957) + data T a where + T1 :: { x :: Int } -> T Bool + T2 :: { x :: Int } -> T a + T3 :: T a + + f :: T Char -> T a + f r = r { x = 3 } + +The desugarer will conservatively generate a case for T1 even though +it's impossible: + f r = case r of + T1 x -> T1 3 -- Inaccessible branch + T2 x -> T2 3 + _ -> error "Missing" + +We don't want to warn about the inaccessible branch because the programmer +didn't put it there! So we filter out the warning here. + +The same can happen for long distance term constraints instead of type +constraints (#17783): + + data T = A { x :: Int } | B { x :: Int } + f r at A{} = r { x = 3 } + f _ = B 0 + +Here, the long distance info from the FunRhs match (@r ~ A x@) will make the +clause matching on @B@ of the desugaring to @case@ redundant. It's generated +code that we don't want to warn about. +-} + +-- +-- * Long-distance information +-- + +-- | Locally update 'dsl_deltas' with the given action, but defer evaluation +-- with 'unsafeInterleaveM' in order not to do unnecessary work. +locallyExtendPmDeltas :: (Deltas -> DsM Deltas) -> DsM a -> DsM a +locallyExtendPmDeltas ext k = do + deltas <- getPmDeltas + deltas' <- unsafeInterleaveM $ do + deltas' <- ext deltas + inh <- isInhabited deltas' + -- If adding a constraint would lead to a contradiction, don't add it. + -- See Note [Recovering from unsatisfiable pattern-matching constraints] + -- for why this is done. + if inh + then pure deltas' + else pure deltas + updPmDeltas deltas' k + +-- | Add in-scope type constraints if the coverage checker might run and then +-- run the given action. +addTyCs :: Origin -> Bag EvVar -> DsM a -> DsM a +addTyCs origin ev_vars m = do + dflags <- getDynFlags + applyWhen (needToRunPmCheck dflags origin) + (locallyExtendPmDeltas (\deltas -> addPmCtsDeltas deltas (PmTyCt . evVarPred <$> ev_vars))) + m + +-- | Add equalities for the 'CoreExpr' scrutinee to the local 'DsM' environment +-- when checking a case expression: +-- case e of x { matches } +-- When checking matches we record that (x ~ e) where x is the initial +-- uncovered. All matches will have to satisfy this equality. +addCoreScrutTmCs :: Maybe CoreExpr -> [Id] -> DsM a -> DsM a +addCoreScrutTmCs Nothing _ k = k +addCoreScrutTmCs (Just scr) [x] k = + flip locallyExtendPmDeltas k $ \deltas -> + addPmCtsDeltas deltas (unitBag (PmCoreCt x scr)) +addCoreScrutTmCs _ _ _ = panic "addCoreScrutTmCs: scrutinee, but more than one match id" + +-- | 'addCoreScrutTmCs', but desugars the 'LHsExpr' first. +addHsScrutTmCs :: Maybe (LHsExpr GhcTc) -> [Id] -> DsM a -> DsM a +addHsScrutTmCs Nothing _ k = k +addHsScrutTmCs (Just scr) vars k = do + scr_e <- dsLExpr scr + addCoreScrutTmCs (Just scr_e) vars k + +{- Note [Long-distance information] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider + + data Color = R | G | B + f :: Color -> Int + f R = … + f c = … (case c of + G -> True + B -> False) … + +Humans can make the "long-distance connection" between the outer pattern match +and the nested case pattern match to see that the inner pattern match is +exhaustive: @c@ can't be @R@ anymore because it was matched in the first clause +of @f at . + +To achieve similar reasoning in the coverage checker, we keep track of the set +of values that can reach a particular program point (often loosely referred to +as "Covered set") in 'GHC.HsToCore.Monad.dsl_deltas'. +We fill that set with Covered Deltas returned by the exported checking +functions, which the call sites put into place with +'GHC.HsToCore.Monad.updPmDeltas'. +Call sites also extend this set with facts from type-constraint dictionaries, +case scrutinees, etc. with the exported functions 'addTyCs', 'addCoreScrutTmCs' +and 'addHsScrutTmCs'. + +Note [Recovering from unsatisfiable pattern-matching constraints] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider the following code (see #12957 and #15450): + + f :: Int ~ Bool => () + f = case True of { False -> () } + +We want to warn that the pattern-matching in `f` is non-exhaustive. But GHC +used not to do this; in fact, it would warn that the match was /redundant/! +This is because the constraint (Int ~ Bool) in `f` is unsatisfiable, and the +coverage checker deems any matches with unsatisfiable constraint sets to be +unreachable. + +We can do better than this, by making sure that the Covered set used for +Note [Long-distance information] is always inhabited. +For Covered sets returned by the exported checking functions, that is ensured +in 'testRedSets', which takes and returns a non-empty fallback 'Deltas' in case +the refined Covered set became uninhabited. +Also, whenever "external" knowledge from a type constraint or case scrutinee is +integrated, we only commit that knowledge to 'GHC.HsToCore.Monad.dsl_deltas' if +the set remains inhabited. That check happens in 'locallyExtendPmDeltas'. +-} ===================================== compiler/GHC/HsToCore/PmCheck/Oracle.hs ===================================== @@ -166,25 +166,6 @@ mkOneConFull arg_tys con = do -- * Pattern match oracle -{- Note [Recovering from unsatisfiable pattern-matching constraints] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider the following code (see #12957 and #15450): - - f :: Int ~ Bool => () - f = case True of { False -> () } - -We want to warn that the pattern-matching in `f` is non-exhaustive. But GHC -used not to do this; in fact, it would warn that the match was /redundant/! -This is because the constraint (Int ~ Bool) in `f` is unsatisfiable, and the -coverage checker deems any matches with unsatisfiable constraint sets to be -unreachable. - -We decide to better than this. When beginning coverage checking, we first -check if the constraints in scope are unsatisfiable, and if so, we start -afresh with an empty set of constraints. This way, we'll get the warnings -that we expect. --} - ------------------------------------- -- * Composable satisfiability checks @@ -1265,7 +1246,7 @@ isTyConTriviallyInhabited tc = elementOfUniqSet tc triviallyInhabitedTyCons {- Note [Checking EmptyCase Expressions] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Empty case expressions are strict on the scrutinee. That is, `case x of {}` -will force argument `x`. Hence, `covCheckMatchGroup` is not sufficient for checking +will force argument `x`. Hence, `covCheckMatches` is not sufficient for checking empty cases, because it assumes that the match is not strict (which is true for all other cases, apart from EmptyCase). This gave rise to #10746. Instead, we do the following: ===================================== compiler/GHC/HsToCore/PmCheck/Types.hs ===================================== @@ -592,5 +592,8 @@ instance Outputable Deltas where instance Semigroup Deltas where MkDeltas l <> MkDeltas r = MkDeltas (l `unionBags` r) +instance Monoid Deltas where + mempty = MkDeltas emptyBag + liftDeltasM :: Monad m => (Delta -> m (Maybe Delta)) -> Deltas -> m Deltas liftDeltasM f (MkDeltas ds) = MkDeltas . catBagMaybes <$> (traverse f ds) ===================================== compiler/GHC/Tc/Types.hs ===================================== @@ -323,7 +323,7 @@ data DsLclEnv = DsLclEnv { dsl_meta :: DsMetaEnv, -- Template Haskell bindings dsl_loc :: RealSrcSpan, -- To put in pattern-matching error msgs - -- See Note [Note [Type and Term Equality Propagation] in "GHC.HsToCore.PmCheck" + -- See Note [Note [Long-distance information] in "GHC.HsToCore.PmCheck" -- The set of reaching values Deltas is augmented as we walk inwards, -- refined through each pattern match in turn dsl_deltas :: Deltas ===================================== compiler/GHC/Utils/Misc.hs ===================================== @@ -556,9 +556,8 @@ isSingleton :: [a] -> Bool isSingleton [_] = True isSingleton _ = False -notNull :: [a] -> Bool -notNull [] = False -notNull _ = True +notNull :: Foldable f => f a -> Bool +notNull = not . null only :: [a] -> a #if defined(DEBUG) ===================================== testsuite/tests/deSugar/should_compile/ds020.stderr ===================================== @@ -18,3 +18,11 @@ ds020.hs:20:1: warning: [-Woverlapping-patterns (in -Wdefault)] ds020.hs:23:1: warning: [-Woverlapping-patterns (in -Wdefault)] Pattern match is redundant In an equation for ‘f’: f x@(~[]) = ... + +ds020.hs:32:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: (x1 : xs1 : ys1) = ... + +ds020.hs:33:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: (~x : ~xs : ~ys) = ... ===================================== testsuite/tests/module/all.T ===================================== @@ -83,7 +83,7 @@ test('mod61', normal, compile_fail, ['']) test('mod62', normal, compile_fail, ['']) test('mod63', normal, compile_fail, ['']) test('mod64', normal, compile, ['']) -test('mod65', normal, compile, ['']) +test('mod65', normal, compile, ['-Wno-overlapping-patterns']) test('mod66', normal, compile_fail, ['']) test('mod67', normal, compile_fail, ['']) test('mod68', normal, compile_fail, ['']) ===================================== testsuite/tests/pmcheck/should_compile/T18572.hs ===================================== @@ -3,10 +3,10 @@ module T18572 where -True = True +True = True -- no warning data SBool (b :: Bool) where STrue :: SBool True SFalse :: SBool False -STrue = SFalse +STrue = SFalse -- "redundant", not "inaccessible" ===================================== testsuite/tests/rename/should_compile/T7085.stderr ===================================== @@ -1,3 +1,7 @@ T7085.hs:8:6: warning: [-Wunused-pattern-binds (in -Wextra, -Wunused-binds)] This pattern-binding binds no variables: Nothing = Just n + +T7085.hs:8:6: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: Nothing = ... ===================================== testsuite/tests/unboxedsums/all.T ===================================== @@ -30,5 +30,5 @@ test('T12711', only_ways(['ghci']), ghci_script, ['T12711.script']) # extra_files([ "unboxedsums" + str(i) + ".hs" for i in range(1, 12) ])], # makefile_test, []) -test('UbxSumLevPoly', normal, compile, ['']) +test('UbxSumLevPoly', normal, compile, ['-Wno-overlapping-patterns']) test('T14051', normal, multi_compile, ['T14051.hs', [('T14051a.hs', '')], '-O2 -v0']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b5a6da4b59318107db0c24224bf7963bc87d02cf -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b5a6da4b59318107db0c24224bf7963bc87d02cf You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 28 13:00:49 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Fri, 28 Aug 2020 09:00:49 -0400 Subject: [Git][ghc/ghc][wip/T18341] 16 commits: PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Message-ID: <5f4900012ed7f_80b3f8496276eec9723831@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18341 at Glasgow Haskell Compiler / GHC Commits: b5a6da4b by Sebastian Graf at 2020-08-28T11:37:15+02:00 PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Previously, we desugared and coverage checked plain guard trees as described in Lower Your Guards. That caused (in !3849) quite a bit of pain when we need to partially recover tree structure of the input syntax to return covered sets for long-distance information, for example. In this refactor, I introduced a guard tree variant for each relevant source syntax component of a pattern-match (mainly match groups, match, GRHS, empty case, pattern binding). I made sure to share as much coverage checking code as possible, so that the syntax-specific checking functions are just wrappers around the more substantial checking functions for the LYG primitives (`checkSequence`, `checkGrds`). The refactoring payed off in clearer code and elimination of all panics related to assumed guard tree structure and thus fixes #18565. I also took the liberty to rename and re-arrange the order of functions and comments in the module, deleted some dead and irrelevant Notes, wrote some new ones and gave an overview module haddock. - - - - - 1ac60f60 by Sebastian Graf at 2020-08-28T11:41:58+02:00 Fix #18341 - - - - - fb066ef4 by Sebastian Graf at 2020-08-28T11:41:58+02:00 Make PmConCt lazy and preserve ⊥ - - - - - 8ed86d04 by Sebastian Graf at 2020-08-28T11:41:58+02:00 Fix a few bugs - - - - - ddb51796 by Sebastian Graf at 2020-08-28T11:41:58+02:00 Accept tests - - - - - 33c7c4f9 by Sebastian Graf at 2020-08-28T11:41:58+02:00 Add regression test for #18341 - - - - - 27cb92d0 by Sebastian Graf at 2020-08-28T11:41:58+02:00 Add regression test for #17725 - - - - - 95db9b7e by Sebastian Graf at 2020-08-28T11:41:58+02:00 Add regression test for #17378 - - - - - 1c88a138 by Sebastian Graf at 2020-08-28T11:41:58+02:00 Add regression test for #10183 - - - - - 1f6c6c17 by Sebastian Graf at 2020-08-28T11:41:58+02:00 Add regression test for #17729 - - - - - 9a5e4653 by Sebastian Graf at 2020-08-28T11:41:58+02:00 Add regression test for fixed #18273 - - - - - e55a62dd by Sebastian Graf at 2020-08-28T11:41:58+02:00 Refactor ensureInhabited and resolve a scoping bug from the previous refactor - - - - - 40c39c8f by Sebastian Graf at 2020-08-28T11:56:39+02:00 review feedback - - - - - 67f24014 by Sebastian Graf at 2020-08-28T12:21:50+02:00 Rename Delta to Nabla - - - - - 44eeaa08 by Sebastian Graf at 2020-08-28T13:28:17+02:00 A bit of cleanup - - - - - 5390abaa by Sebastian Graf at 2020-08-28T15:00:35+02:00 Accept the change to T17340 - - - - - 10 changed files: - .gitignore - compiler/GHC/Core/DataCon.hs - compiler/GHC/Data/Bag.hs - compiler/GHC/Data/OrdList.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/GuardedRHSs.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/Monad.hs - compiler/GHC/HsToCore/PmCheck.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9eb1f47ae367b973948acb4d5e595722b3cc5de6...5390abaafec8bb8328f3db96aa322da505c980fa -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9eb1f47ae367b973948acb4d5e595722b3cc5de6...5390abaafec8bb8328f3db96aa322da505c980fa You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 28 14:29:21 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Fri, 28 Aug 2020 10:29:21 -0400 Subject: [Git][ghc/ghc][wip/T18341] Literal expressions can't diverge Message-ID: <5f4914c1fc8e_80b3f849258088097251ee@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18341 at Glasgow Haskell Compiler / GHC Commits: 3833b5e8 by Sebastian Graf at 2020-08-28T16:29:14+02:00 Literal expressions can't diverge - - - - - 1 changed file: - compiler/GHC/HsToCore/PmCheck/Oracle.hs Changes: ===================================== compiler/GHC/HsToCore/PmCheck/Oracle.hs ===================================== @@ -1759,8 +1759,12 @@ addCoreCt nabla x e = do pm_alt_con_app x (PmAltConLike (RealDataCon dc)) ex_tvs arg_ids -- | Adds a literal constraint, i.e. @x ~ 42 at . + -- Also we assume that literal expressions won't diverge, so this + -- will add a @x ~/ ⊥@ constraint. pm_lit :: Id -> PmLit -> StateT Nabla (MaybeT DsM) () - pm_lit x lit = pm_alt_con_app x (PmAltLit lit) [] [] + pm_lit x lit = do + modifyT $ \nabla -> addNotBotCt nabla x + pm_alt_con_app x (PmAltLit lit) [] [] -- | Adds the given constructor application as a solution for @x at . pm_alt_con_app :: Id -> PmAltCon -> [TyVar] -> [Id] -> StateT Nabla (MaybeT DsM) () View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3833b5e89ae151c54b6e2fa1c516157093b97cd8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3833b5e89ae151c54b6e2fa1c516157093b97cd8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 28 19:24:12 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Fri, 28 Aug 2020 15:24:12 -0400 Subject: [Git][ghc/ghc][wip/T18603] 18 commits: Add a test for #18397 Message-ID: <5f4959dc72b61_80b3f8486181f249735842@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18603 at Glasgow Haskell Compiler / GHC Commits: a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 0a1ecc5f by Ben Gamari at 2020-08-25T07:37:05-04:00 SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' In #18069 we are observing MVar deadlocks from somewhere in ghc.exe. This use of MVar stood out as being one of the more likely culprits. Here we make sure that it is exception-safe. - - - - - db8793ad by Richard Eisenberg at 2020-08-25T07:37:40-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - fb77207a by Simon Peyton Jones at 2020-08-25T07:38:16-04:00 Use LIdP rather than (XRec p (IdP p)) This patch mainly just replaces use of XRec p (IdP p) with LIdP p One slightly more significant change is to parameterise HsPatSynDetails over the pass rather than the argument type, so that it's uniform with HsConDeclDetails and HsConPatDetails. I also got rid of the dead code GHC.Hs.type.conDetailsArgs But this is all just minor refactoring. No change in functionality. - - - - - 8426a136 by Krzysztof Gogolewski at 2020-08-25T07:38:54-04:00 Add a test for #18585 - - - - - 2d635a50 by Takenobu Tani at 2020-08-26T04:50:21-04:00 linters: Make CPP linter skip image files This patch adds an exclusion rule for `docs/users_guide/images`, to avoid lint errors of PDF files. - - - - - b7d98cb2 by Takenobu Tani at 2020-08-26T04:50:21-04:00 users-guide: Color the logo on the front page of the PDF This patch updates the logo with a recent color scheme. This affects only the PDF version of the user's guide. See also: * https://mail.haskell.org/pipermail/ghc-devs/2020-August/019139.html * https://gitlab.haskell.org/ghc/ghc/-/wikis/logo - - - - - 0b17fa18 by Sylvain Henry at 2020-08-26T04:50:58-04:00 Refactor UnitId pretty-printing When we pretty-print a UnitId for the user, we try to map it back to its origin package name, version and component to print "package-version:component" instead of some hash. The UnitId type doesn't carry these information, so we have to look into a UnitState to find them. This is why the Outputable instance of UnitId used `sdocWithDynFlags` in order to access the `unitState` field of DynFlags. This is wrong for several reasons: 1. The DynFlags are accessed when the message is printed, not when it is generated. So we could imagine that the unitState may have changed in-between. Especially if we want to allow unit unloading. 2. We want GHC to support several independent sessions at once, hence several UnitState. The current approach supposes there is a unique UnitState as a UnitId doesn't indicate which UnitState to use. See the Note [Pretty-printing UnitId] in GHC.Unit for the new approach implemented by this patch. One step closer to remove `sdocDynFlags` field from `SDocContext` (#10143). Fix #18124. Also fix some Backpack code to use SDoc instead of String. - - - - - dc476a50 by Sylvain Henry at 2020-08-26T04:51:35-04:00 Bignum: fix BigNat subtraction (#18604) There was a confusion between the boolean expected by withNewWordArrayTrimedMaybe and the boolean returned by subtracting functions. - - - - - fcb10b6c by Peter Trommler at 2020-08-26T10:42:30-04:00 PPC and X86: Portable printing of IEEE floats GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness. This was brought up in #18431 by @hsyl20. - - - - - 770100e0 by Krzysztof Gogolewski at 2020-08-26T10:43:13-04:00 primops: Remove Monadic and Dyadic categories There were four categories of primops: Monadic, Dyadic, Compare, GenPrimOp. The compiler does not treat Monadic and Dyadic in any special way, we can just replace them with GenPrimOp. Compare is still used in isComparisonPrimOp. - - - - - 01ff8c89 by Aditya Gupta at 2020-08-27T14:19:26-04:00 Consolidate imports in getMinimalImports (#18264) - - - - - bacccb73 by Ryan Scott at 2020-08-27T14:20:01-04:00 Make {hsExpr,hsType,pat}NeedsParens aware of boxed 1-tuples `hsExprNeedsParens`, `hsTypeNeedsParens`, and `patNeedsParens` previously assumed that all uses of explicit tuples in the source syntax never need to be parenthesized. This is true save for one exception: boxed one-tuples, which use the `Solo` data type from `GHC.Tuple` instead of special tuple syntax. This patch adds the necessary logic to the three `*NeedsParens` functions to handle `Solo` correctly. Fixes #18612. - - - - - c6f50cea by Krzysztof Gogolewski at 2020-08-28T02:22:36-04:00 Add missing primop documentation (#18454) - Add three pseudoops to primops.txt.pp, so that Haddock renders the documentation - Update comments - Remove special case for "->" - it's no longer exported from GHC.Prim - Remove reference to Note [Compiling GHC.Prim] - the ad-hoc fix is no longer there after updates to levity polymorphism. - Document GHC.Prim - Remove the comment that lazy is levity-polymorphic. As far as I can tell, it never was: in 80e399639, only the unfolding was given an open type variable. - Remove haddock hack in GHC.Magic - no longer neccessary after adding realWorld# to primops.txt.pp. - - - - - f065b6b0 by Tamar Christina at 2020-08-28T02:23:13-04:00 Fix use distro toolchian - - - - - 4517a382 by Tamar Christina at 2020-08-28T02:23:13-04:00 document how build system find toolchains on Windows - - - - - feefabc0 by Simon Peyton Jones at 2020-08-28T20:23:51+01:00 Work in progress on #18603 Occurrence analysis - - - - - 30 changed files: - .gitlab/linters/check-cpp.py - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/CmmToAsm/Dwarf.hs - compiler/GHC/CmmToAsm/PPC/Ppr.hs - compiler/GHC/CmmToAsm/Ppr.hs - compiler/GHC/CmmToAsm/SPARC/Ppr.hs - compiler/GHC/CmmToAsm/X86/Ppr.hs - compiler/GHC/Core/FVs.hs - compiler/GHC/Core/Opt/OccurAnal.hs - compiler/GHC/Core/Type.hs - compiler/GHC/Core/Unify.hs - compiler/GHC/Driver/Backpack.hs - compiler/GHC/Driver/Finder.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Ppr.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Driver/Types.hs - compiler/GHC/Hs/Binds.hs - compiler/GHC/Hs/Decls.hs - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Extension.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Hs/Type.hs - compiler/GHC/Hs/Utils.hs - compiler/GHC/HsToCore/Match/Constructor.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/8e332d669a6a53819f2eac0be16374f5a4fc26d2...feefabc050658b558652555dc944e538f209983a -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/8e332d669a6a53819f2eac0be16374f5a4fc26d2...feefabc050658b558652555dc944e538f209983a You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Fri Aug 28 22:41:31 2020 From: gitlab at gitlab.haskell.org (Simon Peyton Jones) Date: Fri, 28 Aug 2020 18:41:31 -0400 Subject: [Git][ghc/ghc][wip/T18603] Wibbles Message-ID: <5f49881b9cc17_80b1157a4ac97362d7@gitlab.haskell.org.mail> Simon Peyton Jones pushed to branch wip/T18603 at Glasgow Haskell Compiler / GHC Commits: ca76dac5 by Simon Peyton Jones at 2020-08-28T23:40:27+01:00 Wibbles - - - - - 1 changed file: - compiler/GHC/Core/Opt/OccurAnal.hs Changes: ===================================== compiler/GHC/Core/Opt/OccurAnal.hs ===================================== @@ -878,7 +878,7 @@ occAnalRecBind :: OccEnv -> TopLevelFlag -> ImpRuleEdges -> [(Var,CoreExpr)] -- * feed those components to occAnalRec -- See Note [Recursive bindings: the grand plan] occAnalRecBind env lvl imp_rule_edges pairs body_usage - = foldr (occAnalRec rhs_env lvl rule_fv_env) (body_usage, []) sccs + = foldr (occAnalRec rhs_env lvl) (body_usage, []) sccs where sccs :: [SCC Details] sccs = {-# SCC "occAnalBind.scc" #-} @@ -892,17 +892,6 @@ occAnalRecBind env lvl imp_rule_edges pairs body_usage bndr_set = mkVarSet bndrs rhs_env = env `addInScope` bndrs - rule_fv_env :: RuleFvEnv - -- Maps a variable f to the variables from this group - -- mentioned in RHS of /active/ rules for f - -- Domain is *subset* of bound vars (others have no rule fvs) - rule_fv_env -- See Note [Finding rule RHS free vars] - = mkVarEnv [ (b, rule_fvs) - | (node_payload -> ND { nd_bndr = b - , nd_active_rule_fvs = rule_fvs }) <- nodes - , not (isEmptyVarSet rule_fvs) ] - - {- Note [Unfoldings and join points] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -913,33 +902,30 @@ calls for the purpose of finding join points. -} ----------------------------- -occAnalRec :: OccEnv -> TopLevelFlag -> RuleFvEnv +occAnalRec :: OccEnv -> TopLevelFlag -> SCC Details -> (UsageDetails, [CoreBind]) -> (UsageDetails, [CoreBind]) -- The NonRec case is just like a Let (NonRec ...) above -occAnalRec _ lvl rule_fv_env - (AcyclicSCC (ND { nd_bndr = bndr, nd_rhs = rhs, nd_inl = inl_fvs - , nd_uds = rhs_uds, nd_rhs_bndrs = rhs_bndrs })) +occAnalRec _ lvl (AcyclicSCC (ND { nd_bndr = bndr, nd_rhs = rhs + , nd_uds = rhs_uds, nd_rhs_bndrs = rhs_bndrs })) (body_uds, binds) | not (bndr `usedIn` body_uds) = (body_uds, binds) -- See Note [Dead code] | otherwise -- It's mentioned in the body = (body_uds' `andUDs` rhs_uds', - NonRec final_bndr rhs : binds) + NonRec tagged_bndr rhs : binds) where (body_uds', tagged_bndr) = tagNonRecBinder lvl body_uds bndr - final_bndr = setNonRecLoopBreaker lvl rule_fv_env inl_fvs tagged_bndr rhs_uds' = adjustRhsUsage NonRecursive (willBeJoinId_maybe tagged_bndr) rhs_bndrs rhs_uds -- The Rec case is the interesting one -- See Note [Recursive bindings: the grand plan] -- See Note [Loop breaking] -occAnalRec env lvl rule_fv_env - (CyclicSCC details_s) (body_uds, binds) +occAnalRec env lvl (CyclicSCC details_s) (body_uds, binds) | not (any (`usedIn` body_uds) bndrs) -- NB: look at body_uds, not total_uds = (body_uds, binds) -- See Note [Dead code] @@ -950,15 +936,14 @@ occAnalRec env lvl rule_fv_env (final_uds, Rec pairs : binds) where - bndrs = map nd_bndr details_s - bndr_set = mkVarSet bndrs + bndrs = map nd_bndr details_s ------------------------------ - -- See Note [Choosing loop breakers] for loop_breaker_nodes + -- Make the nodes for the loop-breaker analysis + -- See Note [Choosing loop breakers] for loop_breaker_nodes final_uds :: UsageDetails loop_breaker_nodes :: [LetrecNode] - (final_uds, loop_breaker_nodes) - = mkLoopBreakerNodes env lvl rule_fv_env body_uds details_s + (final_uds, loop_breaker_nodes) = mkLoopBreakerNodes env lvl body_uds details_s ------------------------------ weak_fvs :: VarSet @@ -967,8 +952,8 @@ occAnalRec env lvl rule_fv_env --------------------------- -- Now reconstruct the cycle pairs :: [(Id,CoreExpr)] - pairs | isEmptyVarSet weak_fvs = reOrderNodes 0 bndr_set weak_fvs loop_breaker_nodes [] - | otherwise = loopBreakNodes 0 bndr_set weak_fvs loop_breaker_nodes [] + pairs | isEmptyVarSet weak_fvs = reOrderNodes 0 weak_fvs loop_breaker_nodes [] + | otherwise = loopBreakNodes 0 weak_fvs loop_breaker_nodes [] -- If weak_fvs is empty, the loop_breaker_nodes will include -- all the edges in the original scope edges [remember, -- weak_fvs is the difference between scope edges and @@ -981,20 +966,9 @@ occAnalRec env lvl rule_fv_env -- Loop breaking ------------------------------------------------------------------ -setNonRecLoopBreaker :: TopLevelFlag -> RuleFvEnv -> VarSet -> Id -> Id --- See Note [Non-recursive loop breakers] -setNonRecLoopBreaker lvl rule_fv_env inl_fvs bndr - | isTopLevel lvl -- Only relevant for top-level binders - -- since nested binders are never in rng(rule_fv_env) - , rule_loop = mk_loop_breaker bndr - | otherwise = bndr - where - rule_loop = bndr `elemVarSet` extendFvs_ rule_fv_env inl_fvs - type Binding = (Id,CoreExpr) loopBreakNodes :: Int - -> VarSet -- All binders -> VarSet -- Binders whose dependencies may be "missing" -- See Note [Weak loop breakers] -> [LetrecNode] @@ -1018,7 +992,7 @@ recording inlinings for any Ids which aren't marked as "no-inline" as it goes. -} -- Return the bindings sorted into a plausible order, and marked with loop breakers. -loopBreakNodes depth bndr_set weak_fvs nodes binds +loopBreakNodes depth weak_fvs nodes binds = -- pprTrace "loopBreakNodes" (ppr nodes) $ go (stronglyConnCompFromEdgedVerticesUniqR nodes) where @@ -1028,18 +1002,18 @@ loopBreakNodes depth bndr_set weak_fvs nodes binds loop_break_scc scc binds = case scc of AcyclicSCC node -> nodeBinding (mk_non_loop_breaker weak_fvs) node : binds - CyclicSCC nodes -> reOrderNodes depth bndr_set weak_fvs nodes binds + CyclicSCC nodes -> reOrderNodes depth weak_fvs nodes binds ---------------------------------- -reOrderNodes :: Int -> VarSet -> VarSet -> [LetrecNode] -> [Binding] -> [Binding] +reOrderNodes :: Int -> VarSet -> [LetrecNode] -> [Binding] -> [Binding] -- Choose a loop breaker, mark it no-inline, -- and call loopBreakNodes on the rest -reOrderNodes _ _ _ [] _ = panic "reOrderNodes" -reOrderNodes _ _ _ [node] binds = nodeBinding mk_loop_breaker node : binds -reOrderNodes depth bndr_set weak_fvs (node : nodes) binds +reOrderNodes _ _ [] _ = panic "reOrderNodes" +reOrderNodes _ _ [node] binds = nodeBinding mk_loop_breaker node : binds +reOrderNodes depth weak_fvs (node : nodes) binds = -- pprTrace "reOrderNodes" (vcat [ text "unchosen" <+> ppr unchosen -- , text "chosen" <+> ppr chosen_nodes ]) $ - loopBreakNodes new_depth bndr_set weak_fvs unchosen $ + loopBreakNodes new_depth weak_fvs unchosen $ (map (nodeBinding mk_loop_breaker) chosen_nodes ++ binds) where (chosen_nodes, unchosen) = chooseLoopBreaker approximate_lb @@ -1270,7 +1244,8 @@ data Details -- dependencies might not be respected by loop_breaker_nodes -- See Note [Weak loop breakers] - , nd_active_rule_fvs :: IdSet -- Free variables of the RHS of active RULES + , nd_active_rule_fvs :: IdSet -- Variables bound in this Rec group that are free + -- in the RHS of an active rule for this bndr , nd_score :: NodeScore } @@ -1281,7 +1256,7 @@ instance Outputable Details where , text "uds =" <+> ppr (nd_uds nd) , text "inl =" <+> ppr (nd_inl nd) , text "weak =" <+> ppr (nd_weak nd) - , text "rule =" <+> ppr (nd_active_rule_fvs nd) + , text "rule_rvs =" <+> ppr (nd_active_rule_fvs nd) , text "score =" <+> ppr (nd_score nd) ]) @@ -1315,7 +1290,7 @@ makeNode env imp_rule_edges bndr_set (bndr, rhs) , nd_uds = rhs_usage , nd_inl = inl_fvs , nd_weak = node_fvs `minusVarSet` inl_fvs - , nd_active_rule_fvs = active_rule_fvs `intersectVarSet` bndr_set + , nd_active_rule_fvs = active_rule_fvs , nd_score = pprPanic "makeNodeDetails" (ppr bndr) } bndr' = bndr `setIdUnfolding` unf' @@ -1348,7 +1323,6 @@ makeNode env imp_rule_edges bndr_set (bndr, rhs) unf = realIdUnfolding bndr -- realIdUnfolding: Ignore loop-breaker-ness -- here because that is what we are setting! (unf_uds, unf') = occAnalUnfolding rhs_env Recursive mb_join_arity unf - inl_fvs = restrictFreeVars bndr_set (inlineFreeVars unf unf_uds rhs_uds) --------- Rules --------- rules_w_uds :: [(CoreRule, UsageDetails, UsageDetails)] @@ -1361,6 +1335,16 @@ makeNode env imp_rule_edges bndr_set (bndr, rhs) Nothing -> emptyDetails Just vs -> addManyOccs emptyDetails vs + --------- Loop-breaker analysis dependencies + inl_uds | isStableUnfolding unf = unf_uds + | otherwise = rhs_uds + inl_fvs = udFreeVars bndr_set inl_uds + -- inl_fvs: the vars that would become free if the function was inlined; + -- usually that means the RHS, unless the unfolding is a stable one. + -- Note: We could do this only for functions with an *active* unfolding + -- (returning emptyVarSet for an inactive one), but is_active + -- isn't the right thing (it tells about RULE activation), + -- so we'd need more plumbing is_active = occ_rule_act env :: Activation -> Bool imp_rule_fvs = udFreeVars bndr_set imp_rule_uds @@ -1371,35 +1355,21 @@ makeNode env imp_rule_edges bndr_set (bndr, rhs) | otherwise = fvs -inlineFreeVars :: Unfolding - -> UsageDetails -- Of the unfolding - -> UsageDetails -- Of the RHS - -> OccInfoEnv --- Find the UsageDetails that would become free if the function --- was inlined; usually that means the RHS, unless the --- unfolding is a stable one. --- Note: We could do this only for functions with an *active* unfolding --- (returning emptyVarSet for an inactive one), but is_active --- isn't the right thing (it tells about RULE activation), --- so we'd need more plumbing -inlineFreeVars unf unf_uds rhs_uds - | isStableUnfolding unf = ud_env unf_uds - | otherwise = ud_env rhs_uds mkLoopBreakerNodes :: OccEnv -> TopLevelFlag - -> RuleFvEnv -> UsageDetails -- for BODY of let -> [Details] -> (UsageDetails, -- adjusted [LetrecNode]) --- Does four things +-- This function primarily creates the Nodes for the +-- loop-breaker SCC analysis. More specifically: -- a) tag each binder with its occurrence info -- b) add a NodeScore to each node -- c) make a Node with the right dependency edges for -- the loop-breaker SCC analysis -- d) adjust each RHS's usage details according to -- the binder's (new) shotness and join-point-hood -mkLoopBreakerNodes env lvl rule_fv_env body_uds details_s +mkLoopBreakerNodes env lvl body_uds details_s = (final_uds, zipWithEqual "mkLoopBreakerNodes" mk_lb_node details_s bndrs') where (final_uds, bndrs') @@ -1409,7 +1379,7 @@ mkLoopBreakerNodes env lvl rule_fv_env body_uds details_s <- details_s ] mk_lb_node nd@(ND { nd_bndr = old_bndr, nd_inl = inl_fvs }) new_bndr - = DigraphNode { node_payload = nd' + = DigraphNode { node_payload = new_nd , node_key = varUnique old_bndr , node_dependencies = nonDetKeysUniqSet lb_deps } -- It's OK to use nonDetKeysUniqSet here as @@ -1417,11 +1387,37 @@ mkLoopBreakerNodes env lvl rule_fv_env body_uds details_s -- in nondeterministic order as explained in -- Note [Deterministic SCC] in GHC.Data.Graph.Directed. where - nd' = nd { nd_bndr = new_bndr, nd_score = score } - score = nodeScore env new_bndr lb_deps nd + new_nd = nd { nd_bndr = new_bndr, nd_score = score } + score = nodeScore env new_bndr lb_deps nd lb_deps = extendFvs_ rule_fv_env inl_fvs + -- See Note [Loop breaker dependencies] + + rule_fv_env :: IdEnv IdSet + -- Maps a variable f to the variables from this group + -- reachable by a sequence of RULES starting with f + -- Domain is *subset* of bound vars (others have no rule fvs) + -- See Note [Finding rule RHS free vars] + rule_fv_env = transClosureFV $ mkVarEnv $ + [ (b, rule_fvs) + | ND { nd_bndr = b, nd_active_rule_fvs = rule_fvs } <- details_s + , not (isEmptyVarSet rule_fvs) ] + +{- Note [Loop breaker dependencies] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The loop breaker dependencies of x in a recursive +group { f1 = e1; ...; fn = en } are: +- The "inline free variables" of f: the fi free in + either f's unfolding (if f has a stable unfolding) + of f's RHS (if not) +- Any fi reachable from those inline free variables by a sequence + of RULE rewrites. Remember, rule rewriting is not affected + by fi being a loop breaker, so we have to take the transitive + closure in case f is the only possible loop breaker in the loop. + + Hence rule_fv_env. We need only account for /active/ rules. +-} ------------------------------------------ nodeScore :: OccEnv @@ -2301,7 +2297,7 @@ addAppCtxt :: OccEnv -> [Arg CoreBndr] -> OccEnv addAppCtxt env@(OccEnv { occ_one_shots = ctxt }) args = env { occ_one_shots = replicate (valArgCount args) OneShotLam ++ ctxt } -{- +-------------------- transClosureFV :: VarEnv VarSet -> VarEnv VarSet -- If (f,g), (g,h) are in the input, then (f,h) is in the output -- as well as (f,g), (g,h) @@ -2317,7 +2313,7 @@ transClosureFV env | otherwise = (False, (b,new_fvs)) where (new_fvs, no_change_here) = extendFvs env fvs --} + ------------- extendFvs_ :: VarEnv VarSet -> VarSet -> VarSet extendFvs_ env s = fst (extendFvs env s) -- Discard the Bool flag View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ca76dac5b0162c7a7388dd8f9a9ca4c070df4666 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ca76dac5b0162c7a7388dd8f9a9ca4c070df4666 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 29 06:18:22 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Sat, 29 Aug 2020 02:18:22 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/buggymcbugfix/insertArray Message-ID: <5f49f32e191f9_80b3f848707c68c97370e7@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed new branch wip/buggymcbugfix/insertArray at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/buggymcbugfix/insertArray You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 29 06:21:09 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Sat, 29 Aug 2020 02:21:09 -0400 Subject: [Git][ghc/ghc][wip/buggymcbugfix/insertArray] 531 commits: Clean up boot vs non-boot disambiguating types Message-ID: <5f49f3d56f150_80b101ef3ec97372ba@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed to branch wip/buggymcbugfix/insertArray at Glasgow Haskell Compiler / GHC Commits: 32a4ae90 by John Ericson at 2020-06-04T04:34:42-04:00 Clean up boot vs non-boot disambiguating types We often have (ModuleName, Bool) or (Module, Bool) pairs for "extended" module names (without or with a unit id) disambiguating boot and normal modules. We think this is important enough across the compiler that it deserves a new nominal product type. We do this with synnoyms and a functor named with a `Gen` prefix, matching other newly created definitions. It was also requested that we keep custom `IsBoot` / `NotBoot` sum type. So we have it too. This means changing many the many bools to use that instead. Updates `haddock` submodule. - - - - - c05756cd by Niklas Hambüchen at 2020-06-04T04:35:24-04:00 docs: Add more details on InterruptibleFFI. Details from https://gitlab.haskell.org/ghc/ghc/issues/8684 and https://github.com/takano-akio/filelock/pull/7#discussion_r280332430 - - - - - 1b975aed by Andrew Martin at 2020-06-04T04:36:03-04:00 Allow finalizeForeignPtr to be called on FinalPtr/PlainPtr. MR 2165 (commit 49301ad6226d9a83d110bee8c419615dd94f5ded) regressed finalizeForeignPtr by throwing exceptions when PlainPtr was encounterd. This regression did not make it into a release of GHC. Here, the original behavior is restored, and FinalPtr is given the same treatment as PlainPtr. - - - - - 2bd3929a by Luke Lau at 2020-06-04T04:36:41-04:00 Fix documentation on type families not being extracted It looks like the location of the Names used for CoAxioms on type families are now located at their type constructors. Previously, Docs.hs thought the Names were located in the RHS, so the RealSrcSpan in the instanceMap and getInstLoc didn't match up. Fixes #18241 - - - - - 6735b9d9 by Ben Gamari at 2020-06-04T04:37:21-04:00 GHC.Hs.Instances: Compile with -O0 This module contains exclusively Data instances, which are going to be slow no matter what we do. Furthermore, they are incredibly slow to compile with optimisation (see #9557). Consequently we compile this with -O0. See #18254. - - - - - c330331a by nineonine at 2020-06-04T04:37:59-04:00 Add test for #17669 - - - - - cab684f0 by Ben Gamari at 2020-06-04T04:38:36-04:00 rts: Add Windows-specific implementation of rtsSleep Previously we would use the POSIX path, which uses `nanosleep`. However, it turns out that `nanosleep` is provided by `libpthread` on Windows. In general we don't want to incur such a dependency. Avoid this by simply using `Sleep` on Windows. Fixes #18272. - - - - - ad44b504 by Ben Gamari at 2020-06-04T04:38:36-04:00 compiler: Disable use of process jobs with process < 1.6.9 Due to #17926. - - - - - 6a4098a4 by Moritz Angermann at 2020-06-04T04:55:51-04:00 [linker] Adds void printLoadedObjects(void); This allows us to dump in-memory object code locations for debugging. Fixup printLoadedObjects prototype - - - - - af5e3a88 by Artem Pelenitsyn at 2020-06-05T03:18:49-04:00 base: fix sign confusion in log1mexp implementation (fix #17125) author: claude (https://gitlab.haskell.org/trac-claude) The correct threshold for log1mexp is -(log 2) with the current specification of log1mexp. This change improves accuracy for large negative inputs. To avoid code duplication, a small helper function is added; it isn't the default implementation in Floating because it needs Ord. This patch does nothing to address that the Haskell specification is different from that in common use in other languages. - - - - - 2b792fac by Simon Peyton Jones at 2020-06-05T09:27:50-04:00 Simple subsumption This patch simplifies GHC to use simple subsumption. Ticket #17775 Implements GHC proposal #287 https://github.com/ghc-proposals/ghc-proposals/blob/master/ proposals/0287-simplify-subsumption.rst All the motivation is described there; I will not repeat it here. The implementation payload: * tcSubType and friends become noticably simpler, because it no longer uses eta-expansion when checking subsumption. * No deeplyInstantiate or deeplySkolemise That in turn means that some tests fail, by design; they can all be fixed by eta expansion. There is a list of such changes below. Implementing the patch led me into a variety of sticky corners, so the patch includes several othe changes, some quite significant: * I made String wired-in, so that "foo" :: String rather than "foo" :: [Char] This improves error messages, and fixes #15679 * The pattern match checker relies on knowing about in-scope equality constraints, andd adds them to the desugarer's environment using addTyCsDs. But the co_fn in a FunBind was missed, and for some reason simple-subsumption ends up with dictionaries there. So I added a call to addTyCsDs. This is really part of #18049. * I moved the ic_telescope field out of Implication and into ForAllSkol instead. This is a nice win; just expresses the code much better. * There was a bug in GHC.Tc.TyCl.Instance.tcDataFamInstHeader. We called checkDataKindSig inside tc_kind_sig, /before/ solveEqualities and zonking. Obviously wrong, easily fixed. * solveLocalEqualitiesX: there was a whole mess in here, around failing fast enough. I discovered a bad latent bug where we could successfully kind-check a type signature, and use it, but have unsolved constraints that could fill in coercion holes in that signature -- aargh. It's all explained in Note [Failure in local type signatures] in GHC.Tc.Solver. Much better now. * I fixed a serious bug in anonymous type holes. IN f :: Int -> (forall a. a -> _) -> Int that "_" should be a unification variable at the /outer/ level; it cannot be instantiated to 'a'. This was plain wrong. New fields mode_lvl and mode_holes in TcTyMode, and auxiliary data type GHC.Tc.Gen.HsType.HoleMode. This fixes #16292, but makes no progress towards the more ambitious #16082 * I got sucked into an enormous refactoring of the reporting of equality errors in GHC.Tc.Errors, especially in mkEqErr1 mkTyVarEqErr misMatchMsg misMatchMsgOrCND In particular, the very tricky mkExpectedActualMsg function is gone. It took me a full day. But the result is far easier to understand. (Still not easy!) This led to various minor improvements in error output, and an enormous number of test-case error wibbles. One particular point: for occurs-check errors I now just say Can't match 'a' against '[a]' rather than using the intimidating language of "occurs check". * Pretty-printing AbsBinds Tests review * Eta expansions T11305: one eta expansion T12082: one eta expansion (undefined) T13585a: one eta expansion T3102: one eta expansion T3692: two eta expansions (tricky) T2239: two eta expansions T16473: one eta determ004: two eta expansions (undefined) annfail06: two eta (undefined) T17923: four eta expansions (a strange program indeed!) tcrun035: one eta expansion * Ambiguity check at higher rank. Now that we have simple subsumption, a type like f :: (forall a. Eq a => Int) -> Int is no longer ambiguous, because we could write g :: (forall a. Eq a => Int) -> Int g = f and it'd typecheck just fine. But f's type is a bit suspicious, and we might want to consider making the ambiguity check do a check on each sub-term. Meanwhile, these tests are accepted, whereas they were previously rejected as ambiguous: T7220a T15438 T10503 T9222 * Some more interesting error message wibbles T13381: Fine: one error (Int ~ Exp Int) rather than two (Int ~ Exp Int, Exp Int ~ Int) T9834: Small change in error (improvement) T10619: Improved T2414: Small change, due to order of unification, fine T2534: A very simple case in which a change of unification order means we get tow unsolved constraints instead of one tc211: bizarre impredicative tests; just accept this for now Updates Cabal and haddock submodules. Metric Increase: T12150 T12234 T5837 haddock.base Metric Decrease: haddock.compiler haddock.Cabal haddock.base Merge note: This appears to break the `UnliftedNewtypesDifficultUnification` test. It has been marked as broken in the interest of merging. (cherry picked from commit 66b7b195cb3dce93ed5078b80bf568efae904cc5) - - - - - 2dff8141 by Ryan Scott at 2020-06-05T14:21:24-04:00 Simplify bindLHsTyVarBndrs and bindHsQTyVars Both `bindLHsTyVarBndrs` and `bindHsQTyVars` take two separate `Maybe` arguments, which I find terribly confusing. Thankfully, it's possible to remove one `Maybe` argument from each of these functions, which this patch accomplishes: * `bindHsQTyVars` takes a `Maybe SDoc` argument, which is `Just` if GHC should warn about any of the quantified type variables going unused. However, every call site uses `Nothing` in practice. This makes sense, since it doesn't really make sense to warn about unused type variables bound by an `LHsQTyVars`. For instance, you wouldn't warn about the `a` in `data Proxy a = Proxy` going unused. As a result, I simply remove this `Maybe SDoc` argument altogether. * `bindLHsTyVarBndrs` also takes a `Maybe SDoc` argument for the same reasons that `bindHsQTyVars` took one. To make things more confusing, however, `bindLHsTyVarBndrs` also takes a separate `HsDocContext` argument, which is pretty-printed (to an `SDoc`) in warnings and error messages. In practice, the `Maybe SDoc` and the `HsDocContext` often contain the same text. See the call sites for `bindLHsTyVarBndrs` in `rnFamInstEqn` and `rnConDecl`, for instance. There are only a handful of call sites where the text differs between the `Maybe SDoc` and `HsDocContext` arguments: * In `rnHsRuleDecl`, where the `Maybe SDoc` says "`In the rule`" and the `HsDocContext` says "`In the transformation rule`". * In `rnHsTyKi`/`rn_ty`, where the `Maybe SDoc` says "`In the type`" but the `HsDocContext` is inhereted from the surrounding context (e.g., if `rnHsTyKi` were called on a top-level type signature, the `HsDocContext` would be "`In the type signature`" instead) In both cases, warnings/error messages arguably _improve_ by unifying making the `Maybe SDoc`'s text match that of the `HsDocContext`. As a result, I decided to remove the `Maybe SDoc` argument to `bindLHsTyVarBndrs` entirely and simply reuse the text from the `HsDocContext`. (I decided to change the phrase "transformation rule" to "rewrite rule" while I was in the area.) The `Maybe SDoc` argument has one other purpose: signaling when to emit "`Unused quantified type variable`" warnings. To recover this functionality, I replaced the `Maybe SDoc` argument with a boolean-like `WarnUnusedForalls` argument. The only `bindLHsTyVarBndrs` call site that chooses _not_ to emit these warnings in `bindHsQTyVars`. - - - - - e372331b by Ben Gamari at 2020-06-07T08:46:41-04:00 hadrian: Add missing deriveConstants dependency on ghcplatform.h deriveConstants wants to compile C sources which #include PosixSource.h, which itself #includes ghcplatform.h. Make sure that Hadrian knows about this dependency. Fixes #18290. - - - - - b022051a by Moritz Angermann at 2020-06-07T08:46:42-04:00 ghc-prim needs to depend on libc and libm libm is just an empty shell on musl, and all the math functions are contained in libc. - - - - - 6dae6548 by Moritz Angermann at 2020-06-07T08:46:42-04:00 Disable DLL loading if without system linker Some platforms (musl, aarch64) do not have a working dynamic linker implemented in the libc, even though we might see dlopen. It will ultimately just return that this is not supported. Hence we'll add a flag to the compiler to flat our disable loading dlls. This is needed as we will otherwise try to load the shared library even if this will subsequently fail. At that point we have given up looking for static options though. - - - - - 4a158ffc by Moritz Angermann at 2020-06-07T08:46:43-04:00 Range is actually +/-2^32, not +/-2^31 See also: https://static.docs.arm.com/ihi0056/g/aaelf64.pdf - - - - - f1bfb806 by Ben Gamari at 2020-06-07T10:49:30-04:00 OccurAnal: Avoid exponential behavior due to where clauses Previously the `Var` case of `occAnalApp` could in some cases (namely in the case of `runRW#` applications) call `occAnalRhs` two. In the case of nested `runRW#`s this results in exponential complexity. In some cases the compilation time that resulted would be very long indeed (see #18296). Fixes #18296. Metric Decrease: T9961 T12150 T12234 - - - - - 9b607671 by Takenobu Tani at 2020-06-09T08:05:46-04:00 Add link to GHC's wiki in the GHC API header This adds a URL to point to GHC's wiki in the GHC API header. Newcomers could easily find more information from the GHC API's web like [1]. [1]: Current version, https://ghc.gitlab.haskell.org/ghc/doc/libraries/ghc-8.11.0.20200604/index.html [skip ci] - - - - - 72c7fe9a by Ryan Scott at 2020-06-09T08:06:24-04:00 Make GADT constructors adhere to the forall-or-nothing rule properly Issue #18191 revealed that the types of GADT constructors don't quite adhere to the `forall`-or-nothing rule. This patch serves to clean up this sad state of affairs somewhat. The main change is not in the code itself, but in the documentation, as this patch introduces two sections to the GHC User's Guide: * A "Formal syntax for GADTs" section that presents a BNF-style grammar for what is and isn't allowed in GADT constructor types. This mostly exists to codify GHC's existing behavior, but it also imposes a new restriction that addresses #18191: the outermost `forall` and/or context in a GADT constructor is not allowed to be surrounded by parentheses. Doing so would make these `forall`s/contexts nested, and GADTs do not support nested `forall`s/contexts at present. * A "`forall`-or-nothing rule" section that describes exactly what the `forall`-or-nothing rule is all about. Surprisingly, there was no mention of this anywhere in the User's Guide up until now! To adhere the new specification in the "Formal syntax for GADTs" section of the User's Guide, the following code changes were made: * A new function, `GHC.Hs.Type.splitLHsGADTPrefixTy`, was introduced. This is very much like `splitLHsSigmaTy`, except that it avoids splitting apart any parentheses, which can be syntactically significant for GADT types. See `Note [No nested foralls or contexts in GADT constructors]` in `GHC.Hs.Type`. * `ConDeclGADTPrefixPs`, an extension constructor for `XConDecl`, was introduced so that `GHC.Parser.PostProcess.mkGadtDecl` can return it when given a prefix GADT constructor. Unlike `ConDeclGADT`, `ConDeclGADTPrefixPs` does not split the GADT type into its argument and result types, as this cannot be done until after the type is renamed (see `Note [GADT abstract syntax]` in `GHC.Hs.Decls` for why this is the case). * `GHC.Renamer.Module.rnConDecl` now has an additional case for `ConDeclGADTPrefixPs` that (1) splits apart the full `LHsType` into its `forall`s, context, argument types, and result type, and (2) checks for nested `forall`s/contexts. Step (2) used to be performed the typechecker (in `GHC.Tc.TyCl.badDataConTyCon`) rather than the renamer, but now the relevant code from the typechecker can simply be deleted. One nice side effect of this change is that we are able to give a more accurate error message for GADT constructors that use visible dependent quantification (e.g., `MkFoo :: forall a -> a -> Foo a`), which improves the stderr in the `T16326_Fail6` test case. Fixes #18191. Bumps the Haddock submodule. - - - - - a47e6442 by Ryan Scott at 2020-06-10T03:39:12-04:00 Always use rnImplicitBndrs to bring implicit tyvars into scope This implements a first step towards #16762 by changing the renamer to always use `rnImplicitBndrs` to bring implicitly bound type variables into scope. The main change is in `rnFamInstEqn` and `bindHsQTyVars`, which previously used _ad hoc_ methods of binding their implicit tyvars. There are a number of knock-on consequences: * One of the reasons that `rnFamInstEqn` used an _ad hoc_ binding mechanism was to give more precise source locations in `-Wunused-type-patterns` warnings. (See https://gitlab.haskell.org/ghc/ghc/issues/16762#note_273343 for an example of this.) However, these warnings are actually a little _too_ precise, since implicitly bound type variables don't have exact binding sites like explicitly bound type variables do. A similar problem existed for "`Different names for the same type variable`" errors involving implicit tyvars bound by `bindHsQTyVars`. Therefore, we simply accept the less precise (but more accurate) source locations from `rnImplicitBndrs` in `rnFamInstEqn` and `bindHsQTyVars`. See `Note [Source locations for implicitly bound type variables]` in `GHC.Rename.HsType` for the full story. * In order for `rnImplicitBndrs` to work in `rnFamInstEqn`, it needs to be able to look up names from the parent class (in the event that we are renaming an associated type family instance). As a result, `rnImplicitBndrs` now takes an argument of type `Maybe assoc`, which is `Just` in the event that a type family instance is associated with a class. * Previously, GHC kept track of three type synonyms for free type variables in the renamer: `FreeKiTyVars`, `FreeKiTyVarsDups` (which are allowed to contain duplicates), and `FreeKiTyVarsNoDups` (which contain no duplicates). However, making is a distinction between `-Dups` and `-NoDups` is now pointless, as all code that returns `FreeKiTyVars{,Dups,NoDups}` will eventually end up being passed to `rnImplicitBndrs`, which removes duplicates. As a result, I decided to just get rid of `FreeKiTyVarsDups` and `FreeKiTyVarsNoDups`, leaving only `FreeKiTyVars`. * The `bindLRdrNames` and `deleteBys` functions are now dead code, so I took the liberty of removing them. - - - - - 24879129 by Takenobu Tani at 2020-06-10T03:39:59-04:00 Clarify leaf module names for new module hierarchy This updates comments only. This patch replaces leaf module names according to new module hierarchy [1][2] as followings: * Expand leaf names to easily find the module path: for instance, `Id.hs` to `GHC.Types.Id`. * Modify leaf names according to new module hierarchy: for instance, `Convert.hs` to `GHC.ThToHs`. * Fix typo: for instance, `GHC.Core.TyCo.Rep.hs` to `GHC.Core.TyCo.Rep` See also !3375 [1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular [2]: https://gitlab.haskell.org/ghc/ghc/issues/13009 - - - - - 92de9e25 by Ömer Sinan Ağacan at 2020-06-10T03:41:07-04:00 rts: Remove unused GET_ENTRY closure macro This macro is not used and got broken in the meantime, as ENTRY_CODE was deleted. - - - - - 87102928 by Ömer Sinan Ağacan at 2020-06-10T03:41:50-04:00 Fix -fkeep-cafs flag name in users guide - - - - - ccd6843d by Shayne Fletcher at 2020-06-10T04:14:57-04:00 Expose impliedGFlags, impledOffGFlags, impliedXFlags - - - - - 7a737e89 by Ömer Sinan Ağacan at 2020-06-10T04:14:58-04:00 Cross-module LambdaFormInfo passing - Store LambdaFormInfos of exported Ids in interface files - Use them in importing modules This is for optimization purposes: if we know LambdaFormInfo of imported Ids we can generate more efficient calling code, see `getCallMethod`. Exporting (putting them in interface files or in ModDetails) and importing (reading them from interface files) are both optional. We don't assume known LambdaFormInfos anywhere and do not change how we call Ids with unknown LambdaFormInfos. Runtime, allocation, and residency numbers when building Cabal-the-library (commit 0d4ee7ba3): (Log and .hp files are in the MR: !2842) | | GHC HEAD | This patch | Diff | |-----|----------|------------|----------------| | -O0 | 0:35.89 | 0:34.10 | -1.78s, -4.98% | | -O1 | 2:24.01 | 2:23.62 | -0.39s, -0.27% | | -O2 | 2:52.23 | 2:51.35 | -0.88s, -0.51% | | | GHC HEAD | This patch | Diff | |-----|-----------------|-----------------|----------------------------| | -O0 | 54,843,608,416 | 54,878,769,544 | +35,161,128 bytes, +0.06% | | -O1 | 227,136,076,400 | 227,569,045,168 | +432,968,768 bytes, +0.19% | | -O2 | 266,147,063,296 | 266,749,643,440 | +602,580,144 bytes, +0.22% | NOTE: Residency is measured with extra runtime args: `-i0 -h` which effectively turn all GCs into major GCs, and do GC more often. | | GHC HEAD | This patch | Diff | |-----|----------------------------|------------------------------|----------------------------| | -O0 | 410,284,000 (910 samples) | 411,745,008 (906 samples) | +1,461,008 bytes, +0.35% | | -O1 | 928,580,856 (2109 samples) | 943,506,552 (2103 samples) | +14,925,696 bytes, +1.60% | | -O2 | 993,951,352 (2549 samples) | 1,010,156,328 (2545 samples) | +16,204,9760 bytes, +1.63% | NoFib results: -------------------------------------------------------------------------------- Program Size Allocs Instrs Reads Writes -------------------------------------------------------------------------------- CS 0.0% 0.0% +0.0% +0.0% +0.0% CSD 0.0% 0.0% 0.0% +0.0% +0.0% FS 0.0% 0.0% +0.0% +0.0% +0.0% S 0.0% 0.0% +0.0% +0.0% +0.0% VS 0.0% 0.0% +0.0% +0.0% +0.0% VSD 0.0% 0.0% +0.0% +0.0% +0.1% VSM 0.0% 0.0% +0.0% +0.0% +0.0% anna 0.0% 0.0% -0.3% -0.8% -0.0% ansi 0.0% 0.0% -0.0% -0.0% 0.0% atom 0.0% 0.0% -0.0% -0.0% 0.0% awards 0.0% 0.0% -0.1% -0.3% 0.0% banner 0.0% 0.0% -0.0% -0.0% -0.0% bernouilli 0.0% 0.0% -0.0% -0.0% -0.0% binary-trees 0.0% 0.0% -0.0% -0.0% +0.0% boyer 0.0% 0.0% -0.0% -0.0% 0.0% boyer2 0.0% 0.0% -0.0% -0.0% 0.0% bspt 0.0% 0.0% -0.0% -0.2% 0.0% cacheprof 0.0% 0.0% -0.1% -0.4% +0.0% calendar 0.0% 0.0% -0.0% -0.0% 0.0% cichelli 0.0% 0.0% -0.9% -2.4% 0.0% circsim 0.0% 0.0% -0.0% -0.0% 0.0% clausify 0.0% 0.0% -0.1% -0.3% 0.0% comp_lab_zift 0.0% 0.0% -0.0% -0.0% +0.0% compress 0.0% 0.0% -0.0% -0.0% -0.0% compress2 0.0% 0.0% -0.0% -0.0% 0.0% constraints 0.0% 0.0% -0.1% -0.2% -0.0% cryptarithm1 0.0% 0.0% -0.0% -0.0% 0.0% cryptarithm2 0.0% 0.0% -1.4% -4.1% -0.0% cse 0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e1 0.0% 0.0% -0.0% -0.0% -0.0% digits-of-e2 0.0% 0.0% -0.0% -0.0% -0.0% dom-lt 0.0% 0.0% -0.1% -0.2% 0.0% eliza 0.0% 0.0% -0.5% -1.5% 0.0% event 0.0% 0.0% -0.0% -0.0% -0.0% exact-reals 0.0% 0.0% -0.1% -0.3% +0.0% exp3_8 0.0% 0.0% -0.0% -0.0% -0.0% expert 0.0% 0.0% -0.3% -1.0% -0.0% fannkuch-redux 0.0% 0.0% +0.0% +0.0% +0.0% fasta 0.0% 0.0% -0.0% -0.0% +0.0% fem 0.0% 0.0% -0.0% -0.0% 0.0% fft 0.0% 0.0% -0.0% -0.0% 0.0% fft2 0.0% 0.0% -0.0% -0.0% 0.0% fibheaps 0.0% 0.0% -0.0% -0.0% +0.0% fish 0.0% 0.0% 0.0% -0.0% +0.0% fluid 0.0% 0.0% -0.4% -1.2% +0.0% fulsom 0.0% 0.0% -0.0% -0.0% 0.0% gamteb 0.0% 0.0% -0.1% -0.3% 0.0% gcd 0.0% 0.0% -0.0% -0.0% 0.0% gen_regexps 0.0% 0.0% -0.0% -0.0% -0.0% genfft 0.0% 0.0% -0.0% -0.0% 0.0% gg 0.0% 0.0% -0.0% -0.0% +0.0% grep 0.0% 0.0% -0.0% -0.0% -0.0% hidden 0.0% 0.0% -0.1% -0.4% -0.0% hpg 0.0% 0.0% -0.2% -0.5% +0.0% ida 0.0% 0.0% -0.0% -0.0% +0.0% infer 0.0% 0.0% -0.3% -0.8% -0.0% integer 0.0% 0.0% -0.0% -0.0% +0.0% integrate 0.0% 0.0% -0.0% -0.0% 0.0% k-nucleotide 0.0% 0.0% -0.0% -0.0% +0.0% kahan 0.0% 0.0% -0.0% -0.0% +0.0% knights 0.0% 0.0% -2.2% -5.4% 0.0% lambda 0.0% 0.0% -0.6% -1.8% 0.0% last-piece 0.0% 0.0% -0.0% -0.0% 0.0% lcss 0.0% 0.0% -0.0% -0.1% 0.0% life 0.0% 0.0% -0.0% -0.1% 0.0% lift 0.0% 0.0% -0.2% -0.6% +0.0% linear 0.0% 0.0% -0.0% -0.0% -0.0% listcompr 0.0% 0.0% -0.0% -0.0% 0.0% listcopy 0.0% 0.0% -0.0% -0.0% 0.0% maillist 0.0% 0.0% -0.1% -0.3% +0.0% mandel 0.0% 0.0% -0.0% -0.0% 0.0% mandel2 0.0% 0.0% -0.0% -0.0% -0.0% mate +0.0% 0.0% -0.0% -0.0% -0.0% minimax 0.0% 0.0% -0.2% -1.0% 0.0% mkhprog 0.0% 0.0% -0.1% -0.2% -0.0% multiplier 0.0% 0.0% -0.0% -0.0% -0.0% n-body 0.0% 0.0% -0.0% -0.0% +0.0% nucleic2 0.0% 0.0% -0.1% -0.2% 0.0% para 0.0% 0.0% -0.0% -0.0% -0.0% paraffins 0.0% 0.0% -0.0% -0.0% 0.0% parser 0.0% 0.0% -0.2% -0.7% 0.0% parstof 0.0% 0.0% -0.0% -0.0% +0.0% pic 0.0% 0.0% -0.0% -0.0% 0.0% pidigits 0.0% 0.0% +0.0% +0.0% +0.0% power 0.0% 0.0% -0.2% -0.6% +0.0% pretty 0.0% 0.0% -0.0% -0.0% -0.0% primes 0.0% 0.0% -0.0% -0.0% 0.0% primetest 0.0% 0.0% -0.0% -0.0% -0.0% prolog 0.0% 0.0% -0.3% -1.1% 0.0% puzzle 0.0% 0.0% -0.0% -0.0% 0.0% queens 0.0% 0.0% -0.0% -0.0% +0.0% reptile 0.0% 0.0% -0.0% -0.0% 0.0% reverse-complem 0.0% 0.0% -0.0% -0.0% +0.0% rewrite 0.0% 0.0% -0.7% -2.5% -0.0% rfib 0.0% 0.0% -0.0% -0.0% 0.0% rsa 0.0% 0.0% -0.0% -0.0% 0.0% scc 0.0% 0.0% -0.1% -0.2% -0.0% sched 0.0% 0.0% -0.0% -0.0% -0.0% scs 0.0% 0.0% -1.0% -2.6% +0.0% simple 0.0% 0.0% +0.0% -0.0% +0.0% solid 0.0% 0.0% -0.0% -0.0% 0.0% sorting 0.0% 0.0% -0.6% -1.6% 0.0% spectral-norm 0.0% 0.0% +0.0% 0.0% +0.0% sphere 0.0% 0.0% -0.0% -0.0% -0.0% symalg 0.0% 0.0% -0.0% -0.0% +0.0% tak 0.0% 0.0% -0.0% -0.0% 0.0% transform 0.0% 0.0% -0.0% -0.0% 0.0% treejoin 0.0% 0.0% -0.0% -0.0% 0.0% typecheck 0.0% 0.0% -0.0% -0.0% +0.0% veritas +0.0% 0.0% -0.2% -0.4% +0.0% wang 0.0% 0.0% -0.0% -0.0% 0.0% wave4main 0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve1 0.0% 0.0% -0.0% -0.0% -0.0% wheel-sieve2 0.0% 0.0% -0.0% -0.0% +0.0% x2n1 0.0% 0.0% -0.0% -0.0% -0.0% -------------------------------------------------------------------------------- Min 0.0% 0.0% -2.2% -5.4% -0.0% Max +0.0% 0.0% +0.0% +0.0% +0.1% Geometric Mean -0.0% -0.0% -0.1% -0.3% +0.0% Metric increases micro benchmarks tracked in #17686: Metric Increase: T12150 T12234 T12425 T13035 T5837 T6048 T9233 Co-authored-by: Andreas Klebinger <klebinger.andreas at gmx.at> - - - - - 3b22b14a by Shayne Fletcher at 2020-06-10T04:15:01-04:00 Give Language a Bounded instance - - - - - 9454511b by Simon Peyton Jones at 2020-06-10T04:17:06-04:00 Optimisation in Unique.Supply This patch switches on -fno-state-hack in GHC.Types.Unique.Supply. It turned out that my fixes for #18078 (coercion floating) changed the optimisation pathway for mkSplitUniqSupply in such a way that we had an extra allocation inside the inner loop. Adding -fno-state-hack fixed that -- and indeed the loop in mkSplitUniqSupply is a classic example of the way in which -fno-state-hack can be bad; see #18238. Moreover, the new code is better than the old. They allocate the same, but the old code ends up with a partial application. The net effect is that the test perf/should_run/UniqLoop runs 20% faster! From 2.5s down to 2.0s. The allocation numbers are the same -- but elapsed time falls. Good! The bad thing about this is that it's terribly delicate. But at least it's a good example of such delicacy in action. There is a long Note [Optimising the unique supply] which now explains all this. - - - - - 6d49d5be by Simon Peyton Jones at 2020-06-10T04:17:06-04:00 Implement cast worker/wrapper properly The cast worker/wrapper transformation transforms x = e |> co into y = e x = y |> co This is done by the simplifier, but we were being careless about transferring IdInfo from x to y, and about what to do if x is a NOINLNE function. This resulted in a series of bugs: #17673, #18093, #18078. This patch fixes all that: * Main change is in GHC.Core.Opt.Simplify, and the new prepareBinding function, which does this cast worker/wrapper transform. See Note [Cast worker/wrappers]. * There is quite a bit of refactoring around prepareRhs, makeTrivial etc. It's nicer now. * Some wrappers from strictness and cast w/w, notably those for a function with a NOINLINE, should inline very late. There wasn't really a mechanism for that, which was an existing bug really; so I invented a new finalPhase = Phase (-1). It's used for all simplifier runs after the user-visible phase 2,1,0 have run. (No new runs of the simplifier are introduced thereby.) See new Note [Compiler phases] in GHC.Types.Basic; the main changes are in GHC.Core.Opt.Driver * Doing this made me trip over two places where the AnonArgFlag on a FunTy was being lost so we could end up with (Num a -> ty) rather than (Num a => ty) - In coercionLKind/coercionRKind - In contHoleType in the Simplifier I fixed the former by defining mkFunctionType and using it in coercionLKind/RKind. I could have done the same for the latter, but the information is almost to hand. So I fixed the latter by - adding sc_hole_ty to ApplyToVal (like ApplyToTy), - adding as_hole_ty to ValArg (like TyArg) - adding sc_fun_ty to StrictArg Turned out I could then remove ai_type from ArgInfo. This is just moving the deck chairs around, but it worked out nicely. See the new Note [AnonArgFlag] in GHC.Types.Var * When looking at the 'arity decrease' thing (#18093) I discovered that stable unfoldings had a much lower arity than the actual optimised function. That's what led to the arity-decrease message. Simple solution: eta-expand. It's described in Note [Eta-expand stable unfoldings] in GHC.Core.Opt.Simplify * I also discovered that unsafeCoerce wasn't being inlined if the context was boring. So (\x. f (unsafeCoerce x)) would create a thunk -- yikes! I fixed that by making inlineBoringOK a bit cleverer: see Note [Inline unsafeCoerce] in GHC.Core.Unfold. I also found that unsafeCoerceName was unused, so I removed it. I made a test case for #18078, and a very similar one for #17673. The net effect of all this on nofib is very modest, but positive: -------------------------------------------------------------------------------- Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- anna -0.4% -0.1% -3.1% -3.1% 0.0% fannkuch-redux -0.4% -0.3% -0.1% -0.1% 0.0% maillist -0.4% -0.1% -7.8% -1.0% -14.3% primetest -0.4% -15.6% -7.1% -6.6% 0.0% -------------------------------------------------------------------------------- Min -0.9% -15.6% -13.3% -14.2% -14.3% Max -0.3% 0.0% +12.1% +12.4% 0.0% Geometric Mean -0.4% -0.2% -2.3% -2.2% -0.1% All following metric decreases are compile-time allocation decreases between -1% and -3%: Metric Decrease: T5631 T13701 T14697 T15164 - - - - - 32fd37f5 by Luke Lau at 2020-06-10T04:17:22-04:00 Fix lookupGlobalOccRn_maybe sometimes reporting an error In some cases it was possible for lookupGlobalOccRn_maybe to return an error, when it should be returning a Nothing. If it called lookupExactOcc_either when there were no matching GlobalRdrElts in the otherwise case, it would return an error message. This could be caused when lookupThName_maybe in Template Haskell was looking in different namespaces (thRdrNameGuesses), guessing different namespaces that the name wasn't guaranteed to be found in. However, by addressing this some more accurate errors were being lost in the conversion to Maybes. So some of the lookup* functions have been shuffled about so that errors should always be ignored in lookup*_maybes, and propagated otherwise. This fixes #18263 - - - - - 9b283e1b by Roland Senn at 2020-06-10T04:17:34-04:00 Initialize the allocation counter in GHCi to 0 (Fixes #16012) According to the documentation for the function `getAllocationCounter` in [System.Mem](http://hackage.haskell.org/package/base-4.14.0.0/docs/System-Mem.html) initialize the allocationCounter also in GHCi to 0. - - - - - 8d07c48c by Sylvain Henry at 2020-06-10T04:17:36-04:00 test: fix conc038 We had spurious failures of conc038 test on CI with stdout: ``` newThread started -mainThread -Haskell: 2 newThread back again +mainThread 1 sec later shutting down +Haskell: 2 ``` - - - - - 4c7e9689 by Sebastian Graf at 2020-06-11T10:37:38+02:00 Release Notes: Add news from the pattern-match checker [skip ci] - - - - - 3445b965 by Sylvain Henry at 2020-06-13T02:13:01-04:00 Only test T16190 with the NCG T16190 is meant to test a NCG feature. It has already caused spurious failures in other MRs (e.g. !2165) when LLVM is used. - - - - - 2517a51c by Sylvain Henry at 2020-06-13T02:13:01-04:00 DynFlags refactoring VIII (#17957) * Remove several uses of `sdocWithDynFlags`, especially in GHC.Llvm.* * Add LlvmOpts datatype to store Llvm backend options * Remove Outputable instances (for LlvmVar, LlvmLit, LlvmStatic and Llvm.MetaExpr) which require LlvmOpts. * Rename ppMetaExpr into ppMetaAnnotExpr (pprMetaExpr is now used in place of `ppr :: MetaExpr -> SDoc`) - - - - - 7a02599a by Sylvain Henry at 2020-06-13T02:13:02-04:00 Remove unused code - - - - - 72d08610 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Refactor homeUnit * rename thisPackage into homeUnit * document and refactor several Backpack things - - - - - 8dc71f55 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Rename unsafeGetUnitInfo into unsafeLookupUnit - - - - - f6be6e43 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Add allowVirtualUnits field in PackageState Instead of always querying DynFlags to know whether we are allowed to use virtual units (i.e. instantiated on-the-fly, cf Note [About units] in GHC.Unit), we store it once for all in `PackageState.allowVirtualUnits`. This avoids using DynFlags too much (cf #17957) and is preliminary work for #14335. - - - - - e7272d53 by Sylvain Henry at 2020-06-13T02:13:02-04:00 Enhance UnitId use * use UnitId instead of String to identify wired-in units * use UnitId instead of Unit in the backend (Unit are only use by Backpack to produce type-checked interfaces, not real code) * rename lookup functions for consistency * documentation - - - - - 9c5572cd by Sylvain Henry at 2020-06-13T02:13:02-04:00 Remove LinkerUnitId type alias - - - - - d345edfe by Sylvain Henry at 2020-06-13T02:13:02-04:00 Refactor WiredMap * Remove WiredInUnitId and WiredUnitId type aliases - - - - - 3d171cd6 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Document and refactor `mkUnit` and `mkUnitInfoMap` - - - - - d2109b4f by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove PreloadUnitId type alias - - - - - f50c19b8 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename listUnitInfoMap into listUnitInfo There is no Map involved - - - - - ed533ec2 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename Package into Unit The terminology changed over time and now package databases contain "units" (there can be several units compiled from a single Cabal package: one per-component, one for each option set, one per instantiation, etc.). We should try to be consistent internally and use "units": that's what this renaming does. Maybe one day we'll fix the UI too (e.g. replace -package-id with -unit-id, we already have -this-unit-id and ghc-pkg has -unit-id...) but it's not done in this patch. * rename getPkgFrameworkOpts into getUnitFrameworkOpts * rename UnitInfoMap into ClosureUnitInfoMap * rename InstalledPackageIndex into UnitInfoMap * rename UnusablePackages into UnusableUnits * rename PackagePrecedenceIndex into UnitPrecedenceMap * rename PackageDatabase into UnitDatabase * rename pkgDatabase into unitDatabases * rename pkgState into unitState * rename initPackages into initUnits * rename renamePackage into renameUnitInfo * rename UnusablePackageReason into UnusableUnitReason * rename getPackage* into getUnit* * etc. - - - - - 202728e5 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Make ClosureUnitInfoMap uses UnitInfoMap - - - - - 55b4263e by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove ClosureUnitInfoMap - - - - - 653d17bd by Sylvain Henry at 2020-06-13T02:13:03-04:00 Rename Package into Unit (2) * rename PackageState into UnitState * rename findWiredInPackages into findWiredInUnits * rename lookupModuleInAll[Packages,Units] * etc. - - - - - ae900605 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move dump_mod_map into initUnits - - - - - 598cc1dd by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move wiring of homeUnitInstantiations outside of mkUnitState - - - - - 437265eb by Sylvain Henry at 2020-06-13T02:13:03-04:00 Avoid timing module map dump in initUnits - - - - - 9400aa93 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Remove preload parameter of mkUnitState * Remove preload parameter (unused) * Don't explicitly return preloaded units: redundant because already returned as "preloadUnits" field of UnitState - - - - - 266bc3d9 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: refactor unwireUnit - - - - - 9e715c1b by Sylvain Henry at 2020-06-13T02:13:03-04:00 Document getPreloadUnitsAnd - - - - - bd5810dc by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: remove useless add_package parameter - - - - - 36e1daf0 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: make listVisibleModuleNames take a UnitState - - - - - 5226da37 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Refactor and document add_package - - - - - 4b53aac1 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Refactor and document closeUnitDeps - - - - - 42c054f6 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: findWiredInUnits - - - - - a444d01b by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: reportCycles, reportUnusable - - - - - 8408d521 by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: merge_databases - - - - - fca2d25f by Sylvain Henry at 2020-06-13T02:13:03-04:00 DynFlags: add UnitConfig datatype Avoid directly querying flags from DynFlags to build the UnitState. Instead go via UnitConfig so that we could reuse this to make another UnitState for plugins. - - - - - 4274688a by Sylvain Henry at 2020-06-13T02:13:03-04:00 Move distrustAll into mkUnitState - - - - - 28d804e1 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Create helper upd_wired_in_home_instantiations - - - - - ac964c83 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Put database cache in UnitConfig - - - - - bfd0a78c by Sylvain Henry at 2020-06-13T02:13:03-04:00 Don't return preload units when we set DyNFlags Preload units can be retrieved in UnitState when needed (i.e. in GHCi) - - - - - 1fbb4bf5 by Sylvain Henry at 2020-06-13T02:13:03-04:00 NCGConfig: remove useless ncgUnitId field - - - - - c10ff7e7 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Doc: fix some comments - - - - - 456e17f0 by Sylvain Henry at 2020-06-13T02:13:03-04:00 Bump haddock submodule and allow metric decrease Metric Decrease: T12150 T12234 T5837 Metric Increase: T16190 - - - - - 42953902 by Simon Peyton Jones at 2020-06-13T02:13:03-04:00 Trim the demand for recursive product types Ticket #18304 showed that we need to be very careful when exploring the demand (esp usage demand) on recursive product types. This patch solves the problem by trimming the demand on such types -- in effect, a form of "widening". See the Note [Trimming a demand to a type] in DmdAnal, which explains how I did this by piggy-backing on an existing mechansim for trimming demands becuase of GADTs. The significant payload of this patch is very small indeed: * Make GHC.Core.Opt.WorkWrap.Utils.typeShape use RecTcChecker to avoid looking through recursive types. But on the way * I found that ae_rec_tc was entirely inoperative and did nothing. So I removed it altogether from DmdAnal. * I moved some code around in DmdAnal and Demand. (There are no actual changes in dmdFix.) * I changed the API of DmsAnal.dmdAnalRhsLetDown to return a StrictSig rather than a decorated Id * I removed the dead function peelTsFuns from Demand Performance effects: Nofib: 0.0% changes. Not surprising, because they don't use recursive products Perf tests T12227: 1% increase in compiler allocation, becuase $cto gets w/w'd. It did not w/w before because it takes a deeply nested argument, so the worker gets too many args, so we abandon w/w altogether (see GHC.Core.Opt.WorkWrap.Utils.isWorkerSmallEnough) With this patch we trim the demands. That is not strictly necessary (since these Generic type constructors are like tuples -- they can't cause a loop) but the net result is that we now w/w $cto which is fine. UniqLoop: 16% decrease in /runtime/ allocation. The UniqSupply is a recursive product, so currently we abandon all strictness on 'churn'. With this patch 'churn' gets useful strictness, and we w/w it. Hooray Metric Decrease: UniqLoop Metric Increase: T12227 - - - - - 87d504f4 by Viktor Dukhovni at 2020-06-13T02:13:05-04:00 Add introductory prose for Data.Traversable - - - - - 9f09b608 by Oleg Grenrus at 2020-06-13T02:13:07-04:00 Fix #12073: Add MonadFix Q instance - - - - - 220c2d34 by Ben Gamari at 2020-06-13T02:13:07-04:00 testsuite: Increase size of T12150 As noted in #18319, this test was previously very fragile. Increase its size to make it more likely that its fails with its newly-increased acceptance threshold. Metric Increase: T12150 - - - - - 8bba1c26 by Ben Gamari at 2020-06-13T04:59:06-04:00 gitlab-ci: Always push perf notes Previously we ci.sh would run with `set -e` implying that we wouldn't push perf notes if the testsuite were to fail, even if it *only* failed due to perf notes. This rendered the whole performance testing story quite fragile as a single regressing commit would cause every successive commit to fail since a new baseline would not be uploaded. Fix this by ensuring that we always push performance notes. - - - - - 7a773f16 by Ben Gamari at 2020-06-13T15:10:55-04:00 gitlab-ci: Eliminate redundant push of CI metrics - - - - - a31218f7 by Ryan Scott at 2020-06-13T15:58:37-04:00 Use HsForAllTelescope to avoid inferred, visible foralls Currently, `HsForAllTy` permits the combination of `ForallVis` and `Inferred`, but you can't actually typecheck code that uses it (e.g., `forall {a} ->`). This patch refactors `HsForAllTy` to use a new `HsForAllTelescope` data type that makes a type-level distinction between visible and invisible `forall`s such that visible `forall`s do not track `Specificity`. That part of the patch is actually quite small; the rest is simply changing consumers of `HsType` to accommodate this new type. Fixes #18235. Bumps the `haddock` submodule. - - - - - c0e6dee9 by Tamar Christina at 2020-06-14T09:07:44-04:00 winio: Add Atomic Exchange PrimOp and implement Atomic Ptr exchanges. The initial version was rewritten by Tamar Christina. It was rewritten in large parts by Andreas Klebinger. Co-authored-by: Andreas Klebinger <klebinger.andreas at gmx.at> - - - - - 9a7462fb by Ben Gamari at 2020-06-14T15:35:23-04:00 codeGen: Don't discard live case binders in unsafeEqualityProof logic Previously CoreToStg would unconditionally discard cases of the form: case unsafeEqualityProof of wild { _ -> rhs } and rather replace the whole thing with `rhs`. However, in some cases (see #18227) the case binder is still live, resulting in unbound occurrences in `rhs`. Fix this by only discarding the case if the case binder is dead. Fixes #18227. - - - - - e4137c48 by Ben Gamari at 2020-06-14T15:35:23-04:00 testsuite: Add tests for #18227 T18227A is the original issue which gave rise to the ticket and depends upon bytestring. T18227B is a minimized reproducer. - - - - - 8bab9ff1 by Ben Gamari at 2020-06-14T15:35:59-04:00 hadrian: Fix rts include and library paths Fixes two bugs: * (?) and (<>) associated in a surprising way * We neglected to include libdw paths in the rts configure flags - - - - - bd761185 by Ben Gamari at 2020-06-14T15:35:59-04:00 hadrian: Drop redundant GHC arguments Cabal should already be passing this arguments to GHC. - - - - - 01f7052c by Peter Trommler at 2020-06-14T15:36:38-04:00 FFI: Fix pass small ints in foreign call wrappers The Haskell calling convention requires integer parameters smaller than wordsize to be promoted to wordsize (where the upper bits are don't care). To access such small integer parameter read a word from the parameter array and then cast that word to the small integer target type. Fixes #15933 - - - - - 502647f7 by Krzysztof Gogolewski at 2020-06-14T15:37:14-04:00 Fix "ndecreasingIndentation" in manual (#18116) - - - - - 9a9cc089 by Simon Jakobi at 2020-06-15T13:10:00-04:00 Use foldl' in unionManyUniqDSets - - - - - 761dcb84 by Moritz Angermann at 2020-06-15T13:10:36-04:00 Load .lo as well. Some archives contain so called linker objects, with the affectionate .lo suffic. For example the musl libc.a will come in that form. We still want to load those objects, hence we should not discard them and look for .lo as well. Ultimately we might want to fix this proerly by looking at the file magic. - - - - - cf01477f by Vladislav Zavialov at 2020-06-15T13:11:20-04:00 User's Guide: KnownNat evidence is Natural This bit of documentation got outdated after commit 1fcede43d2b30f33b7505e25eb6b1f321be0407f - - - - - d0dcbfe6 by Jan Hrček at 2020-06-16T20:36:38+02:00 Fix typos and formatting in user guide - - - - - 56a9e95f by Jan Hrček at 2020-06-16T20:36:38+02:00 Resolve TODO - - - - - 3e884d14 by Jan Hrček at 2020-06-16T20:36:38+02:00 Rename TcHoleErrors to GHC.Tc.Errors.Hole - - - - - d23fc678 by Stefan Schulze Frielinghaus at 2020-06-17T15:31:09-04:00 hadrian: Build with threaded runtime if available See #16873. - - - - - 0639dc10 by Sylvain Henry at 2020-06-17T15:31:53-04:00 T16190: only measure bytes_allocated Just adding `{-# LANGUAGE BangPatterns #-}` makes the two other metrics fluctuate by 13%. - - - - - 4cab6897 by Adam Sandberg Ericsson at 2020-06-17T15:32:44-04:00 docs: fix formatting in users guide - - - - - eb8115a8 by Sylvain Henry at 2020-06-17T15:33:23-04:00 Move CLabel assertions into smart constructors (#17957) It avoids using DynFlags in the Outputable instance of Clabel to check assertions at pretty-printing time. - - - - - 7faa4509 by Ben Gamari at 2020-06-17T15:43:31-04:00 base: Bump to 4.15.0.0 - - - - - 20616959 by Ben Gamari at 2020-06-17T15:43:31-04:00 configure: Use grep -q instead of --quiet The latter is apparently not supported by busybox. - - - - - 40fa237e by Krzysztof Gogolewski at 2020-06-17T16:21:58-04:00 Linear types (#15981) This is the first step towards implementation of the linear types proposal (https://github.com/ghc-proposals/ghc-proposals/pull/111). It features * A language extension -XLinearTypes * Syntax for linear functions in the surface language * Linearity checking in Core Lint, enabled with -dlinear-core-lint * Core-to-core passes are mostly compatible with linearity * Fields in a data type can be linear or unrestricted; linear fields have multiplicity-polymorphic constructors. If -XLinearTypes is disabled, the GADT syntax defaults to linear fields The following items are not yet supported: * a # m -> b syntax (only prefix FUN is supported for now) * Full multiplicity inference (multiplicities are really only checked) * Decent linearity error messages * Linear let, where, and case expressions in the surface language (each of these currently introduce the unrestricted variant) * Multiplicity-parametric fields * Syntax for annotating lambda-bound or let-bound with a multiplicity * Syntax for non-linear/multiple-field-multiplicity records * Linear projections for records with a single linear field * Linear pattern synonyms * Multiplicity coercions (test LinearPolyType) A high-level description can be found at https://ghc.haskell.org/trac/ghc/wiki/LinearTypes/Implementation Following the link above you will find a description of the changes made to Core. This commit has been authored by * Richard Eisenberg * Krzysztof Gogolewski * Matthew Pickering * Arnaud Spiwack With contributions from: * Mark Barbone * Alexander Vershilov Updates haddock submodule. - - - - - 6cb84c46 by Krzysztof Gogolewski at 2020-06-17T16:22:03-04:00 Various performance improvements This implements several general performance improvements to GHC, to offset the effect of the linear types change. General optimisations: - Add a `coreFullView` function which iterates `coreView` on the head. This avoids making function recursive solely because the iterate `coreView` themselves. As a consequence, this functions can be inlined, and trigger case-of-known constructor (_e.g._ `kindRep_maybe`, `isLiftedRuntimeRep`, `isMultiplicityTy`, `getTyVar_maybe`, `splitAppTy_maybe`, `splitFunType_maybe`, `tyConAppTyCon_maybe`). The common pattern about all these functions is that they are almost always used as views, and immediately consumed by a case expression. This commit also mark them asx `INLINE`. - In `subst_ty` add a special case for nullary `TyConApp`, which avoid allocations altogether. - Use `mkTyConApp` in `subst_ty` for the general `TyConApp`. This required quite a bit of module shuffling. case. `myTyConApp` enforces crucial sharing, which was lost during substitution. See also !2952 . - Make `subst_ty` stricter. - In `eqType` (specifically, in `nonDetCmpType`), add a special case, tested first, for the very common case of nullary `TyConApp`. `nonDetCmpType` has been made `INLINE` otherwise it is actually a regression. This is similar to the optimisations in !2952. Linear-type specific optimisations: - Use `tyConAppTyCon_maybe` instead of the more complex `eqType` in the definition of the pattern synonyms `One` and `Many`. - Break the `hs-boot` cycles between `Multiplicity.hs` and `Type.hs`: `Multiplicity` now import `Type` normally, rather than from the `hs-boot`. This way `tyConAppTyCon_maybe` can inline properly in the `One` and `Many` pattern synonyms. - Make `updateIdTypeAndMult` strict in its type and multiplicity - The `scaleIdBy` gets a specialised definition rather than being an alias to `scaleVarBy` - `splitFunTy_maybe` is given the type `Type -> Maybe (Mult, Type, Type)` instead of `Type -> Maybe (Scaled Type, Type)` - Remove the `MultMul` pattern synonym in favour of a view `isMultMul` because pattern synonyms appear not to inline well. - in `eqType`, in a `FunTy`, compare multiplicities last: they are almost always both `Many`, so it helps failing faster. - Cache `manyDataConTy` in `mkTyConApp`, to make sure that all the instances of `TyConApp ManyDataConTy []` are physically the same. This commit has been authored by * Richard Eisenberg * Krzysztof Gogolewski * Arnaud Spiwack Metric Decrease: haddock.base T12227 T12545 T12990 T1969 T3064 T5030 T9872b Metric Increase: haddock.base haddock.Cabal haddock.compiler T12150 T12234 T12425 T12707 T13035 T13056 T15164 T16190 T18304 T1969 T3064 T3294 T5631 T5642 T5837 T6048 T9020 T9233 T9675 T9872a T9961 WWRec - - - - - 57db91d8 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Remove integer-simple integer-simple uses lists of words (`[Word]`) to represent big numbers instead of ByteArray#: * it is less efficient than the newer ghc-bignum native backend * it isn't compatible with the big number representation that is now shared by all the ghc-bignum backends (based on the one that was used only in integer-gmp before). As a consequence, we simply drop integer-simple - - - - - 9f96bc12 by Sylvain Henry at 2020-06-17T16:22:03-04:00 ghc-bignum library ghc-bignum is a newer package that aims to replace the legacy integer-simple and integer-gmp packages. * it supports several backends. In particular GMP is still supported and most of the code from integer-gmp has been merged in the "gmp" backend. * the pure Haskell "native" backend is new and is much faster than the previous pure Haskell implementation provided by integer-simple * new backends are easier to write because they only have to provide a few well defined functions. All the other code is common to all backends. In particular they all share the efficient small/big number distinction previously used only in integer-gmp. * backends can all be tested against the "native" backend with a simple Cabal flag. Backends are only allowed to differ in performance, their results should be the same. * Add `integer-gmp` compat package: provide some pattern synonyms and function aliases for those in `ghc-bignum`. It is intended to avoid breaking packages that depend on `integer-gmp` internals. Update submodules: text, bytestring Metric Decrease: Conversions ManyAlternatives ManyConstructors Naperian T10359 T10547 T10678 T12150 T12227 T12234 T12425 T13035 T13719 T14936 T1969 T4801 T4830 T5237 T5549 T5837 T8766 T9020 parsing001 space_leak_001 T16190 haddock.base On ARM and i386, T17499 regresses (+6% > 5%). On x86_64 unregistered, T13701 sometimes regresses (+2.2% > 2%). Metric Increase: T17499 T13701 - - - - - 96aa5787 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update compiler Thanks to ghc-bignum, the compiler can be simplified: * Types and constructors of Integer and Natural can be wired-in. It means that we don't have to query them from interfaces. It also means that numeric literals don't have to carry their type with them. * The same code is used whatever ghc-bignum backend is enabled. In particular, conversion of bignum literals into final Core expressions is now much more straightforward. Bignum closure inspection too. * GHC itself doesn't depend on any integer-* package anymore * The `integerLibrary` setting is gone. - - - - - 0f67e344 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update `base` package * GHC.Natural isn't implemented in `base` anymore. It is provided by ghc-bignum in GHC.Num.Natural. It means that we can safely use Natural primitives in `base` without fearing issues with built-in rewrite rules (cf #15286) * `base` doesn't conditionally depend on an integer-* package anymore, it depends on ghc-bignum * Some duplicated code in integer-* can now be factored in GHC.Float * ghc-bignum tries to use a uniform naming convention so most of the other changes are renaming - - - - - aa9e7b71 by Sylvain Henry at 2020-06-17T16:22:03-04:00 Update `make` based build system * replace integer-* package selection with ghc-bignum backend selection - - - - - f817d816 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Update testsuite * support detection of slow ghc-bignum backend (to replace the detection of integer-simple use). There are still some test cases that the native backend doesn't handle efficiently enough. * remove tests for GMP only functions that have been removed from ghc-bignum * fix test results showing dependent packages (e.g. integer-gmp) or showing suggested instances * fix test using Integer/Natural API or showing internal names - - - - - dceecb09 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Update Hadrian * support ghc-bignum backend selection in flavours and command-line * support ghc-bignum "--check" flag (compare results of selected backend against results of the native one) in flavours and command-line (e.g. pass --bignum=check-gmp" to check the "gmp" backend) * remove the hack to workaround #15286 * build GMP only when the gmp backend is used * remove hacks to workaround `text` package flags about integer-*. We fix `text` to use ghc-bignum unconditionally in another patch - - - - - fa4281d6 by Sylvain Henry at 2020-06-17T16:22:04-04:00 Bump bytestring and text submodules - - - - - 1a3f6f34 by Adam Sandberg Ericsson at 2020-06-18T23:03:36-04:00 docs: mention -hiedir in docs for -outputdir [skip ci] - - - - - 729bcb02 by Sylvain Henry at 2020-06-18T23:04:17-04:00 Hadrian: fix build on Mac OS Catalina (#17798) - - - - - 95e18292 by Andreas Klebinger at 2020-06-18T23:04:58-04:00 Relax allocation threshold for T12150. This test performs little work, so the most minor allocation changes often cause the test to fail. Increasing the threshold to 2% should help with this. - - - - - 8ce6c393 by Sebastian Graf at 2020-06-18T23:05:36-04:00 hadrian: Bump pinned cabal.project to an existent index-state - - - - - 08c1cb0f by Ömer Sinan Ağacan at 2020-06-18T23:06:21-04:00 Fix uninitialized field read in Linker.c Valgrind report of the bug when running the test `linker_unload`: ==29666== Conditional jump or move depends on uninitialised value(s) ==29666== at 0x369C5B4: setOcInitialStatus (Linker.c:1305) ==29666== by 0x369C6C5: mkOc (Linker.c:1347) ==29666== by 0x36C027A: loadArchive_ (LoadArchive.c:522) ==29666== by 0x36C0600: loadArchive (LoadArchive.c:626) ==29666== by 0x2C144CD: ??? (in /home/omer/haskell/ghc_2/testsuite/tests/rts/linker/linker_unload.run/linker_unload) ==29666== ==29666== Conditional jump or move depends on uninitialised value(s) ==29666== at 0x369C5B4: setOcInitialStatus (Linker.c:1305) ==29666== by 0x369C6C5: mkOc (Linker.c:1347) ==29666== by 0x369C9F6: preloadObjectFile (Linker.c:1507) ==29666== by 0x369CA8D: loadObj_ (Linker.c:1536) ==29666== by 0x369CB17: loadObj (Linker.c:1557) ==29666== by 0x3866BC: main (linker_unload.c:33) The problem is `mkOc` allocates a new `ObjectCode` and calls `setOcInitialStatus` without initializing the `status` field. `setOcInitialStatus` reads the field as first thing: static void setOcInitialStatus(ObjectCode* oc) { if (oc->status == OBJECT_DONT_RESOLVE) return; if (oc->archiveMemberName == NULL) { oc->status = OBJECT_NEEDED; } else { oc->status = OBJECT_LOADED; } } `setOcInitialStatus` is unsed in two places for two different purposes: in `mkOc` where we don't have the `status` field initialized yet (`mkOc` is supposed to initialize it), and `loadOc` where we do have `status` field initialized and we want to update it. Instead of splitting the function into two functions which are both called just once I inline the functions in the use sites and remove it. Fixes #18342 - - - - - da18ff99 by Tamar Christina at 2020-06-18T23:07:03-04:00 fix windows bootstrap due to linker changes - - - - - 2af0ec90 by Sylvain Henry at 2020-06-18T23:07:47-04:00 DynFlags: store default depth in SDocContext (#17957) It avoids having to use DynFlags to reach for pprUserLength. - - - - - d4a0be75 by Sylvain Henry at 2020-06-18T23:08:35-04:00 Move tablesNextToCode field into Platform tablesNextToCode is a platform setting and doesn't belong into DynFlags (#17957). Doing this is also a prerequisite to fix #14335 where we deal with two platforms (target and host) that may have different platform settings. - - - - - 809caedf by John Ericson at 2020-06-23T22:47:37-04:00 Switch from HscSource to IsBootInterface for module lookup in GhcMake We look up modules by their name, and not their contents. There is no way to separately reference a signature vs regular module; you get what you get. Only boot files can be referenced indepenently with `import {-# SOURCE #-}`. - - - - - 7750bd45 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Cmm: introduce SAVE_REGS/RESTORE_REGS We don't want to save both Fn and Dn register sets on x86-64 as they are aliased to the same arch register (XMMn). Moreover, when SAVE_STGREGS was used in conjunction with `jump foo [*]` which makes a set of Cmm registers alive so that they cover all arch registers used to pass parameter, we could have Fn, Dn and XMMn alive at the same time. It made the LLVM code generator choke (see #17920). Now `SAVE_REGS/RESTORE_REGS` and `jump foo [*]` use the same set of registers. - - - - - 2636794d by Sylvain Henry at 2020-06-23T22:48:18-04:00 CmmToC: don't add extern decl to parsed Cmm data Previously, if a .cmm file *not in the RTS* contained something like: ```cmm section "rodata" { msg : bits8[] "Test\n"; } ``` It would get compiled by CmmToC into: ```c ERW_(msg); const char msg[] = "Test\012"; ``` and fail with: ``` /tmp/ghc32129_0/ghc_4.hc:5:12: error: error: conflicting types for \u2018msg\u2019 const char msg[] = "Test\012"; ^~~ In file included from /tmp/ghc32129_0/ghc_4.hc:3:0: error: /tmp/ghc32129_0/ghc_4.hc:4:6: error: note: previous declaration of \u2018msg\u2019 was here ERW_(msg); ^ /builds/hsyl20/ghc/_build/install/lib/ghc-8.11.0.20200605/lib/../lib/x86_64-linux-ghc-8.11.0.20200605/rts-1.0/include/Stg.h:253:46: error: note: in definition of macro \u2018ERW_\u2019 #define ERW_(X) extern StgWordArray (X) ^ ``` See the rationale for this on https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/backends/ppr-c#prototypes Now we don't generate these extern declarations (ERW_, etc.) for top-level data. It shouldn't change anything for the RTS (the only place we use .cmm files) as it is already special cased in `GHC.Cmm.CLabel.needsCDecl`. And hand-written Cmm can use explicit extern declarations when needed. Note that it allows `cgrun069` test to pass with CmmToC (cf #15467). - - - - - 5f6a0665 by Sylvain Henry at 2020-06-23T22:48:18-04:00 LLVM: refactor and comment register padding code (#17920) - - - - - cad62ef1 by Sylvain Henry at 2020-06-23T22:48:18-04:00 Add tests for #17920 Metric Decrease: T12150 T12234 - - - - - a2a9006b by Xavier Denis at 2020-06-23T22:48:56-04:00 Fix issue #18262 by zonking constraints after solving Zonk residual constraints in checkForExistence to reveal user type errors. Previously when `:instances` was used with instances that have TypeError constraints the result would look something like: instance [safe] s0 => Err 'A -- Defined at ../Bug2.hs:8:10 whereas after zonking, `:instances` now sees the `TypeError` and properly eliminates the constraint from the results. - - - - - 181516bc by Simon Peyton Jones at 2020-06-23T22:49:33-04:00 Fix a buglet in Simplify.simplCast This bug, revealed by #18347, is just a missing update to sc_hole_ty in simplCast. I'd missed a code path when I made the recentchanges in commit 6d49d5be904c0c01788fa7aae1b112d5b4dfaf1c Author: Simon Peyton Jones <simonpj at microsoft.com> Date: Thu May 21 12:53:35 2020 +0100 Implement cast worker/wrapper properly The fix is very easy. Two other minor changes * Tidy up in SimpleOpt.simple_opt_expr. In fact I think this is an outright bug, introduced in the fix to #18112: we were simplifying the same coercion twice *with the same substitution*, which is just wrong. It'd be a hard bug to trigger, so I just fixed it; less code too. * Better debug printing of ApplyToVal - - - - - 625a7f54 by Simon Peyton Jones at 2020-06-23T22:50:11-04:00 Two small tweaks to Coercion.simplifyArgsWorker These tweaks affect the inner loop of simplifyArgsWorker, which in turn is called from the flattener in Flatten.hs. This is a key perf bottleneck to T9872{a,b,c,d}. These two small changes have a modest but useful benefit. No change in functionality whatsoever. Relates to #18354 - - - - - b5768cce by Sylvain Henry at 2020-06-23T22:50:49-04:00 Don't use timesInt2# with GHC < 8.11 (fix #18358) - - - - - 7ad4085c by Sylvain Henry at 2020-06-23T22:51:27-04:00 Fix invalid printf format - - - - - a1f34d37 by Krzysztof Gogolewski at 2020-06-23T22:52:09-04:00 Add missing entry to freeNamesItem (#18369) - - - - - 03a708ba by Andreas Klebinger at 2020-06-25T03:54:37-04:00 Enable large address space optimization on windows. Starting with Win 8.1/Server 2012 windows no longer preallocates page tables for reserverd memory eagerly, which prevented us from using this approach in the past. We also try to allocate the heap high in the memory space. Hopefully this makes it easier to allocate things in the low 4GB of memory that need to be there. Like jump islands for the linker. - - - - - 7e6d3d09 by Roland Senn at 2020-06-25T03:54:38-04:00 In `:break ident` allow out of scope and nested identifiers (Fix #3000) This patch fixes the bug and implements the feature request of #3000. 1. If `Module` is a real module name and `identifier` a name of a top-level function in `Module` then `:break Module.identifer` works also for an `identifier` that is out of scope. 2. Extend the syntax for `:break identifier` to: :break [ModQual.]topLevelIdent[.nestedIdent]...[.nestedIdent] `ModQual` is optional and is either the effective name of a module or the local alias of a qualified import statement. `topLevelIdent` is the name of a top level function in the module referenced by `ModQual`. `nestedIdent` is optional and the name of a function nested in a let or where clause inside the previously mentioned function `nestedIdent` or `topLevelIdent`. If `ModQual` is a module name, then `topLevelIdent` can be any top level identifier in this module. If `ModQual` is missing or a local alias of a qualified import, then `topLevelIdent` must be in scope. Breakpoints can be set on arbitrarily deeply nested functions, but the whole chain of nested function names must be specified. 3. To support the new functionality rewrite the code to tab complete `:break`. - - - - - 30e42652 by Ben Gamari at 2020-06-25T03:54:39-04:00 make: Respect XELATEX variable Previously we simply ignored the XELATEX variable when building PDF documentation. - - - - - 4acc2934 by Ben Gamari at 2020-06-25T03:54:39-04:00 hadrian/make: Detect makeindex Previously we would simply assume that makeindex was available. Now we correctly detect it in `configure` and respect this conclusion in hadrian and make. - - - - - 0d61f866 by Simon Peyton Jones at 2020-06-25T03:54:40-04:00 Expunge GhcTcId GHC.Hs.Extension had type GhcPs = GhcPass 'Parsed type GhcRn = GhcPass 'Renamed type GhcTc = GhcPass 'Typechecked type GhcTcId = GhcTc The last of these, GhcTcId, is a vestige of the past. This patch expunges it from GHC. - - - - - 8ddbed4a by Adam Wespiser at 2020-06-25T03:54:40-04:00 add examples to Data.Traversable - - - - - 284001d0 by Oleg Grenrus at 2020-06-25T03:54:42-04:00 Export readBinIface_ - - - - - 90f43872 by Zubin Duggal at 2020-06-25T03:54:43-04:00 Export everything from HsToCore. This lets us reuse these functions in haddock, avoiding synchronization bugs. Also fixed some divergences with haddock in that file Updates haddock submodule - - - - - c7dd6da7 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part1) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Hs.* - GHC.Core.* - GHC.Stg.* - GHC.Cmm.* - GHC.Types.* - GHC.Data.* - GHC.Builtin.* - GHC.Parser.* - GHC.Driver.* - GHC top - - - - - 1eb997a8 by Takenobu Tani at 2020-06-25T03:54:44-04:00 Clean up haddock hyperlinks of GHC.* (part2) This updates haddock comments only. This patch focuses to update for hyperlinks in GHC API's haddock comments, because broken links especially discourage newcomers. This includes the following hierarchies: - GHC.Iface.* - GHC.Llvm.* - GHC.Rename.* - GHC.Tc.* - GHC.HsToCore.* - GHC.StgToCmm.* - GHC.CmmToAsm.* - GHC.Runtime.* - GHC.Unit.* - GHC.Utils.* - GHC.SysTools.* - - - - - 67a86b4d by Oleg Grenrus at 2020-06-25T03:54:46-04:00 Add MonadZip and MonadFix instances for Complex These instances are taken from https://hackage.haskell.org/package/linear-1.21/docs/Linear-Instances.html They are the unique possible, so let they be in `base`. - - - - - c50ef26e by Artem Pelenitsyn at 2020-06-25T03:54:47-04:00 test suite: add reproducer for #17516 - - - - - fe281b27 by Roland Senn at 2020-06-25T03:54:48-04:00 Enable maxBound checks for OverloadedLists (Fixes #18172) Consider the Literal `[256] :: [Data.Word.Word8]` When the `OverloadedLists` extension is not active, then the `ol_ext` field in the `OverLitTc` record that is passed to the function `getIntegralLit` contains the type `Word8`. This is a simple type, and we can use its type constructor immediately for the `warnAboutOverflowedLiterals` function. When the `OverloadedLists` extension is active, then the `ol_ext` field contains the type family `Item [Word8]`. The function `nomaliseType` is used to convert it to the needed type `Word8`. - - - - - a788d4d1 by Ben Gamari at 2020-06-25T03:54:52-04:00 rts/Hash: Simplify freeing of HashListChunks While looking at #18348 I noticed that the treatment of HashLists are a bit more complex than necessary (which lead to some initial confusion on my part). Specifically, we allocate HashLists in chunks. Each chunk allocation makes two allocations: one for the chunk itself and one for a HashListChunk to link together the chunks for the purposes of freeing. Simplify this (and hopefully make the relationship between these clearer) but allocating the HashLists and HashListChunk in a single malloc. This will both make the implementation easier to follow and reduce C heap fragmentation. Note that even after this patch we fail to bound the size of the free HashList pool. However, this is a separate bug. - - - - - d3c2d59b by Sylvain Henry at 2020-06-25T03:54:55-04:00 RTS: avoid overflow on 32-bit arch (#18375) We're now correctly computing allocated bytes on 32-bit arch, so we get huge increases. Metric Increase: haddock.Cabal haddock.base haddock.compiler space_leak_001 - - - - - a3d69dc6 by Sebastian Graf at 2020-06-25T23:06:18-04:00 GHC.Core.Unify: Make UM actions one-shot by default This MR makes the UM monad in GHC.Core.Unify into a one-shot monad. See the long Note [The one-shot state monad trick]. See also #18202 and !3309, which applies this to all Reader/State-like monads in GHC for compile-time perf improvements. The pattern used here enables something similar to the state-hack, but is applicable to user-defined monads, not just `IO`. Metric Decrease 'runtime/bytes allocated' (test_env='i386-linux-deb9'): haddock.Cabal - - - - - 9ee58f8d by Matthias Pall Gissurarson at 2020-06-26T17:12:45+00:00 Implement the proposed -XQualifiedDo extension Co-authored-by: Facundo Domínguez <facundo.dominguez at tweag.io> QualifiedDo is implemented using the same placeholders for operation names in the AST that were devised for RebindableSyntax. Whenever the renamer checks which names to use for do syntax, it first checks if the do block is qualified (e.g. M.do { stmts }), in which case it searches for qualified names in the module M. This allows users to write {-# LANGUAGE QualifiedDo #-} import qualified SomeModule as M f x = M.do -- desugars to: y <- M.return x -- M.return x M.>>= \y -> M.return y -- M.return y M.>> M.return y -- M.return y See Note [QualifiedDo] and the users' guide for more details. Issue #18214 Proposal: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0216-qualified-do.rst Since we change the constructors `ITdo` and `ITmdo` to carry the new module name, we need to bump the haddock submodule to account or the new shape of these constructors. - - - - - ce987865 by Ryan Scott at 2020-06-27T11:55:21-04:00 Revamp the treatment of auxiliary bindings for derived instances This started as a simple fix for #18321 that organically grew into a much more sweeping refactor of how auxiliary bindings for derived instances are handled. I have rewritten `Note [Auxiliary binders]` in `GHC.Tc.Deriv.Generate` to explain all of the moving parts, but the highlights are: * Previously, the OccName of each auxiliary binding would be given a suffix containing a hash of its package name, module name, and parent data type to avoid name clashes. This was needlessly complicated, so we take the more direct approach of generating `Exact` `RdrName`s for each auxiliary binding with the same `OccName`, but using an underlying `System` `Name` with a fresh `Unique` for each binding. Unlike hashes, allocating new `Unique`s does not require any cleverness and avoid name clashes all the same... * ...speaking of which, in order to convince the renamer that multiple auxiliary bindings with the same `OccName` (but different `Unique`s) are kosher, we now use `rnLocalValBindsLHS` instead of `rnTopBindsLHS` to rename auxiliary bindings. Again, see `Note [Auxiliary binders]` for the full story. * I have removed the `DerivHsBind` constructor for `DerivStuff`—which was only used for `Data.Data`-related auxiliary bindings—and refactored `gen_Data_binds` to use `DerivAuxBind` instead. This brings the treatment of `Data.Data`-related auxiliary bindings in line with every other form of auxiliary binding. Fixes #18321. - - - - - a403eb91 by Sylvain Henry at 2020-06-27T11:55:59-04:00 ghc-bignum: fix division by zero (#18359) - - - - - 1b3d13b6 by Sylvain Henry at 2020-06-27T11:55:59-04:00 Fix ghc-bignum exceptions We must ensure that exceptions are not simplified. Previously we used: case raiseDivZero of _ -> 0## -- dummyValue But it was wrong because the evaluation of `raiseDivZero` was removed and the dummy value was directly returned. See new Note [ghc-bignum exceptions]. I've also removed the exception triggering primops which were fragile. We don't need them to be primops, we can have them exported by ghc-prim. I've also added a test for #18359 which triggered this patch. - - - - - a74ec37c by Simon Peyton Jones at 2020-06-27T11:56:34-04:00 Better loop detection in findTypeShape Andreas pointed out, in !3466, that my fix for #18304 was not quite right. This patch fixes it properly, by having just one RecTcChecker rather than (implicitly) two nested ones, in findTypeShape. - - - - - a04020b8 by Sylvain Henry at 2020-06-27T11:57:11-04:00 DynFlags: don't store buildTag `DynFlags.buildTag` was a field created from the set of Ways in `DynFlags.ways`. It had to be kept in sync with `DynFlags.ways` which was fragile. We want to avoid global state like this (#17957). Moreover in #14335 we also want to support loading units with different ways: target units would still use `DynFlags.ways` but plugins would use `GHC.Driver.Ways.hostFullWays`. To avoid having to deal both with build tag and with ways, we recompute the buildTag on-the-fly (should be pretty cheap) and we remove `DynFlags.buildTag` field. - - - - - 0e83efa2 by Krzysztof Gogolewski at 2020-06-27T11:57:49-04:00 Don't generalize when typechecking a tuple section The code is simpler and cleaner. - - - - - d8ba9e6f by Peter Trommler at 2020-06-28T09:19:11-04:00 RTS: Refactor Haskell-C glue for PPC 64-bit Make sure the stack is 16 byte aligned even when reserved stack bytes are not a multiple of 16 bytes. Avoid saving r2 (TOC). On ELF v1 the function descriptor of StgReturn has the same TOC as StgRun, on ELF v2 the TOC is recomputed in the function prologue. Use the ABI provided functions to save clobbered GPRs and FPRs. Improve comments. Describe what the stack looks like and how it relates to the respective ABIs. - - - - - 42f797b0 by Ryan Scott at 2020-06-28T09:19:46-04:00 Use NHsCoreTy to embed types into GND-generated code `GeneralizedNewtypeDeriving` is in the unique situation where it must produce an `LHsType GhcPs` from a Core `Type`. Historically, this was done with the `typeToLHsType` function, which walked over the entire `Type` and attempted to construct an `LHsType` with the same overall structure. `typeToLHsType` is quite complicated, however, and has been the subject of numerous bugs over the years (e.g., #14579). Luckily, there is an easier way to accomplish the same thing: the `XHsType` constructor of `HsType`. `XHsType` bundles an `NHsCoreTy`, which allows embedding a Core `Type` directly into an `HsType`, avoiding the need to laboriously convert from one to another (as `typeToLHsType` did). Moreover, renaming and typechecking an `XHsType` is simple, since one doesn't need to do anything to a Core `Type`... ...well, almost. For the reasons described in `Note [Typechecking NHsCoreTys]` in `GHC.Tc.Gen.HsType`, we must apply a substitution that we build from the local `tcl_env` type environment. But that's a relatively modest price to pay. Now that `GeneralizedNewtypeDeriving` uses `NHsCoreTy`, the `typeToLHsType` function no longer has any uses in GHC, so this patch rips it out. Some additional tweaks to `hsTypeNeedsParens` were necessary to make the new `-ddump-deriv` output correctly parenthesized, but other than that, this patch is quite straightforward. This is a mostly internal refactoring, although it is likely that `GeneralizedNewtypeDeriving`-generated code will now need fewer language extensions in certain situations than it did before. - - - - - 68530b1c by Jan Hrček at 2020-06-28T09:20:22-04:00 Fix duplicated words and typos in comments and user guide - - - - - 15b79bef by Ryan Scott at 2020-06-28T09:20:57-04:00 Add integer-gmp's ghc.mk and GNUmakefile to .gitignore - - - - - bfa5698b by Simon Peyton Jones at 2020-06-28T09:21:32-04:00 Fix a typo in Lint This simple error in GHC.Core.Litn.lintJoinLams meant that Lint reported bogus errors. Fixes #18399 - - - - - 71006532 by Ryan Scott at 2020-06-30T07:10:42-04:00 Reject nested foralls/contexts in instance types more consistently GHC is very wishy-washy about rejecting instance declarations with nested `forall`s or contexts that are surrounded by outermost parentheses. This can even lead to some strange interactions with `ScopedTypeVariables`, as demonstrated in #18240. This patch makes GHC more consistently reject instance types with nested `forall`s/contexts so as to prevent these strange interactions. On the implementation side, this patch tweaks `splitLHsInstDeclTy` and `getLHsInstDeclHead` to not look through parentheses, which can be semantically significant. I've added a `Note [No nested foralls or contexts in instance types]` in `GHC.Hs.Type` to explain why. This also introduces a `no_nested_foralls_contexts_err` function in `GHC.Rename.HsType` to catch nested `forall`s/contexts in instance types. This function is now used in `rnClsInstDecl` (for ordinary instance declarations) and `rnSrcDerivDecl` (for standalone `deriving` declarations), the latter of which fixes #18271. On the documentation side, this adds a new "Formal syntax for instance declaration types" section to the GHC User's Guide that presents a BNF-style grammar for what is and isn't allowed in instance types. Fixes #18240. Fixes #18271. - - - - - bccf3351 by Sylvain Henry at 2020-06-30T07:10:46-04:00 Add ghc-bignum to 8.12 release notes - - - - - 81704a6f by David Eichmann at 2020-06-30T07:10:48-04:00 Update ssh keys in CI performance metrics upload script - - - - - 85310fb8 by Joshua Price at 2020-06-30T07:10:49-04:00 Add missing Ix instances for tuples of size 6 through 15 (#16643) - - - - - cbb6b62f by Vladislav Zavialov at 2020-07-01T15:41:38-04:00 Implement -XLexicalNegation (GHC Proposal #229) This patch introduces a new extension, -XLexicalNegation, which detects whether the minus sign stands for negation or subtraction using the whitespace-based rules described in GHC Proposal #229. Updates haddock submodule. - - - - - fb5a0d01 by Martin Handley at 2020-07-01T15:42:14-04:00 #17169: Clarify Fixed's Enum instance. - - - - - b316804d by Simon Peyton Jones at 2020-07-01T15:42:49-04:00 Improve debug tracing for substitution This patch improves debug tracing a bit (#18395) * Remove the ancient SDoc argument to substitution, replacing it with a HasDebugCallStack constraint. The latter does the same job (indicate the call site) but much better. * Add HasDebugCallStack to simpleOptExpr, exprIsConApp_maybe I needed this to help nail the lookupIdSubst panic in #18326, #17784 - - - - - 5c9fabb8 by Hécate at 2020-07-01T15:43:25-04:00 Add most common return values for `os` and `arch` - - - - - 76d8cc74 by Ryan Scott at 2020-07-01T15:44:01-04:00 Desugar quoted uses of DerivingVia and expression type signatures properly The way that `GHC.HsToCore.Quote` desugared quoted `via` types (e.g., `deriving via forall a. [a] instance Eq a => Eq (List a)`) and explicit type annotations in signatures (e.g., `f = id @a :: forall a. a -> a`) was completely wrong, as it did not implement the scoping guidelines laid out in `Note [Scoped type variables in bindings]`. This is easily fixed. While I was in town, I did some minor cleanup of related Notes: * `Note [Scoped type variables in bindings]` and `Note [Scoped type variables in class and instance declarations]` say very nearly the same thing. I decided to just consolidate the two Notes into `Note [Scoped type variables in quotes]`. * `Note [Don't quantify implicit type variables in quotes]` is somewhat outdated, as it predates GHC 8.10, where the `forall`-or-nothing rule requires kind variables to be explicitly quantified in the presence of an explicit `forall`. As a result, the running example in that Note doesn't even compile. I have changed the example to something simpler that illustrates the same point that the original Note was making. Fixes #18388. - - - - - 44d6a335 by Andreas Klebinger at 2020-07-02T02:54:54-04:00 T16012: Be verbose on failure. - - - - - f9853330 by Ryan Scott at 2020-07-02T02:55:29-04:00 Bump ghc-prim version to 0.7.0 Fixes #18279. Bumps the `text` submodule. - - - - - 23e4e047 by Sylvain Henry at 2020-07-02T10:46:31-04:00 Hadrian: fix PowerPC64le support (#17601) [ci skip] - - - - - 3cdd8d69 by Sylvain Henry at 2020-07-02T10:47:08-04:00 NCG: correctly handle addresses with huge offsets (#15570) Before this patch we could generate addresses of this form: movzbl cP0_str+-9223372036854775808,%eax The linker can't handle them because the offset is too large: ld.lld: error: Main.o:(.text+0xB3): relocation R_X86_64_32S out of range: -9223372036852653050 is not in [-2147483648, 2147483647] With this patch we detect those cases and generate: movq $-9223372036854775808,%rax addq $cP0_str,%rax movzbl (%rax),%eax I've also refactored `getAmode` a little bit to make it easier to understand and to trace. - - - - - 4d90b3ff by Gabor Greif at 2020-07-02T20:07:59-04:00 No need for CURSES_INCLUDE_DIRS This is a leftover from ef63ff27251a20ff11e58c9303677fa31e609a88 - - - - - f08d6316 by Sylvain Henry at 2020-07-02T20:08:36-04:00 Replace Opt_SccProfilingOn flag with sccProfilingEnabled helper function SCC profiling was enabled in a convoluted way: if WayProf was enabled, Opt_SccProfilingOn general flag was set (in `GHC.Driver.Ways.wayGeneralFlags`), and then this flag was queried in various places. There is no need to go via general flags, so this patch defines a `sccProfilingEnabled :: DynFlags -> Bool` helper function that just checks whether WayProf is enabled. - - - - - 8cc7274b by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Only allocate the Censuses that we need When not LDV profiling there is no reason to allocate 32 Censuses; one will do. This is a very small memory footprint optimisation, but it comes for free. - - - - - b835112c by Ben Gamari at 2020-07-03T02:49:27-04:00 rts/ProfHeap: Free old allocations when reinitialising Censuses Previously when not LDV profiling we would repeatedly reinitialise `censuses[0]` with `initEra`. This failed to free the `Arena` and `HashTable` from the old census, resulting in a memory leak. Fixes #18348. - - - - - 34be6523 by Valery Tolstov at 2020-07-03T02:50:03-04:00 Mention flags that are not enabled by -Wall (#18372) * Mention missing flags that are not actually enabled by -Wall (docs/users_guide/using-warnings.rst) * Additionally remove -Wmissing-monadfail-instances from the list of flags enabled by -Wcompat, as it is not the case since 8.8 - - - - - edc8d22b by Sylvain Henry at 2020-07-03T02:50:40-04:00 LLVM: support R9 and R10 registers d535ef006d85dbdb7cda2b09c5bc35cb80108909 allowed the use of up to 10 vanilla registers but didn't update LLVM backend to support them. This patch fixes it. - - - - - 4bf18646 by Simon Peyton Jones at 2020-07-03T08:37:42+01:00 Improve handling of data type return kinds Following a long conversation with Richard, this patch tidies up the handling of return kinds for data/newtype declarations (vanilla, family, and instance). I have substantially edited the Notes in TyCl, so they would bear careful reading. Fixes #18300, #18357 In GHC.Tc.Instance.Family.newFamInst we were checking some Lint-like properties with ASSSERT. Instead Richard and I have added a proper linter for axioms, and called it from lintGblEnv, which in turn is called in tcRnModuleTcRnM New tests (T18300, T18357) cause an ASSERT failure in HEAD. - - - - - 41d26492 by Sylvain Henry at 2020-07-03T17:33:59-04:00 DynFlags: avoid the use of sdocWithDynFlags in GHC.Core.Rules (#17957) - - - - - 7aa6ef11 by Hécate at 2020-07-03T17:34:36-04:00 Add the __GHC_FULL_VERSION__ CPP macro to expose the full GHC version - - - - - e61d5395 by Chaitanya Koparkar at 2020-07-07T13:55:59-04:00 ghc-prim: Turn some comments into haddocks [ci skip] - - - - - 37743f91 by John Ericson at 2020-07-07T13:56:00-04:00 Support `timesInt2#` in LLVM backend - - - - - 46397e53 by John Ericson at 2020-07-07T13:56:00-04:00 `genericIntMul2Op`: Call `genericWordMul2Op` directly This unblocks a refactor, and removes partiality. It might be a PowerPC regression but that should be fixable. - - - - - 8a1c0584 by John Ericson at 2020-07-07T13:56:00-04:00 Simplify `PrimopCmmEmit` Follow @simonpj's suggestion of pushing the "into regs" logic into `emitPrimOp`. With the previous commit getting rid of the recursion in `genericIntMul2Op`, this is now an easy refactor. - - - - - 6607f203 by John Ericson at 2020-07-07T13:56:00-04:00 `opAllDone` -> `opIntoRegs` The old name was and terrible and became worse after the previous commit's refactor moved non-trivial funcationlity into its body. - - - - - fdcc53ba by Sylvain Henry at 2020-07-07T13:56:00-04:00 Optimise genericIntMul2Op We shouldn't directly call 'genericWordMul2Op' in genericIntMul2Op because a target may provide a faster primop for 'WordMul2Op': we'd better use it! - - - - - 686e7225 by Moritz Angermann at 2020-07-07T13:56:01-04:00 [linker/rtsSymbols] More linker symbols Mostly symbols needed for aarch64/armv7l and in combination with musl, where we have to rely on loading *all* objects/archives - __stack_chk_* only when not DYNAMIC - - - - - 3f60b94d by Moritz Angermann at 2020-07-07T13:56:01-04:00 better if guards. - - - - - 7abffced by Moritz Angermann at 2020-07-07T13:56:01-04:00 Fix (1) - - - - - cdfeb3f2 by Moritz Angermann at 2020-07-07T13:56:01-04:00 AArch32 symbols only on aarch32. - - - - - f496c955 by Adam Sandberg Ericsson at 2020-07-07T13:56:02-04:00 add -flink-rts flag to link the rts when linking a shared or static library #18072 By default we don't link the RTS when linking shared libraries because in the most usual mode a shared library is an intermediary product, for example a Haskell library, that will be linked into some executable in the end. So we wish to defer the RTS flavour to link to the final link. However sometimes the final product is the shared library, for example when writing a plugin for some other system, so we do wish the shared library to link the RTS. For consistency we also make -staticlib honor this flag and its inversion. -staticlib currently implies -flink-shared. - - - - - c59faf67 by Stefan Schulze Frielinghaus at 2020-07-07T13:56:04-04:00 hadrian: link check-ppr against debugging RTS if ghcDebugged - - - - - 0effc57d by Adam Sandberg Ericsson at 2020-07-07T13:56:05-04:00 rts linker: teach the linker about GLIBC's special handling of *stat, mknod and atexit functions #7072 - - - - - 96153433 by Adam Sandberg Ericsson at 2020-07-07T13:56:06-04:00 hadrian: make hadrian/ghci use the bootstrap compiler from configure #18190 - - - - - 4d24f886 by Adam Sandberg Ericsson at 2020-07-07T13:56:07-04:00 hadrian: ignore cabal configure verbosity related flags #18131 - - - - - 7332bbff by Ben Gamari at 2020-07-07T13:56:08-04:00 testsuite: Widen T12234 acceptance window to 2% Previously it wasn't uncommon to see +/-1% fluctuations in compiler allocations on this test. - - - - - 180b6313 by Gabor Greif at 2020-07-07T13:56:08-04:00 When running libtool, report it as such - - - - - d3bd6897 by Sylvain Henry at 2020-07-07T13:56:11-04:00 BigNum: rename BigNat types Before this patch BigNat names were confusing because we had: * GHC.Num.BigNat.BigNat: unlifted type used everywhere else * GHC.Num.BigNat.BigNatW: lifted type only used to share static constants * GHC.Natural.BigNat: lifted type only used for backward compatibility After this patch we have: * GHC.Num.BigNat.BigNat#: unlifted type * GHC.Num.BigNat.BigNat: lifted type (reexported from GHC.Natural) Thanks to @RyanGlScott for spotting this. - - - - - 929d26db by Sylvain Henry at 2020-07-07T13:56:12-04:00 Bignum: don't build ghc-bignum with stage0 Noticed by @Ericson2314 - - - - - d25b6851 by Sylvain Henry at 2020-07-07T13:56:12-04:00 Hadrian: ghc-gmp.h shouldn't be a compiler dependency - - - - - 0ddae2ba by Sylvain Henry at 2020-07-07T13:56:14-04:00 DynFlags: factor out pprUnitId from "Outputable UnitId" instance - - - - - 204f3f5d by Krzysztof Gogolewski at 2020-07-07T13:56:18-04:00 Remove unused function pprHsForAllExtra (#18423) The function `pprHsForAllExtra` was called only on `Nothing` since 2015 (1e041b7382b6aa). - - - - - 3033e0e4 by Adam Sandberg Ericsson at 2020-07-08T20:36:49-04:00 hadrian: add flag to skip rebuilding dependency information #17636 - - - - - b7de4b96 by Stefan Schulze Frielinghaus at 2020-07-09T09:49:22-04:00 Fix GHCi :print on big-endian platforms On big-endian platforms executing import GHC.Exts data Foo = Foo Float# deriving Show foo = Foo 42.0# foo :print foo results in an arithmetic overflow exception which is caused by function index where moveBytes equals word_size - (r + item_size_b) * 8 Here we have a mixture of units. Both, word_size and item_size_b have unit bytes whereas r has unit bits. On 64-bit platforms moveBytes equals then 8 - (0 + 4) * 8 which results in a negative and therefore invalid second parameter for a shiftL operation. In order to make things more clear the expression (word .&. (mask `shiftL` moveBytes)) `shiftR` moveBytes is equivalent to (word `shiftR` moveBytes) .&. mask On big-endian platforms the shift must be a left shift instead of a right shift. For symmetry reasons not a mask is used but two shifts in order to zero out bits. Thus the fixed version equals case endian of BigEndian -> (word `shiftL` moveBits) `shiftR` zeroOutBits `shiftL` zeroOutBits LittleEndian -> (word `shiftR` moveBits) `shiftL` zeroOutBits `shiftR` zeroOutBits Fixes #16548 and #14455 - - - - - 3656dff8 by Sylvain Henry at 2020-07-09T09:50:01-04:00 LLVM: fix MO_S_Mul2 support (#18434) The value indicating if the carry is useful wasn't taken into account. - - - - - d9f09506 by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Define multiShotIO and use it in mkSplitUniqueSupply This patch is part of the ongoing eta-expansion saga; see #18238. It implements a neat trick (suggested by Sebastian Graf) that allows the programmer to disable the default one-shot behaviour of IO (the "state hack"). The trick is to use a new multiShotIO function; see Note [multiShotIO]. For now, multiShotIO is defined here in Unique.Supply; but it should ultimately be moved to the IO library. The change is necessary to get good code for GHC's unique supply; see Note [Optimising the unique supply]. However it makes no difference to GHC as-is. Rather, it makes a difference when a subsequent commit Improve eta-expansion using ArityType lands. - - - - - bce695cc by Simon Peyton Jones at 2020-07-10T10:33:44-04:00 Make arityType deal with join points As Note [Eta-expansion and join points] describes, this patch makes arityType deal correctly with join points. What was there before was not wrong, but yielded lower arities than it could. Fixes #18328 In base GHC this makes no difference to nofib. Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- n-body -0.1% -0.1% -1.2% -1.1% 0.0% -------------------------------------------------------------------------------- Min -0.1% -0.1% -55.0% -56.5% 0.0% Max -0.0% 0.0% +16.1% +13.4% 0.0% Geometric Mean -0.0% -0.0% -30.1% -31.0% -0.0% But it starts to make real difference when we land the change to the way mkDupableAlts handles StrictArg, in fixing #13253 and friends. I think this is because we then get more non-inlined join points. - - - - - 2b7c71cb by Simon Peyton Jones at 2020-07-11T12:17:02-04:00 Improve eta-expansion using ArityType As #18355 shows, we were failing to preserve one-shot info when eta-expanding. It's rather easy to fix, by using ArityType more, rather than just Arity. This patch is important to suport the one-shot monad trick; see #18202. But the extra tracking of one-shot-ness requires the patch Define multiShotIO and use it in mkSplitUniqueSupply If that patch is missing, ths patch makes things worse in GHC.Types.Uniq.Supply. With it, however, we see these improvements T3064 compiler bytes allocated -2.2% T3294 compiler bytes allocated -1.3% T12707 compiler bytes allocated -1.3% T13056 compiler bytes allocated -2.2% Metric Decrease: T3064 T3294 T12707 T13056 - - - - - de139cc4 by Artem Pelenitsyn at 2020-07-12T02:53:20-04:00 add reproducer for #15630 - - - - - c4de6a7a by Andreas Klebinger at 2020-07-12T02:53:55-04:00 Give Uniq[D]FM a phantom type for its key. This fixes #17667 and should help to avoid such issues going forward. The changes are mostly mechanical in nature. With two notable exceptions. * The register allocator. The register allocator references registers by distinct uniques. However they come from the types of VirtualReg, Reg or Unique in various places. As a result we sometimes cast the key type of the map and use functions which operate on the now typed map but take a raw Unique as actual key. The logic itself has not changed it just becomes obvious where we do so now. * <Type>Env Modules. As an example a ClassEnv is currently queried using the types `Class`, `Name`, and `TyCon`. This is safe since for a distinct class value all these expressions give the same unique. getUnique cls getUnique (classTyCon cls) getUnique (className cls) getUnique (tcName $ classTyCon cls) This is for the most part contained within the modules defining the interface. However it requires us to play dirty when we are given a `Name` to lookup in a `UniqFM Class a` map. But again the logic did not change and it's for the most part hidden behind the Env Module. Some of these cases could be avoided by refactoring but this is left for future work. We also bump the haddock submodule as it uses UniqFM. - - - - - c2cfdfde by Aaron Allen at 2020-07-13T09:00:33-04:00 Warn about empty Char enumerations (#18402) Currently the "Enumeration is empty" warning (-Wempty-enumerations) only fires for numeric literals. This patch adds support for `Char` literals so that enumerating an empty list of `Char`s will also trigger the warning. - - - - - c3ac87ec by Stefan Schulze Frielinghaus at 2020-07-13T09:01:10-04:00 hadrian: build check-ppr dynamic if GHC is build dynamic Fixes #18361 - - - - - 9ad072b4 by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Use dumpStyle when printing inlinings This just makes debug-printing consistent, and more informative. - - - - - e78c4efb by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Comments only - - - - - 7ccb760b by Simon Peyton Jones at 2020-07-13T14:52:49-04:00 Reduce result discount in conSize Ticket #18282 showed that the result discount given by conSize was massively too large. This patch reduces that discount to a constant 10, which just balances the cost of the constructor application itself. Note [Constructor size and result discount] elaborates, as does the ticket #18282. Reducing result discount reduces inlining, which affects perf. I found that I could increase the unfoldingUseThrehold from 80 to 90 in compensation; in combination with the result discount change I get these overall nofib numbers: Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer -0.2% +5.4% -3.2% -3.4% 0.0% cichelli -0.1% +5.9% -11.2% -11.7% 0.0% compress2 -0.2% +9.6% -6.0% -6.8% 0.0% cryptarithm2 -0.1% -3.9% -6.0% -5.7% 0.0% gamteb -0.2% +2.6% -13.8% -14.4% 0.0% genfft -0.1% -1.6% -29.5% -29.9% 0.0% gg -0.0% -2.2% -17.2% -17.8% -20.0% life -0.1% -2.2% -62.3% -63.4% 0.0% mate +0.0% +1.4% -5.1% -5.1% -14.3% parser -0.2% -2.1% +7.4% +6.7% 0.0% primetest -0.2% -12.8% -14.3% -14.2% 0.0% puzzle -0.2% +2.1% -10.0% -10.4% 0.0% rsa -0.2% -11.7% -3.7% -3.8% 0.0% simple -0.2% +2.8% -36.7% -38.3% -2.2% wheel-sieve2 -0.1% -19.2% -48.8% -49.2% -42.9% -------------------------------------------------------------------------------- Min -0.4% -19.2% -62.3% -63.4% -42.9% Max +0.3% +9.6% +7.4% +11.0% +16.7% Geometric Mean -0.1% -0.3% -17.6% -18.0% -0.7% I'm ok with these numbers, remembering that this change removes an *exponential* increase in code size in some in-the-wild cases. I investigated compress2. The difference is entirely caused by this function no longer inlining WriteRoutines.$woutputCodes = \ (w :: [CodeEvent]) -> let result_s1Sr = case WriteRoutines.outputCodes_$s$woutput w 0# 0# 8# 9# of (# ww1, ww2 #) -> (ww1, ww2) in (# case result_s1Sr of (x, _) -> map @Int @Char WriteRoutines.outputCodes1 x , case result_s1Sr of { (_, y) -> y } #) It was right on the cusp before, driven by the excessive result discount. Too bad! Happily, the compiler/perf tests show a number of improvements: T12227 compiler bytes-alloc -6.6% T12545 compiler bytes-alloc -4.7% T13056 compiler bytes-alloc -3.3% T15263 runtime bytes-alloc -13.1% T17499 runtime bytes-alloc -14.3% T3294 compiler bytes-alloc -1.1% T5030 compiler bytes-alloc -11.7% T9872a compiler bytes-alloc -2.0% T9872b compiler bytes-alloc -1.2% T9872c compiler bytes-alloc -1.5% Metric Decrease: T12227 T12545 T13056 T15263 T17499 T3294 T5030 T9872a T9872b T9872c - - - - - 7f0b671e by Ben Gamari at 2020-07-13T14:52:49-04:00 testsuite: Widen acceptance threshold on T5837 This test is positively tiny and consequently the bytes allocated measurement will be relatively noisy. Consequently I have seen this fail spuriously quite often. - - - - - 118e1c3d by Alp Mestanogullari at 2020-07-14T21:30:52-04:00 compiler: re-engineer the treatment of rebindable if Executing on the plan described in #17582, this patch changes the way if expressions are handled in the compiler in the presence of rebindable syntax. We get rid of the SyntaxExpr field of HsIf and instead, when rebindable syntax is on, we rewrite the HsIf node to the appropriate sequence of applications of the local `ifThenElse` function. In order to be able to report good error messages, with expressions as they were written by the user (and not as desugared by the renamer), we make use of TTG extensions to extend GhcRn expression ASTs with an `HsExpansion` construct, which keeps track of a source (GhcPs) expression and the desugared (GhcRn) expression that it gives rise to. This way, we can typecheck the latter while reporting the former in error messages. In order to discard the error context lines that arise from typechecking the desugared expressions (because they talk about expressions that the user has not written), we carefully give a special treatment to the nodes fabricated by this new renaming-time transformation when typechecking them. See Note [Rebindable syntax and HsExpansion] for more details. The note also includes a recipe to apply the same treatment to other rebindable constructs. Tests 'rebindable11' and 'rebindable12' have been added to make sure we report identical error messages as before this patch under various circumstances. We also now disable rebindable syntax when processing untyped TH quotes, as per the discussion in #18102 and document the interaction of rebindable syntax and Template Haskell, both in Note [Template Haskell quotes and Rebindable Syntax] and in the user guide, adding a test to make sure that we do not regress in that regard. - - - - - 64c774b0 by Andreas Klebinger at 2020-07-14T21:31:27-04:00 Explain why keeping DynFlags in AnalEnv saves allocation. - - - - - 254245d0 by Ben Gamari at 2020-07-14T21:32:03-04:00 docs/users-guide: Update default -funfolding-use-threshold value This was changed in 3d2991f8 but I neglected to update the documentation. Fixes #18419. - - - - - 4c259f86 by Andreas Klebinger at 2020-07-14T21:32:41-04:00 Escape backslashes in json profiling reports properly. I also took the liberty to do away the fixed buffer size for escaping. Using a fixed size here can only lead to issues down the line. Fixes #18438. - - - - - 23797224 by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 .gitlab: re-enable integer-simple substitute (BIGNUM_BACKEND) Recently build system migrated from INTEGER_LIBRARY to BIGNUM_BACKEND. But gitlab CI was never updated. Let's enable BIGNUM_BACKEND=native. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - e0db878a by Sergei Trofimovich at 2020-07-14T21:33:19-04:00 ghc-bignum: bring in sync .hs-boot files with module declarations Before this change `BIGNUM_BACKEND=native` build was failing as: ``` libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs:708:16: error: * Variable not in scope: naturalFromBigNat# :: WordArray# -> t * Perhaps you meant one of these: `naturalFromBigNat' (imported from GHC.Num.Natural), `naturalToBigNat' (imported from GHC.Num.Natural) | 708 | m' = naturalFromBigNat# m | ``` This happens because `.hs-boot` files are slightly out of date. This change brings in data and function types in sync. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - c9f65c36 by Stefan Schulze Frielinghaus at 2020-07-14T21:33:57-04:00 rts/Disassembler.c: Use FMT_HexWord for printing values in hex format - - - - - 58ae62eb by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 macOS: Load frameworks without stating them first. macOS Big Sur makes the following change to how frameworks are shipped with the OS: > New in macOS Big Sur 11 beta, the system ships with a built-in > dynamic linker cache of all system-provided libraries. As part of > this change, copies of dynamic libraries are no longer present on > the filesystem. Code that attempts to check for dynamic library > presence by looking for a file at a path or enumerating a directory > will fail. Instead, check for library presence by attempting to > dlopen() the path, which will correctly check for the library in the > cache. (62986286) https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/ Therefore, the previous method of checking whether a library exists before attempting to load it makes GHC.Runtime.Linker.loadFramework fail to find frameworks installed at /System/Library/Frameworks. GHC.Runtime.Linker.loadFramework now opportunistically loads the framework libraries without checking for their existence first, failing only if all attempts to load a given framework from any of the various possible locations fail. - - - - - cdc4a6b0 by Matthias Andreas Benkard at 2020-07-14T21:34:35-04:00 loadFramework: Output the errors collected in all loading attempts. With the recent change away from first finding and then loading a framework, loadFramework had no way of communicating the real reason why loadDLL failed if it was any reason other than the framework missing from the file system. It now collects all loading attempt errors into a list and concatenates them into a string to return to the caller. - - - - - 51dbfa52 by Ben Gamari at 2020-07-15T04:05:34-04:00 StgToCmm: Use CmmRegOff smart constructor Previously we would generate expressions of the form `CmmRegOff BaseReg 0`. This should do no harm (and really should be handled by the NCG anyways) but it's better to just generate a plain `CmmReg`. - - - - - ae11bdfd by Ben Gamari at 2020-07-15T04:06:08-04:00 testsuite: Add regression test for #17744 Test due to @monoidal. - - - - - 0e3c277a by Ben Gamari at 2020-07-15T16:41:01-04:00 Bump Cabal submodule Updates a variety of tests as Cabal is now more strict about Cabal file form. - - - - - ceed994a by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Drop Windows Vista support, require Windows 7 - - - - - 00a23bfd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Update Windows FileSystem wrapper utilities. - - - - - 459e1c5f by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Use SlimReaderLocks and ConditonalVariables provided by the OS instead of emulated ones - - - - - 763088fc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Small linker comment and ifdef cleanups - - - - - 1a228ff9 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Flush event logs eagerly. - - - - - e9e04dda by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Refactor Buffer structures to be able to track async operations - - - - - 356dc3fe by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Implement new Console API - - - - - 90e69f77 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add IOPort synchronization primitive - - - - - 71245fcc by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add new io-manager cmdline options - - - - - d548a3b3 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Init Windows console Codepage to UTF-8. - - - - - 58ef6366 by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add unsafeSplat to GHC.Event.Array - - - - - d660725e by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Add size and iterate to GHC.Event.IntTable. - - - - - 050da6dd by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Switch Testsuite to test winio by default - - - - - 4bf542bf by Tamar Christina at 2020-07-15T16:41:01-04:00 winio: Multiple refactorings and support changes. - - - - - 4489af6b by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core threaded I/O manager - - - - - 64d8f2fe by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: core non-threaded I/O manager - - - - - 8da15a09 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix a scheduler bug with the threaded-runtime. - - - - - 84ea3d14 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Relaxing some constraints in io-manager. - - - - - ccf0d107 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Fix issues with non-threaded I/O manager after split. - - - - - b492fe6e by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Remove some barf statements that are a bit strict. - - - - - 01423fd2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Expand comments describing non-threaded loop - - - - - 4b69004f by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: fix FileSize unstat-able handles - - - - - 9b384270 by Tamar Christina at 2020-07-15T16:41:02-04:00 winio: Implement new tempfile routines for winio - - - - - f1e0be82 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix input truncation when reading from handle. This was caused by not upholding the read buffer invariant that bufR == bufL == 0 for empty read buffers. - - - - - e176b625 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix output truncation for writes larger than buffer size - - - - - a831ce0e by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Rewrite bufWrite. I think it's far easier to follow the code now. It's also correct now as I had still missed a spot where we didn't update the offset. - - - - - 6aefdf62 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix offset set by bufReadEmpty. bufReadEmpty returns the bytes read *including* content that was already buffered, But for calculating the offset we only care about the number of bytes read into the new buffer. - - - - - 750ebaee by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Clean up code surrounding IOPort primitives. According to phyx these should only be read and written once per object. Not neccesarily in that order. To strengthen that guarantee the primitives will now throw an exception if we violate this invariant. As a consequence we can eliminate some code from their primops. In particular code dealing with multiple queued readers/writers now simply checks the invariant and throws an exception if it was violated. That is in contrast to mvars which will do things like wake up all readers, queue multi writers etc. - - - - - ffd31db9 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix multi threaded threadDelay and a few other small changes. Multithreaded threadDelay suffered from a race condition based on the ioManagerStatus. Since the status isn't needed for WIO I removed it completely. This resulted in a light refactoring, as consequence we will always wake up the IO manager using interruptSystemManager, which uses `postQueuedCompletionStatus` internally. I also added a few comments which hopefully makes the code easier to dive into for the next person diving in. - - - - - 6ec26df2 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 wionio: Make IO subsystem check a no-op on non-windows platforms. - - - - - 29bcd936 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Set handle offset when opening files in Append mode. Otherwise we would truncate the file. - - - - - 55c29700 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Remove debug event log trace - - - - - 9acb9f40 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix sqrt and openFile009 test cases - - - - - 57017cb7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Allow hp2ps to build with -DDEBUG - - - - - b8cd9995 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update output of T9681 since we now actually run it. - - - - - 10af5b14 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: A few more improvements to the IOPort primitives. - - - - - 39afc4a7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix expected tempfiles output. Tempfiles now works properly on windows, as such we can delete the win32 specific output. - - - - - 99db46e0 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Assign thread labels to IOManager threads. - - - - - be6af732 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Properly check for the tso of an incall to be zero. - - - - - e2c6dac7 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark FD instances as unsupported under WINIO. - - - - - fd02ceed by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Fix threadDelay maxBound invocations. Instead of letting the ns timer overflow now clamp it at (maxBound :: Word64) ns. That still gives a few hundred years. - - - - - bc79f9f1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comments/cleanup an import in base - - - - - 1d197f4b by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Mark outstanding_service_requests volatile. As far as I know C(99) gives no guarantees for code like bool condition; ... while(condition) sleep(); that condition will be updated if it's changed by another thread. So we are explicit here and mark it as volatile, this will force a reload from memory on each iteration. - - - - - dc438186 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Make last_event a local variable - - - - - 2fc957c5 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add comment about thread safety of processCompletion. - - - - - 4c026b6c by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: nonthreaded: Create io processing threads in main thread. We now set a flag in the IO thread. The scheduler when looking for work will check the flag and create/queue threads accordingly. We used to create these in the IO thread. This improved performance but caused frequent segfaults. Thread creation/allocation is only safe to do if nothing currently accesses the storeagemanager. However without locks in the non-threaded runtime this can't be guaranteed. This shouldn't change performance all too much. In the past we had: * IO: Create/Queue thread. * Scheduler: Runs a few times. Eventually picks up IO processing thread. Now it's: * IO: Set flag to queue thread. * Scheduler: Pick up flag, if set create/queue thread. Eventually picks up IO processing thread. - - - - - f47c7208 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Add an exported isHeapAlloced function to the RTS - - - - - cc5d7bb1 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Queue IO processing threads at the front of the queue. This will unblock the IO thread sooner hopefully leading to higher throughput in some situations. - - - - - e7630115 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: ThreadDelay001: Use higher resolution timer. - - - - - 451b5f96 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Update T9681 output, disable T4808 on windows. T4808 tests functionality of the FD interface which won't be supported under WINIO. T9681 just has it's expected output tweaked. - - - - - dd06f930 by Andreas Klebinger at 2020-07-15T16:41:02-04:00 winio: Wake io manager once per registerTimeout. Which is implicitly done in editTimeouts, so need to wake it up twice. - - - - - e87d0bf9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update placeholder comment with actual function name. - - - - - fc9025db by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Always lock win32 event queue - - - - - c24c9a1f by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Display thread labels when tracing scheduler events. - - - - - 06542b03 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Refactor non-threaded runner thread and scheduler interface. Only use a single communication point (registerAlertableWait) to inform the C side aobut both timeouts to use as well as outstanding requests. Also queue a haskell processing thread after each return from alertable waits. This way there is no risk of us missing a timer event. - - - - - 256299b1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove outstanding_requests from runner. We used a variable to keep track of situations where we got entries from the IO port, but all of them had already been canceled. While we can avoid some work that way this case seems quite rare. So we give up on tracking this and instead always assume at least one of the returned entries is valid. If that's not the case no harm is done, we just perform some additional work. But it makes the runner easier to reason about. In particular we don't need to care if another thread modifies oustanding_requests after we return from waiting on the IO Port. - - - - - 3ebd8ad9 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Various fixes related to rebase and testdriver - - - - - 6be6bcba by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: Fix rebase artifacts - - - - - 2c649dc3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename unsafeSplat to unsafeCopyFromBuffer - - - - - a18b73f3 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove unused size/iterate operations from IntTable - - - - - 16bab48e by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Detect running IO Backend via peeking at RtsConfig - - - - - 8b8405a0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update temp path so GCC etc can handle it. Also fix PIPE support, clean up error casting, fix memory leaks - - - - - 2092bc54 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Minor comments/renamings - - - - - a5b5b6c0 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Checking if an error code indicates completion is now a function. - - - - - 362176fd by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Small refactor in withOverlappedEx - - - - - 32e20597 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: A few comments and commented out dbxIO - - - - - a4bfc1d9 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't drop buffer offset in byteView/cwcharView - - - - - b3ad2a54 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: revert BHandle changes. - - - - - 3dcd87e2 by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Fix imports - - - - - 5a371890 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: update ghc-cabal to handle new Cabal submodule bump - - - - - d07ebe0d by Ben Gamari at 2020-07-15T16:41:03-04:00 winio: Only compile sources on Windows - - - - - dcb42393 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Actually return Nothing on EOF for non-blocking read - - - - - 895a3beb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate logic in encodeMultiByte[Raw]IO. - - - - - e06e6734 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Deduplicate openFile logic - - - - - b59430c0 by Tamar Christina at 2020-07-15T16:41:03-04:00 winio: fix -werror issue in encoding file - - - - - f8d39a51 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Don't mention windows specific functions when building on Linux. - - - - - 6a533d2a by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add a note about file locking in the RTS. - - - - - cf37ce34 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Add version to @since annotation - - - - - 0fafa2eb by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename GHC.Conc.IOCP -> GHC.Conc.WinIO - - - - - 1854fc23 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Expand GHC.Conc.POSIX description It now explains users may not use these functions when using the old IO manager. - - - - - fcc7ba41 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Fix potential spaceleak in __createUUIDTempFileErrNo - - - - - 6b3fd9fa by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant -Wno-missing-signatures pragmas - - - - - 916fc861 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Make it explicit that we only create one IO manager - - - - - f260a721 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Note why we don't use blocking waits. - - - - - aa0a4bbf by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove commented out pragma - - - - - d679b544 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Remove redundant buffer write in Handle/Text.hs:bufReadEmpty - - - - - d3f94368 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Rename SmartHandles to StdHandles - - - - - bd6b8ec1 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: add comment stating failure behaviour for getUniqueFileInfo. - - - - - 12846b85 by Andreas Klebinger at 2020-07-15T16:41:03-04:00 winio: Update IOPort haddocks. - - - - - 9f39fb14 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Add a note cross reference - - - - - 62dd5a73 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Name Haskell/OS I/O Manager explicitly in Note - - - - - fa807828 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Expand BlockedOnIOCompletion description. - - - - - f0880a1d by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove historical todos - - - - - 8e58e714 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Update note, remove debugging pragma. - - - - - aa4d84d5 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: flushCharReadBuffer shouldn't need to adjust offsets. - - - - - e580893a by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Remove obsolete comment about cond. variables - - - - - d54e9d79 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix initial linux validate build - - - - - 3cd4de46 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix ThreadDelay001 CPP - - - - - c88b1b9f by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix openFile009 merge conflict leftover - - - - - 849e8889 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept T9681 output. GHC now reports String instead of [Char]. - - - - - e7701818 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix cabal006 after upgrading cabal submodule Demand cabal 2.0 syntax instead of >= 1.20 as required by newer cabal versions. - - - - - a44f0373 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Fix stderr output for ghci/linking/dyn tests. We used to filter rtsopts, i opted to instead just accept the warning of it having no effect. This works both for -rtsopts, as well as -with-rtsopts which winio adds. - - - - - 515d9896 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T15261b stdout for --io-manager flag. - - - - - 949aaacc by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Adjust T5435_dyn_asm stderr The warning about rtsopts having no consequences is expected. So accept new stderr. - - - - - 7d424e1e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Also accept T7037 stderr - - - - - 1f009768 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal04 by filtering rts args - - - - - 981a9f2e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix cabal01 by accepting expected stderr - - - - - b7b0464e by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix safePkg01 by accepting expected stderr - - - - - 32734b29 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix T5435_dyn_gcc by accepting expected stderr - - - - - acc5cebf by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: fix tempfiles test on linux - - - - - c577b789 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for T3807 - - - - - c108c527 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload - - - - - 2b0b9a08 by Andreas Klebinger at 2020-07-15T16:41:04-04:00 winio: Accept accepted stderr for linker_unload_multiple_objs - - - - - 67afb03c by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify wording on conditional variables. - - - - - 3bd41572 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: clarify comment on cooked mode. - - - - - ded58a03 by Tamar Christina at 2020-07-15T16:41:04-04:00 winio: update lockfile signature and remove mistaken symbol in rts. - - - - - 2143c492 by Ben Gamari at 2020-07-15T16:41:04-04:00 testsuite: Add winio and winio_threaded ways Reverts many of the testsuite changes - - - - - c0979cc5 by Ben Gamari at 2020-07-16T10:56:54-04:00 Merge remote-tracking branch 'origin/wip/winio' - - - - - 750a1595 by Ben Gamari at 2020-07-18T07:26:41-04:00 rts: Add --copying-gc flag to reverse effect of --nonmoving-gc Fixes #18281. - - - - - 6ba6a881 by Hécate at 2020-07-18T07:26:42-04:00 Implement `fullCompilerVersion` Follow-up of https://gitlab.haskell.org/ghc/ghc/-/issues/18403 This MR adds `fullCompilerVersion`, a function that shares the same backend as the `--numeric-version` GHC flag, exposing a full, three-digit version datatype. - - - - - e6cf27df by Hécate at 2020-07-18T07:26:43-04:00 Add a Lint hadrian rule and an .hlint.yaml file in base/ - - - - - bcb177dd by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Allow multiple case branches to have a higher rank type As #18412 points out, it should be OK for multiple case alternatives to have a higher rank type, provided they are all the same. This patch implements that change. It sweeps away GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it with an enhanced version of fillInferResult. The basic change to fillInferResult is to permit the case in which another case alternative has already filled in the result; and in that case simply unify. It's very simple actually. See the new Note [fillInferResult] in TcMType Other refactoring: - Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType (previously some of it was in Unify) - Move tcInstType and friends from TcMType to Instantiate, where it more properly belongs. (TCMType was getting very long.) - - - - - e5525a51 by Simon Peyton Jones at 2020-07-18T07:26:43-04:00 Improve typechecking of NPlusK patterns This patch (due to Richard Eisenberg) improves documentation of the wrapper returned by tcSubMult (see Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify). And, more substantially, it cleans up the multiplicity handling in the typechecking of NPlusKPat - - - - - 12f90352 by Krzysztof Gogolewski at 2020-07-18T07:26:45-04:00 Remove {-# CORE #-} pragma (part of #18048) This pragma has no effect since 2011. It was introduced for External Core, which no longer exists. Updates haddock submodule. - - - - - e504c913 by Simon Peyton Jones at 2020-07-18T07:26:45-04:00 Refactor the simplification of join binders This MR (for #18449) refactors the Simplifier's treatment of join-point binders. Specifically, it puts together, into GHC.Core.Opt.Simplify.Env.adjustJoinPointType two currently-separate ways in which we adjust the type of a join point. As the comment says: -- (adjustJoinPointType mult new_res_ty join_id) does two things: -- -- 1. Set the return type of the join_id to new_res_ty -- See Note [Return type for join points] -- -- 2. Adjust the multiplicity of arrows in join_id's type, as -- directed by 'mult'. See Note [Scaling join point arguments] I think this actually fixes a latent bug, by ensuring that the seIdSubst and seInScope have the right multiplicity on the type of join points. I did some tidying up while I was at it. No more setJoinResTy, or modifyJoinResTy: instead it's done locally in Simplify.Env.adjustJoinPointType - - - - - 49b265f0 by Chaitanya Koparkar at 2020-07-18T07:26:46-04:00 Fix minor typos in a Core.hs note - - - - - 8d59aed6 by Stefan Schulze Frielinghaus at 2020-07-18T07:26:47-04:00 GHCi: Fix isLittleEndian - - - - - c26e81d1 by Ben Gamari at 2020-07-18T07:26:47-04:00 testsuite: Mark ghci tests as fragile under unreg compiler In particular I have seen T16012 fail repeatedly under the unregisterised compiler. - - - - - 868e4523 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "AArch32 symbols only on aarch32." This reverts commit cdfeb3f24f76e8fd30452016676e56fbc827789a. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - c915ba84 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "Fix (1)" This reverts commit 7abffced01f5680efafe44f6be2733eab321b039. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 777c452a by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "better if guards." This reverts commit 3f60b94de1f460ca3f689152860b108a19ce193e. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 0dd40552 by Moritz Angermann at 2020-07-20T04:30:38-04:00 Revert "[linker/rtsSymbols] More linker symbols" This reverts commit 686e72253aed3880268dd6858eadd8c320f09e97. Signed-off-by: Moritz Angermann <moritz.angermann at gmail.com> - - - - - 30caeee7 by Sylvain Henry at 2020-07-21T06:39:33-04:00 DynFlags: remove use of sdocWithDynFlags from GHC.Stg.* (#17957) * add StgPprOpts datatype * remove Outputable instances for types that need `StgPprOpts` to be pretty-printed and explicitly call type specific ppr functions * add default `panicStgPprOpts` for panic messages (when it's not convenient to thread StgPprOpts or DynFlags down to the ppr function call) - - - - - 863c544c by Mark at 2020-07-21T06:39:34-04:00 Fix a typo in existential_quantification.rst - - - - - 05910be1 by Krzysztof Gogolewski at 2020-07-21T14:47:07-04:00 Add release notes entry for #17816 [skip ci] - - - - - a6257192 by Matthew Pickering at 2020-07-21T14:47:19-04:00 Use a newtype `Code` for the return type of typed quotations (Proposal #195) There are three problems with the current API: 1. It is hard to properly write instances for ``Quote m => m (TExp a)`` as the type is the composition of two type constructors. Doing so in your program involves making your own newtype and doing a lot of wrapping/unwrapping. For example, if I want to create a language which I can either run immediately or generate code from I could write the following with the new API. :: class Lang r where _int :: Int -> r Int _if :: r Bool -> r a -> r a -> r a instance Lang Identity where _int = Identity _if (Identity b) (Identity t) (Identity f) = Identity (if b then t else f) instance Quote m => Lang (Code m) where _int = liftTyped _if cb ct cf = [|| if $$cb then $$ct else $$cf ||] 2. When doing code generation it is common to want to store code fragments in a map. When doing typed code generation, these code fragments contain a type index so it is desirable to store them in one of the parameterised map data types such as ``DMap`` from ``dependent-map`` or ``MapF`` from ``parameterized-utils``. :: compiler :: Env -> AST a -> Code Q a data AST a where ... data Ident a = ... type Env = MapF Ident (Code Q) newtype Code m a = Code (m (TExp a)) In this example, the ``MapF`` maps an ``Ident String`` directly to a ``Code Q String``. Using one of these map types currently requires creating your own newtype and constantly wrapping every quotation and unwrapping it when using a splice. Achievable, but it creates even more syntactic noise than normal metaprogramming. 3. ``m (TExp a)`` is ugly to read and write, understanding ``Code m a`` is easier. This is a weak reason but one everyone can surely agree with. Updates text submodule. - - - - - 58235d46 by Ben Gamari at 2020-07-21T14:47:28-04:00 users-guide: Fix :rts-flag:`--copying-gc` documentation It was missing a newline. - - - - - 19e80b9a by Vladislav Zavialov at 2020-07-21T14:50:01-04:00 Accumulate Haddock comments in P (#17544, #17561, #8944) Haddock comments are, first and foremost, comments. It's very annoying to incorporate them into the grammar. We can take advantage of an important property: adding a Haddock comment does not change the parse tree in any way other than wrapping some nodes in HsDocTy and the like (and if it does, that's a bug). This patch implements the following: * Accumulate Haddock comments with their locations in the P monad. This is handled in the lexer. * After parsing, do a pass over the AST to associate Haddock comments with AST nodes using location info. * Report the leftover comments to the user as a warning (-Winvalid-haddock). - - - - - 4c719460 by David Binder at 2020-07-22T20:17:35-04:00 Fix dead link to haskell prime discussion - - - - - f2f817e4 by BinderDavid at 2020-07-22T20:17:35-04:00 Replace broken links to old haskell-prime site by working links to gitlab instance. [skip ci] - - - - - 0bf8980e by Daniel Gröber at 2020-07-22T20:18:11-04:00 Remove length field from FastString - - - - - 1010c33b by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use ShortByteString for FastString There are multiple reasons we want this: - Fewer allocations: ByteString has 3 fields, ShortByteString just has one. - ByteString memory is pinned: - This can cause fragmentation issues (see for example #13110) but also - makes using FastStrings in compact regions impossible. Metric Decrease: T5837 T12150 T12234 T12425 - - - - - 8336ba78 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Pass specialised utf8DecodeChar# to utf8DecodeLazy# for performance Currently we're passing a indexWord8OffAddr# type function to utf8DecodeLazy# which then passes it on to utf8DecodeChar#. By passing one of utf8DecodeCharAddr# or utf8DecodeCharByteArray# instead we benefit from the inlining and specialization already done for those. - - - - - 7484a9a4 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Add comment about tricky ForeignPtr lifetime - - - - - 5536ed28 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Use IO constructor instead of `stToIO . ST` - - - - - 5b8902e3 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Remove redundant use of withForeignPtr - - - - - 5976a161 by Daniel Gröber at 2020-07-22T20:18:11-04:00 Encoding: Reformat utf8EncodeShortByteString to be more consistent - - - - - 9ddf1614 by Daniel Gröber at 2020-07-22T20:18:11-04:00 FastString: Reintroduce character count cache Metric Increase: ManyConstructors Metric Decrease: T4029 - - - - - e9491668 by Ben Gamari at 2020-07-22T20:18:46-04:00 get-win32-tarballs: Fix detection of missing tarballs This fixes the error message given by configure when the user attempts to configure without first download the win32 tarballs. - - - - - 9f3ff8fd by Andreas Klebinger at 2020-07-22T20:19:22-04:00 Enable BangPatterns, ScopedTypeVariables for ghc and hadrian by default. This is only for their respective codebases. - - - - - 0f17b930 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused "ncg" flag This flag has been removed in 066b369de2c6f7da03c88206288dca29ab061b31 in 2011. - - - - - bab4ec8f by Sylvain Henry at 2020-07-22T20:19:59-04:00 Don't panic if the NCG isn't built (it is always built) - - - - - 8ea33edb by Sylvain Henry at 2020-07-22T20:19:59-04:00 Remove unused sGhcWithNativeCodeGen - - - - - e079bb72 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Correctly test active backend Previously we used a platform settings to detect if the native code generator was used. This was wrong. We need to use the `DynFlags.hscTarget` field instead. - - - - - 735f9d6b by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace ghcWithNativeCodeGen with a proper Backend datatype * Represent backends with a `Backend` datatype in GHC.Driver.Backend * Don't detect the default backend to use for the target platform at compile time in Hadrian/make but at runtime. It makes "Settings" simpler and it is a step toward making GHC multi-target. * The latter change also fixes hadrian which has not been updated to take into account that the NCG now supports AIX and PPC64 (cf df26b95559fd467abc0a3a4151127c95cb5011b9 and d3c1dda60d0ec07fc7f593bfd83ec9457dfa7984) * Also we don't treat iOS specifically anymore (cf cb4878ffd18a3c70f98bdbb413cd3c4d1f054e1f) - - - - - f7cc4313 by Sylvain Henry at 2020-07-22T20:19:59-04:00 Replace HscTarget with Backend They both have the same role and Backend name is more explicit. Metric Decrease: T3064 Update Haddock submodule - - - - - 15ce1804 by Andreas Klebinger at 2020-07-22T20:20:34-04:00 Deprecate -fdmd-tx-dict-sel. It's behaviour is now unconditionally enabled as it's slightly beneficial. There are almost no benchmarks which benefit from disabling it, so it's not worth the keep this configurable. This fixes #18429. - - - - - ff1b7710 by Sylvain Henry at 2020-07-22T20:21:11-04:00 Add test for #18064 It has been fixed by 0effc57d48ace6b719a9f4cbeac67c95ad55010b - - - - - cfa89149 by Krzysztof Gogolewski at 2020-07-22T20:21:48-04:00 Define type Void# = (# #) (#18441) There's one backwards compatibility issue: GHC.Prim no longer exports Void#, we now manually re-export it from GHC.Exts. - - - - - 02f40b0d by Sebastian Graf at 2020-07-22T20:22:23-04:00 Add regression test for #18478 !3392 backported !2993 to GHC 8.10.2 which most probably is responsible for fixing #18478, which triggered a pattern match checker performance regression in GHC 8.10.1 as first observed in #17977. - - - - - 7f44df1e by Sylvain Henry at 2020-07-22T20:23:00-04:00 Minor refactoring of Unit display * for consistency, try to always use UnitPprInfo to display units to users * remove some uses of `unitPackageIdString` as it doesn't show the component name and it uses String - - - - - dff1cb3d by Moritz Angermann at 2020-07-23T07:55:29-04:00 [linker] Fix out of range relocations. mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space. - - - - - cdd0ff16 by Tamar Christina at 2020-07-24T18:12:23-04:00 winio: restore console cp on exit - - - - - c1f4f81d by Tamar Christina at 2020-07-24T18:13:00-04:00 winio: change memory allocation strategy and fix double free errors. - - - - - ba205046 by Simon Peyton Jones at 2020-07-24T18:13:35-04:00 Care with occCheckExpand in kind of occurrences Issue #18451 showed that we could get an infinite type, through over-use of occCheckExpand in the kind of an /occurrence/ of a type variable. See Note [Occurrence checking: look inside kinds] in GHC.Core.Type This patch fixes the problem by making occCheckExpand less eager to expand synonyms in kinds. It also improves pretty printing of kinds, by *not* suppressing the kind on a tyvar-binder like (a :: Const Type b) where type Const p q = p. Even though the kind of 'a' is Type, we don't want to suppress the kind ascription. Example: the error message for polykinds/T18451{a,b}. See GHC.Core.TyCo.Ppr Note [Suppressing * kinds]. - - - - - 02133353 by Zubin Duggal at 2020-07-25T00:44:30-04:00 Simplify XRec definition Change `Located X` usage to `XRec pass X` This increases the scope of the LPat experiment to almost all of GHC. Introduce UnXRec and MapXRec classes Fixes #17587 and #18408 Updates haddock submodule Co-authored-by: Philipp Krüger <philipp.krueger1 at gmail.com> - - - - - e443846b by Sylvain Henry at 2020-07-25T00:45:07-04:00 DynFlags: store printer in TraceBinIfaceReading We don't need to pass the whole DynFlags, just pass the logging function, if any. - - - - - 15b2b44f by Sylvain Henry at 2020-07-25T00:45:08-04:00 Rename GHC.Driver.Ways into GHC.Platform.Ways - - - - - 342a01af by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add GHC.Platform.Profile - - - - - 6333d739 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Put PlatformConstants into Platform - - - - - 9dfeca6c by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove platform constant wrappers Platform constant wrappers took a DynFlags parameter, hence implicitly used the target platform constants. We removed them to allow support for several platforms at once (#14335) and to avoid having to pass the full DynFlags to every function (#17957). Metric Decrease: T4801 - - - - - 73145d57 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Remove dead code in utils/derivConstants - - - - - 7721b923 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Move GHC.Platform into the compiler Previously it was in ghc-boot so that ghc-pkg could use it. However it wasn't necessary because ghc-pkg only uses a subset of it: reading target arch and OS from the settings file. This is now done via GHC.Platform.ArchOS (was called PlatformMini before). - - - - - 459afeb5 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Fix build systems - - - - - 9e2930c3 by Sylvain Henry at 2020-07-25T00:45:08-04:00 Bump CountParserDeps - - - - - 6e2db34b by Sylvain Henry at 2020-07-25T00:45:08-04:00 Add accessors to ArchOS - - - - - fc0f6fbc by Stefan Schulze Frielinghaus at 2020-07-25T00:45:45-04:00 Require SMP support in order to build a threaded stage1 Fixes 18266 - - - - - a7c4439a by Matthias Andreas Benkard at 2020-07-26T13:23:24-04:00 Document loadFramework changes. (#18446) Adds commentary on the rationale for the changes made in merge request !3689. - - - - - da7269a4 by Ben Gamari at 2020-07-26T13:23:59-04:00 rts/win32: Exit with EXIT_HEAPOVERFLOW if memory commit fails Since switching to the two-step allocator, the `outofmem` test fails via `osCommitMemory` failing to commit. However, this was previously exiting with `EXIT_FAILURE`, rather than `EXIT_HEAPOVERFLOW`. I think the latter is a more reasonable exit code for this case and matches the behavior on POSIX platforms. - - - - - f153a1d0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Update win32 output for parseTree - - - - - e91672f0 by Ben Gamari at 2020-07-26T13:23:59-04:00 testsuite: Normalise WinIO error message differences Previously the old Windows IO manager threw different errors than WinIO. We now canonicalise these to the WinIO errors. - - - - - 9cbfe086 by Ben Gamari at 2020-07-26T13:23:59-04:00 gitlab-ci: Kill ssh-agent after pushing test metrics Otherwise the Windows builds hang forever waiting for the process to terminate. - - - - - 8236925f by Tamar Christina at 2020-07-26T13:24:35-04:00 winio: remove dead argument to stg_newIOPortzh - - - - - ce0a1d67 by Tamar Christina at 2020-07-26T13:25:11-04:00 winio: fix detection of tty terminals - - - - - 52685cf7 by Tamar Christina at 2020-07-26T13:25:48-04:00 winio: update codeowners - - - - - aee45d9e by Vladislav Zavialov at 2020-07-27T07:06:56-04:00 Improve NegativeLiterals (#18022, GHC Proposal #344) Before this patch, NegativeLiterals used to parse x-1 as x (-1). This may not be what the user expects, and now it is fixed: x-1 is parsed as (-) x 1. We achieve this by the following requirement: * When lexing a negative literal, it must not be preceded by a 'closing token'. This also applies to unboxed literals, e.g. -1#. See GHC Proposal #229 for the definition of a closing token. A nice consequence of this change is that -XNegativeLiterals becomes a subset of -XLexicalNegation. In other words, enabling both of those extensions has the same effect as enabling -XLexicalNegation alone. - - - - - 667ab69e by leiftw at 2020-07-27T07:07:32-04:00 fix typo referring to non-existent `-ohidir` flag, should be `-hidir` I think - - - - - 6ff89c17 by Vladislav Zavialov at 2020-07-27T07:08:07-04:00 Refactor the parser a little * Create a dedicated production for type operators * Create a dedicated type for the UNPACK pragma * Remove an outdated part of Note [Parsing data constructors is hard] - - - - - aa054d32 by Ben Gamari at 2020-07-27T20:09:07-04:00 Drop 32-bit Windows support As noted in #18487, we have reached the end of this road. - - - - - 6da73bbf by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Add minimal test for #12492 - - - - - 47680cb7 by Michalis Pardalos at 2020-07-27T20:09:44-04:00 Use allocate, not ALLOC_PRIM_P for unpackClosure# ALLOC_PRIM_P fails for large closures, by directly using allocate we can handle closures which are larger than the block size. Fixes #12492 - - - - - 3d345c96 by Simon Peyton Jones at 2020-07-27T20:10:19-04:00 Eta-expand the Simplifier monad This patch eta-expands the Simplifier's monad, using the method explained in GHC.Core.Unify Note [The one-shot state monad trick]. It's part of the exta-expansion programme in #18202. It's a tiny patch, but is worth a 1-2% reduction in bytes-allocated by the compiler. Here's the list, based on the compiler-performance tests in perf/compiler: Reduction in bytes allocated T10858(normal) -0.7% T12425(optasm) -1.3% T13056(optasm) -1.8% T14683(normal) -1.1% T15164(normal) -1.3% T15630(normal) -1.4% T17516(normal) -2.3% T18282(normal) -1.6% T18304(normal) -0.8% T1969(normal) -0.6% T4801(normal) -0.8% T5321FD(normal) -0.7% T5321Fun(normal) -0.5% T5642(normal) -0.9% T6048(optasm) -1.1% T9020(optasm) -2.7% T9233(normal) -0.7% T9675(optasm) -0.5% T9961(normal) -2.9% WWRec(normal) -1.2% Metric Decrease: T12425 T9020 T9961 - - - - - 57aca6bb by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Ensure that Hadrian jobs don't download artifacts Previously the Hadrian jobs had the default dependencies, meaning that they would download artifacts from all jobs of earlier stages. This is unneccessary. - - - - - 0a815cea by Ben Gamari at 2020-07-27T20:10:54-04:00 gitlab-ci: Bump bootstrap compiler to 8.8.4 Hopefully this will make the Windows jobs a bit more reliable. - - - - - 0bd60059 by Simon Peyton Jones at 2020-07-28T02:01:49-04:00 This patch addresses the exponential blow-up in the simplifier. Specifically: #13253 exponential inlining #10421 ditto #18140 strict constructors #18282 another nested-function call case This patch makes one really significant changes: change the way that mkDupableCont handles StrictArg. The details are explained in GHC.Core.Opt.Simplify Note [Duplicating StrictArg]. Specific changes * In mkDupableCont, when making auxiliary bindings for the other arguments of a call, add extra plumbing so that we don't forget the demand on them. Otherwise we haev to wait for another round of strictness analysis. But actually all the info is to hand. This change affects: - Make the strictness list in ArgInfo be [Demand] instead of [Bool], and rename it to ai_dmds. - Add as_dmd to ValArg - Simplify.makeTrivial takes a Demand - mkDupableContWithDmds takes a [Demand] There are a number of other small changes 1. For Ids that are used at most once in each branch of a case, make the occurrence analyser record the total number of syntactic occurrences. Previously we recorded just OneBranch or MultipleBranches. I thought this was going to be useful, but I ended up barely using it; see Note [Note [Suppress exponential blowup] in GHC.Core.Opt.Simplify.Utils Actual changes: * See the occ_n_br field of OneOcc. * postInlineUnconditionally 2. I found a small perf buglet in SetLevels; see the new function GHC.Core.Opt.SetLevels.hasFreeJoin 3. Remove the sc_cci field of StrictArg. I found I could get its information from the sc_fun field instead. Less to get wrong! 4. In ArgInfo, arrange that ai_dmds and ai_discs have a simpler invariant: they line up with the value arguments beyond ai_args This allowed a bit of nice refactoring; see isStrictArgInfo, lazyArgcontext, strictArgContext There is virtually no difference in nofib. (The runtime numbers are bogus -- I tried a few manually.) Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- fft +0.0% -2.0% -48.3% -49.4% 0.0% multiplier +0.0% -2.2% -50.3% -50.9% 0.0% -------------------------------------------------------------------------------- Min -0.4% -2.2% -59.2% -60.4% 0.0% Max +0.0% +0.1% +3.3% +4.9% 0.0% Geometric Mean +0.0% -0.0% -33.2% -34.3% -0.0% Test T18282 is an existing example of these deeply-nested strict calls. We get a big decrease in compile time (-85%) because so much less inlining takes place. Metric Decrease: T18282 - - - - - 6ee07b49 by Sylvain Henry at 2020-07-28T02:02:27-04:00 Bignum: add support for negative shifts (fix #18499) shiftR/shiftL support negative arguments despite Haskell 2010 report saying otherwise. We explicitly test for negative values which is bad (it gets in the way of constant folding, etc.). Anyway, for consistency we fix Bits instancesof Integer/Natural. - - - - - f305bbfd by Peter Trommler at 2020-07-28T02:03:02-04:00 config: Fix Haskell platform constructor w/ params Fixes #18505 - - - - - 318bb17c by Oleg Grenrus at 2020-07-28T20:54:13-04:00 Fix typo in haddock Spotted by `vilpan` on `#haskell` - - - - - 39c89862 by Sergei Trofimovich at 2020-07-28T20:54:50-04:00 ghc/mk: don't build gmp packages for BIGNUM_BACKEND=native Before this change make-based `BIGNUM_BACKEND=native` build was failing as: ``` x86_64-pc-linux-gnu-gcc: error: libraries/ghc-bignum/gmp/objs/*.o: No such file or directory ``` This happens because ghc.mk was pulling in gmp-dependent ghc-bignum library unconditionally. The change avoid building ghc-bignum. Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/18437 Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org> - - - - - b9a880fc by Felix Wiemuth at 2020-07-29T15:06:35-04:00 Fix typo - - - - - c59064b0 by Brandon Chinn at 2020-07-29T15:07:11-04:00 Add regression test for #16341 - - - - - a61411ca by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass dit_rep_tc_args to dsm_stock_gen_fn - - - - - a26498da by Brandon Chinn at 2020-07-29T15:07:11-04:00 Pass tc_args to gen_fn - - - - - 44b11bad by Brandon Chinn at 2020-07-29T15:07:11-04:00 Filter out unreachable constructors when deriving stock instances (#16431) - - - - - bbc51916 by Simon Peyton Jones at 2020-07-29T15:07:47-04:00 Kill off sc_mult and as_mult fields They are readily derivable from other fields, so this is more efficient, and less error prone. Fixes #18494 - - - - - e3db4b4c by Peter Trommler at 2020-07-29T15:08:22-04:00 configure: Fix build system on ARM - - - - - 96c31ea1 by Sylvain Henry at 2020-07-29T15:09:02-04:00 Fix bug in Natural multiplication (fix #18509) A bug was lingering in Natural multiplication (inverting two limbs) despite QuickCheck tests used during the development leading to wrong results (independently of the selected backend). - - - - - e1dc3d7b by Krzysztof Gogolewski at 2020-07-29T15:09:39-04:00 Fix validation errors (#18510) Test T2632 is a stage1 test that failed because of the Q => Quote change. The remaining tests did not use quotation and failed when the path contained a space. - - - - - 6c68a842 by John Ericson at 2020-07-30T07:11:02-04:00 For `-fkeep-going` do not duplicate dependency edge code We now compute the deps for `-fkeep-going` the same way that the original graph calculates them, so the edges are correct. Upsweep really ought to take the graph rather than a topological sort so we are never recalculating anything, but at least things are recaluclated consistently now. - - - - - 502de556 by cgibbard at 2020-07-30T07:11:02-04:00 Add haddock comment for unfilteredEdges and move the note about drop_hs_boot_nodes into it. - - - - - 01c948eb by Ryan Scott at 2020-07-30T07:11:37-04:00 Clean up the inferred type variable restriction This patch primarily: * Documents `checkInferredVars` (previously called `check_inferred_vars`) more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See `Note [Unobservably inferred type variables]` in `GHC.Rename.HsType`. Note that I now invoke `checkInferredVars` _alongside_ `rnHsSigType`, `rnHsWcSigType`, etc. rather than doing so _inside_ of these functions. This results in slightly more call sites for `checkInferredVars`, but it makes it much easier to enumerate the spots where the inferred type variable restriction comes into effect. * Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432. As a result, this patch fixes #18432. Along the way, I performed some various cleanup: * I moved `no_nested_foralls_contexts_err` into `GHC.Rename.Utils` (under the new name `noNestedForallsContextsErr`), since it now needs to be invoked from multiple modules. I also added a helper function `addNoNestedForallsContextsErr` that throws the error message after producing it, as this is a common idiom. * In order to ensure that users cannot sneak inferred type variables into `SPECIALISE instance` pragmas by way of nested `forall`s, I now invoke `addNoNestedForallsContextsErr` when renaming `SPECIALISE instance` pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240, but this task was somehow overlooked.) As a result, this patch fixes #18455 as a side effect. - - - - - d47324ce by Ryan Scott at 2020-07-30T07:12:16-04:00 Don't mark closed type family equations as occurrences Previously, `rnFamInstEqn` would mark the name of the type/data family used in an equation as an occurrence, regardless of what sort of family it is. Most of the time, this is the correct thing to do. The exception is closed type families, whose equations constitute its definition and therefore should not be marked as occurrences. Overzealously counting the equations of a closed type family as occurrences can cause certain warnings to not be emitted, as observed in #18470. See `Note [Type family equations and occurrences]` in `GHC.Rename.Module` for the full story. This fixes #18470 with a little bit of extra-casing in `rnFamInstEqn`. To accomplish this, I added an extra `ClosedTyFamInfo` field to the `NonAssocTyFamEqn` constructor of `AssocTyFamInfo` and refactored the relevant call sites accordingly so that this information is propagated to `rnFamInstEqn`. While I was in town, I moved `wrongTyFamName`, which checks that the name of a closed type family matches the name in an equation for that family, from the renamer to the typechecker to avoid the need for an `ASSERT`. As an added bonus, this lets us simplify the details of `ClosedTyFamInfo` a bit. - - - - - ebe2cf45 by Simon Peyton Jones at 2020-07-30T07:12:52-04:00 Remove an incorrect WARN in extendLocalRdrEnv I noticed this warning going off, and discovered that it's really fine. This small patch removes the warning, and docments what is going on. - - - - - 9f71f697 by Simon Peyton Jones at 2020-07-30T07:13:27-04:00 Add two bangs to improve perf of flattening This tiny patch improves the compile time of flatten-heavy programs by 1-2%, by adding two bangs. Addresses (somewhat) #18502 This reduces allocation by T9872b -1.1% T9872d -3.3% T5321Fun -0.2% T5631 -0.2% T5837 +0.1% T6048 +0.1% Metric Decrease: T9872b T9872d - - - - - 7c274cd5 by Sylvain Henry at 2020-07-30T22:54:48-04:00 Fix minimal imports dump for boot files (fix #18497) - - - - - 175cb5b4 by Sylvain Henry at 2020-07-30T22:55:25-04:00 DynFlags: don't use sdocWithDynFlags in datacon ppr We don't need to use `sdocWithDynFlags` to know whether we should display linear types for datacon types, we already have `sdocLinearTypes` field in `SDocContext`. Moreover we want to remove `sdocWithDynFlags` (#10143, #17957)). - - - - - 380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00 Bignum: fix powMod for gmp backend (#18515) Also reenable integerPowMod test which had never been reenabled by mistake. - - - - - 56a7c193 by Sylvain Henry at 2020-07-31T19:32:09+02:00 Refactor CLabel pretty-printing Pretty-printing CLabel relies on sdocWithDynFlags that we want to remove (#10143, #17957). It uses it to query the backend and the platform. This patch exposes Clabel ppr functions specialised for each backend so that backend code can directly use them. - - - - - 3b15dc3c by Sylvain Henry at 2020-07-31T19:32:09+02:00 DynFlags: don't use sdocWithDynFlags in GHC.CmmToAsm.Dwarf.Types - - - - - e30fed6c by Vladislav Zavialov at 2020-08-01T04:23:04-04:00 Test case for #17652 The issue was fixed by 19e80b9af252eee760dc047765a9930ef00067ec - - - - - 22641742 by Ryan Scott at 2020-08-02T16:44:11-04:00 Remove ConDeclGADTPrefixPs This removes the `ConDeclGADTPrefixPs` per the discussion in #18517. Most of this patch simply removes code, although the code in the `rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a bit: * The nested `forall`s check now lives in the `rnConDecl` case for `ConDeclGADT`. * The `LinearTypes`-specific code that used to live in the `rnConDecl` case for `ConDeclGADTPrefixPs` now lives in `GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that it can check if `-XLinearTypes` is enabled. Fixes #18157. - - - - - f2d1accf by Leon Schoorl at 2020-08-02T16:44:47-04:00 Fix GHC_STAGE definition generated by make Fixes #18070 GHC_STAGE is the stage of the compiler we're building, it should be 1,2(,3?). But make was generating 0 and 1. Hadrian does this correctly using a similar `+ 1`: https://gitlab.haskell.org/ghc/ghc/-/blob/eb8115a8c4cbc842b66798480fefc7ab64d31931/hadrian/src/Rules/Generate.hs#L245 - - - - - 947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00 hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468. In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db` was already given correctly to tell `stage0/bin/ghc-pkg` that it should use the package DB in `stage1/`. However, `ghc` needs to be given this information as well, not only `ghc-pkg`! Until now that was not the case; the package DB in `stage0` was given to `ghc` instead. This was wrong, because there is no binary compatibility guarantee that says that the `stage0` DB's `package.cache` (which is written by the stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg` from the source code tree. As a result, when trying to add fields to `InstalledPackageInfo` that get serialised into / deserialised from the `package.cache`, errors like _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!) would appear. This was because the `stage0/bin/ghc would try to deserialise the newly added fields from `_build/stage0/lib/package.conf.d/package.cache`, but they were not in there because the system `ghc-pkg` doesn't know about them and thus didn't write them there. It would try to do that because any GHC by default tries to read the global package db in `../lib/package.conf.d/package.cache`. For `stage0/bin/ghc` that *can never work* as explained above, so we must disable this default via `-no-global-package-db` and give it the correct package DB explicitly. This is the same problem as #16534, and the same fix as in MR !780 (but in another context; that one was for developers trying out the `stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix is for a `cabal configure` invocation). I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`, and have fixed that in this commit as well. It only worked until now because nobody tried to add a new ghc-pkg `.conf` field since the introduction of Hadrian. - - - - - ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00 Hardcode RTS includes to cope with unregistered builds - - - - - d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add backward compat integer-gmp functions Also enhance bigNatCheck# and isValidNatural test - - - - - 3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00 Bignum: add more BigNat compat functions in integer-gmp - - - - - 5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00 Rename Core.Opt.Driver -> Core.Opt.Pipeline Closes #18504. - - - - - 2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00 Revert "iserv: Don't pass --export-dynamic on FreeBSD" This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9. - - - - - 53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00 Refactor handling of object merging Previously to merge a set of object files we would invoke the linker as usual, adding -r to the command-line. However, this can result in non-sensical command-lines which causes lld to balk (#17962). To avoid this we introduce a new tool setting into GHC, -pgmlm, which is the linker which we use to merge object files. - - - - - eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00 Remove all the unnecessary LANGUAGE pragmas - - - - - fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00 Make CodeQ and TExpQ levity polymorphic The patch is quite straightforward. The only tricky part is that `Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`). Since `CodeQ` has yet to appear in any released version of `template-haskell`, I didn't bother mentioning the change to `CodeQ` in the `template-haskell` release notes. Fixes #18521. - - - - - 686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Grammar for types and data/newtype constructors Before this patch, we parsed types into a reversed sequence of operators and operands. For example, (F x y + G a b * X) would be parsed as [X, *, b, a, G, +, y, x, F], using a simple grammar: tyapps : tyapp | tyapps tyapp tyapp : atype | PREFIX_AT atype | tyop | unpackedness Then we used a hand-written state machine to assemble this either into a type, using 'mergeOps', or into a constructor, using 'mergeDataCon'. This is due to a syntactic ambiguity: data T1 a = MkT1 a data T2 a = Ord a => MkT2 a In T1, what follows after the = sign is a data/newtype constructor declaration. However, in T2, what follows is a type (of kind Constraint). We don't know which of the two we are parsing until we encounter =>, and we cannot check for => without unlimited lookahead. This poses a few issues when it comes to e.g. infix operators: data I1 = Int :+ Bool :+ Char -- bad data I2 = Int :+ Bool :+ Char => MkI2 -- fine By this issue alone we are forced into parsing into an intermediate representation and doing a separate validation pass. However, should that intermediate representation be as low-level as a flat sequence of operators and operands? Before GHC Proposal #229, the answer was Yes, due to some particularly nasty corner cases: data T = ! A :+ ! B -- used to be fine, hard to parse data T = ! A :+ ! B => MkT -- bad However, now the answer is No, as this corner case is gone: data T = ! A :+ ! B -- bad data T = ! A :+ ! B => MkT -- bad This means we can write a proper grammar for types, overloading it in the DisambECP style, see Note [Ambiguous syntactic categories]. With this patch, we introduce a new class, DisambTD. Just like DisambECP is used to disambiguate between expressions, commands, and patterns, DisambTD is used to disambiguate between types and data/newtype constructors. This way, we get a proper, declarative grammar for constructors and types: infixtype : ftype | ftype tyop infixtype | unpackedness infixtype ftype : atype | tyop | ftype tyarg | ftype PREFIX_AT tyarg tyarg : atype | unpackedness atype And having a grammar for types means we are a step closer to using a single grammar for types and expressions. - - - - - 6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00 Clean up the story around runPV/runECP_P/runECP_PV This patch started as a small documentation change, an attempt to make Note [Parser-Validator] and Note [Ambiguous syntactic categories] more clear and up-to-date. But it turned out that runECP_P/runECP_PV are weakly motivated, and it's easier to remove them than to find a good rationale/explanation for their existence. As the result, there's a bit of refactoring in addition to a documentation update. - - - - - 826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix debug_ppr_ty ForAllTy (#18522) Before this change, GHC would pretty-print forall k. forall a -> () as forall @k a. () which isn't even valid Haskell. - - - - - 0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00 Fix visible forall in ppr_ty (#18522) Before this patch, this type: T :: forall k -> (k ~ k) => forall j -> k -> j -> Type was printed incorrectly as: T :: forall k j -> (k ~ k) => k -> j -> Type - - - - - d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00 Fail eagerly on a lev-poly datacon arg Close #18534. See commentary in the patch. - - - - - 63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00 Use a type alias for Ways - - - - - 9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00 users-guide: Rename 8.12 to 9.0 GHC 8.12.1 has been renamed to GHC 9.0.1. See also: https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html [skip ci] - - - - - 3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00 A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure as suggested by comments on !2330. - - - - - fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00 Add some tests for fail messages in do-expressions and monad-comprehensions. - - - - - 5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00 cmm: Clean up Notes a bit - - - - - 6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00 CmmLint: Check foreign call argument register invariant As mentioned in Note [Register parameter passing] the arguments of foreign calls cannot refer to caller-saved registers. - - - - - 15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00 nativeGen: One approach to fix #18527 Previously the code generator could produce corrupt C call sequences due to register overlap between MachOp lowerings and the platform's calling convention. We fix this using a hack described in Note [Evaluate C-call arguments before placing in destination registers]. - - - - - 3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Add test for #18527 - - - - - dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00 testsuite: Fix prog001 Previously it failed as the `ghc` package was not visible. - - - - - e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00 ApiAnnotations; tweaks for ghc-exactprint update Remove unused ApiAnns, add one for linear arrow. Include API Annotations for trailing comma in export list. - - - - - 8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00 configure: Fix double-negation in ld merge-objects check We want to only run the check if ld is gold. Fixes the fix to #17962. - - - - - a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 293c7fba by Sylvain Henry at 2020-08-21T09:36:38-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - 50eb4460 by Sylvain Henry at 2020-08-21T09:36:38-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 659eb31b by Sylvain Henry at 2020-08-21T09:36:38-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 2d8ca917 by Sylvain Henry at 2020-08-21T09:37:15-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - fddddbf4 by Vladislav Zavialov at 2020-08-21T09:37:49-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - 989c1c27 by Ben Gamari at 2020-08-21T11:27:53-04:00 gitlab-ci: Test master branch as well While these builds are strictly speaking redundant (since every commit is tested by @marge-bot before making it into `master`), they are nevertheless useful as they are displayed in the branch's commit list in GitLab's web interface. Fixes #18595. - - - - - e67ae884 by Aditya Gupta at 2020-08-22T03:29:00-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - 03cfcfd4 by Wander Hillen at 2020-08-22T03:29:36-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 3f501545 by Craig Ferguson at 2020-08-22T03:30:13-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 8b865092 by Krzysztof Gogolewski at 2020-08-23T14:12:53+02:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - d8f61182 by Krzysztof Gogolewski at 2020-08-23T14:12:56+02:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - 364258e0 by Krzysztof Gogolewski at 2020-08-24T00:32:31-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - b1eb38a0 by Sylvain Henry at 2020-08-24T00:33:13-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 0a1ecc5f by Ben Gamari at 2020-08-25T07:37:05-04:00 SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' In #18069 we are observing MVar deadlocks from somewhere in ghc.exe. This use of MVar stood out as being one of the more likely culprits. Here we make sure that it is exception-safe. - - - - - db8793ad by Richard Eisenberg at 2020-08-25T07:37:40-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - fb77207a by Simon Peyton Jones at 2020-08-25T07:38:16-04:00 Use LIdP rather than (XRec p (IdP p)) This patch mainly just replaces use of XRec p (IdP p) with LIdP p One slightly more significant change is to parameterise HsPatSynDetails over the pass rather than the argument type, so that it's uniform with HsConDeclDetails and HsConPatDetails. I also got rid of the dead code GHC.Hs.type.conDetailsArgs But this is all just minor refactoring. No change in functionality. - - - - - 8426a136 by Krzysztof Gogolewski at 2020-08-25T07:38:54-04:00 Add a test for #18585 - - - - - 2d635a50 by Takenobu Tani at 2020-08-26T04:50:21-04:00 linters: Make CPP linter skip image files This patch adds an exclusion rule for `docs/users_guide/images`, to avoid lint errors of PDF files. - - - - - b7d98cb2 by Takenobu Tani at 2020-08-26T04:50:21-04:00 users-guide: Color the logo on the front page of the PDF This patch updates the logo with a recent color scheme. This affects only the PDF version of the user's guide. See also: * https://mail.haskell.org/pipermail/ghc-devs/2020-August/019139.html * https://gitlab.haskell.org/ghc/ghc/-/wikis/logo - - - - - 0b17fa18 by Sylvain Henry at 2020-08-26T04:50:58-04:00 Refactor UnitId pretty-printing When we pretty-print a UnitId for the user, we try to map it back to its origin package name, version and component to print "package-version:component" instead of some hash. The UnitId type doesn't carry these information, so we have to look into a UnitState to find them. This is why the Outputable instance of UnitId used `sdocWithDynFlags` in order to access the `unitState` field of DynFlags. This is wrong for several reasons: 1. The DynFlags are accessed when the message is printed, not when it is generated. So we could imagine that the unitState may have changed in-between. Especially if we want to allow unit unloading. 2. We want GHC to support several independent sessions at once, hence several UnitState. The current approach supposes there is a unique UnitState as a UnitId doesn't indicate which UnitState to use. See the Note [Pretty-printing UnitId] in GHC.Unit for the new approach implemented by this patch. One step closer to remove `sdocDynFlags` field from `SDocContext` (#10143). Fix #18124. Also fix some Backpack code to use SDoc instead of String. - - - - - dc476a50 by Sylvain Henry at 2020-08-26T04:51:35-04:00 Bignum: fix BigNat subtraction (#18604) There was a confusion between the boolean expected by withNewWordArrayTrimedMaybe and the boolean returned by subtracting functions. - - - - - fcb10b6c by Peter Trommler at 2020-08-26T10:42:30-04:00 PPC and X86: Portable printing of IEEE floats GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness. This was brought up in #18431 by @hsyl20. - - - - - 770100e0 by Krzysztof Gogolewski at 2020-08-26T10:43:13-04:00 primops: Remove Monadic and Dyadic categories There were four categories of primops: Monadic, Dyadic, Compare, GenPrimOp. The compiler does not treat Monadic and Dyadic in any special way, we can just replace them with GenPrimOp. Compare is still used in isComparisonPrimOp. - - - - - 01ff8c89 by Aditya Gupta at 2020-08-27T14:19:26-04:00 Consolidate imports in getMinimalImports (#18264) - - - - - bacccb73 by Ryan Scott at 2020-08-27T14:20:01-04:00 Make {hsExpr,hsType,pat}NeedsParens aware of boxed 1-tuples `hsExprNeedsParens`, `hsTypeNeedsParens`, and `patNeedsParens` previously assumed that all uses of explicit tuples in the source syntax never need to be parenthesized. This is true save for one exception: boxed one-tuples, which use the `Solo` data type from `GHC.Tuple` instead of special tuple syntax. This patch adds the necessary logic to the three `*NeedsParens` functions to handle `Solo` correctly. Fixes #18612. - - - - - c6f50cea by Krzysztof Gogolewski at 2020-08-28T02:22:36-04:00 Add missing primop documentation (#18454) - Add three pseudoops to primops.txt.pp, so that Haddock renders the documentation - Update comments - Remove special case for "->" - it's no longer exported from GHC.Prim - Remove reference to Note [Compiling GHC.Prim] - the ad-hoc fix is no longer there after updates to levity polymorphism. - Document GHC.Prim - Remove the comment that lazy is levity-polymorphic. As far as I can tell, it never was: in 80e399639, only the unfolding was given an open type variable. - Remove haddock hack in GHC.Magic - no longer neccessary after adding realWorld# to primops.txt.pp. - - - - - f065b6b0 by Tamar Christina at 2020-08-28T02:23:13-04:00 Fix use distro toolchian - - - - - 4517a382 by Tamar Christina at 2020-08-28T02:23:13-04:00 document how build system find toolchains on Windows - - - - - 5a0320d4 by buggymcbugfix at 2020-08-29T08:20:20+02:00 wip - - - - - 19 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/linters/check-cpp.py - .gitlab/test-metrics.sh - .gitmodules - CODEOWNERS - Makefile - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - + compiler/GHC/Builtin/RebindableNames.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/Builtin/Utils.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e5fb189997d4ac01eb2e96d08a3ba569b5d84389...5a0320d42f30ee4b0c37700d7dfd3e3ac81d13ad -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e5fb189997d4ac01eb2e96d08a3ba569b5d84389...5a0320d42f30ee4b0c37700d7dfd3e3ac81d13ad You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 29 14:55:33 2020 From: gitlab at gitlab.haskell.org (Krzysztof Gogolewski) Date: Sat, 29 Aug 2020 10:55:33 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/cherry-pick-happy-compat Message-ID: <5f4a6c65eb0f1_80b3f84924f6bbc9763682@gitlab.haskell.org.mail> Krzysztof Gogolewski pushed new branch wip/cherry-pick-happy-compat at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/cherry-pick-happy-compat You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 29 15:04:42 2020 From: gitlab at gitlab.haskell.org (Krzysztof Gogolewski) Date: Sat, 29 Aug 2020 11:04:42 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/cherry-pick-happy-compat-8.10 Message-ID: <5f4a6e8a262d7_80b3f84924f6bbc9767950@gitlab.haskell.org.mail> Krzysztof Gogolewski pushed new branch wip/cherry-pick-happy-compat-8.10 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/cherry-pick-happy-compat-8.10 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 29 15:10:59 2020 From: gitlab at gitlab.haskell.org (Krzysztof Gogolewski) Date: Sat, 29 Aug 2020 11:10:59 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/cherry-pick-happy-compat-8.8 Message-ID: <5f4a70036b8d8_80b1084931497709d5@gitlab.haskell.org.mail> Krzysztof Gogolewski pushed new branch wip/cherry-pick-happy-compat-8.8 at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/cherry-pick-happy-compat-8.8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 29 18:19:54 2020 From: gitlab at gitlab.haskell.org (Sven Tennie) Date: Sat, 29 Aug 2020 14:19:54 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/gitignore_clangd_dist-newstyle Message-ID: <5f4a9c4a58f0d_80bd5eb4449782645@gitlab.haskell.org.mail> Sven Tennie pushed new branch wip/gitignore_clangd_dist-newstyle at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/gitignore_clangd_dist-newstyle You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sat Aug 29 21:29:53 2020 From: gitlab at gitlab.haskell.org (John Ericson) Date: Sat, 29 Aug 2020 17:29:53 -0400 Subject: [Git][ghc/ghc][wip/int64-everywhere] Copy enumFrom* implementations from Int/Word for Int64/Word64 Message-ID: <5f4ac8d16d875_80b1069b4e0978749d@gitlab.haskell.org.mail> John Ericson pushed to branch wip/int64-everywhere at Glasgow Haskell Compiler / GHC Commits: 523014ef by John Ericson at 2020-08-29T17:22:19-04:00 Copy enumFrom* implementations from Int/Word for Int64/Word64 Without this, we don't get proper list fusion. I think this sort of copying is OK for now, but we absolutely need something better if we are going to make `IntN` use `IntN#` for all `N`. The degree to which proper metaprogramming has been punted upon by factoring everything through the native-sized types is disconcerting. - - - - - 2 changed files: - libraries/base/GHC/Int.hs - libraries/base/GHC/Word.hs Changes: ===================================== libraries/base/GHC/Int.hs ===================================== @@ -753,14 +753,147 @@ instance Enum Int64 where | x /= minBound = x - 1 | otherwise = predError "Int64" toEnum (I# i#) = I64# (intToInt64# i#) +#if WORD_SIZE_IN_BITS >= 64 + fromEnum (I64# x#) = I# (int64ToInt# x#) +#else fromEnum x@(I64# x#) | x >= fromIntegral (minBound::Int) && x <= fromIntegral (maxBound::Int) = I# (int64ToInt# x#) | otherwise = fromEnumError "Int64" x - enumFrom = integralEnumFrom - enumFromThen = integralEnumFromThen - enumFromTo = integralEnumFromTo - enumFromThenTo = integralEnumFromThenTo +#endif + -- See Note [Stable Unfolding for list producers] + {-# INLINE enumFrom #-} + enumFrom (I64# x) = eftInt64 x maxInt64# + where !(I64# maxInt64#) = maxBound + -- Blarg: technically I guess enumFrom isn't strict! + + -- See Note [Stable Unfolding for list producers] + {-# INLINE enumFromTo #-} + enumFromTo (I64# x) (I64# y) = eftInt64 x y + + -- See Note [Stable Unfolding for list producers] + {-# INLINE enumFromThen #-} + enumFromThen (I64# x1) (I64# x2) = efdInt64 x1 x2 + + -- See Note [Stable Unfolding for list producers] + {-# INLINE enumFromThenTo #-} + enumFromThenTo (I64# x1) (I64# x2) (I64# y) = efdtInt64 x1 x2 y + +-- Modeled after fusion helpers in GHC.Enum for Int +-- See Note [How the Enum rules work] + +{-# RULES +"eftInt64" [~1] forall x y. eftInt64 x y = build (\ c n -> eftInt64FB c n x y) +"eftInt64List" [1] eftInt64FB (:) [] = eftInt64 + #-} + +{-# NOINLINE [1] eftInt64 #-} +eftInt64 :: Int64# -> Int64# -> [Int64] +-- [x1..x2] +eftInt64 x0 y | isTrue# (x0 `gtInt64#` y) = [] + | otherwise = go x0 + where + !one = intToInt64# 1# + go x = I64# x : if isTrue# (x `eqInt64#` y) + then [] + else go (x `plusInt64#` one) + +{-# NOINLINE [0] eftInt64FB #-} +eftInt64FB :: (Int64 -> r -> r) -> r -> Int64# -> Int64# -> r +eftInt64FB c n x0 y | isTrue# (x0 `gtInt64#` y) = n + | otherwise = go x0 + where + !one = intToInt64# 1# + go x = I64# x `c` if isTrue# (x `eqInt64#` y) + then n + else go (x `plusInt64#` one) + +{-# RULES +"efdtInt64" [~1] forall x1 x2 y. + efdtInt64 x1 x2 y = build (\ c n -> efdtInt64FB c n x1 x2 y) +"efdtInt64UpList" [1] efdtInt64FB (:) [] = efdtInt64 + #-} + +efdInt64 :: Int64# -> Int64# -> [Int64] +-- [x1,x2..maxInt64] +efdInt64 x1 x2 + | isTrue# (x2 `geInt64#` x1) = case maxBound of I64# y -> efdtInt64Up x1 x2 y + | otherwise = case minBound of I64# y -> efdtInt64Dn x1 x2 y + +{-# NOINLINE [1] efdtInt64 #-} +efdtInt64 :: Int64# -> Int64# -> Int64# -> [Int64] +-- [x1,x2..y] +efdtInt64 x1 x2 y + | isTrue# (x2 `geInt64#` x1) = efdtInt64Up x1 x2 y + | otherwise = efdtInt64Dn x1 x2 y + +{-# INLINE [0] efdtInt64FB #-} -- See Note [Inline FB functions] in GHC.List +efdtInt64FB :: (Int64 -> r -> r) -> r -> Int64# -> Int64# -> Int64# -> r +efdtInt64FB c n x1 x2 y + | isTrue# (x2 `geInt64#` x1) = efdtInt64UpFB c n x1 x2 y + | otherwise = efdtInt64DnFB c n x1 x2 y + +-- Requires x2 >= x1 +efdtInt64Up :: Int64# -> Int64# -> Int64# -> [Int64] +efdtInt64Up x1 x2 y -- Be careful about overflow! + | isTrue# (y `ltInt64#` x2) = if isTrue# (y `ltInt64#` x1) then [] else [I64# x1] + | otherwise = -- Common case: x1 <= x2 <= y + let !delta = x2 `subInt64#` x1 -- >= 0 + !y' = y `subInt64#` delta -- x1 <= y' <= y; hence y' is representable + + -- Invariant: x <= y + -- Note that: z <= y' => z + delta won't overflow + -- so we are guaranteed not to overflow if/when we recurse + go_up x | isTrue# (x `gtInt64#` y') = [I64# x] + | otherwise = I64# x : go_up (x `plusInt64#` delta) + in I64# x1 : go_up x2 + +-- Requires x2 >= x1 +{-# INLINE [0] efdtInt64UpFB #-} -- See Note [Inline FB functions] in GHC.List +efdtInt64UpFB :: (Int64 -> r -> r) -> r -> Int64# -> Int64# -> Int64# -> r +efdtInt64UpFB c n x1 x2 y -- Be careful about overflow! + | isTrue# (y `ltInt64#` x2) = if isTrue# (y `ltInt64#` x1) then n else I64# x1 `c` n + | otherwise = -- Common case: x1 <= x2 <= y + let !delta = x2 `subInt64#` x1 -- >= 0 + !y' = y `subInt64#` delta -- x1 <= y' <= y; hence y' is representable + + -- Invariant: x <= y + -- Note that: z <= y' => z + delta won't overflow + -- so we are guaranteed not to overflow if/when we recurse + go_up x | isTrue# (x `gtInt64#` y') = I64# x `c` n + | otherwise = I64# x `c` go_up (x `plusInt64#` delta) + in I64# x1 `c` go_up x2 + +-- Requires x2 <= x1 +efdtInt64Dn :: Int64# -> Int64# -> Int64# -> [Int64] +efdtInt64Dn x1 x2 y -- Be careful about underflow! + | isTrue# (y `gtInt64#` x2) = if isTrue# (y `gtInt64#` x1) then [] else [I64# x1] + | otherwise = -- Common case: x1 >= x2 >= y + let !delta = x2 `subInt64#` x1 -- <= 0 + !y' = y `subInt64#` delta -- y <= y' <= x1; hence y' is representable + + -- Invariant: x >= y + -- Note that: z >= y' => z + delta won't underflow + -- so we are guaranteed not to underflow if/when we recurse + go_dn x | isTrue# (x `ltInt64#` y') = [I64# x] + | otherwise = I64# x : go_dn (x `plusInt64#` delta) + in I64# x1 : go_dn x2 + +-- Requires x2 <= x1 +{-# INLINE [0] efdtInt64DnFB #-} -- See Note [Inline FB functions] in GHC.List +efdtInt64DnFB :: (Int64 -> r -> r) -> r -> Int64# -> Int64# -> Int64# -> r +efdtInt64DnFB c n x1 x2 y -- Be careful about underflow! + | isTrue# (y `gtInt64#` x2) = if isTrue# (y `gtInt64#` x1) then n else I64# x1 `c` n + | otherwise = -- Common case: x1 >= x2 >= y + let !delta = x2 `subInt64#` x1 -- <= 0 + !y' = y `subInt64#` delta -- y <= y' <= x1; hence y' is representable + + -- Invariant: x >= y + -- Note that: z >= y' => z + delta won't underflow + -- so we are guaranteed not to underflow if/when we recurse + go_dn x | isTrue# (x `ltInt64#` y') = I64# x `c` n + | otherwise = I64# x `c` go_dn (x `plusInt64#` delta) + in I64# x1 `c` go_dn x2 -- | @since 2.01 instance Integral Int64 where ===================================== libraries/base/GHC/Word.hs ===================================== @@ -739,10 +739,20 @@ instance Enum Word64 where | x <= fromIntegral (maxBound::Int) = I# (word2Int# (word64ToWord# x#)) | otherwise = fromEnumError "Word64" x - enumFrom = integralEnumFrom - enumFromThen = integralEnumFromThen - enumFromTo = integralEnumFromTo - enumFromThenTo = integralEnumFromThenTo + + {-# INLINE enumFrom #-} + enumFrom (W64# x#) = eftWord64 x# maxWord64# + where !(W64# maxWord64#) = maxBound + -- Blarg: technically I guess enumFrom isn't strict! + + {-# INLINE enumFromTo #-} + enumFromTo (W64# x) (W64# y) = eftWord64 x y + + {-# INLINE enumFromThen #-} + enumFromThen (W64# x1) (W64# x2) = efdWord64 x1 x2 + + {-# INLINE enumFromThenTo #-} + enumFromThenTo (W64# x1) (W64# x2) (W64# y) = efdtWord64 x1 x2 y -- | @since 2.01 instance Integral Word64 where @@ -766,6 +776,122 @@ instance Integral Word64 where | otherwise = divZeroError toInteger (W64# x#) = integerFromWord64# x# +-- Modeled after fusion helpers in GHC.Enum for Word +-- See Note [How the Enum rules work] +-- +{-# RULES +"eftWord64" [~1] forall x y. eftWord64 x y = build (\ c n -> eftWord64FB c n x y) +"eftWord64List" [1] eftWord64FB (:) [] = eftWord64 + #-} + +{-# NOINLINE [1] eftWord64 #-} +eftWord64 :: Word64# -> Word64# -> [Word64] +-- [x1..x2] +eftWord64 x0 y | isTrue# (x0 `gtWord64#` y) = [] + | otherwise = go x0 + where + !one = wordToWord64# 1## + go x = W64# x : if isTrue# (x `eqWord64#` y) + then [] + else go (x `plusWord64#` one) + +{-# INLINE [0] eftWord64FB #-} -- See Note [Inline FB functions] in GHC.List +eftWord64FB :: (Word64 -> r -> r) -> r -> Word64# -> Word64# -> r +eftWord64FB c n x0 y | isTrue# (x0 `gtWord64#` y) = n + | otherwise = go x0 + where + !one = wordToWord64# 1## + go x = W64# x `c` if isTrue# (x `eqWord64#` y) + then n + else go (x `plusWord64#` one) + +{-# RULES +"efdtWord64" [~1] forall x1 x2 y. + efdtWord64 x1 x2 y = build (\ c n -> efdtWord64FB c n x1 x2 y) +"efdtWord64UpList" [1] efdtWord64FB (:) [] = efdtWord64 + #-} + +efdWord64 :: Word64# -> Word64# -> [Word64] +-- [x1,x2..maxWord64] +efdWord64 x1 x2 + | isTrue# (x2 `geWord64#` x1) = case maxBound of W64# y -> efdtWord64Up x1 x2 y + | otherwise = case minBound of W64# y -> efdtWord64Dn x1 x2 y + +{-# NOINLINE [1] efdtWord64 #-} +efdtWord64 :: Word64# -> Word64# -> Word64# -> [Word64] +-- [x1,x2..y] +efdtWord64 x1 x2 y + | isTrue# (x2 `geWord64#` x1) = efdtWord64Up x1 x2 y + | otherwise = efdtWord64Dn x1 x2 y + +{-# INLINE [0] efdtWord64FB #-} -- See Note [Inline FB functions] in GHC.List +efdtWord64FB :: (Word64 -> r -> r) -> r -> Word64# -> Word64# -> Word64# -> r +efdtWord64FB c n x1 x2 y + | isTrue# (x2 `geWord64#` x1) = efdtWord64UpFB c n x1 x2 y + | otherwise = efdtWord64DnFB c n x1 x2 y + +-- Requires x2 >= x1 +efdtWord64Up :: Word64# -> Word64# -> Word64# -> [Word64] +efdtWord64Up x1 x2 y -- Be careful about overflow! + | isTrue# (y `ltWord64#` x2) = if isTrue# (y `ltWord64#` x1) then [] else [W64# x1] + | otherwise = -- Common case: x1 <= x2 <= y + let !delta = x2 `subWord64#` x1 -- >= 0 + !y' = y `subWord64#` delta -- x1 <= y' <= y; hence y' is representable + + -- Invariant: x <= y + -- Note that: z <= y' => z + delta won't overflow + -- so we are guaranteed not to overflow if/when we recurse + go_up x | isTrue# (x `gtWord64#` y') = [W64# x] + | otherwise = W64# x : go_up (x `plusWord64#` delta) + in W64# x1 : go_up x2 + +-- Requires x2 >= x1 +{-# INLINE [0] efdtWord64UpFB #-} -- See Note [Inline FB functions] in GHC.List +efdtWord64UpFB :: (Word64 -> r -> r) -> r -> Word64# -> Word64# -> Word64# -> r +efdtWord64UpFB c n x1 x2 y -- Be careful about overflow! + | isTrue# (y `ltWord64#` x2) = if isTrue# (y `ltWord64#` x1) then n else W64# x1 `c` n + | otherwise = -- Common case: x1 <= x2 <= y + let !delta = x2 `subWord64#` x1 -- >= 0 + !y' = y `subWord64#` delta -- x1 <= y' <= y; hence y' is representable + + -- Invariant: x <= y + -- Note that: z <= y' => z + delta won't overflow + -- so we are guaranteed not to overflow if/when we recurse + go_up x | isTrue# (x `gtWord64#` y') = W64# x `c` n + | otherwise = W64# x `c` go_up (x `plusWord64#` delta) + in W64# x1 `c` go_up x2 + +-- Requires x2 <= x1 +efdtWord64Dn :: Word64# -> Word64# -> Word64# -> [Word64] +efdtWord64Dn x1 x2 y -- Be careful about underflow! + | isTrue# (y `gtWord64#` x2) = if isTrue# (y `gtWord64#` x1) then [] else [W64# x1] + | otherwise = -- Common case: x1 >= x2 >= y + let !delta = x2 `subWord64#` x1 -- <= 0 + !y' = y `subWord64#` delta -- y <= y' <= x1; hence y' is representable + + -- Invariant: x >= y + -- Note that: z >= y' => z + delta won't underflow + -- so we are guaranteed not to underflow if/when we recurse + go_dn x | isTrue# (x `ltWord64#` y') = [W64# x] + | otherwise = W64# x : go_dn (x `plusWord64#` delta) + in W64# x1 : go_dn x2 + +-- Requires x2 <= x1 +{-# INLINE [0] efdtWord64DnFB #-} -- See Note [Inline FB functions] in GHC.List +efdtWord64DnFB :: (Word64 -> r -> r) -> r -> Word64# -> Word64# -> Word64# -> r +efdtWord64DnFB c n x1 x2 y -- Be careful about underflow! + | isTrue# (y `gtWord64#` x2) = if isTrue# (y `gtWord64#` x1) then n else W64# x1 `c` n + | otherwise = -- Common case: x1 >= x2 >= y + let !delta = x2 `subWord64#` x1 -- <= 0 + !y' = y `subWord64#` delta -- y <= y' <= x1; hence y' is representable + + -- Invariant: x >= y + -- Note that: z >= y' => z + delta won't underflow + -- so we are guaranteed not to underflow if/when we recurse + go_dn x | isTrue# (x `ltWord64#` y') = W64# x `c` n + | otherwise = W64# x `c` go_dn (x `plusWord64#` delta) + in W64# x1 `c` go_dn x2 + -- | @since 2.01 instance Bits Word64 where {-# INLINE shift #-} View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/523014efd4ca02f4410e847fb01b72bcb766f3b8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/523014efd4ca02f4410e847fb01b72bcb766f3b8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 30 13:50:48 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Sun, 30 Aug 2020 09:50:48 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/buggymcbugfix/appendArrays Message-ID: <5f4baeb8986fc_80b3f84866830cc9829936@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed new branch wip/buggymcbugfix/appendArrays at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/buggymcbugfix/appendArrays You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 30 18:04:30 2020 From: gitlab at gitlab.haskell.org (Shayne Fletcher) Date: Sun, 30 Aug 2020 14:04:30 -0400 Subject: [Git][ghc/ghc][wip/T18599] Add an HsExpr case 'GetField' Message-ID: <5f4bea2ee20de_80b3f8468c43750983648d@gitlab.haskell.org.mail> Shayne Fletcher pushed to branch wip/T18599 at Glasgow Haskell Compiler / GHC Commits: 634e8b86 by Shayne Fletcher at 2020-08-30T13:42:08-04:00 Add an HsExpr case 'GetField' Some syntax is added for get field expressions but we don't yet have the parser create terms of that syntax. - Adds a new AST node 'GetField'; - Give definitions for known incomplete pattern matches; - Update the parser to compute `Located FastString`s for fields. - - - - - 7 changed files: - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Extension.hs - compiler/GHC/Hs/Instances.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Tc/Types/Origin.hs Changes: ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -457,6 +457,21 @@ data HsExpr p -- For a type family, the arg types are of the *instance* tycon, -- not the family tycon + -- | Record projections + + -- A get_field @fIELD arg expression. + -- e.g. z.x = GetField { + -- gf_ext=noExtField, gf_expr=z, gf_fIELD=x, gf_getField = getField @"x" z + -- }. + | GetField + { gf_ext :: XGetField p + , gf_expr :: LHsExpr p + , gf_fIELD :: Located FastString + , gf_getField :: LHsExpr p -- Equivalent 'getField' term. + } + -- Expressions of this case only arise when the RecordDotSyntax + -- langauge extensions is enabled. + -- | Expression with an explicit type signature. @e :: type@ -- -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnDcolon' @@ -580,6 +595,9 @@ data RecordUpdTc = RecordUpdTc , rupd_wrap :: HsWrapper -- See note [Record Update HsWrapper] } +-- | Extra data fields for a 'GetField', added by the type checker +data GetFieldTc = GetFieldTc + -- | HsWrap appears only in typechecker output -- Invariant: The contained Expr is *NOT* itself an HsWrap. -- See Note [Detecting forced eta expansion] in "GHC.HsToCore.Expr". @@ -648,6 +666,10 @@ type instance XRecordUpd GhcPs = NoExtField type instance XRecordUpd GhcRn = NoExtField type instance XRecordUpd GhcTc = RecordUpdTc +type instance XGetField GhcPs = NoExtField +type instance XGetField GhcRn = NoExtField +type instance XGetField GhcTc = GetFieldTc + type instance XExprWithTySig (GhcPass _) = NoExtField type instance XArithSeq GhcPs = NoExtField @@ -1193,6 +1215,9 @@ ppr_expr (RecordCon { rcon_con_name = con_id, rcon_flds = rbinds }) ppr_expr (RecordUpd { rupd_expr = L _ aexp, rupd_flds = rbinds }) = hang (ppr aexp) 2 (braces (fsep (punctuate comma (map ppr rbinds)))) +ppr_expr (GetField { gf_expr = L _ fexp, gf_fIELD = field, gf_getField = _}) + = ppr fexp <> dot <> ppr field + ppr_expr (ExprWithTySig _ expr sig) = hang (nest 2 (ppr_lexpr expr) <+> dcolon) 4 (ppr sig) @@ -1347,6 +1372,10 @@ hsExprNeedsParens p = go go (HsBinTick _ _ _ (L _ e)) = go e go (RecordCon{}) = False go (HsRecFld{}) = False + -- To be honest I'm not sure right now but we know that projection + -- has higher precedence than application since f r.a.b parses as + -- f (r.a.b) so I'm going to with False for the moment. + go (GetField{}) = False go (XExpr x) | GhcTc <- ghcPass @p = case x of ===================================== compiler/GHC/Hs/Extension.hs ===================================== @@ -555,6 +555,7 @@ type family XDo x type family XExplicitList x type family XRecordCon x type family XRecordUpd x +type family XGetField x type family XExprWithTySig x type family XArithSeq x type family XBracket x ===================================== compiler/GHC/Hs/Instances.hs ===================================== @@ -345,6 +345,7 @@ deriving instance Data (ArithSeqInfo GhcTc) deriving instance Data RecordConTc deriving instance Data RecordUpdTc +deriving instance Data GetFieldTc deriving instance Data CmdTopTc deriving instance Data PendingRnSplice deriving instance Data PendingTcSplice ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -269,6 +269,10 @@ dsExpr (HsConLikeOut _ con) = dsConLike con dsExpr (HsIPVar {}) = panic "dsExpr: HsIPVar" dsExpr (HsOverLabel{}) = panic "dsExpr: HsOverLabel" +-- I feel these should have been eliminated by their equivalent +-- getField expressions by now. +dsExpr (GetField{}) = panic "dsExpr: GetField" + dsExpr (HsLit _ lit) = do { warnAboutOverflowedLit lit ; dsLit (convertLit lit) } ===================================== compiler/GHC/Parser.y ===================================== @@ -3281,13 +3281,13 @@ pbind :: { LHsExpr GhcPs -> LHsExpr GhcPs } ; let { ; top = $1 -- foo ; fields = top : reverse $3 -- [foo, bar, baz, quux] ; final = last fields -- quux - ; arg = mkVar $ unpackFS final + ; arg = mkVar $ unpackFS (unLoc final) } ; return $ mkFieldUpdater fields arg } }} -fieldToUpdate :: { [FastString] } +fieldToUpdate :: { [Located FastString] } fieldToUpdate -- See Note [Whitespace-sensitive operator parsing] in Lexer.x : fieldToUpdate TIGHT_INFIX_PROJ field { $3 : $1 } @@ -3585,9 +3585,9 @@ qvar :: { Located RdrName } -- whether it's a qvar or a var can be postponed until -- *after* we see the close paren. -field :: { FastString } - : VARID { getVARID $1 } - | QVARID { snd $ getQVARID $1 } +field :: { Located FastString } + : VARID { sL1 $1 $! getVARID $1 } + | QVARID { sL1 $1 $! snd $ getQVARID $1 } qvarid :: { Located RdrName } : varid { $1 } ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -2929,7 +2929,7 @@ circ = noLoc $ HsVar noExtField (noLoc $ mkRdrUnqual (mkVarOcc ".")) -- mkProj rhs fIELD calculates a projection. -- e.g. .x = mkProj Nothing x = \z -> z.x = \z -> (getField @fIELD x) -- .x.y = mkProj Just(.x) y = (.y) . (.x) = (\z -> z.y) . (\z -> z.x) -mkProj :: Maybe (LHsExpr GhcPs) -> FastString -> LHsExpr GhcPs +mkProj :: Maybe (LHsExpr GhcPs) -> Located FastString -> LHsExpr GhcPs mkProj rhs fIELD = let body = mkGet zVar fIELD grhs = noLoc $ GRHS noExtField [] body @@ -2940,19 +2940,19 @@ mkProj rhs fIELD = -- mkGet arg fIELD calcuates a get_field @fIELD arg expression. -- e.g. z.x = mkGet z x = get_field @x z -mkGet :: LHsExpr GhcPs -> FastString -> LHsExpr GhcPs +mkGet :: LHsExpr GhcPs -> Located FastString -> LHsExpr GhcPs mkGet arg fIELD = head $ mkGet' [arg] fIELD -mkGet' :: [LHsExpr GhcPs] -> FastString -> [LHsExpr GhcPs] -mkGet' l@(r : _) fIELD = get_field `mkAppType` mkSelector fIELD `mkApp` mkParen r : l +mkGet' :: [LHsExpr GhcPs] -> Located FastString -> [LHsExpr GhcPs] +mkGet' l@(r : _) (L _ fIELD) = get_field `mkAppType` mkSelector fIELD `mkApp` mkParen r : l mkGet' [] _ = panic "mkGet' : The impossible has happened!" -- mkSet a fIELD b calculates a set_field @fIELD expression. -- e.g mkSet a fIELD b = set_field @"fIELD" a b (read as "set field 'fIELD' on a to b"). -mkSet :: LHsExpr GhcPs -> FastString -> LHsExpr GhcPs -> LHsExpr GhcPs -mkSet a fIELD b = set_field `mkAppType` mkSelector fIELD `mkApp` a `mkApp` b +mkSet :: LHsExpr GhcPs -> Located FastString -> LHsExpr GhcPs -> LHsExpr GhcPs +mkSet a (L _ fIELD) b = set_field `mkAppType` mkSelector fIELD `mkApp` a `mkApp` b -- mkFieldUpdater calculates functions representing dot notation record updates. -mkFieldUpdater :: [FastString] -> LHsExpr GhcPs -> (LHsExpr GhcPs -> LHsExpr GhcPs) +mkFieldUpdater :: [Located FastString] -> LHsExpr GhcPs -> (LHsExpr GhcPs -> LHsExpr GhcPs) mkFieldUpdater -- e.g {foo.bar.baz.quux = 43} fIELDS -- [foo, bar, baz, quux] arg -- This is 'texp' (43 in the example). @@ -2967,26 +2967,26 @@ mkFieldUpdater -- e.g {foo.bar.baz.quux = 43} in \a -> foldl' mkSet' arg (zips a) -- setField@"foo" (a) (setField@"bar" (getField @"foo" (a))(setField@"baz" (getField @"bar" (getField @"foo" (a)))(setField@"quux" (getField @"baz" (getField @"bar" (getField @"foo" (a))))(quux)))) where - mkSet' :: LHsExpr GhcPs -> (FastString, LHsExpr GhcPs) -> LHsExpr GhcPs + mkSet' :: LHsExpr GhcPs -> (Located FastString, LHsExpr GhcPs) -> LHsExpr GhcPs mkSet' acc (fIELD, g) = mkSet (mkParen g) fIELD (mkParen acc) -- Called from mkRdrRecordUpd. mkSetField :: LHsExpr GhcPs -> LHsRecUpdField GhcPs -> LHsExpr GhcPs -mkSetField e (L _ (HsRecField occ arg _)) = mkSet e (fsLit $ field occ) (val arg) +mkSetField e (L _ (HsRecField occ arg _)) = + let (loc, f) = field occ in mkSet e (L loc (fsLit f)) (val arg) where val :: LHsExpr GhcPs -> LHsExpr GhcPs - val arg = if isPun arg then mkVar $ field occ else arg + val arg = if isPun arg then mkVar $ snd (field occ) else arg isPun :: LHsExpr GhcPs -> Bool isPun = \case L _ (HsVar _ (L _ p)) -> p == pun_RDR _ -> False - field :: Located (AmbiguousFieldOcc GhcPs) -> String + field :: Located (AmbiguousFieldOcc GhcPs) -> (SrcSpan, String) field = \case - L _ (Ambiguous _ (L _ lbl)) -> occNameString . rdrNameOcc $ lbl - L _ (Unambiguous _ (L _ lbl)) -> occNameString . rdrNameOcc $ lbl - _ -> "" -- Extension ctor. + L _ (Ambiguous _ (L loc lbl)) -> (loc, occNameString . rdrNameOcc $ lbl) + L _ (Unambiguous _ (L loc lbl)) -> (loc, occNameString . rdrNameOcc $ lbl) applyFieldUpdates :: LHsExpr GhcPs -> [LHsExpr GhcPs -> LHsExpr GhcPs] -> P (LHsExpr GhcPs) applyFieldUpdates a updates = return $ foldl' apply a updates ===================================== compiler/GHC/Tc/Types/Origin.hs ===================================== @@ -499,6 +499,7 @@ exprCtOrigin (HsAppType _ e1 _) = lexprCtOrigin e1 exprCtOrigin (OpApp _ _ op _) = lexprCtOrigin op exprCtOrigin (NegApp _ e _) = lexprCtOrigin e exprCtOrigin (HsPar _ e) = lexprCtOrigin e +exprCtOrigin (GetField _ e _ _) = lexprCtOrigin e exprCtOrigin (SectionL _ _ _) = SectionOrigin exprCtOrigin (SectionR _ _ _) = SectionOrigin exprCtOrigin (ExplicitTuple {}) = Shouldn'tHappenOrigin "explicit tuple" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/634e8b86483e8dabc2194e5d1705eff668025fce -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/634e8b86483e8dabc2194e5d1705eff668025fce You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 30 18:51:04 2020 From: gitlab at gitlab.haskell.org (John Ericson) Date: Sun, 30 Aug 2020 14:51:04 -0400 Subject: [Git][ghc/ghc][wip/int64-everywhere] 66 commits: hadrian: depend on boot compiler version #18001 Message-ID: <5f4bf51875cb8_80b3f848653d42498378b3@gitlab.haskell.org.mail> John Ericson pushed to branch wip/int64-everywhere at Glasgow Haskell Compiler / GHC Commits: a11c9678 by Adam Sandberg Ericsson at 2020-08-09T11:32:25+02:00 hadrian: depend on boot compiler version #18001 - - - - - c8873b52 by Alan Zimmerman at 2020-08-09T21:17:54-04:00 Api Annotations : Adjust SrcSpans for prefix bang (!). And prefix ~ (cherry picked from commit 8dbee2c578b1f642d45561be3f416119863e01eb) - - - - - 77398b67 by Sylvain Henry at 2020-08-09T21:18:34-04:00 Avoid allocations in `splitAtList` (#18535) As suspected by @simonpj in #18535, avoiding allocations in `GHC.Utils.Misc.splitAtList` when there are no leftover arguments is beneficial for performance: On CI validate-x86_64-linux-deb9-hadrian: T12227 -7% T12545 -12.3% T5030 -10% T9872a -2% T9872b -2.1% T9872c -2.5% Metric Decrease: T12227 T12545 T5030 T9872a T9872b T9872c - - - - - 8ba41a0f by Felix Yan at 2020-08-10T20:23:29-04:00 Correct a typo in ghc.mk - - - - - 1c469264 by Felix Yan at 2020-08-10T20:23:29-04:00 Add a closing parenthesis too - - - - - acf537f9 by Sylvain Henry at 2020-08-10T20:24:09-04:00 Make splitAtList strict in its arguments Also fix its slightly wrong comment Metric Decrease: T5030 T12227 T12545 - - - - - ab4d1589 by Ben Gamari at 2020-08-11T22:18:03-04:00 typecheck: Drop SPECIALISE pragmas when there is no unfolding Previously the desugarer would instead fall over when it realized that there was no unfolding for an imported function with a SPECIALISE pragma. We now rather drop the SPECIALISE pragma and throw a warning. Fixes #18118. - - - - - 0ac8c0a5 by Ben Gamari at 2020-08-11T22:18:03-04:00 testsuite: Add test for #18118 - - - - - c43078d7 by Sven Tennie at 2020-08-11T22:18:38-04:00 Add hie.yaml to ghc-heap This enables IDE support by haskell-language-server for ghc-heap. - - - - - f1088b3f by Ben Gamari at 2020-08-11T22:19:15-04:00 testsuite: Specify metrics collected by T17516 Previously it collected everything, including "max bytes used". This is problematic since the test makes no attempt to control for deviations in GC timing, resulting in high variability. Fix this by only collecting "bytes allocated". - - - - - accbc242 by Sylvain Henry at 2020-08-12T03:50:12-04:00 DynFlags: disentangle Outputable - put panic related functions into GHC.Utils.Panic - put trace related functions using DynFlags in GHC.Driver.Ppr One step closer making Outputable fully independent of DynFlags. Bump haddock submodule - - - - - db6dd810 by Ben Gamari at 2020-08-12T03:50:48-04:00 testsuite: Increase tolerance of T16916 T16916 (testing #16916) has been slightly fragile in CI due to its reliance on CPU times. While it's hard to see how to eliminate the time-dependence entirely, we can nevertheless make it more tolerant. Fixes #16966. - - - - - bee43aca by Sylvain Henry at 2020-08-12T20:52:50-04:00 Rewrite and move the monad-state hack note The note has been rewritten by @simonpj in !3851 [skip ci] - - - - - 25fdf25e by Alan Zimmerman at 2020-08-12T20:53:26-04:00 ApiAnnotations: Fix parser for new GHC 9.0 features - - - - - 7831fe05 by Ben Gamari at 2020-08-13T03:44:17-04:00 parser: Suggest ImportQualifiedPost in prepositive import warning As suggested in #18545. - - - - - 55dec4dc by Sebastian Graf at 2020-08-13T03:44:52-04:00 PmCheck: Better long-distance info for where bindings (#18533) Where bindings can see evidence from the pattern match of the `GRHSs` they belong to, but not from anything in any of the guards (which belong to one of possibly many RHSs). Before this patch, we did *not* consider said evidence, causing #18533, where the lack of considering type information from a case pattern match leads to failure to resolve the vanilla COMPLETE set of a data type. Making available that information required a medium amount of refactoring so that `checkMatches` can return a `[(Deltas, NonEmpty Deltas)]`; one `(Deltas, NonEmpty Deltas)` for each `GRHSs` of the match group. The first component of the pair is the covered set of the pattern, the second component is one covered set per RHS. Fixes #18533. Regression test case: T18533 - - - - - cf97889a by Hécate at 2020-08-13T03:45:29-04:00 Re-add BangPatterns to CodePage.hs - - - - - ffc0d578 by Sylvain Henry at 2020-08-13T09:49:56-04:00 Add HomeUnit type Since Backpack the "home unit" is much more involved than what it was before (just an identifier obtained with `-this-unit-id`). Now it is used in conjunction with `-component-id` and `-instantiated-with` to configure module instantiations and to detect if we are type-checking an indefinite unit or compiling a definite one. This patch introduces a new HomeUnit datatype which is much easier to understand. Moreover to make GHC support several packages in the same instances, we will need to handle several HomeUnits so having a dedicated (documented) type is helpful. Finally in #14335 we will also need to handle the case where we have no HomeUnit at all because we are only loading existing interfaces for plugins which live in a different space compared to units used to produce target code. Several functions will have to be refactored to accept "Maybe HomeUnit" parameters instead of implicitly querying the HomeUnit fields in DynFlags. Having a dedicated type will make this easier. Bump haddock submodule - - - - - 8a51b2ab by Sylvain Henry at 2020-08-13T21:09:15-04:00 Make IOEnv monad one-shot (#18202) On CI (x86_64-linux-deb9-hadrian, compile_time/bytes_allocated): T10421 -1.8% (threshold: +/- 1%) T10421a -1.7% (threshold: +/- 1%) T12150 -4.9% (threshold: +/- 2%) T12227 -1.6 (threshold: +/- 1%) T12425 -1.5% (threshold: +/- 1%) T12545 -3.8% (threshold: +/- 1%) T12707 -3.0% (threshold: +/- 1%) T13035 -3.0% (threshold: +/- 1%) T14683 -10.3% (threshold: +/- 2%) T3064 -6.9% (threshold: +/- 2%) T4801 -4.3% (threshold: +/- 2%) T5030 -2.6% (threshold: +/- 2%) T5321FD -3.6% (threshold: +/- 2%) T5321Fun -4.6% (threshold: +/- 2%) T5631 -19.7% (threshold: +/- 2%) T5642 -13.0% (threshold: +/- 2%) T783 -2.7 (threshold: +/- 2%) T9020 -11.1 (threshold: +/- 2%) T9961 -3.4% (threshold: +/- 2%) T1969 (compile_time/bytes_allocated) -2.2% (threshold: +/-1%) T1969 (compile_time/max_bytes_used) +24.4% (threshold: +/-20%) Additionally on other CIs: haddock.Cabal -10.0% (threshold: +/- 5%) haddock.compiler -9.5% (threshold: +/- 5%) haddock.base (max bytes used) +24.6% (threshold: +/- 15%) T10370 (max bytes used, i386) +18.4% (threshold: +/- 15%) Metric Decrease: T10421 T10421a T12150 T12227 T12425 T12545 T12707 T13035 T14683 T3064 T4801 T5030 T5321FD T5321Fun T5631 T5642 T783 T9020 T9961 haddock.Cabal haddock.compiler Metric Decrease 'compile_time/bytes allocated': T1969 Metric Increase 'compile_time/max_bytes_used': T1969 T10370 haddock.base - - - - - 9f66fdf6 by Ben Gamari at 2020-08-14T15:50:34-04:00 testsuite: Drop --io-manager flag from testsuite configuration This is no longer necessary as there are now dedicated testsuite ways which run tests with WinIO. - - - - - 55fd1dc5 by Ben Gamari at 2020-08-14T15:51:10-04:00 llvm-targets: Add i686 targets Addresses #18422. - - - - - f4cc57fa by Ben Gamari at 2020-08-18T15:38:55-04:00 Allow unsaturated runRW# applications Previously we had a very aggressive Core Lint check which caught unsaturated applications of runRW#. However, there is nothing wrong with such applications and they may naturally arise in desugared Core. For instance, the desugared Core of Data.Primitive.Array.runArray# from the `primitive` package contains: case ($) (runRW# @_ @_) (\s -> ...) of ... In this case it's almost certain that ($) will be inlined, turning the application into a saturated application. However, even if this weren't the case there isn't a problem: CorePrep (after deleting an unnecessary case) can simply generate code in its usual way, resulting in a call to the Haskell definition of runRW#. Fixes #18291. - - - - - 3ac6ae7c by Ben Gamari at 2020-08-18T15:38:55-04:00 testsuite: Add test for #18291 - - - - - a87a0b49 by Eli Schwartz at 2020-08-18T15:39:30-04:00 install: do not install sphinx doctrees These files are 100% not needed at install time, and they contain unreproducible info. See https://reproducible-builds.org/ for why this matters. - - - - - 194b25ee by Ben Gamari at 2020-08-18T15:40:05-04:00 testsuite: Allow baseline commit to be set explicitly - - - - - fdcf7645 by Ben Gamari at 2020-08-18T15:40:05-04:00 gitlab-ci: Use MR base commit as performance baseline - - - - - 9ad5cab3 by Fendor at 2020-08-18T15:40:42-04:00 Expose UnitInfoMap as it is part of the public API - - - - - aa4b744d by Ben Gamari at 2020-08-18T22:11:36-04:00 testsuite: Only run llvm ways if llc is available As noted in #18560, we previously would always run the LLVM ways since `configure` would set `SettingsLlcCommand` to something non-null when it otherwise couldn't find the `llc` executable. Now we rather probe for the existence of the `llc` executable in the testsuite driver. Fixes #18560. - - - - - 0c5ed5c7 by Sylvain Henry at 2020-08-18T22:12:13-04:00 DynFlags: refactor GHC.CmmToAsm (#17957, #10143) This patch removes the use of `sdocWithDynFlags` from GHC.CmmToAsm.*.Ppr To do that I've had to make some refactoring: * X86' and PPC's `Instr` are no longer `Outputable` as they require a `Platform` argument * `Instruction` class now exposes `pprInstr :: Platform -> instr -> SDoc` * as a consequence, I've refactored some modules to avoid .hs-boot files * added (derived) functor instances for some datatypes parametric in the instruction type. It's useful for pretty-printing as we just have to map `pprInstr` before pretty-printing the container datatype. - - - - - 731c8d3b by nineonine at 2020-08-19T18:47:39-04:00 Implement -Wredundant-bang-patterns (#17340) Add new flag '-Wredundant-bang-patterns' that enables checks for "dead" bangs. Dead bangs are the ones that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs. The new check is performed in Pattern-Match Coverage Checker along with other checks (namely, redundant and inaccessible RHSs). Given f :: Bool -> Int f True = 1 f !x = 2 we can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. Note that we don't want to warn for a dead bang that appears on a redundant clause. That is because in that case, we recommend to delete the clause wholly, including its leading pattern match. Dead bang patterns are redundant. But there are bang patterns which are redundant that aren't dead, for example f !() = 0 the bang still forces the match variable, before we attempt to match on (). But it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. - - - - - eb9bdaef by Simon Peyton Jones at 2020-08-19T18:48:14-04:00 Add right-to-left rule for pattern bindings Fix #18323 by adding a few lines of code to handle non-recursive pattern bindings. see GHC.Tc.Gen.Bind Note [Special case for non-recursive pattern bindings] Alas, this confused the pattern-match overlap checker; see #18323. Note that this patch only affects pattern bindings like that for (x,y) in this program combine :: (forall a . [a] -> a) -> [forall a. a -> a] -> ((forall a . [a] -> a), [forall a. a -> a]) breaks = let (x,y) = combine head ids in x y True We need ImpredicativeTypes for those [forall a. a->a] types to be valid. And with ImpredicativeTypes the old, unprincipled "allow unification variables to unify with a polytype" story actually works quite well. So this test compiles fine (if delicatedly) with old GHCs; but not with QuickLook unless we add this patch - - - - - 293c7fba by Sylvain Henry at 2020-08-21T09:36:38-04:00 Put CFG weights into their own module (#17957) It avoids having to query DynFlags to get them - - - - - 50eb4460 by Sylvain Henry at 2020-08-21T09:36:38-04:00 Don't use DynFlags in CmmToAsm.BlockLayout (#17957) - - - - - 659eb31b by Sylvain Henry at 2020-08-21T09:36:38-04:00 NCG: Dwarf configuration * remove references to DynFlags in GHC.CmmToAsm.Dwarf * add specific Dwarf options in NCGConfig instead of directly querying the debug level - - - - - 2d8ca917 by Sylvain Henry at 2020-08-21T09:37:15-04:00 Fix -ddump-stg flag -ddump-stg was dumping the initial STG (just after Core-to-STG pass) which was misleading because we want the final STG to know if a function allocates or not. Now we have a new flag -ddump-stg-from-core for this and -ddump-stg is deprecated. - - - - - fddddbf4 by Vladislav Zavialov at 2020-08-21T09:37:49-04:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. - - - - - 989c1c27 by Ben Gamari at 2020-08-21T11:27:53-04:00 gitlab-ci: Test master branch as well While these builds are strictly speaking redundant (since every commit is tested by @marge-bot before making it into `master`), they are nevertheless useful as they are displayed in the branch's commit list in GitLab's web interface. Fixes #18595. - - - - - e67ae884 by Aditya Gupta at 2020-08-22T03:29:00-04:00 mkUnique refactoring (#18362) Move uniqFromMask from Unique.Supply to Unique. Move the the functions that call mkUnique from Unique to Builtin.Uniques - - - - - 03cfcfd4 by Wander Hillen at 2020-08-22T03:29:36-04:00 Add ubuntu 20.04 jobs for nightly and release - - - - - 3f501545 by Craig Ferguson at 2020-08-22T03:30:13-04:00 Utils: clarify docs slightly The previous comment implies `nTimes n f` is either `f^{n+1}` or `f^{2^n}` (when in fact it's `f^n`). - - - - - 8b865092 by Krzysztof Gogolewski at 2020-08-23T14:12:53+02:00 Do not print synonyms in :i (->), :i Type (#18594) This adds a new printing flag `sdocPrintTypeAbbreviations` that is used specifically to avoid ghci printing 'type (->) = (->)' and 'type Type = Type'. - - - - - d8f61182 by Krzysztof Gogolewski at 2020-08-23T14:12:56+02:00 Move pprTyTcApp' inside pprTyTcApp No semantic change - - - - - 364258e0 by Krzysztof Gogolewski at 2020-08-24T00:32:31-04:00 Fix types in silly shifts (#18589) Patch written by Simon. I have only added a testcase. - - - - - b1eb38a0 by Sylvain Henry at 2020-08-24T00:33:13-04:00 Perf: make SDoc monad one-shot (#18202) With validate-x86_64-linux-deb9-hadrian: T1969 -3.4% (threshold: +/-1%) T3294 -3.3% (threshold: +/-1%) T12707 -1.4% (threshold: +/-1%) Additionally with validate-x86_64-linux-deb9-unreg-hadrian: T4801 -2.4% (threshold: +/-2%) T13035 -1.4% (threshold: +/-1%) T13379 -2.4% (threshold: +/-2%) ManyAlternatives -2.5% (threshold: +/-2%) ManyConstructors -3.0% (threshold: +/-2%) Metric Decrease: T12707 T1969 T3294 ManyAlternatives ManyConstructors T13035 T13379 T4801 - - - - - a77b9ec2 by Krzysztof Gogolewski at 2020-08-24T10:04:20-04:00 Add a test for #18397 The bug was fixed by !3421. - - - - - 05550a5a by Sylvain Henry at 2020-08-24T10:04:59-04:00 Avoid roundtrip through SDoc As found by @monoidal on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3885#note_295126 - - - - - 0a1ecc5f by Ben Gamari at 2020-08-25T07:37:05-04:00 SysTools.Process: Handle exceptions in readCreateProcessWithExitCode' In #18069 we are observing MVar deadlocks from somewhere in ghc.exe. This use of MVar stood out as being one of the more likely culprits. Here we make sure that it is exception-safe. - - - - - db8793ad by Richard Eisenberg at 2020-08-25T07:37:40-04:00 Use tcView, not coreView, in the pure unifier. Addresses a lingering point within #11715. - - - - - fb77207a by Simon Peyton Jones at 2020-08-25T07:38:16-04:00 Use LIdP rather than (XRec p (IdP p)) This patch mainly just replaces use of XRec p (IdP p) with LIdP p One slightly more significant change is to parameterise HsPatSynDetails over the pass rather than the argument type, so that it's uniform with HsConDeclDetails and HsConPatDetails. I also got rid of the dead code GHC.Hs.type.conDetailsArgs But this is all just minor refactoring. No change in functionality. - - - - - 8426a136 by Krzysztof Gogolewski at 2020-08-25T07:38:54-04:00 Add a test for #18585 - - - - - 2d635a50 by Takenobu Tani at 2020-08-26T04:50:21-04:00 linters: Make CPP linter skip image files This patch adds an exclusion rule for `docs/users_guide/images`, to avoid lint errors of PDF files. - - - - - b7d98cb2 by Takenobu Tani at 2020-08-26T04:50:21-04:00 users-guide: Color the logo on the front page of the PDF This patch updates the logo with a recent color scheme. This affects only the PDF version of the user's guide. See also: * https://mail.haskell.org/pipermail/ghc-devs/2020-August/019139.html * https://gitlab.haskell.org/ghc/ghc/-/wikis/logo - - - - - 0b17fa18 by Sylvain Henry at 2020-08-26T04:50:58-04:00 Refactor UnitId pretty-printing When we pretty-print a UnitId for the user, we try to map it back to its origin package name, version and component to print "package-version:component" instead of some hash. The UnitId type doesn't carry these information, so we have to look into a UnitState to find them. This is why the Outputable instance of UnitId used `sdocWithDynFlags` in order to access the `unitState` field of DynFlags. This is wrong for several reasons: 1. The DynFlags are accessed when the message is printed, not when it is generated. So we could imagine that the unitState may have changed in-between. Especially if we want to allow unit unloading. 2. We want GHC to support several independent sessions at once, hence several UnitState. The current approach supposes there is a unique UnitState as a UnitId doesn't indicate which UnitState to use. See the Note [Pretty-printing UnitId] in GHC.Unit for the new approach implemented by this patch. One step closer to remove `sdocDynFlags` field from `SDocContext` (#10143). Fix #18124. Also fix some Backpack code to use SDoc instead of String. - - - - - dc476a50 by Sylvain Henry at 2020-08-26T04:51:35-04:00 Bignum: fix BigNat subtraction (#18604) There was a confusion between the boolean expected by withNewWordArrayTrimedMaybe and the boolean returned by subtracting functions. - - - - - fcb10b6c by Peter Trommler at 2020-08-26T10:42:30-04:00 PPC and X86: Portable printing of IEEE floats GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness. This was brought up in #18431 by @hsyl20. - - - - - 770100e0 by Krzysztof Gogolewski at 2020-08-26T10:43:13-04:00 primops: Remove Monadic and Dyadic categories There were four categories of primops: Monadic, Dyadic, Compare, GenPrimOp. The compiler does not treat Monadic and Dyadic in any special way, we can just replace them with GenPrimOp. Compare is still used in isComparisonPrimOp. - - - - - 01ff8c89 by Aditya Gupta at 2020-08-27T14:19:26-04:00 Consolidate imports in getMinimalImports (#18264) - - - - - bacccb73 by Ryan Scott at 2020-08-27T14:20:01-04:00 Make {hsExpr,hsType,pat}NeedsParens aware of boxed 1-tuples `hsExprNeedsParens`, `hsTypeNeedsParens`, and `patNeedsParens` previously assumed that all uses of explicit tuples in the source syntax never need to be parenthesized. This is true save for one exception: boxed one-tuples, which use the `Solo` data type from `GHC.Tuple` instead of special tuple syntax. This patch adds the necessary logic to the three `*NeedsParens` functions to handle `Solo` correctly. Fixes #18612. - - - - - c6f50cea by Krzysztof Gogolewski at 2020-08-28T02:22:36-04:00 Add missing primop documentation (#18454) - Add three pseudoops to primops.txt.pp, so that Haddock renders the documentation - Update comments - Remove special case for "->" - it's no longer exported from GHC.Prim - Remove reference to Note [Compiling GHC.Prim] - the ad-hoc fix is no longer there after updates to levity polymorphism. - Document GHC.Prim - Remove the comment that lazy is levity-polymorphic. As far as I can tell, it never was: in 80e399639, only the unfolding was given an open type variable. - Remove haddock hack in GHC.Magic - no longer neccessary after adding realWorld# to primops.txt.pp. - - - - - f065b6b0 by Tamar Christina at 2020-08-28T02:23:13-04:00 Fix use distro toolchian - - - - - 4517a382 by Tamar Christina at 2020-08-28T02:23:13-04:00 document how build system find toolchains on Windows - - - - - 21c0a84f by John Ericson at 2020-08-29T20:48:40-04:00 Make fixed-size `Int32#` and `Int64#` The boxed Int64 uses Int64#, but Int32# still uses Int#. The 32-bit case is less pressing to change because it is not a source of brittle CPP---it is the same thing on all platforms. We need Int64/Word64 constant folding to avoid the let/app restriction on Core, so that is implemented now. 32-bit constant unfolding and 32-bit literals are left as follow-up. This is the bulk of #11953 ghc-bignum: add support for Word64#/Int64# on 64-bit arch Fix fingerprint Core generation Fix some tests Co-authored-by: Sylvain Henry <hsyl20 at gmail.com> - - - - - 463dde40 by John Ericson at 2020-08-29T20:50:50-04:00 Inline INT64 and WORD64 macros in primops.txt.pp The definition is now unconditional so there is no reason for that CPP. - - - - - 54ae3476 by Sylvain Henry at 2020-08-29T20:50:51-04:00 Fix toArgRep - - - - - 4952704c by Sylvain Henry at 2020-08-29T20:50:51-04:00 Adapt rules from #16402 to Word64#/Int64# - - - - - 8557e524 by John Ericson at 2020-08-29T20:50:51-04:00 Copy enumFrom* implementations from Int/Word for Int64/Word64 Without this, we don't get proper list fusion. I think this sort of copying is OK for now, but we absolutely need something better if we are going to make `IntN` use `IntN#` for all `N`. The degree to which proper metaprogramming has been punted upon by factoring everything through the native-sized types is disconcerting. - - - - - 30 changed files: - .gitlab-ci.yml - .gitlab/ci.sh - .gitlab/linters/check-cpp.py - aclocal.m4 - compiler/GHC.hs - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Names/TH.hs - compiler/GHC/Builtin/PrimOps.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Types.hs-boot - compiler/GHC/Builtin/Types/Prim.hs - compiler/GHC/Builtin/Uniques.hs - compiler/GHC/Builtin/Uniques.hs-boot - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/Cmm.hs - compiler/GHC/Cmm/CLabel.hs - compiler/GHC/Cmm/CallConv.hs - compiler/GHC/Cmm/CommonBlockElim.hs - compiler/GHC/Cmm/DebugBlock.hs - compiler/GHC/Cmm/Expr.hs - compiler/GHC/Cmm/Info/Build.hs - compiler/GHC/Cmm/LayoutStack.hs - compiler/GHC/Cmm/Liveness.hs - compiler/GHC/Cmm/Opt.hs - compiler/GHC/Cmm/Parser.y - compiler/GHC/Cmm/Ppr/Decl.hs - compiler/GHC/Cmm/Ppr/Expr.hs - compiler/GHC/Cmm/ProcPoint.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/523014efd4ca02f4410e847fb01b72bcb766f3b8...8557e5246ff12ca1a09595166ec09d82528267a6 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/523014efd4ca02f4410e847fb01b72bcb766f3b8...8557e5246ff12ca1a09595166ec09d82528267a6 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Sun Aug 30 22:54:05 2020 From: gitlab at gitlab.haskell.org (John Ericson) Date: Sun, 30 Aug 2020 18:54:05 -0400 Subject: [Git][ghc/ghc][wip/int64-everywhere] `integerFromInt64#` can be inlined when the word size is >= 64 bits Message-ID: <5f4c2e0d6cf5d_80bd61136098441af@gitlab.haskell.org.mail> John Ericson pushed to branch wip/int64-everywhere at Glasgow Haskell Compiler / GHC Commits: 4ad18921 by John Ericson at 2020-08-30T18:49:53-04:00 `integerFromInt64#` can be inlined when the word size is >= 64 bits Maybe this will help with the renaming test failure? - - - - - 1 changed file: - libraries/ghc-bignum/src/GHC/Num/Integer.hs Changes: ===================================== libraries/ghc-bignum/src/GHC/Num/Integer.hs ===================================== @@ -972,8 +972,8 @@ integerIsPowerOf2# (IP w) = bigNatIsPowerOf2# w -- | Convert an Int64# into an Integer integerFromInt64# :: Int64# -> Integer -{-# NOINLINE integerFromInt64# #-} integerFromInt64# !i +#if WORD_SIZE_IN_BITS < 64 | isTrue# ((i `leInt64#` intToInt64# INT_MAXBOUND#) &&# (i `geInt64#` intToInt64# INT_MINBOUND#)) = IS (int64ToInt# i) @@ -983,6 +983,11 @@ integerFromInt64# !i | True = IN (bigNatFromWord64# (int64ToWord64# (negateInt64# i))) +{-# NOINLINE integerFromInt64# #-} +#else + = IS (int64ToInt# i) +{-# INLINE integerFromInt64# #-} +#endif -- | Convert a Word64# into an Integer integerFromWord64# :: Word64# -> Integer View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4ad1892180f714a36707de8a7702fd12cb8f248b -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4ad1892180f714a36707de8a7702fd12cb8f248b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 08:59:25 2020 From: gitlab at gitlab.haskell.org (Moritz Angermann) Date: Mon, 31 Aug 2020 04:59:25 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/angerman/fix-rpath Message-ID: <5f4cbbed79cbf_80b3f843fb1a5dc9853596@gitlab.haskell.org.mail> Moritz Angermann pushed new branch wip/angerman/fix-rpath at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/angerman/fix-rpath You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 12:03:13 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Mon, 31 Aug 2020 08:03:13 -0400 Subject: [Git][ghc/ghc][wip/buggymcbugfix/insertArray] 2 commits: Cleanup Message-ID: <5f4ce701b92c7_80b8b32c4098776b6@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed to branch wip/buggymcbugfix/insertArray at Glasgow Haskell Compiler / GHC Commits: 7fa459f8 by buggymcbugfix at 2020-08-30T15:52:31+02:00 Cleanup * Remove unused variable * Use WDS macro - - - - - 24cf65fc by buggymcbugfix at 2020-08-31T14:02:54+02:00 WIP - - - - - 4 changed files: - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/StgToCmm/Prim.hs - includes/Cmm.h - rts/PrimOps.cmm Changes: ===================================== compiler/GHC/Builtin/primops.txt.pp ===================================== @@ -1264,6 +1264,32 @@ primop CasArrayOp "casArray#" GenPrimOp out_of_line = True has_side_effects = True +primop InsertArrayOp "insertArray#" GenPrimOp + Array# a -> Int# -> a -> Array# a + {Given an array @a@, an index @i@ and an element @x@, insert the @x@ into a + copy of @a@ at @i at . Assumes @0 <= i <= sizeOf a at .} + with + out_of_line = True + has_side_effects = True + can_fail = True + +primop UpdateArrayOp "updateArray#" GenPrimOp + Array# a -> Int# -> a -> Array# a + {Given an array @a@, an index @i@ and an element @x@, update the @i at th element + to @x@ in a copy of @a@ at @i at . Assumes @0 <= i < sizeOf a at .} + with + out_of_line = True + has_side_effects = True + can_fail = True + +primop DeleteArrayOp "deleteArray#" GenPrimOp + Array# a -> Int# -> Array# a + {Given an array @a@ and an index @i@ and an element @x@, return a copy of @a@ + with the @i at th element deleted. Assumes @0 <= i < sizeOf a at .} + with + out_of_line = True + has_side_effects = True + can_fail = True ------------------------------------------------------------------------ section "Small Arrays" @@ -1445,6 +1471,33 @@ primop CasSmallArrayOp "casSmallArray#" GenPrimOp out_of_line = True has_side_effects = True +primop InsertSmallArrayOp "insertSmallArray#" GenPrimOp + SmallArray# a -> Int# -> a -> SmallArray# a + {Given an array, an index and an element, insert the element into a copy of + the array. Assumes 0 <= index <= sizeOf array.} + with + out_of_line = True + has_side_effects = True + can_fail = True + +primop UpdateSmallArrayOp "updateSmallArray#" GenPrimOp + SmallArray# a -> Int# -> a -> SmallArray# a + {Given an array @a@, an index @i@ and an element @x@, update the @i at th element + to @x@ in a copy of @a@ at @i at . Assumes @0 <= i < sizeOf a at .} + with + out_of_line = True + has_side_effects = True + can_fail = True + +primop DeleteSmallArrayOp "deleteSmallArray#" GenPrimOp + SmallArray# a -> Int# -> SmallArray# a + {Clone the array but without the element at the given index. + Assumes 0 <= index < sizeOf array.} + with + out_of_line = True + has_side_effects = True + can_fail = True + ------------------------------------------------------------------------ section "Byte Arrays" {Operations on {\tt ByteArray\#}. A {\tt ByteArray\#} is a just a region of ===================================== compiler/GHC/StgToCmm/Prim.hs ===================================== @@ -219,6 +219,12 @@ emitPrimOp dflags primop = case primop of -> opIntoRegs $ \ [res] -> emitCloneArray mkMAP_DIRTY_infoLabel res src src_off (fromInteger n) _ -> PrimopCmmEmit_External + InsertArrayOp -> const PrimopCmmEmit_External + + UpdateArrayOp -> const PrimopCmmEmit_External + + DeleteArrayOp -> const PrimopCmmEmit_External + NewSmallArrayOp -> \case [(CmmLit (CmmInt n w)), init] | wordsToBytes platform (asUnsigned w n) <= fromIntegral (maxInlineAllocSize dflags) @@ -264,6 +270,12 @@ emitPrimOp dflags primop = case primop of -> opIntoRegs $ \ [res] -> emitCloneSmallArray mkSMAP_DIRTY_infoLabel res src src_off (fromInteger n) _ -> PrimopCmmEmit_External + InsertSmallArrayOp -> const PrimopCmmEmit_External + + UpdateSmallArrayOp -> const PrimopCmmEmit_External + + DeleteSmallArrayOp -> const PrimopCmmEmit_External + -- First we handle various awkward cases specially. ParOp -> \[arg] -> opIntoRegs $ \[res] -> do ===================================== includes/Cmm.h ===================================== @@ -801,7 +801,7 @@ \ dst_p = dst + SIZEOF_StgMutArrPtrs; \ src_p = src + SIZEOF_StgMutArrPtrs + WDS(offset); \ - prim %memcpy(dst_p, src_p, n * SIZEOF_W, SIZEOF_W); \ + prim %memcpy(dst_p, src_p, WDS(n), SIZEOF_W); \ \ return (dst); @@ -862,7 +862,7 @@ array ops. Defined as a macro to avoid function call overhead or code duplication. */ #define cloneSmallArray(info, src, offset, n) \ - W_ words, size; \ + W_ words; \ gcptr dst, dst_p, src_p; \ \ again: MAYBE_GC(again); \ @@ -876,7 +876,7 @@ \ dst_p = dst + SIZEOF_StgSmallMutArrPtrs; \ src_p = src + SIZEOF_StgSmallMutArrPtrs + WDS(offset); \ - prim %memcpy(dst_p, src_p, n * SIZEOF_W, SIZEOF_W); \ + prim %memcpy(dst_p, src_p, WDS(n), SIZEOF_W); \ \ return (dst); ===================================== rts/PrimOps.cmm ===================================== @@ -371,6 +371,19 @@ stg_casArrayzh ( gcptr arr, W_ ind, gcptr old, gcptr new ) } } +stg_insertArrayzh( gcptr src, W_ idx, gcptr elemt ) +{ + return (); +} +stg_updateArrayzh( gcptr src, W_ idx, gcptr elemt ) +{ + return (); +} +stg_deleteArrayzh( gcptr src, W_ idx ) +{ + return (); +} + stg_newArrayArrayzh ( W_ n /* words */ ) { W_ words, size, p; @@ -570,6 +583,81 @@ stg_casSmallArrayzh ( gcptr arr, W_ ind, gcptr old, gcptr new ) } } +stg_insertSmallArrayzh( gcptr src, W_ idx, gcptr elemt ) +{ + W_ words, n; + gcptr dst, dst_p, src_p; + + again: MAYBE_GC(again); + + // ccall barf("argh"); + n = StgSmallMutArrPtrs_ptrs(src) + 1; + + words = BYTES_TO_WDS(SIZEOF_StgSmallMutArrPtrs) + n; + ("ptr" dst) = ccall allocate(MyCapability() "ptr", words); + TICK_ALLOC_PRIM(SIZEOF_StgSmallMutArrPtrs, WDS(n), 0); + + SET_HDR(dst, stg_SMALL_MUT_ARR_PTRS_FROZEN_CLEAN_info, CCCS); + StgSmallMutArrPtrs_ptrs(dst) = n; + + dst_p = dst + SIZEOF_StgSmallMutArrPtrs; + src_p = src + SIZEOF_StgSmallMutArrPtrs; + prim %memcpy(dst_p, src_p, WDS(idx), SIZEOF_W); + REP_StgSmallMutArrPtrs_ptrs[dst_p + WDS(idx)] = elemt; + prim %memcpy(dst_p + WDS(idx + 1), src_p + WDS(idx), WDS(n - idx - 1), SIZEOF_W); + + return (dst); +} + +stg_updateSmallArrayzh( gcptr src, W_ idx, gcptr elemt ) +{ + W_ words, n; + gcptr dst, dst_p, src_p; + + again: MAYBE_GC(again); + + n = StgSmallMutArrPtrs_ptrs(src); + + words = BYTES_TO_WDS(SIZEOF_StgSmallMutArrPtrs) + n; + ("ptr" dst) = ccall allocate(MyCapability() "ptr", words); + TICK_ALLOC_PRIM(SIZEOF_StgSmallMutArrPtrs, WDS(n), 0); + + SET_HDR(dst, stg_SMALL_MUT_ARR_PTRS_FROZEN_CLEAN_info, CCCS); + StgSmallMutArrPtrs_ptrs(dst) = n; + + dst_p = dst + SIZEOF_StgSmallMutArrPtrs; + src_p = src + SIZEOF_StgSmallMutArrPtrs; + prim %memcpy(dst_p, src_p, WDS(idx), SIZEOF_W); + REP_StgSmallMutArrPtrs_ptrs[dst_p + WDS(idx)] = elemt; + prim %memcpy(dst_p + WDS(idx + 1), src_p + WDS(idx + 1), WDS(n - idx - 1), SIZEOF_W); + + return (dst); +} + +stg_deleteSmallArrayzh( gcptr src, W_ idx ) +{ + W_ words, n; + gcptr dst, dst_p, src_p; + + again: MAYBE_GC(again); + + n = StgSmallMutArrPtrs_ptrs(src) - 1; + + words = BYTES_TO_WDS(SIZEOF_StgSmallMutArrPtrs) + n; + ("ptr" dst) = ccall allocate(MyCapability() "ptr", words); + TICK_ALLOC_PRIM(SIZEOF_StgSmallMutArrPtrs, WDS(n), 0); + + SET_HDR(dst, stg_SMALL_MUT_ARR_PTRS_FROZEN_CLEAN_info, CCCS); + StgSmallMutArrPtrs_ptrs(dst) = n; + + dst_p = dst + SIZEOF_StgSmallMutArrPtrs; + src_p = src + SIZEOF_StgSmallMutArrPtrs; + + prim %memcpy(dst_p, src_p, WDS(idx), SIZEOF_W); + prim %memcpy(dst_p + WDS(idx), src_p + WDS(idx + 1), WDS(n - idx), SIZEOF_W); + + return (dst); +} /* ----------------------------------------------------------------------------- MutVar primitives View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5a0320d42f30ee4b0c37700d7dfd3e3ac81d13ad...24cf65fc849c483d75da379495516da09dbd2b38 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5a0320d42f30ee4b0c37700d7dfd3e3ac81d13ad...24cf65fc849c483d75da379495516da09dbd2b38 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 12:10:53 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Mon, 31 Aug 2020 08:10:53 -0400 Subject: [Git][ghc/ghc][wip/buggymcbugfix/insertArray] address comments Message-ID: <5f4ce8cdb4d0d_80b8b32c409880452@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed to branch wip/buggymcbugfix/insertArray at Glasgow Haskell Compiler / GHC Commits: c045d93a by buggymcbugfix at 2020-08-31T14:10:42+02:00 address comments - - - - - 1 changed file: - rts/PrimOps.cmm Changes: ===================================== rts/PrimOps.cmm ===================================== @@ -373,15 +373,15 @@ stg_casArrayzh ( gcptr arr, W_ ind, gcptr old, gcptr new ) stg_insertArrayzh( gcptr src, W_ idx, gcptr elemt ) { - return (); + ccall barf("stg_insertArrayzh not implemented."); } stg_updateArrayzh( gcptr src, W_ idx, gcptr elemt ) { - return (); + ccall barf("stg_updateArrayzh not implemented."); } stg_deleteArrayzh( gcptr src, W_ idx ) { - return (); + ccall barf("stg_deleteArrayzh not implemented."); } stg_newArrayArrayzh ( W_ n /* words */ ) @@ -590,7 +590,6 @@ stg_insertSmallArrayzh( gcptr src, W_ idx, gcptr elemt ) again: MAYBE_GC(again); - // ccall barf("argh"); n = StgSmallMutArrPtrs_ptrs(src) + 1; words = BYTES_TO_WDS(SIZEOF_StgSmallMutArrPtrs) + n; View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c045d93ab1d298b9cdb40e950445b9cec64fa37c -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c045d93ab1d298b9cdb40e950445b9cec64fa37c You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 12:24:10 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Mon, 31 Aug 2020 08:24:10 -0400 Subject: [Git][ghc/ghc][wip/T18565] PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Message-ID: <5f4cebea52564_80b477530498818f4@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18565 at Glasgow Haskell Compiler / GHC Commits: 65d51d90 by Sebastian Graf at 2020-08-31T14:23:54+02:00 PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Previously, we desugared and coverage checked plain guard trees as described in Lower Your Guards. That caused (in !3849) quite a bit of pain when we need to partially recover tree structure of the input syntax to return covered sets for long-distance information, for example. In this refactor, I introduced a guard tree variant for each relevant source syntax component of a pattern-match (mainly match groups, match, GRHS, empty case, pattern binding). I made sure to share as much coverage checking code as possible, so that the syntax-specific checking functions are just wrappers around the more substantial checking functions for the LYG primitives (`checkSequence`, `checkGrds`). The refactoring payed off in clearer code and elimination of all panics related to assumed guard tree structure and thus fixes #18565. I also took the liberty to rename and re-arrange the order of functions and comments in the module, deleted some dead and irrelevant Notes, wrote some new ones and gave an overview module haddock. - - - - - 14 changed files: - compiler/GHC/Data/OrdList.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - compiler/GHC/HsToCore/PmCheck/Types.hs - compiler/GHC/Tc/Types.hs - compiler/GHC/Utils/Misc.hs - testsuite/tests/deSugar/should_compile/ds020.stderr - testsuite/tests/module/all.T - testsuite/tests/pmcheck/should_compile/T18572.hs - testsuite/tests/rename/should_compile/T7085.stderr - testsuite/tests/unboxedsums/all.T Changes: ===================================== compiler/GHC/Data/OrdList.hs ===================================== @@ -5,13 +5,16 @@ -} {-# LANGUAGE DeriveFunctor #-} - {-# LANGUAGE BangPatterns #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE UnboxedSums #-} +{-# LANGUAGE UnboxedTuples #-} -- | Provide trees (of instructions), so that lists of instructions can be -- appended in linear time. module GHC.Data.OrdList ( - OrdList, + OrdList, pattern NilOL, pattern ConsOL, pattern SnocOL, nilOL, isNilOL, unitOL, appOL, consOL, snocOL, concatOL, lastOL, headOL, mapOL, fromOL, toOL, foldrOL, foldlOL, reverseOL, fromOLReverse, @@ -79,6 +82,50 @@ snocOL as b = Snoc as b consOL a bs = Cons a bs concatOL aas = foldr appOL None aas +pattern NilOL :: OrdList a +pattern NilOL <- (isNilOL -> True) where + NilOL = None + +-- | An unboxed 'Maybe' type with two unboxed fields in the 'Just' case. +-- Useful for defining 'viewCons' and 'viewSnoc' without overhead. +type VMaybe a b = (# (# a, b #) | (# #) #) +pattern VJust :: a -> b -> VMaybe a b +pattern VJust a b = (# (# a, b #) | #) +pattern VNothing :: VMaybe a b +pattern VNothing = (# | (# #) #) +{-# COMPLETE VJust, VNothing #-} + +pattern ConsOL :: a -> OrdList a -> OrdList a +pattern ConsOL x xs <- (viewCons -> VJust x xs) where + ConsOL x xs = consOL x xs +{-# COMPLETE NilOL, ConsOL #-} +viewCons :: OrdList a -> VMaybe a (OrdList a) +viewCons (One a) = VJust a NilOL +viewCons (Cons a as) = VJust a as +viewCons (Snoc as a) = case viewCons as of + VJust a' as' -> VJust a' (Snoc as' a) + VNothing -> VJust a NilOL +viewCons (Two as1 as2) = case viewCons as1 of + VJust a' as1' -> VJust a' (Two as1' as2) + VNothing -> viewCons as2 +viewCons _ = VNothing + +pattern SnocOL :: OrdList a -> a -> OrdList a +pattern SnocOL xs x <- (viewSnoc -> VJust xs x) where + SnocOL xs x = snocOL xs x +{-# COMPLETE NilOL, SnocOL #-} +viewSnoc :: OrdList a -> VMaybe (OrdList a) a +viewSnoc (One a) = VJust NilOL a +viewSnoc (Many (reverse -> a:as)) = VJust (Many (reverse as)) a +viewSnoc (Snoc as a) = VJust as a +viewSnoc (Cons a as) = case viewSnoc as of + VJust as' a' -> VJust (Cons a as') a' + VNothing -> VJust NilOL a +viewSnoc (Two as1 as2) = case viewSnoc as2 of + VJust as2' a' -> VJust (Two as1 as2') a' + VNothing -> viewSnoc as1 +viewSnoc _ = VNothing + headOL None = panic "headOL" headOL (One a) = a headOL (Many as) = head as @@ -189,5 +236,3 @@ strictlyOrdOL (Two a1 a2) (Two b1 b2) = strictlyOrdOL (Two _ _) _ = LT strictlyOrdOL (Many as) (Many bs) = compare as bs strictlyOrdOL (Many _ ) _ = GT - - ===================================== compiler/GHC/HsToCore/Binds.hs ===================================== @@ -33,7 +33,7 @@ import {-# SOURCE #-} GHC.HsToCore.Match ( matchWrapper ) import GHC.HsToCore.Monad import GHC.HsToCore.GuardedRHSs import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck ( addTyCsDs, covCheckGRHSs ) +import GHC.HsToCore.PmCheck ( addTyCs, covCheckGRHSs ) import GHC.Hs -- lots of things import GHC.Core -- lots of things @@ -151,14 +151,14 @@ dsHsBind dflags b@(FunBind { fun_id = L loc fun , fun_matches = matches , fun_ext = co_fn , fun_tick = tick }) - = do { (args, body) <- addTyCsDs FromSource (hsWrapDictBinders co_fn) $ + = do { (args, body) <- addTyCs FromSource (hsWrapDictBinders co_fn) $ -- FromSource might not be accurate (we don't have any -- origin annotations for things in this module), but at -- worst we do superfluous calls to the pattern match -- oracle. - -- addTyCsDs: Add type evidence to the refinement type + -- addTyCs: Add type evidence to the refinement type -- predicate of the coverage checker - -- See Note [Type and Term Equality Propagation] in "GHC.HsToCore.PmCheck" + -- See Note [Long-distance information] in "GHC.HsToCore.PmCheck" matchWrapper (mkPrefixFunRhs (L loc (idName fun))) Nothing matches @@ -200,11 +200,11 @@ dsHsBind dflags (AbsBinds { abs_tvs = tyvars, abs_ev_vars = dicts , abs_exports = exports , abs_ev_binds = ev_binds , abs_binds = binds, abs_sig = has_sig }) - = do { ds_binds <- addTyCsDs FromSource (listToBag dicts) $ + = do { ds_binds <- addTyCs FromSource (listToBag dicts) $ dsLHsBinds binds - -- addTyCsDs: push type constraints deeper + -- addTyCs: push type constraints deeper -- for inner pattern match check - -- See Check, Note [Type and Term Equality Propagation] + -- See Check, Note [Long-distance information] ; ds_ev_binds <- dsTcEvBinds_s ev_binds ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -31,7 +31,7 @@ import GHC.HsToCore.ListComp import GHC.HsToCore.Utils import GHC.HsToCore.Arrows import GHC.HsToCore.Monad -import GHC.HsToCore.PmCheck ( addTyCsDs, covCheckGRHSs ) +import GHC.HsToCore.PmCheck ( addTyCs, covCheckGRHSs ) import GHC.Types.Name import GHC.Types.Name.Env import GHC.Core.FamInstEnv( topNormaliseType ) @@ -283,7 +283,7 @@ dsExpr hswrap@(XExpr (WrapExpr (HsWrap co_fn e))) HsConLikeOut _ (RealDataCon dc) -> return $ varToCoreExpr (dataConWrapId dc) XExpr (WrapExpr (HsWrap _ _)) -> pprPanic "dsExpr: HsWrap inside HsWrap" (ppr hswrap) HsPar _ _ -> pprPanic "dsExpr: HsPar inside HsWrap" (ppr hswrap) - _ -> addTyCsDs FromSource (hsWrapDictBinders co_fn) $ + _ -> addTyCs FromSource (hsWrapDictBinders co_fn) $ dsExpr e -- See Note [Detecting forced eta expansion] ; wrap' <- dsHsWrapper co_fn ===================================== compiler/GHC/HsToCore/Match.hs ===================================== @@ -770,8 +770,8 @@ matchWrapper ctxt mb_scr (MG { mg_alts = L _ matches -- Each Match will split off one Deltas for its RHSs from this. ; matches_deltas <- if isMatchContextPmChecked dflags origin ctxt then addHsScrutTmCs mb_scr new_vars $ - -- See Note [Type and Term Equality Propagation] - covCheckMatchGroup (DsMatchContext ctxt locn) new_vars matches + -- See Note [Long-distance information] + covCheckMatches (DsMatchContext ctxt locn) new_vars matches else pure (initDeltasMatches matches) ; eqns_info <- zipWithM mk_eqn_info matches matches_deltas @@ -881,7 +881,7 @@ matchSinglePatVar var mb_scrut ctx pat ty match_result -- Pattern match check warnings ; when (isMatchContextPmChecked dflags FromSource ctx) $ addCoreScrutTmCs mb_scrut [var] $ - covCheckPatBind dflags (DsMatchContext ctx locn) var (unLoc pat) + covCheckPatBind (DsMatchContext ctx locn) var (unLoc pat) ; let eqn_info = EqnInfo { eqn_pats = [unLoc (decideBangHood dflags pat)] , eqn_orig = FromSource ===================================== compiler/GHC/HsToCore/PmCheck.hs ===================================== @@ -1,24 +1,49 @@ -{- -Author: George Karachalias - -Pattern Matching Coverage Checking. --} - -{-# LANGUAGE CPP #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE TupleSections #-} -{-# LANGUAGE ViewPatterns #-} -{-# LANGUAGE MultiWayIf #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE NamedFieldPuns #-} - +{-# LANGUAGE CPP #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE TupleSections #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE MultiWayIf #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE NamedFieldPuns #-} + +-- | This module coverage checks pattern matches. It finds +-- +-- * Uncovered patterns, certifying non-exhaustivity +-- * Redundant equations +-- * Equations with an inaccessible right-hand-side +-- +-- The algorithm is based on the paper +-- [Lower Your Guards: A Compositional Pattern-Match Coverage Checker"](https://dl.acm.org/doi/abs/10.1145/3408989) +-- +-- There is an overview Figure 2 in there that's probably helpful. +-- Here is an overview of how it's implemented, which follows the structure of +-- the entry points such as 'covCheckMatches': +-- +-- 1. Desugar source syntax (like 'LMatch') to guard tree variants (like +-- 'GrdMatch'), with one of the desugaring functions (like 'desugarMatch'). +-- Follows Section 3.1 in the paper. +-- 2. Coverage check guard trees (with a function like 'checkMatch') to get a +-- 'CheckResult', containing +-- a. The set of uncovered values, 'cr_uncov' +-- b. And an annotated tree variant (like 'AnnMatch') that captures +-- redundancy and inaccessibility information as 'RedSets' annotations +-- Basically the UA function from Section 5.1. The Normalised Refinement Types +-- Nabla are modeled as 'Deltas' and checked in "GHC.HsToCore.PmCheck.Oracle". +-- 3. Collect redundancy information into a 'CIRB' with a 'CIRBCollector' such +-- as 'collectMatch'. Follows the R function from Figure 6 of the paper. +-- 4. Format and report uncovered patterns and redundant equations ('CIRB') +-- with 'formatReportWarnings'. Basically job of the G function, plus proper +-- pretty printing of the warnings (Section 5.4 of the paper). +-- 5. Return 'Deltas' reaching syntactic sub-components for +-- Note [Long-distance information]. See Section 4.1 of the paper. module GHC.HsToCore.PmCheck ( -- Checking and printing - covCheckPatBind, covCheckMatchGroup, covCheckGRHSs, + covCheckPatBind, covCheckMatches, covCheckGRHSs, isMatchContextPmChecked, - -- See Note [Type and Term Equality Propagation] - addTyCsDs, addCoreScrutTmCs, addHsScrutTmCs + -- See Note [Long-distance information] + addTyCs, addCoreScrutTmCs, addHsScrutTmCs ) where #include "HsVersions.h" @@ -37,7 +62,6 @@ import GHC.Tc.Utils.Zonk (shortCutLit) import GHC.Types.Id import GHC.Core.ConLike import GHC.Types.Name -import GHC.Tc.Instance.Family import GHC.Builtin.Types import GHC.Types.SrcLoc import GHC.Utils.Misc @@ -62,35 +86,135 @@ import GHC.Core.Type import GHC.HsToCore.Utils (isTrueLHsExpr) import GHC.Data.Maybe import qualified GHC.LanguageExtensions as LangExt -import GHC.Utils.Monad (concatMapM) +import GHC.Utils.Monad (concatMapM, mapMaybeM) import Control.Monad (when, forM_, zipWithM) import Data.List (elemIndex) import qualified Data.Semigroup as Semi -import Data.List.NonEmpty (NonEmpty(..)) +import Data.List.NonEmpty ( NonEmpty(..) ) +import qualified Data.List.NonEmpty as NE +import Data.Coerce -{- -This module checks pattern matches for: -\begin{enumerate} - \item Equations that are redundant - \item Equations with inaccessible right-hand-side - \item Exhaustiveness -\end{enumerate} +-- +-- * Exported entry points to the checker +-- -The algorithm is based on the paper: +-- | Check a pattern binding (let, where) for exhaustiveness. +covCheckPatBind :: DsMatchContext -> Id -> Pat GhcTc -> DsM () +-- See Note [covCheckPatBind only checks PatBindRhs] +covCheckPatBind ctxt@(DsMatchContext PatBindRhs loc) var p = do + missing <- getPmDeltas + pat_bind <- desugarPatBind loc var p + tracePm "covCheckPatBind {" (vcat [ppr ctxt, ppr var, ppr p, ppr pat_bind, ppr missing]) + result <- unCA (checkPatBind pat_bind) missing + tracePm "}: " (ppr (cr_uncov result)) + formatReportWarnings collectPatBind ctxt [var] result +covCheckPatBind _ _ _ = pure () - "GADTs Meet Their Match: - Pattern-matching Warnings That Account for GADTs, Guards, and Laziness" +-- | Exhaustive for guard matches, is used for guards in pattern bindings and +-- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. +covCheckGRHSs + :: HsMatchContext GhcRn -- ^ Match context, for warning messages + -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check + -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long + -- distance info +covCheckGRHSs hs_ctxt guards@(GRHSs _ grhss _) = do + let combined_loc = foldl1 combineSrcSpans (map getLoc grhss) + ctxt = DsMatchContext hs_ctxt combined_loc + matches <- desugarGRHSs combined_loc empty guards + missing <- getPmDeltas + tracePm "covCheckGRHSs" (hang (vcat [ppr ctxt + , text "Guards:"]) + 2 + (pprGRHSs hs_ctxt guards $$ ppr missing)) + result <- unCA (checkGRHSs matches) missing + tracePm "}: " (ppr (cr_uncov result)) + formatReportWarnings (collectGRHSs missing) ctxt [] result + +-- | Check a list of syntactic 'Match'es (part of case, functions, etc.), each +-- with a 'Pat' and one or more 'GRHSs': +-- +-- @ +-- f x y | x == y = 1 -- match on x and y with two guarded RHSs +-- | otherwise = 2 +-- f _ _ = 3 -- clause with a single, un-guarded RHS +-- @ +-- +-- Returns one non-empty 'Deltas' for 1.) each pattern of a 'Match' and 2.) +-- each of a 'Match'es 'GRHS' for Note [Long-distance information]. +-- +-- Special case: When there are /no matches/, then the functionassumes it +-- checks and @-XEmptyCase@ with only a single match variable. +-- See Note [Checking EmptyCase]. +covCheckMatches + :: DsMatchContext -- ^ Match context, for warnings messages + -> [Id] -- ^ Match variables, i.e. x and y above + -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches + -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per Match and + -- GRHS, for long distance info. +covCheckMatches ctxt vars matches = do + missing <- getPmDeltas + -- We have to force @missing@ before printing out the trace message, + -- otherwise we get interleaved output from the solver. This function + -- should be strict in @missing@ anyway! + !missing <- getPmNablas + tracePm "covCheckMatches {" $ + hang (vcat [ppr ctxt, ppr vars, text "Matches:"]) + 2 + (vcat (map ppr matches) $$ ppr missing) + case NE.nonEmpty matches of + Nothing -> do + -- This must be an -XEmptyCase. See Note [Checking EmptyCase] + let var = only vars + empty_case <- desugarEmptyCase var + result <- unCA (checkEmptyCase empty_case) missing + tracePm "}: " (ppr (cr_uncov result)) + [] <$ formatReportWarnings collectEmptyCase ctxt vars result + Just matches -> do + matches <- desugarMatches vars matches + result <- unCA (checkMatchGroup matches) missing + tracePm "}: " (ppr (cr_uncov result)) + NE.toList <$> formatReportWarnings (collectMatchGroup missing) ctxt vars result + +{- Note [covCheckPatBind only checks PatBindRhs] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + at covCheckPatBind@'s sole purpose is to check vanilla pattern bindings, like + at x :: Int; Just x = e@, which is in a @PatBindRhs@ context. +But its caller is also called for individual pattern guards in a @StmtCtxt at . +For example, both pattern guards in @f x y | True <- x, False <- y = ...@ will +go through this function. It makes no sense to do coverage checking there: + * Pattern guards may well fail. Fall-through is not an unrecoverable panic, + but rather behavior the programmer expects, so inexhaustivity should not be + reported. + * Redundancy is already reported for the whole GRHS via one of the other + exported coverage checking functions. Also reporting individual redundant + guards is... redundant. See #17646. +Note that we can't just omit checking of @StmtCtxt@ altogether (by adjusting +'isMatchContextPmChecked'), because that affects the other checking functions, +too. + +Note [Checking EmptyCase] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-XEmptyCase is useful for matching on empty data types like 'Void'. For example, +the following is a complete match: - https://www.microsoft.com/en-us/research/wp-content/uploads/2016/08/gadtpm-acm.pdf + f :: Void -> () + f x = case x of {} -%************************************************************************ -%* * - Pattern Match Check Types -%* * -%************************************************************************ +Really, -XEmptyCase is the only way to write a program that at the same time is +safe (@f _ = error "boom"@ is not because of ⊥), doesn't trigger a warning +(@f !_ = error "inaccessible" has inaccessible RHS) and doesn't turn an +exception into divergence (@f x = f x@). + +Semantically, unlike every other case expression, -XEmptyCase is strict in its +match var x, which rules out ⊥ as an inhabitant. So we add x /~ ⊥ to the +initial Delta and check if there are any values left to match on. -} +-- +-- * Guard language +-- + -- | A very simple language for pattern guards. Let bindings, bang patterns, -- and matching variables against flat constructor patterns. data PmGrd @@ -106,9 +230,9 @@ data PmGrd } -- | @PmBang x@ corresponds to a @seq x True@ guard. - -- If the extra SrcInfo is present, the bang guard came from a source - -- bang pattern, in which case we might want to report it as redundant, - -- see Note [Dead bang patterns]. + -- If the extra 'SrcInfo' is present, the bang guard came from a source + -- bang pattern, in which case we might want to report it as redundant. + -- See Note [Dead bang patterns]. | PmBang { pm_id :: !Id, pm_loc :: !(Maybe SrcInfo) @@ -144,24 +268,118 @@ instance Monoid Precision where mempty = Precise mappend = (Semi.<>) --- | Means by which we identify source location for later pretty-printing --- in a warning message. 'SDoc' for the equation to show, 'Located' for --- the location. +-- +-- * Guard tree language +-- + +-- | Means by which we identify a source construct for later pretty-printing in +-- a warning message. 'SDoc' for the equation to show, 'Located' for the +-- location. type SrcInfo = Located SDoc --- | A representation of the desugaring to 'PmGrd's of all clauses of a --- function definition/pattern match/etc. -data GrdTree - = Rhs !SrcInfo - | Guard !PmGrd !GrdTree - -- ^ @Guard grd t@ will try to match @grd@ and on success continue to match - -- @t at . Falls through if either match fails. Models left-to-right semantics - -- of pattern matching. - | Sequence ![GrdTree] - -- ^ @Sequence (t:ts)@ matches against @t@, and then matches all - -- fallen-through values against @Sequence ts at . Models top-to-bottom semantics - -- of pattern matching. - -- @Sequence []@ always fails; it is useful for Note [Checking EmptyCase]. +-- | A guard tree denoting 'MatchGroup'. +newtype GrdMatchGroup = GrdMatchGroup (NonEmpty GrdMatch) + +-- | A guard tree denoting 'Match'. +data GrdMatch = GrdMatch { gm_pats :: ![PmGrd], gm_grhss :: !(NonEmpty GrdGRHS) } + +-- | A guard tree denoting 'GRHS'. +data GrdGRHS = GrdGRHS { gg_grds :: ![PmGrd], gg_rhs :: !SrcInfo } + +-- | A guard tree denoting an -XEmptyCase. +newtype GrdEmptyCase = GrdEmptyCase { ge_var :: Id } + +-- | A guard tree denoting a pattern binding. +newtype GrdPatBind = + -- just reuse GrdGRHS and pretend its @SrcInfo@ is info on the /pattern/, + -- rather than on the pattern bindings. + GrdPatBind GrdGRHS + +-- | Redundancy sets, used to determine redundancy of RHSs and bang patterns +-- (later digested into a 'CIRB'). +data RedSets + = RedSets + { rs_cov :: !Deltas + -- ^ The /Covered/ set; the set of values reaching a particular program + -- point. + , rs_div :: !Deltas + -- ^ The /Diverging/ set; empty if no match can lead to divergence. + -- If it wasn't empty, we have to turn redundancy warnings into + -- inaccessibility warnings for any subclauses. + , rs_bangs :: !(OrdList (Deltas, SrcInfo)) + -- ^ If any of the 'Deltas' is empty, the corresponding 'SrcInfo' pin-points + -- a bang pattern in source that is redundant. See Note [Dead bang patterns]. + } + +emptyRedSets :: RedSets +-- Semigroup instance would be misleading! +emptyRedSets = RedSets mempty mempty mempty + +-- | An annotated tree denoting 'MatchGroup'. +newtype AnnMatchGroup = AnnMatchGroup (NonEmpty AnnMatch) + +-- | An annotated tree denoting 'Match'. +data AnnMatch = AnnMatch { am_red :: !RedSets, am_grhss :: !(NonEmpty AnnGRHS) } + +-- | An annotated tree denoting 'GRHS'. +data AnnGRHS = AnnGRHS { ag_red :: !RedSets, ag_rhs :: !SrcInfo } + +-- | An annotated tree denoting an -XEmptyCase. +data AnnEmptyCase = AnnEmptyCase + +-- | An annotated tree denoting a pattern binding. +newtype AnnPatBind = AnnPatBind AnnGRHS + +pprSrcInfo :: SrcInfo -> SDoc +pprSrcInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) +pprSrcInfo (L s _) = ppr s + +-- | Format LYG guards as @| True <- x, let x = 42, !z@ +pprLygGuards :: [PmGrd] -> SDoc +pprLygGuards [] = empty +pprLygGuards (g:gs) = fsep (char '|' <+> ppr g : map ((comma <+>) . ppr) gs) + +-- | Format a LYG sequence (e.g. 'Match'es of a 'MatchGroup' or 'GRHSs') as +-- @{ ; ...; }@ +pprLygSequence :: Outputable a => NonEmpty a -> SDoc +pprLygSequence (NE.toList -> as) = + braces (space <> fsep (punctuate semi (map ppr as)) <> space) + +instance Outputable GrdMatchGroup where + ppr (GrdMatchGroup matches) = pprLygSequence matches + +instance Outputable GrdMatch where + ppr (GrdMatch { gm_pats = grds, gm_grhss = grhss }) = + pprLygGuards grds <+> ppr grhss + +instance Outputable GrdGRHS where + ppr (GrdGRHS { gg_grds = grds, gg_rhs = rhs }) = + pprLygGuards grds <+> text "->" <+> pprSrcInfo rhs + +instance Outputable GrdPatBind where + ppr (GrdPatBind GrdGRHS { gg_grds = grds, gg_rhs = bind }) = + ppr bind <+> pprLygGuards grds <+> text "=" <+> text "..." + +instance Outputable GrdEmptyCase where + ppr (GrdEmptyCase { ge_var = var }) = + text " ppr var <> text ">" + +pprRedSets :: RedSets -> SDoc +-- It's useful to change this definition for different verbosity levels in +-- printf-debugging +pprRedSets RedSets { rs_cov = _cov, rs_div = _div, rs_bangs = _bangs } + = empty + +instance Outputable AnnMatchGroup where + ppr (AnnMatchGroup matches) = pprLygSequence matches + +instance Outputable AnnMatch where + ppr (AnnMatch { am_red = red, am_grhss = grhss }) = + pprRedSets red <+> ppr grhss + +instance Outputable AnnGRHS where + ppr (AnnGRHS { ag_red = red, ag_rhs = rhs }) = + pprRedSets red <+> text "->" <+> pprSrcInfo rhs {- Note [Dead bang patterns] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -178,7 +396,7 @@ that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs; see below. We can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable -where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is +where the PmBang appears in 'checkGrd'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. @@ -197,236 +415,9 @@ it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. -} --- | The digest of 'checkGrdTree', representing the annotated pattern-match --- tree. 'extractRedundancyInfo' can figure out redundant and proper --- inaccessible RHSs from this, as well as dead bangs. -data AnnotatedTree - = AccessibleRhs !Deltas !SrcInfo - -- ^ A RHS deemed accessible. The 'Deltas' is the (non-empty) set of covered - -- values. - | InaccessibleRhs !SrcInfo - -- ^ A RHS deemed inaccessible; it covers no value. - | MayDiverge !AnnotatedTree - -- ^ Asserts that the tree may force diverging values, so not all of its - -- clauses can be redundant. - | SequenceAnn !Deltas ![AnnotatedTree] - -- ^ @SequenceAnn inc ts@ mirrors @'Sequence' ts@ for preserving the - -- skeleton of a 'GrdTree's @ts at . It also carries the set of incoming values - -- @inc at . - | RedundantSrcBang !SrcInfo !AnnotatedTree - -- ^ For tracking redundant bangs. See Note [Dead bang patterns] - -pprSrcInfo :: SrcInfo -> SDoc -pprSrcInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) -pprSrcInfo (L s _) = ppr s - -instance Outputable GrdTree where - ppr (Rhs info) = text "->" <+> pprSrcInfo info - -- Format guards as "| True <- x, let x = 42, !z" - ppr g at Guard{} = fsep (prefix (map ppr grds)) <+> ppr t - where - (t, grds) = collect_grds g - collect_grds (Guard grd t) = (grd :) <$> collect_grds t - collect_grds t = (t, []) - prefix [] = [] - prefix (s:sdocs) = char '|' <+> s : map (comma <+>) sdocs - ppr (Sequence []) = text "" - ppr (Sequence ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) - -instance Outputable AnnotatedTree where - ppr (AccessibleRhs _delta info) = parens (ppr _delta) <+> pprSrcInfo info - ppr (InaccessibleRhs info) = text "inaccessible" <+> pprSrcInfo info - ppr (MayDiverge t) = text "div" <+> ppr t - ppr (SequenceAnn _ []) = text "" - ppr (SequenceAnn _ ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) - ppr (RedundantSrcBang l t) = text "redundant bang" <+> pprSrcInfo l <+> ppr t - --- | Lift 'addPmCts' over 'Deltas'. -addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas -addPmCtsDeltas deltas cts = liftDeltasM (\d -> addPmCts d cts) deltas - --- | 'addPmCtsDeltas' a single 'PmCt'. -addPmCtDeltas :: Deltas -> PmCt -> DsM Deltas -addPmCtDeltas deltas ct = addPmCtsDeltas deltas (unitBag ct) - --- | Test if any of the 'Delta's is inhabited. Currently this is pure, because --- we preserve the invariant that there are no uninhabited 'Delta's. But that --- could change in the future, for example by implementing this function in --- terms of @notNull <$> provideEvidence 1 ds at . -isInhabited :: Deltas -> DsM Bool -isInhabited (MkDeltas ds) = pure (not (null ds)) - --- | Pattern-match check result -data CheckResult - = CheckResult - { cr_clauses :: !AnnotatedTree - -- ^ Captures redundancy info for each clause in the original program. - -- (for -Woverlapping-patterns) - , cr_uncov :: !Deltas - -- ^ The set of uncovered values falling out at the bottom. - -- (for -Wincomplete-patterns) - , cr_approx :: !Precision - -- ^ A flag saying whether we ran into the 'maxPmCheckModels' limit for the - -- purpose of suggesting to crank it up in the warning message - } - -instance Outputable CheckResult where - ppr (CheckResult c unc pc) - = text "CheckResult" <+> ppr_precision pc <+> braces (fsep - [ field "clauses" c <> comma - , field "uncov" unc]) - where - ppr_precision Precise = empty - ppr_precision Approximate = text "(Approximate)" - field name value = text name <+> equals <+> ppr value - -{- -%************************************************************************ -%* * - Entry points to the checker: covCheckPatBind and covCheckMatchGroup -%* * -%************************************************************************ --} - --- | Check a pattern binding (let, where) for exhaustiveness. -covCheckPatBind :: DynFlags -> DsMatchContext -> Id -> Pat GhcTc -> DsM () -covCheckPatBind dflags ctxt@(DsMatchContext _ locn) var p = do - -- We only ever need to run this in a context where we need exhaustivity - -- warnings (so not in pattern guards or comprehensions, for example, because - -- they are perfectly fine to fail). - -- Omitting checking this flag emits redundancy warnings twice in obscure - -- cases like #17646. - -- Given the context in which this function is called, it will only ever do - -- something for - -- * PatBindRhs, -Wincomplete-uni-patterns: @let True = False@ - -- * PatBindGuards, -Wincomplete-patterns: @Just x | False = Just 42@ - missing <- getPmDeltas - tracePm "covCheckPatBind" (vcat [ppr ctxt, ppr var, ppr p, ppr missing]) - fam_insts <- dsGetFamInstEnvs - grd_tree <- mkGrdTreeRhs (L locn $ ppr p) <$> translatePat fam_insts var p - res <- checkGrdTree grd_tree missing - dsPmWarn dflags ctxt [var] res - --- | Exhaustive for guard matches, is used for guards in pattern bindings and --- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. -covCheckGRHSs - :: HsMatchContext GhcRn -- ^ Match context, for warning messages - -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check - -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long - -- distance info -covCheckGRHSs hs_ctx guards@(GRHSs _ grhss _) = do - let combinedLoc = foldl1 combineSrcSpans (map getLoc grhss) - dsMatchContext = DsMatchContext hs_ctx combinedLoc - match = L combinedLoc $ - Match { m_ext = noExtField - , m_ctxt = hs_ctx - , m_pats = [] - , m_grhss = guards } - [(_, deltas)] <- covCheckMatchGroup dsMatchContext [] [match] - pure deltas - --- | Check a list of syntactic /match/es (part of case, functions, etc.), each --- with a /pat/ and one or more /grhss/: -- --- @ --- f x y | x == y = 1 -- match on x and y with two guarded RHSs --- | otherwise = 2 --- f _ _ = 3 -- clause with a single, un-guarded RHS --- @ +-- * Desugaring source syntax to guard trees -- --- Returns one 'Deltas' for each GRHS, representing its covered values, or the --- incoming uncovered 'Deltas' (from 'getPmDeltas') if the GRHS is inaccessible. --- Since there is at least one /grhs/ per /match/, the list of 'Deltas' is at --- least as long as the list of matches. -covCheckMatchGroup - :: DsMatchContext -- ^ Match context, for warnings messages - -> [Id] -- ^ Match variables, i.e. x and y above - -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches - -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per RHS, for long - -- distance info. -covCheckMatchGroup ctxt vars matches = do - tracePm "covCheckMatchGroup" (hang (vcat [ppr ctxt - , ppr vars - , text "Matches:"]) - 2 - (vcat (map ppr matches))) - - init_deltas <- getPmDeltas - missing <- case matches of - -- This must be an -XEmptyCase. See Note [Checking EmptyCase] - [] | [var] <- vars -> addPmCtDeltas init_deltas (PmNotBotCt var) - _ -> pure init_deltas - fam_insts <- dsGetFamInstEnvs - grd_tree <- translateMatches fam_insts vars matches - res <- checkGrdTree grd_tree missing - - dflags <- getDynFlags - dsPmWarn dflags ctxt vars res - - return (extractRhsDeltas (cr_clauses res)) - --- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree' for a match --- group. --- For 'AccessibleRhs's, this is stored in the tree node, whereas --- 'InaccessibleRhs's fall back to the supplied original 'Deltas'. --- See @Note [Recovering from unsatisfiable pattern-matching constraints]@. -extractRhsDeltas :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] -extractRhsDeltas = go_matches - where - go_matches :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] - go_matches (SequenceAnn def ts) = map (go_match def) ts -- -XEmptyCase handled here! - go_matches t = pprPanic "extractRhsDeltas.go_matches" (text "Matches must start with SequenceAnn. But was" $$ ppr t) - - go_match :: Deltas -> AnnotatedTree -> (Deltas, NonEmpty Deltas) - -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ - -- is non-empty! - go_match def (SequenceAnn pat ts) = (pat, foldMap1 (text "go_match: empty SequenceAnn") (go_grhss def) ts) - go_match def (MayDiverge t) = go_match def t - go_match def (RedundantSrcBang _ t) = go_match def t - -- Even if there's only a single GRHS, we wrap it in a SequenceAnn for the - -- Deltas covered by the pattern. So the remaining cases are impossible! - go_match _ t = pprPanic "extractRhsDeltas.go_match" (text "Single GRHS must be wrapped in SequenceAnn. But got " $$ ppr t) - - go_grhss :: Deltas -> AnnotatedTree -> NonEmpty Deltas - -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ - -- is non-empty! - go_grhss def (SequenceAnn _ ts) = foldMap1 (text "go_grhss: empty SequenceAnn") (go_grhss def) ts - go_grhss def (MayDiverge t) = go_grhss def t - go_grhss def (RedundantSrcBang _ t) = go_grhss def t - go_grhss _ (AccessibleRhs deltas _) = deltas :| [] - go_grhss def (InaccessibleRhs _) = def :| [] - - foldMap1 msg _ [] = pprPanic "extractRhsDeltas.foldMap1" msg - foldMap1 _ f (x:xs) = foldl' (\acc x -> acc Semi.<> f x) (f x) xs - -{- Note [Checking EmptyCase] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --XEmptyCase is useful for matching on empty data types like 'Void'. For example, -the following is a complete match: - - f :: Void -> () - f x = case x of {} - -Really, -XEmptyCase is the only way to write a program that at the same time is -safe (@f _ = error "boom"@ is not because of ⊥), doesn't trigger a warning -(@f !_ = error "inaccessible" has inaccessible RHS) and doesn't turn an -exception into divergence (@f x = f x@). - -Semantically, unlike every other case expression, -XEmptyCase is strict in its -match var x, which rules out ⊥ as an inhabitant. So we add x /~ ⊥ to the -initial Delta and check if there are any values left to match on. --} - -{- -%************************************************************************ -%* * - Transform source syntax to *our* syntax -%* * -%************************************************************************ --} - --- ----------------------------------------------------------------------- --- * Utilities -- | Smart constructor that eliminates trivial lets mkPmLetVar :: Id -> Id -> GrdVec @@ -459,7 +450,7 @@ mkListGrds a ((x, head_grds):xs) = do -- | Create a 'GrdVec' refining a match variable to a 'PmLit'. mkPmLitGrds :: Id -> PmLit -> DsM GrdVec mkPmLitGrds x (PmLit _ (PmLitString s)) = do - -- We translate String literals to list literals for better overlap reasoning. + -- We desugar String literals to list literals for better overlap reasoning. -- It's a little unfortunate we do this here rather than in -- 'GHC.HsToCore.PmCheck.Oracle.trySolve' and -- 'GHC.HsToCore.PmCheck.Oracle.addRefutableAltCon', but it's so much simpler @@ -477,37 +468,34 @@ mkPmLitGrds x lit = do , pm_con_args = [] } pure [grd] --- ----------------------------------------------------------------------- --- * Transform (Pat Id) into GrdVec - --- | @translatePat _ x pat@ transforms @pat@ into a 'GrdVec', where +-- | @desugarPat _ x pat@ transforms @pat@ into a 'GrdVec', where -- the variable representing the match is @x at . -translatePat :: FamInstEnvs -> Id -> Pat GhcTc -> DsM GrdVec -translatePat fam_insts x pat = case pat of +desugarPat :: Id -> Pat GhcTc -> DsM GrdVec +desugarPat x pat = case pat of WildPat _ty -> pure [] VarPat _ y -> pure (mkPmLetVar (unLoc y) x) - ParPat _ p -> translateLPat fam_insts x p + ParPat _ p -> desugarLPat x p LazyPat _ _ -> pure [] -- like a wildcard BangPat _ p@(L l p') -> -- Add the bang in front of the list, because it will happen before any -- nested stuff. - (PmBang x pm_loc :) <$> translateLPat fam_insts x p - where pm_loc = Just (L l (ppr p')) + (PmBang x pm_loc :) <$> desugarLPat x p + where pm_loc = Just (L l (ppr p')) - -- (x at pat) ==> Translate pat with x as match var and handle impedance + -- (x at pat) ==> Desugar pat with x as match var and handle impedance -- mismatch with incoming match var - AsPat _ (L _ y) p -> (mkPmLetVar y x ++) <$> translateLPat fam_insts y p + AsPat _ (L _ y) p -> (mkPmLetVar y x ++) <$> desugarLPat y p - SigPat _ p _ty -> translateLPat fam_insts x p + SigPat _ p _ty -> desugarLPat x p - -- See Note [Translate CoPats] + -- See Note [Desugar CoPats] -- Generally the translation is -- pat |> co ===> let y = x |> co, pat <- y where y is a match var of pat XPat (CoPat wrapper p _ty) - | isIdHsWrapper wrapper -> translatePat fam_insts x p - | WpCast co <- wrapper, isReflexiveCo co -> translatePat fam_insts x p + | isIdHsWrapper wrapper -> desugarPat x p + | WpCast co <- wrapper, isReflexiveCo co -> desugarPat x p | otherwise -> do - (y, grds) <- translatePatV fam_insts p + (y, grds) <- desugarPatV p wrap_rhs_y <- dsHsWrapper wrapper pure (PmLet y (wrap_rhs_y (Var x)) : grds) @@ -522,13 +510,13 @@ translatePat fam_insts x pat = case pat of -- (fun -> pat) ===> let y = fun x, pat <- y where y is a match var of pat ViewPat _arg_ty lexpr pat -> do - (y, grds) <- translateLPatV fam_insts pat + (y, grds) <- desugarLPatV pat fun <- dsLExpr lexpr pure $ PmLet y (App fun (Var x)) : grds -- list ListPat (ListPatTc _elem_ty Nothing) ps -> - translateListPat fam_insts x ps + desugarListPat x ps -- overloaded list ListPat (ListPatTc elem_ty (Just (pat_ty, to_list))) pats -> do @@ -536,11 +524,11 @@ translatePat fam_insts x pat = case pat of case splitListTyConApp_maybe pat_ty of Just _e_ty | not (xopt LangExt.RebindableSyntax dflags) - -- Just translate it as a regular ListPat - -> translateListPat fam_insts x pats + -- Just desugar it as a regular ListPat + -> desugarListPat x pats _ -> do y <- mkPmId (mkListTy elem_ty) - grds <- translateListPat fam_insts y pats + grds <- desugarListPat y pats rhs_y <- dsSyntaxExpr to_list [Var x] pure $ PmLet y rhs_y : grds @@ -566,7 +554,7 @@ translatePat fam_insts x pat = case pat of , cpt_dicts = dicts } } -> do - translateConPatOut fam_insts x con arg_tys ex_tvs dicts ps + desugarConPatOut x con arg_tys ex_tvs dicts ps NPat ty (L _ olit) mb_neg _ -> do -- See Note [Literal short cut] in "GHC.HsToCore.Match.Literal" @@ -595,46 +583,44 @@ translatePat fam_insts x pat = case pat of mkPmLitGrds x lit TuplePat _tys pats boxity -> do - (vars, grdss) <- mapAndUnzipM (translateLPatV fam_insts) pats + (vars, grdss) <- mapAndUnzipM desugarLPatV pats let tuple_con = tupleDataCon boxity (length vars) pure $ vanillaConGrd x tuple_con vars : concat grdss SumPat _ty p alt arity -> do - (y, grds) <- translateLPatV fam_insts p + (y, grds) <- desugarLPatV p let sum_con = sumDataCon alt arity -- See Note [Unboxed tuple RuntimeRep vars] in GHC.Core.TyCon pure $ vanillaConGrd x sum_con [y] : grds - -- -------------------------------------------------------------------------- - -- Not supposed to happen - SplicePat {} -> panic "Check.translatePat: SplicePat" + SplicePat {} -> panic "Check.desugarPat: SplicePat" --- | 'translatePat', but also select and return a new match var. -translatePatV :: FamInstEnvs -> Pat GhcTc -> DsM (Id, GrdVec) -translatePatV fam_insts pat = do +-- | 'desugarPat', but also select and return a new match var. +desugarPatV :: Pat GhcTc -> DsM (Id, GrdVec) +desugarPatV pat = do x <- selectMatchVar Many pat - grds <- translatePat fam_insts x pat + grds <- desugarPat x pat pure (x, grds) -translateLPat :: FamInstEnvs -> Id -> LPat GhcTc -> DsM GrdVec -translateLPat fam_insts x = translatePat fam_insts x . unLoc +desugarLPat :: Id -> LPat GhcTc -> DsM GrdVec +desugarLPat x = desugarPat x . unLoc --- | 'translateLPat', but also select and return a new match var. -translateLPatV :: FamInstEnvs -> LPat GhcTc -> DsM (Id, GrdVec) -translateLPatV fam_insts = translatePatV fam_insts . unLoc +-- | 'desugarLPat', but also select and return a new match var. +desugarLPatV :: LPat GhcTc -> DsM (Id, GrdVec) +desugarLPatV = desugarPatV . unLoc --- | @translateListPat _ x [p1, ..., pn]@ is basically --- @translateConPatOut _ x $(mkListConPatOuts [p1, ..., pn]>@ without ever +-- | @desugarListPat _ x [p1, ..., pn]@ is basically +-- @desugarConPatOut _ x $(mkListConPatOuts [p1, ..., pn]>@ without ever -- constructing the 'ConPatOut's. -translateListPat :: FamInstEnvs -> Id -> [LPat GhcTc] -> DsM GrdVec -translateListPat fam_insts x pats = do - vars_and_grdss <- traverse (translateLPatV fam_insts) pats +desugarListPat :: Id -> [LPat GhcTc] -> DsM GrdVec +desugarListPat x pats = do + vars_and_grdss <- traverse desugarLPatV pats mkListGrds x vars_and_grdss --- | Translate a constructor pattern -translateConPatOut :: FamInstEnvs -> Id -> ConLike -> [Type] -> [TyVar] +-- | Desugar a constructor pattern +desugarConPatOut :: Id -> ConLike -> [Type] -> [TyVar] -> [EvVar] -> HsConPatDetails GhcTc -> DsM GrdVec -translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case +desugarConPatOut x con univ_tys ex_tvs dicts = \case PrefixCon ps -> go_field_pats (zip [0..] ps) InfixCon p1 p2 -> go_field_pats (zip [0..] [p1,p2]) RecCon (HsRecFields fs _) -> go_field_pats (rec_field_ps fs) @@ -648,7 +634,7 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case where tagged_pat f = (lbl_to_index (getName (hsRecFieldId f)), hsRecFieldArg f) -- Unfortunately the label info is empty when the DataCon wasn't defined - -- with record field labels, hence we translate to field index. + -- with record field labels, hence we desugar to field index. orig_lbls = map flSelector $ conLikeFieldLabels con lbl_to_index lbl = expectJust "lbl_to_index" $ elemIndex lbl orig_lbls @@ -659,10 +645,10 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- the first field of @tagged_pats at . -- See Note [Field match order for RecCon] - -- Translate the mentioned field patterns. We're doing this first to get + -- Desugar the mentioned field patterns. We're doing this first to get -- the Ids for pm_con_args. let trans_pat (n, pat) = do - (var, pvec) <- translateLPatV fam_insts pat + (var, pvec) <- desugarLPatV pat pure ((n, var), pvec) (tagged_vars, arg_grdss) <- mapAndUnzipM trans_pat tagged_pats @@ -688,77 +674,81 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- 1. 2. 3. pure (con_grd : bang_grds ++ arg_grds) --- | Translate a the 'Match'es of a 'MatchGroup' -translateMatches :: FamInstEnvs -> [Id] -> [LMatch GhcTc (LHsExpr GhcTc)] - -> DsM GrdTree -translateMatches fam_insts vars matches = - -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. - -- 'extractRhsDeltas' needs this to recover 'MatchGroup' structure. - Sequence <$> traverse (translateMatch fam_insts vars) matches - --- Translate a single match -translateMatch :: FamInstEnvs -> [Id] -> LMatch GhcTc (LHsExpr GhcTc) - -> DsM GrdTree -translateMatch fam_insts vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do - pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats - grhss' <- translateGRHSs fam_insts match_loc (sep (map ppr pats)) grhss - -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss']) - return (foldr Guard grhss' pats') - -mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree -mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) - -translateGRHSs :: FamInstEnvs -> SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateGRHSs fam_insts match_loc pp_pats grhss = - -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. - -- 'extractRhsDeltas' needs this to recover 'GRHSs' structure. - Sequence <$> traverse (translateLGRHS fam_insts match_loc pp_pats) (grhssGRHSs grhss) - --- | Translate a guarded right-hand side to a single 'GrdTree' -translateLGRHS :: FamInstEnvs -> SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateLGRHS fam_insts match_loc pp_pats (L _loc (GRHS _ gs _)) = - -- _loc points to the match separator (ie =, ->) that comes after the guards.. - mkGrdTreeRhs loc_sdoc <$> concatMapM (translateGuard fam_insts . unLoc) gs - where - loc_sdoc - -- pp_pats is the space-separated pattern of the current Match this - -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . - | null gs = L match_loc pp_pats - | otherwise = L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) - L grd_loc _ = head gs - --- | Translate a guard statement to a 'GrdVec' -translateGuard :: FamInstEnvs -> GuardStmt GhcTc -> DsM GrdVec -translateGuard fam_insts guard = case guard of - BodyStmt _ e _ _ -> translateBoolGuard e - LetStmt _ binds -> translateLet (unLoc binds) - BindStmt _ p e -> translateBind fam_insts p e - LastStmt {} -> panic "translateGuard LastStmt" - ParStmt {} -> panic "translateGuard ParStmt" - TransStmt {} -> panic "translateGuard TransStmt" - RecStmt {} -> panic "translateGuard RecStmt" - ApplicativeStmt {} -> panic "translateGuard ApplicativeLastStmt" - --- | Translate let-bindings -translateLet :: HsLocalBinds GhcTc -> DsM GrdVec -translateLet _binds = return [] - --- | Translate a pattern guard +desugarPatBind :: SrcSpan -> Id -> Pat GhcTc -> DsM GrdPatBind +-- See 'GrdPatBind' for how this simply repurposes GrdGRHS. +desugarPatBind loc var pat = + GrdPatBind . flip GrdGRHS (L loc (ppr pat)) <$> desugarPat var pat + +desugarEmptyCase :: Id -> DsM GrdEmptyCase +desugarEmptyCase var = pure GrdEmptyCase { ge_var = var } + +-- | Desugar the non-empty 'Match'es of a 'MatchGroup'. +desugarMatches :: [Id] -> NonEmpty (LMatch GhcTc (LHsExpr GhcTc)) + -> DsM GrdMatchGroup +desugarMatches vars matches = + GrdMatchGroup <$> traverse (desugarMatch vars) matches + +-- Desugar a single match +desugarMatch :: [Id] -> LMatch GhcTc (LHsExpr GhcTc) -> DsM GrdMatch +desugarMatch vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do + pats' <- concat <$> zipWithM desugarLPat vars pats + grhss' <- desugarGRHSs match_loc (sep (map ppr pats)) grhss + -- tracePm "desugarMatch" (vcat [ppr pats, ppr pats', ppr grhss']) + return GrdMatch { gm_pats = pats', gm_grhss = grhss' } + +desugarGRHSs :: SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM (NonEmpty GrdGRHS) +desugarGRHSs match_loc pp_pats grhss + = traverse (desugarLGRHS match_loc pp_pats) + . expectJust "desugarGRHSs" + . NE.nonEmpty + $ grhssGRHSs grhss + +-- | Desugar a guarded right-hand side to a single 'GrdTree' +desugarLGRHS :: SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdGRHS +desugarLGRHS match_loc pp_pats (L _loc (GRHS _ gs _)) = do + -- _loc points to the match separator (ie =, ->) that comes after the guards. + -- Hence we have to pass in the match_loc, which we use in case that the RHS + -- is unguarded. + -- pp_pats is the space-separated pattern of the current Match this + -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . + let rhs_info = case gs of + [] -> L match_loc pp_pats + (L grd_loc _):_ -> L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) + grds <- concatMapM (desugarGuard . unLoc) gs + pure GrdGRHS { gg_grds = grds, gg_rhs = rhs_info } + +-- | Desugar a guard statement to a 'GrdVec' +desugarGuard :: GuardStmt GhcTc -> DsM GrdVec +desugarGuard guard = case guard of + BodyStmt _ e _ _ -> desugarBoolGuard e + LetStmt _ binds -> desugarLet (unLoc binds) + BindStmt _ p e -> desugarBind p e + LastStmt {} -> panic "desugarGuard LastStmt" + ParStmt {} -> panic "desugarGuard ParStmt" + TransStmt {} -> panic "desugarGuard TransStmt" + RecStmt {} -> panic "desugarGuard RecStmt" + ApplicativeStmt {} -> panic "desugarGuard ApplicativeLastStmt" + +-- | Desugar let-bindings +desugarLet :: HsLocalBinds GhcTc -> DsM GrdVec +desugarLet _binds = return [] + +-- | Desugar a pattern guard -- @pat <- e ==> let x = e; @ -translateBind :: FamInstEnvs -> LPat GhcTc -> LHsExpr GhcTc -> DsM GrdVec -translateBind fam_insts p e = dsLExpr e >>= \case +desugarBind :: LPat GhcTc -> LHsExpr GhcTc -> DsM GrdVec +desugarBind p e = dsLExpr e >>= \case Var y | Nothing <- isDataConId_maybe y -- RHS is a variable, so that will allow us to omit the let - -> translateLPat fam_insts y p + -> desugarLPat y p rhs -> do - (x, grds) <- translateLPatV fam_insts p + (x, grds) <- desugarLPatV p pure (PmLet x rhs : grds) --- | Translate a boolean guard +-- | Desugar a boolean guard -- @e ==> let x = e; True <- x@ -translateBoolGuard :: LHsExpr GhcTc -> DsM GrdVec -translateBoolGuard e +desugarBoolGuard :: LHsExpr GhcTc -> DsM GrdVec +desugarBoolGuard e | isJust (isTrueLHsExpr e) = return [] -- The formal thing to do would be to generate (True <- True) -- but it is trivial to solve so instead we give back an empty @@ -803,7 +793,7 @@ for a pattern match appear matter. Consider a situation similar to T5117: f (0:_) = () f (0:[]) = () -The latter clause is clearly redundant. Yet if we translate the second clause as +The latter clause is clearly redundant. Yet if we desugar the second clause as [x:xs' <- xs, [] <- xs', 0 <- x] @@ -815,52 +805,11 @@ translation would have been And we have to take in the guards on list cells into @mkListGrds at . -Note [Countering exponential blowup] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Precise pattern match exhaustiveness checking is necessarily exponential in -the size of some input programs. We implement a counter-measure in the form of -the -fmax-pmcheck-models flag, limiting the number of Deltas we check against -each pattern by a constant. - -How do we do that? Consider - - f True True = () - f True True = () - -And imagine we set our limit to 1 for the sake of the example. The first clause -will be checked against the initial Delta, {}. Doing so will produce an -Uncovered set of size 2, containing the models {x/~True} and {x~True,y/~True}. -Also we find the first clause to cover the model {x~True,y~True}. - -But the Uncovered set we get out of the match is too huge! We somehow have to -ensure not to make things worse as they are already, so we continue checking -with a singleton Uncovered set of the initial Delta {}. Why is this -sound (wrt. notion of the GADTs Meet their Match paper)? Well, it basically -amounts to forgetting that we matched against the first clause. The values -represented by {} are a superset of those represented by its two refinements -{x/~True} and {x~True,y/~True}. - -This forgetfulness becomes very apparent in the example above: By continuing -with {} we don't detect the second clause as redundant, as it again covers the -same non-empty subset of {}. So we don't flag everything as redundant anymore, -but still will never flag something as redundant that isn't. - -For exhaustivity, the converse applies: We will report @f@ as non-exhaustive -and report @f _ _@ as missing, which is a superset of the actual missing -matches. But soundness means we will never fail to report a missing match. - -This mechanism is implemented in 'throttle'. - -Guards are an extreme example in this regard, with #11195 being a particularly -dreadful example: Since their RHS are often pretty much unique, we split on a -variable (the one representing the RHS) that doesn't occur anywhere else in the -program, so we don't actually get useful information out of that split! - -Note [Translate CoPats] +Note [Desugar CoPats] ~~~~~~~~~~~~~~~~~~~~~~~ -The pattern match checker did not know how to handle coerced patterns `CoPat` -efficiently, which gave rise to #11276. The original approach translated -`CoPat`s: +The pattern match checker did not know how to handle coerced patterns +`CoPat` efficiently, which gave rise to #11276. The original approach +desugared `CoPat`s: pat |> co ===> x (pat <- (x |> co)) @@ -875,108 +824,92 @@ a lot of false warnings. But we can check whether the coercion is a hole or if it is just refl, in which case we can drop it. - -%************************************************************************ -%* * - Utilities for Pattern Match Checking -%* * -%************************************************************************ -} --- ---------------------------------------------------------------------------- --- * Basic utilities - -{- -Note [Extensions to GADTs Meet Their Match] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The GADTs Meet Their Match paper presents the formalism that GHC's coverage -checker adheres to. Since the paper's publication, there have been some -additional features added to the coverage checker which are not described in -the paper. This Note serves as a reference for these new features. - -* Value abstractions are severely simplified to the point where they are just - variables. The information about the shape of a variable is encoded in - the oracle state 'Delta' instead. -* Handling of uninhabited fields like `!Void`. - See Note [Strict argument type constraints] in GHC.HsToCore.PmCheck.Oracle. -* Efficient handling of literal splitting, large enumerations and accurate - redundancy warnings for `COMPLETE` groups through the oracle. - -Note [Filtering out non-matching COMPLETE sets] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Currently, conlikes in a COMPLETE set are simply grouped by the -type constructor heading the return type. This is nice and simple, but it does -mean that there are scenarios when a COMPLETE set might be incompatible with -the type of a scrutinee. For instance, consider (from #14135): - - data Foo a = Foo1 a | Foo2 a - - pattern MyFoo2 :: Int -> Foo Int - pattern MyFoo2 i = Foo2 i - - {-# COMPLETE Foo1, MyFoo2 #-} - - f :: Foo a -> a - f (Foo1 x) = x - -`f` has an incomplete pattern-match, so when choosing which constructors to -report as unmatched in a warning, GHC must choose between the original set of -data constructors {Foo1, Foo2} and the COMPLETE set {Foo1, MyFoo2}. But observe -that GHC shouldn't even consider the COMPLETE set as a possibility: the return -type of MyFoo2, Foo Int, does not match the type of the scrutinee, Foo a, since -there's no substitution `s` such that s(Foo Int) = Foo a. - -To ensure that GHC doesn't pick this COMPLETE set, it checks each pattern -synonym constructor's return type matches the type of the scrutinee, and if one -doesn't, then we remove the whole COMPLETE set from consideration. - -One might wonder why GHC only checks /pattern synonym/ constructors, and not -/data/ constructors as well. The reason is because that the type of a -GADT constructor very well may not match the type of a scrutinee, and that's -OK. Consider this example (from #14059): - - data SBool (z :: Bool) where - SFalse :: SBool False - STrue :: SBool True - - pattern STooGoodToBeTrue :: forall (z :: Bool). () - => z ~ True - => SBool z - pattern STooGoodToBeTrue = STrue - {-# COMPLETE SFalse, STooGoodToBeTrue #-} - - wobble :: SBool z -> Bool - wobble STooGoodToBeTrue = True - -In the incomplete pattern match for `wobble`, we /do/ want to warn that SFalse -should be matched against, even though its type, SBool False, does not match -the scrutinee type, SBool z. - -SG: Another angle at this is that the implied constraints when we instantiate -universal type variables in the return type of a GADT will lead to *provided* -thetas, whereas when we instantiate the return type of a pattern synonym that -corresponds to a *required* theta. See Note [Pattern synonym result type] in -PatSyn. Note how isValidCompleteMatches will successfully filter out - - pattern Just42 :: Maybe Int - pattern Just42 = Just 42 - -But fail to filter out the equivalent - - pattern Just'42 :: (a ~ Int) => Maybe a - pattern Just'42 = Just 42 - -Which seems fine as far as tcMatchTy is concerned, but it raises a few eye -brows. --} +-- +-- * Coverage checking guard trees into annotated trees +-- -{- -%************************************************************************ -%* * - Heart of the algorithm: checkGrdTree -%* * -%************************************************************************ --} +-- | Pattern-match coverage check result +data CheckResult a + = CheckResult + { cr_ret :: !a + -- ^ A hole for redundancy info and covered sets. + , cr_uncov :: !Deltas + -- ^ The set of uncovered values falling out at the bottom. + -- (for -Wincomplete-patterns, but also important state for the algorithm) + , cr_approx :: !Precision + -- ^ A flag saying whether we ran into the 'maxPmCheckModels' limit for the + -- purpose of suggesting to crank it up in the warning message. Writer state. + } deriving Functor + +instance Outputable a => Outputable (CheckResult a) where + ppr (CheckResult c unc pc) + = text "CheckResult" <+> ppr_precision pc <+> braces (fsep + [ field "ret" c <> comma + , field "uncov" unc]) + where + ppr_precision Precise = empty + ppr_precision Approximate = text "(Approximate)" + field name value = text name <+> equals <+> ppr value + +-- | Lift 'addPmCts' over 'Deltas'. +addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas +addPmCtsDeltas deltas cts = liftDeltasM (\d -> addPmCts d cts) deltas + +-- | 'addPmCtsDeltas' for a single 'PmCt'. +addPmCtDeltas :: Deltas -> PmCt -> DsM Deltas +addPmCtDeltas deltas ct = addPmCtsDeltas deltas (unitBag ct) + +-- | Test if any of the 'Delta's is inhabited. Currently this is pure, because +-- we preserve the invariant that there are no uninhabited 'Delta's. But that +-- could change in the future, for example by implementing this function in +-- terms of @notNull <$> provideEvidence 1 ds at . +isInhabited :: Deltas -> DsM Bool +isInhabited (MkDeltas ds) = pure (not (null ds)) + +-- | Coverage checking action. Can be composed 'leftToRight' or 'topToBottom'. +newtype CheckAction a = CA { unCA :: Deltas -> DsM (CheckResult a) } + deriving Functor + +-- | Composes 'CheckAction's top-to-bottom: +-- If a value falls through the resulting action, then it must fall through the +-- first action and then through the second action. +-- If a value matches the resulting action, then it either matches the +-- first action or matches the second action. +-- Basically the semantics of the LYG branching construct. +topToBottom :: (top -> bot -> ret) + -> CheckAction top + -> CheckAction bot + -> CheckAction ret +topToBottom f (CA top) (CA bot) = CA $ \inc -> do + t <- top inc + b <- bot (cr_uncov t) + pure CheckResult { cr_ret = f (cr_ret t) (cr_ret b) + , cr_uncov = cr_uncov b + , cr_approx = cr_approx t Semi.<> cr_approx b } + + +-- | Composes 'CheckAction's left-to-right: +-- If a value falls through the resulting action, then it either falls through the +-- first action or through the second action. +-- If a value matches the resulting action, then it must match the first action +-- and then match the second action. +-- Basically the semantics of the LYG guard construct. +leftToRight :: (RedSets -> right -> ret) + -> CheckAction RedSets + -> CheckAction right + -> CheckAction ret +leftToRight f (CA left) (CA right) = CA $ \inc -> do + l <- left inc + r <- right (rs_cov (cr_ret l)) + limit <- maxPmCheckModels <$> getDynFlags + let uncov = cr_uncov l Semi.<> cr_uncov r + -- See Note [Countering exponential blowup] + let (prec', uncov') = throttle limit inc uncov + pure CheckResult { cr_ret = f (cr_ret l) (cr_ret r) + , cr_uncov = uncov' + , cr_approx = prec' Semi.<> cr_approx l Semi.<> cr_approx r } -- | @throttle limit old new@ returns @old@ if the number of 'Delta's in @new@ -- is exceeding the given @limit@ and the @old@ number of 'Delta's. @@ -994,237 +927,241 @@ conMatchForces (PmAltConLike (RealDataCon dc)) | isNewTyCon (dataConTyCon dc) = False conMatchForces _ = True --- | Makes sure that we only wrap a single 'MayDiverge' around an --- 'AnnotatedTree', purely for esthetic reasons. -mayDiverge :: AnnotatedTree -> AnnotatedTree -mayDiverge a@(MayDiverge _) = a -mayDiverge a = MayDiverge a - --- | Computes two things: --- --- * The set of uncovered values not matched by any of the clauses of the --- 'GrdTree'. Note that 'PmCon' guards are the only way in which values --- fall through from one 'Many' branch to the next. --- * An 'AnnotatedTree' that contains divergence and inaccessibility info --- for all clauses. Will be fed to 'extractRedundancyInfo' for --- presenting redundant and proper innaccessible RHSs, as well as dead --- bangs to the user. -checkGrdTree' :: GrdTree -> Deltas -> DsM CheckResult --- RHS: Check that it covers something and wrap Inaccessible if not -checkGrdTree' (Rhs sdoc) deltas = do - is_covered <- isInhabited deltas - let clauses - | is_covered = AccessibleRhs deltas sdoc - | otherwise = InaccessibleRhs sdoc - pure CheckResult - { cr_clauses = clauses - , cr_uncov = MkDeltas emptyBag - , cr_approx = Precise } --- let x = e: Refine with x ~ e -checkGrdTree' (Guard (PmLet x e) tree) deltas = do - deltas' <- addPmCtDeltas deltas (PmCoreCt x e) - checkGrdTree' tree deltas' --- Bang x: Diverge on x ~ ⊥, refine with x /~ ⊥ -checkGrdTree' (Guard (PmBang x src_bang_info) tree) deltas = do - has_diverged <- addPmCtDeltas deltas (PmBotCt x) >>= isInhabited - deltas' <- addPmCtDeltas deltas (PmNotBotCt x) - res <- checkGrdTree' tree deltas' - let clauses - | not has_diverged - , Just info <- src_bang_info - = RedundantSrcBang info (cr_clauses res) - | has_diverged - = mayDiverge (cr_clauses res) - | otherwise -- won't diverge and it wasn't a source bang - = cr_clauses res - - pure res{ cr_clauses = clauses } - --- Con: Diverge on x ~ ⊥, fall through on x /~ K and refine with x ~ K ys --- and type info -checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do - has_diverged <- - if conMatchForces con - then addPmCtDeltas deltas (PmBotCt x) >>= isInhabited - else pure False - unc_this <- addPmCtDeltas deltas (PmNotConCt x con) - deltas' <- addPmCtsDeltas deltas $ - listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args - -- tracePm "checkGrdTree:Con" (ppr deltas $$ ppr x $$ ppr con $$ ppr dicts $$ ppr deltas') - CheckResult tree' unc_inner prec <- checkGrdTree' tree deltas' - limit <- maxPmCheckModels <$> getDynFlags - let (prec', unc') = throttle limit deltas (unc_this Semi.<> unc_inner) - pure CheckResult - { cr_clauses = applyWhen has_diverged mayDiverge tree' - , cr_uncov = unc' - , cr_approx = prec Semi.<> prec' } --- Sequence: Thread residual uncovered sets from equation to equation -checkGrdTree' (Sequence ts) init_unc = go [] init_unc Precise ts +-- First the functions that correspond to checking LYG primitives: + +checkSequence :: (grdtree -> CheckAction anntree) -> NonEmpty grdtree -> CheckAction (NonEmpty anntree) +-- The implementation is pretty similar to +-- @traverse1 :: Apply f => (a -> f b) -> NonEmpty a -> f (NonEmpty b)@ +checkSequence act (t:|[]) = (:|[]) <$> act t +checkSequence act (t1:|(t2:ts)) = + topToBottom (NE.<|) (act t1) (checkSequence act (t2:|ts)) + +checkGrd :: PmGrd -> CheckAction RedSets +checkGrd grd = CA $ \inc -> case grd of + -- let x = e: Refine with x ~ e + PmLet x e -> do + matched <- addPmCtDeltas inc (PmCoreCt x e) + pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched } + , cr_uncov = mempty + , cr_approx = Precise } + -- Bang x _: Diverge on x ~ ⊥, refine with x /~ ⊥ + PmBang x mb_info -> do + div <- addPmCtDeltas inc (PmBotCt x) + matched <- addPmCtDeltas inc (PmNotBotCt x) + -- See Note [Dead bang patterns] + -- mb_info = Just info <==> PmBang originates from bang pattern in source + let bangs | Just info <- mb_info = unitOL (div, info) + | otherwise = NilOL + pure CheckResult { cr_ret = RedSets { rs_cov = matched, rs_div = div, rs_bangs = bangs } + , cr_uncov = mempty + , cr_approx = Precise } + -- Con: Diverge on x ~ ⊥, fall through on x /~ K and refine with x ~ K ys + -- and type info + PmCon x con tvs dicts args -> do + div <- if conMatchForces con + then addPmCtDeltas inc (PmBotCt x) + else pure mempty + uncov <- addPmCtDeltas inc (PmNotConCt x con) + matched <- addPmCtsDeltas inc $ + listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args + -- tracePm "checkGrd:Con" (ppr inc $$ ppr x $$ ppr con $$ ppr dicts $$ ppr matched) + pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched, rs_div = div } + , cr_uncov = uncov + , cr_approx = Precise } + +checkGrds :: [PmGrd] -> CheckAction RedSets +checkGrds [] = CA $ \inc -> + pure CheckResult { cr_ret = emptyRedSets { rs_cov = inc } + , cr_uncov = mempty + , cr_approx = Precise } +checkGrds (g:grds) = leftToRight merge (checkGrd g) (checkGrds grds) where - -- | Accumulates a CheckResult. Its type is more like - -- @CheckResult -> [GrdTree] -> CheckResult@, but cr_clauses is a single - -- 'AnnotatedTree', not a list thereof. Hence 3 parameters to thread the - -- fields. - go :: [AnnotatedTree] -> Deltas -> Precision -> [GrdTree] -> DsM CheckResult - -- No cases left: Fall through for all values - go ts' unc prec [] = pure CheckResult - { cr_clauses = SequenceAnn init_unc (reverse ts') - , cr_uncov = unc - , cr_approx = prec } - go ts' unc prec (t:ts) = do - CheckResult t' unc_1 prec_t <- checkGrdTree' t unc - go (t':ts') unc_1 (prec_t Semi.<> prec) ts - --- | Print diagnostic info and actually call 'checkGrdTree''. -checkGrdTree :: GrdTree -> Deltas -> DsM CheckResult -checkGrdTree guards deltas = do - tracePm "checkGrdTree {" $ vcat [ ppr guards - , ppr deltas ] - res <- checkGrdTree' guards deltas - tracePm "checkGrdTree }:" (ppr res) -- braces are easier to match by tooling - return res - --- ---------------------------------------------------------------------------- --- * Propagation of term constraints inwards when checking nested matches - -{- Note [Type and Term Equality Propagation] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -When checking a match it would be great to have all type and term information -available so we can get more precise results. For this reason we have functions -`addDictsDs' and `addTmVarCsDs' in GHC.HsToCore.Monad that store in the -environment type and term constraints (respectively) as we go deeper. - -The type constraints we propagate inwards are collected by `collectEvVarsPats' -in GHC.Hs.Pat. This handles bug #4139 ( see example - https://gitlab.haskell.org/ghc/ghc/snippets/672 ) -where this is needed. - -For term equalities we do less, we just generate equalities for HsCase. For -example we accurately give 2 redundancy warnings for the marked cases: - -f :: [a] -> Bool -f x = case x of - - [] -> case x of -- brings (x ~ []) in scope - [] -> True - (_:_) -> False -- can't happen - - (_:_) -> case x of -- brings (x ~ (_:_)) in scope - (_:_) -> True - [] -> False -- can't happen - -Functions `add*ScrutTmCs' is responsible for generating -these constraints. --} + merge ri_g ri_grds = -- This operation would /not/ form a Semigroup! + RedSets { rs_cov = rs_cov ri_grds + , rs_div = rs_div ri_g Semi.<> rs_div ri_grds + , rs_bangs = rs_bangs ri_g Semi.<> rs_bangs ri_grds } --- | Locally update 'dsl_deltas' with the given action, but defer evaluation --- with 'unsafeInterleaveM' in order not to do unnecessary work. -locallyExtendPmDelta :: (Deltas -> DsM Deltas) -> DsM a -> DsM a -locallyExtendPmDelta ext k = do - deltas <- getPmDeltas - deltas' <- unsafeInterleaveM $ do - deltas' <- ext deltas - inh <- isInhabited deltas' - -- If adding a constraint would lead to a contradiction, don't add it. - -- See @Note [Recovering from unsatisfiable pattern-matching constraints]@ - -- for why this is done. - if inh - then pure deltas' - else pure deltas - updPmDeltas deltas' k +checkMatchGroup :: GrdMatchGroup -> CheckAction AnnMatchGroup +checkMatchGroup (GrdMatchGroup matches) = + AnnMatchGroup <$> checkSequence checkMatch matches --- | Add in-scope type constraints if the coverage checker might run and then --- run the given action. -addTyCsDs :: Origin -> Bag EvVar -> DsM a -> DsM a -addTyCsDs origin ev_vars m = do - dflags <- getDynFlags - applyWhen (needToRunPmCheck dflags origin) - (locallyExtendPmDelta (\deltas -> addPmCtsDeltas deltas (PmTyCt . evVarPred <$> ev_vars))) - m +checkMatch :: GrdMatch -> CheckAction AnnMatch +checkMatch (GrdMatch { gm_pats = grds, gm_grhss = grhss }) = + leftToRight AnnMatch (checkGrds grds) (checkGRHSs grhss) --- | Add equalities for the 'CoreExpr' scrutinee to the local 'DsM' environment --- when checking a case expression: --- case e of x { matches } --- When checking matches we record that (x ~ e) where x is the initial --- uncovered. All matches will have to satisfy this equality. -addCoreScrutTmCs :: Maybe CoreExpr -> [Id] -> DsM a -> DsM a -addCoreScrutTmCs Nothing _ k = k -addCoreScrutTmCs (Just scr) [x] k = - flip locallyExtendPmDelta k $ \deltas -> - addPmCtsDeltas deltas (unitBag (PmCoreCt x scr)) -addCoreScrutTmCs _ _ _ = panic "addCoreScrutTmCs: scrutinee, but more than one match id" +checkGRHSs :: NonEmpty GrdGRHS -> CheckAction (NonEmpty AnnGRHS) +checkGRHSs = checkSequence checkGRHS --- | 'addCoreScrutTmCs', but desugars the 'LHsExpr' first. -addHsScrutTmCs :: Maybe (LHsExpr GhcTc) -> [Id] -> DsM a -> DsM a -addHsScrutTmCs Nothing _ k = k -addHsScrutTmCs (Just scr) vars k = do - scr_e <- dsLExpr scr - addCoreScrutTmCs (Just scr_e) vars k +checkGRHS :: GrdGRHS -> CheckAction AnnGRHS +checkGRHS (GrdGRHS { gg_grds = grds, gg_rhs = rhs_info }) = + flip AnnGRHS rhs_info <$> checkGrds grds -{- -%************************************************************************ -%* * - Pretty printing of exhaustiveness/redundancy check warnings -%* * -%************************************************************************ --} +checkEmptyCase :: GrdEmptyCase -> CheckAction AnnEmptyCase +checkEmptyCase (GrdEmptyCase { ge_var = var }) = CA $ \inc -> do + unc <- addPmCtDeltas inc (PmNotBotCt var) + pure CheckResult { cr_ret = AnnEmptyCase, cr_uncov = unc, cr_approx = mempty } --- | Check whether any part of pattern match checking is enabled for this --- 'HsMatchContext' (does not matter whether it is the redundancy check or the --- exhaustiveness check). -isMatchContextPmChecked :: DynFlags -> Origin -> HsMatchContext id -> Bool -isMatchContextPmChecked dflags origin kind - | isGenerated origin - = False - | otherwise - = overlapping dflags kind || exhaustive dflags kind +checkPatBind :: GrdPatBind -> CheckAction AnnPatBind +checkPatBind = coerce checkGRHS --- | Return True when any of the pattern match warnings ('allPmCheckWarnings') --- are enabled, in which case we need to run the pattern match checker. -needToRunPmCheck :: DynFlags -> Origin -> Bool -needToRunPmCheck dflags origin - | isGenerated origin - = False - | otherwise - = notNull (filter (`wopt` dflags) allPmCheckWarnings) +{- Note [Countering exponential blowup] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Precise pattern match exhaustiveness checking is necessarily exponential in +the size of some input programs. We implement a counter-measure in the form of +the -fmax-pmcheck-models flag, limiting the number of Deltas we check against +each pattern by a constant. + +How do we do that? Consider + + f True True = () + f True True = () + +And imagine we set our limit to 1 for the sake of the example. The first clause +will be checked against the initial Delta, {}. Doing so will produce an +Uncovered set of size 2, containing the models {x/~True} and {x~True,y/~True}. +Also we find the first clause to cover the model {x~True,y~True}. + +But the Uncovered set we get out of the match is too huge! We somehow have to +ensure not to make things worse as they are already, so we continue checking +with a singleton Uncovered set of the initial Delta {}. Why is this +sound (wrt. the notion in GADTs Meet Their Match)? Well, it basically amounts +to forgetting that we matched against the first clause. The values represented +by {} are a superset of those represented by its two refinements {x/~True} and +{x~True,y/~True}. + +This forgetfulness becomes very apparent in the example above: By continuing +with {} we don't detect the second clause as redundant, as it again covers the +same non-empty subset of {}. So we don't flag everything as redundant anymore, +but still will never flag something as redundant that isn't. --- | A type for organising information to be used in warnings. -data RedundancyInfo - = RedundancyInfo - { redundant_rhss :: ![SrcInfo] - , inaccessible_rhss :: ![SrcInfo] - , redundant_bangs :: ![Located SDoc] +For exhaustivity, the converse applies: We will report @f@ as non-exhaustive +and report @f _ _@ as missing, which is a superset of the actual missing +matches. But soundness means we will never fail to report a missing match. + +This mechanism is implemented in 'throttle'. + +Guards are an extreme example in this regard, with #11195 being a particularly +dreadful example: Since their RHS are often pretty much unique, we split on a +variable (the one representing the RHS) that doesn't occur anywhere else in the +program, so we don't actually get useful information out of that split! +-} + +-- +-- * Collecting redundancy information +-- + +-- | The result of redundancy checking: +-- * RHSs classified as /C/overed, /I/naccessible and /R/edundant +-- * And redundant (B)ang patterns. +data CIRB + = CIRB + { cirb_cov :: !(OrdList SrcInfo) + , cirb_inacc :: !(OrdList SrcInfo) + , cirb_red :: !(OrdList SrcInfo) + , cirb_bangs :: !(OrdList SrcInfo) } -extractRedundancyInfo :: AnnotatedTree -> RedundancyInfo -extractRedundancyInfo tree = - RedundancyInfo { redundant_rhss = fromOL ol_red - , inaccessible_rhss = fromOL ol_inacc - , redundant_bangs = fromOL ol_bangs } - where - (_ol_acc, ol_inacc, ol_red, ol_bangs) = go tree - -- | Collects - -- 1. accessible RHSs - -- 2. proper inaccessible RHSs (so we can't delete them) - -- 3. hypothetically redundant RHSs (so not only inaccessible, but we can - -- even safely delete the equation without altering semantics) - -- 4. 'Dead' bangs from the source, collected to be warned about - -- See Note [Determining inaccessible clauses] - -- See Note [Dead bang patterns] - go :: AnnotatedTree -> (OrdList SrcInfo, OrdList SrcInfo, OrdList SrcInfo, OrdList SrcInfo) - go (AccessibleRhs _ info) = (unitOL info, nilOL, nilOL , nilOL) - go (InaccessibleRhs info) = (nilOL, nilOL, unitOL info, nilOL) -- presumably redundant - go (MayDiverge t) = case go t of - -- See Note [Determining inaccessible clauses] - (acc, inacc, red, bs) - | isNilOL acc && isNilOL inacc -> (nilOL, red, nilOL, bs) - res -> res - go (SequenceAnn _ ts) = foldMap go ts - go (RedundantSrcBang l t) = case go t of - -- See Note [Dead bang patterns] - res@(acc, inacc, _, _) - | isNilOL acc, isNilOL inacc -> res - | otherwise -> (nilOL, nilOL, nilOL, unitOL l) Semi.<> res +instance Semigroup CIRB where + CIRB a b c d <> CIRB e f g h = CIRB (a <> e) (b <> f) (c <> g) (d <> h) + where (<>) = (Semi.<>) + +instance Monoid CIRB where + mempty = CIRB mempty mempty mempty mempty + +markAllRedundant :: CIRB -> CIRB +markAllRedundant CIRB { cirb_cov = cov, cirb_inacc = inacc, cirb_red = red } = + mempty { cirb_red = cov Semi.<> inacc Semi.<> red } + +-- See Note [Determining inaccessible clauses] +ensureOneNotRedundant :: CIRB -> CIRB +ensureOneNotRedundant ci = case ci of + CIRB { cirb_cov = NilOL, cirb_inacc = NilOL, cirb_red = ConsOL r rs } + -> ci { cirb_inacc = unitOL r, cirb_red = rs } + _ -> ci + +-- | Only adds the redundant bangs to the @CIRB@ if there is at least one +-- non-redundant 'SrcInfo'. There is no point in remembering a redundant bang +-- if the whole match is redundant! +addRedundantBangs :: OrdList SrcInfo -> CIRB -> CIRB +addRedundantBangs _red_bangs cirb at CIRB { cirb_cov = NilOL, cirb_inacc = NilOL } = + cirb +addRedundantBangs red_bangs cirb = + cirb { cirb_bangs = cirb_bangs cirb Semi.<> red_bangs } + +-- | A function that walks along an annotated tree @ann@ and extracts two kinds +-- of coverage info: +-- +-- 1. A 'CIRB', classifying every encountered RHS in the tree as +-- redundant, inaccessible or covered. +-- 2. A piece of long-distance information @ldi@, consisting of a +-- nesting of 'Deltas' mirroring tree structure. +-- For example, 'collectMatchGroup' operates on a Match Group and thus +-- returns a list of 'Deltas' for the pattern part of each Match, as well as +-- a further nested list of 'Deltas' for each of the GRHS of the Match. +type CIRBCollector ann ldi = ann -> DsM (CIRB, ldi) + +-- | Checks the 'Deltas' in a 'RedSets' for inhabitants and returns +-- 1. Whether the Covered set was inhabited +-- 2. Whether the Diverging set was inhabited +-- 3. The new inhabited Covered set for long-distance information. +-- See Note [Recovering from unsatisfiable pattern-matching constraints]. +-- 4. All source bangs whose 'Deltas' were empty, which means they are +-- redundant. +testRedSets :: Deltas -> RedSets -> DsM (Bool, Bool, Deltas, OrdList SrcInfo) +testRedSets ldi RedSets { rs_cov = cov, rs_div = div, rs_bangs = bangs } = do + is_covered <- isInhabited cov + may_diverge <- isInhabited div + red_bangs <- flip mapMaybeM (fromOL bangs) $ \(deltas, bang) -> do + isInhabited deltas >>= \case + True -> pure Nothing + False -> pure (Just bang) + -- See Note [Recovering from unsatisfiable pattern-matching constraints] + -- Deltas for long-distance info: Use (non-empty!) fallback ldi if Covered + -- set was empty + let ldi' + | is_covered = cov + | otherwise = ldi + pure (is_covered, may_diverge, ldi', toOL red_bangs) + +collectMatchGroup :: Deltas -> CIRBCollector AnnMatchGroup (NonEmpty (Deltas, NonEmpty Deltas)) +collectMatchGroup ldi (AnnMatchGroup matches) = do + (cirbs, ldis) <- NE.unzip <$> traverse (collectMatch ldi) matches + pure (Semi.sconcat cirbs, ldis) + +collectMatch :: Deltas -> CIRBCollector AnnMatch (Deltas, NonEmpty Deltas) +collectMatch ldi AnnMatch { am_red = red, am_grhss = grhss } = do + (is_covered, may_diverge, ldi', red_bangs) <- testRedSets ldi red + (cirb, ldis) <- collectGRHSs ldi' grhss + let cirb' = addRedundantBangs red_bangs + -- See Note [Determining inaccessible clauses] + $ applyWhen may_diverge ensureOneNotRedundant + $ applyWhen (not is_covered) markAllRedundant + $ cirb + pure (cirb', (ldi', ldis)) + +collectGRHSs :: Deltas -> CIRBCollector (NonEmpty AnnGRHS) (NonEmpty Deltas) +collectGRHSs ldi grhss = do + (cirbs, ldis) <- NE.unzip <$> traverse (collectGRHS ldi) grhss + pure (Semi.sconcat cirbs, ldis) + +collectGRHS :: Deltas -> CIRBCollector AnnGRHS Deltas +collectGRHS ldi AnnGRHS { ag_red = red, ag_rhs = info } = do + (is_covered, may_diverge, ldi', red_bangs) <- testRedSets ldi red + let cirb | is_covered = mempty { cirb_cov = unitOL info } + | may_diverge = mempty { cirb_inacc = unitOL info } + | otherwise = mempty { cirb_red = unitOL info } + pure (addRedundantBangs red_bangs cirb, ldi') + +collectEmptyCase :: CIRBCollector AnnEmptyCase () +collectEmptyCase _ = pure (mempty, ()) + +collectPatBind :: CIRBCollector AnnPatBind () +-- We don't make use of long-distance information in pattern bindings, hence +-- @()@ instead of some 'Deltas'. +collectPatBind (AnnPatBind grhs) = do + -- use 'mempty' as fallback 'Deltas' because we discard it anyway + (cirb, _) <- collectGRHS mempty grhs + pure (cirb, ()) {- Note [Determining inaccessible clauses] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1239,26 +1176,30 @@ arguments we can ever reach clause 2's RHS, so we say it has inaccessible RHS (as opposed to being completely redundant). We detect an inaccessible RHS simply by pretending it's redundant, until we see -that it's part of a sub-tree in the pattern match that forces some argument -(which corresponds to wrapping the 'AnnotatedTree' in 'MayDiverge'). Then we -turn all supposedly redundant RHSs into inaccessible ones. - -But as it turns out (@g@ from #17465) this is too conservative: - g () | False = () - | otherwise = () -g's first clause has an inaccessible RHS, but it's also safe to delete. So it's -redundant, really! But by just turning all redundant child clauses into -inaccessible ones, we report the first clause as inaccessible. - -Clearly, it is enough if we say that we only degrade if *not all* of the child -clauses are redundant. As long as there is at least one clause which we announce -not to be redundant, the guard prefix responsible for the 'MayDiverge' will -survive. Hence we check for that in 'extractRedundancyInfo'. -} --- | Issue all the warnings (coverage, exhaustiveness, inaccessibility) -dsPmWarn :: DynFlags -> DsMatchContext -> [Id] -> CheckResult -> DsM () -dsPmWarn dflags ctx@(DsMatchContext kind loc) vars result +-- +-- * Formatting and reporting warnings +-- + +-- | Given a 'CIRBCollector', this function will emit warnings for a +-- 'CheckResult' and return the collected long-distance information. +formatReportWarnings :: CIRBCollector ann ldi -> DsMatchContext -> [Id] -> CheckResult ann -> DsM ldi +formatReportWarnings collect ctx vars cr at CheckResult { cr_ret = ann } = do + (cov_info, ldi) <- collect ann + dflags <- getDynFlags + reportWarnings dflags ctx vars cr{cr_ret=cov_info} + pure ldi + +-- | Issue all the warnings +-- (redundancy, inaccessibility, exhaustiveness, redundant bangs). +reportWarnings :: DynFlags -> DsMatchContext -> [Id] -> CheckResult CIRB -> DsM () +reportWarnings dflags ctx@(DsMatchContext kind loc) vars + CheckResult { cr_ret = CIRB { cirb_inacc = inaccessible_rhss + , cirb_red = redundant_rhss + , cirb_bangs = redundant_bangs } + , cr_uncov = uncovered + , cr_approx = precision } = when (flag_i || flag_u || flag_b) $ do unc_examples <- getNFirstUncovered vars (maxPatterns + 1) uncovered let exists_r = flag_i && notNull redundant_rhss @@ -1284,13 +1225,6 @@ dsPmWarn dflags ctx@(DsMatchContext kind loc) vars result when exists_u $ putSrcSpanDs loc $ warnDs flag_u_reason $ pprEqns vars unc_examples where - CheckResult - { cr_clauses = clauses - , cr_uncov = uncovered - , cr_approx = precision } = result - RedundancyInfo{redundant_rhss, inaccessible_rhss, redundant_bangs} - = extractRedundancyInfo clauses - flag_i = overlapping dflags kind flag_u = exhaustive dflags kind flag_b = redundant_bang dflags @@ -1331,44 +1265,30 @@ getNFirstUncovered vars n (MkDeltas deltas) = go n (bagToList deltas) back <- go (n - length front) deltas pure (front ++ back) -{- Note [Inaccessible warnings for record updates] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider (#12957) - data T a where - T1 :: { x :: Int } -> T Bool - T2 :: { x :: Int } -> T a - T3 :: T a - - f :: T Char -> T a - f r = r { x = 3 } - -The desugarer will (conservatively generate a case for T1 even though -it's impossible: - f r = case r of - T1 x -> T1 3 -- Inaccessible branch - T2 x -> T2 3 - _ -> error "Missing" - -We don't want to warn about the inaccessible branch because the programmer -didn't put it there! So we filter out the warning here. - -The same can happen for long distance term constraints instead of type -constraints (#17783): - - data T = A { x :: Int } | B { x :: Int } - f r at A{} = r { x = 3 } - f _ = B 0 - -Here, the long distance info from the FunRhs match (@r ~ A x@) will make the -clause matching on @B@ of the desugaring to @case@ redundant. It's generated -code that we don't want to warn about. --} - dots :: Int -> [a] -> SDoc dots maxPatterns qs | qs `lengthExceeds` maxPatterns = text "..." | otherwise = empty +pprContext :: Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc +pprContext singular (DsMatchContext kind _loc) msg rest_of_msg_fun + = vcat [text txt <+> msg, + sep [ text "In" <+> ppr_match <> char ':' + , nest 4 (rest_of_msg_fun pref)]] + where + txt | singular = "Pattern match" + | otherwise = "Pattern match(es)" + + (ppr_match, pref) + = case kind of + FunRhs { mc_fun = L _ fun } + -> (pprMatchContext kind, \ pp -> ppr fun <+> pp) + _ -> (pprMatchContext kind, \ pp -> pp) + +-- +-- * Utilities +-- + -- | All warning flags that need to run the pattern match checker. allPmCheckWarnings :: [WarningFlag] allPmCheckWarnings = @@ -1411,18 +1331,151 @@ exhaustiveWarningFlag ThPatQuote = Nothing -- etc. They are often *supposed* to be incomplete exhaustiveWarningFlag (StmtCtxt {}) = Nothing --- True <==> singular -pprContext :: Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc -pprContext singular (DsMatchContext kind _loc) msg rest_of_msg_fun - = vcat [text txt <+> msg, - sep [ text "In" <+> ppr_match <> char ':' - , nest 4 (rest_of_msg_fun pref)]] - where - txt | singular = "Pattern match" - | otherwise = "Pattern match(es)" +-- | Check whether any part of pattern match checking is enabled for this +-- 'HsMatchContext' (does not matter whether it is the redundancy check or the +-- exhaustiveness check). +isMatchContextPmChecked :: DynFlags -> Origin -> HsMatchContext id -> Bool +isMatchContextPmChecked dflags origin kind + | isGenerated origin + = False + | otherwise + = overlapping dflags kind || exhaustive dflags kind - (ppr_match, pref) - = case kind of - FunRhs { mc_fun = L _ fun } - -> (pprMatchContext kind, \ pp -> ppr fun <+> pp) - _ -> (pprMatchContext kind, \ pp -> pp) +-- | Return True when any of the pattern match warnings ('allPmCheckWarnings') +-- are enabled, in which case we need to run the pattern match checker. +needToRunPmCheck :: DynFlags -> Origin -> Bool +needToRunPmCheck dflags origin + | isGenerated origin + = False + | otherwise + = notNull (filter (`wopt` dflags) allPmCheckWarnings) + +{- Note [Inaccessible warnings for record updates] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider (#12957) + data T a where + T1 :: { x :: Int } -> T Bool + T2 :: { x :: Int } -> T a + T3 :: T a + + f :: T Char -> T a + f r = r { x = 3 } + +The desugarer will conservatively generate a case for T1 even though +it's impossible: + f r = case r of + T1 x -> T1 3 -- Inaccessible branch + T2 x -> T2 3 + _ -> error "Missing" + +We don't want to warn about the inaccessible branch because the programmer +didn't put it there! So we filter out the warning here. + +The same can happen for long distance term constraints instead of type +constraints (#17783): + + data T = A { x :: Int } | B { x :: Int } + f r at A{} = r { x = 3 } + f _ = B 0 + +Here, the long distance info from the FunRhs match (@r ~ A x@) will make the +clause matching on @B@ of the desugaring to @case@ redundant. It's generated +code that we don't want to warn about. +-} + +-- +-- * Long-distance information +-- + +-- | Locally update 'dsl_deltas' with the given action, but defer evaluation +-- with 'unsafeInterleaveM' in order not to do unnecessary work. +locallyExtendPmDeltas :: (Deltas -> DsM Deltas) -> DsM a -> DsM a +locallyExtendPmDeltas ext k = do + deltas <- getPmDeltas + deltas' <- unsafeInterleaveM $ do + deltas' <- ext deltas + inh <- isInhabited deltas' + -- If adding a constraint would lead to a contradiction, don't add it. + -- See Note [Recovering from unsatisfiable pattern-matching constraints] + -- for why this is done. + if inh + then pure deltas' + else pure deltas + updPmDeltas deltas' k + +-- | Add in-scope type constraints if the coverage checker might run and then +-- run the given action. +addTyCs :: Origin -> Bag EvVar -> DsM a -> DsM a +addTyCs origin ev_vars m = do + dflags <- getDynFlags + applyWhen (needToRunPmCheck dflags origin) + (locallyExtendPmDeltas (\deltas -> addPmCtsDeltas deltas (PmTyCt . evVarPred <$> ev_vars))) + m + +-- | Add equalities for the 'CoreExpr' scrutinee to the local 'DsM' environment +-- when checking a case expression: +-- case e of x { matches } +-- When checking matches we record that (x ~ e) where x is the initial +-- uncovered. All matches will have to satisfy this equality. +addCoreScrutTmCs :: Maybe CoreExpr -> [Id] -> DsM a -> DsM a +addCoreScrutTmCs Nothing _ k = k +addCoreScrutTmCs (Just scr) [x] k = + flip locallyExtendPmDeltas k $ \deltas -> + addPmCtsDeltas deltas (unitBag (PmCoreCt x scr)) +addCoreScrutTmCs _ _ _ = panic "addCoreScrutTmCs: scrutinee, but more than one match id" + +-- | 'addCoreScrutTmCs', but desugars the 'LHsExpr' first. +addHsScrutTmCs :: Maybe (LHsExpr GhcTc) -> [Id] -> DsM a -> DsM a +addHsScrutTmCs Nothing _ k = k +addHsScrutTmCs (Just scr) vars k = do + scr_e <- dsLExpr scr + addCoreScrutTmCs (Just scr_e) vars k + +{- Note [Long-distance information] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider + + data Color = R | G | B + f :: Color -> Int + f R = … + f c = … (case c of + G -> True + B -> False) … + +Humans can make the "long-distance connection" between the outer pattern match +and the nested case pattern match to see that the inner pattern match is +exhaustive: @c@ can't be @R@ anymore because it was matched in the first clause +of @f at . + +To achieve similar reasoning in the coverage checker, we keep track of the set +of values that can reach a particular program point (often loosely referred to +as "Covered set") in 'GHC.HsToCore.Monad.dsl_deltas'. +We fill that set with Covered Deltas returned by the exported checking +functions, which the call sites put into place with +'GHC.HsToCore.Monad.updPmDeltas'. +Call sites also extend this set with facts from type-constraint dictionaries, +case scrutinees, etc. with the exported functions 'addTyCs', 'addCoreScrutTmCs' +and 'addHsScrutTmCs'. + +Note [Recovering from unsatisfiable pattern-matching constraints] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider the following code (see #12957 and #15450): + + f :: Int ~ Bool => () + f = case True of { False -> () } + +We want to warn that the pattern-matching in `f` is non-exhaustive. But GHC +used not to do this; in fact, it would warn that the match was /redundant/! +This is because the constraint (Int ~ Bool) in `f` is unsatisfiable, and the +coverage checker deems any matches with unsatisfiable constraint sets to be +unreachable. + +We can do better than this, by making sure that the Covered set used for +Note [Long-distance information] is always inhabited. +For Covered sets returned by the exported checking functions, that is ensured +in 'testRedSets', which takes and returns a non-empty fallback 'Deltas' in case +the refined Covered set became uninhabited. +Also, whenever "external" knowledge from a type constraint or case scrutinee is +integrated, we only commit that knowledge to 'GHC.HsToCore.Monad.dsl_deltas' if +the set remains inhabited. That check happens in 'locallyExtendPmDeltas'. +-} ===================================== compiler/GHC/HsToCore/PmCheck/Oracle.hs ===================================== @@ -166,25 +166,6 @@ mkOneConFull arg_tys con = do -- * Pattern match oracle -{- Note [Recovering from unsatisfiable pattern-matching constraints] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider the following code (see #12957 and #15450): - - f :: Int ~ Bool => () - f = case True of { False -> () } - -We want to warn that the pattern-matching in `f` is non-exhaustive. But GHC -used not to do this; in fact, it would warn that the match was /redundant/! -This is because the constraint (Int ~ Bool) in `f` is unsatisfiable, and the -coverage checker deems any matches with unsatisfiable constraint sets to be -unreachable. - -We decide to better than this. When beginning coverage checking, we first -check if the constraints in scope are unsatisfiable, and if so, we start -afresh with an empty set of constraints. This way, we'll get the warnings -that we expect. --} - ------------------------------------- -- * Composable satisfiability checks @@ -1265,7 +1246,7 @@ isTyConTriviallyInhabited tc = elementOfUniqSet tc triviallyInhabitedTyCons {- Note [Checking EmptyCase Expressions] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Empty case expressions are strict on the scrutinee. That is, `case x of {}` -will force argument `x`. Hence, `covCheckMatchGroup` is not sufficient for checking +will force argument `x`. Hence, `covCheckMatches` is not sufficient for checking empty cases, because it assumes that the match is not strict (which is true for all other cases, apart from EmptyCase). This gave rise to #10746. Instead, we do the following: ===================================== compiler/GHC/HsToCore/PmCheck/Types.hs ===================================== @@ -592,5 +592,8 @@ instance Outputable Deltas where instance Semigroup Deltas where MkDeltas l <> MkDeltas r = MkDeltas (l `unionBags` r) +instance Monoid Deltas where + mempty = MkDeltas emptyBag + liftDeltasM :: Monad m => (Delta -> m (Maybe Delta)) -> Deltas -> m Deltas liftDeltasM f (MkDeltas ds) = MkDeltas . catBagMaybes <$> (traverse f ds) ===================================== compiler/GHC/Tc/Types.hs ===================================== @@ -323,7 +323,7 @@ data DsLclEnv = DsLclEnv { dsl_meta :: DsMetaEnv, -- Template Haskell bindings dsl_loc :: RealSrcSpan, -- To put in pattern-matching error msgs - -- See Note [Note [Type and Term Equality Propagation] in "GHC.HsToCore.PmCheck" + -- See Note [Note [Long-distance information] in "GHC.HsToCore.PmCheck" -- The set of reaching values Deltas is augmented as we walk inwards, -- refined through each pattern match in turn dsl_deltas :: Deltas ===================================== compiler/GHC/Utils/Misc.hs ===================================== @@ -556,9 +556,8 @@ isSingleton :: [a] -> Bool isSingleton [_] = True isSingleton _ = False -notNull :: [a] -> Bool -notNull [] = False -notNull _ = True +notNull :: Foldable f => f a -> Bool +notNull = not . null only :: [a] -> a #if defined(DEBUG) ===================================== testsuite/tests/deSugar/should_compile/ds020.stderr ===================================== @@ -18,3 +18,11 @@ ds020.hs:20:1: warning: [-Woverlapping-patterns (in -Wdefault)] ds020.hs:23:1: warning: [-Woverlapping-patterns (in -Wdefault)] Pattern match is redundant In an equation for ‘f’: f x@(~[]) = ... + +ds020.hs:32:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: (x1 : xs1 : ys1) = ... + +ds020.hs:33:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: (~x : ~xs : ~ys) = ... ===================================== testsuite/tests/module/all.T ===================================== @@ -83,7 +83,7 @@ test('mod61', normal, compile_fail, ['']) test('mod62', normal, compile_fail, ['']) test('mod63', normal, compile_fail, ['']) test('mod64', normal, compile, ['']) -test('mod65', normal, compile, ['']) +test('mod65', normal, compile, ['-Wno-overlapping-patterns']) test('mod66', normal, compile_fail, ['']) test('mod67', normal, compile_fail, ['']) test('mod68', normal, compile_fail, ['']) ===================================== testsuite/tests/pmcheck/should_compile/T18572.hs ===================================== @@ -3,10 +3,10 @@ module T18572 where -True = True +True = True -- no warning data SBool (b :: Bool) where STrue :: SBool True SFalse :: SBool False -STrue = SFalse +STrue = SFalse -- "redundant", not "inaccessible" ===================================== testsuite/tests/rename/should_compile/T7085.stderr ===================================== @@ -1,3 +1,7 @@ T7085.hs:8:6: warning: [-Wunused-pattern-binds (in -Wextra, -Wunused-binds)] This pattern-binding binds no variables: Nothing = Just n + +T7085.hs:8:6: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: Nothing = ... ===================================== testsuite/tests/unboxedsums/all.T ===================================== @@ -30,5 +30,5 @@ test('T12711', only_ways(['ghci']), ghci_script, ['T12711.script']) # extra_files([ "unboxedsums" + str(i) + ".hs" for i in range(1, 12) ])], # makefile_test, []) -test('UbxSumLevPoly', normal, compile, ['']) +test('UbxSumLevPoly', normal, compile, ['-Wno-overlapping-patterns']) test('T14051', normal, multi_compile, ['T14051.hs', [('T14051a.hs', '')], '-O2 -v0']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/65d51d90902b5aa1522ac6e8113ef999be4c1f7e -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/65d51d90902b5aa1522ac6e8113ef999be4c1f7e You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 12:25:03 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Mon, 31 Aug 2020 08:25:03 -0400 Subject: [Git][ghc/ghc][wip/T18565] PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Message-ID: <5f4cec1f44634_80bd6bc78898823eb@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18565 at Glasgow Haskell Compiler / GHC Commits: 90651e47 by Sebastian Graf at 2020-08-31T14:24:39+02:00 PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Previously, we desugared and coverage checked plain guard trees as described in Lower Your Guards. That caused (in !3849) quite a bit of pain when we need to partially recover tree structure of the input syntax to return covered sets for long-distance information, for example. In this refactor, I introduced a guard tree variant for each relevant source syntax component of a pattern-match (mainly match groups, match, GRHS, empty case, pattern binding). I made sure to share as much coverage checking code as possible, so that the syntax-specific checking functions are just wrappers around the more substantial checking functions for the LYG primitives (`checkSequence`, `checkGrds`). The refactoring payed off in clearer code and elimination of all panics related to assumed guard tree structure and thus fixes #18565. I also took the liberty to rename and re-arrange the order of functions and comments in the module, deleted some dead and irrelevant Notes, wrote some new ones and gave an overview module haddock. - - - - - 14 changed files: - compiler/GHC/Data/OrdList.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - compiler/GHC/HsToCore/PmCheck/Types.hs - compiler/GHC/Tc/Types.hs - compiler/GHC/Utils/Misc.hs - testsuite/tests/deSugar/should_compile/ds020.stderr - testsuite/tests/module/all.T - testsuite/tests/pmcheck/should_compile/T18572.hs - testsuite/tests/rename/should_compile/T7085.stderr - testsuite/tests/unboxedsums/all.T Changes: ===================================== compiler/GHC/Data/OrdList.hs ===================================== @@ -5,13 +5,16 @@ -} {-# LANGUAGE DeriveFunctor #-} - {-# LANGUAGE BangPatterns #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE UnboxedSums #-} +{-# LANGUAGE UnboxedTuples #-} -- | Provide trees (of instructions), so that lists of instructions can be -- appended in linear time. module GHC.Data.OrdList ( - OrdList, + OrdList, pattern NilOL, pattern ConsOL, pattern SnocOL, nilOL, isNilOL, unitOL, appOL, consOL, snocOL, concatOL, lastOL, headOL, mapOL, fromOL, toOL, foldrOL, foldlOL, reverseOL, fromOLReverse, @@ -79,6 +82,50 @@ snocOL as b = Snoc as b consOL a bs = Cons a bs concatOL aas = foldr appOL None aas +pattern NilOL :: OrdList a +pattern NilOL <- (isNilOL -> True) where + NilOL = None + +-- | An unboxed 'Maybe' type with two unboxed fields in the 'Just' case. +-- Useful for defining 'viewCons' and 'viewSnoc' without overhead. +type VMaybe a b = (# (# a, b #) | (# #) #) +pattern VJust :: a -> b -> VMaybe a b +pattern VJust a b = (# (# a, b #) | #) +pattern VNothing :: VMaybe a b +pattern VNothing = (# | (# #) #) +{-# COMPLETE VJust, VNothing #-} + +pattern ConsOL :: a -> OrdList a -> OrdList a +pattern ConsOL x xs <- (viewCons -> VJust x xs) where + ConsOL x xs = consOL x xs +{-# COMPLETE NilOL, ConsOL #-} +viewCons :: OrdList a -> VMaybe a (OrdList a) +viewCons (One a) = VJust a NilOL +viewCons (Cons a as) = VJust a as +viewCons (Snoc as a) = case viewCons as of + VJust a' as' -> VJust a' (Snoc as' a) + VNothing -> VJust a NilOL +viewCons (Two as1 as2) = case viewCons as1 of + VJust a' as1' -> VJust a' (Two as1' as2) + VNothing -> viewCons as2 +viewCons _ = VNothing + +pattern SnocOL :: OrdList a -> a -> OrdList a +pattern SnocOL xs x <- (viewSnoc -> VJust xs x) where + SnocOL xs x = snocOL xs x +{-# COMPLETE NilOL, SnocOL #-} +viewSnoc :: OrdList a -> VMaybe (OrdList a) a +viewSnoc (One a) = VJust NilOL a +viewSnoc (Many (reverse -> a:as)) = VJust (Many (reverse as)) a +viewSnoc (Snoc as a) = VJust as a +viewSnoc (Cons a as) = case viewSnoc as of + VJust as' a' -> VJust (Cons a as') a' + VNothing -> VJust NilOL a +viewSnoc (Two as1 as2) = case viewSnoc as2 of + VJust as2' a' -> VJust (Two as1 as2') a' + VNothing -> viewSnoc as1 +viewSnoc _ = VNothing + headOL None = panic "headOL" headOL (One a) = a headOL (Many as) = head as @@ -189,5 +236,3 @@ strictlyOrdOL (Two a1 a2) (Two b1 b2) = strictlyOrdOL (Two _ _) _ = LT strictlyOrdOL (Many as) (Many bs) = compare as bs strictlyOrdOL (Many _ ) _ = GT - - ===================================== compiler/GHC/HsToCore/Binds.hs ===================================== @@ -33,7 +33,7 @@ import {-# SOURCE #-} GHC.HsToCore.Match ( matchWrapper ) import GHC.HsToCore.Monad import GHC.HsToCore.GuardedRHSs import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck ( addTyCsDs, covCheckGRHSs ) +import GHC.HsToCore.PmCheck ( addTyCs, covCheckGRHSs ) import GHC.Hs -- lots of things import GHC.Core -- lots of things @@ -151,14 +151,14 @@ dsHsBind dflags b@(FunBind { fun_id = L loc fun , fun_matches = matches , fun_ext = co_fn , fun_tick = tick }) - = do { (args, body) <- addTyCsDs FromSource (hsWrapDictBinders co_fn) $ + = do { (args, body) <- addTyCs FromSource (hsWrapDictBinders co_fn) $ -- FromSource might not be accurate (we don't have any -- origin annotations for things in this module), but at -- worst we do superfluous calls to the pattern match -- oracle. - -- addTyCsDs: Add type evidence to the refinement type + -- addTyCs: Add type evidence to the refinement type -- predicate of the coverage checker - -- See Note [Type and Term Equality Propagation] in "GHC.HsToCore.PmCheck" + -- See Note [Long-distance information] in "GHC.HsToCore.PmCheck" matchWrapper (mkPrefixFunRhs (L loc (idName fun))) Nothing matches @@ -200,11 +200,11 @@ dsHsBind dflags (AbsBinds { abs_tvs = tyvars, abs_ev_vars = dicts , abs_exports = exports , abs_ev_binds = ev_binds , abs_binds = binds, abs_sig = has_sig }) - = do { ds_binds <- addTyCsDs FromSource (listToBag dicts) $ + = do { ds_binds <- addTyCs FromSource (listToBag dicts) $ dsLHsBinds binds - -- addTyCsDs: push type constraints deeper + -- addTyCs: push type constraints deeper -- for inner pattern match check - -- See Check, Note [Type and Term Equality Propagation] + -- See Check, Note [Long-distance information] ; ds_ev_binds <- dsTcEvBinds_s ev_binds ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -31,7 +31,7 @@ import GHC.HsToCore.ListComp import GHC.HsToCore.Utils import GHC.HsToCore.Arrows import GHC.HsToCore.Monad -import GHC.HsToCore.PmCheck ( addTyCsDs, covCheckGRHSs ) +import GHC.HsToCore.PmCheck ( addTyCs, covCheckGRHSs ) import GHC.Types.Name import GHC.Types.Name.Env import GHC.Core.FamInstEnv( topNormaliseType ) @@ -283,7 +283,7 @@ dsExpr hswrap@(XExpr (WrapExpr (HsWrap co_fn e))) HsConLikeOut _ (RealDataCon dc) -> return $ varToCoreExpr (dataConWrapId dc) XExpr (WrapExpr (HsWrap _ _)) -> pprPanic "dsExpr: HsWrap inside HsWrap" (ppr hswrap) HsPar _ _ -> pprPanic "dsExpr: HsPar inside HsWrap" (ppr hswrap) - _ -> addTyCsDs FromSource (hsWrapDictBinders co_fn) $ + _ -> addTyCs FromSource (hsWrapDictBinders co_fn) $ dsExpr e -- See Note [Detecting forced eta expansion] ; wrap' <- dsHsWrapper co_fn ===================================== compiler/GHC/HsToCore/Match.hs ===================================== @@ -770,8 +770,8 @@ matchWrapper ctxt mb_scr (MG { mg_alts = L _ matches -- Each Match will split off one Deltas for its RHSs from this. ; matches_deltas <- if isMatchContextPmChecked dflags origin ctxt then addHsScrutTmCs mb_scr new_vars $ - -- See Note [Type and Term Equality Propagation] - covCheckMatchGroup (DsMatchContext ctxt locn) new_vars matches + -- See Note [Long-distance information] + covCheckMatches (DsMatchContext ctxt locn) new_vars matches else pure (initDeltasMatches matches) ; eqns_info <- zipWithM mk_eqn_info matches matches_deltas @@ -881,7 +881,7 @@ matchSinglePatVar var mb_scrut ctx pat ty match_result -- Pattern match check warnings ; when (isMatchContextPmChecked dflags FromSource ctx) $ addCoreScrutTmCs mb_scrut [var] $ - covCheckPatBind dflags (DsMatchContext ctx locn) var (unLoc pat) + covCheckPatBind (DsMatchContext ctx locn) var (unLoc pat) ; let eqn_info = EqnInfo { eqn_pats = [unLoc (decideBangHood dflags pat)] , eqn_orig = FromSource ===================================== compiler/GHC/HsToCore/PmCheck.hs ===================================== @@ -1,24 +1,49 @@ -{- -Author: George Karachalias - -Pattern Matching Coverage Checking. --} - -{-# LANGUAGE CPP #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE TupleSections #-} -{-# LANGUAGE ViewPatterns #-} -{-# LANGUAGE MultiWayIf #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE NamedFieldPuns #-} - +{-# LANGUAGE CPP #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE TupleSections #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE MultiWayIf #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE NamedFieldPuns #-} + +-- | This module coverage checks pattern matches. It finds +-- +-- * Uncovered patterns, certifying non-exhaustivity +-- * Redundant equations +-- * Equations with an inaccessible right-hand-side +-- +-- The algorithm is based on the paper +-- [Lower Your Guards: A Compositional Pattern-Match Coverage Checker"](https://dl.acm.org/doi/abs/10.1145/3408989) +-- +-- There is an overview Figure 2 in there that's probably helpful. +-- Here is an overview of how it's implemented, which follows the structure of +-- the entry points such as 'covCheckMatches': +-- +-- 1. Desugar source syntax (like 'LMatch') to guard tree variants (like +-- 'GrdMatch'), with one of the desugaring functions (like 'desugarMatch'). +-- Follows Section 3.1 in the paper. +-- 2. Coverage check guard trees (with a function like 'checkMatch') to get a +-- 'CheckResult', containing +-- a. The set of uncovered values, 'cr_uncov' +-- b. And an annotated tree variant (like 'AnnMatch') that captures +-- redundancy and inaccessibility information as 'RedSets' annotations +-- Basically the UA function from Section 5.1. The Normalised Refinement Types +-- Nabla are modeled as 'Deltas' and checked in "GHC.HsToCore.PmCheck.Oracle". +-- 3. Collect redundancy information into a 'CIRB' with a 'CIRBCollector' such +-- as 'collectMatch'. Follows the R function from Figure 6 of the paper. +-- 4. Format and report uncovered patterns and redundant equations ('CIRB') +-- with 'formatReportWarnings'. Basically job of the G function, plus proper +-- pretty printing of the warnings (Section 5.4 of the paper). +-- 5. Return 'Deltas' reaching syntactic sub-components for +-- Note [Long-distance information]. See Section 4.1 of the paper. module GHC.HsToCore.PmCheck ( -- Checking and printing - covCheckPatBind, covCheckMatchGroup, covCheckGRHSs, + covCheckPatBind, covCheckMatches, covCheckGRHSs, isMatchContextPmChecked, - -- See Note [Type and Term Equality Propagation] - addTyCsDs, addCoreScrutTmCs, addHsScrutTmCs + -- See Note [Long-distance information] + addTyCs, addCoreScrutTmCs, addHsScrutTmCs ) where #include "HsVersions.h" @@ -37,7 +62,6 @@ import GHC.Tc.Utils.Zonk (shortCutLit) import GHC.Types.Id import GHC.Core.ConLike import GHC.Types.Name -import GHC.Tc.Instance.Family import GHC.Builtin.Types import GHC.Types.SrcLoc import GHC.Utils.Misc @@ -62,35 +86,135 @@ import GHC.Core.Type import GHC.HsToCore.Utils (isTrueLHsExpr) import GHC.Data.Maybe import qualified GHC.LanguageExtensions as LangExt -import GHC.Utils.Monad (concatMapM) +import GHC.Utils.Monad (concatMapM, mapMaybeM) import Control.Monad (when, forM_, zipWithM) import Data.List (elemIndex) import qualified Data.Semigroup as Semi -import Data.List.NonEmpty (NonEmpty(..)) +import Data.List.NonEmpty ( NonEmpty(..) ) +import qualified Data.List.NonEmpty as NE +import Data.Coerce -{- -This module checks pattern matches for: -\begin{enumerate} - \item Equations that are redundant - \item Equations with inaccessible right-hand-side - \item Exhaustiveness -\end{enumerate} +-- +-- * Exported entry points to the checker +-- -The algorithm is based on the paper: +-- | Check a pattern binding (let, where) for exhaustiveness. +covCheckPatBind :: DsMatchContext -> Id -> Pat GhcTc -> DsM () +-- See Note [covCheckPatBind only checks PatBindRhs] +covCheckPatBind ctxt@(DsMatchContext PatBindRhs loc) var p = do + missing <- getPmDeltas + pat_bind <- desugarPatBind loc var p + tracePm "covCheckPatBind {" (vcat [ppr ctxt, ppr var, ppr p, ppr pat_bind, ppr missing]) + result <- unCA (checkPatBind pat_bind) missing + tracePm "}: " (ppr (cr_uncov result)) + formatReportWarnings collectPatBind ctxt [var] result +covCheckPatBind _ _ _ = pure () - "GADTs Meet Their Match: - Pattern-matching Warnings That Account for GADTs, Guards, and Laziness" +-- | Exhaustive for guard matches, is used for guards in pattern bindings and +-- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. +covCheckGRHSs + :: HsMatchContext GhcRn -- ^ Match context, for warning messages + -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check + -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long + -- distance info +covCheckGRHSs hs_ctxt guards@(GRHSs _ grhss _) = do + let combined_loc = foldl1 combineSrcSpans (map getLoc grhss) + ctxt = DsMatchContext hs_ctxt combined_loc + matches <- desugarGRHSs combined_loc empty guards + missing <- getPmDeltas + tracePm "covCheckGRHSs" (hang (vcat [ppr ctxt + , text "Guards:"]) + 2 + (pprGRHSs hs_ctxt guards $$ ppr missing)) + result <- unCA (checkGRHSs matches) missing + tracePm "}: " (ppr (cr_uncov result)) + formatReportWarnings (collectGRHSs missing) ctxt [] result + +-- | Check a list of syntactic 'Match'es (part of case, functions, etc.), each +-- with a 'Pat' and one or more 'GRHSs': +-- +-- @ +-- f x y | x == y = 1 -- match on x and y with two guarded RHSs +-- | otherwise = 2 +-- f _ _ = 3 -- clause with a single, un-guarded RHS +-- @ +-- +-- Returns one non-empty 'Deltas' for 1.) each pattern of a 'Match' and 2.) +-- each of a 'Match'es 'GRHS' for Note [Long-distance information]. +-- +-- Special case: When there are /no matches/, then the functionassumes it +-- checks and @-XEmptyCase@ with only a single match variable. +-- See Note [Checking EmptyCase]. +covCheckMatches + :: DsMatchContext -- ^ Match context, for warnings messages + -> [Id] -- ^ Match variables, i.e. x and y above + -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches + -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per Match and + -- GRHS, for long distance info. +covCheckMatches ctxt vars matches = do + missing <- getPmDeltas + -- We have to force @missing@ before printing out the trace message, + -- otherwise we get interleaved output from the solver. This function + -- should be strict in @missing@ anyway! + !missing <- getPmDeltas + tracePm "covCheckMatches {" $ + hang (vcat [ppr ctxt, ppr vars, text "Matches:"]) + 2 + (vcat (map ppr matches) $$ ppr missing) + case NE.nonEmpty matches of + Nothing -> do + -- This must be an -XEmptyCase. See Note [Checking EmptyCase] + let var = only vars + empty_case <- desugarEmptyCase var + result <- unCA (checkEmptyCase empty_case) missing + tracePm "}: " (ppr (cr_uncov result)) + [] <$ formatReportWarnings collectEmptyCase ctxt vars result + Just matches -> do + matches <- desugarMatches vars matches + result <- unCA (checkMatchGroup matches) missing + tracePm "}: " (ppr (cr_uncov result)) + NE.toList <$> formatReportWarnings (collectMatchGroup missing) ctxt vars result + +{- Note [covCheckPatBind only checks PatBindRhs] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + at covCheckPatBind@'s sole purpose is to check vanilla pattern bindings, like + at x :: Int; Just x = e@, which is in a @PatBindRhs@ context. +But its caller is also called for individual pattern guards in a @StmtCtxt at . +For example, both pattern guards in @f x y | True <- x, False <- y = ...@ will +go through this function. It makes no sense to do coverage checking there: + * Pattern guards may well fail. Fall-through is not an unrecoverable panic, + but rather behavior the programmer expects, so inexhaustivity should not be + reported. + * Redundancy is already reported for the whole GRHS via one of the other + exported coverage checking functions. Also reporting individual redundant + guards is... redundant. See #17646. +Note that we can't just omit checking of @StmtCtxt@ altogether (by adjusting +'isMatchContextPmChecked'), because that affects the other checking functions, +too. + +Note [Checking EmptyCase] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-XEmptyCase is useful for matching on empty data types like 'Void'. For example, +the following is a complete match: - https://www.microsoft.com/en-us/research/wp-content/uploads/2016/08/gadtpm-acm.pdf + f :: Void -> () + f x = case x of {} -%************************************************************************ -%* * - Pattern Match Check Types -%* * -%************************************************************************ +Really, -XEmptyCase is the only way to write a program that at the same time is +safe (@f _ = error "boom"@ is not because of ⊥), doesn't trigger a warning +(@f !_ = error "inaccessible" has inaccessible RHS) and doesn't turn an +exception into divergence (@f x = f x@). + +Semantically, unlike every other case expression, -XEmptyCase is strict in its +match var x, which rules out ⊥ as an inhabitant. So we add x /~ ⊥ to the +initial Delta and check if there are any values left to match on. -} +-- +-- * Guard language +-- + -- | A very simple language for pattern guards. Let bindings, bang patterns, -- and matching variables against flat constructor patterns. data PmGrd @@ -106,9 +230,9 @@ data PmGrd } -- | @PmBang x@ corresponds to a @seq x True@ guard. - -- If the extra SrcInfo is present, the bang guard came from a source - -- bang pattern, in which case we might want to report it as redundant, - -- see Note [Dead bang patterns]. + -- If the extra 'SrcInfo' is present, the bang guard came from a source + -- bang pattern, in which case we might want to report it as redundant. + -- See Note [Dead bang patterns]. | PmBang { pm_id :: !Id, pm_loc :: !(Maybe SrcInfo) @@ -144,24 +268,118 @@ instance Monoid Precision where mempty = Precise mappend = (Semi.<>) --- | Means by which we identify source location for later pretty-printing --- in a warning message. 'SDoc' for the equation to show, 'Located' for --- the location. +-- +-- * Guard tree language +-- + +-- | Means by which we identify a source construct for later pretty-printing in +-- a warning message. 'SDoc' for the equation to show, 'Located' for the +-- location. type SrcInfo = Located SDoc --- | A representation of the desugaring to 'PmGrd's of all clauses of a --- function definition/pattern match/etc. -data GrdTree - = Rhs !SrcInfo - | Guard !PmGrd !GrdTree - -- ^ @Guard grd t@ will try to match @grd@ and on success continue to match - -- @t at . Falls through if either match fails. Models left-to-right semantics - -- of pattern matching. - | Sequence ![GrdTree] - -- ^ @Sequence (t:ts)@ matches against @t@, and then matches all - -- fallen-through values against @Sequence ts at . Models top-to-bottom semantics - -- of pattern matching. - -- @Sequence []@ always fails; it is useful for Note [Checking EmptyCase]. +-- | A guard tree denoting 'MatchGroup'. +newtype GrdMatchGroup = GrdMatchGroup (NonEmpty GrdMatch) + +-- | A guard tree denoting 'Match'. +data GrdMatch = GrdMatch { gm_pats :: ![PmGrd], gm_grhss :: !(NonEmpty GrdGRHS) } + +-- | A guard tree denoting 'GRHS'. +data GrdGRHS = GrdGRHS { gg_grds :: ![PmGrd], gg_rhs :: !SrcInfo } + +-- | A guard tree denoting an -XEmptyCase. +newtype GrdEmptyCase = GrdEmptyCase { ge_var :: Id } + +-- | A guard tree denoting a pattern binding. +newtype GrdPatBind = + -- just reuse GrdGRHS and pretend its @SrcInfo@ is info on the /pattern/, + -- rather than on the pattern bindings. + GrdPatBind GrdGRHS + +-- | Redundancy sets, used to determine redundancy of RHSs and bang patterns +-- (later digested into a 'CIRB'). +data RedSets + = RedSets + { rs_cov :: !Deltas + -- ^ The /Covered/ set; the set of values reaching a particular program + -- point. + , rs_div :: !Deltas + -- ^ The /Diverging/ set; empty if no match can lead to divergence. + -- If it wasn't empty, we have to turn redundancy warnings into + -- inaccessibility warnings for any subclauses. + , rs_bangs :: !(OrdList (Deltas, SrcInfo)) + -- ^ If any of the 'Deltas' is empty, the corresponding 'SrcInfo' pin-points + -- a bang pattern in source that is redundant. See Note [Dead bang patterns]. + } + +emptyRedSets :: RedSets +-- Semigroup instance would be misleading! +emptyRedSets = RedSets mempty mempty mempty + +-- | An annotated tree denoting 'MatchGroup'. +newtype AnnMatchGroup = AnnMatchGroup (NonEmpty AnnMatch) + +-- | An annotated tree denoting 'Match'. +data AnnMatch = AnnMatch { am_red :: !RedSets, am_grhss :: !(NonEmpty AnnGRHS) } + +-- | An annotated tree denoting 'GRHS'. +data AnnGRHS = AnnGRHS { ag_red :: !RedSets, ag_rhs :: !SrcInfo } + +-- | An annotated tree denoting an -XEmptyCase. +data AnnEmptyCase = AnnEmptyCase + +-- | An annotated tree denoting a pattern binding. +newtype AnnPatBind = AnnPatBind AnnGRHS + +pprSrcInfo :: SrcInfo -> SDoc +pprSrcInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) +pprSrcInfo (L s _) = ppr s + +-- | Format LYG guards as @| True <- x, let x = 42, !z@ +pprLygGuards :: [PmGrd] -> SDoc +pprLygGuards [] = empty +pprLygGuards (g:gs) = fsep (char '|' <+> ppr g : map ((comma <+>) . ppr) gs) + +-- | Format a LYG sequence (e.g. 'Match'es of a 'MatchGroup' or 'GRHSs') as +-- @{ ; ...; }@ +pprLygSequence :: Outputable a => NonEmpty a -> SDoc +pprLygSequence (NE.toList -> as) = + braces (space <> fsep (punctuate semi (map ppr as)) <> space) + +instance Outputable GrdMatchGroup where + ppr (GrdMatchGroup matches) = pprLygSequence matches + +instance Outputable GrdMatch where + ppr (GrdMatch { gm_pats = grds, gm_grhss = grhss }) = + pprLygGuards grds <+> ppr grhss + +instance Outputable GrdGRHS where + ppr (GrdGRHS { gg_grds = grds, gg_rhs = rhs }) = + pprLygGuards grds <+> text "->" <+> pprSrcInfo rhs + +instance Outputable GrdPatBind where + ppr (GrdPatBind GrdGRHS { gg_grds = grds, gg_rhs = bind }) = + ppr bind <+> pprLygGuards grds <+> text "=" <+> text "..." + +instance Outputable GrdEmptyCase where + ppr (GrdEmptyCase { ge_var = var }) = + text " ppr var <> text ">" + +pprRedSets :: RedSets -> SDoc +-- It's useful to change this definition for different verbosity levels in +-- printf-debugging +pprRedSets RedSets { rs_cov = _cov, rs_div = _div, rs_bangs = _bangs } + = empty + +instance Outputable AnnMatchGroup where + ppr (AnnMatchGroup matches) = pprLygSequence matches + +instance Outputable AnnMatch where + ppr (AnnMatch { am_red = red, am_grhss = grhss }) = + pprRedSets red <+> ppr grhss + +instance Outputable AnnGRHS where + ppr (AnnGRHS { ag_red = red, ag_rhs = rhs }) = + pprRedSets red <+> text "->" <+> pprSrcInfo rhs {- Note [Dead bang patterns] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -178,7 +396,7 @@ that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs; see below. We can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable -where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is +where the PmBang appears in 'checkGrd'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. @@ -197,236 +415,9 @@ it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. -} --- | The digest of 'checkGrdTree', representing the annotated pattern-match --- tree. 'extractRedundancyInfo' can figure out redundant and proper --- inaccessible RHSs from this, as well as dead bangs. -data AnnotatedTree - = AccessibleRhs !Deltas !SrcInfo - -- ^ A RHS deemed accessible. The 'Deltas' is the (non-empty) set of covered - -- values. - | InaccessibleRhs !SrcInfo - -- ^ A RHS deemed inaccessible; it covers no value. - | MayDiverge !AnnotatedTree - -- ^ Asserts that the tree may force diverging values, so not all of its - -- clauses can be redundant. - | SequenceAnn !Deltas ![AnnotatedTree] - -- ^ @SequenceAnn inc ts@ mirrors @'Sequence' ts@ for preserving the - -- skeleton of a 'GrdTree's @ts at . It also carries the set of incoming values - -- @inc at . - | RedundantSrcBang !SrcInfo !AnnotatedTree - -- ^ For tracking redundant bangs. See Note [Dead bang patterns] - -pprSrcInfo :: SrcInfo -> SDoc -pprSrcInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) -pprSrcInfo (L s _) = ppr s - -instance Outputable GrdTree where - ppr (Rhs info) = text "->" <+> pprSrcInfo info - -- Format guards as "| True <- x, let x = 42, !z" - ppr g at Guard{} = fsep (prefix (map ppr grds)) <+> ppr t - where - (t, grds) = collect_grds g - collect_grds (Guard grd t) = (grd :) <$> collect_grds t - collect_grds t = (t, []) - prefix [] = [] - prefix (s:sdocs) = char '|' <+> s : map (comma <+>) sdocs - ppr (Sequence []) = text "" - ppr (Sequence ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) - -instance Outputable AnnotatedTree where - ppr (AccessibleRhs _delta info) = parens (ppr _delta) <+> pprSrcInfo info - ppr (InaccessibleRhs info) = text "inaccessible" <+> pprSrcInfo info - ppr (MayDiverge t) = text "div" <+> ppr t - ppr (SequenceAnn _ []) = text "" - ppr (SequenceAnn _ ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) - ppr (RedundantSrcBang l t) = text "redundant bang" <+> pprSrcInfo l <+> ppr t - --- | Lift 'addPmCts' over 'Deltas'. -addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas -addPmCtsDeltas deltas cts = liftDeltasM (\d -> addPmCts d cts) deltas - --- | 'addPmCtsDeltas' a single 'PmCt'. -addPmCtDeltas :: Deltas -> PmCt -> DsM Deltas -addPmCtDeltas deltas ct = addPmCtsDeltas deltas (unitBag ct) - --- | Test if any of the 'Delta's is inhabited. Currently this is pure, because --- we preserve the invariant that there are no uninhabited 'Delta's. But that --- could change in the future, for example by implementing this function in --- terms of @notNull <$> provideEvidence 1 ds at . -isInhabited :: Deltas -> DsM Bool -isInhabited (MkDeltas ds) = pure (not (null ds)) - --- | Pattern-match check result -data CheckResult - = CheckResult - { cr_clauses :: !AnnotatedTree - -- ^ Captures redundancy info for each clause in the original program. - -- (for -Woverlapping-patterns) - , cr_uncov :: !Deltas - -- ^ The set of uncovered values falling out at the bottom. - -- (for -Wincomplete-patterns) - , cr_approx :: !Precision - -- ^ A flag saying whether we ran into the 'maxPmCheckModels' limit for the - -- purpose of suggesting to crank it up in the warning message - } - -instance Outputable CheckResult where - ppr (CheckResult c unc pc) - = text "CheckResult" <+> ppr_precision pc <+> braces (fsep - [ field "clauses" c <> comma - , field "uncov" unc]) - where - ppr_precision Precise = empty - ppr_precision Approximate = text "(Approximate)" - field name value = text name <+> equals <+> ppr value - -{- -%************************************************************************ -%* * - Entry points to the checker: covCheckPatBind and covCheckMatchGroup -%* * -%************************************************************************ --} - --- | Check a pattern binding (let, where) for exhaustiveness. -covCheckPatBind :: DynFlags -> DsMatchContext -> Id -> Pat GhcTc -> DsM () -covCheckPatBind dflags ctxt@(DsMatchContext _ locn) var p = do - -- We only ever need to run this in a context where we need exhaustivity - -- warnings (so not in pattern guards or comprehensions, for example, because - -- they are perfectly fine to fail). - -- Omitting checking this flag emits redundancy warnings twice in obscure - -- cases like #17646. - -- Given the context in which this function is called, it will only ever do - -- something for - -- * PatBindRhs, -Wincomplete-uni-patterns: @let True = False@ - -- * PatBindGuards, -Wincomplete-patterns: @Just x | False = Just 42@ - missing <- getPmDeltas - tracePm "covCheckPatBind" (vcat [ppr ctxt, ppr var, ppr p, ppr missing]) - fam_insts <- dsGetFamInstEnvs - grd_tree <- mkGrdTreeRhs (L locn $ ppr p) <$> translatePat fam_insts var p - res <- checkGrdTree grd_tree missing - dsPmWarn dflags ctxt [var] res - --- | Exhaustive for guard matches, is used for guards in pattern bindings and --- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. -covCheckGRHSs - :: HsMatchContext GhcRn -- ^ Match context, for warning messages - -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check - -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long - -- distance info -covCheckGRHSs hs_ctx guards@(GRHSs _ grhss _) = do - let combinedLoc = foldl1 combineSrcSpans (map getLoc grhss) - dsMatchContext = DsMatchContext hs_ctx combinedLoc - match = L combinedLoc $ - Match { m_ext = noExtField - , m_ctxt = hs_ctx - , m_pats = [] - , m_grhss = guards } - [(_, deltas)] <- covCheckMatchGroup dsMatchContext [] [match] - pure deltas - --- | Check a list of syntactic /match/es (part of case, functions, etc.), each --- with a /pat/ and one or more /grhss/: -- --- @ --- f x y | x == y = 1 -- match on x and y with two guarded RHSs --- | otherwise = 2 --- f _ _ = 3 -- clause with a single, un-guarded RHS --- @ +-- * Desugaring source syntax to guard trees -- --- Returns one 'Deltas' for each GRHS, representing its covered values, or the --- incoming uncovered 'Deltas' (from 'getPmDeltas') if the GRHS is inaccessible. --- Since there is at least one /grhs/ per /match/, the list of 'Deltas' is at --- least as long as the list of matches. -covCheckMatchGroup - :: DsMatchContext -- ^ Match context, for warnings messages - -> [Id] -- ^ Match variables, i.e. x and y above - -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches - -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per RHS, for long - -- distance info. -covCheckMatchGroup ctxt vars matches = do - tracePm "covCheckMatchGroup" (hang (vcat [ppr ctxt - , ppr vars - , text "Matches:"]) - 2 - (vcat (map ppr matches))) - - init_deltas <- getPmDeltas - missing <- case matches of - -- This must be an -XEmptyCase. See Note [Checking EmptyCase] - [] | [var] <- vars -> addPmCtDeltas init_deltas (PmNotBotCt var) - _ -> pure init_deltas - fam_insts <- dsGetFamInstEnvs - grd_tree <- translateMatches fam_insts vars matches - res <- checkGrdTree grd_tree missing - - dflags <- getDynFlags - dsPmWarn dflags ctxt vars res - - return (extractRhsDeltas (cr_clauses res)) - --- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree' for a match --- group. --- For 'AccessibleRhs's, this is stored in the tree node, whereas --- 'InaccessibleRhs's fall back to the supplied original 'Deltas'. --- See @Note [Recovering from unsatisfiable pattern-matching constraints]@. -extractRhsDeltas :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] -extractRhsDeltas = go_matches - where - go_matches :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] - go_matches (SequenceAnn def ts) = map (go_match def) ts -- -XEmptyCase handled here! - go_matches t = pprPanic "extractRhsDeltas.go_matches" (text "Matches must start with SequenceAnn. But was" $$ ppr t) - - go_match :: Deltas -> AnnotatedTree -> (Deltas, NonEmpty Deltas) - -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ - -- is non-empty! - go_match def (SequenceAnn pat ts) = (pat, foldMap1 (text "go_match: empty SequenceAnn") (go_grhss def) ts) - go_match def (MayDiverge t) = go_match def t - go_match def (RedundantSrcBang _ t) = go_match def t - -- Even if there's only a single GRHS, we wrap it in a SequenceAnn for the - -- Deltas covered by the pattern. So the remaining cases are impossible! - go_match _ t = pprPanic "extractRhsDeltas.go_match" (text "Single GRHS must be wrapped in SequenceAnn. But got " $$ ppr t) - - go_grhss :: Deltas -> AnnotatedTree -> NonEmpty Deltas - -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ - -- is non-empty! - go_grhss def (SequenceAnn _ ts) = foldMap1 (text "go_grhss: empty SequenceAnn") (go_grhss def) ts - go_grhss def (MayDiverge t) = go_grhss def t - go_grhss def (RedundantSrcBang _ t) = go_grhss def t - go_grhss _ (AccessibleRhs deltas _) = deltas :| [] - go_grhss def (InaccessibleRhs _) = def :| [] - - foldMap1 msg _ [] = pprPanic "extractRhsDeltas.foldMap1" msg - foldMap1 _ f (x:xs) = foldl' (\acc x -> acc Semi.<> f x) (f x) xs - -{- Note [Checking EmptyCase] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --XEmptyCase is useful for matching on empty data types like 'Void'. For example, -the following is a complete match: - - f :: Void -> () - f x = case x of {} - -Really, -XEmptyCase is the only way to write a program that at the same time is -safe (@f _ = error "boom"@ is not because of ⊥), doesn't trigger a warning -(@f !_ = error "inaccessible" has inaccessible RHS) and doesn't turn an -exception into divergence (@f x = f x@). - -Semantically, unlike every other case expression, -XEmptyCase is strict in its -match var x, which rules out ⊥ as an inhabitant. So we add x /~ ⊥ to the -initial Delta and check if there are any values left to match on. --} - -{- -%************************************************************************ -%* * - Transform source syntax to *our* syntax -%* * -%************************************************************************ --} - --- ----------------------------------------------------------------------- --- * Utilities -- | Smart constructor that eliminates trivial lets mkPmLetVar :: Id -> Id -> GrdVec @@ -459,7 +450,7 @@ mkListGrds a ((x, head_grds):xs) = do -- | Create a 'GrdVec' refining a match variable to a 'PmLit'. mkPmLitGrds :: Id -> PmLit -> DsM GrdVec mkPmLitGrds x (PmLit _ (PmLitString s)) = do - -- We translate String literals to list literals for better overlap reasoning. + -- We desugar String literals to list literals for better overlap reasoning. -- It's a little unfortunate we do this here rather than in -- 'GHC.HsToCore.PmCheck.Oracle.trySolve' and -- 'GHC.HsToCore.PmCheck.Oracle.addRefutableAltCon', but it's so much simpler @@ -477,37 +468,34 @@ mkPmLitGrds x lit = do , pm_con_args = [] } pure [grd] --- ----------------------------------------------------------------------- --- * Transform (Pat Id) into GrdVec - --- | @translatePat _ x pat@ transforms @pat@ into a 'GrdVec', where +-- | @desugarPat _ x pat@ transforms @pat@ into a 'GrdVec', where -- the variable representing the match is @x at . -translatePat :: FamInstEnvs -> Id -> Pat GhcTc -> DsM GrdVec -translatePat fam_insts x pat = case pat of +desugarPat :: Id -> Pat GhcTc -> DsM GrdVec +desugarPat x pat = case pat of WildPat _ty -> pure [] VarPat _ y -> pure (mkPmLetVar (unLoc y) x) - ParPat _ p -> translateLPat fam_insts x p + ParPat _ p -> desugarLPat x p LazyPat _ _ -> pure [] -- like a wildcard BangPat _ p@(L l p') -> -- Add the bang in front of the list, because it will happen before any -- nested stuff. - (PmBang x pm_loc :) <$> translateLPat fam_insts x p - where pm_loc = Just (L l (ppr p')) + (PmBang x pm_loc :) <$> desugarLPat x p + where pm_loc = Just (L l (ppr p')) - -- (x at pat) ==> Translate pat with x as match var and handle impedance + -- (x at pat) ==> Desugar pat with x as match var and handle impedance -- mismatch with incoming match var - AsPat _ (L _ y) p -> (mkPmLetVar y x ++) <$> translateLPat fam_insts y p + AsPat _ (L _ y) p -> (mkPmLetVar y x ++) <$> desugarLPat y p - SigPat _ p _ty -> translateLPat fam_insts x p + SigPat _ p _ty -> desugarLPat x p - -- See Note [Translate CoPats] + -- See Note [Desugar CoPats] -- Generally the translation is -- pat |> co ===> let y = x |> co, pat <- y where y is a match var of pat XPat (CoPat wrapper p _ty) - | isIdHsWrapper wrapper -> translatePat fam_insts x p - | WpCast co <- wrapper, isReflexiveCo co -> translatePat fam_insts x p + | isIdHsWrapper wrapper -> desugarPat x p + | WpCast co <- wrapper, isReflexiveCo co -> desugarPat x p | otherwise -> do - (y, grds) <- translatePatV fam_insts p + (y, grds) <- desugarPatV p wrap_rhs_y <- dsHsWrapper wrapper pure (PmLet y (wrap_rhs_y (Var x)) : grds) @@ -522,13 +510,13 @@ translatePat fam_insts x pat = case pat of -- (fun -> pat) ===> let y = fun x, pat <- y where y is a match var of pat ViewPat _arg_ty lexpr pat -> do - (y, grds) <- translateLPatV fam_insts pat + (y, grds) <- desugarLPatV pat fun <- dsLExpr lexpr pure $ PmLet y (App fun (Var x)) : grds -- list ListPat (ListPatTc _elem_ty Nothing) ps -> - translateListPat fam_insts x ps + desugarListPat x ps -- overloaded list ListPat (ListPatTc elem_ty (Just (pat_ty, to_list))) pats -> do @@ -536,11 +524,11 @@ translatePat fam_insts x pat = case pat of case splitListTyConApp_maybe pat_ty of Just _e_ty | not (xopt LangExt.RebindableSyntax dflags) - -- Just translate it as a regular ListPat - -> translateListPat fam_insts x pats + -- Just desugar it as a regular ListPat + -> desugarListPat x pats _ -> do y <- mkPmId (mkListTy elem_ty) - grds <- translateListPat fam_insts y pats + grds <- desugarListPat y pats rhs_y <- dsSyntaxExpr to_list [Var x] pure $ PmLet y rhs_y : grds @@ -566,7 +554,7 @@ translatePat fam_insts x pat = case pat of , cpt_dicts = dicts } } -> do - translateConPatOut fam_insts x con arg_tys ex_tvs dicts ps + desugarConPatOut x con arg_tys ex_tvs dicts ps NPat ty (L _ olit) mb_neg _ -> do -- See Note [Literal short cut] in "GHC.HsToCore.Match.Literal" @@ -595,46 +583,44 @@ translatePat fam_insts x pat = case pat of mkPmLitGrds x lit TuplePat _tys pats boxity -> do - (vars, grdss) <- mapAndUnzipM (translateLPatV fam_insts) pats + (vars, grdss) <- mapAndUnzipM desugarLPatV pats let tuple_con = tupleDataCon boxity (length vars) pure $ vanillaConGrd x tuple_con vars : concat grdss SumPat _ty p alt arity -> do - (y, grds) <- translateLPatV fam_insts p + (y, grds) <- desugarLPatV p let sum_con = sumDataCon alt arity -- See Note [Unboxed tuple RuntimeRep vars] in GHC.Core.TyCon pure $ vanillaConGrd x sum_con [y] : grds - -- -------------------------------------------------------------------------- - -- Not supposed to happen - SplicePat {} -> panic "Check.translatePat: SplicePat" + SplicePat {} -> panic "Check.desugarPat: SplicePat" --- | 'translatePat', but also select and return a new match var. -translatePatV :: FamInstEnvs -> Pat GhcTc -> DsM (Id, GrdVec) -translatePatV fam_insts pat = do +-- | 'desugarPat', but also select and return a new match var. +desugarPatV :: Pat GhcTc -> DsM (Id, GrdVec) +desugarPatV pat = do x <- selectMatchVar Many pat - grds <- translatePat fam_insts x pat + grds <- desugarPat x pat pure (x, grds) -translateLPat :: FamInstEnvs -> Id -> LPat GhcTc -> DsM GrdVec -translateLPat fam_insts x = translatePat fam_insts x . unLoc +desugarLPat :: Id -> LPat GhcTc -> DsM GrdVec +desugarLPat x = desugarPat x . unLoc --- | 'translateLPat', but also select and return a new match var. -translateLPatV :: FamInstEnvs -> LPat GhcTc -> DsM (Id, GrdVec) -translateLPatV fam_insts = translatePatV fam_insts . unLoc +-- | 'desugarLPat', but also select and return a new match var. +desugarLPatV :: LPat GhcTc -> DsM (Id, GrdVec) +desugarLPatV = desugarPatV . unLoc --- | @translateListPat _ x [p1, ..., pn]@ is basically --- @translateConPatOut _ x $(mkListConPatOuts [p1, ..., pn]>@ without ever +-- | @desugarListPat _ x [p1, ..., pn]@ is basically +-- @desugarConPatOut _ x $(mkListConPatOuts [p1, ..., pn]>@ without ever -- constructing the 'ConPatOut's. -translateListPat :: FamInstEnvs -> Id -> [LPat GhcTc] -> DsM GrdVec -translateListPat fam_insts x pats = do - vars_and_grdss <- traverse (translateLPatV fam_insts) pats +desugarListPat :: Id -> [LPat GhcTc] -> DsM GrdVec +desugarListPat x pats = do + vars_and_grdss <- traverse desugarLPatV pats mkListGrds x vars_and_grdss --- | Translate a constructor pattern -translateConPatOut :: FamInstEnvs -> Id -> ConLike -> [Type] -> [TyVar] +-- | Desugar a constructor pattern +desugarConPatOut :: Id -> ConLike -> [Type] -> [TyVar] -> [EvVar] -> HsConPatDetails GhcTc -> DsM GrdVec -translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case +desugarConPatOut x con univ_tys ex_tvs dicts = \case PrefixCon ps -> go_field_pats (zip [0..] ps) InfixCon p1 p2 -> go_field_pats (zip [0..] [p1,p2]) RecCon (HsRecFields fs _) -> go_field_pats (rec_field_ps fs) @@ -648,7 +634,7 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case where tagged_pat f = (lbl_to_index (getName (hsRecFieldId f)), hsRecFieldArg f) -- Unfortunately the label info is empty when the DataCon wasn't defined - -- with record field labels, hence we translate to field index. + -- with record field labels, hence we desugar to field index. orig_lbls = map flSelector $ conLikeFieldLabels con lbl_to_index lbl = expectJust "lbl_to_index" $ elemIndex lbl orig_lbls @@ -659,10 +645,10 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- the first field of @tagged_pats at . -- See Note [Field match order for RecCon] - -- Translate the mentioned field patterns. We're doing this first to get + -- Desugar the mentioned field patterns. We're doing this first to get -- the Ids for pm_con_args. let trans_pat (n, pat) = do - (var, pvec) <- translateLPatV fam_insts pat + (var, pvec) <- desugarLPatV pat pure ((n, var), pvec) (tagged_vars, arg_grdss) <- mapAndUnzipM trans_pat tagged_pats @@ -688,77 +674,81 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- 1. 2. 3. pure (con_grd : bang_grds ++ arg_grds) --- | Translate a the 'Match'es of a 'MatchGroup' -translateMatches :: FamInstEnvs -> [Id] -> [LMatch GhcTc (LHsExpr GhcTc)] - -> DsM GrdTree -translateMatches fam_insts vars matches = - -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. - -- 'extractRhsDeltas' needs this to recover 'MatchGroup' structure. - Sequence <$> traverse (translateMatch fam_insts vars) matches - --- Translate a single match -translateMatch :: FamInstEnvs -> [Id] -> LMatch GhcTc (LHsExpr GhcTc) - -> DsM GrdTree -translateMatch fam_insts vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do - pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats - grhss' <- translateGRHSs fam_insts match_loc (sep (map ppr pats)) grhss - -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss']) - return (foldr Guard grhss' pats') - -mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree -mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) - -translateGRHSs :: FamInstEnvs -> SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateGRHSs fam_insts match_loc pp_pats grhss = - -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. - -- 'extractRhsDeltas' needs this to recover 'GRHSs' structure. - Sequence <$> traverse (translateLGRHS fam_insts match_loc pp_pats) (grhssGRHSs grhss) - --- | Translate a guarded right-hand side to a single 'GrdTree' -translateLGRHS :: FamInstEnvs -> SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateLGRHS fam_insts match_loc pp_pats (L _loc (GRHS _ gs _)) = - -- _loc points to the match separator (ie =, ->) that comes after the guards.. - mkGrdTreeRhs loc_sdoc <$> concatMapM (translateGuard fam_insts . unLoc) gs - where - loc_sdoc - -- pp_pats is the space-separated pattern of the current Match this - -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . - | null gs = L match_loc pp_pats - | otherwise = L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) - L grd_loc _ = head gs - --- | Translate a guard statement to a 'GrdVec' -translateGuard :: FamInstEnvs -> GuardStmt GhcTc -> DsM GrdVec -translateGuard fam_insts guard = case guard of - BodyStmt _ e _ _ -> translateBoolGuard e - LetStmt _ binds -> translateLet (unLoc binds) - BindStmt _ p e -> translateBind fam_insts p e - LastStmt {} -> panic "translateGuard LastStmt" - ParStmt {} -> panic "translateGuard ParStmt" - TransStmt {} -> panic "translateGuard TransStmt" - RecStmt {} -> panic "translateGuard RecStmt" - ApplicativeStmt {} -> panic "translateGuard ApplicativeLastStmt" - --- | Translate let-bindings -translateLet :: HsLocalBinds GhcTc -> DsM GrdVec -translateLet _binds = return [] - --- | Translate a pattern guard +desugarPatBind :: SrcSpan -> Id -> Pat GhcTc -> DsM GrdPatBind +-- See 'GrdPatBind' for how this simply repurposes GrdGRHS. +desugarPatBind loc var pat = + GrdPatBind . flip GrdGRHS (L loc (ppr pat)) <$> desugarPat var pat + +desugarEmptyCase :: Id -> DsM GrdEmptyCase +desugarEmptyCase var = pure GrdEmptyCase { ge_var = var } + +-- | Desugar the non-empty 'Match'es of a 'MatchGroup'. +desugarMatches :: [Id] -> NonEmpty (LMatch GhcTc (LHsExpr GhcTc)) + -> DsM GrdMatchGroup +desugarMatches vars matches = + GrdMatchGroup <$> traverse (desugarMatch vars) matches + +-- Desugar a single match +desugarMatch :: [Id] -> LMatch GhcTc (LHsExpr GhcTc) -> DsM GrdMatch +desugarMatch vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do + pats' <- concat <$> zipWithM desugarLPat vars pats + grhss' <- desugarGRHSs match_loc (sep (map ppr pats)) grhss + -- tracePm "desugarMatch" (vcat [ppr pats, ppr pats', ppr grhss']) + return GrdMatch { gm_pats = pats', gm_grhss = grhss' } + +desugarGRHSs :: SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM (NonEmpty GrdGRHS) +desugarGRHSs match_loc pp_pats grhss + = traverse (desugarLGRHS match_loc pp_pats) + . expectJust "desugarGRHSs" + . NE.nonEmpty + $ grhssGRHSs grhss + +-- | Desugar a guarded right-hand side to a single 'GrdTree' +desugarLGRHS :: SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdGRHS +desugarLGRHS match_loc pp_pats (L _loc (GRHS _ gs _)) = do + -- _loc points to the match separator (ie =, ->) that comes after the guards. + -- Hence we have to pass in the match_loc, which we use in case that the RHS + -- is unguarded. + -- pp_pats is the space-separated pattern of the current Match this + -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . + let rhs_info = case gs of + [] -> L match_loc pp_pats + (L grd_loc _):_ -> L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) + grds <- concatMapM (desugarGuard . unLoc) gs + pure GrdGRHS { gg_grds = grds, gg_rhs = rhs_info } + +-- | Desugar a guard statement to a 'GrdVec' +desugarGuard :: GuardStmt GhcTc -> DsM GrdVec +desugarGuard guard = case guard of + BodyStmt _ e _ _ -> desugarBoolGuard e + LetStmt _ binds -> desugarLet (unLoc binds) + BindStmt _ p e -> desugarBind p e + LastStmt {} -> panic "desugarGuard LastStmt" + ParStmt {} -> panic "desugarGuard ParStmt" + TransStmt {} -> panic "desugarGuard TransStmt" + RecStmt {} -> panic "desugarGuard RecStmt" + ApplicativeStmt {} -> panic "desugarGuard ApplicativeLastStmt" + +-- | Desugar let-bindings +desugarLet :: HsLocalBinds GhcTc -> DsM GrdVec +desugarLet _binds = return [] + +-- | Desugar a pattern guard -- @pat <- e ==> let x = e; @ -translateBind :: FamInstEnvs -> LPat GhcTc -> LHsExpr GhcTc -> DsM GrdVec -translateBind fam_insts p e = dsLExpr e >>= \case +desugarBind :: LPat GhcTc -> LHsExpr GhcTc -> DsM GrdVec +desugarBind p e = dsLExpr e >>= \case Var y | Nothing <- isDataConId_maybe y -- RHS is a variable, so that will allow us to omit the let - -> translateLPat fam_insts y p + -> desugarLPat y p rhs -> do - (x, grds) <- translateLPatV fam_insts p + (x, grds) <- desugarLPatV p pure (PmLet x rhs : grds) --- | Translate a boolean guard +-- | Desugar a boolean guard -- @e ==> let x = e; True <- x@ -translateBoolGuard :: LHsExpr GhcTc -> DsM GrdVec -translateBoolGuard e +desugarBoolGuard :: LHsExpr GhcTc -> DsM GrdVec +desugarBoolGuard e | isJust (isTrueLHsExpr e) = return [] -- The formal thing to do would be to generate (True <- True) -- but it is trivial to solve so instead we give back an empty @@ -803,7 +793,7 @@ for a pattern match appear matter. Consider a situation similar to T5117: f (0:_) = () f (0:[]) = () -The latter clause is clearly redundant. Yet if we translate the second clause as +The latter clause is clearly redundant. Yet if we desugar the second clause as [x:xs' <- xs, [] <- xs', 0 <- x] @@ -815,52 +805,11 @@ translation would have been And we have to take in the guards on list cells into @mkListGrds at . -Note [Countering exponential blowup] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Precise pattern match exhaustiveness checking is necessarily exponential in -the size of some input programs. We implement a counter-measure in the form of -the -fmax-pmcheck-models flag, limiting the number of Deltas we check against -each pattern by a constant. - -How do we do that? Consider - - f True True = () - f True True = () - -And imagine we set our limit to 1 for the sake of the example. The first clause -will be checked against the initial Delta, {}. Doing so will produce an -Uncovered set of size 2, containing the models {x/~True} and {x~True,y/~True}. -Also we find the first clause to cover the model {x~True,y~True}. - -But the Uncovered set we get out of the match is too huge! We somehow have to -ensure not to make things worse as they are already, so we continue checking -with a singleton Uncovered set of the initial Delta {}. Why is this -sound (wrt. notion of the GADTs Meet their Match paper)? Well, it basically -amounts to forgetting that we matched against the first clause. The values -represented by {} are a superset of those represented by its two refinements -{x/~True} and {x~True,y/~True}. - -This forgetfulness becomes very apparent in the example above: By continuing -with {} we don't detect the second clause as redundant, as it again covers the -same non-empty subset of {}. So we don't flag everything as redundant anymore, -but still will never flag something as redundant that isn't. - -For exhaustivity, the converse applies: We will report @f@ as non-exhaustive -and report @f _ _@ as missing, which is a superset of the actual missing -matches. But soundness means we will never fail to report a missing match. - -This mechanism is implemented in 'throttle'. - -Guards are an extreme example in this regard, with #11195 being a particularly -dreadful example: Since their RHS are often pretty much unique, we split on a -variable (the one representing the RHS) that doesn't occur anywhere else in the -program, so we don't actually get useful information out of that split! - -Note [Translate CoPats] +Note [Desugar CoPats] ~~~~~~~~~~~~~~~~~~~~~~~ -The pattern match checker did not know how to handle coerced patterns `CoPat` -efficiently, which gave rise to #11276. The original approach translated -`CoPat`s: +The pattern match checker did not know how to handle coerced patterns +`CoPat` efficiently, which gave rise to #11276. The original approach +desugared `CoPat`s: pat |> co ===> x (pat <- (x |> co)) @@ -875,108 +824,92 @@ a lot of false warnings. But we can check whether the coercion is a hole or if it is just refl, in which case we can drop it. - -%************************************************************************ -%* * - Utilities for Pattern Match Checking -%* * -%************************************************************************ -} --- ---------------------------------------------------------------------------- --- * Basic utilities - -{- -Note [Extensions to GADTs Meet Their Match] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The GADTs Meet Their Match paper presents the formalism that GHC's coverage -checker adheres to. Since the paper's publication, there have been some -additional features added to the coverage checker which are not described in -the paper. This Note serves as a reference for these new features. - -* Value abstractions are severely simplified to the point where they are just - variables. The information about the shape of a variable is encoded in - the oracle state 'Delta' instead. -* Handling of uninhabited fields like `!Void`. - See Note [Strict argument type constraints] in GHC.HsToCore.PmCheck.Oracle. -* Efficient handling of literal splitting, large enumerations and accurate - redundancy warnings for `COMPLETE` groups through the oracle. - -Note [Filtering out non-matching COMPLETE sets] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Currently, conlikes in a COMPLETE set are simply grouped by the -type constructor heading the return type. This is nice and simple, but it does -mean that there are scenarios when a COMPLETE set might be incompatible with -the type of a scrutinee. For instance, consider (from #14135): - - data Foo a = Foo1 a | Foo2 a - - pattern MyFoo2 :: Int -> Foo Int - pattern MyFoo2 i = Foo2 i - - {-# COMPLETE Foo1, MyFoo2 #-} - - f :: Foo a -> a - f (Foo1 x) = x - -`f` has an incomplete pattern-match, so when choosing which constructors to -report as unmatched in a warning, GHC must choose between the original set of -data constructors {Foo1, Foo2} and the COMPLETE set {Foo1, MyFoo2}. But observe -that GHC shouldn't even consider the COMPLETE set as a possibility: the return -type of MyFoo2, Foo Int, does not match the type of the scrutinee, Foo a, since -there's no substitution `s` such that s(Foo Int) = Foo a. - -To ensure that GHC doesn't pick this COMPLETE set, it checks each pattern -synonym constructor's return type matches the type of the scrutinee, and if one -doesn't, then we remove the whole COMPLETE set from consideration. - -One might wonder why GHC only checks /pattern synonym/ constructors, and not -/data/ constructors as well. The reason is because that the type of a -GADT constructor very well may not match the type of a scrutinee, and that's -OK. Consider this example (from #14059): - - data SBool (z :: Bool) where - SFalse :: SBool False - STrue :: SBool True - - pattern STooGoodToBeTrue :: forall (z :: Bool). () - => z ~ True - => SBool z - pattern STooGoodToBeTrue = STrue - {-# COMPLETE SFalse, STooGoodToBeTrue #-} - - wobble :: SBool z -> Bool - wobble STooGoodToBeTrue = True - -In the incomplete pattern match for `wobble`, we /do/ want to warn that SFalse -should be matched against, even though its type, SBool False, does not match -the scrutinee type, SBool z. - -SG: Another angle at this is that the implied constraints when we instantiate -universal type variables in the return type of a GADT will lead to *provided* -thetas, whereas when we instantiate the return type of a pattern synonym that -corresponds to a *required* theta. See Note [Pattern synonym result type] in -PatSyn. Note how isValidCompleteMatches will successfully filter out - - pattern Just42 :: Maybe Int - pattern Just42 = Just 42 - -But fail to filter out the equivalent - - pattern Just'42 :: (a ~ Int) => Maybe a - pattern Just'42 = Just 42 - -Which seems fine as far as tcMatchTy is concerned, but it raises a few eye -brows. --} +-- +-- * Coverage checking guard trees into annotated trees +-- -{- -%************************************************************************ -%* * - Heart of the algorithm: checkGrdTree -%* * -%************************************************************************ --} +-- | Pattern-match coverage check result +data CheckResult a + = CheckResult + { cr_ret :: !a + -- ^ A hole for redundancy info and covered sets. + , cr_uncov :: !Deltas + -- ^ The set of uncovered values falling out at the bottom. + -- (for -Wincomplete-patterns, but also important state for the algorithm) + , cr_approx :: !Precision + -- ^ A flag saying whether we ran into the 'maxPmCheckModels' limit for the + -- purpose of suggesting to crank it up in the warning message. Writer state. + } deriving Functor + +instance Outputable a => Outputable (CheckResult a) where + ppr (CheckResult c unc pc) + = text "CheckResult" <+> ppr_precision pc <+> braces (fsep + [ field "ret" c <> comma + , field "uncov" unc]) + where + ppr_precision Precise = empty + ppr_precision Approximate = text "(Approximate)" + field name value = text name <+> equals <+> ppr value + +-- | Lift 'addPmCts' over 'Deltas'. +addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas +addPmCtsDeltas deltas cts = liftDeltasM (\d -> addPmCts d cts) deltas + +-- | 'addPmCtsDeltas' for a single 'PmCt'. +addPmCtDeltas :: Deltas -> PmCt -> DsM Deltas +addPmCtDeltas deltas ct = addPmCtsDeltas deltas (unitBag ct) + +-- | Test if any of the 'Delta's is inhabited. Currently this is pure, because +-- we preserve the invariant that there are no uninhabited 'Delta's. But that +-- could change in the future, for example by implementing this function in +-- terms of @notNull <$> provideEvidence 1 ds at . +isInhabited :: Deltas -> DsM Bool +isInhabited (MkDeltas ds) = pure (not (null ds)) + +-- | Coverage checking action. Can be composed 'leftToRight' or 'topToBottom'. +newtype CheckAction a = CA { unCA :: Deltas -> DsM (CheckResult a) } + deriving Functor + +-- | Composes 'CheckAction's top-to-bottom: +-- If a value falls through the resulting action, then it must fall through the +-- first action and then through the second action. +-- If a value matches the resulting action, then it either matches the +-- first action or matches the second action. +-- Basically the semantics of the LYG branching construct. +topToBottom :: (top -> bot -> ret) + -> CheckAction top + -> CheckAction bot + -> CheckAction ret +topToBottom f (CA top) (CA bot) = CA $ \inc -> do + t <- top inc + b <- bot (cr_uncov t) + pure CheckResult { cr_ret = f (cr_ret t) (cr_ret b) + , cr_uncov = cr_uncov b + , cr_approx = cr_approx t Semi.<> cr_approx b } + + +-- | Composes 'CheckAction's left-to-right: +-- If a value falls through the resulting action, then it either falls through the +-- first action or through the second action. +-- If a value matches the resulting action, then it must match the first action +-- and then match the second action. +-- Basically the semantics of the LYG guard construct. +leftToRight :: (RedSets -> right -> ret) + -> CheckAction RedSets + -> CheckAction right + -> CheckAction ret +leftToRight f (CA left) (CA right) = CA $ \inc -> do + l <- left inc + r <- right (rs_cov (cr_ret l)) + limit <- maxPmCheckModels <$> getDynFlags + let uncov = cr_uncov l Semi.<> cr_uncov r + -- See Note [Countering exponential blowup] + let (prec', uncov') = throttle limit inc uncov + pure CheckResult { cr_ret = f (cr_ret l) (cr_ret r) + , cr_uncov = uncov' + , cr_approx = prec' Semi.<> cr_approx l Semi.<> cr_approx r } -- | @throttle limit old new@ returns @old@ if the number of 'Delta's in @new@ -- is exceeding the given @limit@ and the @old@ number of 'Delta's. @@ -994,237 +927,241 @@ conMatchForces (PmAltConLike (RealDataCon dc)) | isNewTyCon (dataConTyCon dc) = False conMatchForces _ = True --- | Makes sure that we only wrap a single 'MayDiverge' around an --- 'AnnotatedTree', purely for esthetic reasons. -mayDiverge :: AnnotatedTree -> AnnotatedTree -mayDiverge a@(MayDiverge _) = a -mayDiverge a = MayDiverge a - --- | Computes two things: --- --- * The set of uncovered values not matched by any of the clauses of the --- 'GrdTree'. Note that 'PmCon' guards are the only way in which values --- fall through from one 'Many' branch to the next. --- * An 'AnnotatedTree' that contains divergence and inaccessibility info --- for all clauses. Will be fed to 'extractRedundancyInfo' for --- presenting redundant and proper innaccessible RHSs, as well as dead --- bangs to the user. -checkGrdTree' :: GrdTree -> Deltas -> DsM CheckResult --- RHS: Check that it covers something and wrap Inaccessible if not -checkGrdTree' (Rhs sdoc) deltas = do - is_covered <- isInhabited deltas - let clauses - | is_covered = AccessibleRhs deltas sdoc - | otherwise = InaccessibleRhs sdoc - pure CheckResult - { cr_clauses = clauses - , cr_uncov = MkDeltas emptyBag - , cr_approx = Precise } --- let x = e: Refine with x ~ e -checkGrdTree' (Guard (PmLet x e) tree) deltas = do - deltas' <- addPmCtDeltas deltas (PmCoreCt x e) - checkGrdTree' tree deltas' --- Bang x: Diverge on x ~ ⊥, refine with x /~ ⊥ -checkGrdTree' (Guard (PmBang x src_bang_info) tree) deltas = do - has_diverged <- addPmCtDeltas deltas (PmBotCt x) >>= isInhabited - deltas' <- addPmCtDeltas deltas (PmNotBotCt x) - res <- checkGrdTree' tree deltas' - let clauses - | not has_diverged - , Just info <- src_bang_info - = RedundantSrcBang info (cr_clauses res) - | has_diverged - = mayDiverge (cr_clauses res) - | otherwise -- won't diverge and it wasn't a source bang - = cr_clauses res - - pure res{ cr_clauses = clauses } - --- Con: Diverge on x ~ ⊥, fall through on x /~ K and refine with x ~ K ys --- and type info -checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do - has_diverged <- - if conMatchForces con - then addPmCtDeltas deltas (PmBotCt x) >>= isInhabited - else pure False - unc_this <- addPmCtDeltas deltas (PmNotConCt x con) - deltas' <- addPmCtsDeltas deltas $ - listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args - -- tracePm "checkGrdTree:Con" (ppr deltas $$ ppr x $$ ppr con $$ ppr dicts $$ ppr deltas') - CheckResult tree' unc_inner prec <- checkGrdTree' tree deltas' - limit <- maxPmCheckModels <$> getDynFlags - let (prec', unc') = throttle limit deltas (unc_this Semi.<> unc_inner) - pure CheckResult - { cr_clauses = applyWhen has_diverged mayDiverge tree' - , cr_uncov = unc' - , cr_approx = prec Semi.<> prec' } --- Sequence: Thread residual uncovered sets from equation to equation -checkGrdTree' (Sequence ts) init_unc = go [] init_unc Precise ts +-- First the functions that correspond to checking LYG primitives: + +checkSequence :: (grdtree -> CheckAction anntree) -> NonEmpty grdtree -> CheckAction (NonEmpty anntree) +-- The implementation is pretty similar to +-- @traverse1 :: Apply f => (a -> f b) -> NonEmpty a -> f (NonEmpty b)@ +checkSequence act (t:|[]) = (:|[]) <$> act t +checkSequence act (t1:|(t2:ts)) = + topToBottom (NE.<|) (act t1) (checkSequence act (t2:|ts)) + +checkGrd :: PmGrd -> CheckAction RedSets +checkGrd grd = CA $ \inc -> case grd of + -- let x = e: Refine with x ~ e + PmLet x e -> do + matched <- addPmCtDeltas inc (PmCoreCt x e) + pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched } + , cr_uncov = mempty + , cr_approx = Precise } + -- Bang x _: Diverge on x ~ ⊥, refine with x /~ ⊥ + PmBang x mb_info -> do + div <- addPmCtDeltas inc (PmBotCt x) + matched <- addPmCtDeltas inc (PmNotBotCt x) + -- See Note [Dead bang patterns] + -- mb_info = Just info <==> PmBang originates from bang pattern in source + let bangs | Just info <- mb_info = unitOL (div, info) + | otherwise = NilOL + pure CheckResult { cr_ret = RedSets { rs_cov = matched, rs_div = div, rs_bangs = bangs } + , cr_uncov = mempty + , cr_approx = Precise } + -- Con: Diverge on x ~ ⊥, fall through on x /~ K and refine with x ~ K ys + -- and type info + PmCon x con tvs dicts args -> do + div <- if conMatchForces con + then addPmCtDeltas inc (PmBotCt x) + else pure mempty + uncov <- addPmCtDeltas inc (PmNotConCt x con) + matched <- addPmCtsDeltas inc $ + listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args + -- tracePm "checkGrd:Con" (ppr inc $$ ppr x $$ ppr con $$ ppr dicts $$ ppr matched) + pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched, rs_div = div } + , cr_uncov = uncov + , cr_approx = Precise } + +checkGrds :: [PmGrd] -> CheckAction RedSets +checkGrds [] = CA $ \inc -> + pure CheckResult { cr_ret = emptyRedSets { rs_cov = inc } + , cr_uncov = mempty + , cr_approx = Precise } +checkGrds (g:grds) = leftToRight merge (checkGrd g) (checkGrds grds) where - -- | Accumulates a CheckResult. Its type is more like - -- @CheckResult -> [GrdTree] -> CheckResult@, but cr_clauses is a single - -- 'AnnotatedTree', not a list thereof. Hence 3 parameters to thread the - -- fields. - go :: [AnnotatedTree] -> Deltas -> Precision -> [GrdTree] -> DsM CheckResult - -- No cases left: Fall through for all values - go ts' unc prec [] = pure CheckResult - { cr_clauses = SequenceAnn init_unc (reverse ts') - , cr_uncov = unc - , cr_approx = prec } - go ts' unc prec (t:ts) = do - CheckResult t' unc_1 prec_t <- checkGrdTree' t unc - go (t':ts') unc_1 (prec_t Semi.<> prec) ts - --- | Print diagnostic info and actually call 'checkGrdTree''. -checkGrdTree :: GrdTree -> Deltas -> DsM CheckResult -checkGrdTree guards deltas = do - tracePm "checkGrdTree {" $ vcat [ ppr guards - , ppr deltas ] - res <- checkGrdTree' guards deltas - tracePm "checkGrdTree }:" (ppr res) -- braces are easier to match by tooling - return res - --- ---------------------------------------------------------------------------- --- * Propagation of term constraints inwards when checking nested matches - -{- Note [Type and Term Equality Propagation] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -When checking a match it would be great to have all type and term information -available so we can get more precise results. For this reason we have functions -`addDictsDs' and `addTmVarCsDs' in GHC.HsToCore.Monad that store in the -environment type and term constraints (respectively) as we go deeper. - -The type constraints we propagate inwards are collected by `collectEvVarsPats' -in GHC.Hs.Pat. This handles bug #4139 ( see example - https://gitlab.haskell.org/ghc/ghc/snippets/672 ) -where this is needed. - -For term equalities we do less, we just generate equalities for HsCase. For -example we accurately give 2 redundancy warnings for the marked cases: - -f :: [a] -> Bool -f x = case x of - - [] -> case x of -- brings (x ~ []) in scope - [] -> True - (_:_) -> False -- can't happen - - (_:_) -> case x of -- brings (x ~ (_:_)) in scope - (_:_) -> True - [] -> False -- can't happen - -Functions `add*ScrutTmCs' is responsible for generating -these constraints. --} + merge ri_g ri_grds = -- This operation would /not/ form a Semigroup! + RedSets { rs_cov = rs_cov ri_grds + , rs_div = rs_div ri_g Semi.<> rs_div ri_grds + , rs_bangs = rs_bangs ri_g Semi.<> rs_bangs ri_grds } --- | Locally update 'dsl_deltas' with the given action, but defer evaluation --- with 'unsafeInterleaveM' in order not to do unnecessary work. -locallyExtendPmDelta :: (Deltas -> DsM Deltas) -> DsM a -> DsM a -locallyExtendPmDelta ext k = do - deltas <- getPmDeltas - deltas' <- unsafeInterleaveM $ do - deltas' <- ext deltas - inh <- isInhabited deltas' - -- If adding a constraint would lead to a contradiction, don't add it. - -- See @Note [Recovering from unsatisfiable pattern-matching constraints]@ - -- for why this is done. - if inh - then pure deltas' - else pure deltas - updPmDeltas deltas' k +checkMatchGroup :: GrdMatchGroup -> CheckAction AnnMatchGroup +checkMatchGroup (GrdMatchGroup matches) = + AnnMatchGroup <$> checkSequence checkMatch matches --- | Add in-scope type constraints if the coverage checker might run and then --- run the given action. -addTyCsDs :: Origin -> Bag EvVar -> DsM a -> DsM a -addTyCsDs origin ev_vars m = do - dflags <- getDynFlags - applyWhen (needToRunPmCheck dflags origin) - (locallyExtendPmDelta (\deltas -> addPmCtsDeltas deltas (PmTyCt . evVarPred <$> ev_vars))) - m +checkMatch :: GrdMatch -> CheckAction AnnMatch +checkMatch (GrdMatch { gm_pats = grds, gm_grhss = grhss }) = + leftToRight AnnMatch (checkGrds grds) (checkGRHSs grhss) --- | Add equalities for the 'CoreExpr' scrutinee to the local 'DsM' environment --- when checking a case expression: --- case e of x { matches } --- When checking matches we record that (x ~ e) where x is the initial --- uncovered. All matches will have to satisfy this equality. -addCoreScrutTmCs :: Maybe CoreExpr -> [Id] -> DsM a -> DsM a -addCoreScrutTmCs Nothing _ k = k -addCoreScrutTmCs (Just scr) [x] k = - flip locallyExtendPmDelta k $ \deltas -> - addPmCtsDeltas deltas (unitBag (PmCoreCt x scr)) -addCoreScrutTmCs _ _ _ = panic "addCoreScrutTmCs: scrutinee, but more than one match id" +checkGRHSs :: NonEmpty GrdGRHS -> CheckAction (NonEmpty AnnGRHS) +checkGRHSs = checkSequence checkGRHS --- | 'addCoreScrutTmCs', but desugars the 'LHsExpr' first. -addHsScrutTmCs :: Maybe (LHsExpr GhcTc) -> [Id] -> DsM a -> DsM a -addHsScrutTmCs Nothing _ k = k -addHsScrutTmCs (Just scr) vars k = do - scr_e <- dsLExpr scr - addCoreScrutTmCs (Just scr_e) vars k +checkGRHS :: GrdGRHS -> CheckAction AnnGRHS +checkGRHS (GrdGRHS { gg_grds = grds, gg_rhs = rhs_info }) = + flip AnnGRHS rhs_info <$> checkGrds grds -{- -%************************************************************************ -%* * - Pretty printing of exhaustiveness/redundancy check warnings -%* * -%************************************************************************ --} +checkEmptyCase :: GrdEmptyCase -> CheckAction AnnEmptyCase +checkEmptyCase (GrdEmptyCase { ge_var = var }) = CA $ \inc -> do + unc <- addPmCtDeltas inc (PmNotBotCt var) + pure CheckResult { cr_ret = AnnEmptyCase, cr_uncov = unc, cr_approx = mempty } --- | Check whether any part of pattern match checking is enabled for this --- 'HsMatchContext' (does not matter whether it is the redundancy check or the --- exhaustiveness check). -isMatchContextPmChecked :: DynFlags -> Origin -> HsMatchContext id -> Bool -isMatchContextPmChecked dflags origin kind - | isGenerated origin - = False - | otherwise - = overlapping dflags kind || exhaustive dflags kind +checkPatBind :: GrdPatBind -> CheckAction AnnPatBind +checkPatBind = coerce checkGRHS --- | Return True when any of the pattern match warnings ('allPmCheckWarnings') --- are enabled, in which case we need to run the pattern match checker. -needToRunPmCheck :: DynFlags -> Origin -> Bool -needToRunPmCheck dflags origin - | isGenerated origin - = False - | otherwise - = notNull (filter (`wopt` dflags) allPmCheckWarnings) +{- Note [Countering exponential blowup] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Precise pattern match exhaustiveness checking is necessarily exponential in +the size of some input programs. We implement a counter-measure in the form of +the -fmax-pmcheck-models flag, limiting the number of Deltas we check against +each pattern by a constant. + +How do we do that? Consider + + f True True = () + f True True = () + +And imagine we set our limit to 1 for the sake of the example. The first clause +will be checked against the initial Delta, {}. Doing so will produce an +Uncovered set of size 2, containing the models {x/~True} and {x~True,y/~True}. +Also we find the first clause to cover the model {x~True,y~True}. + +But the Uncovered set we get out of the match is too huge! We somehow have to +ensure not to make things worse as they are already, so we continue checking +with a singleton Uncovered set of the initial Delta {}. Why is this +sound (wrt. the notion in GADTs Meet Their Match)? Well, it basically amounts +to forgetting that we matched against the first clause. The values represented +by {} are a superset of those represented by its two refinements {x/~True} and +{x~True,y/~True}. + +This forgetfulness becomes very apparent in the example above: By continuing +with {} we don't detect the second clause as redundant, as it again covers the +same non-empty subset of {}. So we don't flag everything as redundant anymore, +but still will never flag something as redundant that isn't. --- | A type for organising information to be used in warnings. -data RedundancyInfo - = RedundancyInfo - { redundant_rhss :: ![SrcInfo] - , inaccessible_rhss :: ![SrcInfo] - , redundant_bangs :: ![Located SDoc] +For exhaustivity, the converse applies: We will report @f@ as non-exhaustive +and report @f _ _@ as missing, which is a superset of the actual missing +matches. But soundness means we will never fail to report a missing match. + +This mechanism is implemented in 'throttle'. + +Guards are an extreme example in this regard, with #11195 being a particularly +dreadful example: Since their RHS are often pretty much unique, we split on a +variable (the one representing the RHS) that doesn't occur anywhere else in the +program, so we don't actually get useful information out of that split! +-} + +-- +-- * Collecting redundancy information +-- + +-- | The result of redundancy checking: +-- * RHSs classified as /C/overed, /I/naccessible and /R/edundant +-- * And redundant (B)ang patterns. +data CIRB + = CIRB + { cirb_cov :: !(OrdList SrcInfo) + , cirb_inacc :: !(OrdList SrcInfo) + , cirb_red :: !(OrdList SrcInfo) + , cirb_bangs :: !(OrdList SrcInfo) } -extractRedundancyInfo :: AnnotatedTree -> RedundancyInfo -extractRedundancyInfo tree = - RedundancyInfo { redundant_rhss = fromOL ol_red - , inaccessible_rhss = fromOL ol_inacc - , redundant_bangs = fromOL ol_bangs } - where - (_ol_acc, ol_inacc, ol_red, ol_bangs) = go tree - -- | Collects - -- 1. accessible RHSs - -- 2. proper inaccessible RHSs (so we can't delete them) - -- 3. hypothetically redundant RHSs (so not only inaccessible, but we can - -- even safely delete the equation without altering semantics) - -- 4. 'Dead' bangs from the source, collected to be warned about - -- See Note [Determining inaccessible clauses] - -- See Note [Dead bang patterns] - go :: AnnotatedTree -> (OrdList SrcInfo, OrdList SrcInfo, OrdList SrcInfo, OrdList SrcInfo) - go (AccessibleRhs _ info) = (unitOL info, nilOL, nilOL , nilOL) - go (InaccessibleRhs info) = (nilOL, nilOL, unitOL info, nilOL) -- presumably redundant - go (MayDiverge t) = case go t of - -- See Note [Determining inaccessible clauses] - (acc, inacc, red, bs) - | isNilOL acc && isNilOL inacc -> (nilOL, red, nilOL, bs) - res -> res - go (SequenceAnn _ ts) = foldMap go ts - go (RedundantSrcBang l t) = case go t of - -- See Note [Dead bang patterns] - res@(acc, inacc, _, _) - | isNilOL acc, isNilOL inacc -> res - | otherwise -> (nilOL, nilOL, nilOL, unitOL l) Semi.<> res +instance Semigroup CIRB where + CIRB a b c d <> CIRB e f g h = CIRB (a <> e) (b <> f) (c <> g) (d <> h) + where (<>) = (Semi.<>) + +instance Monoid CIRB where + mempty = CIRB mempty mempty mempty mempty + +markAllRedundant :: CIRB -> CIRB +markAllRedundant CIRB { cirb_cov = cov, cirb_inacc = inacc, cirb_red = red } = + mempty { cirb_red = cov Semi.<> inacc Semi.<> red } + +-- See Note [Determining inaccessible clauses] +ensureOneNotRedundant :: CIRB -> CIRB +ensureOneNotRedundant ci = case ci of + CIRB { cirb_cov = NilOL, cirb_inacc = NilOL, cirb_red = ConsOL r rs } + -> ci { cirb_inacc = unitOL r, cirb_red = rs } + _ -> ci + +-- | Only adds the redundant bangs to the @CIRB@ if there is at least one +-- non-redundant 'SrcInfo'. There is no point in remembering a redundant bang +-- if the whole match is redundant! +addRedundantBangs :: OrdList SrcInfo -> CIRB -> CIRB +addRedundantBangs _red_bangs cirb at CIRB { cirb_cov = NilOL, cirb_inacc = NilOL } = + cirb +addRedundantBangs red_bangs cirb = + cirb { cirb_bangs = cirb_bangs cirb Semi.<> red_bangs } + +-- | A function that walks along an annotated tree @ann@ and extracts two kinds +-- of coverage info: +-- +-- 1. A 'CIRB', classifying every encountered RHS in the tree as +-- redundant, inaccessible or covered. +-- 2. A piece of long-distance information @ldi@, consisting of a +-- nesting of 'Deltas' mirroring tree structure. +-- For example, 'collectMatchGroup' operates on a Match Group and thus +-- returns a list of 'Deltas' for the pattern part of each Match, as well as +-- a further nested list of 'Deltas' for each of the GRHS of the Match. +type CIRBCollector ann ldi = ann -> DsM (CIRB, ldi) + +-- | Checks the 'Deltas' in a 'RedSets' for inhabitants and returns +-- 1. Whether the Covered set was inhabited +-- 2. Whether the Diverging set was inhabited +-- 3. The new inhabited Covered set for long-distance information. +-- See Note [Recovering from unsatisfiable pattern-matching constraints]. +-- 4. All source bangs whose 'Deltas' were empty, which means they are +-- redundant. +testRedSets :: Deltas -> RedSets -> DsM (Bool, Bool, Deltas, OrdList SrcInfo) +testRedSets ldi RedSets { rs_cov = cov, rs_div = div, rs_bangs = bangs } = do + is_covered <- isInhabited cov + may_diverge <- isInhabited div + red_bangs <- flip mapMaybeM (fromOL bangs) $ \(deltas, bang) -> do + isInhabited deltas >>= \case + True -> pure Nothing + False -> pure (Just bang) + -- See Note [Recovering from unsatisfiable pattern-matching constraints] + -- Deltas for long-distance info: Use (non-empty!) fallback ldi if Covered + -- set was empty + let ldi' + | is_covered = cov + | otherwise = ldi + pure (is_covered, may_diverge, ldi', toOL red_bangs) + +collectMatchGroup :: Deltas -> CIRBCollector AnnMatchGroup (NonEmpty (Deltas, NonEmpty Deltas)) +collectMatchGroup ldi (AnnMatchGroup matches) = do + (cirbs, ldis) <- NE.unzip <$> traverse (collectMatch ldi) matches + pure (Semi.sconcat cirbs, ldis) + +collectMatch :: Deltas -> CIRBCollector AnnMatch (Deltas, NonEmpty Deltas) +collectMatch ldi AnnMatch { am_red = red, am_grhss = grhss } = do + (is_covered, may_diverge, ldi', red_bangs) <- testRedSets ldi red + (cirb, ldis) <- collectGRHSs ldi' grhss + let cirb' = addRedundantBangs red_bangs + -- See Note [Determining inaccessible clauses] + $ applyWhen may_diverge ensureOneNotRedundant + $ applyWhen (not is_covered) markAllRedundant + $ cirb + pure (cirb', (ldi', ldis)) + +collectGRHSs :: Deltas -> CIRBCollector (NonEmpty AnnGRHS) (NonEmpty Deltas) +collectGRHSs ldi grhss = do + (cirbs, ldis) <- NE.unzip <$> traverse (collectGRHS ldi) grhss + pure (Semi.sconcat cirbs, ldis) + +collectGRHS :: Deltas -> CIRBCollector AnnGRHS Deltas +collectGRHS ldi AnnGRHS { ag_red = red, ag_rhs = info } = do + (is_covered, may_diverge, ldi', red_bangs) <- testRedSets ldi red + let cirb | is_covered = mempty { cirb_cov = unitOL info } + | may_diverge = mempty { cirb_inacc = unitOL info } + | otherwise = mempty { cirb_red = unitOL info } + pure (addRedundantBangs red_bangs cirb, ldi') + +collectEmptyCase :: CIRBCollector AnnEmptyCase () +collectEmptyCase _ = pure (mempty, ()) + +collectPatBind :: CIRBCollector AnnPatBind () +-- We don't make use of long-distance information in pattern bindings, hence +-- @()@ instead of some 'Deltas'. +collectPatBind (AnnPatBind grhs) = do + -- use 'mempty' as fallback 'Deltas' because we discard it anyway + (cirb, _) <- collectGRHS mempty grhs + pure (cirb, ()) {- Note [Determining inaccessible clauses] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1239,26 +1176,30 @@ arguments we can ever reach clause 2's RHS, so we say it has inaccessible RHS (as opposed to being completely redundant). We detect an inaccessible RHS simply by pretending it's redundant, until we see -that it's part of a sub-tree in the pattern match that forces some argument -(which corresponds to wrapping the 'AnnotatedTree' in 'MayDiverge'). Then we -turn all supposedly redundant RHSs into inaccessible ones. - -But as it turns out (@g@ from #17465) this is too conservative: - g () | False = () - | otherwise = () -g's first clause has an inaccessible RHS, but it's also safe to delete. So it's -redundant, really! But by just turning all redundant child clauses into -inaccessible ones, we report the first clause as inaccessible. - -Clearly, it is enough if we say that we only degrade if *not all* of the child -clauses are redundant. As long as there is at least one clause which we announce -not to be redundant, the guard prefix responsible for the 'MayDiverge' will -survive. Hence we check for that in 'extractRedundancyInfo'. -} --- | Issue all the warnings (coverage, exhaustiveness, inaccessibility) -dsPmWarn :: DynFlags -> DsMatchContext -> [Id] -> CheckResult -> DsM () -dsPmWarn dflags ctx@(DsMatchContext kind loc) vars result +-- +-- * Formatting and reporting warnings +-- + +-- | Given a 'CIRBCollector', this function will emit warnings for a +-- 'CheckResult' and return the collected long-distance information. +formatReportWarnings :: CIRBCollector ann ldi -> DsMatchContext -> [Id] -> CheckResult ann -> DsM ldi +formatReportWarnings collect ctx vars cr at CheckResult { cr_ret = ann } = do + (cov_info, ldi) <- collect ann + dflags <- getDynFlags + reportWarnings dflags ctx vars cr{cr_ret=cov_info} + pure ldi + +-- | Issue all the warnings +-- (redundancy, inaccessibility, exhaustiveness, redundant bangs). +reportWarnings :: DynFlags -> DsMatchContext -> [Id] -> CheckResult CIRB -> DsM () +reportWarnings dflags ctx@(DsMatchContext kind loc) vars + CheckResult { cr_ret = CIRB { cirb_inacc = inaccessible_rhss + , cirb_red = redundant_rhss + , cirb_bangs = redundant_bangs } + , cr_uncov = uncovered + , cr_approx = precision } = when (flag_i || flag_u || flag_b) $ do unc_examples <- getNFirstUncovered vars (maxPatterns + 1) uncovered let exists_r = flag_i && notNull redundant_rhss @@ -1284,13 +1225,6 @@ dsPmWarn dflags ctx@(DsMatchContext kind loc) vars result when exists_u $ putSrcSpanDs loc $ warnDs flag_u_reason $ pprEqns vars unc_examples where - CheckResult - { cr_clauses = clauses - , cr_uncov = uncovered - , cr_approx = precision } = result - RedundancyInfo{redundant_rhss, inaccessible_rhss, redundant_bangs} - = extractRedundancyInfo clauses - flag_i = overlapping dflags kind flag_u = exhaustive dflags kind flag_b = redundant_bang dflags @@ -1331,44 +1265,30 @@ getNFirstUncovered vars n (MkDeltas deltas) = go n (bagToList deltas) back <- go (n - length front) deltas pure (front ++ back) -{- Note [Inaccessible warnings for record updates] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider (#12957) - data T a where - T1 :: { x :: Int } -> T Bool - T2 :: { x :: Int } -> T a - T3 :: T a - - f :: T Char -> T a - f r = r { x = 3 } - -The desugarer will (conservatively generate a case for T1 even though -it's impossible: - f r = case r of - T1 x -> T1 3 -- Inaccessible branch - T2 x -> T2 3 - _ -> error "Missing" - -We don't want to warn about the inaccessible branch because the programmer -didn't put it there! So we filter out the warning here. - -The same can happen for long distance term constraints instead of type -constraints (#17783): - - data T = A { x :: Int } | B { x :: Int } - f r at A{} = r { x = 3 } - f _ = B 0 - -Here, the long distance info from the FunRhs match (@r ~ A x@) will make the -clause matching on @B@ of the desugaring to @case@ redundant. It's generated -code that we don't want to warn about. --} - dots :: Int -> [a] -> SDoc dots maxPatterns qs | qs `lengthExceeds` maxPatterns = text "..." | otherwise = empty +pprContext :: Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc +pprContext singular (DsMatchContext kind _loc) msg rest_of_msg_fun + = vcat [text txt <+> msg, + sep [ text "In" <+> ppr_match <> char ':' + , nest 4 (rest_of_msg_fun pref)]] + where + txt | singular = "Pattern match" + | otherwise = "Pattern match(es)" + + (ppr_match, pref) + = case kind of + FunRhs { mc_fun = L _ fun } + -> (pprMatchContext kind, \ pp -> ppr fun <+> pp) + _ -> (pprMatchContext kind, \ pp -> pp) + +-- +-- * Utilities +-- + -- | All warning flags that need to run the pattern match checker. allPmCheckWarnings :: [WarningFlag] allPmCheckWarnings = @@ -1411,18 +1331,151 @@ exhaustiveWarningFlag ThPatQuote = Nothing -- etc. They are often *supposed* to be incomplete exhaustiveWarningFlag (StmtCtxt {}) = Nothing --- True <==> singular -pprContext :: Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc -pprContext singular (DsMatchContext kind _loc) msg rest_of_msg_fun - = vcat [text txt <+> msg, - sep [ text "In" <+> ppr_match <> char ':' - , nest 4 (rest_of_msg_fun pref)]] - where - txt | singular = "Pattern match" - | otherwise = "Pattern match(es)" +-- | Check whether any part of pattern match checking is enabled for this +-- 'HsMatchContext' (does not matter whether it is the redundancy check or the +-- exhaustiveness check). +isMatchContextPmChecked :: DynFlags -> Origin -> HsMatchContext id -> Bool +isMatchContextPmChecked dflags origin kind + | isGenerated origin + = False + | otherwise + = overlapping dflags kind || exhaustive dflags kind - (ppr_match, pref) - = case kind of - FunRhs { mc_fun = L _ fun } - -> (pprMatchContext kind, \ pp -> ppr fun <+> pp) - _ -> (pprMatchContext kind, \ pp -> pp) +-- | Return True when any of the pattern match warnings ('allPmCheckWarnings') +-- are enabled, in which case we need to run the pattern match checker. +needToRunPmCheck :: DynFlags -> Origin -> Bool +needToRunPmCheck dflags origin + | isGenerated origin + = False + | otherwise + = notNull (filter (`wopt` dflags) allPmCheckWarnings) + +{- Note [Inaccessible warnings for record updates] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider (#12957) + data T a where + T1 :: { x :: Int } -> T Bool + T2 :: { x :: Int } -> T a + T3 :: T a + + f :: T Char -> T a + f r = r { x = 3 } + +The desugarer will conservatively generate a case for T1 even though +it's impossible: + f r = case r of + T1 x -> T1 3 -- Inaccessible branch + T2 x -> T2 3 + _ -> error "Missing" + +We don't want to warn about the inaccessible branch because the programmer +didn't put it there! So we filter out the warning here. + +The same can happen for long distance term constraints instead of type +constraints (#17783): + + data T = A { x :: Int } | B { x :: Int } + f r at A{} = r { x = 3 } + f _ = B 0 + +Here, the long distance info from the FunRhs match (@r ~ A x@) will make the +clause matching on @B@ of the desugaring to @case@ redundant. It's generated +code that we don't want to warn about. +-} + +-- +-- * Long-distance information +-- + +-- | Locally update 'dsl_deltas' with the given action, but defer evaluation +-- with 'unsafeInterleaveM' in order not to do unnecessary work. +locallyExtendPmDeltas :: (Deltas -> DsM Deltas) -> DsM a -> DsM a +locallyExtendPmDeltas ext k = do + deltas <- getPmDeltas + deltas' <- unsafeInterleaveM $ do + deltas' <- ext deltas + inh <- isInhabited deltas' + -- If adding a constraint would lead to a contradiction, don't add it. + -- See Note [Recovering from unsatisfiable pattern-matching constraints] + -- for why this is done. + if inh + then pure deltas' + else pure deltas + updPmDeltas deltas' k + +-- | Add in-scope type constraints if the coverage checker might run and then +-- run the given action. +addTyCs :: Origin -> Bag EvVar -> DsM a -> DsM a +addTyCs origin ev_vars m = do + dflags <- getDynFlags + applyWhen (needToRunPmCheck dflags origin) + (locallyExtendPmDeltas (\deltas -> addPmCtsDeltas deltas (PmTyCt . evVarPred <$> ev_vars))) + m + +-- | Add equalities for the 'CoreExpr' scrutinee to the local 'DsM' environment +-- when checking a case expression: +-- case e of x { matches } +-- When checking matches we record that (x ~ e) where x is the initial +-- uncovered. All matches will have to satisfy this equality. +addCoreScrutTmCs :: Maybe CoreExpr -> [Id] -> DsM a -> DsM a +addCoreScrutTmCs Nothing _ k = k +addCoreScrutTmCs (Just scr) [x] k = + flip locallyExtendPmDeltas k $ \deltas -> + addPmCtsDeltas deltas (unitBag (PmCoreCt x scr)) +addCoreScrutTmCs _ _ _ = panic "addCoreScrutTmCs: scrutinee, but more than one match id" + +-- | 'addCoreScrutTmCs', but desugars the 'LHsExpr' first. +addHsScrutTmCs :: Maybe (LHsExpr GhcTc) -> [Id] -> DsM a -> DsM a +addHsScrutTmCs Nothing _ k = k +addHsScrutTmCs (Just scr) vars k = do + scr_e <- dsLExpr scr + addCoreScrutTmCs (Just scr_e) vars k + +{- Note [Long-distance information] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider + + data Color = R | G | B + f :: Color -> Int + f R = … + f c = … (case c of + G -> True + B -> False) … + +Humans can make the "long-distance connection" between the outer pattern match +and the nested case pattern match to see that the inner pattern match is +exhaustive: @c@ can't be @R@ anymore because it was matched in the first clause +of @f at . + +To achieve similar reasoning in the coverage checker, we keep track of the set +of values that can reach a particular program point (often loosely referred to +as "Covered set") in 'GHC.HsToCore.Monad.dsl_deltas'. +We fill that set with Covered Deltas returned by the exported checking +functions, which the call sites put into place with +'GHC.HsToCore.Monad.updPmDeltas'. +Call sites also extend this set with facts from type-constraint dictionaries, +case scrutinees, etc. with the exported functions 'addTyCs', 'addCoreScrutTmCs' +and 'addHsScrutTmCs'. + +Note [Recovering from unsatisfiable pattern-matching constraints] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider the following code (see #12957 and #15450): + + f :: Int ~ Bool => () + f = case True of { False -> () } + +We want to warn that the pattern-matching in `f` is non-exhaustive. But GHC +used not to do this; in fact, it would warn that the match was /redundant/! +This is because the constraint (Int ~ Bool) in `f` is unsatisfiable, and the +coverage checker deems any matches with unsatisfiable constraint sets to be +unreachable. + +We can do better than this, by making sure that the Covered set used for +Note [Long-distance information] is always inhabited. +For Covered sets returned by the exported checking functions, that is ensured +in 'testRedSets', which takes and returns a non-empty fallback 'Deltas' in case +the refined Covered set became uninhabited. +Also, whenever "external" knowledge from a type constraint or case scrutinee is +integrated, we only commit that knowledge to 'GHC.HsToCore.Monad.dsl_deltas' if +the set remains inhabited. That check happens in 'locallyExtendPmDeltas'. +-} ===================================== compiler/GHC/HsToCore/PmCheck/Oracle.hs ===================================== @@ -166,25 +166,6 @@ mkOneConFull arg_tys con = do -- * Pattern match oracle -{- Note [Recovering from unsatisfiable pattern-matching constraints] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider the following code (see #12957 and #15450): - - f :: Int ~ Bool => () - f = case True of { False -> () } - -We want to warn that the pattern-matching in `f` is non-exhaustive. But GHC -used not to do this; in fact, it would warn that the match was /redundant/! -This is because the constraint (Int ~ Bool) in `f` is unsatisfiable, and the -coverage checker deems any matches with unsatisfiable constraint sets to be -unreachable. - -We decide to better than this. When beginning coverage checking, we first -check if the constraints in scope are unsatisfiable, and if so, we start -afresh with an empty set of constraints. This way, we'll get the warnings -that we expect. --} - ------------------------------------- -- * Composable satisfiability checks @@ -1265,7 +1246,7 @@ isTyConTriviallyInhabited tc = elementOfUniqSet tc triviallyInhabitedTyCons {- Note [Checking EmptyCase Expressions] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Empty case expressions are strict on the scrutinee. That is, `case x of {}` -will force argument `x`. Hence, `covCheckMatchGroup` is not sufficient for checking +will force argument `x`. Hence, `covCheckMatches` is not sufficient for checking empty cases, because it assumes that the match is not strict (which is true for all other cases, apart from EmptyCase). This gave rise to #10746. Instead, we do the following: ===================================== compiler/GHC/HsToCore/PmCheck/Types.hs ===================================== @@ -592,5 +592,8 @@ instance Outputable Deltas where instance Semigroup Deltas where MkDeltas l <> MkDeltas r = MkDeltas (l `unionBags` r) +instance Monoid Deltas where + mempty = MkDeltas emptyBag + liftDeltasM :: Monad m => (Delta -> m (Maybe Delta)) -> Deltas -> m Deltas liftDeltasM f (MkDeltas ds) = MkDeltas . catBagMaybes <$> (traverse f ds) ===================================== compiler/GHC/Tc/Types.hs ===================================== @@ -323,7 +323,7 @@ data DsLclEnv = DsLclEnv { dsl_meta :: DsMetaEnv, -- Template Haskell bindings dsl_loc :: RealSrcSpan, -- To put in pattern-matching error msgs - -- See Note [Note [Type and Term Equality Propagation] in "GHC.HsToCore.PmCheck" + -- See Note [Note [Long-distance information] in "GHC.HsToCore.PmCheck" -- The set of reaching values Deltas is augmented as we walk inwards, -- refined through each pattern match in turn dsl_deltas :: Deltas ===================================== compiler/GHC/Utils/Misc.hs ===================================== @@ -556,9 +556,8 @@ isSingleton :: [a] -> Bool isSingleton [_] = True isSingleton _ = False -notNull :: [a] -> Bool -notNull [] = False -notNull _ = True +notNull :: Foldable f => f a -> Bool +notNull = not . null only :: [a] -> a #if defined(DEBUG) ===================================== testsuite/tests/deSugar/should_compile/ds020.stderr ===================================== @@ -18,3 +18,11 @@ ds020.hs:20:1: warning: [-Woverlapping-patterns (in -Wdefault)] ds020.hs:23:1: warning: [-Woverlapping-patterns (in -Wdefault)] Pattern match is redundant In an equation for ‘f’: f x@(~[]) = ... + +ds020.hs:32:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: (x1 : xs1 : ys1) = ... + +ds020.hs:33:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: (~x : ~xs : ~ys) = ... ===================================== testsuite/tests/module/all.T ===================================== @@ -83,7 +83,7 @@ test('mod61', normal, compile_fail, ['']) test('mod62', normal, compile_fail, ['']) test('mod63', normal, compile_fail, ['']) test('mod64', normal, compile, ['']) -test('mod65', normal, compile, ['']) +test('mod65', normal, compile, ['-Wno-overlapping-patterns']) test('mod66', normal, compile_fail, ['']) test('mod67', normal, compile_fail, ['']) test('mod68', normal, compile_fail, ['']) ===================================== testsuite/tests/pmcheck/should_compile/T18572.hs ===================================== @@ -3,10 +3,10 @@ module T18572 where -True = True +True = True -- no warning data SBool (b :: Bool) where STrue :: SBool True SFalse :: SBool False -STrue = SFalse +STrue = SFalse -- "redundant", not "inaccessible" ===================================== testsuite/tests/rename/should_compile/T7085.stderr ===================================== @@ -1,3 +1,7 @@ T7085.hs:8:6: warning: [-Wunused-pattern-binds (in -Wextra, -Wunused-binds)] This pattern-binding binds no variables: Nothing = Just n + +T7085.hs:8:6: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: Nothing = ... ===================================== testsuite/tests/unboxedsums/all.T ===================================== @@ -30,5 +30,5 @@ test('T12711', only_ways(['ghci']), ghci_script, ['T12711.script']) # extra_files([ "unboxedsums" + str(i) + ".hs" for i in range(1, 12) ])], # makefile_test, []) -test('UbxSumLevPoly', normal, compile, ['']) +test('UbxSumLevPoly', normal, compile, ['-Wno-overlapping-patterns']) test('T14051', normal, multi_compile, ['T14051.hs', [('T14051a.hs', '')], '-O2 -v0']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/90651e473bf35a7b6d82f4b808d58e8d43d142ef -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/90651e473bf35a7b6d82f4b808d58e8d43d142ef You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 12:29:40 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Mon, 31 Aug 2020 08:29:40 -0400 Subject: [Git][ghc/ghc][wip/buggymcbugfix/appendArrays] Implement appendArray# (external) primop Message-ID: <5f4ced34d092d_80b3f84867fdc40988442d@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed to branch wip/buggymcbugfix/appendArrays at Glasgow Haskell Compiler / GHC Commits: fb3986fe by buggymcbugfix at 2020-08-31T14:29:27+02:00 Implement appendArray# (external) primop - - - - - 3 changed files: - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/StgToCmm/Prim.hs - rts/PrimOps.cmm Changes: ===================================== compiler/GHC/Builtin/primops.txt.pp ===================================== @@ -1246,6 +1246,14 @@ primop ThawArrayOp "thawArray#" GenPrimOp has_side_effects = True can_fail = True +primop AppendArrays "appendArrays#" GenPrimOp + Array# a -> Array# a -> Array# a + {Concatenate two arrays by @memcpy at ing them into a new array.} + with + out_of_line = True + has_side_effects = True + can_fail = True + primop CasArrayOp "casArray#" GenPrimOp MutableArray# s a -> Int# -> a -> a -> State# s -> (# State# s, Int#, a #) {Given an array, an offset, the expected old value, and @@ -1437,6 +1445,14 @@ primop ThawSmallArrayOp "thawSmallArray#" GenPrimOp has_side_effects = True can_fail = True +primop AppendSmallArrays "appendSmallArrays#" GenPrimOp + SmallArray# a -> SmallArray# a -> SmallArray# a + {Concatenate two arrays by @memcpy at ing them into a new array.} + with + out_of_line = True + has_side_effects = True + can_fail = True + primop CasSmallArrayOp "casSmallArray#" GenPrimOp SmallMutableArray# s a -> Int# -> a -> a -> State# s -> (# State# s, Int#, a #) {Unsafe, machine-level atomic compare and swap on an element within an array. ===================================== compiler/GHC/StgToCmm/Prim.hs ===================================== @@ -219,6 +219,8 @@ emitPrimOp dflags primop = case primop of -> opIntoRegs $ \ [res] -> emitCloneArray mkMAP_DIRTY_infoLabel res src src_off (fromInteger n) _ -> PrimopCmmEmit_External + AppendArrays -> const PrimopCmmEmit_External + NewSmallArrayOp -> \case [(CmmLit (CmmInt n w)), init] | wordsToBytes platform (asUnsigned w n) <= fromIntegral (maxInlineAllocSize dflags) @@ -264,6 +266,8 @@ emitPrimOp dflags primop = case primop of -> opIntoRegs $ \ [res] -> emitCloneSmallArray mkSMAP_DIRTY_infoLabel res src src_off (fromInteger n) _ -> PrimopCmmEmit_External + AppendSmallArrays -> const PrimopCmmEmit_External + -- First we handle various awkward cases specially. ParOp -> \[arg] -> opIntoRegs $ \[res] -> do ===================================== rts/PrimOps.cmm ===================================== @@ -343,6 +343,40 @@ stg_thawArrayzh ( gcptr src, W_ offset, W_ n ) cloneArray(stg_MUT_ARR_PTRS_DIRTY_info, src, offset, n) } +stg_appendArrayszh( gcptr src1, gcptr src2 ) +{ + W_ words, n1, n2, nDest, size1, size2; + gcptr dst, dst_p, src1_p, src2_p; + + again: MAYBE_GC(again); + + n1 = StgMutArrPtrs_ptrs(src1); + n2 = StgMutArrPtrs_ptrs(src2); + nDest = n1 + n2; + + size1 = n1 + mutArrPtrsCardWords(n1); + size2 = n2 + mutArrPtrsCardWords(n2); + sizeDest = nDest + mutArrPtrsCardWords(nDest); + + words = BYTES_TO_WDS(SIZEOF_StgMutArrPtrs) + sizeDest; + + ("ptr" dst) = ccall allocate(MyCapability() "ptr", words); + TICK_ALLOC_PRIM(SIZEOF_StgMutArrPtrs, WDS(sizeDest), 0); + + SET_HDR(dst, stg_MUT_ARR_PTRS_FROZEN_CLEAN_info, CCCS); + StgMutArrPtrs_ptrs(dst) = nDest; + StgMutArrPtrs_size(dst) = sizeDest; + + dst_p = dst + SIZEOF_StgMutArrPtrs; + src1_p = src1 + SIZEOF_StgMutArrPtrs; + src2_p = src2 + SIZEOF_StgMutArrPtrs; + + prim %memcpy(dst_p, src1_p, WDS(n1), SIZEOF_W); + prim %memcpy(dst_p + WDS(n1), src2_p, WDS(n2), SIZEOF_W); + + return (dst); +} + // RRN: Uses the ticketed approach; see casMutVar stg_casArrayzh ( gcptr arr, W_ ind, gcptr old, gcptr new ) /* MutableArray# s a -> Int# -> a -> a -> State# s -> (# State# s, Int#, Any a #) */ @@ -478,6 +512,34 @@ stg_thawSmallArrayzh ( gcptr src, W_ offset, W_ n ) cloneSmallArray(stg_SMALL_MUT_ARR_PTRS_DIRTY_info, src, offset, n) } +stg_appendSmallArrayszh( gcptr src1, gcptr src2 ) +{ + W_ words, n1, n2, nDest; + gcptr dst, dst_p, src1_p, src2_p; + + again: MAYBE_GC(again); + + n1 = StgSmallMutArrPtrs_ptrs(src1); + n2 = StgSmallMutArrPtrs_ptrs(src2); + nDest = n1 + n2; + words = BYTES_TO_WDS(SIZEOF_StgSmallMutArrPtrs) + nDest; + + ("ptr" dst) = ccall allocate(MyCapability() "ptr", words); + TICK_ALLOC_PRIM(SIZEOF_StgSmallMutArrPtrs, WDS(nDest), 0); + + SET_HDR(dst, stg_SMALL_MUT_ARR_PTRS_FROZEN_CLEAN_info, CCCS); \ + StgSmallMutArrPtrs_ptrs(dst) = nDest; + + dst_p = dst + SIZEOF_StgSmallMutArrPtrs; + src1_p = src1 + SIZEOF_StgSmallMutArrPtrs; + src2_p = src2 + SIZEOF_StgSmallMutArrPtrs; + + prim %memcpy(dst_p, src1_p, WDS(n1), SIZEOF_W); + prim %memcpy(dst_p + WDS(n1), src2_p, WDS(n2), SIZEOF_W); + + return (dst); +} + // Concurrent GC write barrier for pointer array copies // // hdr_size in bytes. dst_off in words, n in words. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fb3986fe47a298c97c19735b86dc026fec9aa9a0 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fb3986fe47a298c97c19735b86dc026fec9aa9a0 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 12:55:54 2020 From: gitlab at gitlab.haskell.org (Moritz Angermann) Date: Mon, 31 Aug 2020 08:55:54 -0400 Subject: [Git][ghc/ghc][wip/angerman/fix-rpath] [macOS] improved runpath handling Message-ID: <5f4cf35a82a72_80b3f84924cf17098872fd@gitlab.haskell.org.mail> Moritz Angermann pushed to branch wip/angerman/fix-rpath at Glasgow Haskell Compiler / GHC Commits: 3bb2834d by Moritz Angermann at 2020-08-31T20:49:55+08:00 [macOS] improved runpath handling In b592bd98ff25730bbe3c13d6f62a427df8c78e28 we started using -dead_strip_dylib on macOS when lining dynamic libraries and binaries. The underlying reason being the Load Command Size Limit in macOS Sierra (10.14) and later. GHC will produce @rpath/libHS... dependency entries together with a corresponding RPATH entry pointing to the location of the libHS... library. Thus for every library we produce two Load Commands. One to specify the dependent library, and one with the path where to find it. This makes relocating libraries and binaries easier, as we just need to update the RPATH entry with the install_name_tool. The dynamic linker will then subsitute each @rpath with the RPATH entries it finds in the libraries load commands or the environement, when looking up @rpath relative libraries. -dead_strip_dylibs intructs the linker to drop unused libraries. This in turn help us reduce the number of referenced libraries, and subsequently the size of the load commands. This however does not remove the RPATH entries. Subsequently we can end up (in extreme cases) with only a single @rpath/libHS... entry, but 100s or more RPATH entries in the Load Commands. This patch rectifies this (slighly unorthodox) by passing *no* -rpath arguments to the linker at link time, but -headerpad 8000. The headerpad argument is in hexadecimal and the maxium 32k of the load command size. This tells the linker to pad the load command section enough for us to inject the RPATHs later. We then proceed to link the library or binary with -dead_strip_dylibs, and *after* the linking inspect the library to find the left over (non-dead-stripped) dependencies (using otool). We find the corresponding RPATHs for each @rpath relative dependency, and inject them into the library or binary using the install_name_tool. Thus achieving a deadstripped dylib (and rpaths) build product. We can not do this in GHC, without starting to reimplement a dynamic linker as we do not know which symbols and subsequently libraries are necessary. Commissioned-by: Mercury Technologies, Inc. (mercury.com) - - - - - 15 changed files: - aclocal.m4 - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Runtime/Linker.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools.hs - compiler/GHC/SysTools/Tasks.hs - configure.ac - docs/users_guide/phases.rst - hadrian/cfg/system.config.in - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - includes/ghc.mk - mk/config.mk.in Changes: ===================================== aclocal.m4 ===================================== @@ -579,6 +579,18 @@ AC_DEFUN([FP_SETTINGS], else SettingsOptCommand="$OptCmd" fi + if test -z "$OtoolCmd" + then + SettingsOtoolCommand="otool" + else + SettingsOtoolCommand="$OtoolCmd" + fi + if test -z "$InstallNameToolCmd" + then + SettingsInstallNameToolCommand="install_name_tool" + else + SettingsInstallNameToolCommand="$InstallNameToolCmd" + fi SettingsCCompilerFlags="$CONF_CC_OPTS_STAGE2" SettingsCxxCompilerFlags="$CONF_CXX_OPTS_STAGE2" SettingsCCompilerLinkFlags="$CONF_GCC_LINKER_OPTS_STAGE2" @@ -596,6 +608,8 @@ AC_DEFUN([FP_SETTINGS], AC_SUBST(SettingsLdFlags) AC_SUBST(SettingsArCommand) AC_SUBST(SettingsRanlibCommand) + AC_SUBST(SettingsOtoolCommand) + AC_SUBST(SettingsInstallNameToolCommand) AC_SUBST(SettingsDllWrapCommand) AC_SUBST(SettingsWindresCommand) AC_SUBST(SettingsLibtoolCommand) ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -1787,9 +1787,12 @@ linkBinary' staticLink dflags o_files dep_units = do rc_objs <- maybeCreateManifest dflags output_fn - let link = if staticLink - then GHC.SysTools.runLibtool - else GHC.SysTools.runLink + let link dflags args | staticLink = GHC.SysTools.runLibtool dflags args + | platformOS platform == OSDarwin + = GHC.SysTools.runLink dflags args >> GHC.SysTools.runInjectRPaths dflags pkg_lib_paths output_fn + | otherwise + = GHC.SysTools.runLink dflags args + link dflags ( map GHC.SysTools.Option verbFlags ++ [ GHC.SysTools.Option "-o" @@ -1856,7 +1859,11 @@ linkBinary' staticLink dflags o_files dep_units = do ++ pkg_link_opts ++ pkg_framework_opts ++ (if platformOS platform == OSDarwin - then [ "-Wl,-dead_strip_dylibs" ] + -- dead_strip_dylibs, will remove unused dylibs, and thus save + -- space in the load commands. The -headerpad is necessary so + -- that we can inject more @rpath's later for the left over + -- libraries in the runInjectRpaths phase below. + then [ "-Wl,-dead_strip_dylibs", "-Wl,-headerpad,8000" ] else []) )) ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -145,8 +145,8 @@ module GHC.Driver.Session ( versionedAppDir, versionedFilePath, extraGccViaCFlags, globalPackageDatabasePath, pgm_L, pgm_P, pgm_F, pgm_c, pgm_a, pgm_l, pgm_lm, pgm_dll, pgm_T, - pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc, - pgm_lcc, pgm_i, + pgm_windres, pgm_libtool, pgm_ar, pgm_otool, pgm_install_name_tool, + pgm_ranlib, pgm_lo, pgm_lc, pgm_lcc, pgm_i, opt_L, opt_P, opt_F, opt_c, opt_cxx, opt_a, opt_l, opt_lm, opt_i, opt_P_signature, opt_windres, opt_lo, opt_lc, opt_lcc, @@ -885,6 +885,10 @@ pgm_lcc :: DynFlags -> (String,[Option]) pgm_lcc dflags = toolSettings_pgm_lcc $ toolSettings dflags pgm_ar :: DynFlags -> String pgm_ar dflags = toolSettings_pgm_ar $ toolSettings dflags +pgm_otool :: DynFlags -> String +pgm_otool dflags = toolSettings_pgm_otool $ toolSettings dflags +pgm_install_name_tool :: DynFlags -> String +pgm_install_name_tool dflags = toolSettings_pgm_install_name_tool $ toolSettings dflags pgm_ranlib :: DynFlags -> String pgm_ranlib dflags = toolSettings_pgm_ranlib $ toolSettings dflags pgm_lo :: DynFlags -> (String,[Option]) @@ -2267,6 +2271,10 @@ dynamic_flags_deps = [ $ hasArg $ \f -> alterToolSettings $ \s -> s { toolSettings_pgm_libtool = f } , make_ord_flag defFlag "pgmar" $ hasArg $ \f -> alterToolSettings $ \s -> s { toolSettings_pgm_ar = f } + , make_ord_flag defFlag "pgmotool" + $ hasArg $ \f -> alterToolSettings $ \s -> s { toolSettings_pgm_otool = f} + , make_ord_flag defFlag "pgminstall_name_tool" + $ hasArg $ \f -> alterToolSettings $ \s -> s { toolSettings_pgm_install_name_tool = f} , make_ord_flag defFlag "pgmranlib" $ hasArg $ \f -> alterToolSettings $ \s -> s { toolSettings_pgm_ranlib = f } @@ -3780,7 +3788,6 @@ defaultFlags settings Opt_OmitYields, Opt_PrintBindContents, Opt_ProfCountEntries, - Opt_RPath, Opt_SharedImplib, Opt_SimplPreInlining, Opt_VersionMacros @@ -3791,6 +3798,8 @@ defaultFlags settings ++ default_PIC platform + ++ default_RPath platform + ++ concatMap (wayGeneralFlags platform) (defaultWays settings) ++ validHoleFitDefaults @@ -3831,6 +3840,26 @@ default_PIC platform = -- information. _ -> [] + +-- We usually want to use RPath, except on macOS (OSDarwin). On recent macOS +-- version the number of load commands we can embed in a dynamic library are +-- restricted. Hence since b592bd98ff2 we rely on -dead_strip_dylib to only +-- link the needed dylibs instead of linking the full dependency closure. +-- +-- If we split the library linking into injecting -rpath and -l @rpath/... +-- components, we will reduce the number of libraries we link, however we will +-- still inject one -rpath entry for each library, independent of their use. +-- That is, we even inject -rpath values for libraries that we dead_strip in +-- the end. As such we can run afoul of the load command size limit simply +-- by polluting the load commands with RPATH entries. +-- +-- Thus, we disable Opt_RPath by default on OSDarwin. The savvy user can always +-- enable it with -use-rpath if they so wish. +default_RPath :: Platform -> [GeneralFlag] +default_RPath platform | platformOS platform == OSDarwin = [] +default_RPath _ = [Opt_RPath] + + -- General flags that are switched on/off when other general flags are switched -- on impliedGFlags :: [(GeneralFlag, TurnOnFlag, GeneralFlag)] ===================================== compiler/GHC/Runtime/Linker.hs ===================================== @@ -929,20 +929,22 @@ dynLoadObjs hsc_env pls at PersistentLinkerState{..} objs = do ldInputs = concatMap (\l -> [ Option ("-l" ++ l) ]) (nub $ snd <$> temp_sos) - ++ concatMap (\lp -> [ Option ("-L" ++ lp) - , Option "-Xlinker" - , Option "-rpath" - , Option "-Xlinker" - , Option lp ]) + ++ concatMap (\lp -> Option ("-L" ++ lp) + : if gopt Opt_RPath dflags + then [ Option "-Xlinker" + , Option "-rpath" + , Option "-Xlinker" + , Option lp ] + else []) (nub $ fst <$> temp_sos) ++ concatMap - (\lp -> - [ Option ("-L" ++ lp) - , Option "-Xlinker" - , Option "-rpath" - , Option "-Xlinker" - , Option lp - ]) + (\lp -> Option ("-L" ++ lp) + : if gopt Opt_RPath dflags + then [ Option "-Xlinker" + , Option "-rpath" + , Option "-Xlinker" + , Option lp ] + else []) minus_big_ls -- See Note [-Xlinker -rpath vs -Wl,-rpath] ++ map (\l -> Option ("-l" ++ l)) minus_ls, ===================================== compiler/GHC/Settings.hs ===================================== @@ -34,6 +34,8 @@ module GHC.Settings , sPgm_windres , sPgm_libtool , sPgm_ar + , sPgm_otool + , sPgm_install_name_tool , sPgm_ranlib , sPgm_lo , sPgm_lc @@ -107,6 +109,8 @@ data ToolSettings = ToolSettings , toolSettings_pgm_windres :: String , toolSettings_pgm_libtool :: String , toolSettings_pgm_ar :: String + , toolSettings_pgm_otool :: String + , toolSettings_pgm_install_name_tool :: String , toolSettings_pgm_ranlib :: String , -- | LLVM: opt llvm optimiser toolSettings_pgm_lo :: (String, [Option]) @@ -216,6 +220,10 @@ sPgm_libtool :: Settings -> String sPgm_libtool = toolSettings_pgm_libtool . sToolSettings sPgm_ar :: Settings -> String sPgm_ar = toolSettings_pgm_ar . sToolSettings +sPgm_otool :: Settings -> String +sPgm_otool = toolSettings_pgm_otool . sToolSettings +sPgm_install_name_tool :: Settings -> String +sPgm_install_name_tool = toolSettings_pgm_install_name_tool . sToolSettings sPgm_ranlib :: Settings -> String sPgm_ranlib = toolSettings_pgm_ranlib . sToolSettings sPgm_lo :: Settings -> (String, [Option]) ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -115,6 +115,8 @@ initSettings top_dir = do windres_path <- getToolSetting "windres command" libtool_path <- getToolSetting "libtool command" ar_path <- getToolSetting "ar command" + otool_path <- getToolSetting "otool command" + install_name_tool_path <- getToolSetting "install_name_tool command" ranlib_path <- getToolSetting "ranlib command" -- TODO this side-effect doesn't belong here. Reading and parsing the settings @@ -191,6 +193,8 @@ initSettings top_dir = do , toolSettings_pgm_windres = windres_path , toolSettings_pgm_libtool = libtool_path , toolSettings_pgm_ar = ar_path + , toolSettings_pgm_otool = otool_path + , toolSettings_pgm_install_name_tool = install_name_tool_path , toolSettings_pgm_ranlib = ranlib_path , toolSettings_pgm_lo = (lo_prog,[]) , toolSettings_pgm_lc = (lc_prog,[]) ===================================== compiler/GHC/SysTools.hs ===================================== @@ -259,7 +259,10 @@ linkDynLib dflags0 o_files dep_packages | ( osElfTarget (platformOS (targetPlatform dflags)) || osMachOTarget (platformOS (targetPlatform dflags)) ) && dynLibLoader dflags == SystemDependent && - WayDyn `Set.member` ways dflags + -- Only if we want dynamic libraries + WayDyn `Set.member` ways dflags && + -- Only use RPath if we explicitly asked for it + gopt Opt_RPath dflags = ["-L" ++ l, "-Xlinker", "-rpath", "-Xlinker", l] -- See Note [-Xlinker -rpath vs -Wl,-rpath] | otherwise = ["-L" ++ l] @@ -384,8 +387,13 @@ linkDynLib dflags0 o_files dep_packages ++ map Option pkg_lib_path_opts ++ map Option pkg_link_opts ++ map Option pkg_framework_opts - ++ [ Option "-Wl,-dead_strip_dylibs" ] + -- dead_strip_dylibs, will remove unused dylibs, and thus save + -- space in the load commands. The -headerpad is necessary so + -- that we can inject more @rpath's later for the left over + -- libraries in the runInjectRpaths phase below. + ++ [ Option "-Wl,-dead_strip_dylibs", Option "-Wl,-headerpad,8000" ] ) + runInjectRPaths dflags pkg_lib_paths output_fn _ -> do ------------------------------------------------------------------- -- Making a DSO ===================================== compiler/GHC/SysTools/Tasks.hs ===================================== @@ -28,6 +28,10 @@ import GHC.CmmToLlvm.Base (LlvmVersion, llvmVersionStr, supportedLlvmVersion, pa import GHC.SysTools.Process import GHC.SysTools.Info +import Control.Monad (join, forM, filterM) +import System.Directory (doesFileExist) +import System.FilePath (()) + {- ************************************************************************ * * @@ -237,6 +241,32 @@ figureLlvmVersion dflags = traceToolCommand dflags "llc" $ do return Nothing) +-- | On macOS we rely on the linkers @-dead_strip_dylibs@ flag to remove unused +-- libraries from the dynamic library. We do this to reduce the number of load +-- commands that end up in the dylib, and has been limited to 32K (32768) since +-- macOS Sierra (10.14). +-- +-- @-dead_strip_dylibs@ does not dead strip @-rpath@ entries, as such passing +-- @-l@ and @-rpath@ to the linker will result in the unnecesasry libraries not +-- being included int he load commands, however the @-rpath@ entries are all +-- forced to be included. This can lead to 100s of @-rpath@ entries being +-- included when only a handful of liraries end up being turely linked. +-- +-- Thus after building the library, we run a fixup phase where we inject the +-- @-rpath@ for each found library (in the given library search paths) into the +-- dynamic library through @-add_rpath at . +runInjectRPaths :: DynFlags -> [FilePath] -> FilePath -> IO () +runInjectRPaths dflags lib_paths dylib = do + info <- lines <$> askOtool dflags Nothing [Option "-L", Option dylib] + -- filter the output for only the libraries. And then drop the @rpath prefix. + let libs = fmap (drop 7) $ filter (isPrefixOf "@rpath") $ fmap (head.words) $ info + rpaths <- nub.sort.join <$> forM libs (\f -> filterM (\l -> doesFileExist (l f)) lib_paths) + -- inject the rpaths + case rpaths of + [] -> return () + _ -> runInstallNameTool dflags $ map Option $ "-add_rpath":(intersperse "-add_rpath" rpaths) ++ [dylib] + + runLink :: DynFlags -> [Option] -> IO () runLink dflags args = traceToolCommand dflags "linker" $ do -- See Note [Run-time linker info] @@ -329,6 +359,17 @@ runAr dflags cwd args = traceToolCommand dflags "ar" $ do let ar = pgm_ar dflags runSomethingFiltered dflags id "Ar" ar args cwd Nothing +askOtool :: DynFlags -> Maybe FilePath -> [Option] -> IO String +askOtool dflags mb_cwd args = do + let otool = pgm_otool dflags + runSomethingWith dflags "otool" otool args $ \real_args -> + readCreateProcessWithExitCode' (proc otool real_args){ cwd = mb_cwd } + +runInstallNameTool :: DynFlags -> [Option] -> IO () +runInstallNameTool dflags args = do + let tool = pgm_install_name_tool dflags + runSomethingFiltered dflags id "Install Name Tool" tool args Nothing Nothing + runRanlib :: DynFlags -> [Option] -> IO () runRanlib dflags args = traceToolCommand dflags "ranlib" $ do let ranlib = pgm_ranlib dflags ===================================== configure.ac ===================================== @@ -697,6 +697,18 @@ else fi AC_SUBST([LibtoolCmd]) +dnl ** Which otool to use on macOS +dnl -------------------------------------------------------------- +AC_CHECK_TARGET_TOOL([OTOOL], [otool]) +OtoolCmd="$OTOOL" +AC_SUBST(OtoolCmd) + +dnl ** Which install_name_tool to use on macOS +dnl -------------------------------------------------------------- +AC_CHECK_TARGET_TOOL([INSTALL_NAME_TOOL], [install_name_tool]) +InstallNameToolCmd="$INSTALL_NAME_TOOL" +AC_SUBST(InstallNameToolCmd) + # Here is where we re-target which specific version of the LLVM # tools we are looking for. In the past, GHC supported a number of # versions of LLVM simultaneously, but that stopped working around @@ -1520,6 +1532,8 @@ echo "\ libtool : $LibtoolCmd objdump : $ObjdumpCmd ranlib : $RanlibCmd + otool : $OtoolCmd + install_name_tool : $InstallNameToolCmd windres : $WindresCmd dllwrap : $DllWrapCmd genlib : $GenlibCmd ===================================== docs/users_guide/phases.rst ===================================== @@ -95,6 +95,24 @@ given compilation phase: Use ⟨cmd⟩ as the pre-processor (with :ghc-flag:`-F` only). +.. ghc-flag:: -pgmotool ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the program to inspect mach-o dylibs on macOS + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the program to inspect mach-o dynamic libraries and + executables to read the dynamic library dependencies. We will compute + the necessary ``runpath``s to bembed for the dependencies based on the + result of the ``otool`` call. + +.. ghc-flag:: -pgminstall_name_tool ⟨cmd⟩ + :shortdesc: Use ⟨cmd⟩ as the program to inject ``runpath`` into mach-o dylibs on macOS + :type: dynamic + :category: phase-programs + + Use ⟨cmd⟩ as the program to inject ``runpath``s into mach-o dynamic + libraries and executables. As detected by the ``otool`` call. + .. ghc-flag:: -pgmwindres ⟨cmd⟩ :shortdesc: Use ⟨cmd⟩ as the program for embedding manifests on Windows. :type: dynamic ===================================== hadrian/cfg/system.config.in ===================================== @@ -151,6 +151,8 @@ settings-merge-objects-command = @SettingsMergeObjectsCommand@ settings-merge-objects-flags = @SettingsMergeObjectsFlags@ settings-ar-command = @SettingsArCommand@ settings-ranlib-command = @SettingsRanlibCommand@ +settings-otool-command = @SettingsOtoolCommand@ +settings-install_name_tool-command = @SettingsInstallNameToolCommand@ settings-dll-wrap-command = @SettingsDllWrapCommand@ settings-windres-command = @SettingsWindresCommand@ settings-libtool-command = @SettingsLibtoolCommand@ ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -114,6 +114,8 @@ data SettingsFileSetting | SettingsFileSetting_MergeObjectsFlags | SettingsFileSetting_ArCommand | SettingsFileSetting_RanlibCommand + | SettingsFileSetting_OtoolCommand + | SettingsFileSetting_InstallNameToolCommand | SettingsFileSetting_DllWrapCommand | SettingsFileSetting_WindresCommand | SettingsFileSetting_LibtoolCommand @@ -200,6 +202,8 @@ settingsFileSetting key = lookupValueOrError configFile $ case key of SettingsFileSetting_MergeObjectsFlags -> "settings-merge-objects-flags" SettingsFileSetting_ArCommand -> "settings-ar-command" SettingsFileSetting_RanlibCommand -> "settings-ranlib-command" + SettingsFileSetting_OtoolCommand -> "settings-otool-command" + SettingsFileSetting_InstallNameToolCommand -> "settings-install_name_tool-command" SettingsFileSetting_DllWrapCommand -> "settings-dll-wrap-command" SettingsFileSetting_WindresCommand -> "settings-windres-command" SettingsFileSetting_LibtoolCommand -> "settings-libtool-command" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -308,6 +308,8 @@ generateSettings = do , ("ar flags", expr $ lookupValueOrError configFile "ar-args") , ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile) , ("ranlib command", expr $ settingsFileSetting SettingsFileSetting_RanlibCommand) + , ("otool command", expr $ settingsFileSetting SettingsFileSetting_OtoolCommand) + , ("install_name_tool command", expr $ settingsFileSetting SettingsFileSetting_InstallNameToolCommand) , ("touch command", expr $ settingsFileSetting SettingsFileSetting_TouchCommand) , ("dllwrap command", expr $ settingsFileSetting SettingsFileSetting_DllWrapCommand) , ("windres command", expr $ settingsFileSetting SettingsFileSetting_WindresCommand) ===================================== includes/ghc.mk ===================================== @@ -233,6 +233,8 @@ $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/. @echo ',("ar flags", "$(ArArgs)")' >> $@ @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@ @echo ',("ranlib command", "$(SettingsRanlibCommand)")' >> $@ + @echo ',("otool command", "$(SettingsOtoolCommand)")' >> $@ + @echo ',("install_name_tool command", "$(SettingsInstallNameToolCommand)")' >> $@ @echo ',("touch command", "$(SettingsTouchCommand)")' >> $@ @echo ',("dllwrap command", "$(SettingsDllWrapCommand)")' >> $@ @echo ',("windres command", "$(SettingsWindresCommand)")' >> $@ ===================================== mk/config.mk.in ===================================== @@ -504,6 +504,8 @@ SettingsLdFlags = @SettingsLdFlags@ SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@ SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@ SettingsArCommand = @SettingsArCommand@ +SettingsOtoolCommand = @SettingsOtoolCommand@ +SettingsInstallNameToolCommand = @SettingsInstallNameToolCommand@ SettingsRanlibCommand = @SettingsRanlibCommand@ SettingsDllWrapCommand = @SettingsDllWrapCommand@ SettingsWindresCommand = @SettingsWindresCommand@ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3bb2834d22ed6607e3398005d34d019af0246cfa -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3bb2834d22ed6607e3398005d34d019af0246cfa You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 12:57:17 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Mon, 31 Aug 2020 08:57:17 -0400 Subject: [Git][ghc/ghc][wip/T18565] PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Message-ID: <5f4cf3ad8c51_80b3f8492490c2c98881b9@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18565 at Glasgow Haskell Compiler / GHC Commits: fc8ab7c9 by Sebastian Graf at 2020-08-31T14:57:03+02:00 PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Previously, we desugared and coverage checked plain guard trees as described in Lower Your Guards. That caused (in !3849) quite a bit of pain when we need to partially recover tree structure of the input syntax to return covered sets for long-distance information, for example. In this refactor, I introduced a guard tree variant for each relevant source syntax component of a pattern-match (mainly match groups, match, GRHS, empty case, pattern binding). I made sure to share as much coverage checking code as possible, so that the syntax-specific checking functions are just wrappers around the more substantial checking functions for the LYG primitives (`checkSequence`, `checkGrds`). The refactoring payed off in clearer code and elimination of all panics related to assumed guard tree structure and thus fixes #18565. I also took the liberty to rename and re-arrange the order of functions and comments in the module, deleted some dead and irrelevant Notes, wrote some new ones and gave an overview module haddock. - - - - - 14 changed files: - compiler/GHC/Data/OrdList.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - compiler/GHC/HsToCore/PmCheck/Types.hs - compiler/GHC/Tc/Types.hs - compiler/GHC/Utils/Misc.hs - testsuite/tests/deSugar/should_compile/ds020.stderr - testsuite/tests/module/all.T - testsuite/tests/pmcheck/should_compile/T18572.hs - testsuite/tests/rename/should_compile/T7085.stderr - testsuite/tests/unboxedsums/all.T Changes: ===================================== compiler/GHC/Data/OrdList.hs ===================================== @@ -5,13 +5,16 @@ -} {-# LANGUAGE DeriveFunctor #-} - {-# LANGUAGE BangPatterns #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE UnboxedSums #-} +{-# LANGUAGE UnboxedTuples #-} -- | Provide trees (of instructions), so that lists of instructions can be -- appended in linear time. module GHC.Data.OrdList ( - OrdList, + OrdList, pattern NilOL, pattern ConsOL, pattern SnocOL, nilOL, isNilOL, unitOL, appOL, consOL, snocOL, concatOL, lastOL, headOL, mapOL, fromOL, toOL, foldrOL, foldlOL, reverseOL, fromOLReverse, @@ -79,6 +82,50 @@ snocOL as b = Snoc as b consOL a bs = Cons a bs concatOL aas = foldr appOL None aas +pattern NilOL :: OrdList a +pattern NilOL <- (isNilOL -> True) where + NilOL = None + +-- | An unboxed 'Maybe' type with two unboxed fields in the 'Just' case. +-- Useful for defining 'viewCons' and 'viewSnoc' without overhead. +type VMaybe a b = (# (# a, b #) | (# #) #) +pattern VJust :: a -> b -> VMaybe a b +pattern VJust a b = (# (# a, b #) | #) +pattern VNothing :: VMaybe a b +pattern VNothing = (# | (# #) #) +{-# COMPLETE VJust, VNothing #-} + +pattern ConsOL :: a -> OrdList a -> OrdList a +pattern ConsOL x xs <- (viewCons -> VJust x xs) where + ConsOL x xs = consOL x xs +{-# COMPLETE NilOL, ConsOL #-} +viewCons :: OrdList a -> VMaybe a (OrdList a) +viewCons (One a) = VJust a NilOL +viewCons (Cons a as) = VJust a as +viewCons (Snoc as a) = case viewCons as of + VJust a' as' -> VJust a' (Snoc as' a) + VNothing -> VJust a NilOL +viewCons (Two as1 as2) = case viewCons as1 of + VJust a' as1' -> VJust a' (Two as1' as2) + VNothing -> viewCons as2 +viewCons _ = VNothing + +pattern SnocOL :: OrdList a -> a -> OrdList a +pattern SnocOL xs x <- (viewSnoc -> VJust xs x) where + SnocOL xs x = snocOL xs x +{-# COMPLETE NilOL, SnocOL #-} +viewSnoc :: OrdList a -> VMaybe (OrdList a) a +viewSnoc (One a) = VJust NilOL a +viewSnoc (Many (reverse -> a:as)) = VJust (Many (reverse as)) a +viewSnoc (Snoc as a) = VJust as a +viewSnoc (Cons a as) = case viewSnoc as of + VJust as' a' -> VJust (Cons a as') a' + VNothing -> VJust NilOL a +viewSnoc (Two as1 as2) = case viewSnoc as2 of + VJust as2' a' -> VJust (Two as1 as2') a' + VNothing -> viewSnoc as1 +viewSnoc _ = VNothing + headOL None = panic "headOL" headOL (One a) = a headOL (Many as) = head as @@ -189,5 +236,3 @@ strictlyOrdOL (Two a1 a2) (Two b1 b2) = strictlyOrdOL (Two _ _) _ = LT strictlyOrdOL (Many as) (Many bs) = compare as bs strictlyOrdOL (Many _ ) _ = GT - - ===================================== compiler/GHC/HsToCore/Binds.hs ===================================== @@ -33,7 +33,7 @@ import {-# SOURCE #-} GHC.HsToCore.Match ( matchWrapper ) import GHC.HsToCore.Monad import GHC.HsToCore.GuardedRHSs import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck ( addTyCsDs, covCheckGRHSs ) +import GHC.HsToCore.PmCheck ( addTyCs, covCheckGRHSs ) import GHC.Hs -- lots of things import GHC.Core -- lots of things @@ -151,14 +151,14 @@ dsHsBind dflags b@(FunBind { fun_id = L loc fun , fun_matches = matches , fun_ext = co_fn , fun_tick = tick }) - = do { (args, body) <- addTyCsDs FromSource (hsWrapDictBinders co_fn) $ + = do { (args, body) <- addTyCs FromSource (hsWrapDictBinders co_fn) $ -- FromSource might not be accurate (we don't have any -- origin annotations for things in this module), but at -- worst we do superfluous calls to the pattern match -- oracle. - -- addTyCsDs: Add type evidence to the refinement type + -- addTyCs: Add type evidence to the refinement type -- predicate of the coverage checker - -- See Note [Type and Term Equality Propagation] in "GHC.HsToCore.PmCheck" + -- See Note [Long-distance information] in "GHC.HsToCore.PmCheck" matchWrapper (mkPrefixFunRhs (L loc (idName fun))) Nothing matches @@ -200,11 +200,11 @@ dsHsBind dflags (AbsBinds { abs_tvs = tyvars, abs_ev_vars = dicts , abs_exports = exports , abs_ev_binds = ev_binds , abs_binds = binds, abs_sig = has_sig }) - = do { ds_binds <- addTyCsDs FromSource (listToBag dicts) $ + = do { ds_binds <- addTyCs FromSource (listToBag dicts) $ dsLHsBinds binds - -- addTyCsDs: push type constraints deeper + -- addTyCs: push type constraints deeper -- for inner pattern match check - -- See Check, Note [Type and Term Equality Propagation] + -- See Check, Note [Long-distance information] ; ds_ev_binds <- dsTcEvBinds_s ev_binds ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -31,7 +31,7 @@ import GHC.HsToCore.ListComp import GHC.HsToCore.Utils import GHC.HsToCore.Arrows import GHC.HsToCore.Monad -import GHC.HsToCore.PmCheck ( addTyCsDs, covCheckGRHSs ) +import GHC.HsToCore.PmCheck ( addTyCs, covCheckGRHSs ) import GHC.Types.Name import GHC.Types.Name.Env import GHC.Core.FamInstEnv( topNormaliseType ) @@ -283,7 +283,7 @@ dsExpr hswrap@(XExpr (WrapExpr (HsWrap co_fn e))) HsConLikeOut _ (RealDataCon dc) -> return $ varToCoreExpr (dataConWrapId dc) XExpr (WrapExpr (HsWrap _ _)) -> pprPanic "dsExpr: HsWrap inside HsWrap" (ppr hswrap) HsPar _ _ -> pprPanic "dsExpr: HsPar inside HsWrap" (ppr hswrap) - _ -> addTyCsDs FromSource (hsWrapDictBinders co_fn) $ + _ -> addTyCs FromSource (hsWrapDictBinders co_fn) $ dsExpr e -- See Note [Detecting forced eta expansion] ; wrap' <- dsHsWrapper co_fn ===================================== compiler/GHC/HsToCore/Match.hs ===================================== @@ -770,8 +770,8 @@ matchWrapper ctxt mb_scr (MG { mg_alts = L _ matches -- Each Match will split off one Deltas for its RHSs from this. ; matches_deltas <- if isMatchContextPmChecked dflags origin ctxt then addHsScrutTmCs mb_scr new_vars $ - -- See Note [Type and Term Equality Propagation] - covCheckMatchGroup (DsMatchContext ctxt locn) new_vars matches + -- See Note [Long-distance information] + covCheckMatches (DsMatchContext ctxt locn) new_vars matches else pure (initDeltasMatches matches) ; eqns_info <- zipWithM mk_eqn_info matches matches_deltas @@ -881,7 +881,7 @@ matchSinglePatVar var mb_scrut ctx pat ty match_result -- Pattern match check warnings ; when (isMatchContextPmChecked dflags FromSource ctx) $ addCoreScrutTmCs mb_scrut [var] $ - covCheckPatBind dflags (DsMatchContext ctx locn) var (unLoc pat) + covCheckPatBind (DsMatchContext ctx locn) var (unLoc pat) ; let eqn_info = EqnInfo { eqn_pats = [unLoc (decideBangHood dflags pat)] , eqn_orig = FromSource ===================================== compiler/GHC/HsToCore/PmCheck.hs ===================================== @@ -1,24 +1,49 @@ -{- -Author: George Karachalias - -Pattern Matching Coverage Checking. --} - -{-# LANGUAGE CPP #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE TupleSections #-} -{-# LANGUAGE ViewPatterns #-} -{-# LANGUAGE MultiWayIf #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE NamedFieldPuns #-} - +{-# LANGUAGE CPP #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE TupleSections #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE MultiWayIf #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE NamedFieldPuns #-} + +-- | This module coverage checks pattern matches. It finds +-- +-- * Uncovered patterns, certifying non-exhaustivity +-- * Redundant equations +-- * Equations with an inaccessible right-hand-side +-- +-- The algorithm is based on the paper +-- [Lower Your Guards: A Compositional Pattern-Match Coverage Checker"](https://dl.acm.org/doi/abs/10.1145/3408989) +-- +-- There is an overview Figure 2 in there that's probably helpful. +-- Here is an overview of how it's implemented, which follows the structure of +-- the entry points such as 'covCheckMatches': +-- +-- 1. Desugar source syntax (like 'LMatch') to guard tree variants (like +-- 'GrdMatch'), with one of the desugaring functions (like 'desugarMatch'). +-- Follows Section 3.1 in the paper. +-- 2. Coverage check guard trees (with a function like 'checkMatch') to get a +-- 'CheckResult', containing +-- a. The set of uncovered values, 'cr_uncov' +-- b. And an annotated tree variant (like 'AnnMatch') that captures +-- redundancy and inaccessibility information as 'RedSets' annotations +-- Basically the UA function from Section 5.1. The Normalised Refinement Types +-- Nabla are modeled as 'Deltas' and checked in "GHC.HsToCore.PmCheck.Oracle". +-- 3. Collect redundancy information into a 'CIRB' with a 'CIRBCollector' such +-- as 'collectMatch'. Follows the R function from Figure 6 of the paper. +-- 4. Format and report uncovered patterns and redundant equations ('CIRB') +-- with 'formatReportWarnings'. Basically job of the G function, plus proper +-- pretty printing of the warnings (Section 5.4 of the paper). +-- 5. Return 'Deltas' reaching syntactic sub-components for +-- Note [Long-distance information]. See Section 4.1 of the paper. module GHC.HsToCore.PmCheck ( -- Checking and printing - covCheckPatBind, covCheckMatchGroup, covCheckGRHSs, + covCheckPatBind, covCheckMatches, covCheckGRHSs, isMatchContextPmChecked, - -- See Note [Type and Term Equality Propagation] - addTyCsDs, addCoreScrutTmCs, addHsScrutTmCs + -- See Note [Long-distance information] + addTyCs, addCoreScrutTmCs, addHsScrutTmCs ) where #include "HsVersions.h" @@ -37,7 +62,6 @@ import GHC.Tc.Utils.Zonk (shortCutLit) import GHC.Types.Id import GHC.Core.ConLike import GHC.Types.Name -import GHC.Tc.Instance.Family import GHC.Builtin.Types import GHC.Types.SrcLoc import GHC.Utils.Misc @@ -62,35 +86,134 @@ import GHC.Core.Type import GHC.HsToCore.Utils (isTrueLHsExpr) import GHC.Data.Maybe import qualified GHC.LanguageExtensions as LangExt -import GHC.Utils.Monad (concatMapM) +import GHC.Utils.Monad (concatMapM, mapMaybeM) import Control.Monad (when, forM_, zipWithM) import Data.List (elemIndex) import qualified Data.Semigroup as Semi -import Data.List.NonEmpty (NonEmpty(..)) +import Data.List.NonEmpty ( NonEmpty(..) ) +import qualified Data.List.NonEmpty as NE +import Data.Coerce -{- -This module checks pattern matches for: -\begin{enumerate} - \item Equations that are redundant - \item Equations with inaccessible right-hand-side - \item Exhaustiveness -\end{enumerate} +-- +-- * Exported entry points to the checker +-- -The algorithm is based on the paper: +-- | Check a pattern binding (let, where) for exhaustiveness. +covCheckPatBind :: DsMatchContext -> Id -> Pat GhcTc -> DsM () +-- See Note [covCheckPatBind only checks PatBindRhs] +covCheckPatBind ctxt@(DsMatchContext PatBindRhs loc) var p = do + missing <- getPmDeltas + pat_bind <- desugarPatBind loc var p + tracePm "covCheckPatBind {" (vcat [ppr ctxt, ppr var, ppr p, ppr pat_bind, ppr missing]) + result <- unCA (checkPatBind pat_bind) missing + tracePm "}: " (ppr (cr_uncov result)) + formatReportWarnings collectPatBind ctxt [var] result +covCheckPatBind _ _ _ = pure () - "GADTs Meet Their Match: - Pattern-matching Warnings That Account for GADTs, Guards, and Laziness" +-- | Exhaustive for guard matches, is used for guards in pattern bindings and +-- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. +covCheckGRHSs + :: HsMatchContext GhcRn -- ^ Match context, for warning messages + -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check + -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long + -- distance info +covCheckGRHSs hs_ctxt guards@(GRHSs _ grhss _) = do + let combined_loc = foldl1 combineSrcSpans (map getLoc grhss) + ctxt = DsMatchContext hs_ctxt combined_loc + matches <- desugarGRHSs combined_loc empty guards + missing <- getPmDeltas + tracePm "covCheckGRHSs" (hang (vcat [ppr ctxt + , text "Guards:"]) + 2 + (pprGRHSs hs_ctxt guards $$ ppr missing)) + result <- unCA (checkGRHSs matches) missing + tracePm "}: " (ppr (cr_uncov result)) + formatReportWarnings (collectGRHSs missing) ctxt [] result + +-- | Check a list of syntactic 'Match'es (part of case, functions, etc.), each +-- with a 'Pat' and one or more 'GRHSs': +-- +-- @ +-- f x y | x == y = 1 -- match on x and y with two guarded RHSs +-- | otherwise = 2 +-- f _ _ = 3 -- clause with a single, un-guarded RHS +-- @ +-- +-- Returns one non-empty 'Deltas' for 1.) each pattern of a 'Match' and 2.) +-- each of a 'Match'es 'GRHS' for Note [Long-distance information]. +-- +-- Special case: When there are /no matches/, then the functionassumes it +-- checks and @-XEmptyCase@ with only a single match variable. +-- See Note [Checking EmptyCase]. +covCheckMatches + :: DsMatchContext -- ^ Match context, for warnings messages + -> [Id] -- ^ Match variables, i.e. x and y above + -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches + -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per Match and + -- GRHS, for long distance info. +covCheckMatches ctxt vars matches = do + -- We have to force @missing@ before printing out the trace message, + -- otherwise we get interleaved output from the solver. This function + -- should be strict in @missing@ anyway! + !missing <- getPmDeltas + tracePm "covCheckMatches {" $ + hang (vcat [ppr ctxt, ppr vars, text "Matches:"]) + 2 + (vcat (map ppr matches) $$ ppr missing) + case NE.nonEmpty matches of + Nothing -> do + -- This must be an -XEmptyCase. See Note [Checking EmptyCase] + let var = only vars + empty_case <- desugarEmptyCase var + result <- unCA (checkEmptyCase empty_case) missing + tracePm "}: " (ppr (cr_uncov result)) + [] <$ formatReportWarnings collectEmptyCase ctxt vars result + Just matches -> do + matches <- desugarMatches vars matches + result <- unCA (checkMatchGroup matches) missing + tracePm "}: " (ppr (cr_uncov result)) + NE.toList <$> formatReportWarnings (collectMatchGroup missing) ctxt vars result + +{- Note [covCheckPatBind only checks PatBindRhs] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + at covCheckPatBind@'s sole purpose is to check vanilla pattern bindings, like + at x :: Int; Just x = e@, which is in a @PatBindRhs@ context. +But its caller is also called for individual pattern guards in a @StmtCtxt at . +For example, both pattern guards in @f x y | True <- x, False <- y = ...@ will +go through this function. It makes no sense to do coverage checking there: + * Pattern guards may well fail. Fall-through is not an unrecoverable panic, + but rather behavior the programmer expects, so inexhaustivity should not be + reported. + * Redundancy is already reported for the whole GRHS via one of the other + exported coverage checking functions. Also reporting individual redundant + guards is... redundant. See #17646. +Note that we can't just omit checking of @StmtCtxt@ altogether (by adjusting +'isMatchContextPmChecked'), because that affects the other checking functions, +too. + +Note [Checking EmptyCase] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-XEmptyCase is useful for matching on empty data types like 'Void'. For example, +the following is a complete match: - https://www.microsoft.com/en-us/research/wp-content/uploads/2016/08/gadtpm-acm.pdf + f :: Void -> () + f x = case x of {} -%************************************************************************ -%* * - Pattern Match Check Types -%* * -%************************************************************************ +Really, -XEmptyCase is the only way to write a program that at the same time is +safe (@f _ = error "boom"@ is not because of ⊥), doesn't trigger a warning +(@f !_ = error "inaccessible" has inaccessible RHS) and doesn't turn an +exception into divergence (@f x = f x@). + +Semantically, unlike every other case expression, -XEmptyCase is strict in its +match var x, which rules out ⊥ as an inhabitant. So we add x /~ ⊥ to the +initial Delta and check if there are any values left to match on. -} +-- +-- * Guard language +-- + -- | A very simple language for pattern guards. Let bindings, bang patterns, -- and matching variables against flat constructor patterns. data PmGrd @@ -106,9 +229,9 @@ data PmGrd } -- | @PmBang x@ corresponds to a @seq x True@ guard. - -- If the extra SrcInfo is present, the bang guard came from a source - -- bang pattern, in which case we might want to report it as redundant, - -- see Note [Dead bang patterns]. + -- If the extra 'SrcInfo' is present, the bang guard came from a source + -- bang pattern, in which case we might want to report it as redundant. + -- See Note [Dead bang patterns]. | PmBang { pm_id :: !Id, pm_loc :: !(Maybe SrcInfo) @@ -144,24 +267,118 @@ instance Monoid Precision where mempty = Precise mappend = (Semi.<>) --- | Means by which we identify source location for later pretty-printing --- in a warning message. 'SDoc' for the equation to show, 'Located' for --- the location. +-- +-- * Guard tree language +-- + +-- | Means by which we identify a source construct for later pretty-printing in +-- a warning message. 'SDoc' for the equation to show, 'Located' for the +-- location. type SrcInfo = Located SDoc --- | A representation of the desugaring to 'PmGrd's of all clauses of a --- function definition/pattern match/etc. -data GrdTree - = Rhs !SrcInfo - | Guard !PmGrd !GrdTree - -- ^ @Guard grd t@ will try to match @grd@ and on success continue to match - -- @t at . Falls through if either match fails. Models left-to-right semantics - -- of pattern matching. - | Sequence ![GrdTree] - -- ^ @Sequence (t:ts)@ matches against @t@, and then matches all - -- fallen-through values against @Sequence ts at . Models top-to-bottom semantics - -- of pattern matching. - -- @Sequence []@ always fails; it is useful for Note [Checking EmptyCase]. +-- | A guard tree denoting 'MatchGroup'. +newtype GrdMatchGroup = GrdMatchGroup (NonEmpty GrdMatch) + +-- | A guard tree denoting 'Match'. +data GrdMatch = GrdMatch { gm_pats :: ![PmGrd], gm_grhss :: !(NonEmpty GrdGRHS) } + +-- | A guard tree denoting 'GRHS'. +data GrdGRHS = GrdGRHS { gg_grds :: ![PmGrd], gg_rhs :: !SrcInfo } + +-- | A guard tree denoting an -XEmptyCase. +newtype GrdEmptyCase = GrdEmptyCase { ge_var :: Id } + +-- | A guard tree denoting a pattern binding. +newtype GrdPatBind = + -- just reuse GrdGRHS and pretend its @SrcInfo@ is info on the /pattern/, + -- rather than on the pattern bindings. + GrdPatBind GrdGRHS + +-- | Redundancy sets, used to determine redundancy of RHSs and bang patterns +-- (later digested into a 'CIRB'). +data RedSets + = RedSets + { rs_cov :: !Deltas + -- ^ The /Covered/ set; the set of values reaching a particular program + -- point. + , rs_div :: !Deltas + -- ^ The /Diverging/ set; empty if no match can lead to divergence. + -- If it wasn't empty, we have to turn redundancy warnings into + -- inaccessibility warnings for any subclauses. + , rs_bangs :: !(OrdList (Deltas, SrcInfo)) + -- ^ If any of the 'Deltas' is empty, the corresponding 'SrcInfo' pin-points + -- a bang pattern in source that is redundant. See Note [Dead bang patterns]. + } + +emptyRedSets :: RedSets +-- Semigroup instance would be misleading! +emptyRedSets = RedSets mempty mempty mempty + +-- | An annotated tree denoting 'MatchGroup'. +newtype AnnMatchGroup = AnnMatchGroup (NonEmpty AnnMatch) + +-- | An annotated tree denoting 'Match'. +data AnnMatch = AnnMatch { am_red :: !RedSets, am_grhss :: !(NonEmpty AnnGRHS) } + +-- | An annotated tree denoting 'GRHS'. +data AnnGRHS = AnnGRHS { ag_red :: !RedSets, ag_rhs :: !SrcInfo } + +-- | An annotated tree denoting an -XEmptyCase. +data AnnEmptyCase = AnnEmptyCase + +-- | An annotated tree denoting a pattern binding. +newtype AnnPatBind = AnnPatBind AnnGRHS + +pprSrcInfo :: SrcInfo -> SDoc +pprSrcInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) +pprSrcInfo (L s _) = ppr s + +-- | Format LYG guards as @| True <- x, let x = 42, !z@ +pprLygGuards :: [PmGrd] -> SDoc +pprLygGuards [] = empty +pprLygGuards (g:gs) = fsep (char '|' <+> ppr g : map ((comma <+>) . ppr) gs) + +-- | Format a LYG sequence (e.g. 'Match'es of a 'MatchGroup' or 'GRHSs') as +-- @{ ; ...; }@ +pprLygSequence :: Outputable a => NonEmpty a -> SDoc +pprLygSequence (NE.toList -> as) = + braces (space <> fsep (punctuate semi (map ppr as)) <> space) + +instance Outputable GrdMatchGroup where + ppr (GrdMatchGroup matches) = pprLygSequence matches + +instance Outputable GrdMatch where + ppr (GrdMatch { gm_pats = grds, gm_grhss = grhss }) = + pprLygGuards grds <+> ppr grhss + +instance Outputable GrdGRHS where + ppr (GrdGRHS { gg_grds = grds, gg_rhs = rhs }) = + pprLygGuards grds <+> text "->" <+> pprSrcInfo rhs + +instance Outputable GrdPatBind where + ppr (GrdPatBind GrdGRHS { gg_grds = grds, gg_rhs = bind }) = + ppr bind <+> pprLygGuards grds <+> text "=" <+> text "..." + +instance Outputable GrdEmptyCase where + ppr (GrdEmptyCase { ge_var = var }) = + text " ppr var <> text ">" + +pprRedSets :: RedSets -> SDoc +-- It's useful to change this definition for different verbosity levels in +-- printf-debugging +pprRedSets RedSets { rs_cov = _cov, rs_div = _div, rs_bangs = _bangs } + = empty + +instance Outputable AnnMatchGroup where + ppr (AnnMatchGroup matches) = pprLygSequence matches + +instance Outputable AnnMatch where + ppr (AnnMatch { am_red = red, am_grhss = grhss }) = + pprRedSets red <+> ppr grhss + +instance Outputable AnnGRHS where + ppr (AnnGRHS { ag_red = red, ag_rhs = rhs }) = + pprRedSets red <+> text "->" <+> pprSrcInfo rhs {- Note [Dead bang patterns] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -178,7 +395,7 @@ that under no circumstances can force a thunk that wasn't already forced. Dead bangs are a form of redundant bangs; see below. We can detect dead bang patterns by checking whether @x ~ ⊥@ is satisfiable -where the PmBang appears in 'checkGrdTree'. If not, then clearly the bang is +where the PmBang appears in 'checkGrd'. If not, then clearly the bang is dead. Such a dead bang is then indicated in the annotated pattern-match tree by a 'RedundantSrcBang' wrapping. In 'redundantAndInaccessibles', we collect all dead bangs to warn about. @@ -197,236 +414,9 @@ it is redundant with the forcing done by the () match. We currently don't detect redundant bangs that aren't dead. -} --- | The digest of 'checkGrdTree', representing the annotated pattern-match --- tree. 'extractRedundancyInfo' can figure out redundant and proper --- inaccessible RHSs from this, as well as dead bangs. -data AnnotatedTree - = AccessibleRhs !Deltas !SrcInfo - -- ^ A RHS deemed accessible. The 'Deltas' is the (non-empty) set of covered - -- values. - | InaccessibleRhs !SrcInfo - -- ^ A RHS deemed inaccessible; it covers no value. - | MayDiverge !AnnotatedTree - -- ^ Asserts that the tree may force diverging values, so not all of its - -- clauses can be redundant. - | SequenceAnn !Deltas ![AnnotatedTree] - -- ^ @SequenceAnn inc ts@ mirrors @'Sequence' ts@ for preserving the - -- skeleton of a 'GrdTree's @ts at . It also carries the set of incoming values - -- @inc at . - | RedundantSrcBang !SrcInfo !AnnotatedTree - -- ^ For tracking redundant bangs. See Note [Dead bang patterns] - -pprSrcInfo :: SrcInfo -> SDoc -pprSrcInfo (L (RealSrcSpan rss _) _) = ppr (srcSpanStartLine rss) -pprSrcInfo (L s _) = ppr s - -instance Outputable GrdTree where - ppr (Rhs info) = text "->" <+> pprSrcInfo info - -- Format guards as "| True <- x, let x = 42, !z" - ppr g at Guard{} = fsep (prefix (map ppr grds)) <+> ppr t - where - (t, grds) = collect_grds g - collect_grds (Guard grd t) = (grd :) <$> collect_grds t - collect_grds t = (t, []) - prefix [] = [] - prefix (s:sdocs) = char '|' <+> s : map (comma <+>) sdocs - ppr (Sequence []) = text "" - ppr (Sequence ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) - -instance Outputable AnnotatedTree where - ppr (AccessibleRhs _delta info) = parens (ppr _delta) <+> pprSrcInfo info - ppr (InaccessibleRhs info) = text "inaccessible" <+> pprSrcInfo info - ppr (MayDiverge t) = text "div" <+> ppr t - ppr (SequenceAnn _ []) = text "" - ppr (SequenceAnn _ ts) = braces (space <> fsep (punctuate semi (map ppr ts)) <> space) - ppr (RedundantSrcBang l t) = text "redundant bang" <+> pprSrcInfo l <+> ppr t - --- | Lift 'addPmCts' over 'Deltas'. -addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas -addPmCtsDeltas deltas cts = liftDeltasM (\d -> addPmCts d cts) deltas - --- | 'addPmCtsDeltas' a single 'PmCt'. -addPmCtDeltas :: Deltas -> PmCt -> DsM Deltas -addPmCtDeltas deltas ct = addPmCtsDeltas deltas (unitBag ct) - --- | Test if any of the 'Delta's is inhabited. Currently this is pure, because --- we preserve the invariant that there are no uninhabited 'Delta's. But that --- could change in the future, for example by implementing this function in --- terms of @notNull <$> provideEvidence 1 ds at . -isInhabited :: Deltas -> DsM Bool -isInhabited (MkDeltas ds) = pure (not (null ds)) - --- | Pattern-match check result -data CheckResult - = CheckResult - { cr_clauses :: !AnnotatedTree - -- ^ Captures redundancy info for each clause in the original program. - -- (for -Woverlapping-patterns) - , cr_uncov :: !Deltas - -- ^ The set of uncovered values falling out at the bottom. - -- (for -Wincomplete-patterns) - , cr_approx :: !Precision - -- ^ A flag saying whether we ran into the 'maxPmCheckModels' limit for the - -- purpose of suggesting to crank it up in the warning message - } - -instance Outputable CheckResult where - ppr (CheckResult c unc pc) - = text "CheckResult" <+> ppr_precision pc <+> braces (fsep - [ field "clauses" c <> comma - , field "uncov" unc]) - where - ppr_precision Precise = empty - ppr_precision Approximate = text "(Approximate)" - field name value = text name <+> equals <+> ppr value - -{- -%************************************************************************ -%* * - Entry points to the checker: covCheckPatBind and covCheckMatchGroup -%* * -%************************************************************************ --} - --- | Check a pattern binding (let, where) for exhaustiveness. -covCheckPatBind :: DynFlags -> DsMatchContext -> Id -> Pat GhcTc -> DsM () -covCheckPatBind dflags ctxt@(DsMatchContext _ locn) var p = do - -- We only ever need to run this in a context where we need exhaustivity - -- warnings (so not in pattern guards or comprehensions, for example, because - -- they are perfectly fine to fail). - -- Omitting checking this flag emits redundancy warnings twice in obscure - -- cases like #17646. - -- Given the context in which this function is called, it will only ever do - -- something for - -- * PatBindRhs, -Wincomplete-uni-patterns: @let True = False@ - -- * PatBindGuards, -Wincomplete-patterns: @Just x | False = Just 42@ - missing <- getPmDeltas - tracePm "covCheckPatBind" (vcat [ppr ctxt, ppr var, ppr p, ppr missing]) - fam_insts <- dsGetFamInstEnvs - grd_tree <- mkGrdTreeRhs (L locn $ ppr p) <$> translatePat fam_insts var p - res <- checkGrdTree grd_tree missing - dsPmWarn dflags ctxt [var] res - --- | Exhaustive for guard matches, is used for guards in pattern bindings and --- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. -covCheckGRHSs - :: HsMatchContext GhcRn -- ^ Match context, for warning messages - -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check - -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long - -- distance info -covCheckGRHSs hs_ctx guards@(GRHSs _ grhss _) = do - let combinedLoc = foldl1 combineSrcSpans (map getLoc grhss) - dsMatchContext = DsMatchContext hs_ctx combinedLoc - match = L combinedLoc $ - Match { m_ext = noExtField - , m_ctxt = hs_ctx - , m_pats = [] - , m_grhss = guards } - [(_, deltas)] <- covCheckMatchGroup dsMatchContext [] [match] - pure deltas - --- | Check a list of syntactic /match/es (part of case, functions, etc.), each --- with a /pat/ and one or more /grhss/: -- --- @ --- f x y | x == y = 1 -- match on x and y with two guarded RHSs --- | otherwise = 2 --- f _ _ = 3 -- clause with a single, un-guarded RHS --- @ +-- * Desugaring source syntax to guard trees -- --- Returns one 'Deltas' for each GRHS, representing its covered values, or the --- incoming uncovered 'Deltas' (from 'getPmDeltas') if the GRHS is inaccessible. --- Since there is at least one /grhs/ per /match/, the list of 'Deltas' is at --- least as long as the list of matches. -covCheckMatchGroup - :: DsMatchContext -- ^ Match context, for warnings messages - -> [Id] -- ^ Match variables, i.e. x and y above - -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches - -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per RHS, for long - -- distance info. -covCheckMatchGroup ctxt vars matches = do - tracePm "covCheckMatchGroup" (hang (vcat [ppr ctxt - , ppr vars - , text "Matches:"]) - 2 - (vcat (map ppr matches))) - - init_deltas <- getPmDeltas - missing <- case matches of - -- This must be an -XEmptyCase. See Note [Checking EmptyCase] - [] | [var] <- vars -> addPmCtDeltas init_deltas (PmNotBotCt var) - _ -> pure init_deltas - fam_insts <- dsGetFamInstEnvs - grd_tree <- translateMatches fam_insts vars matches - res <- checkGrdTree grd_tree missing - - dflags <- getDynFlags - dsPmWarn dflags ctxt vars res - - return (extractRhsDeltas (cr_clauses res)) - --- | Extract the 'Deltas' reaching the RHSs of the 'AnnotatedTree' for a match --- group. --- For 'AccessibleRhs's, this is stored in the tree node, whereas --- 'InaccessibleRhs's fall back to the supplied original 'Deltas'. --- See @Note [Recovering from unsatisfiable pattern-matching constraints]@. -extractRhsDeltas :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] -extractRhsDeltas = go_matches - where - go_matches :: AnnotatedTree -> [(Deltas, NonEmpty Deltas)] - go_matches (SequenceAnn def ts) = map (go_match def) ts -- -XEmptyCase handled here! - go_matches t = pprPanic "extractRhsDeltas.go_matches" (text "Matches must start with SequenceAnn. But was" $$ ppr t) - - go_match :: Deltas -> AnnotatedTree -> (Deltas, NonEmpty Deltas) - -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ - -- is non-empty! - go_match def (SequenceAnn pat ts) = (pat, foldMap1 (text "go_match: empty SequenceAnn") (go_grhss def) ts) - go_match def (MayDiverge t) = go_match def t - go_match def (RedundantSrcBang _ t) = go_match def t - -- Even if there's only a single GRHS, we wrap it in a SequenceAnn for the - -- Deltas covered by the pattern. So the remaining cases are impossible! - go_match _ t = pprPanic "extractRhsDeltas.go_match" (text "Single GRHS must be wrapped in SequenceAnn. But got " $$ ppr t) - - go_grhss :: Deltas -> AnnotatedTree -> NonEmpty Deltas - -- There is no -XEmptyCase at this level, only at the Matches level. So @ts@ - -- is non-empty! - go_grhss def (SequenceAnn _ ts) = foldMap1 (text "go_grhss: empty SequenceAnn") (go_grhss def) ts - go_grhss def (MayDiverge t) = go_grhss def t - go_grhss def (RedundantSrcBang _ t) = go_grhss def t - go_grhss _ (AccessibleRhs deltas _) = deltas :| [] - go_grhss def (InaccessibleRhs _) = def :| [] - - foldMap1 msg _ [] = pprPanic "extractRhsDeltas.foldMap1" msg - foldMap1 _ f (x:xs) = foldl' (\acc x -> acc Semi.<> f x) (f x) xs - -{- Note [Checking EmptyCase] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --XEmptyCase is useful for matching on empty data types like 'Void'. For example, -the following is a complete match: - - f :: Void -> () - f x = case x of {} - -Really, -XEmptyCase is the only way to write a program that at the same time is -safe (@f _ = error "boom"@ is not because of ⊥), doesn't trigger a warning -(@f !_ = error "inaccessible" has inaccessible RHS) and doesn't turn an -exception into divergence (@f x = f x@). - -Semantically, unlike every other case expression, -XEmptyCase is strict in its -match var x, which rules out ⊥ as an inhabitant. So we add x /~ ⊥ to the -initial Delta and check if there are any values left to match on. --} - -{- -%************************************************************************ -%* * - Transform source syntax to *our* syntax -%* * -%************************************************************************ --} - --- ----------------------------------------------------------------------- --- * Utilities -- | Smart constructor that eliminates trivial lets mkPmLetVar :: Id -> Id -> GrdVec @@ -459,7 +449,7 @@ mkListGrds a ((x, head_grds):xs) = do -- | Create a 'GrdVec' refining a match variable to a 'PmLit'. mkPmLitGrds :: Id -> PmLit -> DsM GrdVec mkPmLitGrds x (PmLit _ (PmLitString s)) = do - -- We translate String literals to list literals for better overlap reasoning. + -- We desugar String literals to list literals for better overlap reasoning. -- It's a little unfortunate we do this here rather than in -- 'GHC.HsToCore.PmCheck.Oracle.trySolve' and -- 'GHC.HsToCore.PmCheck.Oracle.addRefutableAltCon', but it's so much simpler @@ -477,37 +467,34 @@ mkPmLitGrds x lit = do , pm_con_args = [] } pure [grd] --- ----------------------------------------------------------------------- --- * Transform (Pat Id) into GrdVec - --- | @translatePat _ x pat@ transforms @pat@ into a 'GrdVec', where +-- | @desugarPat _ x pat@ transforms @pat@ into a 'GrdVec', where -- the variable representing the match is @x at . -translatePat :: FamInstEnvs -> Id -> Pat GhcTc -> DsM GrdVec -translatePat fam_insts x pat = case pat of +desugarPat :: Id -> Pat GhcTc -> DsM GrdVec +desugarPat x pat = case pat of WildPat _ty -> pure [] VarPat _ y -> pure (mkPmLetVar (unLoc y) x) - ParPat _ p -> translateLPat fam_insts x p + ParPat _ p -> desugarLPat x p LazyPat _ _ -> pure [] -- like a wildcard BangPat _ p@(L l p') -> -- Add the bang in front of the list, because it will happen before any -- nested stuff. - (PmBang x pm_loc :) <$> translateLPat fam_insts x p - where pm_loc = Just (L l (ppr p')) + (PmBang x pm_loc :) <$> desugarLPat x p + where pm_loc = Just (L l (ppr p')) - -- (x at pat) ==> Translate pat with x as match var and handle impedance + -- (x at pat) ==> Desugar pat with x as match var and handle impedance -- mismatch with incoming match var - AsPat _ (L _ y) p -> (mkPmLetVar y x ++) <$> translateLPat fam_insts y p + AsPat _ (L _ y) p -> (mkPmLetVar y x ++) <$> desugarLPat y p - SigPat _ p _ty -> translateLPat fam_insts x p + SigPat _ p _ty -> desugarLPat x p - -- See Note [Translate CoPats] + -- See Note [Desugar CoPats] -- Generally the translation is -- pat |> co ===> let y = x |> co, pat <- y where y is a match var of pat XPat (CoPat wrapper p _ty) - | isIdHsWrapper wrapper -> translatePat fam_insts x p - | WpCast co <- wrapper, isReflexiveCo co -> translatePat fam_insts x p + | isIdHsWrapper wrapper -> desugarPat x p + | WpCast co <- wrapper, isReflexiveCo co -> desugarPat x p | otherwise -> do - (y, grds) <- translatePatV fam_insts p + (y, grds) <- desugarPatV p wrap_rhs_y <- dsHsWrapper wrapper pure (PmLet y (wrap_rhs_y (Var x)) : grds) @@ -522,13 +509,13 @@ translatePat fam_insts x pat = case pat of -- (fun -> pat) ===> let y = fun x, pat <- y where y is a match var of pat ViewPat _arg_ty lexpr pat -> do - (y, grds) <- translateLPatV fam_insts pat + (y, grds) <- desugarLPatV pat fun <- dsLExpr lexpr pure $ PmLet y (App fun (Var x)) : grds -- list ListPat (ListPatTc _elem_ty Nothing) ps -> - translateListPat fam_insts x ps + desugarListPat x ps -- overloaded list ListPat (ListPatTc elem_ty (Just (pat_ty, to_list))) pats -> do @@ -536,11 +523,11 @@ translatePat fam_insts x pat = case pat of case splitListTyConApp_maybe pat_ty of Just _e_ty | not (xopt LangExt.RebindableSyntax dflags) - -- Just translate it as a regular ListPat - -> translateListPat fam_insts x pats + -- Just desugar it as a regular ListPat + -> desugarListPat x pats _ -> do y <- mkPmId (mkListTy elem_ty) - grds <- translateListPat fam_insts y pats + grds <- desugarListPat y pats rhs_y <- dsSyntaxExpr to_list [Var x] pure $ PmLet y rhs_y : grds @@ -566,7 +553,7 @@ translatePat fam_insts x pat = case pat of , cpt_dicts = dicts } } -> do - translateConPatOut fam_insts x con arg_tys ex_tvs dicts ps + desugarConPatOut x con arg_tys ex_tvs dicts ps NPat ty (L _ olit) mb_neg _ -> do -- See Note [Literal short cut] in "GHC.HsToCore.Match.Literal" @@ -595,46 +582,44 @@ translatePat fam_insts x pat = case pat of mkPmLitGrds x lit TuplePat _tys pats boxity -> do - (vars, grdss) <- mapAndUnzipM (translateLPatV fam_insts) pats + (vars, grdss) <- mapAndUnzipM desugarLPatV pats let tuple_con = tupleDataCon boxity (length vars) pure $ vanillaConGrd x tuple_con vars : concat grdss SumPat _ty p alt arity -> do - (y, grds) <- translateLPatV fam_insts p + (y, grds) <- desugarLPatV p let sum_con = sumDataCon alt arity -- See Note [Unboxed tuple RuntimeRep vars] in GHC.Core.TyCon pure $ vanillaConGrd x sum_con [y] : grds - -- -------------------------------------------------------------------------- - -- Not supposed to happen - SplicePat {} -> panic "Check.translatePat: SplicePat" + SplicePat {} -> panic "Check.desugarPat: SplicePat" --- | 'translatePat', but also select and return a new match var. -translatePatV :: FamInstEnvs -> Pat GhcTc -> DsM (Id, GrdVec) -translatePatV fam_insts pat = do +-- | 'desugarPat', but also select and return a new match var. +desugarPatV :: Pat GhcTc -> DsM (Id, GrdVec) +desugarPatV pat = do x <- selectMatchVar Many pat - grds <- translatePat fam_insts x pat + grds <- desugarPat x pat pure (x, grds) -translateLPat :: FamInstEnvs -> Id -> LPat GhcTc -> DsM GrdVec -translateLPat fam_insts x = translatePat fam_insts x . unLoc +desugarLPat :: Id -> LPat GhcTc -> DsM GrdVec +desugarLPat x = desugarPat x . unLoc --- | 'translateLPat', but also select and return a new match var. -translateLPatV :: FamInstEnvs -> LPat GhcTc -> DsM (Id, GrdVec) -translateLPatV fam_insts = translatePatV fam_insts . unLoc +-- | 'desugarLPat', but also select and return a new match var. +desugarLPatV :: LPat GhcTc -> DsM (Id, GrdVec) +desugarLPatV = desugarPatV . unLoc --- | @translateListPat _ x [p1, ..., pn]@ is basically --- @translateConPatOut _ x $(mkListConPatOuts [p1, ..., pn]>@ without ever +-- | @desugarListPat _ x [p1, ..., pn]@ is basically +-- @desugarConPatOut _ x $(mkListConPatOuts [p1, ..., pn]>@ without ever -- constructing the 'ConPatOut's. -translateListPat :: FamInstEnvs -> Id -> [LPat GhcTc] -> DsM GrdVec -translateListPat fam_insts x pats = do - vars_and_grdss <- traverse (translateLPatV fam_insts) pats +desugarListPat :: Id -> [LPat GhcTc] -> DsM GrdVec +desugarListPat x pats = do + vars_and_grdss <- traverse desugarLPatV pats mkListGrds x vars_and_grdss --- | Translate a constructor pattern -translateConPatOut :: FamInstEnvs -> Id -> ConLike -> [Type] -> [TyVar] +-- | Desugar a constructor pattern +desugarConPatOut :: Id -> ConLike -> [Type] -> [TyVar] -> [EvVar] -> HsConPatDetails GhcTc -> DsM GrdVec -translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case +desugarConPatOut x con univ_tys ex_tvs dicts = \case PrefixCon ps -> go_field_pats (zip [0..] ps) InfixCon p1 p2 -> go_field_pats (zip [0..] [p1,p2]) RecCon (HsRecFields fs _) -> go_field_pats (rec_field_ps fs) @@ -648,7 +633,7 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case where tagged_pat f = (lbl_to_index (getName (hsRecFieldId f)), hsRecFieldArg f) -- Unfortunately the label info is empty when the DataCon wasn't defined - -- with record field labels, hence we translate to field index. + -- with record field labels, hence we desugar to field index. orig_lbls = map flSelector $ conLikeFieldLabels con lbl_to_index lbl = expectJust "lbl_to_index" $ elemIndex lbl orig_lbls @@ -659,10 +644,10 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- the first field of @tagged_pats at . -- See Note [Field match order for RecCon] - -- Translate the mentioned field patterns. We're doing this first to get + -- Desugar the mentioned field patterns. We're doing this first to get -- the Ids for pm_con_args. let trans_pat (n, pat) = do - (var, pvec) <- translateLPatV fam_insts pat + (var, pvec) <- desugarLPatV pat pure ((n, var), pvec) (tagged_vars, arg_grdss) <- mapAndUnzipM trans_pat tagged_pats @@ -688,77 +673,81 @@ translateConPatOut fam_insts x con univ_tys ex_tvs dicts = \case -- 1. 2. 3. pure (con_grd : bang_grds ++ arg_grds) --- | Translate a the 'Match'es of a 'MatchGroup' -translateMatches :: FamInstEnvs -> [Id] -> [LMatch GhcTc (LHsExpr GhcTc)] - -> DsM GrdTree -translateMatches fam_insts vars matches = - -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. - -- 'extractRhsDeltas' needs this to recover 'MatchGroup' structure. - Sequence <$> traverse (translateMatch fam_insts vars) matches - --- Translate a single match -translateMatch :: FamInstEnvs -> [Id] -> LMatch GhcTc (LHsExpr GhcTc) - -> DsM GrdTree -translateMatch fam_insts vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do - pats' <- concat <$> zipWithM (translateLPat fam_insts) vars pats - grhss' <- translateGRHSs fam_insts match_loc (sep (map ppr pats)) grhss - -- tracePm "translateMatch" (vcat [ppr pats, ppr pats', ppr grhss']) - return (foldr Guard grhss' pats') - -mkGrdTreeRhs :: Located SDoc -> GrdVec -> GrdTree -mkGrdTreeRhs sdoc = foldr Guard (Rhs sdoc) - -translateGRHSs :: FamInstEnvs -> SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateGRHSs fam_insts match_loc pp_pats grhss = - -- It's important that we wrap a 'Sequence' even if it only wraps a singleton. - -- 'extractRhsDeltas' needs this to recover 'GRHSs' structure. - Sequence <$> traverse (translateLGRHS fam_insts match_loc pp_pats) (grhssGRHSs grhss) - --- | Translate a guarded right-hand side to a single 'GrdTree' -translateLGRHS :: FamInstEnvs -> SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdTree -translateLGRHS fam_insts match_loc pp_pats (L _loc (GRHS _ gs _)) = - -- _loc points to the match separator (ie =, ->) that comes after the guards.. - mkGrdTreeRhs loc_sdoc <$> concatMapM (translateGuard fam_insts . unLoc) gs - where - loc_sdoc - -- pp_pats is the space-separated pattern of the current Match this - -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . - | null gs = L match_loc pp_pats - | otherwise = L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) - L grd_loc _ = head gs - --- | Translate a guard statement to a 'GrdVec' -translateGuard :: FamInstEnvs -> GuardStmt GhcTc -> DsM GrdVec -translateGuard fam_insts guard = case guard of - BodyStmt _ e _ _ -> translateBoolGuard e - LetStmt _ binds -> translateLet (unLoc binds) - BindStmt _ p e -> translateBind fam_insts p e - LastStmt {} -> panic "translateGuard LastStmt" - ParStmt {} -> panic "translateGuard ParStmt" - TransStmt {} -> panic "translateGuard TransStmt" - RecStmt {} -> panic "translateGuard RecStmt" - ApplicativeStmt {} -> panic "translateGuard ApplicativeLastStmt" - --- | Translate let-bindings -translateLet :: HsLocalBinds GhcTc -> DsM GrdVec -translateLet _binds = return [] - --- | Translate a pattern guard +desugarPatBind :: SrcSpan -> Id -> Pat GhcTc -> DsM GrdPatBind +-- See 'GrdPatBind' for how this simply repurposes GrdGRHS. +desugarPatBind loc var pat = + GrdPatBind . flip GrdGRHS (L loc (ppr pat)) <$> desugarPat var pat + +desugarEmptyCase :: Id -> DsM GrdEmptyCase +desugarEmptyCase var = pure GrdEmptyCase { ge_var = var } + +-- | Desugar the non-empty 'Match'es of a 'MatchGroup'. +desugarMatches :: [Id] -> NonEmpty (LMatch GhcTc (LHsExpr GhcTc)) + -> DsM GrdMatchGroup +desugarMatches vars matches = + GrdMatchGroup <$> traverse (desugarMatch vars) matches + +-- Desugar a single match +desugarMatch :: [Id] -> LMatch GhcTc (LHsExpr GhcTc) -> DsM GrdMatch +desugarMatch vars (L match_loc (Match { m_pats = pats, m_grhss = grhss })) = do + pats' <- concat <$> zipWithM desugarLPat vars pats + grhss' <- desugarGRHSs match_loc (sep (map ppr pats)) grhss + -- tracePm "desugarMatch" (vcat [ppr pats, ppr pats', ppr grhss']) + return GrdMatch { gm_pats = pats', gm_grhss = grhss' } + +desugarGRHSs :: SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM (NonEmpty GrdGRHS) +desugarGRHSs match_loc pp_pats grhss + = traverse (desugarLGRHS match_loc pp_pats) + . expectJust "desugarGRHSs" + . NE.nonEmpty + $ grhssGRHSs grhss + +-- | Desugar a guarded right-hand side to a single 'GrdTree' +desugarLGRHS :: SrcSpan -> SDoc -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM GrdGRHS +desugarLGRHS match_loc pp_pats (L _loc (GRHS _ gs _)) = do + -- _loc points to the match separator (ie =, ->) that comes after the guards. + -- Hence we have to pass in the match_loc, which we use in case that the RHS + -- is unguarded. + -- pp_pats is the space-separated pattern of the current Match this + -- GRHS belongs to, so the @A B x@ part in @A B x | 0 <- x at . + let rhs_info = case gs of + [] -> L match_loc pp_pats + (L grd_loc _):_ -> L grd_loc (pp_pats <+> vbar <+> interpp'SP gs) + grds <- concatMapM (desugarGuard . unLoc) gs + pure GrdGRHS { gg_grds = grds, gg_rhs = rhs_info } + +-- | Desugar a guard statement to a 'GrdVec' +desugarGuard :: GuardStmt GhcTc -> DsM GrdVec +desugarGuard guard = case guard of + BodyStmt _ e _ _ -> desugarBoolGuard e + LetStmt _ binds -> desugarLet (unLoc binds) + BindStmt _ p e -> desugarBind p e + LastStmt {} -> panic "desugarGuard LastStmt" + ParStmt {} -> panic "desugarGuard ParStmt" + TransStmt {} -> panic "desugarGuard TransStmt" + RecStmt {} -> panic "desugarGuard RecStmt" + ApplicativeStmt {} -> panic "desugarGuard ApplicativeLastStmt" + +-- | Desugar let-bindings +desugarLet :: HsLocalBinds GhcTc -> DsM GrdVec +desugarLet _binds = return [] + +-- | Desugar a pattern guard -- @pat <- e ==> let x = e; @ -translateBind :: FamInstEnvs -> LPat GhcTc -> LHsExpr GhcTc -> DsM GrdVec -translateBind fam_insts p e = dsLExpr e >>= \case +desugarBind :: LPat GhcTc -> LHsExpr GhcTc -> DsM GrdVec +desugarBind p e = dsLExpr e >>= \case Var y | Nothing <- isDataConId_maybe y -- RHS is a variable, so that will allow us to omit the let - -> translateLPat fam_insts y p + -> desugarLPat y p rhs -> do - (x, grds) <- translateLPatV fam_insts p + (x, grds) <- desugarLPatV p pure (PmLet x rhs : grds) --- | Translate a boolean guard +-- | Desugar a boolean guard -- @e ==> let x = e; True <- x@ -translateBoolGuard :: LHsExpr GhcTc -> DsM GrdVec -translateBoolGuard e +desugarBoolGuard :: LHsExpr GhcTc -> DsM GrdVec +desugarBoolGuard e | isJust (isTrueLHsExpr e) = return [] -- The formal thing to do would be to generate (True <- True) -- but it is trivial to solve so instead we give back an empty @@ -803,7 +792,7 @@ for a pattern match appear matter. Consider a situation similar to T5117: f (0:_) = () f (0:[]) = () -The latter clause is clearly redundant. Yet if we translate the second clause as +The latter clause is clearly redundant. Yet if we desugar the second clause as [x:xs' <- xs, [] <- xs', 0 <- x] @@ -815,52 +804,11 @@ translation would have been And we have to take in the guards on list cells into @mkListGrds at . -Note [Countering exponential blowup] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Precise pattern match exhaustiveness checking is necessarily exponential in -the size of some input programs. We implement a counter-measure in the form of -the -fmax-pmcheck-models flag, limiting the number of Deltas we check against -each pattern by a constant. - -How do we do that? Consider - - f True True = () - f True True = () - -And imagine we set our limit to 1 for the sake of the example. The first clause -will be checked against the initial Delta, {}. Doing so will produce an -Uncovered set of size 2, containing the models {x/~True} and {x~True,y/~True}. -Also we find the first clause to cover the model {x~True,y~True}. - -But the Uncovered set we get out of the match is too huge! We somehow have to -ensure not to make things worse as they are already, so we continue checking -with a singleton Uncovered set of the initial Delta {}. Why is this -sound (wrt. notion of the GADTs Meet their Match paper)? Well, it basically -amounts to forgetting that we matched against the first clause. The values -represented by {} are a superset of those represented by its two refinements -{x/~True} and {x~True,y/~True}. - -This forgetfulness becomes very apparent in the example above: By continuing -with {} we don't detect the second clause as redundant, as it again covers the -same non-empty subset of {}. So we don't flag everything as redundant anymore, -but still will never flag something as redundant that isn't. - -For exhaustivity, the converse applies: We will report @f@ as non-exhaustive -and report @f _ _@ as missing, which is a superset of the actual missing -matches. But soundness means we will never fail to report a missing match. - -This mechanism is implemented in 'throttle'. - -Guards are an extreme example in this regard, with #11195 being a particularly -dreadful example: Since their RHS are often pretty much unique, we split on a -variable (the one representing the RHS) that doesn't occur anywhere else in the -program, so we don't actually get useful information out of that split! - -Note [Translate CoPats] +Note [Desugar CoPats] ~~~~~~~~~~~~~~~~~~~~~~~ -The pattern match checker did not know how to handle coerced patterns `CoPat` -efficiently, which gave rise to #11276. The original approach translated -`CoPat`s: +The pattern match checker did not know how to handle coerced patterns +`CoPat` efficiently, which gave rise to #11276. The original approach +desugared `CoPat`s: pat |> co ===> x (pat <- (x |> co)) @@ -875,108 +823,92 @@ a lot of false warnings. But we can check whether the coercion is a hole or if it is just refl, in which case we can drop it. - -%************************************************************************ -%* * - Utilities for Pattern Match Checking -%* * -%************************************************************************ -} --- ---------------------------------------------------------------------------- --- * Basic utilities - -{- -Note [Extensions to GADTs Meet Their Match] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The GADTs Meet Their Match paper presents the formalism that GHC's coverage -checker adheres to. Since the paper's publication, there have been some -additional features added to the coverage checker which are not described in -the paper. This Note serves as a reference for these new features. - -* Value abstractions are severely simplified to the point where they are just - variables. The information about the shape of a variable is encoded in - the oracle state 'Delta' instead. -* Handling of uninhabited fields like `!Void`. - See Note [Strict argument type constraints] in GHC.HsToCore.PmCheck.Oracle. -* Efficient handling of literal splitting, large enumerations and accurate - redundancy warnings for `COMPLETE` groups through the oracle. - -Note [Filtering out non-matching COMPLETE sets] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Currently, conlikes in a COMPLETE set are simply grouped by the -type constructor heading the return type. This is nice and simple, but it does -mean that there are scenarios when a COMPLETE set might be incompatible with -the type of a scrutinee. For instance, consider (from #14135): - - data Foo a = Foo1 a | Foo2 a - - pattern MyFoo2 :: Int -> Foo Int - pattern MyFoo2 i = Foo2 i - - {-# COMPLETE Foo1, MyFoo2 #-} - - f :: Foo a -> a - f (Foo1 x) = x - -`f` has an incomplete pattern-match, so when choosing which constructors to -report as unmatched in a warning, GHC must choose between the original set of -data constructors {Foo1, Foo2} and the COMPLETE set {Foo1, MyFoo2}. But observe -that GHC shouldn't even consider the COMPLETE set as a possibility: the return -type of MyFoo2, Foo Int, does not match the type of the scrutinee, Foo a, since -there's no substitution `s` such that s(Foo Int) = Foo a. - -To ensure that GHC doesn't pick this COMPLETE set, it checks each pattern -synonym constructor's return type matches the type of the scrutinee, and if one -doesn't, then we remove the whole COMPLETE set from consideration. - -One might wonder why GHC only checks /pattern synonym/ constructors, and not -/data/ constructors as well. The reason is because that the type of a -GADT constructor very well may not match the type of a scrutinee, and that's -OK. Consider this example (from #14059): - - data SBool (z :: Bool) where - SFalse :: SBool False - STrue :: SBool True - - pattern STooGoodToBeTrue :: forall (z :: Bool). () - => z ~ True - => SBool z - pattern STooGoodToBeTrue = STrue - {-# COMPLETE SFalse, STooGoodToBeTrue #-} - - wobble :: SBool z -> Bool - wobble STooGoodToBeTrue = True - -In the incomplete pattern match for `wobble`, we /do/ want to warn that SFalse -should be matched against, even though its type, SBool False, does not match -the scrutinee type, SBool z. - -SG: Another angle at this is that the implied constraints when we instantiate -universal type variables in the return type of a GADT will lead to *provided* -thetas, whereas when we instantiate the return type of a pattern synonym that -corresponds to a *required* theta. See Note [Pattern synonym result type] in -PatSyn. Note how isValidCompleteMatches will successfully filter out - - pattern Just42 :: Maybe Int - pattern Just42 = Just 42 - -But fail to filter out the equivalent - - pattern Just'42 :: (a ~ Int) => Maybe a - pattern Just'42 = Just 42 - -Which seems fine as far as tcMatchTy is concerned, but it raises a few eye -brows. --} +-- +-- * Coverage checking guard trees into annotated trees +-- -{- -%************************************************************************ -%* * - Heart of the algorithm: checkGrdTree -%* * -%************************************************************************ --} +-- | Pattern-match coverage check result +data CheckResult a + = CheckResult + { cr_ret :: !a + -- ^ A hole for redundancy info and covered sets. + , cr_uncov :: !Deltas + -- ^ The set of uncovered values falling out at the bottom. + -- (for -Wincomplete-patterns, but also important state for the algorithm) + , cr_approx :: !Precision + -- ^ A flag saying whether we ran into the 'maxPmCheckModels' limit for the + -- purpose of suggesting to crank it up in the warning message. Writer state. + } deriving Functor + +instance Outputable a => Outputable (CheckResult a) where + ppr (CheckResult c unc pc) + = text "CheckResult" <+> ppr_precision pc <+> braces (fsep + [ field "ret" c <> comma + , field "uncov" unc]) + where + ppr_precision Precise = empty + ppr_precision Approximate = text "(Approximate)" + field name value = text name <+> equals <+> ppr value + +-- | Lift 'addPmCts' over 'Deltas'. +addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas +addPmCtsDeltas deltas cts = liftDeltasM (\d -> addPmCts d cts) deltas + +-- | 'addPmCtsDeltas' for a single 'PmCt'. +addPmCtDeltas :: Deltas -> PmCt -> DsM Deltas +addPmCtDeltas deltas ct = addPmCtsDeltas deltas (unitBag ct) + +-- | Test if any of the 'Delta's is inhabited. Currently this is pure, because +-- we preserve the invariant that there are no uninhabited 'Delta's. But that +-- could change in the future, for example by implementing this function in +-- terms of @notNull <$> provideEvidence 1 ds at . +isInhabited :: Deltas -> DsM Bool +isInhabited (MkDeltas ds) = pure (not (null ds)) + +-- | Coverage checking action. Can be composed 'leftToRight' or 'topToBottom'. +newtype CheckAction a = CA { unCA :: Deltas -> DsM (CheckResult a) } + deriving Functor + +-- | Composes 'CheckAction's top-to-bottom: +-- If a value falls through the resulting action, then it must fall through the +-- first action and then through the second action. +-- If a value matches the resulting action, then it either matches the +-- first action or matches the second action. +-- Basically the semantics of the LYG branching construct. +topToBottom :: (top -> bot -> ret) + -> CheckAction top + -> CheckAction bot + -> CheckAction ret +topToBottom f (CA top) (CA bot) = CA $ \inc -> do + t <- top inc + b <- bot (cr_uncov t) + pure CheckResult { cr_ret = f (cr_ret t) (cr_ret b) + , cr_uncov = cr_uncov b + , cr_approx = cr_approx t Semi.<> cr_approx b } + + +-- | Composes 'CheckAction's left-to-right: +-- If a value falls through the resulting action, then it either falls through the +-- first action or through the second action. +-- If a value matches the resulting action, then it must match the first action +-- and then match the second action. +-- Basically the semantics of the LYG guard construct. +leftToRight :: (RedSets -> right -> ret) + -> CheckAction RedSets + -> CheckAction right + -> CheckAction ret +leftToRight f (CA left) (CA right) = CA $ \inc -> do + l <- left inc + r <- right (rs_cov (cr_ret l)) + limit <- maxPmCheckModels <$> getDynFlags + let uncov = cr_uncov l Semi.<> cr_uncov r + -- See Note [Countering exponential blowup] + let (prec', uncov') = throttle limit inc uncov + pure CheckResult { cr_ret = f (cr_ret l) (cr_ret r) + , cr_uncov = uncov' + , cr_approx = prec' Semi.<> cr_approx l Semi.<> cr_approx r } -- | @throttle limit old new@ returns @old@ if the number of 'Delta's in @new@ -- is exceeding the given @limit@ and the @old@ number of 'Delta's. @@ -994,237 +926,241 @@ conMatchForces (PmAltConLike (RealDataCon dc)) | isNewTyCon (dataConTyCon dc) = False conMatchForces _ = True --- | Makes sure that we only wrap a single 'MayDiverge' around an --- 'AnnotatedTree', purely for esthetic reasons. -mayDiverge :: AnnotatedTree -> AnnotatedTree -mayDiverge a@(MayDiverge _) = a -mayDiverge a = MayDiverge a - --- | Computes two things: --- --- * The set of uncovered values not matched by any of the clauses of the --- 'GrdTree'. Note that 'PmCon' guards are the only way in which values --- fall through from one 'Many' branch to the next. --- * An 'AnnotatedTree' that contains divergence and inaccessibility info --- for all clauses. Will be fed to 'extractRedundancyInfo' for --- presenting redundant and proper innaccessible RHSs, as well as dead --- bangs to the user. -checkGrdTree' :: GrdTree -> Deltas -> DsM CheckResult --- RHS: Check that it covers something and wrap Inaccessible if not -checkGrdTree' (Rhs sdoc) deltas = do - is_covered <- isInhabited deltas - let clauses - | is_covered = AccessibleRhs deltas sdoc - | otherwise = InaccessibleRhs sdoc - pure CheckResult - { cr_clauses = clauses - , cr_uncov = MkDeltas emptyBag - , cr_approx = Precise } --- let x = e: Refine with x ~ e -checkGrdTree' (Guard (PmLet x e) tree) deltas = do - deltas' <- addPmCtDeltas deltas (PmCoreCt x e) - checkGrdTree' tree deltas' --- Bang x: Diverge on x ~ ⊥, refine with x /~ ⊥ -checkGrdTree' (Guard (PmBang x src_bang_info) tree) deltas = do - has_diverged <- addPmCtDeltas deltas (PmBotCt x) >>= isInhabited - deltas' <- addPmCtDeltas deltas (PmNotBotCt x) - res <- checkGrdTree' tree deltas' - let clauses - | not has_diverged - , Just info <- src_bang_info - = RedundantSrcBang info (cr_clauses res) - | has_diverged - = mayDiverge (cr_clauses res) - | otherwise -- won't diverge and it wasn't a source bang - = cr_clauses res - - pure res{ cr_clauses = clauses } - --- Con: Diverge on x ~ ⊥, fall through on x /~ K and refine with x ~ K ys --- and type info -checkGrdTree' (Guard (PmCon x con tvs dicts args) tree) deltas = do - has_diverged <- - if conMatchForces con - then addPmCtDeltas deltas (PmBotCt x) >>= isInhabited - else pure False - unc_this <- addPmCtDeltas deltas (PmNotConCt x con) - deltas' <- addPmCtsDeltas deltas $ - listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args - -- tracePm "checkGrdTree:Con" (ppr deltas $$ ppr x $$ ppr con $$ ppr dicts $$ ppr deltas') - CheckResult tree' unc_inner prec <- checkGrdTree' tree deltas' - limit <- maxPmCheckModels <$> getDynFlags - let (prec', unc') = throttle limit deltas (unc_this Semi.<> unc_inner) - pure CheckResult - { cr_clauses = applyWhen has_diverged mayDiverge tree' - , cr_uncov = unc' - , cr_approx = prec Semi.<> prec' } --- Sequence: Thread residual uncovered sets from equation to equation -checkGrdTree' (Sequence ts) init_unc = go [] init_unc Precise ts +-- First the functions that correspond to checking LYG primitives: + +checkSequence :: (grdtree -> CheckAction anntree) -> NonEmpty grdtree -> CheckAction (NonEmpty anntree) +-- The implementation is pretty similar to +-- @traverse1 :: Apply f => (a -> f b) -> NonEmpty a -> f (NonEmpty b)@ +checkSequence act (t:|[]) = (:|[]) <$> act t +checkSequence act (t1:|(t2:ts)) = + topToBottom (NE.<|) (act t1) (checkSequence act (t2:|ts)) + +checkGrd :: PmGrd -> CheckAction RedSets +checkGrd grd = CA $ \inc -> case grd of + -- let x = e: Refine with x ~ e + PmLet x e -> do + matched <- addPmCtDeltas inc (PmCoreCt x e) + pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched } + , cr_uncov = mempty + , cr_approx = Precise } + -- Bang x _: Diverge on x ~ ⊥, refine with x /~ ⊥ + PmBang x mb_info -> do + div <- addPmCtDeltas inc (PmBotCt x) + matched <- addPmCtDeltas inc (PmNotBotCt x) + -- See Note [Dead bang patterns] + -- mb_info = Just info <==> PmBang originates from bang pattern in source + let bangs | Just info <- mb_info = unitOL (div, info) + | otherwise = NilOL + pure CheckResult { cr_ret = RedSets { rs_cov = matched, rs_div = div, rs_bangs = bangs } + , cr_uncov = mempty + , cr_approx = Precise } + -- Con: Diverge on x ~ ⊥, fall through on x /~ K and refine with x ~ K ys + -- and type info + PmCon x con tvs dicts args -> do + div <- if conMatchForces con + then addPmCtDeltas inc (PmBotCt x) + else pure mempty + uncov <- addPmCtDeltas inc (PmNotConCt x con) + matched <- addPmCtsDeltas inc $ + listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args + -- tracePm "checkGrd:Con" (ppr inc $$ ppr x $$ ppr con $$ ppr dicts $$ ppr matched) + pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched, rs_div = div } + , cr_uncov = uncov + , cr_approx = Precise } + +checkGrds :: [PmGrd] -> CheckAction RedSets +checkGrds [] = CA $ \inc -> + pure CheckResult { cr_ret = emptyRedSets { rs_cov = inc } + , cr_uncov = mempty + , cr_approx = Precise } +checkGrds (g:grds) = leftToRight merge (checkGrd g) (checkGrds grds) where - -- | Accumulates a CheckResult. Its type is more like - -- @CheckResult -> [GrdTree] -> CheckResult@, but cr_clauses is a single - -- 'AnnotatedTree', not a list thereof. Hence 3 parameters to thread the - -- fields. - go :: [AnnotatedTree] -> Deltas -> Precision -> [GrdTree] -> DsM CheckResult - -- No cases left: Fall through for all values - go ts' unc prec [] = pure CheckResult - { cr_clauses = SequenceAnn init_unc (reverse ts') - , cr_uncov = unc - , cr_approx = prec } - go ts' unc prec (t:ts) = do - CheckResult t' unc_1 prec_t <- checkGrdTree' t unc - go (t':ts') unc_1 (prec_t Semi.<> prec) ts - --- | Print diagnostic info and actually call 'checkGrdTree''. -checkGrdTree :: GrdTree -> Deltas -> DsM CheckResult -checkGrdTree guards deltas = do - tracePm "checkGrdTree {" $ vcat [ ppr guards - , ppr deltas ] - res <- checkGrdTree' guards deltas - tracePm "checkGrdTree }:" (ppr res) -- braces are easier to match by tooling - return res - --- ---------------------------------------------------------------------------- --- * Propagation of term constraints inwards when checking nested matches - -{- Note [Type and Term Equality Propagation] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -When checking a match it would be great to have all type and term information -available so we can get more precise results. For this reason we have functions -`addDictsDs' and `addTmVarCsDs' in GHC.HsToCore.Monad that store in the -environment type and term constraints (respectively) as we go deeper. - -The type constraints we propagate inwards are collected by `collectEvVarsPats' -in GHC.Hs.Pat. This handles bug #4139 ( see example - https://gitlab.haskell.org/ghc/ghc/snippets/672 ) -where this is needed. - -For term equalities we do less, we just generate equalities for HsCase. For -example we accurately give 2 redundancy warnings for the marked cases: - -f :: [a] -> Bool -f x = case x of - - [] -> case x of -- brings (x ~ []) in scope - [] -> True - (_:_) -> False -- can't happen - - (_:_) -> case x of -- brings (x ~ (_:_)) in scope - (_:_) -> True - [] -> False -- can't happen - -Functions `add*ScrutTmCs' is responsible for generating -these constraints. --} + merge ri_g ri_grds = -- This operation would /not/ form a Semigroup! + RedSets { rs_cov = rs_cov ri_grds + , rs_div = rs_div ri_g Semi.<> rs_div ri_grds + , rs_bangs = rs_bangs ri_g Semi.<> rs_bangs ri_grds } --- | Locally update 'dsl_deltas' with the given action, but defer evaluation --- with 'unsafeInterleaveM' in order not to do unnecessary work. -locallyExtendPmDelta :: (Deltas -> DsM Deltas) -> DsM a -> DsM a -locallyExtendPmDelta ext k = do - deltas <- getPmDeltas - deltas' <- unsafeInterleaveM $ do - deltas' <- ext deltas - inh <- isInhabited deltas' - -- If adding a constraint would lead to a contradiction, don't add it. - -- See @Note [Recovering from unsatisfiable pattern-matching constraints]@ - -- for why this is done. - if inh - then pure deltas' - else pure deltas - updPmDeltas deltas' k +checkMatchGroup :: GrdMatchGroup -> CheckAction AnnMatchGroup +checkMatchGroup (GrdMatchGroup matches) = + AnnMatchGroup <$> checkSequence checkMatch matches --- | Add in-scope type constraints if the coverage checker might run and then --- run the given action. -addTyCsDs :: Origin -> Bag EvVar -> DsM a -> DsM a -addTyCsDs origin ev_vars m = do - dflags <- getDynFlags - applyWhen (needToRunPmCheck dflags origin) - (locallyExtendPmDelta (\deltas -> addPmCtsDeltas deltas (PmTyCt . evVarPred <$> ev_vars))) - m +checkMatch :: GrdMatch -> CheckAction AnnMatch +checkMatch (GrdMatch { gm_pats = grds, gm_grhss = grhss }) = + leftToRight AnnMatch (checkGrds grds) (checkGRHSs grhss) --- | Add equalities for the 'CoreExpr' scrutinee to the local 'DsM' environment --- when checking a case expression: --- case e of x { matches } --- When checking matches we record that (x ~ e) where x is the initial --- uncovered. All matches will have to satisfy this equality. -addCoreScrutTmCs :: Maybe CoreExpr -> [Id] -> DsM a -> DsM a -addCoreScrutTmCs Nothing _ k = k -addCoreScrutTmCs (Just scr) [x] k = - flip locallyExtendPmDelta k $ \deltas -> - addPmCtsDeltas deltas (unitBag (PmCoreCt x scr)) -addCoreScrutTmCs _ _ _ = panic "addCoreScrutTmCs: scrutinee, but more than one match id" +checkGRHSs :: NonEmpty GrdGRHS -> CheckAction (NonEmpty AnnGRHS) +checkGRHSs = checkSequence checkGRHS --- | 'addCoreScrutTmCs', but desugars the 'LHsExpr' first. -addHsScrutTmCs :: Maybe (LHsExpr GhcTc) -> [Id] -> DsM a -> DsM a -addHsScrutTmCs Nothing _ k = k -addHsScrutTmCs (Just scr) vars k = do - scr_e <- dsLExpr scr - addCoreScrutTmCs (Just scr_e) vars k +checkGRHS :: GrdGRHS -> CheckAction AnnGRHS +checkGRHS (GrdGRHS { gg_grds = grds, gg_rhs = rhs_info }) = + flip AnnGRHS rhs_info <$> checkGrds grds -{- -%************************************************************************ -%* * - Pretty printing of exhaustiveness/redundancy check warnings -%* * -%************************************************************************ --} +checkEmptyCase :: GrdEmptyCase -> CheckAction AnnEmptyCase +checkEmptyCase (GrdEmptyCase { ge_var = var }) = CA $ \inc -> do + unc <- addPmCtDeltas inc (PmNotBotCt var) + pure CheckResult { cr_ret = AnnEmptyCase, cr_uncov = unc, cr_approx = mempty } --- | Check whether any part of pattern match checking is enabled for this --- 'HsMatchContext' (does not matter whether it is the redundancy check or the --- exhaustiveness check). -isMatchContextPmChecked :: DynFlags -> Origin -> HsMatchContext id -> Bool -isMatchContextPmChecked dflags origin kind - | isGenerated origin - = False - | otherwise - = overlapping dflags kind || exhaustive dflags kind +checkPatBind :: GrdPatBind -> CheckAction AnnPatBind +checkPatBind = coerce checkGRHS --- | Return True when any of the pattern match warnings ('allPmCheckWarnings') --- are enabled, in which case we need to run the pattern match checker. -needToRunPmCheck :: DynFlags -> Origin -> Bool -needToRunPmCheck dflags origin - | isGenerated origin - = False - | otherwise - = notNull (filter (`wopt` dflags) allPmCheckWarnings) +{- Note [Countering exponential blowup] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Precise pattern match exhaustiveness checking is necessarily exponential in +the size of some input programs. We implement a counter-measure in the form of +the -fmax-pmcheck-models flag, limiting the number of Deltas we check against +each pattern by a constant. + +How do we do that? Consider + + f True True = () + f True True = () + +And imagine we set our limit to 1 for the sake of the example. The first clause +will be checked against the initial Delta, {}. Doing so will produce an +Uncovered set of size 2, containing the models {x/~True} and {x~True,y/~True}. +Also we find the first clause to cover the model {x~True,y~True}. + +But the Uncovered set we get out of the match is too huge! We somehow have to +ensure not to make things worse as they are already, so we continue checking +with a singleton Uncovered set of the initial Delta {}. Why is this +sound (wrt. the notion in GADTs Meet Their Match)? Well, it basically amounts +to forgetting that we matched against the first clause. The values represented +by {} are a superset of those represented by its two refinements {x/~True} and +{x~True,y/~True}. + +This forgetfulness becomes very apparent in the example above: By continuing +with {} we don't detect the second clause as redundant, as it again covers the +same non-empty subset of {}. So we don't flag everything as redundant anymore, +but still will never flag something as redundant that isn't. --- | A type for organising information to be used in warnings. -data RedundancyInfo - = RedundancyInfo - { redundant_rhss :: ![SrcInfo] - , inaccessible_rhss :: ![SrcInfo] - , redundant_bangs :: ![Located SDoc] +For exhaustivity, the converse applies: We will report @f@ as non-exhaustive +and report @f _ _@ as missing, which is a superset of the actual missing +matches. But soundness means we will never fail to report a missing match. + +This mechanism is implemented in 'throttle'. + +Guards are an extreme example in this regard, with #11195 being a particularly +dreadful example: Since their RHS are often pretty much unique, we split on a +variable (the one representing the RHS) that doesn't occur anywhere else in the +program, so we don't actually get useful information out of that split! +-} + +-- +-- * Collecting redundancy information +-- + +-- | The result of redundancy checking: +-- * RHSs classified as /C/overed, /I/naccessible and /R/edundant +-- * And redundant (B)ang patterns. +data CIRB + = CIRB + { cirb_cov :: !(OrdList SrcInfo) + , cirb_inacc :: !(OrdList SrcInfo) + , cirb_red :: !(OrdList SrcInfo) + , cirb_bangs :: !(OrdList SrcInfo) } -extractRedundancyInfo :: AnnotatedTree -> RedundancyInfo -extractRedundancyInfo tree = - RedundancyInfo { redundant_rhss = fromOL ol_red - , inaccessible_rhss = fromOL ol_inacc - , redundant_bangs = fromOL ol_bangs } - where - (_ol_acc, ol_inacc, ol_red, ol_bangs) = go tree - -- | Collects - -- 1. accessible RHSs - -- 2. proper inaccessible RHSs (so we can't delete them) - -- 3. hypothetically redundant RHSs (so not only inaccessible, but we can - -- even safely delete the equation without altering semantics) - -- 4. 'Dead' bangs from the source, collected to be warned about - -- See Note [Determining inaccessible clauses] - -- See Note [Dead bang patterns] - go :: AnnotatedTree -> (OrdList SrcInfo, OrdList SrcInfo, OrdList SrcInfo, OrdList SrcInfo) - go (AccessibleRhs _ info) = (unitOL info, nilOL, nilOL , nilOL) - go (InaccessibleRhs info) = (nilOL, nilOL, unitOL info, nilOL) -- presumably redundant - go (MayDiverge t) = case go t of - -- See Note [Determining inaccessible clauses] - (acc, inacc, red, bs) - | isNilOL acc && isNilOL inacc -> (nilOL, red, nilOL, bs) - res -> res - go (SequenceAnn _ ts) = foldMap go ts - go (RedundantSrcBang l t) = case go t of - -- See Note [Dead bang patterns] - res@(acc, inacc, _, _) - | isNilOL acc, isNilOL inacc -> res - | otherwise -> (nilOL, nilOL, nilOL, unitOL l) Semi.<> res +instance Semigroup CIRB where + CIRB a b c d <> CIRB e f g h = CIRB (a <> e) (b <> f) (c <> g) (d <> h) + where (<>) = (Semi.<>) + +instance Monoid CIRB where + mempty = CIRB mempty mempty mempty mempty + +markAllRedundant :: CIRB -> CIRB +markAllRedundant CIRB { cirb_cov = cov, cirb_inacc = inacc, cirb_red = red } = + mempty { cirb_red = cov Semi.<> inacc Semi.<> red } + +-- See Note [Determining inaccessible clauses] +ensureOneNotRedundant :: CIRB -> CIRB +ensureOneNotRedundant ci = case ci of + CIRB { cirb_cov = NilOL, cirb_inacc = NilOL, cirb_red = ConsOL r rs } + -> ci { cirb_inacc = unitOL r, cirb_red = rs } + _ -> ci + +-- | Only adds the redundant bangs to the @CIRB@ if there is at least one +-- non-redundant 'SrcInfo'. There is no point in remembering a redundant bang +-- if the whole match is redundant! +addRedundantBangs :: OrdList SrcInfo -> CIRB -> CIRB +addRedundantBangs _red_bangs cirb at CIRB { cirb_cov = NilOL, cirb_inacc = NilOL } = + cirb +addRedundantBangs red_bangs cirb = + cirb { cirb_bangs = cirb_bangs cirb Semi.<> red_bangs } + +-- | A function that walks along an annotated tree @ann@ and extracts two kinds +-- of coverage info: +-- +-- 1. A 'CIRB', classifying every encountered RHS in the tree as +-- redundant, inaccessible or covered. +-- 2. A piece of long-distance information @ldi@, consisting of a +-- nesting of 'Deltas' mirroring tree structure. +-- For example, 'collectMatchGroup' operates on a Match Group and thus +-- returns a list of 'Deltas' for the pattern part of each Match, as well as +-- a further nested list of 'Deltas' for each of the GRHS of the Match. +type CIRBCollector ann ldi = ann -> DsM (CIRB, ldi) + +-- | Checks the 'Deltas' in a 'RedSets' for inhabitants and returns +-- 1. Whether the Covered set was inhabited +-- 2. Whether the Diverging set was inhabited +-- 3. The new inhabited Covered set for long-distance information. +-- See Note [Recovering from unsatisfiable pattern-matching constraints]. +-- 4. All source bangs whose 'Deltas' were empty, which means they are +-- redundant. +testRedSets :: Deltas -> RedSets -> DsM (Bool, Bool, Deltas, OrdList SrcInfo) +testRedSets ldi RedSets { rs_cov = cov, rs_div = div, rs_bangs = bangs } = do + is_covered <- isInhabited cov + may_diverge <- isInhabited div + red_bangs <- flip mapMaybeM (fromOL bangs) $ \(deltas, bang) -> do + isInhabited deltas >>= \case + True -> pure Nothing + False -> pure (Just bang) + -- See Note [Recovering from unsatisfiable pattern-matching constraints] + -- Deltas for long-distance info: Use (non-empty!) fallback ldi if Covered + -- set was empty + let ldi' + | is_covered = cov + | otherwise = ldi + pure (is_covered, may_diverge, ldi', toOL red_bangs) + +collectMatchGroup :: Deltas -> CIRBCollector AnnMatchGroup (NonEmpty (Deltas, NonEmpty Deltas)) +collectMatchGroup ldi (AnnMatchGroup matches) = do + (cirbs, ldis) <- NE.unzip <$> traverse (collectMatch ldi) matches + pure (Semi.sconcat cirbs, ldis) + +collectMatch :: Deltas -> CIRBCollector AnnMatch (Deltas, NonEmpty Deltas) +collectMatch ldi AnnMatch { am_red = red, am_grhss = grhss } = do + (is_covered, may_diverge, ldi', red_bangs) <- testRedSets ldi red + (cirb, ldis) <- collectGRHSs ldi' grhss + let cirb' = addRedundantBangs red_bangs + -- See Note [Determining inaccessible clauses] + $ applyWhen may_diverge ensureOneNotRedundant + $ applyWhen (not is_covered) markAllRedundant + $ cirb + pure (cirb', (ldi', ldis)) + +collectGRHSs :: Deltas -> CIRBCollector (NonEmpty AnnGRHS) (NonEmpty Deltas) +collectGRHSs ldi grhss = do + (cirbs, ldis) <- NE.unzip <$> traverse (collectGRHS ldi) grhss + pure (Semi.sconcat cirbs, ldis) + +collectGRHS :: Deltas -> CIRBCollector AnnGRHS Deltas +collectGRHS ldi AnnGRHS { ag_red = red, ag_rhs = info } = do + (is_covered, may_diverge, ldi', red_bangs) <- testRedSets ldi red + let cirb | is_covered = mempty { cirb_cov = unitOL info } + | may_diverge = mempty { cirb_inacc = unitOL info } + | otherwise = mempty { cirb_red = unitOL info } + pure (addRedundantBangs red_bangs cirb, ldi') + +collectEmptyCase :: CIRBCollector AnnEmptyCase () +collectEmptyCase _ = pure (mempty, ()) + +collectPatBind :: CIRBCollector AnnPatBind () +-- We don't make use of long-distance information in pattern bindings, hence +-- @()@ instead of some 'Deltas'. +collectPatBind (AnnPatBind grhs) = do + -- use 'mempty' as fallback 'Deltas' because we discard it anyway + (cirb, _) <- collectGRHS mempty grhs + pure (cirb, ()) {- Note [Determining inaccessible clauses] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1239,26 +1175,30 @@ arguments we can ever reach clause 2's RHS, so we say it has inaccessible RHS (as opposed to being completely redundant). We detect an inaccessible RHS simply by pretending it's redundant, until we see -that it's part of a sub-tree in the pattern match that forces some argument -(which corresponds to wrapping the 'AnnotatedTree' in 'MayDiverge'). Then we -turn all supposedly redundant RHSs into inaccessible ones. - -But as it turns out (@g@ from #17465) this is too conservative: - g () | False = () - | otherwise = () -g's first clause has an inaccessible RHS, but it's also safe to delete. So it's -redundant, really! But by just turning all redundant child clauses into -inaccessible ones, we report the first clause as inaccessible. - -Clearly, it is enough if we say that we only degrade if *not all* of the child -clauses are redundant. As long as there is at least one clause which we announce -not to be redundant, the guard prefix responsible for the 'MayDiverge' will -survive. Hence we check for that in 'extractRedundancyInfo'. -} --- | Issue all the warnings (coverage, exhaustiveness, inaccessibility) -dsPmWarn :: DynFlags -> DsMatchContext -> [Id] -> CheckResult -> DsM () -dsPmWarn dflags ctx@(DsMatchContext kind loc) vars result +-- +-- * Formatting and reporting warnings +-- + +-- | Given a 'CIRBCollector', this function will emit warnings for a +-- 'CheckResult' and return the collected long-distance information. +formatReportWarnings :: CIRBCollector ann ldi -> DsMatchContext -> [Id] -> CheckResult ann -> DsM ldi +formatReportWarnings collect ctx vars cr at CheckResult { cr_ret = ann } = do + (cov_info, ldi) <- collect ann + dflags <- getDynFlags + reportWarnings dflags ctx vars cr{cr_ret=cov_info} + pure ldi + +-- | Issue all the warnings +-- (redundancy, inaccessibility, exhaustiveness, redundant bangs). +reportWarnings :: DynFlags -> DsMatchContext -> [Id] -> CheckResult CIRB -> DsM () +reportWarnings dflags ctx@(DsMatchContext kind loc) vars + CheckResult { cr_ret = CIRB { cirb_inacc = inaccessible_rhss + , cirb_red = redundant_rhss + , cirb_bangs = redundant_bangs } + , cr_uncov = uncovered + , cr_approx = precision } = when (flag_i || flag_u || flag_b) $ do unc_examples <- getNFirstUncovered vars (maxPatterns + 1) uncovered let exists_r = flag_i && notNull redundant_rhss @@ -1284,13 +1224,6 @@ dsPmWarn dflags ctx@(DsMatchContext kind loc) vars result when exists_u $ putSrcSpanDs loc $ warnDs flag_u_reason $ pprEqns vars unc_examples where - CheckResult - { cr_clauses = clauses - , cr_uncov = uncovered - , cr_approx = precision } = result - RedundancyInfo{redundant_rhss, inaccessible_rhss, redundant_bangs} - = extractRedundancyInfo clauses - flag_i = overlapping dflags kind flag_u = exhaustive dflags kind flag_b = redundant_bang dflags @@ -1331,44 +1264,30 @@ getNFirstUncovered vars n (MkDeltas deltas) = go n (bagToList deltas) back <- go (n - length front) deltas pure (front ++ back) -{- Note [Inaccessible warnings for record updates] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider (#12957) - data T a where - T1 :: { x :: Int } -> T Bool - T2 :: { x :: Int } -> T a - T3 :: T a - - f :: T Char -> T a - f r = r { x = 3 } - -The desugarer will (conservatively generate a case for T1 even though -it's impossible: - f r = case r of - T1 x -> T1 3 -- Inaccessible branch - T2 x -> T2 3 - _ -> error "Missing" - -We don't want to warn about the inaccessible branch because the programmer -didn't put it there! So we filter out the warning here. - -The same can happen for long distance term constraints instead of type -constraints (#17783): - - data T = A { x :: Int } | B { x :: Int } - f r at A{} = r { x = 3 } - f _ = B 0 - -Here, the long distance info from the FunRhs match (@r ~ A x@) will make the -clause matching on @B@ of the desugaring to @case@ redundant. It's generated -code that we don't want to warn about. --} - dots :: Int -> [a] -> SDoc dots maxPatterns qs | qs `lengthExceeds` maxPatterns = text "..." | otherwise = empty +pprContext :: Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc +pprContext singular (DsMatchContext kind _loc) msg rest_of_msg_fun + = vcat [text txt <+> msg, + sep [ text "In" <+> ppr_match <> char ':' + , nest 4 (rest_of_msg_fun pref)]] + where + txt | singular = "Pattern match" + | otherwise = "Pattern match(es)" + + (ppr_match, pref) + = case kind of + FunRhs { mc_fun = L _ fun } + -> (pprMatchContext kind, \ pp -> ppr fun <+> pp) + _ -> (pprMatchContext kind, \ pp -> pp) + +-- +-- * Utilities +-- + -- | All warning flags that need to run the pattern match checker. allPmCheckWarnings :: [WarningFlag] allPmCheckWarnings = @@ -1411,18 +1330,151 @@ exhaustiveWarningFlag ThPatQuote = Nothing -- etc. They are often *supposed* to be incomplete exhaustiveWarningFlag (StmtCtxt {}) = Nothing --- True <==> singular -pprContext :: Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc -pprContext singular (DsMatchContext kind _loc) msg rest_of_msg_fun - = vcat [text txt <+> msg, - sep [ text "In" <+> ppr_match <> char ':' - , nest 4 (rest_of_msg_fun pref)]] - where - txt | singular = "Pattern match" - | otherwise = "Pattern match(es)" +-- | Check whether any part of pattern match checking is enabled for this +-- 'HsMatchContext' (does not matter whether it is the redundancy check or the +-- exhaustiveness check). +isMatchContextPmChecked :: DynFlags -> Origin -> HsMatchContext id -> Bool +isMatchContextPmChecked dflags origin kind + | isGenerated origin + = False + | otherwise + = overlapping dflags kind || exhaustive dflags kind - (ppr_match, pref) - = case kind of - FunRhs { mc_fun = L _ fun } - -> (pprMatchContext kind, \ pp -> ppr fun <+> pp) - _ -> (pprMatchContext kind, \ pp -> pp) +-- | Return True when any of the pattern match warnings ('allPmCheckWarnings') +-- are enabled, in which case we need to run the pattern match checker. +needToRunPmCheck :: DynFlags -> Origin -> Bool +needToRunPmCheck dflags origin + | isGenerated origin + = False + | otherwise + = notNull (filter (`wopt` dflags) allPmCheckWarnings) + +{- Note [Inaccessible warnings for record updates] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider (#12957) + data T a where + T1 :: { x :: Int } -> T Bool + T2 :: { x :: Int } -> T a + T3 :: T a + + f :: T Char -> T a + f r = r { x = 3 } + +The desugarer will conservatively generate a case for T1 even though +it's impossible: + f r = case r of + T1 x -> T1 3 -- Inaccessible branch + T2 x -> T2 3 + _ -> error "Missing" + +We don't want to warn about the inaccessible branch because the programmer +didn't put it there! So we filter out the warning here. + +The same can happen for long distance term constraints instead of type +constraints (#17783): + + data T = A { x :: Int } | B { x :: Int } + f r at A{} = r { x = 3 } + f _ = B 0 + +Here, the long distance info from the FunRhs match (@r ~ A x@) will make the +clause matching on @B@ of the desugaring to @case@ redundant. It's generated +code that we don't want to warn about. +-} + +-- +-- * Long-distance information +-- + +-- | Locally update 'dsl_deltas' with the given action, but defer evaluation +-- with 'unsafeInterleaveM' in order not to do unnecessary work. +locallyExtendPmDeltas :: (Deltas -> DsM Deltas) -> DsM a -> DsM a +locallyExtendPmDeltas ext k = do + deltas <- getPmDeltas + deltas' <- unsafeInterleaveM $ do + deltas' <- ext deltas + inh <- isInhabited deltas' + -- If adding a constraint would lead to a contradiction, don't add it. + -- See Note [Recovering from unsatisfiable pattern-matching constraints] + -- for why this is done. + if inh + then pure deltas' + else pure deltas + updPmDeltas deltas' k + +-- | Add in-scope type constraints if the coverage checker might run and then +-- run the given action. +addTyCs :: Origin -> Bag EvVar -> DsM a -> DsM a +addTyCs origin ev_vars m = do + dflags <- getDynFlags + applyWhen (needToRunPmCheck dflags origin) + (locallyExtendPmDeltas (\deltas -> addPmCtsDeltas deltas (PmTyCt . evVarPred <$> ev_vars))) + m + +-- | Add equalities for the 'CoreExpr' scrutinee to the local 'DsM' environment +-- when checking a case expression: +-- case e of x { matches } +-- When checking matches we record that (x ~ e) where x is the initial +-- uncovered. All matches will have to satisfy this equality. +addCoreScrutTmCs :: Maybe CoreExpr -> [Id] -> DsM a -> DsM a +addCoreScrutTmCs Nothing _ k = k +addCoreScrutTmCs (Just scr) [x] k = + flip locallyExtendPmDeltas k $ \deltas -> + addPmCtsDeltas deltas (unitBag (PmCoreCt x scr)) +addCoreScrutTmCs _ _ _ = panic "addCoreScrutTmCs: scrutinee, but more than one match id" + +-- | 'addCoreScrutTmCs', but desugars the 'LHsExpr' first. +addHsScrutTmCs :: Maybe (LHsExpr GhcTc) -> [Id] -> DsM a -> DsM a +addHsScrutTmCs Nothing _ k = k +addHsScrutTmCs (Just scr) vars k = do + scr_e <- dsLExpr scr + addCoreScrutTmCs (Just scr_e) vars k + +{- Note [Long-distance information] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider + + data Color = R | G | B + f :: Color -> Int + f R = … + f c = … (case c of + G -> True + B -> False) … + +Humans can make the "long-distance connection" between the outer pattern match +and the nested case pattern match to see that the inner pattern match is +exhaustive: @c@ can't be @R@ anymore because it was matched in the first clause +of @f at . + +To achieve similar reasoning in the coverage checker, we keep track of the set +of values that can reach a particular program point (often loosely referred to +as "Covered set") in 'GHC.HsToCore.Monad.dsl_deltas'. +We fill that set with Covered Deltas returned by the exported checking +functions, which the call sites put into place with +'GHC.HsToCore.Monad.updPmDeltas'. +Call sites also extend this set with facts from type-constraint dictionaries, +case scrutinees, etc. with the exported functions 'addTyCs', 'addCoreScrutTmCs' +and 'addHsScrutTmCs'. + +Note [Recovering from unsatisfiable pattern-matching constraints] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider the following code (see #12957 and #15450): + + f :: Int ~ Bool => () + f = case True of { False -> () } + +We want to warn that the pattern-matching in `f` is non-exhaustive. But GHC +used not to do this; in fact, it would warn that the match was /redundant/! +This is because the constraint (Int ~ Bool) in `f` is unsatisfiable, and the +coverage checker deems any matches with unsatisfiable constraint sets to be +unreachable. + +We can do better than this, by making sure that the Covered set used for +Note [Long-distance information] is always inhabited. +For Covered sets returned by the exported checking functions, that is ensured +in 'testRedSets', which takes and returns a non-empty fallback 'Deltas' in case +the refined Covered set became uninhabited. +Also, whenever "external" knowledge from a type constraint or case scrutinee is +integrated, we only commit that knowledge to 'GHC.HsToCore.Monad.dsl_deltas' if +the set remains inhabited. That check happens in 'locallyExtendPmDeltas'. +-} ===================================== compiler/GHC/HsToCore/PmCheck/Oracle.hs ===================================== @@ -166,25 +166,6 @@ mkOneConFull arg_tys con = do -- * Pattern match oracle -{- Note [Recovering from unsatisfiable pattern-matching constraints] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider the following code (see #12957 and #15450): - - f :: Int ~ Bool => () - f = case True of { False -> () } - -We want to warn that the pattern-matching in `f` is non-exhaustive. But GHC -used not to do this; in fact, it would warn that the match was /redundant/! -This is because the constraint (Int ~ Bool) in `f` is unsatisfiable, and the -coverage checker deems any matches with unsatisfiable constraint sets to be -unreachable. - -We decide to better than this. When beginning coverage checking, we first -check if the constraints in scope are unsatisfiable, and if so, we start -afresh with an empty set of constraints. This way, we'll get the warnings -that we expect. --} - ------------------------------------- -- * Composable satisfiability checks @@ -1265,7 +1246,7 @@ isTyConTriviallyInhabited tc = elementOfUniqSet tc triviallyInhabitedTyCons {- Note [Checking EmptyCase Expressions] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Empty case expressions are strict on the scrutinee. That is, `case x of {}` -will force argument `x`. Hence, `covCheckMatchGroup` is not sufficient for checking +will force argument `x`. Hence, `covCheckMatches` is not sufficient for checking empty cases, because it assumes that the match is not strict (which is true for all other cases, apart from EmptyCase). This gave rise to #10746. Instead, we do the following: ===================================== compiler/GHC/HsToCore/PmCheck/Types.hs ===================================== @@ -592,5 +592,8 @@ instance Outputable Deltas where instance Semigroup Deltas where MkDeltas l <> MkDeltas r = MkDeltas (l `unionBags` r) +instance Monoid Deltas where + mempty = MkDeltas emptyBag + liftDeltasM :: Monad m => (Delta -> m (Maybe Delta)) -> Deltas -> m Deltas liftDeltasM f (MkDeltas ds) = MkDeltas . catBagMaybes <$> (traverse f ds) ===================================== compiler/GHC/Tc/Types.hs ===================================== @@ -323,7 +323,7 @@ data DsLclEnv = DsLclEnv { dsl_meta :: DsMetaEnv, -- Template Haskell bindings dsl_loc :: RealSrcSpan, -- To put in pattern-matching error msgs - -- See Note [Note [Type and Term Equality Propagation] in "GHC.HsToCore.PmCheck" + -- See Note [Note [Long-distance information] in "GHC.HsToCore.PmCheck" -- The set of reaching values Deltas is augmented as we walk inwards, -- refined through each pattern match in turn dsl_deltas :: Deltas ===================================== compiler/GHC/Utils/Misc.hs ===================================== @@ -556,9 +556,8 @@ isSingleton :: [a] -> Bool isSingleton [_] = True isSingleton _ = False -notNull :: [a] -> Bool -notNull [] = False -notNull _ = True +notNull :: Foldable f => f a -> Bool +notNull = not . null only :: [a] -> a #if defined(DEBUG) ===================================== testsuite/tests/deSugar/should_compile/ds020.stderr ===================================== @@ -18,3 +18,11 @@ ds020.hs:20:1: warning: [-Woverlapping-patterns (in -Wdefault)] ds020.hs:23:1: warning: [-Woverlapping-patterns (in -Wdefault)] Pattern match is redundant In an equation for ‘f’: f x@(~[]) = ... + +ds020.hs:32:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: (x1 : xs1 : ys1) = ... + +ds020.hs:33:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: (~x : ~xs : ~ys) = ... ===================================== testsuite/tests/module/all.T ===================================== @@ -83,7 +83,7 @@ test('mod61', normal, compile_fail, ['']) test('mod62', normal, compile_fail, ['']) test('mod63', normal, compile_fail, ['']) test('mod64', normal, compile, ['']) -test('mod65', normal, compile, ['']) +test('mod65', normal, compile, ['-Wno-overlapping-patterns']) test('mod66', normal, compile_fail, ['']) test('mod67', normal, compile_fail, ['']) test('mod68', normal, compile_fail, ['']) ===================================== testsuite/tests/pmcheck/should_compile/T18572.hs ===================================== @@ -3,10 +3,10 @@ module T18572 where -True = True +True = True -- no warning data SBool (b :: Bool) where STrue :: SBool True SFalse :: SBool False -STrue = SFalse +STrue = SFalse -- "redundant", not "inaccessible" ===================================== testsuite/tests/rename/should_compile/T7085.stderr ===================================== @@ -1,3 +1,7 @@ T7085.hs:8:6: warning: [-Wunused-pattern-binds (in -Wextra, -Wunused-binds)] This pattern-binding binds no variables: Nothing = Just n + +T7085.hs:8:6: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In a pattern binding: Nothing = ... ===================================== testsuite/tests/unboxedsums/all.T ===================================== @@ -30,5 +30,5 @@ test('T12711', only_ways(['ghci']), ghci_script, ['T12711.script']) # extra_files([ "unboxedsums" + str(i) + ".hs" for i in range(1, 12) ])], # makefile_test, []) -test('UbxSumLevPoly', normal, compile, ['']) +test('UbxSumLevPoly', normal, compile, ['-Wno-overlapping-patterns']) test('T14051', normal, multi_compile, ['T14051.hs', [('T14051a.hs', '')], '-O2 -v0']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fc8ab7c96439da7fb595239a83793c80346967e8 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fc8ab7c96439da7fb595239a83793c80346967e8 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 16:21:34 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Mon, 31 Aug 2020 12:21:34 -0400 Subject: [Git][ghc/ghc][wip/T18341] Fix the regression in T12227 Message-ID: <5f4d238e519d0_80b3f84940c26d499062bf@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18341 at Glasgow Haskell Compiler / GHC Commits: d399d072 by Sebastian Graf at 2020-08-31T18:20:16+02:00 Fix the regression in T12227 By * Making constructor constraints `x <- K y` strict in `x` again * Bringing back `initPossibleMatches` in `addNotConCt` - - - - - 2 changed files: - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs Changes: ===================================== compiler/GHC/HsToCore/PmCheck.hs ===================================== @@ -152,10 +152,14 @@ covCheckMatches -> DsM [(Nablas, NonEmpty Nablas)] -- ^ One covered 'Nablas' per Match and -- GRHS, for long distance info. covCheckMatches ctxt vars matches = do - missing <- getPmNablas - tracePm "covCheckMatches {" (hang (vcat [ppr ctxt, ppr vars, text "Matches:"]) - 2 - (vcat (map ppr matches) $$ ppr missing)) + -- We have to force @missing@ before printing out the trace message, + -- otherwise we get interleaved output from the solver. This function + -- should be strict in @missing@ anyway! + !missing <- getPmNablas + tracePm "covCheckMatches {" $ + hang (vcat [ppr ctxt, ppr vars, text "Matches:"]) + 2 + (vcat (map ppr matches) $$ ppr missing) case NE.nonEmpty matches of Nothing -> do -- This must be an -XEmptyCase. See Note [Checking EmptyCase] @@ -419,29 +423,27 @@ mkPmLetVar x y | x == y = [] mkPmLetVar x y = [PmLet x (Var y)] -- | ADT constructor pattern => no existentials, no local constraints -vanillaConGrds :: Id -> DataCon -> [Id] -> GrdVec -vanillaConGrds scrut con arg_ids = - [ PmBang scrut Nothing - , PmCon { pm_id = scrut, pm_con_con = PmAltConLike (RealDataCon con) - , pm_con_tvs = [], pm_con_dicts = [], pm_con_args = arg_ids } - ] +vanillaConGrd :: Id -> DataCon -> [Id] -> PmGrd +vanillaConGrd scrut con arg_ids = + PmCon { pm_id = scrut, pm_con_con = PmAltConLike (RealDataCon con) + , pm_con_tvs = [], pm_con_dicts = [], pm_con_args = arg_ids } -- | Creates a 'GrdVec' refining a match var of list type to a list, -- where list fields are matched against the incoming tagged 'GrdVec's. -- For example: -- @mkListGrds "a" "[(x, True <- x),(y, !y)]"@ -- to --- @"[!a, (x:b) <- a, !x, True <- x, !b, (y:c) <- b, !y, !c, [] <- c]"@ +-- @"[(x:b) <- a, True <- x, (y:c) <- b, !y, [] <- c]"@ -- where @b@ and @c@ are freshly allocated in @mkListGrds@ and @a@ is the match -- variable. mkListGrds :: Id -> [(Id, GrdVec)] -> DsM GrdVec -- See Note [Order of guards matter] for why we need to intertwine guards -- on list elements. -mkListGrds a [] = pure (vanillaConGrds a nilDataCon []) +mkListGrds a [] = pure [vanillaConGrd a nilDataCon []] mkListGrds a ((x, head_grds):xs) = do b <- mkPmId (idType a) tail_grds <- mkListGrds b xs - pure $ vanillaConGrds a consDataCon [x, b] ++ head_grds ++ tail_grds + pure $ vanillaConGrd a consDataCon [x, b] : head_grds ++ tail_grds -- | Create a 'GrdVec' refining a match variable to a 'PmLit'. mkPmLitGrds :: Id -> PmLit -> DsM GrdVec @@ -457,13 +459,12 @@ mkPmLitGrds x (PmLit _ (PmLitString s)) = do char_grdss <- zipWithM mk_char_lit vars (unpackFS s) mkListGrds x (zip vars char_grdss) mkPmLitGrds x lit = do - let con = PmAltLit lit - grd = PmCon { pm_id = x + let grd = PmCon { pm_id = x , pm_con_con = PmAltLit lit , pm_con_tvs = [] , pm_con_dicts = [] , pm_con_args = [] } - pure (conMatchStrictGrds con x ++ [grd]) + pure [grd] -- | @desugarPat _ x pat@ transforms @pat@ into a 'GrdVec', where -- the variable representing the match is @x at . @@ -499,11 +500,11 @@ desugarPat x pat = case pat of -- (n + k) ===> let b = x >= k, True <- b, let n = x-k NPlusKPat _pat_ty (L _ n) k1 k2 ge minus -> do b <- mkPmId boolTy - let grd_b = vanillaConGrds b trueDataCon [] + let grd_b = vanillaConGrd b trueDataCon [] [ke1, ke2] <- traverse dsOverLit [unLoc k1, k2] rhs_b <- dsSyntaxExpr ge [Var x, ke1] rhs_n <- dsSyntaxExpr minus [Var x, ke2] - pure $ PmLet b rhs_b : grd_b ++ [PmLet n rhs_n] + pure [PmLet b rhs_b, grd_b, PmLet n rhs_n] -- (fun -> pat) ===> let y = fun x, pat <- y where y is a match var of pat ViewPat _arg_ty lexpr pat -> do @@ -582,13 +583,13 @@ desugarPat x pat = case pat of TuplePat _tys pats boxity -> do (vars, grdss) <- mapAndUnzipM desugarLPatV pats let tuple_con = tupleDataCon boxity (length vars) - pure $ vanillaConGrds x tuple_con vars ++ concat grdss + pure $ vanillaConGrd x tuple_con vars : concat grdss SumPat _ty p alt arity -> do (y, grds) <- desugarLPatV p let sum_con = sumDataCon alt arity -- See Note [Unboxed tuple RuntimeRep vars] in GHC.Core.TyCon - pure $ vanillaConGrds x sum_con [y] ++ grds + pure $ vanillaConGrd x sum_con [y] : grds SplicePat {} -> panic "Check.desugarPat: SplicePat" @@ -614,11 +615,6 @@ desugarListPat x pats = do vars_and_grdss <- traverse desugarLPatV pats mkListGrds x vars_and_grdss -conMatchStrictGrds :: PmAltCon -> Id -> GrdVec -conMatchStrictGrds con x - | isPmAltConMatchStrict con = [PmBang x Nothing] - | otherwise = [] - -- | Desugar a constructor pattern desugarConPatOut :: Id -> ConLike -> [Type] -> [TyVar] -> [EvVar] -> HsConPatDetails GhcTc -> DsM GrdVec @@ -642,33 +638,31 @@ desugarConPatOut x con univ_tys ex_tvs dicts = \case go_field_pats tagged_pats = do -- The fields that appear might not be in the correct order. So - -- 1. Add a bang that forces the match var if 'isPmAltConMatchStrict'. - -- 2. Do the PmCon match - -- 3. Then pattern match on the fields in the order given by the first + -- 1. Do the PmCon match + -- 2. Then pattern match on the fields in the order given by the first -- field of @tagged_pats at . -- See Note [Field match order for RecCon] -- Desugar the mentioned field patterns. We're doing this first to get - -- the Ids for pm_con_args. + -- the Ids for pm_con_args and bring them in order afterwards. let trans_pat (n, pat) = do (var, pvec) <- desugarLPatV pat pure ((n, var), pvec) (tagged_vars, arg_grdss) <- mapAndUnzipM trans_pat tagged_pats - let alt_con = PmAltConLike con - get_pat_id n ty = case lookup n tagged_vars of + let get_pat_id n ty = case lookup n tagged_vars of Just var -> pure var Nothing -> mkPmId ty - -- the constructor pattern match itself + -- 1. the constructor pattern match itself arg_ids <- zipWithM get_pat_id [0..] arg_tys - let con_grd = PmCon x alt_con ex_tvs dicts arg_ids + let con_grd = PmCon x (PmAltConLike con) ex_tvs dicts arg_ids - -- guards from field selector patterns + -- 2. guards from field selector patterns let arg_grds = concat arg_grdss -- tracePm "ConPatOut" (ppr x $$ ppr con $$ ppr arg_ids) - pure (conMatchStrictGrds alt_con x ++ con_grd : arg_grds) + pure (con_grd : arg_grds) desugarPatBind :: SrcSpan -> Id -> Pat GhcTc -> DsM GrdPatBind -- See 'GrdPatBind' for how this simply repurposes GrdGRHS. @@ -753,10 +747,10 @@ desugarBoolGuard e Var y | Nothing <- isDataConId_maybe y -- Omit the let by matching on y - -> pure (vanillaConGrds y trueDataCon []) + -> pure [vanillaConGrd y trueDataCon []] rhs -> do x <- mkPmId boolTy - pure $ PmLet x rhs : vanillaConGrds x trueDataCon [] + pure [PmLet x rhs, vanillaConGrd x trueDataCon []] {- Note [Field match order for RecCon] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -768,13 +762,11 @@ the pattern match. For example: f T{ b = 42, a = 'a' } = () Then @f (T (error "a") (error "b"))@ errors out with "b" because it is mentioned -frist in the pattern match. +first in the pattern match. This means we can't just desugar the pattern match to -@[!x, T a b <- x, 'a' <- a, 42 <- b]@. Instead we have to force them in the -right order: @[!x, T a b <- x, 42 <- b, 'a' <- a]@. -Note the preceding bang guards on the match var: They are necessary for DataCons -as PmCon guards match lazily. +@[T a b <- x, 'a' <- a, 42 <- b]@. Instead we have to force them in the +right order: @[T a b <- x, 42 <- b, 'a' <- a]@. Note [Strict fields and fields of unlifted type] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -983,11 +975,14 @@ checkGrd grd = CA $ \inc -> case grd of , cr_approx = Precise } -- Con: Fall through on x /~ K and refine with x ~ K ys and type info PmCon x con tvs dicts args -> do + !div <- if isPmAltConMatchStrict con + then addPmCtNablas inc (PmBotCt x) + else pure mempty let con_cts = pmConCts x con tvs dicts args - matched <- addPmCtsNablas inc con_cts - uncov <- addPmCtNablas inc (PmNotConCt x con) + !matched <- addPmCtsNablas inc con_cts + !uncov <- addPmCtNablas inc (PmNotConCt x con) -- tracePm "checkGrd:Con" (ppr inc $$ ppr grd $$ ppr con_cts $$ ppr matched) - pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched } + pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched, rs_div = div } , cr_uncov = uncov , cr_approx = Precise } ===================================== compiler/GHC/HsToCore/PmCheck/Oracle.hs ===================================== @@ -903,7 +903,11 @@ addNotConCt :: Nabla -> Id -> PmAltCon -> MaybeT DsM Nabla addNotConCt _ _ (PmAltConLike (RealDataCon dc)) | isNewDataCon dc = mzero -- (4) in Note [Coverage checking Newtype matches] addNotConCt nabla at MkNabla{ nabla_tm_st = ts@(TmSt env reps) } x nalt = do - let vi@(VI _ pos neg _ pm) = lookupVarInfo ts x + -- For good performance, it's important to initPossibleMatches here. + -- Otherwise we can't mark nalt as matched later on, incurring unnecessary + -- inhabitation tests for nalt. + vi@(VI _ pos neg _ pm) <- lift $ initPossibleMatches (nabla_ty_st nabla) + (lookupVarInfo ts x) -- 1. Bail out quickly when nalt contradicts a solution let contradicts nalt (cl, _tvs, _args) = eqPmAltCon cl nalt == Equal guard (not (any (contradicts nalt) pos)) @@ -915,11 +919,12 @@ addNotConCt nabla at MkNabla{ nabla_tm_st = ts@(TmSt env reps) } x nalt = do -- See Note [Completeness checking with required Thetas] | hasRequiredTheta nalt = neg | otherwise = extendPmAltConSet neg nalt - let vi1 = vi{ vi_neg = neg' } + MASSERT( isPmAltConMatchStrict nalt ) + let vi1 = vi{ vi_neg = neg', vi_bot = IsNotBot } -- 3. Make sure there's at least one other possible constructor vi2 <- case nalt of PmAltConLike cl - -> MaybeT (ensureInhabited nabla vi1{ vi_cache = markMatched cl pm }) + -> ensureInhabited nabla vi1{ vi_cache = markMatched cl pm } _ -> pure vi1 pure nabla{ nabla_tm_st = TmSt (setEntrySDIE env x vi2) reps } @@ -993,30 +998,30 @@ addNotBotCt nabla at MkNabla{ nabla_tm_st = TmSt env reps } x = do IsBot -> mzero -- There was x ~ ⊥. Contradiction! IsNotBot -> pure nabla -- There already is x /~ ⊥. Nothing left to do MaybeBot -> do -- We add x /~ ⊥ and test if x is still inhabited - vi <- MaybeT $ ensureInhabited nabla vi{ vi_bot = IsNotBot } + vi <- ensureInhabited nabla vi{ vi_bot = IsNotBot } pure nabla{ nabla_tm_st = TmSt (setEntrySDIE env y vi) reps} -ensureInhabited :: Nabla -> VarInfo -> DsM (Maybe VarInfo) - -- Returns (Just vi) if at least one member of each ConLike in the COMPLETE - -- set satisfies the oracle - -- - -- Internally uses and updates the ConLikeSets in vi_cache. - -- - -- NB: Does /not/ filter each ConLikeSet with the oracle; members may - -- remain that do not statisfy it. This lazy approach just - -- avoids doing unnecessary work. +-- | Returns (Just vi) if at least one member of each ConLike in the COMPLETE +-- set satisfies the oracle +-- +-- Internally uses and updates the ConLikeSets in vi_cache. +-- +-- NB: Does /not/ filter each ConLikeSet with the oracle; members may +-- remain that do not statisfy it. This lazy approach just +-- avoids doing unnecessary work. +ensureInhabited :: Nabla -> VarInfo -> MaybeT DsM VarInfo ensureInhabited nabla vi = case vi_bot vi of - MaybeBot -> pure (Just vi) -- The |-Bot rule from the paper - IsBot -> pure (Just vi) - IsNotBot -> initPossibleMatches (nabla_ty_st nabla) vi >>= inst_complete_sets + MaybeBot -> pure vi -- The |-Bot rule from the paper + IsBot -> pure vi + IsNotBot -> lift (initPossibleMatches (nabla_ty_st nabla) vi) >>= inst_complete_sets where -- | This is the |-Inst rule from the paper (section 4.5). Tries to -- find an inhabitant in every complete set by instantiating with one their -- constructors. If there is any complete set where we can't find an -- inhabitant, the whole thing is uninhabited. - inst_complete_sets :: VarInfo -> DsM (Maybe VarInfo) - inst_complete_sets vi at VI{ vi_cache = NoPM } = pure (Just vi) - inst_complete_sets vi at VI{ vi_cache = PM ms } = runMaybeT $ do + inst_complete_sets :: VarInfo -> MaybeT DsM VarInfo + inst_complete_sets vi at VI{ vi_cache = NoPM } = pure vi + inst_complete_sets vi at VI{ vi_cache = PM ms } = do ms <- traverse (\cs -> inst_complete_set vi cs (uniqDSetToList cs)) ms pure vi{ vi_cache = PM ms } @@ -1061,8 +1066,7 @@ ensureAllInhabited nabla at MkNabla{ nabla_tm_st = TmSt env reps } = runMaybeT (set_tm_cs_env nabla <$> traverseSDIE go env) where set_tm_cs_env nabla env = nabla{ nabla_tm_st = TmSt env reps } - go vi = MaybeT $ - initPossibleMatches (nabla_ty_st nabla) vi >>= ensureInhabited nabla + go vi = ensureInhabited nabla vi -------------------------------------- -- * Term oracle unification procedure @@ -1144,17 +1148,18 @@ addConCt nabla at MkNabla{ nabla_tm_st = ts@(TmSt env reps) } x alt tvs args = do MaybeT $ addPmCts nabla (listToBag ty_cts `unionBags` listToBag tm_cts) Nothing -> do let pos' = (alt, tvs, args):pos - let nabla' = nabla{ nabla_tm_st = TmSt (setEntrySDIE env x (VI ty pos' neg bot cache)) reps} + let nabla_with bot = nabla{ nabla_tm_st = TmSt (setEntrySDIE env x (VI ty pos' neg bot cache)) reps} -- In case of a newtype constructor, we have to make sure that x ~ ⊥ and -- x /~ ⊥ constraints now apply to the wrapped thing, as 'lookupVarInfoNT' -- looks through newtype constructors. case (alt, args) of (PmAltConLike (RealDataCon dc), [y]) | isNewDataCon dc -> case bot of - MaybeBot -> pure nabla' - IsBot -> addBotCt nabla' y - IsNotBot -> addNotBotCt nabla' y - _ -> pure nabla' + MaybeBot -> pure (nabla_with MaybeBot) + IsBot -> addBotCt (nabla_with MaybeBot) y + IsNotBot -> addNotBotCt (nabla_with MaybeBot) y + _ -> ASSERT( isPmAltConMatchStrict alt ) + pure (nabla_with IsNotBot) -- strict match ==> not ⊥ equateTys :: [Type] -> [Type] -> [PmCt] equateTys ts us = @@ -1671,7 +1676,7 @@ addCoreCt :: Nabla -> Id -> CoreExpr -> MaybeT DsM Nabla addCoreCt nabla x e = do dflags <- getDynFlags let e' = simpleOptExpr dflags e - lift $ tracePm "addCoreCt" (ppr x <+> dcolon <+> ppr (idType x) $$ ppr e $$ ppr e') + -- lift $ tracePm "addCoreCt" (ppr x <+> dcolon <+> ppr (idType x) $$ ppr e $$ ppr e') execStateT (core_expr x e') nabla where -- | Takes apart a 'CoreExpr' and tries to extract as much information about View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d399d072b03a8bb5055d194983b83fdfdf3adf9b -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d399d072b03a8bb5055d194983b83fdfdf3adf9b You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 17:01:36 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Mon, 31 Aug 2020 13:01:36 -0400 Subject: [Git][ghc/ghc][wip/T18341] 2 commits: PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Message-ID: <5f4d2cf0a7170_80baf00fb49913346@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18341 at Glasgow Haskell Compiler / GHC Commits: fc8ab7c9 by Sebastian Graf at 2020-08-31T14:57:03+02:00 PmCheck: Big refactor using guard tree variants more closely following source syntax (#18565) Previously, we desugared and coverage checked plain guard trees as described in Lower Your Guards. That caused (in !3849) quite a bit of pain when we need to partially recover tree structure of the input syntax to return covered sets for long-distance information, for example. In this refactor, I introduced a guard tree variant for each relevant source syntax component of a pattern-match (mainly match groups, match, GRHS, empty case, pattern binding). I made sure to share as much coverage checking code as possible, so that the syntax-specific checking functions are just wrappers around the more substantial checking functions for the LYG primitives (`checkSequence`, `checkGrds`). The refactoring payed off in clearer code and elimination of all panics related to assumed guard tree structure and thus fixes #18565. I also took the liberty to rename and re-arrange the order of functions and comments in the module, deleted some dead and irrelevant Notes, wrote some new ones and gave an overview module haddock. - - - - - b047af87 by Sebastian Graf at 2020-08-31T19:01:02+02:00 PmCheck: Handle ⊥ and strict fields correctly (#18341) In #18341, we discovered an incorrect digression from Lower Your Guards. This MR changes what's necessary to support properly fixing #18341. In particular, bottomness constraints are now properly tracked in the oracle/inhabitation testing, as an additional field `vi_bot :: Maybe Bool` in `VarInfo`. That in turn allows us to model newtypes as advertised in the Appendix of LYG and fix #17725. For some reason I couldn't follow, this also fixes #18273. I also added a couple of regression tests that were missing. Most of them were already fixed before. In summary, this patch fixes #18341, #17725, #18273. - - - - - 10 changed files: - .gitignore - compiler/GHC/Core/DataCon.hs - compiler/GHC/Data/Bag.hs - compiler/GHC/Data/OrdList.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/GuardedRHSs.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/Monad.hs - compiler/GHC/HsToCore/PmCheck.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d399d072b03a8bb5055d194983b83fdfdf3adf9b...b047af87d47c50091f664b6c133a38e8aa4c0bdb -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d399d072b03a8bb5055d194983b83fdfdf3adf9b...b047af87d47c50091f664b6c133a38e8aa4c0bdb You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 17:19:37 2020 From: gitlab at gitlab.haskell.org (Sebastian Graf) Date: Mon, 31 Aug 2020 13:19:37 -0400 Subject: =?UTF-8?Q?[Git][ghc/ghc][wip/T18341]_PmCheck:_Handle_=E2=8A=A5_and?= =?UTF-8?Q?_strict_fields_correctly_=28#18341=29?= Message-ID: <5f4d31291e61b_80b3f8492535c409919260@gitlab.haskell.org.mail> Sebastian Graf pushed to branch wip/T18341 at Glasgow Haskell Compiler / GHC Commits: 42f9bf20 by Sebastian Graf at 2020-08-31T19:19:21+02:00 PmCheck: Handle ⊥ and strict fields correctly (#18341) In #18341, we discovered an incorrect digression from Lower Your Guards. This MR changes what's necessary to support properly fixing #18341. In particular, bottomness constraints are now properly tracked in the oracle/inhabitation testing, as an additional field `vi_bot :: Maybe Bool` in `VarInfo`. That in turn allows us to model newtypes as advertised in the Appendix of LYG and fix #17725. For some reason I couldn't follow, this also fixes #18273. I also added a couple of regression tests that were missing. Most of them were already fixed before. In summary, this patch fixes #18341, #17725, #18273. - - - - - 27 changed files: - .gitignore - compiler/GHC/Core/DataCon.hs - compiler/GHC/Data/Bag.hs - compiler/GHC/HsToCore/Binds.hs - compiler/GHC/HsToCore/Expr.hs - compiler/GHC/HsToCore/GuardedRHSs.hs - compiler/GHC/HsToCore/Match.hs - compiler/GHC/HsToCore/Monad.hs - compiler/GHC/HsToCore/PmCheck.hs - compiler/GHC/HsToCore/PmCheck/Oracle.hs - compiler/GHC/HsToCore/PmCheck/Ppr.hs - compiler/GHC/HsToCore/PmCheck/Types.hs - compiler/GHC/HsToCore/PmCheck/Types.hs-boot - compiler/GHC/Tc/Types.hs - + testsuite/tests/pmcheck/should_compile/T10183.hs - testsuite/tests/pmcheck/should_compile/T17340.stderr - + testsuite/tests/pmcheck/should_compile/T17378.hs - + testsuite/tests/pmcheck/should_compile/T17725.hs - + testsuite/tests/pmcheck/should_compile/T17725.stderr - + testsuite/tests/pmcheck/should_compile/T17729.hs - + testsuite/tests/pmcheck/should_compile/T17729.stderr - + testsuite/tests/pmcheck/should_compile/T18273.hs - + testsuite/tests/pmcheck/should_compile/T18341.hs - + testsuite/tests/pmcheck/should_compile/T18341.stderr - testsuite/tests/pmcheck/should_compile/TooManyDeltas.hs - testsuite/tests/pmcheck/should_compile/TooManyDeltas.stderr - testsuite/tests/pmcheck/should_compile/all.T Changes: ===================================== .gitignore ===================================== @@ -232,3 +232,6 @@ ghc.nix/ # Tooling - vscode .vscode + +# Tooling - ghcide +*.hiedb ===================================== compiler/GHC/Core/DataCon.hs ===================================== @@ -53,7 +53,7 @@ module GHC.Core.DataCon ( -- ** Predicates on DataCons isNullarySrcDataCon, isNullaryRepDataCon, isTupleDataCon, isUnboxedTupleCon, isUnboxedSumCon, - isVanillaDataCon, classDataCon, dataConCannotMatch, + isVanillaDataCon, isNewDataCon, classDataCon, dataConCannotMatch, dataConUserTyVarsArePermuted, isBanged, isMarkedStrict, eqHsBang, isSrcStrict, isSrcUnpacked, specialPromotedDc, @@ -1477,6 +1477,10 @@ isUnboxedSumCon (MkData {dcRepTyCon = tc}) = isUnboxedSumTyCon tc isVanillaDataCon :: DataCon -> Bool isVanillaDataCon dc = dcVanilla dc +-- | Is this the 'DataCon' of a newtype? +isNewDataCon :: DataCon -> Bool +isNewDataCon dc = isNewTyCon (dataConTyCon dc) + -- | Should this DataCon be allowed in a type even without -XDataKinds? -- Currently, only Lifted & Unlifted specialPromotedDc :: DataCon -> Bool ===================================== compiler/GHC/Data/Bag.hs ===================================== @@ -6,7 +6,7 @@ Bag: an unordered collection with duplicates -} -{-# LANGUAGE ScopedTypeVariables, CPP, DeriveFunctor #-} +{-# LANGUAGE ScopedTypeVariables, CPP, DeriveFunctor, TypeFamilies #-} module GHC.Data.Bag ( Bag, -- abstract type @@ -27,9 +27,9 @@ module GHC.Data.Bag ( import GHC.Prelude +import GHC.Exts ( IsList(..) ) import GHC.Utils.Outputable import GHC.Utils.Misc - import GHC.Utils.Monad import Control.Monad import Data.Data @@ -333,3 +333,8 @@ instance Traversable Bag where traverse f (UnitBag x) = UnitBag <$> f x traverse f (TwoBags b1 b2) = TwoBags <$> traverse f b1 <*> traverse f b2 traverse f (ListBag xs) = ListBag <$> traverse f xs + +instance IsList (Bag a) where + type Item (Bag a) = a + fromList = listToBag + toList = bagToList ===================================== compiler/GHC/HsToCore/Binds.hs ===================================== @@ -184,8 +184,8 @@ dsHsBind dflags b@(FunBind { fun_id = L loc fun dsHsBind dflags (PatBind { pat_lhs = pat, pat_rhs = grhss , pat_ext = ty , pat_ticks = (rhs_tick, var_ticks) }) - = do { rhss_deltas <- covCheckGRHSs PatBindGuards grhss - ; body_expr <- dsGuarded grhss ty rhss_deltas + = do { rhss_nablas <- covCheckGRHSs PatBindGuards grhss + ; body_expr <- dsGuarded grhss ty rhss_nablas ; let body' = mkOptTickBox rhs_tick body_expr pat' = decideBangHood dflags pat ; (force_var,sel_binds) <- mkSelectorBinds var_ticks pat body' ===================================== compiler/GHC/HsToCore/Expr.hs ===================================== @@ -215,8 +215,8 @@ dsUnliftedBind (PatBind {pat_lhs = pat, pat_rhs = grhss , pat_ext = ty }) body = -- let C x# y# = rhs in body -- ==> case rhs of C x# y# -> body - do { match_deltas <- covCheckGRHSs PatBindGuards grhss - ; rhs <- dsGuarded grhss ty match_deltas + do { match_nablas <- covCheckGRHSs PatBindGuards grhss + ; rhs <- dsGuarded grhss ty match_nablas ; let upat = unLoc pat eqn = EqnInfo { eqn_pats = [upat], eqn_orig = FromSource, @@ -486,8 +486,8 @@ dsExpr (HsMultiIf res_ty alts) | otherwise = do { let grhss = GRHSs noExtField alts (noLoc emptyLocalBinds) - ; rhss_deltas <- covCheckGRHSs IfAlt grhss - ; match_result <- dsGRHSs IfAlt grhss res_ty rhss_deltas + ; rhss_nablas <- covCheckGRHSs IfAlt grhss + ; match_result <- dsGRHSs IfAlt grhss res_ty rhss_nablas ; error_expr <- mkErrorExpr ; extractMatchResult match_result error_expr } where ===================================== compiler/GHC/HsToCore/GuardedRHSs.hs ===================================== @@ -25,7 +25,7 @@ import GHC.Core.Utils (bindNonRec) import GHC.HsToCore.Monad import GHC.HsToCore.Utils -import GHC.HsToCore.PmCheck.Types ( Deltas ) +import GHC.HsToCore.PmCheck.Types ( Nablas ) import GHC.Core.Type ( Type ) import GHC.Utils.Misc import GHC.Types.SrcLoc @@ -48,9 +48,9 @@ producing an expression with a runtime error in the corner case if necessary. The type argument gives the type of the @ei at . -} -dsGuarded :: GRHSs GhcTc (LHsExpr GhcTc) -> Type -> NonEmpty Deltas -> DsM CoreExpr -dsGuarded grhss rhs_ty rhss_deltas = do - match_result <- dsGRHSs PatBindRhs grhss rhs_ty rhss_deltas +dsGuarded :: GRHSs GhcTc (LHsExpr GhcTc) -> Type -> NonEmpty Nablas -> DsM CoreExpr +dsGuarded grhss rhs_ty rhss_nablas = do + match_result <- dsGRHSs PatBindRhs grhss rhs_ty rhss_nablas error_expr <- mkErrorAppDs nON_EXHAUSTIVE_GUARDS_ERROR_ID rhs_ty empty extractMatchResult match_result error_expr @@ -59,28 +59,28 @@ dsGuarded grhss rhs_ty rhss_deltas = do dsGRHSs :: HsMatchContext GhcRn -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ Guarded RHSs -> Type -- ^ Type of RHS - -> NonEmpty Deltas -- ^ Refined pattern match checking + -> NonEmpty Nablas -- ^ Refined pattern match checking -- models, one for the pattern part and -- one for each GRHS. -> DsM (MatchResult CoreExpr) -dsGRHSs hs_ctx (GRHSs _ grhss binds) rhs_ty rhss_deltas +dsGRHSs hs_ctx (GRHSs _ grhss binds) rhs_ty rhss_nablas = ASSERT( notNull grhss ) - do { match_results <- ASSERT( length grhss == length rhss_deltas ) - zipWithM (dsGRHS hs_ctx rhs_ty) (toList rhss_deltas) grhss - ; deltas <- getPmDeltas - -- We need to remember the Deltas from the particular match context we + do { match_results <- ASSERT( length grhss == length rhss_nablas ) + zipWithM (dsGRHS hs_ctx rhs_ty) (toList rhss_nablas) grhss + ; nablas <- getPmNablas + -- We need to remember the Nablas from the particular match context we -- are in, which might be different to when dsLocalBinds is actually -- called. - ; let ds_binds = updPmDeltas deltas . dsLocalBinds binds + ; let ds_binds = updPmNablas nablas . dsLocalBinds binds match_result1 = foldr1 combineMatchResults match_results match_result2 = adjustMatchResultDs ds_binds match_result1 -- NB: nested dsLet inside matchResult ; return match_result2 } -dsGRHS :: HsMatchContext GhcRn -> Type -> Deltas -> LGRHS GhcTc (LHsExpr GhcTc) +dsGRHS :: HsMatchContext GhcRn -> Type -> Nablas -> LGRHS GhcTc (LHsExpr GhcTc) -> DsM (MatchResult CoreExpr) -dsGRHS hs_ctx rhs_ty rhs_deltas (L _ (GRHS _ guards rhs)) - = matchGuards (map unLoc guards) (PatGuard hs_ctx) rhs_deltas rhs rhs_ty +dsGRHS hs_ctx rhs_ty rhs_nablas (L _ (GRHS _ guards rhs)) + = matchGuards (map unLoc guards) (PatGuard hs_ctx) rhs_nablas rhs rhs_ty {- ************************************************************************ @@ -92,7 +92,7 @@ dsGRHS hs_ctx rhs_ty rhs_deltas (L _ (GRHS _ guards rhs)) matchGuards :: [GuardStmt GhcTc] -- Guard -> HsStmtContext GhcRn -- Context - -> Deltas -- The RHS's covered set for PmCheck + -> Nablas -- The RHS's covered set for PmCheck -> LHsExpr GhcTc -- RHS -> Type -- Type of RHS of guard -> DsM (MatchResult CoreExpr) @@ -100,8 +100,8 @@ matchGuards :: [GuardStmt GhcTc] -- Guard -- See comments with HsExpr.Stmt re what a BodyStmt means -- Here we must be in a guard context (not do-expression, nor list-comp) -matchGuards [] _ deltas rhs _ - = do { core_rhs <- updPmDeltas deltas (dsLExpr rhs) +matchGuards [] _ nablas rhs _ + = do { core_rhs <- updPmNablas nablas (dsLExpr rhs) ; return (cantFailMatchResult core_rhs) } -- BodyStmts must be guards @@ -111,31 +111,31 @@ matchGuards [] _ deltas rhs _ -- NB: The success of this clause depends on the typechecker not -- wrapping the 'otherwise' in empty HsTyApp or HsWrap constructors -- If it does, you'll get bogus overlap warnings -matchGuards (BodyStmt _ e _ _ : stmts) ctx deltas rhs rhs_ty +matchGuards (BodyStmt _ e _ _ : stmts) ctx nablas rhs rhs_ty | Just addTicks <- isTrueLHsExpr e = do - match_result <- matchGuards stmts ctx deltas rhs rhs_ty + match_result <- matchGuards stmts ctx nablas rhs rhs_ty return (adjustMatchResultDs addTicks match_result) -matchGuards (BodyStmt _ expr _ _ : stmts) ctx deltas rhs rhs_ty = do - match_result <- matchGuards stmts ctx deltas rhs rhs_ty +matchGuards (BodyStmt _ expr _ _ : stmts) ctx nablas rhs rhs_ty = do + match_result <- matchGuards stmts ctx nablas rhs rhs_ty pred_expr <- dsLExpr expr return (mkGuardedMatchResult pred_expr match_result) -matchGuards (LetStmt _ binds : stmts) ctx deltas rhs rhs_ty = do - match_result <- matchGuards stmts ctx deltas rhs rhs_ty +matchGuards (LetStmt _ binds : stmts) ctx nablas rhs rhs_ty = do + match_result <- matchGuards stmts ctx nablas rhs rhs_ty return (adjustMatchResultDs (dsLocalBinds binds) match_result) -- NB the dsLet occurs inside the match_result -- Reason: dsLet takes the body expression as its argument -- so we can't desugar the bindings without the -- body expression in hand -matchGuards (BindStmt _ pat bind_rhs : stmts) ctx deltas rhs rhs_ty = do +matchGuards (BindStmt _ pat bind_rhs : stmts) ctx nablas rhs rhs_ty = do let upat = unLoc pat match_var <- selectMatchVar Many upat -- We only allow unrestricted patterns in guard, hence the `Many` -- above. It isn't clear what linear patterns would mean, maybe we will -- figure it out in the future. - match_result <- matchGuards stmts ctx deltas rhs rhs_ty + match_result <- matchGuards stmts ctx nablas rhs rhs_ty core_rhs <- dsLExpr bind_rhs match_result' <- matchSinglePatVar match_var (Just core_rhs) (StmtCtxt ctx) pat rhs_ty match_result ===================================== compiler/GHC/HsToCore/Match.hs ===================================== @@ -35,7 +35,7 @@ import GHC.Tc.Utils.Zonk import GHC.Tc.Types.Evidence import GHC.Tc.Utils.Monad import GHC.HsToCore.PmCheck -import GHC.HsToCore.PmCheck.Types ( Deltas, initDeltas ) +import GHC.HsToCore.PmCheck.Types ( Nablas, initNablas ) import GHC.Core import GHC.Types.Literal import GHC.Core.Utils @@ -766,31 +766,31 @@ matchWrapper ctxt mb_scr (MG { mg_alts = L _ matches (hsLMatchPats m)) -- Pattern match check warnings for /this match-group/. - -- @rhss_deltas@ is a flat list of covered Deltas for each RHS. - -- Each Match will split off one Deltas for its RHSs from this. - ; matches_deltas <- if isMatchContextPmChecked dflags origin ctxt + -- @rhss_nablas@ is a flat list of covered Nablas for each RHS. + -- Each Match will split off one Nablas for its RHSs from this. + ; matches_nablas <- if isMatchContextPmChecked dflags origin ctxt then addHsScrutTmCs mb_scr new_vars $ -- See Note [Long-distance information] covCheckMatches (DsMatchContext ctxt locn) new_vars matches - else pure (initDeltasMatches matches) + else pure (initNablasMatches matches) - ; eqns_info <- zipWithM mk_eqn_info matches matches_deltas + ; eqns_info <- zipWithM mk_eqn_info matches matches_nablas ; result_expr <- handleWarnings $ matchEquations ctxt new_vars eqns_info rhs_ty ; return (new_vars, result_expr) } where -- Called once per equation in the match, or alternative in the case - mk_eqn_info :: LMatch GhcTc (LHsExpr GhcTc) -> (Deltas, NonEmpty Deltas) -> DsM EquationInfo - mk_eqn_info (L _ (Match { m_pats = pats, m_grhss = grhss })) (pat_deltas, rhss_deltas) + mk_eqn_info :: LMatch GhcTc (LHsExpr GhcTc) -> (Nablas, NonEmpty Nablas) -> DsM EquationInfo + mk_eqn_info (L _ (Match { m_pats = pats, m_grhss = grhss })) (pat_nablas, rhss_nablas) = do { dflags <- getDynFlags ; let upats = map (unLoc . decideBangHood dflags) pats - -- pat_deltas is the covered set *after* matching the pattern, but - -- before any of the GRHSs. We extend the environment with pat_deltas - -- (via updPmDeltas) so that the where-clause of 'grhss' can profit + -- pat_nablas is the covered set *after* matching the pattern, but + -- before any of the GRHSs. We extend the environment with pat_nablas + -- (via updPmNablas) so that the where-clause of 'grhss' can profit -- from that knowledge (#18533) - ; match_result <- updPmDeltas pat_deltas $ - dsGRHSs ctxt grhss rhs_ty rhss_deltas + ; match_result <- updPmNablas pat_nablas $ + dsGRHSs ctxt grhss rhs_ty rhss_nablas ; return EqnInfo { eqn_pats = upats , eqn_orig = FromSource , eqn_rhs = match_result } } @@ -799,14 +799,14 @@ matchWrapper ctxt mb_scr (MG { mg_alts = L _ matches then discardWarningsDs else id - initDeltasMatches :: [LMatch GhcTc b] -> [(Deltas, NonEmpty Deltas)] - initDeltasMatches ms - = map (\(L _ m) -> (initDeltas, initDeltasGRHSs (m_grhss m))) ms + initNablasMatches :: [LMatch GhcTc b] -> [(Nablas, NonEmpty Nablas)] + initNablasMatches ms + = map (\(L _ m) -> (initNablas, initNablasGRHSs (m_grhss m))) ms - initDeltasGRHSs :: GRHSs GhcTc b -> NonEmpty Deltas - initDeltasGRHSs m = expectJust "GRHSs non-empty" + initNablasGRHSs :: GRHSs GhcTc b -> NonEmpty Nablas + initNablasGRHSs m = expectJust "GRHSs non-empty" $ NEL.nonEmpty - $ replicate (length (grhssGRHSs m)) initDeltas + $ replicate (length (grhssGRHSs m)) initNablas matchEquations :: HsMatchContext GhcRn ===================================== compiler/GHC/HsToCore/Monad.hs ===================================== @@ -34,7 +34,7 @@ module GHC.HsToCore.Monad ( DsMetaEnv, DsMetaVal(..), dsGetMetaEnv, dsLookupMetaEnv, dsExtendMetaEnv, -- Getting and setting pattern match oracle states - getPmDeltas, updPmDeltas, + getPmNablas, updPmNablas, -- Get COMPLETE sets of a TyCon dsGetCompleteMatches, @@ -304,7 +304,7 @@ mkDsEnvs dflags mod rdr_env type_env fam_inst_env msg_var cc_st_var } lcl_env = DsLclEnv { dsl_meta = emptyNameEnv , dsl_loc = real_span - , dsl_deltas = initDeltas + , dsl_nablas = initNablas } in (gbl_env, lcl_env) @@ -403,14 +403,14 @@ the @SrcSpan@ being carried around. getGhcModeDs :: DsM GhcMode getGhcModeDs = getDynFlags >>= return . ghcMode --- | Get the current pattern match oracle state. See 'dsl_deltas'. -getPmDeltas :: DsM Deltas -getPmDeltas = do { env <- getLclEnv; return (dsl_deltas env) } +-- | Get the current pattern match oracle state. See 'dsl_nablas'. +getPmNablas :: DsM Nablas +getPmNablas = do { env <- getLclEnv; return (dsl_nablas env) } -- | Set the pattern match oracle state within the scope of the given action. --- See 'dsl_deltas'. -updPmDeltas :: Deltas -> DsM a -> DsM a -updPmDeltas deltas = updLclEnv (\env -> env { dsl_deltas = deltas }) +-- See 'dsl_nablas'. +updPmNablas :: Nablas -> DsM a -> DsM a +updPmNablas nablas = updLclEnv (\env -> env { dsl_nablas = nablas }) getSrcSpanDs :: DsM SrcSpan getSrcSpanDs = do { env <- getLclEnv ===================================== compiler/GHC/HsToCore/PmCheck.hs ===================================== @@ -28,14 +28,14 @@ -- a. The set of uncovered values, 'cr_uncov' -- b. And an annotated tree variant (like 'AnnMatch') that captures -- redundancy and inaccessibility information as 'RedSets' annotations --- Basically the UA function from Section 5.1. The Normalised Refinement Types --- Nabla are modeled as 'Deltas' and checked in "GHC.HsToCore.PmCheck.Oracle". +-- Basically the UA function from Section 5.1. The Normalised Refinement +-- Types 'Nablas' are maintained in "GHC.HsToCore.PmCheck.Oracle". -- 3. Collect redundancy information into a 'CIRB' with a 'CIRBCollector' such -- as 'collectMatch'. Follows the R function from Figure 6 of the paper. -- 4. Format and report uncovered patterns and redundant equations ('CIRB') -- with 'formatReportWarnings'. Basically job of the G function, plus proper -- pretty printing of the warnings (Section 5.4 of the paper). --- 5. Return 'Deltas' reaching syntactic sub-components for +-- 5. Return 'Nablas' reaching syntactic sub-components for -- Note [Long-distance information]. See Section 4.1 of the paper. module GHC.HsToCore.PmCheck ( -- Checking and printing @@ -68,7 +68,6 @@ import GHC.Utils.Misc import GHC.Utils.Outputable import GHC.Utils.Panic import GHC.Core.DataCon -import GHC.Core.TyCon import GHC.Types.Var (EvVar) import GHC.Core.Coercion import GHC.Tc.Types.Evidence (HsWrapper(..), isIdHsWrapper) @@ -103,7 +102,7 @@ import Data.Coerce covCheckPatBind :: DsMatchContext -> Id -> Pat GhcTc -> DsM () -- See Note [covCheckPatBind only checks PatBindRhs] covCheckPatBind ctxt@(DsMatchContext PatBindRhs loc) var p = do - missing <- getPmDeltas + missing <- getPmNablas pat_bind <- desugarPatBind loc var p tracePm "covCheckPatBind {" (vcat [ppr ctxt, ppr var, ppr p, ppr pat_bind, ppr missing]) result <- unCA (checkPatBind pat_bind) missing @@ -112,17 +111,17 @@ covCheckPatBind ctxt@(DsMatchContext PatBindRhs loc) var p = do covCheckPatBind _ _ _ = pure () -- | Exhaustive for guard matches, is used for guards in pattern bindings and --- in @MultiIf@ expressions. Returns the 'Deltas' covered by the RHSs. +-- in @MultiIf@ expressions. Returns the 'Nablas' covered by the RHSs. covCheckGRHSs :: HsMatchContext GhcRn -- ^ Match context, for warning messages -> GRHSs GhcTc (LHsExpr GhcTc) -- ^ The GRHSs to check - -> DsM (NonEmpty Deltas) -- ^ Covered 'Deltas' for each RHS, for long + -> DsM (NonEmpty Nablas) -- ^ Covered 'Nablas' for each RHS, for long -- distance info covCheckGRHSs hs_ctxt guards@(GRHSs _ grhss _) = do let combined_loc = foldl1 combineSrcSpans (map getLoc grhss) ctxt = DsMatchContext hs_ctxt combined_loc matches <- desugarGRHSs combined_loc empty guards - missing <- getPmDeltas + missing <- getPmNablas tracePm "covCheckGRHSs" (hang (vcat [ppr ctxt , text "Guards:"]) 2 @@ -140,7 +139,7 @@ covCheckGRHSs hs_ctxt guards@(GRHSs _ grhss _) = do -- f _ _ = 3 -- clause with a single, un-guarded RHS -- @ -- --- Returns one non-empty 'Deltas' for 1.) each pattern of a 'Match' and 2.) +-- Returns one non-empty 'Nablas' for 1.) each pattern of a 'Match' and 2.) -- each of a 'Match'es 'GRHS' for Note [Long-distance information]. -- -- Special case: When there are /no matches/, then the functionassumes it @@ -150,13 +149,13 @@ covCheckMatches :: DsMatchContext -- ^ Match context, for warnings messages -> [Id] -- ^ Match variables, i.e. x and y above -> [LMatch GhcTc (LHsExpr GhcTc)] -- ^ List of matches - -> DsM [(Deltas, NonEmpty Deltas)] -- ^ One covered 'Deltas' per Match and + -> DsM [(Nablas, NonEmpty Nablas)] -- ^ One covered 'Nablas' per Match and -- GRHS, for long distance info. covCheckMatches ctxt vars matches = do -- We have to force @missing@ before printing out the trace message, -- otherwise we get interleaved output from the solver. This function -- should be strict in @missing@ anyway! - !missing <- getPmDeltas + !missing <- getPmNablas tracePm "covCheckMatches {" $ hang (vcat [ppr ctxt, ppr vars, text "Matches:"]) 2 @@ -207,7 +206,7 @@ exception into divergence (@f x = f x@). Semantically, unlike every other case expression, -XEmptyCase is strict in its match var x, which rules out ⊥ as an inhabitant. So we add x /~ ⊥ to the -initial Delta and check if there are any values left to match on. +initial Nabla and check if there are any values left to match on. -} -- @@ -233,8 +232,8 @@ data PmGrd -- bang pattern, in which case we might want to report it as redundant. -- See Note [Dead bang patterns]. | PmBang { - pm_id :: !Id, - pm_loc :: !(Maybe SrcInfo) + pm_id :: !Id, + _pm_loc :: !(Maybe SrcInfo) } -- | @PmLet x expr@ corresponds to a @let x = expr@ guard. This actually @@ -298,15 +297,15 @@ newtype GrdPatBind = -- (later digested into a 'CIRB'). data RedSets = RedSets - { rs_cov :: !Deltas + { rs_cov :: !Nablas -- ^ The /Covered/ set; the set of values reaching a particular program -- point. - , rs_div :: !Deltas + , rs_div :: !Nablas -- ^ The /Diverging/ set; empty if no match can lead to divergence. -- If it wasn't empty, we have to turn redundancy warnings into -- inaccessibility warnings for any subclauses. - , rs_bangs :: !(OrdList (Deltas, SrcInfo)) - -- ^ If any of the 'Deltas' is empty, the corresponding 'SrcInfo' pin-points + , rs_bangs :: !(OrdList (Nablas, SrcInfo)) + -- ^ If any of the 'Nablas' is empty, the corresponding 'SrcInfo' pin-points -- a bang pattern in source that is redundant. See Note [Dead bang patterns]. } @@ -434,7 +433,7 @@ vanillaConGrd scrut con arg_ids = -- For example: -- @mkListGrds "a" "[(x, True <- x),(y, !y)]"@ -- to --- @"[(x:b) <- a, True <- x, (y:c) <- b, seq y True, [] <- c]"@ +-- @"[(x:b) <- a, True <- x, (y:c) <- b, !y, [] <- c]"@ -- where @b@ and @c@ are freshly allocated in @mkListGrds@ and @a@ is the match -- variable. mkListGrds :: Id -> [(Id, GrdVec)] -> DsM GrdVec @@ -618,7 +617,7 @@ desugarListPat x pats = do -- | Desugar a constructor pattern desugarConPatOut :: Id -> ConLike -> [Type] -> [TyVar] - -> [EvVar] -> HsConPatDetails GhcTc -> DsM GrdVec + -> [EvVar] -> HsConPatDetails GhcTc -> DsM GrdVec desugarConPatOut x con univ_tys ex_tvs dicts = \case PrefixCon ps -> go_field_pats (zip [0..] ps) InfixCon p1 p2 -> go_field_pats (zip [0..] [p1,p2]) @@ -638,14 +637,14 @@ desugarConPatOut x con univ_tys ex_tvs dicts = \case lbl_to_index lbl = expectJust "lbl_to_index" $ elemIndex lbl orig_lbls go_field_pats tagged_pats = do - -- The fields that appear might not be in the correct order. So first - -- do a PmCon match, then force according to field strictness and then - -- force evaluation of the field patterns in the order given by - -- the first field of @tagged_pats at . + -- The fields that appear might not be in the correct order. So + -- 1. Do the PmCon match + -- 2. Then pattern match on the fields in the order given by the first + -- field of @tagged_pats at . -- See Note [Field match order for RecCon] -- Desugar the mentioned field patterns. We're doing this first to get - -- the Ids for pm_con_args. + -- the Ids for pm_con_args and bring them in order afterwards. let trans_pat (n, pat) = do (var, pvec) <- desugarLPatV pat pure ((n, var), pvec) @@ -659,19 +658,11 @@ desugarConPatOut x con univ_tys ex_tvs dicts = \case arg_ids <- zipWithM get_pat_id [0..] arg_tys let con_grd = PmCon x (PmAltConLike con) ex_tvs dicts arg_ids - -- 2. bang strict fields - let arg_is_banged = map isBanged $ conLikeImplBangs con - noSrcPmBang i = PmBang {pm_id = i, pm_loc = Nothing} - bang_grds = map noSrcPmBang (filterByList arg_is_banged arg_ids) - - -- 3. guards from field selector patterns + -- 2. guards from field selector patterns let arg_grds = concat arg_grdss -- tracePm "ConPatOut" (ppr x $$ ppr con $$ ppr arg_ids) - -- - -- Store the guards in exactly that order - -- 1. 2. 3. - pure (con_grd : bang_grds ++ arg_grds) + pure (con_grd : arg_grds) desugarPatBind :: SrcSpan -> Id -> Pat GhcTc -> DsM GrdPatBind -- See 'GrdPatBind' for how this simply repurposes GrdGRHS. @@ -759,30 +750,45 @@ desugarBoolGuard e -> pure [vanillaConGrd y trueDataCon []] rhs -> do x <- mkPmId boolTy - pure $ [PmLet x rhs, vanillaConGrd x trueDataCon []] + pure [PmLet x rhs, vanillaConGrd x trueDataCon []] {- Note [Field match order for RecCon] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The order for RecCon field patterns actually determines evaluation order of the pattern match. For example: - data T = T { a :: !Bool, b :: Char, c :: Int } + data T = T { a :: Char, b :: Int } f :: T -> () - f T{ c = 42, b = 'b' } = () + f T{ b = 42, a = 'a' } = () + +Then @f (T (error "a") (error "b"))@ errors out with "b" because it is mentioned +first in the pattern match. -Then - * @f (T (error "a") (error "b") (error "c"))@ errors out with "a" because of - the strict field. - * @f (T True (error "b") (error "c"))@ errors out with "c" because it - is mentioned frist in the pattern match. +This means we can't just desugar the pattern match to +@[T a b <- x, 'a' <- a, 42 <- b]@. Instead we have to force them in the +right order: @[T a b <- x, 42 <- b, 'a' <- a]@. -This means we can't just desugar the pattern match to the PatVec -@[T !_ 'b' 42]@. Instead we have to generate variable matches that have -strictness according to the field declarations and afterwards force them in the -right order. As a result, we get the PatVec @[T !_ b c, 42 <- c, 'b' <- b]@. +Note [Strict fields and fields of unlifted type] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +How do strict fields play into Note [Field match order for RecCon]? Answer: +They don't. Desugaring is entirely unconcerned by strict fields; the forcing +happens *before* pattern matching. But for each strict (or more generally, +unlifted) field @s@ we have to add @s /~ ⊥@ constraints when we check the PmCon +guard in 'checkGrd'. Strict fields are devoid of ⊥ by construction, there's +nothing that a bang pattern would act on. Example from #18341: + + data T = MkT !Int + f :: T -> () + f (MkT _) | False = () -- inaccessible + f (MkT !_) | False = () -- redundant, not only inaccessible! + f _ = () -Of course, when the labels occur in the order they are defined, we can just use -the simpler desugaring. +The second clause desugars to @MkT n <- x, !n at . When coverage checked, the +'PmCon' @MkT n <- x@ refines the set of values that reach the bang pattern with +the constraints @x ~ MkT n, n /~ ⊥@ (this list is computed by 'pmConCts'). +Checking the 'PmBang' @!n@ will then try to add the constraint @n ~ ⊥@ to this +set to get the diverging set, which is found to be empty. Hence the whole +clause is detected as redundant, as expected. Note [Order of guards matters] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -834,7 +840,7 @@ data CheckResult a = CheckResult { cr_ret :: !a -- ^ A hole for redundancy info and covered sets. - , cr_uncov :: !Deltas + , cr_uncov :: !Nablas -- ^ The set of uncovered values falling out at the bottom. -- (for -Wincomplete-patterns, but also important state for the algorithm) , cr_approx :: !Precision @@ -852,23 +858,23 @@ instance Outputable a => Outputable (CheckResult a) where ppr_precision Approximate = text "(Approximate)" field name value = text name <+> equals <+> ppr value --- | Lift 'addPmCts' over 'Deltas'. -addPmCtsDeltas :: Deltas -> PmCts -> DsM Deltas -addPmCtsDeltas deltas cts = liftDeltasM (\d -> addPmCts d cts) deltas +-- | Lift 'addPmCts' over 'Nablas'. +addPmCtsNablas :: Nablas -> PmCts -> DsM Nablas +addPmCtsNablas nablas cts = liftNablasM (\d -> addPmCts d cts) nablas --- | 'addPmCtsDeltas' for a single 'PmCt'. -addPmCtDeltas :: Deltas -> PmCt -> DsM Deltas -addPmCtDeltas deltas ct = addPmCtsDeltas deltas (unitBag ct) +-- | 'addPmCtsNablas' for a single 'PmCt'. +addPmCtNablas :: Nablas -> PmCt -> DsM Nablas +addPmCtNablas nablas ct = addPmCtsNablas nablas (unitBag ct) --- | Test if any of the 'Delta's is inhabited. Currently this is pure, because --- we preserve the invariant that there are no uninhabited 'Delta's. But that +-- | Test if any of the 'Nabla's is inhabited. Currently this is pure, because +-- we preserve the invariant that there are no uninhabited 'Nabla's. But that -- could change in the future, for example by implementing this function in -- terms of @notNull <$> provideEvidence 1 ds at . -isInhabited :: Deltas -> DsM Bool -isInhabited (MkDeltas ds) = pure (not (null ds)) +isInhabited :: Nablas -> DsM Bool +isInhabited (MkNablas ds) = pure (not (null ds)) -- | Coverage checking action. Can be composed 'leftToRight' or 'topToBottom'. -newtype CheckAction a = CA { unCA :: Deltas -> DsM (CheckResult a) } +newtype CheckAction a = CA { unCA :: Nablas -> DsM (CheckResult a) } deriving Functor -- | Composes 'CheckAction's top-to-bottom: @@ -910,23 +916,34 @@ leftToRight f (CA left) (CA right) = CA $ \inc -> do , cr_uncov = uncov' , cr_approx = prec' Semi.<> cr_approx l Semi.<> cr_approx r } --- | @throttle limit old new@ returns @old@ if the number of 'Delta's in @new@ --- is exceeding the given @limit@ and the @old@ number of 'Delta's. +-- | @throttle limit old new@ returns @old@ if the number of 'Nabla's in @new@ +-- is exceeding the given @limit@ and the @old@ number of 'Nabla's. -- See Note [Countering exponential blowup]. -throttle :: Int -> Deltas -> Deltas -> (Precision, Deltas) -throttle limit old@(MkDeltas old_ds) new@(MkDeltas new_ds) +throttle :: Int -> Nablas -> Nablas -> (Precision, Nablas) +throttle limit old@(MkNablas old_ds) new@(MkNablas new_ds) --- | pprTrace "PmCheck:throttle" (ppr (length old_ds) <+> ppr (length new_ds) <+> ppr limit) False = undefined | length new_ds > max limit (length old_ds) = (Approximate, old) | otherwise = (Precise, new) --- | Matching on a newtype doesn't force anything. --- See Note [Divergence of Newtype matches] in "GHC.HsToCore.PmCheck.Oracle". -conMatchForces :: PmAltCon -> Bool -conMatchForces (PmAltConLike (RealDataCon dc)) - | isNewTyCon (dataConTyCon dc) = False -conMatchForces _ = True - --- First the functions that correspond to checking LYG primitives: +-- | The 'PmCts' arising from a successful 'PmCon' match @T gammas as ys <- x at . +-- These include +-- +-- * @gammas@: Constraints arising from the bound evidence vars +-- * @y /~ ⊥@ constraints for each unlifted field (including strict fields) +-- @y@ in @ys@ +-- * The constructor constraint itself: @x ~ T as ys at . +-- +-- See Note [Strict fields and fields of unlifted type]. +pmConCts :: Id -> PmAltCon -> [TyVar] -> [EvVar] -> [Id] -> PmCts +pmConCts x con tvs dicts args = gammas `unionBags` unlifted `snocBag` con_ct + where + gammas = listToBag $ map (PmTyCt . evVarPred) dicts + con_ct = PmConCt x con tvs args + unlifted = listToBag [ PmNotBotCt arg + | (arg, bang) <- + zipEqual "pmConCts" args (pmAltConImplBangs con) + , isBanged bang || isUnliftedType (idType arg) + ] checkSequence :: (grdtree -> CheckAction anntree) -> NonEmpty grdtree -> CheckAction (NonEmpty anntree) -- The implementation is pretty similar to @@ -939,31 +956,32 @@ checkGrd :: PmGrd -> CheckAction RedSets checkGrd grd = CA $ \inc -> case grd of -- let x = e: Refine with x ~ e PmLet x e -> do - matched <- addPmCtDeltas inc (PmCoreCt x e) + matched <- addPmCtNablas inc (PmCoreCt x e) + -- tracePm "check:Let" (ppr x <+> char '=' <+> ppr e) pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched } , cr_uncov = mempty , cr_approx = Precise } -- Bang x _: Diverge on x ~ ⊥, refine with x /~ ⊥ PmBang x mb_info -> do - div <- addPmCtDeltas inc (PmBotCt x) - matched <- addPmCtDeltas inc (PmNotBotCt x) + div <- addPmCtNablas inc (PmBotCt x) + matched <- addPmCtNablas inc (PmNotBotCt x) -- See Note [Dead bang patterns] -- mb_info = Just info <==> PmBang originates from bang pattern in source let bangs | Just info <- mb_info = unitOL (div, info) | otherwise = NilOL + -- tracePm "check:Bang" (ppr x <+> ppr div) pure CheckResult { cr_ret = RedSets { rs_cov = matched, rs_div = div, rs_bangs = bangs } , cr_uncov = mempty , cr_approx = Precise } - -- Con: Diverge on x ~ ⊥, fall through on x /~ K and refine with x ~ K ys - -- and type info + -- Con: Fall through on x /~ K and refine with x ~ K ys and type info PmCon x con tvs dicts args -> do - div <- if conMatchForces con - then addPmCtDeltas inc (PmBotCt x) + !div <- if isPmAltConMatchStrict con + then addPmCtNablas inc (PmBotCt x) else pure mempty - uncov <- addPmCtDeltas inc (PmNotConCt x con) - matched <- addPmCtsDeltas inc $ - listToBag (PmTyCt . evVarPred <$> dicts) `snocBag` PmConCt x con tvs args - -- tracePm "checkGrd:Con" (ppr inc $$ ppr x $$ ppr con $$ ppr dicts $$ ppr matched) + let con_cts = pmConCts x con tvs dicts args + !matched <- addPmCtsNablas inc con_cts + !uncov <- addPmCtNablas inc (PmNotConCt x con) + -- tracePm "checkGrd:Con" (ppr inc $$ ppr grd $$ ppr con_cts $$ ppr matched) pure CheckResult { cr_ret = emptyRedSets { rs_cov = matched, rs_div = div } , cr_uncov = uncov , cr_approx = Precise } @@ -997,7 +1015,7 @@ checkGRHS (GrdGRHS { gg_grds = grds, gg_rhs = rhs_info }) = checkEmptyCase :: GrdEmptyCase -> CheckAction AnnEmptyCase checkEmptyCase (GrdEmptyCase { ge_var = var }) = CA $ \inc -> do - unc <- addPmCtDeltas inc (PmNotBotCt var) + unc <- addPmCtNablas inc (PmNotBotCt var) pure CheckResult { cr_ret = AnnEmptyCase, cr_uncov = unc, cr_approx = mempty } checkPatBind :: GrdPatBind -> CheckAction AnnPatBind @@ -1007,7 +1025,7 @@ checkPatBind = coerce checkGRHS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Precise pattern match exhaustiveness checking is necessarily exponential in the size of some input programs. We implement a counter-measure in the form of -the -fmax-pmcheck-models flag, limiting the number of Deltas we check against +the -fmax-pmcheck-models flag, limiting the number of Nablas we check against each pattern by a constant. How do we do that? Consider @@ -1016,13 +1034,13 @@ How do we do that? Consider f True True = () And imagine we set our limit to 1 for the sake of the example. The first clause -will be checked against the initial Delta, {}. Doing so will produce an +will be checked against the initial Nabla, {}. Doing so will produce an Uncovered set of size 2, containing the models {x/~True} and {x~True,y/~True}. Also we find the first clause to cover the model {x~True,y~True}. But the Uncovered set we get out of the match is too huge! We somehow have to ensure not to make things worse as they are already, so we continue checking -with a singleton Uncovered set of the initial Delta {}. Why is this +with a singleton Uncovered set of the initial Nabla {}. Why is this sound (wrt. the notion in GADTs Meet Their Match)? Well, it basically amounts to forgetting that we matched against the first clause. The values represented by {} are a superset of those represented by its two refinements {x/~True} and @@ -1093,41 +1111,41 @@ addRedundantBangs red_bangs cirb = -- 1. A 'CIRB', classifying every encountered RHS in the tree as -- redundant, inaccessible or covered. -- 2. A piece of long-distance information @ldi@, consisting of a --- nesting of 'Deltas' mirroring tree structure. +-- nesting of 'Nablas' mirroring tree structure. -- For example, 'collectMatchGroup' operates on a Match Group and thus --- returns a list of 'Deltas' for the pattern part of each Match, as well as --- a further nested list of 'Deltas' for each of the GRHS of the Match. +-- returns a list of 'Nablas' for the pattern part of each Match, as well as +-- a further nested list of 'Nablas' for each of the GRHS of the Match. type CIRBCollector ann ldi = ann -> DsM (CIRB, ldi) --- | Checks the 'Deltas' in a 'RedSets' for inhabitants and returns +-- | Checks the 'Nablas' in a 'RedSets' for inhabitants and returns -- 1. Whether the Covered set was inhabited -- 2. Whether the Diverging set was inhabited -- 3. The new inhabited Covered set for long-distance information. -- See Note [Recovering from unsatisfiable pattern-matching constraints]. --- 4. All source bangs whose 'Deltas' were empty, which means they are +-- 4. All source bangs whose 'Nablas' were empty, which means they are -- redundant. -testRedSets :: Deltas -> RedSets -> DsM (Bool, Bool, Deltas, OrdList SrcInfo) +testRedSets :: Nablas -> RedSets -> DsM (Bool, Bool, Nablas, OrdList SrcInfo) testRedSets ldi RedSets { rs_cov = cov, rs_div = div, rs_bangs = bangs } = do is_covered <- isInhabited cov may_diverge <- isInhabited div - red_bangs <- flip mapMaybeM (fromOL bangs) $ \(deltas, bang) -> do - isInhabited deltas >>= \case + red_bangs <- flip mapMaybeM (fromOL bangs) $ \(nablas, bang) -> do + isInhabited nablas >>= \case True -> pure Nothing False -> pure (Just bang) -- See Note [Recovering from unsatisfiable pattern-matching constraints] - -- Deltas for long-distance info: Use (non-empty!) fallback ldi if Covered + -- Nablas for long-distance info: Use (non-empty!) fallback ldi if Covered -- set was empty let ldi' | is_covered = cov | otherwise = ldi pure (is_covered, may_diverge, ldi', toOL red_bangs) -collectMatchGroup :: Deltas -> CIRBCollector AnnMatchGroup (NonEmpty (Deltas, NonEmpty Deltas)) +collectMatchGroup :: Nablas -> CIRBCollector AnnMatchGroup (NonEmpty (Nablas, NonEmpty Nablas)) collectMatchGroup ldi (AnnMatchGroup matches) = do (cirbs, ldis) <- NE.unzip <$> traverse (collectMatch ldi) matches pure (Semi.sconcat cirbs, ldis) -collectMatch :: Deltas -> CIRBCollector AnnMatch (Deltas, NonEmpty Deltas) +collectMatch :: Nablas -> CIRBCollector AnnMatch (Nablas, NonEmpty Nablas) collectMatch ldi AnnMatch { am_red = red, am_grhss = grhss } = do (is_covered, may_diverge, ldi', red_bangs) <- testRedSets ldi red (cirb, ldis) <- collectGRHSs ldi' grhss @@ -1138,12 +1156,12 @@ collectMatch ldi AnnMatch { am_red = red, am_grhss = grhss } = do $ cirb pure (cirb', (ldi', ldis)) -collectGRHSs :: Deltas -> CIRBCollector (NonEmpty AnnGRHS) (NonEmpty Deltas) +collectGRHSs :: Nablas -> CIRBCollector (NonEmpty AnnGRHS) (NonEmpty Nablas) collectGRHSs ldi grhss = do (cirbs, ldis) <- NE.unzip <$> traverse (collectGRHS ldi) grhss pure (Semi.sconcat cirbs, ldis) -collectGRHS :: Deltas -> CIRBCollector AnnGRHS Deltas +collectGRHS :: Nablas -> CIRBCollector AnnGRHS Nablas collectGRHS ldi AnnGRHS { ag_red = red, ag_rhs = info } = do (is_covered, may_diverge, ldi', red_bangs) <- testRedSets ldi red let cirb | is_covered = mempty { cirb_cov = unitOL info } @@ -1156,9 +1174,9 @@ collectEmptyCase _ = pure (mempty, ()) collectPatBind :: CIRBCollector AnnPatBind () -- We don't make use of long-distance information in pattern bindings, hence --- @()@ instead of some 'Deltas'. +-- @()@ instead of some 'Nablas'. collectPatBind (AnnPatBind grhs) = do - -- use 'mempty' as fallback 'Deltas' because we discard it anyway + -- use 'mempty' as fallback 'Nablas' because we discard it anyway (cirb, _) <- collectGRHS mempty grhs pure (cirb, ()) @@ -1236,10 +1254,10 @@ reportWarnings dflags ctx@(DsMatchContext kind loc) vars f (q <+> matchSeparator kind <+> text "...") -- Print several clauses (for uncovered clauses) - pprEqns vars deltas = pprContext False ctx (text "are non-exhaustive") $ \_ -> + pprEqns vars nablas = pprContext False ctx (text "are non-exhaustive") $ \_ -> case vars of -- See #11245 [] -> text "Guards do not cover entire pattern space" - _ -> let us = map (\delta -> pprUncovered delta vars) deltas + _ -> let us = map (\nabla -> pprUncovered nabla vars) nablas in hang (text "Patterns not matched:") 4 (vcat (take maxPatterns us) $$ dots maxPatterns us) @@ -1254,14 +1272,14 @@ reportWarnings dflags ctx@(DsMatchContext kind loc) vars $$ bullet <+> text "Patterns reported as unmatched might actually be matched") , text "Increase the limit or resolve the warnings to suppress this message." ] -getNFirstUncovered :: [Id] -> Int -> Deltas -> DsM [Delta] -getNFirstUncovered vars n (MkDeltas deltas) = go n (bagToList deltas) +getNFirstUncovered :: [Id] -> Int -> Nablas -> DsM [Nabla] +getNFirstUncovered vars n (MkNablas nablas) = go n (bagToList nablas) where go 0 _ = pure [] go _ [] = pure [] - go n (delta:deltas) = do - front <- provideEvidence vars n delta - back <- go (n - length front) deltas + go n (nabla:nablas) = do + front <- provideEvidence vars n nabla + back <- go (n - length front) nablas pure (front ++ back) dots :: Int -> [a] -> SDoc @@ -1386,21 +1404,21 @@ code that we don't want to warn about. -- * Long-distance information -- --- | Locally update 'dsl_deltas' with the given action, but defer evaluation +-- | Locally update 'dsl_nablas' with the given action, but defer evaluation -- with 'unsafeInterleaveM' in order not to do unnecessary work. -locallyExtendPmDeltas :: (Deltas -> DsM Deltas) -> DsM a -> DsM a -locallyExtendPmDeltas ext k = do - deltas <- getPmDeltas - deltas' <- unsafeInterleaveM $ do - deltas' <- ext deltas - inh <- isInhabited deltas' +locallyExtendPmNablas :: (Nablas -> DsM Nablas) -> DsM a -> DsM a +locallyExtendPmNablas ext k = do + nablas <- getPmNablas + nablas' <- unsafeInterleaveM $ do + nablas' <- ext nablas + inh <- isInhabited nablas' -- If adding a constraint would lead to a contradiction, don't add it. -- See Note [Recovering from unsatisfiable pattern-matching constraints] -- for why this is done. if inh - then pure deltas' - else pure deltas - updPmDeltas deltas' k + then pure nablas' + else pure nablas + updPmNablas nablas' k -- | Add in-scope type constraints if the coverage checker might run and then -- run the given action. @@ -1408,7 +1426,7 @@ addTyCs :: Origin -> Bag EvVar -> DsM a -> DsM a addTyCs origin ev_vars m = do dflags <- getDynFlags applyWhen (needToRunPmCheck dflags origin) - (locallyExtendPmDeltas (\deltas -> addPmCtsDeltas deltas (PmTyCt . evVarPred <$> ev_vars))) + (locallyExtendPmNablas (\nablas -> addPmCtsNablas nablas (PmTyCt . evVarPred <$> ev_vars))) m -- | Add equalities for the 'CoreExpr' scrutinee to the local 'DsM' environment @@ -1419,8 +1437,8 @@ addTyCs origin ev_vars m = do addCoreScrutTmCs :: Maybe CoreExpr -> [Id] -> DsM a -> DsM a addCoreScrutTmCs Nothing _ k = k addCoreScrutTmCs (Just scr) [x] k = - flip locallyExtendPmDeltas k $ \deltas -> - addPmCtsDeltas deltas (unitBag (PmCoreCt x scr)) + flip locallyExtendPmNablas k $ \nablas -> + addPmCtsNablas nablas (unitBag (PmCoreCt x scr)) addCoreScrutTmCs _ _ _ = panic "addCoreScrutTmCs: scrutinee, but more than one match id" -- | 'addCoreScrutTmCs', but desugars the 'LHsExpr' first. @@ -1448,10 +1466,10 @@ of @f at . To achieve similar reasoning in the coverage checker, we keep track of the set of values that can reach a particular program point (often loosely referred to -as "Covered set") in 'GHC.HsToCore.Monad.dsl_deltas'. -We fill that set with Covered Deltas returned by the exported checking +as "Covered set") in 'GHC.HsToCore.Monad.dsl_nablas'. +We fill that set with Covered Nablas returned by the exported checking functions, which the call sites put into place with -'GHC.HsToCore.Monad.updPmDeltas'. +'GHC.HsToCore.Monad.updPmNablas'. Call sites also extend this set with facts from type-constraint dictionaries, case scrutinees, etc. with the exported functions 'addTyCs', 'addCoreScrutTmCs' and 'addHsScrutTmCs'. @@ -1472,9 +1490,9 @@ unreachable. We can do better than this, by making sure that the Covered set used for Note [Long-distance information] is always inhabited. For Covered sets returned by the exported checking functions, that is ensured -in 'testRedSets', which takes and returns a non-empty fallback 'Deltas' in case +in 'testRedSets', which takes and returns a non-empty fallback 'Nablas' in case the refined Covered set became uninhabited. Also, whenever "external" knowledge from a type constraint or case scrutinee is -integrated, we only commit that knowledge to 'GHC.HsToCore.Monad.dsl_deltas' if -the set remains inhabited. That check happens in 'locallyExtendPmDeltas'. +integrated, we only commit that knowledge to 'GHC.HsToCore.Monad.dsl_nablas' if +the set remains inhabited. That check happens in 'locallyExtendPmNablas'. -} ===================================== compiler/GHC/HsToCore/PmCheck/Oracle.hs ===================================== @@ -4,22 +4,25 @@ Authors: George Karachalias Ryan Scott -} -{-# LANGUAGE CPP, LambdaCase, TupleSections, PatternSynonyms, ViewPatterns, MultiWayIf #-} +{-# LANGUAGE CPP, LambdaCase, TupleSections, PatternSynonyms, ViewPatterns, MultiWayIf, ScopedTypeVariables #-} -- | The pattern match oracle. The main export of the module are the functions -- 'addPmCts' for adding facts to the oracle, and 'provideEvidence' to turn a --- 'Delta' into a concrete evidence for an equation. +-- 'Nabla' into a concrete evidence for an equation. +-- +-- In terms of the [Lower Your Guards paper](https://dl.acm.org/doi/abs/10.1145/3408989) +-- describing the implementation, this module is concerned with Sections 3.4, 3.6 and 3.7. +-- E.g., it represents refinement types diretly as a normalised refinement type 'Nabla'. module GHC.HsToCore.PmCheck.Oracle ( DsM, tracePm, mkPmId, - Delta, initDeltas, lookupRefuts, lookupSolution, + Nabla, initNablas, lookupRefuts, lookupSolution, PmCt(PmTyCt), PmCts, pattern PmVarCt, pattern PmCoreCt, pattern PmConCt, pattern PmNotConCt, pattern PmBotCt, pattern PmNotBotCt, addPmCts, -- Add a constraint to the oracle. - canDiverge, -- Try to add the term equality x ~ ⊥ provideEvidence ) where @@ -153,12 +156,7 @@ mkOneConFull arg_tys con = do -- to the type oracle let ty_cs = substTheta subst (eqSpecPreds eq_spec ++ thetas) -- Figure out the types of strict constructor fields - let arg_is_strict - | RealDataCon dc <- con - , isNewTyCon (dataConTyCon dc) - = [True] -- See Note [Divergence of Newtype matches] - | otherwise - = map isBanged $ conLikeImplBangs con + let arg_is_strict = map isBanged $ conLikeImplBangs con strict_arg_tys = filterByList arg_is_strict field_tys' return (ex_tvs, vars, listToBag ty_cs, strict_arg_tys) @@ -169,8 +167,8 @@ mkOneConFull arg_tys con = do ------------------------------------- -- * Composable satisfiability checks --- | Given a 'Delta', check if it is compatible with new facts encoded in this --- this check. If so, return 'Just' a potentially extended 'Delta'. Return +-- | Given a 'Nabla', check if it is compatible with new facts encoded in this +-- this check. If so, return 'Just' a potentially extended 'Nabla'. Return -- 'Nothing' if unsatisfiable. -- -- There are three essential SatisfiabilityChecks: @@ -179,22 +177,22 @@ mkOneConFull arg_tys con = do -- 3. 'tysAreNonVoid', checks if the given types have an inhabitant -- Functions like 'pmIsSatisfiable', 'nonVoid' and 'testInhabited' plug these -- together as they see fit. -newtype SatisfiabilityCheck = SC (Delta -> DsM (Maybe Delta)) +newtype SatisfiabilityCheck = SC (Nabla -> DsM (Maybe Nabla)) --- | Check the given 'Delta' for satisfiability by the given --- 'SatisfiabilityCheck'. Return 'Just' a new, potentially extended, 'Delta' if +-- | Check the given 'Nabla' for satisfiability by the given +-- 'SatisfiabilityCheck'. Return 'Just' a new, potentially extended, 'Nabla' if -- successful, and 'Nothing' otherwise. -runSatisfiabilityCheck :: Delta -> SatisfiabilityCheck -> DsM (Maybe Delta) -runSatisfiabilityCheck delta (SC chk) = chk delta +runSatisfiabilityCheck :: Nabla -> SatisfiabilityCheck -> DsM (Maybe Nabla) +runSatisfiabilityCheck nabla (SC chk) = chk nabla -- | Allowing easy composition of 'SatisfiabilityCheck's. instance Semigroup SatisfiabilityCheck where -- This is @a >=> b@ from MaybeT DsM SC a <> SC b = SC c where - c delta = a delta >>= \case + c nabla = a nabla >>= \case Nothing -> pure Nothing - Just delta' -> b delta' + Just nabla' -> b nabla' instance Monoid SatisfiabilityCheck where -- We only need this because of mconcat (which we use in place of sconcat, @@ -213,13 +211,13 @@ instance Monoid SatisfiabilityCheck where -- discussed in GADTs Meet Their Match. For an explanation of what role they -- serve, see @Note [Strict argument type constraints]@. pmIsSatisfiable - :: Delta -- ^ The ambient term and type constraints + :: Nabla -- ^ The ambient term and type constraints -- (known to be satisfiable). -> Bag TyCt -- ^ The new type constraints. -> Bag TmCt -- ^ The new term constraints. -> [Type] -- ^ The strict argument types. - -> DsM (Maybe Delta) - -- ^ @'Just' delta@ if the constraints (@delta@) are + -> DsM (Maybe Nabla) + -- ^ @'Just' nabla@ if the constraints (@nabla@) are -- satisfiable, and each strict argument type is inhabitable. -- 'Nothing' otherwise. pmIsSatisfiable amb_cs new_ty_cs new_tm_cs strict_arg_tys = @@ -492,21 +490,21 @@ tyOracle (TySt inert) cts Nothing -> pprPanic "tyOracle" (vcat $ pprErrMsgBagWithLoc errs) } -- | A 'SatisfiabilityCheck' based on new type-level constraints. --- Returns a new 'Delta' if the new constraints are compatible with existing +-- Returns a new 'Nabla' if the new constraints are compatible with existing -- ones. Doesn't bother calling out to the type oracle if the bag of new type -- constraints was empty. Will only recheck 'PossibleMatches' in the term oracle -- for emptiness if the first argument is 'True'. tyIsSatisfiable :: Bool -> Bag PredType -> SatisfiabilityCheck -tyIsSatisfiable recheck_complete_sets new_ty_cs = SC $ \delta -> +tyIsSatisfiable recheck_complete_sets new_ty_cs = SC $ \nabla -> if isEmptyBag new_ty_cs - then pure (Just delta) - else tyOracle (delta_ty_st delta) new_ty_cs >>= \case + then pure (Just nabla) + else tyOracle (nabla_ty_st nabla) new_ty_cs >>= \case Nothing -> pure Nothing Just ty_st' -> do - let delta' = delta{ delta_ty_st = ty_st' } + let nabla' = nabla{ nabla_ty_st = ty_st' } if recheck_complete_sets - then ensureAllPossibleMatchesInhabited delta' - else pure (Just delta') + then ensureAllInhabited nabla' + else pure (Just nabla') {- ********************************************************************* @@ -618,21 +616,46 @@ warning messages (which can be alleviated by someone with enough dedication). -} -- | A 'SatisfiabilityCheck' based on new term-level constraints. --- Returns a new 'Delta' if the new constraints are compatible with existing +-- Returns a new 'Nabla' if the new constraints are compatible with existing -- ones. tmIsSatisfiable :: Bag TmCt -> SatisfiabilityCheck -tmIsSatisfiable new_tm_cs = SC $ \delta -> runMaybeT $ foldlM addTmCt delta new_tm_cs +tmIsSatisfiable new_tm_cs = SC $ \nabla -> runMaybeT $ foldlM addTmCt nabla new_tm_cs ----------------------- -- * Looking up VarInfo emptyVarInfo :: Id -> VarInfo -emptyVarInfo x = VI (idType x) [] emptyPmAltConSet NoPM +-- We could initialise @bot@ to @Just False@ in case of an unlifted type here, +-- but it's cleaner to let the user of the constraint solver take care of this. +-- After all, there are also strict fields, the unliftedness of which isn't +-- evident in the type. So treating unlifted types here would never be +-- sufficient anyway. +emptyVarInfo x = VI (idType x) [] emptyPmAltConSet MaybeBot NoPM lookupVarInfo :: TmState -> Id -> VarInfo -- (lookupVarInfo tms x) tells what we know about 'x' lookupVarInfo (TmSt env _) x = fromMaybe (emptyVarInfo x) (lookupSDIE env x) +-- | Like @lookupVarInfo ts x@, but @lookupVarInfo ts x = (y, vi)@ also looks +-- through newtype constructors. We have @x ~ N1 (... (Nk y))@ such that the +-- returned @y@ doesn't have a positive newtype constructor constraint +-- associated with it (yet). The 'VarInfo' returned is that of @y@'s +-- representative. +-- +-- Careful, this means that @idType x@ might be different to @idType y@, even +-- modulo type normalisation! +-- +-- See also Note [Coverage checking Newtype matches]. +lookupVarInfoNT :: TmState -> Id -> (Id, VarInfo) +lookupVarInfoNT ts x = case lookupVarInfo ts x of + VI{ vi_pos = as_newtype -> Just y } -> lookupVarInfoNT ts y + res -> (x, res) + where + as_newtype = listToMaybe . mapMaybe go + go (PmAltConLike (RealDataCon dc), _, [y]) + | isNewDataCon dc = Just y + go _ = Nothing + initPossibleMatches :: TyState -> VarInfo -> DsM VarInfo initPossibleMatches ty_st vi at VI{ vi_ty = ty, vi_cache = NoPM } = do -- New evidence might lead to refined info on ty, in turn leading to discovery @@ -669,13 +692,6 @@ initPossibleMatches ty_st vi at VI{ vi_ty = ty, vi_cache = NoPM } = do Just cs -> pure vi{ vi_ty = ty', vi_cache = PM (mkUniqDSet <$> cs) } initPossibleMatches _ vi = pure vi --- | @initLookupVarInfo ts x@ looks up the 'VarInfo' for @x@ in @ts@ and tries --- to initialise the 'vi_cache' component if it was 'NoPM' through --- 'initPossibleMatches'. -initLookupVarInfo :: Delta -> Id -> DsM VarInfo -initLookupVarInfo MkDelta{ delta_tm_st = ts, delta_ty_st = ty_st } x - = initPossibleMatches ty_st (lookupVarInfo ts x) - {- Note [COMPLETE sets on data families] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ User-defined COMPLETE sets involving data families are attached to the family @@ -720,22 +736,11 @@ TyCon, so tc_rep = tc_fam afterwards. -} ------------------------------------------------ --- * Exported utility functions querying 'Delta' +-- * Exported utility functions querying 'Nabla' --- | Check whether adding a constraint @x ~ BOT@ to 'Delta' succeeds. -canDiverge :: Delta -> Id -> Bool -canDiverge delta at MkDelta{ delta_tm_st = ts } x - | VI _ pos neg _ <- lookupVarInfo ts x - = isEmptyPmAltConSet neg && all pos_can_diverge pos - where - pos_can_diverge (PmAltConLike (RealDataCon dc), _, [y]) - -- See Note [Divergence of Newtype matches] - | isNewTyCon (dataConTyCon dc) = canDiverge delta y - pos_can_diverge _ = False - -{- Note [Divergence of Newtype matches] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Newtypes behave rather strangely when compared to ordinary DataCons. In a +{- Note [Coverage checking Newtype matches] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Newtypes have quite peculiar match semantics compared to ordinary DataCons. In a pattern-match, they behave like a irrefutable (lazy) match, but for inhabitation testing purposes (e.g. at construction sites), they behave rather like a DataCon with a *strict* field, because they don't contribute their own bottom and are @@ -750,19 +755,21 @@ This distinction becomes apparent in #17248: If we treat Newtypes like we treat regular DataCons, we would mark the third clause as redundant, which clearly is unsound. The solution: -1. When compiling the PmCon guard in 'pmCompileTree', don't add a @DivergeIf@, - because the match will never diverge. -2. Regard @T2 x@ as 'canDiverge' iff @x@ 'canDiverge'. E.g. @T2 x ~ _|_@ <=> - @x ~ _|_ at . This way, the third clause will still be marked as inaccessible - RHS instead of redundant. -3. When testing for inhabitants ('mkOneConFull'), we regard the newtype field as - strict, so that the newtype is inhabited iff its field is inhabited. +1. 'isPmAltConMatchStrict' returns False for newtypes, indicating that a + newtype match is lazy. +2. When we find @x ~ T2 y@, transfer all constraints on @x@ (which involve @⊥@) + to @y@, similar to what 'equate' does, and don't add a @x /~ ⊥@ constraint. + This way, the third clause will still be marked as inaccessible RHS instead + of redundant. This is ensured by calling 'lookupVarInfoNT'. +3. Immediately reject when we find @x /~ T2 at . +Handling of Newtypes is also described in the Appendix of the Lower Your Guards paper, +where you can find the solution in a perhaps more digestible format. -} -lookupRefuts :: Uniquable k => Delta -> k -> [PmAltCon] +lookupRefuts :: Uniquable k => Nabla -> k -> [PmAltCon] -- Unfortunately we need the extra bit of polymorphism and the unfortunate -- duplication of lookupVarInfo here. -lookupRefuts MkDelta{ delta_tm_st = ts@(TmSt (SDIE env) _) } k = +lookupRefuts MkNabla{ nabla_tm_st = ts@(TmSt (SDIE env) _) } k = case lookupUDFM_Directly env (getUnique k) of Nothing -> [] Just (Indirect y) -> pmAltConSetElems (vi_neg (lookupVarInfo ts y)) @@ -772,10 +779,10 @@ isDataConSolution :: (PmAltCon, [TyVar], [Id]) -> Bool isDataConSolution (PmAltConLike (RealDataCon _), _, _) = True isDataConSolution _ = False --- @lookupSolution delta x@ picks a single solution ('vi_pos') of @x@ from +-- @lookupSolution nabla x@ picks a single solution ('vi_pos') of @x@ from -- possibly many, preferring 'RealDataCon' solutions whenever possible. -lookupSolution :: Delta -> Id -> Maybe (PmAltCon, [TyVar], [Id]) -lookupSolution delta x = case vi_pos (lookupVarInfo (delta_tm_st delta) x) of +lookupSolution :: Nabla -> Id -> Maybe (PmAltCon, [TyVar], [Id]) +lookupSolution nabla x = case vi_pos (lookupVarInfo (nabla_tm_st nabla) x) of [] -> Nothing pos | Just sol <- find isDataConSolution pos -> Just sol @@ -842,13 +849,13 @@ instance Outputable PmCt where ppr (PmTyCt pred_ty) = ppr pred_ty ppr (PmTmCt tm_ct) = ppr tm_ct --- | Adds new constraints to 'Delta' and returns 'Nothing' if that leads to a +-- | Adds new constraints to 'Nabla' and returns 'Nothing' if that leads to a -- contradiction. -addPmCts :: Delta -> PmCts -> DsM (Maybe Delta) +addPmCts :: Nabla -> PmCts -> DsM (Maybe Nabla) -- See Note [TmState invariants]. -addPmCts delta cts = do +addPmCts nabla cts = do let (ty_cts, tm_cts) = partitionTyTmCts cts - runSatisfiabilityCheck delta $ mconcat + runSatisfiabilityCheck nabla $ mconcat [ tyIsSatisfiable True (listToBag ty_cts) , tmIsSatisfiable (listToBag tm_cts) ] @@ -861,44 +868,40 @@ partitionTyTmCts = partitionEithers . map to_either . toList -- | Adds a single term constraint by dispatching to the various term oracle -- functions. -addTmCt :: Delta -> TmCt -> MaybeT DsM Delta -addTmCt delta (TmVarCt x y) = addVarCt delta x y -addTmCt delta (TmCoreCt x e) = addCoreCt delta x e -addTmCt delta (TmConCt x con tvs args) = addConCt delta x con tvs args -addTmCt delta (TmNotConCt x con) = addNotConCt delta x con -addTmCt delta (TmBotCt x) = addBotCt delta x -addTmCt delta (TmNotBotCt x) = addNotBotCt delta x +addTmCt :: Nabla -> TmCt -> MaybeT DsM Nabla +addTmCt nabla (TmVarCt x y) = addVarCt nabla x y +addTmCt nabla (TmCoreCt x e) = addCoreCt nabla x e +addTmCt nabla (TmConCt x con tvs args) = addConCt nabla x con tvs args +addTmCt nabla (TmNotConCt x con) = addNotConCt nabla x con +addTmCt nabla (TmBotCt x) = addBotCt nabla x +addTmCt nabla (TmNotBotCt x) = addNotBotCt nabla x -- | Adds the constraint @x ~ ⊥@, e.g. that evaluation of a particular 'Id' @x@ --- surely diverges. --- --- Only that's a lie, because we don't currently preserve the fact in 'Delta' --- after we checked compatibility. See Note [Preserving TmBotCt] -addBotCt :: Delta -> Id -> MaybeT DsM Delta -addBotCt delta x - | canDiverge delta x = pure delta - | otherwise = mzero - -{- Note [Preserving TmBotCt] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Whenever we add a new constraint to 'Delta' via 'addTmCt', we want to check it -for compatibility with existing constraints in the modeled indert set and then -add it the constraint itself to the inert set. -For a 'TmBotCt' @x ~ ⊥@ we don't actually add it to the inert set after checking -it for compatibility with 'Delta'. -And that is fine in the context of the patter-match checking algorithm! -Whenever we add a 'TmBotCt' (we only do so for checking divergence of bang -patterns and strict constructor matches), we don't add any more constraints to -the inert set afterwards, so we don't need to preserve it. --} +-- surely diverges. Quite similar to 'addConCt', only that it only cares about +-- ⊥. +addBotCt :: Nabla -> Id -> MaybeT DsM Nabla +addBotCt nabla at MkNabla{ nabla_tm_st = TmSt env reps } x = do + let (y, vi at VI { vi_bot = bot }) = lookupVarInfoNT (nabla_tm_st nabla) x + case bot of + IsNotBot -> mzero -- There was x /~ ⊥. Contradiction! + IsBot -> pure nabla -- There already is x ~ ⊥. Nothing left to do + MaybeBot -> do -- We add x ~ ⊥ + let vi' = vi{ vi_bot = IsBot } + pure nabla{ nabla_tm_st = TmSt (setEntrySDIE env y vi') reps} -- | Record a @x ~/ K@ constraint, e.g. that a particular 'Id' @x@ can't --- take the shape of a 'PmAltCon' @K@ in the 'Delta' and return @Nothing@ if +-- take the shape of a 'PmAltCon' @K@ in the 'Nabla' and return @Nothing@ if -- that leads to a contradiction. -- See Note [TmState invariants]. -addNotConCt :: Delta -> Id -> PmAltCon -> MaybeT DsM Delta -addNotConCt delta at MkDelta{ delta_tm_st = TmSt env reps } x nalt = do - vi@(VI _ pos neg pm) <- lift (initLookupVarInfo delta x) +addNotConCt :: Nabla -> Id -> PmAltCon -> MaybeT DsM Nabla +addNotConCt _ _ (PmAltConLike (RealDataCon dc)) + | isNewDataCon dc = mzero -- (3) in Note [Coverage checking Newtype matches] +addNotConCt nabla at MkNabla{ nabla_tm_st = ts@(TmSt env reps) } x nalt = do + -- For good performance, it's important to initPossibleMatches here. + -- Otherwise we can't mark nalt as matched later on, incurring unnecessary + -- inhabitation tests for nalt. + vi@(VI _ pos neg _ pm) <- lift $ initPossibleMatches (nabla_ty_st nabla) + (lookupVarInfo ts x) -- 1. Bail out quickly when nalt contradicts a solution let contradicts nalt (cl, _tvs, _args) = eqPmAltCon cl nalt == Equal guard (not (any (contradicts nalt) pos)) @@ -910,13 +913,14 @@ addNotConCt delta at MkDelta{ delta_tm_st = TmSt env reps } x nalt = do -- See Note [Completeness checking with required Thetas] | hasRequiredTheta nalt = neg | otherwise = extendPmAltConSet neg nalt - let vi_ext = vi{ vi_neg = neg' } + MASSERT( isPmAltConMatchStrict nalt ) + let vi1 = vi{ vi_neg = neg', vi_bot = IsNotBot } -- 3. Make sure there's at least one other possible constructor - vi' <- case nalt of + vi2 <- case nalt of PmAltConLike cl - -> MaybeT (ensureInhabited delta vi_ext{ vi_cache = markMatched cl pm }) - _ -> pure vi_ext - pure delta{ delta_tm_st = TmSt (setEntrySDIE env x vi') reps } + -> ensureInhabited nabla vi1{ vi_cache = markMatched cl pm } + _ -> pure vi1 + pure nabla{ nabla_tm_st = TmSt (setEntrySDIE env x vi2) reps } hasRequiredTheta :: PmAltCon -> Bool hasRequiredTheta (PmAltConLike cl) = notNull req_theta @@ -979,100 +983,104 @@ guessConLikeUnivTyArgsFromResTy _ res_ty (PatSynCon ps) = do subst <- tcMatchTy con_res_ty res_ty traverse (lookupTyVar subst) univ_tvs --- | Adds the constraint @x ~/ ⊥@ to 'Delta'. +-- | Adds the constraint @x ~/ ⊥@ to 'Nabla'. Quite similar to 'addNotConCt', +-- but only cares for the ⊥ "constructor". +addNotBotCt :: Nabla -> Id -> MaybeT DsM Nabla +addNotBotCt nabla at MkNabla{ nabla_tm_st = TmSt env reps } x = do + let (y, vi at VI { vi_bot = bot }) = lookupVarInfoNT (nabla_tm_st nabla) x + case bot of + IsBot -> mzero -- There was x ~ ⊥. Contradiction! + IsNotBot -> pure nabla -- There already is x /~ ⊥. Nothing left to do + MaybeBot -> do -- We add x /~ ⊥ and test if x is still inhabited + vi <- ensureInhabited nabla vi{ vi_bot = IsNotBot } + pure nabla{ nabla_tm_st = TmSt (setEntrySDIE env y vi) reps} + +-- | Returns (Just vi) if at least one member of each ConLike in the COMPLETE +-- set satisfies the oracle +-- +-- Internally uses and updates the ConLikeSets in vi_cache. -- --- But doesn't really commit to upholding that constraint in the future. This --- will be rectified in a follow-up patch. The status quo should work good --- enough for now. -addNotBotCt :: Delta -> Id -> MaybeT DsM Delta -addNotBotCt delta at MkDelta{ delta_tm_st = TmSt env reps } x = do - vi <- lift $ initLookupVarInfo delta x - vi' <- MaybeT $ ensureInhabited delta vi - -- vi' has probably constructed and then thinned out some PossibleMatches. - -- We want to cache that work - pure delta{ delta_tm_st = TmSt (setEntrySDIE env x vi') reps} - -ensureInhabited :: Delta -> VarInfo -> DsM (Maybe VarInfo) - -- Returns (Just vi) if at least one member of each ConLike in the COMPLETE - -- set satisfies the oracle - -- - -- Internally uses and updates the ConLikeSets in vi_cache. - -- - -- NB: Does /not/ filter each ConLikeSet with the oracle; members may - -- remain that do not statisfy it. This lazy approach just - -- avoids doing unnecessary work. -ensureInhabited delta vi = fmap (set_cache vi) <$> test (vi_cache vi) -- This would be much less tedious with lenses +-- NB: Does /not/ filter each ConLikeSet with the oracle; members may +-- remain that do not statisfy it. This lazy approach just +-- avoids doing unnecessary work. +ensureInhabited :: Nabla -> VarInfo -> MaybeT DsM VarInfo +ensureInhabited nabla vi = case vi_bot vi of + MaybeBot -> pure vi -- The |-Bot rule from the paper + IsBot -> pure vi + IsNotBot -> lift (initPossibleMatches (nabla_ty_st nabla) vi) >>= inst_complete_sets where - set_cache vi cache = vi { vi_cache = cache } - - test NoPM = pure (Just NoPM) - test (PM ms) = runMaybeT (PM <$> traverse one_set ms) - - one_set cs = find_one_inh cs (uniqDSetToList cs) - - find_one_inh :: ConLikeSet -> [ConLike] -> MaybeT DsM ConLikeSet - -- (find_one_inh cs cls) iterates over cls, deleting from cs + -- | This is the |-Inst rule from the paper (section 4.5). Tries to + -- find an inhabitant in every complete set by instantiating with one their + -- constructors. If there is any complete set where we can't find an + -- inhabitant, the whole thing is uninhabited. + inst_complete_sets :: VarInfo -> MaybeT DsM VarInfo + inst_complete_sets vi at VI{ vi_cache = NoPM } = pure vi + inst_complete_sets vi at VI{ vi_cache = PM ms } = do + ms <- traverse (\cs -> inst_complete_set vi cs (uniqDSetToList cs)) ms + pure vi{ vi_cache = PM ms } + + inst_complete_set :: VarInfo -> ConLikeSet -> [ConLike] -> MaybeT DsM ConLikeSet + -- (inst_complete_set cs cls) iterates over cls, deleting from cs -- any uninhabited elements of cls. Stop (returning Just cs) -- when you see an inhabited element; return Nothing if all -- are uninhabited - find_one_inh _ [] = mzero - find_one_inh cs (con:cons) = lift (inh_test con) >>= \case + inst_complete_set _ _ [] = mzero + inst_complete_set vi cs (con:cons) = lift (inst_and_test vi con) >>= \case True -> pure cs - False -> find_one_inh (delOneFromUniqDSet cs con) cons + False -> inst_complete_set vi (delOneFromUniqDSet cs con) cons - inh_test :: ConLike -> DsM Bool - -- @inh_test K@ Returns False if a non-bottom value @v::ty@ cannot possibly + inst_and_test :: VarInfo -> ConLike -> DsM Bool + -- @inst_and_test K@ Returns False if a non-bottom value @v::ty@ cannot possibly -- be of form @K _ _ _ at . Returning True is always sound. -- -- It's like 'DataCon.dataConCannotMatch', but more clever because it takes - -- the facts in Delta into account. - inh_test con = do + -- the facts in Nabla into account. + inst_and_test vi con = do env <- dsGetFamInstEnvs case guessConLikeUnivTyArgsFromResTy env (vi_ty vi) con of Nothing -> pure True -- be conservative about this Just arg_tys -> do (_tvs, _vars, ty_cs, strict_arg_tys) <- mkOneConFull arg_tys con - tracePm "inh_test" (ppr con $$ ppr ty_cs) + tracePm "inst_and_test" (ppr con $$ ppr ty_cs) -- No need to run the term oracle compared to pmIsSatisfiable - fmap isJust <$> runSatisfiabilityCheck delta $ mconcat + fmap isJust <$> runSatisfiabilityCheck nabla $ mconcat -- Important to pass False to tyIsSatisfiable here, so that we won't - -- recursively call ensureAllPossibleMatchesInhabited, leading to an + -- recursively call ensureAllInhabited, leading to an -- endless recursion. [ tyIsSatisfiable False ty_cs , tysAreNonVoid initRecTc strict_arg_tys ] -- | Checks if every 'VarInfo' in the term oracle has still an inhabited --- 'vi_cache', considering the current type information in 'Delta'. +-- 'vi_cache', considering the current type information in 'Nabla'. -- This check is necessary after having matched on a GADT con to weed out -- impossible matches. -ensureAllPossibleMatchesInhabited :: Delta -> DsM (Maybe Delta) -ensureAllPossibleMatchesInhabited delta at MkDelta{ delta_tm_st = TmSt env reps } - = runMaybeT (set_tm_cs_env delta <$> traverseSDIE go env) +ensureAllInhabited :: Nabla -> DsM (Maybe Nabla) +ensureAllInhabited nabla at MkNabla{ nabla_tm_st = TmSt env reps } + = runMaybeT (set_tm_cs_env nabla <$> traverseSDIE go env) where - set_tm_cs_env delta env = delta{ delta_tm_st = TmSt env reps } - go vi = MaybeT $ - initPossibleMatches (delta_ty_st delta) vi >>= ensureInhabited delta + set_tm_cs_env nabla env = nabla{ nabla_tm_st = TmSt env reps } + go vi = ensureInhabited nabla vi -------------------------------------- -- * Term oracle unification procedure -- | Adds a @x ~ y@ constraint by trying to unify two 'Id's and record the --- gained knowledge in 'Delta'. +-- gained knowledge in 'Nabla'. -- --- Returns @Nothing@ when there's a contradiction. Returns @Just delta@ --- when the constraint was compatible with prior facts, in which case @delta@ +-- Returns @Nothing@ when there's a contradiction. Returns @Just nabla@ +-- when the constraint was compatible with prior facts, in which case @nabla@ -- has integrated the knowledge from the equality constraint. -- -- See Note [TmState invariants]. -addVarCt :: Delta -> Id -> Id -> MaybeT DsM Delta -addVarCt delta at MkDelta{ delta_tm_st = TmSt env _ } x y +addVarCt :: Nabla -> Id -> Id -> MaybeT DsM Nabla +addVarCt nabla at MkNabla{ nabla_tm_st = TmSt env _ } x y -- It's important that we never @equate@ two variables of the same equivalence -- class, otherwise we might get cyclic substitutions. -- Cf. 'extendSubstAndSolve' and -- @testsuite/tests/pmcheck/should_compile/CyclicSubst.hs at . - | sameRepresentativeSDIE env x y = pure delta - | otherwise = equate delta x y + | sameRepresentativeSDIE env x y = pure nabla + | otherwise = equate nabla x y -- | @equate ts@(TmSt env) x y@ merges the equivalence classes of @x@ and @y@ by -- adding an indirection to the environment. @@ -1081,12 +1089,12 @@ addVarCt delta at MkDelta{ delta_tm_st = TmSt env _ } x y -- Preconditions: @not (sameRepresentativeSDIE env x y)@ -- -- See Note [TmState invariants]. -equate :: Delta -> Id -> Id -> MaybeT DsM Delta -equate delta at MkDelta{ delta_tm_st = TmSt env reps } x y +equate :: Nabla -> Id -> Id -> MaybeT DsM Nabla +equate nabla at MkNabla{ nabla_tm_st = TmSt env reps } x y = ASSERT( not (sameRepresentativeSDIE env x y) ) case (lookupSDIE env x, lookupSDIE env y) of - (Nothing, _) -> pure (delta{ delta_tm_st = TmSt (setIndirectSDIE env x y) reps }) - (_, Nothing) -> pure (delta{ delta_tm_st = TmSt (setIndirectSDIE env y x) reps }) + (Nothing, _) -> pure (nabla{ nabla_tm_st = TmSt (setIndirectSDIE env x y) reps }) + (_, Nothing) -> pure (nabla{ nabla_tm_st = TmSt (setIndirectSDIE env y x) reps }) -- Merge the info we have for x into the info for y (Just vi_x, Just vi_y) -> do -- This assert will probably trigger at some point... @@ -1096,16 +1104,16 @@ equate delta at MkDelta{ delta_tm_st = TmSt env reps } x y let env_ind = setIndirectSDIE env x y -- Then sum up the refinement counters let env_refs = setEntrySDIE env_ind y vi_y - let delta_refs = delta{ delta_tm_st = TmSt env_refs reps } + let nabla_refs = nabla{ nabla_tm_st = TmSt env_refs reps } -- and then gradually merge every positive fact we have on x into y - let add_fact delta (cl, tvs, args) = addConCt delta y cl tvs args - delta_pos <- foldlM add_fact delta_refs (vi_pos vi_x) + let add_fact nabla (cl, tvs, args) = addConCt nabla y cl tvs args + nabla_pos <- foldlM add_fact nabla_refs (vi_pos vi_x) -- Do the same for negative info - let add_refut delta nalt = addNotConCt delta y nalt - delta_neg <- foldlM add_refut delta_pos (pmAltConSetElems (vi_neg vi_x)) + let add_refut nabla nalt = addNotConCt nabla y nalt + nabla_neg <- foldlM add_refut nabla_pos (pmAltConSetElems (vi_neg vi_x)) -- vi_cache will be updated in addNotConCt, so we are good to -- go! - pure delta_neg + pure nabla_neg -- | Add a @x ~ K tvs args ts@ constraint. -- @addConCt x K tvs args ts@ extends the substitution with a solution @@ -1113,9 +1121,9 @@ equate delta at MkDelta{ delta_tm_st = TmSt env reps } x y -- have on @x@, reject (@Nothing@) otherwise. -- -- See Note [TmState invariants]. -addConCt :: Delta -> Id -> PmAltCon -> [TyVar] -> [Id] -> MaybeT DsM Delta -addConCt delta at MkDelta{ delta_tm_st = TmSt env reps } x alt tvs args = do - VI ty pos neg cache <- lift (initLookupVarInfo delta x) +addConCt :: Nabla -> Id -> PmAltCon -> [TyVar] -> [Id] -> MaybeT DsM Nabla +addConCt nabla at MkNabla{ nabla_tm_st = ts@(TmSt env reps) } x alt tvs args = do + let VI ty pos neg bot cache = lookupVarInfo ts x -- First try to refute with a negative fact guard (not (elemPmAltConSet alt neg)) -- Then see if any of the other solutions (remember: each of them is an @@ -1131,10 +1139,19 @@ addConCt delta at MkDelta{ delta_tm_st = TmSt env reps } x alt tvs args = do when (length args /= length other_args) $ lift $ tracePm "error" (ppr x <+> ppr alt <+> ppr args <+> ppr other_args) let tm_cts = zipWithEqual "addConCt" PmVarCt args other_args - MaybeT $ addPmCts delta (listToBag ty_cts `unionBags` listToBag tm_cts) + MaybeT $ addPmCts nabla (listToBag ty_cts `unionBags` listToBag tm_cts) Nothing -> do let pos' = (alt, tvs, args):pos - pure delta{ delta_tm_st = TmSt (setEntrySDIE env x (VI ty pos' neg cache)) reps} + let nabla_with bot = nabla{ nabla_tm_st = TmSt (setEntrySDIE env x (VI ty pos' neg bot cache)) reps} + -- Do (2) in Note [Coverage checking Newtype matches] + case (alt, args) of + (PmAltConLike (RealDataCon dc), [y]) | isNewDataCon dc -> + case bot of + MaybeBot -> pure (nabla_with MaybeBot) + IsBot -> addBotCt (nabla_with MaybeBot) y + IsNotBot -> addNotBotCt (nabla_with MaybeBot) y + _ -> ASSERT( isPmAltConMatchStrict alt ) + pure (nabla_with IsNotBot) -- strict match ==> not ⊥ equateTys :: [Type] -> [Type] -> [PmCt] equateTys ts us = @@ -1183,9 +1200,9 @@ mkInhabitationCandidate x dc = do -- if it can. In this case, the candidates are the signature of the tycon, each -- one accompanied by the term- and type- constraints it gives rise to. -- See also Note [Checking EmptyCase Expressions] -inhabitationCandidates :: Delta -> Type +inhabitationCandidates :: Nabla -> Type -> DsM (Either Type (TyCon, Id, [InhabitationCandidate])) -inhabitationCandidates MkDelta{ delta_ty_st = ty_st } ty = do +inhabitationCandidates MkNabla{ nabla_ty_st = ty_st } ty = do pmTopNormaliseType ty_st ty >>= \case NoChange _ -> alts_to_check ty ty [] NormalisedByConstraints ty' -> alts_to_check ty' ty' [] @@ -1281,20 +1298,20 @@ we do the following: -- | A 'SatisfiabilityCheck' based on "NonVoid ty" constraints, e.g. Will -- check if the @strict_arg_tys@ are actually all inhabited. --- Returns the old 'Delta' if all the types are non-void according to 'Delta'. +-- Returns the old 'Nabla' if all the types are non-void according to 'Nabla'. tysAreNonVoid :: RecTcChecker -> [Type] -> SatisfiabilityCheck -tysAreNonVoid rec_env strict_arg_tys = SC $ \delta -> do - all_non_void <- checkAllNonVoid rec_env delta strict_arg_tys +tysAreNonVoid rec_env strict_arg_tys = SC $ \nabla -> do + all_non_void <- checkAllNonVoid rec_env nabla strict_arg_tys -- Check if each strict argument type is inhabitable pure $ if all_non_void - then Just delta + then Just nabla else Nothing -- | Implements two performance optimizations, as described in -- @Note [Strict argument type constraints]@. -checkAllNonVoid :: RecTcChecker -> Delta -> [Type] -> DsM Bool +checkAllNonVoid :: RecTcChecker -> Nabla -> [Type] -> DsM Bool checkAllNonVoid rec_ts amb_cs strict_arg_tys = do - let definitely_inhabited = definitelyInhabitedType (delta_ty_st amb_cs) + let definitely_inhabited = definitelyInhabitedType (nabla_ty_st amb_cs) tys_to_check <- filterOutM definitely_inhabited strict_arg_tys -- See Note [Fuel for the inhabitation test] let rec_max_bound | tys_to_check `lengthExceeds` 1 @@ -1309,7 +1326,7 @@ checkAllNonVoid rec_ts amb_cs strict_arg_tys = do -- See @Note [Strict argument type constraints]@. nonVoid :: RecTcChecker -- ^ The per-'TyCon' recursion depth limit. - -> Delta -- ^ The ambient term/type constraints (known to be + -> Nabla -- ^ The ambient term/type constraints (known to be -- satisfiable). -> Type -- ^ The strict argument type. -> DsM Bool -- ^ 'True' if the strict argument type might be inhabited by @@ -1337,7 +1354,7 @@ nonVoid rec_ts amb_cs strict_arg_ty = do -- check if recursion is detected). -- -- See Note [Strict argument type constraints] - cand_is_inhabitable :: RecTcChecker -> Delta + cand_is_inhabitable :: RecTcChecker -> Nabla -> InhabitationCandidate -> DsM Bool cand_is_inhabitable rec_ts amb_cs (InhabitationCandidate{ ic_cs = new_cs @@ -1516,21 +1533,21 @@ on a list of strict argument types, we filter out all of the DI ones. -} -------------------------------------------- --- * Providing positive evidence for a Delta +-- * Providing positive evidence for a Nabla --- | @provideEvidence vs n delta@ returns a list of --- at most @n@ (but perhaps empty) refinements of @delta@ that instantiate +-- | @provideEvidence vs n nabla@ returns a list of +-- at most @n@ (but perhaps empty) refinements of @nabla@ that instantiate -- @vs@ to compatible constructor applications or wildcards. -- Negative information is only retained if literals are involved or when -- for recursive GADTs. -provideEvidence :: [Id] -> Int -> Delta -> DsM [Delta] +provideEvidence :: [Id] -> Int -> Nabla -> DsM [Nabla] provideEvidence = go where go _ 0 _ = pure [] - go [] _ delta = pure [delta] - go (x:xs) n delta = do - tracePm "provideEvidence" (ppr x $$ ppr xs $$ ppr delta $$ ppr n) - VI _ pos neg _ <- initLookupVarInfo delta x + go [] _ nabla = pure [nabla] + go (x:xs) n nabla = do + tracePm "provideEvidence" (ppr x $$ ppr xs $$ ppr nabla $$ ppr n) + let VI _ pos neg _ _ = lookupVarInfo (nabla_tm_st nabla) x case pos of _:_ -> do -- All solutions must be valid at once. Try to find candidates for their @@ -1543,56 +1560,57 @@ provideEvidence = go -- some @y@ and @SomePatSyn z@ for some @z at . We must find evidence for @y@ -- and @z@ that is valid at the same time. These constitute arg_vas below. let arg_vas = concatMap (\(_cl, _tvs, args) -> args) pos - go (arg_vas ++ xs) n delta + go (arg_vas ++ xs) n nabla [] -- When there are literals involved, just print negative info -- instead of listing missed constructors | notNull [ l | PmAltLit l <- pmAltConSetElems neg ] - -> go xs n delta - [] -> try_instantiate x xs n delta + -> go xs n nabla + [] -> try_instantiate x xs n nabla -- | Tries to instantiate a variable by possibly following the chain of -- newtypes and then instantiating to all ConLikes of the wrapped type's -- minimal residual COMPLETE set. - try_instantiate :: Id -> [Id] -> Int -> Delta -> DsM [Delta] + try_instantiate :: Id -> [Id] -> Int -> Nabla -> DsM [Nabla] -- Convention: x binds the outer constructor in the chain, y the inner one. - try_instantiate x xs n delta = do - (_src_ty, dcs, core_ty) <- tntrGuts <$> pmTopNormaliseType (delta_ty_st delta) (idType x) - let build_newtype (x, delta) (_ty, dc, arg_ty) = do + try_instantiate x xs n nabla = do + (_src_ty, dcs, core_ty) <- tntrGuts <$> pmTopNormaliseType (nabla_ty_st nabla) (idType x) + let build_newtype (x, nabla) (_ty, dc, arg_ty) = do y <- lift $ mkPmId arg_ty -- Newtypes don't have existentials (yet?!), so passing an empty -- list as ex_tvs. - delta' <- addConCt delta x (PmAltConLike (RealDataCon dc)) [] [y] - pure (y, delta') - runMaybeT (foldlM build_newtype (x, delta) dcs) >>= \case + nabla' <- addConCt nabla x (PmAltConLike (RealDataCon dc)) [] [y] + pure (y, nabla') + runMaybeT (foldlM build_newtype (x, nabla) dcs) >>= \case Nothing -> pure [] - Just (y, newty_delta) -> do + Just (y, newty_nabla) -> do -- Pick a COMPLETE set and instantiate it (n at max). Take care of ⊥. - pm <- vi_cache <$> initLookupVarInfo newty_delta y - mb_cls <- pickMinimalCompleteSet newty_delta pm + let vi = lookupVarInfo (nabla_tm_st newty_nabla) y + vi <- initPossibleMatches (nabla_ty_st newty_nabla) vi + mb_cls <- pickMinimalCompleteSet newty_nabla (vi_cache vi) case uniqDSetToList <$> mb_cls of - Just cls@(_:_) -> instantiate_cons y core_ty xs n newty_delta cls - Just [] | not (canDiverge newty_delta y) -> pure [] + Just cls@(_:_) -> instantiate_cons y core_ty xs n newty_nabla cls + Just [] | vi_bot vi == IsNotBot -> pure [] -- Either ⊥ is still possible (think Void) or there are no COMPLETE -- sets available, so we can assume it's inhabited - _ -> go xs n newty_delta + _ -> go xs n newty_nabla - instantiate_cons :: Id -> Type -> [Id] -> Int -> Delta -> [ConLike] -> DsM [Delta] + instantiate_cons :: Id -> Type -> [Id] -> Int -> Nabla -> [ConLike] -> DsM [Nabla] instantiate_cons _ _ _ _ _ [] = pure [] instantiate_cons _ _ _ 0 _ _ = pure [] - instantiate_cons _ ty xs n delta _ + instantiate_cons _ ty xs n nabla _ -- We don't want to expose users to GHC-specific constructors for Int etc. | fmap (isTyConTriviallyInhabited . fst) (splitTyConApp_maybe ty) == Just True - = go xs n delta - instantiate_cons x ty xs n delta (cl:cls) = do + = go xs n nabla + instantiate_cons x ty xs n nabla (cl:cls) = do env <- dsGetFamInstEnvs case guessConLikeUnivTyArgsFromResTy env ty cl of - Nothing -> pure [delta] -- No idea how to refine this one, so just finish off with a wildcard + Nothing -> pure [nabla] -- No idea how to refine this one, so just finish off with a wildcard Just arg_tys -> do (tvs, arg_vars, new_ty_cs, strict_arg_tys) <- mkOneConFull arg_tys cl let new_tm_cs = unitBag (TmConCt x (PmAltConLike cl) tvs arg_vars) -- Now check satifiability - mb_delta <- pmIsSatisfiable delta new_ty_cs new_tm_cs strict_arg_tys + mb_nabla <- pmIsSatisfiable nabla new_ty_cs new_tm_cs strict_arg_tys tracePm "instantiate_cons" (vcat [ ppr x , ppr (idType x) , ppr ty @@ -1601,21 +1619,21 @@ provideEvidence = go , ppr new_tm_cs , ppr new_ty_cs , ppr strict_arg_tys - , ppr delta - , ppr mb_delta + , ppr nabla + , ppr mb_nabla , ppr n ]) - con_deltas <- case mb_delta of + con_nablas <- case mb_nabla of Nothing -> pure [] -- NB: We don't prepend arg_vars as we don't have any evidence on -- them and we only want to split once on a data type. They are -- inhabited, otherwise pmIsSatisfiable would have refuted. - Just delta' -> go xs n delta' - other_cons_deltas <- instantiate_cons x ty xs (n - length con_deltas) delta cls - pure (con_deltas ++ other_cons_deltas) + Just nabla' -> go xs n nabla' + other_cons_nablas <- instantiate_cons x ty xs (n - length con_nablas) nabla cls + pure (con_nablas ++ other_cons_nablas) -pickMinimalCompleteSet :: Delta -> PossibleMatches -> DsM (Maybe ConLikeSet) +pickMinimalCompleteSet :: Nabla -> PossibleMatches -> DsM (Maybe ConLikeSet) pickMinimalCompleteSet _ NoPM = pure Nothing --- TODO: First prune sets with type info in delta. But this is good enough for +-- TODO: First prune sets with type info in nabla. But this is good enough for -- now and less costly. See #17386. pickMinimalCompleteSet _ (PM clss) = do tracePm "pickMinimalCompleteSet" (ppr $ NonEmpty.toList clss) @@ -1625,14 +1643,14 @@ pickMinimalCompleteSet _ (PM clss) = do -- Which is the @x@ of a @let x = e'@ constraint (with @e@ semantically -- equivalent to @e'@) we encountered earlier, or a fresh identifier if -- there weren't any such constraints. -representCoreExpr :: Delta -> CoreExpr -> DsM (Delta, Id) -representCoreExpr delta at MkDelta{ delta_tm_st = ts at TmSt{ ts_reps = reps } } e - | Just rep <- lookupCoreMap reps e = pure (delta, rep) +representCoreExpr :: Nabla -> CoreExpr -> DsM (Nabla, Id) +representCoreExpr nabla at MkNabla{ nabla_tm_st = ts at TmSt{ ts_reps = reps } } e + | Just rep <- lookupCoreMap reps e = pure (nabla, rep) | otherwise = do rep <- mkPmId (exprType e) let reps' = extendCoreMap reps e rep - let delta' = delta{ delta_tm_st = ts{ ts_reps = reps' } } - pure (delta', rep) + let nabla' = nabla{ nabla_tm_st = ts{ ts_reps = reps' } } + pure (nabla', rep) -- | Inspects a 'PmCoreCt' @let x = e@ by recording constraints for @x@ based -- on the shape of the 'CoreExpr' @e at . Examples: @@ -1646,16 +1664,16 @@ representCoreExpr delta at MkDelta{ delta_tm_st = ts at TmSt{ ts_reps = reps } } e -- for other literals. See 'coreExprAsPmLit'. -- * Finally, if we have @let x = e@ and we already have seen @let y = e@, we -- want to record @x ~ y at . -addCoreCt :: Delta -> Id -> CoreExpr -> MaybeT DsM Delta -addCoreCt delta x e = do +addCoreCt :: Nabla -> Id -> CoreExpr -> MaybeT DsM Nabla +addCoreCt nabla x e = do dflags <- getDynFlags let e' = simpleOptExpr dflags e - lift $ tracePm "addCoreCt" (ppr x <+> dcolon <+> ppr (idType x) $$ ppr e $$ ppr e') - execStateT (core_expr x e') delta + -- lift $ tracePm "addCoreCt" (ppr x <+> dcolon <+> ppr (idType x) $$ ppr e $$ ppr e') + execStateT (core_expr x e') nabla where -- | Takes apart a 'CoreExpr' and tries to extract as much information about -- literals and constructor applications as possible. - core_expr :: Id -> CoreExpr -> StateT Delta (MaybeT DsM) () + core_expr :: Id -> CoreExpr -> StateT Nabla (MaybeT DsM) () -- TODO: Handle newtypes properly, by wrapping the expression in a DataCon -- This is the right thing for casts involving data family instances and -- their representation TyCon, though (which are not visible in source @@ -1680,7 +1698,7 @@ addCoreCt delta x e = do -- See Note [Detecting pattern synonym applications in expressions] | Var y <- e, Nothing <- isDataConId_maybe x -- We don't consider DataCons flexible variables - = modifyT (\delta -> addVarCt delta x y) + = modifyT (\nabla -> addVarCt nabla x y) | otherwise -- Any other expression. Try to find other uses of a semantically -- equivalent expression and represent them by the same variable! @@ -1698,13 +1716,13 @@ addCoreCt delta x e = do -- see if we already encountered a constraint @let y = e'@ with @e'@ -- semantically equivalent to @e@, in which case we may add the constraint -- @x ~ y at . - equate_with_similar_expr :: Id -> CoreExpr -> StateT Delta (MaybeT DsM) () + equate_with_similar_expr :: Id -> CoreExpr -> StateT Nabla (MaybeT DsM) () equate_with_similar_expr x e = do - rep <- StateT $ \delta -> swap <$> lift (representCoreExpr delta e) + rep <- StateT $ \nabla -> swap <$> lift (representCoreExpr nabla e) -- Note that @rep == x@ if we encountered @e@ for the first time. - modifyT (\delta -> addVarCt delta x rep) + modifyT (\nabla -> addVarCt nabla x rep) - bind_expr :: CoreExpr -> StateT Delta (MaybeT DsM) Id + bind_expr :: CoreExpr -> StateT Nabla (MaybeT DsM) Id bind_expr e = do x <- lift (lift (mkPmId (exprType e))) core_expr x e @@ -1712,10 +1730,12 @@ addCoreCt delta x e = do -- | Look at @let x = K taus theta es@ and generate the following -- constraints (assuming universals were dropped from @taus@ before): - -- 1. @a_1 ~ tau_1, ..., a_n ~ tau_n@ for fresh @a_i@ - -- 2. @y_1 ~ e_1, ..., y_m ~ e_m@ for fresh @y_i@ - -- 3. @x ~ K as ys@ - data_con_app :: Id -> InScopeSet -> DataCon -> [CoreExpr] -> StateT Delta (MaybeT DsM) () + -- 1. @x /~ ⊥@ if 'K' is not a Newtype constructor. + -- 2. @a_1 ~ tau_1, ..., a_n ~ tau_n@ for fresh @a_i@ + -- 3. @y_1 ~ e_1, ..., y_m ~ e_m@ for fresh @y_i@ + -- 4. @x ~ K as ys@ + -- This is quite similar to PmCheck.pmConCts. + data_con_app :: Id -> InScopeSet -> DataCon -> [CoreExpr] -> StateT Nabla (MaybeT DsM) () data_con_app x in_scope dc args = do let dc_ex_tvs = dataConExTyCoVars dc arty = dataConSourceArity dc @@ -1725,20 +1745,27 @@ addCoreCt delta x e = do uniq_supply <- lift $ lift $ getUniqueSupplyM let (_, ex_tvs) = cloneTyVarBndrs (mkEmptyTCvSubst in_scope) dc_ex_tvs uniq_supply ty_cts = equateTys (map mkTyVarTy ex_tvs) ex_tys - -- 1. @a_1 ~ tau_1, ..., a_n ~ tau_n@ for fresh @a_i at . See also #17703 - modifyT $ \delta -> MaybeT $ addPmCts delta (listToBag ty_cts) - -- 2. @y_1 ~ e_1, ..., y_m ~ e_m@ for fresh @y_i@ + -- 1. @x /~ ⊥@ if 'K' is not a Newtype constructor (#18341) + when (not (isNewDataCon dc)) $ + modifyT $ \nabla -> addNotBotCt nabla x + -- 2. @a_1 ~ tau_1, ..., a_n ~ tau_n@ for fresh @a_i at . See also #17703 + modifyT $ \nabla -> MaybeT $ addPmCts nabla (listToBag ty_cts) + -- 3. @y_1 ~ e_1, ..., y_m ~ e_m@ for fresh @y_i@ arg_ids <- traverse bind_expr vis_args - -- 3. @x ~ K as ys@ + -- 4. @x ~ K as ys@ pm_alt_con_app x (PmAltConLike (RealDataCon dc)) ex_tvs arg_ids -- | Adds a literal constraint, i.e. @x ~ 42 at . - pm_lit :: Id -> PmLit -> StateT Delta (MaybeT DsM) () - pm_lit x lit = pm_alt_con_app x (PmAltLit lit) [] [] + -- Also we assume that literal expressions won't diverge, so this + -- will add a @x ~/ ⊥@ constraint. + pm_lit :: Id -> PmLit -> StateT Nabla (MaybeT DsM) () + pm_lit x lit = do + modifyT $ \nabla -> addNotBotCt nabla x + pm_alt_con_app x (PmAltLit lit) [] [] -- | Adds the given constructor application as a solution for @x at . - pm_alt_con_app :: Id -> PmAltCon -> [TyVar] -> [Id] -> StateT Delta (MaybeT DsM) () - pm_alt_con_app x con tvs args = modifyT $ \delta -> addConCt delta x con tvs args + pm_alt_con_app :: Id -> PmAltCon -> [TyVar] -> [Id] -> StateT Nabla (MaybeT DsM) () + pm_alt_con_app x con tvs args = modifyT $ \nabla -> addConCt nabla x con tvs args -- | Like 'modify', but with an effectful modifier action modifyT :: Monad m => (s -> m s) -> StateT s m () ===================================== compiler/GHC/HsToCore/PmCheck/Ppr.hs ===================================== @@ -2,7 +2,7 @@ {-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} --- | Provides factilities for pretty-printing 'Delta's in a way appropriate for +-- | Provides factilities for pretty-printing 'Nabla's in a way appropriate for -- user facing pattern match warnings. module GHC.HsToCore.PmCheck.Ppr ( pprUncovered @@ -42,8 +42,8 @@ import GHC.HsToCore.PmCheck.Oracle -- -- When the set of refutable shapes contains more than 3 elements, the -- additional elements are indicated by "...". -pprUncovered :: Delta -> [Id] -> SDoc -pprUncovered delta vas +pprUncovered :: Nabla -> [Id] -> SDoc +pprUncovered nabla vas | isNullUDFM refuts = fsep vec -- there are no refutations | otherwise = hang (fsep vec) 4 $ text "where" <+> vcat (map (pprRefutableShapes . snd) (udfmToList refuts)) @@ -54,8 +54,8 @@ pprUncovered delta vas | [_] <- vas = topPrec | otherwise = appPrec ppr_action = mapM (pprPmVar init_prec) vas - (vec, renamings) = runPmPpr delta ppr_action - refuts = prettifyRefuts delta renamings + (vec, renamings) = runPmPpr nabla ppr_action + refuts = prettifyRefuts nabla renamings -- | Output refutable shapes of a variable in the form of @var is not one of {2, -- Nothing, 3}@. Will never print more than 3 refutable shapes, the tail is @@ -98,21 +98,21 @@ substitution to the vectors before printing them out (see function `pprOne' in -- | Extract and assigns pretty names to constraint variables with refutable -- shapes. -prettifyRefuts :: Delta -> DIdEnv SDoc -> DIdEnv (SDoc, [PmAltCon]) -prettifyRefuts delta = listToUDFM_Directly . map attach_refuts . udfmToList +prettifyRefuts :: Nabla -> DIdEnv SDoc -> DIdEnv (SDoc, [PmAltCon]) +prettifyRefuts nabla = listToUDFM_Directly . map attach_refuts . udfmToList where - attach_refuts (u, sdoc) = (u, (sdoc, lookupRefuts delta u)) + attach_refuts (u, sdoc) = (u, (sdoc, lookupRefuts nabla u)) -type PmPprM a = RWS Delta () (DIdEnv SDoc, [SDoc]) a +type PmPprM a = RWS Nabla () (DIdEnv SDoc, [SDoc]) a -- Try nice names p,q,r,s,t before using the (ugly) t_i nameList :: [SDoc] nameList = map text ["p","q","r","s","t"] ++ [ text ('t':show u) | u <- [(0 :: Int)..] ] -runPmPpr :: Delta -> PmPprM a -> (a, DIdEnv SDoc) -runPmPpr delta m = case runRWS m delta (emptyDVarEnv, nameList) of +runPmPpr :: Nabla -> PmPprM a -> (a, DIdEnv SDoc) +runPmPpr nabla m = case runRWS m nabla (emptyDVarEnv, nameList) of (a, (renamings, _), _) -> (a, renamings) -- | Allocates a new, clean name for the given 'Id' if it doesn't already have @@ -129,8 +129,8 @@ getCleanName x = do checkRefuts :: Id -> PmPprM (Maybe SDoc) -- the clean name if it has negative info attached checkRefuts x = do - delta <- ask - case lookupRefuts delta x of + nabla <- ask + case lookupRefuts nabla x of [] -> pure Nothing -- Will just be a wildcard later on _ -> Just <$> getCleanName x @@ -144,8 +144,8 @@ pprPmVar :: PprPrec -> Id -> PmPprM SDoc -- The useful information in the latter case is the constructor that we missed, -- not the types of the wildcards in the places that aren't matched as a result. pprPmVar prec x = do - delta <- ask - case lookupSolution delta x of + nabla <- ask + case lookupSolution nabla x of Just (alt, _tvs, args) -> pprPmAltCon prec alt args Nothing -> fromMaybe typed_wildcard <$> checkRefuts x where @@ -160,24 +160,24 @@ pprPmVar prec x = do pprPmAltCon :: PprPrec -> PmAltCon -> [Id] -> PmPprM SDoc pprPmAltCon _prec (PmAltLit l) _ = pure (ppr l) pprPmAltCon prec (PmAltConLike cl) args = do - delta <- ask - pprConLike delta prec cl args + nabla <- ask + pprConLike nabla prec cl args -pprConLike :: Delta -> PprPrec -> ConLike -> [Id] -> PmPprM SDoc -pprConLike delta _prec cl args - | Just pm_expr_list <- pmExprAsList delta (PmAltConLike cl) args +pprConLike :: Nabla -> PprPrec -> ConLike -> [Id] -> PmPprM SDoc +pprConLike nabla _prec cl args + | Just pm_expr_list <- pmExprAsList nabla (PmAltConLike cl) args = case pm_expr_list of NilTerminated list -> brackets . fsep . punctuate comma <$> mapM (pprPmVar appPrec) list WcVarTerminated pref x -> parens . fcat . punctuate colon <$> mapM (pprPmVar appPrec) (toList pref ++ [x]) -pprConLike _delta _prec (RealDataCon con) args +pprConLike _nabla _prec (RealDataCon con) args | isUnboxedTupleCon con , let hash_parens doc = text "(#" <+> doc <+> text "#)" = hash_parens . fsep . punctuate comma <$> mapM (pprPmVar appPrec) args | isTupleDataCon con = parens . fsep . punctuate comma <$> mapM (pprPmVar appPrec) args -pprConLike _delta prec cl args +pprConLike _nabla prec cl args | conLikeIsInfix cl = case args of [x, y] -> do x' <- pprPmVar funPrec x y' <- pprPmVar funPrec y @@ -202,11 +202,11 @@ data PmExprList -- ending in a wildcard variable x (of list type). Should be pretty-printed as -- (1:2:_). -- * @pmExprAsList [] == Just ('NilTerminated' [])@ -pmExprAsList :: Delta -> PmAltCon -> [Id] -> Maybe PmExprList -pmExprAsList delta = go_con [] +pmExprAsList :: Nabla -> PmAltCon -> [Id] -> Maybe PmExprList +pmExprAsList nabla = go_con [] where go_var rev_pref x - | Just (alt, _tvs, args) <- lookupSolution delta x + | Just (alt, _tvs, args) <- lookupSolution nabla x = go_con rev_pref alt args go_var rev_pref x | Just pref <- nonEmpty (reverse rev_pref) ===================================== compiler/GHC/HsToCore/PmCheck/Types.hs ===================================== @@ -15,6 +15,7 @@ Author: George Karachalias module GHC.HsToCore.PmCheck.Types ( -- * Representations for Literals and AltCons PmLit(..), PmLitValue(..), PmAltCon(..), pmLitType, pmAltConType, + isPmAltConMatchStrict, pmAltConImplBangs, -- ** Equality on 'PmAltCon's PmEquality(..), eqPmAltCon, @@ -35,8 +36,8 @@ module GHC.HsToCore.PmCheck.Types ( setIndirectSDIE, setEntrySDIE, traverseSDIE, -- * The pattern match oracle - VarInfo(..), TmState(..), TyState(..), Delta(..), - Deltas(..), initDeltas, liftDeltasM + BotInfo(..), VarInfo(..), TmState(..), TyState(..), Nabla(..), + Nablas(..), initNablas, liftNablasM ) where #include "HsVersions.h" @@ -226,6 +227,19 @@ pmAltConType :: PmAltCon -> [Type] -> Type pmAltConType (PmAltLit lit) _arg_tys = ASSERT( null _arg_tys ) pmLitType lit pmAltConType (PmAltConLike con) arg_tys = conLikeResTy con arg_tys +-- | Is a match on this constructor forcing the match variable? +-- True of data constructors, literals and pattern synonyms (#17357), but not of +-- newtypes. +-- See Note [Coverage checking Newtype matches] in "GHC.HsToCore.PmCheck.Oracle". +isPmAltConMatchStrict :: PmAltCon -> Bool +isPmAltConMatchStrict PmAltLit{} = True +isPmAltConMatchStrict (PmAltConLike PatSynCon{}) = True -- #17357 +isPmAltConMatchStrict (PmAltConLike (RealDataCon dc)) = not (isNewDataCon dc) + +pmAltConImplBangs :: PmAltCon -> [HsImplBang] +pmAltConImplBangs PmAltLit{} = [] +pmAltConImplBangs (PmAltConLike con) = conLikeImplBangs con + {- Note [Undecidable Equality for PmAltCons] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Equality on overloaded literals is undecidable in the general case. Consider @@ -477,6 +491,13 @@ instance Outputable a => Outputable (Shared a) where instance Outputable a => Outputable (SharedDIdEnv a) where ppr (SDIE env) = ppr env +-- | See 'vi_bot'. +data BotInfo + = IsBot + | IsNotBot + | MaybeBot + deriving Eq + -- | The term oracle state. Stores 'VarInfo' for encountered 'Id's. These -- entries are possibly shared when we figure out that two variables must be -- equal, thus represent the same set of values. @@ -531,6 +552,13 @@ data VarInfo -- because files like Cabal's `LicenseId` define relatively huge enums -- that lead to quadratic or worse behavior. + , vi_bot :: BotInfo + -- ^ Can this variable be ⊥? Models (mutually contradicting) @x ~ ⊥@ and + -- @x ~/ ⊥@ constraints. E.g. + -- * 'MaybeBot': Don't know; Neither @x ~ ⊥@ nor @x /~ ⊥@. + -- * 'IsBot': @x ~ ⊥@ + -- * 'IsNotBot': @x /~ ⊥@ + , vi_cache :: !PossibleMatches -- ^ A cache of the associated COMPLETE sets. At any time a superset of -- possible constructors of each COMPLETE set. So, if it's not in here, we @@ -538,14 +566,19 @@ data VarInfo -- to recognise completion of a COMPLETE set efficiently for large enums. } +instance Outputable BotInfo where + ppr MaybeBot = empty + ppr IsBot = text "~⊥" + ppr IsNotBot = text "/~⊥" + -- | Not user-facing. instance Outputable TmState where ppr (TmSt state reps) = ppr state $$ ppr reps -- | Not user-facing. instance Outputable VarInfo where - ppr (VI ty pos neg cache) - = braces (hcat (punctuate comma [ppr ty, ppr pos, ppr neg, ppr cache])) + ppr (VI ty pos neg bot cache) + = braces (hcat (punctuate comma [ppr ty, ppr pos, ppr neg, ppr bot, ppr cache])) -- | Initial state of the term oracle. initTmState :: TmState @@ -563,37 +596,38 @@ instance Outputable TyState where initTyState :: TyState initTyState = TySt emptyBag --- | An inert set of canonical (i.e. mutually compatible) term and type --- constraints. -data Delta = MkDelta { delta_ty_st :: TyState -- Type oracle; things like a~Int - , delta_tm_st :: TmState } -- Term oracle; things like x~Nothing +-- | A normalised refinement type, comprised of an inert set of canonical (i.e. +-- mutually compatible) term and type constraints that form the refinement +-- type's predicate. +data Nabla = MkNabla { nabla_ty_st :: TyState -- Type oracle; things like a~Int + , nabla_tm_st :: TmState } -- Term oracle; things like x~Nothing --- | An initial delta that is always satisfiable -initDelta :: Delta -initDelta = MkDelta initTyState initTmState +-- | An initial nabla that is always satisfiable +initNabla :: Nabla +initNabla = MkNabla initTyState initTmState -instance Outputable Delta where - ppr delta = hang (text "Delta") 2 $ vcat [ +instance Outputable Nabla where + ppr nabla = hang (text "Nabla") 2 $ vcat [ -- intentionally formatted this way enable the dev to comment in only -- the info she needs - ppr (delta_tm_st delta), - ppr (delta_ty_st delta) + ppr (nabla_tm_st nabla), + ppr (nabla_ty_st nabla) ] --- | A disjunctive bag of 'Delta's, representing a refinement type. -newtype Deltas = MkDeltas (Bag Delta) +-- | A disjunctive bag of 'Nabla's, representing a refinement type. +newtype Nablas = MkNablas (Bag Nabla) -initDeltas :: Deltas -initDeltas = MkDeltas (unitBag initDelta) +initNablas :: Nablas +initNablas = MkNablas (unitBag initNabla) -instance Outputable Deltas where - ppr (MkDeltas deltas) = ppr deltas +instance Outputable Nablas where + ppr (MkNablas nablas) = ppr nablas -instance Semigroup Deltas where - MkDeltas l <> MkDeltas r = MkDeltas (l `unionBags` r) +instance Semigroup Nablas where + MkNablas l <> MkNablas r = MkNablas (l `unionBags` r) -instance Monoid Deltas where - mempty = MkDeltas emptyBag +instance Monoid Nablas where + mempty = MkNablas emptyBag -liftDeltasM :: Monad m => (Delta -> m (Maybe Delta)) -> Deltas -> m Deltas -liftDeltasM f (MkDeltas ds) = MkDeltas . catBagMaybes <$> (traverse f ds) +liftNablasM :: Monad m => (Nabla -> m (Maybe Nabla)) -> Nablas -> m Nablas +liftNablasM f (MkNablas ds) = MkNablas . catBagMaybes <$> (traverse f ds) ===================================== compiler/GHC/HsToCore/PmCheck/Types.hs-boot ===================================== @@ -2,8 +2,8 @@ module GHC.HsToCore.PmCheck.Types where import GHC.Data.Bag -data Delta +data Nabla -newtype Deltas = MkDeltas (Bag Delta) +newtype Nablas = MkNablas (Bag Nabla) -initDeltas :: Deltas +initNablas :: Nablas ===================================== compiler/GHC/Tc/Types.hs ===================================== @@ -106,7 +106,7 @@ import GHC.Tc.Types.Origin import GHC.Types.Annotations import GHC.Core.InstEnv import GHC.Core.FamInstEnv -import {-# SOURCE #-} GHC.HsToCore.PmCheck.Types (Deltas) +import {-# SOURCE #-} GHC.HsToCore.PmCheck.Types (Nablas) import GHC.Data.IOEnv import GHC.Types.Name.Reader import GHC.Types.Name @@ -324,9 +324,9 @@ data DsLclEnv = DsLclEnv { dsl_loc :: RealSrcSpan, -- To put in pattern-matching error msgs -- See Note [Note [Long-distance information] in "GHC.HsToCore.PmCheck" - -- The set of reaching values Deltas is augmented as we walk inwards, + -- The set of reaching values Nablas is augmented as we walk inwards, -- refined through each pattern match in turn - dsl_deltas :: Deltas + dsl_nablas :: Nablas } -- Inside [| |] brackets, the desugarer looks ===================================== testsuite/tests/pmcheck/should_compile/T10183.hs ===================================== @@ -0,0 +1,22 @@ +{-# LANGUAGE GADTs, DataKinds, TypeOperators, UnicodeSyntax #-} + +module Foo where + +import GHC.TypeLits + +data List l t where + Nil ∷ List 0 t + (:-) ∷ t → List l t → List (l+1) t + +head' ∷ (1<=l) ⇒ List l t → t +head' (x :- _) = x + +data T a where + TT :: T Bool + TF :: T Int + +f :: T Bool -> Bool +f TT = True + +g :: (a ~ Bool) => T a -> Bool +g TT = True ===================================== testsuite/tests/pmcheck/should_compile/T17340.stderr ===================================== @@ -7,6 +7,10 @@ T17340.hs:19:4: warning: [-Wredundant-bang-patterns] Pattern match has redundant bang In an equation for ‘g’: g x = ... +T17340.hs:23:9: warning: [-Wredundant-bang-patterns] + Pattern match has redundant bang + In an equation for ‘h’: h x = ... + T17340.hs:27:4: warning: [-Wredundant-bang-patterns] Pattern match has redundant bang In an equation for ‘k’: k _ = ... ===================================== testsuite/tests/pmcheck/should_compile/T17378.hs ===================================== @@ -0,0 +1,30 @@ +{-# OPTIONS_GHC -Wincomplete-patterns -fforce-recomp #-} +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE EmptyCase #-} +module Lib where + +import Data.Type.Equality +import Data.Functor.Identity +import Data.Void + +f :: a :~: Int -> a :~: Bool -> () +f !_ x = case x of {} + +g :: Identity (a :~: Int) -> a :~: Bool -> () +g (Identity _) Refl = () + +data SMaybe a = SNothing + | SJust !a + +-- | Exhaustive. Note how in addition to @{(a,b) | b /~ True}@, the value set +-- @{(a,b) | y /~ SNothing, b ~ True}@ flows into the next equation, but @y@ is +-- no longer in scope. Normally, we have no way of matching on that without a +-- wildcard match, but in this case we refute @y ~ SJust z@ by unleashing type +-- evidence saying that @z@ must be 'Void' by matching on 'Void'. +h :: forall a. a :~: Void -> Bool -> () +h _ True | let y = undefined :: SMaybe a, SNothing <- y = () +h Refl False = () ===================================== testsuite/tests/pmcheck/should_compile/T17725.hs ===================================== @@ -0,0 +1,10 @@ +{-# OPTIONS_GHC -Wincomplete-patterns -fforce-recomp #-} +{-# LANGUAGE BangPatterns #-} +module Lib where + +newtype IInt = IInt Int + +f :: IInt -> Bool -> () +f !(IInt _) True = () +f (IInt 42) True = () +f _ _ = () ===================================== testsuite/tests/pmcheck/should_compile/T17725.stderr ===================================== @@ -0,0 +1,4 @@ + +T17725.hs:9:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In an equation for ‘f’: f (IInt 42) True = ... ===================================== testsuite/tests/pmcheck/should_compile/T17729.hs ===================================== @@ -0,0 +1,13 @@ +{-# LANGUAGE PatternSynonyms #-} +{-# OPTIONS_GHC -fforce-recomp -Wincomplete-patterns #-} + +incomplete :: Maybe a -> Bool +incomplete ma = case (ma, ()) of + (Nothing, _) -> False + +{-# COMPLETE Pat #-} +pattern Pat :: a -> b -> (a, b) +pattern Pat a b = (a, b) + +main :: IO () +main = print $ incomplete (Just ()) ===================================== testsuite/tests/pmcheck/should_compile/T17729.stderr ===================================== @@ -0,0 +1,4 @@ + +T17729.hs:5:17: warning: [-Wincomplete-patterns (in -Wextra)] + Pattern match(es) are non-exhaustive + In a case alternative: Patterns not matched: ((Just _), ()) ===================================== testsuite/tests/pmcheck/should_compile/T18273.hs ===================================== @@ -0,0 +1,41 @@ +{-# OPTIONS_GHC -fforce-recomp -Wincomplete-patterns #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE EmptyCase #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE TypeFamilies #-} + +module Bug where + +import Data.Kind +import Data.Void + +type SFalse = SBool 'False +type STrue = SBool 'True + +data SBool :: Bool -> Type where + SFalse :: SFalse + STrue :: STrue + +type family F (b :: Bool) :: Type where + F 'False = Void + F 'True = () + +data T (b :: Bool) + = MkT1 + | MkT2 !(F b) + +ex :: SBool b -> T b -> () +ex sb t = + case t of + MkT1 -> () + MkT2 f -> + case sb of + STrue -> f + +ex2 :: SBool b -> T b -> () +ex2 sb t = + case t of + MkT2 f -> + case sb of + STrue -> f + MkT1 -> () ===================================== testsuite/tests/pmcheck/should_compile/T18341.hs ===================================== @@ -0,0 +1,24 @@ +{-# OPTIONS_GHC -Wincomplete-patterns -fforce-recomp #-} +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE MagicHash #-} + +module Lib where + +import GHC.Exts + +data T = MkT !Int {-# UNPACK #-} !Int Int# + +f :: T -> () +f (MkT _ _ _) | False = () -- inaccessible +f (MkT !_ _ _) | False = () -- redundant, not only inaccessible! +f _ = () + +g :: T -> () +g (MkT _ _ _) | False = () -- inaccessible +g (MkT _ !_ _) | False = () -- redundant, not only inaccessible! +g _ = () + +h :: T -> () +h (MkT _ _ _) | False = () -- inaccessible +h (MkT _ _ !_) | False = () -- redundant, not only inaccessible! +h _ = () ===================================== testsuite/tests/pmcheck/should_compile/T18341.stderr ===================================== @@ -0,0 +1,24 @@ + +T18341.hs:12:18: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match has inaccessible right hand side + In an equation for ‘f’: f (MkT _ _ _) | False = ... + +T18341.hs:13:18: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In an equation for ‘f’: f (MkT !_ _ _) | False = ... + +T18341.hs:17:18: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match has inaccessible right hand side + In an equation for ‘g’: g (MkT _ _ _) | False = ... + +T18341.hs:18:18: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In an equation for ‘g’: g (MkT _ !_ _) | False = ... + +T18341.hs:22:18: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match has inaccessible right hand side + In an equation for ‘h’: h (MkT _ _ _) | False = ... + +T18341.hs:23:18: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant + In an equation for ‘h’: h (MkT _ _ !_) | False = ... ===================================== testsuite/tests/pmcheck/should_compile/TooManyDeltas.hs ===================================== @@ -3,8 +3,10 @@ -- As a result, these functions elicit the symptoms describe in the warnings -- message, e.g. -- - False positives on exhaustivity --- - Turns redundant into inaccessible clauses -- - Fails to report redundant matches +-- +-- We used to turn redundant into inaccessible clauses, but SG was unable to +-- produce a testcase. See the comment below. module TooManyDeltas where data T = A | B @@ -13,12 +15,19 @@ data T = A | B f :: T -> T -> () f A A = () +-- SG: As of July 2020, g doesn't reproduce anymore. +-- Because we treat constructor matches lazily and push data con match +-- strictness into a preceding bang guard, The single place that calls the +-- throttling function will not regress in laziness. Note that by throttling we +-- can only "forget" the x /~ K constraint from unc_this, not the preceding +-- x /~ ⊥ constraint. + -- | Reports that the third clause is inaccessible, when really it is -- redundant. g :: T -> T -> () g _ A = () g A A = () -- inaccessible, correctly flagged -g A A = () -- redundant, not inaccessible! +g A A = () -- redundant, used to be inaccessible (see above). g _ _ = () -- (this one is not about exhaustivity) -- | Fails to report that the second clause is redundant. ===================================== testsuite/tests/pmcheck/should_compile/TooManyDeltas.stderr ===================================== @@ -1,12 +1,12 @@ -TooManyDeltas.hs:14:1: warning: +TooManyDeltas.hs:16:1: warning: Pattern match checker ran into -fmax-pmcheck-models=0 limit, so • Redundant clauses might not be reported at all • Redundant clauses might be reported as inaccessible • Patterns reported as unmatched might actually be matched Increase the limit or resolve the warnings to suppress this message. -TooManyDeltas.hs:14:1: warning: [-Wincomplete-patterns (in -Wextra)] +TooManyDeltas.hs:16:1: warning: [-Wincomplete-patterns (in -Wextra)] Pattern match(es) are non-exhaustive In an equation for ‘f’: Patterns not matched: @@ -15,17 +15,17 @@ TooManyDeltas.hs:14:1: warning: [-Wincomplete-patterns (in -Wextra)] B A B B -TooManyDeltas.hs:19:1: warning: +TooManyDeltas.hs:28:1: warning: Pattern match checker ran into -fmax-pmcheck-models=0 limit, so • Redundant clauses might not be reported at all • Redundant clauses might be reported as inaccessible • Patterns reported as unmatched might actually be matched Increase the limit or resolve the warnings to suppress this message. -TooManyDeltas.hs:20:1: warning: [-Woverlapping-patterns (in -Wdefault)] +TooManyDeltas.hs:29:1: warning: [-Woverlapping-patterns (in -Wdefault)] Pattern match has inaccessible right hand side In an equation for ‘g’: g A A = ... -TooManyDeltas.hs:21:1: warning: [-Woverlapping-patterns (in -Wdefault)] - Pattern match has inaccessible right hand side +TooManyDeltas.hs:30:1: warning: [-Woverlapping-patterns (in -Wdefault)] + Pattern match is redundant In an equation for ‘g’: g A A = ... ===================================== testsuite/tests/pmcheck/should_compile/all.T ===================================== @@ -36,6 +36,8 @@ test('T9951b', [], compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T9951', [], compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) +test('T10183', [], compile, + ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T11303', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns +RTS -M1G -RTS']) test('T11276', collect_compiler_stats('bytes allocated',10), compile, @@ -108,12 +110,18 @@ test('T17357', expect_broken(17357), compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T17376', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) +test('T17378', normal, compile, + ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T17465', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T17646', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T17703', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) +test('T17725', normal, compile, + ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) +test('T17729', normal, compile, + ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T17783', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T17977', collect_compiler_stats('bytes allocated',10), compile, @@ -122,6 +130,10 @@ test('T17977b', collect_compiler_stats('bytes allocated',10), compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T18049', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) +test('T18273', normal, compile, + ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) +test('T18341', normal, compile, + ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T18478', collect_compiler_stats('bytes allocated',10), compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T18533', normal, compile, View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/42f9bf20d2d7c9d190023ad053eec82b9d1aad27 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/42f9bf20d2d7c9d190023ad053eec82b9d1aad27 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 17:36:22 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 31 Aug 2020 13:36:22 -0400 Subject: [Git][ghc/ghc][ghc-8.8] Import qualified Prelude in Cmm/Parser.y Message-ID: <5f4d3516a5dd5_80bb25753c994173b@gitlab.haskell.org.mail> Ben Gamari pushed to branch ghc-8.8 at Glasgow Haskell Compiler / GHC Commits: d6cbfd9a by Krzysztof Gogolewski at 2020-08-29T17:10:01+02:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. (cherry picked from commit fddddbf47d6ba2b1b3b6ec89bd40c8fa020e6606) - - - - - 2 changed files: - compiler/cmm/CmmParse.y - compiler/parser/Parser.y Changes: ===================================== compiler/cmm/CmmParse.y ===================================== @@ -201,6 +201,7 @@ necessary to the stack to accommodate it (e.g. 2). module CmmParse ( parseCmmFile ) where import GhcPrelude +import qualified Prelude -- for happy-generated code import StgCmmExtCode import CmmCallConv ===================================== compiler/parser/Parser.y ===================================== @@ -37,7 +37,7 @@ import GHC.Exts import Data.Char import Control.Monad ( mplus ) import Control.Applicative ((<$)) -import qualified Prelude +import qualified Prelude -- for happy-generated code -- compiler/hsSyn import HsSyn View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d6cbfd9a29452b3d4d0ccf17f0f68e472842b6e9 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d6cbfd9a29452b3d4d0ccf17f0f68e472842b6e9 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 17:36:23 2020 From: gitlab at gitlab.haskell.org (Krzysztof Gogolewski) Date: Mon, 31 Aug 2020 13:36:23 -0400 Subject: [Git][ghc/ghc] Deleted branch wip/cherry-pick-happy-compat-8.8 Message-ID: <5f4d35175df5e_80b3f8492535c409941987@gitlab.haskell.org.mail> Krzysztof Gogolewski deleted branch wip/cherry-pick-happy-compat-8.8 at Glasgow Haskell Compiler / GHC -- You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 17:36:48 2020 From: gitlab at gitlab.haskell.org (Krzysztof Gogolewski) Date: Mon, 31 Aug 2020 13:36:48 -0400 Subject: [Git][ghc/ghc] Deleted branch wip/cherry-pick-happy-compat-8.10 Message-ID: <5f4d35302921d_80b3f8402c0345499472e@gitlab.haskell.org.mail> Krzysztof Gogolewski deleted branch wip/cherry-pick-happy-compat-8.10 at Glasgow Haskell Compiler / GHC -- You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 17:36:49 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 31 Aug 2020 13:36:49 -0400 Subject: [Git][ghc/ghc][ghc-8.10] Import qualified Prelude in Cmm/Parser.y Message-ID: <5f4d3531e06c_80b78834c8994742f@gitlab.haskell.org.mail> Ben Gamari pushed to branch ghc-8.10 at Glasgow Haskell Compiler / GHC Commits: e512d310 by Vladislav Zavialov at 2020-08-29T17:03:38+02:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. (cherry picked from commit fddddbf47d6ba2b1b3b6ec89bd40c8fa020e6606) - - - - - 2 changed files: - compiler/cmm/CmmParse.y - compiler/parser/Parser.y Changes: ===================================== compiler/cmm/CmmParse.y ===================================== @@ -203,6 +203,7 @@ necessary to the stack to accommodate it (e.g. 2). module CmmParse ( parseCmmFile ) where import GhcPrelude +import qualified Prelude -- for happy-generated code import GHC.StgToCmm.ExtCode import CmmCallConv ===================================== compiler/parser/Parser.y ===================================== @@ -42,7 +42,7 @@ import Data.Char import Data.Maybe ( maybeToList ) import Control.Monad ( mplus ) import Control.Applicative ((<$)) -import qualified Prelude +import qualified Prelude -- for happy-generated code -- compiler/hsSyn import GHC.Hs View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e512d310e668b77a9d1e022dbff45050f69032f5 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e512d310e668b77a9d1e022dbff45050f69032f5 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 17:37:20 2020 From: gitlab at gitlab.haskell.org (Krzysztof Gogolewski) Date: Mon, 31 Aug 2020 13:37:20 -0400 Subject: [Git][ghc/ghc] Deleted branch wip/cherry-pick-happy-compat Message-ID: <5f4d3550b0d98_80b3f84a07522cc99518f@gitlab.haskell.org.mail> Krzysztof Gogolewski deleted branch wip/cherry-pick-happy-compat at Glasgow Haskell Compiler / GHC -- You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 17:37:21 2020 From: gitlab at gitlab.haskell.org (Ben Gamari) Date: Mon, 31 Aug 2020 13:37:21 -0400 Subject: [Git][ghc/ghc][ghc-9.0] Import qualified Prelude in Cmm/Parser.y Message-ID: <5f4d3551d708e_80b3f8468ca23e0995201e@gitlab.haskell.org.mail> Ben Gamari pushed to branch ghc-9.0 at Glasgow Haskell Compiler / GHC Commits: 29e9d2d1 by Vladislav Zavialov at 2020-08-29T16:54:45+02:00 Import qualified Prelude in Cmm/Parser.y In preparation for the next version of 'happy', c95920 added a qualified import to GHC/Parser.y but for some reason neglected GHC/Cmm/Parser.y This patch adds the missing qualified import to GHC/Cmm/Parser.y and also adds a clarifying comment to explain why this import is needed. (cherry picked from commit fddddbf47d6ba2b1b3b6ec89bd40c8fa020e6606) - - - - - 2 changed files: - compiler/GHC/Cmm/Parser.y - compiler/GHC/Parser.y Changes: ===================================== compiler/GHC/Cmm/Parser.y ===================================== @@ -203,6 +203,7 @@ necessary to the stack to accommodate it (e.g. 2). module GHC.Cmm.Parser ( parseCmmFile ) where import GHC.Prelude +import qualified Prelude -- for happy-generated code import GHC.StgToCmm.ExtCode import GHC.Cmm.CallConv ===================================== compiler/GHC/Parser.y ===================================== @@ -46,7 +46,7 @@ import Data.Char import Data.Maybe ( maybeToList ) import Control.Monad ( mplus ) import Control.Applicative ((<$)) -import qualified Prelude +import qualified Prelude -- for happy-generated code -- compiler import GHC.Hs View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/29e9d2d106082ce435a24ec46c48f257f53a16f6 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/29e9d2d106082ce435a24ec46c48f257f53a16f6 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 17:51:48 2020 From: gitlab at gitlab.haskell.org (Vilem-Benjamin Liepelt) Date: Mon, 31 Aug 2020 13:51:48 -0400 Subject: [Git][ghc/ghc][wip/buggymcbugfix/appendArrays] 2 commits: Implement appendArray# (external) primop Message-ID: <5f4d38b4641eb_80b3f84694d06209962947@gitlab.haskell.org.mail> Vilem-Benjamin Liepelt pushed to branch wip/buggymcbugfix/appendArrays at Glasgow Haskell Compiler / GHC Commits: 9784a81d by buggymcbugfix at 2020-08-31T19:44:44+02:00 Implement appendArray# (external) primop - - - - - ab78a80b by buggymcbugfix at 2020-08-31T19:47:59+02:00 Point to related code - - - - - 3 changed files: - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/StgToCmm/Prim.hs - rts/PrimOps.cmm Changes: ===================================== compiler/GHC/Builtin/primops.txt.pp ===================================== @@ -1246,6 +1246,14 @@ primop ThawArrayOp "thawArray#" GenPrimOp has_side_effects = True can_fail = True +primop AppendArrays "appendArrays#" GenPrimOp + Array# a -> Array# a -> Array# a + {Concatenate two arrays by @memcpy at ing them into a new array.} + with + out_of_line = True + has_side_effects = True + can_fail = True + primop CasArrayOp "casArray#" GenPrimOp MutableArray# s a -> Int# -> a -> a -> State# s -> (# State# s, Int#, a #) {Given an array, an offset, the expected old value, and @@ -1437,6 +1445,14 @@ primop ThawSmallArrayOp "thawSmallArray#" GenPrimOp has_side_effects = True can_fail = True +primop AppendSmallArrays "appendSmallArrays#" GenPrimOp + SmallArray# a -> SmallArray# a -> SmallArray# a + {Concatenate two arrays by @memcpy at ing them into a new array.} + with + out_of_line = True + has_side_effects = True + can_fail = True + primop CasSmallArrayOp "casSmallArray#" GenPrimOp SmallMutableArray# s a -> Int# -> a -> a -> State# s -> (# State# s, Int#, a #) {Unsafe, machine-level atomic compare and swap on an element within an array. ===================================== compiler/GHC/StgToCmm/Prim.hs ===================================== @@ -219,6 +219,8 @@ emitPrimOp dflags primop = case primop of -> opIntoRegs $ \ [res] -> emitCloneArray mkMAP_DIRTY_infoLabel res src src_off (fromInteger n) _ -> PrimopCmmEmit_External + AppendArrays -> const PrimopCmmEmit_External + NewSmallArrayOp -> \case [(CmmLit (CmmInt n w)), init] | wordsToBytes platform (asUnsigned w n) <= fromIntegral (maxInlineAllocSize dflags) @@ -264,6 +266,8 @@ emitPrimOp dflags primop = case primop of -> opIntoRegs $ \ [res] -> emitCloneSmallArray mkSMAP_DIRTY_infoLabel res src src_off (fromInteger n) _ -> PrimopCmmEmit_External + AppendSmallArrays -> const PrimopCmmEmit_External + -- First we handle various awkward cases specially. ParOp -> \[arg] -> opIntoRegs $ \[res] -> do ===================================== rts/PrimOps.cmm ===================================== @@ -343,6 +343,41 @@ stg_thawArrayzh ( gcptr src, W_ offset, W_ n ) cloneArray(stg_MUT_ARR_PTRS_DIRTY_info, src, offset, n) } +// Closely follows the pattern of cloneArray in includes/Cmm.h +stg_appendArrayszh( gcptr src1, gcptr src2 ) +{ + W_ words, n1, n2, nDest, size1, size2; + gcptr dst, dst_p, src1_p, src2_p; + + again: MAYBE_GC(again); + + n1 = StgMutArrPtrs_ptrs(src1); + n2 = StgMutArrPtrs_ptrs(src2); + nDest = n1 + n2; + + size1 = n1 + mutArrPtrsCardWords(n1); + size2 = n2 + mutArrPtrsCardWords(n2); + sizeDest = nDest + mutArrPtrsCardWords(nDest); + + words = BYTES_TO_WDS(SIZEOF_StgMutArrPtrs) + sizeDest; + + ("ptr" dst) = ccall allocate(MyCapability() "ptr", words); + TICK_ALLOC_PRIM(SIZEOF_StgMutArrPtrs, WDS(sizeDest), 0); + + SET_HDR(dst, stg_MUT_ARR_PTRS_FROZEN_CLEAN_info, CCCS); + StgMutArrPtrs_ptrs(dst) = nDest; + StgMutArrPtrs_size(dst) = sizeDest; + + dst_p = dst + SIZEOF_StgMutArrPtrs; + src1_p = src1 + SIZEOF_StgMutArrPtrs; + src2_p = src2 + SIZEOF_StgMutArrPtrs; + + prim %memcpy(dst_p, src1_p, WDS(n1), SIZEOF_W); + prim %memcpy(dst_p + WDS(n1), src2_p, WDS(n2), SIZEOF_W); + + return (dst); +} + // RRN: Uses the ticketed approach; see casMutVar stg_casArrayzh ( gcptr arr, W_ ind, gcptr old, gcptr new ) /* MutableArray# s a -> Int# -> a -> a -> State# s -> (# State# s, Int#, Any a #) */ @@ -478,6 +513,35 @@ stg_thawSmallArrayzh ( gcptr src, W_ offset, W_ n ) cloneSmallArray(stg_SMALL_MUT_ARR_PTRS_DIRTY_info, src, offset, n) } +// Closely follows the pattern of cloneSmallArray in includes/Cmm.h +stg_appendSmallArrayszh( gcptr src1, gcptr src2 ) +{ + W_ words, n1, n2, nDest; + gcptr dst, dst_p, src1_p, src2_p; + + again: MAYBE_GC(again); + + n1 = StgSmallMutArrPtrs_ptrs(src1); + n2 = StgSmallMutArrPtrs_ptrs(src2); + nDest = n1 + n2; + words = BYTES_TO_WDS(SIZEOF_StgSmallMutArrPtrs) + nDest; + + ("ptr" dst) = ccall allocate(MyCapability() "ptr", words); + TICK_ALLOC_PRIM(SIZEOF_StgSmallMutArrPtrs, WDS(nDest), 0); + + SET_HDR(dst, stg_SMALL_MUT_ARR_PTRS_FROZEN_CLEAN_info, CCCS); \ + StgSmallMutArrPtrs_ptrs(dst) = nDest; + + dst_p = dst + SIZEOF_StgSmallMutArrPtrs; + src1_p = src1 + SIZEOF_StgSmallMutArrPtrs; + src2_p = src2 + SIZEOF_StgSmallMutArrPtrs; + + prim %memcpy(dst_p, src1_p, WDS(n1), SIZEOF_W); + prim %memcpy(dst_p + WDS(n1), src2_p, WDS(n2), SIZEOF_W); + + return (dst); +} + // Concurrent GC write barrier for pointer array copies // // hdr_size in bytes. dst_off in words, n in words. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fb3986fe47a298c97c19735b86dc026fec9aa9a0...ab78a80b22e44fe68ba083354d0f164998032ca0 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/fb3986fe47a298c97c19735b86dc026fec9aa9a0...ab78a80b22e44fe68ba083354d0f164998032ca0 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 21:39:16 2020 From: gitlab at gitlab.haskell.org (Marge Bot) Date: Mon, 31 Aug 2020 17:39:16 -0400 Subject: [Git][ghc/ghc][wip/marge_bot_batch_merge_job] 18 commits: Add missing primop documentation (#18454) Message-ID: <5f4d6e046714_80b3f8468b8bd3010009461@gitlab.haskell.org.mail> Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: c6f50cea by Krzysztof Gogolewski at 2020-08-28T02:22:36-04:00 Add missing primop documentation (#18454) - Add three pseudoops to primops.txt.pp, so that Haddock renders the documentation - Update comments - Remove special case for "->" - it's no longer exported from GHC.Prim - Remove reference to Note [Compiling GHC.Prim] - the ad-hoc fix is no longer there after updates to levity polymorphism. - Document GHC.Prim - Remove the comment that lazy is levity-polymorphic. As far as I can tell, it never was: in 80e399639, only the unfolding was given an open type variable. - Remove haddock hack in GHC.Magic - no longer neccessary after adding realWorld# to primops.txt.pp. - - - - - f065b6b0 by Tamar Christina at 2020-08-28T02:23:13-04:00 Fix use distro toolchian - - - - - 4517a382 by Tamar Christina at 2020-08-28T02:23:13-04:00 document how build system find toolchains on Windows - - - - - 3bfdd981 by Ben Gamari at 2020-08-31T17:38:53-04:00 base: Better error message on invalid getSystemTimerManager call Previously we would produce a rather unhelpful pattern match failure error in the case where the user called `getSystemTimerManager` in a program which isn't built with `-threaded`. This understandably confused the user in #15616. Fixes #15616. - - - - - 0f62fa07 by Roland Senn at 2020-08-31T17:38:54-04:00 Add tests for #15617. Avoid a similar regression in the future. - - - - - 4e834ac8 by Roland Senn at 2020-08-31T17:38:55-04:00 Add additional tests for #18172 (Followup MR 3543) There was still one active discussion [thread](https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3543#note_284325) when MR !3543 got merged. This MR adds the requested tests exercising the changes in `compiler/GHC/HsToCore/Match/Literal.hs:warnAboutEmptyEnumerations` and its sub-functions. - - - - - bf4ac6d3 by Ben Gamari at 2020-08-31T17:38:55-04:00 Bump Win32 and process submodules - - - - - f2b71ca7 by Sylvain Henry at 2020-08-31T17:38:59-04:00 Hadrian: fix slow-validate flavour (#18586) - - - - - 25fd1345 by Andreas Klebinger at 2020-08-31T17:38:59-04:00 Update dominator code with fixes from the dom-lt package. Two bugs turned out in the package that have been fixed since. This MR includes this fixes in the GHC port of the code. - - - - - 36036ed7 by Andreas Klebinger at 2020-08-31T17:38:59-04:00 Dominators.hs: Use unix line endings - - - - - c55fc0d6 by Moritz Angermann at 2020-08-31T17:39:00-04:00 [fixup 3433] move debugBelch into IF_DEBUG(linker) The commit in dff1cb3d9c111808fec60190747272b973547c52 incorrectly left the `debugBelch` function without a comment or IF_DEBUG(linker,) decoration. This rectifies it. Needs at least a 8.10 backport, as it was backported in 6471cc6aff80d5deebbdb1bf7b677b31ed2af3d5 - - - - - 6e97fe09 by Sylvain Henry at 2020-08-31T17:39:01-04:00 Don't store HomeUnit in UnitConfig Allow the creation of a UnitConfig (hence of a UnitState) without having a HomeUnit. It's required for #14335. - - - - - ccbf9cf1 by Sylvain Henry at 2020-08-31T17:39:02-04:00 Fix documentation and fix "check" bignum backend (#18604) - - - - - 866dec95 by Moritz Angermann at 2020-08-31T17:39:03-04:00 Set the dynamic-system-linker flag to Manual This flag should be user controllable, hence Manual: True. - - - - - 3438b4eb by Sven Tennie at 2020-08-31T17:39:03-04:00 Ignore more files Ignore files from "new style" cabal builds (dist-newstyle folders) and from clangd (C language server). - - - - - 0718c8ec by Takenobu Tani at 2020-08-31T17:39:05-04:00 Limit upper version of Happy for ghc-9.0 and earlier (#18620) This patch adds the upper bound of a happy version for ghc-9.0 and earlier. Currently, we can't use happy-1.20.0 for ghc-9.0. See #18620. - - - - - f815b3bb by Takenobu Tani at 2020-08-31T17:39:05-04:00 Limit upper version of Happy for ghc-9.2 (#18620) This patch adds the upper bound of a happy version for ghc-9.2. Currently, We can use happy-1.19 or happy-1.20 for ghc-9.2. See #18620. - - - - - b1fd44ba by Sylvain Henry at 2020-08-31T17:39:07-04:00 Bignum: add BigNat compat functions (#18613) - - - - - 30 changed files: - .gitignore - aclocal.m4 - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/CmmToAsm/CFG/Dominators.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/SysTools/BaseDir.hs - compiler/GHC/Types/Id/Make.hs - compiler/GHC/Types/Unique/Supply.hs - compiler/GHC/Unit/State.hs - compiler/ghc.cabal.in - configure.ac - hadrian/cfg/system.config.in - hadrian/hadrian.cabal - hadrian/src/Oracles/Flag.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Settings/Flavours/Validate.hs - includes/ghc.mk - libraries/Win32 - libraries/base/GHC/Event/Thread.hs - libraries/ghc-bignum/src/GHC/Num/BigNat/Check.hs - libraries/ghc-bignum/src/GHC/Num/BigNat/FFI.hs - libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs - libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs - libraries/ghc-bignum/src/GHC/Num/WordArray.hs - libraries/ghc-prim/GHC/Magic.hs - libraries/integer-gmp/src/GHC/Integer/GMP/Internals.hs - libraries/process - mk/config.mk.in The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/36098d00f0906efd87bc4ca7d37001c7658904d5...b1fd44bad93ff54b9e956e4041fd56a83fc4a776 -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/36098d00f0906efd87bc4ca7d37001c7658904d5...b1fd44bad93ff54b9e956e4041fd56a83fc4a776 You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gitlab at gitlab.haskell.org Mon Aug 31 22:30:50 2020 From: gitlab at gitlab.haskell.org (Ryan Scott) Date: Mon, 31 Aug 2020 18:30:50 -0400 Subject: [Git][ghc/ghc] Pushed new branch wip/wire-in-constraint-tuples Message-ID: <5f4d7a1aef89_80b3f8487718bd010037831@gitlab.haskell.org.mail> Ryan Scott pushed new branch wip/wire-in-constraint-tuples at Glasgow Haskell Compiler / GHC -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/wire-in-constraint-tuples You're receiving this email because of your account on gitlab.haskell.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: